From: Andre Noll Date: Tue, 26 Jun 2012 19:28:48 +0000 (+0200) Subject: Introduce afh_get_afhi_txt(). X-Git-Tag: v0.4.12~7^2~17 X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=commitdiff_plain;h=7c8931ecbbf665d399ffbc101fde88eb8d78af85 Introduce afh_get_afhi_txt(). The afh receiver needs a pretty-printed version of the audio format handler structure, like the one that is printed in print_info() of afh.c. This commit moves print_info() to afh_common.c and makes it print into a buffer rather than to stdout. The function is renamed to the more descriptive afh_get_afhi_txt(). The single caller in afh.c is changed accordingly. --- diff --git a/afh.c b/afh.c index 5b1cfe9b..ee55cf0e 100644 --- a/afh.c +++ b/afh.c @@ -25,34 +25,11 @@ INIT_STDERR_LOGGING(loglevel) static void print_info(int audio_format_num, struct afh_info *afhi) { - printf("%s: %dkbit/s\n" /* bitrate */ - "%s: %s\n" /* format */ - "%s: %dHz\n" /* frequency */ - "%s: %d\n" /* channels */ - "%s: %lu\n" /* seconds total */ - "%s: %lu: %lu\n" /* chunk time */ - "%s: %lu\n" /* num chunks */ - "%s: %s\n" /* techinfo */ - "%s: %s\n" /* artist */ - "%s: %s\n" /* title */ - "%s: %s\n" /* year */ - "%s: %s\n" /* album */ - "%s: %s\n", /* comment */ - status_item_list[SI_BITRATE], afhi->bitrate, - status_item_list[SI_FORMAT], audio_format_name(audio_format_num), - status_item_list[SI_FREQUENCY], afhi->frequency, - status_item_list[SI_CHANNELS], afhi->channels, - status_item_list[SI_SECONDS_TOTAL], afhi->seconds_total, - status_item_list[SI_CHUNK_TIME], (long unsigned)afhi->chunk_tv.tv_sec, - (long unsigned)afhi->chunk_tv.tv_usec, - status_item_list[SI_NUM_CHUNKS], afhi->chunks_total, - status_item_list[SI_TECHINFO], afhi->techinfo? afhi->techinfo : "", - status_item_list[SI_ARTIST], afhi->tags.artist? afhi->tags.artist : "", - status_item_list[SI_TITLE], afhi->tags.title? afhi->tags.title : "", - status_item_list[SI_YEAR], afhi->tags.year? afhi->tags.year : "", - status_item_list[SI_ALBUM], afhi->tags.album? afhi->tags.album : "", - status_item_list[SI_COMMENT], afhi->tags.comment? afhi->tags.comment : "" - ); + char *msg; + + afh_get_afhi_txt(audio_format_num, afhi, &msg); + printf("%s", msg); + free(msg); } static void print_chunk_table(struct afh_info *afhi) diff --git a/afh.h b/afh.h index 79528094..4f23a173 100644 --- a/afh.h +++ b/afh.h @@ -105,3 +105,4 @@ void afh_get_header(struct afh_info *afhi, uint8_t audio_format_id, void *map, size_t mapsize, char **buf, size_t *len); void afh_free_header(char *header_buf, uint8_t audio_format_id); void clear_afhi(struct afh_info *afhi); +unsigned afh_get_afhi_txt(int audio_format_num, struct afh_info *afhi, char **result); diff --git a/afh_common.c b/afh_common.c index 5b6301b5..577053d4 100644 --- a/afh_common.c +++ b/afh_common.c @@ -329,3 +329,47 @@ void afh_free_header(char *header_buf, uint8_t audio_format_id) if (afh->get_header) free(header_buf); } + +/** + * Pretty-print the contents of a struct afh_info into a buffer. + * + * \param audio_format_num The audio format number. + * \param afhi Pointer to the structure that contains the information. + * \param result Pretty-printed ahfi is here after the call. + * + * The \a result buffer is dynamically allocated and should be freed by the + * caller. + * + * \return The number of bytes. This function never fails. + */ +unsigned afh_get_afhi_txt(int audio_format_num, struct afh_info *afhi, char **result) +{ + return xasprintf(result, "%s: %dkbit/s\n" /* bitrate */ + "%s: %s\n" /* format */ + "%s: %dHz\n" /* frequency */ + "%s: %d\n" /* channels */ + "%s: %lu\n" /* seconds total */ + "%s: %lu: %lu\n" /* chunk time */ + "%s: %lu\n" /* num chunks */ + "%s: %s\n" /* techinfo */ + "%s: %s\n" /* artist */ + "%s: %s\n" /* title */ + "%s: %s\n" /* year */ + "%s: %s\n" /* album */ + "%s: %s\n", /* comment */ + status_item_list[SI_BITRATE], afhi->bitrate, + status_item_list[SI_FORMAT], audio_format_name(audio_format_num), + status_item_list[SI_FREQUENCY], afhi->frequency, + status_item_list[SI_CHANNELS], afhi->channels, + status_item_list[SI_SECONDS_TOTAL], afhi->seconds_total, + status_item_list[SI_CHUNK_TIME], (long unsigned)afhi->chunk_tv.tv_sec, + (long unsigned)afhi->chunk_tv.tv_usec, + status_item_list[SI_NUM_CHUNKS], afhi->chunks_total, + status_item_list[SI_TECHINFO], afhi->techinfo? afhi->techinfo : "", + status_item_list[SI_ARTIST], afhi->tags.artist? afhi->tags.artist : "", + status_item_list[SI_TITLE], afhi->tags.title? afhi->tags.title : "", + status_item_list[SI_YEAR], afhi->tags.year? afhi->tags.year : "", + status_item_list[SI_ALBUM], afhi->tags.album? afhi->tags.album : "", + status_item_list[SI_COMMENT], afhi->tags.comment? afhi->tags.comment : "" + ); +}