]> git.sesse.net Git - nageru/commitdiff
Only bother doing MJPEG encoding if there are any connected clients that want the...
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 11 Nov 2018 17:29:45 +0000 (18:29 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 11 Nov 2018 17:29:45 +0000 (18:29 +0100)
httpd.cpp
httpd.h
mixer.cpp

index 8d33e75a4f6b5bde8e6f8b79aa23ffa007e8351f..fff3467e99617c0b4d211f0dd86fae93399a6a67 100644 (file)
--- a/httpd.cpp
+++ b/httpd.cpp
@@ -26,6 +26,7 @@ using namespace std;
 HTTPD::HTTPD()
 {
        global_metrics.add("num_connected_clients", &metric_num_connected_clients, Metrics::TYPE_GAUGE);
+       global_metrics.add("num_connected_multicam_clients", &metric_num_connected_multicam_clients, Metrics::TYPE_GAUGE);
 }
 
 HTTPD::~HTTPD()
@@ -136,6 +137,9 @@ int HTTPD::answer_to_connection(MHD_Connection *connection,
                streams.insert(stream);
        }
        ++metric_num_connected_clients;
+       if (stream_type == HTTPD::StreamType::MULTICAM_STREAM) {
+               ++metric_num_connected_multicam_clients;
+       }
        *con_cls = stream;
 
        // Does not strictly have to be equal to MUX_BUFFER_SIZE.
@@ -156,6 +160,9 @@ void HTTPD::free_stream(void *cls)
 {
        HTTPD::Stream *stream = (HTTPD::Stream *)cls;
        HTTPD *httpd = stream->get_parent();
+       if (stream->get_stream_type() == HTTPD::StreamType::MULTICAM_STREAM) {
+               --httpd->metric_num_connected_multicam_clients;
+       }
        {
                unique_lock<mutex> lock(httpd->streams_mutex);
                delete stream;
diff --git a/httpd.h b/httpd.h
index 1ff5c51108facf03ca1b0d8fc2f076a63938e595..9cfe1ad87ffd9386ea404b5c44e8519ee7128f64 100644 (file)
--- a/httpd.h
+++ b/httpd.h
@@ -57,6 +57,9 @@ public:
        int64_t get_num_connected_clients() const {
                return metric_num_connected_clients.load();
        }
+       int64_t get_num_connected_multicam_clients() const {
+               return metric_num_connected_multicam_clients.load();
+       }
 
 private:
        static int answer_to_connection_thunk(void *cls, MHD_Connection *connection,
@@ -119,6 +122,7 @@ private:
 
        // Metrics.
        std::atomic<int64_t> metric_num_connected_clients{0};
+       std::atomic<int64_t> metric_num_connected_multicam_clients{0};
 };
 
 #endif  // !defined(_HTTPD_H)
index 294040f1bfd6fc6dde71a793af91c536e2c9f12e..95cdda98ecd5a42e97cb12cfdb4fb796e771a0e0 100644 (file)
--- a/mixer.cpp
+++ b/mixer.cpp
@@ -1071,12 +1071,16 @@ void Mixer::thread_func()
                                new_frame->upload_func = nullptr;
                        }
 
-                       // There are situations where we could possibly want to
-                       // include FFmpeg inputs (CEF inputs are unlikely),
-                       // but they're not necessarily in 4:2:2 Y'CbCr, so it would
-                       // require more functionality the the JPEG encoder.
-                       if (card_index < num_cards) {
-                               mjpeg_encoder->upload_frame(pts_int, card_index, new_frame->frame, new_frame->video_format, new_frame->y_offset, new_frame->cbcr_offset);
+                       // Only bother doing MJPEG encoding if there are any connected clients
+                       // that want the stream.
+                       if (httpd.get_num_connected_multicam_clients() > 0) {
+                               // There are situations where we could possibly want to
+                               // include FFmpeg inputs (CEF inputs are unlikely),
+                               // but they're not necessarily in 4:2:2 Y'CbCr, so it would
+                               // require more functionality the the JPEG encoder.
+                               if (card_index < num_cards) {
+                                       mjpeg_encoder->upload_frame(pts_int, card_index, new_frame->frame, new_frame->video_format, new_frame->y_offset, new_frame->cbcr_offset);
+                               }
                        }
                }