diff mbox series

[FFmpeg-devel,v2,3/5] avformat/mpegtsenc: Add muxing support for arib_superimpose

Message ID 20210613023421.23039-3-xqq@xqq.im
State New
Headers show
Series [FFmpeg-devel,v2,1/5] avcodec/codec: Add arib_superimpose subtitle codec
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

zheng qian June 13, 2021, 2:34 a.m. UTC
Signed-off-by: zheng qian <xqq@xqq.im>
---
 libavformat/mpegtsenc.c | 30 +++++++++++++++++++++++-------
 1 file changed, 23 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index 98dac17994..68f69d5df8 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -287,7 +287,7 @@  static void putbuf(uint8_t **q_ptr, const uint8_t *buf, size_t len)
     *q_ptr += len;
 }
 
-static int put_arib_caption_descriptor(AVFormatContext *s, uint8_t **q_ptr,
+static int put_arib_descriptor(AVFormatContext *s, uint8_t **q_ptr,
                                        AVCodecParameters *codecpar)
 {
     uint8_t stream_identifier;
@@ -296,11 +296,19 @@  static int put_arib_caption_descriptor(AVFormatContext *s, uint8_t **q_ptr,
 
     switch (codecpar->profile) {
     case FF_PROFILE_ARIB_PROFILE_A:
-        stream_identifier = 0x30;
+        if (codecpar->codec_id == AV_CODEC_ID_ARIB_CAPTION) {
+            stream_identifier = 0x30;
+        } else {  // AV_CODEC_ID_ARIB_SUPERIMPOSE
+            stream_identifier = 0x38;
+        }
         data_component_id = 0x0008;
         break;
     case FF_PROFILE_ARIB_PROFILE_C:
-        stream_identifier = 0x87;
+        if (codecpar->codec_id == AV_CODEC_ID_ARIB_CAPTION) {
+            stream_identifier = 0x87;
+        } else {  // AV_CODEC_ID_ARIB_SUPERIMPOSE
+            stream_identifier = 0x88;
+        }
         data_component_id = 0x0012;
         break;
     default:
@@ -320,11 +328,15 @@  static int put_arib_caption_descriptor(AVFormatContext *s, uint8_t **q_ptr,
     *q++ = 3;     // descriptor_length
     put16(&q, data_component_id);  // data_component_id
     // additional_arib_caption_info: defined in ARIB STD-B24, fascicle 1, Part 3, 9.6.1
-    // Here we utilize a pre-defined set of values defined in ARIB TR-B14,
+    // Here we utilize pre-defined sets of values defined in ARIB TR-B14,
     // Fascicle 2, 4.2.8.5 for PMT usage, with the reserved bits in the middle
     // set to 1 (as that is what every broadcaster seems to be doing in
     // production).
-    *q++ = 0x3D; // DMF('0011'), Reserved('11'), Timing('01')
+    if (codecpar->codec_id == AV_CODEC_ID_ARIB_CAPTION) {
+        *q++ = 0x3D; // DMF('0011'), Reserved('11'), Timing('01')
+    } else {  // AV_CODEC_ID_ARIB_SUPERIMPOSE
+        *q++ = 0x3C; // DMF('0011'), Reserved('11'), Timing('00')
+    }
 
     *q_ptr = q;
 
@@ -414,6 +426,7 @@  static int get_dvb_stream_type(AVFormatContext *s, AVStream *st)
     case AV_CODEC_ID_DVB_SUBTITLE:
     case AV_CODEC_ID_DVB_TELETEXT:
     case AV_CODEC_ID_ARIB_CAPTION:
+    case AV_CODEC_ID_ARIB_SUPERIMPOSE:
         stream_type = STREAM_TYPE_PRIVATE_DATA;
         break;
     case AV_CODEC_ID_SMPTE_KLV:
@@ -771,8 +784,8 @@  static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service)
                }
 
                *len_ptr = q - len_ptr - 1;
-            } else if (codec_id == AV_CODEC_ID_ARIB_CAPTION) {
-                if (put_arib_caption_descriptor(s, &q, st->codecpar) < 0)
+            } else if (codec_id == AV_CODEC_ID_ARIB_CAPTION || codec_id == AV_CODEC_ID_ARIB_SUPERIMPOSE) {
+                if (put_arib_descriptor(s, &q, st->codecpar) < 0)
                     break;
             }
         break;
@@ -1444,6 +1457,9 @@  static int get_pes_stream_id(AVFormatContext *s, AVStream *st, int stream_id, in
         if (stream_id == STREAM_ID_PRIVATE_STREAM_1) /* asynchronous KLV */
             *async = 1;
         return stream_id != -1 ? stream_id : STREAM_ID_METADATA_STREAM;
+    } else if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE &&
+               st->codecpar->codec_id == AV_CODEC_ID_ARIB_SUPERIMPOSE) {
+        return STREAM_ID_PRIVATE_STREAM_2;
     } else {
         return STREAM_ID_PRIVATE_STREAM_1;
     }