diff mbox series

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

Message ID 1596121138-20997-5-git-send-email-lance.lmwang@gmail.com
State New
Headers show
Series [FFmpeg-devel,v2,1/5] avutil/mpegts_audio_desc_metadata: add helper function for AC3 descriptor 0x6a | expand

Checks

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

Commit Message

Lance Wang July 30, 2020, 2:58 p.m. UTC
From: Limin Wang <lance.lmwang@gmail.com>

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

Comments

Moritz Barsnick Aug. 7, 2020, 6:43 a.m. UTC | #1
On Thu, Jul 30, 2020 at 22:58:58 +0800, lance.lmwang@gmail.com wrote:
>                  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++;

This could be coded as
    int len = 1
              + !!(ts_st->desc6a.component_type_flag)
              + !!(ts_st->desc6a.bsid_flag)
              + ...

but I don't know what is preferred (and technically, it results in the
same amount of machine commands). It probably doesn't matter.

> +        side_data = (AVDescriptor6A *) av_packet_get_side_data(pkt,
> +                    AV_PKT_DATA_MPEGTS_DESC_6A, &sd_size);

Indentation is incorrect.

Cheers,
Moritz
Lance Wang Aug. 7, 2020, 3:08 p.m. UTC | #2
On Fri, Aug 07, 2020 at 08:43:05AM +0200, Moritz Barsnick wrote:
> On Thu, Jul 30, 2020 at 22:58:58 +0800, lance.lmwang@gmail.com wrote:
> >                  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++;
> 
> This could be coded as
>     int len = 1
>               + !!(ts_st->desc6a.component_type_flag)
>               + !!(ts_st->desc6a.bsid_flag)
>               + ...

I prefer to your style, it's more simple.

> 
> but I don't know what is preferred (and technically, it results in the
> same amount of machine commands). It probably doesn't matter.
> 
> > +        side_data = (AVDescriptor6A *) av_packet_get_side_data(pkt,
> > +                    AV_PKT_DATA_MPEGTS_DESC_6A, &sd_size);
> 
> Indentation is incorrect.

I haven't make the second line to ident with pkt, for the line will too long
and more difficult to read.

For Kieran prefer to recalculate the descriptor by parse the header so I'll
not update the patchset anyore.

> 
> Cheers,
> Moritz
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
diff mbox series

Patch

diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index 718ddab..f4f4e3d 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 ||