History

avformat/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 10 years ago

Commit 2ab50641 parent 4696f764 files · +42 −10Browse files

Unified · Split

4 files
  1. doc/APIchanges +3 −0
  2. libavformat/avformat.h +15 −0
  3. libavformat/utils.c +23 −9
  4. libavformat/version.h +1 −1
doc/APIchanges+3−0
@@ -15,6 +15,9 @@ libavutil: 2015-08-28 · 14 unmodified lines
1515
1616 API changes, most recent first:
1717
18+2016-11-18 - xxxxxxx - lavf 57.58.100 - avformat.h
19+ Add av_stream_add_side_data().
20+
1821 2016-xx-xx - xxxxxxx - lavu 55.39.100 - hwcontext_vaapi.h
1922 Add AV_VAAPI_DRIVER_QUIRK_ATTRIB_MEMTYPE.
2023
libavformat/avformat.h+15−0
@@ -2048,6 +2048,21 @@ const AVClass *avformat_get_class(void); · 2047 unmodified lines
20482048 */
20492049 AVStream *avformat_new_stream(AVFormatContext *s, const AVCodec *c);
20502050
2051+/**
2052+ * Wrap an existing array as stream side data.
2053+ *
2054+ * @param st stream
2055+ * @param type side information type
2056+ * @param data the side data array. It must be allocated with the av_malloc()
2057+ * family of functions. The ownership of the data is transferred to
2058+ * st.
2059+ * @param size side information size
2060+ * @return zero on success, a negative AVERROR code on failure. On failure,
2061+ * the stream is unchanged and the data remains owned by the caller.
2062+ */
2063+int av_stream_add_side_data(AVStream *st, enum AVPacketSideDataType type,
2064+ uint8_t *data, size_t size);
2065+
20512066 /**
20522067 * Allocate new information from stream.
20532068 *
libavformat/utils.c+23−9
@@ -5104,15 +5104,11 @@ uint8_t *av_stream_get_side_data(const AVStream *st, · 5103 unmodified lines
51045104 return NULL;
51055105 }
51065106
5107−uint8_t *av_stream_new_side_data(AVStream *st, enum AVPacketSideDataType type,
5108− int size)
5107+int av_stream_add_side_data(AVStream *st, enum AVPacketSideDataType type,
5108+ uint8_t *data, size_t size)
51095109 {
51105110 AVPacketSideData *sd, *tmp;
51115111 int i;
5112− uint8_t *data = av_malloc(size);
5113−
5114− if (!data)
5115− return NULL;
51165112
51175113 for (i = 0; i < st->nb_side_data; i++) {
51185114 sd = &st->side_data[i];
@@ -5121,14 +5117,13 @@ uint8_t *av_stream_new_side_data(AVStream *st, enum AVPacketSideDataType type, · 2 unmodified lines
51215117 av_freep(&sd->data);
51225118 sd->data = data;
51235119 sd->size = size;
5124− return sd->data;
5120+ return 0;
51255121 }
51265122 }
51275123
51285124 tmp = av_realloc_array(st->side_data, st->nb_side_data + 1, sizeof(*tmp));
51295125 if (!tmp) {
5130− av_freep(&data);
5131− return NULL;
5126+ return AVERROR(ENOMEM);
51325127 }
51335128
51345129 st->side_data = tmp;
@@ -5138,6 +5133,25 @@ uint8_t *av_stream_new_side_data(AVStream *st, enum AVPacketSideDataType type, · 3 unmodified lines
51385133 sd->type = type;
51395134 sd->data = data;
51405135 sd->size = size;
5136+
5137+ return 0;
5138+}
5139+
5140+uint8_t *av_stream_new_side_data(AVStream *st, enum AVPacketSideDataType type,
5141+ int size)
5142+{
5143+ int ret;
5144+ uint8_t *data = av_malloc(size);
5145+
5146+ if (!data)
5147+ return NULL;
5148+
5149+ ret = av_stream_add_side_data(st, type, data, size);
5150+ if (ret < 0) {
5151+ av_freep(&data);
5152+ return NULL;
5153+ }
5154+
51415155 return data;
51425156 }
51435157
libavformat/version.h+1−1
@@ -32,7 +32,7 @@ · 31 unmodified lines
3232 // Major bumping may affect Ticket5467, 5421, 5451(compatibility with Chromium)
3333 // Also please add any ticket numbers that you believe might be affected here
3434 #define LIBAVFORMAT_VERSION_MAJOR 57
35−#define LIBAVFORMAT_VERSION_MINOR 57
35+#define LIBAVFORMAT_VERSION_MINOR 58
3636 #define LIBAVFORMAT_VERSION_MICRO 100
3737
3838 #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