[vlc-commits] [Git][videolan/vlc][master] 3 commits: doc: thumbnailer: Remove deprecated options

Hugo Beauzée-Luyssen (@chouquette) gitlab at videolan.org
Thu Dec 2 14:17:18 UTC 2021



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


Commits:
33949648 by Hugo Beauzée-Luyssen at 2021-12-02T12:40:22+00:00
doc: thumbnailer: Remove deprecated options

- - - - -
d3be66ed by Hugo Beauzée-Luyssen at 2021-12-02T12:40:22+00:00
doc: vlc-thumb: Remove trailing whitespace

- - - - -
e56d9673 by Hugo Beauzée-Luyssen at 2021-12-02T12:40:22+00:00
doc: thumbnailer: Use new media thumbnailer API

- - - - -


1 changed file:

- doc/libvlc/vlc-thumb.c


Changes:

=====================================
doc/libvlc/vlc-thumb.c
=====================================
@@ -12,7 +12,7 @@
   list=`grep ^Mime vlc.desktop|cut -d= -f2-|sed -e s/";"/\\\n/g -e s,/,@,g`
   vid=`echo $mimes|grep ^vid`
   for i in $vid
-  do 
+  do
     key=/desktop/gnome/thumbnailers/$i/enable
     gconftool-2 -t boolean -s $key true
     gconftool-2 -t string  -s $key "vlc-thumb -s %s %u %o"
@@ -99,8 +99,6 @@ static libvlc_instance_t *create_libvlc(void)
         "--no-video-title-show",            /* nor the filename displayed     */
         "--no-stats",                       /* no stats                       */
         "--no-sub-autodetect-file",         /* we don't want subtitles        */
-        "--no-inhibit",                     /* we don't want interfaces       */
-        "--no-disable-screensaver",         /* we don't want interfaces       */
         "--no-snapshot-preview",            /* no blending in dummy vout      */
 #ifndef NDEBUG
         "--verbose=2",                      /* full log                       */
@@ -116,69 +114,58 @@ static bool done;
 
 static void callback(const libvlc_event_t *ev, void *param)
 {
-    float new_position;
-    (void)param;
-
-    pthread_mutex_lock(&lock);
-    switch (ev->type) {
-    case libvlc_MediaPlayerPositionChanged:
-        new_position = ev->u.media_player_position_changed.new_position;
-        if (new_position < VLC_THUMBNAIL_POSITION * .9 /* 90% margin */)
-            break;
-    case libvlc_MediaPlayerSnapshotTaken:
+    if (ev->type == libvlc_MediaThumbnailGenerated)
+    {
+        libvlc_picture_t** pic = param;
+        pthread_mutex_lock(&lock);
+        libvlc_picture_retain(ev->u.media_thumbnail_generated.p_thumbnail);
+        *pic = ev->u.media_thumbnail_generated.p_thumbnail;
         done = true;
         pthread_cond_signal(&wait);
-        break;
-
-    default:
-        assert(0);
+        pthread_mutex_unlock(&lock);
     }
-    pthread_mutex_unlock(&lock);
 }
 
-static void event_wait(const char *error)
-{
-    int ret;
-    struct timespec ts;
 #define VLC_THUMBNAIL_TIMEOUT   5 /* 5 secs */
 
-    clock_gettime(CLOCK_MONOTONIC, &ts);
-    ts.tv_sec += VLC_THUMBNAIL_TIMEOUT;
-    pthread_mutex_lock(&lock);
-    ret = done ? 0 : pthread_cond_timedwait(&wait, &lock, &ts);
-    pthread_mutex_unlock(&lock);
-
-    assert(!ret || ret == ETIMEDOUT);
-
-    if (ret) {
-        fprintf(stderr,
-                "%s (timeout after %d secs!\n", error, VLC_THUMBNAIL_TIMEOUT);
-        exit(1);
-    }
-}
-
-static void set_position(libvlc_media_player_t *mp)
+static void snapshot(libvlc_media_t *m, int width, char *out_with_ext)
 {
-    libvlc_event_manager_t *em = libvlc_media_player_event_manager(mp);
+    libvlc_event_manager_t *em = libvlc_media_event_manager(m);
     assert(em);
 
-    libvlc_event_attach(em, libvlc_MediaPlayerPositionChanged, callback, NULL);
+    libvlc_picture_t* pic = NULL;
+    libvlc_event_attach(em, libvlc_MediaThumbnailGenerated, callback, &pic);
     done = false;
-    libvlc_media_player_set_position(mp, VLC_THUMBNAIL_POSITION);
-    event_wait("Couldn't set position");
-    libvlc_event_detach(em, libvlc_MediaPlayerPositionChanged, callback, NULL);
-}
-
-static void snapshot(libvlc_media_player_t *mp, int width, char *out_with_ext)
-{
-    libvlc_event_manager_t *em = libvlc_media_player_event_manager(mp);
-    assert(em);
+    libvlc_media_thumbnail_request_t* req =
+            libvlc_media_thumbnail_request_by_pos(m, VLC_THUMBNAIL_POSITION,
+                                          libvlc_media_thumbnail_seek_fast,
+                                          width, 0, false, libvlc_picture_Png,
+                                          VLC_THUMBNAIL_TIMEOUT * 1000);
+    if (!req)
+    {
+        fprintf(stderr, "Failed to request thumbnail\n");
+        exit(1);
+    }
+    pthread_mutex_lock(&lock);
+    while (!done)
+        pthread_cond_wait(&wait, &lock);
+    pthread_mutex_unlock(&lock);
+    libvlc_media_thumbnail_request_destroy(req);
+    libvlc_event_detach(em, libvlc_MediaThumbnailGenerated, callback, &pic);
 
-    libvlc_event_attach(em, libvlc_MediaPlayerSnapshotTaken, callback, NULL);
-    done = false;
-    libvlc_video_take_snapshot(mp, 0, out_with_ext, width, 0);
-    event_wait("Snapshot has not been written");
-    libvlc_event_detach(em, libvlc_MediaPlayerSnapshotTaken, callback, NULL);
+    if (!pic)
+    {
+        fprintf(stderr, "Snapshot has not been written (timeout after %d secs!\n",
+                VLC_THUMBNAIL_TIMEOUT);
+        exit(1);
+    }
+    int res = libvlc_picture_save(pic, out_with_ext);
+    libvlc_picture_release(pic);
+    if (res)
+    {
+        fprintf(stderr, "Failed to save the thumbnail\n");
+        exit(res);
+    }
 }
 
 int main(int argc, const char **argv)
@@ -186,9 +173,7 @@ int main(int argc, const char **argv)
     const char *in;
     char *out, *out_with_ext;
     int width;
-    pthread_condattr_t attr;
     libvlc_instance_t *libvlc;
-    libvlc_media_player_t *mp;
     libvlc_media_t *m;
 
     /* mandatory to support UTF-8 filenames (provided the locale is well set)*/
@@ -196,10 +181,7 @@ int main(int argc, const char **argv)
 
     cmdline(argc, argv, &in, &out, &out_with_ext, &width);
 
-    pthread_condattr_init(&attr);
-    pthread_condattr_setclock(&attr, CLOCK_MONOTONIC);
-    pthread_cond_init(&wait, &attr);
-    pthread_condattr_destroy(&attr);
+    pthread_cond_init(&wait, NULL);
 
     /* starts vlc */
     libvlc = create_libvlc();
@@ -208,16 +190,8 @@ int main(int argc, const char **argv)
     m = libvlc_media_new_path(libvlc, in);
     assert(m);
 
-    mp = libvlc_media_player_new_from_media(m);
-    assert(mp);
-
-    libvlc_media_player_play(mp);
-
     /* takes snapshot */
-    set_position(mp);
-    snapshot(mp, width, out_with_ext);
-
-    libvlc_media_player_stop_async(mp);
+    snapshot(m, width, out_with_ext);
 
     /* clean up */
     if (out != out_with_ext) {
@@ -226,7 +200,6 @@ int main(int argc, const char **argv)
     }
     free(out);
 
-    libvlc_media_player_release(mp);
     libvlc_media_release(m);
     libvlc_release(libvlc);
 



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/b287fd1abb5ce6752b13b84c16a7f18e62f63e59...e56d9673346fc5ae325bfdc7b665817e655eadf5

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




More information about the vlc-commits mailing list