Skip to content

Commit 7bbd96d

Browse files
committed
Begin reducing dependency on ConsoleHandle in infra.
1 parent a4648f8 commit 7bbd96d

File tree

117 files changed

+1102
-732
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+1102
-732
lines changed

SerialPrograms/Source/CommonFramework/ErrorReports/ErrorReports.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include "CommonFramework/Notifications/ProgramNotifications.h"
1919
#include "CommonFramework/Environment/Environment.h"
2020
#include "CommonFramework/Options/Environment/ThemeSelectorOption.h"
21-
#include "CommonFramework/Tools/ConsoleHandle.h"
21+
#include "CommonFramework/Recording/StreamHistorySession.h"
2222
#include "ProgramDumper.h"
2323
#include "ErrorReports.h"
2424

@@ -114,7 +114,7 @@ SendableErrorReport::SendableErrorReport(
114114
std::string title,
115115
std::vector<std::pair<std::string, std::string>> messages,
116116
const ImageViewRGB32& image,
117-
ConsoleHandle* console
117+
const StreamHistorySession* stream_history
118118
)
119119
: SendableErrorReport()
120120
{
@@ -147,8 +147,8 @@ SendableErrorReport::SendableErrorReport(
147147
file.flush();
148148
m_logs_name = ERROR_LOGS_NAME;
149149
}
150-
if (console){
151-
if (console->save_stream_history(m_directory + "Video.mp4")){
150+
if (stream_history){
151+
if (stream_history->save(m_directory + "Video.mp4")){
152152
m_video_name = "Video.mp4";
153153
}
154154
}
@@ -393,7 +393,7 @@ void report_error(
393393
std::string title,
394394
std::vector<std::pair<std::string, std::string>> messages,
395395
const ImageViewRGB32& image,
396-
ConsoleHandle* console,
396+
const StreamHistorySession* stream_history,
397397
const std::vector<std::string>& files
398398
){
399399
if (logger == nullptr){
@@ -407,7 +407,7 @@ void report_error(
407407
std::move(title),
408408
std::move(messages),
409409
image,
410-
console
410+
stream_history
411411
);
412412

413413
std::vector<std::string> full_file_paths;

SerialPrograms/Source/CommonFramework/ErrorReports/ErrorReports.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace PokemonAutomation{
2121

2222

2323
class AsyncTask;
24-
class ConsoleHandle;
24+
class StreamHistorySession;
2525

2626

2727
extern const std::string& ERROR_LOGS_NAME;
@@ -65,7 +65,7 @@ class SendableErrorReport{
6565
std::string title = "",
6666
std::vector<std::pair<std::string, std::string>> messages = {},
6767
const ImageViewRGB32& image = ImageViewRGB32(),
68-
ConsoleHandle* console = nullptr
68+
const StreamHistorySession* stream_history = nullptr
6969
);
7070

7171
// Deserialize from existing report.
@@ -111,7 +111,7 @@ void report_error(
111111
std::string title = "",
112112
std::vector<std::pair<std::string, std::string>> messages = {},
113113
const ImageViewRGB32& image = ImageViewRGB32(),
114-
ConsoleHandle* console = nullptr,
114+
const StreamHistorySession* stream_history = nullptr,
115115
const std::vector<std::string>& files = {}
116116
);
117117

SerialPrograms/Source/CommonFramework/Exceptions/FatalProgramException.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class FatalProgramException : public ScreenshotException{
2020
: ScreenshotException(
2121
e.m_send_error_report,
2222
std::move(e.m_message),
23-
e.m_console,
23+
e.m_stream,
2424
std::move(e.m_screenshot)
2525
)
2626
{}

SerialPrograms/Source/CommonFramework/Exceptions/OperationFailedException.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,19 @@ class OperationFailedException : public ScreenshotException{
2222
// This is the most common use case. Throw and log exception.
2323
// Include console information for screenshot and stream history.
2424
[[noreturn]] static void fire(
25-
ConsoleHandle& console,
2625
ErrorReport error_report,
27-
std::string message
26+
std::string message,
27+
VideoStream& stream
2828
){
29-
throw_and_log<OperationFailedException>(console, error_report, std::move(message), console);
29+
throw_and_log<OperationFailedException>(stream.logger, error_report, std::move(message), stream);
3030
}
3131
[[noreturn]] static void fire(
32-
ConsoleHandle& console,
3332
ErrorReport error_report,
3433
std::string message,
34+
VideoStream& stream,
3535
std::shared_ptr<const ImageRGB32> screenshot
3636
){
37-
throw_and_log<OperationFailedException>(console, error_report, std::move(message), &console, std::move(screenshot));
37+
throw_and_log<OperationFailedException>(stream.logger, error_report, std::move(message), &stream, std::move(screenshot));
3838
}
3939

4040
virtual const char* name() const override{ return "OperationFailedException"; }

SerialPrograms/Source/CommonFramework/Exceptions/ProgramFinishedException.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,24 @@ ProgramFinishedException::ProgramFinishedException(std::string message)
2121

2222
ProgramFinishedException::ProgramFinishedException(
2323
std::string message,
24-
ConsoleHandle& console
24+
VideoStream& stream
2525
)
26-
: ScreenshotException(ErrorReport::NO_ERROR_REPORT, std::move(message), console)
26+
: ScreenshotException(ErrorReport::NO_ERROR_REPORT, std::move(message), stream)
2727
{}
2828
ProgramFinishedException::ProgramFinishedException(
2929
ErrorReport error_report,
3030
std::string message,
31-
ConsoleHandle* console,
31+
VideoStream* stream,
3232
ImageRGB32 screenshot
3333
)
34-
: ScreenshotException(ErrorReport::NO_ERROR_REPORT, std::move(message), console, std::move(screenshot))
34+
: ScreenshotException(ErrorReport::NO_ERROR_REPORT, std::move(message), stream, std::move(screenshot))
3535
{}
3636
ProgramFinishedException::ProgramFinishedException(
3737
std::string message,
38-
ConsoleHandle* console,
38+
VideoStream* stream,
3939
std::shared_ptr<const ImageRGB32> screenshot
4040
)
41-
: ScreenshotException(ErrorReport::NO_ERROR_REPORT, std::move(message), console, std::move(screenshot))
41+
: ScreenshotException(ErrorReport::NO_ERROR_REPORT, std::move(message), stream, std::move(screenshot))
4242
{}
4343

4444
void ProgramFinishedException::log(Logger& logger) const{

SerialPrograms/Source/CommonFramework/Exceptions/ProgramFinishedException.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class ProgramFinishedException : public ScreenshotException{
3333
// This will take a screenshot and store the console if the stream history if requested later.
3434
explicit ProgramFinishedException(
3535
std::string message,
36-
ConsoleHandle& console
36+
VideoStream& stream
3737
);
3838

3939
// Construct exception with message with screenshot and (optionally) console information.
@@ -42,12 +42,12 @@ class ProgramFinishedException : public ScreenshotException{
4242
explicit ProgramFinishedException(
4343
ErrorReport error_report,
4444
std::string message,
45-
ConsoleHandle* console,
45+
VideoStream* stream,
4646
ImageRGB32 screenshot
4747
);
4848
explicit ProgramFinishedException(
4949
std::string message,
50-
ConsoleHandle* console,
50+
VideoStream* stream,
5151
std::shared_ptr<const ImageRGB32> screenshot
5252
);
5353

SerialPrograms/Source/CommonFramework/Exceptions/ScreenshotException.cpp

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,48 +26,49 @@ ScreenshotException::ScreenshotException(ErrorReport error_report, std::string m
2626
ScreenshotException::ScreenshotException(
2727
ErrorReport error_report,
2828
std::string message,
29-
ConsoleHandle& console
29+
VideoStream& stream
3030
)
31-
: ScreenshotException(error_report, std::move(message))
31+
: m_send_error_report(error_report)
32+
, m_message(std::move(message))
33+
, m_stream(&stream)
34+
, m_screenshot(stream.video.snapshot().frame)
3235
{
33-
m_console = &console;
34-
m_screenshot = console.video().snapshot().frame;
3536
if (m_screenshot == nullptr || !*m_screenshot){
36-
console.log("Camera returned empty screenshot. Is the camera frozen?", COLOR_RED);
37+
stream.logger.log("Camera returned empty screenshot. Is the camera frozen?", COLOR_RED);
3738
}
3839
}
3940
ScreenshotException::ScreenshotException(
4041
ErrorReport error_report,
4142
std::string message,
42-
ConsoleHandle* console,
43+
VideoStream* stream,
4344
ImageRGB32 screenshot
4445
)
45-
: ScreenshotException(error_report, std::move(message))
46-
{
47-
m_console = console;
48-
m_screenshot = std::make_shared<ImageRGB32>(std::move(screenshot));
49-
}
46+
: m_send_error_report(error_report)
47+
, m_message(std::move(message))
48+
, m_stream(stream)
49+
, m_screenshot(std::make_shared<ImageRGB32>(std::move(screenshot)))
50+
{}
5051
ScreenshotException::ScreenshotException(
5152
ErrorReport error_report,
5253
std::string message,
53-
ConsoleHandle* console,
54+
VideoStream* stream,
5455
std::shared_ptr<const ImageRGB32> screenshot
5556
)
56-
: ScreenshotException(error_report, std::move(message))
57-
{
58-
m_console = console;
59-
m_screenshot = std::move(screenshot);
60-
}
57+
: m_send_error_report(error_report)
58+
, m_message(std::move(message))
59+
, m_stream(stream)
60+
, m_screenshot(std::move(screenshot))
61+
{}
6162

6263

63-
void ScreenshotException::add_console_if_needed(ConsoleHandle& console){
64-
if (m_console == nullptr){
65-
m_console = &console;
64+
void ScreenshotException::add_stream_if_needed(VideoStream& stream){
65+
if (m_stream == nullptr){
66+
m_stream = &stream;
6667
}
6768
if (!m_screenshot){
68-
m_screenshot = console.video().snapshot();
69+
m_screenshot = stream.video.snapshot();
6970
if (m_screenshot == nullptr || !*m_screenshot){
70-
console.log("Camera returned empty screenshot. Is the camera frozen?", COLOR_RED);
71+
stream.logger.log("Camera returned empty screenshot. Is the camera frozen?", COLOR_RED);
7172
}
7273
}
7374
}
@@ -94,7 +95,7 @@ void ScreenshotException::send_notification(ProgramEnvironment& env, EventNotifi
9495
name(),
9596
embeds,
9697
screenshot(),
97-
m_console
98+
m_stream ? &m_stream->video_history : nullptr
9899
);
99100
}
100101

SerialPrograms/Source/CommonFramework/Exceptions/ScreenshotException.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ namespace PokemonAutomation{
1515
class ImageViewRGB32;
1616
class ImageRGB32;
1717
class EventNotificationOption;
18+
struct VideoStream;
1819
struct ProgramInfo;
1920
class ProgramEnvironment;
20-
class ConsoleHandle;
2121

2222

2323
enum class ErrorReport{
@@ -40,7 +40,7 @@ class ScreenshotException : public Exception{
4040
explicit ScreenshotException(
4141
ErrorReport error_report,
4242
std::string message,
43-
ConsoleHandle& console
43+
VideoStream& stream
4444
);
4545

4646
// Construct exception with message with screenshot and (optionally) console information.
@@ -49,19 +49,19 @@ class ScreenshotException : public Exception{
4949
explicit ScreenshotException(
5050
ErrorReport error_report,
5151
std::string message,
52-
ConsoleHandle* console,
52+
VideoStream* stream,
5353
ImageRGB32 screenshot
5454
);
5555
explicit ScreenshotException(
5656
ErrorReport error_report,
5757
std::string message,
58-
ConsoleHandle* console,
58+
VideoStream* stream,
5959
std::shared_ptr<const ImageRGB32> screenshot
6060
);
6161

6262
// Add console information if it isn't already requested.
6363
// This will provide screenshot and stream history if requested later.
64-
void add_console_if_needed(ConsoleHandle& console);
64+
void add_stream_if_needed(VideoStream& stream);
6565

6666

6767
public:
@@ -75,7 +75,7 @@ class ScreenshotException : public Exception{
7575
public:
7676
ErrorReport m_send_error_report;
7777
std::string m_message;
78-
ConsoleHandle* m_console = nullptr;
78+
VideoStream* m_stream = nullptr;
7979
std::shared_ptr<const ImageRGB32> m_screenshot;
8080
};
8181

SerialPrograms/Source/CommonFramework/Tools/ConsoleHandle.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,25 +36,27 @@ ConsoleHandle::ConsoleHandle(
3636
AudioFeed& audio,
3737
const StreamHistorySession& history
3838
)
39-
: m_index(index)
40-
, m_logger(logger)
39+
: VideoStream(logger, audio, video, history)
40+
, m_index(index)
41+
// , m_logger(logger)
4142
, m_botbase(botbase)
42-
, m_video(video)
43+
// , m_stream(logger, audio, video, history)
44+
// , m_video(video)
4345
, m_overlay(overlay)
44-
, m_audio(audio)
45-
, m_history(history)
46+
// , m_audio(audio)
47+
// , m_history(history)
4648
, m_thread_utilization(new ThreadUtilizationStat(current_thread_handle(), "Program Thread:"))
4749
{
4850
m_overlay.add_stat(*m_thread_utilization);
4951
}
5052

5153
bool ConsoleHandle::save_stream_history(const std::string& filename){
52-
return m_history.save(filename);
54+
return video_history.save(filename);
5355
}
5456

5557
void ConsoleHandle::initialize_inference_threads(CancellableScope& scope, AsyncDispatcher& dispatcher){
56-
m_video_pivot = std::make_unique<VisualInferencePivot>(scope, m_video, dispatcher);
57-
m_audio_pivot = std::make_unique<AudioInferencePivot>(scope, m_audio, dispatcher);
58+
m_video_pivot = std::make_unique<VisualInferencePivot>(scope, VideoStream::video, dispatcher);
59+
m_audio_pivot = std::make_unique<AudioInferencePivot>(scope, VideoStream::audio, dispatcher);
5860
m_overlay.add_stat(*m_video_pivot);
5961
m_overlay.add_stat(*m_audio_pivot);
6062
}

0 commit comments

Comments
 (0)