summaryrefslogtreecommitdiff
path: root/apps/codecs/vox.c
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2011-04-27 03:08:23 +0000
committerMichael Sevakis <jethead71@rockbox.org>2011-04-27 03:08:23 +0000
commitc537d5958e8b421ac4f9bef6c8b9e7425a6cf167 (patch)
tree7ed36518fb6524da7bbd913ba7619b85b5d15d23 /apps/codecs/vox.c
parentdcf0f8de4a37ff1d2ea510aef75fa67977a8bdcc (diff)
downloadrockbox-c537d5958e8b421ac4f9bef6c8b9e7425a6cf167.tar.gz
rockbox-c537d5958e8b421ac4f9bef6c8b9e7425a6cf167.zip
Commit FS#12069 - Playback rework - first stages. Gives as thorough as possible a treatment of codec management, track change and metadata logic as possible while maintaining fairly narrow focus and not rewriting everything all at once. Please see the rockbox-dev mail archive on 2011-04-25 (Playback engine rework) for a more thorough manifest of what was addressed. Plugins and codecs become incompatible.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29785 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/codecs/vox.c')
-rw-r--r--apps/codecs/vox.c78
1 files changed, 38 insertions, 40 deletions
diff --git a/apps/codecs/vox.c b/apps/codecs/vox.c
index c7f39342c3..bf274c6917 100644
--- a/apps/codecs/vox.c
+++ b/apps/codecs/vox.c
@@ -44,9 +44,19 @@ static uint8_t *read_buffer(size_t *realsize)
44} 44}
45 45
46/* this is the codec entry point */ 46/* this is the codec entry point */
47enum codec_status codec_main(void) 47enum codec_status codec_main(enum codec_entry_call_reason reason)
48{
49 if (reason == CODEC_LOAD) {
50 /* Generic codec initialisation */
51 ci->configure(DSP_SET_SAMPLE_DEPTH, PCM_OUTPUT_DEPTH-1);
52 }
53
54 return CODEC_OK;
55}
56
57/* this is called for each file to process */
58enum codec_status codec_run(void)
48{ 59{
49 int status;
50 uint32_t decodedsamples; 60 uint32_t decodedsamples;
51 size_t n; 61 size_t n;
52 int bufcount; 62 int bufcount;
@@ -54,26 +64,18 @@ enum codec_status codec_main(void)
54 uint8_t *voxbuf; 64 uint8_t *voxbuf;
55 off_t firstblockposn = 0; /* position of the first block in file */ 65 off_t firstblockposn = 0; /* position of the first block in file */
56 const struct pcm_codec *codec; 66 const struct pcm_codec *codec;
57 67 intptr_t param;
58 /* Generic codec initialisation */
59 ci->configure(DSP_SET_SAMPLE_DEPTH, PCM_OUTPUT_DEPTH-1);
60
61next_track:
62 status = CODEC_OK;
63 68
64 if (codec_init()) { 69 if (codec_init()) {
65 DEBUGF("codec_init() error\n"); 70 DEBUGF("codec_init() error\n");
66 status = CODEC_ERROR; 71 return CODEC_ERROR;
67 goto exit;
68 } 72 }
69 73
70 if (codec_wait_taginfo() != 0)
71 goto done;
72
73 codec_set_replaygain(ci->id3); 74 codec_set_replaygain(ci->id3);
74 75
75 /* Need to save offset for later use (cleared indirectly by advance_buffer) */ 76 /* Need to save offset for later use (cleared indirectly by advance_buffer) */
76 bytesdone = ci->id3->offset; 77 bytesdone = ci->id3->offset;
78 ci->seek_buffer(0);
77 79
78 ci->memset(&format, 0, sizeof(struct pcm_format)); 80 ci->memset(&format, 0, sizeof(struct pcm_format));
79 81
@@ -96,20 +98,16 @@ next_track:
96 if (!codec) 98 if (!codec)
97 { 99 {
98 DEBUGF("CODEC_ERROR: dialogic oki adpcm codec does not load.\n"); 100 DEBUGF("CODEC_ERROR: dialogic oki adpcm codec does not load.\n");
99 status = CODEC_ERROR; 101 return CODEC_ERROR;
100 goto done;
101 } 102 }
102 103
103 if (!codec->set_format(&format)) 104 if (!codec->set_format(&format)) {
104 { 105 return CODEC_ERROR;
105 status = CODEC_ERROR;
106 goto done;
107 } 106 }
108 107
109 if (format.numbytes == 0) { 108 if (format.numbytes == 0) {
110 DEBUGF("CODEC_ERROR: data size is 0\n"); 109 DEBUGF("CODEC_ERROR: data size is 0\n");
111 status = CODEC_ERROR; 110 return CODEC_ERROR;
112 goto done;
113 } 111 }
114 112
115 /* check chunksize */ 113 /* check chunksize */
@@ -118,8 +116,7 @@ next_track:
118 if (format.chunksize == 0) 116 if (format.chunksize == 0)
119 { 117 {
120 DEBUGF("CODEC_ERROR: chunksize is 0\n"); 118 DEBUGF("CODEC_ERROR: chunksize is 0\n");
121 status = CODEC_ERROR; 119 return CODEC_ERROR;
122 goto done;
123 } 120 }
124 121
125 ci->configure(DSP_SWITCH_FREQUENCY, ci->id3->frequency); 122 ci->configure(DSP_SWITCH_FREQUENCY, ci->id3->frequency);
@@ -131,14 +128,14 @@ next_track:
131 struct pcm_pos *newpos = codec->get_seek_pos(bytesdone - firstblockposn, 128 struct pcm_pos *newpos = codec->get_seek_pos(bytesdone - firstblockposn,
132 PCM_SEEK_POS, &read_buffer); 129 PCM_SEEK_POS, &read_buffer);
133 130
134 if (newpos->pos > format.numbytes) 131 if (newpos->pos > format.numbytes) {
135 goto done; 132 return CODEC_OK;
133 }
136 if (ci->seek_buffer(firstblockposn + newpos->pos)) 134 if (ci->seek_buffer(firstblockposn + newpos->pos))
137 { 135 {
138 bytesdone = newpos->pos; 136 bytesdone = newpos->pos;
139 decodedsamples = newpos->samples; 137 decodedsamples = newpos->samples;
140 } 138 }
141 ci->seek_complete();
142 } else { 139 } else {
143 /* already where we need to be */ 140 /* already where we need to be */
144 bytesdone = 0; 141 bytesdone = 0;
@@ -148,22 +145,29 @@ next_track:
148 endofstream = 0; 145 endofstream = 0;
149 146
150 while (!endofstream) { 147 while (!endofstream) {
151 ci->yield(); 148 enum codec_command_action action = ci->get_command(&param);
152 if (ci->stop_codec || ci->new_track) { 149
150 if (action == CODEC_ACTION_HALT)
153 break; 151 break;
154 }
155 152
156 if (ci->seek_time) { 153 if (action == CODEC_ACTION_SEEK_TIME) {
157 struct pcm_pos *newpos = codec->get_seek_pos(ci->seek_time, PCM_SEEK_TIME, 154 struct pcm_pos *newpos = codec->get_seek_pos(param, PCM_SEEK_TIME,
158 &read_buffer); 155 &read_buffer);
159 156
160 if (newpos->pos > format.numbytes) 157 if (newpos->pos > format.numbytes)
158 {
159 ci->set_elapsed(ci->id3->length);
160 ci->seek_complete();
161 break; 161 break;
162 }
163
162 if (ci->seek_buffer(firstblockposn + newpos->pos)) 164 if (ci->seek_buffer(firstblockposn + newpos->pos))
163 { 165 {
164 bytesdone = newpos->pos; 166 bytesdone = newpos->pos;
165 decodedsamples = newpos->samples; 167 decodedsamples = newpos->samples;
166 } 168 }
169
170 ci->set_elapsed(decodedsamples*1000LL/ci->id3->frequency);
167 ci->seek_complete(); 171 ci->seek_complete();
168 } 172 }
169 173
@@ -175,11 +179,10 @@ next_track:
175 endofstream = 1; 179 endofstream = 1;
176 } 180 }
177 181
178 status = codec->decode(voxbuf, n, samples, &bufcount); 182 if (codec->decode(voxbuf, n, samples, &bufcount) == CODEC_ERROR)
179 if (status == CODEC_ERROR)
180 { 183 {
181 DEBUGF("codec error\n"); 184 DEBUGF("codec error\n");
182 goto done; 185 return CODEC_ERROR;
183 } 186 }
184 187
185 ci->pcmbuf_insert(samples, NULL, bufcount); 188 ci->pcmbuf_insert(samples, NULL, bufcount);
@@ -192,10 +195,5 @@ next_track:
192 ci->set_elapsed(decodedsamples*1000LL/ci->id3->frequency); 195 ci->set_elapsed(decodedsamples*1000LL/ci->id3->frequency);
193 } 196 }
194 197
195done: 198 return CODEC_OK;
196 if (ci->request_next_track())
197 goto next_track;
198
199exit:
200 return status;
201} 199}