sink, source: Add API to update sample spec

This is useful to have visibility into when the whole sample spec
changes at runtime (during reconfiguration, for example).
This commit is contained in:
Arun Raghavan 2022-01-12 13:22:37 -05:00
parent 628c0c0b74
commit b550fa5628
5 changed files with 49 additions and 2 deletions

View file

@ -178,8 +178,9 @@ 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) {
/* We don't need to do anything */
s->sample_spec = *spec;
pa_sink_assert_ref(s);
pa_sink_set_sample_spec(s, spec);
if (map)
pa_sink_set_channel_map(s, map);

View file

@ -4046,6 +4046,28 @@ done:
return out_formats;
}
/* Called from the main thread */
void pa_sink_set_sample_spec(pa_sink *s, pa_sample_spec *spec) {
pa_sample_spec old_spec;
char spec_str[PA_SAMPLE_SPEC_SNPRINT_MAX], old_spec_str[PA_SAMPLE_SPEC_SNPRINT_MAX];
pa_assert(s);
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;

View file

@ -527,6 +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);
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_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);

View file

@ -3040,6 +3040,28 @@ done:
return out_formats;
}
/* Called from the main thread */
void pa_source_set_sample_spec(pa_source *s, pa_sample_spec *spec) {
pa_sample_spec old_spec;
char spec_str[PA_SAMPLE_SPEC_SNPRINT_MAX], old_spec_str[PA_SAMPLE_SPEC_SNPRINT_MAX];
pa_assert(s);
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;

View file

@ -448,6 +448,7 @@ pa_idxset* pa_source_get_formats(pa_source *s);
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);
void pa_source_set_sample_spec(pa_source *s, pa_sample_spec *spec);
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);