diff options
author | James Almer <jamrial@gmail.com> | 2016-11-17 02:02:41 -0300 |
---|---|---|
committer | James Almer <jamrial@gmail.com> | 2016-11-18 22:17:13 -0300 |
commit | 2ab50647ff653ab45d9d78203b6a671124609991 (patch) | |
tree | 781850fb7ca50af41350fdca52b4d9a40f8baf4f /libavformat/utils.c | |
parent | 4696f7639b22c9205792d2e3d5e8e07b3cadbb63 (diff) | |
download | ffmpeg-2ab50647ff653ab45d9d78203b6a671124609991.tar.gz |
avformat/utils: add av_stream_add_side_data()
Functionally similar to av_packet_add_side_data(). Allows the use of an
already allocated buffer as stream side data.
Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: James Almer <jamrial@gmail.com>
Diffstat (limited to 'libavformat/utils.c')
-rw-r--r-- | libavformat/utils.c | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/libavformat/utils.c b/libavformat/utils.c index 56646464b6..19bb8bd420 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -5104,15 +5104,11 @@ uint8_t *av_stream_get_side_data(const AVStream *st, return NULL; } -uint8_t *av_stream_new_side_data(AVStream *st, enum AVPacketSideDataType type, - int size) +int av_stream_add_side_data(AVStream *st, enum AVPacketSideDataType type, + uint8_t *data, size_t 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]; @@ -5121,14 +5117,13 @@ uint8_t *av_stream_new_side_data(AVStream *st, enum AVPacketSideDataType type, av_freep(&sd->data); sd->data = data; sd->size = size; - return sd->data; + return 0; } } tmp = av_realloc_array(st->side_data, st->nb_side_data + 1, sizeof(*tmp)); if (!tmp) { - av_freep(&data); - return NULL; + return AVERROR(ENOMEM); } st->side_data = tmp; @@ -5138,6 +5133,25 @@ uint8_t *av_stream_new_side_data(AVStream *st, enum AVPacketSideDataType type, sd->type = type; sd->data = data; sd->size = size; + + return 0; +} + +uint8_t *av_stream_new_side_data(AVStream *st, enum AVPacketSideDataType type, + int size) +{ + int ret; + uint8_t *data = av_malloc(size); + + if (!data) + return NULL; + + ret = av_stream_add_side_data(st, type, data, size); + if (ret < 0) { + av_freep(&data); + return NULL; + } + return data; } |