comparison cook.c @ 2959:24805f4d1b84 libavcodec

This patch adds some support for non-joint stereo streams. It also removes some fixmes. Patch by Benjamin Larsson
author rtognimp
date Sun, 11 Dec 2005 00:56:39 +0000
parents 5f51b1e0bed6
children f5898b9b8a8a
comparison
equal deleted inserted replaced
2958:e04773e8b253 2959:24805f4d1b84
983 983
984 decode_bytes(inbuffer, q->decoded_bytes_buffer, sub_packet_size); 984 decode_bytes(inbuffer, q->decoded_bytes_buffer, sub_packet_size);
985 init_get_bits(&q->gb, q->decoded_bytes_buffer, sub_packet_size*8); 985 init_get_bits(&q->gb, q->decoded_bytes_buffer, sub_packet_size*8);
986 decode_gain_info(&q->gb, &q->gain_current); 986 decode_gain_info(&q->gb, &q->gain_current);
987 memcpy(&q->gain_copy, &q->gain_current ,sizeof(COOKgain)); //This copy does not seem to be used. FIXME 987 memcpy(&q->gain_copy, &q->gain_current ,sizeof(COOKgain)); //This copy does not seem to be used. FIXME
988 //fprintf(stdout,"cu bits ds = %d\n",get_bits_count(&q->gb)); 988
989 if(q->nb_channels==2 && q->joint_stereo==1){ 989 if(q->nb_channels==2 && q->joint_stereo==1){
990 joint_decode(q, q->decode_buf_ptr[0], q->decode_buf_ptr[2]); 990 joint_decode(q, q->decode_buf_ptr[0], q->decode_buf_ptr[2]);
991 991
992 /* Swap buffer pointers. */ 992 /* Swap buffer pointers. */
993 tmp_ptr = q->decode_buf_ptr[1]; 993 tmp_ptr = q->decode_buf_ptr[1];
1023 1023
1024 memcpy(&q->gain_now, &q->gain_previous, sizeof(COOKgain)); 1024 memcpy(&q->gain_now, &q->gain_previous, sizeof(COOKgain));
1025 memcpy(&q->gain_previous, &q->gain_current, sizeof(COOKgain)); 1025 memcpy(&q->gain_previous, &q->gain_current, sizeof(COOKgain));
1026 1026
1027 } else if (q->nb_channels==2 && q->joint_stereo==0) { 1027 } else if (q->nb_channels==2 && q->joint_stereo==0) {
1028 for (i=0 ; i<q->nb_channels ; i++){ 1028 /* channel 0 */
1029 mono_decode(q, q->decode_buf_ptr[0]); 1029 mono_decode(q, q->decode_buf_ptr[0]);
1030 1030
1031 av_log(NULL,AV_LOG_ERROR,"Non-joint-stereo files are not supported at the moment, do not report as a bug!\n");
1032 tmp_ptr = q->decode_buf_ptr[0]; 1031 tmp_ptr = q->decode_buf_ptr[0];
1033 q->decode_buf_ptr[0] = q->decode_buf_ptr[1]; 1032 q->decode_buf_ptr[0] = q->decode_buf_ptr[1];
1034 q->decode_buf_ptr[1] = q->decode_buf_ptr[2]; 1033 q->decode_buf_ptr[1] = q->decode_buf_ptr[2];
1035 q->decode_buf_ptr[2] = q->decode_buf_ptr[3]; 1034 q->decode_buf_ptr[2] = q->decode_buf_ptr[3];
1036 q->decode_buf_ptr[3] = tmp_ptr; 1035 q->decode_buf_ptr[3] = tmp_ptr;
1048 1047
1049 for (j=0 ; j<q->samples_per_frame ; j++){ 1048 for (j=0 ; j<q->samples_per_frame ; j++){
1050 value = lrintf(q->mono_mdct_output[j]); 1049 value = lrintf(q->mono_mdct_output[j]);
1051 if(value < -32768) value = -32768; 1050 if(value < -32768) value = -32768;
1052 else if(value > 32767) value = 32767; 1051 else if(value > 32767) value = 32767;
1053 outbuffer[2*j+i] = value; 1052 outbuffer[2*j+1] = value;
1054 } 1053 }
1054
1055 /* channel 1 */
1056 //av_log(NULL,AV_LOG_ERROR,"bits = %d\n",get_bits_count(&q->gb));
1057 init_get_bits(&q->gb, q->decoded_bytes_buffer, sub_packet_size*8+q->bits_per_subpacket);
1058 decode_gain_info(&q->gb, &q->gain_current);
1059 //memcpy(&q->gain_copy, &q->gain_current ,sizeof(COOKgain));
1060 mono_decode(q, q->decode_buf_ptr[0]);
1061 tmp_ptr = q->decode_buf_ptr[0];
1062 q->decode_buf_ptr[1] = q->decode_buf_ptr[2];
1063 q->decode_buf_ptr[2] = q->decode_buf_ptr[3];
1064 q->decode_buf_ptr[3] = tmp_ptr;
1065
1066 q->gain_now_ptr = &q->gain_now;
1067 q->gain_previous_ptr = &q->gain_previous;
1068
1069 cook_imlt(q, q->decode_buf_ptr[0], q->mono_mdct_output,q->mlt_tmp);
1070 gain_compensate(q, q->mono_mdct_output, q->gain_now_ptr, q->gain_previous_ptr, q->previous_buffer_ptr[0]);
1071
1072 /* Swap out the previous buffer. */
1073 tmp_ptr = q->previous_buffer_ptr[0];
1074 q->previous_buffer_ptr[0] = q->previous_buffer_ptr[1];
1075 q->previous_buffer_ptr[1] = tmp_ptr;
1076
1077 for (j=0 ; j<q->samples_per_frame ; j++){
1078 value = lrintf(q->mono_mdct_output[j]);
1079 if(value < -32768) value = -32768;
1080 else if(value > 32767) value = 32767;
1081 outbuffer[2*j] = value;
1082 }
1083
1084
1085 /* Swap out the previous buffer. */
1055 memcpy(&q->gain_now, &q->gain_previous, sizeof(COOKgain)); 1086 memcpy(&q->gain_now, &q->gain_previous, sizeof(COOKgain));
1056 memcpy(&q->gain_previous, &q->gain_current, sizeof(COOKgain)); 1087 memcpy(&q->gain_previous, &q->gain_current, sizeof(COOKgain));
1057 } 1088
1058 } else { 1089 } else {
1059 mono_decode(q, q->decode_buf_ptr[0]); 1090 mono_decode(q, q->decode_buf_ptr[0]);
1060 1091
1061 /* Swap buffer pointers. */ 1092 /* Swap buffer pointers. */
1062 tmp_ptr = q->decode_buf_ptr[1]; 1093 tmp_ptr = q->decode_buf_ptr[1];
1080 outbuffer[j] = value; 1111 outbuffer[j] = value;
1081 } 1112 }
1082 memcpy(&q->gain_now, &q->gain_previous, sizeof(COOKgain)); 1113 memcpy(&q->gain_now, &q->gain_previous, sizeof(COOKgain));
1083 memcpy(&q->gain_previous, &q->gain_current, sizeof(COOKgain)); 1114 memcpy(&q->gain_previous, &q->gain_current, sizeof(COOKgain));
1084 } 1115 }
1085 /* FIXME: Shouldn't the total number of bytes be returned? */ 1116 return q->samples_per_frame * sizeof(int16_t);
1086 return /*q->nb_channels*/ q->samples_per_frame * sizeof(int16_t);
1087 } 1117 }
1088 1118
1089 1119
1090 /** 1120 /**
1091 * Cook frame decoding 1121 * Cook frame decoding
1094 */ 1124 */
1095 1125
1096 static int cook_decode_frame(AVCodecContext *avctx, 1126 static int cook_decode_frame(AVCodecContext *avctx,
1097 void *data, int *data_size, 1127 void *data, int *data_size,
1098 uint8_t *buf, int buf_size) { 1128 uint8_t *buf, int buf_size) {
1099 /* This stuff is quite messy, the Cook packets are sent unordered
1100 * and need to be ordered before they are sent to the rest of the
1101 * decoder. The order can be found in the q->frame_reorder_index.
1102 * Currently decoding of the last packets is not handled at
1103 * all. FIXME */
1104
1105 COOKContext *q = avctx->priv_data; 1129 COOKContext *q = avctx->priv_data;
1106 1130
1107 if (buf_size < avctx->block_align) 1131 if (buf_size < avctx->block_align)
1108 return buf_size; 1132 return buf_size;
1109 1133
1199 av_log(NULL,AV_LOG_DEBUG,"MONO_COOK1\n"); 1223 av_log(NULL,AV_LOG_DEBUG,"MONO_COOK1\n");
1200 break; 1224 break;
1201 case MONO_COOK2: 1225 case MONO_COOK2:
1202 if (q->nb_channels != 1) { 1226 if (q->nb_channels != 1) {
1203 q->joint_stereo = 0; 1227 q->joint_stereo = 0;
1204 av_log(NULL,AV_LOG_ERROR,"Non-joint-stereo files are not supported at the moment!\n"); 1228 av_log(NULL,AV_LOG_ERROR,"Non-joint-stereo files are decoded with wrong gain at the moment!\n");
1205 return -1; 1229 q->bits_per_subpacket = q->bits_per_subpacket/2;
1230
1206 } 1231 }
1207 av_log(NULL,AV_LOG_DEBUG,"MONO_COOK2\n"); 1232 av_log(NULL,AV_LOG_DEBUG,"MONO_COOK2\n");
1208 break; 1233 break;
1209 case JOINT_STEREO: 1234 case JOINT_STEREO:
1210 if (q->nb_channels != 2) { 1235 if (q->nb_channels != 2) {