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
|
2006-06-19 21:53:48 +00:00
|
|
|
along with PulseAudio; if not, write to the Free Software
|
2004-07-16 19:56:36 +00:00
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
|
USA.
|
|
|
|
|
***/
|
|
|
|
|
|
2004-07-16 19:16:42 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
#include <config.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2004-07-03 23:35:12 +00:00
|
|
|
#include <stdio.h>
|
2004-06-08 23:54:24 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
2006-06-19 21:53:48 +00:00
|
|
|
#include <pulse/utf8.h>
|
|
|
|
|
#include <pulse/xmalloc.h>
|
2009-01-22 00:15:19 +01:00
|
|
|
#include <pulse/util.h>
|
2006-05-17 16:34:18 +00:00
|
|
|
|
2006-06-19 21:53:48 +00:00
|
|
|
#include <pulsecore/sample-util.h>
|
|
|
|
|
#include <pulsecore/core-subscribe.h>
|
|
|
|
|
#include <pulsecore/log.h>
|
2006-07-29 15:06:49 +00:00
|
|
|
#include <pulsecore/play-memblockq.h>
|
2006-08-13 16:19:56 +00:00
|
|
|
#include <pulsecore/namereg.h>
|
2008-05-15 23:34:41 +00:00
|
|
|
#include <pulsecore/core-util.h>
|
2009-07-16 10:41:34 +08:00
|
|
|
#include <pulse/timeval.h>
|
2006-02-17 12:10:58 +00:00
|
|
|
|
2004-07-16 18:58:23 +00:00
|
|
|
#include "sink-input.h"
|
2004-06-08 23:54:24 +00:00
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
#define MEMBLOCKQ_MAXLENGTH (32*1024*1024)
|
2007-10-28 19:13:50 +00:00
|
|
|
#define CONVERT_BUFFER_LENGTH (PA_PAGE_SIZE)
|
2004-07-03 00:19:17 +00:00
|
|
|
|
2009-08-21 21:27:44 +02:00
|
|
|
PA_DEFINE_PUBLIC_CLASS(pa_sink_input, pa_msgobject);
|
2007-10-28 19:13:50 +00:00
|
|
|
|
|
|
|
|
static void sink_input_free(pa_object *o);
|
2009-08-19 02:55:02 +02:00
|
|
|
static void set_real_ratio(pa_sink_input *i, const pa_cvolume *v);
|
2009-07-16 10:41:34 +08:00
|
|
|
static void sink_input_set_ramping_info(pa_sink_input* i, pa_volume_t pre_virtual_volume, pa_volume_t target_virtual_volume, pa_usec_t t);
|
|
|
|
|
static void sink_input_set_ramping_info_for_mute(pa_sink_input* i, pa_bool_t mute, pa_usec_t t);
|
|
|
|
|
static void sink_input_volume_ramping(pa_sink_input* i, pa_memchunk* chunk);
|
|
|
|
|
static void sink_input_rewind_ramp_info(pa_sink_input *i, size_t nbytes);
|
|
|
|
|
static void sink_input_release_envelope(pa_sink_input *i);
|
2006-05-16 23:47:38 +00:00
|
|
|
|
2006-08-13 16:19:56 +00:00
|
|
|
pa_sink_input_new_data* pa_sink_input_new_data_init(pa_sink_input_new_data *data) {
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_assert(data);
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2009-08-13 02:14:19 +02:00
|
|
|
pa_zero(*data);
|
2006-08-13 16:19:56 +00:00
|
|
|
data->resample_method = PA_RESAMPLER_INVALID;
|
2008-05-15 23:34:41 +00:00
|
|
|
data->proplist = pa_proplist_new();
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2006-08-13 16:19:56 +00:00
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
void pa_sink_input_new_data_set_sample_spec(pa_sink_input_new_data *data, const pa_sample_spec *spec) {
|
|
|
|
|
pa_assert(data);
|
|
|
|
|
|
|
|
|
|
if ((data->sample_spec_is_set = !!spec))
|
|
|
|
|
data->sample_spec = *spec;
|
|
|
|
|
}
|
|
|
|
|
|
2006-08-13 16:19:56 +00:00
|
|
|
void pa_sink_input_new_data_set_channel_map(pa_sink_input_new_data *data, const pa_channel_map *map) {
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_assert(data);
|
2006-08-13 16:19:56 +00:00
|
|
|
|
|
|
|
|
if ((data->channel_map_is_set = !!map))
|
|
|
|
|
data->channel_map = *map;
|
|
|
|
|
}
|
|
|
|
|
|
2009-02-04 18:34:08 +01:00
|
|
|
void pa_sink_input_new_data_set_volume(pa_sink_input_new_data *data, const pa_cvolume *volume) {
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_assert(data);
|
2006-08-13 16:19:56 +00:00
|
|
|
|
2009-02-04 18:34:08 +01:00
|
|
|
if ((data->volume_is_set = !!volume))
|
|
|
|
|
data->volume = *volume;
|
2006-08-13 16:19:56 +00:00
|
|
|
}
|
|
|
|
|
|
2009-02-05 01:22:05 +01:00
|
|
|
void pa_sink_input_new_data_apply_volume_factor(pa_sink_input_new_data *data, const pa_cvolume *volume_factor) {
|
|
|
|
|
pa_assert(data);
|
|
|
|
|
pa_assert(volume_factor);
|
|
|
|
|
|
|
|
|
|
if (data->volume_factor_is_set)
|
|
|
|
|
pa_sw_cvolume_multiply(&data->volume_factor, &data->volume_factor, volume_factor);
|
|
|
|
|
else {
|
|
|
|
|
data->volume_factor_is_set = TRUE;
|
|
|
|
|
data->volume_factor = *volume_factor;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-11 03:26:25 +02:00
|
|
|
void pa_sink_input_new_data_apply_volume_factor_sink(pa_sink_input_new_data *data, const pa_cvolume *volume_factor) {
|
|
|
|
|
pa_assert(data);
|
|
|
|
|
pa_assert(volume_factor);
|
|
|
|
|
|
|
|
|
|
if (data->volume_factor_sink_is_set)
|
|
|
|
|
pa_sw_cvolume_multiply(&data->volume_factor_sink, &data->volume_factor_sink, volume_factor);
|
|
|
|
|
else {
|
|
|
|
|
data->volume_factor_sink_is_set = TRUE;
|
|
|
|
|
data->volume_factor_sink = *volume_factor;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
void pa_sink_input_new_data_set_muted(pa_sink_input_new_data *data, pa_bool_t mute) {
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_assert(data);
|
2006-08-13 16:19:56 +00:00
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
data->muted_is_set = TRUE;
|
|
|
|
|
data->muted = !!mute;
|
2006-08-13 16:19:56 +00:00
|
|
|
}
|
|
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
void pa_sink_input_new_data_done(pa_sink_input_new_data *data) {
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_assert(data);
|
|
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
pa_proplist_free(data->proplist);
|
|
|
|
|
}
|
|
|
|
|
|
2008-06-20 22:32:41 +02:00
|
|
|
/* Called from main context */
|
2008-05-15 23:34:41 +00:00
|
|
|
static void reset_callbacks(pa_sink_input *i) {
|
|
|
|
|
pa_assert(i);
|
|
|
|
|
|
|
|
|
|
i->pop = NULL;
|
|
|
|
|
i->process_rewind = NULL;
|
|
|
|
|
i->update_max_rewind = NULL;
|
2008-06-20 22:32:41 +02:00
|
|
|
i->update_max_request = NULL;
|
|
|
|
|
i->update_sink_requested_latency = NULL;
|
|
|
|
|
i->update_sink_latency_range = NULL;
|
2009-08-15 00:48:14 +02:00
|
|
|
i->update_sink_fixed_latency = NULL;
|
2008-05-15 23:34:41 +00:00
|
|
|
i->attach = NULL;
|
|
|
|
|
i->detach = NULL;
|
|
|
|
|
i->suspend = NULL;
|
2009-04-07 00:46:20 +02:00
|
|
|
i->suspend_within_thread = NULL;
|
2009-03-30 18:21:34 +02:00
|
|
|
i->moving = NULL;
|
2008-05-15 23:34:41 +00:00
|
|
|
i->kill = NULL;
|
|
|
|
|
i->get_latency = NULL;
|
|
|
|
|
i->state_change = NULL;
|
2008-10-21 18:24:45 +02:00
|
|
|
i->may_move_to = NULL;
|
2009-02-12 03:18:05 +01:00
|
|
|
i->send_event = NULL;
|
2009-08-21 02:56:17 +02:00
|
|
|
i->volume_changed = NULL;
|
|
|
|
|
i->mute_changed = NULL;
|
2007-10-28 19:13:50 +00:00
|
|
|
}
|
|
|
|
|
|
2008-06-20 22:32:41 +02:00
|
|
|
/* Called from main context */
|
2009-02-03 03:14:20 +01:00
|
|
|
int pa_sink_input_new(
|
|
|
|
|
pa_sink_input **_i,
|
2006-08-13 16:19:56 +00:00
|
|
|
pa_core *core,
|
2009-08-28 23:24:09 +02:00
|
|
|
pa_sink_input_new_data *data) {
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2006-01-11 01:17:39 +00:00
|
|
|
pa_sink_input *i;
|
|
|
|
|
pa_resampler *resampler = NULL;
|
2007-11-21 01:30:40 +00:00
|
|
|
char st[PA_SAMPLE_SPEC_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX];
|
2008-10-07 22:44:43 +02:00
|
|
|
pa_channel_map original_cm;
|
2009-02-03 03:14:20 +01:00
|
|
|
int r;
|
2009-09-20 03:18:03 +02:00
|
|
|
char *pt;
|
2006-08-13 16:19:56 +00:00
|
|
|
|
2009-02-03 03:14:20 +01:00
|
|
|
pa_assert(_i);
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_assert(core);
|
|
|
|
|
pa_assert(data);
|
2009-08-13 02:14:19 +02:00
|
|
|
pa_assert_ctl_context();
|
2006-08-13 16:19:56 +00:00
|
|
|
|
2009-02-04 18:28:52 +01:00
|
|
|
if (data->client)
|
|
|
|
|
pa_proplist_update(data->proplist, PA_UPDATE_MERGE, data->client->proplist);
|
|
|
|
|
|
2009-02-03 03:14:20 +01:00
|
|
|
if ((r = pa_hook_fire(&core->hooks[PA_CORE_HOOK_SINK_INPUT_NEW], data)) < 0)
|
|
|
|
|
return r;
|
2006-08-13 16:19:56 +00:00
|
|
|
|
2009-02-03 03:14:20 +01:00
|
|
|
pa_return_val_if_fail(!data->driver || pa_utf8_valid(data->driver), -PA_ERR_INVALID);
|
2006-08-13 16:19:56 +00:00
|
|
|
|
2009-01-27 23:35:55 +01:00
|
|
|
if (!data->sink) {
|
2009-01-15 20:07:13 +01:00
|
|
|
data->sink = pa_namereg_get(core, NULL, PA_NAMEREG_SINK);
|
2009-01-27 23:35:55 +01:00
|
|
|
data->save_sink = FALSE;
|
|
|
|
|
}
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2009-02-03 03:14:20 +01:00
|
|
|
pa_return_val_if_fail(data->sink, -PA_ERR_NOENTITY);
|
|
|
|
|
pa_return_val_if_fail(PA_SINK_IS_LINKED(pa_sink_get_state(data->sink)), -PA_ERR_BADSTATE);
|
|
|
|
|
pa_return_val_if_fail(!data->sync_base || (data->sync_base->sink == data->sink && pa_sink_input_get_state(data->sync_base) == PA_SINK_INPUT_CORKED), -PA_ERR_INVALID);
|
2009-02-03 02:23:46 +01:00
|
|
|
|
2006-08-13 16:19:56 +00:00
|
|
|
if (!data->sample_spec_is_set)
|
|
|
|
|
data->sample_spec = data->sink->sample_spec;
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2009-02-03 03:14:20 +01:00
|
|
|
pa_return_val_if_fail(pa_sample_spec_valid(&data->sample_spec), -PA_ERR_INVALID);
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
if (!data->channel_map_is_set) {
|
2008-10-07 22:44:43 +02:00
|
|
|
if (pa_channel_map_compatible(&data->sink->channel_map, &data->sample_spec))
|
2007-10-28 19:13:50 +00:00
|
|
|
data->channel_map = data->sink->channel_map;
|
|
|
|
|
else
|
2008-10-07 22:45:37 +02:00
|
|
|
pa_channel_map_init_extend(&data->channel_map, data->sample_spec.channels, PA_CHANNEL_MAP_DEFAULT);
|
2007-10-28 19:13:50 +00:00
|
|
|
}
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2009-02-03 03:14:20 +01:00
|
|
|
pa_return_val_if_fail(pa_channel_map_compatible(&data->channel_map, &data->sample_spec), -PA_ERR_INVALID);
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2009-02-04 18:34:08 +01:00
|
|
|
if (!data->volume_is_set) {
|
2009-04-13 22:50:24 +02:00
|
|
|
pa_cvolume_reset(&data->volume, data->sample_spec.channels);
|
|
|
|
|
data->volume_is_absolute = FALSE;
|
2009-01-27 23:35:55 +01:00
|
|
|
data->save_volume = FALSE;
|
2009-01-27 04:39:07 +01:00
|
|
|
}
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2009-02-04 18:34:08 +01:00
|
|
|
pa_return_val_if_fail(pa_cvolume_compatible(&data->volume, &data->sample_spec), -PA_ERR_INVALID);
|
2009-01-27 04:39:07 +01:00
|
|
|
|
2009-02-05 01:22:05 +01:00
|
|
|
if (!data->volume_factor_is_set)
|
|
|
|
|
pa_cvolume_reset(&data->volume_factor, data->sample_spec.channels);
|
|
|
|
|
|
|
|
|
|
pa_return_val_if_fail(pa_cvolume_compatible(&data->volume_factor, &data->sample_spec), -PA_ERR_INVALID);
|
|
|
|
|
|
2009-09-11 03:26:25 +02:00
|
|
|
if (!data->volume_factor_sink_is_set)
|
|
|
|
|
pa_cvolume_reset(&data->volume_factor_sink, data->sink->sample_spec.channels);
|
|
|
|
|
|
|
|
|
|
pa_return_val_if_fail(pa_cvolume_compatible(&data->volume_factor_sink, &data->sink->sample_spec), -PA_ERR_INVALID);
|
|
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
if (!data->muted_is_set)
|
|
|
|
|
data->muted = FALSE;
|
|
|
|
|
|
2009-08-28 23:24:09 +02:00
|
|
|
if (data->flags & PA_SINK_INPUT_FIX_FORMAT)
|
2007-11-21 01:30:40 +00:00
|
|
|
data->sample_spec.format = data->sink->sample_spec.format;
|
|
|
|
|
|
2009-08-28 23:24:09 +02:00
|
|
|
if (data->flags & PA_SINK_INPUT_FIX_RATE)
|
2007-11-21 01:30:40 +00:00
|
|
|
data->sample_spec.rate = data->sink->sample_spec.rate;
|
|
|
|
|
|
2008-10-07 22:46:18 +02:00
|
|
|
original_cm = data->channel_map;
|
|
|
|
|
|
2009-08-28 23:24:09 +02:00
|
|
|
if (data->flags & PA_SINK_INPUT_FIX_CHANNELS) {
|
2007-11-21 01:30:40 +00:00
|
|
|
data->sample_spec.channels = data->sink->sample_spec.channels;
|
|
|
|
|
data->channel_map = data->sink->channel_map;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pa_assert(pa_sample_spec_valid(&data->sample_spec));
|
|
|
|
|
pa_assert(pa_channel_map_valid(&data->channel_map));
|
|
|
|
|
|
|
|
|
|
/* Due to the fixing of the sample spec the volume might not match anymore */
|
2009-02-04 18:34:08 +01:00
|
|
|
pa_cvolume_remap(&data->volume, &original_cm, &data->channel_map);
|
2007-11-21 01:30:40 +00:00
|
|
|
|
2006-08-13 16:19:56 +00:00
|
|
|
if (data->resample_method == PA_RESAMPLER_INVALID)
|
|
|
|
|
data->resample_method = core->resample_method;
|
|
|
|
|
|
2009-02-03 03:14:20 +01:00
|
|
|
pa_return_val_if_fail(data->resample_method < PA_RESAMPLER_MAX, -PA_ERR_INVALID);
|
2006-08-13 16:19:56 +00:00
|
|
|
|
2009-02-03 03:14:20 +01:00
|
|
|
if ((r = pa_hook_fire(&core->hooks[PA_CORE_HOOK_SINK_INPUT_FIXATE], data)) < 0)
|
|
|
|
|
return r;
|
2007-11-21 01:30:40 +00:00
|
|
|
|
2009-08-28 23:24:09 +02:00
|
|
|
if ((data->flags & PA_SINK_INPUT_NO_CREATE_ON_SUSPEND) &&
|
2009-02-24 22:27:25 +01:00
|
|
|
pa_sink_get_state(data->sink) == PA_SINK_SUSPENDED) {
|
|
|
|
|
pa_log_warn("Failed to create sink input: sink is suspended.");
|
|
|
|
|
return -PA_ERR_BADSTATE;
|
|
|
|
|
}
|
|
|
|
|
|
2006-08-13 16:19:56 +00:00
|
|
|
if (pa_idxset_size(data->sink->inputs) >= PA_MAX_INPUTS_PER_SINK) {
|
2006-08-18 21:38:40 +00:00
|
|
|
pa_log_warn("Failed to create sink input: too many inputs per sink.");
|
2009-02-03 03:14:20 +01:00
|
|
|
return -PA_ERR_TOOLARGE;
|
2004-09-01 15:00:44 +00:00
|
|
|
}
|
2004-09-17 21:10:05 +00:00
|
|
|
|
2009-08-28 23:24:09 +02:00
|
|
|
if ((data->flags & PA_SINK_INPUT_VARIABLE_RATE) ||
|
2006-08-13 16:19:56 +00:00
|
|
|
!pa_sample_spec_equal(&data->sample_spec, &data->sink->sample_spec) ||
|
2007-10-28 19:13:50 +00:00
|
|
|
!pa_channel_map_equal(&data->channel_map, &data->sink->channel_map)) {
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2006-08-13 16:19:56 +00:00
|
|
|
if (!(resampler = pa_resampler_new(
|
2007-01-04 13:43:45 +00:00
|
|
|
core->mempool,
|
2006-08-13 16:19:56 +00:00
|
|
|
&data->sample_spec, &data->channel_map,
|
|
|
|
|
&data->sink->sample_spec, &data->sink->channel_map,
|
2007-10-28 19:13:50 +00:00
|
|
|
data->resample_method,
|
2009-08-28 23:24:09 +02:00
|
|
|
((data->flags & PA_SINK_INPUT_VARIABLE_RATE) ? PA_RESAMPLER_VARIABLE_RATE : 0) |
|
|
|
|
|
((data->flags & PA_SINK_INPUT_NO_REMAP) ? PA_RESAMPLER_NO_REMAP : 0) |
|
|
|
|
|
(core->disable_remixing || (data->flags & PA_SINK_INPUT_NO_REMIX) ? PA_RESAMPLER_NO_REMIX : 0) |
|
2008-09-05 16:04:42 +03:00
|
|
|
(core->disable_lfe_remixing ? PA_RESAMPLER_NO_LFE : 0)))) {
|
2006-08-18 21:38:40 +00:00
|
|
|
pa_log_warn("Unsupported resampling operation.");
|
2009-02-03 03:14:20 +01:00
|
|
|
return -PA_ERR_NOTSUPPORTED;
|
2006-07-29 15:06:49 +00:00
|
|
|
}
|
2007-10-28 19:13:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
i = pa_msgobject_new(pa_sink_input);
|
|
|
|
|
i->parent.parent.free = sink_input_free;
|
|
|
|
|
i->parent.process_msg = pa_sink_input_process_msg;
|
|
|
|
|
|
|
|
|
|
i->core = core;
|
|
|
|
|
i->state = PA_SINK_INPUT_INIT;
|
2009-08-28 23:24:09 +02:00
|
|
|
i->flags = data->flags;
|
2008-05-15 23:34:41 +00:00
|
|
|
i->proplist = pa_proplist_copy(data->proplist);
|
2009-01-22 00:15:19 +01:00
|
|
|
i->driver = pa_xstrdup(pa_path_get_filename(data->driver));
|
2006-08-13 16:19:56 +00:00
|
|
|
i->module = data->module;
|
|
|
|
|
i->sink = data->sink;
|
|
|
|
|
i->client = data->client;
|
|
|
|
|
|
2009-01-27 00:52:28 +01:00
|
|
|
i->requested_resample_method = data->resample_method;
|
|
|
|
|
i->actual_resample_method = resampler ? pa_resampler_get_method(resampler) : PA_RESAMPLER_INVALID;
|
2006-08-13 16:19:56 +00:00
|
|
|
i->sample_spec = data->sample_spec;
|
|
|
|
|
i->channel_map = data->channel_map;
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2009-02-04 18:34:08 +01:00
|
|
|
if ((i->sink->flags & PA_SINK_FLAT_VOLUME) && !data->volume_is_absolute) {
|
2009-08-19 02:55:02 +02:00
|
|
|
pa_cvolume remapped;
|
|
|
|
|
|
2009-02-04 18:34:08 +01:00
|
|
|
/* When the 'absolute' bool is not set then we'll treat the volume
|
|
|
|
|
* as relative to the sink volume even in flat volume mode */
|
2009-08-19 02:55:02 +02:00
|
|
|
remapped = data->sink->reference_volume;
|
|
|
|
|
pa_cvolume_remap(&remapped, &data->sink->channel_map, &data->channel_map);
|
|
|
|
|
pa_sw_cvolume_multiply(&i->volume, &data->volume, &remapped);
|
2009-02-04 18:34:08 +01:00
|
|
|
} else
|
2009-08-19 02:55:02 +02:00
|
|
|
i->volume = data->volume;
|
2009-02-04 18:34:08 +01:00
|
|
|
|
2009-02-05 01:22:05 +01:00
|
|
|
i->volume_factor = data->volume_factor;
|
2009-09-11 03:26:25 +02:00
|
|
|
i->volume_factor_sink = data->volume_factor_sink;
|
2009-08-19 02:55:02 +02:00
|
|
|
i->real_ratio = i->reference_ratio = data->volume;
|
|
|
|
|
pa_cvolume_reset(&i->soft_volume, i->sample_spec.channels);
|
|
|
|
|
pa_cvolume_reset(&i->real_ratio, i->sample_spec.channels);
|
2009-01-27 23:35:55 +01:00
|
|
|
i->save_volume = data->save_volume;
|
|
|
|
|
i->save_sink = data->save_sink;
|
|
|
|
|
i->save_muted = data->save_muted;
|
2008-10-07 01:37:38 +03:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
i->muted = data->muted;
|
|
|
|
|
|
|
|
|
|
if (data->sync_base) {
|
|
|
|
|
i->sync_next = data->sync_base->sync_next;
|
|
|
|
|
i->sync_prev = data->sync_base;
|
|
|
|
|
|
|
|
|
|
if (data->sync_base->sync_next)
|
|
|
|
|
data->sync_base->sync_next->sync_prev = i;
|
|
|
|
|
data->sync_base->sync_next = i;
|
|
|
|
|
} else
|
|
|
|
|
i->sync_next = i->sync_prev = NULL;
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2008-06-20 22:32:41 +02:00
|
|
|
i->direct_outputs = pa_idxset_new(NULL, NULL);
|
|
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
reset_callbacks(i);
|
2006-01-27 16:25:31 +00:00
|
|
|
i->userdata = NULL;
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2009-07-16 10:41:34 +08:00
|
|
|
/* Set Ramping info */
|
|
|
|
|
i->thread_info.ramp_info.is_ramping = FALSE;
|
|
|
|
|
i->thread_info.ramp_info.envelope_dead = TRUE;
|
|
|
|
|
i->thread_info.ramp_info.envelope = NULL;
|
|
|
|
|
i->thread_info.ramp_info.item = NULL;
|
|
|
|
|
i->thread_info.ramp_info.envelope_dying = 0;
|
|
|
|
|
|
|
|
|
|
pa_atomic_store(&i->before_ramping_v, 0);
|
|
|
|
|
pa_atomic_store(&i->before_ramping_m, 0);
|
|
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
i->thread_info.state = i->state;
|
2008-05-15 23:34:41 +00:00
|
|
|
i->thread_info.attached = FALSE;
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_atomic_store(&i->thread_info.drained, 1);
|
|
|
|
|
i->thread_info.sample_spec = i->sample_spec;
|
|
|
|
|
i->thread_info.resampler = resampler;
|
2009-01-27 04:39:07 +01:00
|
|
|
i->thread_info.soft_volume = i->soft_volume;
|
2007-10-28 19:13:50 +00:00
|
|
|
i->thread_info.muted = i->muted;
|
2008-05-15 23:34:41 +00:00
|
|
|
i->thread_info.requested_sink_latency = (pa_usec_t) -1;
|
|
|
|
|
i->thread_info.rewrite_nbytes = 0;
|
|
|
|
|
i->thread_info.rewrite_flush = FALSE;
|
2009-01-15 00:40:06 +01:00
|
|
|
i->thread_info.dont_rewind_render = FALSE;
|
2008-05-15 23:34:41 +00:00
|
|
|
i->thread_info.underrun_for = (uint64_t) -1;
|
|
|
|
|
i->thread_info.playing_for = 0;
|
2008-06-13 21:56:19 +00:00
|
|
|
i->thread_info.direct_outputs = pa_hashmap_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func);
|
2008-05-15 23:34:41 +00:00
|
|
|
|
|
|
|
|
i->thread_info.render_memblockq = pa_memblockq_new(
|
|
|
|
|
0,
|
|
|
|
|
MEMBLOCKQ_MAXLENGTH,
|
|
|
|
|
0,
|
|
|
|
|
pa_frame_size(&i->sink->sample_spec),
|
|
|
|
|
0,
|
|
|
|
|
1,
|
|
|
|
|
0,
|
|
|
|
|
&i->sink->silence);
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2009-04-10 01:21:16 +02:00
|
|
|
pa_assert_se(pa_idxset_put(core->sink_inputs, i, &i->index) == 0);
|
|
|
|
|
pa_assert_se(pa_idxset_put(i->sink->inputs, pa_sink_input_ref(i), NULL) == 0);
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2009-01-15 18:38:20 +01:00
|
|
|
if (i->client)
|
|
|
|
|
pa_assert_se(pa_idxset_put(i->client->sink_inputs, i, NULL) >= 0);
|
|
|
|
|
|
2009-09-20 03:18:03 +02:00
|
|
|
pt = pa_proplist_to_string_sep(i->proplist, "\n ");
|
|
|
|
|
pa_log_info("Created input %u \"%s\" on %s with sample spec %s and channel map %s\n %s",
|
2006-08-13 16:19:56 +00:00
|
|
|
i->index,
|
2008-05-15 23:34:41 +00:00
|
|
|
pa_strnull(pa_proplist_gets(i->proplist, PA_PROP_MEDIA_NAME)),
|
2006-08-13 16:19:56 +00:00
|
|
|
i->sink->name,
|
2007-11-21 01:30:40 +00:00
|
|
|
pa_sample_spec_snprint(st, sizeof(st), &i->sample_spec),
|
2009-09-20 03:18:03 +02:00
|
|
|
pa_channel_map_snprint(cm, sizeof(cm), &i->channel_map),
|
|
|
|
|
pt);
|
|
|
|
|
pa_xfree(pt);
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
/* Don't forget to call pa_sink_input_put! */
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2009-02-03 03:14:20 +01:00
|
|
|
*_i = i;
|
|
|
|
|
return 0;
|
2004-06-08 23:54:24 +00:00
|
|
|
}
|
|
|
|
|
|
2008-06-20 22:32:41 +02:00
|
|
|
/* Called from main context */
|
2007-10-28 19:13:50 +00:00
|
|
|
static void update_n_corked(pa_sink_input *i, pa_sink_input_state_t state) {
|
|
|
|
|
pa_assert(i);
|
2009-08-13 02:14:19 +02:00
|
|
|
pa_assert_ctl_context();
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2009-01-23 22:38:30 +01:00
|
|
|
if (!i->sink)
|
|
|
|
|
return;
|
|
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
if (i->state == PA_SINK_INPUT_CORKED && state != PA_SINK_INPUT_CORKED)
|
|
|
|
|
pa_assert_se(i->sink->n_corked -- >= 1);
|
|
|
|
|
else if (i->state != PA_SINK_INPUT_CORKED && state == PA_SINK_INPUT_CORKED)
|
|
|
|
|
i->sink->n_corked++;
|
|
|
|
|
}
|
|
|
|
|
|
2008-06-20 22:32:41 +02:00
|
|
|
/* Called from main context */
|
2009-02-03 03:11:31 +01:00
|
|
|
static void sink_input_set_state(pa_sink_input *i, pa_sink_input_state_t state) {
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_sink_input *ssync;
|
|
|
|
|
pa_assert(i);
|
2009-08-13 02:14:19 +02:00
|
|
|
pa_assert_ctl_context();
|
2007-10-28 19:13:50 +00:00
|
|
|
|
|
|
|
|
if (state == PA_SINK_INPUT_DRAINED)
|
|
|
|
|
state = PA_SINK_INPUT_RUNNING;
|
|
|
|
|
|
|
|
|
|
if (i->state == state)
|
2009-02-03 03:11:31 +01:00
|
|
|
return;
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2008-06-20 22:32:41 +02:00
|
|
|
pa_assert_se(pa_asyncmsgq_send(i->sink->asyncmsgq, PA_MSGOBJECT(i), PA_SINK_INPUT_MESSAGE_SET_STATE, PA_UINT_TO_PTR(state), 0, NULL) == 0);
|
2007-10-28 19:13:50 +00:00
|
|
|
|
|
|
|
|
update_n_corked(i, state);
|
|
|
|
|
i->state = state;
|
|
|
|
|
|
|
|
|
|
for (ssync = i->sync_prev; ssync; ssync = ssync->sync_prev) {
|
|
|
|
|
update_n_corked(ssync, state);
|
|
|
|
|
ssync->state = state;
|
|
|
|
|
}
|
|
|
|
|
for (ssync = i->sync_next; ssync; ssync = ssync->sync_next) {
|
|
|
|
|
update_n_corked(ssync, state);
|
|
|
|
|
ssync->state = state;
|
|
|
|
|
}
|
|
|
|
|
|
2008-06-20 22:32:41 +02:00
|
|
|
if (state != PA_SINK_INPUT_UNLINKED) {
|
2009-01-23 22:35:19 +01:00
|
|
|
pa_hook_fire(&i->core->hooks[PA_CORE_HOOK_SINK_INPUT_STATE_CHANGED], i);
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2008-06-20 22:32:41 +02:00
|
|
|
for (ssync = i->sync_prev; ssync; ssync = ssync->sync_prev)
|
2009-01-23 22:35:19 +01:00
|
|
|
pa_hook_fire(&i->core->hooks[PA_CORE_HOOK_SINK_INPUT_STATE_CHANGED], ssync);
|
2008-06-20 22:32:41 +02:00
|
|
|
|
|
|
|
|
for (ssync = i->sync_next; ssync; ssync = ssync->sync_next)
|
2009-01-23 22:35:19 +01:00
|
|
|
pa_hook_fire(&i->core->hooks[PA_CORE_HOOK_SINK_INPUT_STATE_CHANGED], ssync);
|
2008-06-20 22:32:41 +02:00
|
|
|
}
|
|
|
|
|
|
2008-12-17 21:03:17 +01:00
|
|
|
pa_sink_update_status(i->sink);
|
2007-10-28 19:13:50 +00:00
|
|
|
}
|
|
|
|
|
|
2008-06-20 22:32:41 +02:00
|
|
|
/* Called from main context */
|
2007-10-28 19:13:50 +00:00
|
|
|
void pa_sink_input_unlink(pa_sink_input *i) {
|
|
|
|
|
pa_bool_t linked;
|
2008-06-13 21:56:19 +00:00
|
|
|
pa_source_output *o, *p = NULL;
|
2009-08-13 02:14:19 +02:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_assert(i);
|
2009-08-13 02:14:19 +02:00
|
|
|
pa_assert_ctl_context();
|
2007-10-28 19:13:50 +00:00
|
|
|
|
|
|
|
|
/* See pa_sink_unlink() for a couple of comments how this function
|
|
|
|
|
* works */
|
|
|
|
|
|
|
|
|
|
pa_sink_input_ref(i);
|
|
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
linked = PA_SINK_INPUT_IS_LINKED(i->state);
|
2007-10-28 19:13:50 +00:00
|
|
|
|
|
|
|
|
if (linked)
|
2009-01-23 22:35:19 +01:00
|
|
|
pa_hook_fire(&i->core->hooks[PA_CORE_HOOK_SINK_INPUT_UNLINK], i);
|
2007-10-28 19:13:50 +00:00
|
|
|
|
|
|
|
|
if (i->sync_prev)
|
|
|
|
|
i->sync_prev->sync_next = i->sync_next;
|
|
|
|
|
if (i->sync_next)
|
|
|
|
|
i->sync_next->sync_prev = i->sync_prev;
|
|
|
|
|
|
|
|
|
|
i->sync_prev = i->sync_next = NULL;
|
2004-06-08 23:54:24 +00:00
|
|
|
|
2009-01-23 22:38:30 +01:00
|
|
|
pa_idxset_remove_by_data(i->core->sink_inputs, i, NULL);
|
|
|
|
|
|
|
|
|
|
if (i->sink)
|
|
|
|
|
if (pa_idxset_remove_by_data(i->sink->inputs, i, NULL))
|
|
|
|
|
pa_sink_input_unref(i);
|
2004-07-03 00:19:17 +00:00
|
|
|
|
2009-01-15 18:38:20 +01:00
|
|
|
if (i->client)
|
|
|
|
|
pa_idxset_remove_by_data(i->client->sink_inputs, i, NULL);
|
|
|
|
|
|
2008-06-13 21:56:19 +00:00
|
|
|
while ((o = pa_idxset_first(i->direct_outputs, NULL))) {
|
|
|
|
|
pa_assert(o != p);
|
|
|
|
|
pa_source_output_kill(o);
|
|
|
|
|
p = o;
|
|
|
|
|
}
|
|
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
update_n_corked(i, PA_SINK_INPUT_UNLINKED);
|
|
|
|
|
i->state = PA_SINK_INPUT_UNLINKED;
|
2004-09-14 20:53:25 +00:00
|
|
|
|
2009-01-27 04:39:07 +01:00
|
|
|
if (linked && i->sink) {
|
|
|
|
|
/* We might need to update the sink's volume if we are in flat volume mode. */
|
2009-08-19 02:55:02 +02:00
|
|
|
if (i->sink->flags & PA_SINK_FLAT_VOLUME)
|
|
|
|
|
pa_sink_set_volume(i->sink, NULL, FALSE, FALSE);
|
2009-01-27 04:39:07 +01:00
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
if (i->sink->asyncmsgq)
|
2008-06-20 22:32:41 +02:00
|
|
|
pa_assert_se(pa_asyncmsgq_send(i->sink->asyncmsgq, PA_MSGOBJECT(i->sink), PA_SINK_MESSAGE_REMOVE_INPUT, i, 0, NULL) == 0);
|
2009-01-27 04:39:07 +01:00
|
|
|
}
|
2008-05-15 23:34:41 +00:00
|
|
|
|
|
|
|
|
reset_callbacks(i);
|
2007-10-28 19:13:50 +00:00
|
|
|
|
|
|
|
|
if (linked) {
|
2009-01-23 22:35:19 +01:00
|
|
|
pa_subscription_post(i->core, PA_SUBSCRIPTION_EVENT_SINK_INPUT|PA_SUBSCRIPTION_EVENT_REMOVE, i->index);
|
|
|
|
|
pa_hook_fire(&i->core->hooks[PA_CORE_HOOK_SINK_INPUT_UNLINK_POST], i);
|
2007-10-28 19:13:50 +00:00
|
|
|
}
|
2004-09-14 20:53:25 +00:00
|
|
|
|
2009-01-23 22:38:30 +01:00
|
|
|
if (i->sink) {
|
|
|
|
|
pa_sink_update_status(i->sink);
|
|
|
|
|
i->sink = NULL;
|
|
|
|
|
}
|
2008-12-17 21:03:17 +01:00
|
|
|
|
2009-02-25 09:13:19 +01:00
|
|
|
pa_core_maybe_vacuum(i->core);
|
|
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_sink_input_unref(i);
|
2004-09-14 20:53:25 +00:00
|
|
|
}
|
|
|
|
|
|
2008-06-20 22:32:41 +02:00
|
|
|
/* Called from main context */
|
2007-10-28 19:13:50 +00:00
|
|
|
static void sink_input_free(pa_object *o) {
|
|
|
|
|
pa_sink_input* i = PA_SINK_INPUT(o);
|
2004-09-14 20:53:25 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_assert(i);
|
2009-08-13 02:14:19 +02:00
|
|
|
pa_assert_ctl_context();
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_assert(pa_sink_input_refcnt(i) == 0);
|
2004-09-14 20:53:25 +00:00
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
if (PA_SINK_INPUT_IS_LINKED(i->state))
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_sink_input_unlink(i);
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
pa_log_info("Freeing input %u \"%s\"", i->index, pa_strnull(pa_proplist_gets(i->proplist, PA_PROP_MEDIA_NAME)));
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2009-08-22 04:04:23 +02:00
|
|
|
/* Side note: this function must be able to destruct properly any
|
|
|
|
|
* kind of sink input in any state, even those which are
|
|
|
|
|
* "half-moved" or are connected to sinks that have no asyncmsgq
|
|
|
|
|
* and are hence half-destructed themselves! */
|
2004-08-11 00:11:12 +00:00
|
|
|
|
2009-07-16 10:41:34 +08:00
|
|
|
if (i->thread_info.ramp_info.envelope) {
|
|
|
|
|
pa_log_debug ("Freeing envelope\n");
|
|
|
|
|
pa_envelope_free(i->thread_info.ramp_info.envelope);
|
|
|
|
|
i->thread_info.ramp_info.envelope = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
if (i->thread_info.render_memblockq)
|
|
|
|
|
pa_memblockq_free(i->thread_info.render_memblockq);
|
2007-10-28 19:13:50 +00:00
|
|
|
|
|
|
|
|
if (i->thread_info.resampler)
|
|
|
|
|
pa_resampler_free(i->thread_info.resampler);
|
|
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
if (i->proplist)
|
|
|
|
|
pa_proplist_free(i->proplist);
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2008-06-13 21:56:19 +00:00
|
|
|
if (i->direct_outputs)
|
|
|
|
|
pa_idxset_free(i->direct_outputs, NULL, NULL);
|
|
|
|
|
|
|
|
|
|
if (i->thread_info.direct_outputs)
|
|
|
|
|
pa_hashmap_free(i->thread_info.direct_outputs, NULL, NULL);
|
|
|
|
|
|
2006-01-27 16:25:31 +00:00
|
|
|
pa_xfree(i->driver);
|
2004-08-04 16:39:30 +00:00
|
|
|
pa_xfree(i);
|
2004-06-08 23:54:24 +00:00
|
|
|
}
|
|
|
|
|
|
2008-06-20 22:32:41 +02:00
|
|
|
/* Called from main context */
|
2007-10-28 19:13:50 +00:00
|
|
|
void pa_sink_input_put(pa_sink_input *i) {
|
2008-05-15 23:34:41 +00:00
|
|
|
pa_sink_input_state_t state;
|
2009-08-13 02:14:19 +02:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_sink_input_assert_ref(i);
|
2009-08-13 02:14:19 +02:00
|
|
|
pa_assert_ctl_context();
|
2004-09-14 20:53:25 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_assert(i->state == PA_SINK_INPUT_INIT);
|
2008-06-20 22:32:41 +02:00
|
|
|
|
|
|
|
|
/* The following fields must be initialized properly */
|
2008-05-15 23:34:41 +00:00
|
|
|
pa_assert(i->pop);
|
|
|
|
|
pa_assert(i->process_rewind);
|
2008-06-20 22:32:41 +02:00
|
|
|
pa_assert(i->kill);
|
2004-09-14 20:53:25 +00:00
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
state = i->flags & PA_SINK_INPUT_START_CORKED ? PA_SINK_INPUT_CORKED : PA_SINK_INPUT_RUNNING;
|
|
|
|
|
|
|
|
|
|
update_n_corked(i, state);
|
|
|
|
|
i->state = state;
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2009-01-27 04:39:07 +01:00
|
|
|
/* We might need to update the sink's volume if we are in flat volume mode. */
|
2009-08-19 02:55:02 +02:00
|
|
|
if (i->sink->flags & PA_SINK_FLAT_VOLUME)
|
|
|
|
|
pa_sink_set_volume(i->sink, NULL, FALSE, i->save_volume);
|
|
|
|
|
else
|
|
|
|
|
set_real_ratio(i, &i->volume);
|
2009-02-04 18:34:08 +01:00
|
|
|
|
|
|
|
|
i->thread_info.soft_volume = i->soft_volume;
|
|
|
|
|
i->thread_info.muted = i->muted;
|
2009-01-27 04:39:07 +01:00
|
|
|
|
2008-06-20 22:32:41 +02:00
|
|
|
pa_assert_se(pa_asyncmsgq_send(i->sink->asyncmsgq, PA_MSGOBJECT(i->sink), PA_SINK_MESSAGE_ADD_INPUT, i, 0, NULL) == 0);
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2009-01-23 22:35:19 +01:00
|
|
|
pa_subscription_post(i->core, PA_SUBSCRIPTION_EVENT_SINK_INPUT|PA_SUBSCRIPTION_EVENT_NEW, i->index);
|
|
|
|
|
pa_hook_fire(&i->core->hooks[PA_CORE_HOOK_SINK_INPUT_PUT], i);
|
2008-12-17 21:03:17 +01:00
|
|
|
|
|
|
|
|
pa_sink_update_status(i->sink);
|
2004-09-14 20:53:25 +00:00
|
|
|
}
|
|
|
|
|
|
2008-06-20 22:32:41 +02:00
|
|
|
/* Called from main context */
|
2006-01-11 01:17:39 +00:00
|
|
|
void pa_sink_input_kill(pa_sink_input*i) {
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_sink_input_assert_ref(i);
|
2009-08-13 02:14:19 +02:00
|
|
|
pa_assert_ctl_context();
|
2008-05-15 23:34:41 +00:00
|
|
|
pa_assert(PA_SINK_INPUT_IS_LINKED(i->state));
|
2004-06-14 20:30:50 +00:00
|
|
|
|
2008-06-20 22:32:41 +02:00
|
|
|
i->kill(i);
|
2004-06-15 00:29:01 +00:00
|
|
|
}
|
2004-06-18 17:12:50 +00:00
|
|
|
|
2008-06-20 22:32:41 +02:00
|
|
|
/* Called from main context */
|
|
|
|
|
pa_usec_t pa_sink_input_get_latency(pa_sink_input *i, pa_usec_t *sink_latency) {
|
|
|
|
|
pa_usec_t r[2] = { 0, 0 };
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_sink_input_assert_ref(i);
|
2009-08-13 02:14:19 +02:00
|
|
|
pa_assert_ctl_context();
|
2008-05-15 23:34:41 +00:00
|
|
|
pa_assert(PA_SINK_INPUT_IS_LINKED(i->state));
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2008-06-20 22:32:41 +02:00
|
|
|
pa_assert_se(pa_asyncmsgq_send(i->sink->asyncmsgq, PA_MSGOBJECT(i), PA_SINK_INPUT_MESSAGE_GET_LATENCY, r, 0, NULL) == 0);
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2004-06-18 17:12:50 +00:00
|
|
|
if (i->get_latency)
|
2008-06-20 22:32:41 +02:00
|
|
|
r[0] += i->get_latency(i);
|
|
|
|
|
|
|
|
|
|
if (sink_latency)
|
|
|
|
|
*sink_latency = r[1];
|
2004-06-18 17:12:50 +00:00
|
|
|
|
2008-06-20 22:32:41 +02:00
|
|
|
return r[0];
|
2004-06-18 17:12:50 +00:00
|
|
|
}
|
2004-07-02 18:47:03 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
/* Called from thread context */
|
2009-02-03 03:11:31 +01:00
|
|
|
void pa_sink_input_peek(pa_sink_input *i, size_t slength /* in sink frames */, pa_memchunk *chunk, pa_cvolume *volume) {
|
2009-09-11 03:26:25 +02:00
|
|
|
pa_bool_t do_volume_adj_here, need_volume_factor_sink;
|
2008-05-15 23:34:41 +00:00
|
|
|
pa_bool_t volume_is_norm;
|
2009-07-16 10:41:34 +08:00
|
|
|
pa_bool_t ramping;
|
2008-05-15 23:34:41 +00:00
|
|
|
size_t block_size_max_sink, block_size_max_sink_input;
|
|
|
|
|
size_t ilength;
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_sink_input_assert_ref(i);
|
2009-08-13 02:14:19 +02:00
|
|
|
pa_sink_input_assert_io_context(i);
|
2008-05-15 23:34:41 +00:00
|
|
|
pa_assert(PA_SINK_INPUT_IS_LINKED(i->thread_info.state));
|
|
|
|
|
pa_assert(pa_frame_aligned(slength, &i->sink->sample_spec));
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_assert(chunk);
|
|
|
|
|
pa_assert(volume);
|
2004-09-14 20:53:25 +00:00
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
/* pa_log_debug("peek"); */
|
|
|
|
|
|
|
|
|
|
pa_assert(i->thread_info.state == PA_SINK_INPUT_RUNNING ||
|
|
|
|
|
i->thread_info.state == PA_SINK_INPUT_CORKED ||
|
|
|
|
|
i->thread_info.state == PA_SINK_INPUT_DRAINED);
|
|
|
|
|
|
|
|
|
|
block_size_max_sink_input = i->thread_info.resampler ?
|
|
|
|
|
pa_resampler_max_block_size(i->thread_info.resampler) :
|
2009-01-23 22:35:19 +01:00
|
|
|
pa_frame_align(pa_mempool_block_size_max(i->core->mempool), &i->sample_spec);
|
2006-01-27 16:25:31 +00:00
|
|
|
|
2009-01-23 22:35:19 +01:00
|
|
|
block_size_max_sink = pa_frame_align(pa_mempool_block_size_max(i->core->mempool), &i->sink->sample_spec);
|
2006-07-29 15:06:49 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
/* Default buffer size */
|
2008-05-15 23:34:41 +00:00
|
|
|
if (slength <= 0)
|
|
|
|
|
slength = pa_frame_align(CONVERT_BUFFER_LENGTH, &i->sink->sample_spec);
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
if (slength > block_size_max_sink)
|
|
|
|
|
slength = block_size_max_sink;
|
|
|
|
|
|
|
|
|
|
if (i->thread_info.resampler) {
|
|
|
|
|
ilength = pa_resampler_request(i->thread_info.resampler, slength);
|
|
|
|
|
|
|
|
|
|
if (ilength <= 0)
|
|
|
|
|
ilength = pa_frame_align(CONVERT_BUFFER_LENGTH, &i->sample_spec);
|
|
|
|
|
} else
|
|
|
|
|
ilength = slength;
|
|
|
|
|
|
|
|
|
|
if (ilength > block_size_max_sink_input)
|
|
|
|
|
ilength = block_size_max_sink_input;
|
|
|
|
|
|
|
|
|
|
/* If the channel maps of the sink and this stream differ, we need
|
|
|
|
|
* to adjust the volume *before* we resample. Otherwise we can do
|
|
|
|
|
* it after and leave it for the sink code */
|
2004-10-27 14:14:30 +00:00
|
|
|
|
2009-07-16 10:41:34 +08:00
|
|
|
do_volume_adj_here = !pa_channel_map_equal(&i->channel_map, &i->sink->channel_map) || i->thread_info.ramp_info.is_ramping;
|
2009-01-27 04:39:07 +01:00
|
|
|
volume_is_norm = pa_cvolume_is_norm(&i->thread_info.soft_volume) && !i->thread_info.muted;
|
2009-09-11 03:26:25 +02:00
|
|
|
need_volume_factor_sink = !pa_cvolume_is_norm(&i->volume_factor_sink);
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
while (!pa_memblockq_is_readable(i->thread_info.render_memblockq)) {
|
2006-01-11 01:17:39 +00:00
|
|
|
pa_memchunk tchunk;
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
/* There's nothing in our render queue. We need to fill it up
|
|
|
|
|
* with data from the implementor. */
|
2004-07-03 00:19:17 +00:00
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
if (i->thread_info.state == PA_SINK_INPUT_CORKED ||
|
|
|
|
|
i->pop(i, ilength, &tchunk) < 0) {
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
/* OK, we're corked or the implementor didn't give us any
|
|
|
|
|
* data, so let's just hand out silence */
|
|
|
|
|
pa_atomic_store(&i->thread_info.drained, 1);
|
2004-08-22 21:13:58 +00:00
|
|
|
|
2009-04-01 23:05:09 +02:00
|
|
|
pa_memblockq_seek(i->thread_info.render_memblockq, (int64_t) slength, PA_SEEK_RELATIVE, TRUE);
|
2008-05-15 23:34:41 +00:00
|
|
|
i->thread_info.playing_for = 0;
|
|
|
|
|
if (i->thread_info.underrun_for != (uint64_t) -1)
|
|
|
|
|
i->thread_info.underrun_for += ilength;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pa_atomic_store(&i->thread_info.drained, 0);
|
2007-10-28 19:13:50 +00:00
|
|
|
|
|
|
|
|
pa_assert(tchunk.length > 0);
|
2008-05-15 23:34:41 +00:00
|
|
|
pa_assert(tchunk.memblock);
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
i->thread_info.underrun_for = 0;
|
|
|
|
|
i->thread_info.playing_for += tchunk.length;
|
2004-07-03 00:19:17 +00:00
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
while (tchunk.length > 0) {
|
|
|
|
|
pa_memchunk wchunk;
|
2009-09-11 03:26:25 +02:00
|
|
|
pa_bool_t nvfs = need_volume_factor_sink;
|
2004-08-27 01:29:49 +00:00
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
wchunk = tchunk;
|
|
|
|
|
pa_memblock_ref(wchunk.memblock);
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
if (wchunk.length > block_size_max_sink_input)
|
|
|
|
|
wchunk.length = block_size_max_sink_input;
|
|
|
|
|
|
|
|
|
|
/* It might be necessary to adjust the volume here */
|
2009-07-16 10:41:34 +08:00
|
|
|
if (do_volume_adj_here && !volume_is_norm && !i->thread_info.ramp_info.is_ramping) {
|
2008-05-15 23:34:41 +00:00
|
|
|
pa_memchunk_make_writable(&wchunk, 0);
|
|
|
|
|
|
2009-09-11 03:26:25 +02:00
|
|
|
if (i->thread_info.muted) {
|
2008-05-15 23:34:41 +00:00
|
|
|
pa_silence_memchunk(&wchunk, &i->thread_info.sample_spec);
|
2009-09-11 03:26:25 +02:00
|
|
|
nvfs = FALSE;
|
|
|
|
|
|
|
|
|
|
} else if (!i->thread_info.resampler && nvfs) {
|
|
|
|
|
pa_cvolume v;
|
|
|
|
|
|
|
|
|
|
/* If we don't need a resampler we can merge the
|
|
|
|
|
* post and the pre volume adjustment into one */
|
|
|
|
|
|
|
|
|
|
pa_sw_cvolume_multiply(&v, &i->thread_info.soft_volume, &i->volume_factor_sink);
|
|
|
|
|
pa_volume_memchunk(&wchunk, &i->thread_info.sample_spec, &v);
|
|
|
|
|
nvfs = FALSE;
|
|
|
|
|
|
|
|
|
|
} else
|
2009-01-27 04:39:07 +01:00
|
|
|
pa_volume_memchunk(&wchunk, &i->thread_info.sample_spec, &i->thread_info.soft_volume);
|
2008-05-15 23:34:41 +00:00
|
|
|
}
|
|
|
|
|
|
2009-09-11 03:26:25 +02:00
|
|
|
if (!i->thread_info.resampler) {
|
|
|
|
|
|
|
|
|
|
if (nvfs) {
|
|
|
|
|
pa_memchunk_make_writable(&wchunk, 0);
|
|
|
|
|
pa_volume_memchunk(&wchunk, &i->sink->sample_spec, &i->volume_factor_sink);
|
|
|
|
|
}
|
|
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
pa_memblockq_push_align(i->thread_info.render_memblockq, &wchunk);
|
2009-09-11 03:26:25 +02:00
|
|
|
} else {
|
2008-05-15 23:34:41 +00:00
|
|
|
pa_memchunk rchunk;
|
|
|
|
|
pa_resampler_run(i->thread_info.resampler, &wchunk, &rchunk);
|
|
|
|
|
|
|
|
|
|
/* pa_log_debug("pushing %lu", (unsigned long) rchunk.length); */
|
|
|
|
|
|
|
|
|
|
if (rchunk.memblock) {
|
2009-11-11 04:18:10 +01:00
|
|
|
|
|
|
|
|
if (nvfs) {
|
|
|
|
|
pa_memchunk_make_writable(&rchunk, 0);
|
|
|
|
|
pa_volume_memchunk(&rchunk, &i->sink->sample_spec, &i->volume_factor_sink);
|
|
|
|
|
}
|
|
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
pa_memblockq_push_align(i->thread_info.render_memblockq, &rchunk);
|
|
|
|
|
pa_memblock_unref(rchunk.memblock);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pa_memblock_unref(wchunk.memblock);
|
|
|
|
|
|
|
|
|
|
tchunk.index += wchunk.length;
|
|
|
|
|
tchunk.length -= wchunk.length;
|
2006-02-03 12:23:17 +00:00
|
|
|
}
|
|
|
|
|
|
2004-07-03 23:35:12 +00:00
|
|
|
pa_memblock_unref(tchunk.memblock);
|
2004-07-03 00:19:17 +00:00
|
|
|
}
|
|
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
pa_assert_se(pa_memblockq_peek(i->thread_info.render_memblockq, chunk) >= 0);
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
pa_assert(chunk->length > 0);
|
|
|
|
|
pa_assert(chunk->memblock);
|
2004-09-14 20:53:25 +00:00
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
/* pa_log_debug("peeking %lu", (unsigned long) chunk->length); */
|
2004-09-14 20:53:25 +00:00
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
if (chunk->length > block_size_max_sink)
|
|
|
|
|
chunk->length = block_size_max_sink;
|
2004-09-14 20:53:25 +00:00
|
|
|
|
2009-07-16 10:41:34 +08:00
|
|
|
ramping = i->thread_info.ramp_info.is_ramping;
|
|
|
|
|
if (ramping)
|
|
|
|
|
sink_input_volume_ramping(i, chunk);
|
|
|
|
|
|
|
|
|
|
if (!i->thread_info.ramp_info.envelope_dead) {
|
|
|
|
|
i->thread_info.ramp_info.envelope_dying += chunk->length;
|
2009-12-10 15:43:58 +08:00
|
|
|
pa_log_debug("Envelope dying is %d, chunk length is %zu, dead thresholder is %lu\n", i->thread_info.ramp_info.envelope_dying,
|
2009-07-16 10:41:34 +08:00
|
|
|
chunk->length,
|
|
|
|
|
i->sink->thread_info.max_rewind + pa_envelope_length(i->thread_info.ramp_info.envelope));
|
|
|
|
|
|
2009-12-10 15:43:58 +08:00
|
|
|
if (i->thread_info.ramp_info.envelope_dying >= (int32_t) (i->sink->thread_info.max_rewind + pa_envelope_length(i->thread_info.ramp_info.envelope))) {
|
2009-07-16 10:41:34 +08:00
|
|
|
pa_log_debug("RELEASE Envelop");
|
|
|
|
|
i->thread_info.ramp_info.envelope_dead = TRUE;
|
|
|
|
|
sink_input_release_envelope(i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
/* Let's see if we had to apply the volume adjustment ourselves,
|
|
|
|
|
* or if this can be done by the sink for us */
|
2006-01-27 16:25:31 +00:00
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
if (do_volume_adj_here)
|
|
|
|
|
/* We had different channel maps, so we already did the adjustment */
|
|
|
|
|
pa_cvolume_reset(volume, i->sink->sample_spec.channels);
|
|
|
|
|
else if (i->thread_info.muted)
|
|
|
|
|
/* We've both the same channel map, so let's have the sink do the adjustment for us*/
|
|
|
|
|
pa_cvolume_mute(volume, i->sink->sample_spec.channels);
|
|
|
|
|
else
|
2009-01-27 04:39:07 +01:00
|
|
|
*volume = i->thread_info.soft_volume;
|
2004-07-03 00:19:17 +00:00
|
|
|
}
|
|
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
/* Called from thread context */
|
2008-05-15 23:34:41 +00:00
|
|
|
void pa_sink_input_drop(pa_sink_input *i, size_t nbytes /* in sink sample spec */) {
|
2004-07-03 00:19:17 +00:00
|
|
|
|
2009-08-13 02:14:19 +02:00
|
|
|
pa_sink_input_assert_ref(i);
|
|
|
|
|
pa_sink_input_assert_io_context(i);
|
2008-05-15 23:34:41 +00:00
|
|
|
pa_assert(PA_SINK_INPUT_IS_LINKED(i->thread_info.state));
|
|
|
|
|
pa_assert(pa_frame_aligned(nbytes, &i->sink->sample_spec));
|
|
|
|
|
pa_assert(nbytes > 0);
|
2006-07-29 15:06:49 +00:00
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
/* pa_log_debug("dropping %lu", (unsigned long) nbytes); */
|
2006-07-29 15:06:49 +00:00
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
pa_memblockq_drop(i->thread_info.render_memblockq, nbytes);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Called from thread context */
|
|
|
|
|
void pa_sink_input_process_rewind(pa_sink_input *i, size_t nbytes /* in sink sample spec */) {
|
|
|
|
|
size_t lbq;
|
2008-08-03 23:21:51 +02:00
|
|
|
pa_bool_t called = FALSE;
|
2008-05-15 23:34:41 +00:00
|
|
|
|
2009-08-13 02:14:19 +02:00
|
|
|
pa_sink_input_assert_ref(i);
|
|
|
|
|
pa_sink_input_assert_io_context(i);
|
2008-05-15 23:34:41 +00:00
|
|
|
pa_assert(PA_SINK_INPUT_IS_LINKED(i->thread_info.state));
|
|
|
|
|
pa_assert(pa_frame_aligned(nbytes, &i->sink->sample_spec));
|
|
|
|
|
|
|
|
|
|
/* pa_log_debug("rewind(%lu, %lu)", (unsigned long) nbytes, (unsigned long) i->thread_info.rewrite_nbytes); */
|
2006-07-29 15:06:49 +00:00
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
lbq = pa_memblockq_get_length(i->thread_info.render_memblockq);
|
|
|
|
|
|
2009-01-15 00:40:06 +01:00
|
|
|
if (nbytes > 0 && !i->thread_info.dont_rewind_render) {
|
2008-05-15 23:34:41 +00:00
|
|
|
pa_log_debug("Have to rewind %lu bytes on render memblockq.", (unsigned long) nbytes);
|
|
|
|
|
pa_memblockq_rewind(i->thread_info.render_memblockq, nbytes);
|
2009-07-16 10:41:34 +08:00
|
|
|
sink_input_rewind_ramp_info(i, nbytes);
|
2007-10-28 19:13:50 +00:00
|
|
|
}
|
|
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
if (i->thread_info.rewrite_nbytes == (size_t) -1) {
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
/* We were asked to drop all buffered data, and rerequest new
|
|
|
|
|
* data from implementor the next time push() is called */
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2010-01-18 01:33:04 +01:00
|
|
|
pa_memblockq_flush_write(i->thread_info.render_memblockq, TRUE);
|
2006-07-29 15:06:49 +00:00
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
} else if (i->thread_info.rewrite_nbytes > 0) {
|
|
|
|
|
size_t max_rewrite, amount;
|
|
|
|
|
|
|
|
|
|
/* Calculate how much make sense to rewrite at most */
|
|
|
|
|
max_rewrite = nbytes + lbq;
|
|
|
|
|
|
|
|
|
|
/* Transform into local domain */
|
|
|
|
|
if (i->thread_info.resampler)
|
|
|
|
|
max_rewrite = pa_resampler_request(i->thread_info.resampler, max_rewrite);
|
|
|
|
|
|
|
|
|
|
/* Calculate how much of the rewinded data should actually be rewritten */
|
|
|
|
|
amount = PA_MIN(i->thread_info.rewrite_nbytes, max_rewrite);
|
|
|
|
|
|
|
|
|
|
if (amount > 0) {
|
|
|
|
|
pa_log_debug("Have to rewind %lu bytes on implementor.", (unsigned long) amount);
|
2006-07-29 15:06:49 +00:00
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
/* Tell the implementor */
|
|
|
|
|
if (i->process_rewind)
|
|
|
|
|
i->process_rewind(i, amount);
|
2008-06-26 02:56:00 +02:00
|
|
|
called = TRUE;
|
2008-05-15 23:34:41 +00:00
|
|
|
|
|
|
|
|
/* Convert back to to sink domain */
|
|
|
|
|
if (i->thread_info.resampler)
|
|
|
|
|
amount = pa_resampler_result(i->thread_info.resampler, amount);
|
|
|
|
|
|
|
|
|
|
if (amount > 0)
|
|
|
|
|
/* Ok, now update the write pointer */
|
2009-04-01 23:05:09 +02:00
|
|
|
pa_memblockq_seek(i->thread_info.render_memblockq, - ((int64_t) amount), PA_SEEK_RELATIVE, TRUE);
|
2008-05-15 23:34:41 +00:00
|
|
|
|
|
|
|
|
if (i->thread_info.rewrite_flush)
|
|
|
|
|
pa_memblockq_silence(i->thread_info.render_memblockq);
|
|
|
|
|
|
|
|
|
|
/* And reset the resampler */
|
|
|
|
|
if (i->thread_info.resampler)
|
|
|
|
|
pa_resampler_reset(i->thread_info.resampler);
|
|
|
|
|
}
|
2006-07-29 15:06:49 +00:00
|
|
|
}
|
|
|
|
|
|
2008-06-26 02:56:00 +02:00
|
|
|
if (!called)
|
|
|
|
|
if (i->process_rewind)
|
|
|
|
|
i->process_rewind(i, 0);
|
|
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
i->thread_info.rewrite_nbytes = 0;
|
|
|
|
|
i->thread_info.rewrite_flush = FALSE;
|
2009-01-15 00:40:06 +01:00
|
|
|
i->thread_info.dont_rewind_render = FALSE;
|
2008-05-15 23:34:41 +00:00
|
|
|
}
|
|
|
|
|
|
2009-08-13 02:17:24 +02:00
|
|
|
/* Called from thread context */
|
|
|
|
|
size_t pa_sink_input_get_max_rewind(pa_sink_input *i) {
|
|
|
|
|
pa_sink_input_assert_ref(i);
|
|
|
|
|
pa_sink_input_assert_io_context(i);
|
|
|
|
|
|
|
|
|
|
return i->thread_info.resampler ? pa_resampler_request(i->thread_info.resampler, i->sink->thread_info.max_rewind) : i->sink->thread_info.max_rewind;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Called from thread context */
|
|
|
|
|
size_t pa_sink_input_get_max_request(pa_sink_input *i) {
|
|
|
|
|
pa_sink_input_assert_ref(i);
|
|
|
|
|
pa_sink_input_assert_io_context(i);
|
|
|
|
|
|
|
|
|
|
/* We're not verifying the status here, to allow this to be called
|
|
|
|
|
* in the state change handler between _INIT and _RUNNING */
|
|
|
|
|
|
|
|
|
|
return i->thread_info.resampler ? pa_resampler_request(i->thread_info.resampler, i->sink->thread_info.max_request) : i->sink->thread_info.max_request;
|
|
|
|
|
}
|
|
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
/* Called from thread context */
|
|
|
|
|
void pa_sink_input_update_max_rewind(pa_sink_input *i, size_t nbytes /* in the sink's sample spec */) {
|
|
|
|
|
pa_sink_input_assert_ref(i);
|
2009-08-13 02:14:19 +02:00
|
|
|
pa_sink_input_assert_io_context(i);
|
2008-05-15 23:34:41 +00:00
|
|
|
pa_assert(PA_SINK_INPUT_IS_LINKED(i->thread_info.state));
|
|
|
|
|
pa_assert(pa_frame_aligned(nbytes, &i->sink->sample_spec));
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
pa_memblockq_set_maxrewind(i->thread_info.render_memblockq, nbytes);
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
if (i->update_max_rewind)
|
|
|
|
|
i->update_max_rewind(i, i->thread_info.resampler ? pa_resampler_request(i->thread_info.resampler, nbytes) : nbytes);
|
|
|
|
|
}
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2008-06-20 22:32:41 +02:00
|
|
|
/* Called from thread context */
|
|
|
|
|
void pa_sink_input_update_max_request(pa_sink_input *i, size_t nbytes /* in the sink's sample spec */) {
|
|
|
|
|
pa_sink_input_assert_ref(i);
|
2009-08-13 02:14:19 +02:00
|
|
|
pa_sink_input_assert_io_context(i);
|
2008-06-20 22:32:41 +02:00
|
|
|
pa_assert(PA_SINK_INPUT_IS_LINKED(i->thread_info.state));
|
|
|
|
|
pa_assert(pa_frame_aligned(nbytes, &i->sink->sample_spec));
|
|
|
|
|
|
|
|
|
|
if (i->update_max_request)
|
|
|
|
|
i->update_max_request(i, i->thread_info.resampler ? pa_resampler_request(i->thread_info.resampler, nbytes) : nbytes);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Called from thread context */
|
2008-05-15 23:34:41 +00:00
|
|
|
pa_usec_t pa_sink_input_set_requested_latency_within_thread(pa_sink_input *i, pa_usec_t usec) {
|
|
|
|
|
pa_sink_input_assert_ref(i);
|
2009-08-13 02:14:19 +02:00
|
|
|
pa_sink_input_assert_io_context(i);
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2009-04-10 01:26:04 +02:00
|
|
|
if (!(i->sink->flags & PA_SINK_DYNAMIC_LATENCY))
|
2009-08-15 00:48:14 +02:00
|
|
|
usec = i->sink->thread_info.fixed_latency;
|
2009-04-10 01:26:04 +02:00
|
|
|
|
2009-03-30 18:23:48 +02:00
|
|
|
if (usec != (pa_usec_t) -1)
|
2009-05-08 02:02:06 +02:00
|
|
|
usec = PA_CLAMP(usec, i->sink->thread_info.min_latency, i->sink->thread_info.max_latency);
|
2009-03-30 18:23:48 +02:00
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
i->thread_info.requested_sink_latency = usec;
|
2009-08-15 00:48:14 +02:00
|
|
|
pa_sink_invalidate_requested_latency(i->sink, TRUE);
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
return usec;
|
|
|
|
|
}
|
2004-07-03 00:19:17 +00:00
|
|
|
|
2008-06-20 22:32:41 +02:00
|
|
|
/* Called from main context */
|
2008-05-15 23:34:41 +00:00
|
|
|
pa_usec_t pa_sink_input_set_requested_latency(pa_sink_input *i, pa_usec_t usec) {
|
|
|
|
|
pa_sink_input_assert_ref(i);
|
2009-08-13 02:14:19 +02:00
|
|
|
pa_assert_ctl_context();
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2009-03-30 18:23:48 +02:00
|
|
|
if (PA_SINK_INPUT_IS_LINKED(i->state) && i->sink) {
|
2008-06-20 22:32:41 +02:00
|
|
|
pa_assert_se(pa_asyncmsgq_send(i->sink->asyncmsgq, PA_MSGOBJECT(i), PA_SINK_INPUT_MESSAGE_SET_REQUESTED_LATENCY, &usec, 0, NULL) == 0);
|
2009-03-30 18:23:48 +02:00
|
|
|
return usec;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* If this sink input is not realized yet or we are being moved,
|
|
|
|
|
* we have to touch the thread info data directly */
|
|
|
|
|
|
2009-04-01 03:03:20 +02:00
|
|
|
if (i->sink) {
|
2009-04-10 01:26:04 +02:00
|
|
|
if (!(i->sink->flags & PA_SINK_DYNAMIC_LATENCY))
|
2009-08-15 00:48:14 +02:00
|
|
|
usec = pa_sink_get_fixed_latency(i->sink);
|
2008-06-20 22:32:41 +02:00
|
|
|
|
2009-04-10 01:26:04 +02:00
|
|
|
if (usec != (pa_usec_t) -1) {
|
|
|
|
|
pa_usec_t min_latency, max_latency;
|
|
|
|
|
pa_sink_get_latency_range(i->sink, &min_latency, &max_latency);
|
2009-04-01 03:03:20 +02:00
|
|
|
usec = PA_CLAMP(usec, min_latency, max_latency);
|
2009-04-10 01:26:04 +02:00
|
|
|
}
|
2009-04-01 03:03:20 +02:00
|
|
|
}
|
2009-03-30 18:23:48 +02:00
|
|
|
|
|
|
|
|
i->thread_info.requested_sink_latency = usec;
|
2008-05-15 23:34:41 +00:00
|
|
|
|
|
|
|
|
return usec;
|
|
|
|
|
}
|
|
|
|
|
|
2008-06-20 22:32:41 +02:00
|
|
|
/* Called from main context */
|
2008-05-15 23:34:41 +00:00
|
|
|
pa_usec_t pa_sink_input_get_requested_latency(pa_sink_input *i) {
|
|
|
|
|
pa_sink_input_assert_ref(i);
|
2009-08-13 02:14:19 +02:00
|
|
|
pa_assert_ctl_context();
|
2008-05-15 23:34:41 +00:00
|
|
|
|
2009-03-30 18:23:48 +02:00
|
|
|
if (PA_SINK_INPUT_IS_LINKED(i->state) && i->sink) {
|
|
|
|
|
pa_usec_t usec = 0;
|
2008-06-20 22:32:41 +02:00
|
|
|
pa_assert_se(pa_asyncmsgq_send(i->sink->asyncmsgq, PA_MSGOBJECT(i), PA_SINK_INPUT_MESSAGE_GET_REQUESTED_LATENCY, &usec, 0, NULL) == 0);
|
2009-03-30 18:23:48 +02:00
|
|
|
return usec;
|
|
|
|
|
}
|
2008-05-15 23:34:41 +00:00
|
|
|
|
2009-03-30 18:23:48 +02:00
|
|
|
/* If this sink input is not realized yet or we are being moved,
|
|
|
|
|
* we have to touch the thread info data directly */
|
|
|
|
|
|
|
|
|
|
return i->thread_info.requested_sink_latency;
|
2004-07-03 00:19:17 +00:00
|
|
|
}
|
2004-08-15 13:15:51 +00:00
|
|
|
|
2009-08-19 02:55:02 +02:00
|
|
|
/* Called from main context */
|
|
|
|
|
static void set_real_ratio(pa_sink_input *i, const pa_cvolume *v) {
|
|
|
|
|
pa_sink_input_assert_ref(i);
|
|
|
|
|
pa_assert_ctl_context();
|
|
|
|
|
pa_assert(PA_SINK_INPUT_IS_LINKED(i->state));
|
|
|
|
|
pa_assert(!v || pa_cvolume_compatible(v, &i->sample_spec));
|
|
|
|
|
|
|
|
|
|
/* This basically calculates:
|
|
|
|
|
*
|
|
|
|
|
* i->real_ratio := v
|
|
|
|
|
* i->soft_volume := i->real_ratio * i->volume_factor */
|
|
|
|
|
|
|
|
|
|
if (v)
|
|
|
|
|
i->real_ratio = *v;
|
|
|
|
|
else
|
|
|
|
|
pa_cvolume_reset(&i->real_ratio, i->sample_spec.channels);
|
|
|
|
|
|
|
|
|
|
pa_sw_cvolume_multiply(&i->soft_volume, &i->real_ratio, &i->volume_factor);
|
|
|
|
|
/* We don't copy the data to the thread_info data. That's left for someone else to do */
|
|
|
|
|
}
|
|
|
|
|
|
2008-06-20 22:32:41 +02:00
|
|
|
/* Called from main context */
|
2009-04-13 22:50:24 +02:00
|
|
|
void pa_sink_input_set_volume(pa_sink_input *i, const pa_cvolume *volume, pa_bool_t save, pa_bool_t absolute) {
|
2009-11-05 22:54:42 +01:00
|
|
|
/* test ramping -> return pa_sink_input_set_volume_with_ramping(i, volume, save, absolute, 2000 * PA_USEC_PER_MSEC); */
|
|
|
|
|
return pa_sink_input_set_volume_with_ramping(i, volume, save, absolute, 0);
|
2006-01-27 16:25:31 +00:00
|
|
|
}
|
|
|
|
|
|
2008-06-20 22:32:41 +02:00
|
|
|
/* Called from main context */
|
2009-04-13 22:50:24 +02:00
|
|
|
pa_cvolume *pa_sink_input_get_volume(pa_sink_input *i, pa_cvolume *volume, pa_bool_t absolute) {
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_sink_input_assert_ref(i);
|
2009-08-13 02:14:19 +02:00
|
|
|
pa_assert_ctl_context();
|
2008-05-15 23:34:41 +00:00
|
|
|
pa_assert(PA_SINK_INPUT_IS_LINKED(i->state));
|
2006-01-27 16:25:31 +00:00
|
|
|
|
2009-08-19 02:55:02 +02:00
|
|
|
if (absolute || !(i->sink->flags & PA_SINK_FLAT_VOLUME))
|
|
|
|
|
*volume = i->volume;
|
|
|
|
|
else
|
|
|
|
|
*volume = i->reference_ratio;
|
2009-04-13 22:50:24 +02:00
|
|
|
|
|
|
|
|
return volume;
|
2004-08-15 13:15:51 +00:00
|
|
|
}
|
2004-08-22 21:13:58 +00:00
|
|
|
|
2008-06-20 22:32:41 +02:00
|
|
|
/* Called from main context */
|
2009-01-27 23:35:55 +01:00
|
|
|
void pa_sink_input_set_mute(pa_sink_input *i, pa_bool_t mute, pa_bool_t save) {
|
2009-07-16 10:41:34 +08:00
|
|
|
/* test ramping -> return pa_sink_input_set_mute_with_ramping(i, mute, save, 2000 * PA_USEC_PER_MSEC); */
|
|
|
|
|
return pa_sink_input_set_mute_with_ramping(i, mute, save, 0);
|
2007-10-28 19:13:50 +00:00
|
|
|
}
|
|
|
|
|
|
2008-06-20 22:32:41 +02:00
|
|
|
/* Called from main context */
|
|
|
|
|
pa_bool_t pa_sink_input_get_mute(pa_sink_input *i) {
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_sink_input_assert_ref(i);
|
2009-08-13 02:14:19 +02:00
|
|
|
pa_assert_ctl_context();
|
2008-05-15 23:34:41 +00:00
|
|
|
pa_assert(PA_SINK_INPUT_IS_LINKED(i->state));
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2008-06-20 22:32:41 +02:00
|
|
|
return i->muted;
|
2007-10-28 19:13:50 +00:00
|
|
|
}
|
2006-07-28 23:27:16 +00:00
|
|
|
|
2009-01-13 19:06:10 +02:00
|
|
|
/* Called from main thread */
|
2009-02-05 04:07:27 +01:00
|
|
|
void pa_sink_input_update_proplist(pa_sink_input *i, pa_update_mode_t mode, pa_proplist *p) {
|
|
|
|
|
pa_sink_input_assert_ref(i);
|
2009-08-13 02:14:19 +02:00
|
|
|
pa_assert_ctl_context();
|
2009-01-13 19:06:10 +02:00
|
|
|
|
2009-02-22 05:01:32 +01:00
|
|
|
if (p)
|
|
|
|
|
pa_proplist_update(i->proplist, mode, p);
|
2009-01-13 19:06:10 +02:00
|
|
|
|
2010-02-09 21:37:32 +00:00
|
|
|
if (PA_SINK_INPUT_IS_LINKED(i->state)) {
|
2009-02-05 04:07:27 +01:00
|
|
|
pa_hook_fire(&i->core->hooks[PA_CORE_HOOK_SINK_INPUT_PROPLIST_CHANGED], i);
|
|
|
|
|
pa_subscription_post(i->core, PA_SUBSCRIPTION_EVENT_SINK_INPUT|PA_SUBSCRIPTION_EVENT_CHANGE, i->index);
|
|
|
|
|
}
|
2009-01-13 19:06:10 +02:00
|
|
|
}
|
|
|
|
|
|
2008-06-20 22:32:41 +02:00
|
|
|
/* Called from main context */
|
2007-10-28 19:13:50 +00:00
|
|
|
void pa_sink_input_cork(pa_sink_input *i, pa_bool_t b) {
|
|
|
|
|
pa_sink_input_assert_ref(i);
|
2009-08-13 02:14:19 +02:00
|
|
|
pa_assert_ctl_context();
|
2008-05-15 23:34:41 +00:00
|
|
|
pa_assert(PA_SINK_INPUT_IS_LINKED(i->state));
|
2004-08-22 21:13:58 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
sink_input_set_state(i, b ? PA_SINK_INPUT_CORKED : PA_SINK_INPUT_RUNNING);
|
2004-08-22 21:13:58 +00:00
|
|
|
}
|
2004-09-14 17:52:11 +00:00
|
|
|
|
2008-06-20 22:32:41 +02:00
|
|
|
/* Called from main context */
|
2007-10-28 19:13:50 +00:00
|
|
|
int pa_sink_input_set_rate(pa_sink_input *i, uint32_t rate) {
|
|
|
|
|
pa_sink_input_assert_ref(i);
|
2009-08-13 02:14:19 +02:00
|
|
|
pa_assert_ctl_context();
|
2008-05-15 23:34:41 +00:00
|
|
|
pa_assert(PA_SINK_INPUT_IS_LINKED(i->state));
|
2009-02-03 03:14:20 +01:00
|
|
|
pa_return_val_if_fail(i->thread_info.resampler, -PA_ERR_BADSTATE);
|
2004-09-14 17:52:11 +00:00
|
|
|
|
|
|
|
|
if (i->sample_spec.rate == rate)
|
2007-10-28 19:13:50 +00:00
|
|
|
return 0;
|
2004-09-14 17:52:11 +00:00
|
|
|
|
|
|
|
|
i->sample_spec.rate = rate;
|
2007-10-28 19:13:50 +00:00
|
|
|
|
|
|
|
|
pa_asyncmsgq_post(i->sink->asyncmsgq, PA_MSGOBJECT(i), PA_SINK_INPUT_MESSAGE_SET_RATE, PA_UINT_TO_PTR(rate), 0, NULL, NULL);
|
2006-07-29 15:06:49 +00:00
|
|
|
|
2009-01-23 22:35:19 +01:00
|
|
|
pa_subscription_post(i->core, PA_SUBSCRIPTION_EVENT_SINK_INPUT|PA_SUBSCRIPTION_EVENT_CHANGE, i->index);
|
2007-10-28 19:13:50 +00:00
|
|
|
return 0;
|
2004-09-14 17:52:11 +00:00
|
|
|
}
|
2004-09-14 20:53:25 +00:00
|
|
|
|
2008-06-20 22:32:41 +02:00
|
|
|
/* Called from main context */
|
2006-01-11 01:17:39 +00:00
|
|
|
void pa_sink_input_set_name(pa_sink_input *i, const char *name) {
|
2008-05-15 23:34:41 +00:00
|
|
|
const char *old;
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_sink_input_assert_ref(i);
|
2009-08-13 02:14:19 +02:00
|
|
|
pa_assert_ctl_context();
|
2004-09-14 20:53:25 +00:00
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
if (!name && !pa_proplist_contains(i->proplist, PA_PROP_MEDIA_NAME))
|
2006-08-12 02:19:36 +00:00
|
|
|
return;
|
|
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
old = pa_proplist_gets(i->proplist, PA_PROP_MEDIA_NAME);
|
|
|
|
|
|
2009-08-13 02:14:19 +02:00
|
|
|
if (old && name && pa_streq(old, name))
|
2006-08-12 02:19:36 +00:00
|
|
|
return;
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
if (name)
|
|
|
|
|
pa_proplist_sets(i->proplist, PA_PROP_MEDIA_NAME, name);
|
|
|
|
|
else
|
|
|
|
|
pa_proplist_unset(i->proplist, PA_PROP_MEDIA_NAME);
|
2004-09-15 19:16:57 +00:00
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
if (PA_SINK_INPUT_IS_LINKED(i->state)) {
|
2009-01-23 22:35:19 +01:00
|
|
|
pa_hook_fire(&i->core->hooks[PA_CORE_HOOK_SINK_INPUT_PROPLIST_CHANGED], i);
|
|
|
|
|
pa_subscription_post(i->core, PA_SUBSCRIPTION_EVENT_SINK_INPUT|PA_SUBSCRIPTION_EVENT_CHANGE, i->index);
|
2007-10-28 19:13:50 +00:00
|
|
|
}
|
2004-09-14 20:53:25 +00:00
|
|
|
}
|
2004-11-20 16:23:53 +00:00
|
|
|
|
2008-06-20 22:32:41 +02:00
|
|
|
/* Called from main context */
|
2006-01-27 16:25:31 +00:00
|
|
|
pa_resample_method_t pa_sink_input_get_resample_method(pa_sink_input *i) {
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_sink_input_assert_ref(i);
|
2009-08-13 02:14:19 +02:00
|
|
|
pa_assert_ctl_context();
|
2004-11-20 16:23:53 +00:00
|
|
|
|
2009-01-27 00:52:28 +01:00
|
|
|
return i->actual_resample_method;
|
2004-11-20 16:23:53 +00:00
|
|
|
}
|
2006-07-29 15:06:49 +00:00
|
|
|
|
2008-10-21 18:24:45 +02:00
|
|
|
/* Called from main context */
|
2009-01-23 22:38:30 +01:00
|
|
|
pa_bool_t pa_sink_input_may_move(pa_sink_input *i) {
|
2008-10-21 18:24:45 +02:00
|
|
|
pa_sink_input_assert_ref(i);
|
2009-08-13 02:14:19 +02:00
|
|
|
pa_assert_ctl_context();
|
2008-10-21 18:24:45 +02:00
|
|
|
pa_assert(PA_SINK_INPUT_IS_LINKED(i->state));
|
|
|
|
|
|
|
|
|
|
if (i->flags & PA_SINK_INPUT_DONT_MOVE)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
if (i->sync_next || i->sync_prev) {
|
|
|
|
|
pa_log_warn("Moving synchronised streams not supported.");
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-23 22:38:30 +01:00
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Called from main context */
|
|
|
|
|
pa_bool_t pa_sink_input_may_move_to(pa_sink_input *i, pa_sink *dest) {
|
|
|
|
|
pa_sink_input_assert_ref(i);
|
2009-08-13 02:14:19 +02:00
|
|
|
pa_assert_ctl_context();
|
2009-01-23 22:38:30 +01:00
|
|
|
pa_assert(PA_SINK_INPUT_IS_LINKED(i->state));
|
|
|
|
|
pa_sink_assert_ref(dest);
|
|
|
|
|
|
|
|
|
|
if (dest == i->sink)
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
if (!pa_sink_input_may_move(i))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
2008-10-21 18:24:45 +02:00
|
|
|
if (pa_idxset_size(dest->inputs) >= PA_MAX_INPUTS_PER_SINK) {
|
|
|
|
|
pa_log_warn("Failed to move sink input: too many inputs per sink.");
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (i->may_move_to)
|
|
|
|
|
if (!i->may_move_to(i, dest))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2008-06-20 22:32:41 +02:00
|
|
|
/* Called from main context */
|
2009-01-23 22:38:30 +01:00
|
|
|
int pa_sink_input_start_move(pa_sink_input *i) {
|
2008-06-13 21:56:19 +00:00
|
|
|
pa_source_output *o, *p = NULL;
|
2009-02-03 03:14:20 +01:00
|
|
|
int r;
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_sink_input_assert_ref(i);
|
2009-08-13 02:14:19 +02:00
|
|
|
pa_assert_ctl_context();
|
2008-05-15 23:34:41 +00:00
|
|
|
pa_assert(PA_SINK_INPUT_IS_LINKED(i->state));
|
2009-01-23 22:38:30 +01:00
|
|
|
pa_assert(i->sink);
|
2006-07-29 15:06:49 +00:00
|
|
|
|
2009-01-23 22:38:30 +01:00
|
|
|
if (!pa_sink_input_may_move(i))
|
2009-02-03 03:14:20 +01:00
|
|
|
return -PA_ERR_NOTSUPPORTED;
|
2006-07-29 15:06:49 +00:00
|
|
|
|
2009-02-03 03:14:20 +01:00
|
|
|
if ((r = pa_hook_fire(&i->core->hooks[PA_CORE_HOOK_SINK_INPUT_MOVE_START], i)) < 0)
|
|
|
|
|
return r;
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2008-06-13 21:56:19 +00:00
|
|
|
/* Kill directly connected outputs */
|
|
|
|
|
while ((o = pa_idxset_first(i->direct_outputs, NULL))) {
|
|
|
|
|
pa_assert(o != p);
|
|
|
|
|
pa_source_output_kill(o);
|
|
|
|
|
p = o;
|
|
|
|
|
}
|
2009-01-23 22:38:30 +01:00
|
|
|
pa_assert(pa_idxset_isempty(i->direct_outputs));
|
|
|
|
|
|
2009-01-27 04:39:07 +01:00
|
|
|
pa_idxset_remove_by_data(i->sink->inputs, i, NULL);
|
2009-01-23 22:38:30 +01:00
|
|
|
|
|
|
|
|
if (pa_sink_input_get_state(i) == PA_SINK_INPUT_CORKED)
|
|
|
|
|
pa_assert_se(i->sink->n_corked-- >= 1);
|
|
|
|
|
|
2009-08-19 02:55:02 +02:00
|
|
|
if (i->sink->flags & PA_SINK_FLAT_VOLUME)
|
2009-02-03 04:06:52 +01:00
|
|
|
/* We might need to update the sink's volume if we are in flat
|
|
|
|
|
* volume mode. */
|
2009-08-19 02:55:02 +02:00
|
|
|
pa_sink_set_volume(i->sink, NULL, FALSE, FALSE);
|
2009-01-27 04:39:07 +01:00
|
|
|
|
|
|
|
|
pa_assert_se(pa_asyncmsgq_send(i->sink->asyncmsgq, PA_MSGOBJECT(i->sink), PA_SINK_MESSAGE_START_MOVE, i, 0, NULL) == 0);
|
2009-01-23 22:38:30 +01:00
|
|
|
|
2009-01-27 04:39:07 +01:00
|
|
|
pa_sink_update_status(i->sink);
|
2009-09-11 03:26:25 +02:00
|
|
|
pa_cvolume_remap(&i->volume_factor_sink, &i->sink->channel_map, &i->channel_map);
|
2009-01-27 04:39:07 +01:00
|
|
|
i->sink = NULL;
|
2009-01-23 22:38:30 +01:00
|
|
|
|
2009-04-10 01:21:16 +02:00
|
|
|
pa_sink_input_unref(i);
|
|
|
|
|
|
2009-01-23 22:38:30 +01:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Called from main context */
|
2009-01-27 23:35:55 +01:00
|
|
|
int pa_sink_input_finish_move(pa_sink_input *i, pa_sink *dest, pa_bool_t save) {
|
2009-01-23 22:38:30 +01:00
|
|
|
pa_resampler *new_resampler;
|
|
|
|
|
|
|
|
|
|
pa_sink_input_assert_ref(i);
|
2009-08-13 02:14:19 +02:00
|
|
|
pa_assert_ctl_context();
|
2009-01-23 22:38:30 +01:00
|
|
|
pa_assert(PA_SINK_INPUT_IS_LINKED(i->state));
|
|
|
|
|
pa_assert(!i->sink);
|
|
|
|
|
pa_sink_assert_ref(dest);
|
|
|
|
|
|
|
|
|
|
if (!pa_sink_input_may_move_to(i, dest))
|
2009-02-03 03:14:20 +01:00
|
|
|
return -PA_ERR_NOTSUPPORTED;
|
2008-06-13 21:56:19 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
if (i->thread_info.resampler &&
|
2009-01-23 22:38:30 +01:00
|
|
|
pa_sample_spec_equal(pa_resampler_output_sample_spec(i->thread_info.resampler), &dest->sample_spec) &&
|
|
|
|
|
pa_channel_map_equal(pa_resampler_output_channel_map(i->thread_info.resampler), &dest->channel_map))
|
2006-07-29 15:06:49 +00:00
|
|
|
|
|
|
|
|
/* Try to reuse the old resampler if possible */
|
2007-10-28 19:13:50 +00:00
|
|
|
new_resampler = i->thread_info.resampler;
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2006-08-13 17:30:51 +00:00
|
|
|
else if ((i->flags & PA_SINK_INPUT_VARIABLE_RATE) ||
|
2007-10-28 19:13:50 +00:00
|
|
|
!pa_sample_spec_equal(&i->sample_spec, &dest->sample_spec) ||
|
|
|
|
|
!pa_channel_map_equal(&i->channel_map, &dest->channel_map)) {
|
2006-07-29 15:06:49 +00:00
|
|
|
|
|
|
|
|
/* Okey, we need a new resampler for the new sink */
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2006-07-29 15:06:49 +00:00
|
|
|
if (!(new_resampler = pa_resampler_new(
|
2009-01-23 22:35:19 +01:00
|
|
|
i->core->mempool,
|
2006-07-29 15:06:49 +00:00
|
|
|
&i->sample_spec, &i->channel_map,
|
|
|
|
|
&dest->sample_spec, &dest->channel_map,
|
2009-01-27 00:52:28 +01:00
|
|
|
i->requested_resample_method,
|
2007-11-21 01:30:40 +00:00
|
|
|
((i->flags & PA_SINK_INPUT_VARIABLE_RATE) ? PA_RESAMPLER_VARIABLE_RATE : 0) |
|
|
|
|
|
((i->flags & PA_SINK_INPUT_NO_REMAP) ? PA_RESAMPLER_NO_REMAP : 0) |
|
|
|
|
|
(i->core->disable_remixing || (i->flags & PA_SINK_INPUT_NO_REMIX) ? PA_RESAMPLER_NO_REMIX : 0)))) {
|
2006-08-18 21:38:40 +00:00
|
|
|
pa_log_warn("Unsupported resampling operation.");
|
2009-02-03 03:14:20 +01:00
|
|
|
return -PA_ERR_NOTSUPPORTED;
|
2006-07-29 15:06:49 +00:00
|
|
|
}
|
2007-10-28 19:13:50 +00:00
|
|
|
} else
|
|
|
|
|
new_resampler = NULL;
|
|
|
|
|
|
2009-03-30 18:21:34 +02:00
|
|
|
if (i->moving)
|
2009-04-01 03:04:39 +02:00
|
|
|
i->moving(i, dest);
|
2009-03-30 18:21:34 +02:00
|
|
|
|
2009-02-03 03:14:20 +01:00
|
|
|
i->sink = dest;
|
|
|
|
|
i->save_sink = save;
|
2009-04-10 01:21:16 +02:00
|
|
|
pa_idxset_put(dest->inputs, pa_sink_input_ref(i), NULL);
|
2009-02-03 03:14:20 +01:00
|
|
|
|
2009-09-11 03:26:25 +02:00
|
|
|
pa_cvolume_remap(&i->volume_factor_sink, &i->channel_map, &i->sink->channel_map);
|
|
|
|
|
|
2009-02-03 03:14:20 +01:00
|
|
|
if (pa_sink_input_get_state(i) == PA_SINK_INPUT_CORKED)
|
|
|
|
|
i->sink->n_corked++;
|
|
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
/* Replace resampler and render queue */
|
2007-10-28 19:13:50 +00:00
|
|
|
if (new_resampler != i->thread_info.resampler) {
|
2008-05-15 23:34:41 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
if (i->thread_info.resampler)
|
|
|
|
|
pa_resampler_free(i->thread_info.resampler);
|
|
|
|
|
i->thread_info.resampler = new_resampler;
|
2006-07-29 15:06:49 +00:00
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
pa_memblockq_free(i->thread_info.render_memblockq);
|
|
|
|
|
|
|
|
|
|
i->thread_info.render_memblockq = pa_memblockq_new(
|
|
|
|
|
0,
|
|
|
|
|
MEMBLOCKQ_MAXLENGTH,
|
|
|
|
|
0,
|
|
|
|
|
pa_frame_size(&i->sink->sample_spec),
|
|
|
|
|
0,
|
|
|
|
|
1,
|
|
|
|
|
0,
|
|
|
|
|
&i->sink->silence);
|
2006-07-29 15:06:49 +00:00
|
|
|
}
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_sink_update_status(dest);
|
2009-01-27 04:39:07 +01:00
|
|
|
|
|
|
|
|
if (i->sink->flags & PA_SINK_FLAT_VOLUME) {
|
2009-08-19 02:55:02 +02:00
|
|
|
pa_cvolume remapped;
|
2009-02-03 04:06:52 +01:00
|
|
|
|
2009-08-19 02:55:02 +02:00
|
|
|
/* Make relative volumes absolute */
|
|
|
|
|
remapped = dest->reference_volume;
|
|
|
|
|
pa_cvolume_remap(&remapped, &dest->channel_map, &i->channel_map);
|
|
|
|
|
pa_sw_cvolume_multiply(&i->volume, &i->reference_ratio, &remapped);
|
2009-02-03 04:06:52 +01:00
|
|
|
|
|
|
|
|
/* We might need to update the sink's volume if we are in flat volume mode. */
|
2009-08-19 02:55:02 +02:00
|
|
|
pa_sink_set_volume(i->sink, NULL, FALSE, i->save_volume);
|
2009-01-27 04:39:07 +01:00
|
|
|
}
|
|
|
|
|
|
2008-06-20 22:32:41 +02:00
|
|
|
pa_assert_se(pa_asyncmsgq_send(i->sink->asyncmsgq, PA_MSGOBJECT(i->sink), PA_SINK_MESSAGE_FINISH_MOVE, i, 0, NULL) == 0);
|
2008-05-15 23:34:41 +00:00
|
|
|
|
2009-01-23 22:38:30 +01:00
|
|
|
pa_log_debug("Successfully moved sink input %i to %s.", i->index, dest->name);
|
|
|
|
|
|
|
|
|
|
/* Notify everyone */
|
|
|
|
|
pa_hook_fire(&i->core->hooks[PA_CORE_HOOK_SINK_INPUT_MOVE_FINISH], i);
|
2009-08-21 02:56:17 +02:00
|
|
|
|
|
|
|
|
if (i->volume_changed)
|
|
|
|
|
i->volume_changed(i);
|
|
|
|
|
|
2009-01-23 22:38:30 +01:00
|
|
|
pa_subscription_post(i->core, PA_SUBSCRIPTION_EVENT_SINK_INPUT|PA_SUBSCRIPTION_EVENT_CHANGE, i->index);
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2009-01-23 22:38:30 +01:00
|
|
|
return 0;
|
|
|
|
|
}
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2009-08-15 00:03:50 +02:00
|
|
|
/* Called from main context */
|
|
|
|
|
void pa_sink_input_fail_move(pa_sink_input *i) {
|
|
|
|
|
|
|
|
|
|
pa_sink_input_assert_ref(i);
|
|
|
|
|
pa_assert_ctl_context();
|
|
|
|
|
pa_assert(PA_SINK_INPUT_IS_LINKED(i->state));
|
|
|
|
|
pa_assert(!i->sink);
|
|
|
|
|
|
|
|
|
|
/* Check if someone wants this sink input? */
|
|
|
|
|
if (pa_hook_fire(&i->core->hooks[PA_CORE_HOOK_SINK_INPUT_MOVE_FAIL], i) == PA_HOOK_STOP)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (i->moving)
|
|
|
|
|
i->moving(i, NULL);
|
|
|
|
|
|
|
|
|
|
pa_sink_input_kill(i);
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-23 22:38:30 +01:00
|
|
|
/* Called from main context */
|
2009-01-27 23:35:55 +01:00
|
|
|
int pa_sink_input_move_to(pa_sink_input *i, pa_sink *dest, pa_bool_t save) {
|
2009-02-03 03:14:20 +01:00
|
|
|
int r;
|
|
|
|
|
|
2009-01-23 22:38:30 +01:00
|
|
|
pa_sink_input_assert_ref(i);
|
2009-08-13 02:14:19 +02:00
|
|
|
pa_assert_ctl_context();
|
2009-01-23 22:38:30 +01:00
|
|
|
pa_assert(PA_SINK_INPUT_IS_LINKED(i->state));
|
2009-01-27 00:56:57 +01:00
|
|
|
pa_assert(i->sink);
|
2009-01-23 22:38:30 +01:00
|
|
|
pa_sink_assert_ref(dest);
|
|
|
|
|
|
|
|
|
|
if (dest == i->sink)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
if (!pa_sink_input_may_move_to(i, dest))
|
2009-02-03 03:14:20 +01:00
|
|
|
return -PA_ERR_NOTSUPPORTED;
|
2009-01-23 22:38:30 +01:00
|
|
|
|
2009-04-10 01:21:16 +02:00
|
|
|
pa_sink_input_ref(i);
|
|
|
|
|
|
|
|
|
|
if ((r = pa_sink_input_start_move(i)) < 0) {
|
|
|
|
|
pa_sink_input_unref(i);
|
2009-02-03 03:14:20 +01:00
|
|
|
return r;
|
2009-04-10 01:21:16 +02:00
|
|
|
}
|
2009-01-23 22:38:30 +01:00
|
|
|
|
2009-04-10 01:21:16 +02:00
|
|
|
if ((r = pa_sink_input_finish_move(i, dest, save)) < 0) {
|
2009-08-15 00:03:50 +02:00
|
|
|
pa_sink_input_fail_move(i);
|
2009-04-10 01:21:16 +02:00
|
|
|
pa_sink_input_unref(i);
|
2009-02-03 03:14:20 +01:00
|
|
|
return r;
|
2009-04-10 01:21:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pa_sink_input_unref(i);
|
2006-07-29 15:06:49 +00:00
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2008-06-20 22:32:41 +02:00
|
|
|
/* Called from IO thread context */
|
2008-05-15 23:34:41 +00:00
|
|
|
void pa_sink_input_set_state_within_thread(pa_sink_input *i, pa_sink_input_state_t state) {
|
2008-06-27 00:28:17 +02:00
|
|
|
pa_bool_t corking, uncorking;
|
2009-08-13 02:14:19 +02:00
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
pa_sink_input_assert_ref(i);
|
2009-08-13 02:14:19 +02:00
|
|
|
pa_sink_input_assert_io_context(i);
|
2008-05-15 23:34:41 +00:00
|
|
|
|
|
|
|
|
if (state == i->thread_info.state)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if ((state == PA_SINK_INPUT_DRAINED || state == PA_SINK_INPUT_RUNNING) &&
|
|
|
|
|
!(i->thread_info.state == PA_SINK_INPUT_DRAINED || i->thread_info.state != PA_SINK_INPUT_RUNNING))
|
|
|
|
|
pa_atomic_store(&i->thread_info.drained, 1);
|
|
|
|
|
|
2008-06-27 00:28:17 +02:00
|
|
|
corking = state == PA_SINK_INPUT_CORKED && i->thread_info.state == PA_SINK_INPUT_RUNNING;
|
|
|
|
|
uncorking = i->thread_info.state == PA_SINK_INPUT_CORKED && state == PA_SINK_INPUT_RUNNING;
|
|
|
|
|
|
|
|
|
|
if (i->state_change)
|
|
|
|
|
i->state_change(i, state);
|
|
|
|
|
|
|
|
|
|
i->thread_info.state = state;
|
|
|
|
|
|
|
|
|
|
if (corking) {
|
|
|
|
|
|
|
|
|
|
pa_log_debug("Requesting rewind due to corking");
|
2008-05-15 23:34:41 +00:00
|
|
|
|
|
|
|
|
/* This will tell the implementing sink input driver to rewind
|
|
|
|
|
* so that the unplayed already mixed data is not lost */
|
2009-01-15 00:40:06 +01:00
|
|
|
pa_sink_input_request_rewind(i, 0, TRUE, TRUE, FALSE);
|
2008-05-15 23:34:41 +00:00
|
|
|
|
2008-06-27 00:28:17 +02:00
|
|
|
} else if (uncorking) {
|
|
|
|
|
|
2008-10-06 02:26:08 +02:00
|
|
|
i->thread_info.underrun_for = (uint64_t) -1;
|
|
|
|
|
i->thread_info.playing_for = 0;
|
|
|
|
|
|
2008-06-27 00:28:17 +02:00
|
|
|
pa_log_debug("Requesting rewind due to uncorking");
|
2008-05-15 23:34:41 +00:00
|
|
|
|
|
|
|
|
/* OK, we're being uncorked. Make sure we're not rewound when
|
|
|
|
|
* the hw buffer is remixed and request a remix. */
|
2009-01-15 00:40:06 +01:00
|
|
|
pa_sink_input_request_rewind(i, 0, FALSE, TRUE, TRUE);
|
2008-05-15 23:34:41 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-06-20 22:32:41 +02:00
|
|
|
/* Called from thread context, except when it is not. */
|
2007-10-28 19:13:50 +00:00
|
|
|
int pa_sink_input_process_msg(pa_msgobject *o, int code, void *userdata, int64_t offset, pa_memchunk *chunk) {
|
|
|
|
|
pa_sink_input *i = PA_SINK_INPUT(o);
|
|
|
|
|
pa_sink_input_assert_ref(i);
|
|
|
|
|
|
|
|
|
|
switch (code) {
|
2008-06-20 22:32:41 +02:00
|
|
|
|
2009-01-27 04:39:07 +01:00
|
|
|
case PA_SINK_INPUT_MESSAGE_SET_SOFT_VOLUME:
|
2009-07-16 10:41:34 +08:00
|
|
|
if (pa_atomic_load(&i->before_ramping_v))
|
|
|
|
|
i->thread_info.future_soft_volume = i->soft_volume;
|
|
|
|
|
|
2009-01-27 04:39:07 +01:00
|
|
|
if (!pa_cvolume_equal(&i->thread_info.soft_volume, &i->soft_volume)) {
|
2009-07-16 10:41:34 +08:00
|
|
|
if (!pa_atomic_load(&i->before_ramping_v))
|
|
|
|
|
i->thread_info.soft_volume = i->soft_volume;
|
2009-01-27 04:39:07 +01:00
|
|
|
pa_sink_input_request_rewind(i, 0, TRUE, FALSE, FALSE);
|
|
|
|
|
}
|
2007-10-28 19:13:50 +00:00
|
|
|
return 0;
|
|
|
|
|
|
2009-01-27 04:39:07 +01:00
|
|
|
case PA_SINK_INPUT_MESSAGE_SET_SOFT_MUTE:
|
2009-07-16 10:41:34 +08:00
|
|
|
if (pa_atomic_load(&i->before_ramping_m))
|
|
|
|
|
i->thread_info.future_muted = i->muted;
|
|
|
|
|
|
2009-01-27 04:39:07 +01:00
|
|
|
if (i->thread_info.muted != i->muted) {
|
2009-07-16 10:41:34 +08:00
|
|
|
if (!pa_atomic_load(&i->before_ramping_m))
|
|
|
|
|
i->thread_info.muted = i->muted;
|
2009-01-27 04:39:07 +01:00
|
|
|
pa_sink_input_request_rewind(i, 0, TRUE, FALSE, FALSE);
|
|
|
|
|
}
|
2007-10-28 19:13:50 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
case PA_SINK_INPUT_MESSAGE_GET_LATENCY: {
|
|
|
|
|
pa_usec_t *r = userdata;
|
2008-06-20 22:32:41 +02:00
|
|
|
|
|
|
|
|
r[0] += pa_bytes_to_usec(pa_memblockq_get_length(i->thread_info.render_memblockq), &i->sink->sample_spec);
|
2009-04-14 01:03:10 +02:00
|
|
|
r[1] += pa_sink_get_latency_within_thread(i->sink);
|
2007-10-28 19:13:50 +00:00
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case PA_SINK_INPUT_MESSAGE_SET_RATE:
|
|
|
|
|
|
|
|
|
|
i->thread_info.sample_spec.rate = PA_PTR_TO_UINT(userdata);
|
|
|
|
|
pa_resampler_set_input_rate(i->thread_info.resampler, PA_PTR_TO_UINT(userdata));
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
case PA_SINK_INPUT_MESSAGE_SET_STATE: {
|
|
|
|
|
pa_sink_input *ssync;
|
|
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
pa_sink_input_set_state_within_thread(i, PA_PTR_TO_UINT(userdata));
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
for (ssync = i->thread_info.sync_prev; ssync; ssync = ssync->thread_info.sync_prev)
|
|
|
|
|
pa_sink_input_set_state_within_thread(ssync, PA_PTR_TO_UINT(userdata));
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
for (ssync = i->thread_info.sync_next; ssync; ssync = ssync->thread_info.sync_next)
|
|
|
|
|
pa_sink_input_set_state_within_thread(ssync, PA_PTR_TO_UINT(userdata));
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2008-06-20 22:32:41 +02:00
|
|
|
case PA_SINK_INPUT_MESSAGE_SET_REQUESTED_LATENCY: {
|
|
|
|
|
pa_usec_t *usec = userdata;
|
2008-05-15 23:34:41 +00:00
|
|
|
|
2008-06-20 22:32:41 +02:00
|
|
|
*usec = pa_sink_input_set_requested_latency_within_thread(i, *usec);
|
2008-05-15 23:34:41 +00:00
|
|
|
return 0;
|
2008-06-20 22:32:41 +02:00
|
|
|
}
|
2008-05-15 23:34:41 +00:00
|
|
|
|
|
|
|
|
case PA_SINK_INPUT_MESSAGE_GET_REQUESTED_LATENCY: {
|
|
|
|
|
pa_usec_t *r = userdata;
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
*r = i->thread_info.requested_sink_latency;
|
2007-10-28 19:13:50 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
2009-07-16 10:41:34 +08:00
|
|
|
|
|
|
|
|
case PA_SINK_INPUT_MESSAGE_SET_ENVELOPE: {
|
|
|
|
|
if (!i->thread_info.ramp_info.envelope)
|
|
|
|
|
i->thread_info.ramp_info.envelope = pa_envelope_new(&i->sink->sample_spec);
|
|
|
|
|
|
|
|
|
|
if (i->thread_info.ramp_info.envelope && i->thread_info.ramp_info.item) {
|
|
|
|
|
pa_envelope_remove(i->thread_info.ramp_info.envelope, i->thread_info.ramp_info.item);
|
|
|
|
|
i->thread_info.ramp_info.item = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
i->thread_info.ramp_info.item = pa_envelope_add(i->thread_info.ramp_info.envelope, &i->using_def);
|
|
|
|
|
i->thread_info.ramp_info.is_ramping = TRUE;
|
|
|
|
|
i->thread_info.ramp_info.envelope_dead = FALSE;
|
|
|
|
|
i->thread_info.ramp_info.envelope_dying = 0;
|
|
|
|
|
|
|
|
|
|
if (i->thread_info.ramp_info.envelope)
|
|
|
|
|
pa_envelope_restart(i->thread_info.ramp_info.envelope);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2007-10-28 19:13:50 +00:00
|
|
|
}
|
|
|
|
|
|
2009-02-03 03:14:20 +01:00
|
|
|
return -PA_ERR_NOTIMPLEMENTED;
|
2007-10-28 19:13:50 +00:00
|
|
|
}
|
|
|
|
|
|
2008-06-20 22:32:41 +02:00
|
|
|
/* Called from main thread */
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_sink_input_state_t pa_sink_input_get_state(pa_sink_input *i) {
|
|
|
|
|
pa_sink_input_assert_ref(i);
|
2009-08-13 02:14:19 +02:00
|
|
|
pa_assert_ctl_context();
|
2007-10-28 19:13:50 +00:00
|
|
|
|
|
|
|
|
if (i->state == PA_SINK_INPUT_RUNNING || i->state == PA_SINK_INPUT_DRAINED)
|
|
|
|
|
return pa_atomic_load(&i->thread_info.drained) ? PA_SINK_INPUT_DRAINED : PA_SINK_INPUT_RUNNING;
|
|
|
|
|
|
|
|
|
|
return i->state;
|
|
|
|
|
}
|
2008-05-15 23:34:41 +00:00
|
|
|
|
|
|
|
|
/* Called from IO context */
|
|
|
|
|
pa_bool_t pa_sink_input_safe_to_remove(pa_sink_input *i) {
|
|
|
|
|
pa_sink_input_assert_ref(i);
|
2009-08-13 02:14:19 +02:00
|
|
|
pa_sink_input_assert_io_context(i);
|
2008-05-15 23:34:41 +00:00
|
|
|
|
|
|
|
|
if (PA_SINK_INPUT_IS_LINKED(i->thread_info.state))
|
|
|
|
|
return pa_memblockq_is_empty(i->thread_info.render_memblockq);
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2008-06-20 22:32:41 +02:00
|
|
|
/* Called from IO context */
|
2009-08-27 00:07:15 +02:00
|
|
|
void pa_sink_input_request_rewind(
|
|
|
|
|
pa_sink_input *i,
|
|
|
|
|
size_t nbytes /* in our sample spec */,
|
|
|
|
|
pa_bool_t rewrite,
|
|
|
|
|
pa_bool_t flush,
|
|
|
|
|
pa_bool_t dont_rewind_render) {
|
|
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
size_t lbq;
|
|
|
|
|
|
|
|
|
|
/* If 'rewrite' is TRUE the sink is rewound as far as requested
|
|
|
|
|
* and possible and the exact value of this is passed back the
|
|
|
|
|
* implementor via process_rewind(). If 'flush' is also TRUE all
|
|
|
|
|
* already rendered data is also dropped.
|
|
|
|
|
*
|
|
|
|
|
* If 'rewrite' is FALSE the sink is rewound as far as requested
|
|
|
|
|
* and possible and the already rendered data is dropped so that
|
|
|
|
|
* in the next iteration we read new data from the
|
2009-01-15 00:40:06 +01:00
|
|
|
* implementor. This implies 'flush' is TRUE. If
|
|
|
|
|
* dont_rewind_render is TRUE then the render memblockq is not
|
|
|
|
|
* rewound. */
|
2008-05-15 23:34:41 +00:00
|
|
|
|
2009-08-27 00:07:15 +02:00
|
|
|
/* nbytes = 0 means maximum rewind request */
|
|
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
pa_sink_input_assert_ref(i);
|
2009-08-13 02:14:19 +02:00
|
|
|
pa_sink_input_assert_io_context(i);
|
2009-08-27 00:07:15 +02:00
|
|
|
pa_assert(rewrite || flush);
|
|
|
|
|
pa_assert(!dont_rewind_render || !rewrite);
|
2008-06-26 02:56:00 +02:00
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
/* We don't take rewind requests while we are corked */
|
|
|
|
|
if (i->thread_info.state == PA_SINK_INPUT_CORKED)
|
|
|
|
|
return;
|
|
|
|
|
|
2009-08-27 00:07:15 +02:00
|
|
|
nbytes = PA_MAX(i->thread_info.rewrite_nbytes, nbytes);
|
|
|
|
|
|
|
|
|
|
/* pa_log_debug("request rewrite %zu", nbytes); */
|
2008-05-15 23:34:41 +00:00
|
|
|
|
|
|
|
|
/* Calculate how much we can rewind locally without having to
|
|
|
|
|
* touch the sink */
|
|
|
|
|
if (rewrite)
|
|
|
|
|
lbq = pa_memblockq_get_length(i->thread_info.render_memblockq);
|
|
|
|
|
else
|
|
|
|
|
lbq = 0;
|
|
|
|
|
|
|
|
|
|
/* Check if rewinding for the maximum is requested, and if so, fix up */
|
|
|
|
|
if (nbytes <= 0) {
|
|
|
|
|
|
|
|
|
|
/* Calculate maximum number of bytes that could be rewound in theory */
|
|
|
|
|
nbytes = i->sink->thread_info.max_rewind + lbq;
|
|
|
|
|
|
|
|
|
|
/* Transform from sink domain */
|
|
|
|
|
if (i->thread_info.resampler)
|
|
|
|
|
nbytes = pa_resampler_request(i->thread_info.resampler, nbytes);
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-27 00:07:15 +02:00
|
|
|
/* Remember how much we actually want to rewrite */
|
2008-12-21 17:55:29 +01:00
|
|
|
if (i->thread_info.rewrite_nbytes != (size_t) -1) {
|
|
|
|
|
if (rewrite) {
|
|
|
|
|
/* Make sure to not overwrite over underruns */
|
|
|
|
|
if (nbytes > i->thread_info.playing_for)
|
|
|
|
|
nbytes = (size_t) i->thread_info.playing_for;
|
2008-05-15 23:34:41 +00:00
|
|
|
|
2008-12-21 17:55:29 +01:00
|
|
|
i->thread_info.rewrite_nbytes = nbytes;
|
|
|
|
|
} else
|
|
|
|
|
i->thread_info.rewrite_nbytes = (size_t) -1;
|
|
|
|
|
}
|
2008-05-15 23:34:41 +00:00
|
|
|
|
2008-12-21 17:55:29 +01:00
|
|
|
i->thread_info.rewrite_flush =
|
|
|
|
|
i->thread_info.rewrite_flush ||
|
|
|
|
|
(flush && i->thread_info.rewrite_nbytes != 0);
|
2008-05-15 23:34:41 +00:00
|
|
|
|
2009-01-15 00:40:06 +01:00
|
|
|
i->thread_info.dont_rewind_render =
|
|
|
|
|
i->thread_info.dont_rewind_render ||
|
|
|
|
|
dont_rewind_render;
|
|
|
|
|
|
2008-12-21 17:55:29 +01:00
|
|
|
if (nbytes != (size_t) -1) {
|
2008-05-15 23:34:41 +00:00
|
|
|
|
2008-12-21 17:55:29 +01:00
|
|
|
/* Transform to sink domain */
|
|
|
|
|
if (i->thread_info.resampler)
|
|
|
|
|
nbytes = pa_resampler_result(i->thread_info.resampler, nbytes);
|
|
|
|
|
|
|
|
|
|
if (nbytes > lbq)
|
|
|
|
|
pa_sink_request_rewind(i->sink, nbytes - lbq);
|
|
|
|
|
else
|
|
|
|
|
/* This call will make sure process_rewind() is called later */
|
|
|
|
|
pa_sink_request_rewind(i->sink, 0);
|
|
|
|
|
}
|
2008-05-15 23:34:41 +00:00
|
|
|
}
|
|
|
|
|
|
2008-06-20 22:32:41 +02:00
|
|
|
/* Called from main context */
|
2008-05-15 23:34:41 +00:00
|
|
|
pa_memchunk* pa_sink_input_get_silence(pa_sink_input *i, pa_memchunk *ret) {
|
|
|
|
|
pa_sink_input_assert_ref(i);
|
2009-08-13 02:14:19 +02:00
|
|
|
pa_assert_ctl_context();
|
2008-05-15 23:34:41 +00:00
|
|
|
pa_assert(ret);
|
|
|
|
|
|
2009-08-13 02:14:19 +02:00
|
|
|
/* FIXME: Shouldn't access resampler object from main context! */
|
|
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
pa_silence_memchunk_get(
|
2009-01-23 22:35:19 +01:00
|
|
|
&i->core->silence_cache,
|
|
|
|
|
i->core->mempool,
|
2008-05-15 23:34:41 +00:00
|
|
|
ret,
|
|
|
|
|
&i->sample_spec,
|
|
|
|
|
i->thread_info.resampler ? pa_resampler_max_block_size(i->thread_info.resampler) : 0);
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
2009-02-12 03:18:05 +01:00
|
|
|
|
|
|
|
|
/* Called from main context */
|
|
|
|
|
void pa_sink_input_send_event(pa_sink_input *i, const char *event, pa_proplist *data) {
|
|
|
|
|
pa_proplist *pl = NULL;
|
|
|
|
|
pa_sink_input_send_event_hook_data hook_data;
|
|
|
|
|
|
|
|
|
|
pa_sink_input_assert_ref(i);
|
2009-08-13 02:14:19 +02:00
|
|
|
pa_assert_ctl_context();
|
2009-02-12 03:18:05 +01:00
|
|
|
pa_assert(event);
|
|
|
|
|
|
|
|
|
|
if (!i->send_event)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!data)
|
|
|
|
|
data = pl = pa_proplist_new();
|
|
|
|
|
|
|
|
|
|
hook_data.sink_input = i;
|
|
|
|
|
hook_data.data = data;
|
|
|
|
|
hook_data.event = event;
|
|
|
|
|
|
|
|
|
|
if (pa_hook_fire(&i->core->hooks[PA_CORE_HOOK_SINK_INPUT_SEND_EVENT], &hook_data) < 0)
|
|
|
|
|
goto finish;
|
|
|
|
|
|
|
|
|
|
i->send_event(i, event, data);
|
|
|
|
|
|
|
|
|
|
finish:
|
|
|
|
|
if (pl)
|
|
|
|
|
pa_proplist_free(pl);
|
|
|
|
|
}
|
2009-07-16 10:41:34 +08:00
|
|
|
|
|
|
|
|
/* Called from IO context */
|
|
|
|
|
static void sink_input_volume_ramping(pa_sink_input* i, pa_memchunk* chunk) {
|
|
|
|
|
pa_assert(i);
|
|
|
|
|
pa_assert(chunk);
|
|
|
|
|
pa_assert(chunk->memblock);
|
|
|
|
|
pa_assert(i->thread_info.ramp_info.is_ramping);
|
|
|
|
|
|
|
|
|
|
/* Volume is adjusted with ramping effect here */
|
|
|
|
|
pa_envelope_apply(i->thread_info.ramp_info.envelope, chunk);
|
|
|
|
|
|
|
|
|
|
if (pa_envelope_is_finished(i->thread_info.ramp_info.envelope)) {
|
|
|
|
|
i->thread_info.ramp_info.is_ramping = FALSE;
|
|
|
|
|
if (pa_atomic_load(&i->before_ramping_v)) {
|
|
|
|
|
i->thread_info.soft_volume = i->thread_info.future_soft_volume;
|
|
|
|
|
pa_atomic_store(&i->before_ramping_v, 0);
|
|
|
|
|
}
|
|
|
|
|
else if (pa_atomic_load(&i->before_ramping_m)) {
|
|
|
|
|
i->thread_info.muted = i->thread_info.future_muted;
|
|
|
|
|
pa_atomic_store(&i->before_ramping_m, 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Called from main context
|
|
|
|
|
* This function should be called inside pa_sink_input_set_volume_with_ramping
|
|
|
|
|
* should be called after soft_volume of sink_input and sink are all adjusted
|
|
|
|
|
*/
|
|
|
|
|
static void sink_input_set_ramping_info(pa_sink_input* i, pa_volume_t pre_virtual_volume, pa_volume_t target_virtual_volume, pa_usec_t t) {
|
|
|
|
|
|
|
|
|
|
int32_t target_abs_vol, target_apply_vol, pre_apply_vol;
|
|
|
|
|
pa_assert(i);
|
|
|
|
|
|
|
|
|
|
pa_log_debug("Sink input's soft volume is %d= %f ", pa_cvolume_avg(&i->soft_volume), pa_sw_volume_to_linear(pa_cvolume_avg(&i->soft_volume)));
|
|
|
|
|
|
|
|
|
|
/* Calculation formula are target_abs_vol := i->soft_volume
|
|
|
|
|
* target_apply_vol := lrint(pa_sw_volume_to_linear(target_abs_vol) * 0x10000)
|
|
|
|
|
* pre_apply_vol := ( previous_virtual_volume / target_virtual_volume ) * target_apply_vol
|
|
|
|
|
*
|
|
|
|
|
* Will do volume adjustment inside pa_sink_input_peek
|
|
|
|
|
*/
|
|
|
|
|
target_abs_vol = pa_cvolume_avg(&i->soft_volume);
|
|
|
|
|
target_apply_vol = (int32_t) lrint(pa_sw_volume_to_linear(target_abs_vol) * 0x10000);
|
|
|
|
|
pre_apply_vol = (int32_t) ((pa_sw_volume_to_linear(pre_virtual_volume) / pa_sw_volume_to_linear(target_virtual_volume)) * target_apply_vol);
|
|
|
|
|
|
|
|
|
|
i->using_def.n_points = 2;
|
|
|
|
|
i->using_def.points_x[0] = 0;
|
|
|
|
|
i->using_def.points_x[1] = t;
|
|
|
|
|
i->using_def.points_y.i[0] = pre_apply_vol;
|
|
|
|
|
i->using_def.points_y.i[1] = target_apply_vol;
|
|
|
|
|
i->using_def.points_y.f[0] = ((float) i->using_def.points_y.i[0]) /0x10000;
|
|
|
|
|
i->using_def.points_y.f[1] = ((float) i->using_def.points_y.i[1]) /0x10000;
|
|
|
|
|
|
|
|
|
|
pa_log_debug("Volume Ramping: Point 1 is %d=%f, Point 2 is %d=%f\n", i->using_def.points_y.i[0], i->using_def.points_y.f[0],
|
|
|
|
|
i->using_def.points_y.i[1], i->using_def.points_y.f[1]);
|
|
|
|
|
|
|
|
|
|
pa_assert_se(pa_asyncmsgq_send(i->sink->asyncmsgq, PA_MSGOBJECT(i), PA_SINK_INPUT_MESSAGE_SET_ENVELOPE, NULL, 0, NULL) == 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Called from main context */
|
|
|
|
|
static void sink_input_set_ramping_info_for_mute(pa_sink_input* i, pa_bool_t mute, pa_usec_t t) {
|
|
|
|
|
|
|
|
|
|
int32_t cur_vol;
|
|
|
|
|
pa_assert(i);
|
|
|
|
|
|
|
|
|
|
i->using_def.n_points = 2;
|
|
|
|
|
i->using_def.points_x[0] = 0;
|
|
|
|
|
i->using_def.points_x[1] = t;
|
|
|
|
|
cur_vol = (int32_t) lrint( pa_sw_volume_to_linear(pa_cvolume_avg(&i->soft_volume)) * 0x10000);
|
|
|
|
|
|
|
|
|
|
if (mute) {
|
|
|
|
|
i->using_def.points_y.i[0] = cur_vol;
|
|
|
|
|
i->using_def.points_y.i[1] = 0;
|
|
|
|
|
} else {
|
|
|
|
|
i->using_def.points_y.i[0] = 0;
|
|
|
|
|
i->using_def.points_y.i[1] = cur_vol;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
i->using_def.points_y.f[0] = ((float) i->using_def.points_y.i[0]) /0x10000;
|
|
|
|
|
i->using_def.points_y.f[1] = ((float) i->using_def.points_y.i[1]) /0x10000;
|
|
|
|
|
|
|
|
|
|
pa_log_debug("Mute Ramping: Point 1 is %d=%f, Point 2 is %d=%f\n", i->using_def.points_y.i[0], i->using_def.points_y.f[0],
|
|
|
|
|
i->using_def.points_y.i[1], i->using_def.points_y.f[1]);
|
|
|
|
|
|
|
|
|
|
pa_assert_se(pa_asyncmsgq_send(i->sink->asyncmsgq, PA_MSGOBJECT(i), PA_SINK_INPUT_MESSAGE_SET_ENVELOPE, NULL, 0, NULL) == 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Called from IO context */
|
|
|
|
|
static void sink_input_release_envelope(pa_sink_input *i) {
|
|
|
|
|
pa_assert(i);
|
|
|
|
|
pa_assert(!i->thread_info.ramp_info.is_ramping);
|
|
|
|
|
pa_assert(i->thread_info.ramp_info.envelope_dead);
|
|
|
|
|
|
|
|
|
|
pa_envelope_free(i->thread_info.ramp_info.envelope);
|
|
|
|
|
i->thread_info.ramp_info.envelope = NULL;
|
|
|
|
|
i->thread_info.ramp_info.item = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Called from IO context */
|
|
|
|
|
static void sink_input_rewind_ramp_info(pa_sink_input *i, size_t nbytes) {
|
|
|
|
|
pa_assert(i);
|
|
|
|
|
|
|
|
|
|
if (!i->thread_info.ramp_info.envelope_dead) {
|
2009-12-10 15:43:58 +08:00
|
|
|
int32_t envelope_length;
|
2009-07-16 10:41:34 +08:00
|
|
|
|
2010-01-06 10:41:55 +02:00
|
|
|
pa_assert(i->thread_info.ramp_info.envelope);
|
2009-12-10 15:43:58 +08:00
|
|
|
|
|
|
|
|
envelope_length = pa_envelope_length(i->thread_info.ramp_info.envelope);
|
2009-07-16 10:41:34 +08:00
|
|
|
|
|
|
|
|
if (i->thread_info.ramp_info.envelope_dying > envelope_length) {
|
2009-12-10 15:43:58 +08:00
|
|
|
if ((int32_t) (i->thread_info.ramp_info.envelope_dying - nbytes) < envelope_length) {
|
2009-07-16 10:41:34 +08:00
|
|
|
pa_log_debug("Envelope Become Alive");
|
|
|
|
|
pa_envelope_rewind(i->thread_info.ramp_info.envelope, envelope_length - (i->thread_info.ramp_info.envelope_dying - nbytes));
|
|
|
|
|
i->thread_info.ramp_info.is_ramping = TRUE;
|
|
|
|
|
}
|
|
|
|
|
} else if (i->thread_info.ramp_info.envelope_dying < envelope_length) {
|
2010-01-06 00:21:07 +01:00
|
|
|
if ((i->thread_info.ramp_info.envelope_dying - (ssize_t) nbytes) <= 0) {
|
2009-07-16 10:41:34 +08:00
|
|
|
pa_log_debug("Envelope Restart");
|
|
|
|
|
pa_envelope_restart(i->thread_info.ramp_info.envelope);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
pa_log_debug("Envelope Simple Rewind");
|
|
|
|
|
pa_envelope_rewind(i->thread_info.ramp_info.envelope, nbytes);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
i->thread_info.ramp_info.envelope_dying -= nbytes;
|
|
|
|
|
if (i->thread_info.ramp_info.envelope_dying <= 0)
|
|
|
|
|
i->thread_info.ramp_info.envelope_dying = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void pa_sink_input_set_volume_with_ramping(pa_sink_input *i, const pa_cvolume *volume, pa_bool_t save, pa_bool_t absolute, pa_usec_t t){
|
|
|
|
|
pa_cvolume v;
|
|
|
|
|
pa_volume_t previous_virtual_volume, target_virtual_volume;
|
|
|
|
|
|
2009-11-05 22:54:42 +01:00
|
|
|
pa_sink_input_assert_ref(i);
|
|
|
|
|
pa_assert_ctl_context();
|
2009-07-16 10:41:34 +08:00
|
|
|
pa_assert(PA_SINK_INPUT_IS_LINKED(i->state));
|
|
|
|
|
pa_assert(volume);
|
|
|
|
|
pa_assert(pa_cvolume_valid(volume));
|
2009-11-05 22:54:42 +01:00
|
|
|
pa_assert(volume->channels == 1 || pa_cvolume_compatible(volume, &i->sample_spec));
|
2009-07-16 10:41:34 +08:00
|
|
|
|
|
|
|
|
if ((i->sink->flags & PA_SINK_FLAT_VOLUME) && !absolute) {
|
|
|
|
|
v = i->sink->reference_volume;
|
|
|
|
|
pa_cvolume_remap(&v, &i->sink->channel_map, &i->channel_map);
|
2009-11-05 22:54:42 +01:00
|
|
|
|
|
|
|
|
if (pa_cvolume_compatible(volume, &i->sample_spec))
|
|
|
|
|
volume = pa_sw_cvolume_multiply(&v, &v, volume);
|
|
|
|
|
else
|
|
|
|
|
volume = pa_sw_cvolume_multiply_scalar(&v, &v, pa_cvolume_max(volume));
|
|
|
|
|
} else {
|
2009-11-05 22:55:14 +01:00
|
|
|
|
2009-11-05 22:54:42 +01:00
|
|
|
if (!pa_cvolume_compatible(volume, &i->sample_spec)) {
|
|
|
|
|
v = i->volume;
|
|
|
|
|
volume = pa_cvolume_scale(&v, pa_cvolume_max(volume));
|
|
|
|
|
}
|
2009-07-16 10:41:34 +08:00
|
|
|
}
|
|
|
|
|
|
2009-11-05 22:54:42 +01:00
|
|
|
if (pa_cvolume_equal(volume, &i->volume)) {
|
|
|
|
|
i->save_volume = i->save_volume || save;
|
2009-07-16 10:41:34 +08:00
|
|
|
return;
|
2009-11-05 22:54:42 +01:00
|
|
|
}
|
2009-07-16 10:41:34 +08:00
|
|
|
|
2009-11-05 22:54:42 +01:00
|
|
|
previous_virtual_volume = pa_cvolume_avg(&i->volume);
|
2009-07-16 10:41:34 +08:00
|
|
|
target_virtual_volume = pa_cvolume_avg(volume);
|
2009-11-05 22:54:42 +01:00
|
|
|
|
2009-07-16 10:41:34 +08:00
|
|
|
if (t > 0 && target_virtual_volume > 0)
|
|
|
|
|
pa_log_debug("SetVolumeWithRamping: Virtual Volume From %u=%f to %u=%f\n", previous_virtual_volume, pa_sw_volume_to_linear(previous_virtual_volume),
|
|
|
|
|
target_virtual_volume, pa_sw_volume_to_linear(target_virtual_volume));
|
|
|
|
|
|
2009-11-05 22:54:42 +01:00
|
|
|
i->volume = *volume;
|
2009-07-16 10:41:34 +08:00
|
|
|
i->save_volume = save;
|
|
|
|
|
|
|
|
|
|
/* Set this flag before the following code modify i->thread_info.soft_volume */
|
|
|
|
|
if (t > 0 && target_virtual_volume > 0)
|
|
|
|
|
pa_atomic_store(&i->before_ramping_v, 1);
|
|
|
|
|
|
|
|
|
|
if (i->sink->flags & PA_SINK_FLAT_VOLUME) {
|
|
|
|
|
/* We are in flat volume mode, so let's update all sink input
|
|
|
|
|
* volumes and update the flat volume of the sink */
|
|
|
|
|
|
2009-11-05 22:54:42 +01:00
|
|
|
pa_sink_set_volume(i->sink, NULL, TRUE, save);
|
2009-07-16 10:41:34 +08:00
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
/* OK, we are in normal volume mode. The volume only affects
|
|
|
|
|
* ourselves */
|
2009-11-05 22:54:42 +01:00
|
|
|
set_real_ratio(i, volume);
|
2009-07-16 10:41:34 +08:00
|
|
|
|
|
|
|
|
/* Copy the new soft_volume to the thread_info struct */
|
|
|
|
|
pa_assert_se(pa_asyncmsgq_send(i->sink->asyncmsgq, PA_MSGOBJECT(i), PA_SINK_INPUT_MESSAGE_SET_SOFT_VOLUME, NULL, 0, NULL) == 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (t > 0 && target_virtual_volume > 0)
|
|
|
|
|
sink_input_set_ramping_info(i, previous_virtual_volume, target_virtual_volume, t);
|
|
|
|
|
|
2009-11-05 22:54:42 +01:00
|
|
|
/* The volume changed, let's tell people so */
|
|
|
|
|
if (i->volume_changed)
|
|
|
|
|
i->volume_changed(i);
|
|
|
|
|
|
2009-07-16 10:41:34 +08:00
|
|
|
/* The virtual volume changed, let's tell people so */
|
|
|
|
|
pa_subscription_post(i->core, PA_SUBSCRIPTION_EVENT_SINK_INPUT|PA_SUBSCRIPTION_EVENT_CHANGE, i->index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void pa_sink_input_set_mute_with_ramping(pa_sink_input *i, pa_bool_t mute, pa_bool_t save, pa_usec_t t){
|
|
|
|
|
|
|
|
|
|
pa_sink_input_assert_ref(i);
|
2009-11-05 22:55:14 +01:00
|
|
|
pa_assert_ctl_context();
|
2009-07-16 10:41:34 +08:00
|
|
|
pa_assert(PA_SINK_INPUT_IS_LINKED(i->state));
|
|
|
|
|
|
2009-11-05 22:55:14 +01:00
|
|
|
if (!i->muted == !mute) {
|
|
|
|
|
i->save_muted = i->save_muted || mute;
|
2009-07-16 10:41:34 +08:00
|
|
|
return;
|
2009-11-05 22:55:14 +01:00
|
|
|
}
|
2009-07-16 10:41:34 +08:00
|
|
|
|
|
|
|
|
i->muted = mute;
|
|
|
|
|
i->save_muted = save;
|
2009-11-05 22:55:14 +01:00
|
|
|
|
2009-07-16 10:41:34 +08:00
|
|
|
/* Set this flag before the following code modify i->thread_info.muted, otherwise distortion will be heard */
|
|
|
|
|
if (t > 0)
|
|
|
|
|
pa_atomic_store(&i->before_ramping_m, 1);
|
|
|
|
|
|
|
|
|
|
pa_assert_se(pa_asyncmsgq_send(i->sink->asyncmsgq, PA_MSGOBJECT(i), PA_SINK_INPUT_MESSAGE_SET_SOFT_MUTE, NULL, 0, NULL) == 0);
|
|
|
|
|
|
|
|
|
|
if (t > 0)
|
|
|
|
|
sink_input_set_ramping_info_for_mute(i, mute, t);
|
|
|
|
|
|
2009-11-05 22:55:14 +01:00
|
|
|
/* The mute status changed, let's tell people so */
|
|
|
|
|
if (i->mute_changed)
|
|
|
|
|
i->mute_changed(i);
|
|
|
|
|
|
2009-07-16 10:41:34 +08:00
|
|
|
pa_subscription_post(i->core, PA_SUBSCRIPTION_EVENT_SINK_INPUT|PA_SUBSCRIPTION_EVENT_CHANGE, i->index);
|
|
|
|
|
}
|