alsa: use pa_strbuf

This commit is contained in:
Wim Taymans 2023-03-21 09:47:10 +01:00
parent c7ca024607
commit 1d3c4501ef
2 changed files with 26 additions and 27 deletions

View file

@ -4734,35 +4734,29 @@ static int profile_verify(pa_alsa_profile *p) {
PA_ELEMENTSOF(well_known_descriptions)));
if (!p->description) {
pa_strbuf *sb;
uint32_t idx;
pa_alsa_mapping *m;
char *ptr;
size_t size;
FILE *f;
int count = 0;
f = open_memstream(&ptr, &size);
if (f == NULL) {
pa_log("failed to open memstream: %m");
return -1;
}
sb = pa_strbuf_new();
if (p->output_mappings)
PA_IDXSET_FOREACH(m, p->output_mappings, idx) {
if (count++ > 0)
fprintf(f, " + ");
fprintf(f, _("%s Output"), m->description);
if (!pa_strbuf_isempty(sb))
pa_strbuf_puts(sb, " + ");
pa_strbuf_printf(sb, _("%s Output"), m->description);
}
if (p->input_mappings)
PA_IDXSET_FOREACH(m, p->input_mappings, idx) {
if (count++ > 0)
fprintf(f, " + ");
fprintf(f, _("%s Input"), m->description);
if (!pa_strbuf_isempty(sb))
pa_strbuf_puts(sb, " + ");
pa_strbuf_printf(sb, _("%s Input"), m->description);
}
fclose(f);
p->description = ptr;
p->description = pa_strbuf_to_string_free(sb);
}
return 0;
@ -4814,23 +4808,17 @@ void pa_alsa_decibel_fix_dump(pa_alsa_decibel_fix *db_fix) {
pa_assert(db_fix);
if (db_fix->db_values) {
pa_strbuf *buf;
unsigned long i, nsteps;
FILE *f;
char *ptr;
size_t size;
f = open_memstream(&ptr, &size);
if (f == NULL)
return;
pa_assert(db_fix->min_step <= db_fix->max_step);
nsteps = db_fix->max_step - db_fix->min_step + 1;
buf = pa_strbuf_new();
for (i = 0; i < nsteps; ++i)
fprintf(f, "[%li]:%0.2f ", i + db_fix->min_step, db_fix->db_values[i] / 100.0);
pa_strbuf_printf(buf, "[%li]:%0.2f ", i + db_fix->min_step, db_fix->db_values[i] / 100.0);
fclose(f);
db_values = ptr;
db_values = pa_strbuf_to_string_free(buf);
}
pa_log_debug("Decibel fix %s, min_step=%li, max_step=%li, db_values=%s",

View file

@ -373,6 +373,17 @@ static PA_PRINTF_FUNC(2,3) inline size_t pa_strbuf_printf(pa_strbuf *sb, const c
return ret > 0 ? ret : 0;
}
static inline void pa_strbuf_puts(pa_strbuf *sb, const char *t)
{
fputs(t, sb->f);
}
static inline bool pa_strbuf_isempty(pa_strbuf *sb)
{
fflush(sb->f);
return sb->size == 0;
}
static inline char *pa_strbuf_to_string_free(pa_strbuf *sb)
{
char *ptr;