# HG changeset patch # User michael # Date 1236005598 0 # Node ID cecf81f93756402eac1a4537f42a1a67d9631dd9 # Parent bea68afbf1996a57929475962e8bb54b671b8a55 Call ff_fetch_timestamp() for mpeg1/2 when a picture start code is found instead of calling it at the end of a frame with a large negative offset. This significantly reduces the maximal distance in container packets between the point where the first byte of the "access unit" was stored and where we call ff_fetch_timestamp() thus reducing the constraints on our parser. Also change the parser from next_frame_offset to cur, this is needed because now the reference is from container packet start instead of frame start. (i previously misinterpreted this as bug) diff -r bea68afbf199 -r cecf81f93756 mpeg12.c --- a/mpeg12.c Mon Mar 02 09:22:17 2009 +0000 +++ b/mpeg12.c Mon Mar 02 14:53:18 2009 +0000 @@ -2196,7 +2196,7 @@ * Finds the end of the current frame in the bitstream. * @return the position of the first byte of the next frame, or -1 */ -int ff_mpeg1_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size) +int ff_mpeg1_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size, AVCodecParserContext *s) { int i; uint32_t state= pc->state; @@ -2244,6 +2244,9 @@ return i-3; } } + if(s && state == PICTURE_START_CODE){ + ff_fetch_timestamp(s, i-4, 1); + } } } pc->state= state; @@ -2276,7 +2279,7 @@ } if(s2->flags&CODEC_FLAG_TRUNCATED){ - int next= ff_mpeg1_find_frame_end(&s2->parse_context, buf, buf_size); + int next= ff_mpeg1_find_frame_end(&s2->parse_context, buf, buf_size, NULL); if( ff_combine_frame(&s2->parse_context, next, (const uint8_t **)&buf, &buf_size) < 0 ) return buf_size; diff -r bea68afbf199 -r cecf81f93756 mpegvideo.h --- a/mpegvideo.h Mon Mar 02 09:22:17 2009 +0000 +++ b/mpegvideo.h Mon Mar 02 14:53:18 2009 +0000 @@ -769,7 +769,7 @@ void ff_mpeg1_encode_init(MpegEncContext *s); void ff_mpeg1_encode_slice_header(MpegEncContext *s); void ff_mpeg1_clean_buffers(MpegEncContext *s); -int ff_mpeg1_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size); +int ff_mpeg1_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size, AVCodecParserContext *s); extern const uint8_t ff_mpeg4_y_dc_scale_table[32]; extern const uint8_t ff_mpeg4_c_dc_scale_table[32]; diff -r bea68afbf199 -r cecf81f93756 mpegvideo_parser.c --- a/mpegvideo_parser.c Mon Mar 02 09:22:17 2009 +0000 +++ b/mpegvideo_parser.c Mon Mar 02 14:53:18 2009 +0000 @@ -29,7 +29,6 @@ { ParseContext1 *pc = s->priv_data; const uint8_t *buf_end; - const uint8_t *buf_start= buf; uint32_t start_code; int frame_rate_index, ext_type, bytes_left; int frame_rate_ext_n, frame_rate_ext_d; @@ -44,8 +43,6 @@ bytes_left = buf_end - buf; switch(start_code) { case PICTURE_START_CODE: - ff_fetch_timestamp(s, buf-buf_start-4, 1); - if (bytes_left >= 2) { s->pict_type = (buf[1] >> 3) & 7; } @@ -137,7 +134,7 @@ if(s->flags & PARSER_FLAG_COMPLETE_FRAMES){ next= buf_size; }else{ - next= ff_mpeg1_find_frame_end(pc, buf, buf_size); + next= ff_mpeg1_find_frame_end(pc, buf, buf_size, s); if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) { *poutbuf = NULL; diff -r bea68afbf199 -r cecf81f93756 parser.c --- a/parser.c Mon Mar 02 09:22:17 2009 +0000 +++ b/parser.c Mon Mar 02 14:53:18 2009 +0000 @@ -87,7 +87,7 @@ s->dts= s->pts= AV_NOPTS_VALUE; s->offset= 0; for(i = 0; i < AV_PARSER_PTS_NB; i++) { - if ( s->next_frame_offset + off >= s->cur_frame_offset[i] + if ( s->cur_offset + off >= s->cur_frame_offset[i] &&(s-> frame_offset < s->cur_frame_offset[i] || !s->frame_offset) //check is disabled becausue mpeg-ts doesnt send complete PES packets && /*s->next_frame_offset + off <*/ s->cur_frame_end[i]){