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.
This commit is contained in:
Clément Bœsch
2012-12-29 22:09:59 +01:00
parent e911f4ae72
commit 36e61e24e7
9 changed files with 45 additions and 23 deletions

View File

@@ -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;
}