fix: resolve UI freezes during video playback on Steam Deck
- Default MPV native log level to "warn" instead of "v" (Linux/Windows), add setLogLevel method channel to raise it when debug logging is enabled - Coalesce MPV render requests via atomic compare_exchange on needs_redraw_ - Clear redraw flag before render so new redraws queue during current frame
This commit is contained in:
@@ -84,8 +84,8 @@ bool MpvPlayer::Initialize(HWND container, HWND flutter_window) {
|
||||
mpv_set_option_string(mpv_, "tone-mapping", "auto");
|
||||
mpv_set_option_string(mpv_, "hdr-compute-peak", "auto");
|
||||
|
||||
// Enable logging
|
||||
mpv_request_log_messages(mpv_, "v");
|
||||
// Default to warn-level logging; Dart side can raise to "v" if debug logging is enabled.
|
||||
mpv_request_log_messages(mpv_, "warn");
|
||||
|
||||
// Initialize mpv.
|
||||
LogToFile("MpvPlayer::Initialize - calling mpv_initialize()");
|
||||
@@ -282,6 +282,11 @@ void MpvPlayer::SetVisible(bool visible) {
|
||||
}
|
||||
}
|
||||
|
||||
void MpvPlayer::SetLogLevel(const std::string& level) {
|
||||
if (!mpv_) return;
|
||||
mpv_request_log_messages(mpv_, level.c_str());
|
||||
}
|
||||
|
||||
void MpvPlayer::SetEventCallback(EventCallback callback) {
|
||||
std::lock_guard<std::mutex> lock(callback_mutex_);
|
||||
event_callback_ = std::move(callback);
|
||||
|
||||
@@ -65,6 +65,9 @@ class MpvPlayer {
|
||||
// Shows or hides the video window.
|
||||
void SetVisible(bool visible);
|
||||
|
||||
// Sets the MPV log message level (e.g., "warn", "v", "debug").
|
||||
void SetLogLevel(const std::string& level);
|
||||
|
||||
// Sets the event callback for property changes and events.
|
||||
void SetEventCallback(EventCallback callback);
|
||||
|
||||
|
||||
@@ -248,6 +248,29 @@ void MpvPlayerPlugin::HandleMethodCall(
|
||||
player_->SetProperty(std::get<std::string>(name_it->second),
|
||||
std::get<std::string>(value_it->second));
|
||||
result->Success();
|
||||
} else if (method == "setLogLevel") {
|
||||
if (!player_ || !player_->IsInitialized()) {
|
||||
result->Error("NOT_INITIALIZED", "Player not initialized");
|
||||
return;
|
||||
}
|
||||
|
||||
const auto* args = method_call.arguments();
|
||||
if (!args || !std::holds_alternative<flutter::EncodableMap>(*args)) {
|
||||
result->Error("INVALID_ARGS", "Expected map argument");
|
||||
return;
|
||||
}
|
||||
|
||||
const auto& map = std::get<flutter::EncodableMap>(*args);
|
||||
auto level_it = map.find(flutter::EncodableValue("level"));
|
||||
|
||||
if (level_it == map.end() ||
|
||||
!std::holds_alternative<std::string>(level_it->second)) {
|
||||
result->Error("INVALID_ARGS", "Missing 'level'");
|
||||
return;
|
||||
}
|
||||
|
||||
player_->SetLogLevel(std::get<std::string>(level_it->second));
|
||||
result->Success();
|
||||
} else if (method == "getProperty") {
|
||||
if (!player_ || !player_->IsInitialized()) {
|
||||
result->Error("NOT_INITIALIZED", "Player not initialized");
|
||||
|
||||
Reference in New Issue
Block a user