]> git.sesse.net Git - nageru/blobdiff - mixer.h
Add functionality for MJPEG export.
[nageru] / mixer.h
diff --git a/mixer.h b/mixer.h
index d8a9c8badf527e0e6dfcf2867156a10ad4677c9c..84313e5130b0816b2a997ee9265d637781cb3aed 100644 (file)
--- a/mixer.h
+++ b/mixer.h
@@ -42,6 +42,7 @@
 class ALSAOutput;
 class ChromaSubsampler;
 class DeckLinkOutput;
+class MJPEGEncoder;
 class QSurface;
 class QSurfaceFormat;
 class TimecodeRenderer;
@@ -322,6 +323,11 @@ public:
                return cards[card_index].output != nullptr;
        }
 
+       bool card_is_ffmpeg(unsigned card_index) const {
+               assert(card_index < num_cards + num_video_inputs);
+               return cards[card_index].type == CardType::FFMPEG_INPUT;
+       }
+
        std::map<uint32_t, bmusb::VideoMode> get_available_video_modes(unsigned card_index) const {
                assert(card_index < num_cards);
                return cards[card_index].capture->get_available_video_modes();
@@ -369,6 +375,10 @@ public:
                cards[card_index].capture->set_audio_input(input);
        }
 
+       std::string get_ffmpeg_filename(unsigned card_index) const;
+
+       void set_ffmpeg_filename(unsigned card_index, const std::string &filename);
+
        void change_x264_bitrate(unsigned rate_kbit) {
                video_encoder->change_x264_bitrate(rate_kbit);
        }
@@ -412,6 +422,8 @@ public:
                theme->set_theme_menu_callback(callback);
        }
 
+       void wait_for_next_frame();
+
 private:
        struct CaptureCard;
 
@@ -464,6 +476,7 @@ private:
        std::unique_ptr<ChromaSubsampler> chroma_subsampler;
        std::unique_ptr<v210Converter> v210_converter;
        std::unique_ptr<VideoEncoder> video_encoder;
+       std::unique_ptr<MJPEGEncoder> mjpeg_encoder;
 
        std::unique_ptr<TimecodeRenderer> timecode_renderer;
        std::atomic<bool> display_timecode_in_stream{false};
@@ -473,7 +486,10 @@ private:
        movit::YCbCrInput *display_input;
 
        int64_t pts_int = 0;  // In TIMEBASE units.
-       unsigned frame_num = 0;
+
+       mutable std::mutex frame_num_mutex;
+       std::condition_variable frame_num_updated;
+       unsigned frame_num = 0;  // Under <frame_num_mutex>.
 
        // Accumulated errors in number of 1/TIMEBASE audio samples. If OUTPUT_FREQUENCY divided by
        // frame rate is integer, will always stay zero.
@@ -516,10 +532,15 @@ private:
                        std::function<void()> upload_func;  // Needs to be called to actually upload the texture to OpenGL.
                        unsigned dropped_frames = 0;  // Number of dropped frames before this one.
                        std::chrono::steady_clock::time_point received_timestamp = std::chrono::steady_clock::time_point::min();
+
+                       // Used for MJPEG encoding. (upload_func packs everything it needs
+                       // into the functor, but would otherwise also use these.)
+                       // width=0 or height=0 means a broken frame, ie., do not upload.
+                       bmusb::VideoFormat video_format;
+                       size_t y_offset, cbcr_offset;
                };
                std::deque<NewFrame> new_frames;
-               bool should_quit = false;
-               std::condition_variable new_frames_changed;  // Set whenever new_frames (or should_quit) is changed.
+               std::condition_variable new_frames_changed;  // Set whenever new_frames is changed.
 
                QueueLengthPolicy queue_length_policy;  // Refers to the "new_frames" queue.