summaryrefslogtreecommitdiff
path: root/libavcodec/wavpack.c
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2013-05-27 09:44:27 +0200
committerAnton Khirnov <anton@khirnov.net>2013-05-28 08:14:35 +0200
commit9b6f47c44807f14788e909c4c71db58eebba8277 (patch)
treeed68064c1ed437c8d65b439eac10a7dac1add236 /libavcodec/wavpack.c
parent5074f4545c439420daebe4c2f28ed216440b6ec7 (diff)
matroskadec: export full wavpack blocks.
This allows us to get rid of demuxer-specific hacks in the decoder and will allow streamcopy from matroska once we have a wavpack muxer.
Diffstat (limited to 'libavcodec/wavpack.c')
-rw-r--r--libavcodec/wavpack.c52
1 files changed, 12 insertions, 40 deletions
diff --git a/libavcodec/wavpack.c b/libavcodec/wavpack.c
index 3a0fe272a8..4cf9478b8b 100644
--- a/libavcodec/wavpack.c
+++ b/libavcodec/wavpack.c
@@ -135,7 +135,6 @@ typedef struct WavpackContext {
int fdec_num;
int multichannel;
- int mkv_mode;
int block;
int samples;
int ch_offset;
@@ -724,14 +723,6 @@ static av_cold int wavpack_decode_init(AVCodecContext *avctx)
: AV_CH_LAYOUT_MONO;
s->multichannel = avctx->channels > 2;
- /* lavf demuxer does not provide extradata, Matroska stores 0x403
- * there, use this to detect decoding mode for multichannel */
- s->mkv_mode = 0;
- if (s->multichannel && avctx->extradata && avctx->extradata_size == 2) {
- int ver = AV_RL16(avctx->extradata);
- if (ver >= 0x402 && ver <= 0x410)
- s->mkv_mode = 1;
- }
s->fdec_num = 0;
@@ -783,15 +774,11 @@ static int wavpack_decode_block(AVCodecContext *avctx, int block_no,
bytestream2_init(&gb, buf, buf_size);
- if (!wc->mkv_mode) {
- s->samples = bytestream2_get_le32(&gb);
- if (s->samples != wc->samples) {
- av_log(avctx, AV_LOG_ERROR, "Mismatching number of samples in "
- "a sequence: %d and %d\n", wc->samples, s->samples);
- return AVERROR_INVALIDDATA;
- }
- } else {
- s->samples = wc->samples;
+ s->samples = bytestream2_get_le32(&gb);
+ if (s->samples != wc->samples) {
+ av_log(avctx, AV_LOG_ERROR, "Mismatching number of samples in "
+ "a sequence: %d and %d\n", wc->samples, s->samples);
+ return AVERROR_INVALIDDATA;
}
s->frame_flags = bytestream2_get_le32(&gb);
bpp = av_get_bytes_per_sample(avctx->sample_fmt);
@@ -811,9 +798,6 @@ static int wavpack_decode_block(AVCodecContext *avctx, int block_no,
if (s->stereo)
samples_r = data[wc->ch_offset + 1];
- if (wc->mkv_mode)
- bytestream2_skip(&gb, 4); // skip block size;
-
wc->ch_offset += 1 + s->stereo;
// parse metadata blocks
@@ -1154,14 +1138,8 @@ static int wavpack_decode_frame(AVCodecContext *avctx, void *data,
s->ch_offset = 0;
/* determine number of samples */
- if (s->mkv_mode) {
- s->samples = AV_RL32(buf);
- buf += 4;
- frame_flags = AV_RL32(buf);
- } else {
- s->samples = AV_RL32(buf + 20);
- frame_flags = AV_RL32(buf + 24);
- }
+ s->samples = AV_RL32(buf + 20);
+ frame_flags = AV_RL32(buf + 24);
if (s->samples <= 0) {
av_log(avctx, AV_LOG_ERROR, "Invalid number of samples: %d\n",
s->samples);
@@ -1185,17 +1163,11 @@ static int wavpack_decode_frame(AVCodecContext *avctx, void *data,
}
while (buf_size > 0) {
- if (!s->mkv_mode) {
- if (buf_size <= WV_HEADER_SIZE)
- break;
- frame_size = AV_RL32(buf + 4) - 12;
- buf += 20;
- buf_size -= 20;
- } else {
- if (buf_size < 12) // MKV files can have zero flags after last block
- break;
- frame_size = AV_RL32(buf + 8) + 12;
- }
+ if (buf_size <= WV_HEADER_SIZE)
+ break;
+ frame_size = AV_RL32(buf + 4) - 12;
+ buf += 20;
+ buf_size -= 20;
if (frame_size <= 0 || frame_size > buf_size) {
av_log(avctx, AV_LOG_ERROR,
"Block %d has invalid size (size %d vs. %d bytes left)\n",