summaryrefslogtreecommitdiff
path: root/apps/playback.c
diff options
context:
space:
mode:
authorJeffrey Goode <jeffg7@gmail.com>2009-11-01 19:39:23 +0000
committerJeffrey Goode <jeffg7@gmail.com>2009-11-01 19:39:23 +0000
commite8eefe98bfd3768a9f3962bc71f0ee0431bae8b1 (patch)
tree8ce274e93fe8882fc25ed61ce5890cbd76c20e5c /apps/playback.c
parentbcadf96066c20953ae6be7447f1ee2cd8742ab4f (diff)
downloadrockbox-e8eefe98bfd3768a9f3962bc71f0ee0431bae8b1.tar.gz
rockbox-e8eefe98bfd3768a9f3962bc71f0ee0431bae8b1.zip
Code cleanup in codec_thread, playback and pcmbuf; more elegant solution to leftover samples
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@23471 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/playback.c')
-rw-r--r--apps/playback.c57
1 files changed, 12 insertions, 45 deletions
diff --git a/apps/playback.c b/apps/playback.c
index 57ed3bdb96..35f1e8ff4d 100644
--- a/apps/playback.c
+++ b/apps/playback.c
@@ -23,70 +23,36 @@
23/* TODO: Pause should be handled in here, rather than PCMBUF so that voice can 23/* TODO: Pause should be handled in here, rather than PCMBUF so that voice can
24 * play whilst audio is paused */ 24 * play whilst audio is paused */
25 25
26//#include <stdio.h>
27#include <string.h> 26#include <string.h>
28//#include <ctype.h>
29
30#include "playback.h" 27#include "playback.h"
31#include "codec_thread.h" 28#include "codec_thread.h"
32//#include "system.h"
33//#include "thread.h"
34//#include "file.h"
35//#include "panic.h"
36//#include "memory.h"
37//#include "lcd.h"
38//#include "font.h"
39//#include "button.h"
40#include "kernel.h" 29#include "kernel.h"
41//#include "tree.h"
42//#include "debug.h"
43//#include "sprintf.h"
44//#include "settings.h"
45#include "codecs.h" 30#include "codecs.h"
46//#include "audio.h"
47#include "buffering.h" 31#include "buffering.h"
48//#include "appevents.h"
49#include "voice_thread.h" 32#include "voice_thread.h"
50//#include "mp3_playback.h"
51#include "usb.h" 33#include "usb.h"
52//#include "storage.h"
53#include "ata.h" 34#include "ata.h"
54//#include "screens.h"
55#include "playlist.h" 35#include "playlist.h"
56#include "pcmbuf.h" 36#include "pcmbuf.h"
57#include "buffer.h" 37#include "buffer.h"
58//#include "dsp.h"
59//#include "abrepeat.h"
60#include "cuesheet.h" 38#include "cuesheet.h"
61#ifdef HAVE_TAGCACHE 39#ifdef HAVE_TAGCACHE
62#include "tagcache.h" 40#include "tagcache.h"
63#endif 41#endif
64#ifdef HAVE_LCD_BITMAP 42#ifdef HAVE_LCD_BITMAP
65//#include "icons.h"
66//#include "peakmeter.h"
67//#include "action.h"
68#ifdef HAVE_ALBUMART 43#ifdef HAVE_ALBUMART
69#include "albumart.h" 44#include "albumart.h"
70//#include "bmp.h"
71#endif 45#endif
72#endif 46#endif
73//#include "lang.h"
74//#include "misc.h"
75#include "sound.h" 47#include "sound.h"
76#include "metadata.h" 48#include "metadata.h"
77#include "splash.h" 49#include "splash.h"
78#include "talk.h" 50#include "talk.h"
79//#include "ata_idle_notify.h"
80 51
81#ifdef HAVE_RECORDING 52#ifdef HAVE_RECORDING
82//#include "recording.h"
83#include "pcm_record.h" 53#include "pcm_record.h"
84#endif 54#endif
85 55
86#ifdef IPOD_ACCESSORY_PROTOCOL
87//#include "iap.h"
88#endif
89
90#define PLAYBACK_VOICE 56#define PLAYBACK_VOICE
91 57
92/* amount of guess-space to allow for codecs that must hunt and peck 58/* amount of guess-space to allow for codecs that must hunt and peck
@@ -139,8 +105,9 @@ static bool audio_thread_ready SHAREDBSS_ATTR = false;
139/* TBD: Split out "audio" and "playback" (ie. calling) threads */ 105/* TBD: Split out "audio" and "playback" (ie. calling) threads */
140 106
141/* Main state control */ 107/* Main state control */
142static volatile bool playing SHAREDBSS_ATTR = false; /* Is audio playing? (A) */ 108static volatile bool playing SHAREDBSS_ATTR = false;/* Is audio playing? (A) */
143static volatile bool paused SHAREDBSS_ATTR = false; /* Is audio paused? (A/C-) */ 109static volatile bool paused SHAREDBSS_ATTR = false; /* Is audio paused? (A/C-) */
110extern volatile bool audio_codec_loaded; /* Codec loaded? (C/A-) */
144 111
145/* Ring buffer where compressed audio and codecs are loaded */ 112/* Ring buffer where compressed audio and codecs are loaded */
146static unsigned char *filebuf = NULL; /* Start of buffer (A/C-) */ 113static unsigned char *filebuf = NULL; /* Start of buffer (A/C-) */
@@ -233,7 +200,7 @@ static size_t buffer_margin = 5; /* Buffer margin aka anti-skip buffer (A/C-) *
233/* Event queues */ 200/* Event queues */
234struct event_queue audio_queue SHAREDBSS_ATTR; 201struct event_queue audio_queue SHAREDBSS_ATTR;
235struct event_queue codec_queue SHAREDBSS_ATTR; 202struct event_queue codec_queue SHAREDBSS_ATTR;
236struct event_queue pcmbuf_queue SHAREDBSS_ATTR; 203static struct event_queue pcmbuf_queue SHAREDBSS_ATTR;
237 204
238extern struct codec_api ci; 205extern struct codec_api ci;
239extern unsigned int codec_thread_id; 206extern unsigned int codec_thread_id;
@@ -256,6 +223,13 @@ static void audio_stop_playback(void);
256 223
257/**************************************/ 224/**************************************/
258 225
226/* Post message from pcmbuf callback in the codec thread that
227 * the end of the previous track has just been played. */
228void audio_post_track_change(void)
229{
230 queue_post(&pcmbuf_queue, Q_AUDIO_TRACK_CHANGED, 0);
231}
232
259/* Scan the pcmbuf queue and return true if a message pulled. 233/* Scan the pcmbuf queue and return true if a message pulled.
260 * Permissible Context(s): Thread 234 * Permissible Context(s): Thread
261 */ 235 */
@@ -1077,7 +1051,7 @@ static bool audio_loadcodec(bool start_play)
1077 if (id3 && prev_id3 && 1051 if (id3 && prev_id3 &&
1078 get_codec_base_type(id3->codectype) == 1052 get_codec_base_type(id3->codectype) ==
1079 get_codec_base_type(prev_id3->codectype) 1053 get_codec_base_type(prev_id3->codectype)
1080 && codec_is_loaded()) 1054 && audio_codec_loaded)
1081 { 1055 {
1082 logf("Reusing prev. codec"); 1056 logf("Reusing prev. codec");
1083 return true; 1057 return true;
@@ -1634,7 +1608,7 @@ static void audio_stop_codec_flush(void)
1634 ci.stop_codec = true; 1608 ci.stop_codec = true;
1635 pcmbuf_pause(true); 1609 pcmbuf_pause(true);
1636 1610
1637 while (codec_is_loaded()) 1611 while (audio_codec_loaded)
1638 yield(); 1612 yield();
1639 1613
1640 /* If the audio codec is not loaded any more, and the audio is still 1614 /* If the audio codec is not loaded any more, and the audio is still
@@ -1652,13 +1626,6 @@ static void audio_stop_playback(void)
1652{ 1626{
1653 if (playing) 1627 if (playing)
1654 { 1628 {
1655 /* If still actively playing here, play out the last samples in the
1656 * pcm buffer before stopping. If a manual stop has occurred, the
1657 * paused flag is set, so don't continue playback.
1658 */
1659 if (!paused)
1660 pcmbuf_play_remainder();
1661
1662 /* If we were playing, save resume information */ 1629 /* If we were playing, save resume information */
1663 struct mp3entry *id3 = NULL; 1630 struct mp3entry *id3 = NULL;
1664 1631