Skip to content

Commit 27ab6be

Browse files
committed
Allow refreshing usb devices
1 parent 496cb6f commit 27ab6be

File tree

11 files changed

+53
-35
lines changed

11 files changed

+53
-35
lines changed

3rd/flint_gui

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.20)
33
# This should go before project declaration.
44
if (WIN32)
55
message("[aviateur] <${VCPKG_ROOT}> should be the vcpkg dir in which you have installed the dependency libs.")
6-
set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake")
6+
set(CMAKE_TOOLCHAIN_FILE "D:/Dev/vcpkg/scripts/buildsystems/vcpkg.cmake")
77
endif ()
88

99
project(aviateur
@@ -27,7 +27,7 @@ file(GLOB_RECURSE SRC_LIST
2727
src/*.h
2828
)
2929

30-
file(COPY gs.key openipc-logo-white.svg DESTINATION ${CMAKE_BINARY_DIR})
30+
file(COPY gs.key assets DESTINATION ${CMAKE_BINARY_DIR})
3131

3232
add_executable(${PROJECT_NAME} ${SRC_LIST})
3333

assets/COPYRIGHT.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Some icons are from [Godot](https://github.com/godotengine/godot).

assets/CaptureImage.svg

Lines changed: 1 addition & 0 deletions
Loading

assets/FPS.svg

Lines changed: 1 addition & 0 deletions
Loading

assets/RecordVideo.svg

Lines changed: 1 addition & 0 deletions
Loading

assets/Refresh.svg

Lines changed: 1 addition & 0 deletions
Loading
File renamed without changes.

src/gui_interface.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ class GuiInterface {
190190
std::vector<toolkit::AnyCallable<void>> rtpStreamCallbacks;
191191
std::vector<toolkit::AnyCallable<void>> bitrateUpdateCallbacks;
192192
std::vector<toolkit::AnyCallable<void>> decoderReadyCallbacks;
193+
std::vector<toolkit::AnyCallable<void>> dongleUpdateCallbacks;
193194

194195
void EmitLog(LogLevel level, std::string msg) {
195196
for (auto &callback : logCallbacks) {
@@ -269,4 +270,14 @@ class GuiInterface {
269270
}
270271
}
271272
}
273+
274+
void EmitDongleUpdate() {
275+
for (auto &callback : dongleUpdateCallbacks) {
276+
try {
277+
callback.operator()<>();
278+
} catch (std::bad_any_cast &) {
279+
Instance().PutLog(LogLevel::Error, "Mismatched signal argument types!");
280+
}
281+
}
282+
}
272283
};

src/main.cpp

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class MyRenderRect : public Flint::TextureRect {
119119
auto vbox = std::make_shared<Flint::VBoxContainer>();
120120
collapse_panel_->add_child(vbox);
121121

122-
logo_ = std::make_shared<Flint::VectorImage>("openipc-logo-white.svg");
122+
logo_ = std::make_shared<Flint::VectorImage>("assets/openipc-logo-white.svg");
123123
texture = logo_;
124124

125125
auto render_server = Flint::RenderServer::get_singleton();
@@ -187,6 +187,8 @@ class MyRenderRect : public Flint::TextureRect {
187187
auto capture_button = std::make_shared<Flint::Button>();
188188
vbox->add_child(capture_button);
189189
capture_button->set_text("Capture Frame");
190+
auto icon = std::make_shared<Flint::VectorImage>("assets/CaptureImage.svg");
191+
capture_button->set_icon_normal(icon);
190192
auto capture_callback = [this] {
191193
auto output_file = player_->captureJpeg();
192194
if (output_file.empty()) {
@@ -199,6 +201,8 @@ class MyRenderRect : public Flint::TextureRect {
199201

200202
auto record_button = std::make_shared<Flint::Button>();
201203
vbox->add_child(record_button);
204+
auto icon2 = std::make_shared<Flint::VectorImage>("assets/RecordVideo.svg");
205+
record_button->set_icon_normal(icon2);
202206
record_button->set_text("Record MP4");
203207

204208
auto record_button_raw = record_button.get();
@@ -322,7 +326,7 @@ class MyRenderRect : public Flint::TextureRect {
322326
void custom_update(double delta) override {
323327
player_->update(delta);
324328

325-
hw_status_label_->set_text("Hw Acc: " + std::string(player_->isHardwareAccelerated() ? "ON" : "OFF"));
329+
hw_status_label_->set_text("Hw Decoding: " + std::string(player_->isHardwareAccelerated() ? "ON" : "OFF"));
326330

327331
display_fps_label_->set_text("Display FPS: " + std::to_string(Flint::Engine::get_singleton()->get_fps_int()));
328332

@@ -384,24 +388,29 @@ class MyControlPanel : public Flint::Panel {
384388
std::shared_ptr<Flint::MenuButton> dongle_menu_button_;
385389
std::shared_ptr<Flint::MenuButton> channel_button_;
386390
std::shared_ptr<Flint::MenuButton> channel_width_button_;
391+
std::shared_ptr<Flint::Button> refresh_dongle_button_;
387392

388-
std::string vidPid = "";
393+
std::string vidPid;
389394
int channel = 173;
390395
int channelWidthMode = 0;
391396
std::string keyPath = DEFAULT_KEY_NAME;
392397
std::string codec = "AUTO";
393398

394399
std::shared_ptr<Flint::Button> play_button_;
395400

396-
void update_dongle_list(Flint::PopupMenu &menu) {
401+
void update_dongle_list() {
402+
auto menu = dongle_menu_button_->get_popup_menu().lock();
403+
397404
auto dongles = GuiInterface::GetDongleList();
398405

406+
menu->clear_items();
407+
399408
bool previous_device_exists = false;
400-
for (auto dongle : dongles) {
409+
for (const auto& dongle : dongles) {
401410
if (vidPid == dongle) {
402411
previous_device_exists = true;
403412
}
404-
menu.create_item(dongle);
413+
menu->create_item(dongle);
405414
}
406415

407416
if (!previous_device_exists) {
@@ -458,12 +467,19 @@ class MyControlPanel : public Flint::Panel {
458467
dongle_menu_button_->container_sizing.flag_h = Flint::ContainerSizingFlag::Fill;
459468
hbox_container->add_child(dongle_menu_button_);
460469

461-
auto dongle_menu = dongle_menu_button_->get_popup_menu();
462-
463470
auto callback = [this](uint32_t) { vidPid = dongle_menu_button_->get_selected_item_text(); };
464471
dongle_menu_button_->connect_signal("item_selected", callback);
465472

466-
update_dongle_list(*dongle_menu.lock());
473+
update_dongle_list();
474+
475+
refresh_dongle_button_ = std::make_shared<Flint::Button>();
476+
auto icon = std::make_shared<Flint::VectorImage>("assets/Refresh.svg");
477+
refresh_dongle_button_->set_icon_normal(icon);
478+
refresh_dongle_button_->set_text("");
479+
hbox_container->add_child(refresh_dongle_button_);
480+
481+
auto callback2 = [this]() { update_dongle_list(); };
482+
refresh_dongle_button_->connect_signal("pressed", callback2);
467483
}
468484

469485
{
@@ -605,6 +621,9 @@ int main() {
605621
// Redirect standard output to a file
606622
freopen("last_run_log.txt", "w", stdout);
607623

624+
// Initialize the default libusb context.
625+
int rc = libusb_init(NULL);
626+
608627
Flint::Logger::set_module_level("Aviateur", Flint::Logger::Level::Info);
609628

610629
auto logCallback = [](LogLevel level, std::string msg) {
@@ -677,5 +696,7 @@ int main() {
677696

678697
delete app;
679698

699+
libusb_exit(NULL);
700+
680701
return EXIT_SUCCESS;
681702
}

src/wifi/WFBReceiver.cpp

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
std::vector<std::string> WFBReceiver::GetDongleList() {
2222
std::vector<std::string> list;
2323

24-
libusb_context *find_ctx;
2524
// Initialize libusb
25+
libusb_context *find_ctx;
2626
libusb_init(&find_ctx);
2727

2828
// Get list of USB devices
@@ -88,25 +88,6 @@ bool WFBReceiver::Start(const std::string &vidPid, uint8_t channel, int channelW
8888

8989
auto logger = std::make_shared<Logger>();
9090

91-
auto logCallback = [logger](LogLevel level, const std::string &msg) {
92-
switch (level) {
93-
case LogLevel::Info: {
94-
logger->info(msg);
95-
} break;
96-
case LogLevel::Debug: {
97-
logger->debug(msg);
98-
} break;
99-
case LogLevel::Warn: {
100-
logger->warn(msg);
101-
} break;
102-
case LogLevel::Error: {
103-
logger->error(msg);
104-
} break;
105-
default:;
106-
}
107-
};
108-
// GuiInterface::Instance().logCallbacks.emplace_back(logCallback);
109-
11091
int rc = libusb_init(&ctx);
11192
if (rc < 0) {
11293
GuiInterface::Instance().PutLog(LogLevel::Error, "Failed to initialize libusb");
@@ -118,7 +99,7 @@ bool WFBReceiver::Start(const std::string &vidPid, uint8_t channel, int channelW
11899
devHandle = libusb_open_device_with_vid_pid(ctx, wifiDeviceVid, wifiDevicePid);
119100
if (devHandle == nullptr) {
120101
GuiInterface::Instance().PutLog(LogLevel::Error,
121-
"Cannot find device {:04x}:{:04x}",
102+
"Cannot open device {:04x}:{:04x}",
122103
wifiDeviceVid,
123104
wifiDevicePid);
124105
libusb_exit(ctx);
@@ -137,7 +118,7 @@ bool WFBReceiver::Start(const std::string &vidPid, uint8_t channel, int channelW
137118
return false;
138119
}
139120

140-
usbThread = std::make_shared<std::thread>([=]() {
121+
usbThread = std::make_shared<std::thread>([=, this]() {
141122
WiFiDriver wifi_driver{logger};
142123
try {
143124
rtlDevice = wifi_driver.CreateRtlDevice(devHandle);
@@ -161,7 +142,7 @@ bool WFBReceiver::Start(const std::string &vidPid, uint8_t channel, int channelW
161142
GuiInterface::Instance().PutLog(LogLevel::Error, "Failed to release interface");
162143
}
163144

164-
logger->info("USB thread stopped");
145+
GuiInterface::Instance().PutLog(LogLevel::Info, "USB thread stopped");
165146

166147
libusb_close(devHandle);
167148
libusb_exit(ctx);

0 commit comments

Comments
 (0)