summaryrefslogtreecommitdiff
path: root/apps/plugins/mpegplayer/audio_thread.c
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2009-01-05 10:31:19 +0000
committerMichael Sevakis <jethead71@rockbox.org>2009-01-05 10:31:19 +0000
commit2054627caa7f71c564ce35b4525b6281fcd2cc39 (patch)
tree2b0aa3b9b8888c4746b75d4750d90f79552159ee /apps/plugins/mpegplayer/audio_thread.c
parent45aa9a22f9a3e08505cc2f2999459d249356ed9c (diff)
downloadrockbox-2054627caa7f71c564ce35b4525b6281fcd2cc39.tar.gz
rockbox-2054627caa7f71c564ce35b4525b6281fcd2cc39.zip
Have the codec thread do callbacks instead of messing with the stack which is much simpler and safer. Remove threads array from plugin API since it now serves no purpose. Up minimum API version and sort.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@19684 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/mpegplayer/audio_thread.c')
-rw-r--r--apps/plugins/mpegplayer/audio_thread.c75
1 files changed, 16 insertions, 59 deletions
diff --git a/apps/plugins/mpegplayer/audio_thread.c b/apps/plugins/mpegplayer/audio_thread.c
index 2fb46efd56..f6552218b0 100644
--- a/apps/plugins/mpegplayer/audio_thread.c
+++ b/apps/plugins/mpegplayer/audio_thread.c
@@ -38,14 +38,7 @@ struct audio_thread_data
38 struct dsp_config *dsp; /* The DSP we're using */ 38 struct dsp_config *dsp; /* The DSP we're using */
39}; 39};
40 40
41/* The audio stack is stolen from the core codec thread (but not in uisim) */ 41/* The audio thread is stolen from the core codec thread */
42/* Used for stealing codec thread's stack */
43static uint32_t* audio_stack;
44static size_t audio_stack_size; /* Keep gcc happy and init */
45#define AUDIO_STACKSIZE (9*1024)
46#ifndef SIMULATOR
47static uint32_t codec_stack_copy[AUDIO_STACKSIZE / sizeof(uint32_t)];
48#endif
49static struct event_queue audio_str_queue SHAREDBSS_ATTR; 42static struct event_queue audio_str_queue SHAREDBSS_ATTR;
50static struct queue_sender_list audio_str_queue_send SHAREDBSS_ATTR; 43static struct queue_sender_list audio_str_queue_send SHAREDBSS_ATTR;
51struct stream audio_str IBSS_ATTR; 44struct stream audio_str IBSS_ATTR;
@@ -473,6 +466,11 @@ static void audio_thread_msg(struct audio_thread_data *td)
473static void audio_thread(void) 466static void audio_thread(void)
474{ 467{
475 struct audio_thread_data td; 468 struct audio_thread_data td;
469#ifdef HAVE_PRIORITY_SCHEDULING
470 /* Up the priority since the core DSP over-yields internally */
471 int old_priority = rb->thread_set_priority(THREAD_ID_CURRENT,
472 PRIORITY_PLAYBACK-4);
473#endif
476 474
477 rb->memset(&td, 0, sizeof (td)); 475 rb->memset(&td, 0, sizeof (td));
478 td.status = STREAM_STOPPED; 476 td.status = STREAM_STOPPED;
@@ -512,7 +510,13 @@ static void audio_thread(void)
512 case TSTATE_RENDER_WAIT: goto render_wait; 510 case TSTATE_RENDER_WAIT: goto render_wait;
513 case TSTATE_RENDER_WAIT_END: goto render_wait_end; 511 case TSTATE_RENDER_WAIT_END: goto render_wait_end;
514 /* Anything else is interpreted as an exit */ 512 /* Anything else is interpreted as an exit */
515 default: return; 513 default:
514 {
515#ifdef HAVE_PRIORITY_SCHEDULING
516 rb->thread_set_priority(THREAD_ID_CURRENT, old_priority);
517#endif
518 return;
519 }
516 } 520 }
517 } 521 }
518 522
@@ -677,43 +681,6 @@ static void audio_thread(void)
677/* Initializes the audio thread resources and starts the thread */ 681/* Initializes the audio thread resources and starts the thread */
678bool audio_thread_init(void) 682bool audio_thread_init(void)
679{ 683{
680 int i;
681#ifdef SIMULATOR
682 /* The simulator thread implementation doesn't have stack buffers, and
683 these parameters are ignored. */
684 (void)i; /* Keep gcc happy */
685 audio_stack = NULL;
686 audio_stack_size = 0;
687#else
688 /* Borrow the codec thread's stack (in IRAM on most targets) */
689 audio_stack = NULL;
690 for (i = 0; i < MAXTHREADS; i++)
691 {
692 if (rb->strcmp(rb->threads[i].name, "codec") == 0)
693 {
694 /* Wait to ensure the codec thread has blocked */
695 while (rb->threads[i].state != STATE_BLOCKED)
696 rb->yield();
697
698 /* Now we can steal the stack */
699 audio_stack = rb->threads[i].stack;
700 audio_stack_size = rb->threads[i].stack_size;
701
702 /* Backup the codec thread's stack */
703 rb->memcpy(codec_stack_copy, audio_stack, audio_stack_size);
704 break;
705 }
706 }
707
708 if (audio_stack == NULL)
709 {
710 /* This shouldn't happen, but deal with it anyway by using
711 the copy instead */
712 audio_stack = codec_stack_copy;
713 audio_stack_size = AUDIO_STACKSIZE;
714 }
715#endif
716
717 /* Initialise the encoded audio buffer and its descriptors */ 684 /* Initialise the encoded audio buffer and its descriptors */
718 audio_queue.start = mpeg_malloc(AUDIOBUF_ALLOC_SIZE, 685 audio_queue.start = mpeg_malloc(AUDIOBUF_ALLOC_SIZE,
719 MPEG_ALLOC_AUDIOBUF); 686 MPEG_ALLOC_AUDIOBUF);
@@ -724,17 +691,12 @@ bool audio_thread_init(void)
724 audio_str.hdr.q = &audio_str_queue; 691 audio_str.hdr.q = &audio_str_queue;
725 rb->queue_init(audio_str.hdr.q, false); 692 rb->queue_init(audio_str.hdr.q, false);
726 693
727 /* One-up on the priority since the core DSP over-yields internally */ 694 /* We steal the codec thread for audio */
728 audio_str.thread = rb->create_thread( 695 rb->codec_thread_do_callback(audio_thread, &audio_str.thread);
729 audio_thread, audio_stack, audio_stack_size, 0,
730 "mpgaudio" IF_PRIO(,PRIORITY_PLAYBACK-4) IF_COP(, CPU));
731 696
732 rb->queue_enable_queue_send(audio_str.hdr.q, &audio_str_queue_send, 697 rb->queue_enable_queue_send(audio_str.hdr.q, &audio_str_queue_send,
733 audio_str.thread); 698 audio_str.thread);
734 699
735 if (audio_str.thread == 0)
736 return false;
737
738 /* Wait for thread to initialize */ 700 /* Wait for thread to initialize */
739 str_send_msg(&audio_str, STREAM_NULL, 0); 701 str_send_msg(&audio_str, STREAM_NULL, 0);
740 702
@@ -747,12 +709,7 @@ void audio_thread_exit(void)
747 if (audio_str.thread != 0) 709 if (audio_str.thread != 0)
748 { 710 {
749 str_post_msg(&audio_str, STREAM_QUIT, 0); 711 str_post_msg(&audio_str, STREAM_QUIT, 0);
750 rb->thread_wait(audio_str.thread); 712 rb->codec_thread_do_callback(NULL, NULL);
751 audio_str.thread = 0; 713 audio_str.thread = 0;
752 } 714 }
753
754#ifndef SIMULATOR
755 /* Restore the codec thread's stack */
756 rb->memcpy(audio_stack, codec_stack_copy, audio_stack_size);
757#endif
758} 715}