diff mbox series

[FFmpeg-devel,2/5] avcodec/libdav1d: add support for A53 Closed Captions

Message ID 20200810154941.4988-2-jamrial@gmail.com
State Accepted
Commit 6c1bf7c02e8ec5f3c0a432774373ba0e8448e499
Headers show
Series [FFmpeg-devel,1/5] avcodec: split off A53 Closed Caption parsing code into its own file
Related show

Checks

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

Commit Message

James Almer Aug. 10, 2020, 3:49 p.m. UTC
Signed-off-by: James Almer <jamrial@gmail.com>
---
 configure             |  3 ++-
 libavcodec/libdav1d.c | 30 ++++++++++++++++++++++++++++++
 2 files changed, 32 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/configure b/configure
index 37fe01e8be..83f051fdee 100755
--- a/configure
+++ b/configure
@@ -3211,6 +3211,7 @@  libcelt_decoder_deps="libcelt"
 libcodec2_decoder_deps="libcodec2"
 libcodec2_encoder_deps="libcodec2"
 libdav1d_decoder_deps="libdav1d"
+libdav1d_decoder_select="atsc_a53"
 libdavs2_decoder_deps="libdavs2"
 libfdk_aac_decoder_deps="libfdk_aac"
 libfdk_aac_encoder_deps="libfdk_aac"
@@ -6328,7 +6329,7 @@  enabled libcelt           && require libcelt celt/celt.h celt_decode -lcelt0 &&
                                die "ERROR: libcelt must be installed and version must be >= 0.11.0."; }
 enabled libcaca           && require_pkg_config libcaca caca caca.h caca_create_canvas
 enabled libcodec2         && require libcodec2 codec2/codec2.h codec2_create -lcodec2
-enabled libdav1d          && require_pkg_config libdav1d "dav1d >= 0.4.0" "dav1d/dav1d.h" dav1d_version
+enabled libdav1d          && require_pkg_config libdav1d "dav1d >= 0.5.0" "dav1d/dav1d.h" dav1d_version
 enabled libdavs2          && require_pkg_config libdavs2 "davs2 >= 1.6.0" davs2.h davs2_decoder_open
 enabled libdc1394         && require_pkg_config libdc1394 libdc1394-2 dc1394/dc1394.h dc1394_new
 enabled libdrm            && require_pkg_config libdrm libdrm xf86drm.h drmGetVersion
diff --git a/libavcodec/libdav1d.c b/libavcodec/libdav1d.c
index 132d344296..fd801c6fd5 100644
--- a/libavcodec/libdav1d.c
+++ b/libavcodec/libdav1d.c
@@ -26,7 +26,9 @@ 
 #include "libavutil/imgutils.h"
 #include "libavutil/opt.h"
 
+#include "atsc_a53.h"
 #include "avcodec.h"
+#include "bytestream.h"
 #include "decode.h"
 #include "internal.h"
 
@@ -364,6 +366,34 @@  FF_ENABLE_DEPRECATION_WARNINGS
         light->MaxCLL = p->content_light->max_content_light_level;
         light->MaxFALL = p->content_light->max_frame_average_light_level;
     }
+    if (p->itut_t35) {
+        GetByteContext gb;
+        unsigned int user_identifier;
+
+        bytestream2_init(&gb, p->itut_t35->payload, p->itut_t35->payload_size);
+        bytestream2_skip(&gb, 1); // terminal provider code
+        bytestream2_skip(&gb, 1); // terminal provider oriented code
+        user_identifier = bytestream2_get_be32(&gb);
+        switch (user_identifier) {
+        case MKBETAG('G', 'A', '9', '4'): { // closed captions
+            AVBufferRef *buf = NULL;
+
+            res = ff_parse_a53_cc(&buf, gb.buffer, bytestream2_get_bytes_left(&gb));
+            if (res < 0)
+                goto fail;
+            if (!res)
+                break;
+
+            if (!av_frame_new_side_data_from_buf(frame, AV_FRAME_DATA_A53_CC, buf))
+                av_buffer_unref(&buf);
+
+            c->properties |= FF_CODEC_PROPERTY_CLOSED_CAPTIONS;
+            break;
+        }
+        default: // ignore unsupported identifiers
+            break;
+        }
+    }
 
     res = 0;
 fail: