}
/**
- * 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;
}