Skip to content

Commit

Permalink
Remove redundant calls to "QMediaDevices::videoInputs()" because it's…
Browse files Browse the repository at this point in the history
… slow.
  • Loading branch information
Mysticial committed Sep 28, 2023
1 parent 39bc426 commit cc7fef0
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

#include <QtGlobal>
#include "Common/Cpp/PrettyPrint.h"
#include "CommonFramework/GlobalSettingsPanel.h"
#include "CameraImplementations.h"

Expand Down Expand Up @@ -109,9 +110,12 @@ VideoBackendOption::VideoBackendOption()
std::vector<CameraInfo> get_all_cameras(){
size_t index = GlobalSettings::instance().VIDEO_BACKEND.current_value();
const CameraBackend& backend = *CameraBackends::instance().m_backends[index].backend;
// cout << "Querying camera list..." << endl;
global_logger_tagged().log("Start loading camera list...");
WallClock start = current_time();
std::vector<CameraInfo> ret = backend.get_all_cameras();
// cout << "Done querying camera list..." << endl;
WallClock end = current_time();
double seconds = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() / 1000.;
global_logger_tagged().log("Done loading camera list... " + tostr_fixed(seconds, 3) + " seconds");
return ret;
}
std::string get_camera_name(const CameraInfo& info){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ CameraSelectorWidget::~CameraSelectorWidget(){
CameraSelectorWidget::CameraSelectorWidget(
CameraSession& session,
Logger& logger,
VideoDisplayWidget& holder
VideoDisplayWidget& holder,
std::vector<CameraInfo> starting_camera_list
)
: m_logger(logger)
, m_session(session)
Expand All @@ -45,7 +46,6 @@ CameraSelectorWidget::CameraSelectorWidget(

m_camera_box = new NoWheelComboBox(this);
camera_row->addWidget(m_camera_box, 5);
// update_camera_list();
camera_row->addSpacing(5);

m_resolution_box = new NoWheelComboBox(this);
Expand All @@ -55,7 +55,7 @@ CameraSelectorWidget::CameraSelectorWidget(
m_reset_button = new QPushButton("Reset Camera", this);
camera_row->addWidget(m_reset_button, 1);

update_camera_list();
update_camera_list(std::move(starting_camera_list));
update_resolution_list();

connect(
Expand Down Expand Up @@ -94,10 +94,13 @@ CameraSelectorWidget::CameraSelectorWidget(
m_session.add_listener(*this);
}
void CameraSelectorWidget::update_camera_list(){
update_camera_list(get_all_cameras());
}
void CameraSelectorWidget::update_camera_list(std::vector<CameraInfo> cameras){
m_camera_box->clear();
m_camera_box->addItem("(none)");

m_cameras = get_all_cameras();
m_cameras = std::move(cameras);
CameraInfo info = m_session.current_device();

size_t index = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ class CameraSelectorWidget : public QWidget, public CameraSession::Listener{
CameraSelectorWidget(
CameraSession& session,
Logger& logger,
VideoDisplayWidget& holder
VideoDisplayWidget& holder,
std::vector<CameraInfo> starting_camera_list
);
~CameraSelectorWidget();

private:
void update_camera_list();
void update_camera_list(std::vector<CameraInfo> cameras);
void update_resolution_list();

virtual void shutdown() override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <QVBoxLayout>
#include <QLabel>
#include "Common/Qt/NoWheelComboBox.h"
#include "CommonFramework/VideoPipeline/Backends/CameraImplementations.h"
#include "NintendoSwitch_SwitchSystemWidget.h"
#include "NintendoSwitch_MultiSwitchSystemWidget.h"

Expand Down Expand Up @@ -116,10 +117,18 @@ void MultiSwitchSystemWidget::redraw_videos(size_t count){
vbox->setContentsMargins(0, 0, 0, 0);

// m_option.resize(count);
std::vector<CameraInfo> cameras = get_all_cameras();
for (size_t c = 0; c < m_session.count(); c++){
// const auto& item = m_option.m_switches[c];
// m_switches.emplace_back(item->make_ui(*this, m_logger, m_program_id));
m_switches.emplace_back(new SwitchSystemWidget(*m_videos, m_session[c], m_program_id));
m_switches.emplace_back(
new SwitchSystemWidget(
*m_videos,
m_session[c],
m_program_id,
cameras
)
);
}

QHBoxLayout* vrow0 = new QHBoxLayout();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "CommonFramework/NewVersionCheck.h"
#include "CommonFramework/Panels/PanelTools.h"
#include "CommonFramework/Panels/UI/PanelElements.h"
#include "CommonFramework/VideoPipeline/Backends/CameraImplementations.h"
#include "CommonFramework/Tools/StatsTracking.h"
#include "NintendoSwitch/Framework/NintendoSwitch_SingleSwitchProgramOption.h"
#include "NintendoSwitch_SingleSwitchProgramWidget.h"
Expand Down Expand Up @@ -68,7 +69,12 @@ SingleSwitchProgramWidget2::SingleSwitchProgramWidget2(
QVBoxLayout* scroll_layout = new QVBoxLayout(scroll_inner);
scroll_layout->setAlignment(Qt::AlignTop);

m_system = new SwitchSystemWidget(*this, m_session.system(), m_session.instance_id());
m_system = new SwitchSystemWidget(
*this,
m_session.system(),
m_session.instance_id(),
get_all_cameras()
);
scroll_layout->addWidget(m_system);

m_options = option.options().make_QtWidget(*this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ SwitchSystemWidget::~SwitchSystemWidget(){
SwitchSystemWidget::SwitchSystemWidget(
QWidget& parent,
SwitchSystemSession& session,
uint64_t program_id
uint64_t program_id,
std::vector<CameraInfo> starting_camera_list
)
: QWidget(&parent)
, m_session(session)
Expand Down Expand Up @@ -77,7 +78,12 @@ SwitchSystemWidget::SwitchSystemWidget(
);
video_holder->addWidget(m_video_display);

m_camera_widget = new CameraSelectorWidget(m_session.camera_session(), m_session.logger(), *m_video_display);
m_camera_widget = new CameraSelectorWidget(
m_session.camera_session(),
m_session.logger(),
*m_video_display,
std::move(starting_camera_list)
);
group_layout->addWidget(m_camera_widget);

m_audio_widget = new AudioSelectorWidget(*widget, m_session.logger(), m_session.audio_session());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ class SwitchSystemWidget final : public QWidget, public CommandReceiver{
SwitchSystemWidget(
QWidget& parent,
SwitchSystemSession& session,
uint64_t program_id
uint64_t program_id,
std::vector<CameraInfo> starting_camera_list
);

public:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <QScrollArea>
#include "Common/Cpp/Json/JsonValue.h"
#include "Common/Qt/CollapsibleGroupBox.h"
#include "CommonFramework/VideoPipeline/Backends/CameraImplementations.h"
#include "NintendoSwitch/Framework/UI/NintendoSwitch_SwitchSystemWidget.h"
#include "NintendoSwitch_VirtualConsole.h"

Expand Down Expand Up @@ -76,7 +77,7 @@ void VirtualConsole_Widget::construct(){
QVBoxLayout* scroll_layout = new QVBoxLayout(scroll_inner);
scroll_layout->setAlignment(Qt::AlignTop);

m_switch = new SwitchSystemWidget(*this, m_session, 0);
m_switch = new SwitchSystemWidget(*this, m_session, 0, get_all_cameras());
scroll_layout->addWidget(m_switch);
}

Expand Down

0 comments on commit cc7fef0

Please sign in to comment.