Merge branch 'refs/heads/t/para_play'
authorAndre Noll <maan@tuebingen.mpg.de>
Sat, 16 May 2020 10:14:23 +0000 (12:14 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Sat, 16 May 2020 10:15:09 +0000 (12:15 +0200)
A single patch which adds --end-of-playlist to control the behaviour
of para_play when the end of the playlist is reached.

Cooking for three weeks.

* refs/heads/t/para_play:
  play: New option: --end-of-playlist.

NEWS.md
error.h
m4/lls/play.suite.m4
play.c

diff --git a/NEWS.md b/NEWS.md
index 34aad07..de0aa1b 100644 (file)
--- a/NEWS.md
+++ b/NEWS.md
@@ -28,6 +28,7 @@ NEWS
 - Robustness improvements for para_mixer.
 - A fix for an old bug that could cause the server to crash or report
   garbage in its status output.
+- New para_play option: --end-of-playlist
 
 --------------------------------------
 0.6.2 (2018-06-30) "elastic diversity"
diff --git a/error.h b/error.h
index 8ef9e37..fe44ff5 100644 (file)
--- a/error.h
+++ b/error.h
@@ -83,6 +83,7 @@
        PARA_ERROR(EMPTY, "file is empty"), \
        PARA_ERROR(ENCRYPT, "encrypt error"), \
        PARA_ERROR(EOF, "end of file"), \
+       PARA_ERROR(EOP, "end of playlist"), \
        PARA_ERROR(FEC_BAD_IDX, "invalid index vector"), \
        PARA_ERROR(FECDEC_EOF, "received eof packet"), \
        PARA_ERROR(FECDEC_OVERRUN, "fecdec output buffer overrun"), \
index 57a9377..f2220f1 100644 (file)
@@ -26,6 +26,16 @@ version-string = GIT_VERSION()
        [option randomize]
                short_opt = z
                summary = randomize playlist at startup
+       [option end-of-playlist]
+               summary = what to do after the last file has been played
+               arg_info = required_arg
+               arg_type = string
+               typestr = behaviour
+               values = {
+                       EOP_LOOP = "loop",
+                       EOP_STOP = "stop",
+                       EOP_QUIT = "quit"
+                }
        [option key-map]
                short_opt = k
                summary = map a key to a command
diff --git a/play.c b/play.c
index 86edc4d..2346c6b 100644 (file)
--- a/play.c
+++ b/play.c
@@ -219,7 +219,6 @@ static long unsigned get_play_time(void)
        return result;
 }
 
-
 static void wipe_receiver_node(void)
 {
        PARA_NOTICE_LOG("cleaning up receiver node\n");
@@ -434,6 +433,15 @@ static int next_valid_file(void)
        int i, j = pt->current_file;
        unsigned num_inputs = lls_num_inputs(play_lpr);
 
+       if (j == num_inputs - 1) {
+               switch (OPT_UINT32_VAL(END_OF_PLAYLIST)) {
+               case EOP_LOOP: break;
+               case EOP_STOP:
+                       pt->playing = false;
+                       return 0;
+               case EOP_QUIT: return -E_EOP;
+               }
+       }
        for (i = 0; i < num_inputs; i++) {
                j = (j + 1) % num_inputs;
                if (!pt->invalid[j])
@@ -1245,7 +1253,6 @@ int main(int argc, char *argv[])
        init_shuffle_map();
        pt->invalid = para_calloc(sizeof(*pt->invalid) * num_inputs);
        pt->rq = CRT_FILE_CHANGE;
-       pt->current_file = num_inputs - 1;
        pt->playing = true;
        pt->task = task_register(&(struct task_info){
                .name = "play",