]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/mpegts.c
Only link against alsa if enabled.
[ffmpeg] / libavformat / mpegts.c
index df281571b15ff6199fb0a3abd38e66bb0b761678..0d38e6f92a9bb7994846c8d5725f45117f66c6fb 100644 (file)
@@ -128,13 +128,15 @@ struct MpegTSContext {
 
 enum MpegTSState {
     MPEGTS_HEADER = 0,
+    MPEGTS_PESHEADER,
     MPEGTS_PESHEADER_FILL,
     MPEGTS_PAYLOAD,
     MPEGTS_SKIP,
 };
 
 /* enough for PES header + length */
-#define PES_START_SIZE 9
+#define PES_START_SIZE  6
+#define PES_HEADER_SIZE 9
 #define MAX_PES_HEADER_SIZE (9 + 255)
 
 struct PESContext {
@@ -526,6 +528,7 @@ static const StreamType DESC_types[] = {
     { 0x7a, CODEC_TYPE_AUDIO,            CODEC_ID_EAC3 }, /* E-AC-3 descriptor */
     { 0x7b, CODEC_TYPE_AUDIO,             CODEC_ID_DTS },
     { 0x59, CODEC_TYPE_SUBTITLE, CODEC_ID_DVB_SUBTITLE }, /* subtitling descriptor */
+    { 0 },
 };
 
 static void mpegts_find_stream_type(AVStream *st,
@@ -550,7 +553,7 @@ static AVStream *new_pes_av_stream(PESContext *pes, uint32_t prog_reg_desc, uint
     av_set_pts_info(st, 33, 1, 90000);
     st->priv_data = pes;
     st->codec->codec_type = CODEC_TYPE_DATA;
-    st->codec->codec_id   = CODEC_ID_PROBE;
+    st->codec->codec_id   = CODEC_ID_NONE;
     st->need_parsing = AVSTREAM_PARSE_FULL;
     pes->st = st;
 
@@ -561,13 +564,13 @@ static AVStream *new_pes_av_stream(PESContext *pes, uint32_t prog_reg_desc, uint
 
     mpegts_find_stream_type(st, pes->stream_type, ISO_types);
     if (prog_reg_desc == AV_RL32("HDMV") &&
-        st->codec->codec_id == CODEC_ID_PROBE)
+        st->codec->codec_id == CODEC_ID_NONE)
         mpegts_find_stream_type(st, pes->stream_type, HDMV_types);
-    if (st->codec->codec_id == CODEC_ID_PROBE)
+    if (st->codec->codec_id == CODEC_ID_NONE)
         mpegts_find_stream_type(st, pes->stream_type, MISC_types);
 
     /* stream was not present in PMT, guess based on PES start code */
-    if (st->codec->codec_id == CODEC_ID_PROBE) {
+    if (st->codec->codec_id == CODEC_ID_NONE) {
         if (code >= 0x1c0 && code <= 0x1df) {
             st->codec->codec_type = CODEC_TYPE_AUDIO;
             st->codec->codec_id = CODEC_ID_MP2;
@@ -684,7 +687,7 @@ static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len
             dprintf(ts->stream, "tag: 0x%02x len=%d\n",
                    desc_tag, desc_len);
 
-            if (st->codec->codec_id == CODEC_ID_PROBE &&
+            if (st->codec->codec_id == CODEC_ID_NONE &&
                 stream_type == STREAM_TYPE_PRIVATE_DATA)
                 mpegts_find_stream_type(st, desc_tag, DESC_types);
 
@@ -710,7 +713,7 @@ static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len
             case 0x05: /* registration descriptor */
                 st->codec->codec_tag = bytestream_get_le32(&p);
                 dprintf(ts->stream, "reg_desc=%.4s\n", (char*)&st->codec->codec_tag);
-                if (st->codec->codec_id == CODEC_ID_PROBE &&
+                if (st->codec->codec_id == CODEC_ID_NONE &&
                     stream_type == STREAM_TYPE_PRIVATE_DATA)
                     mpegts_find_stream_type(st, st->codec->codec_tag, REGD_types);
                 break;
@@ -951,8 +954,12 @@ static int mpegts_push_data(MpegTSFilter *filter,
                         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;
+                        pes->state = MPEGTS_PESHEADER;
+                        if (pes->st->codec->codec_id == CODEC_ID_NONE) {
+                            dprintf(pes->stream, "pid=%x stream_type=%x probing\n",
+                                    pes->pid, pes->stream_type);
+                            pes->st->codec->codec_id = CODEC_ID_PROBE;
+                        }
                     } else {
                         pes->state = MPEGTS_PAYLOAD;
                         pes->data_index = 0;
@@ -968,6 +975,21 @@ static int mpegts_push_data(MpegTSFilter *filter,
             break;
             /**********************************************/
             /* PES packing parsing */
+        case MPEGTS_PESHEADER:
+            len = PES_HEADER_SIZE - pes->data_index;
+            if (len < 0)
+                return -1;
+            if (len > buf_size)
+                len = buf_size;
+            memcpy(pes->header + pes->data_index, p, len);
+            pes->data_index += len;
+            p += len;
+            buf_size -= len;
+            if (pes->data_index == PES_HEADER_SIZE) {
+                pes->pes_header_size = pes->header[8] + 9;
+                pes->state = MPEGTS_PESHEADER_FILL;
+            }
+            break;
         case MPEGTS_PESHEADER_FILL:
             len = pes->pes_header_size - pes->data_index;
             if (len < 0)