History

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.

James Almer committed 9 years ago

Commit 79ff9931 parent 286ab874 files · +46 −11Browse files

Unified · Split

4 files
  1. doc/APIchanges +3 −0
  2. libavformat/avformat.h +15 −0
  3. libavformat/utils.c +27 −10
  4. libavformat/version.h +1 −1
doc/APIchanges+3−0
@@ -13,6 +13,9 @@ libavutil: 2015-08-28 · 12 unmodified lines
1313
1414 API changes, most recent first:
1515
16+2016-xx-xx - xxxxxxx - lavf 57.10.0 - avformat.h
17+ Add av_stream_add_side_data().
18+
1619 2016-xx-xx - xxxxxxx - lavu 55.28.0 - pixfmt.h
1720 Add AV_PIX_FMT_GRAY12(LE/BE).
1821
libavformat/avformat.h+15−0
@@ -1399,6 +1399,21 @@ const AVClass *avformat_get_class(void); · 1398 unmodified lines
13991399 */
14001400 AVStream *avformat_new_stream(AVFormatContext *s, const AVCodec *c);
14011401
1402+/**
1403+ * Wrap an existing array as stream side data.
1404+ *
1405+ * @param st stream
1406+ * @param type side information type
1407+ * @param data the side data array. It must be allocated with the av_malloc()
1408+ * family of functions. The ownership of the data is transferred to
1409+ * st.
1410+ * @param size side information size
1411+ * @return zero on success, a negative AVERROR code on failure. On failure,
1412+ * the stream is unchanged and the data remains owned by the caller.
1413+ */
1414+int av_stream_add_side_data(AVStream *st, enum AVPacketSideDataType type,
1415+ uint8_t *data, size_t size);
1416+
14021417 /**
14031418 * Allocate new information from stream.
14041419 *
libavformat/utils.c+27−10
@@ -3388,15 +3388,11 @@ uint8_t *av_stream_get_side_data(AVStream *st, enum AVPacketSideDataType type, · 3387 unmodified lines
33883388 return NULL;
33893389 }
33903390
3391−uint8_t *av_stream_new_side_data(AVStream *st, enum AVPacketSideDataType type,
3392− int size)
3391+int av_stream_add_side_data(AVStream *st, enum AVPacketSideDataType type,
3392+ uint8_t *data, size_t size)
33933393 {
33943394 AVPacketSideData *sd, *tmp;
33953395 int i;
3396− uint8_t *data = av_malloc(size);
3397−
3398− if (!data)
3399− return NULL;
34003396
34013397 for (i = 0; i < st->nb_side_data; i++) {
34023398 sd = &st->side_data[i];
@@ -3405,14 +3401,16 @@ uint8_t *av_stream_new_side_data(AVStream *st, enum AVPacketSideDataType type, · 2 unmodified lines
34053401 av_freep(&sd->data);
34063402 sd->data = data;
34073403 sd->size = size;
3408− return sd->data;
3404+ return 0;
34093405 }
34103406 }
34113407
3412− tmp = av_realloc_array(st->side_data, st->nb_side_data + 1, sizeof(*tmp));
3408+ if ((unsigned) st->nb_side_data + 1 >= INT_MAX / sizeof(*st->side_data))
3409+ return AVERROR(ERANGE);
3410+
3411+ tmp = av_realloc(st->side_data, (st->nb_side_data + 1) * sizeof(*tmp));
34133412 if (!tmp) {
3414− av_freep(&data);
3415− return NULL;
3413+ return AVERROR(ENOMEM);
34163414 }
34173415
34183416 st->side_data = tmp;
@@ -3422,6 +3420,25 @@ uint8_t *av_stream_new_side_data(AVStream *st, enum AVPacketSideDataType type, · 3 unmodified lines
34223420 sd->type = type;
34233421 sd->data = data;
34243422 sd->size = size;
3423+
3424+ return 0;
3425+}
3426+
3427+uint8_t *av_stream_new_side_data(AVStream *st, enum AVPacketSideDataType type,
3428+ int size)
3429+{
3430+ int ret;
3431+ uint8_t *data = av_malloc(size);
3432+
3433+ if (!data)
3434+ return NULL;
3435+
3436+ ret = av_stream_add_side_data(st, type, data, size);
3437+ if (ret < 0) {
3438+ av_freep(&data);
3439+ return NULL;
3440+ }
3441+
34253442 return data;
34263443 }
34273444
libavformat/version.h+1−1
@@ -30,7 +30,7 @@ · 29 unmodified lines
3030 #include "libavutil/version.h"
3131
3232 #define LIBAVFORMAT_VERSION_MAJOR 57
33−#define LIBAVFORMAT_VERSION_MINOR 9
33+#define LIBAVFORMAT_VERSION_MINOR 10
3434 #define LIBAVFORMAT_VERSION_MICRO 0
3535
3636 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t