From b2883408befa737d6cfe8dd50e6ea7e2622a9d60 Mon Sep 17 00:00:00 2001 From: Thomas Guillem Date: Mon, 28 Oct 2024 15:59:24 +0100 Subject: [PATCH] thumbnailer: notify on_ended when cancelled Like the preparser is doing. --- include/vlc_thumbnailer.h | 8 +++++--- src/input/thumbnailer.c | 13 ++++++++++--- test/src/input/thumbnail.c | 4 ++-- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/include/vlc_thumbnailer.h b/include/vlc_thumbnailer.h index 49aed755ff5c..2c59b1747220 100644 --- a/include/vlc_thumbnailer.h +++ b/include/vlc_thumbnailer.h @@ -45,9 +45,11 @@ struct vlc_thumbnailer_cbs * * @note This callback is mandatory. * - * In case of failure, p_thumbnail will be NULL. The picture, if any, is - * owned by the thumbnailer, and must be acquired by using \link - * picture_Hold \endlink to use it pass the callback's scope. + * In case of failure, timeout or cancellation, p_thumbnail will be NULL. + * The picture, if any, is owned by the thumbnailer, and must be acquired + * by using \link picture_Hold \endlink to use it pass the callback's + * scope. + * * \param thumbnail The generated thumbnail, or NULL in case of failure or * timeout * \param data Is the opaque pointer passed as vlc_thumbnailer_Request last diff --git a/src/input/thumbnailer.c b/src/input/thumbnailer.c index 3ff29ee4bed0..80e10cbb523e 100644 --- a/src/input/thumbnailer.c +++ b/src/input/thumbnailer.c @@ -209,13 +209,12 @@ RunnableRun(void *userdata) picture_t* pic = task->pic; task->pic = NULL; - bool notify = task->status != INTERRUPTED; + bool interrupted = task->status == INTERRUPTED; vlc_list_remove(&task->node); vlc_mutex_unlock(&thumbnailer->lock); - if (notify) - NotifyThumbnail(task, pic); + NotifyThumbnail(task, interrupted ? NULL : pic); if (pic) picture_Release(pic); @@ -268,7 +267,15 @@ size_t vlc_thumbnailer_Cancel( vlc_thumbnailer_t* thumbnailer, vlc_thumbnailer_r if (canceled) { vlc_list_remove(&task->node); + vlc_mutex_unlock(&thumbnailer->lock); + NotifyThumbnail(task, NULL); TaskDestroy(task); + + /* Small optimisation in the likely case where the user cancel + * only one task */ + if (id != VLC_THUMBNAILER_REQ_ID_INVALID) + return count; + vlc_mutex_lock(&thumbnailer->lock); } else { diff --git a/test/src/input/thumbnail.c b/test/src/input/thumbnail.c index 2db84fc01205..01fc6b3c6f43 100644 --- a/test/src/input/thumbnail.c +++ b/test/src/input/thumbnail.c @@ -173,9 +173,9 @@ static void test_thumbnails( libvlc_instance_t* p_vlc ) static void thumbnailer_callback_cancel( picture_t* p_thumbnail, void *data ) { - (void) data; (void) p_thumbnail; + (void) data; /* This callback should not be called since the request is cancelled */ - vlc_assert_unreachable(); + assert( p_thumbnail == NULL ); } static void test_cancel_thumbnail( libvlc_instance_t* p_vlc )