Skip to content

Commit ac53418

Browse files
committed
Add stream history for real this time. (still buggy though)
1 parent 9dcdb0c commit ac53418

16 files changed

+673
-30
lines changed

SerialPrograms/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,8 +512,11 @@ file(GLOB MAIN_SOURCES
512512
Source/CommonFramework/Recording/StreamHistorySession.cpp
513513
Source/CommonFramework/Recording/StreamHistorySession.h
514514
Source/CommonFramework/Recording/StreamHistoryTracker_Null.h
515+
Source/CommonFramework/Recording/StreamHistoryTracker_ParallelStreams.h
515516
Source/CommonFramework/Recording/StreamHistoryTracker_RecordOnTheFly.h
516517
Source/CommonFramework/Recording/StreamHistoryTracker_SaveFrames.h
518+
Source/CommonFramework/Recording/StreamRecorder.cpp
519+
Source/CommonFramework/Recording/StreamRecorder.h
517520
Source/CommonFramework/Resources/SpriteDatabase.cpp
518521
Source/CommonFramework/Resources/SpriteDatabase.h
519522
Source/CommonFramework/SetupSettings.cpp

SerialPrograms/SerialPrograms.pro

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ SOURCES += \
272272
Source/CommonFramework/PersistentSettings.cpp \
273273
Source/CommonFramework/ProgramSession.cpp \
274274
Source/CommonFramework/Recording/StreamHistorySession.cpp \
275+
Source/CommonFramework/Recording/StreamRecorder.cpp \
275276
Source/CommonFramework/Resources/SpriteDatabase.cpp \
276277
Source/CommonFramework/SetupSettings.cpp \
277278
Source/CommonFramework/Tools/BlackBorderCheck.cpp \
@@ -1365,6 +1366,7 @@ HEADERS += \
13651366
Source/CommonFramework/Recording/StreamHistorySession.h \
13661367
Source/CommonFramework/Recording/StreamHistoryTracker_RecordOnTheFly.h \
13671368
Source/CommonFramework/Recording/StreamHistoryTracker_SaveFrames.h \
1369+
Source/CommonFramework/Recording/StreamRecorder.h \
13681370
Source/CommonFramework/Resources/SpriteDatabase.h \
13691371
Source/CommonFramework/SetupSettings.h \
13701372
Source/CommonFramework/Tools/BlackBorderCheck.h \

SerialPrograms/Source/CommonFramework/AudioPipeline/AudioStream.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#ifndef PokemonAutomation_AudioPipeline_AudioSourceReader_H
88
#define PokemonAutomation_AudioPipeline_AudioSourceReader_H
99

10+
#include "Common/Cpp/Time.h"
1011
#include "Common/Cpp/StreamConverters.h"
1112
#include "Common/Cpp/Containers/AlignedVector.h"
1213
#include "AudioInfo.h"

SerialPrograms/Source/CommonFramework/ErrorReports/ErrorReports.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ ErrorReportOption::ErrorReportOption()
5757
true
5858
)
5959
, VIDEO(
60-
"<b>Include Video:</b><br>Include a video leading up to the error. (if possible)",
60+
"<b>Include Video:</b><br>Include a video leading up to the error. (if available)",
6161
LockMode::UNLOCK_WHILE_RUNNING,
6262
true
6363
)
@@ -80,9 +80,7 @@ ErrorReportOption::ErrorReportOption()
8080
PA_ADD_STATIC(DESCRIPTION);
8181
PA_ADD_OPTION(SEND_MODE);
8282
PA_ADD_OPTION(SCREENSHOT);
83-
if (PreloadSettings::instance().DEVELOPER_MODE){
84-
PA_ADD_OPTION(VIDEO);
85-
}
83+
PA_ADD_OPTION(VIDEO);
8684
PA_ADD_OPTION(LOGS);
8785
PA_ADD_OPTION(DUMPS);
8886
if (PreloadSettings::instance().DEVELOPER_MODE){
@@ -179,7 +177,7 @@ SendableErrorReport::SendableErrorReport(std::string directory)
179177
const std::string* image_name = obj.get_string("Screenshot");
180178
if (image_name){
181179
try{
182-
m_image_owner = ImageRGB32(*image_name);
180+
m_image_owner = ImageRGB32(m_directory + *image_name);
183181
m_image = m_image_owner;
184182
}catch (FileException&){}
185183
}
@@ -238,9 +236,8 @@ void SendableErrorReport::save(Logger* logger) const{
238236
report["Messages"] = std::move(messages);
239237
}
240238
if (m_image){
241-
std::string image_name = m_directory + "Screenshot.png";
242-
if (m_image.save(image_name)){
243-
report["Screenshot"] = std::move(image_name);
239+
if (m_image.save(m_directory + "Screenshot.png")){
240+
report["Screenshot"] = "Screenshot.png";
244241
}
245242
}
246243
if (!m_video_name.empty()){

SerialPrograms/Source/CommonFramework/GlobalSettingsPanel.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,18 @@ ResolutionOption::ResolutionOption(
5252
}
5353

5454
StreamHistoryOption::StreamHistoryOption()
55-
: GroupOption("Stream History", LockMode::LOCK_WHILE_RUNNING, true, false)
55+
: GroupOption(
56+
"Stream History",
57+
LockMode::LOCK_WHILE_RUNNING,
58+
true,
59+
IS_BETA_VERSION
60+
)
5661
, DESCRIPTION(
57-
"Keep a record of this many seconds of video+audio. This will allow video capture for unexpected events.<br>"
58-
"<font color=\"red\">Warning (Developer Only): The current implementation is inefficient and requires "
59-
"10 GB of ram to store just 30 seconds of video. This feature is still a work-in-progress."
62+
"Keep a record of this many seconds of video+audio. This will allow "
63+
"video capture for unexpected events.<br>"
64+
"<font color=\"orange\">Warning: The current implementation is inefficient "
65+
"and may write a lot of data to disk. "
66+
"This feature is still a work-in-progress."
6067
"</font>"
6168
)
6269
, VIDEO_HISTORY_SECONDS(
@@ -285,10 +292,10 @@ GlobalSettings::GlobalSettings()
285292
#if QT_VERSION_MAJOR == 5
286293
PA_ADD_OPTION(ENABLE_FRAME_SCREENSHOTS);
287294
#endif
288-
#if QT_VERSION_MAJOR >= 6
289-
if (PreloadSettings::instance().DEVELOPER_MODE){
290-
PA_ADD_OPTION(STREAM_HISTORY);
291-
}
295+
#if (QT_VERSION_MAJOR == 6) && (QT_VERSION_MINOR >= 8)
296+
PA_ADD_OPTION(STREAM_HISTORY);
297+
#else
298+
STREAM_HISTORY.set_enabled(false);
292299
#endif
293300

294301
PA_ADD_OPTION(AUTO_RESET_AUDIO_SECONDS);

SerialPrograms/Source/CommonFramework/Globals.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace PokemonAutomation{
2525
const bool IS_BETA_VERSION = true;
2626
const int PROGRAM_VERSION_MAJOR = 0;
2727
const int PROGRAM_VERSION_MINOR = 50;
28-
const int PROGRAM_VERSION_PATCH = 9;
28+
const int PROGRAM_VERSION_PATCH = 10;
2929

3030
const std::string PROGRAM_VERSION_BASE =
3131
"v" + std::to_string(PROGRAM_VERSION_MAJOR) +
@@ -68,6 +68,10 @@ const std::string COMPILER_VERSION = "Unknown Compiler";
6868
#endif
6969

7070

71+
72+
const size_t LOG_HISTORY_LINES = 2000;
73+
74+
7175
namespace{
7276

7377
QString get_application_base_dir_path(){

SerialPrograms/Source/CommonFramework/Globals.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ extern const std::string COMPILER_VERSION;
3333

3434
const auto SERIAL_REFRESH_RATE = std::chrono::milliseconds(1000);
3535

36+
extern const size_t LOG_HISTORY_LINES;
37+
3638
// Folder path (end with "/") to hold program setting files.
3739
const std::string& SETTINGS_PATH();
3840

SerialPrograms/Source/CommonFramework/Logging/FileWindowLogger.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include <QCoreApplication>
88
#include <QMenuBar>
99
#include <QDir>
10-
#include <CommonFramework/Globals.h>
10+
#include "CommonFramework/Globals.h"
1111
#include "CommonFramework/Windows/DpiScaler.h"
1212
#include "CommonFramework/Windows/WindowTracker.h"
1313
#include "FileWindowLogger.h"
@@ -46,7 +46,7 @@ FileWindowLogger::~FileWindowLogger(){
4646
}
4747
FileWindowLogger::FileWindowLogger(const std::string& path)
4848
: m_file(QString::fromStdString(path))
49-
, m_max_queue_size(10000)
49+
, m_max_queue_size(LOG_HISTORY_LINES)
5050
, m_stopping(false)
5151
, m_thread(&FileWindowLogger::thread_loop, this)
5252
{

SerialPrograms/Source/CommonFramework/Recording/StreamHistorySession.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
#include "CommonFramework/VideoPipeline/Backends/VideoFrameQt.h"
1212

1313
#if (QT_VERSION_MAJOR == 6) && (QT_VERSION_MINOR >= 8)
14-
#include "StreamHistoryTracker_SaveFrames.h"
14+
//#include "StreamHistoryTracker_SaveFrames.h"
1515
//#include "StreamHistoryTracker_RecordOnTheFly.h"
16+
#include "StreamHistoryTracker_ParallelStreams.h"
1617
#else
1718
#include "StreamHistoryTracker_Null.h"
1819
#endif
@@ -61,7 +62,7 @@ void StreamHistorySession::start(AudioChannelFormat format){
6162

6263
class HistorySaverThread : public QThread{
6364
public:
64-
HistorySaverThread(Logger& logger, const StreamHistoryTracker& tracker, const std::string& filename)
65+
HistorySaverThread(Logger& logger, StreamHistoryTracker& tracker, const std::string& filename)
6566
: m_logger(logger)
6667
, m_tracker(tracker)
6768
, m_filename(filename)
@@ -78,12 +79,13 @@ class HistorySaverThread : public QThread{
7879
return m_success;
7980
}
8081
virtual void run() override{
81-
m_success = m_tracker.save(m_logger, m_filename);
82+
// m_success = m_tracker.save(m_logger, m_filename);
83+
m_success = m_tracker.save(m_filename);
8284
}
8385

8486
private:
8587
Logger& m_logger;
86-
const StreamHistoryTracker& m_tracker;
88+
StreamHistoryTracker& m_tracker;
8789
const std::string& m_filename;
8890
bool m_success = false;
8991
};
@@ -143,19 +145,19 @@ void StreamHistorySession::initialize(){
143145
switch (data.m_audio_format){
144146
case AudioChannelFormat::NONE:
145147
expected_samples_per_frame = 0;
146-
data.m_current.reset(new StreamHistoryTracker(0, 0, data.m_window));
148+
data.m_current.reset(new StreamHistoryTracker(data.m_logger, 0, 0, data.m_window));
147149
return;
148150
case AudioChannelFormat::MONO_48000:
149-
data.m_current.reset(new StreamHistoryTracker(1, 48000, data.m_window));
151+
data.m_current.reset(new StreamHistoryTracker(data.m_logger, 1, 48000, data.m_window));
150152
return;
151153
case AudioChannelFormat::DUAL_44100:
152-
data.m_current.reset(new StreamHistoryTracker(1, 44100, data.m_window));
154+
data.m_current.reset(new StreamHistoryTracker(data.m_logger, 1, 44100, data.m_window));
153155
return;
154156
case AudioChannelFormat::DUAL_48000:
155157
case AudioChannelFormat::MONO_96000:
156158
case AudioChannelFormat::INTERLEAVE_LR_96000:
157159
case AudioChannelFormat::INTERLEAVE_RL_96000:
158-
data.m_current.reset(new StreamHistoryTracker(2, 48000, data.m_window));
160+
data.m_current.reset(new StreamHistoryTracker(data.m_logger, 2, 48000, data.m_window));
159161
return;
160162
default:
161163
throw InternalProgramError(

SerialPrograms/Source/CommonFramework/Recording/StreamHistoryTracker_Null.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,17 @@ namespace PokemonAutomation{
1919
class StreamHistoryTracker{
2020
public:
2121
StreamHistoryTracker(
22+
Logger& logger,
2223
size_t audio_samples_per_frame,
2324
size_t audio_frames_per_second,
2425
std::chrono::seconds window
25-
){}
26+
)
27+
: m_logger(logger)
28+
{}
2629
void set_window(std::chrono::seconds window){}
2730

28-
bool save(Logger& logger, const std::string& filename) const{
29-
logger.log("Cannot save stream history: Not implemented.", COLOR_RED);
31+
bool save(const std::string& filename) const{
32+
m_logger.log("Cannot save stream history: Not implemented.", COLOR_RED);
3033
return false;
3134
}
3235

@@ -35,6 +38,7 @@ class StreamHistoryTracker{
3538
void on_frame(std::shared_ptr<VideoFrame> frame){}
3639

3740
private:
41+
Logger& m_logger;
3842
};
3943

4044

0 commit comments

Comments
 (0)