summaryrefslogtreecommitdiff
path: root/apps/plugins
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2007-09-28 11:12:45 +0000
committerMichael Sevakis <jethead71@rockbox.org>2007-09-28 11:12:45 +0000
commitd7cb90722f2cbda4c10c1552248a54633d30820c (patch)
tree99521bf3557f7ad9f59d7084f84658afa91deb8d /apps/plugins
parenta13a1d5492ce30c51f4b2277819d2a6736705c90 (diff)
downloadrockbox-d7cb90722f2cbda4c10c1552248a54633d30820c.tar.gz
rockbox-d7cb90722f2cbda4c10c1552248a54633d30820c.zip
Get the plugins synced up with the threading changes.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14881 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins')
-rw-r--r--apps/plugins/alpine_cdc.c1
-rw-r--r--apps/plugins/battery_bench.c2
-rw-r--r--apps/plugins/mpegplayer/alloc.c102
-rw-r--r--apps/plugins/mpegplayer/mpegplayer.c59
-rw-r--r--apps/plugins/test_codec.c3
5 files changed, 107 insertions, 60 deletions
diff --git a/apps/plugins/alpine_cdc.c b/apps/plugins/alpine_cdc.c
index f0f2939de1..c4b897fc3a 100644
--- a/apps/plugins/alpine_cdc.c
+++ b/apps/plugins/alpine_cdc.c
@@ -1114,7 +1114,6 @@ void thread(void)
1114 } while (!gTread.exiting); 1114 } while (!gTread.exiting);
1115 1115
1116 gTread.ended = true; /* acknowledge the exit */ 1116 gTread.ended = true; /* acknowledge the exit */
1117 rb->remove_thread(NULL); /* commit suicide */
1118} 1117}
1119 1118
1120/* callback to end the TSR plugin, called before a new one gets loaded */ 1119/* callback to end the TSR plugin, called before a new one gets loaded */
diff --git a/apps/plugins/battery_bench.c b/apps/plugins/battery_bench.c
index 43bfc7255f..a938fea1ba 100644
--- a/apps/plugins/battery_bench.c
+++ b/apps/plugins/battery_bench.c
@@ -332,7 +332,7 @@ void thread(void)
332 "bench exit"); 332 "bench exit");
333#endif 333#endif
334 thread_stopped = true; 334 thread_stopped = true;
335 rb->remove_thread(NULL); /* Suicide. Never returns. */ 335 return;
336 } 336 }
337 337
338 rb->queue_wait_w_tmo(&thread_q, &ev, sleep_time); 338 rb->queue_wait_w_tmo(&thread_q, &ev, sleep_time);
diff --git a/apps/plugins/mpegplayer/alloc.c b/apps/plugins/mpegplayer/alloc.c
index 3bdf7ecb0a..b8f68458c0 100644
--- a/apps/plugins/mpegplayer/alloc.c
+++ b/apps/plugins/mpegplayer/alloc.c
@@ -27,40 +27,71 @@
27 27
28extern struct plugin_api* rb; 28extern struct plugin_api* rb;
29 29
30long mem_ptr; 30/* Main allocator */
31long bufsize; 31static off_t mem_ptr;
32unsigned char* mallocbuf; 32static size_t bufsize;
33 33static unsigned char* mallocbuf;
34void mpeg2_alloc_init(unsigned char* buf, int mallocsize) 34
35/* libmpeg2 allocator */
36static off_t mpeg2_mem_ptr;
37static size_t mpeg2_bufsize;
38static unsigned char *mpeg2_mallocbuf;
39
40static void * mpeg_malloc_internal (unsigned char *mallocbuf,
41 off_t *mem_ptr,
42 size_t bufsize,
43 unsigned size,
44 int reason)
35{ 45{
36 mem_ptr = 0; 46 void *x;
37 bufsize = mallocsize;
38 mallocbuf = buf;
39 rb->memset(buf,0,bufsize);
40 47
41 return; 48 if (*mem_ptr + size > bufsize)
49 {
50 DEBUGF("OUT OF MEMORY\n");
51 return NULL;
52 }
53
54 x = &mallocbuf[*mem_ptr];
55 *mem_ptr += (size + 3) & ~3; /* Keep memory 32-bit aligned */
56
57 return x;
58 (void)reason;
42} 59}
43 60
44void * mpeg2_malloc (unsigned size, mpeg2_alloc_t reason) 61void *mpeg_malloc(size_t size, mpeg2_alloc_t reason)
45{ 62{
46 void* x; 63 return mpeg_malloc_internal(mallocbuf, &mem_ptr, bufsize, size,
64 reason);
65}
47 66
48 (void)reason; 67size_t mpeg_alloc_init(unsigned char *buf, size_t mallocsize,
68 size_t libmpeg2size)
69{
70 mem_ptr = 0;
71 bufsize = mallocsize;
72 /* Line-align buffer */
73 mallocbuf = (char *)(((intptr_t)buf + 15) & ~15);
74 /* Adjust for real size */
75 bufsize -= mallocbuf - buf;
76 rb->memset(buf,0,bufsize);
49 77
50 DEBUGF("mpeg2_malloc(%d,%d)\n",size,reason); 78 /* Separate allocator for video */
51 if (mem_ptr + (long)size > bufsize) { 79 libmpeg2size = (libmpeg2size + 15) & ~15;
52 DEBUGF("OUT OF MEMORY\n"); 80 if (mpeg_malloc_internal(mallocbuf, &mem_ptr,
53 return NULL; 81 bufsize, libmpeg2size, 0) == NULL)
82 {
83 return 0;
54 } 84 }
55
56 x=&mallocbuf[mem_ptr];
57 mem_ptr+=(size+3)&~3; /* Keep memory 32-bit aligned */
58 85
59 return(x); 86 mpeg2_mallocbuf = mallocbuf;
60} 87 mpeg2_mem_ptr = 0;
88 mpeg2_bufsize = libmpeg2size;
61 89
62void mpeg2_free(void* ptr) { 90#if NUM_CORES > 1
63 (void)ptr; 91 flush_icache();
92#endif
93
94 return bufsize - mpeg2_bufsize;
64} 95}
65 96
66/* gcc may want to use memcpy before rb is initialised, so here's a trivial 97/* gcc may want to use memcpy before rb is initialised, so here's a trivial
@@ -77,18 +108,30 @@ void *memcpy(void *dest, const void *src, size_t n) {
77 return dest; 108 return dest;
78} 109}
79 110
111void * mpeg2_malloc(unsigned size, mpeg2_alloc_t reason)
112{
113 return mpeg_malloc_internal(mpeg2_mallocbuf, &mpeg2_mem_ptr,
114 mpeg2_bufsize, size, reason);
115}
116
117void mpeg2_free(void *ptr)
118{
119 (void)ptr;
120}
80 121
81/* The following are expected by libmad */ 122/* The following are expected by libmad */
82void* codec_malloc(size_t size) 123void * codec_malloc(size_t size)
83{ 124{
84 return mpeg2_malloc(size,-3); 125 return mpeg_malloc_internal(mallocbuf, &mem_ptr,
126 bufsize, size, -3);
85} 127}
86 128
87void* codec_calloc(size_t nmemb, size_t size) 129void * codec_calloc(size_t nmemb, size_t size)
88{ 130{
89 void* ptr; 131 void* ptr;
90 132
91 ptr = mpeg2_malloc(nmemb*size,-3); 133 ptr = mpeg_malloc_internal(mallocbuf, &mem_ptr,
134 bufsize, nmemb*size, -3);
92 135
93 if (ptr) 136 if (ptr)
94 rb->memset(ptr,0,size); 137 rb->memset(ptr,0,size);
@@ -96,7 +139,8 @@ void* codec_calloc(size_t nmemb, size_t size)
96 return ptr; 139 return ptr;
97} 140}
98 141
99void codec_free(void* ptr) { 142void codec_free(void* ptr)
143{
100 (void)ptr; 144 (void)ptr;
101} 145}
102 146
diff --git a/apps/plugins/mpegplayer/mpegplayer.c b/apps/plugins/mpegplayer/mpegplayer.c
index af0567c0d1..1ee472bde4 100644
--- a/apps/plugins/mpegplayer/mpegplayer.c
+++ b/apps/plugins/mpegplayer/mpegplayer.c
@@ -173,10 +173,16 @@ PLUGIN_IRAM_DECLARE
173 173
174struct plugin_api* rb; 174struct plugin_api* rb;
175 175
176static mpeg2dec_t * mpeg2dec; 176CACHE_FUNCTION_WRAPPERS(rb);
177static int total_offset = 0; 177
178static int num_drawn = 0; 178extern void *mpeg_malloc(size_t size, mpeg2_alloc_t reason);
179static int count_start = 0; 179extern size_t mpeg_alloc_init(unsigned char *buf, size_t mallocsize,
180 size_t libmpeg2size);
181
182static mpeg2dec_t * mpeg2dec NOCACHEBSS_ATTR;
183static int total_offset NOCACHEBSS_ATTR = 0;
184static int num_drawn NOCACHEBSS_ATTR = 0;
185static int count_start NOCACHEBSS_ATTR = 0;
180 186
181/* Streams */ 187/* Streams */
182typedef struct 188typedef struct
@@ -348,9 +354,6 @@ static inline void unlock_stream(void)
348 { } 354 { }
349#endif 355#endif
350 356
351/* Events */
352static struct event_queue msg_queue IBSS_ATTR;
353
354#define MSG_BUFFER_NEARLY_EMPTY 1 357#define MSG_BUFFER_NEARLY_EMPTY 1
355#define MSG_EXIT_REQUESTED 2 358#define MSG_EXIT_REQUESTED 2
356 359
@@ -383,7 +386,7 @@ unsigned char mad_main_data[MAD_BUFFER_MDLEN]; /* 2567 bytes */
383#ifdef CPU_COLDFIRE 386#ifdef CPU_COLDFIRE
384static mad_fixed_t mad_frame_overlap[2][32][18] IBSS_ATTR; /* 4608 bytes */ 387static mad_fixed_t mad_frame_overlap[2][32][18] IBSS_ATTR; /* 4608 bytes */
385#else 388#else
386static mad_fixed_t mad_frame_overlap[2][32][18]; /* 4608 bytes */ 389static mad_fixed_t mad_frame_overlap[2][32][18] __attribute__((aligned(16))); /* 4608 bytes */
387#endif 390#endif
388 391
389static void init_mad(void* mad_frame_overlap) 392static void init_mad(void* mad_frame_overlap)
@@ -717,11 +720,11 @@ static void get_next_data( Stream* str )
717#define TIME_TO_TICKS(stamp) ((uint64_t)CLOCK_RATE*(stamp) / 27000000) 720#define TIME_TO_TICKS(stamp) ((uint64_t)CLOCK_RATE*(stamp) / 27000000)
718 721
719/** MPEG audio stream buffer */ 722/** MPEG audio stream buffer */
720uint8_t* mpa_buffer; 723uint8_t* mpa_buffer NOCACHEBSS_ATTR;
721 724
722static bool init_mpabuf(void) 725static bool init_mpabuf(void)
723{ 726{
724 mpa_buffer = mpeg2_malloc(MPABUF_SIZE,-2); 727 mpa_buffer = mpeg_malloc(MPABUF_SIZE,-2);
725 return mpa_buffer != NULL; 728 return mpa_buffer != NULL;
726} 729}
727 730
@@ -732,13 +735,13 @@ struct pts_queue_slot
732{ 735{
733 uint32_t pts; /* Time stamp for packet */ 736 uint32_t pts; /* Time stamp for packet */
734 ssize_t size; /* Number of bytes left in packet */ 737 ssize_t size; /* Number of bytes left in packet */
735} pts_queue[PTS_QUEUE_LEN]; 738} pts_queue[PTS_QUEUE_LEN] __attribute__((aligned(16)));
736 739
737 /* This starts out wr == rd but will never be emptied to zero during 740 /* This starts out wr == rd but will never be emptied to zero during
738 streaming again in order to support initializing the first packet's 741 streaming again in order to support initializing the first packet's
739 pts value without a special case */ 742 pts value without a special case */
740static unsigned pts_queue_rd; 743static unsigned pts_queue_rd NOCACHEBSS_ATTR;
741static unsigned pts_queue_wr; 744static unsigned pts_queue_wr NOCACHEBSS_ATTR;
742 745
743/* Increments the queue head postion - should be used to preincrement */ 746/* Increments the queue head postion - should be used to preincrement */
744static bool pts_queue_add_head(void) 747static bool pts_queue_add_head(void)
@@ -811,7 +814,7 @@ static ssize_t pcmbuf_used(void)
811 814
812static bool init_pcmbuf(void) 815static bool init_pcmbuf(void)
813{ 816{
814 pcm_buffer = mpeg2_malloc(PCMBUFFER_SIZE + PCMBUFFER_GUARD_SIZE, -2); 817 pcm_buffer = mpeg_malloc(PCMBUFFER_SIZE + PCMBUFFER_GUARD_SIZE, -2);
815 818
816 if (pcm_buffer == NULL) 819 if (pcm_buffer == NULL)
817 return false; 820 return false;
@@ -1365,7 +1368,6 @@ audio_thread_quit:
1365 pcm_playback_stop(); 1368 pcm_playback_stop();
1366 1369
1367 audio_str.status = STREAM_TERMINATED; 1370 audio_str.status = STREAM_TERMINATED;
1368 rb->remove_thread(NULL);
1369} 1371}
1370 1372
1371/* End of libmad stuff */ 1373/* End of libmad stuff */
@@ -1405,7 +1407,7 @@ static void video_thread(void)
1405 rb->splash(0, "mpeg2_init failed"); 1407 rb->splash(0, "mpeg2_init failed");
1406 /* Commit suicide */ 1408 /* Commit suicide */
1407 video_str.status = STREAM_TERMINATED; 1409 video_str.status = STREAM_TERMINATED;
1408 rb->remove_thread(NULL); 1410 return;
1409 } 1411 }
1410 1412
1411 /* Clear the display - this is mainly just to indicate that the 1413 /* Clear the display - this is mainly just to indicate that the
@@ -1444,7 +1446,9 @@ static void video_thread(void)
1444 video_str.status = STREAM_STOPPED; 1446 video_str.status = STREAM_STOPPED;
1445 goto video_thread_quit; 1447 goto video_thread_quit;
1446 case STREAM_PAUSE: 1448 case STREAM_PAUSE:
1449 #if NUM_CORES > 1
1447 flush_icache(); 1450 flush_icache();
1451 #endif
1448 video_str.status = STREAM_PAUSED; 1452 video_str.status = STREAM_PAUSED;
1449 str_reply_msg(&video_str, 1); 1453 str_reply_msg(&video_str, 1);
1450 continue; 1454 continue;
@@ -1742,7 +1746,9 @@ static void video_thread(void)
1742 } 1746 }
1743 1747
1744done: 1748done:
1749#if NUM_CORES > 1
1745 flush_icache(); 1750 flush_icache();
1751#endif
1746 1752
1747 video_str.status = STREAM_DONE; 1753 video_str.status = STREAM_DONE;
1748 1754
@@ -1757,11 +1763,8 @@ done:
1757 } 1763 }
1758 1764
1759video_thread_quit: 1765video_thread_quit:
1760 flush_icache();
1761
1762 /* Commit suicide */ 1766 /* Commit suicide */
1763 video_str.status = STREAM_TERMINATED; 1767 video_str.status = STREAM_TERMINATED;
1764 rb->remove_thread(NULL);
1765} 1768}
1766 1769
1767enum plugin_status plugin_start(struct plugin_api* api, void* parameter) 1770enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
@@ -1811,15 +1814,17 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
1811 audio_str.id = 0xc0; 1814 audio_str.id = 0xc0;
1812 1815
1813 /* Initialise our malloc buffer */ 1816 /* Initialise our malloc buffer */
1814 mpeg2_alloc_init(audiobuf,audiosize); 1817 audiosize = mpeg_alloc_init(audiobuf, audiosize, LIBMPEG2BUFFER_SIZE);
1818 if (audiosize == 0)
1819 return PLUGIN_ERROR;
1815 1820
1816 /* Grab most of the buffer for the compressed video - leave some for 1821 /* Grab most of the buffer for the compressed video - leave some for
1817 PCM audio data and some for libmpeg2 malloc use. */ 1822 PCM audio data and some for libmpeg2 malloc use. */
1818 buffer_size = audiosize - (PCMBUFFER_SIZE+PCMBUFFER_GUARD_SIZE+ 1823 buffer_size = audiosize - (PCMBUFFER_SIZE+PCMBUFFER_GUARD_SIZE+
1819 MPABUF_SIZE+LIBMPEG2BUFFER_SIZE); 1824 MPABUF_SIZE);
1820 1825
1821 DEBUGF("audiosize=%ld, buffer_size=%ld\n",audiosize,buffer_size); 1826 DEBUGF("audiosize=%ld, buffer_size=%ld\n",audiosize,buffer_size);
1822 buffer = mpeg2_malloc(buffer_size,-1); 1827 buffer = mpeg_malloc(buffer_size,-1);
1823 1828
1824 if (buffer == NULL) 1829 if (buffer == NULL)
1825 return PLUGIN_ERROR; 1830 return PLUGIN_ERROR;
@@ -1877,10 +1882,6 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
1877 1882
1878 init_settings(); 1883 init_settings();
1879 1884
1880 /* Msg queue init - no need for queue_remove since it's not a registered
1881 queue */
1882 rb->queue_init( &msg_queue, false );
1883
1884 /* Initialise libmad */ 1885 /* Initialise libmad */
1885 rb->memset(mad_frame_overlap, 0, sizeof(mad_frame_overlap)); 1886 rb->memset(mad_frame_overlap, 0, sizeof(mad_frame_overlap));
1886 init_mad(mad_frame_overlap); 1887 init_mad(mad_frame_overlap);
@@ -1913,7 +1914,9 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
1913 1914
1914 init_stream_lock(); 1915 init_stream_lock();
1915 1916
1917#if NUM_CORES > 1
1916 flush_icache(); 1918 flush_icache();
1919#endif
1917 1920
1918 /* We put the video thread on the second processor for multi-core targets. */ 1921 /* We put the video thread on the second processor for multi-core targets. */
1919 if ((video_str.thread = rb->create_thread(video_thread, 1922 if ((video_str.thread = rb->create_thread(video_thread,
@@ -1983,6 +1986,10 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
1983 1986
1984 rb->sleep(HZ/10); 1987 rb->sleep(HZ/10);
1985 1988
1989#if NUM_CORES > 1
1990 invalidate_icache();
1991#endif
1992
1986#ifndef HAVE_LCD_COLOR 1993#ifndef HAVE_LCD_COLOR
1987 gray_release(); 1994 gray_release();
1988#endif 1995#endif
diff --git a/apps/plugins/test_codec.c b/apps/plugins/test_codec.c
index 94be6b7397..4e671094c8 100644
--- a/apps/plugins/test_codec.c
+++ b/apps/plugins/test_codec.c
@@ -493,9 +493,6 @@ static void codec_thread(void)
493 493
494 /* Signal to the main thread that we are done */ 494 /* Signal to the main thread that we are done */
495 codec_playing = false; 495 codec_playing = false;
496
497 /* Commit suicide */
498 rb->remove_thread(NULL);
499} 496}
500 497
501static unsigned char* codec_stack; 498static unsigned char* codec_stack;