Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(189)

Side by Side Diff: webrtc/modules/pacing/paced_sender.h

Issue 2235373004: Probing: Add support for exponential startup probing (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@fix_probing2
Patch Set: Updates Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <map>
15 #include <memory> 16 #include <memory>
16 #include <set> 17 #include <set>
17 18
19 #include "webrtc/base/checks.h"
18 #include "webrtc/base/thread_annotations.h" 20 #include "webrtc/base/thread_annotations.h"
19 #include "webrtc/modules/include/module.h" 21 #include "webrtc/modules/include/module.h"
20 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" 22 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
21 #include "webrtc/typedefs.h" 23 #include "webrtc/typedefs.h"
22 24
23 namespace webrtc { 25 namespace webrtc {
24 class BitrateProber; 26 class BitrateProber;
25 class Clock; 27 class Clock;
26 class CriticalSectionWrapper; 28 class CriticalSectionWrapper;
27 29
28 namespace paced_sender { 30 namespace paced_sender {
29 class IntervalBudget; 31 class IntervalBudget;
30 struct Packet; 32 struct Packet;
31 class PacketQueue; 33 class PacketQueue;
32 } // namespace paced_sender 34 } // namespace paced_sender
33 35
34 class PacedSender : public Module, public RtpPacketSender { 36 class PacedSender : public Module, public RtpPacketSender {
35 public: 37 public:
38 enum class State {
39 kInit,
40 kWaitForProbingResult,
41 kStartupProbing,
42 kNormal,
43 };
44
36 class PacketSender { 45 class PacketSender {
37 public: 46 public:
38 // Note: packets sent as a result of a callback should not pass by this 47 // Note: packets sent as a result of a callback should not pass by this
39 // module again. 48 // module again.
40 // Called when it's time to send a queued packet. 49 // Called when it's time to send a queued packet.
41 // Returns false if packet cannot be sent. 50 // Returns false if packet cannot be sent.
42 virtual bool TimeToSendPacket(uint32_t ssrc, 51 virtual bool TimeToSendPacket(uint32_t ssrc,
43 uint16_t sequence_number, 52 uint16_t sequence_number,
44 int64_t capture_time_ms, 53 int64_t capture_time_ms,
45 bool retransmission, 54 bool retransmission,
(...skipping 11 matching lines...) Expand all
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 // TODO(isheriff): Large enough to allow measurements up-to 7 Mbps.
77 // This requirement will go away when we cluster multiple packets as a single
78 // probe.
79 static const size_t kMinProbePacketSize = 1000;
stefan-webrtc 2016/08/16 11:27:04 I'm not sure about introducing this change. It wil
Irfan 2016/08/16 18:12:47 I will go ahead and revert this. Since I plan to a
68 80
69 PacedSender(Clock* clock, 81 PacedSender(Clock* clock,
70 PacketSender* packet_sender); 82 PacketSender* packet_sender);
71 83
72 virtual ~PacedSender(); 84 virtual ~PacedSender();
73 85
74 // Temporarily pause all sending. 86 // Temporarily pause all sending.
75 void Pause(); 87 void Pause();
76 88
77 // Resume sending packets. 89 // Resume sending packets.
78 void Resume(); 90 void Resume();
79 91
80 // Enable bitrate probing. Enabled by default, mostly here to simplify 92 // Enable bitrate probing. Enabled by default, mostly here to simplify
81 // testing. Must be called before any packets are being sent to have an 93 // testing. Must be called before any packets are being sent to have an
82 // effect. 94 // effect.
83 void SetProbingEnabled(bool enabled); 95 void SetProbingEnabled(bool enabled);
84 96
85 // Sets the estimated capacity of the network. Must be called once before 97 // Sets the estimated capacity of the network. Must be called once before
86 // packets can be sent. 98 // packets can be sent.
87 // |bitrate_bps| is our estimate of what we are allowed to send on average. 99 // |bitrate_bps| is our estimate of what we are allowed to send on average.
88 // We will pace out bursts of packets at a bitrate of 100 // We will pace out bursts of packets at a bitrate of
89 // |bitrate_bps| * kDefaultPaceMultiplier. 101 // |bitrate_bps| * kDefaultPaceMultiplier.
90 virtual void SetEstimatedBitrate(uint32_t bitrate_bps); 102 virtual void SetEstimatedBitrate(int bitrate_bps);
91 103
92 // Sets the minimum send bitrate and maximum padding bitrate requested by send 104 // Sets the minimum send bitrate and maximum padding bitrate requested by send
93 // streams. 105 // streams.
94 // |min_send_bitrate_bps| might be higher that the estimated available network 106 // |min_send_bitrate_bps| might be higher that the estimated available network
95 // bitrate and if so, the pacer will send with |min_send_bitrate_bps|. 107 // bitrate and if so, the pacer will send with |min_send_bitrate_bps|.
96 // |max_padding_bitrate_bps| might be higher than the estimate available 108 // |max_padding_bitrate_bps| might be higher than the estimate available
97 // network bitrate and if so, the pacer will send padding packets to reach 109 // network bitrate and if so, the pacer will send padding packets to reach
98 // the min of the estimated available bitrate and |max_padding_bitrate_bps|. 110 // the min of the estimated available bitrate and |max_padding_bitrate_bps|.
99 void SetSendBitrateLimits(int min_send_bitrate_bps, 111 void SetSendBitrateLimits(int min_send_bitrate_bps,
100 int max_padding_bitrate_bps); 112 int max_padding_bitrate_bps);
(...skipping 20 matching lines...) Expand all
121 // packets currently in the pacer queue, or 0 if queue is empty. 133 // packets currently in the pacer queue, or 0 if queue is empty.
122 virtual int64_t AverageQueueTimeMs(); 134 virtual int64_t AverageQueueTimeMs();
123 135
124 // Returns the number of milliseconds until the module want a worker thread 136 // Returns the number of milliseconds until the module want a worker thread
125 // to call Process. 137 // to call Process.
126 int64_t TimeUntilNextProcess() override; 138 int64_t TimeUntilNextProcess() override;
127 139
128 // Process any pending packets in the queue(s). 140 // Process any pending packets in the queue(s).
129 void Process() override; 141 void Process() override;
130 142
143 State PacingState();
144 void OnProbingBitrateMeasured(int bitrate_bps);
145
131 private: 146 private:
132 // Updates the number of bytes that can be sent for the next time interval. 147 // Updates the number of bytes that can be sent for the next time interval.
133 void UpdateBytesPerInterval(int64_t delta_time_in_ms) 148 void UpdateBytesPerInterval(int64_t delta_time_in_ms)
134 EXCLUSIVE_LOCKS_REQUIRED(critsect_); 149 EXCLUSIVE_LOCKS_REQUIRED(critsect_);
135 150
136 bool SendPacket(const paced_sender::Packet& packet, int probe_cluster_id) 151 bool SendPacket(const paced_sender::Packet& packet, int probe_cluster_id)
137 EXCLUSIVE_LOCKS_REQUIRED(critsect_); 152 EXCLUSIVE_LOCKS_REQUIRED(critsect_);
138 void SendPadding(size_t padding_needed, int probe_cluster_id) 153 void SendPadding(size_t padding_needed, int probe_cluster_id)
139 EXCLUSIVE_LOCKS_REQUIRED(critsect_); 154 EXCLUSIVE_LOCKS_REQUIRED(critsect_);
140 155
141 Clock* const clock_; 156 Clock* const clock_;
142 PacketSender* const packet_sender_; 157 PacketSender* const packet_sender_;
143 158
144 std::unique_ptr<CriticalSectionWrapper> critsect_; 159 std::unique_ptr<CriticalSectionWrapper> critsect_;
145 bool paused_ GUARDED_BY(critsect_); 160 bool paused_ GUARDED_BY(critsect_);
146 // This is the media budget, keeping track of how many bits of media 161 // This is the media budget, keeping track of how many bits of media
147 // we can pace out during the current interval. 162 // we can pace out during the current interval.
148 std::unique_ptr<paced_sender::IntervalBudget> media_budget_ 163 std::unique_ptr<paced_sender::IntervalBudget> media_budget_
149 GUARDED_BY(critsect_); 164 GUARDED_BY(critsect_);
150 // This is the padding budget, keeping track of how many bits of padding we're 165 // This is the padding budget, keeping track of how many bits of padding we're
151 // allowed to send out during the current interval. This budget will be 166 // allowed to send out during the current interval. This budget will be
152 // utilized when there's no media to send. 167 // utilized when there's no media to send.
153 std::unique_ptr<paced_sender::IntervalBudget> padding_budget_ 168 std::unique_ptr<paced_sender::IntervalBudget> padding_budget_
154 GUARDED_BY(critsect_); 169 GUARDED_BY(critsect_);
155 170
156 std::unique_ptr<BitrateProber> prober_ GUARDED_BY(critsect_); 171 std::unique_ptr<BitrateProber> prober_ GUARDED_BY(critsect_);
157 // Actual configured bitrates (media_budget_ may temporarily be higher in 172 // Actual configured bitrates (media_budget_ may temporarily be higher in
158 // order to meet pace time constraint). 173 // order to meet pace time constraint).
159 uint32_t estimated_bitrate_bps_ GUARDED_BY(critsect_); 174 int estimated_bitrate_bps_ GUARDED_BY(critsect_);
160 uint32_t min_send_bitrate_kbps_ GUARDED_BY(critsect_); 175 int min_send_bitrate_kbps_ GUARDED_BY(critsect_);
161 uint32_t max_padding_bitrate_kbps_ GUARDED_BY(critsect_); 176 int max_padding_bitrate_kbps_ GUARDED_BY(critsect_);
162 uint32_t pacing_bitrate_kbps_ GUARDED_BY(critsect_); 177 int pacing_bitrate_kbps_ GUARDED_BY(critsect_);
163 178
164 int64_t time_last_update_us_ GUARDED_BY(critsect_); 179 int64_t time_last_update_us_ GUARDED_BY(critsect_);
165 180
166 std::unique_ptr<paced_sender::PacketQueue> packets_ GUARDED_BY(critsect_); 181 std::unique_ptr<paced_sender::PacketQueue> packets_ GUARDED_BY(critsect_);
167 uint64_t packet_counter_; 182 uint64_t packet_counter_;
183 // TODO(isheriff): Adding critsect_ gets clang complaints even with
184 // critsect_ protection turned on!
185 State pacing_state_;
186 int64_t start_time_wait_probe_result_ms_ GUARDED_BY(critsect_);
187 int min_bitrate_to_probe_further_ GUARDED_BY(critsect_);
188 int bitrate_below_expected_count_ GUARDED_BY(critsect_) = 0;
stefan-webrtc 2016/08/16 11:27:05 Initialize in initializer list instead.
Irfan 2016/08/16 18:12:47 Will do, but I seem to recall seeing in style this
168 }; 189 };
169 } // namespace webrtc 190 } // namespace webrtc
170 #endif // WEBRTC_MODULES_PACING_PACED_SENDER_H_ 191 #endif // WEBRTC_MODULES_PACING_PACED_SENDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698