nx_server_plugin_sdk 1.0 Server Plugin SDK

media_stream_statistics.h
1 // Copyright 2018-present Network Optix, Inc. Licensed under MPL 2.0: www.mozilla.org/MPL/2.0/
2
3 #pragma once
4
5 #include <chrono>
6 #include <deque>
7 #include <limits>
8 #include <mutex>
9
10 namespace nx::sdk {
11
16 class MediaStreamStatistics
17 {
18 public:
19 MediaStreamStatistics(
20 std::chrono::microseconds windowSize = std::chrono::seconds(2),
21 int maxDurationInFrames = 0);
22
23 void setWindowSize(std::chrono::microseconds windowSize);
24 void setMaxDurationInFrames(int maxDurationInFrames);
25
26 void reset();
27 void onData(std::chrono::microseconds timestamp, size_t dataSize, bool isKeyFrame);
28 int64_t bitrateBitsPerSecond() const;
29 float getFrameRate() const;
30 float getAverageGopSize() const;
31 bool hasMediaData() const;
32
33 private:
34 std::chrono::microseconds m_windowSize {};
35 int m_maxDurationInFrames = 0;
36
37 struct Data
38 {
39 Data() = default;
40 Data(std::chrono::microseconds timestamp, size_t size, bool isKeyFrame):
41 timestamp(timestamp), size(size), isKeyFrame(isKeyFrame)
42 {
43 }
44
45 std::chrono::microseconds timestamp{};
46 size_t size = 0;
47 bool isKeyFrame = false;
48
49 bool operator<(std::chrono::microseconds value) const { return timestamp < value; }
50 };
51
52 std::chrono::microseconds intervalUnsafe() const;
53
54 mutable std::mutex m_mutex;
55 std::deque<Data> m_data;
56 int64_t m_totalSizeBytes = 0;
57 //nx::utils::ElapsedTimer m_lastDataTimer;
58 std::chrono::steady_clock::time_point m_lastDataTimer;
59 };
60
61 } // namespace nx::sdk
nx::sdk::MediaStreamStatistics
Definition: media_stream_statistics.h:16
nx::sdk
Definition: device_agent.h:12