| 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 <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 size_t target_burst_size, // Should normally be kTargetBurstSize. | 108 size_t target_burst_size, // Should normally be kTargetBurstSize. |
| 109 size_t max_burst_size, // Should normally be kMaxBurstSize. | 109 size_t max_burst_size, // Should normally be kMaxBurstSize. |
| 110 base::TickClock* clock, | 110 base::TickClock* clock, |
| 111 std::vector<PacketEvent>* recent_packet_events, | 111 std::vector<PacketEvent>* recent_packet_events, |
| 112 PacketTransport* external_transport, | 112 PacketTransport* external_transport, |
| 113 const scoped_refptr<base::SingleThreadTaskRunner>& transport_task_runner); | 113 const scoped_refptr<base::SingleThreadTaskRunner>& transport_task_runner); |
| 114 | 114 |
| 115 ~PacedSender() final; | 115 ~PacedSender() final; |
| 116 | 116 |
| 117 // These must be called before non-RTCP packets are sent. | 117 // These must be called before non-RTCP packets are sent. |
| 118 void RegisterAudioSsrc(uint32_t audio_ssrc); | 118 void RegisterSsrc(uint32_t ssrc, bool is_audio); |
| 119 void RegisterVideoSsrc(uint32_t video_ssrc); | |
| 120 | 119 |
| 121 // Register SSRC that has a higher priority for sending. Multiple SSRCs can | 120 // Register SSRC that has a higher priority for sending. Multiple SSRCs can |
| 122 // be registered. | 121 // be registered. |
| 123 // Note that it is not expected to register many SSRCs with this method. | 122 // Note that it is not expected to register many SSRCs with this method. |
| 124 // Because IsHigherPriority() is determined in linear time. | 123 // Because IsHigherPriority() is determined in linear time. |
| 125 void RegisterPrioritySsrc(uint32_t ssrc); | 124 void RegisterPrioritySsrc(uint32_t ssrc); |
| 126 | 125 |
| 127 // Returns the total number of bytes sent to the socket when the specified | 126 // Returns the total number of bytes sent to the socket when the specified |
| 128 // packet was just sent. | 127 // packet was just sent. |
| 129 // Returns 0 if the packet cannot be found or not yet sent. | 128 // Returns 0 if the packet cannot be found or not yet sent. |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 | 197 |
| 199 // Returns true if the packet should have a higher priority. | 198 // Returns true if the packet should have a higher priority. |
| 200 bool IsHighPriority(const PacketKey& packet_key) const; | 199 bool IsHighPriority(const PacketKey& packet_key) const; |
| 201 | 200 |
| 202 // These are externally-owned objects injected via the constructor. | 201 // These are externally-owned objects injected via the constructor. |
| 203 base::TickClock* const clock_; | 202 base::TickClock* const clock_; |
| 204 std::vector<PacketEvent>* const recent_packet_events_; | 203 std::vector<PacketEvent>* const recent_packet_events_; |
| 205 PacketTransport* const transport_; | 204 PacketTransport* const transport_; |
| 206 | 205 |
| 207 scoped_refptr<base::SingleThreadTaskRunner> transport_task_runner_; | 206 scoped_refptr<base::SingleThreadTaskRunner> transport_task_runner_; |
| 208 uint32_t audio_ssrc_; | |
| 209 uint32_t video_ssrc_; | |
| 210 | 207 |
| 211 // Set of SSRCs that have higher priority. This is a vector instead of a | 208 // Set of SSRCs that have higher priority. This is a vector instead of a |
| 212 // set because there's only very few in it (most likely 1). | 209 // set because there's only very few in it (most likely 1). |
| 213 std::vector<uint32_t> priority_ssrcs_; | 210 std::vector<uint32_t> priority_ssrcs_; |
| 214 typedef std::map<PacketKey, std::pair<PacketType, PacketRef> > PacketList; | 211 typedef std::map<PacketKey, std::pair<PacketType, PacketRef> > PacketList; |
| 215 PacketList packet_list_; | 212 PacketList packet_list_; |
| 216 PacketList priority_packet_list_; | 213 PacketList priority_packet_list_; |
| 217 | 214 |
| 218 struct PacketSendRecord { | 215 struct PacketSendRecord; |
| 219 PacketSendRecord(); | 216 using PacketSendHistory = std::map<PacketKey, PacketSendRecord>; |
| 220 base::TimeTicks time; // Time when the packet was sent. | |
| 221 int64_t last_byte_sent; // Number of bytes sent to network just after this | |
| 222 // packet was sent. | |
| 223 int64_t last_byte_sent_for_audio; // Number of bytes sent to network from | |
| 224 // audio stream just before this packet. | |
| 225 int cancel_count; // Number of times the packet was canceled (debugging). | |
| 226 }; | |
| 227 typedef std::map<PacketKey, PacketSendRecord> PacketSendHistory; | |
| 228 PacketSendHistory send_history_; | 217 PacketSendHistory send_history_; |
| 229 PacketSendHistory send_history_buffer_; | 218 PacketSendHistory send_history_buffer_; |
| 230 // Records the last byte sent for payload with a specific SSRC. | 219 |
| 231 std::map<uint32_t, int64_t> last_byte_sent_; | 220 struct RtpSession; |
| 221 using SessionMap = std::map<uint32_t, RtpSession>; |
| 222 SessionMap sessions_; |
| 223 |
| 224 // Records the last byte sent for audio payload. |
| 225 int64_t last_byte_sent_for_audio_; |
| 232 | 226 |
| 233 size_t target_burst_size_; | 227 size_t target_burst_size_; |
| 234 size_t max_burst_size_; | 228 size_t max_burst_size_; |
| 235 | 229 |
| 236 // Maximum burst size for the next three bursts. | 230 // Maximum burst size for the next three bursts. |
| 237 size_t current_max_burst_size_; | 231 size_t current_max_burst_size_; |
| 238 size_t next_max_burst_size_; | 232 size_t next_max_burst_size_; |
| 239 size_t next_next_max_burst_size_; | 233 size_t next_next_max_burst_size_; |
| 240 // Number of packets already sent in the current burst. | 234 // Number of packets already sent in the current burst. |
| 241 size_t current_burst_size_; | 235 size_t current_burst_size_; |
| 242 // This is when the current burst ends. | 236 // This is when the current burst ends. |
| 243 base::TimeTicks burst_end_; | 237 base::TimeTicks burst_end_; |
| 244 | 238 |
| 245 State state_; | 239 State state_; |
| 246 | 240 |
| 247 bool has_reached_upper_bound_once_; | 241 bool has_reached_upper_bound_once_; |
| 248 | 242 |
| 249 // Tracks recently-logged RTP timestamps so that it can expand the truncated | |
| 250 // values found in packets. | |
| 251 RtpTimeTicks last_logged_audio_rtp_timestamp_; | |
| 252 RtpTimeTicks last_logged_video_rtp_timestamp_; | |
| 253 | |
| 254 // NOTE: Weak pointers must be invalidated before all other member variables. | 243 // NOTE: Weak pointers must be invalidated before all other member variables. |
| 255 base::WeakPtrFactory<PacedSender> weak_factory_; | 244 base::WeakPtrFactory<PacedSender> weak_factory_; |
| 256 | 245 |
| 257 DISALLOW_COPY_AND_ASSIGN(PacedSender); | 246 DISALLOW_COPY_AND_ASSIGN(PacedSender); |
| 258 }; | 247 }; |
| 259 | 248 |
| 260 } // namespace cast | 249 } // namespace cast |
| 261 } // namespace media | 250 } // namespace media |
| 262 | 251 |
| 263 #endif // MEDIA_CAST_NET_PACING_PACED_SENDER_H_ | 252 #endif // MEDIA_CAST_NET_PACING_PACED_SENDER_H_ |
| OLD | NEW |