diff options
author | Clément Bœsch <ubitux@gmail.com> | 2012-12-29 22:09:59 +0100 |
---|---|---|
committer | Clément Bœsch <ubitux@gmail.com> | 2012-12-30 22:19:04 +0100 |
commit | 36e61e24e7ac737b38c4382d439329352d9e0c29 (patch) | |
tree | a3a478a143dcbb3d4d386fabfa1513487543c438 /libavcodec/utils.c | |
parent | e911f4ae720afe4a090ded2b165647734f0320ef (diff) | |
download | ffmpeg-36e61e24e7ac737b38c4382d439329352d9e0c29.tar.gz |
lavc: add ff_bprint_to_extradata() helper and use it.
This commit also makes sure the extradata and subtitle_header are NUL
terminated, without taking into account the trailing '\0' in account in
the size.
At the same time, it should fix 'warning: dereferencing type-punned
pointer will break strict-aliasing rules' warning for compilers who
don't consider uint8_t** and char** compatibles.
Diffstat (limited to 'libavcodec/utils.c')
-rw-r--r-- | libavcodec/utils.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/libavcodec/utils.c b/libavcodec/utils.c index b3669950d5..a275899ff7 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -27,6 +27,7 @@ #include "libavutil/avassert.h" #include "libavutil/avstring.h" +#include "libavutil/bprint.h" #include "libavutil/channel_layout.h" #include "libavutil/crc.h" #include "libavutil/mathematics.h" @@ -2684,3 +2685,21 @@ int avcodec_is_open(AVCodecContext *s) { return !!s->internal; } + +int ff_bprint_to_extradata(AVCodecContext *avctx, struct AVBPrint *buf) +{ + int ret; + char *str; + + ret = av_bprint_finalize(buf, &str); + if (ret < 0) + return ret; + avctx->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 FF_INPUT_BUFFER_PADDING_SIZE + * zeros. */ + avctx->extradata_size = buf->len; + return 0; +} |