Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions media_kit_video/linux/gl_render_thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ void GLRenderThread::PostAndWait(std::function<void()> task) {
wait_cv.wait(lock, [&]() { return done; });
}

bool GLRenderThread::IsCurrentThread() const {
return std::this_thread::get_id() == thread_id_;
}

void GLRenderThread::Run() {
// Store thread ID
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,9 @@ class GLRenderThread {

// Post a task to the GL render thread
void Post(std::function<void()> task);

// Post a task and wait for completion (synchronous)
void PostAndWait(std::function<void()> task);

// Check if we're on the GL render thread
bool IsCurrentThread() const;

private:
void Run();
Expand Down
23 changes: 5 additions & 18 deletions media_kit_video/linux/include/media_kit_video/texture_gl.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,17 @@ G_DECLARE_FINAL_TYPE(TextureGL, texture_gl, TEXTURE_GL, TEXTURE_GL, FlTextureGL)

TextureGL* texture_gl_new(VideoOutput* video_output);

/**
* @brief Checks if texture needs resize and performs it if necessary.
* This manages the mailbox triple buffering - creates/resizes all three buffers.
*/
// Creates/resizes all three mailbox buffers if needed. GL thread only.
void texture_gl_check_and_resize(TextureGL* self, gint64 required_width, gint64 required_height);

/**
* @brief Renders mpv frame to the back buffer (called from dedicated GL thread).
* Uses mailbox model: renders to back buffer, then swaps with mailbox atomically.
* @return TRUE if rendering was performed, FALSE if skipped.
*/
// Renders an mpv frame to the back buffer. GL thread only.
// Returns TRUE if a frame was rendered.
gboolean texture_gl_render(TextureGL* self);

/**
* @brief Publishes the rendered frame using mailbox swap.
* Atomically swaps back buffer with mailbox, old mailbox content becomes new back buffer.
* Called from dedicated GL thread after render finishes.
*/
// Publishes the back buffer into the mailbox (dirty=1). GL thread only.
void texture_gl_swap_buffers(TextureGL* self);

/**
* @brief Populates texture with video frame using mailbox model.
* Atomically swaps front buffer with mailbox to get the latest frame.
*/
// Consumer side of the mailbox; called from Flutter's raster thread.
gboolean texture_gl_populate_texture(FlTextureGL* texture,
guint32* target,
guint32* name,
Expand Down
44 changes: 7 additions & 37 deletions media_kit_video/linux/include/media_kit_video/video_output.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,57 +47,30 @@ G_DECLARE_FINAL_TYPE(VideoOutput,
#define VIDEO_OUTPUT(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj), video_output_get_type(), VideoOutput))

/**
* @brief Creates a new |VideoOutput| instance for given |handle|.
*
* @param texture_registrar |FlTextureRegistrar| reference.
* @param view |FlView| reference.
* @param handle |mpv_handle| reference casted to gint64.
* @param configuration Video output configuration.
* @param gl_render_thread |GLRenderThread| reference for dedicated GL rendering.
* @return VideoOutput*
*/
// Creates a new |VideoOutput| for given |handle| (|mpv_handle| casted to
// gint64). Falls back to S/W rendering if no usable EGL display is found.
VideoOutput* video_output_new(FlTextureRegistrar* texture_registrar,
FlView* view,
gint64 handle,
VideoOutputConfiguration configuration,
GLRenderThread* gl_render_thread);

/**
* @brief Sets the callback invoked when the texture ID updates i.e. video
* dimensions changes.
*
* @param self |VideoOutput| reference.
* @param texture_update_callback Callback.
* @param texture_update_callback_context Callback context.
*/
// Sets the callback invoked when the texture ID updates i.e. video
// dimensions change.
void video_output_set_texture_update_callback(
VideoOutput* self,
TextureUpdateCallback texture_update_callback,
gpointer texture_update_callback_context);

/**
* @brief Sets the required video output size. This forces |VideoOutput| to
* resize the internal OpenGL surface / texture.
*
* @param texture_registrar |FlTextureRegistrar| reference.
* @param width Preferred width of the video. Pass `NULL` for using texture
* dimensions based on video's resolution.
* @param height Preferred height of the video. Pass `NULL` for using texture
* dimensions based on video's resolution.
*/
// Sets the required video output size. Pass 0 to size the texture based on
// the video's own resolution.
void video_output_set_size(VideoOutput* self, gint64 width, gint64 height);

mpv_render_context* video_output_get_render_context(VideoOutput* self);

GdkGLContext* video_output_get_gdk_gl_context(VideoOutput* self);

EGLDisplay video_output_get_egl_display(VideoOutput* self);

EGLContext video_output_get_egl_context(VideoOutput* self);

EGLSurface video_output_get_egl_surface(VideoOutput* self);

GLRenderThread* video_output_get_gl_render_thread(VideoOutput* self);

guint8* video_output_get_pixel_buffer(VideoOutput* self);
Expand All @@ -110,10 +83,7 @@ gint64 video_output_get_texture_id(VideoOutput* self);

void video_output_notify_texture_update(VideoOutput* self);

// Schedules resize-check + render on the dedicated GL thread.
void video_output_notify_render(VideoOutput* self);

void video_output_check_and_resize(VideoOutput* self);

void video_output_render(VideoOutput* self);

#endif // VIDEO_OUTPUT_H_
Original file line number Diff line number Diff line change
Expand Up @@ -26,51 +26,23 @@ G_DECLARE_FINAL_TYPE(VideoOutputManager,
VideoOutputManager))

VideoOutputManager* video_output_manager_new(
FlTextureRegistrar* texture_registrar,
FlView* view);
FlTextureRegistrar* texture_registrar);

/**
* @brief Creates a new |VideoOutput| instance for given |handle|.
*
* @param self |VideoOutputManager| reference.
* @param handle |mpv_handle| reference casted to gint64.
* @param width Preferred width of the video. Pass `NULL` for using texture
* dimensions based on video's resolution.
* @param height Preferred height of the video. Pass `NULL` for using texture
* dimensions based on video's resolution.
* @param enable_hardware_acceleration Whether to enable hardware acceleration.
* @param texture_update_callback Callback invoked when the texture ID updates
* i.e. video dimensions changes.
* @param texture_update_callback_context Context passed to
* |texture_update_callback|.
*/
// Creates a new |VideoOutput| instance for given |handle|.
void video_output_manager_create(VideoOutputManager* self,
gint64 handle,
VideoOutputConfiguration configuration,
TextureUpdateCallback texture_update_callback,
gpointer texture_update_callback_context);

/**
* @brief Sets the required video output size. This forces |VideoOutput| to
* resize the internal OpenGL surface / texture.
*
* @param texture_registrar |FlTextureRegistrar| reference.
* @param width Preferred width of the video. Pass `NULL` for using texture
* dimensions based on video's resolution.
* @param height Preferred height of the video. Pass `NULL` for using texture
* dimensions based on video's resolution.
*/
// Sets the required video output size. Pass 0 to size the texture based on
// the video's own resolution.
void video_output_manager_set_size(VideoOutputManager* self,
gint64 handle,
gint64 width,
gint64 height);

/**
* @brief Disposes |VideoOutput| instance for given |handle|.
*
* @param self |VideoOutputManager| reference.
* @param handle |mpv_handle| reference casted to gint64.
*/
// Disposes |VideoOutput| instance for given |handle|.
void video_output_manager_dispose(VideoOutputManager* self, gint64 handle);

#endif
7 changes: 3 additions & 4 deletions media_kit_video/linux/media_kit_video_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,9 @@ static MediaKitVideoPlugin* media_kit_video_plugin_new(
g_object_unref);
FlTextureRegistrar* texture_registrar =
fl_plugin_registrar_get_texture_registrar(registrar);
FlView* view = fl_plugin_registrar_get_view(registrar);
self->view = view;
self->video_output_manager =
video_output_manager_new(texture_registrar, view);
// |view| is only needed for native fullscreen handling.
self->view = fl_plugin_registrar_get_view(registrar);
self->video_output_manager = video_output_manager_new(texture_registrar);
return self;
}

Expand Down
Loading
Loading