222 lines
8.1 KiB
C++
222 lines
8.1 KiB
C++
#include "pch.h"
|
|
#include "SettingsPage.xaml.h"
|
|
#include "src/Logger/LogManager.h"
|
|
#if __has_include("SettingsPage.g.cpp")
|
|
#include "SettingsPage.g.cpp"
|
|
#endif
|
|
|
|
using namespace winrt;
|
|
using namespace winrt::Microsoft::UI::Xaml;
|
|
using namespace winrt::Microsoft::UI::Xaml::Controls;
|
|
|
|
namespace winrt::Vav2Player::implementation
|
|
{
|
|
SettingsPage::SettingsPage()
|
|
{
|
|
this->InitializeComponent();
|
|
LoadSettings();
|
|
UpdateDecoderStatus();
|
|
}
|
|
|
|
void SettingsPage::DecoderComboBox_SelectionChanged(IInspectable const& sender, SelectionChangedEventArgs const& e)
|
|
{
|
|
auto comboBox = sender.as<ComboBox>();
|
|
auto selectedItem = comboBox.SelectedItem().as<ComboBoxItem>();
|
|
|
|
if (selectedItem)
|
|
{
|
|
auto tag = selectedItem.Tag().as<hstring>();
|
|
m_selectedDecoderType = GetDecoderTypeFromTag(tag);
|
|
UpdateDecoderStatus();
|
|
}
|
|
}
|
|
|
|
void SettingsPage::QualityComboBox_SelectionChanged(IInspectable const& sender, SelectionChangedEventArgs const& e)
|
|
{
|
|
auto comboBox = sender.as<ComboBox>();
|
|
auto selectedItem = comboBox.SelectedItem().as<ComboBoxItem>();
|
|
|
|
if (selectedItem)
|
|
{
|
|
auto tag = selectedItem.Tag().as<hstring>();
|
|
m_selectedQualityMode = GetQualityModeFromTag(tag);
|
|
}
|
|
}
|
|
|
|
void SettingsPage::ApplyButton_Click(IInspectable const& sender, RoutedEventArgs const& e)
|
|
{
|
|
SaveSettings();
|
|
|
|
// Log settings application for VideoPlayerControl to detect
|
|
std::wstring message = L"Settings applied - Decoder: ";
|
|
switch (m_selectedDecoderType) {
|
|
case VAVCORE_DECODER_AUTO: message += L"Auto"; break;
|
|
case VAVCORE_DECODER_DAV1D: message += L"Software (dav1d)"; break;
|
|
case VAVCORE_DECODER_MEDIA_FOUNDATION: message += L"Hardware (Media Foundation)"; break;
|
|
case VAVCORE_DECODER_NVDEC: message += L"Hardware (NVDEC)"; break;
|
|
case VAVCORE_DECODER_VPL: message += L"Hardware (Intel VPL)"; break;
|
|
case VAVCORE_DECODER_AMF: message += L"Hardware (AMD AMF)"; break;
|
|
}
|
|
|
|
// Use LogManager to notify about settings change
|
|
::Vav2Player::LogManager::GetInstance().LogInfo(message, L"Settings");
|
|
|
|
// Show confirmation
|
|
auto dialog = ContentDialog();
|
|
dialog.Title(box_value(L"Settings Applied"));
|
|
dialog.Content(box_value(L"Settings have been saved successfully. The new decoder settings will be used for new video files. Currently playing videos will use the new decoder when reloaded."));
|
|
dialog.CloseButtonText(L"OK");
|
|
dialog.XamlRoot(this->XamlRoot());
|
|
|
|
// Show dialog asynchronously
|
|
[dialog]() -> winrt::Windows::Foundation::IAsyncAction {
|
|
co_await dialog.ShowAsync();
|
|
}();
|
|
}
|
|
|
|
void SettingsPage::ResetButton_Click(IInspectable const& sender, RoutedEventArgs const& e)
|
|
{
|
|
// Reset to defaults
|
|
m_selectedDecoderType = VAVCORE_DECODER_AUTO;
|
|
m_selectedQualityMode = VAVCORE_QUALITY_FAST;
|
|
|
|
// Update UI
|
|
DecoderComboBox().SelectedIndex(0); // AUTO
|
|
QualityComboBox().SelectedIndex(1); // FAST
|
|
|
|
UpdateDecoderStatus();
|
|
|
|
// Auto-save
|
|
SaveSettings();
|
|
}
|
|
|
|
void SettingsPage::LoadSettings()
|
|
{
|
|
// Load from Windows.Storage.ApplicationData.Current.LocalSettings
|
|
auto localSettings = Windows::Storage::ApplicationData::Current().LocalSettings();
|
|
auto values = localSettings.Values();
|
|
|
|
// Load decoder type (default: AUTO)
|
|
if (values.HasKey(L"DecoderType"))
|
|
{
|
|
m_selectedDecoderType = static_cast<VavCoreDecoderType>(unbox_value<int32_t>(values.Lookup(L"DecoderType")));
|
|
}
|
|
else
|
|
{
|
|
m_selectedDecoderType = VAVCORE_DECODER_AUTO;
|
|
}
|
|
|
|
// Load quality mode (default: FAST)
|
|
if (values.HasKey(L"QualityMode"))
|
|
{
|
|
m_selectedQualityMode = static_cast<VavCoreQualityMode>(unbox_value<int32_t>(values.Lookup(L"QualityMode")));
|
|
}
|
|
else
|
|
{
|
|
m_selectedQualityMode = VAVCORE_QUALITY_FAST;
|
|
}
|
|
|
|
// Update UI controls
|
|
auto decoderTag = GetTagFromDecoderType(m_selectedDecoderType);
|
|
auto qualityTag = GetTagFromQualityMode(m_selectedQualityMode);
|
|
|
|
// Set decoder combobox selection
|
|
for (uint32_t i = 0; i < DecoderComboBox().Items().Size(); ++i)
|
|
{
|
|
auto item = DecoderComboBox().Items().GetAt(i).as<ComboBoxItem>();
|
|
if (item.Tag().as<hstring>() == decoderTag)
|
|
{
|
|
DecoderComboBox().SelectedIndex(i);
|
|
break;
|
|
}
|
|
}
|
|
|
|
// Set quality combobox selection
|
|
for (uint32_t i = 0; i < QualityComboBox().Items().Size(); ++i)
|
|
{
|
|
auto item = QualityComboBox().Items().GetAt(i).as<ComboBoxItem>();
|
|
if (item.Tag().as<hstring>() == qualityTag)
|
|
{
|
|
QualityComboBox().SelectedIndex(i);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
void SettingsPage::SaveSettings()
|
|
{
|
|
// Save to Windows.Storage.ApplicationData.Current.LocalSettings
|
|
auto localSettings = Windows::Storage::ApplicationData::Current().LocalSettings();
|
|
auto values = localSettings.Values();
|
|
|
|
values.Insert(L"DecoderType", box_value(static_cast<int32_t>(m_selectedDecoderType)));
|
|
values.Insert(L"QualityMode", box_value(static_cast<int32_t>(m_selectedQualityMode)));
|
|
}
|
|
|
|
void SettingsPage::UpdateDecoderStatus()
|
|
{
|
|
auto description = GetDecoderDescription(m_selectedDecoderType);
|
|
DecoderStatusText().Text(description);
|
|
}
|
|
|
|
hstring SettingsPage::GetDecoderDescription(VavCoreDecoderType type)
|
|
{
|
|
switch (type)
|
|
{
|
|
case VAVCORE_DECODER_AUTO:
|
|
return L"Automatically selects the best available decoder based on hardware capabilities and performance. Recommended for most users.";
|
|
case VAVCORE_DECODER_NVDEC:
|
|
return L"NVIDIA hardware-accelerated decoder. Requires NVIDIA GPU with AV1 decode support (RTX 30 series or newer).";
|
|
case VAVCORE_DECODER_DAV1D:
|
|
return L"Software decoder with CPU optimization. Works on all systems but may use more CPU resources.";
|
|
case VAVCORE_DECODER_MEDIA_FOUNDATION:
|
|
return L"Windows Media Foundation decoder. Uses system-provided AV1 decoding capabilities.";
|
|
default:
|
|
return L"Unknown decoder type.";
|
|
}
|
|
}
|
|
|
|
VavCoreDecoderType SettingsPage::GetDecoderTypeFromTag(hstring const& tag)
|
|
{
|
|
if (tag == L"AUTO") return VAVCORE_DECODER_AUTO;
|
|
if (tag == L"NVDEC") return VAVCORE_DECODER_NVDEC;
|
|
if (tag == L"VPL") return VAVCORE_DECODER_VPL;
|
|
if (tag == L"AMF") return VAVCORE_DECODER_AMF;
|
|
if (tag == L"DAV1D") return VAVCORE_DECODER_DAV1D;
|
|
if (tag == L"MEDIA_FOUNDATION") return VAVCORE_DECODER_MEDIA_FOUNDATION;
|
|
return VAVCORE_DECODER_AUTO;
|
|
}
|
|
|
|
VavCoreQualityMode SettingsPage::GetQualityModeFromTag(hstring const& tag)
|
|
{
|
|
if (tag == L"CONSERVATIVE") return VAVCORE_QUALITY_CONSERVATIVE;
|
|
if (tag == L"FAST") return VAVCORE_QUALITY_FAST;
|
|
if (tag == L"ULTRA_FAST") return VAVCORE_QUALITY_ULTRA_FAST;
|
|
return VAVCORE_QUALITY_FAST;
|
|
}
|
|
|
|
hstring SettingsPage::GetTagFromDecoderType(VavCoreDecoderType type)
|
|
{
|
|
switch (type)
|
|
{
|
|
case VAVCORE_DECODER_AUTO: return L"AUTO";
|
|
case VAVCORE_DECODER_NVDEC: return L"NVDEC";
|
|
case VAVCORE_DECODER_VPL: return L"VPL";
|
|
case VAVCORE_DECODER_AMF: return L"AMF";
|
|
case VAVCORE_DECODER_DAV1D: return L"DAV1D";
|
|
case VAVCORE_DECODER_MEDIA_FOUNDATION: return L"MEDIA_FOUNDATION";
|
|
default: return L"AUTO";
|
|
}
|
|
}
|
|
|
|
hstring SettingsPage::GetTagFromQualityMode(VavCoreQualityMode mode)
|
|
{
|
|
switch (mode)
|
|
{
|
|
case VAVCORE_QUALITY_CONSERVATIVE: return L"CONSERVATIVE";
|
|
case VAVCORE_QUALITY_FAST: return L"FAST";
|
|
case VAVCORE_QUALITY_ULTRA_FAST: return L"ULTRA_FAST";
|
|
default: return L"FAST";
|
|
}
|
|
}
|
|
} |