summaryrefslogtreecommitdiff
path: root/apps/codecs/libwmapro/wmaprodec.c
diff options
context:
space:
mode:
authorMohamed Tarek <mt@rockbox.org>2010-06-21 10:48:34 +0000
committerMohamed Tarek <mt@rockbox.org>2010-06-21 10:48:34 +0000
commit816fca820caa537a07c761f49d1f8ecf996a91ce (patch)
tree8ea2805d0536bd45c7a4f56fa39904e65829466a /apps/codecs/libwmapro/wmaprodec.c
parent9297a02d4964cae7727248665e278b251cac5533 (diff)
downloadrockbox-816fca820caa537a07c761f49d1f8ecf996a91ce.tar.gz
rockbox-816fca820caa537a07c761f49d1f8ecf996a91ce.zip
Wrote apps/codecs/wmapro.c and modified libwmapro to make the codec work in the sim. Neither libwmapro nor wmapro.c have been added to the main build yet, codecs.make should be edited to compile both with rockbox.
current status of the decoder : - Plays and seeks in the sim - Still in floating point git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27006 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/codecs/libwmapro/wmaprodec.c')
-rw-r--r--apps/codecs/libwmapro/wmaprodec.c33
1 files changed, 23 insertions, 10 deletions
diff --git a/apps/codecs/libwmapro/wmaprodec.c b/apps/codecs/libwmapro/wmaprodec.c
index 88d317d5f6..e72919434c 100644
--- a/apps/codecs/libwmapro/wmaprodec.c
+++ b/apps/codecs/libwmapro/wmaprodec.c
@@ -93,13 +93,11 @@
93#include "wmaprodata.h" 93#include "wmaprodata.h"
94#include "dsputil.h" 94#include "dsputil.h"
95#include "wma.h" 95#include "wma.h"
96#include "wmaprodec.h"
96 97
97/* Some defines to make it compile */ 98/* Some defines to make it compile */
98#define AVERROR_INVALIDDATA -1 99#define AVERROR_INVALIDDATA -1
99#define AVERROR_PATCHWELCOME -2 100#define AVERROR_PATCHWELCOME -2
100#ifndef M_PI
101#define M_PI 3.14159265358979323846 /* pi */
102#endif
103#define av_log_ask_for_sample(...) 101#define av_log_ask_for_sample(...)
104 102
105/** current decoder limitations */ 103/** current decoder limitations */
@@ -238,8 +236,8 @@ typedef struct WMAProDecodeCtx {
238 */ 236 */
239static void av_cold dump_context(WMAProDecodeCtx *s) 237static void av_cold dump_context(WMAProDecodeCtx *s)
240{ 238{
241#define PRINT(a, b) av_log(s->avctx, AV_LOG_DEBUG, " %s = %d\n", a, b); 239#define PRINT(a, b) printf(" %s = %d\n", a, b);
242#define PRINT_HEX(a, b) av_log(s->avctx, AV_LOG_DEBUG, " %s = %x\n", a, b); 240#define PRINT_HEX(a, b) printf(" %s = %x\n", a, b);
243 241
244 PRINT("ed sample bit depth", s->bits_per_sample); 242 PRINT("ed sample bit depth", s->bits_per_sample);
245 PRINT_HEX("ed decode flags", s->decode_flags); 243 PRINT_HEX("ed decode flags", s->decode_flags);
@@ -255,7 +253,7 @@ static void av_cold dump_context(WMAProDecodeCtx *s)
255 *@param avctx codec context 253 *@param avctx codec context
256 *@return 0 on success, < 0 otherwise 254 *@return 0 on success, < 0 otherwise
257 */ 255 */
258static av_cold int decode_end(AVCodecContext *avctx) 256av_cold int decode_end(AVCodecContext *avctx)
259{ 257{
260 WMAProDecodeCtx *s = avctx->priv_data; 258 WMAProDecodeCtx *s = avctx->priv_data;
261 int i; 259 int i;
@@ -271,8 +269,10 @@ static av_cold int decode_end(AVCodecContext *avctx)
271 *@param avctx codec context 269 *@param avctx codec context
272 *@return 0 on success, -1 otherwise 270 *@return 0 on success, -1 otherwise
273 */ 271 */
274static av_cold int decode_init(AVCodecContext *avctx) 272av_cold int decode_init(AVCodecContext *avctx)
275{ 273{
274 avctx->priv_data = malloc(sizeof(WMAProDecodeCtx));
275 memset(avctx->priv_data, 0, sizeof(WMAProDecodeCtx));
276 WMAProDecodeCtx *s = avctx->priv_data; 276 WMAProDecodeCtx *s = avctx->priv_data;
277 uint8_t *edata_ptr = avctx->extradata; 277 uint8_t *edata_ptr = avctx->extradata;
278 unsigned int channel_mask; 278 unsigned int channel_mask;
@@ -454,7 +454,6 @@ static av_cold int decode_init(AVCodecContext *avctx)
454 sin64[i] = sin(i*M_PI / 64.0); 454 sin64[i] = sin(i*M_PI / 64.0);
455#if 0 455#if 0
456 if (avctx->debug & FF_DEBUG_BITSTREAM) 456 if (avctx->debug & FF_DEBUG_BITSTREAM)
457 dump_context(s);
458#endif 457#endif
459 458
460 avctx->channel_layout = channel_mask; 459 avctx->channel_layout = channel_mask;
@@ -1379,7 +1378,7 @@ static int decode_frame(WMAProDecodeCtx *s)
1379 if (len != (get_bits_count(gb) - s->frame_offset) + 2) { 1378 if (len != (get_bits_count(gb) - s->frame_offset) + 2) {
1380 /** FIXME: not sure if this is always an error */ 1379 /** FIXME: not sure if this is always an error */
1381 av_log(s->avctx, AV_LOG_ERROR, "frame[%i] would have to skip %i bits\n", 1380 av_log(s->avctx, AV_LOG_ERROR, "frame[%i] would have to skip %i bits\n",
1382 s->frame_num, len - (get_bits_count(gb) - s->frame_offset) - 1); 1381 (int)s->frame_num, len - (get_bits_count(gb) - s->frame_offset) - 1);
1383 s->packet_loss = 1; 1382 s->packet_loss = 1;
1384 return 0; 1383 return 0;
1385 } 1384 }
@@ -1465,7 +1464,7 @@ static void save_bits(WMAProDecodeCtx *s, GetBitContext* gb, int len,
1465 *@param avpkt input packet 1464 *@param avpkt input packet
1466 *@return number of bytes that were read from the input buffer 1465 *@return number of bytes that were read from the input buffer
1467 */ 1466 */
1468static int decode_packet(AVCodecContext *avctx, 1467int decode_packet(AVCodecContext *avctx,
1469 void *data, int *data_size, AVPacket* avpkt) 1468 void *data, int *data_size, AVPacket* avpkt)
1470{ 1469{
1471 WMAProDecodeCtx *s = avctx->priv_data; 1470 WMAProDecodeCtx *s = avctx->priv_data;
@@ -1549,6 +1548,20 @@ static int decode_packet(AVCodecContext *avctx,
1549 *data_size = (int8_t *)s->samples - (int8_t *)data; 1548 *data_size = (int8_t *)s->samples - (int8_t *)data;
1550 s->packet_offset = get_bits_count(gb) & 7; 1549 s->packet_offset = get_bits_count(gb) & 7;
1551 1550
1551/* Convert the pcm samples to signed 16-bit integers. This is the format that
1552 * the rockbox simulator works with. */
1553#ifdef ROCKBOX
1554 float* fptr = data;
1555 int32_t* ptr = data;
1556 int x;
1557 for(x = 0; x < *data_size; x++)
1558 {
1559 fptr[x] *= ((float)(INT32_MAX));
1560 ptr[x] = (int32_t)fptr[x];
1561
1562 }
1563#endif
1564
1552 return (s->packet_loss) ? AVERROR_INVALIDDATA : get_bits_count(gb) >> 3; 1565 return (s->packet_loss) ? AVERROR_INVALIDDATA : get_bits_count(gb) >> 3;
1553} 1566}
1554 1567