diff mbox series

[FFmpeg-devel,5/5] avcodec: move ff_alloc_a53_sei() to atsc_53

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

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                    |  9 +++++---
 libavcodec/atsc_a53.c        | 43 ++++++++++++++++++++++++++++++++++++
 libavcodec/atsc_a53.h        | 17 ++++++++++++++
 libavcodec/internal.h        | 15 -------------
 libavcodec/libx264.c         |  1 +
 libavcodec/nvenc.c           |  1 +
 libavcodec/utils.c           | 43 ------------------------------------
 libavcodec/videotoolboxenc.c |  1 +
 8 files changed, 69 insertions(+), 61 deletions(-)
diff mbox series

Patch

diff --git a/configure b/configure
index 762e74a8ab..0815b0d6a0 100755
--- a/configure
+++ b/configure
@@ -3060,9 +3060,10 @@  h264_mediacodec_decoder_select="h264_mp4toannexb_bsf h264_parser"
 h264_mf_encoder_deps="mediafoundation"
 h264_mmal_decoder_deps="mmal"
 h264_nvenc_encoder_deps="nvenc"
+h264_nvenc_encoder_select="atsc_a53"
 h264_omx_encoder_deps="omx"
 h264_qsv_decoder_select="h264_mp4toannexb_bsf qsvdec"
-h264_qsv_encoder_select="qsvenc"
+h264_qsv_encoder_select="atsc_a53 qsvenc"
 h264_rkmpp_decoder_deps="rkmpp"
 h264_rkmpp_decoder_select="h264_mp4toannexb_bsf"
 h264_vaapi_encoder_select="cbs_h264 vaapi_encode"
@@ -3076,6 +3077,7 @@  hevc_mediacodec_decoder_deps="mediacodec"
 hevc_mediacodec_decoder_select="hevc_mp4toannexb_bsf hevc_parser"
 hevc_mf_encoder_deps="mediafoundation"
 hevc_nvenc_encoder_deps="nvenc"
+hevc_nvenc_encoder_select="atsc_a53"
 hevc_qsv_decoder_select="hevc_mp4toannexb_bsf qsvdec"
 hevc_qsv_encoder_select="hevcparse qsvenc"
 hevc_rkmpp_decoder_deps="rkmpp"
@@ -3200,9 +3202,9 @@  pcm_mulaw_at_encoder_deps="audiotoolbox"
 pcm_mulaw_at_encoder_select="audio_frame_queue"
 chromaprint_muxer_deps="chromaprint"
 h264_videotoolbox_encoder_deps="pthreads"
-h264_videotoolbox_encoder_select="videotoolbox_encoder"
+h264_videotoolbox_encoder_select="atsc_a53 videotoolbox_encoder"
 hevc_videotoolbox_encoder_deps="pthreads"
-hevc_videotoolbox_encoder_select="videotoolbox_encoder"
+hevc_videotoolbox_encoder_select="atsc_a53 videotoolbox_encoder"
 libaom_av1_decoder_deps="libaom"
 libaom_av1_encoder_deps="libaom"
 libaom_av1_encoder_select="extract_extradata_bsf"
@@ -3265,6 +3267,7 @@  libwebp_encoder_deps="libwebp"
 libwebp_anim_encoder_deps="libwebp"
 libx262_encoder_deps="libx262"
 libx264_encoder_deps="libx264"
+libx264_encoder_select="atsc_a53"
 libx264rgb_encoder_deps="libx264 x264_csp_bgr"
 libx264rgb_encoder_select="libx264_encoder"
 libx265_encoder_deps="libx265"
diff --git a/libavcodec/atsc_a53.c b/libavcodec/atsc_a53.c
index f040b0c10e..b0e4bbd4a3 100644
--- a/libavcodec/atsc_a53.c
+++ b/libavcodec/atsc_a53.c
@@ -22,6 +22,49 @@ 
 #include "atsc_a53.h"
 #include "get_bits.h"
 
+int ff_alloc_a53_sei(const AVFrame *frame, size_t prefix_len,
+                     void **data, size_t *sei_size)
+{
+    AVFrameSideData *side_data = NULL;
+    uint8_t *sei_data;
+
+    if (frame)
+        side_data = av_frame_get_side_data(frame, AV_FRAME_DATA_A53_CC);
+
+    if (!side_data) {
+        *data = NULL;
+        return 0;
+    }
+
+    *sei_size = side_data->size + 11;
+    *data = av_mallocz(*sei_size + prefix_len);
+    if (!*data)
+        return AVERROR(ENOMEM);
+    sei_data = (uint8_t*)*data + prefix_len;
+
+    // country code
+    sei_data[0] = 181;
+    sei_data[1] = 0;
+    sei_data[2] = 49;
+
+    /**
+     * 'GA94' is standard in North America for ATSC, but hard coding
+     * this style may not be the right thing to do -- other formats
+     * do exist. This information is not available in the side_data
+     * so we are going with this right now.
+     */
+    AV_WL32(sei_data + 3, MKTAG('G', 'A', '9', '4'));
+    sei_data[7] = 3;
+    sei_data[8] = ((side_data->size/3) & 0x1f) | 0x40;
+    sei_data[9] = 0;
+
+    memcpy(sei_data + 10, side_data->data, side_data->size);
+
+    sei_data[side_data->size+10] = 255;
+
+    return 0;
+}
+
 int ff_parse_a53_cc(AVBufferRef **pbuf, const uint8_t *data, int size)
 {
     AVBufferRef *buf = *pbuf;
diff --git a/libavcodec/atsc_a53.h b/libavcodec/atsc_a53.h
index a419d801b9..0622a55549 100644
--- a/libavcodec/atsc_a53.h
+++ b/libavcodec/atsc_a53.h
@@ -19,9 +19,26 @@ 
 #ifndef AVCODEC_ATSC_A53_H
 #define AVCODEC_ATSC_A53_H
 
+#include <stddef.h>
 #include <stdint.h>
 
 #include "libavutil/buffer.h"
+#include "libavutil/frame.h"
+
+/**
+ * Check AVFrame for A53 side data and allocate and fill SEI message with A53 info
+ *
+ * @param frame      Raw frame to get A53 side data from
+ * @param prefix_len Number of bytes to allocate before SEI message
+ * @param data       Pointer to a variable to store allocated memory
+ *                   Upon return the variable will hold NULL on error or if frame has no A53 info.
+ *                   Otherwise it will point to prefix_len uninitialized bytes followed by
+ *                   *sei_size SEI message
+ * @param sei_size   Pointer to a variable to store generated SEI message length
+ * @return           Zero on success, negative error code on failure
+ */
+int ff_alloc_a53_sei(const AVFrame *frame, size_t prefix_len,
+                     void **data, size_t *sei_size);
 
 /**
  * Parse a data array for ATSC A53 Part 4 Closed Captions and store them in an AVBufferRef.
diff --git a/libavcodec/internal.h b/libavcodec/internal.h
index 0a1c0a17ec..21486ae987 100644
--- a/libavcodec/internal.h
+++ b/libavcodec/internal.h
@@ -363,21 +363,6 @@  int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame);
  */
 AVCPBProperties *ff_add_cpb_side_data(AVCodecContext *avctx);
 
-/**
- * Check AVFrame for A53 side data and allocate and fill SEI message with A53 info
- *
- * @param frame      Raw frame to get A53 side data from
- * @param prefix_len Number of bytes to allocate before SEI message
- * @param data       Pointer to a variable to store allocated memory
- *                   Upon return the variable will hold NULL on error or if frame has no A53 info.
- *                   Otherwise it will point to prefix_len uninitialized bytes followed by
- *                   *sei_size SEI message
- * @param sei_size   Pointer to a variable to store generated SEI message length
- * @return           Zero on success, negative error code on failure
- */
-int ff_alloc_a53_sei(const AVFrame *frame, size_t prefix_len,
-                     void **data, size_t *sei_size);
-
 /**
  * Check AVFrame for S12M timecode side data and allocate and fill TC SEI message with timecode info
  *
diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
index 347d29df27..ca7cc3a540 100644
--- a/libavcodec/libx264.c
+++ b/libavcodec/libx264.c
@@ -30,6 +30,7 @@ 
 #include "avcodec.h"
 #include "internal.h"
 #include "packet_internal.h"
+#include "atsc_a53.h"
 
 #if defined(_MSC_VER)
 #define X264_API_IMPORTS 1
diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
index 8f5036b699..ee8ba3cb39 100644
--- a/libavcodec/nvenc.c
+++ b/libavcodec/nvenc.c
@@ -31,6 +31,7 @@ 
 #include "libavutil/avassert.h"
 #include "libavutil/mem.h"
 #include "libavutil/pixdesc.h"
+#include "atsc_a53.h"
 #include "encode.h"
 #include "internal.h"
 #include "packet_internal.h"
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 5a2a90b030..1814b417fc 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -2204,49 +2204,6 @@  int avcodec_parameters_to_context(AVCodecContext *codec,
     return 0;
 }
 
-int ff_alloc_a53_sei(const AVFrame *frame, size_t prefix_len,
-                     void **data, size_t *sei_size)
-{
-    AVFrameSideData *side_data = NULL;
-    uint8_t *sei_data;
-
-    if (frame)
-        side_data = av_frame_get_side_data(frame, AV_FRAME_DATA_A53_CC);
-
-    if (!side_data) {
-        *data = NULL;
-        return 0;
-    }
-
-    *sei_size = side_data->size + 11;
-    *data = av_mallocz(*sei_size + prefix_len);
-    if (!*data)
-        return AVERROR(ENOMEM);
-    sei_data = (uint8_t*)*data + prefix_len;
-
-    // country code
-    sei_data[0] = 181;
-    sei_data[1] = 0;
-    sei_data[2] = 49;
-
-    /**
-     * 'GA94' is standard in North America for ATSC, but hard coding
-     * this style may not be the right thing to do -- other formats
-     * do exist. This information is not available in the side_data
-     * so we are going with this right now.
-     */
-    AV_WL32(sei_data + 3, MKTAG('G', 'A', '9', '4'));
-    sei_data[7] = 3;
-    sei_data[8] = ((side_data->size/3) & 0x1f) | 0x40;
-    sei_data[9] = 0;
-
-    memcpy(sei_data + 10, side_data->data, side_data->size);
-
-    sei_data[side_data->size+10] = 255;
-
-    return 0;
-}
-
 static unsigned bcd2uint(uint8_t bcd)
 {
     unsigned low  = bcd & 0xf;
diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
index cc08cf6a50..e89cfaeed8 100644
--- a/libavcodec/videotoolboxenc.c
+++ b/libavcodec/videotoolboxenc.c
@@ -31,6 +31,7 @@ 
 #include "libavutil/pixdesc.h"
 #include "internal.h"
 #include <pthread.h>
+#include "atsc_a53.h"
 #include "h264.h"
 #include "h264_sei.h"
 #include <dlfcn.h>