summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/av_common.c35
-rw-r--r--common/av_common.h3
2 files changed, 38 insertions, 0 deletions
diff --git a/common/av_common.c b/common/av_common.c
index c91da79634..d3237250ef 100644
--- a/common/av_common.c
+++ b/common/av_common.c
@@ -352,3 +352,38 @@ int mp_set_avopts(struct mp_log *log, void *avobj, char **kv)
}
return success;
}
+
+AVFrameSideData *ffmpeg_garbage(AVFrame *frame,
+ enum AVFrameSideDataType type,
+ AVBufferRef *buf)
+{
+ AVFrameSideData *ret, **tmp;
+
+ if (!buf)
+ return NULL;
+
+ if (frame->nb_side_data > INT_MAX / sizeof(*frame->side_data) - 1)
+ goto fail;
+
+ tmp = av_realloc(frame->side_data,
+ (frame->nb_side_data + 1) * sizeof(*frame->side_data));
+ if (!tmp)
+ goto fail;
+ frame->side_data = tmp;
+
+ ret = av_mallocz(sizeof(*ret));
+ if (!ret)
+ goto fail;
+
+ ret->buf = buf;
+ ret->data = ret->buf->data;
+ ret->size = buf->size;
+ ret->type = type;
+
+ frame->side_data[frame->nb_side_data++] = ret;
+
+ return ret;
+fail:
+ av_buffer_unref(&buf);
+ return NULL;
+}
diff --git a/common/av_common.h b/common/av_common.h
index 1d30fab71f..6d0c823b8d 100644
--- a/common/av_common.h
+++ b/common/av_common.h
@@ -46,5 +46,8 @@ const char *mp_codec_from_av_codec_id(int codec_id);
void mp_set_avdict(struct AVDictionary **dict, char **kv);
void mp_avdict_print_unset(struct mp_log *log, int msgl, struct AVDictionary *d);
int mp_set_avopts(struct mp_log *log, void *avobj, char **kv);
+AVFrameSideData *ffmpeg_garbage(AVFrame *frame,
+ enum AVFrameSideDataType type,
+ AVBufferRef *buf);
#endif