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
13 13
14API changes, most recent first:14API changes, most recent first:
15 15
162016-xx-xx - xxxxxxx - lavf 57.10.0 - avformat.h
17 Add av_stream_add_side_data().
18
162016-xx-xx - xxxxxxx - lavu 55.28.0 - pixfmt.h192016-xx-xx - xxxxxxx - lavu 55.28.0 - pixfmt.h
17 Add AV_PIX_FMT_GRAY12(LE/BE).20 Add AV_PIX_FMT_GRAY12(LE/BE).
18 21
libavformat/avformat.h+15−0
@@ -1399,6 +1399,21 @@ const AVClass *avformat_get_class(void); · 1398 unmodified lines
1399 */1399 */
1400AVStream *avformat_new_stream(AVFormatContext *s, const AVCodec *c);1400AVStream *avformat_new_stream(AVFormatContext *s, const AVCodec *c);
1401 1401
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 */
1414int av_stream_add_side_data(AVStream *st, enum AVPacketSideDataType type,
1415 uint8_t *data, size_t size);
1416
1402/**1417/**
1403 * Allocate new information from stream.1418 * Allocate new information from stream.
1404 *1419 *
libavformat/utils.c+27−10
@@ -3388,15 +3388,11 @@ uint8_t *av_stream_get_side_data(AVStream *st, enum AVPacketSideDataType type, · 3387 unmodified lines
3388 return NULL;3388 return NULL;
3389}3389}
3390 3390
3391uint8_t *av_stream_new_side_data(AVStream *st, enum AVPacketSideDataType type,3391int av_stream_add_side_data(AVStream *st, enum AVPacketSideDataType type,
3392 int size)3392 uint8_t *data, size_t size)
3393{3393{
3394 AVPacketSideData *sd, *tmp;3394 AVPacketSideData *sd, *tmp;
3395 int i;3395 int i;
3396 uint8_t *data = av_malloc(size);
3397
3398 if (!data)
3399 return NULL;
3400 3396
3401 for (i = 0; i < st->nb_side_data; i++) {3397 for (i = 0; i < st->nb_side_data; i++) {
3402 sd = &st->side_data[i];3398 sd = &st->side_data[i];
@@ -3405,14 +3401,16 @@ uint8_t *av_stream_new_side_data(AVStream *st, enum AVPacketSideDataType type, · 2 unmodified lines
3405 av_freep(&sd->data);3401 av_freep(&sd->data);
3406 sd->data = data;3402 sd->data = data;
3407 sd->size = size;3403 sd->size = size;
3408 return sd->data;3404 return 0;
3409 }3405 }
3410 }3406 }
3411 3407
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));
3413 if (!tmp) {3412 if (!tmp) {
3414 av_freep(&data);3413 return AVERROR(ENOMEM);
3415 return NULL;
3416 }3414 }
3417 3415
3418 st->side_data = tmp;3416 st->side_data = tmp;
@@ -3422,6 +3420,25 @@ uint8_t *av_stream_new_side_data(AVStream *st, enum AVPacketSideDataType type, · 3 unmodified lines
3422 sd->type = type;3420 sd->type = type;
3423 sd->data = data;3421 sd->data = data;
3424 sd->size = size;3422 sd->size = size;
3423
3424 return 0;
3425}
3426
3427uint8_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
3425 return data;3442 return data;
3426}3443}
3427 3444
libavformat/version.h+1−1
@@ -30,7 +30,7 @@ · 29 unmodified lines
30#include "libavutil/version.h"30#include "libavutil/version.h"
31 31
32#define LIBAVFORMAT_VERSION_MAJOR 5732#define LIBAVFORMAT_VERSION_MAJOR 57
33#define LIBAVFORMAT_VERSION_MINOR 933#define LIBAVFORMAT_VERSION_MINOR 10
34#define LIBAVFORMAT_VERSION_MICRO 034#define LIBAVFORMAT_VERSION_MICRO 0
35 35
36#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \36#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