changeset 4998:5540ea103272 libavformat

export data from private streams
author bcoudurier
date Tue, 02 Jun 2009 07:26:58 +0000
parents 54cc10207200
children 476d3417effa
files mpegts.c
diffstat 1 files changed, 23 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/mpegts.c	Sun May 31 08:47:40 2009 +0000
+++ b/mpegts.c	Tue Jun 02 07:26:58 2009 +0000
@@ -923,6 +923,11 @@
                     pes->header[2] == 0x01) {
                     /* it must be an mpeg2 PES stream */
                     code = pes->header[3] | 0x100;
+                    dprintf(pes->stream, "pid=%x pes_code=%#x\n", pes->pid, code);
+
+                    if ((pes->st && pes->st->discard == AVDISCARD_ALL) ||
+                        code == 0x1be) /* padding_stream */
+                        goto skip;
 
                     /* stream not present in PMT */
                     if (!pes->st)
@@ -930,16 +935,27 @@
                     if (!pes->st)
                         return AVERROR(ENOMEM);
 
-                    if (pes->st->discard == AVDISCARD_ALL ||
-                        !((code >= 0x1c0 && code <= 0x1df) ||
-                          (code >= 0x1e0 && code <= 0x1ef) ||
-                          (code == 0x1bd) || (code == 0x1fd)))
-                        goto skip;
-                    pes->state = MPEGTS_PESHEADER_FILL;
                     pes->total_size = AV_RB16(pes->header + 4);
                     /* NOTE: a zero total size means the PES size is
                        unbounded */
-                    pes->pes_header_size = pes->header[8] + 9;
+                    if (!pes->total_size)
+                        pes->total_size = MAX_PES_PAYLOAD;
+
+                    /* allocate pes buffer */
+                    pes->buffer = av_malloc(pes->total_size+FF_INPUT_BUFFER_PADDING_SIZE);
+                    if (!pes->buffer)
+                        return AVERROR(ENOMEM);
+
+                    if (code != 0x1bc && code != 0x1bf && /* program_stream_map, private_stream_2 */
+                        code != 0x1f0 && code != 0x1f1 && /* ECM, EMM */
+                        code != 0x1ff && code != 0x1f2 && /* program_stream_directory, DSMCC_stream */
+                        code != 0x1f8) {                  /* ITU-T Rec. H.222.1 type E stream */
+                        pes->state = MPEGTS_PESHEADER_FILL;
+                        pes->pes_header_size = pes->header[8] + 9;
+                    } else {
+                        pes->state = MPEGTS_PAYLOAD;
+                        pes->data_index = 0;
+                    }
                 } else {
                     /* otherwise, it should be a table */
                     /* skip packet */
@@ -979,15 +995,6 @@
                     r += 5;
                 }
 
-                if (pes->total_size > pes->data_index - 6)
-                    pes->total_size -= pes->data_index - 6;
-                else
-                    pes->total_size = MAX_PES_PAYLOAD;
-                /* allocate pes buffer */
-                pes->buffer = av_malloc(pes->total_size+FF_INPUT_BUFFER_PADDING_SIZE);
-                if (!pes->buffer)
-                    return AVERROR(ENOMEM);
-
                 /* we got the full header. We parse it and get the payload */
                 pes->state = MPEGTS_PAYLOAD;
                 pes->data_index = 0;