diff options
author | Hendrik Leppkes <h.leppkes@gmail.com> | 2015-12-17 13:12:07 +0100 |
---|---|---|
committer | Hendrik Leppkes <h.leppkes@gmail.com> | 2015-12-17 13:12:07 +0100 |
commit | 30833d121e24fc644c9c4e6ca07df3e9e4963180 (patch) | |
tree | db5e1913911cfaa1366f9bcf9efd2371b06f492e | |
parent | 10e55bd658b06034d700553190b419b1af92b7cb (diff) | |
parent | 31c51f7441de07b88cfea2550245bf1f5140cb8f (diff) | |
download | ffmpeg-30833d121e24fc644c9c4e6ca07df3e9e4963180.tar.gz |
Merge commit '31c51f7441de07b88cfea2550245bf1f5140cb8f'
* commit '31c51f7441de07b88cfea2550245bf1f5140cb8f':
avpacket: add a function for wrapping existing data as side data
Merged-by: Hendrik Leppkes <h.leppkes@gmail.com>
-rw-r--r-- | doc/APIchanges | 3 | ||||
-rw-r--r-- | libavcodec/avcodec.h | 16 | ||||
-rw-r--r-- | libavcodec/avpacket.c | 38 | ||||
-rw-r--r-- | libavcodec/version.h | 2 |
4 files changed, 48 insertions, 11 deletions
diff --git a/doc/APIchanges b/doc/APIchanges index 1d0a3d295a..265d6d5489 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -14,6 +14,9 @@ libavutil: 2015-08-28 API changes, most recent first: +2015-12-17 - xxxxxxx - lavc 57.18.100 / 57.11.0 - avcodec.h + Add av_packet_add_side_data(). + 2015-12-11 - xxxxxxx - lavf 57.20.100 - avformat.h Add av_program_add_stream_index() diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 5e36c94ee3..a60d28c5ab 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -3997,6 +3997,22 @@ uint8_t* av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, int size); /** + * Wrap an existing array as a packet side data. + * + * @param pkt packet + * @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 + * pkt. + * @param size side information size + * @return a non-negative number on success, a negative AVERROR code on + * failure. On failure, the packet is unchanged and the data remains + * owned by the caller. + */ +int av_packet_add_side_data(AVPacket *pkt, enum AVPacketSideDataType type, + uint8_t *data, size_t size); + +/** * Shrink the already allocated side data buffer * * @param pkt packet diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c index 1cc10eba05..cb1d44d4fb 100644 --- a/libavcodec/avpacket.c +++ b/libavcodec/avpacket.c @@ -274,29 +274,47 @@ void av_free_packet(AVPacket *pkt) FF_ENABLE_DEPRECATION_WARNINGS #endif -uint8_t *av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, - int size) +int av_packet_add_side_data(AVPacket *pkt, enum AVPacketSideDataType type, + uint8_t *data, size_t size) { int elems = pkt->side_data_elems; if ((unsigned)elems + 1 > INT_MAX / sizeof(*pkt->side_data)) - return NULL; - if ((unsigned)size > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE) - return NULL; + return AVERROR(EOVERFLOW); pkt->side_data = av_realloc(pkt->side_data, (elems + 1) * sizeof(*pkt->side_data)); if (!pkt->side_data) - return NULL; + return AVERROR(ENOMEM); - pkt->side_data[elems].data = av_mallocz(size + AV_INPUT_BUFFER_PADDING_SIZE); - if (!pkt->side_data[elems].data) - return NULL; + pkt->side_data[elems].data = data; pkt->side_data[elems].size = size; pkt->side_data[elems].type = type; pkt->side_data_elems++; - return pkt->side_data[elems].data; + return 0; +} + + +uint8_t *av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, + int size) +{ + int ret; + uint8_t *data; + + if ((unsigned)size > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE) + return NULL; + data = av_mallocz(size + AV_INPUT_BUFFER_PADDING_SIZE); + if (!data) + return NULL; + + ret = av_packet_add_side_data(pkt, type, data, size); + if (ret < 0) { + av_freep(&data); + return NULL; + } + + return data; } uint8_t *av_packet_get_side_data(AVPacket *pkt, enum AVPacketSideDataType type, diff --git a/libavcodec/version.h b/libavcodec/version.h index 3027853263..6f88ee47bc 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -29,7 +29,7 @@ #include "libavutil/version.h" #define LIBAVCODEC_VERSION_MAJOR 57 -#define LIBAVCODEC_VERSION_MINOR 17 +#define LIBAVCODEC_VERSION_MINOR 18 #define LIBAVCODEC_VERSION_MICRO 100 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ |