]> git.sesse.net Git - nageru/blobdiff - mixer.cpp
Add an HTTP endpoint for enumerating channels and one for getting only their colors...
[nageru] / mixer.cpp
index f502eb0e4590c86092588841bd04298e1f4f4600..70175a163c4a2c9a51be1690a9c9c408ac16f81f 100644 (file)
--- a/mixer.cpp
+++ b/mixer.cpp
 #include "v210_converter.h"
 #include "video_encoder.h"
 
+#undef Status
+#include <google/protobuf/util/json_util.h>
+#include "json.pb.h"
+
 class IDeckLink;
 class QOpenGLContext;
 
@@ -239,7 +243,7 @@ double JitterHistory::estimate_max_jitter() const
        if (percentile <= 0.5) {
                return *next(orders.begin(), elem_idx) * multiplier;
        } else {
-               return *prev(orders.end(), elem_idx + 1) * multiplier;
+               return *prev(orders.end(), orders.size() - elem_idx) * multiplier;
        }
 }
 
@@ -352,6 +356,13 @@ Mixer::Mixer(const QSurfaceFormat &format, unsigned num_cards)
        // Must be instantiated after VideoEncoder has initialized global_flags.use_zerocopy.
        theme.reset(new Theme(global_flags.theme_filename, global_flags.theme_dirs, resource_pool.get(), num_cards));
 
+       httpd.add_endpoint("/channels", bind(&Mixer::get_channels_json, this));
+       for (int channel_idx = 2; channel_idx < theme->get_num_channels(); ++channel_idx) {
+               char url[256];
+               snprintf(url, sizeof(url), "/channels/%d/color", channel_idx);
+               httpd.add_endpoint(url, bind(&Mixer::get_channel_color_http, this, unsigned(channel_idx)));
+       }
+
        // Start listening for clients only once VideoEncoder has written its header, if any.
        httpd.start(global_flags.http_port);
 
@@ -1096,6 +1107,24 @@ void Mixer::trim_queue(CaptureCard *card, size_t safe_queue_length)
 #endif
 }
 
+pair<string, string> Mixer::get_channels_json()
+{
+       Channels ret;
+       for (int channel_idx = 2; channel_idx < theme->get_num_channels(); ++channel_idx) {
+               Channel *channel = ret.add_channel();
+               channel->set_index(channel_idx);
+               channel->set_name(theme->get_channel_name(channel_idx));
+               channel->set_color(theme->get_channel_color(channel_idx));
+       }
+       string contents;
+       google::protobuf::util::MessageToJsonString(ret, &contents);  // Ignore any errors.
+       return make_pair(contents, "text/json");
+}
+
+pair<string, string> Mixer::get_channel_color_http(unsigned channel_idx)
+{
+       return make_pair(theme->get_channel_color(channel_idx), "text/plain");
+}
 
 Mixer::OutputFrameInfo Mixer::get_one_frame_from_each_card(unsigned master_card_index, bool master_card_is_output, CaptureCard::NewFrame new_frames[MAX_VIDEO_CARDS], bool has_new_frame[MAX_VIDEO_CARDS])
 {
@@ -1390,7 +1419,7 @@ void Mixer::render_one_frame(int64_t duration)
        live_frame.ready_fence = fence;
        live_frame.input_frames = {};
        live_frame.temp_textures = { y_display_tex, cbcr_display_tex };
-       output_channel[OUTPUT_LIVE].output_frame(live_frame);
+       output_channel[OUTPUT_LIVE].output_frame(move(live_frame));
 
        // Set up preview and any additional channels.
        for (int i = 1; i < theme->get_num_channels() + 2; ++i) {
@@ -1401,7 +1430,7 @@ void Mixer::render_one_frame(int64_t duration)
                display_frame.ready_fence = fence;
                display_frame.input_frames = move(chain.input_frames);
                display_frame.temp_textures = {};
-               output_channel[i].output_frame(display_frame);
+               output_channel[i].output_frame(move(display_frame));
        }
 }
 
@@ -1521,7 +1550,7 @@ Mixer::OutputChannel::~OutputChannel()
        }
 }
 
-void Mixer::OutputChannel::output_frame(DisplayFrame frame)
+void Mixer::OutputChannel::output_frame(DisplayFrame &&frame)
 {
        // Store this frame for display. Remove the ready frame if any
        // (it was seemingly never used).