summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Bavin <pondlife@pondlife.me>2006-10-30 08:54:48 +0000
committerSteve Bavin <pondlife@pondlife.me>2006-10-30 08:54:48 +0000
commit145ec81d2f879482fbfe192dcf39350f36bda3d7 (patch)
tree3aca57766370602bf49be1a1e88eaafed9df6fd2
parentf40f0debcbada2ef635872b9c4d352b7416bf721 (diff)
downloadrockbox-145ec81d2f879482fbfe192dcf39350f36bda3d7.tar.gz
rockbox-145ec81d2f879482fbfe192dcf39350f36bda3d7.zip
Rearrange and comment variable declarations; no functional change
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11391 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/playback.c159
1 files changed, 72 insertions, 87 deletions
diff --git a/apps/playback.c b/apps/playback.c
index feeb61a3ff..53dd05866e 100644
--- a/apps/playback.c
+++ b/apps/playback.c
@@ -154,14 +154,6 @@ enum {
154#endif 154#endif
155#define CODEC_IRAM_SIZE 0xc000 155#define CODEC_IRAM_SIZE 0xc000
156 156
157#ifdef PLAYBACK_VOICE
158#ifdef SIMULATOR
159static unsigned char sim_iram[CODEC_IRAM_SIZE];
160#undef CODEC_IRAM_ORIGIN
161#define CODEC_IRAM_ORIGIN sim_iram
162#endif
163#endif
164
165#ifndef SIMULATOR 157#ifndef SIMULATOR
166extern bool audio_is_initialized; 158extern bool audio_is_initialized;
167#else 159#else
@@ -169,87 +161,66 @@ static bool audio_is_initialized = false;
169#endif 161#endif
170 162
171 163
164/* Variables are commented with the threads that use them: *
165 * A=audio, C=codec, V=voice. A suffix of - indicates that *
166 * the variable is read but not updated on that thread. */
172 167
173static struct mutex mutex_codecthread; 168/* Main state control */
174static struct event_queue codec_callback_queue; 169static struct event_queue codec_callback_queue; /* Queue for codec callback responses */
175 170static volatile bool audio_codec_loaded; /* Is codec loaded? (C/A-) */
176static volatile bool audio_codec_loaded; 171static volatile bool playing; /* Is audio playing? (A) */
177static volatile bool playing; 172static volatile bool paused; /* Is audio paused? (A/C-) */
178static volatile bool paused; 173static volatile bool filling IDATA_ATTR; /* Is file buffer currently being refilled? (A/C-) */
179
180/* Is file buffer currently being refilled? */
181static volatile bool filling IDATA_ATTR;
182
183volatile int current_codec IDATA_ATTR;
184extern unsigned char codecbuf[];
185 174
186/* Ring buffer where tracks and codecs are loaded. */ 175/* Ring buffer where tracks and codecs are loaded */
187static char *filebuf; 176static char *filebuf; /* Pointer to start of ring buffer (A/C-) */
177size_t filebuflen; /* Total size of the ring buffer FIXME: make static (A/C-)*/
178static volatile size_t buf_ridx IDATA_ATTR; /* Ring buffer read position (A/C) FIXME? should be (C/A-) */
179static volatile size_t buf_widx IDATA_ATTR; /* Ring buffer read position (A/C-) */
188 180
189/* Total size of the ring buffer. */
190size_t filebuflen;
191
192/* Ring buffer read and write indexes. */
193static volatile size_t buf_ridx IDATA_ATTR;
194static volatile size_t buf_widx IDATA_ATTR;
195
196/* Ring buffer arithmetic */
197#define RINGBUF_ADD(p,v) ((p+v)<filebuflen ? p+v : p+v-filebuflen) 181#define RINGBUF_ADD(p,v) ((p+v)<filebuflen ? p+v : p+v-filebuflen)
198#define RINGBUF_SUB(p,v) ((p>=v) ? p-v : p+filebuflen-v) 182#define RINGBUF_SUB(p,v) ((p>=v) ? p-v : p+filebuflen-v)
199#define RINGBUF_ADD_CROSS(p1,v,p2) ((p1<p2)?(int)(p1+v)-(int)p2:(int)(p1+v-p2)-(int)filebuflen) 183#define RINGBUF_ADD_CROSS(p1,v,p2) ((p1<p2)?(int)(p1+v)-(int)p2:(int)(p1+v-p2)-(int)filebuflen)
184#define FILEBUFUSED RINGBUF_SUB(buf_widx, buf_ridx) /* Bytes available in the buffer */
200 185
201/* Bytes available in the buffer. */ 186/* Track info buffer */
202#define FILEBUFUSED RINGBUF_SUB(buf_widx, buf_ridx) 187static struct track_info tracks[MAX_TRACK]; /* Track info structure about songs in the file buffer (A/C-) */
203 188static volatile int track_ridx; /* Track being decoded (A/C-) */
204/* Codec swapping pointers */ 189static int track_widx; /* Track being buffered (A) */
205static unsigned char *iram_buf[2]; 190static bool track_changed; /* Set to indicate track has changed (A) */
206static unsigned char *dram_buf[2]; 191static struct track_info *prev_ti; /* Pointer to previous track played info (A/C-) */
207
208/* Step count to the next unbuffered track. */
209static int last_peek_offset; /* Audio thread */
210
211/* Track information (count in file buffer, read/write indexes for
212 track ring structure. */
213static int track_ridx;
214static int track_widx;
215static bool track_changed; /* Audio and codec threads */
216 192
217/* Partially loaded song's file handle to continue buffering later. */ 193#define CUR_TI (&tracks[track_ridx]) /* Pointer to current track playing info (A/C-) */
218static int current_fd;
219 194
220/* Track info structure about songs in the file buffer. */ 195/* Audio buffering controls */
221static struct track_info tracks[MAX_TRACK]; /* Audio thread */ 196static int last_peek_offset; /* Step count to the next unbuffered track (A) */
197static int current_fd; /* Partially loaded track file handle to continue buffering (A) */
222 198
223/* Pointer to track info structure about current song playing. */ 199/* Scrobbler support */
224#define CUR_TI (&tracks[track_ridx]) 200static unsigned long prev_track_elapsed; /* Previous track elapsed time (C/A-) */
225 201
226/* Pointer to track info structure about previous played song. */ 202/* Track change controls */
227static struct track_info *prev_ti; /* Audio and codec threads */ 203static bool automatic_skip = false; /* Was the skip being executed manual or automatic? (C/A-) */
204static bool playlist_end = false; /* Have we reached end of the current playlist? (A) */
205static bool dir_skip = false; /* Is a directory skip pending? (A) */
206static bool new_playlist = false; /* Are we starting a new playlist? (A) */
207static int wps_offset = 0; /* Pending track change offset, to keep WPS responsive (A) */
228 208
229/* Have we reached end of the current playlist. */ 209/* Callbacks.. */
230static bool playlist_end = false; /* Audio thread */ 210void (*track_changed_callback)(struct mp3entry *id3); /* ...when current track has really changed */
231 211void (*track_buffer_callback)(struct mp3entry *id3, bool last_track); /* ...when track has been buffered */
232/* Was the skip being executed manual or automatic? */ 212void (*track_unbuffer_callback)(struct mp3entry *id3, bool last_track); /* ...when track is being unbuffered */
233static bool automatic_skip = false; /* Audio and codec threads */
234static bool dir_skip = false; /* Audio thread */
235static bool new_playlist = false; /* Audio thread */
236static int wps_offset = 0;
237
238/* Callback function to call when current track has really changed. */
239void (*track_changed_callback)(struct mp3entry *id3);
240void (*track_buffer_callback)(struct mp3entry *id3, bool last_track);
241void (*track_unbuffer_callback)(struct mp3entry *id3, bool last_track);
242 213
243/* Configuration */ 214/* Configuration */
244static size_t conf_watermark; 215static size_t conf_watermark; /* Low water mark (A/C) FIXME */
245static size_t conf_filechunk; 216static size_t conf_filechunk; /* Largest chunk the codec accepts (A/C) FIXME */
246static size_t conf_preseek; 217static size_t conf_preseek; /* Codec pre-seek margin (A/C) FIXME */
247static size_t buffer_margin; 218static size_t buffer_margin; /* Buffer margin aka anti-skip buffer (A/C-) */
248static bool v1first = false; 219static bool v1first = false; /* ID3 data control, true if V1 then V2 (A) */
249 220
250/* Multiple threads */ 221/* Multiple threads */
251static const char * get_codec_filename(int enc_spec); 222static const char *get_codec_filename(int enc_spec); /* Returns codec filename (A-/C-/V-) */
252static void set_filebuf_watermark(int seconds); 223static void set_filebuf_watermark(int seconds); /* Set low watermark (A/C) FIXME */
253 224
254/* Audio thread */ 225/* Audio thread */
255static struct event_queue audio_queue; 226static struct event_queue audio_queue;
@@ -267,34 +238,48 @@ static struct event_queue codec_queue;
267static long codec_stack[(DEFAULT_STACK_SIZE + 0x2000)/sizeof(long)] 238static long codec_stack[(DEFAULT_STACK_SIZE + 0x2000)/sizeof(long)]
268IBSS_ATTR; 239IBSS_ATTR;
269static const char codec_thread_name[] = "codec"; 240static const char codec_thread_name[] = "codec";
270/* For modifying thread priority later. */ 241struct thread_entry *codec_thread_p; /* For modifying thread priority later. */
271struct thread_entry *codec_thread_p; 242
243volatile int current_codec IDATA_ATTR; /* Current codec (normal/voice) */
272 244
273/* Voice thread */ 245/* Voice thread */
274#ifdef PLAYBACK_VOICE 246#ifdef PLAYBACK_VOICE
275extern struct codec_api ci_voice;
276 247
277/* Play time of the previous track */ 248extern struct codec_api ci_voice;
278unsigned long prev_track_elapsed;
279 249
280static volatile bool voice_thread_start;
281static volatile bool voice_is_playing;
282static volatile bool voice_codec_loaded;
283static void (*voice_getmore)(unsigned char** start, int* size);
284static char *voicebuf;
285static size_t voice_remaining;
286static struct thread_entry *voice_thread_p = NULL; 250static struct thread_entry *voice_thread_p = NULL;
287
288static struct event_queue voice_queue; 251static struct event_queue voice_queue;
289static long voice_stack[(DEFAULT_STACK_SIZE + 0x2000)/sizeof(long)] 252static long voice_stack[(DEFAULT_STACK_SIZE + 0x2000)/sizeof(long)]
290IBSS_ATTR; 253IBSS_ATTR;
291static const char voice_thread_name[] = "voice codec"; 254static const char voice_thread_name[] = "voice codec";
255
256/* Voice codec swapping control */
257extern unsigned char codecbuf[]; /* DRAM codec swap buffer */
258
259#ifdef SIMULATOR
260static unsigned char sim_iram[CODEC_IRAM_SIZE]; /* IRAM codec swap buffer for sim*/
261#undef CODEC_IRAM_ORIGIN
262#define CODEC_IRAM_ORIGIN sim_iram
263#endif
264
265static unsigned char *iram_buf[2]; /* Ptr to IRAM buffers for normal/voice codecs */
266static unsigned char *dram_buf[2]; /* Ptr to DRAM buffers for normal/voice codecs */
267static struct mutex mutex_codecthread; /* Mutex to control which codec (normal/voice) is running */
268
269/* Voice state */
270static volatile bool voice_thread_start; /* Set to trigger voice playback (A/V) */
271static volatile bool voice_is_playing; /* Is voice currently playing? (V) */
272static volatile bool voice_codec_loaded; /* Is voice codec loaded (V/A-) */
273static char *voicebuf;
274static size_t voice_remaining;
275
276static void (*voice_getmore)(unsigned char** start, int* size);
277
292struct voice_info { 278struct voice_info {
293 void (*callback)(unsigned char **start, int *size); 279 void (*callback)(unsigned char **start, int *size);
294 int size; 280 int size;
295 char *buf; 281 char *buf;
296}; 282};
297
298static void voice_thread(void); 283static void voice_thread(void);
299 284
300#endif /* PLAYBACK_VOICE */ 285#endif /* PLAYBACK_VOICE */
@@ -1585,7 +1570,7 @@ static void codec_configure_callback(int setting, void *value)
1585static void codec_track_changed(void) 1570static void codec_track_changed(void)
1586{ 1571{
1587 automatic_skip = false; 1572 automatic_skip = false;
1588 track_changed = true; 1573 track_changed = true; /* FIXME: should only be updated on the audio thread? */
1589 LOGFQUEUE("codec > audio Q_AUDIO_TRACK_CHANGED"); 1574 LOGFQUEUE("codec > audio Q_AUDIO_TRACK_CHANGED");
1590 queue_post(&audio_queue, Q_AUDIO_TRACK_CHANGED, 0); 1575 queue_post(&audio_queue, Q_AUDIO_TRACK_CHANGED, 0);
1591} 1576}