2 This file is part of PulseAudio.
4 Copyright 2004-2006 Lennart Poettering
6 PulseAudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published
8 by the Free Software Foundation; either version 2.1 of the License,
9 or (at your option) any later version.
11 PulseAudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
29 #include <pulse/timeval.h>
32 #include <pulse/rtclock.h>
35 #include <pulse/utf8.h>
36 #include <pulse/xmalloc.h>
37 #include <pulse/util.h>
38 #include <pulse/internal.h>
40 #include <pulsecore/core-format.h>
41 #include <pulsecore/mix.h>
42 #include <pulsecore/stream-util.h>
43 #include <pulsecore/core-subscribe.h>
44 #include <pulsecore/log.h>
45 #include <pulsecore/namereg.h>
46 #include <pulsecore/core-util.h>
48 #include "source-output.h"
50 #define MEMBLOCKQ_MAXLENGTH (32*1024*1024)
52 PA_DEFINE_PUBLIC_CLASS(pa_source_output, pa_msgobject);
54 static void source_output_free(pa_object* mo);
55 static void set_real_ratio(pa_source_output *o, const pa_cvolume *v);
57 static void pa_source_output_write_pcm_dump(pa_source_output *o, pa_memchunk *chunk)
59 char *dump_time = NULL, *dump_path_surfix = NULL;
60 const char *s_device_api_str, *card_name_str, *device_idx_str;
65 /* open file for dump pcm */
66 if (o->core->pcm_dump & PA_PCM_DUMP_SOURCE_OUTPUT && !o->pcm_dump_fp && o->state == PA_SOURCE_OUTPUT_RUNNING) {
67 pa_gettimeofday(&now);
68 localtime_r(&now.tv_sec, &tm);
69 memset(&datetime[0], 0x00, sizeof(datetime));
70 strftime(&datetime[0], sizeof(datetime), "%H%M%S", &tm);
71 dump_time = pa_sprintf_malloc("%s.%03ld", &datetime[0], now.tv_usec / 1000);
73 if ((s_device_api_str = pa_proplist_gets(o->source->proplist, PA_PROP_DEVICE_API))) {
74 if (pa_streq(s_device_api_str, "alsa")) {
75 card_name_str = pa_proplist_gets(o->source->proplist, "alsa.card_name");
76 device_idx_str = pa_proplist_gets(o->source->proplist, "alsa.device");
77 dump_path_surfix = pa_sprintf_malloc("%s.%s", pa_strnull(card_name_str), pa_strnull(device_idx_str));
79 dump_path_surfix = pa_sprintf_malloc("%s", s_device_api_str);
82 dump_path_surfix = pa_sprintf_malloc("%s", o->source->name);
85 o->dump_path = pa_sprintf_malloc("%s_%s_pa-output%d-source%d-%s_%dch_%d.raw", PA_PCM_DUMP_PATH_PREFIX, pa_strempty(dump_time),
86 o->index, o->source->index, pa_strempty(dump_path_surfix), o->sample_spec.channels, o->sample_spec.rate);
88 o->pcm_dump_fp = fopen(o->dump_path, "w");
90 pa_log_warn("%s open failed", o->dump_path);
92 pa_log_info("%s opened", o->dump_path);
95 pa_xfree(dump_path_surfix);
96 /* close file for dump pcm when config is changed */
97 } else if (~o->core->pcm_dump & PA_PCM_DUMP_SOURCE_OUTPUT && o->pcm_dump_fp) {
98 fclose(o->pcm_dump_fp);
99 pa_log_info("%s closed", o->dump_path);
100 pa_xfree(o->dump_path);
101 o->pcm_dump_fp = NULL;
105 if (o->pcm_dump_fp) {
108 ptr = pa_memblock_acquire(chunk->memblock);
110 fwrite((uint8_t *)ptr + chunk->index, 1, chunk->length, o->pcm_dump_fp);
112 pa_log_warn("pa_memblock_acquire is failed. ptr is NULL");
114 pa_memblock_release(chunk->memblock);
119 pa_source_output_new_data* pa_source_output_new_data_init(pa_source_output_new_data *data) {
123 data->resample_method = PA_RESAMPLER_INVALID;
124 data->proplist = pa_proplist_new();
125 data->volume_writable = true;
126 #ifdef TIZEN_INDIVIDUAL_VOLUME_RATIO
127 data->individual_volume_ratio = 1.0;
133 void pa_source_output_new_data_set_sample_spec(pa_source_output_new_data *data, const pa_sample_spec *spec) {
136 if ((data->sample_spec_is_set = !!spec))
137 data->sample_spec = *spec;
140 void pa_source_output_new_data_set_channel_map(pa_source_output_new_data *data, const pa_channel_map *map) {
143 if ((data->channel_map_is_set = !!map))
144 data->channel_map = *map;
147 bool pa_source_output_new_data_is_passthrough(pa_source_output_new_data *data) {
150 if (PA_LIKELY(data->format) && PA_UNLIKELY(!pa_format_info_is_pcm(data->format)))
153 if (PA_UNLIKELY(data->flags & PA_SOURCE_OUTPUT_PASSTHROUGH))
159 void pa_source_output_new_data_set_volume(pa_source_output_new_data *data, const pa_cvolume *volume) {
161 pa_assert(data->volume_writable);
163 if ((data->volume_is_set = !!volume))
164 data->volume = *volume;
167 void pa_source_output_new_data_apply_volume_factor(pa_source_output_new_data *data, const pa_cvolume *volume_factor) {
169 pa_assert(volume_factor);
171 if (data->volume_factor_is_set)
172 pa_sw_cvolume_multiply(&data->volume_factor, &data->volume_factor, volume_factor);
174 data->volume_factor_is_set = true;
175 data->volume_factor = *volume_factor;
179 void pa_source_output_new_data_apply_volume_factor_source(pa_source_output_new_data *data, const pa_cvolume *volume_factor) {
181 pa_assert(volume_factor);
183 if (data->volume_factor_source_is_set)
184 pa_sw_cvolume_multiply(&data->volume_factor_source, &data->volume_factor_source, volume_factor);
186 data->volume_factor_source_is_set = true;
187 data->volume_factor_source = *volume_factor;
191 void pa_source_output_new_data_set_muted(pa_source_output_new_data *data, bool mute) {
194 data->muted_is_set = true;
198 bool pa_source_output_new_data_set_source(pa_source_output_new_data *data, pa_source *s, bool save,
199 bool requested_by_application) {
201 pa_idxset *formats = NULL;
206 if (!data->req_formats) {
207 /* We're not working with the extended API */
210 pa_xfree(data->preferred_source);
211 data->preferred_source = pa_xstrdup(s->name);
213 data->source_requested_by_application = requested_by_application;
215 /* Extended API: let's see if this source supports the formats the client would like */
216 formats = pa_source_check_formats(s, data->req_formats);
218 if (formats && !pa_idxset_isempty(formats)) {
219 /* Source supports at least one of the requested formats */
222 pa_xfree(data->preferred_source);
223 data->preferred_source = pa_xstrdup(s->name);
225 data->source_requested_by_application = requested_by_application;
226 if (data->nego_formats)
227 pa_idxset_free(data->nego_formats, (pa_free_cb_t) pa_format_info_free);
228 data->nego_formats = formats;
230 /* Source doesn't support any of the formats requested by the client */
232 pa_idxset_free(formats, (pa_free_cb_t) pa_format_info_free);
240 bool pa_source_output_new_data_set_formats(pa_source_output_new_data *data, pa_idxset *formats) {
244 if (data->req_formats)
245 pa_idxset_free(data->req_formats, (pa_free_cb_t) pa_format_info_free);
247 data->req_formats = formats;
250 /* Trigger format negotiation */
251 return pa_source_output_new_data_set_source(data, data->source, (data->preferred_source != NULL),
252 data->source_requested_by_application);
258 void pa_source_output_new_data_done(pa_source_output_new_data *data) {
261 if (data->req_formats)
262 pa_idxset_free(data->req_formats, (pa_free_cb_t) pa_format_info_free);
264 if (data->nego_formats)
265 pa_idxset_free(data->nego_formats, (pa_free_cb_t) pa_format_info_free);
268 pa_format_info_free(data->format);
270 if (data->preferred_source)
271 pa_xfree(data->preferred_source);
273 pa_proplist_free(data->proplist);
276 /* Called from main context */
277 static void reset_callbacks(pa_source_output *o) {
281 o->process_rewind = NULL;
282 o->update_max_rewind = NULL;
283 o->update_source_requested_latency = NULL;
284 o->update_source_latency_range = NULL;
285 o->update_source_fixed_latency = NULL;
289 o->suspend_within_thread = NULL;
292 o->get_latency = NULL;
293 o->state_change = NULL;
294 o->may_move_to = NULL;
295 o->send_event = NULL;
296 o->volume_changed = NULL;
297 o->mute_changed = NULL;
300 /* Called from main context */
301 int pa_source_output_new(
302 pa_source_output**_o,
304 pa_source_output_new_data *data) {
307 pa_resampler *resampler = NULL;
308 char st[PA_SAMPLE_SPEC_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX], fmt[PA_FORMAT_INFO_SNPRINT_MAX];
309 pa_channel_map volume_map;
316 pa_assert_ctl_context();
319 pa_proplist_update(data->proplist, PA_UPDATE_MERGE, data->client->proplist);
321 if (data->destination_source && (data->destination_source->flags & PA_SOURCE_SHARE_VOLUME_WITH_MASTER))
322 data->volume_writable = false;
324 if (!data->req_formats) {
325 /* From this point on, we want to work only with formats, and get back
326 * to using the sample spec and channel map after all decisions w.r.t.
327 * routing are complete. */
331 f = pa_format_info_from_sample_spec2(&data->sample_spec, data->channel_map_is_set ? &data->channel_map : NULL,
332 !(data->flags & PA_SOURCE_OUTPUT_FIX_FORMAT),
333 !(data->flags & PA_SOURCE_OUTPUT_FIX_RATE),
334 !(data->flags & PA_SOURCE_OUTPUT_FIX_CHANNELS));
336 return -PA_ERR_INVALID;
338 formats = pa_idxset_new(NULL, NULL);
339 pa_idxset_put(formats, f, NULL);
340 pa_source_output_new_data_set_formats(data, formats);
343 if ((r = pa_hook_fire(&core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_NEW], data)) < 0)
346 pa_return_val_if_fail(!data->driver || pa_utf8_valid(data->driver), -PA_ERR_INVALID);
351 if (data->direct_on_input) {
352 source = data->direct_on_input->sink->monitor_source;
353 pa_return_val_if_fail(source, -PA_ERR_INVALID);
355 source = pa_namereg_get(core, NULL, PA_NAMEREG_SOURCE);
356 pa_return_val_if_fail(source, -PA_ERR_NOENTITY);
359 pa_source_output_new_data_set_source(data, source, false, false);
363 pa_source_output_new_data_set_source(data, data->source, false, false);
368 /* If something didn't pick a format for us, pick the top-most format since
369 * we assume this is sorted in priority order */
370 if (!data->format && data->nego_formats && !pa_idxset_isempty(data->nego_formats))
371 data->format = pa_format_info_copy(pa_idxset_first(data->nego_formats, NULL));
373 if (PA_LIKELY(data->format)) {
374 /* We know that data->source is set, because data->format has been set.
375 * data->format is set after a successful format negotiation, and that
376 * can't happen before data->source has been set. */
377 pa_assert(data->source);
379 pa_log_debug("Negotiated format: %s", pa_format_info_snprint(fmt, sizeof(fmt), data->format));
381 pa_format_info *format;
384 pa_log_info("Source does not support any requested format:");
385 PA_IDXSET_FOREACH(format, data->req_formats, idx)
386 pa_log_info(" -- %s", pa_format_info_snprint(fmt, sizeof(fmt), format));
388 return -PA_ERR_NOTSUPPORTED;
391 pa_return_val_if_fail(PA_SOURCE_IS_LINKED(data->source->state), -PA_ERR_BADSTATE);
392 pa_return_val_if_fail(!data->direct_on_input || data->direct_on_input->sink == data->source->monitor_of, -PA_ERR_INVALID);
394 /* Routing is done. We have a source and a format. */
396 if (data->volume_is_set && !pa_source_output_new_data_is_passthrough(data)) {
397 /* If volume is set, we need to save the original data->channel_map,
398 * so that we can remap the volume from the original channel map to the
399 * final channel map of the stream in case data->channel_map gets
400 * modified in pa_format_info_to_sample_spec2(). */
401 r = pa_stream_get_volume_channel_map(&data->volume, data->channel_map_is_set ? &data->channel_map : NULL, data->format, &volume_map);
405 /* Initialize volume_map to invalid state. We check the state later to
406 * determine if volume remapping is needed. */
407 pa_channel_map_init(&volume_map);
410 /* Now populate the sample spec and channel map according to the final
411 * format that we've negotiated */
412 r = pa_format_info_to_sample_spec2(data->format, &data->sample_spec, &data->channel_map, &data->source->sample_spec,
413 &data->source->channel_map);
417 /* Don't restore (or save) stream volume for passthrough streams and
418 * prevent attenuation/gain */
419 if (pa_source_output_new_data_is_passthrough(data)) {
420 data->volume_is_set = true;
421 pa_cvolume_reset(&data->volume, data->sample_spec.channels);
422 data->volume_is_absolute = true;
423 data->save_volume = false;
426 if (!data->volume_is_set) {
427 pa_cvolume_reset(&data->volume, data->sample_spec.channels);
428 data->volume_is_absolute = false;
429 data->save_volume = false;
432 if (!data->volume_writable)
433 data->save_volume = false;
435 if (pa_channel_map_valid(&volume_map))
436 /* The original volume channel map may be different than the final
437 * stream channel map, so remapping may be needed. */
438 pa_cvolume_remap(&data->volume, &volume_map, &data->channel_map);
440 if (!data->volume_factor_is_set)
441 pa_cvolume_reset(&data->volume_factor, data->sample_spec.channels);
443 pa_return_val_if_fail(pa_cvolume_compatible(&data->volume_factor, &data->sample_spec), -PA_ERR_INVALID);
445 if (!data->volume_factor_source_is_set)
446 pa_cvolume_reset(&data->volume_factor_source, data->source->sample_spec.channels);
448 pa_return_val_if_fail(pa_cvolume_compatible(&data->volume_factor_source, &data->source->sample_spec), -PA_ERR_INVALID);
450 if (!data->muted_is_set)
453 if (!(data->flags & PA_SOURCE_OUTPUT_VARIABLE_RATE) &&
454 !pa_sample_spec_equal(&data->sample_spec, &data->source->sample_spec)) {
455 /* try to change source format and rate. This is done before the FIXATE hook since
456 module-suspend-on-idle can resume a source */
458 pa_log_info("Trying to change sample spec");
459 pa_source_reconfigure(data->source, &data->sample_spec, pa_source_output_new_data_is_passthrough(data));
462 if (pa_source_output_new_data_is_passthrough(data) &&
463 !pa_sample_spec_equal(&data->sample_spec, &data->source->sample_spec)) {
464 /* rate update failed, or other parts of sample spec didn't match */
466 pa_log_debug("Could not update source sample spec to match passthrough stream");
467 return -PA_ERR_NOTSUPPORTED;
470 if (data->resample_method == PA_RESAMPLER_INVALID)
471 data->resample_method = core->resample_method;
473 pa_return_val_if_fail(data->resample_method < PA_RESAMPLER_MAX, -PA_ERR_INVALID);
475 if ((r = pa_hook_fire(&core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_FIXATE], data)) < 0)
478 if ((data->flags & PA_SOURCE_OUTPUT_NO_CREATE_ON_SUSPEND) &&
479 data->source->state == PA_SOURCE_SUSPENDED) {
480 pa_log("Failed to create source output: source is suspended.");
481 return -PA_ERR_BADSTATE;
484 if (pa_idxset_size(data->source->outputs) >= PA_MAX_OUTPUTS_PER_SOURCE) {
485 pa_log("Failed to create source output: too many outputs per source.");
486 return -PA_ERR_TOOLARGE;
489 if ((data->flags & PA_SOURCE_OUTPUT_VARIABLE_RATE) ||
490 !pa_sample_spec_equal(&data->sample_spec, &data->source->sample_spec) ||
491 !pa_channel_map_equal(&data->channel_map, &data->source->channel_map)) {
493 if (!pa_source_output_new_data_is_passthrough(data)) /* no resampler for passthrough content */
494 if (!(resampler = pa_resampler_new(
496 &data->source->sample_spec, &data->source->channel_map,
497 &data->sample_spec, &data->channel_map,
498 core->lfe_crossover_freq,
499 data->resample_method,
500 ((data->flags & PA_SOURCE_OUTPUT_VARIABLE_RATE) ? PA_RESAMPLER_VARIABLE_RATE : 0) |
501 ((data->flags & PA_SOURCE_OUTPUT_NO_REMAP) ? PA_RESAMPLER_NO_REMAP : 0) |
502 (core->disable_remixing || (data->flags & PA_SOURCE_OUTPUT_NO_REMIX) ? PA_RESAMPLER_NO_REMIX : 0) |
503 (core->remixing_use_all_sink_channels ? 0 : PA_RESAMPLER_NO_FILL_SINK) |
504 (core->remixing_produce_lfe ? PA_RESAMPLER_PRODUCE_LFE : 0) |
505 (core->remixing_consume_lfe ? PA_RESAMPLER_CONSUME_LFE : 0)))) {
506 pa_log_warn("Unsupported resampling operation.");
507 return -PA_ERR_NOTSUPPORTED;
511 o = pa_msgobject_new(pa_source_output);
512 o->parent.parent.free = source_output_free;
513 o->parent.process_msg = pa_source_output_process_msg;
516 o->state = PA_SOURCE_OUTPUT_INIT;
517 o->flags = data->flags;
518 o->proplist = pa_proplist_copy(data->proplist);
519 o->driver = pa_xstrdup(pa_path_get_filename(data->driver));
520 o->module = data->module;
521 o->source = data->source;
522 o->source_requested_by_application = data->source_requested_by_application;
523 o->destination_source = data->destination_source;
524 o->client = data->client;
526 o->requested_resample_method = data->resample_method;
527 o->actual_resample_method = resampler ? pa_resampler_get_method(resampler) : PA_RESAMPLER_INVALID;
528 o->sample_spec = data->sample_spec;
529 o->channel_map = data->channel_map;
530 o->format = pa_format_info_copy(data->format);
532 if (!data->volume_is_absolute && pa_source_flat_volume_enabled(o->source)) {
535 /* When the 'absolute' bool is not set then we'll treat the volume
536 * as relative to the source volume even in flat volume mode */
537 remapped = data->source->reference_volume;
538 pa_cvolume_remap(&remapped, &data->source->channel_map, &data->channel_map);
539 pa_sw_cvolume_multiply(&o->volume, &data->volume, &remapped);
541 o->volume = data->volume;
543 o->volume_factor = data->volume_factor;
544 o->volume_factor_source = data->volume_factor_source;
545 o->real_ratio = o->reference_ratio = data->volume;
546 pa_cvolume_reset(&o->soft_volume, o->sample_spec.channels);
547 pa_cvolume_reset(&o->real_ratio, o->sample_spec.channels);
548 #ifdef TIZEN_INDIVIDUAL_VOLUME_RATIO
549 o->individual_volume_ratio = data->individual_volume_ratio;
551 o->volume_writable = data->volume_writable;
552 o->save_volume = data->save_volume;
553 o->preferred_source = pa_xstrdup(data->preferred_source);
554 o->save_muted = data->save_muted;
556 o->muted = data->muted;
558 o->direct_on_input = data->direct_on_input;
563 o->thread_info.state = o->state;
564 o->thread_info.attached = false;
565 o->thread_info.sample_spec = o->sample_spec;
566 o->thread_info.resampler = resampler;
567 o->thread_info.soft_volume = o->soft_volume;
568 o->thread_info.muted = o->muted;
569 o->thread_info.requested_source_latency = (pa_usec_t) -1;
570 o->thread_info.direct_on_input = o->direct_on_input;
572 o->thread_info.processor_holder = data->processor_holder;
575 o->thread_info.delay_memblockq = pa_memblockq_new(
576 "source output delay_memblockq",
580 &o->source->sample_spec,
584 &o->source->silence);
586 pa_assert_se(pa_idxset_put(core->source_outputs, o, &o->index) == 0);
587 pa_assert_se(pa_idxset_put(o->source->outputs, pa_source_output_ref(o), NULL) == 0);
590 pa_assert_se(pa_idxset_put(o->client->source_outputs, o, NULL) >= 0);
592 if (o->direct_on_input)
593 pa_assert_se(pa_idxset_put(o->direct_on_input->direct_outputs, o, NULL) == 0);
595 pt = pa_proplist_to_string_sep(o->proplist, "\n ");
596 pa_log_info("Created output %u \"%s\" on %s with sample spec %s and channel map %s\n %s",
598 pa_strnull(pa_proplist_gets(o->proplist, PA_PROP_MEDIA_NAME)),
600 pa_sample_spec_snprint(st, sizeof(st), &o->sample_spec),
601 pa_channel_map_snprint(cm, sizeof(cm), &o->channel_map),
605 /* Don't forget to call pa_source_output_put! */
611 /* Called from main context */
612 static void update_n_corked(pa_source_output *o, pa_source_output_state_t state) {
614 pa_assert_ctl_context();
619 if (o->state == PA_SOURCE_OUTPUT_CORKED && state != PA_SOURCE_OUTPUT_CORKED)
620 pa_assert_se(o->source->n_corked -- >= 1);
621 else if (o->state != PA_SOURCE_OUTPUT_CORKED && state == PA_SOURCE_OUTPUT_CORKED)
622 o->source->n_corked++;
625 /* Called from main context */
626 static void source_output_set_state(pa_source_output *o, pa_source_output_state_t state) {
629 pa_assert_ctl_context();
631 if (o->state == state)
635 if (o->state == PA_SOURCE_OUTPUT_CORKED && state == PA_SOURCE_OUTPUT_RUNNING && pa_source_used_by(o->source) == 0 &&
636 !pa_sample_spec_equal(&o->sample_spec, &o->source->sample_spec)) {
637 /* We were uncorked and the source was not playing anything -- let's try
638 * to update the sample format and rate to avoid resampling */
639 pa_source_reconfigure(o->source, &o->sample_spec, pa_source_output_is_passthrough(o));
642 pa_assert_se(pa_asyncmsgq_send(o->source->asyncmsgq, PA_MSGOBJECT(o), PA_SOURCE_OUTPUT_MESSAGE_SET_STATE, PA_UINT_TO_PTR(state), 0, NULL) == 0);
644 /* If the source is not valid, pa_source_output_set_state_within_thread() must be called directly */
645 pa_source_output_set_state_within_thread(o, state);
647 #ifdef TIZEN_PCM_DUMP
648 if (o->state == PA_SOURCE_OUTPUT_RUNNING && o->pcm_dump_fp && (o->core->pcm_dump & PA_PCM_DUMP_SEPARATED)) {
649 /* close file for dump pcm */
650 fclose(o->pcm_dump_fp);
651 pa_log_info("%s closed", o->dump_path);
652 pa_xfree(o->dump_path);
653 o->pcm_dump_fp = NULL;
657 if (state == PA_SOURCE_OUTPUT_RUNNING)
658 o->time_of_start_to_run = pa_rtclock_now();
660 update_n_corked(o, state);
663 if (state != PA_SOURCE_OUTPUT_UNLINKED) {
664 pa_hook_fire(&o->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_STATE_CHANGED], o);
666 if (PA_SOURCE_OUTPUT_IS_LINKED(state))
667 pa_subscription_post(o->core, PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT|PA_SUBSCRIPTION_EVENT_CHANGE, o->index);
671 pa_source_update_status(o->source);
674 /* Called from main context */
675 void pa_source_output_unlink(pa_source_output*o) {
678 pa_source_output_assert_ref(o);
679 pa_assert_ctl_context();
681 /* See pa_sink_unlink() for a couple of comments how this function
684 pa_source_output_ref(o);
686 linked = PA_SOURCE_OUTPUT_IS_LINKED(o->state);
689 pa_hook_fire(&o->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_UNLINK], o);
691 if (o->direct_on_input)
692 pa_idxset_remove_by_data(o->direct_on_input->direct_outputs, o, NULL);
694 pa_idxset_remove_by_data(o->core->source_outputs, o, NULL);
697 if (pa_idxset_remove_by_data(o->source->outputs, o, NULL))
698 pa_source_output_unref(o);
701 pa_idxset_remove_by_data(o->client->source_outputs, o, NULL);
703 update_n_corked(o, PA_SOURCE_OUTPUT_UNLINKED);
704 o->state = PA_SOURCE_OUTPUT_UNLINKED;
706 if (linked && o->source) {
707 if (pa_source_output_is_passthrough(o))
708 pa_source_leave_passthrough(o->source);
710 /* We might need to update the source's volume if we are in flat volume mode. */
711 if (pa_source_flat_volume_enabled(o->source))
712 pa_source_set_volume(o->source, NULL, false, false);
714 if (o->source->asyncmsgq)
715 pa_assert_se(pa_asyncmsgq_send(o->source->asyncmsgq, PA_MSGOBJECT(o->source), PA_SOURCE_MESSAGE_REMOVE_OUTPUT, o, 0, NULL) == 0);
721 if (PA_SOURCE_IS_LINKED(o->source->state))
722 pa_source_update_status(o->source);
728 pa_subscription_post(o->core, PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT|PA_SUBSCRIPTION_EVENT_REMOVE, o->index);
729 pa_hook_fire(&o->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_UNLINK_POST], o);
732 pa_core_maybe_vacuum(o->core);
734 pa_source_output_unref(o);
737 /* Called from main context */
738 static void source_output_free(pa_object* mo) {
739 pa_source_output *o = PA_SOURCE_OUTPUT(mo);
742 pa_assert_ctl_context();
743 pa_assert(pa_source_output_refcnt(o) == 0);
744 pa_assert(!PA_SOURCE_OUTPUT_IS_LINKED(o->state));
746 pa_log_info("Freeing output %u \"%s\"", o->index,
747 o->proplist ? pa_strnull(pa_proplist_gets(o->proplist, PA_PROP_MEDIA_NAME)) : "");
749 if (o->thread_info.delay_memblockq)
750 pa_memblockq_free(o->thread_info.delay_memblockq);
752 if (o->thread_info.resampler)
753 pa_resampler_free(o->thread_info.resampler);
754 #ifdef TIZEN_PCM_DUMP
755 /* close file for dump pcm */
756 if (o->pcm_dump_fp) {
757 fclose(o->pcm_dump_fp);
758 pa_log_info("%s closed", o->dump_path);
759 pa_xfree(o->dump_path);
760 o->pcm_dump_fp = NULL;
765 pa_format_info_free(o->format);
768 pa_proplist_free(o->proplist);
770 if (o->preferred_source)
771 pa_xfree(o->preferred_source);
777 /* Called from main context */
778 void pa_source_output_put(pa_source_output *o) {
779 pa_source_output_state_t state;
781 pa_source_output_assert_ref(o);
782 pa_assert_ctl_context();
784 pa_assert(o->state == PA_SOURCE_OUTPUT_INIT);
786 /* The following fields must be initialized properly */
790 state = o->flags & PA_SOURCE_OUTPUT_START_CORKED ? PA_SOURCE_OUTPUT_CORKED : PA_SOURCE_OUTPUT_RUNNING;
792 update_n_corked(o, state);
795 /* We might need to update the source's volume if we are in flat volume mode. */
796 if (pa_source_flat_volume_enabled(o->source))
797 pa_source_set_volume(o->source, NULL, false, o->save_volume);
799 if (o->destination_source && (o->destination_source->flags & PA_SOURCE_SHARE_VOLUME_WITH_MASTER)) {
800 pa_assert(pa_cvolume_is_norm(&o->volume));
801 pa_assert(pa_cvolume_is_norm(&o->reference_ratio));
804 set_real_ratio(o, &o->volume);
807 if (pa_source_output_is_passthrough(o))
808 pa_source_enter_passthrough(o->source);
810 o->thread_info.soft_volume = o->soft_volume;
811 o->thread_info.muted = o->muted;
813 pa_assert_se(pa_asyncmsgq_send(o->source->asyncmsgq, PA_MSGOBJECT(o->source), PA_SOURCE_MESSAGE_ADD_OUTPUT, o, 0, NULL) == 0);
815 pa_subscription_post(o->core, PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT|PA_SUBSCRIPTION_EVENT_NEW, o->index);
816 pa_hook_fire(&o->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_PUT], o);
818 pa_source_update_status(o->source);
821 /* Called from main context */
822 void pa_source_output_kill(pa_source_output*o) {
823 pa_source_output_assert_ref(o);
824 pa_assert_ctl_context();
825 pa_assert(PA_SOURCE_OUTPUT_IS_LINKED(o->state));
830 /* Called from main context */
831 pa_usec_t pa_source_output_get_latency(pa_source_output *o, pa_usec_t *source_latency) {
832 pa_usec_t r[2] = { 0, 0 };
834 pa_source_output_assert_ref(o);
835 pa_assert_ctl_context();
836 pa_assert(PA_SOURCE_OUTPUT_IS_LINKED(o->state));
838 pa_assert_se(pa_asyncmsgq_send(o->source->asyncmsgq, PA_MSGOBJECT(o), PA_SOURCE_OUTPUT_MESSAGE_GET_LATENCY, r, 0, NULL) == 0);
841 r[0] += o->get_latency(o);
844 *source_latency = r[1];
849 /* Called from thread context */
850 void pa_source_output_push(pa_source_output *o, const pa_memchunk *chunk) {
851 bool need_volume_factor_source;
854 size_t limit, mbs = 0;
856 pa_memchunk ochunk = { .memblock = NULL };
859 pa_source_output_assert_ref(o);
860 pa_source_output_assert_io_context(o);
861 pa_assert(PA_SOURCE_OUTPUT_IS_LINKED(o->thread_info.state));
863 pa_assert(pa_frame_aligned(chunk->length, &o->source->sample_spec));
865 if (!o->push || o->thread_info.state == PA_SOURCE_OUTPUT_CORKED)
868 pa_assert(o->thread_info.state == PA_SOURCE_OUTPUT_RUNNING);
870 if (pa_memblockq_push(o->thread_info.delay_memblockq, chunk) < 0) {
871 pa_log_debug("Delay queue overflow!");
872 pa_memblockq_seek(o->thread_info.delay_memblockq, (int64_t) chunk->length, PA_SEEK_RELATIVE, true);
875 limit = o->process_rewind ? 0 : o->source->thread_info.max_rewind;
877 volume_is_norm = pa_cvolume_is_norm(&o->thread_info.soft_volume) && !o->thread_info.muted;
878 need_volume_factor_source = !pa_cvolume_is_norm(&o->volume_factor_source);
880 if (limit > 0 && o->source->monitor_of) {
884 /* Hmm, check the latency for knowing how much of the buffered
885 * data is actually still unplayed and might hence still
886 * change. This is suboptimal. Ideally we'd have a call like
887 * pa_sink_get_changeable_size() or so that tells us how much
888 * of the queued data is actually still changeable. Hence
891 latency = pa_sink_get_latency_within_thread(o->source->monitor_of, false);
893 n = pa_usec_to_bytes(latency, &o->source->sample_spec);
899 /* Implement the delay queue */
900 while ((length = pa_memblockq_get_length(o->thread_info.delay_memblockq)) > limit) {
902 bool nvfs = need_volume_factor_source;
906 pa_assert_se(pa_memblockq_peek(o->thread_info.delay_memblockq, &qchunk) >= 0);
908 if (qchunk.length > length)
909 qchunk.length = length;
911 pa_assert(qchunk.length > 0);
913 /* It might be necessary to adjust the volume here */
914 if (!volume_is_norm) {
915 pa_memchunk_make_writable(&qchunk, 0);
917 if (o->thread_info.muted) {
918 pa_silence_memchunk(&qchunk, &o->source->sample_spec);
921 } else if (!o->thread_info.resampler && nvfs) {
924 /* If we don't need a resampler we can merge the
925 * post and the pre volume adjustment into one */
927 pa_sw_cvolume_multiply(&v, &o->thread_info.soft_volume, &o->volume_factor_source);
928 pa_volume_memchunk(&qchunk, &o->source->sample_spec, &v);
932 pa_volume_memchunk(&qchunk, &o->source->sample_spec, &o->thread_info.soft_volume);
936 pa_memchunk_make_writable(&qchunk, 0);
937 pa_volume_memchunk(&qchunk, &o->source->sample_spec, &o->volume_factor_source);
940 if (!o->thread_info.resampler) {
943 int ret = o->preprocess(o, &qchunk, &ochunk);
945 /* in case of -2(ERR_BUFFERING), pushing a memblock should be skipped.
946 * Because the preprocess needs more blocks to apply audio-effects */
961 mbs = pa_resampler_max_block_size(o->thread_info.resampler);
963 if (qchunk.length > mbs)
966 pa_resampler_run(o->thread_info.resampler, &qchunk, &rchunk);
968 if (rchunk.length > 0) {
971 int ret = o->preprocess(o, &rchunk, &ochunk);
986 pa_memblock_unref(rchunk.memblock);
989 pa_memblock_unref(qchunk.memblock);
990 pa_memblockq_drop(o->thread_info.delay_memblockq, qchunk.length);
994 pa_memblock_unref(ochunk.memblock);
997 #ifdef TIZEN_PCM_DUMP
998 pa_source_output_write_pcm_dump(o, (pa_memchunk *)chunk);
1002 /* Called from thread context */
1003 void pa_source_output_process_rewind(pa_source_output *o, size_t nbytes /* in source sample spec */) {
1005 pa_source_output_assert_ref(o);
1006 pa_source_output_assert_io_context(o);
1007 pa_assert(PA_SOURCE_OUTPUT_IS_LINKED(o->thread_info.state));
1008 pa_assert(pa_frame_aligned(nbytes, &o->source->sample_spec));
1013 if (o->process_rewind) {
1014 pa_assert(pa_memblockq_get_length(o->thread_info.delay_memblockq) == 0);
1016 if (o->thread_info.resampler)
1017 nbytes = pa_resampler_result(o->thread_info.resampler, nbytes);
1019 pa_log_debug("Have to rewind %lu bytes on implementor.", (unsigned long) nbytes);
1020 #ifdef TIZEN_PCM_DUMP
1023 fseeko(o->pcm_dump_fp, (off_t)nbytes * (-1), SEEK_CUR);
1027 o->process_rewind(o, nbytes);
1029 if (o->thread_info.resampler)
1030 pa_resampler_rewind(o->thread_info.resampler, nbytes);
1033 pa_memblockq_seek(o->thread_info.delay_memblockq, - ((int64_t) nbytes), PA_SEEK_RELATIVE, true);
1036 /* Called from thread context */
1037 size_t pa_source_output_get_max_rewind(pa_source_output *o) {
1038 pa_source_output_assert_ref(o);
1039 pa_source_output_assert_io_context(o);
1041 return o->thread_info.resampler ? pa_resampler_request(o->thread_info.resampler, o->source->thread_info.max_rewind) : o->source->thread_info.max_rewind;
1044 /* Called from thread context */
1045 void pa_source_output_update_max_rewind(pa_source_output *o, size_t nbytes /* in the source's sample spec */) {
1046 pa_source_output_assert_ref(o);
1047 pa_source_output_assert_io_context(o);
1048 pa_assert(PA_SOURCE_OUTPUT_IS_LINKED(o->thread_info.state));
1049 pa_assert(pa_frame_aligned(nbytes, &o->source->sample_spec));
1051 if (o->update_max_rewind)
1052 o->update_max_rewind(o, o->thread_info.resampler ? pa_resampler_result(o->thread_info.resampler, nbytes) : nbytes);
1055 /* Called from thread context */
1056 pa_usec_t pa_source_output_set_requested_latency_within_thread(pa_source_output *o, pa_usec_t usec) {
1057 pa_source_output_assert_ref(o);
1058 pa_source_output_assert_io_context(o);
1060 if (!(o->source->flags & PA_SOURCE_DYNAMIC_LATENCY))
1061 usec = o->source->thread_info.fixed_latency;
1063 if (usec != (pa_usec_t) -1)
1064 usec = PA_CLAMP(usec, o->source->thread_info.min_latency, o->source->thread_info.max_latency);
1066 o->thread_info.requested_source_latency = usec;
1067 pa_source_invalidate_requested_latency(o->source, true);
1072 /* Called from main context */
1073 pa_usec_t pa_source_output_set_requested_latency(pa_source_output *o, pa_usec_t usec) {
1074 pa_source_output_assert_ref(o);
1075 pa_assert_ctl_context();
1077 if (PA_SOURCE_OUTPUT_IS_LINKED(o->state) && o->source) {
1078 pa_assert_se(pa_asyncmsgq_send(o->source->asyncmsgq, PA_MSGOBJECT(o), PA_SOURCE_OUTPUT_MESSAGE_SET_REQUESTED_LATENCY, &usec, 0, NULL) == 0);
1082 /* If this source output is not realized yet or is being moved, we
1083 * have to touch the thread info data directly */
1086 if (!(o->source->flags & PA_SOURCE_DYNAMIC_LATENCY))
1087 usec = pa_source_get_fixed_latency(o->source);
1089 if (usec != (pa_usec_t) -1) {
1090 pa_usec_t min_latency, max_latency;
1091 pa_source_get_latency_range(o->source, &min_latency, &max_latency);
1092 usec = PA_CLAMP(usec, min_latency, max_latency);
1096 o->thread_info.requested_source_latency = usec;
1101 /* Called from main context */
1102 pa_usec_t pa_source_output_get_requested_latency(pa_source_output *o) {
1103 pa_source_output_assert_ref(o);
1104 pa_assert_ctl_context();
1106 if (PA_SOURCE_OUTPUT_IS_LINKED(o->state) && o->source) {
1108 pa_assert_se(pa_asyncmsgq_send(o->source->asyncmsgq, PA_MSGOBJECT(o), PA_SOURCE_OUTPUT_MESSAGE_GET_REQUESTED_LATENCY, &usec, 0, NULL) == 0);
1112 /* If this source output is not realized yet or is being moved, we
1113 * have to touch the thread info data directly */
1115 return o->thread_info.requested_source_latency;
1118 /* Called from main context */
1119 void pa_source_output_set_volume(pa_source_output *o, const pa_cvolume *volume, bool save, bool absolute) {
1122 pa_source_output_assert_ref(o);
1123 pa_assert_ctl_context();
1124 pa_assert(PA_SOURCE_OUTPUT_IS_LINKED(o->state));
1126 pa_assert(pa_cvolume_valid(volume));
1127 pa_assert(volume->channels == 1 || pa_cvolume_compatible(volume, &o->sample_spec));
1128 pa_assert(o->volume_writable);
1130 if (!absolute && pa_source_flat_volume_enabled(o->source)) {
1131 v = o->source->reference_volume;
1132 pa_cvolume_remap(&v, &o->source->channel_map, &o->channel_map);
1134 if (pa_cvolume_compatible(volume, &o->sample_spec))
1135 volume = pa_sw_cvolume_multiply(&v, &v, volume);
1137 volume = pa_sw_cvolume_multiply_scalar(&v, &v, pa_cvolume_max(volume));
1139 if (!pa_cvolume_compatible(volume, &o->sample_spec)) {
1141 volume = pa_cvolume_scale(&v, pa_cvolume_max(volume));
1145 if (pa_cvolume_equal(volume, &o->volume)) {
1146 o->save_volume = o->save_volume || save;
1150 pa_source_output_set_volume_direct(o, volume);
1151 o->save_volume = save;
1153 if (pa_source_flat_volume_enabled(o->source)) {
1154 /* We are in flat volume mode, so let's update all source input
1155 * volumes and update the flat volume of the source */
1157 pa_source_set_volume(o->source, NULL, true, save);
1160 /* OK, we are in normal volume mode. The volume only affects
1162 set_real_ratio(o, volume);
1164 /* Copy the new soft_volume to the thread_info struct */
1165 pa_assert_se(pa_asyncmsgq_send(o->source->asyncmsgq, PA_MSGOBJECT(o), PA_SOURCE_OUTPUT_MESSAGE_SET_SOFT_VOLUME, NULL, 0, NULL) == 0);
1168 /* The volume changed, let's tell people so */
1169 if (o->volume_changed)
1170 o->volume_changed(o);
1172 /* The virtual volume changed, let's tell people so */
1173 pa_subscription_post(o->core, PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT|PA_SUBSCRIPTION_EVENT_CHANGE, o->index);
1176 /* Called from main context */
1177 static void set_real_ratio(pa_source_output *o, const pa_cvolume *v) {
1178 pa_source_output_assert_ref(o);
1179 pa_assert_ctl_context();
1180 pa_assert(PA_SOURCE_OUTPUT_IS_LINKED(o->state));
1181 pa_assert(!v || pa_cvolume_compatible(v, &o->sample_spec));
1183 /* This basically calculates:
1185 * o->real_ratio := v
1186 * o->soft_volume := o->real_ratio * o->volume_factor */
1191 pa_cvolume_reset(&o->real_ratio, o->sample_spec.channels);
1193 pa_sw_cvolume_multiply(&o->soft_volume, &o->real_ratio, &o->volume_factor);
1194 /* We don't copy the data to the thread_info data. That's left for someone else to do */
1197 /* Called from main or I/O context */
1198 bool pa_source_output_is_passthrough(pa_source_output *o) {
1199 pa_source_output_assert_ref(o);
1201 if (PA_UNLIKELY(!pa_format_info_is_pcm(o->format)))
1204 if (PA_UNLIKELY(o->flags & PA_SOURCE_OUTPUT_PASSTHROUGH))
1210 /* Called from main context */
1211 bool pa_source_output_is_volume_readable(pa_source_output *o) {
1212 pa_source_output_assert_ref(o);
1213 pa_assert_ctl_context();
1215 return !pa_source_output_is_passthrough(o);
1218 /* Called from main context */
1219 pa_cvolume *pa_source_output_get_volume(pa_source_output *o, pa_cvolume *volume, bool absolute) {
1220 pa_source_output_assert_ref(o);
1221 pa_assert_ctl_context();
1222 pa_assert(PA_SOURCE_OUTPUT_IS_LINKED(o->state));
1223 pa_assert(pa_source_output_is_volume_readable(o));
1225 if (absolute || !pa_source_flat_volume_enabled(o->source))
1226 *volume = o->volume;
1228 *volume = o->reference_ratio;
1233 /* Called from main context */
1234 void pa_source_output_set_mute(pa_source_output *o, bool mute, bool save) {
1237 pa_source_output_assert_ref(o);
1238 pa_assert_ctl_context();
1239 pa_assert(PA_SOURCE_OUTPUT_IS_LINKED(o->state));
1241 old_mute = o->muted;
1243 if (mute == old_mute) {
1244 o->save_muted |= save;
1249 pa_log_debug("The mute of source output %u changed from %s to %s.", o->index, pa_yes_no(old_mute), pa_yes_no(mute));
1251 o->save_muted = save;
1253 pa_assert_se(pa_asyncmsgq_send(o->source->asyncmsgq, PA_MSGOBJECT(o), PA_SOURCE_OUTPUT_MESSAGE_SET_SOFT_MUTE, NULL, 0, NULL) == 0);
1255 /* The mute status changed, let's tell people so */
1256 if (o->mute_changed)
1259 pa_subscription_post(o->core, PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT|PA_SUBSCRIPTION_EVENT_CHANGE, o->index);
1260 pa_hook_fire(&o->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_MUTE_CHANGED], o);
1263 void pa_source_output_set_property(pa_source_output *o, const char *key, const char *value) {
1264 char *old_value = NULL;
1265 const char *new_value;
1270 if (pa_proplist_contains(o->proplist, key)) {
1271 old_value = pa_xstrdup(pa_proplist_gets(o->proplist, key));
1272 if (value && old_value && pa_streq(value, old_value))
1276 old_value = pa_xstrdup("(data)");
1281 old_value = pa_xstrdup("(unset)");
1285 pa_proplist_sets(o->proplist, key, value);
1288 pa_proplist_unset(o->proplist, key);
1289 new_value = "(unset)";
1292 if (PA_SOURCE_OUTPUT_IS_LINKED(o->state)) {
1293 pa_log_debug("Source output %u: proplist[%s]: %s -> %s", o->index, key, old_value, new_value);
1294 pa_hook_fire(&o->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_PROPLIST_CHANGED], o);
1295 pa_subscription_post(o->core, PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT | PA_SUBSCRIPTION_EVENT_CHANGE, o->index);
1299 pa_xfree(old_value);
1302 void pa_source_output_set_property_arbitrary(pa_source_output *o, const char *key, const uint8_t *value, size_t nbytes) {
1303 const uint8_t *old_value;
1305 const char *old_value_str;
1306 const char *new_value_str;
1311 if (pa_proplist_get(o->proplist, key, (const void **) &old_value, &old_nbytes) >= 0) {
1312 if (value && nbytes == old_nbytes && !memcmp(value, old_value, nbytes))
1315 old_value_str = "(data)";
1321 old_value_str = "(unset)";
1325 pa_proplist_set(o->proplist, key, value, nbytes);
1326 new_value_str = "(data)";
1328 pa_proplist_unset(o->proplist, key);
1329 new_value_str = "(unset)";
1332 if (PA_SOURCE_OUTPUT_IS_LINKED(o->state)) {
1333 pa_log_debug("Source output %u: proplist[%s]: %s -> %s", o->index, key, old_value_str, new_value_str);
1334 pa_hook_fire(&o->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_PROPLIST_CHANGED], o);
1335 pa_subscription_post(o->core, PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT | PA_SUBSCRIPTION_EVENT_CHANGE, o->index);
1339 /* Called from main thread */
1340 void pa_source_output_update_proplist(pa_source_output *o, pa_update_mode_t mode, pa_proplist *p) {
1343 const uint8_t *value;
1346 pa_source_output_assert_ref(o);
1348 pa_assert_ctl_context();
1352 /* Delete everything that is not in p. */
1353 for (state = NULL; (key = pa_proplist_iterate(o->proplist, &state));) {
1354 if (!pa_proplist_contains(p, key))
1355 pa_source_output_set_property(o, key, NULL);
1359 case PA_UPDATE_REPLACE:
1360 for (state = NULL; (key = pa_proplist_iterate(p, &state));) {
1361 pa_proplist_get(p, key, (const void **) &value, &nbytes);
1362 pa_source_output_set_property_arbitrary(o, key, value, nbytes);
1366 case PA_UPDATE_MERGE:
1367 for (state = NULL; (key = pa_proplist_iterate(p, &state));) {
1368 if (pa_proplist_contains(o->proplist, key))
1371 pa_proplist_get(p, key, (const void **) &value, &nbytes);
1372 pa_source_output_set_property_arbitrary(o, key, value, nbytes);
1379 /* Called from main context */
1380 void pa_source_output_cork(pa_source_output *o, bool b) {
1381 pa_source_output_assert_ref(o);
1382 pa_assert_ctl_context();
1383 pa_assert(PA_SOURCE_OUTPUT_IS_LINKED(o->state));
1385 source_output_set_state(o, b ? PA_SOURCE_OUTPUT_CORKED : PA_SOURCE_OUTPUT_RUNNING);
1388 /* Called from main context */
1389 int pa_source_output_set_rate(pa_source_output *o, uint32_t rate) {
1390 pa_source_output_assert_ref(o);
1391 pa_assert_ctl_context();
1392 pa_assert(PA_SOURCE_OUTPUT_IS_LINKED(o->state));
1393 pa_return_val_if_fail(o->thread_info.resampler, -PA_ERR_BADSTATE);
1395 if (o->sample_spec.rate == rate)
1398 o->sample_spec.rate = rate;
1400 pa_asyncmsgq_post(o->source->asyncmsgq, PA_MSGOBJECT(o), PA_SOURCE_OUTPUT_MESSAGE_SET_RATE, PA_UINT_TO_PTR(rate), 0, NULL, NULL);
1402 pa_subscription_post(o->core, PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT|PA_SUBSCRIPTION_EVENT_CHANGE, o->index);
1406 /* Called from main context */
1407 pa_resample_method_t pa_source_output_get_resample_method(pa_source_output *o) {
1408 pa_source_output_assert_ref(o);
1409 pa_assert_ctl_context();
1411 return o->actual_resample_method;
1414 /* Called from main context */
1415 bool pa_source_output_may_move(pa_source_output *o) {
1416 pa_source_output_assert_ref(o);
1417 pa_assert_ctl_context();
1418 pa_assert(PA_SOURCE_OUTPUT_IS_LINKED(o->state));
1420 if (o->flags & PA_SOURCE_OUTPUT_DONT_MOVE)
1423 if (o->direct_on_input)
1429 static bool find_filter_source_output(pa_source_output *target, pa_source *s) {
1430 unsigned PA_UNUSED i = 0;
1431 while (s && s->output_from_master) {
1432 if (s->output_from_master == target)
1434 s = s->output_from_master->source;
1435 pa_assert(i++ < 100);
1440 static bool is_filter_source_moving(pa_source_output *o) {
1441 pa_source *source = o->source;
1446 while (source->output_from_master) {
1447 source = source->output_from_master->source;
1456 /* Called from main context */
1457 bool pa_source_output_may_move_to(pa_source_output *o, pa_source *dest) {
1458 pa_source_output_assert_ref(o);
1459 pa_assert(PA_SOURCE_OUTPUT_IS_LINKED(o->state));
1460 pa_source_assert_ref(dest);
1462 if (dest == o->source)
1465 if (dest->unlink_requested)
1468 if (!pa_source_output_may_move(o))
1471 /* Make sure we're not creating a filter source cycle */
1472 if (find_filter_source_output(o, dest)) {
1473 pa_log_debug("Can't connect output to %s, as that would create a cycle.", dest->name);
1477 /* If this source output is connected to a filter source that itself is
1478 * moving, then don't allow the move. Moving requires sending a message to
1479 * the IO thread of the old source, and if the old source is a filter
1480 * source that is moving, there's no IO thread associated to the old
1482 if (is_filter_source_moving(o)) {
1483 pa_log_debug("Can't move output from filter source %s, because the filter source itself is currently moving.",
1488 if (pa_idxset_size(dest->outputs) >= PA_MAX_OUTPUTS_PER_SOURCE) {
1489 pa_log_warn("Failed to move source output: too many outputs per source.");
1494 if (!o->may_move_to(o, dest))
1500 /* Called from main context */
1501 int pa_source_output_start_move(pa_source_output *o) {
1505 pa_source_output_assert_ref(o);
1506 pa_assert_ctl_context();
1507 pa_assert(PA_SOURCE_OUTPUT_IS_LINKED(o->state));
1508 pa_assert(o->source);
1510 if (!pa_source_output_may_move(o))
1511 return -PA_ERR_NOTSUPPORTED;
1513 if ((r = pa_hook_fire(&o->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_MOVE_START], o)) < 0)
1516 pa_log_debug("Starting to move source output %u from '%s'", (unsigned) o->index, o->source->name);
1520 pa_idxset_remove_by_data(o->source->outputs, o, NULL);
1522 if (o->state == PA_SOURCE_OUTPUT_CORKED)
1523 pa_assert_se(origin->n_corked-- >= 1);
1525 if (pa_source_output_is_passthrough(o))
1526 pa_source_leave_passthrough(o->source);
1528 if (pa_source_flat_volume_enabled(o->source))
1529 /* We might need to update the source's volume if we are in flat
1531 pa_source_set_volume(o->source, NULL, false, false);
1533 pa_assert_se(pa_asyncmsgq_send(o->source->asyncmsgq, PA_MSGOBJECT(o->source), PA_SOURCE_MESSAGE_REMOVE_OUTPUT, o, 0, NULL) == 0);
1535 pa_source_update_status(o->source);
1537 pa_cvolume_remap(&o->volume_factor_source, &o->source->channel_map, &o->channel_map);
1540 o->source_requested_by_application = false;
1542 pa_source_output_unref(o);
1547 /* Called from main context. If it has an origin source that uses volume sharing,
1548 * then also the origin source and all streams connected to it need to update
1549 * their volume - this function does all that by using recursion. */
1550 static void update_volume_due_to_moving(pa_source_output *o, pa_source *dest) {
1551 pa_cvolume new_volume;
1555 pa_assert(o->source); /* The destination source should already be set. */
1557 if (o->destination_source && (o->destination_source->flags & PA_SOURCE_SHARE_VOLUME_WITH_MASTER)) {
1558 pa_source *root_source;
1559 pa_source_output *destination_source_output;
1562 root_source = pa_source_get_master(o->source);
1564 if (PA_UNLIKELY(!root_source))
1567 if (pa_source_flat_volume_enabled(o->source)) {
1568 /* Ok, so the origin source uses volume sharing, and flat volume is
1569 * enabled. The volume will have to be updated as follows:
1571 * o->volume := o->source->real_volume
1572 * (handled later by pa_source_set_volume)
1573 * o->reference_ratio := o->volume / o->source->reference_volume
1574 * (handled later by pa_source_set_volume)
1575 * o->real_ratio stays unchanged
1576 * (streams whose origin source uses volume sharing should
1577 * always have real_ratio of 0 dB)
1578 * o->soft_volume stays unchanged
1579 * (streams whose origin source uses volume sharing should
1580 * always have volume_factor as soft_volume, so no change
1581 * should be needed) */
1583 pa_assert(pa_cvolume_is_norm(&o->real_ratio));
1584 pa_assert(pa_cvolume_equal(&o->soft_volume, &o->volume_factor));
1586 /* Notifications will be sent by pa_source_set_volume(). */
1589 /* Ok, so the origin source uses volume sharing, and flat volume is
1590 * disabled. The volume will have to be updated as follows:
1593 * o->reference_ratio := 0 dB
1594 * o->real_ratio stays unchanged
1595 * (streams whose origin source uses volume sharing should
1596 * always have real_ratio of 0 dB)
1597 * o->soft_volume stays unchanged
1598 * (streams whose origin source uses volume sharing should
1599 * always have volume_factor as soft_volume, so no change
1600 * should be needed) */
1602 pa_cvolume_reset(&new_volume, o->volume.channels);
1603 pa_source_output_set_volume_direct(o, &new_volume);
1604 pa_source_output_set_reference_ratio(o, &new_volume);
1605 pa_assert(pa_cvolume_is_norm(&o->real_ratio));
1606 pa_assert(pa_cvolume_equal(&o->soft_volume, &o->volume_factor));
1609 /* Additionally, the origin source volume needs updating:
1611 * o->destination_source->reference_volume := root_source->reference_volume
1612 * o->destination_source->real_volume := root_source->real_volume
1613 * o->destination_source->soft_volume stays unchanged
1614 * (sources that use volume sharing should always have
1615 * soft_volume of 0 dB) */
1617 new_volume = root_source->reference_volume;
1618 pa_cvolume_remap(&new_volume, &root_source->channel_map, &o->destination_source->channel_map);
1619 pa_source_set_reference_volume_direct(o->destination_source, &new_volume);
1621 o->destination_source->real_volume = root_source->real_volume;
1622 pa_cvolume_remap(&o->destination_source->real_volume, &root_source->channel_map, &o->destination_source->channel_map);
1624 pa_assert(pa_cvolume_is_norm(&o->destination_source->soft_volume));
1626 /* If you wonder whether o->destination_source->set_volume() should be
1627 * called somewhere, that's not the case, because sources that use
1628 * volume sharing shouldn't have any internal volume that set_volume()
1629 * would update. If you wonder whether the thread_info variables should
1630 * be synced, yes, they should, and it's done by the
1631 * PA_SOURCE_MESSAGE_FINISH_MOVE message handler. */
1633 /* Recursively update origin source outputs. */
1634 PA_IDXSET_FOREACH(destination_source_output, o->destination_source->outputs, idx)
1635 update_volume_due_to_moving(destination_source_output, dest);
1638 if (pa_source_flat_volume_enabled(o->source)) {
1639 /* Ok, so this is a regular stream, and flat volume is enabled. The
1640 * volume will have to be updated as follows:
1642 * o->volume := o->reference_ratio * o->source->reference_volume
1643 * o->reference_ratio stays unchanged
1644 * o->real_ratio := o->volume / o->source->real_volume
1645 * (handled later by pa_source_set_volume)
1646 * o->soft_volume := o->real_ratio * o->volume_factor
1647 * (handled later by pa_source_set_volume) */
1649 new_volume = o->source->reference_volume;
1650 pa_cvolume_remap(&new_volume, &o->source->channel_map, &o->channel_map);
1651 pa_sw_cvolume_multiply(&new_volume, &new_volume, &o->reference_ratio);
1652 pa_source_output_set_volume_direct(o, &new_volume);
1655 /* Ok, so this is a regular stream, and flat volume is disabled.
1656 * The volume will have to be updated as follows:
1658 * o->volume := o->reference_ratio
1659 * o->reference_ratio stays unchanged
1660 * o->real_ratio := o->reference_ratio
1661 * o->soft_volume := o->real_ratio * o->volume_factor */
1663 pa_source_output_set_volume_direct(o, &o->reference_ratio);
1664 o->real_ratio = o->reference_ratio;
1665 pa_sw_cvolume_multiply(&o->soft_volume, &o->real_ratio, &o->volume_factor);
1667 /* If this is a virtual source stream, we have to apply the source volume
1668 * to the source output. */
1669 if (o->destination_source) {
1672 vol = o->destination_source->real_volume;
1673 pa_cvolume_remap(&vol, &o->destination_source->channel_map, &o->channel_map);
1674 pa_source_output_set_volume(o, &vol, o->destination_source->save_volume, true);
1679 /* If o->source == dest, then recursion has finished, and we can finally call
1680 * pa_source_set_volume(), which will do the rest of the updates. */
1681 if ((o->source == dest) && pa_source_flat_volume_enabled(o->source))
1682 pa_source_set_volume(o->source, NULL, false, o->save_volume);
1685 /* Called from the main thread. */
1686 static void set_preferred_source(pa_source_output *o, const char *source_name) {
1689 if (pa_safe_streq(o->preferred_source, source_name))
1692 pa_log_debug("Source output %u: preferred_source: %s -> %s",
1693 o->index, o->preferred_source ? o->preferred_source : "(unset)", source_name ? source_name : "(unset)");
1694 pa_xfree(o->preferred_source);
1695 o->preferred_source = pa_xstrdup(source_name);
1697 pa_subscription_post(o->core, PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT | PA_SUBSCRIPTION_EVENT_CHANGE, o->index);
1698 pa_hook_fire(&o->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_PREFERRED_SOURCE_CHANGED], o);
1701 /* Called from main context */
1702 int pa_source_output_finish_move(pa_source_output *o, pa_source *dest, bool save) {
1703 pa_source_output_assert_ref(o);
1704 pa_assert_ctl_context();
1705 pa_assert(PA_SOURCE_OUTPUT_IS_LINKED(o->state));
1706 pa_assert(!o->source);
1707 pa_source_assert_ref(dest);
1709 if (!pa_source_output_may_move_to(o, dest))
1710 return -PA_ERR_NOTSUPPORTED;
1712 if (pa_source_output_is_passthrough(o) && !pa_source_check_format(dest, o->format)) {
1713 pa_proplist *p = pa_proplist_new();
1714 pa_log_debug("New source doesn't support stream format, sending format-changed and killing");
1715 /* Tell the client what device we want to be on if it is going to
1717 pa_proplist_sets(p, "device", dest->name);
1718 pa_source_output_send_event(o, PA_STREAM_EVENT_FORMAT_LOST, p);
1719 pa_proplist_free(p);
1720 return -PA_ERR_NOTSUPPORTED;
1723 if (!(o->flags & PA_SOURCE_OUTPUT_VARIABLE_RATE) &&
1724 !pa_sample_spec_equal(&o->sample_spec, &dest->sample_spec)) {
1725 /* try to change dest source format and rate if possible without glitches.
1726 module-suspend-on-idle resumes destination source with
1727 SOURCE_OUTPUT_MOVE_FINISH hook */
1729 pa_log_info("Trying to change sample spec");
1730 pa_source_reconfigure(dest, &o->sample_spec, pa_source_output_is_passthrough(o));
1737 /* save == true, means user is calling the move_to() and want to
1738 save the preferred_source */
1740 if (dest == dest->core->default_source)
1741 set_preferred_source(o, NULL);
1743 set_preferred_source(o, dest->name);
1746 pa_idxset_put(o->source->outputs, pa_source_output_ref(o), NULL);
1748 pa_cvolume_remap(&o->volume_factor_source, &o->channel_map, &o->source->channel_map);
1750 if (o->state == PA_SOURCE_OUTPUT_CORKED)
1751 o->source->n_corked++;
1753 pa_source_output_update_resampler(o);
1755 pa_source_update_status(dest);
1757 update_volume_due_to_moving(o, dest);
1759 if (pa_source_output_is_passthrough(o))
1760 pa_source_enter_passthrough(o->source);
1762 pa_assert_se(pa_asyncmsgq_send(o->source->asyncmsgq, PA_MSGOBJECT(o->source), PA_SOURCE_MESSAGE_ADD_OUTPUT, o, 0, NULL) == 0);
1764 pa_log_debug("Successfully moved source output %i to %s.", o->index, dest->name);
1766 /* Notify everyone */
1767 pa_hook_fire(&o->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_MOVE_FINISH], o);
1768 pa_subscription_post(o->core, PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT|PA_SUBSCRIPTION_EVENT_CHANGE, o->index);
1773 /* Called from main context */
1774 void pa_source_output_fail_move(pa_source_output *o) {
1776 pa_source_output_assert_ref(o);
1777 pa_assert_ctl_context();
1778 pa_assert(PA_SOURCE_OUTPUT_IS_LINKED(o->state));
1779 pa_assert(!o->source);
1781 /* Check if someone wants this source output? */
1782 if (pa_hook_fire(&o->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_MOVE_FAIL], o) == PA_HOOK_STOP)
1785 /* Can we move the source output to the default source? */
1786 if (o->core->rescue_streams && pa_source_output_may_move_to(o, o->core->default_source)) {
1787 if (pa_source_output_finish_move(o, o->core->default_source, false) >= 0)
1794 pa_source_output_kill(o);
1797 /* Called from main context */
1798 int pa_source_output_move_to(pa_source_output *o, pa_source *dest, bool save) {
1801 pa_source_output_assert_ref(o);
1802 pa_assert_ctl_context();
1803 pa_assert(PA_SOURCE_OUTPUT_IS_LINKED(o->state));
1804 pa_assert(o->source);
1805 pa_source_assert_ref(dest);
1807 if (dest == o->source)
1810 if (!pa_source_output_may_move_to(o, dest))
1811 return -PA_ERR_NOTSUPPORTED;
1813 pa_source_output_ref(o);
1815 if ((r = pa_source_output_start_move(o)) < 0) {
1816 pa_source_output_unref(o);
1820 if ((r = pa_source_output_finish_move(o, dest, save)) < 0) {
1821 pa_source_output_fail_move(o);
1822 pa_source_output_unref(o);
1826 pa_source_output_unref(o);
1831 /* Called from IO thread context except when cork() is called without a valid source. */
1832 void pa_source_output_set_state_within_thread(pa_source_output *o, pa_source_output_state_t state) {
1833 pa_source_output_assert_ref(o);
1835 if (state == o->thread_info.state)
1838 if (o->state_change)
1839 o->state_change(o, state);
1841 o->thread_info.state = state;
1844 /* Called from IO thread context, except when it is not */
1845 int pa_source_output_process_msg(pa_msgobject *mo, int code, void *userdata, int64_t offset, pa_memchunk* chunk) {
1846 pa_source_output *o = PA_SOURCE_OUTPUT(mo);
1847 pa_source_output_assert_ref(o);
1851 case PA_SOURCE_OUTPUT_MESSAGE_GET_LATENCY: {
1852 pa_usec_t *r = userdata;
1854 r[0] += pa_bytes_to_usec(pa_memblockq_get_length(o->thread_info.delay_memblockq), &o->source->sample_spec);
1855 r[1] += pa_source_get_latency_within_thread(o->source, false);
1860 case PA_SOURCE_OUTPUT_MESSAGE_SET_RATE:
1862 o->thread_info.sample_spec.rate = PA_PTR_TO_UINT(userdata);
1863 pa_resampler_set_output_rate(o->thread_info.resampler, PA_PTR_TO_UINT(userdata));
1866 case PA_SOURCE_OUTPUT_MESSAGE_SET_STATE:
1868 pa_source_output_set_state_within_thread(o, PA_PTR_TO_UINT(userdata));
1872 case PA_SOURCE_OUTPUT_MESSAGE_SET_REQUESTED_LATENCY: {
1873 pa_usec_t *usec = userdata;
1875 *usec = pa_source_output_set_requested_latency_within_thread(o, *usec);
1880 case PA_SOURCE_OUTPUT_MESSAGE_GET_REQUESTED_LATENCY: {
1881 pa_usec_t *r = userdata;
1883 *r = o->thread_info.requested_source_latency;
1887 case PA_SOURCE_OUTPUT_MESSAGE_SET_SOFT_VOLUME:
1888 if (!pa_cvolume_equal(&o->thread_info.soft_volume, &o->soft_volume)) {
1889 o->thread_info.soft_volume = o->soft_volume;
1893 case PA_SOURCE_OUTPUT_MESSAGE_SET_SOFT_MUTE:
1894 if (o->thread_info.muted != o->muted) {
1895 o->thread_info.muted = o->muted;
1900 return -PA_ERR_NOTIMPLEMENTED;
1903 /* Called from main context */
1904 void pa_source_output_send_event(pa_source_output *o, const char *event, pa_proplist *data) {
1905 pa_proplist *pl = NULL;
1906 pa_source_output_send_event_hook_data hook_data;
1908 pa_source_output_assert_ref(o);
1909 pa_assert_ctl_context();
1916 data = pl = pa_proplist_new();
1918 hook_data.source_output = o;
1919 hook_data.data = data;
1920 hook_data.event = event;
1922 if (pa_hook_fire(&o->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_SEND_EVENT], &hook_data) < 0)
1925 o->send_event(o, event, data);
1929 pa_proplist_free(pl);
1932 /* Called from main context */
1933 /* Updates the source output's resampler with whatever the current source
1934 * requires -- useful when the underlying source's sample spec might have changed */
1935 int pa_source_output_update_resampler(pa_source_output *o) {
1936 pa_resampler *new_resampler;
1937 char *memblockq_name;
1939 pa_source_output_assert_ref(o);
1940 pa_assert_ctl_context();
1942 if (o->thread_info.resampler &&
1943 pa_sample_spec_equal(pa_resampler_input_sample_spec(o->thread_info.resampler), &o->source->sample_spec) &&
1944 pa_channel_map_equal(pa_resampler_input_channel_map(o->thread_info.resampler), &o->source->channel_map))
1946 new_resampler = o->thread_info.resampler;
1948 else if (!pa_source_output_is_passthrough(o) &&
1949 ((o->flags & PA_SOURCE_OUTPUT_VARIABLE_RATE) ||
1950 !pa_sample_spec_equal(&o->sample_spec, &o->source->sample_spec) ||
1951 !pa_channel_map_equal(&o->channel_map, &o->source->channel_map))) {
1953 new_resampler = pa_resampler_new(o->core->mempool,
1954 &o->source->sample_spec, &o->source->channel_map,
1955 &o->sample_spec, &o->channel_map,
1956 o->core->lfe_crossover_freq,
1957 o->requested_resample_method,
1958 ((o->flags & PA_SOURCE_OUTPUT_VARIABLE_RATE) ? PA_RESAMPLER_VARIABLE_RATE : 0) |
1959 ((o->flags & PA_SOURCE_OUTPUT_NO_REMAP) ? PA_RESAMPLER_NO_REMAP : 0) |
1960 (o->core->disable_remixing || (o->flags & PA_SOURCE_OUTPUT_NO_REMIX) ? PA_RESAMPLER_NO_REMIX : 0) |
1961 (o->core->remixing_use_all_sink_channels ? 0 : PA_RESAMPLER_NO_FILL_SINK) |
1962 (o->core->remixing_produce_lfe ? PA_RESAMPLER_PRODUCE_LFE : 0) |
1963 (o->core->remixing_consume_lfe ? PA_RESAMPLER_CONSUME_LFE : 0));
1965 if (!new_resampler) {
1966 pa_log_warn("Unsupported resampling operation.");
1967 return -PA_ERR_NOTSUPPORTED;
1970 new_resampler = NULL;
1972 if (new_resampler == o->thread_info.resampler)
1975 if (o->thread_info.resampler)
1976 pa_resampler_free(o->thread_info.resampler);
1978 o->thread_info.resampler = new_resampler;
1980 pa_memblockq_free(o->thread_info.delay_memblockq);
1982 memblockq_name = pa_sprintf_malloc("source output delay_memblockq [%u]", o->index);
1983 o->thread_info.delay_memblockq = pa_memblockq_new(
1986 MEMBLOCKQ_MAXLENGTH,
1988 &o->source->sample_spec,
1992 &o->source->silence);
1993 pa_xfree(memblockq_name);
1995 o->actual_resample_method = new_resampler ? pa_resampler_get_method(new_resampler) : PA_RESAMPLER_INVALID;
1997 pa_log_debug("Updated resampler for source output %d", o->index);
2002 /* Called from the IO thread. */
2003 void pa_source_output_attach(pa_source_output *o) {
2005 pa_assert(!o->thread_info.attached);
2007 o->thread_info.attached = true;
2013 /* Called from the IO thread. */
2014 void pa_source_output_detach(pa_source_output *o) {
2017 if (!o->thread_info.attached)
2020 o->thread_info.attached = false;
2026 /* Called from the main thread. */
2027 void pa_source_output_set_volume_direct(pa_source_output *o, const pa_cvolume *volume) {
2028 pa_cvolume old_volume;
2029 char old_volume_str[PA_CVOLUME_SNPRINT_VERBOSE_MAX];
2030 char new_volume_str[PA_CVOLUME_SNPRINT_VERBOSE_MAX];
2035 old_volume = o->volume;
2037 if (pa_cvolume_equal(volume, &old_volume))
2040 o->volume = *volume;
2041 pa_log_debug("The volume of source output %u changed from %s to %s.", o->index,
2042 pa_cvolume_snprint_verbose(old_volume_str, sizeof(old_volume_str), &old_volume, &o->channel_map, true),
2043 pa_cvolume_snprint_verbose(new_volume_str, sizeof(new_volume_str), volume, &o->channel_map, true));
2045 if (o->volume_changed)
2046 o->volume_changed(o);
2048 pa_subscription_post(o->core, PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT|PA_SUBSCRIPTION_EVENT_CHANGE, o->index);
2049 pa_hook_fire(&o->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_VOLUME_CHANGED], o);
2052 /* Called from the main thread. */
2053 void pa_source_output_set_reference_ratio(pa_source_output *o, const pa_cvolume *ratio) {
2054 pa_cvolume old_ratio;
2055 char old_ratio_str[PA_CVOLUME_SNPRINT_VERBOSE_MAX];
2056 char new_ratio_str[PA_CVOLUME_SNPRINT_VERBOSE_MAX];
2061 old_ratio = o->reference_ratio;
2063 if (pa_cvolume_equal(ratio, &old_ratio))
2066 o->reference_ratio = *ratio;
2068 if (!PA_SOURCE_OUTPUT_IS_LINKED(o->state))
2071 pa_log_debug("Source output %u reference ratio changed from %s to %s.", o->index,
2072 pa_cvolume_snprint_verbose(old_ratio_str, sizeof(old_ratio_str), &old_ratio, &o->channel_map, true),
2073 pa_cvolume_snprint_verbose(new_ratio_str, sizeof(new_ratio_str), ratio, &o->channel_map, true));
2076 /* Called from the main thread.
2078 * This is called when e.g. module-stream-restore wants to change the preferred
2079 * source. As a side effect the stream is moved to the new preferred source.
2080 * Note that things can work also in the other direction: if the user moves
2081 * a stream, as a side effect the preferred source is changed. This could cause
2082 * an infinite loop, but it's avoided by these two measures:
2083 * - When pa_source_output_set_preferred_source() is called, it calls
2084 * pa_source_output_move_to() with save=false, which avoids the recursive
2085 * pa_source_output_set_preferred_source() call.
2086 * - When the primary operation is to move a stream,
2087 * pa_source_output_finish_move() calls set_preferred_source() instead of
2088 * pa_source_output_set_preferred_source(). set_preferred_source() doesn't
2089 * move the stream as a side effect.
2091 void pa_source_output_set_preferred_source(pa_source_output *o, pa_source *s) {
2095 set_preferred_source(o, s->name);
2096 pa_source_output_move_to(o, s, false);
2098 set_preferred_source(o, NULL);
2099 pa_source_output_move_to(o, o->core->default_source, false);
2104 void pa_source_output_dump_info(pa_source_output *o, unsigned int iteration, unsigned int total) {
2107 pa_log_warn(" #(%2u/%2u), index(%4u), client(%5d), source(%2u), state(%d), muted(%s)"
2108 ", app(%s, %s), media(name:%s, role:%s)",
2109 iteration, total, o->index,
2110 o->client ? (int)o->client->index : -1,
2111 o->source->index, o->state, pa_yes_no(o->muted),
2112 pa_strnull(pa_proplist_gets(o->proplist, PA_PROP_APPLICATION_PROCESS_ID)),
2113 pa_strnull(pa_proplist_gets(o->proplist, PA_PROP_APPLICATION_PROCESS_BINARY)),
2114 pa_strnull(pa_proplist_gets(o->proplist, PA_PROP_MEDIA_NAME)),
2115 pa_strnull(pa_proplist_gets(o->proplist, PA_PROP_MEDIA_ROLE)));