Skip to content

Commit

Permalink
Add StreamHistory quality controls.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mysticial committed Dec 8, 2024
1 parent 5f89e8f commit 62f7223
Show file tree
Hide file tree
Showing 9 changed files with 163 additions and 67 deletions.
4 changes: 4 additions & 0 deletions SerialPrograms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,8 @@ file(GLOB MAIN_SOURCES
Source/CommonFramework/Options/LabelCellOption.h
Source/CommonFramework/Options/LanguageOCROption.cpp
Source/CommonFramework/Options/LanguageOCROption.h
Source/CommonFramework/Options/ResolutionOption.cpp
Source/CommonFramework/Options/ResolutionOption.h
Source/CommonFramework/Options/ScreenWatchOption.cpp
Source/CommonFramework/Options/ScreenWatchOption.h
Source/CommonFramework/Options/ScreenshotFormatOption.h
Expand Down Expand Up @@ -509,6 +511,8 @@ file(GLOB MAIN_SOURCES
Source/CommonFramework/PersistentSettings.h
Source/CommonFramework/ProgramSession.cpp
Source/CommonFramework/ProgramSession.h
Source/CommonFramework/Recording/StreamHistoryOption.cpp
Source/CommonFramework/Recording/StreamHistoryOption.h
Source/CommonFramework/Recording/StreamHistorySession.cpp
Source/CommonFramework/Recording/StreamHistorySession.h
Source/CommonFramework/Recording/StreamHistoryTracker_Null.h
Expand Down
4 changes: 4 additions & 0 deletions SerialPrograms/SerialPrograms.pro
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ SOURCES += \
Source/CommonFramework/Options/Environment/ThemeSelectorOption.cpp \
Source/CommonFramework/Options/LabelCellOption.cpp \
Source/CommonFramework/Options/LanguageOCROption.cpp \
Source/CommonFramework/Options/ResolutionOption.cpp \
Source/CommonFramework/Options/ScreenWatchOption.cpp \
Source/CommonFramework/Options/StringSelectOption.cpp \
Source/CommonFramework/Options/UI/LabelCellWidget.cpp \
Expand All @@ -271,6 +272,7 @@ SOURCES += \
Source/CommonFramework/Panels/UI/SettingsPanelWidget.cpp \
Source/CommonFramework/PersistentSettings.cpp \
Source/CommonFramework/ProgramSession.cpp \
Source/CommonFramework/Recording/StreamHistoryOption.cpp \
Source/CommonFramework/Recording/StreamHistorySession.cpp \
Source/CommonFramework/Recording/StreamRecorder.cpp \
Source/CommonFramework/Resources/SpriteDatabase.cpp \
Expand Down Expand Up @@ -1344,6 +1346,7 @@ HEADERS += \
Source/CommonFramework/Options/Environment/SleepSuppressOption.h \
Source/CommonFramework/Options/LabelCellOption.h \
Source/CommonFramework/Options/LanguageOCROption.h \
Source/CommonFramework/Options/ResolutionOption.h \
Source/CommonFramework/Options/ScreenWatchOption.h \
Source/CommonFramework/Options/ScreenshotFormatOption.h \
Source/CommonFramework/Options/StringSelectOption.h \
Expand All @@ -1363,6 +1366,7 @@ HEADERS += \
Source/CommonFramework/Panels/UI/SettingsPanelWidget.h \
Source/CommonFramework/PersistentSettings.h \
Source/CommonFramework/ProgramSession.h \
Source/CommonFramework/Recording/StreamHistoryOption.h \
Source/CommonFramework/Recording/StreamHistorySession.h \
Source/CommonFramework/Recording/StreamHistoryTracker_RecordOnTheFly.h \
Source/CommonFramework/Recording/StreamHistoryTracker_SaveFrames.h \
Expand Down
47 changes: 1 addition & 46 deletions SerialPrograms/Source/CommonFramework/GlobalSettingsPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include "Common/Cpp/Json/JsonObject.h"
#include "CommonFramework/Globals.h"
//#include "CommonFramework/Environment/Environment.h"
#include "CommonFramework/Windows/DpiScaler.h"
#include "GlobalSettingsPanel.h"

// #include <iostream>
Expand All @@ -37,50 +36,6 @@ const std::set<std::string> TOKENS{



ResolutionOption::ResolutionOption(
std::string label, std::string description,
int default_width, int default_height
)
: GroupOption(std::move(label), LockMode::LOCK_WHILE_RUNNING)
, DESCRIPTION(std::move(description))
, WIDTH("<b>Width:</b>", LockMode::LOCK_WHILE_RUNNING, scale_dpi_width(default_width))
, HEIGHT("<b>Height:</b>", LockMode::LOCK_WHILE_RUNNING, scale_dpi_height(default_height))
{
PA_ADD_STATIC(DESCRIPTION);
PA_ADD_OPTION(WIDTH);
PA_ADD_OPTION(HEIGHT);
}

StreamHistoryOption::StreamHistoryOption()
: GroupOption(
"Stream History",
LockMode::LOCK_WHILE_RUNNING,
true,
IS_BETA_VERSION
)
, DESCRIPTION(
"Keep a record of the recent video+audio streams. This will allow video capture "
"for unexpected events.<br><br>"
"<font color=\"orange\">Warning: This feature is computationally expensive and "
"will require a more powerful computer to run (especially for multi-Switch programs).<br>"
"Furthermore, the current implementation is inefficient as it will write a lot "
"of data to disk. This feature is still a work-in-progress."
"</font>"
)
, HISTORY_SECONDS(
"<b>History (seconds):</b><br>"
"Keep this many seconds of video and audio feed for video capture and debugging purposes.<br><br>"
"<font color=\"orange\">Do not set this too large as it will consume a lot of memory and may exceed the "
"attachment size limit for Discord notifications."
"</font>",
LockMode::UNLOCK_WHILE_RUNNING,
30
)
{
PA_ADD_STATIC(DESCRIPTION);
PA_ADD_OPTION(HISTORY_SECONDS);
}



PreloadSettings::PreloadSettings(){}
Expand Down Expand Up @@ -267,8 +222,8 @@ GlobalSettings::GlobalSettings()
PA_ADD_OPTION(CHECK_FOR_UPDATES);
PA_ADD_OPTION(STATS_FILE);
PA_ADD_OPTION(ALL_STATS);
PA_ADD_OPTION(WINDOW_SIZE);
PA_ADD_OPTION(THEME);
PA_ADD_OPTION(WINDOW_SIZE);
#if (QT_VERSION_MAJOR == 6) && (QT_VERSION_MINOR >= 8)
PA_ADD_OPTION(STREAM_HISTORY);
#else
Expand Down
22 changes: 3 additions & 19 deletions SerialPrograms/Source/CommonFramework/GlobalSettingsPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
#include "Common/Cpp/Options/SimpleIntegerOption.h"
#include "Common/Cpp/Options/FloatingPointOption.h"
#include "Common/Cpp/Options/StringOption.h"
#include "CommonFramework/Options/ResolutionOption.h"
#include "CommonFramework/Options/Environment/ProcessPriorityOption.h"
#include "CommonFramework/Options/Environment/ProcessorLevelOption.h"
#include "CommonFramework/Options/Environment/ThemeSelectorOption.h"
#include "CommonFramework/Options/Environment/SleepSuppressOption.h"
#include "CommonFramework/ErrorReports/ErrorReports.h"
#include "CommonFramework/VideoPipeline/Backends/CameraImplementations.h"
#include "CommonFramework/Recording/StreamHistoryOption.h"
#include "CommonFramework/Panels/SettingsPanel.h"
#include "CommonFramework/Panels/PanelTools.h"
#include "Integrations/DiscordSettingsOption.h"
Expand All @@ -32,29 +34,11 @@ namespace PokemonAutomation{



class ResolutionOption : public GroupOption{
public:
ResolutionOption(
std::string label, std::string description,
int default_width, int default_height
);

StaticTextOption DESCRIPTION;
SimpleIntegerOption<uint32_t> WIDTH;
SimpleIntegerOption<uint32_t> HEIGHT;
};
struct DebugSettings{
bool COLOR_CHECK = false;
bool IMAGE_TEMPLATE_MATCHING = false;
bool IMAGE_DICTIONARY_MATCHING = false;
};
class StreamHistoryOption : public GroupOption{
public:
StreamHistoryOption();

StaticTextOption DESCRIPTION;
SimpleIntegerOption<uint16_t> HISTORY_SECONDS;
};



Expand Down Expand Up @@ -92,8 +76,8 @@ class GlobalSettings : public BatchOption, private ConfigOption::Listener{
StringOption STATS_FILE;
BooleanCheckBoxOption ALL_STATS;

ResolutionOption WINDOW_SIZE;
ThemeSelectorOption THEME;
ResolutionOption WINDOW_SIZE;

StreamHistoryOption STREAM_HISTORY;
SleepSuppressOptions SLEEP_SUPPRESS;
Expand Down
28 changes: 28 additions & 0 deletions SerialPrograms/Source/CommonFramework/Options/ResolutionOption.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* Resolution Option
*
* From: https://github.com/PokemonAutomation/Arduino-Source
*
*/

#include "CommonFramework/Windows/DpiScaler.h"
#include "ResolutionOption.h"

namespace PokemonAutomation{


ResolutionOption::ResolutionOption(
std::string label, std::string description,
int default_width, int default_height
)
: GroupOption(std::move(label), LockMode::LOCK_WHILE_RUNNING)
, DESCRIPTION(std::move(description))
, WIDTH("<b>Width:</b>", LockMode::LOCK_WHILE_RUNNING, scale_dpi_width(default_width))
, HEIGHT("<b>Height:</b>", LockMode::LOCK_WHILE_RUNNING, scale_dpi_height(default_height))
{
PA_ADD_STATIC(DESCRIPTION);
PA_ADD_OPTION(WIDTH);
PA_ADD_OPTION(HEIGHT);
}


}
31 changes: 31 additions & 0 deletions SerialPrograms/Source/CommonFramework/Options/ResolutionOption.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* Resolution Option
*
* From: https://github.com/PokemonAutomation/Arduino-Source
*
*/

#ifndef PokemonAutomation_Options_ResolutionOption_H
#define PokemonAutomation_Options_ResolutionOption_H

#include "Common/Cpp/Options/StaticTextOption.h"
#include "Common/Cpp/Options/SimpleIntegerOption.h"
#include "Common/Cpp/Options/GroupOption.h"

namespace PokemonAutomation{


class ResolutionOption : public GroupOption{
public:
ResolutionOption(
std::string label, std::string description,
int default_width, int default_height
);

StaticTextOption DESCRIPTION;
SimpleIntegerOption<uint32_t> WIDTH;
SimpleIntegerOption<uint32_t> HEIGHT;
};


}
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* Stream History Option
*
* From: https://github.com/PokemonAutomation/Arduino-Source
*
*/

#include "CommonFramework/Globals.h"
#include "StreamHistoryOption.h"

namespace PokemonAutomation{


StreamHistoryOption::StreamHistoryOption()
: GroupOption(
"Stream History",
LockMode::LOCK_WHILE_RUNNING,
true,
IS_BETA_VERSION
)
, DESCRIPTION(
"Keep a record of the recent video+audio streams. This will allow video capture "
"for unexpected events.<br><br>"
"<font color=\"orange\">Warning: This feature is computationally expensive and "
"will require a more powerful computer to run (especially for multi-Switch programs).<br>"
"Furthermore, the current implementation is inefficient as it will write a lot "
"of data to disk. This feature is still a work-in-progress."
"</font>"
)
, HISTORY_SECONDS(
"<b>History (seconds):</b><br>"
"Keep this many seconds of video and audio feed for video capture and debugging purposes.<br><br>"
"<font color=\"orange\">Do not set this too large as it will consume a lot of memory and may exceed the "
"attachment size limit for Discord notifications."
"</font>",
LockMode::UNLOCK_WHILE_RUNNING,
30
)
, VIDEO_BITRATE(
"<b>Video Bit-Rate (kbps):</b><br>"
"Lower = lower quality, smaller file size.<br>"
"Higher = high quality, larger file size.<br><br>"
"<font color=\"orange\">Large values can exceed the attachment size limit for Discord notifications."
"</font>",
LockMode::UNLOCK_WHILE_RUNNING,
5000
)
{
PA_ADD_STATIC(DESCRIPTION);
PA_ADD_OPTION(HISTORY_SECONDS);
PA_ADD_OPTION(VIDEO_BITRATE);
}



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* Stream History Option
*
* From: https://github.com/PokemonAutomation/Arduino-Source
*
*/

#ifndef PokemonAutomation_StreamHistoryOption_H
#define PokemonAutomation_StreamHistoryOption_H

#include "Common/Cpp/Options/StaticTextOption.h"
#include "Common/Cpp/Options/SimpleIntegerOption.h"
#include "Common/Cpp/Options/GroupOption.h"

namespace PokemonAutomation{



class StreamHistoryOption : public GroupOption{
public:
StreamHistoryOption();

StaticTextOption DESCRIPTION;
SimpleIntegerOption<uint16_t> HISTORY_SECONDS;
SimpleIntegerOption<uint32_t> VIDEO_BITRATE;
};


}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <QMediaRecorder>
#include "Common/Cpp/PrettyPrint.h"
#include "Common/Cpp/Concurrency/SpinPause.h"
#include "CommonFramework/GlobalSettingsPanel.h"
#include "CommonFramework/VideoPipeline/Backends/VideoFrameQt.h"
#include "StreamRecorder.h"

Expand Down Expand Up @@ -153,9 +154,13 @@ void StreamRecording::internal_run(){
session.setRecorder(&recorder);
recorder.setMediaFormat(QMediaFormat::MPEG4);
// recorder.setQuality(QMediaRecorder::NormalQuality);
recorder.setQuality(QMediaRecorder::LowQuality);
// recorder.setQuality(QMediaRecorder::LowQuality);
// recorder.setQuality(QMediaRecorder::VeryLowQuality);

recorder.setVideoResolution(1280, 720);
recorder.setVideoBitRate(GlobalSettings::instance().STREAM_HISTORY.VIDEO_BITRATE * 1000);
recorder.setEncodingMode(QMediaRecorder::AverageBitRateEncoding);

#ifdef PA_STREAM_HISTORY_LOCAL_BUFFER
recorder.setOutputDevice(&m_write_buffer);
#else
Expand All @@ -165,7 +170,8 @@ void StreamRecording::internal_run(){
);
#endif

// cout << "EncodingMode = " << (int)recorder.encodingMode() << endl;
// cout << "Encoding Mode = " << (int)recorder.encodingMode() << endl;
// cout << "Bit Rate = " << (int)recorder.videoBitRate() << endl;

recorder.connect(
&audio_input, &QAudioBufferInput::readyToSendAudioBuffer,
Expand Down

0 comments on commit 62f7223

Please sign in to comment.