[FFmpeg-devel] [PATCH 5/5] avformat/mpegtsenc: support 0x6a descriptor for AC-3 by side data if have

lance.lmwang at gmail.com lance.lmwang at gmail.com
Tue Jul 28 18:03:34 EEST 2020


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

Signed-off-by: Limin Wang <lance.lmwang at gmail.com>
---
 libavformat/mpegtsenc.c | 28 ++++++++++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)

diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index 718ddab..ff0da62 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -26,6 +26,7 @@
 #include "libavutil/intreadwrite.h"
 #include "libavutil/mathematics.h"
 #include "libavutil/opt.h"
+#include "libavutil//mpegts_audio_desc_metadata.h"
 
 #include "libavcodec/internal.h"
 
@@ -244,6 +245,8 @@ typedef struct MpegTSWriteStream {
     /* For Opus */
     int opus_queued_samples;
     int opus_pending_trim_start;
+
+    AVDescriptor6A desc6a;
 } MpegTSWriteStream;
 
 static void mpegts_write_pat(AVFormatContext *s)
@@ -486,9 +489,22 @@ 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;
+
+                    if (ts_st->desc6a.component_type_flag) len ++;
+                    if (ts_st->desc6a.bsid_flag)           len ++;
+                    if (ts_st->desc6a.mainid_flag)         len ++;
+                    if (ts_st->desc6a.asvc_flag)           len ++;
+
                     *q++=0x6a; // AC3 descriptor see A038 DVB SI
-                    *q++=1; // 1 byte, all flags sets to 0
-                    *q++=0; // omit all fields...
+                    *q++ = len;
+                    *q++ = ts_st->desc6a.component_type_flag << 7 | ts_st->desc6a.bsid_flag << 6 |
+                           ts_st->desc6a.mainid_flag << 5         | ts_st->desc6a.asvc_flag << 4;
+
+                    if (ts_st->desc6a.component_type_flag) *q++ = ts_st->desc6a.component_type;
+                    if (ts_st->desc6a.bsid_flag)           *q++ = ts_st->desc6a.bsid;
+                    if (ts_st->desc6a.mainid_flag)         *q++ = ts_st->desc6a.mainid;
+                    if (ts_st->desc6a.asvc_flag)           *q++ = ts_st->desc6a.asvc;
                 } 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
@@ -1075,6 +1091,7 @@ static int mpegts_init(AVFormatContext *s)
         ts_st->first_pts_check = 1;
         ts_st->cc              = 15;
         ts_st->discontinuity   = ts->flags & MPEGTS_FLAG_DISCONT;
+        memset(&ts_st->desc6a, 0, sizeof(ts_st->desc6a));
         if (st->codecpar->codec_id == AV_CODEC_ID_AAC &&
             st->codecpar->extradata_size > 0) {
             AVStream *ast;
@@ -1843,6 +1860,13 @@ static int mpegts_write_packet_internal(AVFormatContext *s, AVPacket *pkt)
              * need to count the samples of that too! */
             av_log(s, AV_LOG_WARNING, "Got MPEG-TS formatted Opus data, unhandled");
         }
+    } else if (st->codecpar->codec_id == AV_CODEC_ID_AC3) {
+        AVDescriptor6A *side_data;
+        int sd_size;
+        side_data = (AVDescriptor6A *) av_packet_get_side_data(pkt,
+                    AV_PKT_DATA_MPEGTS_DESC_6A, &sd_size);
+        if (side_data && sd_size == sizeof(*side_data))
+            memcpy(&ts_st->desc6a, side_data, sizeof(*side_data));
     }
 
     if (ts_st->payload_size && (ts_st->payload_size + size > ts->pes_payload_size ||
-- 
1.8.3.1



More information about the ffmpeg-devel mailing list