mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2025-12-13 10:30:05 +01:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user