work on sink

This commit is contained in:
Wim Taymans 2016-08-18 12:43:25 +02:00
parent bdbddaf75b
commit a03352353f
9 changed files with 180 additions and 306 deletions

View file

@ -52,6 +52,7 @@ reset_alsa_sink_props (SpaALSASinkProps *props)
typedef struct {
bool opened;
bool have_buffers;
snd_pcm_t *handle;
snd_output_t *output;
snd_pcm_sframes_t buffer_size;
@ -391,6 +392,9 @@ spa_alsa_sink_node_port_set_format (SpaNode *node,
if ((res = spa_audio_raw_format_parse (format, &this->current_format)) < 0)
return res;
if (alsa_set_format (this, &this->current_format, false) < 0)
return SPA_RESULT_ERROR;
this->have_format = true;
return SPA_RESULT_OK;

View file

@ -11,6 +11,48 @@ static int verbose = 0; /* verbose flag */
#define CHECK(s,msg) if ((err = (s)) < 0) { printf (msg ": %s\n", snd_strerror(err)); return err; }
static int
spa_alsa_open (SpaALSASink *this)
{
SpaALSAState *state = &this->state;
int err;
SpaALSASinkProps *props = &this->props[1];
if (state->opened)
return 0;
CHECK (snd_output_stdio_attach (&state->output, stdout, 0), "attach failed");
printf ("Playback device is '%s'\n", props->device);
CHECK (snd_pcm_open (&state->handle,
props->device,
SND_PCM_STREAM_PLAYBACK,
SND_PCM_NONBLOCK |
SND_PCM_NO_AUTO_RESAMPLE |
SND_PCM_NO_AUTO_CHANNELS |
SND_PCM_NO_AUTO_FORMAT), "open failed");
state->opened = true;
return 0;
}
static int
spa_alsa_close (SpaALSASink *this)
{
SpaALSAState *state = &this->state;
int err = 0;
if (!state->opened)
return 0;
CHECK (snd_pcm_close (state->handle), "close failed");
state->opened = false;
return err;
}
static snd_pcm_format_t
spa_alsa_format_to_alsa (SpaAudioFormat format)
{
@ -63,7 +105,7 @@ spa_alsa_format_to_alsa (SpaAudioFormat format)
}
static int
set_hwparams (SpaALSASink *this)
alsa_set_format (SpaALSASink *this, SpaAudioRawFormat *fmt, bool try_only)
{
unsigned int rrate;
snd_pcm_uframes_t size;
@ -71,13 +113,17 @@ set_hwparams (SpaALSASink *this)
snd_pcm_hw_params_t *params;
snd_pcm_format_t format;
SpaALSAState *state = &this->state;
SpaAudioRawFormat *fmt = &this->current_format;
SpaAudioRawInfo *info = &fmt->info;
snd_pcm_t *handle = state->handle;
snd_pcm_t *handle;
unsigned int buffer_time;
unsigned int period_time;
SpaALSASinkProps *props = &this->props[1];
if ((err = spa_alsa_open (this)) < 0)
return err;
handle = state->handle;
snd_pcm_hw_params_alloca (&params);
/* choose all parameters */
CHECK (snd_pcm_hw_params_any (handle, params), "Broken configuration for playback: no configurations available");
@ -175,32 +221,6 @@ xrun_recovery (snd_pcm_t *handle, int err)
return err;
}
static int
spa_alsa_open (SpaALSASink *this)
{
SpaALSAState *state = &this->state;
int err;
SpaALSASinkProps *props = &this->props[1];
if (state->opened)
return 0;
CHECK (snd_output_stdio_attach (&state->output, stdout, 0), "attach failed");
printf ("Playback device is '%s'\n", props->device);
CHECK (snd_pcm_open (&state->handle,
props->device,
SND_PCM_STREAM_PLAYBACK,
SND_PCM_NONBLOCK |
SND_PCM_NO_AUTO_RESAMPLE |
SND_PCM_NO_AUTO_CHANNELS |
SND_PCM_NO_AUTO_FORMAT), "open failed");
state->opened = true;
return 0;
}
static void
pull_input (SpaALSASink *this, void *data, snd_pcm_uframes_t frames)
{
@ -303,22 +323,6 @@ alsa_on_fd_events (SpaPollNotifyData *data)
return 0;
}
static int
spa_alsa_close (SpaALSASink *this)
{
SpaALSAState *state = &this->state;
int err = 0;
if (!state->opened)
return 0;
CHECK (snd_pcm_close (state->handle), "close failed");
state->opened = false;
return err;
}
static int
spa_alsa_start (SpaALSASink *this)
{
@ -329,7 +333,9 @@ spa_alsa_start (SpaALSASink *this)
if (spa_alsa_open (this) < 0)
return -1;
CHECK (set_hwparams (this), "hwparams");
if (!state->have_buffers)
return -1;
CHECK (set_swparams (this), "swparams");
snd_pcm_dump (state->handle, state->output);

View file

@ -66,6 +66,24 @@ spa_v4l2_open (SpaV4l2Source *this)
return 0;
}
static int
spa_v4l2_close (SpaV4l2Source *this)
{
SpaV4l2State *state = &this->state[0];
if (!state->opened)
return 0;
fprintf (stderr, "close\n");
if (close(state->fd))
perror ("close");
state->fd = -1;
state->opened = false;
return 0;
}
typedef struct {
uint32_t fourcc;
SpaVideoFormat format;
@ -418,24 +436,6 @@ spa_v4l2_set_format (SpaV4l2Source *this, V4l2Format *f, bool try_only)
return 0;
}
static int
spa_v4l2_close (SpaV4l2Source *this)
{
SpaV4l2State *state = &this->state[0];
if (!state->opened)
return 0;
fprintf (stderr, "close\n");
if (close(state->fd))
perror ("close");
state->fd = -1;
state->opened = false;
return 0;
}
static SpaResult
mmap_read (SpaV4l2Source *this)
{