From 970247623b17124a5aacb14a8061da56e1f3b0be Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Sun, 25 Mar 2007 16:34:20 +0200 Subject: [PATCH] do not copy the audio file header It's present in the memory map anyway. So instead of making a copy, store the position of the header (always zero for now) in mmd->audio_format_info. --- afh.h | 21 +++++++++++---------- ogg_afh.c | 10 +--------- vss.c | 7 +++---- 3 files changed, 15 insertions(+), 23 deletions(-) diff --git a/afh.h b/afh.h index e365df86..38e1ff04 100644 --- a/afh.h +++ b/afh.h @@ -61,17 +61,18 @@ struct audio_format_info { /** end of file timeout - do not load new audio file until this time */ struct timeval eof_tv; /** - * optional audio file header - * - * This is read from a sender in case a new client connects in the - * middle of the stream. The audio format handler does not need to set - * this if the audio format does not need any special header treatment. - * If non-NULL, it must point to a buffer holding the current audio - * file header. - */ - char *header; - /** the length of the header, ignored if \a header is \p NULL */ + * The header is needed by senders in case a new client connects in the + * middle of the stream. The length of the header defaults to zero + * which means that this audio format does not need any special header + * treatment. The audio format handler does not need to set this to + * zero in this case. + */ unsigned header_len; + /** + * The position of the header within the audio file. Ignored if \a + * header_len equals zero. + */ + unsigned header_offset; uint8_t channels; uint16_t frequency; uint16_t bitrate; diff --git a/ogg_afh.c b/ogg_afh.c index 078ff786..5adcc252 100644 --- a/ogg_afh.c +++ b/ogg_afh.c @@ -117,12 +117,6 @@ static int ogg_open_callbacks(void *datasource, OggVorbis_File *vf, ov_callbacks } -static void ogg_save_header(char *map, struct audio_format_info *afi) -{ - afi->header = para_malloc(afi->header_len); - memcpy(afi->header, map, afi->header_len); -} - static int ogg_compute_header_len(char *map, off_t numbytes, struct audio_format_info *afi) { @@ -187,7 +181,7 @@ static int ogg_compute_header_len(char *map, off_t numbytes, while (ogg_stream_flush(stream_out, &page)) afi->header_len += page.body_len + page.header_len; PARA_INFO_LOG("header_len = %d\n", afi->header_len); - ogg_save_header(map, afi); + afi->header_offset = 0; ret = 1; err2: ogg_stream_destroy(stream_in); @@ -287,8 +281,6 @@ static int ogg_get_file_info(char *map, off_t numbytes, ret = 1; err: ov_clear(&of); /* keeps the file open */ - if (ret < 0) - free(afi->header); return ret; } diff --git a/vss.c b/vss.c index cb2d16c8..a3c2e650 100644 --- a/vss.c +++ b/vss.c @@ -278,6 +278,7 @@ static void vss_get_audio_file(void) map = para_mmap(file_status.st_size, PROT_READ, MAP_PRIVATE, audio_file, 0); strcpy(mmd->filename, sl[i]); + mmd->afi.header_len = 0; /* default: no header */ if (update_mmd() < 0) { /* invalid file */ close(audio_file); munmap(map, mmd->size); @@ -384,8 +385,6 @@ static void vss_eof(void) mmd->afi.seconds_total = 0; free(mmd->afi.chunk_table); mmd->afi.chunk_table = NULL; - free(mmd->afi.header); - mmd->afi.header = NULL; tmp = make_message("%s:\n%s:\n%s:\n", status_item_list[SI_AUDIO_INFO1], status_item_list[SI_AUDIO_INFO2], status_item_list[SI_AUDIO_INFO3]); strcpy(mmd->afi.info_string, tmp); @@ -411,10 +410,10 @@ static void vss_eof(void) */ char *vss_get_header(int *header_len) { - if (mmd->audio_format < 0) + if (mmd->audio_format < 0 || !map || !mmd->afi.header_len) return NULL; *header_len = mmd->afi.header_len; - return mmd->afi.header; + return map + mmd->afi.header_offset; } /** -- 2.39.5