Commit 6518cbc5 authored by Hendrik Leppkes's avatar Hendrik Leppkes Committed by Derek Buitenhuis

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: 's avatarDerek Buitenhuis <derek.buitenhuis@gmail.com>
parent 06c4ed0c
...@@ -22,6 +22,8 @@ ...@@ -22,6 +22,8 @@
#define AVFORMAT_INTERNAL_H #define AVFORMAT_INTERNAL_H
#include <stdint.h> #include <stdint.h>
#include "libavutil/bprint.h"
#include "avformat.h" #include "avformat.h"
#include "os_support.h" #include "os_support.h"
...@@ -596,4 +598,9 @@ int ff_reshuffle_raw_rgb(AVFormatContext *s, AVPacket **ppkt, AVCodecContext *en ...@@ -596,4 +598,9 @@ int ff_reshuffle_raw_rgb(AVFormatContext *s, AVPacket **ppkt, AVCodecContext *en
*/ */
int ff_get_packet_palette(AVFormatContext *s, AVPacket *pkt, int ret, uint32_t *palette); int ff_get_packet_palette(AVFormatContext *s, AVPacket *pkt, int ret, uint32_t *palette);
/**
* Finalize buf into extradata and set its size appropriately.
*/
int ff_bprint_to_codecpar_extradata(AVCodecParameters *par, struct AVBPrint *buf);
#endif /* AVFORMAT_INTERNAL_H */ #endif /* AVFORMAT_INTERNAL_H */
...@@ -4866,3 +4866,26 @@ int ff_get_packet_palette(AVFormatContext *s, AVPacket *pkt, int ret, uint32_t * ...@@ -4866,3 +4866,26 @@ int ff_get_packet_palette(AVFormatContext *s, AVPacket *pkt, int ret, uint32_t *
return 0; 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;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment