diff mbox series

[FFmpeg-devel,6/8] avformat/mpegtsenc: support dvb ac3 descriptor by metadata

Message ID 1595431659-664-6-git-send-email-lance.lmwang@gmail.com
State New
Headers show
Series [FFmpeg-devel,1/8] avformat/mpegts: add dvb ac3 descriptor metadata
Related show

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Limin Wang July 22, 2020, 3:27 p.m. UTC
From: Limin Wang <lance.lmwang@gmail.com>

Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
---
 libavformat/mpegtsenc.c | 45 +++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 43 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index 718ddab..a5b45fb 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -486,9 +486,50 @@  static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service)
         case AVMEDIA_TYPE_AUDIO:
             if (ts->flags & MPEGTS_FLAG_SYSTEM_B) {
                 if (codec_id == AV_CODEC_ID_AC3) {
+                    int len = 1;
+                    uint8_t component_type_flag = 0;
+                    uint8_t bsid_flag           = 0;
+                    uint8_t mainid_flag         = 0;
+                    uint8_t asvc_flag           = 0;
+                    uint8_t componenet_type_value, bsid_value, mainid_value, asvc_value;
+                    AVDictionaryEntry *component_type = av_dict_get(st->metadata, "dvb.ac3_desc.component_type", NULL, 0);
+                    AVDictionaryEntry *bsid   = av_dict_get(st->metadata, "dvb.ac3_desc.bsid", NULL, 0);
+                    AVDictionaryEntry *mainid = av_dict_get(st->metadata, "dvb.ac3_desc.mainid", NULL, 0);
+                    AVDictionaryEntry *asvc   = av_dict_get(st->metadata, "dvb.ac3_desc.asvc", NULL, 0);
+
                     *q++=0x6a; // AC3 descriptor see A038 DVB SI
-                    *q++=1; // 1 byte, all flags sets to 0
-                    *q++=0; // omit all fields...
+
+                    if (component_type) {
+                        component_type_flag   = 1;
+                        componenet_type_value = atoi(component_type->value);
+                        len ++;
+                    }
+                    if (bsid) {
+                        bsid_flag    = 1;
+                        bsid_value   = atoi(bsid->value);
+                        len ++;
+                    }
+                    if (mainid) {
+                        mainid_flag  = 1;
+                        mainid_value = atoi(mainid->value);
+                        len ++;
+                    }
+                    if (asvc) {
+                        asvc_flag    = 1;
+                        asvc_value   = atoi(asvc->value);
+                        len ++;
+                    }
+
+                    *q++ = len;
+                    *q++ = component_type_flag << 7 | bsid_flag << 6 | mainid_flag << 5 | asvc_flag << 4;
+                    if (component_type_flag)
+                        *q++ = componenet_type_value;
+                    if (bsid_flag)
+                        *q++ = bsid_value;
+                    if (mainid_flag)
+                        *q++ = mainid_value;
+                    if (asvc_flag)
+                        *q++ = asvc_value;
                 } else if (codec_id == AV_CODEC_ID_EAC3) {
                     *q++=0x7a; // EAC3 descriptor see A038 DVB SI
                     *q++=1; // 1 byte, all flags sets to 0