diff options
Diffstat (limited to 'apps/codecs/wma.c')
-rw-r--r-- | apps/codecs/wma.c | 77 |
1 files changed, 38 insertions, 39 deletions
diff --git a/apps/codecs/wma.c b/apps/codecs/wma.c index 1b46813444..c327fafb5a 100644 --- a/apps/codecs/wma.c +++ b/apps/codecs/wma.c | |||
@@ -29,53 +29,52 @@ CODEC_HEADER | |||
29 | static WMADecodeContext wmadec; | 29 | static WMADecodeContext wmadec; |
30 | 30 | ||
31 | /* this is the codec entry point */ | 31 | /* this is the codec entry point */ |
32 | enum codec_status codec_main(void) | 32 | enum codec_status codec_main(enum codec_entry_call_reason reason) |
33 | { | ||
34 | if (reason == CODEC_LOAD) { | ||
35 | /* Generic codec initialisation */ | ||
36 | ci->configure(DSP_SET_SAMPLE_DEPTH, 29); | ||
37 | } | ||
38 | |||
39 | return CODEC_OK; | ||
40 | } | ||
41 | |||
42 | /* this is called for each file to process */ | ||
43 | enum codec_status codec_run(void) | ||
33 | { | 44 | { |
34 | uint32_t elapsedtime; | 45 | uint32_t elapsedtime; |
35 | int retval; | ||
36 | asf_waveformatex_t wfx; | 46 | asf_waveformatex_t wfx; |
37 | size_t resume_offset; | 47 | size_t resume_offset; |
38 | int i; | 48 | int i; |
39 | int wmares, res; | 49 | int wmares; |
50 | int res = 0; | ||
40 | uint8_t* audiobuf; | 51 | uint8_t* audiobuf; |
41 | int audiobufsize; | 52 | int audiobufsize; |
42 | int packetlength = 0; | 53 | int packetlength = 0; |
43 | int errcount = 0; | 54 | int errcount = 0; |
44 | 55 | intptr_t param; | |
45 | /* Generic codec initialisation */ | ||
46 | ci->configure(DSP_SET_SAMPLE_DEPTH, 29); | ||
47 | |||
48 | next_track: | ||
49 | retval = CODEC_OK; | ||
50 | 56 | ||
51 | /* Proper reset of the decoder context. */ | 57 | /* Proper reset of the decoder context. */ |
52 | memset(&wmadec, 0, sizeof(wmadec)); | 58 | memset(&wmadec, 0, sizeof(wmadec)); |
53 | 59 | ||
54 | /* Wait for the metadata to be read */ | ||
55 | if (codec_wait_taginfo() != 0) | ||
56 | goto done; | ||
57 | |||
58 | /* Remember the resume position - when the codec is opened, the | 60 | /* Remember the resume position - when the codec is opened, the |
59 | playback engine will reset it. */ | 61 | playback engine will reset it. */ |
60 | resume_offset = ci->id3->offset; | 62 | resume_offset = ci->id3->offset; |
61 | 63 | ||
62 | restart_track: | 64 | restart_track: |
63 | retval = CODEC_OK; | ||
64 | |||
65 | if (codec_init()) { | 65 | if (codec_init()) { |
66 | LOGF("WMA: Error initialising codec\n"); | 66 | LOGF("WMA: Error initialising codec\n"); |
67 | retval = CODEC_ERROR; | 67 | return CODEC_ERROR; |
68 | goto exit; | ||
69 | } | 68 | } |
70 | 69 | ||
71 | /* Copy the format metadata we've stored in the id3 TOC field. This | 70 | /* Copy the format metadata we've stored in the id3 TOC field. This |
72 | saves us from parsing it again here. */ | 71 | saves us from parsing it again here. */ |
73 | memcpy(&wfx, ci->id3->toc, sizeof(wfx)); | 72 | memcpy(&wfx, ci->id3->toc, sizeof(wfx)); |
74 | 73 | ||
74 | ci->seek_buffer(ci->id3->first_frame_offset); | ||
75 | if (wma_decode_init(&wmadec,&wfx) < 0) { | 75 | if (wma_decode_init(&wmadec,&wfx) < 0) { |
76 | LOGF("WMA: Unsupported or corrupt file\n"); | 76 | LOGF("WMA: Unsupported or corrupt file\n"); |
77 | retval = CODEC_ERROR; | 77 | return CODEC_ERROR; |
78 | goto exit; | ||
79 | } | 78 | } |
80 | 79 | ||
81 | if (resume_offset > ci->id3->first_frame_offset) | 80 | if (resume_offset > ci->id3->first_frame_offset) |
@@ -101,34 +100,35 @@ restart_track: | |||
101 | codec_set_replaygain(ci->id3); | 100 | codec_set_replaygain(ci->id3); |
102 | 101 | ||
103 | /* The main decoding loop */ | 102 | /* The main decoding loop */ |
104 | |||
105 | res = 1; | ||
106 | while (res >= 0) | 103 | while (res >= 0) |
107 | { | 104 | { |
108 | ci->yield(); | 105 | enum codec_command_action action = ci->get_command(¶m); |
109 | if (ci->stop_codec || ci->new_track) { | 106 | |
110 | goto done; | 107 | if (action == CODEC_ACTION_HALT) |
111 | } | 108 | break; |
112 | 109 | ||
113 | /* Deal with any pending seek requests */ | 110 | /* Deal with any pending seek requests */ |
114 | if (ci->seek_time){ | 111 | if (action == CODEC_ACTION_SEEK_TIME) { |
115 | 112 | ||
116 | if (ci->seek_time == 1) { | 113 | if (param == 0) { |
114 | ci->set_elapsed(0); | ||
117 | ci->seek_complete(); | 115 | ci->seek_complete(); |
118 | goto restart_track; /* Pretend you never saw this... */ | 116 | goto restart_track; /* Pretend you never saw this... */ |
119 | } | 117 | } |
120 | 118 | ||
121 | elapsedtime = asf_seek(ci->seek_time, &wfx); | 119 | elapsedtime = asf_seek(param, &wfx); |
122 | if (elapsedtime < 1){ | 120 | if (elapsedtime < 1){ |
121 | ci->set_elapsed(0); | ||
123 | ci->seek_complete(); | 122 | ci->seek_complete(); |
124 | goto next_track; | 123 | break; |
125 | } | 124 | } |
126 | /*DEBUGF("Seek returned %d\n", (int)elapsedtime);*/ | 125 | /*DEBUGF("Seek returned %d\n", (int)elapsedtime);*/ |
127 | ci->set_elapsed(elapsedtime); | ||
128 | 126 | ||
129 | /*flush the wma decoder state*/ | 127 | /*flush the wma decoder state*/ |
130 | wmadec.last_superframe_len = 0; | 128 | wmadec.last_superframe_len = 0; |
131 | wmadec.last_bitoffset = 0; | 129 | wmadec.last_bitoffset = 0; |
130 | |||
131 | ci->set_elapsed(elapsedtime); | ||
132 | ci->seek_complete(); | 132 | ci->seek_complete(); |
133 | } | 133 | } |
134 | errcount = 0; | 134 | errcount = 0; |
@@ -140,10 +140,15 @@ new_packet: | |||
140 | * times. If we succeed, the error counter will be reset. | 140 | * times. If we succeed, the error counter will be reset. |
141 | */ | 141 | */ |
142 | 142 | ||
143 | if (res == ASF_ERROR_EOF) { | ||
144 | /* File ended - not an error */ | ||
145 | break; | ||
146 | } | ||
147 | |||
143 | errcount++; | 148 | errcount++; |
144 | DEBUGF("read_packet error %d, errcount %d\n",wmares, errcount); | 149 | DEBUGF("read_packet error %d, errcount %d\n",wmares, errcount); |
145 | if (errcount > 5) { | 150 | if (errcount > 5) { |
146 | goto done; | 151 | return CODEC_ERROR; |
147 | } else { | 152 | } else { |
148 | ci->advance_buffer(packetlength); | 153 | ci->advance_buffer(packetlength); |
149 | goto new_packet; | 154 | goto new_packet; |
@@ -163,7 +168,7 @@ new_packet: | |||
163 | errcount++; | 168 | errcount++; |
164 | DEBUGF("WMA decode error %d, errcount %d\n",wmares, errcount); | 169 | DEBUGF("WMA decode error %d, errcount %d\n",wmares, errcount); |
165 | if (errcount > 5) { | 170 | if (errcount > 5) { |
166 | goto done; | 171 | return CODEC_ERROR; |
167 | } else { | 172 | } else { |
168 | ci->advance_buffer(packetlength); | 173 | ci->advance_buffer(packetlength); |
169 | goto new_packet; | 174 | goto new_packet; |
@@ -173,18 +178,12 @@ new_packet: | |||
173 | elapsedtime += (wmares*10)/(wfx.rate/100); | 178 | elapsedtime += (wmares*10)/(wfx.rate/100); |
174 | ci->set_elapsed(elapsedtime); | 179 | ci->set_elapsed(elapsedtime); |
175 | } | 180 | } |
176 | ci->yield(); | ||
177 | } | 181 | } |
178 | } | 182 | } |
179 | 183 | ||
180 | ci->advance_buffer(packetlength); | 184 | ci->advance_buffer(packetlength); |
181 | } | 185 | } |
182 | 186 | ||
183 | done: | ||
184 | /*LOGF("WMA: Decoded %ld samples\n",elapsedtime*wfx.rate/1000);*/ | 187 | /*LOGF("WMA: Decoded %ld samples\n",elapsedtime*wfx.rate/1000);*/ |
185 | 188 | return CODEC_OK; | |
186 | if (ci->request_next_track()) | ||
187 | goto next_track; | ||
188 | exit: | ||
189 | return retval; | ||
190 | } | 189 | } |