summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/plugins/mpegplayer/mpegplayer.c51
1 files changed, 27 insertions, 24 deletions
diff --git a/apps/plugins/mpegplayer/mpegplayer.c b/apps/plugins/mpegplayer/mpegplayer.c
index 440bbd721d..50452b6fdc 100644
--- a/apps/plugins/mpegplayer/mpegplayer.c
+++ b/apps/plugins/mpegplayer/mpegplayer.c
@@ -251,8 +251,8 @@ enum
251 THREAD_TERMINATED, 251 THREAD_TERMINATED,
252}; 252};
253 253
254int audiostatus IBSS_ATTR; 254volatile int audiostatus IBSS_ATTR;
255int videostatus IBSS_ATTR; 255volatile int videostatus IBSS_ATTR;
256 256
257/* Various buffers */ 257/* Various buffers */
258/* TODO: Can we reduce the PCM buffer size? */ 258/* TODO: Can we reduce the PCM buffer size? */
@@ -782,7 +782,7 @@ static struct pcm_frame_header * volatile pcmbuf_head IBSS_ATTR;
782static struct pcm_frame_header * volatile pcmbuf_tail IBSS_ATTR; 782static struct pcm_frame_header * volatile pcmbuf_tail IBSS_ATTR;
783 783
784static volatile uint32_t samplesplayed IBSS_ATTR; /* Our base clock */ 784static volatile uint32_t samplesplayed IBSS_ATTR; /* Our base clock */
785static uint32_t samplestart IBSS_ATTR; /* Clock at playback start */ 785static volatile uint32_t samplestart IBSS_ATTR; /* Clock at playback start */
786static volatile int32_t sampleadjust IBSS_ATTR; /* Clock drift adjustment */ 786static volatile int32_t sampleadjust IBSS_ATTR; /* Clock drift adjustment */
787 787
788static bool init_pcmbuf(void) 788static bool init_pcmbuf(void)
@@ -1172,19 +1172,25 @@ static void audio_thread(void)
1172 } /* end decoding loop */ 1172 } /* end decoding loop */
1173 1173
1174done: 1174done:
1175 /* Force any residue to play if audio ended before reaching the 1175 if (audiostatus != PLEASE_STOP)
1176 threshold */
1177 if (pcmbuf_threshold != PCMBUF_PLAY_ALL && pcmbuf_used > 0)
1178 { 1176 {
1179 pcm_playback_play(pcmbuf_tail->time); 1177 /* Force any residue to play if audio ended before reaching the
1180 pcmbuf_threshold = PCMBUF_PLAY_ALL; 1178 threshold */
1181 } 1179 if (pcmbuf_threshold != PCMBUF_PLAY_ALL && pcmbuf_used > 0)
1180 {
1181 pcm_playback_play(pcmbuf_tail->time);
1182 pcmbuf_threshold = PCMBUF_PLAY_ALL;
1183 }
1182 1184
1183 if (rb->pcm_is_playing() && !rb->pcm_is_paused()) 1185 if (rb->pcm_is_playing() && !rb->pcm_is_paused())
1184 { 1186 {
1185 /* Wait for audio to finish */ 1187 /* Wait for audio to finish */
1186 while (pcmbuf_used > 0) 1188 while (pcmbuf_used > 0 && audiostatus != PLEASE_STOP)
1187 rb->sleep(HZ/10); 1189 {
1190 button_loop();
1191 rb->sleep(HZ/10);
1192 }
1193 }
1188 } 1194 }
1189 1195
1190 audiostatus = STREAM_DONE; 1196 audiostatus = STREAM_DONE;
@@ -1560,12 +1566,11 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
1560 } 1566 }
1561 1567
1562 /* Initialize IRAM - stops audio and voice as well */ 1568 /* Initialize IRAM - stops audio and voice as well */
1569 audiobuf = api->plugin_get_audio_buffer(&audiosize);
1563 PLUGIN_IRAM_INIT(api) 1570 PLUGIN_IRAM_INIT(api)
1564 1571
1565 rb = api; 1572 rb = api;
1566 1573
1567 audiobuf = rb->plugin_get_audio_buffer(&audiosize);
1568
1569 /* Set disk pointers to NULL */ 1574 /* Set disk pointers to NULL */
1570 disk_buf_end = disk_buf = NULL; 1575 disk_buf_end = disk_buf = NULL;
1571 1576
@@ -1688,14 +1693,12 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
1688 IF_COP(, COP, true))) == NULL) 1693 IF_COP(, COP, true))) == NULL)
1689 { 1694 {
1690 rb->splash(HZ, "Cannot create video thread!"); 1695 rb->splash(HZ, "Cannot create video thread!");
1691 videostatus = THREAD_TERMINATED;
1692 } 1696 }
1693 else if ((audiothread_id = rb->create_thread(audio_thread, 1697 else if ((audiothread_id = rb->create_thread(audio_thread,
1694 (uint8_t*)audio_stack,AUDIO_STACKSIZE,"mpgaudio" IF_PRIO(,PRIORITY_PLAYBACK) 1698 (uint8_t*)audio_stack,AUDIO_STACKSIZE,"mpgaudio" IF_PRIO(,PRIORITY_PLAYBACK)
1695 IF_COP(, CPU, false))) == NULL) 1699 IF_COP(, CPU, false))) == NULL)
1696 { 1700 {
1697 rb->splash(HZ, "Cannot create audio thread!"); 1701 rb->splash(HZ, "Cannot create audio thread!");
1698 audiostatus = THREAD_TERMINATED;
1699 } 1702 }
1700 else 1703 else
1701 { 1704 {
@@ -1736,19 +1739,15 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
1736 status = PLUGIN_OK; 1739 status = PLUGIN_OK;
1737 } 1740 }
1738 1741
1739#ifndef HAVE_LCD_COLOR
1740 gray_release();
1741#endif
1742
1743 /* Stop the threads and wait for them to terminate */ 1742 /* Stop the threads and wait for them to terminate */
1744 if (videostatus != THREAD_TERMINATED) 1743 if (videothread_id != NULL && videostatus != THREAD_TERMINATED)
1745 { 1744 {
1746 videostatus = PLEASE_STOP; 1745 videostatus = PLEASE_STOP;
1747 while (videostatus != THREAD_TERMINATED) 1746 while (videostatus != THREAD_TERMINATED)
1748 rb->yield(); 1747 rb->yield();
1749 } 1748 }
1750 1749
1751 if (audiostatus != THREAD_TERMINATED) 1750 if (audiothread_id != NULL && audiostatus != THREAD_TERMINATED)
1752 { 1751 {
1753 audiostatus = PLEASE_STOP; 1752 audiostatus = PLEASE_STOP;
1754 while (audiostatus != THREAD_TERMINATED) 1753 while (audiostatus != THREAD_TERMINATED)
@@ -1757,6 +1756,10 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
1757 1756
1758 rb->sleep(HZ/10); 1757 rb->sleep(HZ/10);
1759 1758
1759#ifndef HAVE_LCD_COLOR
1760 gray_release();
1761#endif
1762
1760 rb->lcd_clear_display(); 1763 rb->lcd_clear_display();
1761 rb->lcd_update(); 1764 rb->lcd_update();
1762 1765