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