[FFmpeg-cvslog] Merge commit '409d1cd2c955485798f8b0b0147c2b899b9144ec'

Clément Bœsch git at videolan.org
Sun Mar 19 18:50:21 EET 2017


ffmpeg | branch: master | Clément Bœsch <u at pkh.me> | Sun Mar 19 17:47:19 2017 +0100| [d707e667c5605a712c144cec0edfca62e0a9804e] | committer: Clément Bœsch

Merge commit '409d1cd2c955485798f8b0b0147c2b899b9144ec'

* commit '409d1cd2c955485798f8b0b0147c2b899b9144ec':
  cook: use the bytestream2 API for reading extradata

Merged-by: Clément Bœsch <u at pkh.me>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=d707e667c5605a712c144cec0edfca62e0a9804e
---

 libavcodec/cook.c | 38 +++++++++++++++-----------------------
 1 file changed, 15 insertions(+), 23 deletions(-)

diff --git a/libavcodec/cook.c b/libavcodec/cook.c
index 794a475..4488f8e 100644
--- a/libavcodec/cook.c
+++ b/libavcodec/cook.c
@@ -1053,9 +1053,7 @@ static void dump_cook_context(COOKContext *q)
 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 = 0;
@@ -1063,12 +1061,14 @@ static av_cold int cook_decode_init(AVCodecContext *avctx)
     q->avctx = avctx;
 
     /* Take care of the codec specific extradata. */
-    if (extradata_size < 8) {
+    if (avctx->extradata_size < 8) {
         av_log(avctx, AV_LOG_ERROR, "Necessary extradata missing!\n");
         return AVERROR_INVALIDDATA;
     }
     av_log(avctx, AV_LOG_DEBUG, "codecdata_length=%d\n", avctx->extradata_size);
 
+    bytestream2_init(&gb, avctx->extradata, avctx->extradata_size);
+
     /* Take data from the AVCodecContext (RM container). */
     if (!avctx->channels) {
         av_log(avctx, AV_LOG_ERROR, "Invalid number of channels\n");
@@ -1080,26 +1080,19 @@ static av_cold int cook_decode_init(AVCodecContext *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;
@@ -1151,8 +1144,7 @@ static av_cold int cook_decode_init(AVCodecContext *avctx)
             break;
         case MC_COOK:
             av_log(avctx, AV_LOG_DEBUG, "MULTI_CHANNEL\n");
-            if (extradata_size >= 4)
-                channel_mask |= q->subpacket[s].channel_mask = bytestream_get_be32(&edata_ptr);
+            channel_mask |= q->subpacket[s].channel_mask = bytestream2_get_be32(&gb);
 
             if (av_get_channel_layout_nb_channels(q->subpacket[s].channel_mask) > 1) {
                 q->subpacket[s].total_subbands = q->subpacket[s].subbands +


======================================================================

diff --cc libavcodec/cook.c
index 794a475,016b1d0..4488f8e
--- a/libavcodec/cook.c
+++ b/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;
  
@@@ -1080,26 -1068,15 +1080,19 @@@
  
      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;



More information about the ffmpeg-cvslog mailing list