@@ -19,19 +19,25 @@ class PlayerEvents : public PlayerGetters {
19
19
std::bind (&PlayerEvents::OnOpenCallback, this , std::placeholders::_1));
20
20
}
21
21
22
- void OnPlay (std::function<void (void )> callback) {
22
+ void OnPlay (std::function<void ()> callback) {
23
23
play_callback_ = callback;
24
24
vlc_media_player_.eventManager ().onPlaying (
25
25
std::bind (&PlayerEvents::OnPlayCallback, this ));
26
26
}
27
27
28
- void OnPause (std::function<void (void )> callback) {
28
+ void OnVideoDimensions (std::function<void (int32_t , int32_t )> callback) {
29
+ video_dimension_callback_ = callback;
30
+ vlc_media_player_.eventManager ().onPlaying (
31
+ std::bind (&PlayerEvents::OnVideoDimensionsCallback, this ));
32
+ }
33
+
34
+ void OnPause (std::function<void ()> callback) {
29
35
pause_callback_ = callback;
30
36
vlc_media_player_.eventManager ().onPaused (
31
37
std::bind (&PlayerEvents::OnPauseCallback, this ));
32
38
}
33
39
34
- void OnStop (std::function<void (void )> callback) {
40
+ void OnStop (std::function<void ()> callback) {
35
41
stop_callback_ = callback;
36
42
vlc_media_player_.eventManager ().onStopped (
37
43
std::bind (&PlayerEvents::OnStopCallback, this ));
@@ -49,7 +55,7 @@ class PlayerEvents : public PlayerGetters {
49
55
&PlayerEvents::OnSeekableCallback, this , std::placeholders::_1));
50
56
}
51
57
52
- void OnComplete (std::function<void (void )> callback) {
58
+ void OnComplete (std::function<void ()> callback) {
53
59
complete_callback_ = callback;
54
60
vlc_media_player_.eventManager ().onEndReached (
55
61
std::bind (&PlayerEvents::OnCompleteCallback, this ));
@@ -63,37 +69,18 @@ class PlayerEvents : public PlayerGetters {
63
69
rate_callback_ = callback;
64
70
}
65
71
66
- void OnPlaylist (std::function<void (void )> callback) {
72
+ void OnPlaylist (std::function<void ()> callback) {
67
73
playlist_callback_ = callback;
68
74
}
69
75
70
- void OnVideo (std::function<void (uint8_t * frame)> callback) {
76
+ void OnVideo (
77
+ std::function<void (uint8_t * frame, int32_t width, int32_t height)>
78
+ callback) {
71
79
video_callback_ = callback;
72
- int32_t pitch = video_width_ * 4 ;
73
- int32_t size = video_height_ * pitch;
74
- video_frame_buffer_.reset (new uint8_t [size]);
75
- vlc_media_player_.setVideoCallbacks (
76
- std::bind (&PlayerEvents::OnVideoLockCallback, this ,
77
- std::placeholders::_1),
78
- nullptr , std::bind (&PlayerEvents::OnVideoPictureCallback, this ,
79
- std::placeholders::_1));
80
- vlc_media_player_.setVideoFormatCallbacks (
81
- [=](char * chroma, uint32_t * w, uint32_t * h, uint32_t * p,
82
- uint32_t * l) -> int32_t {
83
- strcpy (chroma, " RGBA" );
84
- *w = video_width_;
85
- *h = video_height_;
86
- *p = pitch;
87
- *l = video_height_;
88
- return 1 ;
89
- },
90
- nullptr );
91
- vlc_media_player_.setVideoFormat (" RGBA" , video_width_, video_height_,
92
- pitch);
93
80
}
94
81
95
82
protected:
96
- std::function<void (void )> playlist_callback_ = [=]() -> void {};
83
+ std::function<void ()> playlist_callback_ = [=]() -> void {};
97
84
98
85
void OnPlaylistCallback () {
99
86
if (is_playlist_modified_) {
@@ -110,10 +97,9 @@ class PlayerEvents : public PlayerGetters {
110
97
};
111
98
}
112
99
113
- std::function<void (VLC::Media)> open_callback_ = [=](
114
- VLC::Media media) -> void {};
100
+ std::function<void (VLC::Media)> open_callback_ = [=](VLC::Media) -> void {};
115
101
116
- void OnOpenCallback (VLC::MediaPtr media_ptr ) {
102
+ void OnOpenCallback (VLC::MediaPtr vlc_media_ptr ) {
117
103
state ()->is_playing_ = vlc_media_player_.isPlaying ();
118
104
state ()->is_valid_ = vlc_media_player_.isValid ();
119
105
if (duration () > 0 ) {
@@ -125,11 +111,51 @@ class PlayerEvents : public PlayerGetters {
125
111
state ()->position_ = 0 ;
126
112
state ()->duration_ = 0 ;
127
113
}
128
- state ()->index_ = vlc_media_list_.indexOfItem (*media_ptr.get ());
129
- open_callback_ (*media_ptr.get ());
114
+ state ()->index_ = vlc_media_list_.indexOfItem (*vlc_media_ptr.get ());
115
+ open_callback_ (*vlc_media_ptr.get ());
116
+ }
117
+
118
+ std::function<void (int32_t , int32_t )> video_dimension_callback_ =
119
+ [=](int32_t , int32_t ) -> void {};
120
+
121
+ void OnVideoDimensionsCallback () {
122
+ int32_t video_width = preferred_video_width_.has_value ()
123
+ ? preferred_video_width_.value ()
124
+ : libvlc_video_get_width (vlc_media_player_.get ());
125
+ int32_t video_height =
126
+ preferred_video_height_.has_value ()
127
+ ? preferred_video_height_.value ()
128
+ : libvlc_video_get_height (vlc_media_player_.get ());
129
+ video_dimension_callback_ (video_width, video_height);
130
+ if (video_width_ != video_width || video_height_ != video_height) {
131
+ video_width_ = video_width;
132
+ video_height_ = video_height;
133
+ int32_t pitch = video_width * 4 ;
134
+ int32_t size = video_height * pitch;
135
+ video_frame_buffer_.reset (new uint8_t [size]);
136
+ vlc_media_player_.setVideoCallbacks (
137
+ std::bind (&PlayerEvents::OnVideoLockCallback, this ,
138
+ std::placeholders::_1),
139
+ nullptr ,
140
+ std::bind (&PlayerEvents::OnVideoPictureCallback, this ,
141
+ std::placeholders::_1));
142
+ vlc_media_player_.setVideoFormatCallbacks (
143
+ [=](char * chroma, uint32_t * w, uint32_t * h, uint32_t * p,
144
+ uint32_t * l) -> int32_t {
145
+ strcpy (chroma, " RGBA" );
146
+ *w = video_width;
147
+ *h = video_height;
148
+ *p = pitch;
149
+ *l = video_height;
150
+ return 1 ;
151
+ },
152
+ nullptr );
153
+ vlc_media_player_.setVideoFormat (" RGBA" , video_width, video_height,
154
+ pitch);
155
+ }
130
156
}
131
157
132
- std::function<void (void )> play_callback_ = [=]() -> void {};
158
+ std::function<void ()> play_callback_ = [=]() -> void {};
133
159
134
160
void OnPlayCallback () {
135
161
state ()->is_playing_ = vlc_media_player_.isPlaying ();
@@ -142,7 +168,7 @@ class PlayerEvents : public PlayerGetters {
142
168
play_callback_ ();
143
169
}
144
170
145
- std::function<void (void )> pause_callback_ = [=]() -> void {};
171
+ std::function<void ()> pause_callback_ = [=]() -> void {};
146
172
147
173
void OnPauseCallback () {
148
174
state ()->is_playing_ = vlc_media_player_.isPlaying ();
@@ -154,7 +180,7 @@ class PlayerEvents : public PlayerGetters {
154
180
pause_callback_ ();
155
181
}
156
182
157
- std::function<void (void )> stop_callback_ = [=]() -> void {};
183
+ std::function<void ()> stop_callback_ = [=]() -> void {};
158
184
159
185
void OnStopCallback () {
160
186
state ()->is_playing_ = vlc_media_player_.isPlaying ();
@@ -164,8 +190,8 @@ class PlayerEvents : public PlayerGetters {
164
190
stop_callback_ ();
165
191
}
166
192
167
- std::function<void (int32_t )> position_callback_ = [=](
168
- int32_t position) -> void {};
193
+ std::function<void (int32_t )> position_callback_ =
194
+ [=]( int32_t position) -> void {};
169
195
170
196
void OnPositionCallback (float relative_position) {
171
197
state ()->is_playing_ = vlc_media_player_.isPlaying ();
@@ -178,8 +204,7 @@ class PlayerEvents : public PlayerGetters {
178
204
static_cast <int32_t >(relative_position * vlc_media_player_.length ()));
179
205
}
180
206
181
- std::function<void (bool )> seekable_callback_ = [=](bool isSeekable) -> void {
182
- };
207
+ std::function<void (bool )> seekable_callback_ = [=](bool ) -> void {};
183
208
184
209
void OnSeekableCallback (bool isSeekable) {
185
210
if (duration () > 0 ) {
@@ -188,7 +213,7 @@ class PlayerEvents : public PlayerGetters {
188
213
}
189
214
}
190
215
191
- std::function<void (void )> complete_callback_ = [=]() -> void {};
216
+ std::function<void ()> complete_callback_ = [=]() -> void {};
192
217
193
218
void OnCompleteCallback () {
194
219
state ()->is_playing_ = vlc_media_player_.isPlaying ();
@@ -205,19 +230,19 @@ class PlayerEvents : public PlayerGetters {
205
230
}
206
231
}
207
232
208
- std::function<void (float )> volume_callback_ = [=](float volume ) -> void {};
233
+ std::function<void (float )> volume_callback_ = [=](float ) -> void {};
209
234
210
- std::function<void (float )> rate_callback_ = [=](float rate ) -> void {};
235
+ std::function<void (float )> rate_callback_ = [=](float ) -> void {};
211
236
212
- std::function<void (uint8_t * frame )> video_callback_ = [=](
213
- uint8_t * frame ) -> void {};
237
+ std::function<void (uint8_t *, int32_t , int32_t )> video_callback_ =
238
+ [=]( uint8_t *, int32_t width, int32_t height ) -> void {};
214
239
215
240
void * OnVideoLockCallback (void ** planes) {
216
241
planes[0 ] = static_cast <void *>(video_frame_buffer_.get ());
217
242
return nullptr ;
218
243
}
219
244
220
245
void OnVideoPictureCallback (void * picture) {
221
- video_callback_ (static_cast < uint8_t *>( video_frame_buffer_.get ()) );
246
+ video_callback_ (video_frame_buffer_.get (), video_width_, video_height_ );
222
247
}
223
248
};
0 commit comments