[vlc-commits] [Git][videolan/vlc][master] 2 commits: input: thumbnailer: Invoke completion callback upon cancellation

Hugo Beauzée-Luyssen (@chouquette) gitlab at videolan.org
Thu Sep 2 15:27:35 UTC 2021



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


Commits:
063c45a8 by Hugo Beauzée-Luyssen at 2021-09-02T15:14:31+00:00
input: thumbnailer: Invoke completion callback upon cancellation

This matches the documented libvlc behavior.
Refs #26053

- - - - -
6a81d000 by Hugo Beauzée-Luyssen at 2021-09-02T15:14:31+00:00
test: thumbnail: Fix use of uninitialized value

This was most likely causing the test to sporadically succeed, while it
should have always fail as it was waiting for a callback that was never
invoked.
Fix #26053

- - - - -


3 changed files:

- include/vlc_thumbnailer.h
- src/input/thumbnailer.c
- test/src/input/thumbnail.c


Changes:

=====================================
include/vlc_thumbnailer.h
=====================================
@@ -117,7 +117,7 @@ vlc_thumbnailer_RequestByPos( vlc_thumbnailer_t *thumbnailer,
  * \param thumbnailer A thumbnailer object
  * \param request An opaque thumbnail request object
  *
- * Cancelling a request will *not* invoke the completion callback.
+ * Cancelling a request will invoke the completion callback with a NULL picture
  * The behavior is undefined if the request is cancelled after its completion.
  */
 VLC_API void


=====================================
src/input/thumbnailer.c
=====================================
@@ -73,6 +73,7 @@ struct vlc_thumbnailer_request_t
     vlc_mutex_t lock;
     vlc_cond_t cond_ended;
     bool ended;
+    picture_t *pic;
 
     struct vlc_runnable runnable; /**< to be passed to the executor */
 
@@ -101,6 +102,7 @@ TaskNew(vlc_thumbnailer_t *thumbnailer, input_item_t *item,
     vlc_mutex_init(&task->lock);
     vlc_cond_init(&task->cond_ended);
     task->ended = false;
+    task->pic = NULL;
 
     task->runnable.run = RunnableRun;
     task->runnable.userdata = task;
@@ -137,6 +139,8 @@ static void NotifyThumbnail(task_t *task, picture_t *pic)
 {
     assert(task->cb);
     task->cb(task->userdata, pic);
+    if (pic)
+        picture_Release(pic);
 }
 
 static void
@@ -162,13 +166,12 @@ on_thumbnailer_input_event( input_thread_t *input,
     }
 
     task->ended = true;
-    vlc_mutex_unlock(&task->lock);
 
-    picture_t *pic = NULL;
     if (event->type == INPUT_EVENT_THUMBNAIL_READY)
-        pic = event->thumbnail;
+        task->pic = picture_Hold(event->thumbnail);
+
+    vlc_mutex_unlock(&task->lock);
 
-    NotifyThumbnail(task, pic);
     vlc_cond_signal(&task->cond_ended);
 }
 
@@ -215,8 +218,12 @@ RunnableRun(void *userdata)
             timeout =
                 vlc_cond_timedwait(&task->cond_ended, &task->lock, deadline);
     }
+    picture_t* pic = task->pic;
+    task->pic = NULL;
     vlc_mutex_unlock(&task->lock);
 
+    NotifyThumbnail(task, pic);
+
     input_Stop(input);
     input_Close(input);
 


=====================================
test/src/input/thumbnail.c
=====================================
@@ -181,6 +181,7 @@ static void test_cancel_thumbnail( libvlc_instance_t* p_vlc )
     assert( p_thumbnailer != NULL );
 
     struct test_ctx ctx;
+    ctx.b_done = false;
     vlc_cond_init( &ctx.cond );
     vlc_mutex_init( &ctx.lock );
 



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/3895e912bffaed9f99a5f657272f307f2251791d...6a81d00090386b6a337f8c46814aa3f6d9eb503d

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/3895e912bffaed9f99a5f657272f307f2251791d...6a81d00090386b6a337f8c46814aa3f6d9eb503d
You're receiving this email because of your account on code.videolan.org.




More information about the vlc-commits mailing list