mirror of
				https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
				synced 2025-11-03 09:01:50 -05:00 
			
		
		
		
	modify module-volume-restore to change the initial volume of a sink input from a hook instead of an asyncronous subscription event.
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1238 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
		
							parent
							
								
									a621d90285
								
							
						
					
					
						commit
						b37ad1ffd3
					
				
					 1 changed files with 28 additions and 7 deletions
				
			
		| 
						 | 
					@ -68,6 +68,7 @@ struct rule {
 | 
				
			||||||
struct userdata {
 | 
					struct userdata {
 | 
				
			||||||
    pa_hashmap *hashmap;
 | 
					    pa_hashmap *hashmap;
 | 
				
			||||||
    pa_subscription *subscription;
 | 
					    pa_subscription *subscription;
 | 
				
			||||||
 | 
					    pa_hook_slot *hook_slot;
 | 
				
			||||||
    int modified;
 | 
					    int modified;
 | 
				
			||||||
    char *table_file;
 | 
					    char *table_file;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
| 
						 | 
					@ -255,7 +256,7 @@ static char* client_name(pa_client *c) {
 | 
				
			||||||
    return t;
 | 
					    return t;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void callback(pa_core *c, pa_subscription_event_type_t t, uint32_t idx, void *userdata) {
 | 
					static void subscribe_callback(pa_core *c, pa_subscription_event_type_t t, uint32_t idx, void *userdata) {
 | 
				
			||||||
    struct userdata *u =  userdata;
 | 
					    struct userdata *u =  userdata;
 | 
				
			||||||
    pa_sink_input *si;
 | 
					    pa_sink_input *si;
 | 
				
			||||||
    struct rule *r;
 | 
					    struct rule *r;
 | 
				
			||||||
| 
						 | 
					@ -277,15 +278,11 @@ static void callback(pa_core *c, pa_subscription_event_type_t t, uint32_t idx, v
 | 
				
			||||||
    if ((r = pa_hashmap_get(u->hashmap, name))) {
 | 
					    if ((r = pa_hashmap_get(u->hashmap, name))) {
 | 
				
			||||||
        pa_xfree(name);
 | 
					        pa_xfree(name);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_NEW) && si->sample_spec.channels == r->volume.channels) {
 | 
					        if (!pa_cvolume_equal(pa_sink_input_get_volume(si), &r->volume)) {
 | 
				
			||||||
            pa_log_info(__FILE__": Restoring volume for <%s>", r->name);
 | 
					 | 
				
			||||||
            pa_sink_input_set_volume(si, &r->volume);
 | 
					 | 
				
			||||||
        } else if (!pa_cvolume_equal(pa_sink_input_get_volume(si), &r->volume)) {
 | 
					 | 
				
			||||||
            pa_log_info(__FILE__": Saving volume for <%s>", r->name);
 | 
					            pa_log_info(__FILE__": Saving volume for <%s>", r->name);
 | 
				
			||||||
            r->volume = *pa_sink_input_get_volume(si);
 | 
					            r->volume = *pa_sink_input_get_volume(si);
 | 
				
			||||||
            u->modified = 1;
 | 
					            u->modified = 1;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        
 | 
					 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        pa_log_info(__FILE__": Creating new entry for <%s>", name);
 | 
					        pa_log_info(__FILE__": Creating new entry for <%s>", name);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -298,6 +295,26 @@ static void callback(pa_core *c, pa_subscription_event_type_t t, uint32_t idx, v
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static pa_hook_result_t hook_callback(pa_core *c, pa_sink_input_new_data *data, struct userdata *u) {
 | 
				
			||||||
 | 
					    struct rule *r;
 | 
				
			||||||
 | 
					    char *name;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    assert(data);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (!data->client || !(name = client_name(data->client)))
 | 
				
			||||||
 | 
					        return PA_HOOK_OK;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ((r = pa_hashmap_get(u->hashmap, name))) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (data->sample_spec_is_set && data->sample_spec.channels == r->volume.channels) {
 | 
				
			||||||
 | 
					            pa_log_info(__FILE__": Restoring volume for <%s>", r->name);
 | 
				
			||||||
 | 
					            pa_sink_input_new_data_set_volume(data, &r->volume);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return PA_HOOK_OK;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int pa__init(pa_core *c, pa_module*m) {
 | 
					int pa__init(pa_core *c, pa_module*m) {
 | 
				
			||||||
    pa_modargs *ma = NULL;
 | 
					    pa_modargs *ma = NULL;
 | 
				
			||||||
    struct userdata *u;
 | 
					    struct userdata *u;
 | 
				
			||||||
| 
						 | 
					@ -321,7 +338,8 @@ int pa__init(pa_core *c, pa_module*m) {
 | 
				
			||||||
    if (load_rules(u) < 0)
 | 
					    if (load_rules(u) < 0)
 | 
				
			||||||
        goto fail;
 | 
					        goto fail;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    u->subscription = pa_subscription_new(c, PA_SUBSCRIPTION_MASK_SINK_INPUT, callback, u);
 | 
					    u->subscription = pa_subscription_new(c, PA_SUBSCRIPTION_MASK_SINK_INPUT, subscribe_callback, u);
 | 
				
			||||||
 | 
					    u->hook_slot = pa_hook_connect(&c->hook_sink_input_new, (pa_hook_cb_t) hook_callback, u);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pa_modargs_free(ma);
 | 
					    pa_modargs_free(ma);
 | 
				
			||||||
    return 0;
 | 
					    return 0;
 | 
				
			||||||
| 
						 | 
					@ -355,6 +373,9 @@ void pa__done(pa_core *c, pa_module*m) {
 | 
				
			||||||
    if (u->subscription)
 | 
					    if (u->subscription)
 | 
				
			||||||
        pa_subscription_free(u->subscription);
 | 
					        pa_subscription_free(u->subscription);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (u->hook_slot)
 | 
				
			||||||
 | 
					        pa_hook_slot_free(u->hook_slot);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (u->hashmap) {
 | 
					    if (u->hashmap) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (u->modified)
 | 
					        if (u->modified)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue