Files
plezy/windows/runner/mpv/mpv_plugin.h
T

80 lines
2.8 KiB
C++
Raw Normal View History

2025-12-01 15:30:28 +01:00
#ifndef MPV_PLUGIN_H_
#define MPV_PLUGIN_H_
#include <flutter/encodable_value.h>
#include <flutter/event_channel.h>
#include <flutter/event_stream_handler_functions.h>
#include <flutter/method_channel.h>
#include <flutter/plugin_registrar_windows.h>
#include <flutter/standard_method_codec.h>
#include <atomic>
#include <cstdint>
2026-05-03 08:23:44 +02:00
#include <functional>
2025-12-01 15:30:28 +01:00
#include <memory>
2026-05-03 08:23:44 +02:00
#include <mutex>
2025-12-01 15:30:28 +01:00
#include <optional>
2026-05-03 08:23:44 +02:00
#include <queue>
#include <string>
2025-12-01 15:30:28 +01:00
#include "display_mode_manager.h"
2025-12-01 15:30:28 +01:00
#include "mpv_player.h"
// C-style registration functions for the video and audio-only plugin
// instances.
2026-05-01 05:47:13 +02:00
void MpvPlayerPluginRegisterWithRegistrar(FlutterDesktopPluginRegistrarRef registrar);
void MpvAudioPlayerPluginRegisterWithRegistrar(FlutterDesktopPluginRegistrarRef registrar);
2025-12-01 15:30:28 +01:00
namespace mpv {
class MpvPlayerPlugin : public flutter::Plugin {
public:
// |channel_name| is the method channel name; the event channel is
// |channel_name| + "/events". |audio_only| runs a windowless music core:
// no child HWND, no display-mode handling (see MpvPlayer).
static void RegisterWithRegistrar(
flutter::PluginRegistrarWindows* registrar, const std::string& channel_name = "com.plezy/mpv_player",
bool audio_only = false);
2025-12-01 15:30:28 +01:00
MpvPlayerPlugin(
flutter::PluginRegistrarWindows* registrar, const std::string& channel_name = "com.plezy/mpv_player",
bool audio_only = false);
2025-12-01 15:30:28 +01:00
virtual ~MpvPlayerPlugin();
private:
void HandleMethodCall(
const flutter::MethodCall<flutter::EncodableValue>& method_call,
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result);
void SendEvent(uint64_t player_generation, const flutter::EncodableValue& event);
2026-05-03 08:23:44 +02:00
void PostToPlatformThread(std::function<void()> task);
void DrainPlatformTasks();
2025-12-01 15:30:28 +01:00
HWND GetWindow();
HWND GetChildWindow();
flutter::PluginRegistrarWindows* registrar_;
2026-05-03 08:23:44 +02:00
DWORD platform_thread_id_;
const bool audio_only_;
// Per-instance wakeup message: the first window-proc delegate that handles
// a message consumes it, so the video and audio instances must not share
// one message id or one instance's wakeup would strand the other's queue.
const UINT platform_task_message_;
2026-05-03 08:23:44 +02:00
HWND flutter_window_ = nullptr;
2026-05-01 05:47:13 +02:00
std::unique_ptr<flutter::MethodChannel<flutter::EncodableValue>> method_channel_;
std::unique_ptr<flutter::EventChannel<flutter::EncodableValue>> event_channel_;
2025-12-01 15:30:28 +01:00
std::unique_ptr<flutter::EventSink<flutter::EncodableValue>> event_sink_;
std::unique_ptr<MpvPlayer> player_;
std::atomic<uint64_t> player_generation_{0};
DisplayModeManager display_mode_manager_;
2025-12-01 15:30:28 +01:00
std::optional<int32_t> proc_id_;
2026-05-03 08:23:44 +02:00
std::mutex platform_tasks_mutex_;
std::queue<std::function<void()>> platform_tasks_;
bool wakeup_posted_ = false; // guarded by platform_tasks_mutex_
2025-12-01 15:30:28 +01:00
};
} // namespace mpv
#endif // MPV_PLUGIN_H_