]> rtime.felk.cvut.cz Git - frescor/ffmpeg.git/blobdiff - libavcodec/cook.c
frsh: Export information about the last RTP contract and VRES
[frescor/ffmpeg.git] / libavcodec / cook.c
index 59d3ef23f98daddd0419b300db6b5bef463ea3d4..a33222bf0e7fdc30ed5e791e9717c907722eee26 100644 (file)
@@ -1008,6 +1008,15 @@ static int cook_decode_frame(AVCodecContext *avctx,
     /* estimate subpacket sizes */
     q->subpacket[0].size = avctx->block_align;
 
+    for(i=1;i<q->num_subpackets;i++){
+        q->subpacket[i].size = 2 * buf[avctx->block_align - q->num_subpackets + i];
+        q->subpacket[0].size -= q->subpacket[i].size + 1;
+        if (q->subpacket[0].size < 0) {
+            av_log(avctx,AV_LOG_DEBUG,"frame subpacket size total > avctx->block_align!\n");
+            return -1;
+        }
+    }
+
     /* decode supbackets */
     *data_size = 0;
     for(i=0;i<q->num_subpackets;i++){
@@ -1033,23 +1042,23 @@ static void dump_cook_context(COOKContext *q)
     //int i=0;
 #define PRINT(a,b) av_log(q->avctx,AV_LOG_ERROR," %s = %d\n", a, b);
     av_log(q->avctx,AV_LOG_ERROR,"COOKextradata\n");
-    av_log(q->avctx,AV_LOG_ERROR,"cookversion=%x\n",q->cookversion);
-    if (q->cookversion > STEREO) {
-        PRINT("js_subband_start",q->js_subband_start);
-        PRINT("js_vlc_bits",q->js_vlc_bits);
+    av_log(q->avctx,AV_LOG_ERROR,"cookversion=%x\n",q->subpacket[0].cookversion);
+    if (q->subpacket[0].cookversion > STEREO) {
+        PRINT("js_subband_start",q->subpacket[0].js_subband_start);
+        PRINT("js_vlc_bits",q->subpacket[0].js_vlc_bits);
     }
     av_log(q->avctx,AV_LOG_ERROR,"COOKContext\n");
     PRINT("nb_channels",q->nb_channels);
     PRINT("bit_rate",q->bit_rate);
     PRINT("sample_rate",q->sample_rate);
-    PRINT("samples_per_channel",q->samples_per_channel);
-    PRINT("samples_per_frame",q->samples_per_frame);
-    PRINT("subbands",q->subbands);
+    PRINT("samples_per_channel",q->subpacket[0].samples_per_channel);
+    PRINT("samples_per_frame",q->subpacket[0].samples_per_frame);
+    PRINT("subbands",q->subpacket[0].subbands);
     PRINT("random_state",q->random_state);
-    PRINT("js_subband_start",q->js_subband_start);
-    PRINT("log2_numvector_size",q->log2_numvector_size);
-    PRINT("numvector_size",q->numvector_size);
-    PRINT("total_subbands",q->total_subbands);
+    PRINT("js_subband_start",q->subpacket[0].js_subband_start);
+    PRINT("log2_numvector_size",q->subpacket[0].log2_numvector_size);
+    PRINT("numvector_size",q->subpacket[0].numvector_size);
+    PRINT("total_subbands",q->subpacket[0].total_subbands);
 }
 #endif
 
@@ -1076,6 +1085,7 @@ static av_cold int cook_decode_init(AVCodecContext *avctx)
     const uint8_t *edata_ptr_end = edata_ptr + avctx->extradata_size;
     int extradata_size = avctx->extradata_size;
     int s = 0;
+    unsigned int channel_mask = 0;
     q->avctx = avctx;
 
     /* Take care of the codec specific extradata. */
@@ -1155,8 +1165,25 @@ static av_cold int cook_decode_init(AVCodecContext *avctx)
                 }
                 break;
             case MC_COOK:
-                av_log(avctx,AV_LOG_ERROR,"MC_COOK not supported!\n");
-                return -1;
+                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);
+
+                if(cook_count_channels(q->subpacket[s].channel_mask) > 1){
+                    q->subpacket[s].total_subbands = q->subpacket[s].subbands + q->subpacket[s].js_subband_start;
+                    q->subpacket[s].joint_stereo = 1;
+                    q->subpacket[s].num_channels = 2;
+                    q->subpacket[s].samples_per_channel = q->subpacket[s].samples_per_frame >> 1;
+
+                    if (q->subpacket[s].samples_per_channel > 256) {
+                        q->subpacket[s].log2_numvector_size  = 6;
+                    }
+                    if (q->subpacket[s].samples_per_channel > 512) {
+                        q->subpacket[s].log2_numvector_size  = 7;
+                    }
+                }else
+                    q->subpacket[s].samples_per_channel = q->subpacket[s].samples_per_frame;
+
                 break;
             default:
                 av_log(avctx,AV_LOG_ERROR,"Unknown Cook version, report sample!\n");
@@ -1196,6 +1223,10 @@ static av_cold int cook_decode_init(AVCodecContext *avctx)
 
         q->num_subpackets++;
         s++;
+        if (s > MAX_SUBPACKETS) {
+            av_log(avctx,AV_LOG_ERROR,"Too many subpackets > 5, report file!\n");
+            return -1;
+        }
     }
     /* Generate tables */
     init_pow2table();
@@ -1240,7 +1271,10 @@ static av_cold int cook_decode_init(AVCodecContext *avctx)
     }
 
     avctx->sample_fmt = SAMPLE_FMT_S16;
-    avctx->channel_layout = (avctx->channels==2) ? CH_LAYOUT_STEREO : CH_LAYOUT_MONO;
+    if (channel_mask)
+        avctx->channel_layout = channel_mask;
+    else
+        avctx->channel_layout = (avctx->channels==2) ? CH_LAYOUT_STEREO : CH_LAYOUT_MONO;
 
 #ifdef COOKDEBUG
     dump_cook_context(q);