diff options
Diffstat (limited to 'apps/codecs/aac.c')
-rw-r--r-- | apps/codecs/aac.c | 62 |
1 files changed, 27 insertions, 35 deletions
diff --git a/apps/codecs/aac.c b/apps/codecs/aac.c index 5638dc49a9..90cf0438ce 100644 --- a/apps/codecs/aac.c +++ b/apps/codecs/aac.c | |||
@@ -33,7 +33,19 @@ CODEC_HEADER | |||
33 | #define FAAD_BYTE_BUFFER_SIZE (2048-12) | 33 | #define FAAD_BYTE_BUFFER_SIZE (2048-12) |
34 | 34 | ||
35 | /* this is the codec entry point */ | 35 | /* this is the codec entry point */ |
36 | enum codec_status codec_main(void) | 36 | enum codec_status codec_main(enum codec_entry_call_reason reason) |
37 | { | ||
38 | if (reason == CODEC_LOAD) { | ||
39 | /* Generic codec initialisation */ | ||
40 | ci->configure(DSP_SET_STEREO_MODE, STEREO_NONINTERLEAVED); | ||
41 | ci->configure(DSP_SET_SAMPLE_DEPTH, 29); | ||
42 | } | ||
43 | |||
44 | return CODEC_OK; | ||
45 | } | ||
46 | |||
47 | /* this is called for each file to process */ | ||
48 | enum codec_status codec_run(void) | ||
37 | { | 49 | { |
38 | /* Note that when dealing with QuickTime/MPEG4 files, terminology is | 50 | /* Note that when dealing with QuickTime/MPEG4 files, terminology is |
39 | * a bit confusing. Files with sound are split up in chunks, where | 51 | * a bit confusing. Files with sound are split up in chunks, where |
@@ -59,25 +71,15 @@ enum codec_status codec_main(void) | |||
59 | uint32_t sbr_fac = 1; | 71 | uint32_t sbr_fac = 1; |
60 | unsigned char c = 0; | 72 | unsigned char c = 0; |
61 | void *ret; | 73 | void *ret; |
62 | 74 | intptr_t param; | |
63 | /* Generic codec initialisation */ | ||
64 | ci->configure(DSP_SET_STEREO_MODE, STEREO_NONINTERLEAVED); | ||
65 | ci->configure(DSP_SET_SAMPLE_DEPTH, 29); | ||
66 | |||
67 | next_track: | ||
68 | err = CODEC_OK; | ||
69 | 75 | ||
70 | /* Clean and initialize decoder structures */ | 76 | /* Clean and initialize decoder structures */ |
71 | memset(&demux_res , 0, sizeof(demux_res)); | 77 | memset(&demux_res , 0, sizeof(demux_res)); |
72 | if (codec_init()) { | 78 | if (codec_init()) { |
73 | LOGF("FAAD: Codec init error\n"); | 79 | LOGF("FAAD: Codec init error\n"); |
74 | err = CODEC_ERROR; | 80 | return CODEC_ERROR; |
75 | goto exit; | ||
76 | } | 81 | } |
77 | 82 | ||
78 | if (codec_wait_taginfo() != 0) | ||
79 | goto done; | ||
80 | |||
81 | file_offset = ci->id3->offset; | 83 | file_offset = ci->id3->offset; |
82 | 84 | ||
83 | ci->configure(DSP_SWITCH_FREQUENCY, ci->id3->frequency); | 85 | ci->configure(DSP_SWITCH_FREQUENCY, ci->id3->frequency); |
@@ -85,12 +87,13 @@ next_track: | |||
85 | 87 | ||
86 | stream_create(&input_stream,ci); | 88 | stream_create(&input_stream,ci); |
87 | 89 | ||
90 | ci->seek_buffer(ci->id3->first_frame_offset); | ||
91 | |||
88 | /* if qtmovie_read returns successfully, the stream is up to | 92 | /* if qtmovie_read returns successfully, the stream is up to |
89 | * the movie data, which can be used directly by the decoder */ | 93 | * the movie data, which can be used directly by the decoder */ |
90 | if (!qtmovie_read(&input_stream, &demux_res)) { | 94 | if (!qtmovie_read(&input_stream, &demux_res)) { |
91 | LOGF("FAAD: File init error\n"); | 95 | LOGF("FAAD: File init error\n"); |
92 | err = CODEC_ERROR; | 96 | return CODEC_ERROR; |
93 | goto done; | ||
94 | } | 97 | } |
95 | 98 | ||
96 | /* initialise the sound converter */ | 99 | /* initialise the sound converter */ |
@@ -98,8 +101,7 @@ next_track: | |||
98 | 101 | ||
99 | if (!decoder) { | 102 | if (!decoder) { |
100 | LOGF("FAAD: Decode open error\n"); | 103 | LOGF("FAAD: Decode open error\n"); |
101 | err = CODEC_ERROR; | 104 | return CODEC_ERROR; |
102 | goto done; | ||
103 | } | 105 | } |
104 | 106 | ||
105 | NeAACDecConfigurationPtr conf = NeAACDecGetCurrentConfiguration(decoder); | 107 | NeAACDecConfigurationPtr conf = NeAACDecGetCurrentConfiguration(decoder); |
@@ -109,8 +111,7 @@ next_track: | |||
109 | err = NeAACDecInit2(decoder, demux_res.codecdata, demux_res.codecdata_len, &s, &c); | 111 | err = NeAACDecInit2(decoder, demux_res.codecdata, demux_res.codecdata_len, &s, &c); |
110 | if (err) { | 112 | if (err) { |
111 | LOGF("FAAD: DecInit: %d, %d\n", err, decoder->object_type); | 113 | LOGF("FAAD: DecInit: %d, %d\n", err, decoder->object_type); |
112 | err = CODEC_ERROR; | 114 | return CODEC_ERROR; |
113 | goto done; | ||
114 | } | 115 | } |
115 | 116 | ||
116 | #ifdef SBR_DEC | 117 | #ifdef SBR_DEC |
@@ -150,20 +151,19 @@ next_track: | |||
150 | 151 | ||
151 | /* The main decoding loop */ | 152 | /* The main decoding loop */ |
152 | while (i < demux_res.num_sample_byte_sizes) { | 153 | while (i < demux_res.num_sample_byte_sizes) { |
153 | ci->yield(); | 154 | enum codec_command_action action = ci->get_command(¶m); |
154 | 155 | ||
155 | if (ci->stop_codec || ci->new_track) { | 156 | if (action == CODEC_ACTION_HALT) |
156 | break; | 157 | break; |
157 | } | ||
158 | 158 | ||
159 | /* Deal with any pending seek requests */ | 159 | /* Deal with any pending seek requests */ |
160 | if (ci->seek_time) { | 160 | if (action == CODEC_ACTION_SEEK_TIME) { |
161 | /* Seek to the desired time position. Important: When seeking in SBR | 161 | /* Seek to the desired time position. Important: When seeking in SBR |
162 | * upsampling files the seek_time must be divided by 2 when calling | 162 | * upsampling files the seek_time must be divided by 2 when calling |
163 | * m4a_seek and the resulting sound_samples_done must be expanded | 163 | * m4a_seek and the resulting sound_samples_done must be expanded |
164 | * by a factor 2. This is done via using sbr_fac. */ | 164 | * by a factor 2. This is done via using sbr_fac. */ |
165 | if (m4a_seek(&demux_res, &input_stream, | 165 | if (m4a_seek(&demux_res, &input_stream, |
166 | ((ci->seek_time-1)/10/sbr_fac)*(ci->id3->frequency/100), | 166 | (param/10/sbr_fac)*(ci->id3->frequency/100), |
167 | &sound_samples_done, (int*) &i)) { | 167 | &sound_samples_done, (int*) &i)) { |
168 | sound_samples_done *= sbr_fac; | 168 | sound_samples_done *= sbr_fac; |
169 | elapsed_time = (sound_samples_done * 10) / (ci->id3->frequency / 100); | 169 | elapsed_time = (sound_samples_done * 10) / (ci->id3->frequency / 100); |
@@ -194,8 +194,7 @@ next_track: | |||
194 | else if (file_offset == 0) | 194 | else if (file_offset == 0) |
195 | { | 195 | { |
196 | LOGF("AAC: get_sample_offset error\n"); | 196 | LOGF("AAC: get_sample_offset error\n"); |
197 | err = CODEC_ERROR; | 197 | return CODEC_ERROR; |
198 | goto done; | ||
199 | } | 198 | } |
200 | 199 | ||
201 | /* Request the required number of bytes from the input buffer */ | 200 | /* Request the required number of bytes from the input buffer */ |
@@ -207,8 +206,7 @@ next_track: | |||
207 | /* NeAACDecDecode may sometimes return NULL without setting error. */ | 206 | /* NeAACDecDecode may sometimes return NULL without setting error. */ |
208 | if (ret == NULL || frame_info.error > 0) { | 207 | if (ret == NULL || frame_info.error > 0) { |
209 | LOGF("FAAD: decode error '%s'\n", NeAACDecGetErrorMessage(frame_info.error)); | 208 | LOGF("FAAD: decode error '%s'\n", NeAACDecGetErrorMessage(frame_info.error)); |
210 | err = CODEC_ERROR; | 209 | return CODEC_ERROR; |
211 | goto done; | ||
212 | } | 210 | } |
213 | 211 | ||
214 | /* Advance codec buffer (no need to call set_offset because of this) */ | 212 | /* Advance codec buffer (no need to call set_offset because of this) */ |
@@ -251,12 +249,6 @@ next_track: | |||
251 | i++; | 249 | i++; |
252 | } | 250 | } |
253 | 251 | ||
254 | done: | ||
255 | LOGF("AAC: Decoded %lu samples\n", (unsigned long)sound_samples_done); | 252 | LOGF("AAC: Decoded %lu samples\n", (unsigned long)sound_samples_done); |
256 | 253 | return CODEC_OK; | |
257 | if (ci->request_next_track()) | ||
258 | goto next_track; | ||
259 | |||
260 | exit: | ||
261 | return err; | ||
262 | } | 254 | } |