comparison cook.c @ 4430:407e7fd9b4f4 libavcodec

Get rid of the COOKextradata struct. And use valid C to parse the extradata.
author banan
date Mon, 29 Jan 2007 10:32:14 +0000
parents ba087eea0a53
children 85ac154efd99
comparison
equal deleted inserted replaced
4429:ba087eea0a53 4430:407e7fd9b4f4
49 49
50 #include "avcodec.h" 50 #include "avcodec.h"
51 #include "bitstream.h" 51 #include "bitstream.h"
52 #include "dsputil.h" 52 #include "dsputil.h"
53 #include "common.h" 53 #include "common.h"
54 #include "bytestream.h"
54 55
55 #include "cookdata.h" 56 #include "cookdata.h"
56 57
57 /* the different Cook versions */ 58 /* the different Cook versions */
58 #define MONO 0x1000001 59 #define MONO 0x1000001
66 typedef struct { 67 typedef struct {
67 int size; 68 int size;
68 int qidx_table1[8]; 69 int qidx_table1[8];
69 int qidx_table2[8]; 70 int qidx_table2[8];
70 } COOKgain; 71 } COOKgain;
71
72 typedef struct __attribute__((__packed__)){
73 /* codec data start */
74 uint32_t cookversion; //in network order, bigendian
75 uint16_t samples_per_frame; //amount of samples per frame per channel, bigendian
76 uint16_t subbands; //amount of bands used in the frequency domain, bigendian
77 /* Mono extradata ends here. */
78 uint32_t unused;
79 uint16_t js_subband_start; //bigendian
80 uint16_t js_vlc_bits; //bigendian
81 /* Stereo extradata ends here. */
82 } COOKextradata;
83
84 72
85 typedef struct { 73 typedef struct {
86 GetBitContext gb; 74 GetBitContext gb;
87 /* stream data */ 75 /* stream data */
88 int nb_channels; 76 int nb_channels;
96 int numvector_size; //1 << log2_numvector_size; 84 int numvector_size; //1 << log2_numvector_size;
97 int js_subband_start; 85 int js_subband_start;
98 int total_subbands; 86 int total_subbands;
99 int num_vectors; 87 int num_vectors;
100 int bits_per_subpacket; 88 int bits_per_subpacket;
89 int cookversion;
101 /* states */ 90 /* states */
102 int random_state; 91 int random_state;
103 92
104 /* transform data */ 93 /* transform data */
105 FFTContext fft_ctx; 94 FFTContext fft_ctx;
1081 1070
1082 return avctx->block_align; 1071 return avctx->block_align;
1083 } 1072 }
1084 1073
1085 #ifdef COOKDEBUG 1074 #ifdef COOKDEBUG
1086 static void dump_cook_context(COOKContext *q, COOKextradata *e) 1075 static void dump_cook_context(COOKContext *q)
1087 { 1076 {
1088 //int i=0; 1077 //int i=0;
1089 #define PRINT(a,b) av_log(NULL,AV_LOG_ERROR," %s = %d\n", a, b); 1078 #define PRINT(a,b) av_log(NULL,AV_LOG_ERROR," %s = %d\n", a, b);
1090 av_log(NULL,AV_LOG_ERROR,"COOKextradata\n"); 1079 av_log(NULL,AV_LOG_ERROR,"COOKextradata\n");
1091 av_log(NULL,AV_LOG_ERROR,"cookversion=%x\n",e->cookversion); 1080 av_log(NULL,AV_LOG_ERROR,"cookversion=%x\n",q->cookversion);
1092 if (e->cookversion > STEREO) { 1081 if (q->cookversion > STEREO) {
1093 PRINT("js_subband_start",e->js_subband_start); 1082 PRINT("js_subband_start",q->js_subband_start);
1094 PRINT("js_vlc_bits",e->js_vlc_bits); 1083 PRINT("js_vlc_bits",q->js_vlc_bits);
1095 } 1084 }
1096 av_log(NULL,AV_LOG_ERROR,"COOKContext\n"); 1085 av_log(NULL,AV_LOG_ERROR,"COOKContext\n");
1097 PRINT("nb_channels",q->nb_channels); 1086 PRINT("nb_channels",q->nb_channels);
1098 PRINT("bit_rate",q->bit_rate); 1087 PRINT("bit_rate",q->bit_rate);
1099 PRINT("sample_rate",q->sample_rate); 1088 PRINT("sample_rate",q->sample_rate);
1115 * @param avctx pointer to the AVCodecContext 1104 * @param avctx pointer to the AVCodecContext
1116 */ 1105 */
1117 1106
1118 static int cook_decode_init(AVCodecContext *avctx) 1107 static int cook_decode_init(AVCodecContext *avctx)
1119 { 1108 {
1120 COOKextradata *e = (COOKextradata *)avctx->extradata;
1121 COOKContext *q = avctx->priv_data; 1109 COOKContext *q = avctx->priv_data;
1110 uint8_t *edata_ptr = avctx->extradata;
1122 1111
1123 /* Take care of the codec specific extradata. */ 1112 /* Take care of the codec specific extradata. */
1124 if (avctx->extradata_size <= 0) { 1113 if (avctx->extradata_size <= 0) {
1125 av_log(avctx,AV_LOG_ERROR,"Necessary extradata missing!\n"); 1114 av_log(avctx,AV_LOG_ERROR,"Necessary extradata missing!\n");
1126 return -1; 1115 return -1;
1127 } else { 1116 } else {
1128 /* 8 for mono, 16 for stereo, ? for multichannel 1117 /* 8 for mono, 16 for stereo, ? for multichannel
1129 Swap to right endianness so we don't need to care later on. */ 1118 Swap to right endianness so we don't need to care later on. */
1130 av_log(avctx,AV_LOG_DEBUG,"codecdata_length=%d\n",avctx->extradata_size); 1119 av_log(avctx,AV_LOG_DEBUG,"codecdata_length=%d\n",avctx->extradata_size);
1131 if (avctx->extradata_size >= 8){ 1120 if (avctx->extradata_size >= 8){
1132 e->cookversion = be2me_32(e->cookversion); 1121 q->cookversion = be2me_32(bytestream_get_le32(&edata_ptr));
1133 e->samples_per_frame = be2me_16(e->samples_per_frame); 1122 q->samples_per_frame = be2me_16(bytestream_get_le16(&edata_ptr));
1134 e->subbands = be2me_16(e->subbands); 1123 q->subbands = be2me_16(bytestream_get_le16(&edata_ptr));
1135 } 1124 }
1136 if (avctx->extradata_size >= 16){ 1125 if (avctx->extradata_size >= 16){
1137 e->js_subband_start = be2me_16(e->js_subband_start); 1126 bytestream_get_le32(&edata_ptr); //Unknown unused
1138 e->js_vlc_bits = be2me_16(e->js_vlc_bits); 1127 q->js_subband_start = be2me_16(bytestream_get_le16(&edata_ptr));
1128 q->js_vlc_bits = be2me_16(bytestream_get_le16(&edata_ptr));
1139 } 1129 }
1140 } 1130 }
1141 1131
1142 /* Take data from the AVCodecContext (RM container). */ 1132 /* Take data from the AVCodecContext (RM container). */
1143 q->sample_rate = avctx->sample_rate; 1133 q->sample_rate = avctx->sample_rate;
1146 1136
1147 /* Initialize state. */ 1137 /* Initialize state. */
1148 q->random_state = 1; 1138 q->random_state = 1;
1149 1139
1150 /* Initialize extradata related variables. */ 1140 /* Initialize extradata related variables. */
1151 q->samples_per_channel = e->samples_per_frame / q->nb_channels; 1141 q->samples_per_channel = q->samples_per_frame / q->nb_channels;
1152 q->samples_per_frame = e->samples_per_frame;
1153 q->subbands = e->subbands;
1154 q->bits_per_subpacket = avctx->block_align * 8; 1142 q->bits_per_subpacket = avctx->block_align * 8;
1155 1143
1156 /* Initialize default data states. */ 1144 /* Initialize default data states. */
1157 q->js_subband_start = 0;
1158 q->log2_numvector_size = 5; 1145 q->log2_numvector_size = 5;
1159 q->total_subbands = q->subbands; 1146 q->total_subbands = q->subbands;
1160 1147
1161 /* Initialize version-dependent variables */ 1148 /* Initialize version-dependent variables */
1162 av_log(NULL,AV_LOG_DEBUG,"e->cookversion=%x\n",e->cookversion); 1149 av_log(NULL,AV_LOG_DEBUG,"q->cookversion=%x\n",q->cookversion);
1163 q->joint_stereo = 0; 1150 q->joint_stereo = 0;
1164 switch (e->cookversion) { 1151 switch (q->cookversion) {
1165 case MONO: 1152 case MONO:
1166 if (q->nb_channels != 1) { 1153 if (q->nb_channels != 1) {
1167 av_log(avctx,AV_LOG_ERROR,"Container channels != 1, report sample!\n"); 1154 av_log(avctx,AV_LOG_ERROR,"Container channels != 1, report sample!\n");
1168 return -1; 1155 return -1;
1169 } 1156 }
1180 av_log(avctx,AV_LOG_ERROR,"Container channels != 2, report sample!\n"); 1167 av_log(avctx,AV_LOG_ERROR,"Container channels != 2, report sample!\n");
1181 return -1; 1168 return -1;
1182 } 1169 }
1183 av_log(avctx,AV_LOG_DEBUG,"JOINT_STEREO\n"); 1170 av_log(avctx,AV_LOG_DEBUG,"JOINT_STEREO\n");
1184 if (avctx->extradata_size >= 16){ 1171 if (avctx->extradata_size >= 16){
1185 q->total_subbands = q->subbands + e->js_subband_start; 1172 q->total_subbands = q->subbands + q->js_subband_start;
1186 q->js_subband_start = e->js_subband_start;
1187 q->joint_stereo = 1; 1173 q->joint_stereo = 1;
1188 q->js_vlc_bits = e->js_vlc_bits;
1189 } 1174 }
1190 if (q->samples_per_channel > 256) { 1175 if (q->samples_per_channel > 256) {
1191 q->log2_numvector_size = 6; 1176 q->log2_numvector_size = 6;
1192 } 1177 }
1193 if (q->samples_per_channel > 512) { 1178 if (q->samples_per_channel > 512) {
1260 av_log(avctx,AV_LOG_ERROR,"unknown amount of samples_per_channel = %d, report sample!\n",q->samples_per_channel); 1245 av_log(avctx,AV_LOG_ERROR,"unknown amount of samples_per_channel = %d, report sample!\n",q->samples_per_channel);
1261 return -1; 1246 return -1;
1262 } 1247 }
1263 1248
1264 #ifdef COOKDEBUG 1249 #ifdef COOKDEBUG
1265 dump_cook_context(q,e); 1250 dump_cook_context(q);
1266 #endif 1251 #endif
1267 return 0; 1252 return 0;
1268 } 1253 }
1269 1254
1270 1255