Skip to content

Commit

Permalink
Some updates on roar driver.
Browse files Browse the repository at this point in the history
  • Loading branch information
Themaister committed Aug 13, 2010
1 parent 1a008a9 commit 7148d5c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 27 deletions.
29 changes: 6 additions & 23 deletions roar/pcm_roar.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//pcm.c:
//pcm_roar.c:

/*
* Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010
Expand Down Expand Up @@ -119,7 +119,7 @@ static int roar_pcm_stop (snd_pcm_ioplug_t *io) {

if ( self->thread_active )
{
pthread_cancel(self->thread);
self->thread_active = 0;
pthread_cond_signal(&self->cond);
pthread_join(self->thread, NULL);
}
Expand Down Expand Up @@ -174,16 +174,6 @@ static int roar_hw_constraint(struct roar_alsa_pcm * self) {
if ( (ret = snd_pcm_ioplug_set_param_minmax(io, SND_PCM_IOPLUG_HW_RATE, 8000, 192000)) < 0 )
return ret;

#if 0
if ( (ret = snd_pcm_ioplug_set_param_minmax(io, SND_PCM_IOPLUG_HW_PERIOD_BYTES, 1, 4294967295U)) < 0 )
return ret;

if ( (ret = snd_pcm_ioplug_set_param_minmax(io, SND_PCM_IOPLUG_HW_PERIODS, 1, 4294967295U)) < 0 )
return ret;

if ( (ret = snd_pcm_ioplug_set_param_minmax(io, SND_PCM_IOPLUG_HW_BUFFER_BYTES, 1, 4294967295U)) < 0 )
return ret;
#else
// We shouldn't let ALSA use extremely low or high values, it will kill a kitty most likely. :v
if ( (ret = snd_pcm_ioplug_set_param_minmax(io, SND_PCM_IOPLUG_HW_PERIOD_BYTES, 1 << 6, 1 << 18)) < 0 )
return ret;
Expand All @@ -193,7 +183,6 @@ static int roar_hw_constraint(struct roar_alsa_pcm * self) {

if ( (ret = snd_pcm_ioplug_set_param_minmax(io, SND_PCM_IOPLUG_HW_BUFFER_BYTES, 1 << 13, 1 << 24)) < 0 )
return ret;
#endif

ROAR_DBG("roar_hw_constraint(*) = 0");

Expand Down Expand Up @@ -255,7 +244,6 @@ static snd_pcm_sframes_t roar_pcm_transfer(snd_pcm_ioplug_t *io,
// Weird ALSA stuff.
buf = (char *)areas->addr + (areas->first + areas->step * offset) / 8;

// ret = roar_vio_write(&(self->stream_vio), buf, len);
ret = roar_write(self, buf, len);

if ( ret != -1 ) {
Expand Down Expand Up @@ -406,6 +394,10 @@ static int roar_pcm_close (snd_pcm_ioplug_t * io) {

roar_disconnect(&(self->roar.con));

pthread_mutex_destroy(&self->lock);
pthread_mutex_destroy(&self->cond_lock);
pthread_cond_destroy(&self->cond);

free(self->buffer);
free(self);

Expand All @@ -415,20 +407,11 @@ static int roar_pcm_close (snd_pcm_ioplug_t * io) {
static snd_pcm_ioplug_callback_t roar_pcm_callback = {
.start = roar_pcm_start,
.stop = roar_pcm_stop,
.drain = NULL,
.pointer = roar_pcm_pointer,
.transfer = roar_pcm_transfer,
.delay = roar_pcm_delay,
.poll_descriptors_count = NULL,
.poll_descriptors = NULL,
.poll_revents = NULL,
.prepare = roar_pcm_prepare,
.hw_params = roar_pcm_hw_params,
.hw_free = NULL,
.sw_params = NULL,
.pause = NULL,
.resume = NULL,
.dump = NULL,
.close = roar_pcm_close,
};

Expand Down
14 changes: 10 additions & 4 deletions roar/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ size_t roar_write( struct roar_alsa_pcm *self, const char *buf, size_t size )
}
pthread_mutex_unlock(&self->lock);

pthread_cond_signal(&self->cond);
/* Sleeps until we can write to the FIFO. */
pthread_mutex_lock(&self->cond_lock);
pthread_cond_wait(&self->cond, &self->cond_lock);
Expand All @@ -39,6 +40,11 @@ size_t roar_write( struct roar_alsa_pcm *self, const char *buf, size_t size )
return size;
}

#define TEST_CANCEL do { \
if ( !self->thread_active ) \
goto test_quit; \
} while(0)

// Attemps to drain the buffer at all times and write to libroar.
// If there is no data, it will wait for roar_write() to fill up more data.
void* roar_thread ( void * thread_data )
Expand Down Expand Up @@ -67,14 +73,13 @@ void* roar_thread ( void * thread_data )
}
pthread_mutex_unlock(&self->lock);

pthread_testcancel();
TEST_CANCEL;
rc = roar_vio_write(&(self->stream_vio), self->buffer, CHUNK_SIZE);
// fprintf(stderr, "Thread wrote %d\n", rc);

/* If this happens, we should make sure that subsequent and current calls to rsd_write() will fail. */
if ( rc < 0 )
{
pthread_testcancel();
TEST_CANCEL;
roar_reset(self);

/* Wakes up a potentially sleeping fill_buffer() */
Expand Down Expand Up @@ -109,9 +114,10 @@ void* roar_thread ( void * thread_data )
}

/* If we're still good to go, sleep. We are waiting for fill_buffer() to fill up some data. */
pthread_testcancel();
test_quit:
if ( self->thread_active )
{
pthread_cond_signal(&self->cond);
pthread_mutex_lock(&self->cond_lock);
pthread_cond_wait(&self->cond, &self->cond_lock);
pthread_mutex_unlock(&self->cond_lock);
Expand Down

0 comments on commit 7148d5c

Please sign in to comment.