From 70901d93f5b877c14b58d6d577d5000701e1ece5 Mon Sep 17 00:00:00 2001 From: alexmercerind Date: Mon, 23 Aug 2021 00:32:42 +0530 Subject: [PATCH] wrapper: expose libvlc_video_take_snapshot --- dartvlc/api/api.cc | 6 ++++++ dartvlc/api/api.h | 5 ++++- dartvlc/internal/setters.h | 4 ++++ ffi/lib/src/internal/ffi.dart | 4 ++++ ffi/lib/src/internal/typedefs/player.dart | 4 ++++ ffi/lib/src/player.dart | 6 ++++++ 6 files changed, 28 insertions(+), 1 deletion(-) diff --git a/dartvlc/api/api.cc b/dartvlc/api/api.cc index 49436ebe..3c4b7a0a 100644 --- a/dartvlc/api/api.cc +++ b/dartvlc/api/api.cc @@ -219,6 +219,12 @@ void PlayerMove(int32_t id, int32_t initial_index, int32_t final_index) { player->Move(initial_index, final_index); } +void PlayerTakeSnapshot(int32_t id, const char* file_path, int32_t width, + int32_t height) { + Player* player = g_players->Get(id); + player->TakeSnapshot(file_path, width, height); +} + void MediaClearMap(void*, void* peer) { delete reinterpret_cast*>(peer); } diff --git a/dartvlc/api/api.h b/dartvlc/api/api.h index 72d2f56a..7f0a75a9 100644 --- a/dartvlc/api/api.h +++ b/dartvlc/api/api.h @@ -88,6 +88,9 @@ DLLEXPORT void PlayerInsert(int32_t id, int32_t index, const char* type, DLLEXPORT void PlayerMove(int32_t id, int32_t initial_index, int32_t final_index); +DLLEXPORT void PlayerTakeSnapshot(int32_t id, const char* file_path, + int32_t width, int32_t height); + DLLEXPORT const char** MediaParse(Dart_Handle object, const char* type, const char* resource, int32_t timeout); @@ -120,7 +123,7 @@ DLLEXPORT DartDeviceList* DevicesAll(Dart_Handle object); DLLEXPORT struct DartEqualizer* EqualizerCreateEmpty(Dart_Handle object); DLLEXPORT struct DartEqualizer* EqualizerCreateMode(Dart_Handle object, - int32_t mode); + int32_t mode); DLLEXPORT void EqualizerSetBandAmp(int32_t id, float band, float amp); diff --git a/dartvlc/internal/setters.h b/dartvlc/internal/setters.h index 38e57b93..3d018473 100644 --- a/dartvlc/internal/setters.h +++ b/dartvlc/internal/setters.h @@ -197,6 +197,10 @@ class PlayerSetters : public PlayerEvents { OnPlaylistCallback(); } + void TakeSnapshot(std::string file_path, int32_t width, int32_t height) { + vlc_media_player_.takeSnapshot(0, file_path, width, height); + } + void SetVideoWidth(int32_t video_width) { preferred_video_width_ = video_width; } diff --git a/ffi/lib/src/internal/ffi.dart b/ffi/lib/src/internal/ffi.dart index 024b496d..56cb1633 100644 --- a/ffi/lib/src/internal/ffi.dart +++ b/ffi/lib/src/internal/ffi.dart @@ -100,6 +100,10 @@ abstract class PlayerFFI { static final PlayerMoveDart move = dynamicLibrary .lookup>('PlayerMove') .asFunction(); + + static final PlayerTakeSnapshotDart takeSnapshot = dynamicLibrary + .lookup>('PlayerTakeSnapshot') + .asFunction(); } abstract class MediaFFI { diff --git a/ffi/lib/src/internal/typedefs/player.dart b/ffi/lib/src/internal/typedefs/player.dart index c07daa68..2c140b45 100644 --- a/ffi/lib/src/internal/typedefs/player.dart +++ b/ffi/lib/src/internal/typedefs/player.dart @@ -54,3 +54,7 @@ typedef PlayerMoveCXX = Void Function( Int32 id, Int32 initialIndex, Int32 finalIndex); typedef PlayerMoveDart = void Function( int id, int initialIndex, int finalIndex); +typedef PlayerTakeSnapshotCXX = Void Function( + Int32 id, Pointer filePath, Int32 width, Int32 height); +typedef PlayerTakeSnapshotDart = void Function( + int id, Pointer filePath, int width, int height); diff --git a/ffi/lib/src/player.dart b/ffi/lib/src/player.dart index dafd1806..ce52fda8 100644 --- a/ffi/lib/src/player.dart +++ b/ffi/lib/src/player.dart @@ -1,3 +1,4 @@ +import 'dart:io'; import 'dart:async'; import 'package:ffi/ffi.dart'; import 'package:dart_vlc_ffi/dart_vlc_ffi.dart'; @@ -269,6 +270,11 @@ class Player { PlayerFFI.setEqualizer(this.id, equalizer.id); } + /// Saves snapshot of a video to a desired [File] location. + void takeSnapshot(File file, int width, int height) { + PlayerFFI.takeSnapshot(this.id, file.path.toNativeUtf8(), width, height); + } + /// Destroys the instance of [Player] & closes all [StreamController]s in it. void dispose() { this.currentController.close();