[FFmpeg-devel] [PATCH 2/8] avformat/mpegts: decode and export ATSC AC-3 descriptor

lance.lmwang at gmail.com lance.lmwang at gmail.com
Wed Jul 22 18:27:33 EEST 2020


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

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

diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index 1ed7eaf..d450507 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -1990,6 +1990,48 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type
                 st->request_probe = 50;
         }
         break;
+    case 0x81: /* ATSC AC-3 descriptor */
+        {
+            uint8_t buf;
+            uint8_t sample_rate_code, bsid,bitrate_code,surround_mode, bsmod;
+            uint8_t num_channels, full_svc, mainid, priority, asvcflags;
+
+            if (desc_len < 4)
+                return AVERROR_INVALIDDATA;
+
+            buf = get8(pp, desc_end);
+            sample_rate_code = (buf >> 5 ) & 0x07;
+            bsid             =  buf        & 0x1F;
+            av_dict_set_int(&st->metadata, "atsc.ac3_desc.sample_rate_code", sample_rate_code, 0);
+            av_dict_set_int(&st->metadata, "atsc.ac3_desc.bsid", bsid, 0);
+
+            buf = get8(pp, desc_end);
+            bitrate_code = (buf >> 2 ) & 0x1F;
+            surround_mode = buf        & 0x03;
+            av_dict_set_int(&st->metadata, "atsc.ac3_desc.bitrate_code", bitrate_code, 0);
+            av_dict_set_int(&st->metadata, "atsc.ac3_desc.surround_mode", surround_mode, 0);
+
+            buf = get8(pp, desc_end);
+            bsmod        = (buf >> 5) & 0x07;
+            num_channels = (buf >> 1) & 0x0F;
+            full_svc     = buf & 0x01;
+            av_dict_set_int(&st->metadata, "atsc.ac3_desc.bsmod", bsmod, 0);
+            av_dict_set_int(&st->metadata, "atsc.ac3_desc.num_channels", num_channels, 0);
+            av_dict_set_int(&st->metadata, "atsc.ac3_desc.full_svc", full_svc, 0);
+
+            buf = get8(pp, desc_end);
+            if (bsmod < 2) {
+                mainid   = (buf >> 5) & 0x7;
+                priority = (buf >> 3) & 0x3;
+                av_dict_set_int(&st->metadata, "atsc.ac3_desc.mainid", mainid, 0);
+                av_dict_set_int(&st->metadata, "atsc.ac3_desc.priority", priority, 0);
+            } else {
+                asvcflags = buf;
+                av_dict_set_int(&st->metadata, "atsc.ac3_desc.asvc", asvcflags, 0);
+            }
+            /* other field in standard will be skipped  */
+        }
+        break;
     case 0x52: /* stream identifier descriptor */
         st->stream_identifier = 1 + get8(pp, desc_end);
         break;
-- 
1.8.3.1



More information about the ffmpeg-devel mailing list