Commit 2ab50647 authored by James Almer's avatar James Almer

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: 's avatarMichael Niedermayer <michael@niedermayer.cc>
Signed-off-by: 's avatarJames Almer <jamrial@gmail.com>
parent 4696f763
...@@ -15,6 +15,9 @@ libavutil: 2015-08-28 ...@@ -15,6 +15,9 @@ libavutil: 2015-08-28
API changes, most recent first: API changes, most recent first:
2016-11-18 - xxxxxxx - lavf 57.58.100 - avformat.h
Add av_stream_add_side_data().
2016-xx-xx - xxxxxxx - lavu 55.39.100 - hwcontext_vaapi.h 2016-xx-xx - xxxxxxx - lavu 55.39.100 - hwcontext_vaapi.h
Add AV_VAAPI_DRIVER_QUIRK_ATTRIB_MEMTYPE. Add AV_VAAPI_DRIVER_QUIRK_ATTRIB_MEMTYPE.
......
...@@ -2048,6 +2048,21 @@ const AVClass *avformat_get_class(void); ...@@ -2048,6 +2048,21 @@ const AVClass *avformat_get_class(void);
*/ */
AVStream *avformat_new_stream(AVFormatContext *s, const AVCodec *c); AVStream *avformat_new_stream(AVFormatContext *s, const AVCodec *c);
/**
* Wrap an existing array as stream side data.
*
* @param st stream
* @param type side information type
* @param data the side data array. It must be allocated with the av_malloc()
* family of functions. The ownership of the data is transferred to
* st.
* @param size side information size
* @return zero on success, a negative AVERROR code on failure. On failure,
* the stream is unchanged and the data remains owned by the caller.
*/
int av_stream_add_side_data(AVStream *st, enum AVPacketSideDataType type,
uint8_t *data, size_t size);
/** /**
* Allocate new information from stream. * Allocate new information from stream.
* *
......
...@@ -5104,15 +5104,11 @@ uint8_t *av_stream_get_side_data(const AVStream *st, ...@@ -5104,15 +5104,11 @@ uint8_t *av_stream_get_side_data(const AVStream *st,
return NULL; return NULL;
} }
uint8_t *av_stream_new_side_data(AVStream *st, enum AVPacketSideDataType type, int av_stream_add_side_data(AVStream *st, enum AVPacketSideDataType type,
int size) uint8_t *data, size_t size)
{ {
AVPacketSideData *sd, *tmp; AVPacketSideData *sd, *tmp;
int i; int i;
uint8_t *data = av_malloc(size);
if (!data)
return NULL;
for (i = 0; i < st->nb_side_data; i++) { for (i = 0; i < st->nb_side_data; i++) {
sd = &st->side_data[i]; sd = &st->side_data[i];
...@@ -5121,14 +5117,13 @@ uint8_t *av_stream_new_side_data(AVStream *st, enum AVPacketSideDataType type, ...@@ -5121,14 +5117,13 @@ uint8_t *av_stream_new_side_data(AVStream *st, enum AVPacketSideDataType type,
av_freep(&sd->data); av_freep(&sd->data);
sd->data = data; sd->data = data;
sd->size = size; sd->size = size;
return sd->data; return 0;
} }
} }
tmp = av_realloc_array(st->side_data, st->nb_side_data + 1, sizeof(*tmp)); tmp = av_realloc_array(st->side_data, st->nb_side_data + 1, sizeof(*tmp));
if (!tmp) { if (!tmp) {
av_freep(&data); return AVERROR(ENOMEM);
return NULL;
} }
st->side_data = tmp; st->side_data = tmp;
...@@ -5138,6 +5133,25 @@ uint8_t *av_stream_new_side_data(AVStream *st, enum AVPacketSideDataType type, ...@@ -5138,6 +5133,25 @@ uint8_t *av_stream_new_side_data(AVStream *st, enum AVPacketSideDataType type,
sd->type = type; sd->type = type;
sd->data = data; sd->data = data;
sd->size = size; 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; return data;
} }
......
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
// Major bumping may affect Ticket5467, 5421, 5451(compatibility with Chromium) // Major bumping may affect Ticket5467, 5421, 5451(compatibility with Chromium)
// Also please add any ticket numbers that you believe might be affected here // Also please add any ticket numbers that you believe might be affected here
#define LIBAVFORMAT_VERSION_MAJOR 57 #define LIBAVFORMAT_VERSION_MAJOR 57
#define LIBAVFORMAT_VERSION_MINOR 57 #define LIBAVFORMAT_VERSION_MINOR 58
#define LIBAVFORMAT_VERSION_MICRO 100 #define LIBAVFORMAT_VERSION_MICRO 100
#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment