[Ffmpeg-cvslog] CVS: ffmpeg/libavcodec cook.c,1.1,1.2

Roberto Togni CVS rtognimp
Sun Dec 11 01:56:41 CET 2005


Update of /cvsroot/ffmpeg/ffmpeg/libavcodec
In directory mail:/var2/tmp/cvs-serv16763

Modified Files:
	cook.c 
Log Message:
This patch adds some support for non-joint stereo streams. It also
removes some fixmes.
Patch by Benjamin Larsson


Index: cook.c
===================================================================
RCS file: /cvsroot/ffmpeg/ffmpeg/libavcodec/cook.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- cook.c	9 Dec 2005 16:08:18 -0000	1.1
+++ cook.c	11 Dec 2005 00:56:39 -0000	1.2
@@ -985,7 +985,7 @@
     init_get_bits(&q->gb, q->decoded_bytes_buffer, sub_packet_size*8);
     decode_gain_info(&q->gb, &q->gain_current);
     memcpy(&q->gain_copy, &q->gain_current ,sizeof(COOKgain));  //This copy does not seem to be used. FIXME
-    //fprintf(stdout,"cu bits ds = %d\n",get_bits_count(&q->gb));
+
     if(q->nb_channels==2 && q->joint_stereo==1){
         joint_decode(q, q->decode_buf_ptr[0], q->decode_buf_ptr[2]);
 
@@ -1025,10 +1025,9 @@
         memcpy(&q->gain_previous, &q->gain_current, sizeof(COOKgain));
 
     } else if (q->nb_channels==2 && q->joint_stereo==0) {
-        for (i=0 ; i<q->nb_channels ; i++){
+            /* channel 0 */
             mono_decode(q, q->decode_buf_ptr[0]);
 
-            av_log(NULL,AV_LOG_ERROR,"Non-joint-stereo files are not supported at the moment, do not report as a bug!\n");
             tmp_ptr = q->decode_buf_ptr[0];
             q->decode_buf_ptr[0] = q->decode_buf_ptr[1];
             q->decode_buf_ptr[1] = q->decode_buf_ptr[2];
@@ -1050,11 +1049,43 @@
                 value = lrintf(q->mono_mdct_output[j]);
                 if(value < -32768) value = -32768;
                 else if(value > 32767) value = 32767;
-                outbuffer[2*j+i] = value;
+                outbuffer[2*j+1] = value;
             }
+
+            /* channel 1 */
+            //av_log(NULL,AV_LOG_ERROR,"bits = %d\n",get_bits_count(&q->gb));
+            init_get_bits(&q->gb, q->decoded_bytes_buffer, sub_packet_size*8+q->bits_per_subpacket);
+            decode_gain_info(&q->gb, &q->gain_current);
+            //memcpy(&q->gain_copy, &q->gain_current ,sizeof(COOKgain));
+            mono_decode(q, q->decode_buf_ptr[0]);
+            tmp_ptr = q->decode_buf_ptr[0];
+            q->decode_buf_ptr[1] = q->decode_buf_ptr[2];
+            q->decode_buf_ptr[2] = q->decode_buf_ptr[3];
+            q->decode_buf_ptr[3] = tmp_ptr;
+
+            q->gain_now_ptr = &q->gain_now;
+            q->gain_previous_ptr = &q->gain_previous;
+
+            cook_imlt(q, q->decode_buf_ptr[0], q->mono_mdct_output,q->mlt_tmp);
+            gain_compensate(q, q->mono_mdct_output, q->gain_now_ptr, q->gain_previous_ptr, q->previous_buffer_ptr[0]);
+
+            /* Swap out the previous buffer. */
+            tmp_ptr = q->previous_buffer_ptr[0];
+            q->previous_buffer_ptr[0] = q->previous_buffer_ptr[1];
+            q->previous_buffer_ptr[1] = tmp_ptr;
+
+            for (j=0 ; j<q->samples_per_frame ; j++){
+                value = lrintf(q->mono_mdct_output[j]);
+                if(value < -32768) value = -32768;
+                else if(value > 32767) value = 32767;
+                outbuffer[2*j] = value;
+            }
+
+
+            /* Swap out the previous buffer. */
             memcpy(&q->gain_now, &q->gain_previous, sizeof(COOKgain));
             memcpy(&q->gain_previous, &q->gain_current, sizeof(COOKgain));
-        }
+
     } else {
         mono_decode(q, q->decode_buf_ptr[0]);
 
@@ -1082,8 +1113,7 @@
         memcpy(&q->gain_now, &q->gain_previous, sizeof(COOKgain));
         memcpy(&q->gain_previous, &q->gain_current, sizeof(COOKgain));
     }
-    /* FIXME: Shouldn't the total number of bytes be returned? */
-    return /*q->nb_channels*/ q->samples_per_frame * sizeof(int16_t);
+    return q->samples_per_frame * sizeof(int16_t);
 }
 
 
@@ -1096,12 +1126,6 @@
 static int cook_decode_frame(AVCodecContext *avctx,
             void *data, int *data_size,
             uint8_t *buf, int buf_size) {
-    /* This stuff is quite messy, the Cook packets are sent unordered
-     * and need to be ordered before they are sent to the rest of the
-     * decoder. The order can be found in the q->frame_reorder_index.
-     * Currently decoding of the last packets is not handled at
-     * all. FIXME */
-
     COOKContext *q = avctx->priv_data;
 
     if (buf_size < avctx->block_align)
@@ -1201,8 +1225,9 @@
         case MONO_COOK2:
             if (q->nb_channels != 1) {
                 q->joint_stereo = 0;
-                av_log(NULL,AV_LOG_ERROR,"Non-joint-stereo files are not supported at the moment!\n");
-                return -1;
+                av_log(NULL,AV_LOG_ERROR,"Non-joint-stereo files are decoded with wrong gain at the moment!\n");
+                q->bits_per_subpacket = q->bits_per_subpacket/2;
+
             }
             av_log(NULL,AV_LOG_DEBUG,"MONO_COOK2\n");
             break;





More information about the ffmpeg-cvslog mailing list