mpegplayer: Refine the earlier additions and be more explicit about a message intent by renaming it.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@13938 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Michael Sevakis 2007-07-20 03:56:59 +00:00
parent bab671eb4d
commit 930278bcc0

View file

@ -200,9 +200,9 @@ static Stream video_str IBSS_ATTR;
/* Messages */ /* Messages */
enum enum
{ {
STREAM_STOP,
STREAM_PLAY, STREAM_PLAY,
STREAM_PAUSE, STREAM_PAUSE,
STREAM_QUIT
}; };
/* Status */ /* Status */
@ -250,13 +250,12 @@ static void str_wait_msg(Stream *str)
/* Returns a message waiting or blocks until one is available - removes the /* Returns a message waiting or blocks until one is available - removes the
event */ event */
static bool str_get_msg(Stream *str, struct event *ev) static void str_get_msg(Stream *str, struct event *ev)
{ {
str_wait_msg(str); str_wait_msg(str);
ev->id = str->ev.id; ev->id = str->ev.id;
ev->data = str->ev.data; ev->data = str->ev.data;
str->have_msg = 0; str->have_msg = 0;
return true;
} }
/* Peeks at the current message without blocking, returns the data but /* Peeks at the current message without blocking, returns the data but
@ -964,10 +963,9 @@ static int button_loop(void)
struct event ev; struct event ev;
str_get_msg(&audio_str, &ev); str_get_msg(&audio_str, &ev);
if (ev.id == STREAM_STOP) if (ev.id == STREAM_QUIT)
{ {
audio_str.status = STREAM_STOPPED; audio_str.status = STREAM_STOPPED;
str_reply_msg(&audio_str, 1);
goto quit; goto quit;
} }
else else
@ -1031,7 +1029,7 @@ static int button_loop(void)
rb->lcd_setfont(FONT_SYSFIXED); rb->lcd_setfont(FONT_SYSFIXED);
if (result) { if (result) {
str_send_msg(&video_str, STREAM_STOP, 0); str_send_msg(&video_str, STREAM_QUIT, 0);
audio_str.status = STREAM_STOPPED; audio_str.status = STREAM_STOPPED;
} else { } else {
audio_str.status = STREAM_PLAYING; audio_str.status = STREAM_PLAYING;
@ -1041,7 +1039,7 @@ static int button_loop(void)
break; break;
case MPEG_STOP: case MPEG_STOP:
str_send_msg(&video_str, STREAM_STOP, 0); str_send_msg(&video_str, STREAM_QUIT, 0);
audio_str.status = STREAM_STOPPED; audio_str.status = STREAM_STOPPED;
break; break;
@ -1057,7 +1055,7 @@ static int button_loop(void)
do { do {
button = rb->button_get(true); button = rb->button_get(true);
if (button == MPEG_STOP) { if (button == MPEG_STOP) {
str_send_msg(&video_str, STREAM_STOP, 0); str_send_msg(&video_str, STREAM_QUIT, 0);
audio_str.status = STREAM_STOPPED; audio_str.status = STREAM_STOPPED;
goto quit; goto quit;
} }
@ -1073,7 +1071,7 @@ static int button_loop(void)
default: default:
if(rb->default_event_handler(button) == SYS_USB_CONNECTED) { if(rb->default_event_handler(button) == SYS_USB_CONNECTED) {
str_send_msg(&video_str, STREAM_STOP, 0); str_send_msg(&video_str, STREAM_QUIT, 0);
audio_str.status = STREAM_STOPPED; audio_str.status = STREAM_STOPPED;
} }
} }
@ -1114,8 +1112,8 @@ static void audio_thread(void)
int mad_stat; int mad_stat;
size_t len; size_t len;
if (button_loop() < 0) if (button_loop() == STREAM_STOPPED)
goto done; goto audio_thread_quit;
if (pts->size <= 0) if (pts->size <= 0)
{ {
@ -1269,12 +1267,8 @@ static void audio_thread(void)
struct event ev; struct event ev;
str_look_msg(&audio_str, &ev); str_look_msg(&audio_str, &ev);
if (ev.id == STREAM_STOP) if (ev.id == STREAM_QUIT)
{ goto audio_thread_quit;
str_get_msg(&audio_str, &ev);
str_reply_msg(&audio_str, 1);
goto stop_and_wait;
}
} }
rb->priority_yield(); rb->priority_yield();
@ -1337,7 +1331,7 @@ static void audio_thread(void)
done: done:
if (audio_str.status == STREAM_STOPPED) if (audio_str.status == STREAM_STOPPED)
goto stop_and_wait; goto audio_thread_quit;
/* Force any residue to play if audio ended before reaching the /* Force any residue to play if audio ended before reaching the
threshold */ threshold */
@ -1353,19 +1347,18 @@ done:
while (pcmbuf_used() > 0) while (pcmbuf_used() > 0)
{ {
if (button_loop() == STREAM_STOPPED) if (button_loop() == STREAM_STOPPED)
break; goto audio_thread_quit;
rb->sleep(HZ/10); rb->sleep(HZ/10);
} }
} }
stop_and_wait:
audio_str.status = STREAM_DONE; audio_str.status = STREAM_DONE;
/* Process events until finished */ /* Process events until finished */
while (button_loop() != STREAM_STOPPED) while (button_loop() != STREAM_STOPPED)
rb->sleep(HZ/4); rb->sleep(HZ/4);
audio_thread_quit:
pcm_playback_stop(); pcm_playback_stop();
audio_str.status = STREAM_TERMINATED; audio_str.status = STREAM_TERMINATED;
@ -1444,10 +1437,9 @@ static void video_thread(void)
switch (ev.id) switch (ev.id)
{ {
case STREAM_STOP: case STREAM_QUIT:
video_str.status = STREAM_STOPPED; video_str.status = STREAM_STOPPED;
str_reply_msg(&video_str, 1); goto video_thread_quit;
goto done;
case STREAM_PAUSE: case STREAM_PAUSE:
flush_icache(); flush_icache();
video_str.status = STREAM_PAUSED; video_str.status = STREAM_PAUSED;
@ -1695,9 +1687,11 @@ static void video_thread(void)
{ {
str_look_msg(&video_str, &ev); str_look_msg(&video_str, &ev);
/* If not to play, process up top */
if (ev.id != STREAM_PLAY) if (ev.id != STREAM_PLAY)
goto rendering_finished; goto rendering_finished;
/* Told to play but already playing */
str_get_msg(&video_str, &ev); str_get_msg(&video_str, &ev);
str_reply_msg(&video_str, 1); str_reply_msg(&video_str, 1);
} }
@ -1753,14 +1747,16 @@ done:
{ {
str_get_msg(&video_str, &ev); str_get_msg(&video_str, &ev);
if (ev.id == STREAM_STOP) if (ev.id == STREAM_QUIT)
break; break;
str_reply_msg(&video_str, 0); str_reply_msg(&video_str, 0);
} }
video_thread_quit:
flush_icache();
/* Commit suicide */ /* Commit suicide */
str_reply_msg(&video_str, 1);
video_str.status = STREAM_TERMINATED; video_str.status = STREAM_TERMINATED;
rb->remove_thread(NULL); rb->remove_thread(NULL);
} }
@ -1984,10 +1980,10 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
/* Stop the threads and wait for them to terminate */ /* Stop the threads and wait for them to terminate */
if (video_str.thread != NULL) if (video_str.thread != NULL)
str_send_msg(&video_str, STREAM_STOP, 0); str_send_msg(&video_str, STREAM_QUIT, 0);
if (audio_str.thread != NULL) if (audio_str.thread != NULL)
str_send_msg(&audio_str, STREAM_STOP, 0); str_send_msg(&audio_str, STREAM_QUIT, 0);
rb->sleep(HZ/10); rb->sleep(HZ/10);