Lines Matching refs:sink

43 #include "sink-input.h"
253 data->sink = s;
260 /* Extended API: let's see if this sink supports the formats the client can provide */
265 data->sink = s;
294 if (data->sink) {
296 return pa_sink_input_new_data_set_sink(data, data->sink, (data->preferred_sink != NULL), data->sink_requested_by_application);
404 if (!data->sink) {
405 pa_sink *sink = pa_namereg_get(core, NULL, PA_NAMEREG_SINK);
406 pa_return_val_if_fail(sink, -PA_ERR_NOENTITY);
407 pa_sink_input_new_data_set_sink(data, sink, false, false);
416 /* We know that data->sink is set, because data->format has been set.
418 * can't happen before data->sink has been set. */
419 pa_assert(data->sink);
433 pa_return_val_if_fail(PA_SINK_IS_LINKED(data->sink->state), -PA_ERR_BADSTATE);
434 pa_return_val_if_fail(!data->sync_base || (data->sync_base->sink == data->sink
438 /* Routing is done. We have a sink and a format. */
456 r = pa_format_info_to_sample_spec2(data->format, &data->sample_spec, &data->channel_map, &data->sink->sample_spec,
457 &data->sink->channel_map);
461 r = check_passthrough_connection(pa_sink_input_new_data_is_passthrough(data), data->sink);
492 !pa_sample_spec_equal(&data->sample_spec, &data->sink->sample_spec)) {
493 /* try to change sink format and rate. This is done before the FIXATE hook since
494 module-suspend-on-idle can resume a sink */
497 pa_sink_reconfigure(data->sink, &data->sample_spec, pa_sink_input_new_data_is_passthrough(data));
501 !pa_sample_spec_equal(&data->sample_spec, &data->sink->sample_spec)) {
504 pa_log_debug("Could not update sink sample spec to match passthrough stream");
517 data->sink->state == PA_SINK_SUSPENDED) {
518 pa_log_warn("Failed to create sink input: sink is suspended.");
522 if (pa_idxset_size(data->sink->inputs) >= PA_MAX_INPUTS_PER_SINK) {
523 pa_log_warn("Failed to create sink input: too many inputs per sink.");
528 !pa_sample_spec_equal(&data->sample_spec, &data->sink->sample_spec) ||
529 !pa_channel_map_equal(&data->channel_map, &data->sink->channel_map)) {
531 /* Note: for passthrough content we need to adjust the output rate to that of the current sink-input */
536 &data->sink->sample_spec, &data->sink->channel_map,
560 i->sink = data->sink;
571 if (!data->volume_is_absolute && pa_sink_flat_volume_enabled(i->sink)) {
575 * as relative to the sink volume even in flat volume mode */
576 remapped = data->sink->reference_volume;
577 pa_cvolume_remap(&remapped, &data->sink->channel_map, &data->channel_map);
588 volume_factor_from_hashmap(&i->volume_factor_sink, i->volume_factor_sink_items, i->sink->sample_spec.channels);
638 pa_assert_se(pa_idxset_put(i->sink->inputs, pa_sink_input_ref(i), NULL) == 0);
643 memblockq_name = pa_sprintf_malloc("sink input render_memblockq [%u]", i->index);
649 &i->sink->sample_spec,
653 &i->sink->silence);
656 memblockq_name = pa_sprintf_malloc("sink input history memblockq [%u]", i->index);
675 i->sink->name,
692 if (!i->sink)
696 pa_assert_se(i->sink->n_corked -- >= 1);
698 i->sink->n_corked++;
710 if (i->sink) {
711 if (i->state == PA_SINK_INPUT_CORKED && state == PA_SINK_INPUT_RUNNING && pa_sink_used_by(i->sink) == 0 &&
712 !pa_sample_spec_equal(&i->sample_spec, &i->sink->sample_spec)) {
713 /* We were uncorked and the sink was not playing anything -- let's try
715 pa_sink_reconfigure(i->sink, &i->sample_spec, pa_sink_input_is_passthrough(i));
718 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);
720 /* If the sink is not valid, pa_sink_input_set_state_within_thread() must be called directly */
756 if (i->sink)
757 pa_sink_update_status(i->sink);
787 if (i->sink)
788 if (pa_idxset_remove_by_data(i->sink->inputs, i, NULL))
803 if (linked && i->sink) {
805 pa_sink_leave_passthrough(i->sink);
807 /* We might need to update the sink's volume if we are in flat volume mode. */
808 if (pa_sink_flat_volume_enabled(i->sink))
809 pa_sink_set_volume(i->sink, NULL, false, false);
811 if (i->sink->asyncmsgq)
812 pa_assert_se(pa_asyncmsgq_send(i->sink->asyncmsgq, PA_MSGOBJECT(i->sink), PA_SINK_MESSAGE_REMOVE_INPUT, i, 0, NULL) == 0);
817 if (i->sink) {
818 if (PA_SINK_IS_LINKED(i->sink->state))
819 pa_sink_update_status(i->sink);
821 i->sink = NULL;
847 * kind of sink input in any state, even those which are
904 /* We might need to update the sink's volume if we are in flat volume mode. */
905 if (pa_sink_flat_volume_enabled(i->sink))
906 pa_sink_set_volume(i->sink, NULL, false, i->save_volume);
917 pa_sink_enter_passthrough(i->sink);
922 pa_assert_se(pa_asyncmsgq_send(i->sink->asyncmsgq, PA_MSGOBJECT(i->sink), PA_SINK_MESSAGE_ADD_INPUT, i, 0, NULL) == 0);
927 pa_sink_update_status(i->sink);
947 pa_assert_se(pa_asyncmsgq_send(i->sink->asyncmsgq, PA_MSGOBJECT(i), PA_SINK_INPUT_MESSAGE_GET_LATENCY, r, 0, NULL) == 0);
959 void pa_sink_input_peek(pa_sink_input *i, size_t slength /* in sink bytes */, pa_memchunk *chunk, pa_cvolume *volume) {
969 pa_assert(pa_frame_aligned(slength, &i->sink->sample_spec));
981 block_size_max_sink = pa_frame_align(pa_mempool_block_size_max(i->core->mempool), &i->sink->sample_spec);
985 slength = pa_frame_align(CONVERT_BUFFER_LENGTH, &i->sink->sample_spec);
1005 /* If the channel maps of the sink and this stream differ, we need
1007 * it after and leave it for the sink code */
1009 do_volume_adj_here = !pa_channel_map_equal(&i->channel_map, &i->sink->channel_map);
1081 pa_volume_memchunk(&wchunk, &i->sink->sample_spec, &i->volume_factor_sink);
1097 pa_volume_memchunk(&rchunk, &i->sink->sample_spec, &i->volume_factor_sink);
1127 * or if this can be done by the sink for us */
1131 pa_cvolume_reset(volume, i->sink->sample_spec.channels);
1133 /* We've both the same channel map, so let's have the sink do the adjustment for us*/
1134 pa_cvolume_mute(volume, i->sink->sample_spec.channels);
1140 void pa_sink_input_drop(pa_sink_input *i, size_t nbytes /* in sink sample spec */) {
1146 pa_assert(pa_frame_aligned(nbytes, &i->sink->sample_spec));
1190 void pa_sink_input_process_rewind(pa_sink_input *i, size_t nbytes /* in sink sample spec */) {
1198 pa_assert(pa_frame_aligned(nbytes, &i->sink->sample_spec));
1238 /* Transform to sink domain */
1265 * The replay of the rewound sink input data will then produce a deviation in
1305 return pa_resampler_request(i->thread_info.resampler, i->sink->thread_info.max_rewind);
1316 return pa_resampler_request(i->thread_info.resampler, i->sink->thread_info.max_request);
1320 void pa_sink_input_update_max_rewind(pa_sink_input *i, size_t nbytes /* in the sink's sample spec */) {
1327 pa_assert(pa_frame_aligned(nbytes, &i->sink->sample_spec));
1343 void pa_sink_input_update_max_request(pa_sink_input *i, size_t nbytes /* in the sink's sample spec */) {
1347 pa_assert(pa_frame_aligned(nbytes, &i->sink->sample_spec));
1358 if (!(i->sink->flags & PA_SINK_DYNAMIC_LATENCY))
1359 usec = i->sink->thread_info.fixed_latency;
1362 usec = PA_CLAMP(usec, i->sink->thread_info.min_latency, i->sink->thread_info.max_latency);
1365 pa_sink_invalidate_requested_latency(i->sink, true);
1375 if (PA_SINK_INPUT_IS_LINKED(i->state) && i->sink) {
1376 pa_assert_se(pa_asyncmsgq_send(i->sink->asyncmsgq, PA_MSGOBJECT(i), PA_SINK_INPUT_MESSAGE_SET_REQUESTED_LATENCY, &usec, 0, NULL) == 0);
1380 /* If this sink input is not realized yet or we are being moved,
1383 if (i->sink) {
1384 if (!(i->sink->flags & PA_SINK_DYNAMIC_LATENCY))
1385 usec = pa_sink_get_fixed_latency(i->sink);
1389 pa_sink_get_latency_range(i->sink, &min_latency, &max_latency);
1404 if (PA_SINK_INPUT_IS_LINKED(i->state) && i->sink) {
1406 pa_assert_se(pa_asyncmsgq_send(i->sink->asyncmsgq, PA_MSGOBJECT(i), PA_SINK_INPUT_MESSAGE_GET_REQUESTED_LATENCY, &usec, 0, NULL) == 0);
1410 /* If this sink input is not realized yet or we are being moved,
1428 if (!absolute && pa_sink_flat_volume_enabled(i->sink)) {
1429 v = i->sink->reference_volume;
1430 pa_cvolume_remap(&v, &i->sink->channel_map, &i->channel_map);
1451 if (pa_sink_flat_volume_enabled(i->sink)) {
1452 /* We are in flat volume mode, so let's update all sink input
1453 * volumes and update the flat volume of the sink */
1455 pa_sink_set_volume(i->sink, NULL, true, save);
1464 pa_assert_se(pa_asyncmsgq_send(i->sink->asyncmsgq, PA_MSGOBJECT(i), PA_SINK_INPUT_MESSAGE_SET_SOFT_VOLUME, NULL, 0, NULL) == 0);
1492 pa_assert_se(pa_asyncmsgq_send(i->sink->asyncmsgq, PA_MSGOBJECT(i), PA_SINK_INPUT_MESSAGE_SET_SOFT_VOLUME, NULL, 0, NULL) == 0);
1523 pa_assert_se(pa_asyncmsgq_send(i->sink->asyncmsgq, PA_MSGOBJECT(i), PA_SINK_INPUT_MESSAGE_SET_SOFT_VOLUME, NULL, 0, NULL) == 0);
1577 if (absolute || !pa_sink_flat_volume_enabled(i->sink))
1601 pa_log_debug("The mute of sink input %u changed from %s to %s.", i->index, pa_yes_no(old_mute), pa_yes_no(mute));
1605 pa_assert_se(pa_asyncmsgq_send(i->sink->asyncmsgq, PA_MSGOBJECT(i), PA_SINK_INPUT_MESSAGE_SET_SOFT_MUTE, NULL, 0, NULL) == 0);
1756 if (i->sink)
1757 pa_asyncmsgq_post(i->sink->asyncmsgq, PA_MSGOBJECT(i), PA_SINK_INPUT_MESSAGE_SET_RATE, PA_UINT_TO_PTR(rate), 0, NULL, NULL);
1797 s = s->input_to_master->sink;
1804 pa_sink *sink = i->sink;
1806 if (!sink)
1809 while (sink->input_to_master) {
1810 sink = sink->input_to_master->sink;
1812 if (!sink)
1826 if (dest == i->sink)
1835 /* Make sure we're not creating a filter sink cycle */
1841 /* If this sink input is connected to a filter sink that itself is moving,
1843 * thread of the old sink, and if the old sink is a filter sink that is
1844 * moving, there's no IO thread associated to the old sink. */
1846 pa_log_debug("Can't move input from filter sink %s, because the filter sink itself is currently moving.",
1847 i->sink->name);
1852 pa_log_warn("Failed to move sink input: too many inputs per sink.");
1876 pa_assert(i->sink);
1884 pa_log_debug("Starting to move sink input %u from '%s'", (unsigned) i->index, i->sink->name);
1894 pa_idxset_remove_by_data(i->sink->inputs, i, NULL);
1897 pa_assert_se(i->sink->n_corked-- >= 1);
1900 pa_sink_leave_passthrough(i->sink);
1902 if (pa_sink_flat_volume_enabled(i->sink))
1903 /* We might need to update the sink's volume if we are in flat
1905 pa_sink_set_volume(i->sink, NULL, false, false);
1907 pa_assert_se(pa_asyncmsgq_send(i->sink->asyncmsgq, PA_MSGOBJECT(i->sink), PA_SINK_MESSAGE_START_MOVE, i, 0, NULL) == 0);
1909 pa_sink_update_status(i->sink);
1912 pa_cvolume_remap(&v->volume, &i->sink->channel_map, &i->channel_map);
1914 pa_cvolume_remap(&i->volume_factor_sink, &i->sink->channel_map, &i->channel_map);
1916 /* Calculate how much of the latency was rewound on the old sink */
1917 i->origin_rewind_bytes = pa_sink_get_last_rewind(i->sink) / pa_frame_size(&i->sink->sample_spec);
1918 i->origin_rewind_bytes = i->origin_rewind_bytes * i->sample_spec.rate / i->sink->sample_spec.rate;
1921 i->sink = NULL;
1929 /* Called from main context. If i has an origin sink that uses volume sharing,
1930 * then also the origin sink and all streams connected to it need to update
1937 pa_assert(i->sink); /* The destination sink should already be set. */
1940 pa_sink *root_sink = pa_sink_get_master(i->sink);
1947 if (pa_sink_flat_volume_enabled(i->sink)) {
1948 /* Ok, so the origin sink uses volume sharing, and flat volume is
1951 * i->volume := i->sink->real_volume
1953 * i->reference_ratio := i->volume / i->sink->reference_volume
1956 * (streams whose origin sink uses volume sharing should
1959 * (streams whose origin sink uses volume sharing should
1969 /* Ok, so the origin sink uses volume sharing, and flat volume is
1975 * (streams whose origin sink uses volume sharing should
1978 * (streams whose origin sink uses volume sharing should
1989 /* Additionally, the origin sink volume needs updating:
2013 /* Recursively update origin sink inputs. */
2018 if (pa_sink_flat_volume_enabled(i->sink)) {
2022 * i->volume := i->reference_ratio * i->sink->reference_volume
2024 * i->real_ratio := i->volume / i->sink->real_volume
2029 new_volume = i->sink->reference_volume;
2030 pa_cvolume_remap(&new_volume, &i->sink->channel_map, &i->channel_map);
2049 /* If i->sink == dest, then recursion has finished, and we can finally call
2051 if ((i->sink == dest) && pa_sink_flat_volume_enabled(i->sink))
2052 pa_sink_set_volume(i->sink, NULL, false, i->save_volume);
2072 * Called from main context while the sink input is detached. */
2079 /* Calculate how much of the latency was left on the old sink */
2096 /* If something is left playing on the origin sink, add silence to the render memblockq */
2104 pa_silence_memchunk(&chunk, &i->sink->sample_spec);
2149 /* Tell the sink input not to ask the implementer to rewrite during the
2162 pa_assert(!i->sink);
2170 pa_log_debug("New sink doesn't support stream format, sending format-changed and killing");
2181 /* try to change dest sink format and rate if possible without glitches.
2182 module-suspend-on-idle resumes destination sink with
2192 i->sink = dest;
2205 pa_cvolume_remap(&v->volume, &i->channel_map, &i->sink->channel_map);
2207 pa_cvolume_remap(&i->volume_factor_sink, &i->channel_map, &i->sink->channel_map);
2210 i->sink->n_corked++;
2221 pa_sink_enter_passthrough(i->sink);
2223 pa_assert_se(pa_asyncmsgq_send(i->sink->asyncmsgq, PA_MSGOBJECT(i->sink), PA_SINK_MESSAGE_FINISH_MOVE, i, 0, NULL) == 0);
2228 pa_log_debug("Successfully moved sink input %i to %s.", i->index, dest->name);
2243 pa_assert(!i->sink);
2245 /* Check if someone wants this sink input? */
2249 /* Can we move the sink input to the default sink? */
2268 pa_assert(i->sink);
2271 if (dest == i->sink)
2295 /* Called from IO thread context except when cork() is called without a valid sink. */
2314 /* This will tell the implementing sink input driver to rewind
2316 if (i->sink)
2335 if (i->sink)
2366 r[0] += pa_bytes_to_usec(pa_memblockq_get_length(i->thread_info.render_memblockq), &i->sink->sample_spec);
2368 r[1] += pa_sink_get_latency_within_thread(i->sink, false);
2433 /* If 'rewrite' is true the sink is rewound as far as requested
2438 * If 'rewrite' is false the sink is rewound as far as requested
2463 * touch the sink */
2473 * If the sink has a virtual sink attached, limit rewinding to max_rewind.
2475 * The max_rewind value of a virtual sink depends on the rewinding capability
2477 * of the sink input. Therefore rewinding must be limited to max_rewind here. */
2478 nbytes = i->sink->thread_info.max_rewind;
2479 if (!pa_sink_has_filter_attached(i->sink) && !pa_sink_is_filter(i->sink))
2482 /* Transform from sink domain */
2488 * 2) When the sink input is rewound during a move when it is attached to
2489 * the destination sink.
2490 * Moving a sink input is handled without involving the implementer, so the
2519 /* Transform to sink domain */
2523 pa_sink_request_rewind(i->sink, nbytes - lbq);
2526 pa_sink_request_rewind(i->sink, 0);
2578 /* Updates the sink input's resampler with whatever the current sink requires
2579 * -- useful when the underlying sink's sample spec might have changed */
2588 pa_sample_spec_equal(pa_resampler_output_sample_spec(i->thread_info.resampler), &i->sink->sample_spec) &&
2589 pa_channel_map_equal(pa_resampler_output_channel_map(i->thread_info.resampler), &i->sink->channel_map))
2595 !pa_sample_spec_equal(&i->sample_spec, &i->sink->sample_spec) ||
2596 !pa_channel_map_equal(&i->channel_map, &i->sink->channel_map))) {
2600 &i->sink->sample_spec, &i->sink->channel_map,
2630 memblockq_name = pa_sprintf_malloc("sink input render_memblockq [%u]", i->index);
2636 &i->sink->sample_spec,
2640 &i->sink->silence);
2645 pa_log_debug("Updated resampler for sink input %d", i->index);
2689 pa_log_debug("The volume of sink input %u changed from %s to %s.", i->index,
2727 * sink. As a side effect the stream is moved to the new preferred sink. Note
2729 * a stream, as a side effect the preferred sink is changed. This could cause