summaryrefslogtreecommitdiff
path: root/libavformat/utils.c
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2014-11-14 12:45:08 +0100
committerAnton Khirnov <anton@khirnov.net>2015-01-27 09:18:32 +0100
commit4227e4fe7443733fb906f6fb6c265105e8269c74 (patch)
treee8d550c90fbcd6c574a0c68c91aac6fd7918c2d5 /libavformat/utils.c
parent728685f37ab333ca35980bd01766c78d197f784a (diff)
lavf: add a convenience function for adding side data to a stream
Diffstat (limited to 'libavformat/utils.c')
-rw-r--r--libavformat/utils.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/libavformat/utils.c b/libavformat/utils.c
index ce715f725c..13b6de21e1 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -3113,3 +3113,40 @@ uint8_t *av_stream_get_side_data(AVStream *st, enum AVPacketSideDataType type,
}
return NULL;
}
+
+uint8_t *ff_stream_new_side_data(AVStream *st, enum AVPacketSideDataType type,
+ int size)
+{
+ AVPacketSideData *sd, *tmp;
+ int i;
+ uint8_t *data = av_malloc(size);
+
+ if (!data)
+ return NULL;
+
+ for (i = 0; i < st->nb_side_data; i++) {
+ sd = &st->side_data[i];
+
+ if (sd->type == type) {
+ av_freep(&sd->data);
+ sd->data = data;
+ sd->size = size;
+ return sd->data;
+ }
+ }
+
+ tmp = av_realloc_array(st->side_data, st->nb_side_data + 1, sizeof(*tmp));
+ if (!tmp) {
+ av_freep(&data);
+ return NULL;
+ }
+
+ st->side_data = tmp;
+ st->nb_side_data++;
+
+ sd = &st->side_data[st->nb_side_data - 1];
+ sd->type = type;
+ sd->data = data;
+ sd->size = size;
+ return data;
+}