summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-01-11 01:25:49 +0100
committerwm4 <wm4@nowhere>2014-03-11 00:07:51 +0100
commit5ab2aa84e03ca878a66cc1ce7919edc0ad9b23ed (patch)
treea3cd4045fc2cc9f46e837bf4cdeafb42107f9815
parent229d398ba941e13b755e96acc9b624bfbf48c14d (diff)
downloadmpv-5ab2aa84e03ca878a66cc1ce7919edc0ad9b23ed.tar.bz2
mpv-5ab2aa84e03ca878a66cc1ce7919edc0ad9b23ed.tar.xz
Factor out setting AVCodecContext extradata
-rw-r--r--audio/decode/ad_lavc.c14
-rw-r--r--common/av_common.c24
-rw-r--r--common/av_common.h1
-rw-r--r--video/decode/vd_lavc.c27
4 files changed, 27 insertions, 39 deletions
diff --git a/audio/decode/ad_lavc.c b/audio/decode/ad_lavc.c
index b2f29505c2..0484fb9521 100644
--- a/audio/decode/ad_lavc.c
+++ b/audio/decode/ad_lavc.c
@@ -172,11 +172,8 @@ static void set_from_wf(AVCodecContext *avctx, MP_WAVEFORMATEX *wf)
avctx->block_align = wf->nBlockAlign;
avctx->bits_per_coded_sample = wf->wBitsPerSample;
- if (wf->cbSize > 0) {
- avctx->extradata = av_mallocz(wf->cbSize + FF_INPUT_BUFFER_PADDING_SIZE);
- avctx->extradata_size = wf->cbSize;
- memcpy(avctx->extradata, wf + 1, avctx->extradata_size);
- }
+ if (wf->cbSize > 0)
+ mp_lavc_set_extradata(avctx, wf + 1, wf->cbSize);
}
static int init(struct dec_audio *da, const char *decoder)
@@ -244,11 +241,8 @@ static int init(struct dec_audio *da, const char *decoder)
// demux_mkv, demux_mpg
if (sh_audio->codecdata_len && sh_audio->codecdata &&
!lavc_context->extradata) {
- lavc_context->extradata = av_malloc(sh_audio->codecdata_len +
- FF_INPUT_BUFFER_PADDING_SIZE);
- lavc_context->extradata_size = sh_audio->codecdata_len;
- memcpy(lavc_context->extradata, (char *)sh_audio->codecdata,
- lavc_context->extradata_size);
+ mp_lavc_set_extradata(lavc_context, sh_audio->codecdata,
+ sh_audio->codecdata_len);
}
if (sh->lav_headers)
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);
diff --git a/video/decode/vd_lavc.c b/video/decode/vd_lavc.c
index dcd208ad10..355db26556 100644
--- a/video/decode/vd_lavc.c
+++ b/video/decode/vd_lavc.c
@@ -318,10 +318,7 @@ static void set_from_bih(AVCodecContext *avctx, uint32_t format,
if (bih->biSize <= sizeof(*bih))
break;
av_opt_set_int(avctx, "extern_huff", 1, AV_OPT_SEARCH_CHILDREN);
- avctx->extradata_size = bih->biSize - sizeof(*bih);
- avctx->extradata = av_mallocz(avctx->extradata_size +
- FF_INPUT_BUFFER_PADDING_SIZE);
- memcpy(avctx->extradata, bih + 1, avctx->extradata_size);
+ mp_lavc_set_extradata(avctx, bih + 1, bih->biSize - sizeof(*bih));
break;
case MP_FOURCC('R','V','1','0'):
@@ -331,29 +328,21 @@ static void set_from_bih(AVCodecContext *avctx, uint32_t format,
case MP_FOURCC('R','V','4','0'):
if (bih->biSize < sizeof(*bih) + 8) {
// only 1 packet per frame & sub_id from fourcc
- avctx->extradata_size = 8;
- avctx->extradata = av_mallocz(avctx->extradata_size +
- FF_INPUT_BUFFER_PADDING_SIZE);
- ((uint32_t *)avctx->extradata)[0] = 0;
- ((uint32_t *)avctx->extradata)[1] =
- format == MP_FOURCC('R','V','1','3') ?
- 0x10003001 : 0x10000000;
+ uint32_t extradata[2] = {
+ 0,
+ format == MP_FOURCC('R','V','1','3') ? 0x10003001 : 0x10000000,
+ };
+ mp_lavc_set_extradata(avctx, &extradata, 8);
} else {
// has extra slice header (demux_rm or rm->avi streamcopy)
- avctx->extradata_size = bih->biSize - sizeof(*bih);
- avctx->extradata = av_mallocz(avctx->extradata_size +
- FF_INPUT_BUFFER_PADDING_SIZE);
- memcpy(avctx->extradata, bih + 1, avctx->extradata_size);
+ mp_lavc_set_extradata(avctx, bih + 1, bih->biSize - sizeof(*bih));
}
break;
default:
if (bih->biSize <= sizeof(*bih))
break;
- avctx->extradata_size = bih->biSize - sizeof(*bih);
- avctx->extradata = av_mallocz(avctx->extradata_size +
- FF_INPUT_BUFFER_PADDING_SIZE);
- memcpy(avctx->extradata, bih + 1, avctx->extradata_size);
+ mp_lavc_set_extradata(avctx, bih + 1, bih->biSize - sizeof(*bih));
break;
}