Ver código fonte

Support side by side display.

jcsyshc 2 anos atrás
pai
commit
27d5136183

+ 1 - 1
data/sophiar_config.json

@@ -260,7 +260,7 @@
       "type": "ndi_interface",
       "name": "ndi",
       "init_config": {
-        "address_type": "serial",
+        "address_type": "ethernet",
         "ip": "10.0.0.5",
         "tcp_port": 8765,
         "com_port": "/dev/ttyUSB0",

+ 2 - 1
src/frame_sender/sender_tcp.cpp

@@ -65,7 +65,8 @@ struct sender_tcp::impl {
         }
 
         q_this->log_frame_sent(frame->frame_id);
-        SPDLOG_TRACE("Frame {} sent.", frame->frame_id);
+        SPDLOG_TRACE("Frame {} sent, length = {}",
+                     frame->frame_id, frame->length);
     }
 
     void async_waiting_client() {

+ 16 - 6
src/main_ext.cpp

@@ -94,6 +94,7 @@ std::unique_ptr<vtk_viewer> augment_viewer;
 
 std::unique_ptr<std::thread> encoder_thread;
 bool output_full_frame = false;
+bool output_halve_width = false;
 int output_width = -1, output_height = -1;
 encoder_type chosen_encoder = ENCODER_JPEG;
 nvenc_config main_nvenc_conf;
@@ -905,6 +906,10 @@ void prepare_imgui_frame() {
                 if (ImGui::Button("Close")) {
                     simple_eq.emplace(stop_encoder);
                 }
+                ImGui::SameLine();
+                if (ImGui::Button("Request IDR")) {
+                    simple_eq.emplace([] { mq().update_variable(REQUEST_IDR, true); });
+                }
             }
 
             ImGui::SeparatorText("Configs");
@@ -929,7 +934,11 @@ void prepare_imgui_frame() {
             {
                 auto guard = imgui_disable_guard{is_encoding()};
                 ImGui::Checkbox("Full Resolution", &output_full_frame);
-                ImGui::SameLine();
+                if (!output_full_frame) {
+                    ImGui::SameLine();
+                    ImGui::Checkbox("Halve Width", &output_halve_width);
+                }
+//                ImGui::SameLine();
                 ImGui::Checkbox("Save Video", &encoder_save_file);
                 if (encoder_save_file) {
                     ImGui::SameLine();
@@ -1058,9 +1067,7 @@ void render_main_window() {
         // draw preview camera frame
         assert(left->img_dev->size() == right->img_dev->size());
         float width_normal = left->img_dev->size().aspectRatio() / frame_size.aspectRatio();
-        auto render_rect = simple_rect{
-                -width_normal, -1, 2 * width_normal, 2
-        };
+        auto render_rect = simple_rect{-1, -1, 2, 2}.fit_aspect(width_normal);
         if (preview_camera_index == 0) { // left camera
             if (!left->img_dev->empty()) {
                 left->render(render_rect);
@@ -1094,8 +1101,11 @@ void generate_output_frame() {
     } else {
         float width_normal = left->img_dev->size().aspectRatio() /
                              output_fbo->size().aspectRatio();
-        left_rect = simple_rect{-0.5f - width_normal / 2, -1, width_normal, 2};
-        right_rect = simple_rect{0.5f - width_normal / 2, -1, width_normal, 2};
+        if (output_halve_width) {
+            width_normal *= 0.5f;
+        }
+        left_rect = simple_rect{-1, -1, 1, 2}.fit_aspect(width_normal);
+        right_rect = simple_rect{0, -1, 1, 2}.fit_aspect(width_normal);
     }
     left->render(left_rect, true);
     right->render(right_rect, true);

+ 17 - 0
src/simple_opengl.cpp

@@ -388,3 +388,20 @@ void smart_texture::create(GLenum format, cv::Size size, GLint min_filter, GLint
 cv::Size smart_texture::size() const {
     return pimpl->last_size;
 }
+
+simple_rect simple_rect::fit_aspect(float aspect_target) const {
+    simple_rect ret = {};
+    auto aspect_this = width / height;
+    if (aspect_this > aspect_target) { // adjust width
+        ret.height = height;
+        ret.width = height * aspect_target;
+        ret.x = x + 0.5f * (width - ret.width);
+        ret.y = y;
+    } else { // adjust height
+        ret.width = width;
+        ret.height = width / aspect_target;
+        ret.x = x;
+        ret.y = y + 0.5f * (height - ret.height);
+    }
+    return ret;
+}

+ 2 - 0
src/simple_opengl.h

@@ -13,6 +13,8 @@
 struct simple_rect {
     GLfloat x, y;
     GLfloat width, height;
+
+    simple_rect fit_aspect(float aspect) const;
 };
 
 struct smart_texture {