[vlc-commits] [Git][videolan/vlc][master] 2 commits: lib/media: track instance in thumbnail request

Rémi Denis-Courmont (@Courmisch) gitlab at videolan.org
Fri Jun 17 10:46:28 UTC 2022



Rémi Denis-Courmont pushed to branch master at VideoLAN / VLC


Commits:
8bb3e3d4 by Rémi Denis-Courmont at 2022-06-17T10:30:35+00:00
lib/media: track instance in thumbnail request

- - - - -
cd05f2ff by Rémi Denis-Courmont at 2022-06-17T10:30:35+00:00
lib/media: pass explicit instance to generate thumbnail

- - - - -


3 changed files:

- doc/libvlc/vlc-thumb.c
- include/vlc/libvlc_media.h
- lib/media.c


Changes:

=====================================
doc/libvlc/vlc-thumb.c
=====================================
@@ -128,7 +128,8 @@ static void callback(const libvlc_event_t *ev, void *param)
 
 #define VLC_THUMBNAIL_TIMEOUT   5 /* 5 secs */
 
-static void snapshot(libvlc_media_t *m, int width, char *out_with_ext)
+static void snapshot(libvlc_instance_t *vlc, libvlc_media_t *m,
+                     int width, char *out_with_ext)
 {
     libvlc_event_manager_t *em = libvlc_media_event_manager(m);
     assert(em);
@@ -137,7 +138,8 @@ static void snapshot(libvlc_media_t *m, int width, char *out_with_ext)
     libvlc_event_attach(em, libvlc_MediaThumbnailGenerated, callback, &pic);
     done = false;
     libvlc_media_thumbnail_request_t* req =
-            libvlc_media_thumbnail_request_by_pos(m, VLC_THUMBNAIL_POSITION,
+            libvlc_media_thumbnail_request_by_pos(vlc, m,
+                                          VLC_THUMBNAIL_POSITION,
                                           libvlc_media_thumbnail_seek_fast,
                                           width, 0, false, libvlc_picture_Png,
                                           VLC_THUMBNAIL_TIMEOUT * 1000);
@@ -191,7 +193,7 @@ int main(int argc, const char **argv)
     assert(m);
 
     /* takes snapshot */
-    snapshot(m, width, out_with_ext);
+    snapshot(libvlc, m, width, out_with_ext);
 
     /* clean up */
     if (out != out_with_ext) {


=====================================
include/vlc/libvlc_media.h
=====================================
@@ -726,6 +726,7 @@ typedef enum libvlc_thumbnailer_seek_speed_t
  * - Derived from the media aspect ratio if only width or height is provided and
  *   the other one is set to 0.
  *
+ * \param inst LibVLC instance to generate the thumbnail with
  * \param md media descriptor object
  * \param time The time at which the thumbnail should be generated
  * \param speed The seeking speed \sa{libvlc_thumbnailer_seek_speed_t}
@@ -745,8 +746,8 @@ typedef enum libvlc_thumbnailer_seek_speed_t
  * \see libvlc_picture_type_t
  */
 LIBVLC_API libvlc_media_thumbnail_request_t*
-libvlc_media_thumbnail_request_by_time( libvlc_media_t *md,
-                                        libvlc_time_t time,
+libvlc_media_thumbnail_request_by_time( libvlc_instance_t *inst,
+                                        libvlc_media_t *md, libvlc_time_t time,
                                         libvlc_thumbnailer_seek_speed_t speed,
                                         unsigned int width, unsigned int height,
                                         bool crop, libvlc_picture_type_t picture_type,
@@ -763,6 +764,7 @@ libvlc_media_thumbnail_request_by_time( libvlc_media_t *md,
  * - Derived from the media aspect ratio if only width or height is provided and
  *   the other one is set to 0.
  *
+ * \param inst LibVLC instance to generate the thumbnail with
  * \param md media descriptor object
  * \param pos The position at which the thumbnail should be generated
  * \param speed The seeking speed \sa{libvlc_thumbnailer_seek_speed_t}
@@ -782,8 +784,8 @@ libvlc_media_thumbnail_request_by_time( libvlc_media_t *md,
  * \see libvlc_picture_type_t
  */
 LIBVLC_API libvlc_media_thumbnail_request_t*
-libvlc_media_thumbnail_request_by_pos( libvlc_media_t *md,
-                                       float pos,
+libvlc_media_thumbnail_request_by_pos( libvlc_instance_t *inst,
+                                       libvlc_media_t *md, float pos,
                                        libvlc_thumbnailer_seek_speed_t speed,
                                        unsigned int width, unsigned int height,
                                        bool crop, libvlc_picture_type_t picture_type,


=====================================
lib/media.c
=====================================
@@ -1101,6 +1101,7 @@ libvlc_media_type_t libvlc_media_get_type( libvlc_media_t *p_md )
 
 struct libvlc_media_thumbnail_request_t
 {
+    libvlc_instance_t *instance;
     libvlc_media_t *md;
     unsigned int width;
     unsigned int height;
@@ -1117,7 +1118,7 @@ static void media_on_thumbnail_ready( void* data, picture_t* thumbnail )
     event.type = libvlc_MediaThumbnailGenerated;
     libvlc_picture_t* pic = NULL;
     if ( thumbnail != NULL )
-        pic = libvlc_picture_new( VLC_OBJECT(p_media->p_libvlc_instance->p_libvlc_int),
+        pic = libvlc_picture_new( VLC_OBJECT(req->instance->p_libvlc_int),
                                     thumbnail, req->type, req->width, req->height,
                                     req->crop );
     event.u.media_thumbnail_generated.p_thumbnail = pic;
@@ -1128,20 +1129,24 @@ static void media_on_thumbnail_ready( void* data, picture_t* thumbnail )
 
 // Start an asynchronous thumbnail generation
 libvlc_media_thumbnail_request_t*
-libvlc_media_thumbnail_request_by_time( libvlc_media_t *md, libvlc_time_t time,
+libvlc_media_thumbnail_request_by_time( libvlc_instance_t *inst,
+                                        libvlc_media_t *md, libvlc_time_t time,
                                         libvlc_thumbnailer_seek_speed_t speed,
                                         unsigned int width, unsigned int height,
                                         bool crop, libvlc_picture_type_t picture_type,
                                         libvlc_time_t timeout )
 {
     assert( md );
-    libvlc_priv_t *p_priv = libvlc_priv(md->p_libvlc_instance->p_libvlc_int);
+
+    libvlc_priv_t *p_priv = libvlc_priv(inst->p_libvlc_int);
     if( unlikely( p_priv->p_thumbnailer == NULL ) )
         return NULL;
+
     libvlc_media_thumbnail_request_t *req = malloc( sizeof( *req ) );
     if ( unlikely( req == NULL ) )
         return NULL;
 
+    req->instance = inst;
     req->md = md;
     req->width = width;
     req->height = height;
@@ -1161,25 +1166,30 @@ libvlc_media_thumbnail_request_by_time( libvlc_media_t *md, libvlc_time_t time,
         libvlc_media_release( md );
         return NULL;
     }
+    libvlc_retain(inst);
     return req;
 }
 
 // Start an asynchronous thumbnail generation
 libvlc_media_thumbnail_request_t*
-libvlc_media_thumbnail_request_by_pos( libvlc_media_t *md, float pos,
+libvlc_media_thumbnail_request_by_pos( libvlc_instance_t *inst,
+                                       libvlc_media_t *md, float pos,
                                        libvlc_thumbnailer_seek_speed_t speed,
                                        unsigned int width, unsigned int height,
                                        bool crop, libvlc_picture_type_t picture_type,
                                        libvlc_time_t timeout )
 {
     assert( md );
-    libvlc_priv_t *priv = libvlc_priv(md->p_libvlc_instance->p_libvlc_int);
+
+    libvlc_priv_t *priv = libvlc_priv(inst->p_libvlc_int);
     if( unlikely( priv->p_thumbnailer == NULL ) )
         return NULL;
+
     libvlc_media_thumbnail_request_t *req = malloc( sizeof( *req ) );
     if ( unlikely( req == NULL ) )
         return NULL;
 
+    req->instance = inst;
     req->md = md;
     req->width = width;
     req->height = height;
@@ -1198,13 +1208,14 @@ libvlc_media_thumbnail_request_by_pos( libvlc_media_t *md, float pos,
         libvlc_media_release( md );
         return NULL;
     }
+    libvlc_retain(inst);
     return req;
 }
 
 // Cancel a thumbnail request
 void libvlc_media_thumbnail_request_cancel( libvlc_media_thumbnail_request_t *req )
 {
-    libvlc_priv_t *p_priv = libvlc_priv(req->md->p_libvlc_instance->p_libvlc_int);
+    libvlc_priv_t *p_priv = libvlc_priv(req->instance->p_libvlc_int);
     assert( p_priv->p_thumbnailer != NULL );
     vlc_thumbnailer_Cancel( p_priv->p_thumbnailer, req->req );
 }
@@ -1213,6 +1224,7 @@ void libvlc_media_thumbnail_request_cancel( libvlc_media_thumbnail_request_t *re
 void libvlc_media_thumbnail_request_destroy( libvlc_media_thumbnail_request_t *req )
 {
     libvlc_media_release( req->md );
+    libvlc_release(req->instance);
     free( req );
 }
 



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/0d8012dd0c4498cc2d39abcded8c67491f704755...cd05f2ff55207517b74bd35376ffeb7bfb2c53b0

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


VideoLAN code repository instance


More information about the vlc-commits mailing list