Skip to content

Commit

Permalink
Merge pull request #129 from alexmercerind/take-snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmercerind authored Aug 22, 2021
2 parents 822bb3b + 70901d9 commit b7a793c
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 1 deletion.
6 changes: 6 additions & 0 deletions dartvlc/api/api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::map<std::string, std::string>*>(peer);
}
Expand Down
5 changes: 4 additions & 1 deletion dartvlc/api/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
4 changes: 4 additions & 0 deletions dartvlc/internal/setters.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 4 additions & 0 deletions ffi/lib/src/internal/ffi.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ abstract class PlayerFFI {
static final PlayerMoveDart move = dynamicLibrary
.lookup<NativeFunction<PlayerMoveCXX>>('PlayerMove')
.asFunction();

static final PlayerTakeSnapshotDart takeSnapshot = dynamicLibrary
.lookup<NativeFunction<PlayerTakeSnapshotCXX>>('PlayerTakeSnapshot')
.asFunction();
}

abstract class MediaFFI {
Expand Down
4 changes: 4 additions & 0 deletions ffi/lib/src/internal/typedefs/player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<Utf8> filePath, Int32 width, Int32 height);
typedef PlayerTakeSnapshotDart = void Function(
int id, Pointer<Utf8> filePath, int width, int height);
6 changes: 6 additions & 0 deletions ffi/lib/src/player.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dart:io';
import 'dart:async';
import 'package:ffi/ffi.dart';
import 'package:dart_vlc_ffi/dart_vlc_ffi.dart';
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit b7a793c

Please sign in to comment.