/** \file vss.c the virtual streaming system
*
- * This contains the audio sending part of para_server which is independent of
- * the current audio format, audio file selector and of the activated senders.
+ * This contains the audio streaming code of para_server which is independent
+ * of the current audio format, audio file selector and of the activated
+ * senders.
*/
#include "server.h"
extern struct audio_file_selector selectors[];
extern struct sender senders[];
-static FILE *audio_file = NULL;
+static int audio_file;
static char *map;
#if 1
FOR_EACH_AUDIO_FORMAT(i) {
if (i == omit)
continue;
- rewind(audio_file);
if (get_file_info(i) > 0)
return i;
- rewind(audio_file);
}
return -E_AUDIO_FORMAT;
}
*/
static int update_mmd(void)
{
- int i, fd = fileno(audio_file);
- struct stat file_status;
+ int i;
- if (fstat(fd, &file_status) == -1)
- return -E_FSTAT;
- mmd->size = file_status.st_size;
- mmd->mtime = file_status.st_mtime;
- map = para_mmap(file_status.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
i = guess_audio_format(mmd->filename);
if (i < 0 || get_file_info(i) < 0)
i = get_audio_format(i);
mmd->current_chunk = 0;
mmd->offset = 0;
mmd->events++;
- PARA_NOTICE_LOG("next audio file: %s\n", mmd->filename);
return 1;
}
{
char **sl = selectors[mmd->selector_num].get_audio_file_list(10);
int i;
+ struct stat file_status;
if (!sl)
goto err_out;
PARA_INFO_LOG("trying %s\n", sl[i]);
if (strlen(sl[i]) >= _POSIX_PATH_MAX)
continue;
- audio_file = fopen(sl[i], "r");
- if (!audio_file)
+ audio_file = open(sl[i], O_RDONLY);
+ if (audio_file < 0)
+ continue;
+ if (fstat(audio_file, &file_status) == -1) {
+ close(audio_file);
continue;
+ }
+ mmd->size = file_status.st_size;
+ mmd->mtime = file_status.st_mtime;
+ map = para_mmap(file_status.st_size, PROT_READ, MAP_PRIVATE,
+ audio_file, 0);
strcpy(mmd->filename, sl[i]);
- if (update_mmd() < 0) {
- fclose(audio_file);
- audio_file = NULL;
+ if (update_mmd() < 0) { /* invalid file */
+ close(audio_file);
+ munmap(map, mmd->size);
+ map = NULL;
continue;
}
mmd->num_played++;
if (selectors[mmd->selector_num].update_audio_file)
selectors[mmd->selector_num].update_audio_file(sl[i]);
- PARA_DEBUG_LOG("%s", "success\n");
+ PARA_NOTICE_LOG("next audio file: %s\n", mmd->filename);
mmd->new_vss_status_flags &= (~VSS_NEXT);
gettimeofday(&now, NULL);
tv_add(&now, &announce_tv, &data_send_barrier);
-
goto free;
}
- PARA_ERROR_LOG("%s", "no valid files found\n");
err_out:
+ PARA_ERROR_LOG("%s", "no valid files found\n");
mmd->new_vss_status_flags = VSS_NEXT;
free:
if (sl) {
if (chk_barrier("data send", &now, &data_send_barrier,
&the_timeout, 1) < 0)
return &the_timeout;
- if (mmd->audio_format < 0 || !vss_playing() || !audio_file)
+ if (mmd->audio_format < 0 || !vss_playing() || !map)
return NULL;
vss_next_chunk_time(&next_chunk);
if (chk_barrier(afl[mmd->audio_format].name, &now, &next_chunk,
int i;
char *tmp;
- if (!af || !audio_file) {
+ if (!af || !map) {
for (i = 0; senders[i].name; i++)
senders[i].shutdown_clients();
return;
gettimeofday(&now, NULL);
tv_add(&mmd->afi.eof_tv, &now, &eof_barrier);
munmap(map, mmd->size);
- fclose(audio_file);
- audio_file = NULL;
+ map = NULL;
+ close(audio_file);
mmd->audio_format = -1;
af = NULL;
mmd->chunks_sent = 0;
mmd->current_chunk = mmd->repos_request;
}
ret = vss_compute_timeout();
- if (!ret && !audio_file && vss_playing() &&
+ if (!ret && !map && vss_playing() &&
!(mmd->new_vss_status_flags & VSS_NOMORE)) {
PARA_DEBUG_LOG("%s", "ready and playing, but no audio file\n");
vss_get_audio_file();
ssize_t pos, len;
struct timeval now, due;
- if (mmd->audio_format < 0 || !audio_file || !vss_playing())
+ if (mmd->audio_format < 0 || !map || !vss_playing())
return;
af = &afl[mmd->audio_format];
gettimeofday(&now, NULL);