2004-07-16 19:56:36 +00:00
|
|
|
/***
|
2006-06-19 21:53:48 +00:00
|
|
|
This file is part of PulseAudio.
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2007-02-13 15:35:19 +00:00
|
|
|
Copyright 2004-2006 Lennart Poettering
|
|
|
|
|
Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
|
|
|
|
|
|
2006-06-19 21:53:48 +00:00
|
|
|
PulseAudio is free software; you can redistribute it and/or modify
|
2004-11-14 14:58:54 +00:00
|
|
|
it under the terms of the GNU Lesser General Public License as published
|
2009-03-03 20:23:02 +00:00
|
|
|
by the Free Software Foundation; either version 2.1 of the License,
|
2004-07-16 19:56:36 +00:00
|
|
|
or (at your option) any later version.
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2006-06-19 21:53:48 +00:00
|
|
|
PulseAudio is distributed in the hope that it will be useful, but
|
2004-07-16 19:56:36 +00:00
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
General Public License for more details.
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2004-11-14 14:58:54 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
2014-11-26 14:14:51 +01:00
|
|
|
along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
|
2004-07-16 19:56:36 +00:00
|
|
|
***/
|
|
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
/* General power management rules:
|
|
|
|
|
*
|
|
|
|
|
* When SUSPENDED we close the audio device.
|
|
|
|
|
*
|
|
|
|
|
* We make no difference between IDLE and RUNNING in our handling.
|
|
|
|
|
*
|
|
|
|
|
* As long as we are in RUNNING/IDLE state we will *always* write data to
|
2011-08-24 18:24:46 +02:00
|
|
|
* the device. If none is available from the inputs, we write silence
|
2007-10-28 19:13:50 +00:00
|
|
|
* instead.
|
|
|
|
|
*
|
|
|
|
|
* If power should be saved on IDLE module-suspend-on-idle should be used.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2004-07-16 19:16:42 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
#include <config.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
#ifdef HAVE_SYS_MMAN_H
|
|
|
|
|
#include <sys/mman.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2004-06-15 00:29:01 +00:00
|
|
|
#include <sys/soundcard.h>
|
|
|
|
|
#include <sys/ioctl.h>
|
2004-06-14 22:47:12 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
2006-06-19 21:53:48 +00:00
|
|
|
#include <pulse/xmalloc.h>
|
2006-08-12 16:26:59 +00:00
|
|
|
#include <pulse/util.h>
|
2006-05-17 16:34:18 +00:00
|
|
|
|
2006-06-19 21:53:48 +00:00
|
|
|
#include <pulsecore/core-error.h>
|
2007-10-28 19:13:50 +00:00
|
|
|
#include <pulsecore/thread.h>
|
2006-06-19 21:53:48 +00:00
|
|
|
#include <pulsecore/sink.h>
|
|
|
|
|
#include <pulsecore/source.h>
|
|
|
|
|
#include <pulsecore/module.h>
|
|
|
|
|
#include <pulsecore/sample-util.h>
|
|
|
|
|
#include <pulsecore/core-util.h>
|
|
|
|
|
#include <pulsecore/modargs.h>
|
|
|
|
|
#include <pulsecore/log.h>
|
2007-10-28 19:13:50 +00:00
|
|
|
#include <pulsecore/macro.h>
|
|
|
|
|
#include <pulsecore/thread-mq.h>
|
|
|
|
|
#include <pulsecore/rtpoll.h>
|
2011-01-04 11:17:53 +01:00
|
|
|
#include <pulsecore/poll.h>
|
2006-02-16 19:19:58 +00:00
|
|
|
|
2009-01-22 02:24:04 +01:00
|
|
|
#if defined(__NetBSD__) && !defined(SNDCTL_DSP_GETODELAY)
|
|
|
|
|
#include <sys/audioio.h>
|
|
|
|
|
#include <sys/syscall.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2006-02-16 22:08:06 +00:00
|
|
|
#include "oss-util.h"
|
2004-06-14 22:47:12 +00:00
|
|
|
|
2007-11-09 18:25:40 +00:00
|
|
|
PA_MODULE_AUTHOR("Lennart Poettering");
|
|
|
|
|
PA_MODULE_DESCRIPTION("OSS Sink/Source");
|
|
|
|
|
PA_MODULE_VERSION(PACKAGE_VERSION);
|
2013-06-27 19:28:09 +02:00
|
|
|
PA_MODULE_LOAD_ONCE(false);
|
2006-04-10 19:42:44 +00:00
|
|
|
PA_MODULE_USAGE(
|
|
|
|
|
"sink_name=<name for the sink> "
|
2009-05-28 02:39:22 +02:00
|
|
|
"sink_properties=<properties for the sink> "
|
2006-04-10 19:42:44 +00:00
|
|
|
"source_name=<name for the source> "
|
2009-05-28 02:39:22 +02:00
|
|
|
"source_properties=<properties for the source> "
|
2006-04-10 19:42:44 +00:00
|
|
|
"device=<OSS device> "
|
|
|
|
|
"record=<enable source?> "
|
|
|
|
|
"playback=<enable sink?> "
|
|
|
|
|
"format=<sample format> "
|
|
|
|
|
"rate=<sample rate> "
|
2009-05-28 02:39:22 +02:00
|
|
|
"channels=<number of channels> "
|
|
|
|
|
"channel_map=<channel map> "
|
2006-04-10 19:42:44 +00:00
|
|
|
"fragments=<number of fragments> "
|
2006-04-26 15:40:14 +00:00
|
|
|
"fragment_size=<fragment size> "
|
2007-11-09 18:25:40 +00:00
|
|
|
"mmap=<enable memory mapping?>");
|
2009-05-28 02:47:36 +02:00
|
|
|
#ifdef __linux__
|
|
|
|
|
PA_MODULE_DEPRECATED("Please use module-alsa-card instead of module-oss!");
|
|
|
|
|
#endif
|
2007-10-28 19:13:50 +00:00
|
|
|
|
|
|
|
|
#define DEFAULT_DEVICE "/dev/dsp"
|
2004-09-11 23:17:38 +00:00
|
|
|
|
2004-06-14 22:47:12 +00:00
|
|
|
struct userdata {
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_core *core;
|
|
|
|
|
pa_module *module;
|
2006-01-11 01:17:39 +00:00
|
|
|
pa_sink *sink;
|
|
|
|
|
pa_source *source;
|
2004-06-14 22:47:12 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_thread *thread;
|
|
|
|
|
pa_thread_mq thread_mq;
|
|
|
|
|
pa_rtpoll *rtpoll;
|
|
|
|
|
|
|
|
|
|
char *device_name;
|
|
|
|
|
|
|
|
|
|
pa_memchunk memchunk;
|
2004-06-14 22:47:12 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
size_t frame_size;
|
|
|
|
|
uint32_t in_fragment_size, out_fragment_size, in_nfrags, out_nfrags, in_hwbuf_size, out_hwbuf_size;
|
2013-06-27 19:28:09 +02:00
|
|
|
bool use_getospace, use_getispace;
|
|
|
|
|
bool use_getodelay;
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2013-06-27 19:28:09 +02:00
|
|
|
bool sink_suspended, source_suspended;
|
2004-06-16 00:05:30 +00:00
|
|
|
|
|
|
|
|
int fd;
|
2007-10-28 19:13:50 +00:00
|
|
|
int mode;
|
|
|
|
|
|
|
|
|
|
int mixer_fd;
|
|
|
|
|
int mixer_devmask;
|
|
|
|
|
|
2009-01-22 01:15:49 +01:00
|
|
|
int nfrags, frag_size, orig_frag_size;
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2013-06-27 19:28:09 +02:00
|
|
|
bool use_mmap;
|
2007-10-28 19:13:50 +00:00
|
|
|
unsigned out_mmap_current, in_mmap_current;
|
|
|
|
|
void *in_mmap, *out_mmap;
|
|
|
|
|
pa_memblock **in_mmap_memblocks, **out_mmap_memblocks;
|
|
|
|
|
|
|
|
|
|
int in_mmap_saved_nfrags, out_mmap_saved_nfrags;
|
|
|
|
|
|
|
|
|
|
pa_rtpoll_item *rtpoll_item;
|
2004-06-14 22:47:12 +00:00
|
|
|
};
|
|
|
|
|
|
2004-07-11 23:21:32 +00:00
|
|
|
static const char* const valid_modargs[] = {
|
|
|
|
|
"sink_name",
|
2009-05-28 02:39:22 +02:00
|
|
|
"sink_properties",
|
2004-07-11 23:21:32 +00:00
|
|
|
"source_name",
|
2009-05-28 02:39:22 +02:00
|
|
|
"source_properties",
|
2004-07-11 23:21:32 +00:00
|
|
|
"device",
|
|
|
|
|
"record",
|
|
|
|
|
"playback",
|
2004-07-16 17:51:53 +00:00
|
|
|
"fragments",
|
|
|
|
|
"fragment_size",
|
|
|
|
|
"format",
|
|
|
|
|
"rate",
|
|
|
|
|
"channels",
|
2006-04-26 15:40:14 +00:00
|
|
|
"channel_map",
|
2007-10-28 19:13:50 +00:00
|
|
|
"mmap",
|
2004-07-11 23:21:32 +00:00
|
|
|
NULL
|
|
|
|
|
};
|
|
|
|
|
|
oss: don't fail resume if trigger() fails
The previous code made the SET_STATE message fail if trigger() failed.
However, trigger() was called after pa_sink/source_process_msg(), which
meant that the main thread that sent the SET_STATE thought that resuming
failed, but nothing was undone in the IO thread, so in the IO thread
things seemed as if the sink/source was successfully resumed. (I don't
use OSS myself, so I don't know what kind of practical problems this
could cause).
Unless some complex undo logic is implemented, I believe it's best to
ignore all failures in trigger(). Most error cases were already ignored,
and the only one that wasn't ignored doesn't seem too serious.
I also moved trigger() to happen before pa_sink/source_process_msg(),
which made it necessary to add new state parameters to trigger(). The
reason for this move is that I want to move the SET_STATE handler code
into a separate callback, and if things are done both before and after
pa_sink/source_process_msg(), that makes things more complicated.
The previous code checked the return value of
pa_sink/source_process_msg() before calling trigger(), but that was
unnecessary, since pa_sink/source_process_msg() never fails when
processing the SET_STATE messages.
2018-03-13 19:40:37 +02:00
|
|
|
/* Sink and source states are passed as arguments, because this is called
|
|
|
|
|
* during state changes, and we need the new state, but thread_info.state
|
|
|
|
|
* has not yet been updated. */
|
|
|
|
|
static void trigger(struct userdata *u, pa_sink_state_t sink_state, pa_source_state_t source_state, bool quick) {
|
2007-10-28 19:13:50 +00:00
|
|
|
int enable_bits = 0, zero = 0;
|
2004-07-11 23:21:32 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_assert(u);
|
2004-08-04 16:39:30 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
if (u->fd < 0)
|
oss: don't fail resume if trigger() fails
The previous code made the SET_STATE message fail if trigger() failed.
However, trigger() was called after pa_sink/source_process_msg(), which
meant that the main thread that sent the SET_STATE thought that resuming
failed, but nothing was undone in the IO thread, so in the IO thread
things seemed as if the sink/source was successfully resumed. (I don't
use OSS myself, so I don't know what kind of practical problems this
could cause).
Unless some complex undo logic is implemented, I believe it's best to
ignore all failures in trigger(). Most error cases were already ignored,
and the only one that wasn't ignored doesn't seem too serious.
I also moved trigger() to happen before pa_sink/source_process_msg(),
which made it necessary to add new state parameters to trigger(). The
reason for this move is that I want to move the SET_STATE handler code
into a separate callback, and if things are done both before and after
pa_sink/source_process_msg(), that makes things more complicated.
The previous code checked the return value of
pa_sink/source_process_msg() before calling trigger(), but that was
unnecessary, since pa_sink/source_process_msg() never fails when
processing the SET_STATE messages.
2018-03-13 19:40:37 +02:00
|
|
|
return;
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2011-03-02 12:41:26 +01:00
|
|
|
pa_log_debug("trigger");
|
2007-01-04 13:43:45 +00:00
|
|
|
|
oss: don't fail resume if trigger() fails
The previous code made the SET_STATE message fail if trigger() failed.
However, trigger() was called after pa_sink/source_process_msg(), which
meant that the main thread that sent the SET_STATE thought that resuming
failed, but nothing was undone in the IO thread, so in the IO thread
things seemed as if the sink/source was successfully resumed. (I don't
use OSS myself, so I don't know what kind of practical problems this
could cause).
Unless some complex undo logic is implemented, I believe it's best to
ignore all failures in trigger(). Most error cases were already ignored,
and the only one that wasn't ignored doesn't seem too serious.
I also moved trigger() to happen before pa_sink/source_process_msg(),
which made it necessary to add new state parameters to trigger(). The
reason for this move is that I want to move the SET_STATE handler code
into a separate callback, and if things are done both before and after
pa_sink/source_process_msg(), that makes things more complicated.
The previous code checked the return value of
pa_sink/source_process_msg() before calling trigger(), but that was
unnecessary, since pa_sink/source_process_msg() never fails when
processing the SET_STATE messages.
2018-03-13 19:40:37 +02:00
|
|
|
if (u->source && PA_SOURCE_IS_OPENED(source_state))
|
2007-10-28 19:13:50 +00:00
|
|
|
enable_bits |= PCM_ENABLE_INPUT;
|
2006-08-12 16:02:26 +00:00
|
|
|
|
oss: don't fail resume if trigger() fails
The previous code made the SET_STATE message fail if trigger() failed.
However, trigger() was called after pa_sink/source_process_msg(), which
meant that the main thread that sent the SET_STATE thought that resuming
failed, but nothing was undone in the IO thread, so in the IO thread
things seemed as if the sink/source was successfully resumed. (I don't
use OSS myself, so I don't know what kind of practical problems this
could cause).
Unless some complex undo logic is implemented, I believe it's best to
ignore all failures in trigger(). Most error cases were already ignored,
and the only one that wasn't ignored doesn't seem too serious.
I also moved trigger() to happen before pa_sink/source_process_msg(),
which made it necessary to add new state parameters to trigger(). The
reason for this move is that I want to move the SET_STATE handler code
into a separate callback, and if things are done both before and after
pa_sink/source_process_msg(), that makes things more complicated.
The previous code checked the return value of
pa_sink/source_process_msg() before calling trigger(), but that was
unnecessary, since pa_sink/source_process_msg() never fails when
processing the SET_STATE messages.
2018-03-13 19:40:37 +02:00
|
|
|
if (u->sink && PA_SINK_IS_OPENED(sink_state))
|
2007-10-28 19:13:50 +00:00
|
|
|
enable_bits |= PCM_ENABLE_OUTPUT;
|
2006-08-12 16:02:26 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_log_debug("trigger: %i", enable_bits);
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
if (u->use_mmap) {
|
2004-06-14 22:47:12 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
if (!quick)
|
|
|
|
|
ioctl(u->fd, SNDCTL_DSP_SETTRIGGER, &zero);
|
2004-06-14 22:47:12 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
#ifdef SNDCTL_DSP_HALT
|
|
|
|
|
if (enable_bits == 0)
|
|
|
|
|
if (ioctl(u->fd, SNDCTL_DSP_HALT, NULL) < 0)
|
|
|
|
|
pa_log_warn("SNDCTL_DSP_HALT: %s", pa_cstrerror(errno));
|
|
|
|
|
#endif
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
if (ioctl(u->fd, SNDCTL_DSP_SETTRIGGER, &enable_bits) < 0)
|
|
|
|
|
pa_log_warn("SNDCTL_DSP_SETTRIGGER: %s", pa_cstrerror(errno));
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
if (u->sink && !(enable_bits & PCM_ENABLE_OUTPUT)) {
|
|
|
|
|
pa_log_debug("clearing playback buffer");
|
|
|
|
|
pa_silence_memory(u->out_mmap, u->out_hwbuf_size, &u->sink->sample_spec);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
if (enable_bits)
|
|
|
|
|
if (ioctl(u->fd, SNDCTL_DSP_POST, NULL) < 0)
|
|
|
|
|
pa_log_warn("SNDCTL_DSP_POST: %s", pa_cstrerror(errno));
|
|
|
|
|
|
|
|
|
|
if (!quick) {
|
|
|
|
|
/*
|
|
|
|
|
* Some crappy drivers do not start the recording until we
|
|
|
|
|
* read something. Without this snippet, poll will never
|
|
|
|
|
* register the fd as ready.
|
|
|
|
|
*/
|
|
|
|
|
|
oss: don't fail resume if trigger() fails
The previous code made the SET_STATE message fail if trigger() failed.
However, trigger() was called after pa_sink/source_process_msg(), which
meant that the main thread that sent the SET_STATE thought that resuming
failed, but nothing was undone in the IO thread, so in the IO thread
things seemed as if the sink/source was successfully resumed. (I don't
use OSS myself, so I don't know what kind of practical problems this
could cause).
Unless some complex undo logic is implemented, I believe it's best to
ignore all failures in trigger(). Most error cases were already ignored,
and the only one that wasn't ignored doesn't seem too serious.
I also moved trigger() to happen before pa_sink/source_process_msg(),
which made it necessary to add new state parameters to trigger(). The
reason for this move is that I want to move the SET_STATE handler code
into a separate callback, and if things are done both before and after
pa_sink/source_process_msg(), that makes things more complicated.
The previous code checked the return value of
pa_sink/source_process_msg() before calling trigger(), but that was
unnecessary, since pa_sink/source_process_msg() never fails when
processing the SET_STATE messages.
2018-03-13 19:40:37 +02:00
|
|
|
if (u->source && PA_SOURCE_IS_OPENED(source_state)) {
|
2007-10-28 19:13:50 +00:00
|
|
|
uint8_t *buf = pa_xnew(uint8_t, u->in_fragment_size);
|
2012-04-02 16:13:54 +03:00
|
|
|
|
oss: don't fail resume if trigger() fails
The previous code made the SET_STATE message fail if trigger() failed.
However, trigger() was called after pa_sink/source_process_msg(), which
meant that the main thread that sent the SET_STATE thought that resuming
failed, but nothing was undone in the IO thread, so in the IO thread
things seemed as if the sink/source was successfully resumed. (I don't
use OSS myself, so I don't know what kind of practical problems this
could cause).
Unless some complex undo logic is implemented, I believe it's best to
ignore all failures in trigger(). Most error cases were already ignored,
and the only one that wasn't ignored doesn't seem too serious.
I also moved trigger() to happen before pa_sink/source_process_msg(),
which made it necessary to add new state parameters to trigger(). The
reason for this move is that I want to move the SET_STATE handler code
into a separate callback, and if things are done both before and after
pa_sink/source_process_msg(), that makes things more complicated.
The previous code checked the return value of
pa_sink/source_process_msg() before calling trigger(), but that was
unnecessary, since pa_sink/source_process_msg() never fails when
processing the SET_STATE messages.
2018-03-13 19:40:37 +02:00
|
|
|
/* XXX: Shouldn't this be done only when resuming the source?
|
|
|
|
|
* Currently this code path is executed also when resuming the
|
|
|
|
|
* sink while the source is already running. */
|
|
|
|
|
|
|
|
|
|
if (pa_read(u->fd, buf, u->in_fragment_size, NULL) < 0)
|
2012-04-02 16:13:54 +03:00
|
|
|
pa_log("pa_read() failed: %s", pa_cstrerror(errno));
|
|
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_xfree(buf);
|
2004-09-16 00:05:56 +00:00
|
|
|
}
|
|
|
|
|
}
|
2004-06-14 22:47:12 +00:00
|
|
|
}
|
2007-10-28 19:13:50 +00:00
|
|
|
}
|
2004-09-16 00:05:56 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
static void mmap_fill_memblocks(struct userdata *u, unsigned n) {
|
|
|
|
|
pa_assert(u);
|
|
|
|
|
pa_assert(u->out_mmap_memblocks);
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
/* pa_log("Mmmap writing %u blocks", n); */
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
while (n > 0) {
|
|
|
|
|
pa_memchunk chunk;
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
if (u->out_mmap_memblocks[u->out_mmap_current])
|
|
|
|
|
pa_memblock_unref_fixed(u->out_mmap_memblocks[u->out_mmap_current]);
|
2006-08-12 16:02:26 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
chunk.memblock = u->out_mmap_memblocks[u->out_mmap_current] =
|
|
|
|
|
pa_memblock_new_fixed(
|
|
|
|
|
u->core->mempool,
|
|
|
|
|
(uint8_t*) u->out_mmap + u->out_fragment_size * u->out_mmap_current,
|
|
|
|
|
u->out_fragment_size,
|
|
|
|
|
1);
|
2007-05-29 17:24:48 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
chunk.length = pa_memblock_get_length(chunk.memblock);
|
|
|
|
|
chunk.index = 0;
|
2007-05-29 17:24:48 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_sink_render_into_full(u->sink, &chunk);
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
u->out_mmap_current++;
|
|
|
|
|
while (u->out_mmap_current >= u->out_nfrags)
|
|
|
|
|
u->out_mmap_current -= u->out_nfrags;
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
n--;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int mmap_write(struct userdata *u) {
|
|
|
|
|
struct count_info info;
|
|
|
|
|
|
|
|
|
|
pa_assert(u);
|
|
|
|
|
pa_assert(u->sink);
|
|
|
|
|
|
|
|
|
|
/* pa_log("Mmmap writing..."); */
|
|
|
|
|
|
|
|
|
|
if (ioctl(u->fd, SNDCTL_DSP_GETOPTR, &info) < 0) {
|
|
|
|
|
pa_log("SNDCTL_DSP_GETOPTR: %s", pa_cstrerror(errno));
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
info.blocks += u->out_mmap_saved_nfrags;
|
|
|
|
|
u->out_mmap_saved_nfrags = 0;
|
|
|
|
|
|
|
|
|
|
if (info.blocks > 0)
|
2008-08-19 22:39:54 +02:00
|
|
|
mmap_fill_memblocks(u, (unsigned) info.blocks);
|
2004-09-16 00:05:56 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
return info.blocks;
|
2004-06-14 22:47:12 +00:00
|
|
|
}
|
|
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
static void mmap_post_memblocks(struct userdata *u, unsigned n) {
|
|
|
|
|
pa_assert(u);
|
|
|
|
|
pa_assert(u->in_mmap_memblocks);
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
/* pa_log("Mmmap reading %u blocks", n); */
|
2004-06-14 22:47:12 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
while (n > 0) {
|
|
|
|
|
pa_memchunk chunk;
|
2004-08-04 16:39:30 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
if (!u->in_mmap_memblocks[u->in_mmap_current]) {
|
2004-06-14 22:47:12 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
chunk.memblock = u->in_mmap_memblocks[u->in_mmap_current] =
|
|
|
|
|
pa_memblock_new_fixed(
|
|
|
|
|
u->core->mempool,
|
|
|
|
|
(uint8_t*) u->in_mmap + u->in_fragment_size*u->in_mmap_current,
|
|
|
|
|
u->in_fragment_size,
|
|
|
|
|
1);
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
chunk.length = pa_memblock_get_length(chunk.memblock);
|
|
|
|
|
chunk.index = 0;
|
|
|
|
|
|
|
|
|
|
pa_source_post(u->source, &chunk);
|
2004-09-16 00:05:56 +00:00
|
|
|
}
|
2007-10-28 19:13:50 +00:00
|
|
|
|
|
|
|
|
u->in_mmap_current++;
|
|
|
|
|
while (u->in_mmap_current >= u->in_nfrags)
|
|
|
|
|
u->in_mmap_current -= u->in_nfrags;
|
|
|
|
|
|
|
|
|
|
n--;
|
2004-09-16 00:05:56 +00:00
|
|
|
}
|
2007-10-28 19:13:50 +00:00
|
|
|
}
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
static void mmap_clear_memblocks(struct userdata*u, unsigned n) {
|
|
|
|
|
unsigned i = u->in_mmap_current;
|
2007-05-29 17:24:48 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_assert(u);
|
|
|
|
|
pa_assert(u->in_mmap_memblocks);
|
2007-05-29 17:24:48 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
if (n > u->in_nfrags)
|
|
|
|
|
n = u->in_nfrags;
|
2007-05-29 17:24:48 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
while (n > 0) {
|
|
|
|
|
if (u->in_mmap_memblocks[i]) {
|
|
|
|
|
pa_memblock_unref_fixed(u->in_mmap_memblocks[i]);
|
|
|
|
|
u->in_mmap_memblocks[i] = NULL;
|
2004-09-16 00:05:56 +00:00
|
|
|
}
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
i++;
|
|
|
|
|
while (i >= u->in_nfrags)
|
|
|
|
|
i -= u->in_nfrags;
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
n--;
|
|
|
|
|
}
|
|
|
|
|
}
|
2004-06-14 22:47:12 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
static int mmap_read(struct userdata *u) {
|
|
|
|
|
struct count_info info;
|
|
|
|
|
pa_assert(u);
|
|
|
|
|
pa_assert(u->source);
|
|
|
|
|
|
|
|
|
|
/* pa_log("Mmmap reading..."); */
|
|
|
|
|
|
|
|
|
|
if (ioctl(u->fd, SNDCTL_DSP_GETIPTR, &info) < 0) {
|
|
|
|
|
pa_log("SNDCTL_DSP_GETIPTR: %s", pa_cstrerror(errno));
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* pa_log("... %i", info.blocks); */
|
|
|
|
|
|
|
|
|
|
info.blocks += u->in_mmap_saved_nfrags;
|
|
|
|
|
u->in_mmap_saved_nfrags = 0;
|
|
|
|
|
|
|
|
|
|
if (info.blocks > 0) {
|
2008-08-19 22:39:54 +02:00
|
|
|
mmap_post_memblocks(u, (unsigned) info.blocks);
|
2007-10-28 19:13:50 +00:00
|
|
|
mmap_clear_memblocks(u, u->in_nfrags/2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return info.blocks;
|
2004-08-19 23:14:59 +00:00
|
|
|
}
|
2004-06-14 22:47:12 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
static pa_usec_t mmap_sink_get_latency(struct userdata *u) {
|
|
|
|
|
struct count_info info;
|
|
|
|
|
size_t bpos, n;
|
|
|
|
|
|
|
|
|
|
pa_assert(u);
|
|
|
|
|
|
|
|
|
|
if (ioctl(u->fd, SNDCTL_DSP_GETOPTR, &info) < 0) {
|
|
|
|
|
pa_log("SNDCTL_DSP_GETOPTR: %s", pa_cstrerror(errno));
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
u->out_mmap_saved_nfrags += info.blocks;
|
|
|
|
|
|
2008-08-19 22:39:54 +02:00
|
|
|
bpos = ((u->out_mmap_current + (unsigned) u->out_mmap_saved_nfrags) * u->out_fragment_size) % u->out_hwbuf_size;
|
2007-10-28 19:13:50 +00:00
|
|
|
|
|
|
|
|
if (bpos <= (size_t) info.ptr)
|
2008-08-19 22:39:54 +02:00
|
|
|
n = u->out_hwbuf_size - ((size_t) info.ptr - bpos);
|
2007-10-28 19:13:50 +00:00
|
|
|
else
|
2008-08-19 22:39:54 +02:00
|
|
|
n = bpos - (size_t) info.ptr;
|
2007-10-28 19:13:50 +00:00
|
|
|
|
|
|
|
|
/* pa_log("n = %u, bpos = %u, ptr = %u, total=%u, fragsize = %u, n_frags = %u\n", n, bpos, (unsigned) info.ptr, total, u->out_fragment_size, u->out_fragments); */
|
|
|
|
|
|
|
|
|
|
return pa_bytes_to_usec(n, &u->sink->sample_spec);
|
2004-06-14 22:47:12 +00:00
|
|
|
}
|
|
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
static pa_usec_t mmap_source_get_latency(struct userdata *u) {
|
|
|
|
|
struct count_info info;
|
|
|
|
|
size_t bpos, n;
|
|
|
|
|
|
|
|
|
|
pa_assert(u);
|
|
|
|
|
|
|
|
|
|
if (ioctl(u->fd, SNDCTL_DSP_GETIPTR, &info) < 0) {
|
|
|
|
|
pa_log("SNDCTL_DSP_GETIPTR: %s", pa_cstrerror(errno));
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
u->in_mmap_saved_nfrags += info.blocks;
|
2008-08-19 22:39:54 +02:00
|
|
|
bpos = ((u->in_mmap_current + (unsigned) u->in_mmap_saved_nfrags) * u->in_fragment_size) % u->in_hwbuf_size;
|
2007-10-28 19:13:50 +00:00
|
|
|
|
|
|
|
|
if (bpos <= (size_t) info.ptr)
|
2008-08-19 22:39:54 +02:00
|
|
|
n = (size_t) info.ptr - bpos;
|
2007-10-28 19:13:50 +00:00
|
|
|
else
|
2008-08-19 22:39:54 +02:00
|
|
|
n = u->in_hwbuf_size - bpos + (size_t) info.ptr;
|
2007-10-28 19:13:50 +00:00
|
|
|
|
|
|
|
|
/* pa_log("n = %u, bpos = %u, ptr = %u, total=%u, fragsize = %u, n_frags = %u\n", n, bpos, (unsigned) info.ptr, total, u->in_fragment_size, u->in_fragments); */
|
|
|
|
|
|
|
|
|
|
return pa_bytes_to_usec(n, &u->source->sample_spec);
|
2006-01-12 16:11:54 +00:00
|
|
|
}
|
|
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
static pa_usec_t io_sink_get_latency(struct userdata *u) {
|
2004-09-13 13:26:44 +00:00
|
|
|
pa_usec_t r = 0;
|
2004-06-16 00:05:30 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_assert(u);
|
|
|
|
|
|
|
|
|
|
if (u->use_getodelay) {
|
|
|
|
|
int arg;
|
2009-01-22 02:24:04 +01:00
|
|
|
#if defined(__NetBSD__) && !defined(SNDCTL_DSP_GETODELAY)
|
|
|
|
|
#if defined(AUDIO_GETBUFINFO)
|
|
|
|
|
struct audio_info info;
|
|
|
|
|
if (syscall(SYS_ioctl, u->fd, AUDIO_GETBUFINFO, &info) < 0) {
|
|
|
|
|
pa_log_info("Device doesn't support AUDIO_GETBUFINFO: %s", pa_cstrerror(errno));
|
|
|
|
|
u->use_getodelay = 0;
|
|
|
|
|
} else {
|
|
|
|
|
arg = info.play.seek + info.blocksize / 2;
|
|
|
|
|
r = pa_bytes_to_usec((size_t) arg, &u->sink->sample_spec);
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
pa_log_info("System doesn't support AUDIO_GETBUFINFO");
|
|
|
|
|
u->use_getodelay = 0;
|
|
|
|
|
#endif
|
|
|
|
|
#else
|
2007-10-28 19:13:50 +00:00
|
|
|
if (ioctl(u->fd, SNDCTL_DSP_GETODELAY, &arg) < 0) {
|
|
|
|
|
pa_log_info("Device doesn't support SNDCTL_DSP_GETODELAY: %s", pa_cstrerror(errno));
|
|
|
|
|
u->use_getodelay = 0;
|
|
|
|
|
} else
|
2008-08-19 22:39:54 +02:00
|
|
|
r = pa_bytes_to_usec((size_t) arg, &u->sink->sample_spec);
|
2009-01-22 02:24:04 +01:00
|
|
|
#endif
|
2004-06-16 00:05:30 +00:00
|
|
|
}
|
|
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
if (!u->use_getodelay && u->use_getospace) {
|
|
|
|
|
struct audio_buf_info info;
|
|
|
|
|
|
|
|
|
|
if (ioctl(u->fd, SNDCTL_DSP_GETOSPACE, &info) < 0) {
|
|
|
|
|
pa_log_info("Device doesn't support SNDCTL_DSP_GETOSPACE: %s", pa_cstrerror(errno));
|
|
|
|
|
u->use_getospace = 0;
|
|
|
|
|
} else
|
2008-08-19 22:39:54 +02:00
|
|
|
r = pa_bytes_to_usec((size_t) info.bytes, &u->sink->sample_spec);
|
2007-10-28 19:13:50 +00:00
|
|
|
}
|
2004-09-13 13:26:44 +00:00
|
|
|
|
|
|
|
|
if (u->memchunk.memblock)
|
2007-10-28 19:13:50 +00:00
|
|
|
r += pa_bytes_to_usec(u->memchunk.length, &u->sink->sample_spec);
|
2004-09-13 13:26:44 +00:00
|
|
|
|
|
|
|
|
return r;
|
2004-06-16 00:05:30 +00:00
|
|
|
}
|
|
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
static pa_usec_t io_source_get_latency(struct userdata *u) {
|
|
|
|
|
pa_usec_t r = 0;
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_assert(u);
|
|
|
|
|
|
|
|
|
|
if (u->use_getispace) {
|
|
|
|
|
struct audio_buf_info info;
|
|
|
|
|
|
|
|
|
|
if (ioctl(u->fd, SNDCTL_DSP_GETISPACE, &info) < 0) {
|
|
|
|
|
pa_log_info("Device doesn't support SNDCTL_DSP_GETISPACE: %s", pa_cstrerror(errno));
|
|
|
|
|
u->use_getispace = 0;
|
|
|
|
|
} else
|
2008-08-19 22:39:54 +02:00
|
|
|
r = pa_bytes_to_usec((size_t) info.bytes, &u->source->sample_spec);
|
2004-09-16 00:05:56 +00:00
|
|
|
}
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void build_pollfd(struct userdata *u) {
|
|
|
|
|
struct pollfd *pollfd;
|
2004-09-16 00:05:56 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_assert(u);
|
|
|
|
|
pa_assert(u->fd >= 0);
|
|
|
|
|
|
|
|
|
|
if (u->rtpoll_item)
|
|
|
|
|
pa_rtpoll_item_free(u->rtpoll_item);
|
|
|
|
|
|
|
|
|
|
u->rtpoll_item = pa_rtpoll_item_new(u->rtpoll, PA_RTPOLL_NEVER, 1);
|
|
|
|
|
pollfd = pa_rtpoll_item_get_pollfd(u->rtpoll_item, NULL);
|
|
|
|
|
pollfd->fd = u->fd;
|
|
|
|
|
pollfd->events = 0;
|
|
|
|
|
pollfd->revents = 0;
|
2004-09-16 00:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
2009-05-26 22:30:36 +02:00
|
|
|
/* Called from IO context */
|
2018-02-19 16:48:19 +02:00
|
|
|
static void suspend(struct userdata *u) {
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_assert(u);
|
|
|
|
|
pa_assert(u->fd >= 0);
|
2006-01-27 16:25:31 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_log_info("Suspending...");
|
|
|
|
|
|
|
|
|
|
if (u->out_mmap_memblocks) {
|
|
|
|
|
unsigned i;
|
|
|
|
|
for (i = 0; i < u->out_nfrags; i++)
|
|
|
|
|
if (u->out_mmap_memblocks[i]) {
|
|
|
|
|
pa_memblock_unref_fixed(u->out_mmap_memblocks[i]);
|
|
|
|
|
u->out_mmap_memblocks[i] = NULL;
|
|
|
|
|
}
|
2006-01-27 16:25:31 +00:00
|
|
|
}
|
|
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
if (u->in_mmap_memblocks) {
|
|
|
|
|
unsigned i;
|
|
|
|
|
for (i = 0; i < u->in_nfrags; i++)
|
|
|
|
|
if (u->in_mmap_memblocks[i]) {
|
|
|
|
|
pa_memblock_unref_fixed(u->in_mmap_memblocks[i]);
|
|
|
|
|
u->in_mmap_memblocks[i] = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (u->in_mmap && u->in_mmap != MAP_FAILED) {
|
|
|
|
|
munmap(u->in_mmap, u->in_hwbuf_size);
|
|
|
|
|
u->in_mmap = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (u->out_mmap && u->out_mmap != MAP_FAILED) {
|
|
|
|
|
munmap(u->out_mmap, u->out_hwbuf_size);
|
|
|
|
|
u->out_mmap = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Let's suspend */
|
|
|
|
|
ioctl(u->fd, SNDCTL_DSP_SYNC, NULL);
|
|
|
|
|
pa_close(u->fd);
|
|
|
|
|
u->fd = -1;
|
|
|
|
|
|
|
|
|
|
if (u->rtpoll_item) {
|
|
|
|
|
pa_rtpoll_item_free(u->rtpoll_item);
|
|
|
|
|
u->rtpoll_item = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pa_log_info("Device suspended...");
|
2006-01-27 16:25:31 +00:00
|
|
|
}
|
|
|
|
|
|
2009-05-26 22:30:36 +02:00
|
|
|
/* Called from IO context */
|
2007-10-28 19:13:50 +00:00
|
|
|
static int unsuspend(struct userdata *u) {
|
|
|
|
|
int m;
|
|
|
|
|
pa_sample_spec ss, *ss_original;
|
|
|
|
|
int frag_size, in_frag_size, out_frag_size;
|
|
|
|
|
int in_nfrags, out_nfrags;
|
|
|
|
|
struct audio_buf_info info;
|
|
|
|
|
|
|
|
|
|
pa_assert(u);
|
|
|
|
|
pa_assert(u->fd < 0);
|
|
|
|
|
|
|
|
|
|
m = u->mode;
|
|
|
|
|
|
|
|
|
|
pa_log_info("Trying resume...");
|
2006-01-27 16:25:31 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
if ((u->fd = pa_oss_open(u->device_name, &m, NULL)) < 0) {
|
|
|
|
|
pa_log_warn("Resume failed, device busy (%s)", pa_cstrerror(errno));
|
2006-02-23 08:59:31 +00:00
|
|
|
return -1;
|
2008-08-19 22:39:54 +02:00
|
|
|
}
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2008-08-19 22:39:54 +02:00
|
|
|
if (m != u->mode) {
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_log_warn("Resume failed, couldn't open device with original access mode.");
|
|
|
|
|
goto fail;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (u->nfrags >= 2 && u->frag_size >= 1)
|
2009-01-22 01:15:49 +01:00
|
|
|
if (pa_oss_set_fragments(u->fd, u->nfrags, u->orig_frag_size) < 0) {
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_log_warn("Resume failed, couldn't set original fragment settings.");
|
|
|
|
|
goto fail;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ss = *(ss_original = u->sink ? &u->sink->sample_spec : &u->source->sample_spec);
|
|
|
|
|
if (pa_oss_auto_format(u->fd, &ss) < 0 || !pa_sample_spec_equal(&ss, ss_original)) {
|
|
|
|
|
pa_log_warn("Resume failed, couldn't set original sample format settings.");
|
|
|
|
|
goto fail;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ioctl(u->fd, SNDCTL_DSP_GETBLKSIZE, &frag_size) < 0) {
|
|
|
|
|
pa_log_warn("SNDCTL_DSP_GETBLKSIZE: %s", pa_cstrerror(errno));
|
|
|
|
|
goto fail;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
in_frag_size = out_frag_size = frag_size;
|
|
|
|
|
in_nfrags = out_nfrags = u->nfrags;
|
|
|
|
|
|
|
|
|
|
if (ioctl(u->fd, SNDCTL_DSP_GETISPACE, &info) >= 0) {
|
|
|
|
|
in_frag_size = info.fragsize;
|
|
|
|
|
in_nfrags = info.fragstotal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ioctl(u->fd, SNDCTL_DSP_GETOSPACE, &info) >= 0) {
|
|
|
|
|
out_frag_size = info.fragsize;
|
|
|
|
|
out_nfrags = info.fragstotal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((u->source && (in_frag_size != (int) u->in_fragment_size || in_nfrags != (int) u->in_nfrags)) ||
|
|
|
|
|
(u->sink && (out_frag_size != (int) u->out_fragment_size || out_nfrags != (int) u->out_nfrags))) {
|
|
|
|
|
pa_log_warn("Resume failed, input fragment settings don't match.");
|
|
|
|
|
goto fail;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (u->use_mmap) {
|
|
|
|
|
if (u->source) {
|
|
|
|
|
if ((u->in_mmap = mmap(NULL, u->in_hwbuf_size, PROT_READ, MAP_SHARED, u->fd, 0)) == MAP_FAILED) {
|
|
|
|
|
pa_log("Resume failed, mmap(): %s", pa_cstrerror(errno));
|
|
|
|
|
goto fail;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (u->sink) {
|
|
|
|
|
if ((u->out_mmap = mmap(NULL, u->out_hwbuf_size, PROT_WRITE, MAP_SHARED, u->fd, 0)) == MAP_FAILED) {
|
|
|
|
|
pa_log("Resume failed, mmap(): %s", pa_cstrerror(errno));
|
|
|
|
|
if (u->in_mmap && u->in_mmap != MAP_FAILED) {
|
|
|
|
|
munmap(u->in_mmap, u->in_hwbuf_size);
|
|
|
|
|
u->in_mmap = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
goto fail;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pa_silence_memory(u->out_mmap, u->out_hwbuf_size, &ss);
|
|
|
|
|
}
|
2006-02-23 08:59:31 +00:00
|
|
|
}
|
|
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
u->out_mmap_current = u->in_mmap_current = 0;
|
|
|
|
|
u->out_mmap_saved_nfrags = u->in_mmap_saved_nfrags = 0;
|
|
|
|
|
|
|
|
|
|
pa_assert(!u->rtpoll_item);
|
|
|
|
|
|
|
|
|
|
build_pollfd(u);
|
|
|
|
|
|
2009-05-26 22:30:36 +02:00
|
|
|
if (u->sink && u->sink->get_volume)
|
|
|
|
|
u->sink->get_volume(u->sink);
|
|
|
|
|
if (u->source && u->source->get_volume)
|
|
|
|
|
u->source->get_volume(u->source);
|
2007-10-28 19:13:50 +00:00
|
|
|
|
|
|
|
|
pa_log_info("Resumed successfully...");
|
|
|
|
|
|
2006-02-23 08:59:31 +00:00
|
|
|
return 0;
|
2007-10-28 19:13:50 +00:00
|
|
|
|
|
|
|
|
fail:
|
|
|
|
|
pa_close(u->fd);
|
|
|
|
|
u->fd = -1;
|
|
|
|
|
return -1;
|
2006-02-23 08:59:31 +00:00
|
|
|
}
|
|
|
|
|
|
2009-05-26 22:30:36 +02:00
|
|
|
/* Called from IO context */
|
2007-10-28 19:13:50 +00:00
|
|
|
static int sink_process_msg(pa_msgobject *o, int code, void *data, int64_t offset, pa_memchunk *chunk) {
|
|
|
|
|
struct userdata *u = PA_SINK(o)->userdata;
|
|
|
|
|
|
|
|
|
|
switch (code) {
|
|
|
|
|
|
|
|
|
|
case PA_SINK_MESSAGE_GET_LATENCY: {
|
|
|
|
|
pa_usec_t r = 0;
|
|
|
|
|
|
|
|
|
|
if (u->fd >= 0) {
|
|
|
|
|
if (u->use_mmap)
|
|
|
|
|
r = mmap_sink_get_latency(u);
|
|
|
|
|
else
|
|
|
|
|
r = io_sink_get_latency(u);
|
|
|
|
|
}
|
|
|
|
|
|
source/sink: Allow pa_{source, sink}_get_latency_within_thread() to return negative values
The reported latency of source or sink is based on measured initial conditions.
If the conditions contain an error, the estimated latency values may become negative.
This does not indicate that the latency is indeed negative but can be considered
merely an offset error. The current get_latency_in_thread() calls and the
implementations of the PA_{SINK,SOURCE}_MESSAGE_GET_LATENCY messages truncate negative
latencies because they do not make sense from a physical point of view. In fact,
the values are truncated twice, once in the message handler and a second time in
the pa_{source,sink}_get_latency_within_thread() call itself.
This leads to two problems for the latency controller within module-loopback:
- Truncating leads to discontinuities in the latency reports which then trigger
unwanted end to end latency corrections.
- If a large negative port latency offsets is set, the reported latency is always 0,
making it impossible to control the end to end latency at all.
This patch is a pre-condition for solving these problems.
It adds a new flag to pa_{sink,source}_get_latency_within_thread() to allow
negative return values. Truncating is also removed in all implementations of the
PA_{SINK,SOURCE}_MESSAGE_GET_LATENCY message handlers. The allow_negative flag
is set to false for all calls of pa_{sink,source}_get_latency_within_thread()
except when used within PA_{SINK,SOURCE}_MESSAGE_GET_LATENCY. This means that the
original behavior is not altered in most cases. Only if a positive latency offset
is set and the message returns a negative value, the reported latency is smaller
because the values are not truncated twice.
Additionally let PA_SOURCE_MESSAGE_GET_LATENCY return -pa_sink_get_latency_within_thread()
for monitor sources because the source gets the data before it is played.
2017-04-17 19:50:10 +02:00
|
|
|
*((int64_t*) data) = (int64_t)r;
|
2007-10-28 19:13:50 +00:00
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2018-03-13 19:40:38 +02:00
|
|
|
}
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2018-03-13 19:40:38 +02:00
|
|
|
return pa_sink_process_msg(o, code, data, offset, chunk);
|
|
|
|
|
}
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2018-03-13 19:40:38 +02:00
|
|
|
/* Called from the IO thread. */
|
|
|
|
|
static int sink_set_state_in_io_thread_cb(pa_sink *s, pa_sink_state_t new_state) {
|
|
|
|
|
struct userdata *u;
|
|
|
|
|
bool do_trigger = false;
|
|
|
|
|
bool quick = true;
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2018-03-13 19:40:38 +02:00
|
|
|
pa_assert(s);
|
|
|
|
|
pa_assert_se(u = s->userdata);
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2018-03-13 19:40:38 +02:00
|
|
|
switch (new_state) {
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2018-03-13 19:40:38 +02:00
|
|
|
case PA_SINK_SUSPENDED:
|
|
|
|
|
pa_assert(PA_SINK_IS_OPENED(u->sink->thread_info.state));
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2018-03-13 19:40:38 +02:00
|
|
|
if (!u->source || u->source_suspended)
|
|
|
|
|
suspend(u);
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2018-03-13 19:40:38 +02:00
|
|
|
do_trigger = true;
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2018-03-13 19:40:38 +02:00
|
|
|
u->sink_suspended = true;
|
|
|
|
|
break;
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2018-03-13 19:40:38 +02:00
|
|
|
case PA_SINK_IDLE:
|
|
|
|
|
case PA_SINK_RUNNING:
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2018-03-13 19:40:38 +02:00
|
|
|
if (u->sink->thread_info.state == PA_SINK_INIT) {
|
|
|
|
|
do_trigger = true;
|
|
|
|
|
quick = u->source && PA_SOURCE_IS_OPENED(u->source->thread_info.state);
|
|
|
|
|
}
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2018-03-13 19:40:38 +02:00
|
|
|
if (u->sink->thread_info.state == PA_SINK_SUSPENDED) {
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2018-03-13 19:40:38 +02:00
|
|
|
if (!u->source || u->source_suspended) {
|
|
|
|
|
if (unsuspend(u) < 0)
|
|
|
|
|
return -1;
|
|
|
|
|
quick = false;
|
|
|
|
|
}
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2018-03-13 19:40:38 +02:00
|
|
|
do_trigger = true;
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2018-03-13 19:40:38 +02:00
|
|
|
u->out_mmap_current = 0;
|
|
|
|
|
u->out_mmap_saved_nfrags = 0;
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2018-03-13 19:40:38 +02:00
|
|
|
u->sink_suspended = false;
|
2007-10-28 19:13:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
2018-03-13 19:40:38 +02:00
|
|
|
|
|
|
|
|
case PA_SINK_INVALID_STATE:
|
|
|
|
|
case PA_SINK_UNLINKED:
|
|
|
|
|
case PA_SINK_INIT:
|
|
|
|
|
;
|
2006-02-23 08:59:31 +00:00
|
|
|
}
|
|
|
|
|
|
oss: don't fail resume if trigger() fails
The previous code made the SET_STATE message fail if trigger() failed.
However, trigger() was called after pa_sink/source_process_msg(), which
meant that the main thread that sent the SET_STATE thought that resuming
failed, but nothing was undone in the IO thread, so in the IO thread
things seemed as if the sink/source was successfully resumed. (I don't
use OSS myself, so I don't know what kind of practical problems this
could cause).
Unless some complex undo logic is implemented, I believe it's best to
ignore all failures in trigger(). Most error cases were already ignored,
and the only one that wasn't ignored doesn't seem too serious.
I also moved trigger() to happen before pa_sink/source_process_msg(),
which made it necessary to add new state parameters to trigger(). The
reason for this move is that I want to move the SET_STATE handler code
into a separate callback, and if things are done both before and after
pa_sink/source_process_msg(), that makes things more complicated.
The previous code checked the return value of
pa_sink/source_process_msg() before calling trigger(), but that was
unnecessary, since pa_sink/source_process_msg() never fails when
processing the SET_STATE messages.
2018-03-13 19:40:37 +02:00
|
|
|
if (do_trigger)
|
|
|
|
|
trigger(u, new_state, u->source ? u->source->thread_info.state : PA_SOURCE_INVALID_STATE, quick);
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2018-03-13 19:40:38 +02:00
|
|
|
return 0;
|
2006-02-23 08:59:31 +00:00
|
|
|
}
|
|
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
static int source_process_msg(pa_msgobject *o, int code, void *data, int64_t offset, pa_memchunk *chunk) {
|
|
|
|
|
struct userdata *u = PA_SOURCE(o)->userdata;
|
|
|
|
|
|
|
|
|
|
switch (code) {
|
|
|
|
|
|
|
|
|
|
case PA_SOURCE_MESSAGE_GET_LATENCY: {
|
|
|
|
|
pa_usec_t r = 0;
|
|
|
|
|
|
|
|
|
|
if (u->fd >= 0) {
|
|
|
|
|
if (u->use_mmap)
|
|
|
|
|
r = mmap_source_get_latency(u);
|
|
|
|
|
else
|
|
|
|
|
r = io_source_get_latency(u);
|
|
|
|
|
}
|
|
|
|
|
|
source/sink: Allow pa_{source, sink}_get_latency_within_thread() to return negative values
The reported latency of source or sink is based on measured initial conditions.
If the conditions contain an error, the estimated latency values may become negative.
This does not indicate that the latency is indeed negative but can be considered
merely an offset error. The current get_latency_in_thread() calls and the
implementations of the PA_{SINK,SOURCE}_MESSAGE_GET_LATENCY messages truncate negative
latencies because they do not make sense from a physical point of view. In fact,
the values are truncated twice, once in the message handler and a second time in
the pa_{source,sink}_get_latency_within_thread() call itself.
This leads to two problems for the latency controller within module-loopback:
- Truncating leads to discontinuities in the latency reports which then trigger
unwanted end to end latency corrections.
- If a large negative port latency offsets is set, the reported latency is always 0,
making it impossible to control the end to end latency at all.
This patch is a pre-condition for solving these problems.
It adds a new flag to pa_{sink,source}_get_latency_within_thread() to allow
negative return values. Truncating is also removed in all implementations of the
PA_{SINK,SOURCE}_MESSAGE_GET_LATENCY message handlers. The allow_negative flag
is set to false for all calls of pa_{sink,source}_get_latency_within_thread()
except when used within PA_{SINK,SOURCE}_MESSAGE_GET_LATENCY. This means that the
original behavior is not altered in most cases. Only if a positive latency offset
is set and the message returns a negative value, the reported latency is smaller
because the values are not truncated twice.
Additionally let PA_SOURCE_MESSAGE_GET_LATENCY return -pa_sink_get_latency_within_thread()
for monitor sources because the source gets the data before it is played.
2017-04-17 19:50:10 +02:00
|
|
|
*((int64_t*) data) = (int64_t)r;
|
2007-10-28 19:13:50 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
2018-03-13 19:40:38 +02:00
|
|
|
}
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2018-03-13 19:40:38 +02:00
|
|
|
return pa_source_process_msg(o, code, data, offset, chunk);
|
|
|
|
|
}
|
oss: don't fail resume if trigger() fails
The previous code made the SET_STATE message fail if trigger() failed.
However, trigger() was called after pa_sink/source_process_msg(), which
meant that the main thread that sent the SET_STATE thought that resuming
failed, but nothing was undone in the IO thread, so in the IO thread
things seemed as if the sink/source was successfully resumed. (I don't
use OSS myself, so I don't know what kind of practical problems this
could cause).
Unless some complex undo logic is implemented, I believe it's best to
ignore all failures in trigger(). Most error cases were already ignored,
and the only one that wasn't ignored doesn't seem too serious.
I also moved trigger() to happen before pa_sink/source_process_msg(),
which made it necessary to add new state parameters to trigger(). The
reason for this move is that I want to move the SET_STATE handler code
into a separate callback, and if things are done both before and after
pa_sink/source_process_msg(), that makes things more complicated.
The previous code checked the return value of
pa_sink/source_process_msg() before calling trigger(), but that was
unnecessary, since pa_sink/source_process_msg() never fails when
processing the SET_STATE messages.
2018-03-13 19:40:37 +02:00
|
|
|
|
2018-03-13 19:40:38 +02:00
|
|
|
/* Called from the IO thread. */
|
|
|
|
|
static int source_set_state_in_io_thread_cb(pa_source *s, pa_source_state_t new_state) {
|
|
|
|
|
struct userdata *u;
|
|
|
|
|
bool do_trigger = false;
|
|
|
|
|
bool quick = true;
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2018-03-13 19:40:38 +02:00
|
|
|
pa_assert(s);
|
|
|
|
|
pa_assert_se(u = s->userdata);
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2018-03-13 19:40:38 +02:00
|
|
|
switch (new_state) {
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2018-03-13 19:40:38 +02:00
|
|
|
case PA_SOURCE_SUSPENDED:
|
|
|
|
|
pa_assert(PA_SOURCE_IS_OPENED(u->source->thread_info.state));
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2018-03-13 19:40:38 +02:00
|
|
|
if (!u->sink || u->sink_suspended)
|
|
|
|
|
suspend(u);
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2018-03-13 19:40:38 +02:00
|
|
|
do_trigger = true;
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2018-03-13 19:40:38 +02:00
|
|
|
u->source_suspended = true;
|
|
|
|
|
break;
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2018-03-13 19:40:38 +02:00
|
|
|
case PA_SOURCE_IDLE:
|
|
|
|
|
case PA_SOURCE_RUNNING:
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2018-03-13 19:40:38 +02:00
|
|
|
if (u->source->thread_info.state == PA_SOURCE_INIT) {
|
|
|
|
|
do_trigger = true;
|
|
|
|
|
quick = u->sink && PA_SINK_IS_OPENED(u->sink->thread_info.state);
|
|
|
|
|
}
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2018-03-13 19:40:38 +02:00
|
|
|
if (u->source->thread_info.state == PA_SOURCE_SUSPENDED) {
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2018-03-13 19:40:38 +02:00
|
|
|
if (!u->sink || u->sink_suspended) {
|
|
|
|
|
if (unsuspend(u) < 0)
|
|
|
|
|
return -1;
|
|
|
|
|
quick = false;
|
|
|
|
|
}
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2018-03-13 19:40:38 +02:00
|
|
|
do_trigger = true;
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2018-03-13 19:40:38 +02:00
|
|
|
u->in_mmap_current = 0;
|
|
|
|
|
u->in_mmap_saved_nfrags = 0;
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2018-03-13 19:40:38 +02:00
|
|
|
u->source_suspended = false;
|
2007-10-28 19:13:50 +00:00
|
|
|
}
|
|
|
|
|
break;
|
2018-03-13 19:40:38 +02:00
|
|
|
|
|
|
|
|
case PA_SOURCE_UNLINKED:
|
|
|
|
|
case PA_SOURCE_INIT:
|
|
|
|
|
case PA_SOURCE_INVALID_STATE:
|
|
|
|
|
;
|
2006-01-27 16:25:31 +00:00
|
|
|
}
|
|
|
|
|
|
oss: don't fail resume if trigger() fails
The previous code made the SET_STATE message fail if trigger() failed.
However, trigger() was called after pa_sink/source_process_msg(), which
meant that the main thread that sent the SET_STATE thought that resuming
failed, but nothing was undone in the IO thread, so in the IO thread
things seemed as if the sink/source was successfully resumed. (I don't
use OSS myself, so I don't know what kind of practical problems this
could cause).
Unless some complex undo logic is implemented, I believe it's best to
ignore all failures in trigger(). Most error cases were already ignored,
and the only one that wasn't ignored doesn't seem too serious.
I also moved trigger() to happen before pa_sink/source_process_msg(),
which made it necessary to add new state parameters to trigger(). The
reason for this move is that I want to move the SET_STATE handler code
into a separate callback, and if things are done both before and after
pa_sink/source_process_msg(), that makes things more complicated.
The previous code checked the return value of
pa_sink/source_process_msg() before calling trigger(), but that was
unnecessary, since pa_sink/source_process_msg() never fails when
processing the SET_STATE messages.
2018-03-13 19:40:37 +02:00
|
|
|
if (do_trigger)
|
|
|
|
|
trigger(u, u->sink ? u->sink->thread_info.state : PA_SINK_INVALID_STATE, new_state, quick);
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2018-03-13 19:40:38 +02:00
|
|
|
return 0;
|
2007-10-28 19:13:50 +00:00
|
|
|
}
|
|
|
|
|
|
2009-01-27 04:39:07 +01:00
|
|
|
static void sink_get_volume(pa_sink *s) {
|
2007-10-28 19:13:50 +00:00
|
|
|
struct userdata *u;
|
|
|
|
|
|
|
|
|
|
pa_assert_se(u = s->userdata);
|
|
|
|
|
|
|
|
|
|
pa_assert(u->mixer_devmask & (SOUND_MASK_VOLUME|SOUND_MASK_PCM));
|
|
|
|
|
|
|
|
|
|
if (u->mixer_devmask & SOUND_MASK_VOLUME)
|
2009-08-19 02:55:02 +02:00
|
|
|
if (pa_oss_get_volume(u->mixer_fd, SOUND_MIXER_READ_VOLUME, &s->sample_spec, &s->real_volume) >= 0)
|
2009-01-27 04:39:07 +01:00
|
|
|
return;
|
2007-10-28 19:13:50 +00:00
|
|
|
|
|
|
|
|
if (u->mixer_devmask & SOUND_MASK_PCM)
|
2009-08-19 02:55:02 +02:00
|
|
|
if (pa_oss_get_volume(u->mixer_fd, SOUND_MIXER_READ_PCM, &s->sample_spec, &s->real_volume) >= 0)
|
2009-01-27 04:39:07 +01:00
|
|
|
return;
|
2007-10-28 19:13:50 +00:00
|
|
|
|
|
|
|
|
pa_log_info("Device doesn't support reading mixer settings: %s", pa_cstrerror(errno));
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-27 04:39:07 +01:00
|
|
|
static void sink_set_volume(pa_sink *s) {
|
2007-10-28 19:13:50 +00:00
|
|
|
struct userdata *u;
|
|
|
|
|
|
|
|
|
|
pa_assert_se(u = s->userdata);
|
|
|
|
|
|
|
|
|
|
pa_assert(u->mixer_devmask & (SOUND_MASK_VOLUME|SOUND_MASK_PCM));
|
|
|
|
|
|
|
|
|
|
if (u->mixer_devmask & SOUND_MASK_VOLUME)
|
2009-08-19 02:55:02 +02:00
|
|
|
if (pa_oss_set_volume(u->mixer_fd, SOUND_MIXER_WRITE_VOLUME, &s->sample_spec, &s->real_volume) >= 0)
|
2009-01-27 04:39:07 +01:00
|
|
|
return;
|
2007-10-28 19:13:50 +00:00
|
|
|
|
|
|
|
|
if (u->mixer_devmask & SOUND_MASK_PCM)
|
2009-08-19 02:55:02 +02:00
|
|
|
if (pa_oss_get_volume(u->mixer_fd, SOUND_MIXER_WRITE_PCM, &s->sample_spec, &s->real_volume) >= 0)
|
2009-01-27 04:39:07 +01:00
|
|
|
return;
|
2007-10-28 19:13:50 +00:00
|
|
|
|
|
|
|
|
pa_log_info("Device doesn't support writing mixer settings: %s", pa_cstrerror(errno));
|
2006-01-27 16:25:31 +00:00
|
|
|
}
|
|
|
|
|
|
2009-01-27 04:39:07 +01:00
|
|
|
static void source_get_volume(pa_source *s) {
|
2007-10-28 19:13:50 +00:00
|
|
|
struct userdata *u;
|
|
|
|
|
|
|
|
|
|
pa_assert_se(u = s->userdata);
|
|
|
|
|
|
|
|
|
|
pa_assert(u->mixer_devmask & (SOUND_MASK_IGAIN|SOUND_MASK_RECLEV));
|
|
|
|
|
|
|
|
|
|
if (u->mixer_devmask & SOUND_MASK_IGAIN)
|
2011-05-17 22:31:10 +01:00
|
|
|
if (pa_oss_get_volume(u->mixer_fd, SOUND_MIXER_READ_IGAIN, &s->sample_spec, &s->real_volume) >= 0)
|
2009-01-27 04:39:07 +01:00
|
|
|
return;
|
2007-10-28 19:13:50 +00:00
|
|
|
|
|
|
|
|
if (u->mixer_devmask & SOUND_MASK_RECLEV)
|
2011-05-17 22:31:10 +01:00
|
|
|
if (pa_oss_get_volume(u->mixer_fd, SOUND_MIXER_READ_RECLEV, &s->sample_spec, &s->real_volume) >= 0)
|
2009-01-27 04:39:07 +01:00
|
|
|
return;
|
2007-10-28 19:13:50 +00:00
|
|
|
|
|
|
|
|
pa_log_info("Device doesn't support reading mixer settings: %s", pa_cstrerror(errno));
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-27 04:39:07 +01:00
|
|
|
static void source_set_volume(pa_source *s) {
|
2007-10-28 19:13:50 +00:00
|
|
|
struct userdata *u;
|
|
|
|
|
|
|
|
|
|
pa_assert_se(u = s->userdata);
|
|
|
|
|
|
|
|
|
|
pa_assert(u->mixer_devmask & (SOUND_MASK_IGAIN|SOUND_MASK_RECLEV));
|
|
|
|
|
|
|
|
|
|
if (u->mixer_devmask & SOUND_MASK_IGAIN)
|
2011-05-17 22:31:10 +01:00
|
|
|
if (pa_oss_set_volume(u->mixer_fd, SOUND_MIXER_WRITE_IGAIN, &s->sample_spec, &s->real_volume) >= 0)
|
2009-01-27 04:39:07 +01:00
|
|
|
return;
|
2007-10-28 19:13:50 +00:00
|
|
|
|
|
|
|
|
if (u->mixer_devmask & SOUND_MASK_RECLEV)
|
2011-05-17 22:31:10 +01:00
|
|
|
if (pa_oss_get_volume(u->mixer_fd, SOUND_MIXER_WRITE_RECLEV, &s->sample_spec, &s->real_volume) >= 0)
|
2009-01-27 04:39:07 +01:00
|
|
|
return;
|
2007-10-28 19:13:50 +00:00
|
|
|
|
|
|
|
|
pa_log_info("Device doesn't support writing mixer settings: %s", pa_cstrerror(errno));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void thread_func(void *userdata) {
|
|
|
|
|
struct userdata *u = userdata;
|
|
|
|
|
int write_type = 0, read_type = 0;
|
2008-08-19 22:39:54 +02:00
|
|
|
short revents = 0;
|
2007-10-28 19:13:50 +00:00
|
|
|
|
|
|
|
|
pa_assert(u);
|
|
|
|
|
|
|
|
|
|
pa_log_debug("Thread starting up");
|
|
|
|
|
|
2007-11-01 02:58:26 +00:00
|
|
|
if (u->core->realtime_scheduling)
|
|
|
|
|
pa_make_realtime(u->core->realtime_priority);
|
2007-10-28 19:13:50 +00:00
|
|
|
|
|
|
|
|
pa_thread_mq_install(&u->thread_mq);
|
|
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
/* pa_log("loop"); */
|
|
|
|
|
|
2012-11-16 23:09:15 +05:30
|
|
|
if (PA_UNLIKELY(u->sink && u->sink->thread_info.rewind_requested))
|
2012-08-30 16:50:13 +03:00
|
|
|
pa_sink_process_rewind(u->sink, 0);
|
2008-06-27 21:57:54 +02:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
/* Render some data and write it to the dsp */
|
|
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
if (u->sink && PA_SINK_IS_OPENED(u->sink->thread_info.state) && ((revents & POLLOUT) || u->use_mmap || u->use_getospace)) {
|
2007-10-28 19:13:50 +00:00
|
|
|
|
|
|
|
|
if (u->use_mmap) {
|
|
|
|
|
|
|
|
|
|
if ((ret = mmap_write(u)) < 0)
|
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
|
|
revents &= ~POLLOUT;
|
|
|
|
|
|
|
|
|
|
if (ret > 0)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
ssize_t l;
|
2013-06-27 19:28:09 +02:00
|
|
|
bool loop = false, work_done = false;
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2008-08-20 03:33:06 +03:00
|
|
|
l = (ssize_t) u->out_fragment_size;
|
2007-10-28 19:13:50 +00:00
|
|
|
|
|
|
|
|
if (u->use_getospace) {
|
|
|
|
|
audio_buf_info info;
|
|
|
|
|
|
|
|
|
|
if (ioctl(u->fd, SNDCTL_DSP_GETOSPACE, &info) < 0) {
|
|
|
|
|
pa_log_info("Device doesn't support SNDCTL_DSP_GETOSPACE: %s", pa_cstrerror(errno));
|
2013-06-27 19:28:09 +02:00
|
|
|
u->use_getospace = false;
|
2007-10-28 19:13:50 +00:00
|
|
|
} else {
|
|
|
|
|
l = info.bytes;
|
|
|
|
|
|
|
|
|
|
/* We loop only if GETOSPACE worked and we
|
|
|
|
|
* actually *know* that we can write more than
|
|
|
|
|
* one fragment at a time */
|
2013-06-27 19:28:09 +02:00
|
|
|
loop = true;
|
2007-10-28 19:13:50 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Round down to multiples of the fragment size,
|
|
|
|
|
* because OSS needs that (at least some versions
|
|
|
|
|
* do) */
|
2008-08-20 03:33:06 +03:00
|
|
|
l = (l/(ssize_t) u->out_fragment_size) * (ssize_t) u->out_fragment_size;
|
2007-10-28 19:13:50 +00:00
|
|
|
|
|
|
|
|
/* Hmm, so poll() signalled us that we can read
|
|
|
|
|
* something, but GETOSPACE told us there was nothing?
|
|
|
|
|
* Hmm, make the best of it, try to read some data, to
|
|
|
|
|
* avoid spinning forever. */
|
|
|
|
|
if (l <= 0 && (revents & POLLOUT)) {
|
2008-08-20 03:33:06 +03:00
|
|
|
l = (ssize_t) u->out_fragment_size;
|
2013-06-27 19:28:09 +02:00
|
|
|
loop = false;
|
2007-10-28 19:13:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while (l > 0) {
|
|
|
|
|
void *p;
|
|
|
|
|
ssize_t t;
|
|
|
|
|
|
|
|
|
|
if (u->memchunk.length <= 0)
|
2008-08-19 22:39:54 +02:00
|
|
|
pa_sink_render(u->sink, (size_t) l, &u->memchunk);
|
2007-10-28 19:13:50 +00:00
|
|
|
|
|
|
|
|
pa_assert(u->memchunk.length > 0);
|
|
|
|
|
|
|
|
|
|
p = pa_memblock_acquire(u->memchunk.memblock);
|
|
|
|
|
t = pa_write(u->fd, (uint8_t*) p + u->memchunk.index, u->memchunk.length, &write_type);
|
|
|
|
|
pa_memblock_release(u->memchunk.memblock);
|
|
|
|
|
|
|
|
|
|
/* pa_log("wrote %i bytes of %u", t, l); */
|
|
|
|
|
|
|
|
|
|
pa_assert(t != 0);
|
|
|
|
|
|
|
|
|
|
if (t < 0) {
|
|
|
|
|
|
|
|
|
|
if (errno == EINTR)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
else if (errno == EAGAIN) {
|
|
|
|
|
pa_log_debug("EAGAIN");
|
|
|
|
|
|
|
|
|
|
revents &= ~POLLOUT;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
pa_log("Failed to write data to DSP: %s", pa_cstrerror(errno));
|
|
|
|
|
goto fail;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
2008-08-19 22:39:54 +02:00
|
|
|
u->memchunk.index += (size_t) t;
|
|
|
|
|
u->memchunk.length -= (size_t) t;
|
2007-10-28 19:13:50 +00:00
|
|
|
|
|
|
|
|
if (u->memchunk.length <= 0) {
|
|
|
|
|
pa_memblock_unref(u->memchunk.memblock);
|
|
|
|
|
pa_memchunk_reset(&u->memchunk);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
l -= t;
|
|
|
|
|
|
|
|
|
|
revents &= ~POLLOUT;
|
2013-06-27 19:28:09 +02:00
|
|
|
work_done = true;
|
2007-10-28 19:13:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!loop)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (work_done)
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Try to read some data and pass it on to the source driver. */
|
|
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
if (u->source && PA_SOURCE_IS_OPENED(u->source->thread_info.state) && ((revents & POLLIN) || u->use_mmap || u->use_getispace)) {
|
2007-10-28 19:13:50 +00:00
|
|
|
|
|
|
|
|
if (u->use_mmap) {
|
|
|
|
|
|
|
|
|
|
if ((ret = mmap_read(u)) < 0)
|
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
|
|
revents &= ~POLLIN;
|
|
|
|
|
|
|
|
|
|
if (ret > 0)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
void *p;
|
|
|
|
|
ssize_t l;
|
|
|
|
|
pa_memchunk memchunk;
|
2013-06-27 19:28:09 +02:00
|
|
|
bool loop = false, work_done = false;
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2008-08-20 03:33:06 +03:00
|
|
|
l = (ssize_t) u->in_fragment_size;
|
2007-10-28 19:13:50 +00:00
|
|
|
|
|
|
|
|
if (u->use_getispace) {
|
|
|
|
|
audio_buf_info info;
|
|
|
|
|
|
|
|
|
|
if (ioctl(u->fd, SNDCTL_DSP_GETISPACE, &info) < 0) {
|
|
|
|
|
pa_log_info("Device doesn't support SNDCTL_DSP_GETISPACE: %s", pa_cstrerror(errno));
|
2013-06-27 19:28:09 +02:00
|
|
|
u->use_getispace = false;
|
2007-10-28 19:13:50 +00:00
|
|
|
} else {
|
|
|
|
|
l = info.bytes;
|
2013-06-27 19:28:09 +02:00
|
|
|
loop = true;
|
2007-10-28 19:13:50 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-08-20 03:33:06 +03:00
|
|
|
l = (l/(ssize_t) u->in_fragment_size) * (ssize_t) u->in_fragment_size;
|
2007-10-28 19:13:50 +00:00
|
|
|
|
|
|
|
|
if (l <= 0 && (revents & POLLIN)) {
|
2008-08-20 03:33:06 +03:00
|
|
|
l = (ssize_t) u->in_fragment_size;
|
2013-06-27 19:28:09 +02:00
|
|
|
loop = false;
|
2007-10-28 19:13:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while (l > 0) {
|
2008-08-19 22:39:54 +02:00
|
|
|
ssize_t t;
|
|
|
|
|
size_t k;
|
2007-10-28 19:13:50 +00:00
|
|
|
|
|
|
|
|
pa_assert(l > 0);
|
|
|
|
|
|
|
|
|
|
memchunk.memblock = pa_memblock_new(u->core->mempool, (size_t) -1);
|
|
|
|
|
|
|
|
|
|
k = pa_memblock_get_length(memchunk.memblock);
|
|
|
|
|
|
2008-08-19 22:39:54 +02:00
|
|
|
if (k > (size_t) l)
|
|
|
|
|
k = (size_t) l;
|
2007-10-28 19:13:50 +00:00
|
|
|
|
|
|
|
|
k = (k/u->frame_size)*u->frame_size;
|
|
|
|
|
|
|
|
|
|
p = pa_memblock_acquire(memchunk.memblock);
|
|
|
|
|
t = pa_read(u->fd, p, k, &read_type);
|
|
|
|
|
pa_memblock_release(memchunk.memblock);
|
|
|
|
|
|
|
|
|
|
pa_assert(t != 0); /* EOF cannot happen */
|
|
|
|
|
|
|
|
|
|
/* pa_log("read %i bytes of %u", t, l); */
|
|
|
|
|
|
|
|
|
|
if (t < 0) {
|
|
|
|
|
pa_memblock_unref(memchunk.memblock);
|
|
|
|
|
|
|
|
|
|
if (errno == EINTR)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
else if (errno == EAGAIN) {
|
|
|
|
|
pa_log_debug("EAGAIN");
|
|
|
|
|
|
|
|
|
|
revents &= ~POLLIN;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
pa_log("Failed to read data from DSP: %s", pa_cstrerror(errno));
|
|
|
|
|
goto fail;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
memchunk.index = 0;
|
2008-08-19 22:39:54 +02:00
|
|
|
memchunk.length = (size_t) t;
|
2007-10-28 19:13:50 +00:00
|
|
|
|
|
|
|
|
pa_source_post(u->source, &memchunk);
|
|
|
|
|
pa_memblock_unref(memchunk.memblock);
|
|
|
|
|
|
|
|
|
|
l -= t;
|
|
|
|
|
|
|
|
|
|
revents &= ~POLLIN;
|
2013-06-27 19:28:09 +02:00
|
|
|
work_done = true;
|
2007-10-28 19:13:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!loop)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (work_done)
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* pa_log("loop2 revents=%i", revents); */
|
|
|
|
|
|
|
|
|
|
if (u->rtpoll_item) {
|
|
|
|
|
struct pollfd *pollfd;
|
|
|
|
|
|
|
|
|
|
pa_assert(u->fd >= 0);
|
|
|
|
|
|
|
|
|
|
pollfd = pa_rtpoll_item_get_pollfd(u->rtpoll_item, NULL);
|
2008-08-19 22:39:54 +02:00
|
|
|
pollfd->events = (short)
|
|
|
|
|
(((u->source && PA_SOURCE_IS_OPENED(u->source->thread_info.state)) ? POLLIN : 0) |
|
|
|
|
|
((u->sink && PA_SINK_IS_OPENED(u->sink->thread_info.state)) ? POLLOUT : 0));
|
2007-10-28 19:13:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Hmm, nothing to do. Let's sleep */
|
2014-10-28 13:46:37 +01:00
|
|
|
if ((ret = pa_rtpoll_run(u->rtpoll)) < 0)
|
2007-10-28 19:13:50 +00:00
|
|
|
goto fail;
|
|
|
|
|
|
|
|
|
|
if (ret == 0)
|
|
|
|
|
goto finish;
|
|
|
|
|
|
|
|
|
|
if (u->rtpoll_item) {
|
|
|
|
|
struct pollfd *pollfd;
|
|
|
|
|
|
|
|
|
|
pollfd = pa_rtpoll_item_get_pollfd(u->rtpoll_item, NULL);
|
|
|
|
|
|
|
|
|
|
if (pollfd->revents & ~(POLLOUT|POLLIN)) {
|
|
|
|
|
pa_log("DSP shutdown.");
|
|
|
|
|
goto fail;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
revents = pollfd->revents;
|
|
|
|
|
} else
|
|
|
|
|
revents = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fail:
|
|
|
|
|
/* If this was no regular exit from the loop we have to continue
|
|
|
|
|
* processing messages until we received PA_MESSAGE_SHUTDOWN */
|
|
|
|
|
pa_asyncmsgq_post(u->thread_mq.outq, PA_MSGOBJECT(u->core), PA_CORE_MESSAGE_UNLOAD_MODULE, u->module, 0, NULL, NULL);
|
|
|
|
|
pa_asyncmsgq_wait_for(u->thread_mq.inq, PA_MESSAGE_SHUTDOWN);
|
|
|
|
|
|
|
|
|
|
finish:
|
|
|
|
|
pa_log_debug("Thread shutting down");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int pa__init(pa_module*m) {
|
|
|
|
|
|
2004-06-15 00:29:01 +00:00
|
|
|
struct audio_buf_info info;
|
2004-06-14 22:47:12 +00:00
|
|
|
struct userdata *u = NULL;
|
2007-10-28 19:13:50 +00:00
|
|
|
const char *dev;
|
2004-06-14 22:47:12 +00:00
|
|
|
int fd = -1;
|
2009-01-22 01:15:49 +01:00
|
|
|
int nfrags, orig_frag_size, frag_size;
|
2007-10-28 19:13:50 +00:00
|
|
|
int mode, caps;
|
2013-06-27 19:28:09 +02:00
|
|
|
bool record = true, playback = true, use_mmap = true;
|
2006-01-11 01:17:39 +00:00
|
|
|
pa_sample_spec ss;
|
2006-04-26 15:40:14 +00:00
|
|
|
pa_channel_map map;
|
2006-01-11 01:17:39 +00:00
|
|
|
pa_modargs *ma = NULL;
|
2008-05-15 23:34:41 +00:00
|
|
|
char hwdesc[64];
|
2006-08-12 16:26:59 +00:00
|
|
|
const char *name;
|
2013-06-27 19:28:09 +02:00
|
|
|
bool namereg_fail;
|
2008-05-15 23:34:41 +00:00
|
|
|
pa_sink_new_data sink_new_data;
|
|
|
|
|
pa_source_new_data source_new_data;
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_assert(m);
|
2004-06-14 22:47:12 +00:00
|
|
|
|
2004-07-11 23:21:32 +00:00
|
|
|
if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_log("Failed to parse module arguments.");
|
2004-07-11 23:21:32 +00:00
|
|
|
goto fail;
|
|
|
|
|
}
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2004-09-04 00:27:36 +00:00
|
|
|
if (pa_modargs_get_value_boolean(ma, "record", &record) < 0 || pa_modargs_get_value_boolean(ma, "playback", &playback) < 0) {
|
2007-11-21 01:21:53 +00:00
|
|
|
pa_log("record= and playback= expect boolean argument.");
|
2004-07-11 23:21:32 +00:00
|
|
|
goto fail;
|
2004-06-14 22:47:12 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-04 00:27:36 +00:00
|
|
|
if (!playback && !record) {
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_log("Neither playback nor record enabled for device.");
|
2004-07-11 23:21:32 +00:00
|
|
|
goto fail;
|
2004-06-14 22:47:12 +00:00
|
|
|
}
|
2004-06-15 15:18:33 +00:00
|
|
|
|
2017-03-07 21:41:56 +01:00
|
|
|
mode = (playback && record) ? O_RDWR : (playback ? O_WRONLY : O_RDONLY);
|
2006-04-10 19:42:44 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
ss = m->core->default_sample_spec;
|
2009-02-21 16:32:42 +01:00
|
|
|
map = m->core->default_channel_map;
|
2006-05-17 13:09:46 +00:00
|
|
|
if (pa_modargs_get_sample_spec_and_channel_map(ma, &ss, &map, PA_CHANNEL_MAP_OSS) < 0) {
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_log("Failed to parse sample specification or channel map");
|
2004-07-16 17:51:53 +00:00
|
|
|
goto fail;
|
|
|
|
|
}
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2008-08-19 22:39:54 +02:00
|
|
|
nfrags = (int) m->core->default_n_fragments;
|
|
|
|
|
frag_size = (int) pa_usec_to_bytes(m->core->default_fragment_size_msec*1000, &ss);
|
2007-10-28 19:13:50 +00:00
|
|
|
if (frag_size <= 0)
|
2008-08-19 22:39:54 +02:00
|
|
|
frag_size = (int) pa_frame_size(&ss);
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2006-05-13 21:20:34 +00:00
|
|
|
if (pa_modargs_get_value_s32(ma, "fragments", &nfrags) < 0 || pa_modargs_get_value_s32(ma, "fragment_size", &frag_size) < 0) {
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_log("Failed to parse fragments arguments");
|
2006-05-13 21:20:34 +00:00
|
|
|
goto fail;
|
|
|
|
|
}
|
|
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
if (pa_modargs_get_value_boolean(ma, "mmap", &use_mmap) < 0) {
|
|
|
|
|
pa_log("Failed to parse mmap argument.");
|
2004-07-11 23:21:32 +00:00
|
|
|
goto fail;
|
2007-10-28 19:13:50 +00:00
|
|
|
}
|
2004-07-11 23:21:32 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
if ((fd = pa_oss_open(dev = pa_modargs_get_value(ma, "device", DEFAULT_DEVICE), &mode, &caps)) < 0)
|
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
|
|
if (use_mmap && (!(caps & DSP_CAP_MMAP) || !(caps & DSP_CAP_TRIGGER))) {
|
|
|
|
|
pa_log_info("OSS device not mmap capable, falling back to UNIX read/write mode.");
|
2013-06-27 19:28:09 +02:00
|
|
|
use_mmap = false;
|
2007-10-28 19:13:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (use_mmap && mode == O_WRONLY) {
|
|
|
|
|
pa_log_info("Device opened for playback only, cannot do memory mapping, falling back to UNIX write() mode.");
|
2013-06-27 19:28:09 +02:00
|
|
|
use_mmap = false;
|
2007-10-28 19:13:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pa_oss_get_hw_description(dev, hwdesc, sizeof(hwdesc)) >= 0)
|
|
|
|
|
pa_log_info("Hardware name is '%s'.", hwdesc);
|
2006-02-21 23:40:07 +00:00
|
|
|
else
|
|
|
|
|
hwdesc[0] = 0;
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_log_info("Device opened in %s mode.", mode == O_WRONLY ? "O_WRONLY" : (mode == O_RDONLY ? "O_RDONLY" : "O_RDWR"));
|
2004-07-16 17:51:53 +00:00
|
|
|
|
2009-01-22 01:15:49 +01:00
|
|
|
orig_frag_size = frag_size;
|
2004-09-07 22:40:43 +00:00
|
|
|
if (nfrags >= 2 && frag_size >= 1)
|
2007-01-04 13:43:45 +00:00
|
|
|
if (pa_oss_set_fragments(fd, nfrags, frag_size) < 0)
|
|
|
|
|
goto fail;
|
2004-06-14 22:47:12 +00:00
|
|
|
|
2004-07-03 23:35:12 +00:00
|
|
|
if (pa_oss_auto_format(fd, &ss) < 0)
|
2004-06-14 22:47:12 +00:00
|
|
|
goto fail;
|
|
|
|
|
|
2004-06-15 00:29:01 +00:00
|
|
|
if (ioctl(fd, SNDCTL_DSP_GETBLKSIZE, &frag_size) < 0) {
|
2006-08-18 21:38:40 +00:00
|
|
|
pa_log("SNDCTL_DSP_GETBLKSIZE: %s", pa_cstrerror(errno));
|
2004-06-14 22:47:12 +00:00
|
|
|
goto fail;
|
|
|
|
|
}
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_assert(frag_size > 0);
|
2004-06-15 00:29:01 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
u = pa_xnew0(struct userdata, 1);
|
|
|
|
|
u->core = m->core;
|
|
|
|
|
u->module = m;
|
|
|
|
|
m->userdata = u;
|
|
|
|
|
u->fd = fd;
|
|
|
|
|
u->mixer_fd = -1;
|
2009-01-22 00:20:15 +01:00
|
|
|
u->mixer_devmask = 0;
|
2013-06-27 19:28:09 +02:00
|
|
|
u->use_getospace = u->use_getispace = true;
|
|
|
|
|
u->use_getodelay = true;
|
2007-10-28 19:13:50 +00:00
|
|
|
u->mode = mode;
|
|
|
|
|
u->frame_size = pa_frame_size(&ss);
|
|
|
|
|
u->device_name = pa_xstrdup(dev);
|
2008-08-19 22:39:54 +02:00
|
|
|
u->in_nfrags = u->out_nfrags = (uint32_t) (u->nfrags = nfrags);
|
|
|
|
|
u->out_fragment_size = u->in_fragment_size = (uint32_t) (u->frag_size = frag_size);
|
2009-01-22 01:15:49 +01:00
|
|
|
u->orig_frag_size = orig_frag_size;
|
2007-10-28 19:13:50 +00:00
|
|
|
u->use_mmap = use_mmap;
|
|
|
|
|
u->rtpoll = pa_rtpoll_new();
|
2016-09-13 18:43:38 +03:00
|
|
|
|
|
|
|
|
if (pa_thread_mq_init(&u->thread_mq, m->core->mainloop, u->rtpoll) < 0) {
|
|
|
|
|
pa_log("pa_thread_mq_init() failed.");
|
|
|
|
|
goto fail;
|
|
|
|
|
}
|
|
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
u->rtpoll_item = NULL;
|
|
|
|
|
build_pollfd(u);
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2004-06-15 00:29:01 +00:00
|
|
|
if (ioctl(fd, SNDCTL_DSP_GETISPACE, &info) >= 0) {
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_log_info("Input -- %u fragments of size %u.", info.fragstotal, info.fragsize);
|
2008-08-19 22:39:54 +02:00
|
|
|
u->in_fragment_size = (uint32_t) info.fragsize;
|
|
|
|
|
u->in_nfrags = (uint32_t) info.fragstotal;
|
2013-06-27 19:28:09 +02:00
|
|
|
u->use_getispace = true;
|
2004-06-15 00:29:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ioctl(fd, SNDCTL_DSP_GETOSPACE, &info) >= 0) {
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_log_info("Output -- %u fragments of size %u.", info.fragstotal, info.fragsize);
|
2008-08-19 22:39:54 +02:00
|
|
|
u->out_fragment_size = (uint32_t) info.fragsize;
|
|
|
|
|
u->out_nfrags = (uint32_t) info.fragstotal;
|
2013-06-27 19:28:09 +02:00
|
|
|
u->use_getospace = true;
|
2004-06-15 00:29:01 +00:00
|
|
|
}
|
|
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
u->in_hwbuf_size = u->in_nfrags * u->in_fragment_size;
|
|
|
|
|
u->out_hwbuf_size = u->out_nfrags * u->out_fragment_size;
|
|
|
|
|
|
2004-07-10 20:56:38 +00:00
|
|
|
if (mode != O_WRONLY) {
|
2007-10-28 19:13:50 +00:00
|
|
|
char *name_buf = NULL;
|
|
|
|
|
|
|
|
|
|
if (use_mmap) {
|
|
|
|
|
if ((u->in_mmap = mmap(NULL, u->in_hwbuf_size, PROT_READ, MAP_SHARED, fd, 0)) == MAP_FAILED) {
|
|
|
|
|
pa_log_warn("mmap(PROT_READ) failed, reverting to non-mmap mode: %s", pa_cstrerror(errno));
|
2013-06-27 19:28:09 +02:00
|
|
|
use_mmap = u->use_mmap = false;
|
2007-10-28 19:13:50 +00:00
|
|
|
u->in_mmap = NULL;
|
|
|
|
|
} else
|
|
|
|
|
pa_log_debug("Successfully mmap()ed input buffer.");
|
|
|
|
|
}
|
|
|
|
|
|
2006-08-12 16:26:59 +00:00
|
|
|
if ((name = pa_modargs_get_value(ma, "source_name", NULL)))
|
2013-06-27 19:28:09 +02:00
|
|
|
namereg_fail = true;
|
2006-08-12 16:26:59 +00:00
|
|
|
else {
|
2007-10-28 19:13:50 +00:00
|
|
|
name = name_buf = pa_sprintf_malloc("oss_input.%s", pa_path_get_filename(dev));
|
2013-06-27 19:28:09 +02:00
|
|
|
namereg_fail = false;
|
2006-08-12 16:26:59 +00:00
|
|
|
}
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
pa_source_new_data_init(&source_new_data);
|
|
|
|
|
source_new_data.driver = __FILE__;
|
|
|
|
|
source_new_data.module = m;
|
|
|
|
|
pa_source_new_data_set_name(&source_new_data, name);
|
|
|
|
|
source_new_data.namereg_fail = namereg_fail;
|
|
|
|
|
pa_source_new_data_set_sample_spec(&source_new_data, &ss);
|
|
|
|
|
pa_source_new_data_set_channel_map(&source_new_data, &map);
|
|
|
|
|
pa_proplist_sets(source_new_data.proplist, PA_PROP_DEVICE_STRING, dev);
|
|
|
|
|
pa_proplist_sets(source_new_data.proplist, PA_PROP_DEVICE_API, "oss");
|
|
|
|
|
pa_proplist_sets(source_new_data.proplist, PA_PROP_DEVICE_DESCRIPTION, hwdesc[0] ? hwdesc : dev);
|
|
|
|
|
pa_proplist_sets(source_new_data.proplist, PA_PROP_DEVICE_ACCESS_MODE, use_mmap ? "mmap" : "serial");
|
|
|
|
|
pa_proplist_setf(source_new_data.proplist, PA_PROP_DEVICE_BUFFERING_BUFFER_SIZE, "%lu", (unsigned long) (u->in_hwbuf_size));
|
|
|
|
|
pa_proplist_setf(source_new_data.proplist, PA_PROP_DEVICE_BUFFERING_FRAGMENT_SIZE, "%lu", (unsigned long) (u->in_fragment_size));
|
|
|
|
|
|
2009-05-28 02:39:22 +02:00
|
|
|
if (pa_modargs_get_proplist(ma, "source_properties", source_new_data.proplist, PA_UPDATE_REPLACE) < 0) {
|
|
|
|
|
pa_log("Invalid properties");
|
|
|
|
|
pa_source_new_data_done(&source_new_data);
|
2013-12-16 16:31:20 +01:00
|
|
|
pa_xfree(name_buf);
|
2009-05-28 02:39:22 +02:00
|
|
|
goto fail;
|
|
|
|
|
}
|
|
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
u->source = pa_source_new(m->core, &source_new_data, PA_SOURCE_HARDWARE|PA_SOURCE_LATENCY);
|
|
|
|
|
pa_source_new_data_done(&source_new_data);
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_xfree(name_buf);
|
2008-05-15 23:34:41 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
if (!u->source) {
|
|
|
|
|
pa_log("Failed to create source object");
|
2006-04-10 19:42:44 +00:00
|
|
|
goto fail;
|
2007-10-28 19:13:50 +00:00
|
|
|
}
|
2006-04-10 19:42:44 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
u->source->parent.process_msg = source_process_msg;
|
2018-03-13 19:40:38 +02:00
|
|
|
u->source->set_state_in_io_thread = source_set_state_in_io_thread_cb;
|
2004-07-10 20:56:38 +00:00
|
|
|
u->source->userdata = u;
|
2007-10-28 19:13:50 +00:00
|
|
|
|
|
|
|
|
pa_source_set_asyncmsgq(u->source, u->thread_mq.inq);
|
|
|
|
|
pa_source_set_rtpoll(u->source, u->rtpoll);
|
2009-05-08 01:56:21 +02:00
|
|
|
pa_source_set_fixed_latency(u->source, pa_bytes_to_usec(u->in_hwbuf_size, &u->source->sample_spec));
|
2013-06-27 19:28:09 +02:00
|
|
|
u->source->refresh_volume = true;
|
2004-07-10 20:56:38 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
if (use_mmap)
|
|
|
|
|
u->in_mmap_memblocks = pa_xnew0(pa_memblock*, u->in_nfrags);
|
|
|
|
|
}
|
2006-08-12 16:26:59 +00:00
|
|
|
|
2004-06-15 00:29:01 +00:00
|
|
|
if (mode != O_RDONLY) {
|
2007-10-28 19:13:50 +00:00
|
|
|
char *name_buf = NULL;
|
|
|
|
|
|
|
|
|
|
if (use_mmap) {
|
|
|
|
|
if ((u->out_mmap = mmap(NULL, u->out_hwbuf_size, PROT_WRITE, MAP_SHARED, fd, 0)) == MAP_FAILED) {
|
|
|
|
|
if (mode == O_RDWR) {
|
|
|
|
|
pa_log_debug("mmap() failed for input. Changing to O_WRONLY mode.");
|
|
|
|
|
mode = O_WRONLY;
|
|
|
|
|
goto go_on;
|
|
|
|
|
} else {
|
|
|
|
|
pa_log_warn("mmap(PROT_WRITE) failed, reverting to non-mmap mode: %s", pa_cstrerror(errno));
|
2013-06-27 19:28:09 +02:00
|
|
|
u->use_mmap = use_mmap = false;
|
2007-10-28 19:13:50 +00:00
|
|
|
u->out_mmap = NULL;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
pa_log_debug("Successfully mmap()ed output buffer.");
|
|
|
|
|
pa_silence_memory(u->out_mmap, u->out_hwbuf_size, &ss);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-08-12 16:26:59 +00:00
|
|
|
if ((name = pa_modargs_get_value(ma, "sink_name", NULL)))
|
2013-06-27 19:28:09 +02:00
|
|
|
namereg_fail = true;
|
2006-08-12 16:26:59 +00:00
|
|
|
else {
|
2007-10-28 19:13:50 +00:00
|
|
|
name = name_buf = pa_sprintf_malloc("oss_output.%s", pa_path_get_filename(dev));
|
2013-06-27 19:28:09 +02:00
|
|
|
namereg_fail = false;
|
2006-08-12 16:26:59 +00:00
|
|
|
}
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
pa_sink_new_data_init(&sink_new_data);
|
|
|
|
|
sink_new_data.driver = __FILE__;
|
|
|
|
|
sink_new_data.module = m;
|
|
|
|
|
pa_sink_new_data_set_name(&sink_new_data, name);
|
|
|
|
|
sink_new_data.namereg_fail = namereg_fail;
|
|
|
|
|
pa_sink_new_data_set_sample_spec(&sink_new_data, &ss);
|
|
|
|
|
pa_sink_new_data_set_channel_map(&sink_new_data, &map);
|
|
|
|
|
pa_proplist_sets(sink_new_data.proplist, PA_PROP_DEVICE_STRING, dev);
|
|
|
|
|
pa_proplist_sets(sink_new_data.proplist, PA_PROP_DEVICE_API, "oss");
|
|
|
|
|
pa_proplist_sets(sink_new_data.proplist, PA_PROP_DEVICE_DESCRIPTION, hwdesc[0] ? hwdesc : dev);
|
|
|
|
|
pa_proplist_sets(sink_new_data.proplist, PA_PROP_DEVICE_ACCESS_MODE, use_mmap ? "mmap" : "serial");
|
|
|
|
|
pa_proplist_setf(sink_new_data.proplist, PA_PROP_DEVICE_BUFFERING_BUFFER_SIZE, "%lu", (unsigned long) (u->out_hwbuf_size));
|
|
|
|
|
pa_proplist_setf(sink_new_data.proplist, PA_PROP_DEVICE_BUFFERING_FRAGMENT_SIZE, "%lu", (unsigned long) (u->out_fragment_size));
|
|
|
|
|
|
2009-05-28 02:39:22 +02:00
|
|
|
if (pa_modargs_get_proplist(ma, "sink_properties", sink_new_data.proplist, PA_UPDATE_REPLACE) < 0) {
|
|
|
|
|
pa_log("Invalid properties");
|
|
|
|
|
pa_sink_new_data_done(&sink_new_data);
|
2013-12-16 16:31:20 +01:00
|
|
|
pa_xfree(name_buf);
|
2009-05-28 02:39:22 +02:00
|
|
|
goto fail;
|
|
|
|
|
}
|
|
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
u->sink = pa_sink_new(m->core, &sink_new_data, PA_SINK_HARDWARE|PA_SINK_LATENCY);
|
|
|
|
|
pa_sink_new_data_done(&sink_new_data);
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_xfree(name_buf);
|
2008-05-15 23:34:41 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
if (!u->sink) {
|
|
|
|
|
pa_log("Failed to create sink object");
|
2006-04-10 19:42:44 +00:00
|
|
|
goto fail;
|
2007-10-28 19:13:50 +00:00
|
|
|
}
|
2006-04-10 19:42:44 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
u->sink->parent.process_msg = sink_process_msg;
|
2018-03-13 19:40:38 +02:00
|
|
|
u->sink->set_state_in_io_thread = sink_set_state_in_io_thread_cb;
|
2004-06-16 00:05:30 +00:00
|
|
|
u->sink->userdata = u;
|
2007-10-28 19:13:50 +00:00
|
|
|
|
|
|
|
|
pa_sink_set_asyncmsgq(u->sink, u->thread_mq.inq);
|
|
|
|
|
pa_sink_set_rtpoll(u->sink, u->rtpoll);
|
2009-05-08 01:56:21 +02:00
|
|
|
pa_sink_set_fixed_latency(u->sink, pa_bytes_to_usec(u->out_hwbuf_size, &u->sink->sample_spec));
|
2013-06-27 19:28:09 +02:00
|
|
|
u->sink->refresh_volume = true;
|
2004-06-14 22:47:12 +00:00
|
|
|
|
2009-03-24 21:13:41 +01:00
|
|
|
pa_sink_set_max_request(u->sink, u->out_hwbuf_size);
|
2008-06-20 22:32:41 +02:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
if (use_mmap)
|
|
|
|
|
u->out_mmap_memblocks = pa_xnew0(pa_memblock*, u->out_nfrags);
|
|
|
|
|
}
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
if ((u->mixer_fd = pa_oss_open_mixer_for_device(u->device_name)) >= 0) {
|
2013-06-27 19:28:09 +02:00
|
|
|
bool do_close = true;
|
2004-06-14 22:47:12 +00:00
|
|
|
|
2015-04-30 13:21:02 +03:00
|
|
|
if (ioctl(u->mixer_fd, SOUND_MIXER_READ_DEVMASK, &u->mixer_devmask) < 0)
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_log_warn("SOUND_MIXER_READ_DEVMASK failed: %s", pa_cstrerror(errno));
|
|
|
|
|
else {
|
|
|
|
|
if (u->sink && (u->mixer_devmask & (SOUND_MASK_VOLUME|SOUND_MASK_PCM))) {
|
|
|
|
|
pa_log_debug("Found hardware mixer track for playback.");
|
2011-07-17 15:29:29 +01:00
|
|
|
pa_sink_set_get_volume_callback(u->sink, sink_get_volume);
|
|
|
|
|
pa_sink_set_set_volume_callback(u->sink, sink_set_volume);
|
2009-01-27 04:39:07 +01:00
|
|
|
u->sink->n_volume_steps = 101;
|
2013-06-27 19:28:09 +02:00
|
|
|
do_close = false;
|
2007-10-28 19:13:50 +00:00
|
|
|
}
|
2004-06-14 22:47:12 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
if (u->source && (u->mixer_devmask & (SOUND_MASK_RECLEV|SOUND_MASK_IGAIN))) {
|
|
|
|
|
pa_log_debug("Found hardware mixer track for recording.");
|
2011-07-17 15:29:29 +01:00
|
|
|
pa_source_set_get_volume_callback(u->source, source_get_volume);
|
|
|
|
|
pa_source_set_set_volume_callback(u->source, source_set_volume);
|
2009-01-27 04:39:07 +01:00
|
|
|
u->source->n_volume_steps = 101;
|
2013-06-27 19:28:09 +02:00
|
|
|
do_close = false;
|
2007-10-28 19:13:50 +00:00
|
|
|
}
|
|
|
|
|
}
|
2004-08-04 16:39:30 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
if (do_close) {
|
|
|
|
|
pa_close(u->mixer_fd);
|
|
|
|
|
u->mixer_fd = -1;
|
2009-01-22 00:20:15 +01:00
|
|
|
u->mixer_devmask = 0;
|
2007-10-28 19:13:50 +00:00
|
|
|
}
|
|
|
|
|
}
|
2004-06-14 22:47:12 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
go_on:
|
|
|
|
|
|
|
|
|
|
pa_assert(u->source || u->sink);
|
2004-07-15 17:33:56 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_memchunk_reset(&u->memchunk);
|
|
|
|
|
|
2010-05-03 13:28:15 +02:00
|
|
|
if (!(u->thread = pa_thread_new("oss", thread_func, u))) {
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_log("Failed to create thread.");
|
|
|
|
|
goto fail;
|
2006-01-12 16:09:58 +00:00
|
|
|
}
|
|
|
|
|
|
2006-01-27 16:25:31 +00:00
|
|
|
/* Read mixer settings */
|
2008-05-15 23:34:41 +00:00
|
|
|
if (u->sink) {
|
|
|
|
|
if (sink_new_data.volume_is_set) {
|
|
|
|
|
if (u->sink->set_volume)
|
|
|
|
|
u->sink->set_volume(u->sink);
|
|
|
|
|
} else {
|
|
|
|
|
if (u->sink->get_volume)
|
|
|
|
|
u->sink->get_volume(u->sink);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (u->source) {
|
|
|
|
|
if (source_new_data.volume_is_set) {
|
|
|
|
|
if (u->source->set_volume)
|
|
|
|
|
u->source->set_volume(u->source);
|
|
|
|
|
} else {
|
|
|
|
|
if (u->source->get_volume)
|
|
|
|
|
u->source->get_volume(u->source);
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2006-01-27 16:25:31 +00:00
|
|
|
if (u->sink)
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_sink_put(u->sink);
|
|
|
|
|
if (u->source)
|
|
|
|
|
pa_source_put(u->source);
|
|
|
|
|
|
|
|
|
|
pa_modargs_free(ma);
|
2006-01-27 16:25:31 +00:00
|
|
|
|
2004-06-14 22:47:12 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
fail:
|
2007-10-28 19:13:50 +00:00
|
|
|
|
|
|
|
|
if (u)
|
|
|
|
|
pa__done(m);
|
|
|
|
|
else if (fd >= 0)
|
|
|
|
|
pa_close(fd);
|
2004-06-14 22:47:12 +00:00
|
|
|
|
2004-07-11 23:21:32 +00:00
|
|
|
if (ma)
|
|
|
|
|
pa_modargs_free(ma);
|
2006-08-12 16:26:59 +00:00
|
|
|
|
2004-06-14 22:47:12 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
void pa__done(pa_module*m) {
|
2004-06-14 22:47:12 +00:00
|
|
|
struct userdata *u;
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_assert(m);
|
2004-06-14 22:47:12 +00:00
|
|
|
|
2004-08-04 16:39:30 +00:00
|
|
|
if (!(u = m->userdata))
|
|
|
|
|
return;
|
2006-08-12 16:02:26 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
if (u->sink)
|
|
|
|
|
pa_sink_unlink(u->sink);
|
|
|
|
|
|
|
|
|
|
if (u->source)
|
|
|
|
|
pa_source_unlink(u->source);
|
|
|
|
|
|
|
|
|
|
if (u->thread) {
|
|
|
|
|
pa_asyncmsgq_send(u->thread_mq.inq, NULL, PA_MESSAGE_SHUTDOWN, NULL, 0, NULL);
|
|
|
|
|
pa_thread_free(u->thread);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pa_thread_mq_done(&u->thread_mq);
|
|
|
|
|
|
|
|
|
|
if (u->sink)
|
|
|
|
|
pa_sink_unref(u->sink);
|
|
|
|
|
|
|
|
|
|
if (u->source)
|
|
|
|
|
pa_source_unref(u->source);
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2004-06-14 22:47:12 +00:00
|
|
|
if (u->memchunk.memblock)
|
2004-07-03 23:35:12 +00:00
|
|
|
pa_memblock_unref(u->memchunk.memblock);
|
2007-10-28 19:13:50 +00:00
|
|
|
|
|
|
|
|
if (u->rtpoll_item)
|
|
|
|
|
pa_rtpoll_item_free(u->rtpoll_item);
|
|
|
|
|
|
|
|
|
|
if (u->rtpoll)
|
|
|
|
|
pa_rtpoll_free(u->rtpoll);
|
|
|
|
|
|
|
|
|
|
if (u->out_mmap_memblocks) {
|
|
|
|
|
unsigned i;
|
|
|
|
|
for (i = 0; i < u->out_nfrags; i++)
|
|
|
|
|
if (u->out_mmap_memblocks[i])
|
|
|
|
|
pa_memblock_unref_fixed(u->out_mmap_memblocks[i]);
|
|
|
|
|
pa_xfree(u->out_mmap_memblocks);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (u->in_mmap_memblocks) {
|
|
|
|
|
unsigned i;
|
|
|
|
|
for (i = 0; i < u->in_nfrags; i++)
|
|
|
|
|
if (u->in_mmap_memblocks[i])
|
|
|
|
|
pa_memblock_unref_fixed(u->in_mmap_memblocks[i]);
|
|
|
|
|
pa_xfree(u->in_mmap_memblocks);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (u->in_mmap && u->in_mmap != MAP_FAILED)
|
|
|
|
|
munmap(u->in_mmap, u->in_hwbuf_size);
|
|
|
|
|
|
|
|
|
|
if (u->out_mmap && u->out_mmap != MAP_FAILED)
|
|
|
|
|
munmap(u->out_mmap, u->out_hwbuf_size);
|
|
|
|
|
|
|
|
|
|
if (u->fd >= 0)
|
|
|
|
|
pa_close(u->fd);
|
|
|
|
|
|
|
|
|
|
if (u->mixer_fd >= 0)
|
|
|
|
|
pa_close(u->mixer_fd);
|
|
|
|
|
|
|
|
|
|
pa_xfree(u->device_name);
|
2004-06-15 15:18:33 +00:00
|
|
|
|
2004-08-04 16:39:30 +00:00
|
|
|
pa_xfree(u);
|
2004-06-14 22:47:12 +00:00
|
|
|
}
|