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