Skip to content

Commit 62f7223

Browse files
committed
Add StreamHistory quality controls.
1 parent 5f89e8f commit 62f7223

File tree

9 files changed

+163
-67
lines changed

9 files changed

+163
-67
lines changed

SerialPrograms/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,8 @@ file(GLOB MAIN_SOURCES
471471
Source/CommonFramework/Options/LabelCellOption.h
472472
Source/CommonFramework/Options/LanguageOCROption.cpp
473473
Source/CommonFramework/Options/LanguageOCROption.h
474+
Source/CommonFramework/Options/ResolutionOption.cpp
475+
Source/CommonFramework/Options/ResolutionOption.h
474476
Source/CommonFramework/Options/ScreenWatchOption.cpp
475477
Source/CommonFramework/Options/ScreenWatchOption.h
476478
Source/CommonFramework/Options/ScreenshotFormatOption.h
@@ -509,6 +511,8 @@ file(GLOB MAIN_SOURCES
509511
Source/CommonFramework/PersistentSettings.h
510512
Source/CommonFramework/ProgramSession.cpp
511513
Source/CommonFramework/ProgramSession.h
514+
Source/CommonFramework/Recording/StreamHistoryOption.cpp
515+
Source/CommonFramework/Recording/StreamHistoryOption.h
512516
Source/CommonFramework/Recording/StreamHistorySession.cpp
513517
Source/CommonFramework/Recording/StreamHistorySession.h
514518
Source/CommonFramework/Recording/StreamHistoryTracker_Null.h

SerialPrograms/SerialPrograms.pro

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ SOURCES += \
254254
Source/CommonFramework/Options/Environment/ThemeSelectorOption.cpp \
255255
Source/CommonFramework/Options/LabelCellOption.cpp \
256256
Source/CommonFramework/Options/LanguageOCROption.cpp \
257+
Source/CommonFramework/Options/ResolutionOption.cpp \
257258
Source/CommonFramework/Options/ScreenWatchOption.cpp \
258259
Source/CommonFramework/Options/StringSelectOption.cpp \
259260
Source/CommonFramework/Options/UI/LabelCellWidget.cpp \
@@ -271,6 +272,7 @@ SOURCES += \
271272
Source/CommonFramework/Panels/UI/SettingsPanelWidget.cpp \
272273
Source/CommonFramework/PersistentSettings.cpp \
273274
Source/CommonFramework/ProgramSession.cpp \
275+
Source/CommonFramework/Recording/StreamHistoryOption.cpp \
274276
Source/CommonFramework/Recording/StreamHistorySession.cpp \
275277
Source/CommonFramework/Recording/StreamRecorder.cpp \
276278
Source/CommonFramework/Resources/SpriteDatabase.cpp \
@@ -1344,6 +1346,7 @@ HEADERS += \
13441346
Source/CommonFramework/Options/Environment/SleepSuppressOption.h \
13451347
Source/CommonFramework/Options/LabelCellOption.h \
13461348
Source/CommonFramework/Options/LanguageOCROption.h \
1349+
Source/CommonFramework/Options/ResolutionOption.h \
13471350
Source/CommonFramework/Options/ScreenWatchOption.h \
13481351
Source/CommonFramework/Options/ScreenshotFormatOption.h \
13491352
Source/CommonFramework/Options/StringSelectOption.h \
@@ -1363,6 +1366,7 @@ HEADERS += \
13631366
Source/CommonFramework/Panels/UI/SettingsPanelWidget.h \
13641367
Source/CommonFramework/PersistentSettings.h \
13651368
Source/CommonFramework/ProgramSession.h \
1369+
Source/CommonFramework/Recording/StreamHistoryOption.h \
13661370
Source/CommonFramework/Recording/StreamHistorySession.h \
13671371
Source/CommonFramework/Recording/StreamHistoryTracker_RecordOnTheFly.h \
13681372
Source/CommonFramework/Recording/StreamHistoryTracker_SaveFrames.h \

SerialPrograms/Source/CommonFramework/GlobalSettingsPanel.cpp

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include "Common/Cpp/Json/JsonObject.h"
1414
#include "CommonFramework/Globals.h"
1515
//#include "CommonFramework/Environment/Environment.h"
16-
#include "CommonFramework/Windows/DpiScaler.h"
1716
#include "GlobalSettingsPanel.h"
1817

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

3837

3938

40-
ResolutionOption::ResolutionOption(
41-
std::string label, std::string description,
42-
int default_width, int default_height
43-
)
44-
: GroupOption(std::move(label), LockMode::LOCK_WHILE_RUNNING)
45-
, DESCRIPTION(std::move(description))
46-
, WIDTH("<b>Width:</b>", LockMode::LOCK_WHILE_RUNNING, scale_dpi_width(default_width))
47-
, HEIGHT("<b>Height:</b>", LockMode::LOCK_WHILE_RUNNING, scale_dpi_height(default_height))
48-
{
49-
PA_ADD_STATIC(DESCRIPTION);
50-
PA_ADD_OPTION(WIDTH);
51-
PA_ADD_OPTION(HEIGHT);
52-
}
53-
54-
StreamHistoryOption::StreamHistoryOption()
55-
: GroupOption(
56-
"Stream History",
57-
LockMode::LOCK_WHILE_RUNNING,
58-
true,
59-
IS_BETA_VERSION
60-
)
61-
, DESCRIPTION(
62-
"Keep a record of the recent video+audio streams. This will allow video capture "
63-
"for unexpected events.<br><br>"
64-
"<font color=\"orange\">Warning: This feature is computationally expensive and "
65-
"will require a more powerful computer to run (especially for multi-Switch programs).<br>"
66-
"Furthermore, the current implementation is inefficient as it will write a lot "
67-
"of data to disk. This feature is still a work-in-progress."
68-
"</font>"
69-
)
70-
, HISTORY_SECONDS(
71-
"<b>History (seconds):</b><br>"
72-
"Keep this many seconds of video and audio feed for video capture and debugging purposes.<br><br>"
73-
"<font color=\"orange\">Do not set this too large as it will consume a lot of memory and may exceed the "
74-
"attachment size limit for Discord notifications."
75-
"</font>",
76-
LockMode::UNLOCK_WHILE_RUNNING,
77-
30
78-
)
79-
{
80-
PA_ADD_STATIC(DESCRIPTION);
81-
PA_ADD_OPTION(HISTORY_SECONDS);
82-
}
83-
8439

8540

8641
PreloadSettings::PreloadSettings(){}
@@ -267,8 +222,8 @@ GlobalSettings::GlobalSettings()
267222
PA_ADD_OPTION(CHECK_FOR_UPDATES);
268223
PA_ADD_OPTION(STATS_FILE);
269224
PA_ADD_OPTION(ALL_STATS);
270-
PA_ADD_OPTION(WINDOW_SIZE);
271225
PA_ADD_OPTION(THEME);
226+
PA_ADD_OPTION(WINDOW_SIZE);
272227
#if (QT_VERSION_MAJOR == 6) && (QT_VERSION_MINOR >= 8)
273228
PA_ADD_OPTION(STREAM_HISTORY);
274229
#else

SerialPrograms/Source/CommonFramework/GlobalSettingsPanel.h

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@
1313
#include "Common/Cpp/Options/SimpleIntegerOption.h"
1414
#include "Common/Cpp/Options/FloatingPointOption.h"
1515
#include "Common/Cpp/Options/StringOption.h"
16+
#include "CommonFramework/Options/ResolutionOption.h"
1617
#include "CommonFramework/Options/Environment/ProcessPriorityOption.h"
1718
#include "CommonFramework/Options/Environment/ProcessorLevelOption.h"
1819
#include "CommonFramework/Options/Environment/ThemeSelectorOption.h"
1920
#include "CommonFramework/Options/Environment/SleepSuppressOption.h"
2021
#include "CommonFramework/ErrorReports/ErrorReports.h"
2122
#include "CommonFramework/VideoPipeline/Backends/CameraImplementations.h"
23+
#include "CommonFramework/Recording/StreamHistoryOption.h"
2224
#include "CommonFramework/Panels/SettingsPanel.h"
2325
#include "CommonFramework/Panels/PanelTools.h"
2426
#include "Integrations/DiscordSettingsOption.h"
@@ -32,29 +34,11 @@ namespace PokemonAutomation{
3234

3335

3436

35-
class ResolutionOption : public GroupOption{
36-
public:
37-
ResolutionOption(
38-
std::string label, std::string description,
39-
int default_width, int default_height
40-
);
41-
42-
StaticTextOption DESCRIPTION;
43-
SimpleIntegerOption<uint32_t> WIDTH;
44-
SimpleIntegerOption<uint32_t> HEIGHT;
45-
};
4637
struct DebugSettings{
4738
bool COLOR_CHECK = false;
4839
bool IMAGE_TEMPLATE_MATCHING = false;
4940
bool IMAGE_DICTIONARY_MATCHING = false;
5041
};
51-
class StreamHistoryOption : public GroupOption{
52-
public:
53-
StreamHistoryOption();
54-
55-
StaticTextOption DESCRIPTION;
56-
SimpleIntegerOption<uint16_t> HISTORY_SECONDS;
57-
};
5842

5943

6044

@@ -92,8 +76,8 @@ class GlobalSettings : public BatchOption, private ConfigOption::Listener{
9276
StringOption STATS_FILE;
9377
BooleanCheckBoxOption ALL_STATS;
9478

95-
ResolutionOption WINDOW_SIZE;
9679
ThemeSelectorOption THEME;
80+
ResolutionOption WINDOW_SIZE;
9781

9882
StreamHistoryOption STREAM_HISTORY;
9983
SleepSuppressOptions SLEEP_SUPPRESS;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/* Resolution Option
2+
*
3+
* From: https://github.com/PokemonAutomation/Arduino-Source
4+
*
5+
*/
6+
7+
#include "CommonFramework/Windows/DpiScaler.h"
8+
#include "ResolutionOption.h"
9+
10+
namespace PokemonAutomation{
11+
12+
13+
ResolutionOption::ResolutionOption(
14+
std::string label, std::string description,
15+
int default_width, int default_height
16+
)
17+
: GroupOption(std::move(label), LockMode::LOCK_WHILE_RUNNING)
18+
, DESCRIPTION(std::move(description))
19+
, WIDTH("<b>Width:</b>", LockMode::LOCK_WHILE_RUNNING, scale_dpi_width(default_width))
20+
, HEIGHT("<b>Height:</b>", LockMode::LOCK_WHILE_RUNNING, scale_dpi_height(default_height))
21+
{
22+
PA_ADD_STATIC(DESCRIPTION);
23+
PA_ADD_OPTION(WIDTH);
24+
PA_ADD_OPTION(HEIGHT);
25+
}
26+
27+
28+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/* Resolution Option
2+
*
3+
* From: https://github.com/PokemonAutomation/Arduino-Source
4+
*
5+
*/
6+
7+
#ifndef PokemonAutomation_Options_ResolutionOption_H
8+
#define PokemonAutomation_Options_ResolutionOption_H
9+
10+
#include "Common/Cpp/Options/StaticTextOption.h"
11+
#include "Common/Cpp/Options/SimpleIntegerOption.h"
12+
#include "Common/Cpp/Options/GroupOption.h"
13+
14+
namespace PokemonAutomation{
15+
16+
17+
class ResolutionOption : public GroupOption{
18+
public:
19+
ResolutionOption(
20+
std::string label, std::string description,
21+
int default_width, int default_height
22+
);
23+
24+
StaticTextOption DESCRIPTION;
25+
SimpleIntegerOption<uint32_t> WIDTH;
26+
SimpleIntegerOption<uint32_t> HEIGHT;
27+
};
28+
29+
30+
}
31+
#endif
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/* Stream History Option
2+
*
3+
* From: https://github.com/PokemonAutomation/Arduino-Source
4+
*
5+
*/
6+
7+
#include "CommonFramework/Globals.h"
8+
#include "StreamHistoryOption.h"
9+
10+
namespace PokemonAutomation{
11+
12+
13+
StreamHistoryOption::StreamHistoryOption()
14+
: GroupOption(
15+
"Stream History",
16+
LockMode::LOCK_WHILE_RUNNING,
17+
true,
18+
IS_BETA_VERSION
19+
)
20+
, DESCRIPTION(
21+
"Keep a record of the recent video+audio streams. This will allow video capture "
22+
"for unexpected events.<br><br>"
23+
"<font color=\"orange\">Warning: This feature is computationally expensive and "
24+
"will require a more powerful computer to run (especially for multi-Switch programs).<br>"
25+
"Furthermore, the current implementation is inefficient as it will write a lot "
26+
"of data to disk. This feature is still a work-in-progress."
27+
"</font>"
28+
)
29+
, HISTORY_SECONDS(
30+
"<b>History (seconds):</b><br>"
31+
"Keep this many seconds of video and audio feed for video capture and debugging purposes.<br><br>"
32+
"<font color=\"orange\">Do not set this too large as it will consume a lot of memory and may exceed the "
33+
"attachment size limit for Discord notifications."
34+
"</font>",
35+
LockMode::UNLOCK_WHILE_RUNNING,
36+
30
37+
)
38+
, VIDEO_BITRATE(
39+
"<b>Video Bit-Rate (kbps):</b><br>"
40+
"Lower = lower quality, smaller file size.<br>"
41+
"Higher = high quality, larger file size.<br><br>"
42+
"<font color=\"orange\">Large values can exceed the attachment size limit for Discord notifications."
43+
"</font>",
44+
LockMode::UNLOCK_WHILE_RUNNING,
45+
5000
46+
)
47+
{
48+
PA_ADD_STATIC(DESCRIPTION);
49+
PA_ADD_OPTION(HISTORY_SECONDS);
50+
PA_ADD_OPTION(VIDEO_BITRATE);
51+
}
52+
53+
54+
55+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/* Stream History Option
2+
*
3+
* From: https://github.com/PokemonAutomation/Arduino-Source
4+
*
5+
*/
6+
7+
#ifndef PokemonAutomation_StreamHistoryOption_H
8+
#define PokemonAutomation_StreamHistoryOption_H
9+
10+
#include "Common/Cpp/Options/StaticTextOption.h"
11+
#include "Common/Cpp/Options/SimpleIntegerOption.h"
12+
#include "Common/Cpp/Options/GroupOption.h"
13+
14+
namespace PokemonAutomation{
15+
16+
17+
18+
class StreamHistoryOption : public GroupOption{
19+
public:
20+
StreamHistoryOption();
21+
22+
StaticTextOption DESCRIPTION;
23+
SimpleIntegerOption<uint16_t> HISTORY_SECONDS;
24+
SimpleIntegerOption<uint32_t> VIDEO_BITRATE;
25+
};
26+
27+
28+
}
29+
#endif

SerialPrograms/Source/CommonFramework/Recording/StreamRecorder.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <QMediaRecorder>
1919
#include "Common/Cpp/PrettyPrint.h"
2020
#include "Common/Cpp/Concurrency/SpinPause.h"
21+
#include "CommonFramework/GlobalSettingsPanel.h"
2122
#include "CommonFramework/VideoPipeline/Backends/VideoFrameQt.h"
2223
#include "StreamRecorder.h"
2324

@@ -153,9 +154,13 @@ void StreamRecording::internal_run(){
153154
session.setRecorder(&recorder);
154155
recorder.setMediaFormat(QMediaFormat::MPEG4);
155156
// recorder.setQuality(QMediaRecorder::NormalQuality);
156-
recorder.setQuality(QMediaRecorder::LowQuality);
157+
// recorder.setQuality(QMediaRecorder::LowQuality);
157158
// recorder.setQuality(QMediaRecorder::VeryLowQuality);
158159

160+
recorder.setVideoResolution(1280, 720);
161+
recorder.setVideoBitRate(GlobalSettings::instance().STREAM_HISTORY.VIDEO_BITRATE * 1000);
162+
recorder.setEncodingMode(QMediaRecorder::AverageBitRateEncoding);
163+
159164
#ifdef PA_STREAM_HISTORY_LOCAL_BUFFER
160165
recorder.setOutputDevice(&m_write_buffer);
161166
#else
@@ -165,7 +170,8 @@ void StreamRecording::internal_run(){
165170
);
166171
#endif
167172

168-
// cout << "EncodingMode = " << (int)recorder.encodingMode() << endl;
173+
// cout << "Encoding Mode = " << (int)recorder.encodingMode() << endl;
174+
// cout << "Bit Rate = " << (int)recorder.videoBitRate() << endl;
169175

170176
recorder.connect(
171177
&audio_input, &QAudioBufferInput::readyToSendAudioBuffer,

0 commit comments

Comments
 (0)