Skip to content

Commit

Permalink
thumbnailer: notify on_ended when cancelled
Browse files Browse the repository at this point in the history
Like the preparser is doing.
  • Loading branch information
tguillem authored and robUx4 committed Nov 1, 2024
1 parent 64cce80 commit b288340
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
8 changes: 5 additions & 3 deletions include/vlc_thumbnailer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 10 additions & 3 deletions src/input/thumbnailer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
{
Expand Down
4 changes: 2 additions & 2 deletions test/src/input/thumbnail.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down

0 comments on commit b288340

Please sign in to comment.