do not copy the audio file header
authorAndre Noll <maan@systemlinux.org>
Sun, 25 Mar 2007 14:34:20 +0000 (16:34 +0200)
committerAndre Noll <maan@systemlinux.org>
Sun, 25 Mar 2007 14:34:20 +0000 (16:34 +0200)
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
ogg_afh.c
vss.c

diff --git a/afh.h b/afh.h
index e365df86569337ba767cfe9601f81c3ba39c939c..38e1ff04c4ad9823456d788b835d11f77952bc86 100644 (file)
--- 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;
        /**
        /** 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;
        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;
        uint8_t channels;
        uint16_t frequency;
        uint16_t bitrate;
index 078ff786883b53c17b83ffc04f42cb61bc0be4c5..5adcc25218377e57c8b038e30e325268aeb6e86f 100644 (file)
--- 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)
 {
 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);
        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);
        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 */
        ret = 1;
 err:
        ov_clear(&of); /* keeps the file open */
-       if (ret < 0)
-               free(afi->header);
        return ret;
 }
 
        return ret;
 }
 
diff --git a/vss.c b/vss.c
index cb2d16c8d0c84843de9f5be213ed09b752aee890..a3c2e65063d267c26b20597f7ae5e1f8c81c24dc 100644 (file)
--- 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]);
                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);
                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;
        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);
        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)
 {
  */
 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 NULL;
        *header_len = mmd->afi.header_len;
-       return mmd->afi.header;
+       return map + mmd->afi.header_offset;
 }
 
 /**
 }
 
 /**