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
39963996 uint8_t* av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
39973997 int size);
39983998
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+ */
4012+int av_packet_add_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
4013+ uint8_t *data, size_t size);
4014+
39994015 /**
40004016 * Shrink the already allocated side data buffer
40014017 *
libavcodec/avpacket.c+28−10
@@ -274,29 +274,47 @@ void av_free_packet(AVPacket *pkt) · 273 unmodified lines
274274 FF_ENABLE_DEPRECATION_WARNINGS
275275 #endif
276276
277−uint8_t *av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
278− int size)
277+int av_packet_add_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
278+ uint8_t *data, size_t size)
279279 {
280280 int elems = pkt->side_data_elems;
281281
282282 if ((unsigned)elems + 1 > INT_MAX / sizeof(*pkt->side_data))
283− return NULL;
284− if ((unsigned)size > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE)
285− return NULL;
283+ return AVERROR(EOVERFLOW);
286284
287285 pkt->side_data = av_realloc(pkt->side_data,
288286 (elems + 1) * sizeof(*pkt->side_data));
289287 if (!pkt->side_data)
290− return NULL;
288+ return AVERROR(ENOMEM);
291289
292− pkt->side_data[elems].data = av_mallocz(size + AV_INPUT_BUFFER_PADDING_SIZE);
293− if (!pkt->side_data[elems].data)
294− return NULL;
290+ pkt->side_data[elems].data = data;
295291 pkt->side_data[elems].size = size;
296292 pkt->side_data[elems].type = type;
297293 pkt->side_data_elems++;
298294
299− return pkt->side_data[elems].data;
295+ return 0;
296+}
297+
298+
299+uint8_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;
300318 }
301319
302320 uint8_t *av_packet_get_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
libavcodec/version.h+1−1
@@ -29,7 +29,7 @@ · 28 unmodified lines
2929 #include "libavutil/version.h"
3030
3131 #define LIBAVCODEC_VERSION_MAJOR 57
32−#define LIBAVCODEC_VERSION_MINOR 17
32+#define LIBAVCODEC_VERSION_MINOR 18
3333 #define LIBAVCODEC_VERSION_MICRO 100
3434
3535 #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