X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=nageru%2Fmixer.h;h=1852e48ed8196fa79938a5d4527e9e55f7f7a14a;hb=5a34f92eb0bf5fe911cb6ca72a18ad03ce9898ac;hp=61db4a5c30857b06728d8dee0810a6caf3a06df1;hpb=0490c42536a845dd6d718a7c58cfb3e3ab02b1ab;p=nageru diff --git a/nageru/mixer.h b/nageru/mixer.h index 61db4a5..1852e48 100644 --- a/nageru/mixer.h +++ b/nageru/mixer.h @@ -331,6 +331,12 @@ public: 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.) + return false; + } return cards[card_index].type == CardType::FFMPEG_INPUT; } @@ -439,11 +445,15 @@ private: FFMPEG_INPUT, CEF_INPUT, }; - void configure_card(unsigned card_index, bmusb::CaptureInterface *capture, CardType card_type, DeckLinkOutput *output); + void configure_card(unsigned card_index, bmusb::CaptureInterface *capture, CardType card_type, DeckLinkOutput *output, bool is_srt_card = false); 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, bmusb::FrameAllocator::Frame audio_frame, size_t audio_offset, bmusb::AudioFormat audio_format); + void upload_texture_for_frame( + int field, bmusb::VideoFormat video_format, + size_t y_offset, size_t cbcr_offset, size_t video_offset, + PBOFrameAllocator::Userdata *userdata); void bm_hotplug_add(libusb_device *dev); void bm_hotplug_remove(unsigned card_index); void place_rectangle(movit::Effect *resample_effect, movit::Effect *padding_effect, float x0, float y0, float x1, float y1); @@ -454,6 +464,9 @@ private: void render_one_frame(int64_t duration); void audio_thread_func(); void release_display_frame(DisplayFrame *frame); +#ifdef HAVE_SRT + void start_srt(); +#endif double pts() { return double(pts_int) / TIMEBASE; } void trim_queue(CaptureCard *card, size_t safe_queue_length); std::pair get_channels_json(); @@ -501,11 +514,19 @@ private: // frame rate is integer, will always stay zero. unsigned fractional_samples = 0; + // Monotonic counter that lets us know which slot was last turned into + // a fake capture. Used for SRT re-plugging. + unsigned fake_capture_counter = 0; + mutable std::mutex card_mutex; bool has_bmusb_thread = false; struct CaptureCard { std::unique_ptr capture; 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. + int fake_capture_counter; + std::string last_srt_stream_id = ""; // Used for SRT re-plugging. CardType type; std::unique_ptr output; @@ -535,16 +556,15 @@ private: int64_t length; // In TIMEBASE units. bool interlaced; unsigned field; // Which field (0 or 1) of the frame to use. Always 0 for progressive. - std::function upload_func; // Needs to be called to actually upload the texture to OpenGL. + bool texture_uploaded = false; 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(); movit::RGBTriplet neutral_color{1.0f, 1.0f, 1.0f}; - // Used for MJPEG encoding. (upload_func packs everything it needs - // into the functor, but would otherwise also use these.) + // Used for MJPEG encoding, and texture upload. // width=0 or height=0 means a broken frame, ie., do not upload. bmusb::VideoFormat video_format; - size_t y_offset, cbcr_offset; + size_t video_offset, y_offset, cbcr_offset; }; std::deque new_frames; std::condition_variable new_frames_changed; // Set whenever new_frames is changed. @@ -573,6 +593,53 @@ private: std::atomic metric_input_frame_rate_nom{-1}; std::atomic metric_input_frame_rate_den{-1}; std::atomic metric_input_sample_rate_hz{-1}; + + // SRT metrics. + std::atomic metric_srt_uptime_seconds{0.0 / 0.0}; + std::atomic metric_srt_send_duration_seconds{0.0 / 0.0}; + std::atomic metric_srt_sent_bytes{-1}; + std::atomic metric_srt_received_bytes{-1}; + std::atomic metric_srt_sent_packets_normal{-1}; + std::atomic metric_srt_received_packets_normal{-1}; + std::atomic metric_srt_sent_packets_lost{-1}; + std::atomic metric_srt_received_packets_lost{-1}; + std::atomic metric_srt_sent_packets_retransmitted{-1}; + std::atomic metric_srt_sent_bytes_retransmitted{-1}; + std::atomic metric_srt_sent_packets_ack{-1}; + std::atomic metric_srt_received_packets_ack{-1}; + std::atomic metric_srt_sent_packets_nak{-1}; + std::atomic metric_srt_received_packets_nak{-1}; + std::atomic metric_srt_sent_packets_dropped{-1}; + std::atomic metric_srt_received_packets_dropped{-1}; + std::atomic metric_srt_sent_bytes_dropped{-1}; + std::atomic metric_srt_received_bytes_dropped{-1}; + std::atomic metric_srt_received_packets_undecryptable{-1}; + std::atomic metric_srt_received_bytes_undecryptable{-1}; + + std::atomic metric_srt_filter_received_extra_packets{-1}; + std::atomic metric_srt_filter_received_rebuilt_packets{-1}; + std::atomic metric_srt_filter_received_lost_packets{-1}; + + std::atomic metric_srt_packet_sending_period_seconds{0.0 / 0.0}; + std::atomic metric_srt_flow_window_packets{-1}; + std::atomic metric_srt_congestion_window_packets{-1}; + std::atomic metric_srt_flight_size_packets{-1}; + std::atomic metric_srt_rtt_seconds{0.0 / 0.0}; + std::atomic metric_srt_estimated_bandwidth_bits_per_second{0.0 / 0.0}; + std::atomic metric_srt_bandwidth_ceiling_bits_per_second{0.0 / 0.0}; + std::atomic metric_srt_send_buffer_available_bytes{-1}; + std::atomic metric_srt_receive_buffer_available_bytes{-1}; + std::atomic metric_srt_mss_bytes{-1}; + std::atomic metric_srt_sender_unacked_packets{-1}; + std::atomic metric_srt_sender_unacked_bytes{-1}; + std::atomic metric_srt_sender_unacked_timespan_seconds{0.0 / 0.0}; + std::atomic metric_srt_sender_delivery_delay_seconds{0.0 / 0.0}; + std::atomic metric_srt_receiver_unacked_packets{-1}; + std::atomic metric_srt_receiver_unacked_bytes{-1}; + std::atomic metric_srt_receiver_unacked_timespan_seconds{0.0 / 0.0}; + std::atomic metric_srt_receiver_delivery_delay_seconds{0.0 / 0.0}; + std::atomic metric_srt_filter_sent_packets{-1}; + }; JitterHistory output_jitter_history; CaptureCard cards[MAX_VIDEO_CARDS]; // Protected by . @@ -589,12 +656,19 @@ private: }; OutputFrameInfo 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], std::vector raw_audio[MAX_VIDEO_CARDS]); +#ifdef HAVE_SRT + void update_srt_stats(int srt_sock, Mixer::CaptureCard *card); +#endif + InputState input_state; // Cards we have been noticed about being hotplugged, but haven't tried adding yet. // Protected by its own mutex. std::mutex hotplug_mutex; std::vector hotplugged_cards; +#ifdef HAVE_SRT + std::vector hotplugged_srt_cards; +#endif class OutputChannel { public: @@ -627,6 +701,9 @@ private: std::thread mixer_thread; std::thread audio_thread; +#ifdef HAVE_SRT + std::thread srt_thread; +#endif std::atomic should_quit{false}; std::atomic should_cut{false};