11
11
12
12
#include " internal/getters.h"
13
13
14
- typedef std::function<void (uint8_t *, int32_t , int32_t )> VideoFrameCallback ;
14
+ using VideoFrameCallback = std::function<void (uint8_t *, int32_t , int32_t )>;
15
15
16
16
class PlayerEvents : public PlayerGetters {
17
17
public:
@@ -29,8 +29,53 @@ class PlayerEvents : public PlayerGetters {
29
29
30
30
void OnVideoDimensions (std::function<void (int32_t , int32_t )> callback) {
31
31
video_dimension_callback_ = callback;
32
- vlc_media_player_.eventManager ().onPlaying (
33
- std::bind (&PlayerEvents::OnVideoDimensionsCallback, this ));
32
+ vlc_media_player_.setVideoCallbacks (
33
+ std::bind (&PlayerEvents::OnVideoLockCallback, this ,
34
+ std::placeholders::_1),
35
+ nullptr , std::bind (&PlayerEvents::OnVideoPictureCallback, this ,
36
+ std::placeholders::_1));
37
+ vlc_media_player_.setVideoFormatCallbacks (
38
+ [=](char * chroma, uint32_t * w, uint32_t * h, uint32_t * p,
39
+ uint32_t * l) -> int32_t {
40
+ int32_t video_width = video_width_, video_height = video_height_,
41
+ pitch = video_width_ * 4 ;
42
+ if (video_height_ != static_cast <int32_t >(*h) ||
43
+ video_width_ != static_cast <int32_t >(*w)) {
44
+ video_height_ = static_cast <int32_t >(*h);
45
+ video_width_ = static_cast <int32_t >(*w);
46
+ video_dimension_callback_ (video_width_, video_height_);
47
+ if (preferred_video_width_.has_value () &&
48
+ preferred_video_height_.has_value ()) {
49
+ video_width = preferred_video_width_.value_or (0 );
50
+ video_height = preferred_video_height_.value_or (0 );
51
+ pitch = video_width_ * 4 ;
52
+ vlc_media_player_.setVideoFormat (" RGBA" , video_width,
53
+ video_height, pitch);
54
+ } else {
55
+ video_height = video_height_;
56
+ video_width = video_width_;
57
+ pitch = video_width_ * 4 ;
58
+ #ifndef __APPLE__
59
+ vlc_media_player_.setVideoFormat (" RGBA" , video_width,
60
+ video_height, pitch);
61
+ #else
62
+ vlc_media_player_.setVideoFormat (" RV32" , video_width,
63
+ video_height, pitch);
64
+ #endif
65
+ }
66
+ }
67
+ #ifndef __APPLE__
68
+ strncpy (chroma, " RGBA" , 4 );
69
+ #else
70
+ strncpy (chroma, " RV32" , 4 );
71
+ #endif
72
+ *w = video_width;
73
+ *h = video_height;
74
+ *p = pitch;
75
+ *l = video_height;
76
+ return 1 ;
77
+ },
78
+ nullptr );
34
79
}
35
80
36
81
void OnPause (std::function<void ()> callback) {
@@ -120,56 +165,56 @@ class PlayerEvents : public PlayerGetters {
120
165
std::function<void (int32_t , int32_t )> video_dimension_callback_ = [=](
121
166
int32_t , int32_t ) -> void {};
122
167
123
- void OnVideoDimensionsCallback () {
124
- int32_t video_width = 0 ;
125
- int32_t video_height = 0 ;
126
- if (preferred_video_width_.has_value () &&
127
- preferred_video_height_.has_value ()) {
128
- video_width = preferred_video_width_.value_or (0 );
129
- video_height = preferred_video_height_.value_or (0 );
130
- } else {
131
- uint32_t px = 0 , py = 0 ;
132
- libvlc_video_get_size (vlc_media_player_.get (), 0 , &px, &py);
133
- video_width = static_cast <int32_t >(px);
134
- video_height = static_cast <int32_t >(py);
135
- }
136
- video_dimension_callback_ (video_width, video_height);
137
- if (video_width_ != video_width || video_height_ != video_height) {
138
- video_width_ = video_width;
139
- video_height_ = video_height;
140
- int32_t pitch = video_width * 4 ;
141
- // https://github.com/alexmercerind/dart_vlc/pull/137
142
- // int32_t size = video_height * pitch;
143
- // video_frame_buffer_.reset(new uint8_t[size]);
144
- vlc_media_player_.setVideoCallbacks (
145
- std::bind (&PlayerEvents::OnVideoLockCallback, this ,
146
- std::placeholders::_1),
147
- nullptr , std::bind (&PlayerEvents::OnVideoPictureCallback, this ,
148
- std::placeholders::_1));
149
- vlc_media_player_.setVideoFormatCallbacks (
150
- [=](char * chroma, uint32_t * w, uint32_t * h, uint32_t * p,
151
- uint32_t * l) -> int32_t {
152
- #ifndef __APPLE__
153
- strncpy (chroma, " RGBA" , 4 );
154
- #else
155
- strncpy (chroma, " RV32" , 4 );
156
- #endif
157
- *w = video_width;
158
- *h = video_height;
159
- *p = pitch;
160
- *l = video_height;
161
- return 1 ;
162
- },
163
- nullptr );
164
- #ifndef __APPLE__
165
- vlc_media_player_.setVideoFormat (" RGBA" , video_width, video_height,
166
- pitch);
167
- #else
168
- vlc_media_player_.setVideoFormat (" RV32" , video_width, video_height,
169
- pitch);
170
- #endif
171
- }
172
- }
168
+ // void OnVideoDimensionsCallback() {
169
+ // int32_t video_width = 0;
170
+ // int32_t video_height = 0;
171
+ // if (preferred_video_width_.has_value() &&
172
+ // preferred_video_height_.has_value()) {
173
+ // video_width = preferred_video_width_.value_or(0);
174
+ // video_height = preferred_video_height_.value_or(0);
175
+ // } else {
176
+ // uint32_t px = 0, py = 0;
177
+ // libvlc_video_get_size(vlc_media_player_.get(), 0, &px, &py);
178
+ // video_width = static_cast<int32_t>(px);
179
+ // video_height = static_cast<int32_t>(py);
180
+ // }
181
+ // video_dimension_callback_(video_width, video_height);
182
+ // if (video_width_ != video_width || video_height_ != video_height) {
183
+ // video_width_ = video_width;
184
+ // video_height_ = video_height;
185
+ // int32_t pitch = video_width * 4;
186
+ // // https://github.com/alexmercerind/dart_vlc/pull/137
187
+ // // int32_t size = video_height * pitch;
188
+ // // video_frame_buffer_.reset(new uint8_t[size]);
189
+ // vlc_media_player_.setVideoCallbacks(
190
+ // std::bind(&PlayerEvents::OnVideoLockCallback, this,
191
+ // std::placeholders::_1),
192
+ // nullptr, std::bind(&PlayerEvents::OnVideoPictureCallback, this,
193
+ // std::placeholders::_1));
194
+ // vlc_media_player_.setVideoFormatCallbacks(
195
+ // [=](char* chroma, uint32_t* w, uint32_t* h, uint32_t* p,
196
+ // uint32_t* l) -> int32_t {
197
+ // #ifndef __APPLE__
198
+ // strncpy(chroma, "RGBA", 4);
199
+ // #else
200
+ // strncpy(chroma, "RV32", 4);
201
+ // #endif
202
+ // *w = video_width;
203
+ // *h = video_height;
204
+ // *p = pitch;
205
+ // *l = video_height;
206
+ // return 1;
207
+ // },
208
+ // nullptr);
209
+ // #ifndef __APPLE__
210
+ // vlc_media_player_.setVideoFormat("RGBA", video_width, video_height,
211
+ // pitch);
212
+ // #else
213
+ // vlc_media_player_.setVideoFormat("RV32", video_width, video_height,
214
+ // pitch);
215
+ // #endif
216
+ // }
217
+ // }
173
218
174
219
std::function<void ()> play_callback_ = [=]() -> void {};
175
220
@@ -259,7 +304,9 @@ class PlayerEvents : public PlayerGetters {
259
304
260
305
void OnVideoPictureCallback (void * picture) {
261
306
if (video_callback_) {
262
- video_callback_ (video_frame_buffer_.get (), video_width_, video_height_);
307
+ video_callback_ (video_frame_buffer_.get (),
308
+ preferred_video_width_.value_or (video_width_),
309
+ preferred_video_height_.value_or (video_height_));
263
310
}
264
311
}
265
312
};
0 commit comments