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