summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2007-07-20 03:56:59 +0000
committerMichael Sevakis <jethead71@rockbox.org>2007-07-20 03:56:59 +0000
commit930278bcc0fd944ec50f30074b53b4c7cf0e3ccf (patch)
tree72c63c767c8b15dbad03217744e7b5b6ab44af13
parentbab671eb4d4f72cffdf48b3d6d6b81d4c8814e61 (diff)
downloadrockbox-930278bcc0fd944ec50f30074b53b4c7cf0e3ccf.tar.gz
rockbox-930278bcc0fd944ec50f30074b53b4c7cf0e3ccf.zip
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
-rw-r--r--apps/plugins/mpegplayer/mpegplayer.c52
1 files changed, 24 insertions, 28 deletions
diff --git a/apps/plugins/mpegplayer/mpegplayer.c b/apps/plugins/mpegplayer/mpegplayer.c
index cbd4999655..a3f64afd72 100644
--- a/apps/plugins/mpegplayer/mpegplayer.c
+++ b/apps/plugins/mpegplayer/mpegplayer.c
@@ -200,9 +200,9 @@ static Stream video_str IBSS_ATTR;
200/* Messages */ 200/* Messages */
201enum 201enum
202{ 202{
203 STREAM_STOP,
204 STREAM_PLAY, 203 STREAM_PLAY,
205 STREAM_PAUSE, 204 STREAM_PAUSE,
205 STREAM_QUIT
206}; 206};
207 207
208/* Status */ 208/* Status */
@@ -250,13 +250,12 @@ static void str_wait_msg(Stream *str)
250 250
251/* Returns a message waiting or blocks until one is available - removes the 251/* Returns a message waiting or blocks until one is available - removes the
252 event */ 252 event */
253static bool str_get_msg(Stream *str, struct event *ev) 253static void str_get_msg(Stream *str, struct event *ev)
254{ 254{
255 str_wait_msg(str); 255 str_wait_msg(str);
256 ev->id = str->ev.id; 256 ev->id = str->ev.id;
257 ev->data = str->ev.data; 257 ev->data = str->ev.data;
258 str->have_msg = 0; 258 str->have_msg = 0;
259 return true;
260} 259}
261 260
262/* Peeks at the current message without blocking, returns the data but 261/* Peeks at the current message without blocking, returns the data but
@@ -964,10 +963,9 @@ static int button_loop(void)
964 struct event ev; 963 struct event ev;
965 str_get_msg(&audio_str, &ev); 964 str_get_msg(&audio_str, &ev);
966 965
967 if (ev.id == STREAM_STOP) 966 if (ev.id == STREAM_QUIT)
968 { 967 {
969 audio_str.status = STREAM_STOPPED; 968 audio_str.status = STREAM_STOPPED;
970 str_reply_msg(&audio_str, 1);
971 goto quit; 969 goto quit;
972 } 970 }
973 else 971 else
@@ -1031,7 +1029,7 @@ static int button_loop(void)
1031 rb->lcd_setfont(FONT_SYSFIXED); 1029 rb->lcd_setfont(FONT_SYSFIXED);
1032 1030
1033 if (result) { 1031 if (result) {
1034 str_send_msg(&video_str, STREAM_STOP, 0); 1032 str_send_msg(&video_str, STREAM_QUIT, 0);
1035 audio_str.status = STREAM_STOPPED; 1033 audio_str.status = STREAM_STOPPED;
1036 } else { 1034 } else {
1037 audio_str.status = STREAM_PLAYING; 1035 audio_str.status = STREAM_PLAYING;
@@ -1041,7 +1039,7 @@ static int button_loop(void)
1041 break; 1039 break;
1042 1040
1043 case MPEG_STOP: 1041 case MPEG_STOP:
1044 str_send_msg(&video_str, STREAM_STOP, 0); 1042 str_send_msg(&video_str, STREAM_QUIT, 0);
1045 audio_str.status = STREAM_STOPPED; 1043 audio_str.status = STREAM_STOPPED;
1046 break; 1044 break;
1047 1045
@@ -1057,7 +1055,7 @@ static int button_loop(void)
1057 do { 1055 do {
1058 button = rb->button_get(true); 1056 button = rb->button_get(true);
1059 if (button == MPEG_STOP) { 1057 if (button == MPEG_STOP) {
1060 str_send_msg(&video_str, STREAM_STOP, 0); 1058 str_send_msg(&video_str, STREAM_QUIT, 0);
1061 audio_str.status = STREAM_STOPPED; 1059 audio_str.status = STREAM_STOPPED;
1062 goto quit; 1060 goto quit;
1063 } 1061 }
@@ -1073,7 +1071,7 @@ static int button_loop(void)
1073 1071
1074 default: 1072 default:
1075 if(rb->default_event_handler(button) == SYS_USB_CONNECTED) { 1073 if(rb->default_event_handler(button) == SYS_USB_CONNECTED) {
1076 str_send_msg(&video_str, STREAM_STOP, 0); 1074 str_send_msg(&video_str, STREAM_QUIT, 0);
1077 audio_str.status = STREAM_STOPPED; 1075 audio_str.status = STREAM_STOPPED;
1078 } 1076 }
1079 } 1077 }
@@ -1114,8 +1112,8 @@ static void audio_thread(void)
1114 int mad_stat; 1112 int mad_stat;
1115 size_t len; 1113 size_t len;
1116 1114
1117 if (button_loop() < 0) 1115 if (button_loop() == STREAM_STOPPED)
1118 goto done; 1116 goto audio_thread_quit;
1119 1117
1120 if (pts->size <= 0) 1118 if (pts->size <= 0)
1121 { 1119 {
@@ -1269,12 +1267,8 @@ static void audio_thread(void)
1269 struct event ev; 1267 struct event ev;
1270 str_look_msg(&audio_str, &ev); 1268 str_look_msg(&audio_str, &ev);
1271 1269
1272 if (ev.id == STREAM_STOP) 1270 if (ev.id == STREAM_QUIT)
1273 { 1271 goto audio_thread_quit;
1274 str_get_msg(&audio_str, &ev);
1275 str_reply_msg(&audio_str, 1);
1276 goto stop_and_wait;
1277 }
1278 } 1272 }
1279 1273
1280 rb->priority_yield(); 1274 rb->priority_yield();
@@ -1337,7 +1331,7 @@ static void audio_thread(void)
1337 1331
1338done: 1332done:
1339 if (audio_str.status == STREAM_STOPPED) 1333 if (audio_str.status == STREAM_STOPPED)
1340 goto stop_and_wait; 1334 goto audio_thread_quit;
1341 1335
1342 /* Force any residue to play if audio ended before reaching the 1336 /* Force any residue to play if audio ended before reaching the
1343 threshold */ 1337 threshold */
@@ -1353,19 +1347,18 @@ done:
1353 while (pcmbuf_used() > 0) 1347 while (pcmbuf_used() > 0)
1354 { 1348 {
1355 if (button_loop() == STREAM_STOPPED) 1349 if (button_loop() == STREAM_STOPPED)
1356 break; 1350 goto audio_thread_quit;
1357 rb->sleep(HZ/10); 1351 rb->sleep(HZ/10);
1358 } 1352 }
1359 } 1353 }
1360 1354
1361stop_and_wait:
1362
1363 audio_str.status = STREAM_DONE; 1355 audio_str.status = STREAM_DONE;
1364 1356
1365 /* Process events until finished */ 1357 /* Process events until finished */
1366 while (button_loop() != STREAM_STOPPED) 1358 while (button_loop() != STREAM_STOPPED)
1367 rb->sleep(HZ/4); 1359 rb->sleep(HZ/4);
1368 1360
1361audio_thread_quit:
1369 pcm_playback_stop(); 1362 pcm_playback_stop();
1370 1363
1371 audio_str.status = STREAM_TERMINATED; 1364 audio_str.status = STREAM_TERMINATED;
@@ -1444,10 +1437,9 @@ static void video_thread(void)
1444 1437
1445 switch (ev.id) 1438 switch (ev.id)
1446 { 1439 {
1447 case STREAM_STOP: 1440 case STREAM_QUIT:
1448 video_str.status = STREAM_STOPPED; 1441 video_str.status = STREAM_STOPPED;
1449 str_reply_msg(&video_str, 1); 1442 goto video_thread_quit;
1450 goto done;
1451 case STREAM_PAUSE: 1443 case STREAM_PAUSE:
1452 flush_icache(); 1444 flush_icache();
1453 video_str.status = STREAM_PAUSED; 1445 video_str.status = STREAM_PAUSED;
@@ -1695,9 +1687,11 @@ static void video_thread(void)
1695 { 1687 {
1696 str_look_msg(&video_str, &ev); 1688 str_look_msg(&video_str, &ev);
1697 1689
1690 /* If not to play, process up top */
1698 if (ev.id != STREAM_PLAY) 1691 if (ev.id != STREAM_PLAY)
1699 goto rendering_finished; 1692 goto rendering_finished;
1700 1693
1694 /* Told to play but already playing */
1701 str_get_msg(&video_str, &ev); 1695 str_get_msg(&video_str, &ev);
1702 str_reply_msg(&video_str, 1); 1696 str_reply_msg(&video_str, 1);
1703 } 1697 }
@@ -1753,14 +1747,16 @@ done:
1753 { 1747 {
1754 str_get_msg(&video_str, &ev); 1748 str_get_msg(&video_str, &ev);
1755 1749
1756 if (ev.id == STREAM_STOP) 1750 if (ev.id == STREAM_QUIT)
1757 break; 1751 break;
1758 1752
1759 str_reply_msg(&video_str, 0); 1753 str_reply_msg(&video_str, 0);
1760 } 1754 }
1761 1755
1756video_thread_quit:
1757 flush_icache();
1758
1762 /* Commit suicide */ 1759 /* Commit suicide */
1763 str_reply_msg(&video_str, 1);
1764 video_str.status = STREAM_TERMINATED; 1760 video_str.status = STREAM_TERMINATED;
1765 rb->remove_thread(NULL); 1761 rb->remove_thread(NULL);
1766} 1762}
@@ -1984,10 +1980,10 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
1984 1980
1985 /* Stop the threads and wait for them to terminate */ 1981 /* Stop the threads and wait for them to terminate */
1986 if (video_str.thread != NULL) 1982 if (video_str.thread != NULL)
1987 str_send_msg(&video_str, STREAM_STOP, 0); 1983 str_send_msg(&video_str, STREAM_QUIT, 0);
1988 1984
1989 if (audio_str.thread != NULL) 1985 if (audio_str.thread != NULL)
1990 str_send_msg(&audio_str, STREAM_STOP, 0); 1986 str_send_msg(&audio_str, STREAM_QUIT, 0);
1991 1987
1992 rb->sleep(HZ/10); 1988 rb->sleep(HZ/10);
1993 1989