[FFmpeg-devel] [PATCH 2/2] avformat/mpegts: parse for AC-3 descriptor 6A

lance.lmwang at gmail.com lance.lmwang at gmail.com
Fri Aug 14 17:35:17 EEST 2020


From: Limin Wang <lance.lmwang at gmail.com>

Signed-off-by: Limin Wang <lance.lmwang at gmail.com>
---
 libavformat/mpegts.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 47 insertions(+), 6 deletions(-)

diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index f71f18a5..72cc72a 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -2075,16 +2075,57 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type
         break;
     case 0x6a: /* ac-3_descriptor */
         {
-            int component_type_flag = get8(pp, desc_end) & (1 << 7);
-            if (component_type_flag) {
-                int component_type = get8(pp, desc_end);
-                int service_type_mask = 0x38;  // 0b00111000
-                int service_type = ((component_type & service_type_mask) >> 3);
+            AVDVBAC3Descriptor desc6a;
+            uint8_t buf;
+
+            if (desc_end - *pp < 1)
+                return AVERROR_INVALIDDATA;
+
+            buf = get8(pp, desc_end);
+            desc6a.component_type_flag = (buf >> 7) & 0x1;
+            desc6a.bsid_flag           = (buf >> 6) & 0x1;
+            desc6a.mainid_flag         = (buf >> 5) & 0x1;
+            desc6a.asvc_flag           = (buf >> 4) & 0x1;
+
+            av_log(ts ? ts->stream : fc, AV_LOG_DEBUG, "Stream[0x%x] AC-3(6a):", st->id);
+            if (desc6a.component_type_flag) {
+                int service_type;
+                int number_of_channels;
+                desc6a.component_type = get8(pp, desc_end);
+                service_type = ((desc6a.component_type >> 3) & 0x7);
                 if (service_type == 0x02 /* 0b010 */) {
                     st->disposition |= AV_DISPOSITION_DESCRIPTIONS;
-                    av_log(ts ? ts->stream : fc, AV_LOG_DEBUG, "New track disposition for id %u: %u\n", st->id, st->disposition);
+                    av_log(ts ? ts->stream : fc, AV_LOG_DEBUG,
+                           " disposition: 0x%x", st->disposition);
+                }
+                number_of_channels = desc6a.component_type & 0x7;
+                av_log(ts ? ts->stream : fc, AV_LOG_DEBUG, " component_type: 0x%x number_of_channels: %u",
+                        desc6a.component_type, number_of_channels);
+            }
+            if (desc6a.bsid_flag) {
+                if (desc_end - *pp < 1) {
+                    return AVERROR_INVALIDDATA;
+                }
+                desc6a.bsid = get8(pp, desc_end);
+                av_log(ts ? ts->stream : fc, AV_LOG_DEBUG, " bsid: %u", desc6a.bsid);
+            }
+            if (desc6a.mainid_flag) {
+                if (desc_end - *pp < 1) {
+                    return AVERROR_INVALIDDATA;
+                }
+                desc6a.mainid = get8(pp, desc_end);
+                av_log(ts ? ts->stream : fc, AV_LOG_DEBUG, " mainid: %u", desc6a.mainid);
+            }
+            if (desc6a.asvc_flag) {
+                if (desc_end - *pp < 1) {
+                    return AVERROR_INVALIDDATA;
                 }
+                desc6a.asvc = get8(pp, desc_end);
+                av_log(ts ? ts->stream : fc, AV_LOG_DEBUG, " asvc: %u", desc6a.asvc);
             }
+            if (desc6a.component_type_flag || desc6a.bsid_flag ||
+                desc6a.mainid_flag         || desc6a.asvc_flag)
+                av_log(ts ? ts->stream : fc, AV_LOG_DEBUG, "\n");
         }
         break;
     case 0x7a: /* enhanced_ac-3_descriptor */
-- 
1.8.3.1



More information about the ffmpeg-devel mailing list