mirror of
				https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
				synced 2025-11-03 09:01:50 -05:00 
			
		
		
		
	source-output: add a new API pa_source_output_set_preferred_source
If the source here is NULL, that means users want to clear the preferred_source and move the source-output to the default_source, otherwise set the preferred_source to the source->name and move the source-output to the source. After that fire the source_output_change event. After adding this API, we can use this API to simplify the entry_apply in the module-stream-restore.c. Signed-off-by: Hui Wang <hui.wang@canonical.com>
This commit is contained in:
		
							parent
							
								
									5eec504d68
								
							
						
					
					
						commit
						e529db75ec
					
				
					 3 changed files with 18 additions and 8 deletions
				
			
		| 
						 | 
					@ -1905,17 +1905,11 @@ static void entry_apply(struct userdata *u, const char *name, struct entry *e) {
 | 
				
			||||||
                    /* If the device is not valid we should make sure the
 | 
					                    /* If the device is not valid we should make sure the
 | 
				
			||||||
                       preferred_source is cleared as the user may have specifically
 | 
					                       preferred_source is cleared as the user may have specifically
 | 
				
			||||||
                       removed the source element from the rule. */
 | 
					                       removed the source element from the rule. */
 | 
				
			||||||
                    pa_xfree(so->preferred_source);
 | 
					                    pa_source_output_set_preferred_source(so, NULL);
 | 
				
			||||||
                    so->preferred_source = NULL;
 | 
					 | 
				
			||||||
                    /* This is cheating a bit. The source output itself has not changed
 | 
					 | 
				
			||||||
                       but the rules governing its routing have, so we fire this event
 | 
					 | 
				
			||||||
                       such that other routing modules (e.g. module-device-manager)
 | 
					 | 
				
			||||||
                       will pick up the change and reapply their routing */
 | 
					 | 
				
			||||||
                    pa_subscription_post(so->core, PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT|PA_SUBSCRIPTION_EVENT_CHANGE, so->index);
 | 
					 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            } else if ((s = pa_namereg_get(u->core, e->device, PA_NAMEREG_SOURCE))) {
 | 
					            } else if ((s = pa_namereg_get(u->core, e->device, PA_NAMEREG_SOURCE))) {
 | 
				
			||||||
                pa_log_info("Restoring device for stream %s.", name);
 | 
					                pa_log_info("Restoring device for stream %s.", name);
 | 
				
			||||||
                pa_source_output_move_to(so, s, true);
 | 
					                pa_source_output_set_preferred_source(so, s);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1886,3 +1886,17 @@ void pa_source_output_set_reference_ratio(pa_source_output *o, const pa_cvolume
 | 
				
			||||||
                 pa_cvolume_snprint_verbose(old_ratio_str, sizeof(old_ratio_str), &old_ratio, &o->channel_map, true),
 | 
					                 pa_cvolume_snprint_verbose(old_ratio_str, sizeof(old_ratio_str), &old_ratio, &o->channel_map, true),
 | 
				
			||||||
                 pa_cvolume_snprint_verbose(new_ratio_str, sizeof(new_ratio_str), ratio, &o->channel_map, true));
 | 
					                 pa_cvolume_snprint_verbose(new_ratio_str, sizeof(new_ratio_str), ratio, &o->channel_map, true));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Called from the main thread. */
 | 
				
			||||||
 | 
					void pa_source_output_set_preferred_source(pa_source_output *o, pa_source *s) {
 | 
				
			||||||
 | 
					    pa_assert(o);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    pa_xfree(o->preferred_source);
 | 
				
			||||||
 | 
					    if (s) {
 | 
				
			||||||
 | 
					        o->preferred_source = pa_xstrdup(s->name);
 | 
				
			||||||
 | 
					        pa_source_output_move_to(o, s, false);
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					        o->preferred_source = NULL;
 | 
				
			||||||
 | 
					        pa_source_output_move_to(o, o->core->default_source, false);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -402,6 +402,8 @@ void pa_source_output_set_volume_direct(pa_source_output *o, const pa_cvolume *v
 | 
				
			||||||
 * o->reference_ratio and logs a message if the value changes. */
 | 
					 * o->reference_ratio and logs a message if the value changes. */
 | 
				
			||||||
void pa_source_output_set_reference_ratio(pa_source_output *o, const pa_cvolume *ratio);
 | 
					void pa_source_output_set_reference_ratio(pa_source_output *o, const pa_cvolume *ratio);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void pa_source_output_set_preferred_source(pa_source_output *o, pa_source *s);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define pa_source_output_assert_io_context(s) \
 | 
					#define pa_source_output_assert_io_context(s) \
 | 
				
			||||||
    pa_assert(pa_thread_mq_get() || !PA_SOURCE_OUTPUT_IS_LINKED((s)->state))
 | 
					    pa_assert(pa_thread_mq_get() || !PA_SOURCE_OUTPUT_IS_LINKED((s)->state))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue