Skip to content

Commit d5113e2

Browse files
committed
Still image video source.
1 parent dcbdb38 commit d5113e2

20 files changed

+481
-65
lines changed

SerialPrograms/CMakeLists.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -493,10 +493,12 @@ file(GLOB MAIN_SOURCES
493493
Source/CommonFramework/VideoPipeline/VideoSource.h
494494
Source/CommonFramework/VideoPipeline/VideoSourceDescriptor.cpp
495495
Source/CommonFramework/VideoPipeline/VideoSourceDescriptor.h
496-
Source/CommonFramework/VideoPipeline/VideoSource_Camera.cpp
497-
Source/CommonFramework/VideoPipeline/VideoSource_Camera.h
498-
Source/CommonFramework/VideoPipeline/VideoSource_Null.cpp
499-
Source/CommonFramework/VideoPipeline/VideoSource_Null.h
496+
Source/CommonFramework/VideoPipeline/VideoSources/VideoSource_Camera.cpp
497+
Source/CommonFramework/VideoPipeline/VideoSources/VideoSource_Camera.h
498+
Source/CommonFramework/VideoPipeline/VideoSources/VideoSource_Null.cpp
499+
Source/CommonFramework/VideoPipeline/VideoSources/VideoSource_Null.h
500+
Source/CommonFramework/VideoPipeline/VideoSources/VideoSource_StillImage.cpp
501+
Source/CommonFramework/VideoPipeline/VideoSources/VideoSource_StillImage.h
500502
Source/CommonFramework/Windows/ButtonDiagram.cpp
501503
Source/CommonFramework/Windows/ButtonDiagram.h
502504
Source/CommonFramework/Windows/DpiScaler.cpp

SerialPrograms/Source/CommonFramework/AudioPipeline/UI/AudioSelectorWidget.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
#include "AudioSelectorWidget.h"
1818
#include "CommonFramework/GlobalSettingsPanel.h"
1919

20-
#include <iostream>
21-
using std::cout;
22-
using std::endl;
20+
//#include <iostream>
21+
//using std::cout;
22+
//using std::endl;
2323

2424
namespace PokemonAutomation{
2525

@@ -105,7 +105,7 @@ AudioSelectorWidget::AudioSelectorWidget(QWidget& parent, AudioSession& session)
105105
if (index <= 0 || index >= (int)m_input_audios.size() + 2){
106106
m_session.clear_audio_input();
107107
}else if (index == 1){
108-
std::string path = QFileDialog::getOpenFileName(this, tr("Open audio file"), ".", "*.wav *.mp3").toStdString();
108+
std::string path = QFileDialog::getOpenFileName(this, "Open audio file", ".", "*.wav *.mp3").toStdString();
109109
if (path.empty()){
110110
m_session.clear_audio_input();
111111
}else{

SerialPrograms/Source/CommonFramework/VideoPipeline/Backends/CameraWidgetQt6.5.cpp

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ CameraVideoSource::CameraVideoSource(
9191
const CameraInfo& info,
9292
Resolution desired_resolution
9393
)
94-
: m_logger(logger)
94+
: VideoSource(true)
95+
, m_logger(logger)
9596
, m_last_image_timestamp(WallClock::min())
9697
, m_stats_conversion("ConvertFrame", "ms", 1000, std::chrono::seconds(10))
9798
, m_last_frame_seqnum(0)
@@ -205,15 +206,6 @@ void CameraVideoSource::set_video_output(QGraphicsVideoItem& item){
205206

206207

207208

208-
Resolution CameraVideoSource::current_resolution() const{
209-
// No to lock since it doesn't change after construction.
210-
return m_resolution;
211-
}
212-
std::vector<Resolution> CameraVideoSource::supported_resolutions() const{
213-
// No to lock since it doesn't change after construction.
214-
return m_resolutions;
215-
}
216-
217209
VideoSnapshot CameraVideoSource::snapshot(){
218210
// This will be coming in from random threads. (not the main thread)
219211
// So we efficiently grab the last frame to unblock the main thread.
@@ -263,7 +255,7 @@ VideoSnapshot CameraVideoSource::snapshot(){
263255
return VideoSnapshot(m_last_image, m_last_image_timestamp);
264256
}
265257

266-
QWidget* CameraVideoSource::make_QtWidget(QWidget* parent){
258+
QWidget* CameraVideoSource::make_display_QtWidget(QWidget* parent){
267259
return new CameraVideoDisplay(parent, *this);
268260
}
269261

SerialPrograms/Source/CommonFramework/VideoPipeline/Backends/CameraWidgetQt6.5.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,16 @@ class CameraVideoSource : public QObject, public VideoSource{
109109
Resolution desired_resolution
110110
);
111111

112-
virtual Resolution current_resolution() const override;
113-
virtual std::vector<Resolution> supported_resolutions() const override;
112+
virtual Resolution current_resolution() const override{
113+
return m_resolution;
114+
}
115+
virtual const std::vector<Resolution>& supported_resolutions() const override{
116+
return m_resolutions;
117+
}
114118

115119
virtual VideoSnapshot snapshot() override;
116120

117-
virtual QWidget* make_QtWidget(QWidget* parent) override;
121+
virtual QWidget* make_display_QtWidget(QWidget* parent) override;
118122

119123
private:
120124
void set_video_output(QGraphicsVideoItem& item);

SerialPrograms/Source/CommonFramework/VideoPipeline/Backends/CameraWidgetQt6.cpp

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ CameraVideoSource::CameraVideoSource(
8484
const CameraInfo& info,
8585
Resolution desired_resolution
8686
)
87-
: m_logger(logger)
87+
: VideoSource(true)
88+
, m_logger(logger)
8889
, m_last_image_timestamp(WallClock::min())
8990
, m_stats_conversion("ConvertFrame", "ms", 1000, std::chrono::seconds(10))
9091
, m_last_frame_seqnum(0)
@@ -174,15 +175,6 @@ CameraVideoSource::CameraVideoSource(
174175
m_camera->start();
175176
}
176177

177-
Resolution CameraVideoSource::current_resolution() const{
178-
// No to lock since it doesn't change after construction.
179-
return m_resolution;
180-
}
181-
std::vector<Resolution> CameraVideoSource::supported_resolutions() const{
182-
// No to lock since it doesn't change after construction.
183-
return m_resolutions;
184-
}
185-
186178
VideoSnapshot CameraVideoSource::snapshot(){
187179
// Prevent multiple concurrent screenshots from entering here.
188180
std::lock_guard<std::mutex> lg(m_snapshot_lock);
@@ -229,7 +221,7 @@ VideoSnapshot CameraVideoSource::snapshot(){
229221
return VideoSnapshot(m_last_image, m_last_image_timestamp);
230222
}
231223

232-
QWidget* CameraVideoSource::make_QtWidget(QWidget* parent){
224+
QWidget* CameraVideoSource::make_display_QtWidget(QWidget* parent){
233225
return new CameraVideoDisplay(parent, *this);
234226
}
235227

SerialPrograms/Source/CommonFramework/VideoPipeline/Backends/CameraWidgetQt6.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,16 @@ class CameraVideoSource : public QObject, public VideoSource{
5656
Resolution desired_resolution
5757
);
5858

59-
virtual Resolution current_resolution() const override;
60-
virtual std::vector<Resolution> supported_resolutions() const override;
59+
virtual Resolution current_resolution() const override{
60+
return m_resolution;
61+
}
62+
virtual const std::vector<Resolution>& supported_resolutions() const override{
63+
return m_resolutions;
64+
}
6165

6266
virtual VideoSnapshot snapshot() override;
6367

64-
virtual QWidget* make_QtWidget(QWidget* parent) override;
68+
virtual QWidget* make_display_QtWidget(QWidget* parent) override;
6569

6670
private:
6771
// void set_video_output(QGraphicsVideoItem& item);

SerialPrograms/Source/CommonFramework/VideoPipeline/UI/VideoDisplayWidget.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ VideoDisplayWidget::VideoDisplayWidget(
4242

4343
VideoSource* source = video_session.current_source();
4444
if (source){
45-
m_video = source->make_QtWidget(this);
45+
m_video = source->make_display_QtWidget(this);
4646
this->add_widget(*m_video);
4747
}
4848

@@ -136,7 +136,7 @@ void VideoDisplayWidget::clear_video_source(){
136136
void VideoDisplayWidget::post_startup(VideoSource* source){
137137
clear_video_source();
138138
if (source){
139-
m_video = source->make_QtWidget(this);
139+
m_video = source->make_display_QtWidget(this);
140140
this->add_widget(*m_video);
141141
set_aspect_ratio(source->current_resolution().aspect_ratio());
142142
m_overlay->raise();

SerialPrograms/Source/CommonFramework/VideoPipeline/UI/VideoSourceSelectorWidget.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
#include "CommonFramework/VideoPipeline/Backends/CameraImplementations.h"
1313
#include "VideoSourceSelectorWidget.h"
1414

15-
#include "CommonFramework/VideoPipeline/VideoSource_Null.h"
16-
#include "CommonFramework/VideoPipeline/VideoSource_Camera.h"
15+
#include "CommonFramework/VideoPipeline/VideoSources/VideoSource_Null.h"
16+
#include "CommonFramework/VideoPipeline/VideoSources/VideoSource_StillImage.h"
17+
#include "CommonFramework/VideoPipeline/VideoSources/VideoSource_Camera.h"
1718

1819
//#include <iostream>
1920
//using std::cout;
@@ -55,6 +56,7 @@ VideoSourceSelectorWidget::VideoSourceSelectorWidget(Logger& logger, VideoSessio
5556
m_sources_box, static_cast<void(QComboBox::*)(int)>(&QComboBox::activated),
5657
this, [this](int index){
5758
if (0 <= index && index < (int)m_sources.size()){
59+
m_sources[index]->run_post_select();
5860
m_session.set_source(m_sources[index]);
5961
}else{
6062
m_session.set_source(std::make_unique<VideoSourceDescriptor_Null>());
@@ -90,8 +92,16 @@ void VideoSourceSelectorWidget::update_source_list(){
9092
m_sources.clear();
9193

9294
std::shared_ptr<const VideoSourceDescriptor> current_descriptor = m_session.descriptor();
93-
m_sources.emplace_back(std::make_unique<VideoSourceDescriptor_Null>());
9495

96+
// Add all the static options.
97+
{
98+
VideoSourceOption option;
99+
m_session.get(option);
100+
m_sources.emplace_back(option.get_descriptor_from_cache(VideoSourceType::None));
101+
m_sources.emplace_back(option.get_descriptor_from_cache(VideoSourceType::StillImage));
102+
}
103+
104+
// Now add all the cameras.
95105
for (const CameraInfo& info : get_all_cameras()){
96106
m_sources.emplace_back(std::make_unique<VideoSourceDescriptor_Camera>(info));
97107
}

SerialPrograms/Source/CommonFramework/VideoPipeline/UI/VideoSourceSelectorWidget.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class VideoSourceSelectorWidget : public QWidget, public VideoSession::StateList
3939
QComboBox* m_resolution_box;
4040
QPushButton* m_reset_button;
4141

42-
std::vector<std::shared_ptr<const VideoSourceDescriptor>> m_sources;
42+
std::vector<std::shared_ptr<VideoSourceDescriptor>> m_sources;
4343
std::vector<Resolution> m_resolutions;
4444

4545
};

SerialPrograms/Source/CommonFramework/VideoPipeline/VideoSession.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include "CommonFramework/GlobalServices.h"
1010
#include "CommonFramework/VideoPipeline/VideoPipelineOptions.h"
1111
#include "Backends/VideoFrameQt.h"
12-
#include "VideoSource_Null.h"
12+
#include "VideoSources/VideoSource_Null.h"
1313
#include "VideoSession.h"
1414

1515
//#include <iostream>
@@ -119,7 +119,7 @@ void VideoSession::reset(){
119119
);
120120
});
121121
}
122-
void VideoSession::set_source(const std::shared_ptr<const VideoSourceDescriptor>& device){
122+
void VideoSession::set_source(const std::shared_ptr<VideoSourceDescriptor>& device){
123123
m_logger.log("Changing video...", COLOR_GREEN);
124124
dispatch_to_main_thread([this, device]{
125125
std::lock_guard<std::mutex> lg0(m_reset_lock);
@@ -225,7 +225,7 @@ void VideoSession::on_rendered_frame(WallClock timestamp){
225225
void VideoSession::on_watchdog_timeout(){
226226
{
227227
ReadSpinLock lg(m_state_lock);
228-
if (!m_video_source){
228+
if (!m_video_source || !m_video_source->allow_watchdog_reset()){
229229
return;
230230
}
231231
}

0 commit comments

Comments
 (0)