}
/**
- * Open the audio file with highest score.
+ * Pass the fd of the next audio file to the server process.
*
* This stores all information for streaming the "best" audio file in a shared
* memory area. The id of that area and an open file descriptor for the next
*/
static int open_next_audio_file(void)
{
- struct osl_row *aft_row;
struct audio_file_data afd;
int ret, shmid;
char buf[8];
- long score;
-again:
- PARA_NOTICE_LOG("getting next audio file\n");
- ret = score_get_best(&aft_row, &score);
+
+ ret = open_and_update_audio_file(&afd);
if (ret < 0) {
PARA_ERROR_LOG("%s\n", para_strerror(-ret));
goto no_admissible_files;
}
- ret = open_and_update_audio_file(aft_row, score, &afd);
- if (ret < 0) {
- ret = score_delete(aft_row);
- if (ret < 0) {
- PARA_ERROR_LOG("%s\n", para_strerror(-ret));
- goto no_admissible_files;
- }
- goto again;
- }
shmid = ret;
if (!write_ok(server_socket)) {
ret = -E_AFS_SOCKET;
/* aft */
void aft_init(struct afs_table *t);
int aft_get_row_of_path(const char *path, struct osl_row **row);
-int open_and_update_audio_file(struct osl_row *aft_row, long score,
- struct audio_file_data *afd);
+int open_and_update_audio_file(struct audio_file_data *afd);
int load_afd(int shmid, struct audio_file_data *afd);
int get_afsi_of_row(const struct osl_row *row, struct afs_info *afsi);
int get_afhi_of_row(const struct osl_row *row, struct afh_info *afhi);
}
/**
- * Mmap the given audio file and update statistics.
+ * Open the audio file with highest score and set up an afd structure.
*
- * \param aft_row Determines the audio file to be opened and updated.
- * \param score The score of the audio file.
* \param afd Result pointer.
*
* On success, the numplayed field of the audio file selector info is increased
*
* \return Positive shmid on success, negative on errors.
*/
-int open_and_update_audio_file(struct osl_row *aft_row, long score,
- struct audio_file_data *afd)
+int open_and_update_audio_file(struct audio_file_data *afd)
{
+ struct osl_row *aft_row;
+ long score;
unsigned char *aft_hash, file_hash[HASH_SIZE];
struct osl_object afsi_obj;
struct afs_info old_afsi, new_afsi;
- int ret = get_hash_of_row(aft_row, &aft_hash);
+ int ret;
struct afsi_change_event_data aced;
struct osl_object map, chunk_table_obj;
char *path;
-
+again:
+ ret = score_get_best(&aft_row, &score);
+ if (ret < 0)
+ return ret;
+ ret = get_hash_of_row(aft_row, &aft_hash);
if (ret < 0)
return ret;
ret = get_audio_file_path_of_row(aft_row, &path);
err:
free(afd->afhi.chunk_table);
osl_close_disk_object(&chunk_table_obj);
- if (ret < 0)
+ if (ret < 0) {
PARA_ERROR_LOG("%s: %s\n", path, para_strerror(-ret));
+ ret = score_delete(aft_row);
+ if (ret >= 0)
+ goto again;
+ }
return ret;
}