mirror of
				https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
				synced 2025-11-03 09:01:50 -05:00 
			
		
		
		
	sink, source: Merge sink sample spec setter functions into one
It seems better to update the whole sample spec (and channel map) at a shot rather than piecemeal.
This commit is contained in:
		
							parent
							
								
									7df1b78ac2
								
							
						
					
					
						commit
						2046afe683
					
				
					 7 changed files with 67 additions and 249 deletions
				
			
		| 
						 | 
					@ -1824,22 +1824,15 @@ static int sink_reconfigure_cb(pa_sink *s, pa_sample_spec *spec, pa_channel_map
 | 
				
			||||||
    bool format_supported = false;
 | 
					    bool format_supported = false;
 | 
				
			||||||
    bool rate_supported = false;
 | 
					    bool rate_supported = false;
 | 
				
			||||||
    bool channels_supported = false;
 | 
					    bool channels_supported = false;
 | 
				
			||||||
#ifdef USE_SMOOTHER_2
 | 
					 | 
				
			||||||
    pa_sample_spec effective_spec;
 | 
					    pa_sample_spec effective_spec;
 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pa_assert(u);
 | 
					    pa_assert(u);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef USE_SMOOTHER_2
 | 
					    effective_spec = s->sample_spec;
 | 
				
			||||||
    effective_spec.channels = s->sample_spec.channels;
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for (i = 0; u->supported_formats[i] != PA_SAMPLE_MAX; i++) {
 | 
					    for (i = 0; u->supported_formats[i] != PA_SAMPLE_MAX; i++) {
 | 
				
			||||||
        if (u->supported_formats[i] == spec->format) {
 | 
					        if (u->supported_formats[i] == spec->format) {
 | 
				
			||||||
            pa_sink_set_sample_format(u->sink, spec->format);
 | 
					 | 
				
			||||||
#ifdef USE_SMOOTHER_2
 | 
					 | 
				
			||||||
            effective_spec.format = spec->format;
 | 
					            effective_spec.format = spec->format;
 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
            format_supported = true;
 | 
					            format_supported = true;
 | 
				
			||||||
            break;
 | 
					            break;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					@ -1848,18 +1841,12 @@ static int sink_reconfigure_cb(pa_sink *s, pa_sample_spec *spec, pa_channel_map
 | 
				
			||||||
    if (!format_supported) {
 | 
					    if (!format_supported) {
 | 
				
			||||||
        pa_log_info("Sink does not support sample format of %s, set it to a verified value",
 | 
					        pa_log_info("Sink does not support sample format of %s, set it to a verified value",
 | 
				
			||||||
                    pa_sample_format_to_string(spec->format));
 | 
					                    pa_sample_format_to_string(spec->format));
 | 
				
			||||||
        pa_sink_set_sample_format(u->sink, u->verified_sample_spec.format);
 | 
					 | 
				
			||||||
#ifdef USE_SMOOTHER_2
 | 
					 | 
				
			||||||
        effective_spec.format = u->verified_sample_spec.format;
 | 
					        effective_spec.format = u->verified_sample_spec.format;
 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for (i = 0; u->supported_rates[i]; i++) {
 | 
					    for (i = 0; u->supported_rates[i]; i++) {
 | 
				
			||||||
        if (u->supported_rates[i] == spec->rate) {
 | 
					        if (u->supported_rates[i] == spec->rate) {
 | 
				
			||||||
            pa_sink_set_sample_rate(u->sink, spec->rate);
 | 
					 | 
				
			||||||
#ifdef USE_SMOOTHER_2
 | 
					 | 
				
			||||||
            effective_spec.rate = spec->rate;
 | 
					            effective_spec.rate = spec->rate;
 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
            rate_supported = true;
 | 
					            rate_supported = true;
 | 
				
			||||||
            break;
 | 
					            break;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					@ -1867,19 +1854,12 @@ static int sink_reconfigure_cb(pa_sink *s, pa_sample_spec *spec, pa_channel_map
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!rate_supported) {
 | 
					    if (!rate_supported) {
 | 
				
			||||||
        pa_log_info("Sink does not support sample rate of %u, set it to a verified value", spec->rate);
 | 
					        pa_log_info("Sink does not support sample rate of %u, set it to a verified value", spec->rate);
 | 
				
			||||||
        pa_sink_set_sample_rate(u->sink, u->verified_sample_spec.rate);
 | 
					 | 
				
			||||||
#ifdef USE_SMOOTHER_2
 | 
					 | 
				
			||||||
        effective_spec.rate = u->verified_sample_spec.rate;
 | 
					        effective_spec.rate = u->verified_sample_spec.rate;
 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef USE_SMOOTHER_2
 | 
					 | 
				
			||||||
    pa_smoother_2_set_sample_spec(u->smoother, pa_rtclock_now(), &effective_spec);
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    for (i = 0; u->supported_channels[i]; i++) {
 | 
					    for (i = 0; u->supported_channels[i]; i++) {
 | 
				
			||||||
        if (u->supported_channels[i] == spec->channels) {
 | 
					        if (u->supported_channels[i] == spec->channels) {
 | 
				
			||||||
            pa_sink_set_channels(u->sink, spec->channels);
 | 
					            effective_spec.channels = spec->channels;
 | 
				
			||||||
            channels_supported = true;
 | 
					            channels_supported = true;
 | 
				
			||||||
            break;
 | 
					            break;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					@ -1887,16 +1867,14 @@ static int sink_reconfigure_cb(pa_sink *s, pa_sample_spec *spec, pa_channel_map
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!channels_supported) {
 | 
					    if (!channels_supported) {
 | 
				
			||||||
        pa_log_info("Sink does not support %u channels, set it to a verified value", spec->channels);
 | 
					        pa_log_info("Sink does not support %u channels, set it to a verified value", spec->channels);
 | 
				
			||||||
        pa_sink_set_channels(u->sink, u->verified_sample_spec.channels);
 | 
					        effective_spec.channels = u->verified_sample_spec.channels;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (map) {
 | 
					    pa_sink_set_sample_spec(u->sink, &effective_spec, map);
 | 
				
			||||||
        pa_sink_set_channel_map(s, map);
 | 
					
 | 
				
			||||||
    } else {
 | 
					#ifdef USE_SMOOTHER_2
 | 
				
			||||||
        pa_channel_map def_map;
 | 
					    pa_smoother_2_set_sample_spec(u->smoother, pa_rtclock_now(), &effective_spec);
 | 
				
			||||||
        pa_channel_map_init_auto(&def_map, spec->channels, PA_CHANNEL_MAP_DEFAULT);
 | 
					#endif
 | 
				
			||||||
        pa_sink_set_channel_map(s, &def_map);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Passthrough status change is handled during unsuspend */
 | 
					    /* Passthrough status change is handled during unsuspend */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1645,16 +1645,11 @@ static int source_reconfigure_cb(pa_source *s, pa_sample_spec *spec, pa_channel_
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pa_assert(u);
 | 
					    pa_assert(u);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef USE_SMOOTHER_2
 | 
					    effective_spec = s->sample_spec;
 | 
				
			||||||
    effective_spec.channels = s->sample_spec.channels;
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for (i = 0; u->supported_formats[i] != PA_SAMPLE_MAX; i++) {
 | 
					    for (i = 0; u->supported_formats[i] != PA_SAMPLE_MAX; i++) {
 | 
				
			||||||
        if (u->supported_formats[i] == spec->format) {
 | 
					        if (u->supported_formats[i] == spec->format) {
 | 
				
			||||||
            pa_source_set_sample_format(u->source, spec->format);
 | 
					 | 
				
			||||||
#ifdef USE_SMOOTHER_2
 | 
					 | 
				
			||||||
            effective_spec.format = spec->format;
 | 
					            effective_spec.format = spec->format;
 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
            format_supported = true;
 | 
					            format_supported = true;
 | 
				
			||||||
            break;
 | 
					            break;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					@ -1663,18 +1658,12 @@ static int source_reconfigure_cb(pa_source *s, pa_sample_spec *spec, pa_channel_
 | 
				
			||||||
    if (!format_supported) {
 | 
					    if (!format_supported) {
 | 
				
			||||||
        pa_log_info("Source does not support sample format of %s, set it to a verified value",
 | 
					        pa_log_info("Source does not support sample format of %s, set it to a verified value",
 | 
				
			||||||
                    pa_sample_format_to_string(spec->format));
 | 
					                    pa_sample_format_to_string(spec->format));
 | 
				
			||||||
        pa_source_set_sample_format(u->source, u->verified_sample_spec.format);
 | 
					 | 
				
			||||||
#ifdef USE_SMOOTHER_2
 | 
					 | 
				
			||||||
        effective_spec.format = u->verified_sample_spec.format;
 | 
					        effective_spec.format = u->verified_sample_spec.format;
 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for (i = 0; u->supported_rates[i]; i++) {
 | 
					    for (i = 0; u->supported_rates[i]; i++) {
 | 
				
			||||||
        if (u->supported_rates[i] == spec->rate) {
 | 
					        if (u->supported_rates[i] == spec->rate) {
 | 
				
			||||||
            pa_source_set_sample_rate(u->source, spec->rate);
 | 
					 | 
				
			||||||
#ifdef USE_SMOOTHER_2
 | 
					 | 
				
			||||||
            effective_spec.rate = spec->rate;
 | 
					            effective_spec.rate = spec->rate;
 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
            rate_supported = true;
 | 
					            rate_supported = true;
 | 
				
			||||||
            break;
 | 
					            break;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					@ -1682,19 +1671,12 @@ static int source_reconfigure_cb(pa_source *s, pa_sample_spec *spec, pa_channel_
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!rate_supported) {
 | 
					    if (!rate_supported) {
 | 
				
			||||||
        pa_log_info("Source does not support sample rate of %u, set it to a verfied value", spec->rate);
 | 
					        pa_log_info("Source does not support sample rate of %u, set it to a verfied value", spec->rate);
 | 
				
			||||||
        pa_source_set_sample_rate(u->source, u->verified_sample_spec.rate);
 | 
					 | 
				
			||||||
#ifdef USE_SMOOTHER_2
 | 
					 | 
				
			||||||
        effective_spec.rate = u->verified_sample_spec.rate;
 | 
					        effective_spec.rate = u->verified_sample_spec.rate;
 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef USE_SMOOTHER_2
 | 
					 | 
				
			||||||
    pa_smoother_2_set_sample_spec(u->smoother, pa_rtclock_now(), &effective_spec);
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    for (i = 0; u->supported_channels[i]; i++) {
 | 
					    for (i = 0; u->supported_channels[i]; i++) {
 | 
				
			||||||
        if (u->supported_channels[i] == spec->channels) {
 | 
					        if (u->supported_channels[i] == spec->channels) {
 | 
				
			||||||
            pa_source_set_channels(u->source, spec->channels);
 | 
					            effective_spec.channels = spec->channels;
 | 
				
			||||||
            channels_supported = true;
 | 
					            channels_supported = true;
 | 
				
			||||||
            break;
 | 
					            break;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					@ -1702,16 +1684,14 @@ static int source_reconfigure_cb(pa_source *s, pa_sample_spec *spec, pa_channel_
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!channels_supported) {
 | 
					    if (!channels_supported) {
 | 
				
			||||||
        pa_log_info("Sink does not support %u channels, set it to a verified value", spec->channels);
 | 
					        pa_log_info("Sink does not support %u channels, set it to a verified value", spec->channels);
 | 
				
			||||||
        pa_source_set_channels(u->source, u->verified_sample_spec.channels);
 | 
					        effective_spec.channels = u->verified_sample_spec.channels;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (map) {
 | 
					    pa_source_set_sample_spec(u->source, &effective_spec, map);
 | 
				
			||||||
       pa_source_set_channel_map(s, map);
 | 
					
 | 
				
			||||||
    } else {
 | 
					#if USE_SMOOTHER_2
 | 
				
			||||||
        pa_channel_map def_map;
 | 
					    pa_smoother_2_set_sample_spec(u->smoother, pa_rtclock_now(), &effective_spec);
 | 
				
			||||||
        pa_channel_map_init_auto(&def_map, spec->channels, PA_CHANNEL_MAP_DEFAULT);
 | 
					#endif
 | 
				
			||||||
        pa_source_set_channel_map(s, &def_map);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return 0;
 | 
					    return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -180,15 +180,7 @@ static void sink_update_requested_latency_cb(pa_sink *s) {
 | 
				
			||||||
static int sink_reconfigure_cb(pa_sink *s, pa_sample_spec *spec, pa_channel_map *map, bool passthrough) {
 | 
					static int sink_reconfigure_cb(pa_sink *s, pa_sample_spec *spec, pa_channel_map *map, bool passthrough) {
 | 
				
			||||||
    pa_sink_assert_ref(s);
 | 
					    pa_sink_assert_ref(s);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pa_sink_set_sample_spec(s, spec);
 | 
					    pa_sink_set_sample_spec(s, spec, map);
 | 
				
			||||||
 | 
					 | 
				
			||||||
    if (map)
 | 
					 | 
				
			||||||
        pa_sink_set_channel_map(s, map);
 | 
					 | 
				
			||||||
    else {
 | 
					 | 
				
			||||||
        pa_channel_map def_map;
 | 
					 | 
				
			||||||
        pa_channel_map_init_auto(&def_map, spec->channels, PA_CHANNEL_MAP_DEFAULT);
 | 
					 | 
				
			||||||
        pa_sink_set_channel_map(s, &def_map);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return 0;
 | 
					    return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4050,103 +4050,41 @@ done:
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Called from the main thread */
 | 
					/* Called from the main thread */
 | 
				
			||||||
void pa_sink_set_sample_spec(pa_sink *s, pa_sample_spec *spec) {
 | 
					void pa_sink_set_sample_spec(pa_sink *s, pa_sample_spec *spec, pa_channel_map *map) {
 | 
				
			||||||
    pa_sample_spec old_spec;
 | 
					    pa_sample_spec old_spec;
 | 
				
			||||||
 | 
					    pa_channel_map old_map;
 | 
				
			||||||
    char spec_str[PA_SAMPLE_SPEC_SNPRINT_MAX], old_spec_str[PA_SAMPLE_SPEC_SNPRINT_MAX];
 | 
					    char spec_str[PA_SAMPLE_SPEC_SNPRINT_MAX], old_spec_str[PA_SAMPLE_SPEC_SNPRINT_MAX];
 | 
				
			||||||
 | 
					    char old_map_str[PA_CHANNEL_MAP_SNPRINT_MAX], new_map_str[PA_CHANNEL_MAP_SNPRINT_MAX];
 | 
				
			||||||
 | 
					    bool changed = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pa_assert(s);
 | 
					    pa_assert(s);
 | 
				
			||||||
    pa_assert(pa_sample_spec_valid(spec));
 | 
					    pa_assert(pa_sample_spec_valid(spec));
 | 
				
			||||||
 | 
					 | 
				
			||||||
    old_spec = s->sample_spec;
 | 
					 | 
				
			||||||
    if (pa_sample_spec_equal(&old_spec, spec))
 | 
					 | 
				
			||||||
        return;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    pa_sample_spec_snprint(spec_str, sizeof(spec_str), spec);
 | 
					 | 
				
			||||||
    pa_sample_spec_snprint(old_spec_str, sizeof(old_spec_str), &old_spec);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    pa_log_info("%s: spec: %s -> %s", s->name, old_spec_str, spec_str);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    s->sample_spec = *spec;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SINK | PA_SUBSCRIPTION_EVENT_CHANGE, s->index);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* Called from the main thread */
 | 
					 | 
				
			||||||
void pa_sink_set_sample_format(pa_sink *s, pa_sample_format_t format) {
 | 
					 | 
				
			||||||
    pa_sample_format_t old_format;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    pa_assert(s);
 | 
					 | 
				
			||||||
    pa_assert(pa_sample_format_valid(format));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    old_format = s->sample_spec.format;
 | 
					 | 
				
			||||||
    if (old_format == format)
 | 
					 | 
				
			||||||
        return;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    pa_log_info("%s: format: %s -> %s",
 | 
					 | 
				
			||||||
                s->name, pa_sample_format_to_string(old_format), pa_sample_format_to_string(format));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    s->sample_spec.format = format;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SINK | PA_SUBSCRIPTION_EVENT_CHANGE, s->index);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* Called from the main thread */
 | 
					 | 
				
			||||||
void pa_sink_set_sample_rate(pa_sink *s, uint32_t rate) {
 | 
					 | 
				
			||||||
    uint32_t old_rate;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    pa_assert(s);
 | 
					 | 
				
			||||||
    pa_assert(pa_sample_rate_valid(rate));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    old_rate = s->sample_spec.rate;
 | 
					 | 
				
			||||||
    if (old_rate == rate)
 | 
					 | 
				
			||||||
        return;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    pa_log_info("%s: rate: %u -> %u", s->name, old_rate, rate);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    s->sample_spec.rate = rate;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SINK | PA_SUBSCRIPTION_EVENT_CHANGE, s->index);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* Called from the main thread */
 | 
					 | 
				
			||||||
void pa_sink_set_channels(pa_sink *s, uint8_t channels) {
 | 
					 | 
				
			||||||
    uint8_t old_channels;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    pa_assert(s);
 | 
					 | 
				
			||||||
    pa_assert(pa_channels_valid(channels));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    old_channels = s->sample_spec.channels;
 | 
					 | 
				
			||||||
    if (old_channels == channels)
 | 
					 | 
				
			||||||
        return;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    pa_log_info("%s: channels: %u -> %u", s->name, old_channels, channels);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    s->sample_spec.channels = channels;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SINK | PA_SUBSCRIPTION_EVENT_CHANGE, s->index);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* Called from the main thread */
 | 
					 | 
				
			||||||
void pa_sink_set_channel_map(pa_sink *s, pa_channel_map *map) {
 | 
					 | 
				
			||||||
    pa_channel_map old_map;
 | 
					 | 
				
			||||||
    char old_map_str[PA_CHANNEL_MAP_SNPRINT_MAX];
 | 
					 | 
				
			||||||
    char new_map_str[PA_CHANNEL_MAP_SNPRINT_MAX];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    pa_assert(s);
 | 
					 | 
				
			||||||
    pa_assert(map);
 | 
					    pa_assert(map);
 | 
				
			||||||
    pa_assert(pa_channel_map_valid(map));
 | 
					    pa_assert(pa_channel_map_valid(map));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    old_spec = s->sample_spec;
 | 
				
			||||||
 | 
					    if (!pa_sample_spec_equal(&old_spec, spec)) {
 | 
				
			||||||
 | 
					        pa_sample_spec_snprint(spec_str, sizeof(spec_str), spec);
 | 
				
			||||||
 | 
					        pa_sample_spec_snprint(old_spec_str, sizeof(old_spec_str), &old_spec);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        pa_log_info("%s: spec: %s -> %s", s->name, old_spec_str, spec_str);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        s->sample_spec = *spec;
 | 
				
			||||||
 | 
					        changed = true;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    old_map = s->channel_map;
 | 
					    old_map = s->channel_map;
 | 
				
			||||||
    if (pa_channel_map_equal(&old_map, map))
 | 
					    if (!pa_channel_map_equal(&old_map, map)) {
 | 
				
			||||||
        return;
 | 
					        pa_log_info("%s: channel map: %s -> %s", s->name,
 | 
				
			||||||
 | 
					                pa_channel_map_snprint(old_map_str, sizeof(old_map_str), &old_map),
 | 
				
			||||||
 | 
					                pa_channel_map_snprint(new_map_str, sizeof(new_map_str), map));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pa_log_info("%s: channel map: %s -> %s", s->name,
 | 
					        s->channel_map = *map;
 | 
				
			||||||
            pa_channel_map_snprint(old_map_str, sizeof(old_map_str), &old_map),
 | 
					        changed = true;
 | 
				
			||||||
            pa_channel_map_snprint(new_map_str, sizeof(new_map_str), map));
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    s->channel_map = *map;
 | 
					    if (changed)
 | 
				
			||||||
 | 
					        pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SINK | PA_SUBSCRIPTION_EVENT_CHANGE, s->index);
 | 
				
			||||||
    pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SINK | PA_SUBSCRIPTION_EVENT_CHANGE, s->index);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Called from the main thread. */
 | 
					/* Called from the main thread. */
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -527,11 +527,7 @@ bool pa_sink_set_formats(pa_sink *s, pa_idxset *formats);
 | 
				
			||||||
bool pa_sink_check_format(pa_sink *s, pa_format_info *f);
 | 
					bool pa_sink_check_format(pa_sink *s, pa_format_info *f);
 | 
				
			||||||
pa_idxset* pa_sink_check_formats(pa_sink *s, pa_idxset *in_formats);
 | 
					pa_idxset* pa_sink_check_formats(pa_sink *s, pa_idxset *in_formats);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void pa_sink_set_sample_spec(pa_sink *s, pa_sample_spec *spec);
 | 
					void pa_sink_set_sample_spec(pa_sink *s, pa_sample_spec *spec, pa_channel_map *map);
 | 
				
			||||||
void pa_sink_set_sample_format(pa_sink *s, pa_sample_format_t format);
 | 
					 | 
				
			||||||
void pa_sink_set_sample_rate(pa_sink *s, uint32_t rate);
 | 
					 | 
				
			||||||
void pa_sink_set_channels(pa_sink *s, uint8_t channels);
 | 
					 | 
				
			||||||
void pa_sink_set_channel_map(pa_sink *s, pa_channel_map *map);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*** To be called exclusively by the sink driver, from IO context */
 | 
					/*** To be called exclusively by the sink driver, from IO context */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3045,103 +3045,41 @@ done:
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Called from the main thread */
 | 
					/* Called from the main thread */
 | 
				
			||||||
void pa_source_set_sample_spec(pa_source *s, pa_sample_spec *spec) {
 | 
					void pa_source_set_sample_spec(pa_source *s, pa_sample_spec *spec, pa_channel_map *map) {
 | 
				
			||||||
    pa_sample_spec old_spec;
 | 
					    pa_sample_spec old_spec;
 | 
				
			||||||
 | 
					    pa_channel_map old_map;
 | 
				
			||||||
    char spec_str[PA_SAMPLE_SPEC_SNPRINT_MAX], old_spec_str[PA_SAMPLE_SPEC_SNPRINT_MAX];
 | 
					    char spec_str[PA_SAMPLE_SPEC_SNPRINT_MAX], old_spec_str[PA_SAMPLE_SPEC_SNPRINT_MAX];
 | 
				
			||||||
 | 
					    char old_map_str[PA_CHANNEL_MAP_SNPRINT_MAX], new_map_str[PA_CHANNEL_MAP_SNPRINT_MAX];
 | 
				
			||||||
 | 
					    bool changed = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pa_assert(s);
 | 
					    pa_assert(s);
 | 
				
			||||||
    pa_assert(pa_sample_spec_valid(spec));
 | 
					    pa_assert(pa_sample_spec_valid(spec));
 | 
				
			||||||
 | 
					 | 
				
			||||||
    old_spec = s->sample_spec;
 | 
					 | 
				
			||||||
    if (pa_sample_spec_equal(&old_spec, spec))
 | 
					 | 
				
			||||||
        return;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    pa_sample_spec_snprint(spec_str, sizeof(spec_str), spec);
 | 
					 | 
				
			||||||
    pa_sample_spec_snprint(old_spec_str, sizeof(old_spec_str), &old_spec);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    pa_log_info("%s: spec: %s -> %s", s->name, old_spec_str, spec_str);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    s->sample_spec = *spec;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SOURCE | PA_SUBSCRIPTION_EVENT_CHANGE, s->index);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* Called from the main thread */
 | 
					 | 
				
			||||||
void pa_source_set_sample_format(pa_source *s, pa_sample_format_t format) {
 | 
					 | 
				
			||||||
    pa_sample_format_t old_format;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    pa_assert(s);
 | 
					 | 
				
			||||||
    pa_assert(pa_sample_format_valid(format));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    old_format = s->sample_spec.format;
 | 
					 | 
				
			||||||
    if (old_format == format)
 | 
					 | 
				
			||||||
        return;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    pa_log_info("%s: format: %s -> %s",
 | 
					 | 
				
			||||||
                s->name, pa_sample_format_to_string(old_format), pa_sample_format_to_string(format));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    s->sample_spec.format = format;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SOURCE | PA_SUBSCRIPTION_EVENT_CHANGE, s->index);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* Called from the main thread */
 | 
					 | 
				
			||||||
void pa_source_set_sample_rate(pa_source *s, uint32_t rate) {
 | 
					 | 
				
			||||||
    uint32_t old_rate;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    pa_assert(s);
 | 
					 | 
				
			||||||
    pa_assert(pa_sample_rate_valid(rate));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    old_rate = s->sample_spec.rate;
 | 
					 | 
				
			||||||
    if (old_rate == rate)
 | 
					 | 
				
			||||||
        return;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    pa_log_info("%s: rate: %u -> %u", s->name, old_rate, rate);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    s->sample_spec.rate = rate;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SOURCE | PA_SUBSCRIPTION_EVENT_CHANGE, s->index);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* Called from the main thread */
 | 
					 | 
				
			||||||
void pa_source_set_channels(pa_source *s, uint8_t channels) {
 | 
					 | 
				
			||||||
    uint8_t old_channels;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    pa_assert(s);
 | 
					 | 
				
			||||||
    pa_assert(pa_channels_valid(channels));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    old_channels = s->sample_spec.channels;
 | 
					 | 
				
			||||||
    if (old_channels == channels)
 | 
					 | 
				
			||||||
        return;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    pa_log_info("%s: channels: %u -> %u", s->name, old_channels, channels);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    s->sample_spec.channels = channels;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SOURCE | PA_SUBSCRIPTION_EVENT_CHANGE, s->index);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* Called from the main thread */
 | 
					 | 
				
			||||||
void pa_source_set_channel_map(pa_source *s, pa_channel_map *map) {
 | 
					 | 
				
			||||||
    pa_channel_map old_map;
 | 
					 | 
				
			||||||
    char old_map_str[PA_CHANNEL_MAP_SNPRINT_MAX];
 | 
					 | 
				
			||||||
    char new_map_str[PA_CHANNEL_MAP_SNPRINT_MAX];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    pa_assert(s);
 | 
					 | 
				
			||||||
    pa_assert(map);
 | 
					    pa_assert(map);
 | 
				
			||||||
    pa_assert(pa_channel_map_valid(map));
 | 
					    pa_assert(pa_channel_map_valid(map));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    old_spec = s->sample_spec;
 | 
				
			||||||
 | 
					    if (!pa_sample_spec_equal(&old_spec, spec)) {
 | 
				
			||||||
 | 
					        pa_sample_spec_snprint(spec_str, sizeof(spec_str), spec);
 | 
				
			||||||
 | 
					        pa_sample_spec_snprint(old_spec_str, sizeof(old_spec_str), &old_spec);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        pa_log_info("%s: spec: %s -> %s", s->name, old_spec_str, spec_str);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        s->sample_spec = *spec;
 | 
				
			||||||
 | 
					        changed = true;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    old_map = s->channel_map;
 | 
					    old_map = s->channel_map;
 | 
				
			||||||
    if (pa_channel_map_equal(&old_map, map))
 | 
					    if (!pa_channel_map_equal(&old_map, map)) {
 | 
				
			||||||
        return;
 | 
					        pa_log_info("%s: channel map: %s -> %s", s->name,
 | 
				
			||||||
 | 
					                pa_channel_map_snprint(old_map_str, sizeof(old_map_str), &old_map),
 | 
				
			||||||
 | 
					                pa_channel_map_snprint(new_map_str, sizeof(new_map_str), map));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pa_log_info("%s: channel map: %s -> %s", s->name,
 | 
					        s->channel_map = *map;
 | 
				
			||||||
            pa_channel_map_snprint(old_map_str, sizeof(old_map_str), &old_map),
 | 
					        changed = true;
 | 
				
			||||||
            pa_channel_map_snprint(new_map_str, sizeof(new_map_str), map));
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    s->channel_map = *map;
 | 
					    if (changed)
 | 
				
			||||||
 | 
					        pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SOURCE | PA_SUBSCRIPTION_EVENT_CHANGE, s->index);
 | 
				
			||||||
    pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SOURCE | PA_SUBSCRIPTION_EVENT_CHANGE, s->index);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Called from the main thread. */
 | 
					/* Called from the main thread. */
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -448,11 +448,7 @@ pa_idxset* pa_source_get_formats(pa_source *s);
 | 
				
			||||||
bool pa_source_check_format(pa_source *s, pa_format_info *f);
 | 
					bool pa_source_check_format(pa_source *s, pa_format_info *f);
 | 
				
			||||||
pa_idxset* pa_source_check_formats(pa_source *s, pa_idxset *in_formats);
 | 
					pa_idxset* pa_source_check_formats(pa_source *s, pa_idxset *in_formats);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void pa_source_set_sample_spec(pa_source *s, pa_sample_spec *spec);
 | 
					void pa_source_set_sample_spec(pa_source *s, pa_sample_spec *spec, pa_channel_map *map);
 | 
				
			||||||
void pa_source_set_sample_format(pa_source *s, pa_sample_format_t format);
 | 
					 | 
				
			||||||
void pa_source_set_sample_rate(pa_source *s, uint32_t rate);
 | 
					 | 
				
			||||||
void pa_source_set_channels(pa_source *s, uint8_t channels);
 | 
					 | 
				
			||||||
void pa_source_set_channel_map(pa_source *s, pa_channel_map *map);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*** To be called exclusively by the source driver, from IO context */
 | 
					/*** To be called exclusively by the source driver, from IO context */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue