]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
afs: Simplify open_next_audio_file().
authorAndre Noll <maan@tuebingen.mpg.de>
Sun, 21 Dec 2014 15:24:18 +0000 (15:24 +0000)
committerAndre Noll <maan@tuebingen.mpg.de>
Mon, 30 Mar 2015 21:40:57 +0000 (21:40 +0000)
This function of afs.c is called whenever the virtual streaming
system requests a new audio file. It determines the row of the audio
file table that corresponds to the audio file with highest score,
according to the current mood or playlist. The function passes this
information to open_and_update_audio_file() of aft.c which sets up
an afd structure to be passed back to the server process.

Letting open_and_update_audio_file() determine which file to
open is shorter, and it allows to get rid of two arguments to
open_and_update_audio_file().

afs.c
afs.h
aft.c

diff --git a/afs.c b/afs.c
index c5e2c93ee51363a69f3178b77c4d79982b427f73..a16252cdf037e50bdd415b8978968b638b508f0c 100644 (file)
--- a/afs.c
+++ b/afs.c
@@ -455,7 +455,7 @@ static int pass_afd(int fd, char *buf, size_t size)
 }
 
 /**
- * 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
@@ -467,27 +467,15 @@ static int pass_afd(int fd, char *buf, size_t size)
  */
 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;
diff --git a/afs.h b/afs.h
index 88b891c829d835efcef315ff8e5aa8fd1b725353..cccb143f5bdfa1e4aaa2cdcaa1d1e73e6780f119 100644 (file)
--- a/afs.h
+++ b/afs.h
@@ -245,8 +245,7 @@ int get_attribute_text(uint64_t *atts, const char *delim, char **text);
 /* 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);
diff --git a/aft.c b/aft.c
index a73537c74446b3cdb49e405f7918701d837a8e8f..8a633298ead4d05d6c11b8a7a429b0ec7974ed80 100644 (file)
--- a/aft.c
+++ b/aft.c
@@ -1080,10 +1080,8 @@ static int make_status_items(struct audio_file_data *afd,
 }
 
 /**
- * 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
@@ -1092,17 +1090,22 @@ static int make_status_items(struct audio_file_data *afd,
  *
  * \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);
@@ -1150,8 +1153,12 @@ int open_and_update_audio_file(struct osl_row *aft_row, long score,
 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;
 }