X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=nageru%2Fmixer.h;h=e382f7755ed31f642513118c8a2b41dbf6c6756e;hb=ecaec75dd52d076ba53cafa1fed716ebc0d93da6;hp=1852e48ed8196fa79938a5d4527e9e55f7f7a14a;hpb=5a34f92eb0bf5fe911cb6ca72a18ad03ce9898ac;p=nageru diff --git a/nageru/mixer.h b/nageru/mixer.h index 1852e48..e382f77 100644 --- a/nageru/mixer.h +++ b/nageru/mixer.h @@ -29,6 +29,7 @@ #include "audio_mixer.h" #include "bmusb/bmusb.h" #include "defs.h" +#include "ffmpeg_capture.h" #include "shared/httpd.h" #include "input_state.h" #include "libusb.h" @@ -158,7 +159,7 @@ private: class Mixer { public: // The surface format is used for offscreen destinations for OpenGL contexts we need. - Mixer(const QSurfaceFormat &format, unsigned num_cards); + Mixer(const QSurfaceFormat &format); ~Mixer(); void start(); void quit(); @@ -303,10 +304,8 @@ public: should_cut = true; } - unsigned get_num_cards() const { return num_cards; } - std::string get_card_description(unsigned card_index) const { - assert(card_index < num_cards); + assert(card_index < MAX_VIDEO_CARDS); return cards[card_index].capture->get_description(); } @@ -316,7 +315,7 @@ public: // the card's actual name. std::string get_output_card_description(unsigned card_index) const { assert(card_can_be_used_as_output(card_index)); - assert(card_index < num_cards); + assert(card_index < MAX_VIDEO_CARDS); if (cards[card_index].parked_capture) { return cards[card_index].parked_capture->get_description(); } else { @@ -325,65 +324,87 @@ public: } bool card_can_be_used_as_output(unsigned card_index) const { - assert(card_index < num_cards); - return cards[card_index].output != nullptr; + assert(card_index < MAX_VIDEO_CARDS); + return cards[card_index].output != nullptr && cards[card_index].capture != nullptr; + } + + bool card_is_cef(unsigned card_index) const { + assert(card_index < MAX_VIDEO_CARDS); + return cards[card_index].type == CardType::CEF_INPUT; } bool card_is_ffmpeg(unsigned card_index) const { - assert(card_index < num_cards + num_video_inputs); - if (card_index < num_cards) { - // SRT inputs are more like regular inputs than FFmpeg inputs, - // so show them as such. (This allows the user to right-click - // to select a different input.) + assert(card_index < MAX_VIDEO_CARDS); + if (cards[card_index].type != CardType::FFMPEG_INPUT) { return false; } - return cards[card_index].type == CardType::FFMPEG_INPUT; +#ifdef HAVE_SRT + // SRT inputs are more like regular inputs than FFmpeg inputs, + // so show them as such. (This allows the user to right-click + // to select a different input.) + return static_cast(cards[card_index].capture.get())->get_srt_sock() == -1; +#else + return true; +#endif + } + + bool card_is_active(unsigned card_index) const { + assert(card_index < MAX_VIDEO_CARDS); + std::lock_guard lock(card_mutex); + return cards[card_index].capture != nullptr; + } + + void force_card_active(unsigned card_index) + { + // handle_hotplugged_cards() will pick this up. + std::lock_guard lock(card_mutex); + cards[card_index].force_active = true; } std::map get_available_video_modes(unsigned card_index) const { - assert(card_index < num_cards); + assert(card_index < MAX_VIDEO_CARDS); return cards[card_index].capture->get_available_video_modes(); } uint32_t get_current_video_mode(unsigned card_index) const { - assert(card_index < num_cards); + assert(card_index < MAX_VIDEO_CARDS); return cards[card_index].capture->get_current_video_mode(); } void set_video_mode(unsigned card_index, uint32_t mode) { - assert(card_index < num_cards); + assert(card_index < MAX_VIDEO_CARDS); cards[card_index].capture->set_video_mode(mode); } void start_mode_scanning(unsigned card_index); std::map get_available_video_inputs(unsigned card_index) const { - assert(card_index < num_cards); + assert(card_index < MAX_VIDEO_CARDS); return cards[card_index].capture->get_available_video_inputs(); } uint32_t get_current_video_input(unsigned card_index) const { - assert(card_index < num_cards); + assert(card_index < MAX_VIDEO_CARDS); return cards[card_index].capture->get_current_video_input(); } void set_video_input(unsigned card_index, uint32_t input) { - assert(card_index < num_cards); + assert(card_index < MAX_VIDEO_CARDS); cards[card_index].capture->set_video_input(input); } std::map get_available_audio_inputs(unsigned card_index) const { - assert(card_index < num_cards); + assert(card_index < MAX_VIDEO_CARDS); return cards[card_index].capture->get_available_audio_inputs(); } uint32_t get_current_audio_input(unsigned card_index) const { - assert(card_index < num_cards); + assert(card_index < MAX_VIDEO_CARDS); return cards[card_index].capture->get_current_audio_input(); } void set_audio_input(unsigned card_index, uint32_t input) { - assert(card_index < num_cards); + assert(card_index < MAX_VIDEO_CARDS); cards[card_index].capture->set_audio_input(input); } @@ -439,13 +460,7 @@ public: private: struct CaptureCard; - enum class CardType { - LIVE_CARD, - FAKE_CAPTURE, - FFMPEG_INPUT, - CEF_INPUT, - }; - void configure_card(unsigned card_index, bmusb::CaptureInterface *capture, CardType card_type, DeckLinkOutput *output, bool is_srt_card = false); + void configure_card(unsigned card_index, bmusb::CaptureInterface *capture, CardType card_type, DeckLinkOutput *output, bool is_srt_card); void set_output_card_internal(int card_index); // Should only be called from the mixer thread. void bm_frame(unsigned card_index, uint16_t timecode, bmusb::FrameAllocator::Frame video_frame, size_t video_offset, bmusb::VideoFormat video_format, @@ -473,7 +488,7 @@ private: std::pair get_channel_color_http(unsigned channel_idx); HTTPD httpd; - unsigned num_cards, num_video_inputs, num_html_inputs = 0; + unsigned num_video_inputs, num_html_inputs = 0; QSurface *mixer_surface, *h264_encoder_surface, *decklink_output_surface, *image_update_surface; std::unique_ptr resource_pool; @@ -521,7 +536,12 @@ private: mutable std::mutex card_mutex; bool has_bmusb_thread = false; struct CaptureCard { + // If nullptr, the card is inactive, and will be hidden in the UI. + // Only fake capture cards can be inactive. std::unique_ptr capture; + // If true, card must always be active (typically because it's one of the + // first cards, or because the theme has explicitly asked for it). + bool force_active = false; bool is_fake_capture; // If is_fake_capture is true, contains a monotonic timer value for when // it was last changed. Otherwise undefined. Used for SRT re-plugging. @@ -660,6 +680,9 @@ private: void update_srt_stats(int srt_sock, Mixer::CaptureCard *card); #endif + std::string description_for_card(unsigned card_index); + static bool is_srt_card(const CaptureCard *card); + InputState input_state; // Cards we have been noticed about being hotplugged, but haven't tried adding yet.