Skip to content

Commit 1fd62ad

Browse files
committed
video player: use playbin3 instead of uridecodebin
Use playbin3 for playback instead of uridecodebin. This also enables audio support. Furthermore, separate out the appsink (which uploads buffers into a flutter texture) into a separate "pseudo" gstreamer-element, which can be created using `flutter_gl_texture_sink_new`. Synchronization is reworked as well, it is now assumed the player is only accessed from a single thread, the platform thread. The callbacks called by gstreamer (which are called on internal threads) will rethread, if necessary, by posting messages to the GstBus. The buffering query is also now properly fixed. Previously it queried the playbin instead of the element that does the actual queueing (a `multiqueue`). Also, a one-shot debug logging message is added to the frame uploader, to inform the user when slower, manual dmabuf uploads are used instead of zero-copy.
1 parent 9a8689a commit 1fd62ad

File tree

6 files changed

+852
-816
lines changed

6 files changed

+852
-816
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ if (BUILD_GSTREAMER_VIDEO_PLAYER_PLUGIN)
335335
src/plugins/gstreamer_video_player/plugin.c
336336
src/plugins/gstreamer_video_player/player.c
337337
src/plugins/gstreamer_video_player/frame.c
338+
src/plugins/gstreamer_video_player/flutter_texture_sink.c
338339
)
339340
target_link_libraries(flutterpi_module PUBLIC
340341
PkgConfig::LIBGSTREAMER

src/plugins/gstreamer_video_player.h

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
#include "gles.h"
1515
#endif
1616

17+
#define GSTREAMER_VER(major, minor, patch) ((((major) &0xFF) << 16) | (((minor) &0xFF) << 8) | ((patch) &0xFF))
18+
#define THIS_GSTREAMER_VER GSTREAMER_VER(LIBGSTREAMER_VERSION_MAJOR, LIBGSTREAMER_VERSION_MINOR, LIBGSTREAMER_VERSION_PATCH)
19+
1720
enum format_hint { FORMAT_HINT_NONE, FORMAT_HINT_MPEG_DASH, FORMAT_HINT_HLS, FORMAT_HINT_SS, FORMAT_HINT_OTHER };
1821

1922
enum buffering_mode { BUFFERING_MODE_STREAM, BUFFERING_MODE_DOWNLOAD, BUFFERING_MODE_TIMESHIFT, BUFFERING_MODE_LIVE };
@@ -72,7 +75,7 @@ struct gstplayer *gstplayer_new_from_asset(struct flutterpi *flutterpi, const ch
7275
/// @arg uri The URI to the video. (for example, http://, https://, rtmp://, rtsp://)
7376
/// @arg format_hint A hint to the format of the video. FORMAT_HINT_NONE means there's no hint.
7477
/// @arg userdata The userdata associated with this player.
75-
struct gstplayer *gstplayer_new_from_network(struct flutterpi *flutterpi, const char *uri, enum format_hint format_hint, void *userdata);
78+
struct gstplayer *gstplayer_new_from_network(struct flutterpi *flutterpi, const char *uri, enum format_hint format_hint, void *userdata, GstStructure *headers);
7679

7780
/// Create a gstreamer video player that loads the video from a file URI.
7881
/// @arg uri The file:// URI to the video.
@@ -92,26 +95,20 @@ struct gstplayer *gstplayer_new_from_pipeline(struct flutterpi *flutterpi, const
9295
/// might be a race condition.
9396
void gstplayer_destroy(struct gstplayer *player);
9497

95-
DECLARE_LOCK_OPS(gstplayer)
96-
9798
/// Set the generic userdata associated with this gstreamer player instance.
9899
/// Overwrites the userdata set in the constructor and any userdata previously
99-
/// set using @ref gstplayer_set_userdata_locked.
100+
/// set using @ref gstplayer_set_userdata.
100101
/// @arg userdata The new userdata that should be associated with this player.
101-
void gstplayer_set_userdata_locked(struct gstplayer *player, void *userdata);
102+
void gstplayer_set_userdata(struct gstplayer *player, void *userdata);
102103

103104
/// Get the userdata that was given to the constructor or was previously set using
104-
/// @ref gstplayer_set_userdata_locked.
105+
/// @ref gstplayer_set_userdata.
105106
/// @returns userdata associated with this player.
106-
void *gstplayer_get_userdata_locked(struct gstplayer *player);
107+
void *gstplayer_get_userdata(struct gstplayer *player);
107108

108109
/// Get the id of the flutter external texture that this player is rendering into.
109110
int64_t gstplayer_get_texture_id(struct gstplayer *player);
110111

111-
//void gstplayer_set_info_callback(struct gstplayer *player, gstplayer_info_callback_t cb, void *userdata);
112-
113-
//void gstplayer_set_buffering_callback(struct gstplayer *player, gstplayer_buffering_callback_t callback, void *userdata);
114-
115112
/// Add a http header (consisting of a string key and value) to the list of http headers that
116113
/// gstreamer will use when playing back from a HTTP/S URI.
117114
/// This has no effect after @ref gstplayer_initialize was called.
@@ -122,12 +119,6 @@ void gstplayer_put_http_header(struct gstplayer *player, const char *key, const
122119
/// @returns 0 if initialization was successfull, errno-style error code if an error ocurred.
123120
int gstplayer_initialize(struct gstplayer *player);
124121

125-
/// Get the video info. If the video info (format, size, etc) is already known, @arg callback will be called
126-
/// synchronously, inside this call. If the video info is not known, @arg callback will be called on the flutter-pi
127-
/// platform thread as soon as the info is known.
128-
/// @returns The handle for the deferred callback.
129-
//struct sd_event_source_generic *gstplayer_probe_video_info(struct gstplayer *player, gstplayer_info_callback_t callback, void *userdata);
130-
131122
/// Set the current playback state to "playing" if that's not the case already.
132123
/// @returns 0 if initialization was successfull, errno-style error code if an error ocurred.
133124
int gstplayer_play(struct gstplayer *player);
@@ -164,6 +155,17 @@ int gstplayer_step_forward(struct gstplayer *player);
164155

165156
int gstplayer_step_backward(struct gstplayer *player);
166157

158+
struct video_info {
159+
int width, height;
160+
161+
double fps;
162+
163+
int64_t duration_ms;
164+
165+
bool can_seek;
166+
int64_t seek_begin_ms, seek_end_ms;
167+
};
168+
167169
/// @brief Get the value notifier for the video info.
168170
///
169171
/// Gets notified with a value of type `struct video_info*` when the video info changes.
@@ -212,19 +214,6 @@ DECLARE_REF_OPS(frame_interface)
212214
typedef struct _GstVideoInfo GstVideoInfo;
213215
typedef struct _GstVideoMeta GstVideoMeta;
214216

215-
struct video_info {
216-
int width, height;
217-
double fps;
218-
int64_t duration_ms;
219-
bool can_seek;
220-
int64_t seek_begin_ms, seek_end_ms;
221-
};
222-
223-
struct frame_info {
224-
const GstVideoInfo *gst_info;
225-
uint32_t drm_format;
226-
EGLint egl_color_space;
227-
};
228217

229218
struct _GstSample;
230219

@@ -238,4 +227,9 @@ struct gl_texture_frame;
238227

239228
const struct gl_texture_frame *frame_get_gl_frame(struct video_frame *frame);
240229

230+
struct texture;
231+
struct gl_renderer;
232+
typedef struct _GstElement GstElement;
233+
GstElement *flutter_gl_texture_sink_new(struct texture *texture, struct gl_renderer *renderer);
234+
241235
#endif

0 commit comments

Comments
 (0)