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 |
(...skipping 15 matching lines...) Expand all Loading... | |
26 class CriticalSectionWrapper; | 26 class CriticalSectionWrapper; |
27 | 27 |
28 namespace paced_sender { | 28 namespace paced_sender { |
29 class IntervalBudget; | 29 class IntervalBudget; |
30 struct Packet; | 30 struct Packet; |
31 class PacketQueue; | 31 class PacketQueue; |
32 } // namespace paced_sender | 32 } // namespace paced_sender |
33 | 33 |
34 class PacedSender : public Module, public RtpPacketSender { | 34 class PacedSender : public Module, public RtpPacketSender { |
35 public: | 35 public: |
36 class Callback { | 36 class SenderDelegate { |
mflodman
2016/05/03 11:30:10
Should this be called something with 'Packet' in t
perkj_webrtc
2016/05/03 13:56:00
Why not just call it PacketSender?
| |
37 public: | 37 public: |
38 // Note: packets sent as a result of a callback should not pass by this | 38 // Note: packets sent as a result of a callback should not pass by this |
39 // module again. | 39 // module again. |
40 // Called when it's time to send a queued packet. | 40 // Called when it's time to send a queued packet. |
41 // Returns false if packet cannot be sent. | 41 // Returns false if packet cannot be sent. |
42 virtual bool TimeToSendPacket(uint32_t ssrc, | 42 virtual bool TimeToSendPacket(uint32_t ssrc, |
43 uint16_t sequence_number, | 43 uint16_t sequence_number, |
44 int64_t capture_time_ms, | 44 int64_t capture_time_ms, |
45 bool retransmission) = 0; | 45 bool retransmission) = 0; |
46 // Called when it's a good time to send a padding data. | 46 // Called when it's a good time to send a padding data. |
47 // Returns the number of bytes sent. | 47 // Returns the number of bytes sent. |
48 virtual size_t TimeToSendPadding(size_t bytes) = 0; | 48 virtual size_t TimeToSendPadding(size_t bytes) = 0; |
49 | 49 |
50 protected: | 50 protected: |
51 virtual ~Callback() {} | 51 virtual ~SenderDelegate() {} |
52 }; | 52 }; |
53 | 53 |
54 // Expected max pacer delay in ms. If ExpectedQueueTimeMs() is higher than | 54 // Expected max pacer delay in ms. If ExpectedQueueTimeMs() is higher than |
55 // this value, the packet producers should wait (eg drop frames rather than | 55 // this value, the packet producers should wait (eg drop frames rather than |
56 // encoding them). Bitrate sent may temporarily exceed target set by | 56 // encoding them). Bitrate sent may temporarily exceed target set by |
57 // UpdateBitrate() so that this limit will be upheld. | 57 // UpdateBitrate() so that this limit will be upheld. |
58 static const int64_t kMaxQueueLengthMs; | 58 static const int64_t kMaxQueueLengthMs; |
59 // Pace in kbits/s until we receive first estimate. | 59 // Pace in kbits/s until we receive first estimate. |
60 static const int kDefaultInitialPaceKbps = 2000; | 60 static const int kDefaultInitialPaceKbps = 2000; |
61 // Pacing-rate relative to our target send rate. | 61 // Pacing-rate relative to our target send rate. |
62 // Multiplicative factor that is applied to the target bitrate to calculate | 62 // Multiplicative factor that is applied to the target bitrate to calculate |
63 // the number of bytes that can be transmitted per interval. | 63 // the number of bytes that can be transmitted per interval. |
64 // Increasing this factor will result in lower delays in cases of bitrate | 64 // Increasing this factor will result in lower delays in cases of bitrate |
65 // overshoots from the encoder. | 65 // overshoots from the encoder. |
66 static const float kDefaultPaceMultiplier; | 66 static const float kDefaultPaceMultiplier; |
67 | 67 |
68 static const size_t kMinProbePacketSize = 200; | 68 static const size_t kMinProbePacketSize = 200; |
69 | 69 |
70 PacedSender(Clock* clock, | 70 PacedSender(Clock* clock, SenderDelegate* delegate, int target_bitrate_bps); |
71 Callback* callback, | |
72 int bitrate_kbps, | |
73 int max_bitrate_kbps, | |
74 int min_bitrate_kbps); | |
75 | 71 |
76 virtual ~PacedSender(); | 72 virtual ~PacedSender(); |
77 | 73 |
78 // Temporarily pause all sending. | 74 // Temporarily pause all sending. |
79 void Pause(); | 75 void Pause(); |
80 | 76 |
81 // Resume sending packets. | 77 // Resume sending packets. |
82 void Resume(); | 78 void Resume(); |
83 | 79 |
84 // Enable bitrate probing. Enabled by default, mostly here to simplify | 80 // Enable bitrate probing. Enabled by default, mostly here to simplify |
85 // testing. Must be called before any packets are being sent to have an | 81 // testing. Must be called before any packets are being sent to have an |
86 // effect. | 82 // effect. |
87 void SetProbingEnabled(bool enabled); | 83 void SetProbingEnabled(bool enabled); |
88 | 84 |
89 // Set target bitrates for the pacer. | 85 // Sets the estimated capacity of the network. |
90 // We will pace out bursts of packets at a bitrate of |max_bitrate_kbps|. | 86 // |bitrate_bps| is our estimate of what we are allowed to send on average. |
91 // |bitrate_kbps| is our estimate of what we are allowed to send on average. | 87 // We will pace out bursts of packets at a bitrate of |
92 // Padding packets will be utilized to reach |min_bitrate| unless enough media | 88 // |bitrate_bps| * kDefaultPaceMultiplier. |
93 // packets are available. | 89 void SetEstimatedBitrate(uint32_t bitrate_bps); |
94 void UpdateBitrate(int bitrate_kbps, | 90 |
95 int max_bitrate_kbps, | 91 // Sets the bitrate that has been allocated for encoders. |
96 int min_bitrate_kbps); | 92 // |allocated_bitrate| might be higher that the estimated available network |
93 // bitrate and if so, the pacer will send with |allocated_bitrate|. | |
94 // Padding packets will be utilized to reach |padding_bitrate| unless enough | |
95 // media packets are available. | |
96 void SetAllocatedSendBitrate(int allocated_bitrate_bps, | |
97 int padding_bitrate_bps); | |
97 | 98 |
98 // Returns true if we send the packet now, else it will add the packet | 99 // Returns true if we send the packet now, else it will add the packet |
99 // information to the queue and call TimeToSendPacket when it's time to send. | 100 // information to the queue and call TimeToSendPacket when it's time to send. |
100 void InsertPacket(RtpPacketSender::Priority priority, | 101 void InsertPacket(RtpPacketSender::Priority priority, |
101 uint32_t ssrc, | 102 uint32_t ssrc, |
102 uint16_t sequence_number, | 103 uint16_t sequence_number, |
103 int64_t capture_time_ms, | 104 int64_t capture_time_ms, |
104 size_t bytes, | 105 size_t bytes, |
105 bool retransmission) override; | 106 bool retransmission) override; |
106 | 107 |
(...skipping 20 matching lines...) Expand all Loading... | |
127 private: | 128 private: |
128 // Updates the number of bytes that can be sent for the next time interval. | 129 // Updates the number of bytes that can be sent for the next time interval. |
129 void UpdateBytesPerInterval(int64_t delta_time_in_ms) | 130 void UpdateBytesPerInterval(int64_t delta_time_in_ms) |
130 EXCLUSIVE_LOCKS_REQUIRED(critsect_); | 131 EXCLUSIVE_LOCKS_REQUIRED(critsect_); |
131 | 132 |
132 bool SendPacket(const paced_sender::Packet& packet) | 133 bool SendPacket(const paced_sender::Packet& packet) |
133 EXCLUSIVE_LOCKS_REQUIRED(critsect_); | 134 EXCLUSIVE_LOCKS_REQUIRED(critsect_); |
134 void SendPadding(size_t padding_needed) EXCLUSIVE_LOCKS_REQUIRED(critsect_); | 135 void SendPadding(size_t padding_needed) EXCLUSIVE_LOCKS_REQUIRED(critsect_); |
135 | 136 |
136 Clock* const clock_; | 137 Clock* const clock_; |
137 Callback* const callback_; | 138 SenderDelegate* const delegate_; |
138 | 139 |
139 std::unique_ptr<CriticalSectionWrapper> critsect_; | 140 std::unique_ptr<CriticalSectionWrapper> critsect_; |
140 bool paused_ GUARDED_BY(critsect_); | 141 bool paused_ GUARDED_BY(critsect_); |
141 bool probing_enabled_; | 142 bool probing_enabled_; |
142 // This is the media budget, keeping track of how many bits of media | 143 // This is the media budget, keeping track of how many bits of media |
143 // we can pace out during the current interval. | 144 // we can pace out during the current interval. |
144 std::unique_ptr<paced_sender::IntervalBudget> media_budget_ | 145 std::unique_ptr<paced_sender::IntervalBudget> media_budget_ |
145 GUARDED_BY(critsect_); | 146 GUARDED_BY(critsect_); |
146 // This is the padding budget, keeping track of how many bits of padding we're | 147 // This is the padding budget, keeping track of how many bits of padding we're |
147 // allowed to send out during the current interval. This budget will be | 148 // allowed to send out during the current interval. This budget will be |
148 // utilized when there's no media to send. | 149 // utilized when there's no media to send. |
149 std::unique_ptr<paced_sender::IntervalBudget> padding_budget_ | 150 std::unique_ptr<paced_sender::IntervalBudget> padding_budget_ |
150 GUARDED_BY(critsect_); | 151 GUARDED_BY(critsect_); |
151 | 152 |
152 std::unique_ptr<BitrateProber> prober_ GUARDED_BY(critsect_); | 153 std::unique_ptr<BitrateProber> prober_ GUARDED_BY(critsect_); |
153 // Actual configured bitrates (media_budget_ may temporarily be higher in | 154 // Actual configured bitrates (media_budget_ may temporarily be higher in |
154 // order to meet pace time constraint). | 155 // order to meet pace time constraint). |
155 int bitrate_bps_ GUARDED_BY(critsect_); | 156 uint32_t estimated_bitrate_bps_ GUARDED_BY(critsect_); |
156 int max_bitrate_kbps_ GUARDED_BY(critsect_); | 157 uint32_t min_send_bitrate_kbps_ GUARDED_BY(critsect_); |
158 uint32_t pacing_bitrate_kbps_ GUARDED_BY(critsect_); | |
157 | 159 |
158 int64_t time_last_update_us_ GUARDED_BY(critsect_); | 160 int64_t time_last_update_us_ GUARDED_BY(critsect_); |
159 | 161 |
160 std::unique_ptr<paced_sender::PacketQueue> packets_ GUARDED_BY(critsect_); | 162 std::unique_ptr<paced_sender::PacketQueue> packets_ GUARDED_BY(critsect_); |
161 uint64_t packet_counter_; | 163 uint64_t packet_counter_; |
162 }; | 164 }; |
163 } // namespace webrtc | 165 } // namespace webrtc |
164 #endif // WEBRTC_MODULES_PACING_PACED_SENDER_H_ | 166 #endif // WEBRTC_MODULES_PACING_PACED_SENDER_H_ |
OLD | NEW |