mirror of
				https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
				synced 2025-11-03 09:01:50 -05:00 
			
		
		
		
	sink: move streams to new appeared sinks if they prefer these sinks
When a new sink appears, all streams that have their preferred_sink set to the new sink should be moved to the new sink. Signed-off-by: Hui Wang <hui.wang@canonical.com>
This commit is contained in:
		
							parent
							
								
									40d92e9b1a
								
							
						
					
					
						commit
						b886836630
					
				
					 4 changed files with 35 additions and 53 deletions
				
			
		| 
						 | 
				
			
			@ -95,7 +95,6 @@ struct userdata {
 | 
			
		|||
        *sink_input_fixate_hook_slot,
 | 
			
		||||
        *source_output_new_hook_slot,
 | 
			
		||||
        *source_output_fixate_hook_slot,
 | 
			
		||||
        *sink_put_hook_slot,
 | 
			
		||||
        *source_put_hook_slot,
 | 
			
		||||
        *sink_unlink_hook_slot,
 | 
			
		||||
        *source_unlink_hook_slot,
 | 
			
		||||
| 
						 | 
				
			
			@ -1639,57 +1638,6 @@ static pa_hook_result_t source_output_fixate_hook_callback(pa_core *c, pa_source
 | 
			
		|||
    return PA_HOOK_OK;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static pa_hook_result_t sink_put_hook_callback(pa_core *c, pa_sink *sink, struct userdata *u) {
 | 
			
		||||
    pa_sink_input *si;
 | 
			
		||||
    uint32_t idx;
 | 
			
		||||
 | 
			
		||||
    pa_assert(c);
 | 
			
		||||
    pa_assert(sink);
 | 
			
		||||
    pa_assert(u);
 | 
			
		||||
    pa_assert(u->on_hotplug && u->restore_device);
 | 
			
		||||
 | 
			
		||||
    PA_IDXSET_FOREACH(si, c->sink_inputs, idx) {
 | 
			
		||||
        char *name;
 | 
			
		||||
        struct entry *e;
 | 
			
		||||
 | 
			
		||||
        if (si->sink == sink)
 | 
			
		||||
            continue;
 | 
			
		||||
 | 
			
		||||
        /* Skip this if it is already in the process of being moved
 | 
			
		||||
         * anyway */
 | 
			
		||||
        if (!si->sink)
 | 
			
		||||
            continue;
 | 
			
		||||
 | 
			
		||||
        if (pa_safe_streq(si->sink->name, si->preferred_sink))
 | 
			
		||||
            continue;
 | 
			
		||||
 | 
			
		||||
        /* Skip this sink input if it is connecting a filter sink to
 | 
			
		||||
         * the master */
 | 
			
		||||
        if (si->origin_sink)
 | 
			
		||||
            continue;
 | 
			
		||||
 | 
			
		||||
        /* It might happen that a stream and a sink are set up at the
 | 
			
		||||
           same time, in which case we want to make sure we don't
 | 
			
		||||
           interfere with that */
 | 
			
		||||
        if (!PA_SINK_INPUT_IS_LINKED(si->state))
 | 
			
		||||
            continue;
 | 
			
		||||
 | 
			
		||||
        if (!(name = pa_proplist_get_stream_group(si->proplist, "sink-input", IDENTIFICATION_PROPERTY)))
 | 
			
		||||
            continue;
 | 
			
		||||
 | 
			
		||||
        if ((e = entry_read(u, name))) {
 | 
			
		||||
            if (e->device_valid && pa_streq(e->device, sink->name))
 | 
			
		||||
                pa_sink_input_move_to(si, sink, true);
 | 
			
		||||
 | 
			
		||||
            entry_free(e);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        pa_xfree(name);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return PA_HOOK_OK;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static pa_hook_result_t source_put_hook_callback(pa_core *c, pa_source *source, struct userdata *u) {
 | 
			
		||||
    pa_source_output *so;
 | 
			
		||||
    uint32_t idx;
 | 
			
		||||
| 
						 | 
				
			
			@ -2465,7 +2413,6 @@ int pa__init(pa_module*m) {
 | 
			
		|||
 | 
			
		||||
    if (restore_device && on_hotplug) {
 | 
			
		||||
        /* A little bit earlier than module-intended-roles ... */
 | 
			
		||||
        pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SINK_PUT], PA_HOOK_LATE, (pa_hook_cb_t) sink_put_hook_callback, u);
 | 
			
		||||
        pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SOURCE_PUT], PA_HOOK_LATE, (pa_hook_cb_t) source_put_hook_callback, u);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -523,6 +523,37 @@ void pa_core_rttime_restart(pa_core *c, pa_time_event *e, pa_usec_t usec) {
 | 
			
		|||
    c->mainloop->time_restart(e, pa_timeval_rtstore(&tv, usec, true));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void pa_core_move_streams_to_newly_available_preferred_sink(pa_core *c, pa_sink *s) {
 | 
			
		||||
    pa_sink_input *si;
 | 
			
		||||
    uint32_t idx;
 | 
			
		||||
 | 
			
		||||
    pa_assert(c);
 | 
			
		||||
    pa_assert(s);
 | 
			
		||||
 | 
			
		||||
    PA_IDXSET_FOREACH(si, c->sink_inputs, idx) {
 | 
			
		||||
        if (si->sink == s)
 | 
			
		||||
            continue;
 | 
			
		||||
 | 
			
		||||
        if (!si->sink)
 | 
			
		||||
            continue;
 | 
			
		||||
 | 
			
		||||
        /* Skip this sink input if it is connecting a filter sink to
 | 
			
		||||
         * the master */
 | 
			
		||||
        if (si->origin_sink)
 | 
			
		||||
            continue;
 | 
			
		||||
 | 
			
		||||
        /* It might happen that a stream and a sink are set up at the
 | 
			
		||||
           same time, in which case we want to make sure we don't
 | 
			
		||||
           interfere with that */
 | 
			
		||||
        if (!PA_SINK_INPUT_IS_LINKED(si->state))
 | 
			
		||||
            continue;
 | 
			
		||||
 | 
			
		||||
        if (pa_safe_streq(si->preferred_sink, s->name))
 | 
			
		||||
            pa_sink_input_move_to(si, s, false);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Helper macro to reduce repetition in pa_suspend_cause_to_string().
 | 
			
		||||
 * Parameters:
 | 
			
		||||
 *   char *p: the current position in the write buffer
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -278,4 +278,6 @@ static const size_t PA_SUSPEND_CAUSE_TO_STRING_BUF_SIZE =
 | 
			
		|||
 * provided buffer. The same buffer is the return value of this function. */
 | 
			
		||||
const char *pa_suspend_cause_to_string(pa_suspend_cause_t cause, char buf[PA_SUSPEND_CAUSE_TO_STRING_BUF_SIZE]);
 | 
			
		||||
 | 
			
		||||
void pa_core_move_streams_to_newly_available_preferred_sink(pa_core *c, pa_sink *s);
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -730,6 +730,8 @@ void pa_sink_put(pa_sink* s) {
 | 
			
		|||
     * the default sink might change twice, causing unnecessary stream moving. */
 | 
			
		||||
 | 
			
		||||
    pa_core_update_default_sink(s->core);
 | 
			
		||||
 | 
			
		||||
    pa_core_move_streams_to_newly_available_preferred_sink(s->core, s);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Called from main context */
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue