mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-10-13 18:17:39 -04:00
Get the plugins synced up with the threading changes.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14881 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
a13a1d5492
commit
d7cb90722f
5 changed files with 109 additions and 62 deletions
|
@ -1114,7 +1114,6 @@ void thread(void)
|
|||
} while (!gTread.exiting);
|
||||
|
||||
gTread.ended = true; /* acknowledge the exit */
|
||||
rb->remove_thread(NULL); /* commit suicide */
|
||||
}
|
||||
|
||||
/* callback to end the TSR plugin, called before a new one gets loaded */
|
||||
|
|
|
@ -332,7 +332,7 @@ void thread(void)
|
|||
"bench exit");
|
||||
#endif
|
||||
thread_stopped = true;
|
||||
rb->remove_thread(NULL); /* Suicide. Never returns. */
|
||||
return;
|
||||
}
|
||||
|
||||
rb->queue_wait_w_tmo(&thread_q, &ev, sleep_time);
|
||||
|
|
|
@ -27,40 +27,71 @@
|
|||
|
||||
extern struct plugin_api* rb;
|
||||
|
||||
long mem_ptr;
|
||||
long bufsize;
|
||||
unsigned char* mallocbuf;
|
||||
/* Main allocator */
|
||||
static off_t mem_ptr;
|
||||
static size_t bufsize;
|
||||
static unsigned char* mallocbuf;
|
||||
|
||||
void mpeg2_alloc_init(unsigned char* buf, int mallocsize)
|
||||
/* libmpeg2 allocator */
|
||||
static off_t mpeg2_mem_ptr;
|
||||
static size_t mpeg2_bufsize;
|
||||
static unsigned char *mpeg2_mallocbuf;
|
||||
|
||||
static void * mpeg_malloc_internal (unsigned char *mallocbuf,
|
||||
off_t *mem_ptr,
|
||||
size_t bufsize,
|
||||
unsigned size,
|
||||
int reason)
|
||||
{
|
||||
mem_ptr = 0;
|
||||
bufsize = mallocsize;
|
||||
mallocbuf = buf;
|
||||
rb->memset(buf,0,bufsize);
|
||||
void *x;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void * mpeg2_malloc (unsigned size, mpeg2_alloc_t reason)
|
||||
{
|
||||
void* x;
|
||||
|
||||
(void)reason;
|
||||
|
||||
DEBUGF("mpeg2_malloc(%d,%d)\n",size,reason);
|
||||
if (mem_ptr + (long)size > bufsize) {
|
||||
if (*mem_ptr + size > bufsize)
|
||||
{
|
||||
DEBUGF("OUT OF MEMORY\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
x=&mallocbuf[mem_ptr];
|
||||
mem_ptr+=(size+3)&~3; /* Keep memory 32-bit aligned */
|
||||
x = &mallocbuf[*mem_ptr];
|
||||
*mem_ptr += (size + 3) & ~3; /* Keep memory 32-bit aligned */
|
||||
|
||||
return(x);
|
||||
return x;
|
||||
(void)reason;
|
||||
}
|
||||
|
||||
void mpeg2_free(void* ptr) {
|
||||
(void)ptr;
|
||||
void *mpeg_malloc(size_t size, mpeg2_alloc_t reason)
|
||||
{
|
||||
return mpeg_malloc_internal(mallocbuf, &mem_ptr, bufsize, size,
|
||||
reason);
|
||||
}
|
||||
|
||||
size_t mpeg_alloc_init(unsigned char *buf, size_t mallocsize,
|
||||
size_t libmpeg2size)
|
||||
{
|
||||
mem_ptr = 0;
|
||||
bufsize = mallocsize;
|
||||
/* Line-align buffer */
|
||||
mallocbuf = (char *)(((intptr_t)buf + 15) & ~15);
|
||||
/* Adjust for real size */
|
||||
bufsize -= mallocbuf - buf;
|
||||
rb->memset(buf,0,bufsize);
|
||||
|
||||
/* Separate allocator for video */
|
||||
libmpeg2size = (libmpeg2size + 15) & ~15;
|
||||
if (mpeg_malloc_internal(mallocbuf, &mem_ptr,
|
||||
bufsize, libmpeg2size, 0) == NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
mpeg2_mallocbuf = mallocbuf;
|
||||
mpeg2_mem_ptr = 0;
|
||||
mpeg2_bufsize = libmpeg2size;
|
||||
|
||||
#if NUM_CORES > 1
|
||||
flush_icache();
|
||||
#endif
|
||||
|
||||
return bufsize - mpeg2_bufsize;
|
||||
}
|
||||
|
||||
/* 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) {
|
|||
return dest;
|
||||
}
|
||||
|
||||
|
||||
/* The following are expected by libmad */
|
||||
void* codec_malloc(size_t size)
|
||||
void * mpeg2_malloc(unsigned size, mpeg2_alloc_t reason)
|
||||
{
|
||||
return mpeg2_malloc(size,-3);
|
||||
return mpeg_malloc_internal(mpeg2_mallocbuf, &mpeg2_mem_ptr,
|
||||
mpeg2_bufsize, size, reason);
|
||||
}
|
||||
|
||||
void* codec_calloc(size_t nmemb, size_t size)
|
||||
void mpeg2_free(void *ptr)
|
||||
{
|
||||
(void)ptr;
|
||||
}
|
||||
|
||||
/* The following are expected by libmad */
|
||||
void * codec_malloc(size_t size)
|
||||
{
|
||||
return mpeg_malloc_internal(mallocbuf, &mem_ptr,
|
||||
bufsize, size, -3);
|
||||
}
|
||||
|
||||
void * codec_calloc(size_t nmemb, size_t size)
|
||||
{
|
||||
void* ptr;
|
||||
|
||||
ptr = mpeg2_malloc(nmemb*size,-3);
|
||||
ptr = mpeg_malloc_internal(mallocbuf, &mem_ptr,
|
||||
bufsize, nmemb*size, -3);
|
||||
|
||||
if (ptr)
|
||||
rb->memset(ptr,0,size);
|
||||
|
@ -96,7 +139,8 @@ void* codec_calloc(size_t nmemb, size_t size)
|
|||
return ptr;
|
||||
}
|
||||
|
||||
void codec_free(void* ptr) {
|
||||
void codec_free(void* ptr)
|
||||
{
|
||||
(void)ptr;
|
||||
}
|
||||
|
||||
|
|
|
@ -173,10 +173,16 @@ PLUGIN_IRAM_DECLARE
|
|||
|
||||
struct plugin_api* rb;
|
||||
|
||||
static mpeg2dec_t * mpeg2dec;
|
||||
static int total_offset = 0;
|
||||
static int num_drawn = 0;
|
||||
static int count_start = 0;
|
||||
CACHE_FUNCTION_WRAPPERS(rb);
|
||||
|
||||
extern void *mpeg_malloc(size_t size, mpeg2_alloc_t reason);
|
||||
extern size_t mpeg_alloc_init(unsigned char *buf, size_t mallocsize,
|
||||
size_t libmpeg2size);
|
||||
|
||||
static mpeg2dec_t * mpeg2dec NOCACHEBSS_ATTR;
|
||||
static int total_offset NOCACHEBSS_ATTR = 0;
|
||||
static int num_drawn NOCACHEBSS_ATTR = 0;
|
||||
static int count_start NOCACHEBSS_ATTR = 0;
|
||||
|
||||
/* Streams */
|
||||
typedef struct
|
||||
|
@ -348,9 +354,6 @@ static inline void unlock_stream(void)
|
|||
{ }
|
||||
#endif
|
||||
|
||||
/* Events */
|
||||
static struct event_queue msg_queue IBSS_ATTR;
|
||||
|
||||
#define MSG_BUFFER_NEARLY_EMPTY 1
|
||||
#define MSG_EXIT_REQUESTED 2
|
||||
|
||||
|
@ -383,7 +386,7 @@ unsigned char mad_main_data[MAD_BUFFER_MDLEN]; /* 2567 bytes */
|
|||
#ifdef CPU_COLDFIRE
|
||||
static mad_fixed_t mad_frame_overlap[2][32][18] IBSS_ATTR; /* 4608 bytes */
|
||||
#else
|
||||
static mad_fixed_t mad_frame_overlap[2][32][18]; /* 4608 bytes */
|
||||
static mad_fixed_t mad_frame_overlap[2][32][18] __attribute__((aligned(16))); /* 4608 bytes */
|
||||
#endif
|
||||
|
||||
static void init_mad(void* mad_frame_overlap)
|
||||
|
@ -717,11 +720,11 @@ static void get_next_data( Stream* str )
|
|||
#define TIME_TO_TICKS(stamp) ((uint64_t)CLOCK_RATE*(stamp) / 27000000)
|
||||
|
||||
/** MPEG audio stream buffer */
|
||||
uint8_t* mpa_buffer;
|
||||
uint8_t* mpa_buffer NOCACHEBSS_ATTR;
|
||||
|
||||
static bool init_mpabuf(void)
|
||||
{
|
||||
mpa_buffer = mpeg2_malloc(MPABUF_SIZE,-2);
|
||||
mpa_buffer = mpeg_malloc(MPABUF_SIZE,-2);
|
||||
return mpa_buffer != NULL;
|
||||
}
|
||||
|
||||
|
@ -732,13 +735,13 @@ struct pts_queue_slot
|
|||
{
|
||||
uint32_t pts; /* Time stamp for packet */
|
||||
ssize_t size; /* Number of bytes left in packet */
|
||||
} pts_queue[PTS_QUEUE_LEN];
|
||||
} pts_queue[PTS_QUEUE_LEN] __attribute__((aligned(16)));
|
||||
|
||||
/* This starts out wr == rd but will never be emptied to zero during
|
||||
streaming again in order to support initializing the first packet's
|
||||
pts value without a special case */
|
||||
static unsigned pts_queue_rd;
|
||||
static unsigned pts_queue_wr;
|
||||
static unsigned pts_queue_rd NOCACHEBSS_ATTR;
|
||||
static unsigned pts_queue_wr NOCACHEBSS_ATTR;
|
||||
|
||||
/* Increments the queue head postion - should be used to preincrement */
|
||||
static bool pts_queue_add_head(void)
|
||||
|
@ -811,7 +814,7 @@ static ssize_t pcmbuf_used(void)
|
|||
|
||||
static bool init_pcmbuf(void)
|
||||
{
|
||||
pcm_buffer = mpeg2_malloc(PCMBUFFER_SIZE + PCMBUFFER_GUARD_SIZE, -2);
|
||||
pcm_buffer = mpeg_malloc(PCMBUFFER_SIZE + PCMBUFFER_GUARD_SIZE, -2);
|
||||
|
||||
if (pcm_buffer == NULL)
|
||||
return false;
|
||||
|
@ -1365,7 +1368,6 @@ audio_thread_quit:
|
|||
pcm_playback_stop();
|
||||
|
||||
audio_str.status = STREAM_TERMINATED;
|
||||
rb->remove_thread(NULL);
|
||||
}
|
||||
|
||||
/* End of libmad stuff */
|
||||
|
@ -1405,7 +1407,7 @@ static void video_thread(void)
|
|||
rb->splash(0, "mpeg2_init failed");
|
||||
/* Commit suicide */
|
||||
video_str.status = STREAM_TERMINATED;
|
||||
rb->remove_thread(NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Clear the display - this is mainly just to indicate that the
|
||||
|
@ -1444,7 +1446,9 @@ static void video_thread(void)
|
|||
video_str.status = STREAM_STOPPED;
|
||||
goto video_thread_quit;
|
||||
case STREAM_PAUSE:
|
||||
#if NUM_CORES > 1
|
||||
flush_icache();
|
||||
#endif
|
||||
video_str.status = STREAM_PAUSED;
|
||||
str_reply_msg(&video_str, 1);
|
||||
continue;
|
||||
|
@ -1742,7 +1746,9 @@ static void video_thread(void)
|
|||
}
|
||||
|
||||
done:
|
||||
#if NUM_CORES > 1
|
||||
flush_icache();
|
||||
#endif
|
||||
|
||||
video_str.status = STREAM_DONE;
|
||||
|
||||
|
@ -1757,11 +1763,8 @@ done:
|
|||
}
|
||||
|
||||
video_thread_quit:
|
||||
flush_icache();
|
||||
|
||||
/* Commit suicide */
|
||||
video_str.status = STREAM_TERMINATED;
|
||||
rb->remove_thread(NULL);
|
||||
}
|
||||
|
||||
enum 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)
|
|||
audio_str.id = 0xc0;
|
||||
|
||||
/* Initialise our malloc buffer */
|
||||
mpeg2_alloc_init(audiobuf,audiosize);
|
||||
audiosize = mpeg_alloc_init(audiobuf, audiosize, LIBMPEG2BUFFER_SIZE);
|
||||
if (audiosize == 0)
|
||||
return PLUGIN_ERROR;
|
||||
|
||||
/* Grab most of the buffer for the compressed video - leave some for
|
||||
PCM audio data and some for libmpeg2 malloc use. */
|
||||
buffer_size = audiosize - (PCMBUFFER_SIZE+PCMBUFFER_GUARD_SIZE+
|
||||
MPABUF_SIZE+LIBMPEG2BUFFER_SIZE);
|
||||
MPABUF_SIZE);
|
||||
|
||||
DEBUGF("audiosize=%ld, buffer_size=%ld\n",audiosize,buffer_size);
|
||||
buffer = mpeg2_malloc(buffer_size,-1);
|
||||
buffer = mpeg_malloc(buffer_size,-1);
|
||||
|
||||
if (buffer == NULL)
|
||||
return PLUGIN_ERROR;
|
||||
|
@ -1877,10 +1882,6 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
|
|||
|
||||
init_settings();
|
||||
|
||||
/* Msg queue init - no need for queue_remove since it's not a registered
|
||||
queue */
|
||||
rb->queue_init( &msg_queue, false );
|
||||
|
||||
/* Initialise libmad */
|
||||
rb->memset(mad_frame_overlap, 0, sizeof(mad_frame_overlap));
|
||||
init_mad(mad_frame_overlap);
|
||||
|
@ -1913,7 +1914,9 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
|
|||
|
||||
init_stream_lock();
|
||||
|
||||
#if NUM_CORES > 1
|
||||
flush_icache();
|
||||
#endif
|
||||
|
||||
/* We put the video thread on the second processor for multi-core targets. */
|
||||
if ((video_str.thread = rb->create_thread(video_thread,
|
||||
|
@ -1983,6 +1986,10 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
|
|||
|
||||
rb->sleep(HZ/10);
|
||||
|
||||
#if NUM_CORES > 1
|
||||
invalidate_icache();
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_LCD_COLOR
|
||||
gray_release();
|
||||
#endif
|
||||
|
|
|
@ -493,9 +493,6 @@ static void codec_thread(void)
|
|||
|
||||
/* Signal to the main thread that we are done */
|
||||
codec_playing = false;
|
||||
|
||||
/* Commit suicide */
|
||||
rb->remove_thread(NULL);
|
||||
}
|
||||
|
||||
static unsigned char* codec_stack;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue