diff options
author | Rudolf Polzer <divverent@xonotic.org> | 2012-12-03 20:16:17 +0100 |
---|---|---|
committer | Rudolf Polzer <divverent@xonotic.org> | 2012-12-03 20:16:17 +0100 |
commit | 1085539bde0937dd156566b3dea957f3efbe0b29 (patch) | |
tree | 45cf9258bd5b4ff281c83f7a9c11738ecd001c32 /audio/filter/af_lavcac3enc.c | |
parent | 54d998d5e7f101312cf26e9fc4d199fa9fed33c2 (diff) | |
download | mpv-1085539bde0937dd156566b3dea957f3efbe0b29.tar.bz2 mpv-1085539bde0937dd156566b3dea957f3efbe0b29.tar.xz |
af_lavcac3enc, encode: support planar formats
This fixes operation with current ffmpeg releases.
Note that this planarization is slow and should be reverted once proper
planar audio support is there in mpv.
Diffstat (limited to 'audio/filter/af_lavcac3enc.c')
-rw-r--r-- | audio/filter/af_lavcac3enc.c | 47 |
1 files changed, 44 insertions, 3 deletions
diff --git a/audio/filter/af_lavcac3enc.c b/audio/filter/af_lavcac3enc.c index b54f5bf61e..2b7a4ffb4c 100644 --- a/audio/filter/af_lavcac3enc.c +++ b/audio/filter/af_lavcac3enc.c @@ -47,6 +47,7 @@ const uint16_t ac3_bitrate_tab[19] = { typedef struct af_ac3enc_s { struct AVCodec *lavc_acodec; struct AVCodecContext *lavc_actx; + bool planarize; int add_iec61937_header; int bit_rate; int pending_data_size; @@ -232,8 +233,19 @@ static struct mp_audio* play(struct af_instance* af, struct mp_audio* data) c->nch, s->expect_len / samplesize, samplesize); - len = avcodec_encode_audio(s->lavc_actx, dest, destsize, - (void *)s->pending_data); + void *data = (void *) s->pending_data; + if (s->planarize) { + void *data2 = malloc(s->expect_len); + reorder_to_planar(data2, data, samplesize, + c->nch, s->expect_len / samplesize / c->nch); + data = data2; + } + + len = avcodec_encode_audio(s->lavc_actx, dest, destsize, data); + + if (s->planarize) + free(data); + s->pending_len = 0; } else { @@ -243,7 +255,20 @@ static struct mp_audio* play(struct af_instance* af, struct mp_audio* data) AF_CHANNEL_LAYOUT_LAVC_DEFAULT, c->nch, s->expect_len / samplesize, samplesize); - len = avcodec_encode_audio(s->lavc_actx,dest,destsize,(void *)src); + + void *data = (void *) src; + if (s->planarize) { + void *data2 = malloc(s->expect_len); + reorder_to_planar(data2, data, samplesize, + c->nch, s->expect_len / samplesize / c->nch); + data = data2; + } + + len = avcodec_encode_audio(s->lavc_actx, dest, destsize, data); + + if (s->planarize) + free(data); + src += s->expect_len; left -= s->expect_len; } @@ -305,10 +330,22 @@ static int af_open(struct af_instance* af){ } else if (fmts[i] == AV_SAMPLE_FMT_S16) { s->in_sampleformat = AF_FORMAT_S16_NE; s->lavc_actx->sample_fmt = fmts[i]; + s->planarize = 0; break; } else if (fmts[i] == AV_SAMPLE_FMT_FLT) { s->in_sampleformat = AF_FORMAT_FLOAT_NE; s->lavc_actx->sample_fmt = fmts[i]; + s->planarize = 0; + break; + } else if (fmts[i] == AV_SAMPLE_FMT_S16P) { + s->in_sampleformat = AF_FORMAT_S16_NE; + s->lavc_actx->sample_fmt = fmts[i]; + s->planarize = 1; + break; + } else if (fmts[i] == AV_SAMPLE_FMT_FLTP) { + s->in_sampleformat = AF_FORMAT_FLOAT_NE; + s->lavc_actx->sample_fmt = fmts[i]; + s->planarize = 1; break; } } @@ -319,6 +356,10 @@ static int af_open(struct af_instance* af){ af_fmt2bits(s->in_sampleformat) / 8; s->pending_data = malloc(s->pending_data_size); + if (s->planarize) + mp_msg(MSGT_AFILTER, MSGL_WARN, + "[af_lavcac3enc]: need to planarize audio data\n"); + return AF_OK; } |