summaryrefslogtreecommitdiff
path: root/apps/codecs/libwmapro/wmaprodec.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/codecs/libwmapro/wmaprodec.c')
-rw-r--r--apps/codecs/libwmapro/wmaprodec.c71
1 files changed, 35 insertions, 36 deletions
diff --git a/apps/codecs/libwmapro/wmaprodec.c b/apps/codecs/libwmapro/wmaprodec.c
index 8a8171aeb6..2dd2a6a1e4 100644
--- a/apps/codecs/libwmapro/wmaprodec.c
+++ b/apps/codecs/libwmapro/wmaprodec.c
@@ -103,6 +103,13 @@
103/* Uncomment the following line to enable some debug output */ 103/* Uncomment the following line to enable some debug output */
104//#define WMAPRO_DUMP_CTX_EN 104//#define WMAPRO_DUMP_CTX_EN
105 105
106#undef DEBUGF
107#ifdef WMAPRO_DUMP_CTX_EN
108# define DEBUGF printf
109#else
110# define DEBUGF(...)
111#endif
112
106/* Some defines to make it compile */ 113/* Some defines to make it compile */
107#define AVERROR_INVALIDDATA -1 114#define AVERROR_INVALIDDATA -1
108#define AVERROR_PATCHWELCOME -2 115#define AVERROR_PATCHWELCOME -2
@@ -177,7 +184,6 @@ typedef struct {
177typedef struct WMAProDecodeCtx { 184typedef struct WMAProDecodeCtx {
178 /* generic decoder variables */ 185 /* generic decoder variables */
179 AVCodecContext* avctx; ///< codec context for av_log 186 AVCodecContext* avctx; ///< codec context for av_log
180 DSPContext dsp; ///< accelerated DSP functions
181 uint8_t frame_data[MAX_FRAMESIZE + 187 uint8_t frame_data[MAX_FRAMESIZE +
182 FF_INPUT_BUFFER_PADDING_SIZE];///< compressed frame data 188 FF_INPUT_BUFFER_PADDING_SIZE];///< compressed frame data
183 PutBitContext pb; ///< context for filling the frame_data buffer 189 PutBitContext pb; ///< context for filling the frame_data buffer
@@ -236,6 +242,8 @@ typedef struct WMAProDecodeCtx {
236 WMAProChannelCtx channel[WMAPRO_MAX_CHANNELS]; ///< per channel data 242 WMAProChannelCtx channel[WMAPRO_MAX_CHANNELS]; ///< per channel data
237} WMAProDecodeCtx; 243} WMAProDecodeCtx;
238 244
245/* static decode context, to avoid malloc */
246static WMAProDecodeCtx globWMAProDecCtx;
239 247
240/** 248/**
241 *@brief helper function to print the most important members of the context 249 *@brief helper function to print the most important members of the context
@@ -264,7 +272,7 @@ static void av_cold dump_context(WMAProDecodeCtx *s)
264 */ 272 */
265av_cold int decode_init(AVCodecContext *avctx) 273av_cold int decode_init(AVCodecContext *avctx)
266{ 274{
267 avctx->priv_data = malloc(sizeof(WMAProDecodeCtx)); 275 avctx->priv_data = &globWMAProDecCtx;
268 memset(avctx->priv_data, 0, sizeof(WMAProDecodeCtx)); 276 memset(avctx->priv_data, 0, sizeof(WMAProDecodeCtx));
269 WMAProDecodeCtx *s = avctx->priv_data; 277 WMAProDecodeCtx *s = avctx->priv_data;
270 uint8_t *edata_ptr = avctx->extradata; 278 uint8_t *edata_ptr = avctx->extradata;
@@ -276,8 +284,6 @@ av_cold int decode_init(AVCodecContext *avctx)
276 s->avctx = avctx; 284 s->avctx = avctx;
277 init_put_bits(&s->pb, s->frame_data, MAX_FRAMESIZE); 285 init_put_bits(&s->pb, s->frame_data, MAX_FRAMESIZE);
278 286
279 avctx->sample_fmt = SAMPLE_FMT_FLT;
280
281 if (avctx->extradata_size >= 18) { 287 if (avctx->extradata_size >= 18) {
282 s->decode_flags = AV_RL16(edata_ptr+14); 288 s->decode_flags = AV_RL16(edata_ptr+14);
283 channel_mask = AV_RL32(edata_ptr+2); 289 channel_mask = AV_RL32(edata_ptr+2);
@@ -288,7 +294,7 @@ av_cold int decode_init(AVCodecContext *avctx)
288 dprintf(avctx, "\n"); 294 dprintf(avctx, "\n");
289 295
290 } else { 296 } else {
291 av_log_ask_for_sample(avctx, "Unknown extradata size\n"); 297 DEBUGF("Unknown extradata size\n");
292 return AVERROR_INVALIDDATA; 298 return AVERROR_INVALIDDATA;
293 } 299 }
294 300
@@ -301,7 +307,7 @@ av_cold int decode_init(AVCodecContext *avctx)
301 s->len_prefix = (s->decode_flags & 0x40); 307 s->len_prefix = (s->decode_flags & 0x40);
302 308
303 if (!s->len_prefix) { 309 if (!s->len_prefix) {
304 av_log_ask_for_sample(avctx, "no length prefix\n"); 310 DEBUGF("no length prefix\n");
305 return AVERROR_INVALIDDATA; 311 return AVERROR_INVALIDDATA;
306 } 312 }
307 313
@@ -325,7 +331,7 @@ av_cold int decode_init(AVCodecContext *avctx)
325 s->dynamic_range_compression = (s->decode_flags & 0x80); 331 s->dynamic_range_compression = (s->decode_flags & 0x80);
326 332
327 if (s->max_num_subframes > MAX_SUBFRAMES) { 333 if (s->max_num_subframes > MAX_SUBFRAMES) {
328 av_log(avctx, AV_LOG_ERROR, "invalid number of subframes %i\n", 334 DEBUGF("invalid number of subframes %i\n",
329 s->max_num_subframes); 335 s->max_num_subframes);
330 return AVERROR_INVALIDDATA; 336 return AVERROR_INVALIDDATA;
331 } 337 }
@@ -344,10 +350,10 @@ av_cold int decode_init(AVCodecContext *avctx)
344 } 350 }
345 351
346 if (s->num_channels < 0) { 352 if (s->num_channels < 0) {
347 av_log(avctx, AV_LOG_ERROR, "invalid number of channels %d\n", s->num_channels); 353 DEBUGF("invalid number of channels %d\n", s->num_channels);
348 return AVERROR_INVALIDDATA; 354 return AVERROR_INVALIDDATA;
349 } else if (s->num_channels > WMAPRO_MAX_CHANNELS) { 355 } else if (s->num_channels > WMAPRO_MAX_CHANNELS) {
350 av_log_ask_for_sample(avctx, "unsupported number of channels\n"); 356 DEBUGF("unsupported number of channels\n");
351 return AVERROR_PATCHWELCOME; 357 return AVERROR_PATCHWELCOME;
352 } 358 }
353 359
@@ -437,8 +443,6 @@ av_cold int decode_init(AVCodecContext *avctx)
437#ifdef WMAPRO_DUMP_CTX_EN 443#ifdef WMAPRO_DUMP_CTX_EN
438 dump_context(s); 444 dump_context(s);
439#endif 445#endif
440
441 avctx->channel_layout = channel_mask;
442 return 0; 446 return 0;
443} 447}
444 448
@@ -469,7 +473,7 @@ static int decode_subframe_length(WMAProDecodeCtx *s, int offset)
469 /** sanity check the length */ 473 /** sanity check the length */
470 if (subframe_len < s->min_samples_per_subframe || 474 if (subframe_len < s->min_samples_per_subframe ||
471 subframe_len > s->samples_per_frame) { 475 subframe_len > s->samples_per_frame) {
472 av_log(s->avctx, AV_LOG_ERROR, "broken frame: subframe_len %i\n", 476 DEBUGF("broken frame: subframe_len %i\n",
473 subframe_len); 477 subframe_len);
474 return AVERROR_INVALIDDATA; 478 return AVERROR_INVALIDDATA;
475 } 479 }
@@ -546,16 +550,15 @@ static int decode_tilehdr(WMAProDecodeCtx *s)
546 WMAProChannelCtx* chan = &s->channel[c]; 550 WMAProChannelCtx* chan = &s->channel[c];
547 551
548 if (contains_subframe[c]) { 552 if (contains_subframe[c]) {
549 if (chan->num_subframes >= MAX_SUBFRAMES) { 553 if (chan->num_subframes >= MAX_SUBFRAMES) {
550 av_log(s->avctx, AV_LOG_ERROR, 554 DEBUGF("broken frame: num subframes > 31\n");
551 "broken frame: num subframes > 31\n");
552 return AVERROR_INVALIDDATA; 555 return AVERROR_INVALIDDATA;
553 } 556 }
554 chan->subframe_len[chan->num_subframes] = subframe_len; 557 chan->subframe_len[chan->num_subframes] = subframe_len;
555 num_samples[c] += subframe_len; 558 num_samples[c] += subframe_len;
556 ++chan->num_subframes; 559 ++chan->num_subframes;
557 if (num_samples[c] > s->samples_per_frame) { 560 if (num_samples[c] > s->samples_per_frame) {
558 av_log(s->avctx, AV_LOG_ERROR, "broken frame: " 561 DEBUGF("broken frame: "
559 "channel len > samples_per_frame\n"); 562 "channel len > samples_per_frame\n");
560 return AVERROR_INVALIDDATA; 563 return AVERROR_INVALIDDATA;
561 } 564 }
@@ -674,8 +677,7 @@ static int decode_channel_transform(WMAProDecodeCtx* s)
674 int remaining_channels = s->channels_for_cur_subframe; 677 int remaining_channels = s->channels_for_cur_subframe;
675 678
676 if (get_bits1(&s->gb)) { 679 if (get_bits1(&s->gb)) {
677 av_log_ask_for_sample(s->avctx, 680 DEBUGF("unsupported channel transform bit\n");
678 "unsupported channel transform bit\n");
679 return AVERROR_INVALIDDATA; 681 return AVERROR_INVALIDDATA;
680 } 682 }
681 683
@@ -711,8 +713,7 @@ static int decode_channel_transform(WMAProDecodeCtx* s)
711 if (chgroup->num_channels == 2) { 713 if (chgroup->num_channels == 2) {
712 if (get_bits1(&s->gb)) { 714 if (get_bits1(&s->gb)) {
713 if (get_bits1(&s->gb)) { 715 if (get_bits1(&s->gb)) {
714 av_log_ask_for_sample(s->avctx, 716 DEBUGF("unsupported channel transform type\n");
715 "unsupported channel transform type\n");
716 } 717 }
717 } else { 718 } else {
718 chgroup->transform = 1; 719 chgroup->transform = 1;
@@ -730,7 +731,7 @@ static int decode_channel_transform(WMAProDecodeCtx* s)
730 } 731 }
731 } 732 }
732 } else if (chgroup->num_channels > 2) { 733 } else if (chgroup->num_channels > 2) {
733 LOGF("in wmaprodec.c: Multichannel streams still not supported\n"); 734 DEBUGF("in wmaprodec.c: Multichannel streams still not supported\n");
734 return -1; 735 return -1;
735#if 0 736#if 0
736 if (get_bits1(&s->gb)) { 737 if (get_bits1(&s->gb)) {
@@ -857,7 +858,7 @@ static int decode_coeffs(WMAProDecodeCtx *s, int c)
857 memset(&ci->coeffs[cur_coeff], 0, 858 memset(&ci->coeffs[cur_coeff], 0,
858 sizeof(*ci->coeffs) * (s->subframe_len - cur_coeff)); 859 sizeof(*ci->coeffs) * (s->subframe_len - cur_coeff));
859 860
860 if (ff_wma_run_level_decode(s->avctx, &s->gb, vlc, 861 if (ff_wma_run_level_decode(&s->gb, vlc,
861 level, run, 1, ci->coeffs, 862 level, run, 1, ci->coeffs,
862 cur_coeff, s->subframe_len, 863 cur_coeff, s->subframe_len,
863 s->subframe_len, s->esc_len, 0)) 864 s->subframe_len, s->esc_len, 0))
@@ -937,8 +938,7 @@ static int decode_scale_factors(WMAProDecodeCtx* s)
937 938
938 i += skip; 939 i += skip;
939 if (i >= s->num_bands) { 940 if (i >= s->num_bands) {
940 av_log(s->avctx, AV_LOG_ERROR, 941 DEBUGF("invalid scale factor coding\n");
941 "invalid scale factor coding\n");
942 return AVERROR_INVALIDDATA; 942 return AVERROR_INVALIDDATA;
943 } 943 }
944 s->channel[c].scale_factors[i] += (val ^ sign) - sign; 944 s->channel[c].scale_factors[i] += (val ^ sign) - sign;
@@ -1137,7 +1137,7 @@ static int decode_subframe(WMAProDecodeCtx *s)
1137 1137
1138 if (num_fill_bits >= 0) { 1138 if (num_fill_bits >= 0) {
1139 if (get_bits_count(&s->gb) + num_fill_bits > s->num_saved_bits) { 1139 if (get_bits_count(&s->gb) + num_fill_bits > s->num_saved_bits) {
1140 av_log(s->avctx, AV_LOG_ERROR, "invalid number of fill bits\n"); 1140 DEBUGF("invalid number of fill bits\n");
1141 return AVERROR_INVALIDDATA; 1141 return AVERROR_INVALIDDATA;
1142 } 1142 }
1143 1143
@@ -1147,7 +1147,7 @@ static int decode_subframe(WMAProDecodeCtx *s)
1147 1147
1148 /** no idea for what the following bit is used */ 1148 /** no idea for what the following bit is used */
1149 if (get_bits1(&s->gb)) { 1149 if (get_bits1(&s->gb)) {
1150 av_log_ask_for_sample(s->avctx, "reserved bit set\n"); 1150 DEBUGF("reserved bit set\n");
1151 return AVERROR_INVALIDDATA; 1151 return AVERROR_INVALIDDATA;
1152 } 1152 }
1153 1153
@@ -1165,7 +1165,7 @@ static int decode_subframe(WMAProDecodeCtx *s)
1165 int quant_step = 90 * s->bits_per_sample >> 4; 1165 int quant_step = 90 * s->bits_per_sample >> 4;
1166 if ((get_bits1(&s->gb))) { 1166 if ((get_bits1(&s->gb))) {
1167 /** FIXME: might change run level mode decision */ 1167 /** FIXME: might change run level mode decision */
1168 av_log_ask_for_sample(s->avctx, "unsupported quant step coding\n"); 1168 DEBUGF("unsupported quant step coding\n");
1169 return AVERROR_INVALIDDATA; 1169 return AVERROR_INVALIDDATA;
1170 } 1170 }
1171 /** decode quantization step */ 1171 /** decode quantization step */
@@ -1181,7 +1181,7 @@ static int decode_subframe(WMAProDecodeCtx *s)
1181 quant_step += ((quant + step) ^ sign) - sign; 1181 quant_step += ((quant + step) ^ sign) - sign;
1182 } 1182 }
1183 if (quant_step < 0) { 1183 if (quant_step < 0) {
1184 av_log(s->avctx, AV_LOG_DEBUG, "negative quant step\n"); 1184 DEBUGF("negative quant step\n");
1185 } 1185 }
1186 1186
1187 /** decode quantization step modifiers for every channel */ 1187 /** decode quantization step modifiers for every channel */
@@ -1245,7 +1245,7 @@ static int decode_subframe(WMAProDecodeCtx *s)
1245 s->channel[c].scale_factor_step; 1245 s->channel[c].scale_factor_step;
1246 1246
1247 if(exp < EXP_MIN || exp > EXP_MAX) { 1247 if(exp < EXP_MIN || exp > EXP_MAX) {
1248 LOGF("in wmaprodec.c : unhandled value for exp, please report sample.\n"); 1248 DEBUGF("in wmaprodec.c : unhandled value for exp, please report sample.\n");
1249 return -1; 1249 return -1;
1250 } 1250 }
1251 const FIXED quant = QUANT(exp); 1251 const FIXED quant = QUANT(exp);
@@ -1272,7 +1272,7 @@ static int decode_subframe(WMAProDecodeCtx *s)
1272 for (i = 0; i < s->channels_for_cur_subframe; i++) { 1272 for (i = 0; i < s->channels_for_cur_subframe; i++) {
1273 int c = s->channel_indexes_for_cur_subframe[i]; 1273 int c = s->channel_indexes_for_cur_subframe[i];
1274 if (s->channel[c].cur_subframe >= s->channel[c].num_subframes) { 1274 if (s->channel[c].cur_subframe >= s->channel[c].num_subframes) {
1275 av_log(s->avctx, AV_LOG_ERROR, "broken subframe\n"); 1275 DEBUGF("broken subframe\n");
1276 return AVERROR_INVALIDDATA; 1276 return AVERROR_INVALIDDATA;
1277 } 1277 }
1278 ++s->channel[c].cur_subframe; 1278 ++s->channel[c].cur_subframe;
@@ -1297,8 +1297,7 @@ static int decode_frame(WMAProDecodeCtx *s)
1297 /** check for potential output buffer overflow */ 1297 /** check for potential output buffer overflow */
1298 if (s->num_channels * s->samples_per_frame > s->samples_end - s->samples) { 1298 if (s->num_channels * s->samples_per_frame > s->samples_end - s->samples) {
1299 /** return an error if no frame could be decoded at all */ 1299 /** return an error if no frame could be decoded at all */
1300 av_log(s->avctx, AV_LOG_ERROR, 1300 DEBUGF("not enough space for the output samples\n");
1301 "not enough space for the output samples\n");
1302 s->packet_loss = 1; 1301 s->packet_loss = 1;
1303 return 0; 1302 return 0;
1304 } 1303 }
@@ -1317,7 +1316,7 @@ static int decode_frame(WMAProDecodeCtx *s)
1317 1316
1318 /** read postproc transform */ 1317 /** read postproc transform */
1319 if (s->num_channels > 1 && get_bits1(gb)) { 1318 if (s->num_channels > 1 && get_bits1(gb)) {
1320 av_log_ask_for_sample(s->avctx, "Unsupported postproc transform found\n"); 1319 DEBUGF("Unsupported postproc transform found\n");
1321 s->packet_loss = 1; 1320 s->packet_loss = 1;
1322 return 0; 1321 return 0;
1323 } 1322 }
@@ -1391,7 +1390,7 @@ static int decode_frame(WMAProDecodeCtx *s)
1391 1390
1392 if (len != (get_bits_count(gb) - s->frame_offset) + 2) { 1391 if (len != (get_bits_count(gb) - s->frame_offset) + 2) {
1393 /** FIXME: not sure if this is always an error */ 1392 /** FIXME: not sure if this is always an error */
1394 av_log(s->avctx, AV_LOG_ERROR, "frame[%i] would have to skip %i bits\n", 1393 DEBUGF("frame[%i] would have to skip %i bits\n",
1395 (int)s->frame_num, len - (get_bits_count(gb) - s->frame_offset) - 1); 1394 (int)s->frame_num, len - (get_bits_count(gb) - s->frame_offset) - 1);
1396 s->packet_loss = 1; 1395 s->packet_loss = 1;
1397 return 0; 1396 return 0;
@@ -1443,7 +1442,7 @@ static void save_bits(WMAProDecodeCtx *s, GetBitContext* gb, int len,
1443 buflen = (s->num_saved_bits + len + 8) >> 3; 1442 buflen = (s->num_saved_bits + len + 8) >> 3;
1444 1443
1445 if (len <= 0 || buflen > MAX_FRAMESIZE) { 1444 if (len <= 0 || buflen > MAX_FRAMESIZE) {
1446 av_log_ask_for_sample(s->avctx, "input buffer too small\n"); 1445 DEBUGF("input buffer too small\n");
1447 s->packet_loss = 1; 1446 s->packet_loss = 1;
1448 return; 1447 return;
1449 } 1448 }
@@ -1516,7 +1515,7 @@ int decode_packet(AVCodecContext *avctx,
1516 if (!s->packet_loss && 1515 if (!s->packet_loss &&
1517 ((s->packet_sequence_number + 1) & 0xF) != packet_sequence_number) { 1516 ((s->packet_sequence_number + 1) & 0xF) != packet_sequence_number) {
1518 s->packet_loss = 1; 1517 s->packet_loss = 1;
1519 av_log(avctx, AV_LOG_ERROR, "Packet loss detected! seq %x vs %x\n", 1518 DEBUGF("Packet loss detected! seq %x vs %x\n",
1520 s->packet_sequence_number, packet_sequence_number); 1519 s->packet_sequence_number, packet_sequence_number);
1521 } 1520 }
1522 s->packet_sequence_number = packet_sequence_number; 1521 s->packet_sequence_number = packet_sequence_number;