[SCM] libav/experimental: Correct packetization for MPEG video frames, and correct setting of the "B" and "E" bits in the payload header

siretart at users.alioth.debian.org siretart at users.alioth.debian.org
Sun Jun 30 16:06:10 UTC 2013


The following commit has been merged in the experimental branch:
commit 46b274d4e51a4d16613c88e34d1b0723f5c90622
Author: Luca Abeni <lucabe72 at email.it>
Date:   Wed Aug 29 10:47:15 2007 +0000

    Correct packetization for MPEG video frames, and correct setting of the
    "B" and "E" bits in the payload header
    
    Originally committed as revision 10260 to svn://svn.ffmpeg.org/ffmpeg/trunk

diff --git a/libavformat/rtp_mpv.c b/libavformat/rtp_mpv.c
index 55c1b08..dc18d90 100644
--- a/libavformat/rtp_mpv.c
+++ b/libavformat/rtp_mpv.c
@@ -21,6 +21,8 @@
 #include "avformat.h"
 #include "rtp_internal.h"
 
+#include "mpegvideo.h"
+
 /* NOTE: a single frame must be passed with sequence header if
    needed. XXX: use slices. */
 void ff_rtp_send_mpegvideo(AVFormatContext *s1, const uint8_t *buf1, int size)
@@ -28,22 +30,54 @@ void ff_rtp_send_mpegvideo(AVFormatContext *s1, const uint8_t *buf1, int size)
     RTPDemuxContext *s = s1->priv_data;
     AVStream *st = s1->streams[0];
     int len, h, max_packet_size;
-    int b=1, e=0;
     uint8_t *q;
+    int begin_of_slice, end_of_slice;
 
     max_packet_size = s->max_payload_size;
+    begin_of_slice = 1;
+    end_of_slice = 0;
 
     while (size > 0) {
         len = max_packet_size - 4;
 
         if (len >= size) {
             len = size;
-            e = 1;
+            end_of_slice = 1;
+        } else {
+            const uint8_t *r, *r1;
+            int start_code;
+
+            r1 = buf1;
+            while (1) {
+                start_code = -1;
+                r = ff_find_start_code(r1, buf1 + size, &start_code);
+                if((start_code & 0xFFFFFF00) == 0x100) {
+                    /* New start code found */
+                    if (r - buf1 < len) {
+                        /* The current slice fits in the packet */
+                        if (begin_of_slice == 0) {
+                            /* no slice at the beginning of the packet... */
+                            end_of_slice = 1;
+                            len = r - buf1 - 4;
+                            break;
+                        }
+                        r1 = r;
+                    } else {
+                        if (r - r1 < max_packet_size) {
+                            len = r1 - buf1 - 4;
+                            end_of_slice = 1;
+                        }
+                        break;
+                    }
+                } else {
+                    break;
+                }
+            }
         }
 
         h = 0;
-        h |= b << 12;
-        h |= e << 11;
+        h |= begin_of_slice << 12;
+        h |= end_of_slice << 11;
 
         q = s->buf;
         *q++ = h >> 24;
@@ -61,6 +95,8 @@ void ff_rtp_send_mpegvideo(AVFormatContext *s1, const uint8_t *buf1, int size)
 
         buf1 += len;
         size -= len;
+        begin_of_slice = end_of_slice;
+        end_of_slice = 0;
     }
     s->cur_timestamp++;
 }

-- 
Libav/FFmpeg packaging



More information about the pkg-multimedia-commits mailing list