[FFmpeg-devel] [PATCH] Make parser not favor packets with pts/dts (and related fixes)

Michael Niedermayer michaelni
Sun Mar 1 20:42:19 CET 2009


Hi

patch below does make the parser treat packets equal, <put some joke mixing
human and packet rights here>

above being hunk 3
rest being surrounding changes needed and or found while trying to
get it working

this should make it easier to feed pos in the parser as well

i will commit this cleanly split as soon as the release happens or is
postponed or the release branch is finally forked off or if nothing
happens for too long ...


Index: libavcodec/parser.c
===================================================================
--- libavcodec/parser.c	(revision 17675)
+++ libavcodec/parser.c	(working copy)
@@ -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]){
@@ -96,6 +96,8 @@
             s->offset = s->next_frame_offset - s->cur_frame_offset[i];
             if(remove)
                 s->cur_frame_offset[i]= INT64_MAX;
+            if(s->cur_offset + off < s->cur_frame_end[i])
+                break;
         }
     }
 }
@@ -139,14 +141,12 @@
         buf = dummy_buf;
     } else {
         /* add a new packet descriptor */
-        if(pts != AV_NOPTS_VALUE || dts != AV_NOPTS_VALUE){
             i = (s->cur_frame_start_index + 1) & (AV_PARSER_PTS_NB - 1);
             s->cur_frame_start_index = i;
             s->cur_frame_offset[i] = s->cur_offset;
             s->cur_frame_end[i] = s->cur_offset + buf_size;
             s->cur_frame_pts[i] = pts;
             s->cur_frame_dts[i] = dts;
-        }
     }
 
     if (s->fetch_timestamp){
Index: libavcodec/mpegvideo_parser.c
===================================================================
--- libavcodec/mpegvideo_parser.c	(revision 17675)
+++ libavcodec/mpegvideo_parser.c	(working copy)
@@ -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;
Index: libavcodec/mpegvideo.h
===================================================================
--- libavcodec/mpegvideo.h	(revision 17675)
+++ libavcodec/mpegvideo.h	(working copy)
@@ -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];
Index: libavcodec/mpeg12.c
===================================================================
--- libavcodec/mpeg12.c	(revision 17675)
+++ libavcodec/mpeg12.c	(working copy)
@@ -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;



-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

When you are offended at any man's fault, turn to yourself and study your
own failings. Then you will forget your anger. -- Epictetus
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090301/66b1d2b8/attachment.pgp>



More information about the ffmpeg-devel mailing list