mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-11-16 08:32:36 -05:00
mpegplayer: do some reordering, add some needed volatiles, make sure thread creation failure is handled correctly, make sure audio doesn't attempt to finish remaining data if it was asked to stop.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@13118 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
9cd6394d8c
commit
4bd827b242
1 changed files with 27 additions and 24 deletions
|
|
@ -251,8 +251,8 @@ enum
|
||||||
THREAD_TERMINATED,
|
THREAD_TERMINATED,
|
||||||
};
|
};
|
||||||
|
|
||||||
int audiostatus IBSS_ATTR;
|
volatile int audiostatus IBSS_ATTR;
|
||||||
int videostatus IBSS_ATTR;
|
volatile int videostatus IBSS_ATTR;
|
||||||
|
|
||||||
/* Various buffers */
|
/* Various buffers */
|
||||||
/* TODO: Can we reduce the PCM buffer size? */
|
/* TODO: Can we reduce the PCM buffer size? */
|
||||||
|
|
@ -782,7 +782,7 @@ static struct pcm_frame_header * volatile pcmbuf_head IBSS_ATTR;
|
||||||
static struct pcm_frame_header * volatile pcmbuf_tail IBSS_ATTR;
|
static struct pcm_frame_header * volatile pcmbuf_tail IBSS_ATTR;
|
||||||
|
|
||||||
static volatile uint32_t samplesplayed IBSS_ATTR; /* Our base clock */
|
static volatile uint32_t samplesplayed IBSS_ATTR; /* Our base clock */
|
||||||
static uint32_t samplestart IBSS_ATTR; /* Clock at playback start */
|
static volatile uint32_t samplestart IBSS_ATTR; /* Clock at playback start */
|
||||||
static volatile int32_t sampleadjust IBSS_ATTR; /* Clock drift adjustment */
|
static volatile int32_t sampleadjust IBSS_ATTR; /* Clock drift adjustment */
|
||||||
|
|
||||||
static bool init_pcmbuf(void)
|
static bool init_pcmbuf(void)
|
||||||
|
|
@ -1172,6 +1172,8 @@ static void audio_thread(void)
|
||||||
} /* end decoding loop */
|
} /* end decoding loop */
|
||||||
|
|
||||||
done:
|
done:
|
||||||
|
if (audiostatus != PLEASE_STOP)
|
||||||
|
{
|
||||||
/* Force any residue to play if audio ended before reaching the
|
/* Force any residue to play if audio ended before reaching the
|
||||||
threshold */
|
threshold */
|
||||||
if (pcmbuf_threshold != PCMBUF_PLAY_ALL && pcmbuf_used > 0)
|
if (pcmbuf_threshold != PCMBUF_PLAY_ALL && pcmbuf_used > 0)
|
||||||
|
|
@ -1183,9 +1185,13 @@ done:
|
||||||
if (rb->pcm_is_playing() && !rb->pcm_is_paused())
|
if (rb->pcm_is_playing() && !rb->pcm_is_paused())
|
||||||
{
|
{
|
||||||
/* Wait for audio to finish */
|
/* Wait for audio to finish */
|
||||||
while (pcmbuf_used > 0)
|
while (pcmbuf_used > 0 && audiostatus != PLEASE_STOP)
|
||||||
|
{
|
||||||
|
button_loop();
|
||||||
rb->sleep(HZ/10);
|
rb->sleep(HZ/10);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
audiostatus = STREAM_DONE;
|
audiostatus = STREAM_DONE;
|
||||||
|
|
||||||
|
|
@ -1560,12 +1566,11 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initialize IRAM - stops audio and voice as well */
|
/* Initialize IRAM - stops audio and voice as well */
|
||||||
|
audiobuf = api->plugin_get_audio_buffer(&audiosize);
|
||||||
PLUGIN_IRAM_INIT(api)
|
PLUGIN_IRAM_INIT(api)
|
||||||
|
|
||||||
rb = api;
|
rb = api;
|
||||||
|
|
||||||
audiobuf = rb->plugin_get_audio_buffer(&audiosize);
|
|
||||||
|
|
||||||
/* Set disk pointers to NULL */
|
/* Set disk pointers to NULL */
|
||||||
disk_buf_end = disk_buf = NULL;
|
disk_buf_end = disk_buf = NULL;
|
||||||
|
|
||||||
|
|
@ -1688,14 +1693,12 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
|
||||||
IF_COP(, COP, true))) == NULL)
|
IF_COP(, COP, true))) == NULL)
|
||||||
{
|
{
|
||||||
rb->splash(HZ, "Cannot create video thread!");
|
rb->splash(HZ, "Cannot create video thread!");
|
||||||
videostatus = THREAD_TERMINATED;
|
|
||||||
}
|
}
|
||||||
else if ((audiothread_id = rb->create_thread(audio_thread,
|
else if ((audiothread_id = rb->create_thread(audio_thread,
|
||||||
(uint8_t*)audio_stack,AUDIO_STACKSIZE,"mpgaudio" IF_PRIO(,PRIORITY_PLAYBACK)
|
(uint8_t*)audio_stack,AUDIO_STACKSIZE,"mpgaudio" IF_PRIO(,PRIORITY_PLAYBACK)
|
||||||
IF_COP(, CPU, false))) == NULL)
|
IF_COP(, CPU, false))) == NULL)
|
||||||
{
|
{
|
||||||
rb->splash(HZ, "Cannot create audio thread!");
|
rb->splash(HZ, "Cannot create audio thread!");
|
||||||
audiostatus = THREAD_TERMINATED;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -1736,19 +1739,15 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
|
||||||
status = PLUGIN_OK;
|
status = PLUGIN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef HAVE_LCD_COLOR
|
|
||||||
gray_release();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Stop the threads and wait for them to terminate */
|
/* Stop the threads and wait for them to terminate */
|
||||||
if (videostatus != THREAD_TERMINATED)
|
if (videothread_id != NULL && videostatus != THREAD_TERMINATED)
|
||||||
{
|
{
|
||||||
videostatus = PLEASE_STOP;
|
videostatus = PLEASE_STOP;
|
||||||
while (videostatus != THREAD_TERMINATED)
|
while (videostatus != THREAD_TERMINATED)
|
||||||
rb->yield();
|
rb->yield();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (audiostatus != THREAD_TERMINATED)
|
if (audiothread_id != NULL && audiostatus != THREAD_TERMINATED)
|
||||||
{
|
{
|
||||||
audiostatus = PLEASE_STOP;
|
audiostatus = PLEASE_STOP;
|
||||||
while (audiostatus != THREAD_TERMINATED)
|
while (audiostatus != THREAD_TERMINATED)
|
||||||
|
|
@ -1757,6 +1756,10 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
|
||||||
|
|
||||||
rb->sleep(HZ/10);
|
rb->sleep(HZ/10);
|
||||||
|
|
||||||
|
#ifndef HAVE_LCD_COLOR
|
||||||
|
gray_release();
|
||||||
|
#endif
|
||||||
|
|
||||||
rb->lcd_clear_display();
|
rb->lcd_clear_display();
|
||||||
rb->lcd_update();
|
rb->lcd_update();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue