Commit 24d31a80 authored by Paul B Mahol's avatar Paul B Mahol

avcodec/qdm2: make use of bytestream2

Signed-off-by: 's avatarPaul B Mahol <onemda@gmail.com>
parent 7aef5686
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
#define BITSTREAM_READER_LE #define BITSTREAM_READER_LE
#include "avcodec.h" #include "avcodec.h"
#include "get_bits.h" #include "get_bits.h"
#include "bytestream.h"
#include "internal.h" #include "internal.h"
#include "mpegaudio.h" #include "mpegaudio.h"
#include "mpegaudiodsp.h" #include "mpegaudiodsp.h"
...@@ -1605,9 +1606,8 @@ static av_cold void qdm2_init_static_data(void) { ...@@ -1605,9 +1606,8 @@ static av_cold void qdm2_init_static_data(void) {
static av_cold int qdm2_decode_init(AVCodecContext *avctx) static av_cold int qdm2_decode_init(AVCodecContext *avctx)
{ {
QDM2Context *s = avctx->priv_data; QDM2Context *s = avctx->priv_data;
uint8_t *extradata;
int extradata_size;
int tmp_val, tmp, size; int tmp_val, tmp, size;
GetByteContext gb;
qdm2_init_static_data(); qdm2_init_static_data();
...@@ -1650,55 +1650,39 @@ static av_cold int qdm2_decode_init(AVCodecContext *avctx) ...@@ -1650,55 +1650,39 @@ static av_cold int qdm2_decode_init(AVCodecContext *avctx)
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
extradata = avctx->extradata; bytestream2_init(&gb, avctx->extradata, avctx->extradata_size);
extradata_size = avctx->extradata_size;
while (extradata_size > 7) { while (bytestream2_get_bytes_left(&gb) > 8) {
if (!memcmp(extradata, "frmaQDM", 7)) if (bytestream2_peek_be64(&gb) == (((uint64_t)MKBETAG('f','r','m','a') << 32) |
(uint64_t)MKBETAG('Q','D','M','2')))
break; break;
extradata++; bytestream2_skip(&gb, 1);
extradata_size--;
} }
if (extradata_size < 12) { if (bytestream2_get_bytes_left(&gb) < 12) {
av_log(avctx, AV_LOG_ERROR, "not enough extradata (%i)\n", av_log(avctx, AV_LOG_ERROR, "not enough extradata (%i)\n",
extradata_size); bytestream2_get_bytes_left(&gb));
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
if (memcmp(extradata, "frmaQDM", 7)) { bytestream2_skip(&gb, 8);
av_log(avctx, AV_LOG_ERROR, "invalid headers, QDM? not found\n"); size = bytestream2_get_be32(&gb);
return AVERROR_INVALIDDATA;
}
if (extradata[7] == 'C') {
// s->is_qdmc = 1;
avpriv_report_missing_feature(avctx, "QDMC version 1");
return AVERROR_PATCHWELCOME;
}
extradata += 8;
extradata_size -= 8;
size = AV_RB32(extradata); if (size > bytestream2_get_bytes_left(&gb)) {
if(size > extradata_size){
av_log(avctx, AV_LOG_ERROR, "extradata size too small, %i < %i\n", av_log(avctx, AV_LOG_ERROR, "extradata size too small, %i < %i\n",
extradata_size, size); bytestream2_get_bytes_left(&gb), size);
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
extradata += 4;
av_log(avctx, AV_LOG_DEBUG, "size: %d\n", size); av_log(avctx, AV_LOG_DEBUG, "size: %d\n", size);
if (AV_RB32(extradata) != MKBETAG('Q','D','C','A')) { if (bytestream2_get_be32(&gb) != MKBETAG('Q','D','C','A')) {
av_log(avctx, AV_LOG_ERROR, "invalid extradata, expecting QDCA\n"); av_log(avctx, AV_LOG_ERROR, "invalid extradata, expecting QDCA\n");
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
extradata += 8; bytestream2_skip(&gb, 4);
avctx->channels = s->nb_channels = s->channels = AV_RB32(extradata); avctx->channels = s->nb_channels = s->channels = bytestream2_get_be32(&gb);
extradata += 4;
if (s->channels <= 0 || s->channels > MPA_MAX_CHANNELS) { if (s->channels <= 0 || s->channels > MPA_MAX_CHANNELS) {
av_log(avctx, AV_LOG_ERROR, "Invalid number of channels\n"); av_log(avctx, AV_LOG_ERROR, "Invalid number of channels\n");
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
...@@ -1706,19 +1690,11 @@ static av_cold int qdm2_decode_init(AVCodecContext *avctx) ...@@ -1706,19 +1690,11 @@ static av_cold int qdm2_decode_init(AVCodecContext *avctx)
avctx->channel_layout = avctx->channels == 2 ? AV_CH_LAYOUT_STEREO : avctx->channel_layout = avctx->channels == 2 ? AV_CH_LAYOUT_STEREO :
AV_CH_LAYOUT_MONO; AV_CH_LAYOUT_MONO;
avctx->sample_rate = AV_RB32(extradata); avctx->sample_rate = bytestream2_get_be32(&gb);
extradata += 4; avctx->bit_rate = bytestream2_get_be32(&gb);
s->group_size = bytestream2_get_be32(&gb);
avctx->bit_rate = AV_RB32(extradata); s->fft_size = bytestream2_get_be32(&gb);
extradata += 4; s->checksum_size = bytestream2_get_be32(&gb);
s->group_size = AV_RB32(extradata);
extradata += 4;
s->fft_size = AV_RB32(extradata);
extradata += 4;
s->checksum_size = AV_RB32(extradata);
if (s->checksum_size >= 1U << 28) { if (s->checksum_size >= 1U << 28) {
av_log(avctx, AV_LOG_ERROR, "data block size too large (%u)\n", s->checksum_size); av_log(avctx, AV_LOG_ERROR, "data block size too large (%u)\n", s->checksum_size);
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
......
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