mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-09 13:30:06 -05:00
event: add PULL_INPUT event
Rename some events, add an explicit event to pull input
This commit is contained in:
parent
e56f120559
commit
6377b9bd12
4 changed files with 21 additions and 109 deletions
|
|
@ -9,74 +9,6 @@
|
|||
|
||||
static int verbose = 0; /* verbose flag */
|
||||
|
||||
#if 0
|
||||
static void
|
||||
generate_sine(const snd_pcm_channel_area_t *areas,
|
||||
snd_pcm_uframes_t offset,
|
||||
int count, double *_phase)
|
||||
{
|
||||
static double max_phase = 2. * M_PI;
|
||||
double phase = *_phase;
|
||||
double step = max_phase*freq/(double)rate;
|
||||
unsigned char *samples[channels];
|
||||
int steps[channels];
|
||||
unsigned int chn;
|
||||
int format_bits = snd_pcm_format_width(format);
|
||||
unsigned int maxval = (1 << (format_bits - 1)) - 1;
|
||||
int bps = format_bits / 8; /* bytes per sample */
|
||||
int phys_bps = snd_pcm_format_physical_width(format) / 8;
|
||||
int big_endian = snd_pcm_format_big_endian(format) == 1;
|
||||
int to_unsigned = snd_pcm_format_unsigned(format) == 1;
|
||||
int is_float = (format == SND_PCM_FORMAT_FLOAT_LE ||
|
||||
format == SND_PCM_FORMAT_FLOAT_BE);
|
||||
|
||||
/* verify and prepare the contents of areas */
|
||||
for (chn = 0; chn < channels; chn++) {
|
||||
if ((areas[chn].first % 8) != 0) {
|
||||
printf("areas[%i].first == %i, aborting...\n", chn, areas[chn].first);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
samples[chn] = /*(signed short *)*/(((unsigned char *)areas[chn].addr) + (areas[chn].first / 8));
|
||||
if ((areas[chn].step % 16) != 0) {
|
||||
printf("areas[%i].step == %i, aborting...\n", chn, areas[chn].step);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
steps[chn] = areas[chn].step / 8;
|
||||
samples[chn] += offset * steps[chn];
|
||||
}
|
||||
/* fill the channel areas */
|
||||
while (count-- > 0) {
|
||||
union {
|
||||
float f;
|
||||
int i;
|
||||
} fval;
|
||||
int res, i;
|
||||
if (is_float) {
|
||||
fval.f = sin(phase) * maxval;
|
||||
res = fval.i;
|
||||
} else
|
||||
res = sin(phase) * maxval;
|
||||
if (to_unsigned)
|
||||
res ^= 1U << (format_bits - 1);
|
||||
for (chn = 0; chn < channels; chn++) {
|
||||
/* Generate data in native endian format */
|
||||
if (big_endian) {
|
||||
for (i = 0; i < bps; i++)
|
||||
*(samples[chn] + phys_bps - 1 - i) = (res >> i * 8) & 0xff;
|
||||
} else {
|
||||
for (i = 0; i < bps; i++)
|
||||
*(samples[chn] + i) = (res >> i * 8) & 0xff;
|
||||
}
|
||||
samples[chn] += steps[chn];
|
||||
}
|
||||
phase += step;
|
||||
if (phase >= max_phase)
|
||||
phase -= max_phase;
|
||||
}
|
||||
*_phase = phase;
|
||||
}
|
||||
#endif
|
||||
|
||||
#define CHECK(s,msg) if ((err = (s)) < 0) { printf (msg ": %s\n", snd_strerror(err)); return err; }
|
||||
|
||||
static snd_pcm_format_t
|
||||
|
|
@ -236,26 +168,6 @@ xrun_recovery (snd_pcm_t *handle, int err)
|
|||
return err;
|
||||
}
|
||||
|
||||
#if 0
|
||||
/*
|
||||
* Transfer method - write and wait for room in buffer using poll
|
||||
*/
|
||||
static int
|
||||
wait_for_poll (snd_pcm_t *handle, struct pollfd *ufds, unsigned int count)
|
||||
{
|
||||
unsigned short revents;
|
||||
|
||||
while (1) {
|
||||
poll(ufds, count, -1);
|
||||
snd_pcm_poll_descriptors_revents(handle, ufds, count, &revents);
|
||||
if (revents & POLLERR)
|
||||
return -EIO;
|
||||
if (revents & POLLOUT)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Transfer method - direct write only
|
||||
*/
|
||||
|
|
@ -335,7 +247,7 @@ direct_loop (void *user_data)
|
|||
|
||||
event.refcount = 1;
|
||||
event.notify = NULL;
|
||||
event.type = SPI_EVENT_TYPE_NEED_INPUT;
|
||||
event.type = SPI_EVENT_TYPE_PULL_INPUT;
|
||||
event.port_id = 0;
|
||||
event.data = buffer;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue