Skip to content

Commit dae0f19

Browse files
Merge pull request #96 from alexmercerind/windows-texture-migration
Using flutter::TextureRegistrar for Video on Windows.
2 parents cfc8f0d + 5ae9dc2 commit dae0f19

22 files changed

+363
-183
lines changed

.github/FUNDING.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
ko_fi: 'alexmercerind'
21
custom: ['https://www.buymeacoffee.com/alexmercerind']

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## 0.1.2
2+
3+
- Now using `flutter::TextureRegistrar` for performant `Video` on Windows. (#54).
4+
- Fixed `autoStart` in `Player.open`.
5+
- Fixed other crashes for Windows.
6+
- Improved stability.
7+
18
## 0.1.1
29

310
- Fixed setState being called after dispose (#75) (Finally)

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -320,16 +320,16 @@ sudo dnf install vlc-devel
320320

321321
You can see an example project [here](https://github.com/alexmercerind/dart_vlc/blob/master/example/lib/main.dart).
322322

323-
Windows
324-
325323
![](https://github.com/alexmercerind/dart_vlc/blob/assets/dart_vlc_6.png?raw=true)
326324

325+
dart_vlc running on Ubuntu Linux.
327326

328327
## Workings
328+
329329
The repository contains a [C++ wrapper](https://github.com/alexmercerind/dart_vlc/tree/master/dartvlc) based on libVLC++. This makes handling of events and controls a lot easier & has additional features in it.
330330
I preferred to do majority of handling in C++ itself, thus Dart code is minimal & very slight mapping to it.
331331

332-
This project might seem like a Flutter plugin, but it is based on FFI instead. [Here](https://github.com/alexmercerind/dart_vlc/tree/master/ffi) are the FFI bindings to [C++ wrapper](https://github.com/alexmercerind/dart_vlc/tree/master/dartvlc), which are shared by all platforms & same can be used in Dart CLI apps aswell.
332+
This project might seem like a Flutter plugin, but it is based on FFI instead. [Here](https://github.com/alexmercerind/dart_vlc/tree/master/ffi) are the FFI bindings to [C++ wrapper](https://github.com/alexmercerind/dart_vlc/tree/master/dartvlc), which are shared by all platforms & same can be used in Dart CLI apps aswell. Platform channel interface is only used for [flutter]
333333

334334
## Progress
335335

@@ -379,6 +379,8 @@ Done
379379
Under progress or planned features (irrespective of order)...
380380

381381
- Removing [libVLC++](https://github.com/videolan/libvlcpp) dependency. (Maybe).
382+
- Subtitle control.
383+
- Audio track control.
382384
- Writing metadata tags.
383385
- Making things more efficient.
384386
- Supporting native volume control/lock screen notifications (Maybe).
@@ -389,9 +391,9 @@ Under progress or planned features (irrespective of order)...
389391

390392
First of all, thanks to the [VideoLAN](https://www.videolan.org) team for creating [libVLC](https://github.com/videolan/vlc) & [libVLC++](https://github.com/videolan/libvlcpp). Really great guys really great at their work.
391393

392-
Massive thanks to [@stuartmorgan](https://github.com/stuartmorgan) from [Flutter](https://flutter.dev) team to my review code & help me fix the loopholes.
394+
[@jnschulze](https://github.com/jnschulze) for his awesome contributions to Flutter engine like adding texture support.
393395

394-
Thanks to following members of libVLC community to give me bit of look & advice about how things work:
396+
Thanks to following members of libVLC community (irrespective of the order) to give me bit of look & advice about how things work:
395397

396398
- [@jeremyVignelles](https://github.com/jeremyVignelles)
397399
- [@chouquette](https://github.com/chouquette)

dartvlc/internal/events.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class PlayerEvents : public PlayerGetters {
8686
);
8787
this->mediaPlayer.setVideoFormatCallbacks(
8888
[=](char* chroma, uint32_t* w, uint32_t* h, uint32_t* p, uint32_t* l) -> int {
89-
strcpy(chroma, "RV32");
89+
strcpy(chroma, "RGBA");
9090
*w = this->videoWidth;
9191
*h = this->videoHeight;
9292
*p = pitch;
@@ -95,7 +95,7 @@ class PlayerEvents : public PlayerGetters {
9595
},
9696
nullptr
9797
);
98-
this->mediaPlayer.setVideoFormat("RV32", this->videoWidth, this->videoHeight, pitch);
98+
this->mediaPlayer.setVideoFormat("RGBA", this->videoWidth, this->videoHeight, pitch);
9999
}
100100

101101
protected:

dartvlc/internal/setters.hpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ class PlayerSetters: public PlayerEvents {
1919
public:
2020
void open(MediaSource* mediaSource, bool autoStart = true) {
2121
/* Freed the previous `Media` objects when a new `Playlist` or `Media` is opened. */
22+
this->state->isStarted = false;
23+
this->stop();
2224
for (Media* media: this->state->medias->medias) {
2325
delete media;
2426
}
25-
this->stop();
2627
this->state->medias->medias = {};
2728
this->mediaList = VLC::MediaList(this->instance);
2829
if (mediaSource->mediaSourceType() == "MediaSourceType.media") {
@@ -46,14 +47,20 @@ class PlayerSetters: public PlayerEvents {
4647
this->state->isPlaylist = true;
4748
}
4849
this->_onOpenCallback(this->mediaList.itemAtIndex(0));
49-
this->mediaListPlayer.playItemAtIndex(0);
5050
this->state->index = 0;
5151
this->state->isPlaying = this->mediaListPlayer.isPlaying();
5252
this->state->isValid = this->mediaListPlayer.isValid();
53+
if (autoStart) this->play();
5354
}
5455

5556
void play() {
56-
this->mediaListPlayer.play();
57+
if (!this->state->isStarted) {
58+
this->mediaListPlayer.playItemAtIndex(0);
59+
this->state->isStarted = true;
60+
}
61+
else {
62+
this->mediaListPlayer.play();
63+
}
5764
}
5865

5966
void pause() {
@@ -63,7 +70,13 @@ class PlayerSetters: public PlayerEvents {
6370
}
6471

6572
void playOrPause() {
66-
this->mediaListPlayer.pause();
73+
if (!this->state->isStarted) {
74+
this->mediaListPlayer.playItemAtIndex(0);
75+
this->state->isStarted = true;
76+
}
77+
else {
78+
this->mediaListPlayer.pause();
79+
}
6780
}
6881

6982
void stop() {

dartvlc/internal/state.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ class PlayerState {
2828
float rate = 1.0;
2929
bool isPlaylist = false;
3030
Device* device = nullptr;
31+
/* NOTE: Used for autoStart. */
32+
bool isStarted = false;
3133
/* TODO: Not used yet.
3234
Equalizer* equalizer = nullptr;
3335
*/

dartvlc/player.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ class Player: public PlayerSetters {
6060
this->mediaPlayer.stop();
6161
delete this->state;
6262
delete this->_videoFrameBuffer;
63-
for (size_t i = 0; i < argsSize; i++) delete this->args[i];
6463
delete[] this->args;
6564
}
6665

@@ -81,6 +80,7 @@ class Players {
8180

8281
void dispose(int id, std::function<void()> callback = []() -> void {}) {
8382
delete this->players[id];
83+
this->players.erase(id);
8484
callback();
8585
}
8686

ffi/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.1.1
2+
3+
- Removed `Player::onVideo` callbacks for win32.
4+
15
## 0.1.0
26

37
- Added new native methods for handling with memory leaks.

ffi/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<h5 align="center">Written in C++ using libVLC & libVLC++.</h5>
44

55

6-
FFI bindings & NativePort event callback handling for `dart_vlc.so`.
6+
FFI bindings & NativePort event callback handling for `dart_vlc.dll`.
77

88
Dependency package for [dart_vlc](https:///github.com/alexmercerind/dart_vlc).
99

ffi/lib/src/player.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Map<int, Player> players = {};
3737
///
3838
class Player {
3939
/// Id associated with the [Player] instance.
40-
final int id;
40+
int id;
4141

4242
/// Width of the [Video] frames to be extracted. Higher value may lead to degraded performance.
4343
late int videoWidth;

0 commit comments

Comments
 (0)