summaryrefslogtreecommitdiff
path: root/libavformat/utils.c
diff options
context:
space:
mode:
authorHendrik Leppkes <h.leppkes@gmail.com>2016-03-31 21:49:02 +0100
committerDerek Buitenhuis <derek.buitenhuis@gmail.com>2016-04-03 13:04:17 -0400
commit6518cbc52a8c59f8f590405a852385adbc47ed62 (patch)
tree8190319ae6f22317b30f92d65c804e7733712860 /libavformat/utils.c
parent06c4ed0c0e349602ae6ca31c39693f73bce9bf61 (diff)
lavc/utils: Introduce ff_bprint_to_codecpar_extradata for avformat
It will be used by text subtitle demuxers to construct format instructions straight into extradata. They all currently a similar function that accepts an AVCodecContext instead. Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
Diffstat (limited to 'libavformat/utils.c')
-rw-r--r--libavformat/utils.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 3bd2df3013..3bf96adaab 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -4866,3 +4866,26 @@ int ff_get_packet_palette(AVFormatContext *s, AVPacket *pkt, int ret, uint32_t *
return 0;
}
+
+int ff_bprint_to_codecpar_extradata(AVCodecParameters *par, struct AVBPrint *buf)
+{
+ int ret;
+ char *str;
+
+ ret = av_bprint_finalize(buf, &str);
+ if (ret < 0)
+ return ret;
+ if (!av_bprint_is_complete(buf)) {
+ av_free(str);
+ return AVERROR(ENOMEM);
+ }
+
+ par->extradata = str;
+ /* Note: the string is NUL terminated (so extradata can be read as a
+ * string), but the ending character is not accounted in the size (in
+ * binary formats you are likely not supposed to mux that character). When
+ * extradata is copied, it is also padded with AV_INPUT_BUFFER_PADDING_SIZE
+ * zeros. */
+ par->extradata_size = buf->len;
+ return 0;
+}