diff --git a/rtsp_output.cpp b/rtsp_output.cpp index d1058f6..5255869 100644 --- a/rtsp_output.cpp +++ b/rtsp_output.cpp @@ -21,6 +21,7 @@ #define ERROR_START_MULTICAST 4 #define ERROR_ENCODE OBS_OUTPUT_ENCODE_ERROR +#define OBS_RTSPSERVER_QUEUE_SIZE_LIMIT 2 struct queue_frame { queue_frame(size_t size = 0) @@ -359,8 +360,8 @@ static void rtsp_output_rtsp_start(void *data) } } - out_data->frame_queue = - std::make_unique>(); + out_data->frame_queue = std::make_unique>( + OBS_RTSPSERVER_QUEUE_SIZE_LIMIT); session->AddNotifyConnectedCallback( [](const xop::MediaSessionId session_id, @@ -643,6 +644,18 @@ static uint64_t rtsp_output_total_bytes_sent(void *data) return out_data->total_bytes_sent; } +static int rtsp_output_get_dropped_frames(void *data) +{ + const auto *out_data = static_cast(data); + if (!active(out_data) || out_data->frame_queue == nullptr) { + return 0; + } + auto dropped_count = out_data->frame_queue->dropped_count(); + while (dropped_count > INT32_MAX) + dropped_count -= INT32_MAX; + return static_cast(dropped_count); +} + void rtsp_output_register() { struct obs_output_info output_info = {}; @@ -661,6 +674,7 @@ void rtsp_output_register() output_info.update = rtsp_output_update; output_info.get_properties = rtsp_output_properties; output_info.get_total_bytes = rtsp_output_total_bytes_sent; + output_info.get_dropped_frames = rtsp_output_get_dropped_frames; obs_register_output(&output_info); } diff --git a/rtsp_output_helper.cpp b/rtsp_output_helper.cpp index 6dc6031..c5cd4c2 100644 --- a/rtsp_output_helper.cpp +++ b/rtsp_output_helper.cpp @@ -98,6 +98,16 @@ uint64_t RtspOutputHelper::GetTotalBytes() const return obs_output_get_total_bytes(obsOutput); } +int RtspOutputHelper::GetTotalFrames() const +{ + return obs_output_get_total_frames(obsOutput); +} + +int RtspOutputHelper::GetFramesDropped() const +{ + return obs_output_get_frames_dropped(obsOutput); +} + bool RtspOutputHelper::IsActive() const { return obs_output_active(obsOutput); diff --git a/rtsp_output_helper.h b/rtsp_output_helper.h index bb2818b..724d5ab 100644 --- a/rtsp_output_helper.h +++ b/rtsp_output_helper.h @@ -29,6 +29,8 @@ class RtspOutputHelper { void *data) const; std::string GetOutputName() const; uint64_t GetTotalBytes() const; + int GetTotalFrames() const; + int GetFramesDropped() const; bool IsActive() const; private: diff --git a/threadsafe_queue.h b/threadsafe_queue.h index 10ee942..f5bdd2a 100644 --- a/threadsafe_queue.h +++ b/threadsafe_queue.h @@ -94,6 +94,10 @@ template class threadsafe_queue shared_ptr data(make_shared(std::move(new_value))); unique_lock lk(mut); data_queue.push(data); + if (data_queue.size() > size_limit) { + data_queue.pop(); + m_dropped_count.fetch_add(1, memory_order_relaxed); + } data_cond.notify_one(); } @@ -139,6 +143,7 @@ template class threadsafe_queue private: mutex mut; queue> data_queue; + const size_t size_limit; condition_variable data_cond; atomic_bool m_termination; atomic_size_t m_dropped_count; diff --git a/ui/rtsp_properties.ui b/ui/rtsp_properties.ui index dfa9576..9648c53 100644 --- a/ui/rtsp_properties.ui +++ b/ui/rtsp_properties.ui @@ -60,7 +60,7 @@ - + 0 @@ -439,7 +439,7 @@ - + 0