avcodec/dca: avoid using bitstream reader in a non-standard way
authorfoo86 <foobaz86@gmail.com>
Mon, 10 Jul 2017 14:11:40 +0000 (17:11 +0300)
committerJames Almer <jamrial@gmail.com>
Wed, 19 Jul 2017 00:04:58 +0000 (21:04 -0300)
Use proper get_bits.h functions instead of directly accessing index.

Signed-off-by: James Almer <jamrial@gmail.com>
libavcodec/dca_core.c
libavcodec/dca_core.h
libavcodec/dca_xll.c
libavcodec/dcadec.h

index 4a7ea4e..3add9f8 100644 (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)
         return ret;
+    s->gb_in = s->gb;
 
     if ((ret = parse_frame_header(s)) < 0)
         return ret;
@@ -1831,7 +1832,6 @@ int ff_dca_core_parse_exss(DCACoreDecoder *s, uint8_t *data, DCAExssAsset *asset
 {
     AVCodecContext *avctx = s->avctx;
     DCAContext *dca = avctx->priv_data;
-    GetBitContext gb = s->gb;
     int exss_mask = asset ? asset->extension_mask : 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);
             ext = DCA_EXSS_XXCH;
         } 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);
             ext = DCA_CSS_XXCH;
         } 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);
             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;
             }
         } else if (s->x96_pos) {
-            s->gb = gb;
-            s->gb.index = s->x96_pos;
+            s->gb = s->gb_in;
+            skip_bits_long(&s->gb, s->x96_pos);
             if ((ret = parse_x96_frame(s)) < 0) {
                 if (ret == AVERROR(ENOMEM) || (avctx->err_recognition & AV_EF_EXPLODE))
                     return ret;
index cce0ffd..10128d1 100644 (file)
@@ -101,6 +101,7 @@ typedef struct DCADSPData {
 typedef struct DCACoreDecoder {
     AVCodecContext  *avctx;
     GetBitContext   gb;
+    GetBitContext   gb_in;
 
     // Bit stream header
     int     crc_present;        ///< CRC present flag
index 38a1999..d265cab 100644 (file)
@@ -1028,7 +1028,7 @@ static int parse_band_data(DCAXllDecoder *s)
                             return ret;
                         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++;
             }
index 456f3c4..9da8d3b 100644 (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)
 {
-    if (p < s->index || p > s->size_in_bits)
+    if (p < get_bits_count(s) || p > s->size_in_bits)
         return -1;
-    s->index = p;
+    skip_bits_long(s, p - get_bits_count(s));
     return 0;
 }