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_PACING_PACED_SENDER_H_ | 11 #ifndef WEBRTC_MODULES_PACING_PACED_SENDER_H_ |
12 #define WEBRTC_MODULES_PACING_PACED_SENDER_H_ | 12 #define WEBRTC_MODULES_PACING_PACED_SENDER_H_ |
13 | 13 |
14 #include <list> | 14 #include <list> |
15 #include <memory> | 15 #include <memory> |
16 #include <set> | 16 #include <set> |
17 | 17 |
18 #include "webrtc/base/thread_annotations.h" | 18 #include "webrtc/base/thread_annotations.h" |
19 #include "webrtc/modules/include/module.h" | 19 #include "webrtc/modules/include/module.h" |
20 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" | 20 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
21 #include "webrtc/typedefs.h" | 21 #include "webrtc/typedefs.h" |
22 | 22 |
23 namespace webrtc { | 23 namespace webrtc { |
24 class AlrDetector; | |
24 class BitrateProber; | 25 class BitrateProber; |
25 class Clock; | 26 class Clock; |
26 class CriticalSectionWrapper; | 27 class CriticalSectionWrapper; |
27 | 28 |
28 namespace paced_sender { | 29 namespace paced_sender { |
29 class IntervalBudget; | 30 class IntervalBudget; |
30 struct Packet; | 31 struct Packet; |
31 class PacketQueue; | 32 class PacketQueue; |
32 } // namespace paced_sender | 33 } // namespace paced_sender |
33 | 34 |
(...skipping 11 matching lines...) Expand all Loading... | |
45 bool retransmission, | 46 bool retransmission, |
46 int probe_cluster_id) = 0; | 47 int probe_cluster_id) = 0; |
47 // Called when it's a good time to send a padding data. | 48 // Called when it's a good time to send a padding data. |
48 // Returns the number of bytes sent. | 49 // Returns the number of bytes sent. |
49 virtual size_t TimeToSendPadding(size_t bytes, int probe_cluster_id) = 0; | 50 virtual size_t TimeToSendPadding(size_t bytes, int probe_cluster_id) = 0; |
50 | 51 |
51 protected: | 52 protected: |
52 virtual ~PacketSender() {} | 53 virtual ~PacketSender() {} |
53 }; | 54 }; |
54 | 55 |
56 class PacingObserver { | |
stefan-webrtc
2016/09/27 14:26:09
Wouldn't it be simpler to let the PacedSender own
| |
57 public: | |
58 virtual void OnBytesSent(size_t bytes_sent, int64_t elapsed_time_ms) = 0; | |
59 | |
60 protected: | |
61 virtual ~PacingObserver() {} | |
62 }; | |
63 | |
55 // Expected max pacer delay in ms. If ExpectedQueueTimeMs() is higher than | 64 // Expected max pacer delay in ms. If ExpectedQueueTimeMs() is higher than |
56 // this value, the packet producers should wait (eg drop frames rather than | 65 // this value, the packet producers should wait (eg drop frames rather than |
57 // encoding them). Bitrate sent may temporarily exceed target set by | 66 // encoding them). Bitrate sent may temporarily exceed target set by |
58 // UpdateBitrate() so that this limit will be upheld. | 67 // UpdateBitrate() so that this limit will be upheld. |
59 static const int64_t kMaxQueueLengthMs; | 68 static const int64_t kMaxQueueLengthMs; |
60 // Pacing-rate relative to our target send rate. | 69 // Pacing-rate relative to our target send rate. |
61 // Multiplicative factor that is applied to the target bitrate to calculate | 70 // Multiplicative factor that is applied to the target bitrate to calculate |
62 // the number of bytes that can be transmitted per interval. | 71 // the number of bytes that can be transmitted per interval. |
63 // Increasing this factor will result in lower delays in cases of bitrate | 72 // Increasing this factor will result in lower delays in cases of bitrate |
64 // overshoots from the encoder. | 73 // overshoots from the encoder. |
65 static const float kDefaultPaceMultiplier; | 74 static const float kDefaultPaceMultiplier; |
66 | 75 |
67 static const size_t kMinProbePacketSize = 200; | 76 static const size_t kMinProbePacketSize = 200; |
68 | 77 |
69 PacedSender(Clock* clock, | 78 PacedSender(Clock* clock, |
70 PacketSender* packet_sender); | 79 PacketSender* packet_sender, |
80 PacingObserver* pacing_observer); | |
81 PacedSender(Clock* clock, PacketSender* packet_sender); | |
71 | 82 |
72 virtual ~PacedSender(); | 83 virtual ~PacedSender(); |
73 | 84 |
74 virtual void CreateProbeCluster(int bitrate_bps, int num_packets); | 85 virtual void CreateProbeCluster(int bitrate_bps, int num_packets); |
75 | 86 |
76 // Temporarily pause all sending. | 87 // Temporarily pause all sending. |
77 void Pause(); | 88 void Pause(); |
78 | 89 |
79 // Resume sending packets. | 90 // Resume sending packets. |
80 void Resume(); | 91 void Resume(); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
125 | 136 |
126 // Returns the number of milliseconds until the module want a worker thread | 137 // Returns the number of milliseconds until the module want a worker thread |
127 // to call Process. | 138 // to call Process. |
128 int64_t TimeUntilNextProcess() override; | 139 int64_t TimeUntilNextProcess() override; |
129 | 140 |
130 // Process any pending packets in the queue(s). | 141 // Process any pending packets in the queue(s). |
131 void Process() override; | 142 void Process() override; |
132 | 143 |
133 private: | 144 private: |
134 // Updates the number of bytes that can be sent for the next time interval. | 145 // Updates the number of bytes that can be sent for the next time interval. |
135 void UpdateBytesPerInterval(int64_t delta_time_in_ms) | 146 void UpdateBudgetWithElapsedTime(int64_t delta_time_in_ms) |
147 EXCLUSIVE_LOCKS_REQUIRED(critsect_); | |
148 void UpdateBudgetWithBytesSent(size_t bytes) | |
136 EXCLUSIVE_LOCKS_REQUIRED(critsect_); | 149 EXCLUSIVE_LOCKS_REQUIRED(critsect_); |
137 | 150 |
138 bool SendPacket(const paced_sender::Packet& packet, int probe_cluster_id) | 151 bool SendPacket(const paced_sender::Packet& packet, int probe_cluster_id) |
139 EXCLUSIVE_LOCKS_REQUIRED(critsect_); | 152 EXCLUSIVE_LOCKS_REQUIRED(critsect_); |
140 size_t SendPadding(size_t padding_needed, int probe_cluster_id) | 153 size_t SendPadding(size_t padding_needed, int probe_cluster_id) |
141 EXCLUSIVE_LOCKS_REQUIRED(critsect_); | 154 EXCLUSIVE_LOCKS_REQUIRED(critsect_); |
142 | 155 |
143 Clock* const clock_; | 156 Clock* const clock_; |
144 PacketSender* const packet_sender_; | 157 PacketSender* const packet_sender_; |
158 PacingObserver* const pacing_observer_; | |
145 | 159 |
146 std::unique_ptr<CriticalSectionWrapper> critsect_; | 160 std::unique_ptr<CriticalSectionWrapper> critsect_; |
147 bool paused_ GUARDED_BY(critsect_); | 161 bool paused_ GUARDED_BY(critsect_); |
148 // This is the media budget, keeping track of how many bits of media | 162 // This is the media budget, keeping track of how many bits of media |
149 // we can pace out during the current interval. | 163 // we can pace out during the current interval. |
150 std::unique_ptr<paced_sender::IntervalBudget> media_budget_ | 164 std::unique_ptr<paced_sender::IntervalBudget> media_budget_ |
151 GUARDED_BY(critsect_); | 165 GUARDED_BY(critsect_); |
152 // This is the padding budget, keeping track of how many bits of padding we're | 166 // This is the padding budget, keeping track of how many bits of padding we're |
153 // allowed to send out during the current interval. This budget will be | 167 // allowed to send out during the current interval. This budget will be |
154 // utilized when there's no media to send. | 168 // utilized when there's no media to send. |
155 std::unique_ptr<paced_sender::IntervalBudget> padding_budget_ | 169 std::unique_ptr<paced_sender::IntervalBudget> padding_budget_ |
156 GUARDED_BY(critsect_); | 170 GUARDED_BY(critsect_); |
157 | 171 |
158 std::unique_ptr<BitrateProber> prober_ GUARDED_BY(critsect_); | 172 std::unique_ptr<BitrateProber> prober_ GUARDED_BY(critsect_); |
159 // Actual configured bitrates (media_budget_ may temporarily be higher in | 173 // Actual configured bitrates (media_budget_ may temporarily be higher in |
160 // order to meet pace time constraint). | 174 // order to meet pace time constraint). |
161 uint32_t estimated_bitrate_bps_ GUARDED_BY(critsect_); | 175 uint32_t estimated_bitrate_bps_ GUARDED_BY(critsect_); |
162 uint32_t min_send_bitrate_kbps_ GUARDED_BY(critsect_); | 176 uint32_t min_send_bitrate_kbps_ GUARDED_BY(critsect_); |
163 uint32_t max_padding_bitrate_kbps_ GUARDED_BY(critsect_); | 177 uint32_t max_padding_bitrate_kbps_ GUARDED_BY(critsect_); |
164 uint32_t pacing_bitrate_kbps_ GUARDED_BY(critsect_); | 178 uint32_t pacing_bitrate_kbps_ GUARDED_BY(critsect_); |
165 | 179 |
166 int64_t time_last_update_us_ GUARDED_BY(critsect_); | 180 int64_t time_last_update_us_ GUARDED_BY(critsect_); |
167 | 181 |
168 std::unique_ptr<paced_sender::PacketQueue> packets_ GUARDED_BY(critsect_); | 182 std::unique_ptr<paced_sender::PacketQueue> packets_ GUARDED_BY(critsect_); |
169 uint64_t packet_counter_; | 183 uint64_t packet_counter_; |
170 }; | 184 }; |
171 } // namespace webrtc | 185 } // namespace webrtc |
172 #endif // WEBRTC_MODULES_PACING_PACED_SENDER_H_ | 186 #endif // WEBRTC_MODULES_PACING_PACED_SENDER_H_ |
OLD | NEW |