Skip to content

Commit 70901d9

Browse files
committed
wrapper: expose libvlc_video_take_snapshot
1 parent 822bb3b commit 70901d9

File tree

6 files changed

+28
-1
lines changed

6 files changed

+28
-1
lines changed

dartvlc/api/api.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,12 @@ void PlayerMove(int32_t id, int32_t initial_index, int32_t final_index) {
219219
player->Move(initial_index, final_index);
220220
}
221221

222+
void PlayerTakeSnapshot(int32_t id, const char* file_path, int32_t width,
223+
int32_t height) {
224+
Player* player = g_players->Get(id);
225+
player->TakeSnapshot(file_path, width, height);
226+
}
227+
222228
void MediaClearMap(void*, void* peer) {
223229
delete reinterpret_cast<std::map<std::string, std::string>*>(peer);
224230
}

dartvlc/api/api.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ DLLEXPORT void PlayerInsert(int32_t id, int32_t index, const char* type,
8888
DLLEXPORT void PlayerMove(int32_t id, int32_t initial_index,
8989
int32_t final_index);
9090

91+
DLLEXPORT void PlayerTakeSnapshot(int32_t id, const char* file_path,
92+
int32_t width, int32_t height);
93+
9194
DLLEXPORT const char** MediaParse(Dart_Handle object, const char* type,
9295
const char* resource, int32_t timeout);
9396

@@ -120,7 +123,7 @@ DLLEXPORT DartDeviceList* DevicesAll(Dart_Handle object);
120123
DLLEXPORT struct DartEqualizer* EqualizerCreateEmpty(Dart_Handle object);
121124

122125
DLLEXPORT struct DartEqualizer* EqualizerCreateMode(Dart_Handle object,
123-
int32_t mode);
126+
int32_t mode);
124127

125128
DLLEXPORT void EqualizerSetBandAmp(int32_t id, float band, float amp);
126129

dartvlc/internal/setters.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,10 @@ class PlayerSetters : public PlayerEvents {
197197
OnPlaylistCallback();
198198
}
199199

200+
void TakeSnapshot(std::string file_path, int32_t width, int32_t height) {
201+
vlc_media_player_.takeSnapshot(0, file_path, width, height);
202+
}
203+
200204
void SetVideoWidth(int32_t video_width) {
201205
preferred_video_width_ = video_width;
202206
}

ffi/lib/src/internal/ffi.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ abstract class PlayerFFI {
100100
static final PlayerMoveDart move = dynamicLibrary
101101
.lookup<NativeFunction<PlayerMoveCXX>>('PlayerMove')
102102
.asFunction();
103+
104+
static final PlayerTakeSnapshotDart takeSnapshot = dynamicLibrary
105+
.lookup<NativeFunction<PlayerTakeSnapshotCXX>>('PlayerTakeSnapshot')
106+
.asFunction();
103107
}
104108

105109
abstract class MediaFFI {

ffi/lib/src/internal/typedefs/player.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,7 @@ typedef PlayerMoveCXX = Void Function(
5454
Int32 id, Int32 initialIndex, Int32 finalIndex);
5555
typedef PlayerMoveDart = void Function(
5656
int id, int initialIndex, int finalIndex);
57+
typedef PlayerTakeSnapshotCXX = Void Function(
58+
Int32 id, Pointer<Utf8> filePath, Int32 width, Int32 height);
59+
typedef PlayerTakeSnapshotDart = void Function(
60+
int id, Pointer<Utf8> filePath, int width, int height);

ffi/lib/src/player.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'dart:io';
12
import 'dart:async';
23
import 'package:ffi/ffi.dart';
34
import 'package:dart_vlc_ffi/dart_vlc_ffi.dart';
@@ -269,6 +270,11 @@ class Player {
269270
PlayerFFI.setEqualizer(this.id, equalizer.id);
270271
}
271272

273+
/// Saves snapshot of a video to a desired [File] location.
274+
void takeSnapshot(File file, int width, int height) {
275+
PlayerFFI.takeSnapshot(this.id, file.path.toNativeUtf8(), width, height);
276+
}
277+
272278
/// Destroys the instance of [Player] & closes all [StreamController]s in it.
273279
void dispose() {
274280
this.currentController.close();

0 commit comments

Comments
 (0)