[FFmpeg-devel] [PATCH 2/6] avcodec/utils: add ff_add_s12m_timecode_side_data()

lance.lmwang at gmail.com lance.lmwang at gmail.com
Wed Jul 15 02:29:58 EEST 2020


From: Limin Wang <lance.lmwang at gmail.com>

Signed-off-by: Limin Wang <lance.lmwang at gmail.com>
---
 libavcodec/internal.h |  5 +++++
 libavcodec/utils.c    | 30 ++++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+)

diff --git a/libavcodec/internal.h b/libavcodec/internal.h
index 0a1c0a1..e0040fc 100644
--- a/libavcodec/internal.h
+++ b/libavcodec/internal.h
@@ -364,6 +364,11 @@ int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame);
 AVCPBProperties *ff_add_cpb_side_data(AVCodecContext *avctx);
 
 /**
+ * Add a S12M timecode side data to an codec context.
+ */
+uint32_t *ff_add_s12m_timecode_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
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 2ece34f..270c0c4 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -2029,6 +2029,36 @@ AVCPBProperties *ff_add_cpb_side_data(AVCodecContext *avctx)
     return props;
 }
 
+uint32_t *ff_add_s12m_timecode_side_data(AVCodecContext *avctx)
+{
+    AVPacketSideData *tmp;
+    uint32_t *data;
+    int size = sizeof(uint32_t) * 4;
+    int i;
+
+    for (i = 0; i < avctx->nb_coded_side_data; i++)
+        if (avctx->coded_side_data[i].type == AV_PKT_DATA_S12M_TIMECODE)
+            return (uint32_t*)avctx->coded_side_data[i].data;
+
+    data = av_mallocz(size);
+    if (!data)
+        return NULL;
+
+    tmp = av_realloc_array(avctx->coded_side_data, avctx->nb_coded_side_data + 1, sizeof(*tmp));
+    if (!tmp) {
+        av_freep(&data);
+        return NULL;
+    }
+    avctx->coded_side_data = tmp;
+
+    avctx->coded_side_data[avctx->nb_coded_side_data].type = AV_PKT_DATA_S12M_TIMECODE;
+    avctx->coded_side_data[avctx->nb_coded_side_data].data = (uint8_t *)data;
+    avctx->coded_side_data[avctx->nb_coded_side_data].size = size;
+    avctx->nb_coded_side_data++;
+
+    return data;
+}
+
 static void codec_parameters_reset(AVCodecParameters *par)
 {
     av_freep(&par->extradata);
-- 
1.8.3.1



More information about the ffmpeg-devel mailing list