OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license | |
5 * that can be found in the LICENSE file in the root of the source | |
6 * tree. An additional intellectual property rights grant can be found | |
7 * in the file PATENTS. All contributing project authors may | |
8 * be found in the AUTHORS file in the root of the source tree. | |
9 */ | |
10 | |
11 #ifndef WEBRTC_MODULES_VIDEO_CODING_UTILITY_INCLUDE_FRAME_DROPPER_H_ | |
12 #define WEBRTC_MODULES_VIDEO_CODING_UTILITY_INCLUDE_FRAME_DROPPER_H_ | |
13 | |
14 #include <cstddef> | |
15 | |
16 #include "webrtc/base/exp_filter.h" | |
17 #include "webrtc/typedefs.h" | |
18 | |
19 namespace webrtc | |
20 { | |
21 | |
22 // The Frame Dropper implements a variant of the leaky bucket algorithm | |
23 // for keeping track of when to drop frames to avoid bit rate | |
24 // over use when the encoder can't keep its bit rate. | |
25 class FrameDropper | |
26 { | |
27 public: | |
28 FrameDropper(); | |
29 explicit FrameDropper(float max_time_drops); | |
30 virtual ~FrameDropper() {} | |
31 | |
32 // Resets the FrameDropper to its initial state. | |
33 // This means that the frameRateWeight is set to its | |
34 // default value as well. | |
35 virtual void Reset(); | |
36 | |
37 virtual void Enable(bool enable); | |
38 // Answers the question if it's time to drop a frame | |
39 // if we want to reach a given frame rate. Must be | |
40 // called for every frame. | |
41 // | |
42 // Return value : True if we should drop the current frame | |
43 virtual bool DropFrame(); | |
44 // Updates the FrameDropper with the size of the latest encoded | |
45 // frame. The FrameDropper calculates a new drop ratio (can be | |
46 // seen as the probability to drop a frame) and updates its | |
47 // internal statistics. | |
48 // | |
49 // Input: | |
50 // - frameSizeBytes : The size of the latest frame | |
51 // returned from the encoder. | |
52 // - deltaFrame : True if the encoder returned | |
53 // a key frame. | |
54 virtual void Fill(size_t frameSizeBytes, bool deltaFrame); | |
55 | |
56 virtual void Leak(uint32_t inputFrameRate); | |
57 | |
58 void UpdateNack(uint32_t nackBytes); | |
59 | |
60 // Sets the target bit rate and the frame rate produced by | |
61 // the camera. | |
62 // | |
63 // Input: | |
64 // - bitRate : The target bit rate | |
65 virtual void SetRates(float bitRate, float incoming_frame_rate); | |
66 | |
67 // Return value : The current average frame rate produced | |
68 // if the DropFrame() function is used as | |
69 // instruction of when to drop frames. | |
70 virtual float ActualFrameRate(uint32_t inputFrameRate) const; | |
71 | |
72 private: | |
73 void FillBucket(float inKbits, float outKbits); | |
74 void UpdateRatio(); | |
75 void CapAccumulator(); | |
76 | |
77 rtc::ExpFilter _keyFrameSizeAvgKbits; | |
78 rtc::ExpFilter _keyFrameRatio; | |
79 float _keyFrameSpreadFrames; | |
80 int32_t _keyFrameCount; | |
81 float _accumulator; | |
82 float _accumulatorMax; | |
83 float _targetBitRate; | |
84 bool _dropNext; | |
85 rtc::ExpFilter _dropRatio; | |
86 int32_t _dropCount; | |
87 float _windowSize; | |
88 float _incoming_frame_rate; | |
89 bool _wasBelowMax; | |
90 bool _enabled; | |
91 bool _fastMode; | |
92 float _cap_buffer_size; | |
93 float _max_time_drops; | |
94 }; // end of VCMFrameDropper class | |
95 | |
96 } // namespace webrtc | |
97 | |
98 #endif // WEBRTC_MODULES_VIDEO_CODING_UTILITY_INCLUDE_FRAME_DROPPER_H_ | |
OLD | NEW |