Do not split audio frames accross pes packets.
authorBaptiste Coudurier <baptiste.coudurier@gmail.com>
Wed, 13 Jan 2010 22:21:45 +0000 (22:21 +0000)
committerBaptiste Coudurier <baptiste.coudurier@gmail.com>
Wed, 13 Jan 2010 22:21:45 +0000 (22:21 +0000)
This was not supported by some equipment and cisco analyzer.

Originally committed as revision 21203 to svn://svn.ffmpeg.org/ffmpeg/trunk

libavformat/mpegtsenc.c
tests/lavf.regression.ref

index 148507f..be30e68 100644 (file)
@@ -775,7 +775,7 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st,
 static int mpegts_write_packet(AVFormatContext *s, AVPacket *pkt)
 {
     AVStream *st = s->streams[pkt->stream_index];
 static int mpegts_write_packet(AVFormatContext *s, AVPacket *pkt)
 {
     AVStream *st = s->streams[pkt->stream_index];
-    int len, size = pkt->size;
+    int size = pkt->size;
     uint8_t *buf= pkt->data;
     uint8_t *data= NULL;
     MpegTSWriteStream *ts_st = st->priv_data;
     uint8_t *buf= pkt->data;
     uint8_t *data= NULL;
     MpegTSWriteStream *ts_st = st->priv_data;
@@ -818,29 +818,20 @@ static int mpegts_write_packet(AVFormatContext *s, AVPacket *pkt)
         return 0;
     }
 
         return 0;
     }
 
-    if (ts_st->payload_pts == AV_NOPTS_VALUE) {
-        ts_st->payload_dts = dts;
-        ts_st->payload_pts = pts;
+    if (ts_st->payload_index + size > DEFAULT_PES_PAYLOAD_SIZE) {
+        mpegts_write_pes(s, st, ts_st->payload, ts_st->payload_index,
+                         ts_st->payload_pts, ts_st->payload_dts);
+        ts_st->payload_index = 0;
     }
 
     }
 
-    // audio
-    while (size > 0) {
-        len = DEFAULT_PES_PAYLOAD_SIZE - ts_st->payload_index;
-        if (len > size)
-            len = size;
-        memcpy(ts_st->payload + ts_st->payload_index, buf, len);
-        buf += len;
-        size -= len;
-        ts_st->payload_index += len;
-        if (ts_st->payload_index >= DEFAULT_PES_PAYLOAD_SIZE) {
-            mpegts_write_pes(s, st, ts_st->payload, ts_st->payload_index,
-                             ts_st->payload_pts, ts_st->payload_dts);
-            ts_st->payload_pts = AV_NOPTS_VALUE;
-            ts_st->payload_dts = AV_NOPTS_VALUE;
-            ts_st->payload_index = 0;
-        }
+    if (!ts_st->payload_index) {
+        ts_st->payload_pts = pts;
+        ts_st->payload_dts = dts;
     }
 
     }
 
+    memcpy(ts_st->payload + ts_st->payload_index, buf, size);
+    ts_st->payload_index += size;
+
     return 0;
 }
 
     return 0;
 }
 
index 83be8db..8b5110a 100644 (file)
@@ -15,7 +15,7 @@ e36a005ecca9add8bda6e0655d03716f *./tests/data/b-lavf.mpg
 b3174e2db508564c1cce0b5e3c1bc1bd *./tests/data/b-lavf.mxf_d10
 5330989 ./tests/data/b-lavf.mxf_d10
 ./tests/data/b-lavf.mxf_d10 CRC=0xc3f4f92e
 b3174e2db508564c1cce0b5e3c1bc1bd *./tests/data/b-lavf.mxf_d10
 5330989 ./tests/data/b-lavf.mxf_d10
 ./tests/data/b-lavf.mxf_d10 CRC=0xc3f4f92e
-da0d4fea54e7473e3cddb1607294c9e2 *./tests/data/b-lavf.ts
+a1a799fe07b3b9944aad8455a9706c5f *./tests/data/b-lavf.ts
 430144 ./tests/data/b-lavf.ts
 ./tests/data/b-lavf.ts CRC=0x133216c1
 62c5aeb636fc82cf6ba6277d36e42cb5 *./tests/data/b-lavf.swf
 430144 ./tests/data/b-lavf.ts
 ./tests/data/b-lavf.ts CRC=0x133216c1
 62c5aeb636fc82cf6ba6277d36e42cb5 *./tests/data/b-lavf.swf