[vlc-commits] [Git][videolan/vlc][master] 6 commits: test: player: rework the ignored media case

Hugo Beauzée-Luyssen (@chouquette) gitlab at videolan.org
Thu Dec 9 12:27:18 UTC 2021



Hugo Beauzée-Luyssen pushed to branch master at VideoLAN / VLC


Commits:
1a718b7d by Thomas Guillem at 2021-12-09T12:09:06+00:00
test: player: rework the ignored media case

Don't use player_set_current_mock_media() for this single test.

- - - - -
767d2f2e by Thomas Guillem at 2021-12-09T12:09:06+00:00
test: player: add added_medias vector

To differentiate between added medias and played medias in tests.

- - - - -
c1451c4c by Thomas Guillem at 2021-12-09T12:09:06+00:00
player: always play the next media...

...if the last one has not been played.

Regardless of the user option.

Refs #26312

- - - - -
956b118a by Thomas Guillem at 2021-12-09T12:09:06+00:00
player: always process the STOPPED event

Fix playback of the current media if a last one has been set without
being played.

Refs #26312

- - - - -
560a8ac3 by Thomas Guillem at 2021-12-09T12:09:06+00:00
test: player: test playback after an ignored media

This validate the previous commit.

- - - - -
65d5911a by Thomas Guillem at 2021-12-09T12:09:06+00:00
test: player: add test_same_media

Ensure that a single media, if set more than one time, is only played
once.

Refs #26312

- - - - -


3 changed files:

- src/player/input.c
- src/player/player.c
- test/src/player/player.c


Changes:

=====================================
src/player/input.c
=====================================
@@ -135,6 +135,7 @@ vlc_player_input_HandleState(struct vlc_player_input *input,
      && state != VLC_PLAYER_STATE_STOPPED)
         return;
 
+    enum vlc_player_state last_state = input->state;
     input->state = state;
 
     /* Override the global state if the player is still playing and has a next
@@ -167,7 +168,15 @@ vlc_player_input_HandleState(struct vlc_player_input *input,
             if (!player->input)
                 player->started = false;
 
-            switch (player->media_stopped_action)
+            /* If the last input was not even started, always play the next
+             * media */
+            enum vlc_player_media_stopped_action stopped_action;
+            if (last_state == VLC_PLAYER_STATE_STOPPED)
+                stopped_action = VLC_PLAYER_MEDIA_STOPPED_CONTINUE;
+            else
+                stopped_action = player->media_stopped_action;
+
+            switch (stopped_action)
             {
                 case VLC_PLAYER_MEDIA_STOPPED_EXIT:
                     if (player->input && player->started)


=====================================
src/player/player.c
=====================================
@@ -232,9 +232,8 @@ vlc_player_destructor_Thread(void *data)
 
             keep_sout = var_GetBool(input->thread, "sout-keep");
 
-            if (input->state == VLC_PLAYER_STATE_STOPPING)
-                vlc_player_input_HandleState(input, VLC_PLAYER_STATE_STOPPED,
-                                             VLC_TICK_INVALID);
+            vlc_player_input_HandleState(input, VLC_PLAYER_STATE_STOPPED,
+                                         VLC_TICK_INVALID);
 
             vlc_list_remove(&input->node);
             vlc_player_input_Delete(input);
@@ -1875,7 +1874,10 @@ vlc_player_Delete(vlc_player_t *player)
     vlc_mutex_lock(&player->lock);
 
     if (player->input)
+    {
         vlc_player_destructor_AddInput(player, player->input);
+        player->input = NULL;
+    }
 
     player->deleting = true;
     vlc_cond_signal(&player->destructor.wait);


=====================================
test/src/player/player.c
=====================================
@@ -226,6 +226,7 @@ struct ctx
     vlc_player_t *player;
     vlc_player_listener_id *listener;
     struct VLC_VECTOR(input_item_t *) next_medias;
+    struct VLC_VECTOR(input_item_t *) added_medias;
     struct VLC_VECTOR(input_item_t *) played_medias;
 
     size_t program_switch_count;
@@ -259,7 +260,9 @@ player_get_next(vlc_player_t *player, void *data)
         vlc_vector_remove(&ctx->next_medias, 0);
 
         input_item_Hold(next_media);
-        bool success = vlc_vector_push(&ctx->played_medias, next_media);
+        bool success = vlc_vector_push(&ctx->added_medias, next_media);
+        assert(success);
+        success = vlc_vector_push(&ctx->played_medias, next_media);
         assert(success);
     }
     else
@@ -686,9 +689,11 @@ REPORT_LIST
     }
     vlc_vector_clear(&ctx->next_medias);
 
-    vlc_vector_foreach(media, &ctx->played_medias)
+    vlc_vector_foreach(media, &ctx->added_medias)
         if (media)
             input_item_Release(media);
+    vlc_vector_clear(&ctx->added_medias);
+
     vlc_vector_clear(&ctx->played_medias);
 
     ctx->extra_start_count = 0;
@@ -750,14 +755,12 @@ player_set_current_mock_media(struct ctx *ctx, const char *name,
     int ret = vlc_player_SetCurrentMedia(ctx->player, media);
     assert(ret == VLC_SUCCESS);
 
-    if (ignored)
-    {
-        if (media)
-            input_item_Release(media);
-    }
-    else
+    bool success = vlc_vector_push(&ctx->added_medias, media);
+    assert(success);
+
+    if (!ignored)
     {
-        bool success = vlc_vector_push(&ctx->played_medias, media);
+        success = vlc_vector_push(&ctx->played_medias, media);
         assert(success);
     }
 }
@@ -768,7 +771,7 @@ player_set_next_mock_media(struct ctx *ctx, const char *name,
 {
     if (vlc_player_GetCurrentMedia(ctx->player) == NULL)
     {
-        assert(ctx->played_medias.size == 0);
+        assert(ctx->added_medias.size == 0);
         player_set_current_mock_media(ctx, name, params, false);
     }
     else
@@ -776,7 +779,7 @@ player_set_next_mock_media(struct ctx *ctx, const char *name,
         input_item_t *media = create_mock_media(name, params);
         assert(media);
 
-        assert(ctx->played_medias.size > 0);
+        assert(ctx->added_medias.size > 0);
         bool success = vlc_vector_push(&ctx->next_medias, media);
         assert(success);
     }
@@ -993,9 +996,9 @@ test_end_poststop_medias(struct ctx *ctx)
     while (vec->size == oldsize)
         vlc_player_CondWait(player, &ctx->wait);
 
-    assert(vec->size == ctx->played_medias.size);
+    assert(vec->size == ctx->added_medias.size);
     for (size_t i  = 0; i < vec->size; ++i)
-        assert(vec->data[i] == ctx->played_medias.data[i]);
+        assert(vec->data[i] == ctx->added_medias.data[i]);
 
     assert(VEC_LAST(vec) == NULL);
     assert(vlc_player_GetCurrentMedia(player) == NULL);
@@ -1661,7 +1664,9 @@ test_unknown_uri(struct ctx *ctx)
     assert(ret == VLC_SUCCESS);
 
     ctx->params.error = true;
-    bool success = vlc_vector_push(&ctx->played_medias, media);
+    bool success = vlc_vector_push(&ctx->added_medias, media);
+    assert(success);
+    success = vlc_vector_push(&ctx->played_medias, media);
     assert(success);
 
     player_start(ctx);
@@ -1888,6 +1893,32 @@ test_next_media(struct ctx *ctx)
     test_end(ctx);
 }
 
+static void
+test_same_media(struct ctx *ctx)
+{
+    test_log("same_media\n");
+
+    vlc_player_t *player = ctx->player;
+    struct media_params params = DEFAULT_MEDIA_PARAMS(VLC_TICK_FROM_MS(10));
+
+    player_set_current_mock_media(ctx, "media", &params, false);
+
+    input_item_t *media = vlc_player_GetCurrentMedia(player);
+    assert(media);
+
+    input_item_Hold(media);
+    vlc_player_SetCurrentMedia(player, media);
+    bool success = vlc_vector_push(&ctx->added_medias, media);
+    assert(success);
+
+    player_start(ctx);
+
+    wait_state(ctx, VLC_PLAYER_STATE_STARTED);
+    wait_state(ctx, VLC_PLAYER_STATE_STOPPED);
+
+    test_end(ctx);
+}
+
 static void
 test_set_current_media(struct ctx *ctx)
 {
@@ -1898,6 +1929,9 @@ test_set_current_media(struct ctx *ctx)
     vlc_player_t *player = ctx->player;
     struct media_params params = DEFAULT_MEDIA_PARAMS(VLC_TICK_FROM_MS(100));
 
+    /* Ensure that this media is not played */
+    player_set_current_mock_media(ctx, "ignored", &params, true);
+
     player_set_current_mock_media(ctx, media_names[0], &params, false);
     player_start(ctx);
 
@@ -1907,16 +1941,17 @@ test_set_current_media(struct ctx *ctx)
      * the player and without passing by the next_media provider. */
     {
         vec_on_current_media_changed *vec = &ctx->report.on_current_media_changed;
-        assert(vec->size == 1);
+        assert(vec->size == 2);
+
         for (size_t i = 1; i <= media_count; ++i)
         {
-            while (vec->size != i)
+            while (vec->size - 1 /* ignored */!= i)
                 vlc_player_CondWait(player, &ctx->wait);
 
             input_item_t *last_media = VEC_LAST(vec);
             assert(last_media);
             assert(last_media == vlc_player_GetCurrentMedia(player));
-            assert(last_media == VEC_LAST(&ctx->played_medias));
+            assert(last_media == VEC_LAST(&ctx->added_medias));
             assert_media_name(last_media, media_names[i - 1]);
 
             if (i < media_count)
@@ -1924,8 +1959,12 @@ test_set_current_media(struct ctx *ctx)
                 /* Next vlc_player_SetCurrentMedia() call should be
                  * asynchronous since we are still playing. Therefore,
                  * vlc_player_GetCurrentMedia() should return the last one. */
-                player_set_current_mock_media(ctx, "ignored", &params, true);
+                input_item_t *ignored = create_mock_media("ignored", &params);
+                assert(ignored);
+                int ret = vlc_player_SetCurrentMedia(ctx->player, ignored);
+                assert(ret == VLC_SUCCESS);
                 assert(vlc_player_GetCurrentMedia(player) == last_media);
+                input_item_Release(ignored);
 
                 /* The previous media is ignored due to this call */
                 player_set_current_mock_media(ctx, media_names[i], &params, false);
@@ -1949,7 +1988,7 @@ test_set_current_media(struct ctx *ctx)
 
     /* Playback is stopped: vlc_player_SetCurrentMedia should be synchronous */
     player_set_current_mock_media(ctx, media_names[0], &params, false);
-    assert(vlc_player_GetCurrentMedia(player) == VEC_LAST(&ctx->played_medias));
+    assert(vlc_player_GetCurrentMedia(player) == VEC_LAST(&ctx->added_medias));
 
     player_start(ctx);
 
@@ -2110,6 +2149,7 @@ REPORT_LIST
     *ctx = (struct ctx) {
         .vlc = vlc,
         .next_medias = VLC_VECTOR_INITIALIZER,
+        .added_medias = VLC_VECTOR_INITIALIZER,
         .played_medias = VLC_VECTOR_INITIALIZER,
         .program_switch_count = 1,
         .extra_start_count = 0,
@@ -2866,6 +2906,7 @@ main(void)
 
     test_outputs(&ctx); /* Must be the first test */
 
+    test_same_media(&ctx);
     test_set_current_media(&ctx);
     test_next_media(&ctx);
     test_seeks(&ctx);



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/b3986c8cb734b41d2282454a2471e77fa71306df...65d5911a1b3d166dd22c832db428a339e7ea1336

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/b3986c8cb734b41d2282454a2471e77fa71306df...65d5911a1b3d166dd22c832db428a339e7ea1336
You're receiving this email because of your account on code.videolan.org.




More information about the vlc-commits mailing list