-static int get_file_info(int i)
-{
- return afl[i].get_file_info(map, mmd->size, &mmd->afi);
-}
-
-/**
- * guess the audio format judging from filename
- *
- * \param name the filename
- *
- * \return This function returns -1 if it has no idea what kind of audio
- * file this might be. Otherwise the (non-negative) number of the audio format
- * is returned.
- */
-int guess_audio_format(const char *name)
-{
- int i,j, len = strlen(name);
-
- FOR_EACH_AUDIO_FORMAT(i) {
- for (j = 0; afl[i].suffixes[j]; j++) {
- const char *p = afl[i].suffixes[j];
- int plen = strlen(p);
- if (len < plen + 1)
- continue;
- if (name[len - plen - 1] != '.')
- continue;
- if (strcasecmp(name + len - plen, p))
- continue;
-// PARA_DEBUG_LOG("might be %s\n", audio_format_name(i));
- return i;
- }
- }
- return -1;
-}
-
-static int get_audio_format(int omit)
-{
- int i;
-
- FOR_EACH_AUDIO_FORMAT(i) {
- if (i == omit)
- continue;
- if (get_file_info(i) > 0)
- return i;
- }
- return -E_AUDIO_FORMAT;
-}
-
-/*
- * upddate shared mem
- */
-static int update_mmd(void)
-{
- int i;
-
- i = guess_audio_format(mmd->filename);
- if (i < 0 || get_file_info(i) < 0)
- i = get_audio_format(i);
- if (i < 0)
- return i;
- mmd->audio_format = i;
- mmd->chunks_sent = 0;
- mmd->current_chunk = 0;
- mmd->offset = 0;
- mmd->events++;
- return 1;
-}
-
-static void vss_get_audio_file(void)
-{
- char **sl = selectors[mmd->selector_num].get_audio_file_list(10);
- int i;
- struct stat file_status;
-
- if (!sl)
- goto err_out;
- for (i = 0; sl[i]; i++) {
- struct timeval now;
- PARA_INFO_LOG("trying %s\n", sl[i]);
- if (strlen(sl[i]) >= _POSIX_PATH_MAX)
- continue;
- audio_file = open(sl[i], O_RDONLY);
- if (audio_file < 0)
- continue;
- if (fstat(audio_file, &file_status) == -1 ||
- !file_status.st_size) {
- 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]);
- mmd->afi.header_len = 0; /* default: no header */
- 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_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;
- }
-err_out:
- PARA_ERROR_LOG("%s", "no valid files found\n");
- mmd->new_vss_status_flags = VSS_NEXT;
-free:
- if (sl) {
- for (i = 0; sl[i]; i++)
- free(sl[i]);
- free(sl);
- }
-}
-