diff mbox series

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

Message ID 1594769402-22526-2-git-send-email-lance.lmwang@gmail.com
State New
Headers show
Series [FFmpeg-devel,1/6] avcodec: add AV_CODEC_EXPORT_DATA_S12M_TC flag to export S12M timecode | 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 14, 2020, 11:29 p.m. UTC
From: Limin Wang <lance.lmwang@gmail.com>

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

Patch

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);