summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-01-11 01:25:49 +0100
committerwm4 <wm4@nowhere>2014-01-11 01:25:49 +0100
commit4b4926bbb3102836fc0c2edafe791cca6209f45e (patch)
tree3ed7d5f45e2e61ab956e18db96106cf27d99323a /common
parent27e4360b0bc521ec6bb6ecd7c374a51c8114d090 (diff)
downloadmpv-4b4926bbb3102836fc0c2edafe791cca6209f45e.tar.bz2
mpv-4b4926bbb3102836fc0c2edafe791cca6209f45e.tar.xz
Factor out setting AVCodecContext extradata
Diffstat (limited to 'common')
-rw-r--r--common/av_common.c24
-rw-r--r--common/av_common.h1
2 files changed, 15 insertions, 10 deletions
diff --git a/common/av_common.c b/common/av_common.c
index 9c41c03251..1a162b7d95 100644
--- a/common/av_common.c
+++ b/common/av_common.c
@@ -29,6 +29,19 @@
#include "osdep/numcores.h"
+int mp_lavc_set_extradata(AVCodecContext *avctx, void *ptr, int size)
+{
+ if (size) {
+ av_free(avctx->extradata);
+ avctx->extradata_size = 0;
+ avctx->extradata = av_mallocz(size + FF_INPUT_BUFFER_PADDING_SIZE);
+ if (!avctx->extradata)
+ return -1;
+ avctx->extradata_size = size;
+ memcpy(avctx->extradata, ptr, size);
+ }
+ return 0;
+}
// Copy the codec-related fields from st into avctx. This does not set the
// codec itself, only codec related header data provided by libavformat.
@@ -38,16 +51,7 @@
// This is strictly for decoding only.
void mp_copy_lav_codec_headers(AVCodecContext *avctx, AVCodecContext *st)
{
- if (st->extradata_size) {
- av_free(avctx->extradata);
- avctx->extradata_size = 0;
- avctx->extradata =
- av_mallocz(st->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
- if (avctx->extradata) {
- avctx->extradata_size = st->extradata_size;
- memcpy(avctx->extradata, st->extradata, st->extradata_size);
- }
- }
+ mp_lavc_set_extradata(avctx, st->extradata, st->extradata_size);
avctx->codec_tag = st->codec_tag;
avctx->stream_codec_tag = st->stream_codec_tag;
avctx->bit_rate = st->bit_rate;
diff --git a/common/av_common.h b/common/av_common.h
index 7bf2d64d9e..2e55fe17a0 100644
--- a/common/av_common.h
+++ b/common/av_common.h
@@ -27,6 +27,7 @@
struct mp_decoder_list;
struct demux_packet;
+int mp_lavc_set_extradata(AVCodecContext *avctx, void *ptr, int size);
void mp_copy_lav_codec_headers(AVCodecContext *avctx, AVCodecContext *st);
void mp_set_av_packet(AVPacket *dst, struct demux_packet *mpkt, AVRational *tb);
int64_t mp_pts_to_av(double mp_pts, AVRational *tb);