Merge commit '409d1cd2c955485798f8b0b0147c2b899b9144ec'
authorClément Bœsch <u@pkh.me>
Sun, 19 Mar 2017 16:47:19 +0000 (17:47 +0100)
committerClément Bœsch <u@pkh.me>
Sun, 19 Mar 2017 16:47:19 +0000 (17:47 +0100)
* commit '409d1cd2c955485798f8b0b0147c2b899b9144ec':
  cook: use the bytestream2 API for reading extradata

Merged-by: Clément Bœsch <u@pkh.me>
1  2 
libavcodec/cook.c

@@@ -1053,12 -1041,10 +1053,10 @@@ static void dump_cook_context(COOKConte
  static av_cold int cook_decode_init(AVCodecContext *avctx)
  {
      COOKContext *q = avctx->priv_data;
-     const uint8_t *edata_ptr = avctx->extradata;
-     const uint8_t *edata_ptr_end = edata_ptr + avctx->extradata_size;
-     int extradata_size = avctx->extradata_size;
+     GetByteContext gb;
      int s = 0;
      unsigned int channel_mask = 0;
 -    int samples_per_frame;
 +    int samples_per_frame = 0;
      int ret;
      q->avctx = avctx;
  
  
      ff_audiodsp_init(&q->adsp);
  
-     while (edata_ptr < edata_ptr_end) {
+     while (bytestream2_get_bytes_left(&gb)) {
          /* 8 for mono, 16 for stereo, ? for multichannel
             Swap to right endianness so we don't need to care later on. */
-         if (extradata_size >= 8) {
-             q->subpacket[s].cookversion = bytestream_get_be32(&edata_ptr);
-             samples_per_frame           = bytestream_get_be16(&edata_ptr);
-             q->subpacket[s].subbands = bytestream_get_be16(&edata_ptr);
-             extradata_size -= 8;
-         }
-         if (extradata_size >= 8) {
-             bytestream_get_be32(&edata_ptr);    // Unknown unused
-             q->subpacket[s].js_subband_start = bytestream_get_be16(&edata_ptr);
-             if (q->subpacket[s].js_subband_start >= 51) {
-                 av_log(avctx, AV_LOG_ERROR, "js_subband_start %d is too large\n", q->subpacket[s].js_subband_start);
-                 return AVERROR_INVALIDDATA;
-             }
-             q->subpacket[s].js_vlc_bits = bytestream_get_be16(&edata_ptr);
-             extradata_size -= 8;
+         q->subpacket[s].cookversion      = bytestream2_get_be32(&gb);
+         samples_per_frame                = bytestream2_get_be16(&gb);
+         q->subpacket[s].subbands         = bytestream2_get_be16(&gb);
+         bytestream2_get_be32(&gb);    // Unknown unused
+         q->subpacket[s].js_subband_start = bytestream2_get_be16(&gb);
++        if (q->subpacket[s].js_subband_start >= 51) {
++            av_log(avctx, AV_LOG_ERROR, "js_subband_start %d is too large\n", q->subpacket[s].js_subband_start);
++            return AVERROR_INVALIDDATA;
 +        }
+         q->subpacket[s].js_vlc_bits      = bytestream2_get_be16(&gb);
  
          /* Initialize extradata related variables. */
          q->subpacket[s].samples_per_channel = samples_per_frame / avctx->channels;