]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
Introduce afh_get_afhi_txt().
authorAndre Noll <maan@systemlinux.org>
Tue, 26 Jun 2012 19:28:48 +0000 (21:28 +0200)
committerAndre Noll <maan@systemlinux.org>
Sun, 18 Nov 2012 19:28:27 +0000 (20:28 +0100)
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.

afh.c
afh.h
afh_common.c

diff --git a/afh.c b/afh.c
index 5b1cfe9bd1bd367939b9df2ddce2e4069c6df70d..ee55cf0e603d1ff0cfa8b4f1bf55eeb8aba10098 100644 (file)
--- 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 7952809436752f19a795362469291a4996f0d468..4f23a173164a5678c66c4fddc43409f5851bdcbc 100644 (file)
--- 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);
index 5b6301b5f3d06405930df8fbcc64c7095f7ece06..577053d45c743d01cc50494e5c9e84e74c42b6a2 100644 (file)
@@ -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 : ""
+       );
+}