1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

avcodec/dca: avoid using bitstream reader in a non-standard way

Use proper get_bits.h functions instead of directly accessing index.

Signed-off-by: James Almer <jamrial@gmail.com>
This commit is contained in:
foo86 2017-07-10 17:11:40 +03:00 committed by James Almer
parent 902cd30e9b
commit 012620aa1b
4 changed files with 11 additions and 8 deletions

View File

@ -1804,6 +1804,7 @@ int ff_dca_core_parse(DCACoreDecoder *s, uint8_t *data, int size)
if ((ret = init_get_bits8(&s->gb, data, size)) < 0) if ((ret = init_get_bits8(&s->gb, data, size)) < 0)
return ret; return ret;
s->gb_in = s->gb;
if ((ret = parse_frame_header(s)) < 0) if ((ret = parse_frame_header(s)) < 0)
return ret; return ret;
@ -1831,7 +1832,6 @@ int ff_dca_core_parse_exss(DCACoreDecoder *s, uint8_t *data, DCAExssAsset *asset
{ {
AVCodecContext *avctx = s->avctx; AVCodecContext *avctx = s->avctx;
DCAContext *dca = avctx->priv_data; DCAContext *dca = avctx->priv_data;
GetBitContext gb = s->gb;
int exss_mask = asset ? asset->extension_mask : 0; int exss_mask = asset ? asset->extension_mask : 0;
int ret = 0, ext = 0; int ret = 0, ext = 0;
@ -1843,11 +1843,13 @@ int ff_dca_core_parse_exss(DCACoreDecoder *s, uint8_t *data, DCAExssAsset *asset
ret = parse_xxch_frame(s); ret = parse_xxch_frame(s);
ext = DCA_EXSS_XXCH; ext = DCA_EXSS_XXCH;
} else if (s->xxch_pos) { } else if (s->xxch_pos) {
s->gb.index = s->xxch_pos; s->gb = s->gb_in;
skip_bits_long(&s->gb, s->xxch_pos);
ret = parse_xxch_frame(s); ret = parse_xxch_frame(s);
ext = DCA_CSS_XXCH; ext = DCA_CSS_XXCH;
} else if (s->xch_pos) { } else if (s->xch_pos) {
s->gb.index = s->xch_pos; s->gb = s->gb_in;
skip_bits_long(&s->gb, s->xch_pos);
ret = parse_xch_frame(s); ret = parse_xch_frame(s);
ext = DCA_CSS_XCH; ext = DCA_CSS_XCH;
} }
@ -1889,8 +1891,8 @@ int ff_dca_core_parse_exss(DCACoreDecoder *s, uint8_t *data, DCAExssAsset *asset
s->ext_audio_mask |= DCA_EXSS_X96; s->ext_audio_mask |= DCA_EXSS_X96;
} }
} else if (s->x96_pos) { } else if (s->x96_pos) {
s->gb = gb; s->gb = s->gb_in;
s->gb.index = s->x96_pos; skip_bits_long(&s->gb, s->x96_pos);
if ((ret = parse_x96_frame(s)) < 0) { if ((ret = parse_x96_frame(s)) < 0) {
if (ret == AVERROR(ENOMEM) || (avctx->err_recognition & AV_EF_EXPLODE)) if (ret == AVERROR(ENOMEM) || (avctx->err_recognition & AV_EF_EXPLODE))
return ret; return ret;

View File

@ -101,6 +101,7 @@ typedef struct DCADSPData {
typedef struct DCACoreDecoder { typedef struct DCACoreDecoder {
AVCodecContext *avctx; AVCodecContext *avctx;
GetBitContext gb; GetBitContext gb;
GetBitContext gb_in;
// Bit stream header // Bit stream header
int crc_present; ///< CRC present flag int crc_present; ///< CRC present flag

View File

@ -1028,7 +1028,7 @@ static int parse_band_data(DCAXllDecoder *s)
return ret; return ret;
chs_clear_band_data(s, c, band, seg); chs_clear_band_data(s, c, band, seg);
} }
s->gb.index = navi_pos; skip_bits_long(&s->gb, navi_pos - get_bits_count(&s->gb));
} }
navi_ptr++; navi_ptr++;
} }

View File

@ -88,9 +88,9 @@ static inline int ff_dca_check_crc(AVCodecContext *avctx, GetBitContext *s,
static inline int ff_dca_seek_bits(GetBitContext *s, int p) static inline int ff_dca_seek_bits(GetBitContext *s, int p)
{ {
if (p < s->index || p > s->size_in_bits) if (p < get_bits_count(s) || p > s->size_in_bits)
return -1; return -1;
s->index = p; skip_bits_long(s, p - get_bits_count(s));
return 0; return 0;
} }