@ -21,50 +21,36 @@
# include "avcodec.h"
# include "avcodec.h"
# include "bsf.h"
# include "bsf.h"
# include "internal.h"
# include "mpeg4video.h"
# include "mpeg4video.h"
typedef struct UnpackBFramesBSFContext {
typedef struct UnpackBFramesBSFContext {
AVPacket * b_frame ;
AVPacket * b_frame ;
} UnpackBFramesBSFContext ;
} UnpackBFramesBSFContext ;
/* search next start code */
static unsigned int find_startcode ( const uint8_t * buf , int buf_size , int * pos )
{
unsigned int startcode = 0xFF ;
for ( ; * pos < buf_size ; ) {
startcode = ( ( startcode < < 8 ) | buf [ * pos ] ) & 0xFFFFFFFF ;
* pos + = 1 ;
if ( ( startcode & 0xFFFFFF00 ) ! = 0x100 )
continue ; /* no startcode */
return startcode ;
}
return 0 ;
}
/* determine the position of the packed marker in the userdata,
/* determine the position of the packed marker in the userdata,
* the number of VOPs and the position of the second VOP */
* the number of VOPs and the position of the second VOP */
static void scan_buffer ( const uint8_t * buf , int buf_size ,
static void scan_buffer ( const uint8_t * buf , int buf_size ,
int * pos_p , int * nb_vop , int * pos_vop2 ) {
int * pos_p , int * nb_vop , int * pos_vop2 ) {
unsigned in t startcode ;
uint32_t startcode ;
int pos , i ;
const uint8_t * end = buf + buf_size , * pos = buf ;
for ( pos = 0 ; pos < buf_size ; ) {
while ( pos < end ) {
startcode = find_startcode ( buf , buf_size , & pos ) ;
startcode = - 1 ;
pos = avpriv_find_start_code ( pos , end , & startcode ) ;
if ( startcode = = USER_DATA_STARTCODE & & pos_p ) {
if ( startcode = = USER_DATA_STARTCODE & & pos_p ) {
/* check if the (DivX) userdata string ends with 'p' (packed) */
/* check if the (DivX) userdata string ends with 'p' (packed) */
for ( i = 0 ; i < 255 & & pos + i + 1 < buf_siz e; i + + ) {
for ( int i = 0 ; i < 255 & & pos + i + 1 < end ; i + + ) {
if ( buf [ pos + i ] = = ' p ' & & buf [ pos + i + 1 ] = = ' \0 ' ) {
if ( pos [ i ] = = ' p ' & & pos [ i + 1 ] = = ' \0 ' ) {
* pos_p = pos + i ;
* pos_p = pos + i - buf ;
break ;
break ;
}
}
}
}
} else if ( startcode = = VOP_STARTCODE & & nb_vop ) {
} else if ( startcode = = VOP_STARTCODE & & nb_vop ) {
* nb_vop + = 1 ;
* nb_vop + = 1 ;
if ( * nb_vop = = 2 & & pos_vop2 ) {
if ( * nb_vop = = 2 & & pos_vop2 ) {
* pos_vop2 = pos - 4 ; /* subtract 4 bytes startcode */
* pos_vop2 = pos - buf - 4 ; /* subtract 4 bytes startcode */
}
}
}
}
}
}