]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/mpegts.c
Support some LATM AAC streams (they can be decoded with MPlayer).
[ffmpeg] / libavformat / mpegts.c
index 76efe30e767d1f5d28b490876bdd5ce5ac8a6acf..ceec2a15c2b49e5966238292dce76445d43cfbae 100644 (file)
@@ -36,7 +36,7 @@
 
 /* maximum size in which we look for synchronisation if
    synchronisation is lost */
-#define MAX_RESYNC_SIZE 4096
+#define MAX_RESYNC_SIZE 65536
 
 #define MAX_PES_PAYLOAD 200*1024
 
@@ -501,6 +501,7 @@ static const StreamType ISO_types[] = {
     { 0x04, CODEC_TYPE_AUDIO,        CODEC_ID_MP3 },
     { 0x0f, CODEC_TYPE_AUDIO,        CODEC_ID_AAC },
     { 0x10, CODEC_TYPE_VIDEO,      CODEC_ID_MPEG4 },
+    { 0x11, CODEC_TYPE_AUDIO,        CODEC_ID_AAC }, /* LATM syntax */
     { 0x1b, CODEC_TYPE_VIDEO,       CODEC_ID_H264 },
     { 0xd1, CODEC_TYPE_VIDEO,      CODEC_ID_DIRAC },
     { 0xea, CODEC_TYPE_VIDEO,        CODEC_ID_VC1 },
@@ -512,6 +513,7 @@ static const StreamType HDMV_types[] = {
     { 0x81, CODEC_TYPE_AUDIO, CODEC_ID_AC3 },
     { 0x82, CODEC_TYPE_AUDIO, CODEC_ID_DTS },
     { 0x83, CODEC_TYPE_AUDIO, CODEC_ID_TRUEHD },
+    { 0x84, CODEC_TYPE_AUDIO, CODEC_ID_EAC3 },
     { 0x90, CODEC_TYPE_SUBTITLE, CODEC_ID_HDMV_PGS_SUBTITLE },
     { 0 },
 };
@@ -534,6 +536,7 @@ static const StreamType DESC_types[] = {
     { 0x6a, CODEC_TYPE_AUDIO,             CODEC_ID_AC3 }, /* AC-3 descriptor */
     { 0x7a, CODEC_TYPE_AUDIO,            CODEC_ID_EAC3 }, /* E-AC-3 descriptor */
     { 0x7b, CODEC_TYPE_AUDIO,             CODEC_ID_DTS },
+    { 0x56, CODEC_TYPE_SUBTITLE, CODEC_ID_DVB_TELETEXT },
     { 0x59, CODEC_TYPE_SUBTITLE, CODEC_ID_DVB_SUBTITLE }, /* subtitling descriptor */
     { 0 },
 };
@@ -728,6 +731,13 @@ static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len
                 mpegts_find_stream_type(st, desc_tag, DESC_types);
 
             switch(desc_tag) {
+            case 0x56: /* DVB teletext descriptor */
+                language[0] = get8(&p, desc_end);
+                language[1] = get8(&p, desc_end);
+                language[2] = get8(&p, desc_end);
+                language[3] = 0;
+                av_metadata_set(&st->metadata, "language", language);
+                break;
             case 0x59: /* subtitling descriptor */
                 language[0] = get8(&p, desc_end);
                 language[1] = get8(&p, desc_end);
@@ -1208,8 +1218,9 @@ static int handle_packet(MpegTSContext *ts, const uint8_t *packet)
 
 /* XXX: try to find a better synchro over several packets (use
    get_packet_size() ?) */
-static int mpegts_resync(ByteIOContext *pb)
+static int mpegts_resync(AVFormatContext *s)
 {
+    ByteIOContext *pb = s->pb;
     int c, i;
 
     for(i = 0;i < MAX_RESYNC_SIZE; i++) {
@@ -1221,13 +1232,15 @@ static int mpegts_resync(ByteIOContext *pb)
             return 0;
         }
     }
+    av_log(s, AV_LOG_ERROR, "max resync size reached, could not find sync byte\n");
     /* no sync found */
     return -1;
 }
 
 /* return -1 if error or EOF. Return 0 if OK. */
-static int read_packet(ByteIOContext *pb, uint8_t *buf, int raw_packet_size)
+static int read_packet(AVFormatContext *s, uint8_t *buf, int raw_packet_size)
 {
+    ByteIOContext *pb = s->pb;
     int skip, len;
 
     for(;;) {
@@ -1238,8 +1251,8 @@ static int read_packet(ByteIOContext *pb, uint8_t *buf, int raw_packet_size)
         if (buf[0] != 0x47) {
             /* find a new packet start */
             url_fseek(pb, -TS_PACKET_SIZE, SEEK_CUR);
-            if (mpegts_resync(pb) < 0)
-                return AVERROR_INVALIDDATA;
+            if (mpegts_resync(s) < 0)
+                return AVERROR(EAGAIN);
             else
                 continue;
         } else {
@@ -1255,7 +1268,6 @@ static int read_packet(ByteIOContext *pb, uint8_t *buf, int raw_packet_size)
 static int handle_packets(MpegTSContext *ts, int nb_packets)
 {
     AVFormatContext *s = ts->stream;
-    ByteIOContext *pb = s->pb;
     uint8_t packet[TS_PACKET_SIZE];
     int packet_num, ret;
 
@@ -1267,7 +1279,7 @@ static int handle_packets(MpegTSContext *ts, int nb_packets)
         packet_num++;
         if (nb_packets != 0 && packet_num >= nb_packets)
             break;
-        ret = read_packet(pb, packet, ts->raw_packet_size);
+        ret = read_packet(s, packet, ts->raw_packet_size);
         if (ret != 0)
             return ret;
         ret = handle_packet(ts, packet);
@@ -1374,7 +1386,7 @@ static int mpegts_read_header(AVFormatContext *s,
 
         mpegts_open_section_filter(ts, PAT_PID, pat_cb, ts, 1);
 
-        handle_packets(ts, s->probesize);
+        handle_packets(ts, s->probesize / ts->raw_packet_size);
         /* if could not find service, enable auto_guess */
 
         ts->auto_guess = 1;
@@ -1403,7 +1415,7 @@ static int mpegts_read_header(AVFormatContext *s,
         nb_pcrs = 0;
         nb_packets = 0;
         for(;;) {
-            ret = read_packet(s->pb, packet, ts->raw_packet_size);
+            ret = read_packet(s, packet, ts->raw_packet_size);
             if (ret < 0)
                 return -1;
             pid = AV_RB16(packet + 1) & 0x1fff;
@@ -1452,7 +1464,7 @@ static int mpegts_raw_read_packet(AVFormatContext *s,
     if (av_new_packet(pkt, TS_PACKET_SIZE) < 0)
         return AVERROR(ENOMEM);
     pkt->pos= url_ftell(s->pb);
-    ret = read_packet(s->pb, pkt->data, ts->raw_packet_size);
+    ret = read_packet(s, pkt->data, ts->raw_packet_size);
     if (ret < 0) {
         av_free_packet(pkt);
         return ret;