OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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_MEDIA_OPTIMIZATION_H_ | 11 #ifndef WEBRTC_MODULES_VIDEO_CODING_MEDIA_OPTIMIZATION_H_ |
12 #define WEBRTC_MODULES_VIDEO_CODING_MEDIA_OPTIMIZATION_H_ | 12 #define WEBRTC_MODULES_VIDEO_CODING_MEDIA_OPTIMIZATION_H_ |
13 | 13 |
14 #include <list> | 14 #include <list> |
15 #include <memory> | 15 #include <memory> |
16 | 16 |
17 #include "webrtc/modules/include/module_common_types.h" | 17 #include "webrtc/modules/include/module_common_types.h" |
18 #include "webrtc/modules/video_coding/include/video_coding.h" | 18 #include "webrtc/modules/video_coding/include/video_coding.h" |
19 #include "webrtc/modules/video_coding/media_opt_util.h" | 19 #include "webrtc/modules/video_coding/media_opt_util.h" |
20 #include "webrtc/rtc_base/criticalsection.h" | 20 #include "webrtc/rtc_base/criticalsection.h" |
21 | 21 |
22 namespace webrtc { | 22 namespace webrtc { |
23 | 23 |
24 // Forward declarations. | |
25 class Clock; | 24 class Clock; |
26 class FrameDropper; | 25 class FrameDropper; |
27 class VCMContentMetricsProcessing; | 26 class VCMContentMetricsProcessing; |
28 | 27 |
29 namespace media_optimization { | 28 namespace media_optimization { |
30 | 29 |
31 class MediaOptimization { | 30 class MediaOptimization { |
32 public: | 31 public: |
33 explicit MediaOptimization(Clock* clock); | 32 explicit MediaOptimization(Clock* clock); |
34 ~MediaOptimization(); | 33 ~MediaOptimization(); |
35 | 34 |
36 // TODO(andresp): Can Reset and SetEncodingData be done at construction time | 35 // TODO(andresp): Can Reset and SetEncodingData be done at construction time |
37 // only? | 36 // only? |
38 void Reset(); | 37 void Reset(); |
39 | 38 |
40 // Informs media optimization of initial encoding state. | 39 // Informs media optimization of initial encoding state. |
41 // TODO(perkj): Deprecate SetEncodingData once its not used for stats in | 40 // TODO(perkj): Deprecate SetEncodingData once its not used for stats in |
42 // VieEncoder. | 41 // VieEncoder. |
43 void SetEncodingData(int32_t max_bit_rate, | 42 void SetEncodingData(int32_t max_bit_rate, |
44 uint32_t bit_rate, | 43 uint32_t bit_rate, |
45 uint16_t width, | 44 uint32_t frame_rate); |
46 uint16_t height, | |
47 uint32_t frame_rate, | |
48 int num_temporal_layers, | |
49 int32_t mtu); | |
50 | 45 |
51 // Sets target rates for the encoder given the channel parameters. | 46 // Sets target rates for the encoder given the channel parameters. |
52 // Input: target bitrate - the encoder target bitrate in bits/s. | 47 // Input: |target bitrate| - the encoder target bitrate in bits/s. |
53 uint32_t SetTargetRates(uint32_t target_bitrate); | 48 uint32_t SetTargetRates(uint32_t target_bitrate); |
54 | 49 |
55 void EnableFrameDropper(bool enable); | 50 void EnableFrameDropper(bool enable); |
56 bool DropFrame(); | 51 bool DropFrame(); |
57 | 52 |
58 // Informs Media Optimization of encoded output. | 53 // Informs Media Optimization of encoded output. |
59 // TODO(perkj): Deprecate SetEncodingData once its not used for stats in | 54 // TODO(perkj): Deprecate SetEncodingData once its not used for stats in |
60 // VieEncoder. | 55 // VieEncoder. |
61 int32_t UpdateWithEncodedData(const EncodedImage& encoded_image); | 56 int32_t UpdateWithEncodedData(const EncodedImage& encoded_image); |
62 | 57 |
63 // InputFrameRate 0 = no frame rate estimate available. | 58 // InputFrameRate 0 = no frame rate estimate available. |
64 uint32_t InputFrameRate(); | 59 uint32_t InputFrameRate(); |
65 uint32_t SentFrameRate(); | 60 uint32_t SentFrameRate(); |
66 uint32_t SentBitRate(); | 61 uint32_t SentBitRate(); |
67 | 62 |
68 private: | 63 private: |
69 enum { kFrameCountHistorySize = 90 }; | 64 enum { kFrameCountHistorySize = 90 }; |
70 enum { kFrameHistoryWinMs = 2000 }; | 65 enum { kFrameHistoryWinMs = 2000 }; |
71 enum { kBitrateAverageWinMs = 1000 }; | 66 enum { kBitrateAverageWinMs = 1000 }; |
72 | 67 |
73 struct EncodedFrameSample; | 68 struct EncodedFrameSample; |
74 typedef std::list<EncodedFrameSample> FrameSampleList; | 69 typedef std::list<EncodedFrameSample> FrameSampleList; |
75 | 70 |
76 void UpdateIncomingFrameRate() EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | 71 void UpdateIncomingFrameRate() EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
77 void PurgeOldFrameSamples(int64_t threshold_ms) | 72 void PurgeOldFrameSamples(int64_t threshold_ms) |
78 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | 73 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
79 // Updates the sent bitrate field, a call to PurgeOldFrameSamples must preceed | |
80 int GetSentBitrate(int64_t now_ms) EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | |
81 void UpdateSentFramerate() EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | 74 void UpdateSentFramerate() EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
82 | 75 |
83 void ProcessIncomingFrameRate(int64_t now) | 76 void ProcessIncomingFrameRate(int64_t now) |
84 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | 77 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
85 | 78 |
86 // Checks conditions for suspending the video. The method compares | 79 // Checks conditions for suspending the video. The method compares |
87 // |video_target_bitrate_| with the threshold values for suspension, and | 80 // |video_target_bitrate_| with the threshold values for suspension, and |
88 // changes the state of |video_suspended_| accordingly. | 81 // changes the state of |video_suspended_| accordingly. |
89 void CheckSuspendConditions() EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | 82 void CheckSuspendConditions() EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
90 | 83 |
91 void SetEncodingDataInternal(int32_t max_bit_rate, | 84 void SetEncodingDataInternal(int32_t max_bit_rate, |
92 uint32_t frame_rate, | 85 uint32_t frame_rate, |
93 uint32_t bit_rate, | 86 uint32_t bit_rate) |
94 uint16_t width, | |
95 uint16_t height, | |
96 int num_temporal_layers, | |
97 int32_t mtu) | |
98 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | 87 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
99 | 88 |
100 uint32_t InputFrameRateInternal() EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | 89 uint32_t InputFrameRateInternal() EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
101 | 90 |
102 uint32_t SentFrameRateInternal() EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | 91 uint32_t SentFrameRateInternal() EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
103 | 92 |
104 // Protect all members. | 93 // Protect all members. |
105 rtc::CriticalSection crit_sect_; | 94 rtc::CriticalSection crit_sect_; |
106 | 95 |
107 Clock* clock_ GUARDED_BY(crit_sect_); | 96 Clock* clock_ GUARDED_BY(crit_sect_); |
108 int32_t max_bit_rate_ GUARDED_BY(crit_sect_); | 97 int32_t max_bit_rate_ GUARDED_BY(crit_sect_); |
109 uint16_t codec_width_ GUARDED_BY(crit_sect_); | |
110 uint16_t codec_height_ GUARDED_BY(crit_sect_); | |
111 float user_frame_rate_ GUARDED_BY(crit_sect_); | 98 float user_frame_rate_ GUARDED_BY(crit_sect_); |
112 std::unique_ptr<FrameDropper> frame_dropper_ GUARDED_BY(crit_sect_); | 99 std::unique_ptr<FrameDropper> frame_dropper_ GUARDED_BY(crit_sect_); |
113 uint32_t send_statistics_[4] GUARDED_BY(crit_sect_); | |
114 uint32_t send_statistics_zero_encode_ GUARDED_BY(crit_sect_); | |
115 int32_t max_payload_size_ GUARDED_BY(crit_sect_); | |
116 int video_target_bitrate_ GUARDED_BY(crit_sect_); | 100 int video_target_bitrate_ GUARDED_BY(crit_sect_); |
117 float incoming_frame_rate_ GUARDED_BY(crit_sect_); | 101 float incoming_frame_rate_ GUARDED_BY(crit_sect_); |
118 int64_t incoming_frame_times_[kFrameCountHistorySize] GUARDED_BY(crit_sect_); | 102 int64_t incoming_frame_times_[kFrameCountHistorySize] GUARDED_BY(crit_sect_); |
119 std::list<EncodedFrameSample> encoded_frame_samples_ GUARDED_BY(crit_sect_); | 103 std::list<EncodedFrameSample> encoded_frame_samples_ GUARDED_BY(crit_sect_); |
120 uint32_t avg_sent_framerate_ GUARDED_BY(crit_sect_); | 104 uint32_t avg_sent_framerate_ GUARDED_BY(crit_sect_); |
121 int num_layers_ GUARDED_BY(crit_sect_); | |
122 }; | 105 }; |
123 } // namespace media_optimization | 106 } // namespace media_optimization |
124 } // namespace webrtc | 107 } // namespace webrtc |
125 | 108 |
126 #endif // WEBRTC_MODULES_VIDEO_CODING_MEDIA_OPTIMIZATION_H_ | 109 #endif // WEBRTC_MODULES_VIDEO_CODING_MEDIA_OPTIMIZATION_H_ |
OLD | NEW |