summaryrefslogtreecommitdiffstats
path: root/firmware/target/hosted
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2012-02-23 08:14:46 -0500
committerMichael Sevakis <jethead71@rockbox.org>2012-03-03 07:23:38 +0100
commit286a4c5caa1945c8d1cb365a3d90fb09d5700cb2 (patch)
tree4835f46d16ec78d035ec9f49333079fe618384c1 /firmware/target/hosted
parent3f82f3aca14eb954e55f761721ffdd2684f0e812 (diff)
downloadrockbox-286a4c5caa1945c8d1cb365a3d90fb09d5700cb2.tar.gz
rockbox-286a4c5caa1945c8d1cb365a3d90fb09d5700cb2.zip
Revise the PCM callback system after adding multichannel audio.
Additional status callback is added to pcm_play/rec_data instead of using a special function to set it. Status includes DMA error reporting to the status callback. Playback and recording callback become more alike except playback uses "const void **addr" (because the data should not be altered) and recording uses "void **addr". "const" is put in place throughout where appropriate. Most changes are fairly trivial. One that should be checked in particular because it isn't so much is telechips, if anyone cares to bother. PP5002 is not so trivial either but that tested as working. Change-Id: I4928d69b3b3be7fb93e259f81635232df9bd1df2 Reviewed-on: http://gerrit.rockbox.org/166 Reviewed-by: Michael Sevakis <jethead71@rockbox.org> Tested-by: Michael Sevakis <jethead71@rockbox.org>
Diffstat (limited to 'firmware/target/hosted')
-rw-r--r--firmware/target/hosted/android/pcm-android.c16
-rw-r--r--firmware/target/hosted/maemo/pcm-gstreamer.c7
-rw-r--r--firmware/target/hosted/pcm-alsa.c8
-rw-r--r--firmware/target/hosted/sdl/pcm-sdl.c66
4 files changed, 49 insertions, 48 deletions
diff --git a/firmware/target/hosted/android/pcm-android.c b/firmware/target/hosted/android/pcm-android.c
index 4e58707d0a..7a0f28634e 100644
--- a/firmware/target/hosted/android/pcm-android.c
+++ b/firmware/target/hosted/android/pcm-android.c
@@ -80,8 +80,8 @@ Java_org_rockbox_RockboxPCM_nativeWrite(JNIEnv *env, jobject this,
if (!pcm_data_size) /* get some initial data */
{
- new_buffer = true;
- pcm_play_get_more_callback((void**) &pcm_data_start, &pcm_data_size);
+ new_buffer = pcm_play_dma_complete_callback(PCM_DMAST_OK,
+ (const void**)&pcm_data_start, &pcm_data_size);
}
while(left > 0 && pcm_data_size)
@@ -99,7 +99,7 @@ Java_org_rockbox_RockboxPCM_nativeWrite(JNIEnv *env, jobject this,
if (new_buffer)
{
new_buffer = false;
- pcm_play_dma_started_callback();
+ pcm_play_dma_status_callback(PCM_DMAST_STARTED);
/* NOTE: might need to release the mutex and sleep here if the
buffer is shorter than the required buffer (like pcm-sdl.c) to
@@ -114,15 +114,15 @@ Java_org_rockbox_RockboxPCM_nativeWrite(JNIEnv *env, jobject this,
if (pcm_data_size == 0) /* need new data */
{
- new_buffer = true;
- pcm_play_get_more_callback((void**)&pcm_data_start, &pcm_data_size);
+ new_buffer = pcm_play_dma_complete_callback(PCM_DMAST_OK,
+ (const void**)&pcm_data_start, &pcm_data_size);
}
else /* increment data pointer and feed more */
pcm_data_start += transfer_size;
}
- if (new_buffer && pcm_data_size)
- pcm_play_dma_started_callback();
+ if (new_buffer)
+ pcm_play_dma_status_callback(PCM_DMAST_STARTED);
unlock_audio();
return max_size - left;
@@ -154,7 +154,7 @@ void pcm_play_dma_start(const void *addr, size_t size)
void pcm_play_dma_stop(void)
{
- /* NOTE: due to how pcm_play_get_more_callback() works, this is
+ /* NOTE: due to how pcm_play_dma_complete_callback() works, this is
* possibly called from nativeWrite(), i.e. another (host) thread
* => need to discover the appropriate JNIEnv* */
JNIEnv* env = getJavaEnvironment();
diff --git a/firmware/target/hosted/maemo/pcm-gstreamer.c b/firmware/target/hosted/maemo/pcm-gstreamer.c
index e5620d0702..61f33cbadd 100644
--- a/firmware/target/hosted/maemo/pcm-gstreamer.c
+++ b/firmware/target/hosted/maemo/pcm-gstreamer.c
@@ -189,9 +189,8 @@ static void feed_data(GstElement * appsrc, guint size_hint, void *unused)
from inside gstreamer's stream thread as it will deadlock */
inside_feed_data = 1;
- pcm_play_get_more_callback((void **)&pcm_data, &pcm_data_size);
-
- if (pcm_data_size != 0)
+ if (pcm_play_dma_complete_callback(PCM_DMAST_OK, (const void **)&pcm_data,
+ &pcm_data_size))
{
GstBuffer *buffer = gst_buffer_new ();
GstFlowReturn ret;
@@ -205,7 +204,7 @@ static void feed_data(GstElement * appsrc, guint size_hint, void *unused)
if (ret != 0)
DEBUGF("push-buffer error result: %d\n", ret);
- pcm_play_dma_started_callback();
+ pcm_play_dma_status_callback(PCM_DMAST_STARTED);
} else
{
DEBUGF("feed_data: No Data.\n");
diff --git a/firmware/target/hosted/pcm-alsa.c b/firmware/target/hosted/pcm-alsa.c
index b78993dd0a..1385f75b34 100644
--- a/firmware/target/hosted/pcm-alsa.c
+++ b/firmware/target/hosted/pcm-alsa.c
@@ -223,9 +223,11 @@ static bool fill_frames(void)
if (!pcm_size)
{
new_buffer = true;
- pcm_play_get_more_callback((void **)&pcm_data, &pcm_size);
- if (!pcm_size || !pcm_data)
+ if (!pcm_play_dma_complete_callback(PCM_DMAST_OK,
+ (const void **)&pcm_data, &pcm_size))
+ {
return false;
+ }
}
copy_n = MIN((ssize_t)pcm_size, frames_left*4);
memcpy(&frames[2*(period_size-frames_left)], pcm_data, copy_n);
@@ -237,7 +239,7 @@ static bool fill_frames(void)
if (new_buffer)
{
new_buffer = false;
- pcm_play_dma_started_callback();
+ pcm_play_dma_status_callback(PCM_DMAST_STARTED);
}
}
return true;
diff --git a/firmware/target/hosted/sdl/pcm-sdl.c b/firmware/target/hosted/sdl/pcm-sdl.c
index 020928d572..2c535b2dc5 100644
--- a/firmware/target/hosted/sdl/pcm-sdl.c
+++ b/firmware/target/hosted/sdl/pcm-sdl.c
@@ -56,7 +56,7 @@ static int sim_volume = 0;
#if CONFIG_CODEC == SWCODEC
static int cvt_status = -1;
-static Uint8* pcm_data;
+static const Uint8* pcm_data;
static size_t pcm_data_size;
static size_t pcm_sample_bytes;
static size_t pcm_channel_bytes;
@@ -109,7 +109,7 @@ void pcm_play_dma_start(const void *addr, size_t size)
{
pcm_dma_apply_settings_nolock();
- pcm_data = (Uint8 *) addr;
+ pcm_data = addr;
pcm_data_size = size;
SDL_PauseAudio(0);
@@ -245,48 +245,48 @@ static void sdl_audio_callback(struct pcm_udata *udata, Uint8 *stream, int len)
/* Audio card wants more? Get some more then. */
while (len > 0) {
- new_buffer = true;
- pcm_play_get_more_callback((void **)&pcm_data, &pcm_data_size);
+ new_buffer = pcm_play_dma_complete_callback(PCM_DMAST_OK,
+ (const void **)&pcm_data, &pcm_data_size);
+
+ if (!new_buffer) {
+ DEBUGF("sdl_audio_callback: No Data.\n");
+ break;
+ }
+
start:
- if (pcm_data_size != 0) {
- udata->num_in = pcm_data_size / pcm_sample_bytes;
- udata->num_out = len / pcm_sample_bytes;
+ udata->num_in = pcm_data_size / pcm_sample_bytes;
+ udata->num_out = len / pcm_sample_bytes;
- write_to_soundcard(udata);
+ write_to_soundcard(udata);
- udata->num_in *= pcm_sample_bytes;
- udata->num_out *= pcm_sample_bytes;
+ udata->num_in *= pcm_sample_bytes;
+ udata->num_out *= pcm_sample_bytes;
+ if (new_buffer)
+ {
+ new_buffer = false;
+ pcm_play_dma_status_callback(PCM_DMAST_STARTED);
- if (new_buffer)
+ if ((size_t)len > udata->num_out)
{
- new_buffer = false;
- pcm_play_dma_started_callback();
+ int delay = pcm_data_size*250 / pcm_sampr - 1;
- if ((size_t)len > udata->num_out)
+ if (delay > 0)
{
- int delay = pcm_data_size*250 / pcm_sampr - 1;
-
- if (delay > 0)
- {
- SDL_UnlockMutex(audio_lock);
- SDL_Delay(delay);
- SDL_LockMutex(audio_lock);
-
- if (!pcm_is_playing())
- break;
- }
+ SDL_UnlockMutex(audio_lock);
+ SDL_Delay(delay);
+ SDL_LockMutex(audio_lock);
+
+ if (!pcm_is_playing())
+ break;
}
}
-
- pcm_data += udata->num_in;
- pcm_data_size -= udata->num_in;
- udata->stream += udata->num_out;
- len -= udata->num_out;
- } else {
- DEBUGF("sdl_audio_callback: No Data.\n");
- break;
}
+
+ pcm_data += udata->num_in;
+ pcm_data_size -= udata->num_in;
+ udata->stream += udata->num_out;
+ len -= udata->num_out;
}
SDL_UnlockMutex(audio_lock);