diff options
Diffstat (limited to 'apps/codecs/wmapro.c')
-rw-r--r-- | apps/codecs/wmapro.c | 41 |
1 files changed, 9 insertions, 32 deletions
diff --git a/apps/codecs/wmapro.c b/apps/codecs/wmapro.c index ba19e2925c..33032f3b16 100644 --- a/apps/codecs/wmapro.c +++ b/apps/codecs/wmapro.c | |||
@@ -30,27 +30,6 @@ CODEC_HEADER | |||
30 | #define BUFSIZE MAXCHANNELS * MAXSAMPLES | 30 | #define BUFSIZE MAXCHANNELS * MAXSAMPLES |
31 | int32_t decoded[BUFSIZE]; | 31 | int32_t decoded[BUFSIZE]; |
32 | 32 | ||
33 | AVCodecContext avctx; | ||
34 | AVPacket avpkt; | ||
35 | |||
36 | /* This function initialises AVCodecContext with the data needed for the wmapro | ||
37 | * decoder to work. The required data is taken from asf_waveformatex_t because that's | ||
38 | * what the rockbox asf metadata parser fill/work with. In the future, when the | ||
39 | * codec is being optimised for on-target playback this function should not be needed, | ||
40 | * as we will be working directly with WMAProDecodeCtx (declared in wmaprodec.c) */ | ||
41 | static void init_codec_ctx(AVCodecContext *avctx, asf_waveformatex_t *wfx) | ||
42 | { | ||
43 | /* Copy the extra-data */ | ||
44 | avctx->extradata_size = wfx->datalen; | ||
45 | avctx->extradata = (uint8_t *)malloc(wfx->datalen*sizeof(uint8_t)); | ||
46 | memcpy(avctx->extradata, wfx->data, wfx->datalen*sizeof(uint8_t)); | ||
47 | |||
48 | avctx->block_align = wfx->blockalign; | ||
49 | avctx->sample_rate = wfx->rate; | ||
50 | avctx->channels = wfx->channels; | ||
51 | |||
52 | } | ||
53 | |||
54 | /* this is the codec entry point */ | 33 | /* this is the codec entry point */ |
55 | enum codec_status codec_main(void) | 34 | enum codec_status codec_main(void) |
56 | { | 35 | { |
@@ -64,6 +43,8 @@ enum codec_status codec_main(void) | |||
64 | int packetlength = 0; /* Logical packet size (minus the header size) */ | 43 | int packetlength = 0; /* Logical packet size (minus the header size) */ |
65 | int outlen = 0; /* Number of bytes written to the output buffer */ | 44 | int outlen = 0; /* Number of bytes written to the output buffer */ |
66 | int pktcnt = 0; /* Count of the packets played */ | 45 | int pktcnt = 0; /* Count of the packets played */ |
46 | uint8_t *data; /* Pointer to decoder input buffer */ | ||
47 | int size; /* Size of the input frame to the decoder */ | ||
67 | 48 | ||
68 | /* Generic codec initialisation */ | 49 | /* Generic codec initialisation */ |
69 | ci->configure(DSP_SET_SAMPLE_DEPTH, 17); | 50 | ci->configure(DSP_SET_SAMPLE_DEPTH, 17); |
@@ -94,11 +75,8 @@ next_track: | |||
94 | ci->configure(DSP_SET_STEREO_MODE, wfx.channels == 1 ? | 75 | ci->configure(DSP_SET_STEREO_MODE, wfx.channels == 1 ? |
95 | STEREO_MONO : STEREO_INTERLEAVED); | 76 | STEREO_MONO : STEREO_INTERLEAVED); |
96 | codec_set_replaygain(ci->id3); | 77 | codec_set_replaygain(ci->id3); |
97 | |||
98 | /* Initialise the AVCodecContext */ | ||
99 | init_codec_ctx(&avctx, &wfx); | ||
100 | 78 | ||
101 | if (decode_init(&avctx) < 0) { | 79 | if (decode_init(&wfx) < 0) { |
102 | LOGF("(WMA PRO) Error: Unsupported or corrupt file\n"); | 80 | LOGF("(WMA PRO) Error: Unsupported or corrupt file\n"); |
103 | retval = CODEC_ERROR; | 81 | retval = CODEC_ERROR; |
104 | goto done; | 82 | goto done; |
@@ -143,20 +121,19 @@ next_track: | |||
143 | LOGF("(WMA PRO) Warning: asf_read_packet returned %d", res); | 121 | LOGF("(WMA PRO) Warning: asf_read_packet returned %d", res); |
144 | goto done; | 122 | goto done; |
145 | } else { | 123 | } else { |
146 | avpkt.data = audiobuf; | 124 | data = audiobuf; |
147 | avpkt.size = audiobufsize; | 125 | size = audiobufsize; |
148 | pktcnt++; | 126 | pktcnt++; |
149 | 127 | ||
150 | /* We now loop on the packet, decoding and outputting the subframes | 128 | /* We now loop on the packet, decoding and outputting the subframes |
151 | * one-by-one. For more information about how wma pro structures its | 129 | * one-by-one. For more information about how wma pro structures its |
152 | * audio frames, see libwmapro/wmaprodec.c */ | 130 | * audio frames, see libwmapro/wmaprodec.c */ |
153 | while(avpkt.size > 0) | 131 | while(size > 0) |
154 | { | 132 | { |
155 | outlen = BUFSIZE; /* decode_packet needs to know the size of the output buffer */ | 133 | outlen = BUFSIZE; /* decode_packet needs to know the size of the output buffer */ |
156 | res = decode_packet(&avctx, decoded, &outlen, &avpkt); | 134 | res = decode_packet(&wfx, decoded, &outlen, data, size); |
157 | avpkt.data += res; | 135 | data += res; |
158 | avpkt.size -= res; | 136 | size -= res; |
159 | avctx.frame_number++; | ||
160 | if(outlen) { | 137 | if(outlen) { |
161 | ci->yield (); | 138 | ci->yield (); |
162 | /* outlen now holds the size of the data in bytes - we want the | 139 | /* outlen now holds the size of the data in bytes - we want the |