summaryrefslogtreecommitdiff
path: root/apps/codecs/wmavoice.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/codecs/wmavoice.c')
-rw-r--r--apps/codecs/wmavoice.c68
1 files changed, 33 insertions, 35 deletions
diff --git a/apps/codecs/wmavoice.c b/apps/codecs/wmavoice.c
index ddf66828f1..64c8cd1692 100644
--- a/apps/codecs/wmavoice.c
+++ b/apps/codecs/wmavoice.c
@@ -52,10 +52,20 @@ static void init_codec_ctx(AVCodecContext *avctx, asf_waveformatex_t *wfx)
52} 52}
53 53
54/* this is the codec entry point */ 54/* this is the codec entry point */
55enum codec_status codec_main(void) 55enum codec_status codec_main(enum codec_entry_call_reason reason)
56{
57 if (reason == CODEC_LOAD) {
58 /* Generic codec initialisation */
59 ci->configure(DSP_SET_SAMPLE_DEPTH, 31);
60 }
61
62 return CODEC_OK;
63}
64
65/* this is called for each file to process */
66enum codec_status codec_run(void)
56{ 67{
57 uint32_t elapsedtime; 68 uint32_t elapsedtime;
58 int retval;
59 asf_waveformatex_t wfx; /* Holds the stream properties */ 69 asf_waveformatex_t wfx; /* Holds the stream properties */
60 size_t resume_offset; 70 size_t resume_offset;
61 int res; /* Return values from asf_read_packet() and decode_packet() */ 71 int res; /* Return values from asf_read_packet() and decode_packet() */
@@ -64,27 +74,14 @@ enum codec_status codec_main(void)
64 int packetlength = 0; /* Logical packet size (minus the header size) */ 74 int packetlength = 0; /* Logical packet size (minus the header size) */
65 int outlen = 0; /* Number of bytes written to the output buffer */ 75 int outlen = 0; /* Number of bytes written to the output buffer */
66 int pktcnt = 0; /* Count of the packets played */ 76 int pktcnt = 0; /* Count of the packets played */
67 77 intptr_t param;
68 /* Generic codec initialisation */
69 ci->configure(DSP_SET_SAMPLE_DEPTH, 31);
70
71
72next_track:
73 retval = CODEC_OK;
74
75 /* Wait for the metadata to be read */
76 if (codec_wait_taginfo() != 0)
77 goto done;
78 78
79 /* Remember the resume position */ 79 /* Remember the resume position */
80 resume_offset = ci->id3->offset; 80 resume_offset = ci->id3->offset;
81restart_track: 81restart_track:
82 retval = CODEC_OK;
83
84 if (codec_init()) { 82 if (codec_init()) {
85 LOGF("(WMA Voice) Error: Error initialising codec\n"); 83 LOGF("(WMA Voice) Error: Error initialising codec\n");
86 retval = CODEC_ERROR; 84 return CODEC_ERROR;
87 goto done;
88 } 85 }
89 86
90 /* Copy the format metadata we've stored in the id3 TOC field. This 87 /* Copy the format metadata we've stored in the id3 TOC field. This
@@ -97,14 +94,15 @@ restart_track:
97 ci->configure(DSP_SET_STEREO_MODE, wfx.channels == 1 ? 94 ci->configure(DSP_SET_STEREO_MODE, wfx.channels == 1 ?
98 STEREO_MONO : STEREO_INTERLEAVED); 95 STEREO_MONO : STEREO_INTERLEAVED);
99 codec_set_replaygain(ci->id3); 96 codec_set_replaygain(ci->id3);
97
98 ci->seek_buffer(0);
100 99
101 /* Initialise the AVCodecContext */ 100 /* Initialise the AVCodecContext */
102 init_codec_ctx(&avctx, &wfx); 101 init_codec_ctx(&avctx, &wfx);
103 102
104 if (wmavoice_decode_init(&avctx) < 0) { 103 if (wmavoice_decode_init(&avctx) < 0) {
105 LOGF("(WMA Voice) Error: Unsupported or corrupt file\n"); 104 LOGF("(WMA Voice) Error: Unsupported or corrupt file\n");
106 retval = CODEC_ERROR; 105 return CODEC_ERROR;
107 goto done;
108 } 106 }
109 107
110 /* Now advance the file position to the first frame */ 108 /* Now advance the file position to the first frame */
@@ -117,21 +115,24 @@ restart_track:
117 115
118 while (pktcnt < wfx.numpackets) 116 while (pktcnt < wfx.numpackets)
119 { 117 {
120 ci->yield(); 118 enum codec_command_action action = ci->get_command(&param);
121 if (ci->stop_codec || ci->new_track) { 119
122 goto done; 120 if (action == CODEC_ACTION_HALT)
123 } 121 break;
124 122
125 /* Deal with any pending seek requests */ 123 /* Deal with any pending seek requests */
126 if (ci->seek_time){ 124 if (action == CODEC_ACTION_SEEK_TIME) {
125 ci->set_elapsed(param);
127 126
128 if (ci->seek_time == 1) { 127 if (param == 0) {
128 ci->set_elapsed(0);
129 ci->seek_complete(); 129 ci->seek_complete();
130 goto restart_track; /* Pretend you never saw this... */ 130 goto restart_track; /* Pretend you never saw this... */
131 } 131 }
132 132
133 elapsedtime = asf_seek(ci->seek_time, &wfx); 133 elapsedtime = asf_seek(param, &wfx);
134 if (elapsedtime < 1){ 134 if (elapsedtime < 1){
135 ci->set_elapsed(0);
135 ci->seek_complete(); 136 ci->seek_complete();
136 goto next_track; 137 goto next_track;
137 } 138 }
@@ -145,7 +146,7 @@ new_packet:
145 146
146 if (res < 0) { 147 if (res < 0) {
147 LOGF("(WMA Voice) read_packet error %d\n",res); 148 LOGF("(WMA Voice) read_packet error %d\n",res);
148 goto done; 149 return CODEC_ERROR;
149 } else { 150 } else {
150 avpkt.data = audiobuf; 151 avpkt.data = audiobuf;
151 avpkt.size = audiobufsize; 152 avpkt.size = audiobufsize;
@@ -165,8 +166,9 @@ new_packet:
165 ci->advance_buffer(packetlength); 166 ci->advance_buffer(packetlength);
166 goto new_packet; 167 goto new_packet;
167 } 168 }
168 else 169 else {
169 goto done; 170 return CODEC_ERROR;
171 }
170 } 172 }
171 avpkt.data += res; 173 avpkt.data += res;
172 avpkt.size -= res; 174 avpkt.size -= res;
@@ -186,10 +188,6 @@ new_packet:
186 ci->advance_buffer(packetlength); 188 ci->advance_buffer(packetlength);
187 } 189 }
188 190
189done: 191 return CODEC_OK;
190 if (ci->request_next_track())
191 goto next_track;
192
193 return retval;
194} 192}
195 193