OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MEDIA_CAST_NET_PACING_PACED_SENDER_H_ | 5 #ifndef MEDIA_CAST_NET_PACING_PACED_SENDER_H_ |
6 #define MEDIA_CAST_NET_PACING_PACED_SENDER_H_ | 6 #define MEDIA_CAST_NET_PACING_PACED_SENDER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
15 #include "base/threading/non_thread_safe.h" | 15 #include "base/threading/non_thread_safe.h" |
16 #include "base/time/default_tick_clock.h" | 16 #include "base/time/default_tick_clock.h" |
17 #include "base/time/tick_clock.h" | 17 #include "base/time/tick_clock.h" |
18 #include "base/time/time.h" | 18 #include "base/time/time.h" |
19 #include "media/cast/logging/logging_defines.h" | 19 #include "media/cast/logging/logging_defines.h" |
20 #include "media/cast/net/cast_transport_config.h" | 20 #include "media/cast/net/cast_transport_config.h" |
21 | 21 |
22 namespace media { | 22 namespace media { |
23 namespace cast { | 23 namespace cast { |
24 | 24 |
| 25 // Meant to use as defaults for pacer construction. |
| 26 static const size_t kTargetBurstSize = 10; |
| 27 static const size_t kMaxBurstSize = 20; |
| 28 |
25 class LoggingImpl; | 29 class LoggingImpl; |
26 | 30 |
27 // Use std::pair for free comparison operators. | 31 // Use std::pair for free comparison operators. |
28 // { capture_time, ssrc, packet_id } | 32 // { capture_time, ssrc, packet_id } |
29 // The PacketKey is designed to meet two criteria: | 33 // The PacketKey is designed to meet two criteria: |
30 // 1. When we re-send the same packet again, we can use the packet key | 34 // 1. When we re-send the same packet again, we can use the packet key |
31 // to identify it so that we can de-duplicate packets in the queue. | 35 // to identify it so that we can de-duplicate packets in the queue. |
32 // 2. The sort order of the PacketKey determines the order that packets | 36 // 2. The sort order of the PacketKey determines the order that packets |
33 // are sent out. Using the capture_time as the first member basically | 37 // are sent out. Using the capture_time as the first member basically |
34 // means that older packets are sent first. | 38 // means that older packets are sent first. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 uint16 packet_id); | 75 uint16 packet_id); |
72 }; | 76 }; |
73 | 77 |
74 class PacedSender : public PacedPacketSender, | 78 class PacedSender : public PacedPacketSender, |
75 public base::NonThreadSafe, | 79 public base::NonThreadSafe, |
76 public base::SupportsWeakPtr<PacedSender> { | 80 public base::SupportsWeakPtr<PacedSender> { |
77 public: | 81 public: |
78 // The |external_transport| should only be used by the Cast receiver and for | 82 // The |external_transport| should only be used by the Cast receiver and for |
79 // testing. | 83 // testing. |
80 PacedSender( | 84 PacedSender( |
| 85 size_t target_burst_size, // Should normally be kTargetBurstSize. |
| 86 size_t max_burst_size, // Should normally be kMaxBurstSize. |
81 base::TickClock* clock, | 87 base::TickClock* clock, |
82 LoggingImpl* logging, | 88 LoggingImpl* logging, |
83 PacketSender* external_transport, | 89 PacketSender* external_transport, |
84 const scoped_refptr<base::SingleThreadTaskRunner>& transport_task_runner); | 90 const scoped_refptr<base::SingleThreadTaskRunner>& transport_task_runner); |
85 | 91 |
86 virtual ~PacedSender(); | 92 virtual ~PacedSender(); |
87 | 93 |
88 // These must be called before non-RTCP packets are sent. | 94 // These must be called before non-RTCP packets are sent. |
89 void RegisterAudioSsrc(uint32 audio_ssrc); | 95 void RegisterAudioSsrc(uint32 audio_ssrc); |
90 void RegisterVideoSsrc(uint32 video_ssrc); | 96 void RegisterVideoSsrc(uint32 video_ssrc); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 // packet was sent. | 184 // packet was sent. |
179 int64 last_byte_sent_for_audio; // Number of bytes sent to network from | 185 int64 last_byte_sent_for_audio; // Number of bytes sent to network from |
180 // audio stream just before this packet. | 186 // audio stream just before this packet. |
181 }; | 187 }; |
182 typedef std::map<PacketKey, PacketSendRecord> PacketSendHistory; | 188 typedef std::map<PacketKey, PacketSendRecord> PacketSendHistory; |
183 PacketSendHistory send_history_; | 189 PacketSendHistory send_history_; |
184 PacketSendHistory send_history_buffer_; | 190 PacketSendHistory send_history_buffer_; |
185 // Records the last byte sent for payload with a specific SSRC. | 191 // Records the last byte sent for payload with a specific SSRC. |
186 std::map<uint32, int64> last_byte_sent_; | 192 std::map<uint32, int64> last_byte_sent_; |
187 | 193 |
| 194 size_t target_burst_size_; |
| 195 size_t max_burst_size_; |
| 196 |
188 // Maximum burst size for the next three bursts. | 197 // Maximum burst size for the next three bursts. |
189 size_t max_burst_size_; | 198 size_t current_max_burst_size_; |
190 size_t next_max_burst_size_; | 199 size_t next_max_burst_size_; |
191 size_t next_next_max_burst_size_; | 200 size_t next_next_max_burst_size_; |
192 // Number of packets already sent in the current burst. | 201 // Number of packets already sent in the current burst. |
193 size_t current_burst_size_; | 202 size_t current_burst_size_; |
194 // This is when the current burst ends. | 203 // This is when the current burst ends. |
195 base::TimeTicks burst_end_; | 204 base::TimeTicks burst_end_; |
196 | 205 |
197 State state_; | 206 State state_; |
198 | 207 |
199 // NOTE: Weak pointers must be invalidated before all other member variables. | 208 // NOTE: Weak pointers must be invalidated before all other member variables. |
200 base::WeakPtrFactory<PacedSender> weak_factory_; | 209 base::WeakPtrFactory<PacedSender> weak_factory_; |
201 | 210 |
202 DISALLOW_COPY_AND_ASSIGN(PacedSender); | 211 DISALLOW_COPY_AND_ASSIGN(PacedSender); |
203 }; | 212 }; |
204 | 213 |
205 } // namespace cast | 214 } // namespace cast |
206 } // namespace media | 215 } // namespace media |
207 | 216 |
208 #endif // MEDIA_CAST_NET_PACING_PACED_SENDER_H_ | 217 #endif // MEDIA_CAST_NET_PACING_PACED_SENDER_H_ |
OLD | NEW |