/** 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;
}
-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)
{
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;
err:
ov_clear(&of); /* keeps the file open */
- if (ret < 0)
- free(afi->header);
return ret;
}
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);
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);
*/
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;
}
/**