History

Merge commit '31c51f7441de07b88cfea2550245bf1f5140cb8f'

* commit '31c51f7441de07b88cfea2550245bf1f5140cb8f': avpacket: add a function for wrapping existing data as side data

Hendrik Leppkes committed 10 years ago

Commit 30833d12 parents 10e55bd 31c51f74 files · +48 −11Browse files

Showing the changes to libavcodec (3 of 4 files). Show all

Unified · Split

3 files
  1. libavcodec/avcodec.h +16 −0
  2. libavcodec/avpacket.c +28 −10
  3. libavcodec/version.h +1 −1
libavcodec/avcodec.h+16−0
@@ -3996,6 +3996,22 @@ void av_free_packet(AVPacket *pkt); · 3995 unmodified lines
3996uint8_t* av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type,3996uint8_t* av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
3997 int size);3997 int size);
3998 3998
3999/**
4000 * Wrap an existing array as a packet side data.
4001 *
4002 * @param pkt packet
4003 * @param type side information type
4004 * @param data the side data array. It must be allocated with the av_malloc()
4005 * family of functions. The ownership of the data is transferred to
4006 * pkt.
4007 * @param size side information size
4008 * @return a non-negative number on success, a negative AVERROR code on
4009 * failure. On failure, the packet is unchanged and the data remains
4010 * owned by the caller.
4011 */
4012int av_packet_add_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
4013 uint8_t *data, size_t size);
4014
3999/**4015/**
4000 * Shrink the already allocated side data buffer4016 * Shrink the already allocated side data buffer
4001 *4017 *
libavcodec/avpacket.c+28−10
@@ -274,29 +274,47 @@ void av_free_packet(AVPacket *pkt) · 273 unmodified lines
274FF_ENABLE_DEPRECATION_WARNINGS274FF_ENABLE_DEPRECATION_WARNINGS
275#endif275#endif
276 276
277uint8_t *av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type,277int av_packet_add_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
278 int size)278 uint8_t *data, size_t size)
279{279{
280 int elems = pkt->side_data_elems;280 int elems = pkt->side_data_elems;
281 281
282 if ((unsigned)elems + 1 > INT_MAX / sizeof(*pkt->side_data))282 if ((unsigned)elems + 1 > INT_MAX / sizeof(*pkt->side_data))
283 return NULL;283 return AVERROR(EOVERFLOW);
284 if ((unsigned)size > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE)
285 return NULL;
286 284
287 pkt->side_data = av_realloc(pkt->side_data,285 pkt->side_data = av_realloc(pkt->side_data,
288 (elems + 1) * sizeof(*pkt->side_data));286 (elems + 1) * sizeof(*pkt->side_data));
289 if (!pkt->side_data)287 if (!pkt->side_data)
290 return NULL;288 return AVERROR(ENOMEM);
291 289
292 pkt->side_data[elems].data = av_mallocz(size + AV_INPUT_BUFFER_PADDING_SIZE);290 pkt->side_data[elems].data = data;
293 if (!pkt->side_data[elems].data)
294 return NULL;
295 pkt->side_data[elems].size = size;291 pkt->side_data[elems].size = size;
296 pkt->side_data[elems].type = type;292 pkt->side_data[elems].type = type;
297 pkt->side_data_elems++;293 pkt->side_data_elems++;
298 294
299 return pkt->side_data[elems].data;295 return 0;
296}
297
298
299uint8_t *av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
300 int size)
301{
302 int ret;
303 uint8_t *data;
304
305 if ((unsigned)size > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE)
306 return NULL;
307 data = av_mallocz(size + AV_INPUT_BUFFER_PADDING_SIZE);
308 if (!data)
309 return NULL;
310
311 ret = av_packet_add_side_data(pkt, type, data, size);
312 if (ret < 0) {
313 av_freep(&data);
314 return NULL;
315 }
316
317 return data;
300}318}
301 319
302uint8_t *av_packet_get_side_data(AVPacket *pkt, enum AVPacketSideDataType type,320uint8_t *av_packet_get_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
libavcodec/version.h+1−1
@@ -29,7 +29,7 @@ · 28 unmodified lines
29#include "libavutil/version.h"29#include "libavutil/version.h"
30 30
31#define LIBAVCODEC_VERSION_MAJOR 5731#define LIBAVCODEC_VERSION_MAJOR 57
32#define LIBAVCODEC_VERSION_MINOR 1732#define LIBAVCODEC_VERSION_MINOR 18
33#define LIBAVCODEC_VERSION_MICRO 10033#define LIBAVCODEC_VERSION_MICRO 100
34 34
35#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \35#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_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