diff mbox series

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

Message ID 1595431659-664-2-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/mpegts.c | 42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

Comments

Marton Balint July 22, 2020, 5:45 p.m. UTC | #1
On Wed, 22 Jul 2020, lance.lmwang@gmail.com wrote:

> From: Limin Wang <lance.lmwang@gmail.com>
>
> Signed-off-by: Limin Wang <lance.lmwang@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);

Same comments as for patch 1/8, do not use metadata for this, either 
define a new side data type for the descriptor data or a side data type 
for arbitrary descriptors...

Regards,
Marton

> +
> +            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
>
> _______________________________________________
> 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/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;