Simplified v4l2loopback system

This commit is contained in:
brunoherbelin
2020-11-10 20:27:03 +01:00
parent ea1192c334
commit 39f8b56c99
5 changed files with 27 additions and 15 deletions

View File

@@ -124,7 +124,7 @@ void ImGuiToolkit::Icon(int i, int j)
ImGui::Image((void*)(intptr_t)textureicons, ImVec2(ImGui::GetTextLineHeightWithSpacing(), ImGui::GetTextLineHeightWithSpacing()), uv0, uv1); ImGui::Image((void*)(intptr_t)textureicons, ImVec2(ImGui::GetTextLineHeightWithSpacing(), ImGui::GetTextLineHeightWithSpacing()), uv0, uv1);
} }
bool ImGuiToolkit::ButtonIcon(int i, int j) bool ImGuiToolkit::ButtonIcon(int i, int j, const char *tooltip)
{ {
// icons.dds is a 20 x 20 grid of icons // icons.dds is a 20 x 20 grid of icons
if (textureicons == 0) if (textureicons == 0)
@@ -137,6 +137,13 @@ bool ImGuiToolkit::ButtonIcon(int i, int j)
bool ret = ImGui::ImageButton((void*)(intptr_t)textureicons, ImVec2(ImGui::GetTextLineHeightWithSpacing(),ImGui::GetTextLineHeightWithSpacing()), uv0, uv1, 3); bool ret = ImGui::ImageButton((void*)(intptr_t)textureicons, ImVec2(ImGui::GetTextLineHeightWithSpacing(),ImGui::GetTextLineHeightWithSpacing()), uv0, uv1, 3);
ImGui::PopID(); ImGui::PopID();
if (tooltip != nullptr && ImGui::IsItemHovered())
{
ImGui::BeginTooltip();
ImGui::Text("%s", tooltip);
ImGui::EndTooltip();
}
return ret; return ret;
} }

View File

@@ -15,7 +15,7 @@ namespace ImGuiToolkit
void ShowIconsWindow(bool* p_open); void ShowIconsWindow(bool* p_open);
// utility buttons // utility buttons
bool ButtonIcon (int i, int j); bool ButtonIcon (int i, int j, const char* tooltip = nullptr);
bool ButtonIconToggle (int i, int j, int i_toggle, int j_toggle, bool* toggle); bool ButtonIconToggle (int i, int j, int i_toggle, int j_toggle, bool* toggle);
bool ButtonIconMultistate (std::vector<std::pair<int, int> > icons, int* state); bool ButtonIconMultistate (std::vector<std::pair<int, int> > icons, int* state);
bool ButtonToggle(const char* label, bool* toggle); bool ButtonToggle(const char* label, bool* toggle);

View File

@@ -55,7 +55,7 @@ bool Loopback::system_loopback_initialized = false;
* Useful command lines for debug * Useful command lines for debug
* $ v4l2-ctl --all -d 10 * $ v4l2-ctl --all -d 10
* $ gst-launch-1.0 v4l2src device=/dev/video10 ! videoconvert ! autovideosink * $ gst-launch-1.0 v4l2src device=/dev/video10 ! videoconvert ! autovideosink
* $ gst-launch-1.0 videotestsrc ! v4l2sink device=/dev/video1 * $ gst-launch-1.0 videotestsrc ! v4l2sink device=/dev/video10
*/ */
#include <stdio.h> #include <stdio.h>
@@ -64,7 +64,7 @@ bool Loopback::system_loopback_initialized = false;
#include <unistd.h> #include <unistd.h>
std::string Loopback::system_loopback_name = "/dev/video10"; std::string Loopback::system_loopback_name = "/dev/video10";
std::string Loopback::system_loopback_pipeline = "appsrc name=src ! videoconvert ! v4l2sink sync=false name=sink"; std::string Loopback::system_loopback_pipeline = "appsrc name=src ! videoconvert ! queue ! v4l2sink sync=false name=sink";
bool Loopback::initializeSystemLoopback() bool Loopback::initializeSystemLoopback()
{ {
@@ -87,6 +87,7 @@ bool Loopback::initializeSystemLoopback()
// create command line for installing v4l2loopback // create command line for installing v4l2loopback
std::string cmdline = "export SUDO_ASKPASS=\"" + sudoscript + "\"\n"; std::string cmdline = "export SUDO_ASKPASS=\"" + sudoscript + "\"\n";
cmdline += "sudo -A apt install v4l2loopback-dkms 2>&1\n"; cmdline += "sudo -A apt install v4l2loopback-dkms 2>&1\n";
cmdline += "sudo -A modprobe -r v4l2loopback 2>&1\n";
cmdline += "sudo -A modprobe v4l2loopback exclusive_caps=1 video_nr=10 card_label=\"vimix loopback\" 2>&1\n"; cmdline += "sudo -A modprobe v4l2loopback exclusive_caps=1 video_nr=10 card_label=\"vimix loopback\" 2>&1\n";
// execute v4l2 command line // execute v4l2 command line

View File

@@ -1314,22 +1314,26 @@ void UserInterface::RenderPreview()
static char dummy_str[512]; static char dummy_str[512];
sprintf(dummy_str, "sudo apt install v4l2loopback-dkms"); sprintf(dummy_str, "sudo apt install v4l2loopback-dkms");
ImGui::SetNextItemWidth(w + 20); ImGui::Text("Install v4l2loopack:");
ImGui::InputText("##cmd1", dummy_str, IM_ARRAYSIZE(dummy_str), ImGuiInputTextFlags_ReadOnly); ImGui::InputText("##cmd1", dummy_str, IM_ARRAYSIZE(dummy_str), ImGuiInputTextFlags_ReadOnly);
ImGui::SameLine();
ImGui::PushID(358794);
if ( ImGuiToolkit::ButtonIcon(3,6, "Copy to clipboard") )
ImGui::SetClipboardText(dummy_str);
ImGui::PopID();
sprintf(dummy_str, "sudo modprobe v4l2loopback exclusive_caps=1 video_nr=10 card_label=\"vimix loopback\""); sprintf(dummy_str, "sudo modprobe v4l2loopback exclusive_caps=1 video_nr=10 card_label=\"vimix loopback\"");
ImGui::SetNextItemWidth(w + 20); ImGui::Text("Initialize v4l2loopack:");
ImGui::InputText("##cmd2", dummy_str, IM_ARRAYSIZE(dummy_str), ImGuiInputTextFlags_ReadOnly); ImGui::InputText("##cmd2", dummy_str, IM_ARRAYSIZE(dummy_str), ImGuiInputTextFlags_ReadOnly);
ImGui::SameLine();
ImGui::PushID(899872);
if ( ImGuiToolkit::ButtonIcon(3,6, "Copy to clipboard") )
ImGui::SetClipboardText(dummy_str);
ImGui::PopID();
ImGui::Separator(); ImGui::Separator();
if (ImGui::Button("Cancel, I'll do it.\n(try again later)", ImVec2(w/2, 0))) { ImGui::CloseCurrentPopup(); }
ImGui::SameLine();
ImGui::SetItemDefaultFocus(); ImGui::SetItemDefaultFocus();
if (ImGui::Button("Ok, let vimix try.\n(sudo password required)", ImVec2(w/2, 0)) ) { if (ImGui::Button("Ok, I'll do it and try again later.", ImVec2(w, 0)) ) {
if (Loopback::initializeSystemLoopback()) {
FrameGrabber *fg = new Loopback;
webcam_emulator_ = fg->id();
FrameGrabbing::manager().add(fg);
}
ImGui::CloseCurrentPopup(); ImGui::CloseCurrentPopup();
} }