From 7d6e58471f378215d4f104b85ca6190d7e98abcf Mon Sep 17 00:00:00 2001 From: wm4 Date: Tue, 25 Nov 2014 11:11:31 +0100 Subject: audio: make mp_audio_config_to_str return a stack-allocated string Simpler overall. --- audio/audio.c | 15 +++++---------- audio/audio.h | 4 ++-- audio/filter/af.c | 11 +++-------- player/audio.c | 5 ++--- 4 files changed, 12 insertions(+), 23 deletions(-) diff --git a/audio/audio.c b/audio/audio.c index 2cda1ba110..93e9f1814b 100644 --- a/audio/audio.c +++ b/audio/audio.c @@ -91,17 +91,12 @@ bool mp_audio_config_valid(const struct mp_audio *mpa) && mpa->rate >= 1 && mpa->rate < 10000000; } -char *mp_audio_fmt_to_str(int srate, const struct mp_chmap *chmap, int format) +char *mp_audio_config_to_str_buf(char *buf, size_t buf_sz, struct mp_audio *mpa) { - char *res = talloc_asprintf(NULL, "%dHz %s %dch %s", srate, - mp_chmap_to_str(chmap), chmap->num, - af_fmt_to_str(format)); - return res; -} - -char *mp_audio_config_to_str(struct mp_audio *mpa) -{ - return mp_audio_fmt_to_str(mpa->rate, &mpa->channels, mpa->format); + snprintf(buf, buf_sz, "%dHz %s %dch %s", mpa->rate, + mp_chmap_to_str(&mpa->channels), mpa->channels.num, + af_fmt_to_str(mpa->format)); + return buf; } void mp_audio_force_interleaved_format(struct mp_audio *mpa) diff --git a/audio/audio.h b/audio/audio.h index 0b092867ca..e2346ee0aa 100644 --- a/audio/audio.h +++ b/audio/audio.h @@ -49,8 +49,8 @@ void mp_audio_copy_config(struct mp_audio *dst, const struct mp_audio *src); bool mp_audio_config_equals(const struct mp_audio *a, const struct mp_audio *b); bool mp_audio_config_valid(const struct mp_audio *mpa); -char *mp_audio_fmt_to_str(int srate, const struct mp_chmap *chmap, int format); -char *mp_audio_config_to_str(struct mp_audio *mpa); +char *mp_audio_config_to_str_buf(char *buf, size_t buf_sz, struct mp_audio *mpa); +#define mp_audio_config_to_str(m) mp_audio_config_to_str_buf((char[64]){0}, 64, (m)) void mp_audio_force_interleaved_format(struct mp_audio *mpa); diff --git a/audio/filter/af.c b/audio/filter/af.c index b93b703883..171169f62c 100644 --- a/audio/filter/af.c +++ b/audio/filter/af.c @@ -308,11 +308,8 @@ static void af_print_filter_chain(struct af_stream *s, struct af_instance *at, while (af) { char b[128] = {0}; mp_snprintf_cat(b, sizeof(b), " [%s] ", af->info->name); - if (af->data) { - char *info = mp_audio_config_to_str(af->data); - mp_snprintf_cat(b, sizeof(b), "%s", info); - talloc_free(info); - } + if (af->data) + mp_snprintf_cat(b, sizeof(b), "%s", mp_audio_config_to_str(af->data)); if (af == at) mp_snprintf_cat(b, sizeof(b), " <-"); MP_MSG(s, msg_level, "%s\n", b); @@ -320,9 +317,7 @@ static void af_print_filter_chain(struct af_stream *s, struct af_instance *at, af = af->next; } - char *info = mp_audio_config_to_str(&s->output); - MP_MSG(s, msg_level, " [ao] %s\n", info); - talloc_free(info); + MP_MSG(s, msg_level, " [ao] %s\n", mp_audio_config_to_str(&s->output)); } static int af_count_filters(struct af_stream *s) diff --git a/player/audio.c b/player/audio.c index e8516bca0d..f2b49b190c 100644 --- a/player/audio.c +++ b/player/audio.c @@ -275,9 +275,8 @@ void reinit_audio_chain(struct MPContext *mpctx) mpctx->ao_decoder_fmt = talloc(NULL, struct mp_audio); *mpctx->ao_decoder_fmt = in_format; - char *s = mp_audio_config_to_str(&fmt); - MP_INFO(mpctx, "AO: [%s] %s\n", ao_get_name(ao), s); - talloc_free(s); + MP_INFO(mpctx, "AO: [%s] %s\n", ao_get_name(ao), + mp_audio_config_to_str(&fmt)); MP_VERBOSE(mpctx, "AO: Description: %s\n", ao_get_description(ao)); update_window_title(mpctx, true); } -- cgit v1.2.3