| 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. |
| 129 // This function is currently only used by unittests. |
| 130 int64_t GetLastByteSentForPacket(const PacketKey& packet_key); | 130 int64_t GetLastByteSentForPacket(const PacketKey& packet_key); |
| 131 | 131 |
| 132 // Returns the total number of bytes sent to the socket when the last payload | 132 // Returns the total number of bytes sent to the socket when the last payload |
| 133 // identified by SSRC is just sent. | 133 // identified by SSRC is just sent. Returns 0 for an unknown ssrc. |
| 134 // This function is currently only used by unittests. |
| 134 int64_t GetLastByteSentForSsrc(uint32_t ssrc); | 135 int64_t GetLastByteSentForSsrc(uint32_t ssrc); |
| 135 | 136 |
| 136 // PacedPacketSender implementation. | 137 // PacedPacketSender implementation. |
| 137 bool SendPackets(const SendPacketVector& packets) final; | 138 bool SendPackets(const SendPacketVector& packets) final; |
| 138 bool ResendPackets(const SendPacketVector& packets, | 139 bool ResendPackets(const SendPacketVector& packets, |
| 139 const DedupInfo& dedup_info) final; | 140 const DedupInfo& dedup_info) final; |
| 140 bool SendRtcpPacket(uint32_t ssrc, PacketRef packet) final; | 141 bool SendRtcpPacket(uint32_t ssrc, PacketRef packet) final; |
| 141 void CancelSendingPacket(const PacketKey& packet_key) final; | 142 void CancelSendingPacket(const PacketKey& packet_key) final; |
| 142 | 143 |
| 143 void SetTargetBurstSize(int burst_size) { | 144 void SetTargetBurstSize(int burst_size) { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 | 199 |
| 199 // Returns true if the packet should have a higher priority. | 200 // Returns true if the packet should have a higher priority. |
| 200 bool IsHighPriority(const PacketKey& packet_key) const; | 201 bool IsHighPriority(const PacketKey& packet_key) const; |
| 201 | 202 |
| 202 // These are externally-owned objects injected via the constructor. | 203 // These are externally-owned objects injected via the constructor. |
| 203 base::TickClock* const clock_; | 204 base::TickClock* const clock_; |
| 204 std::vector<PacketEvent>* const recent_packet_events_; | 205 std::vector<PacketEvent>* const recent_packet_events_; |
| 205 PacketTransport* const transport_; | 206 PacketTransport* const transport_; |
| 206 | 207 |
| 207 scoped_refptr<base::SingleThreadTaskRunner> transport_task_runner_; | 208 scoped_refptr<base::SingleThreadTaskRunner> transport_task_runner_; |
| 208 uint32_t audio_ssrc_; | |
| 209 uint32_t video_ssrc_; | |
| 210 | 209 |
| 211 // Set of SSRCs that have higher priority. This is a vector instead of a | 210 // 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). | 211 // set because there's only very few in it (most likely 1). |
| 213 std::vector<uint32_t> priority_ssrcs_; | 212 std::vector<uint32_t> priority_ssrcs_; |
| 214 typedef std::map<PacketKey, std::pair<PacketType, PacketRef> > PacketList; | 213 typedef std::map<PacketKey, std::pair<PacketType, PacketRef> > PacketList; |
| 215 PacketList packet_list_; | 214 PacketList packet_list_; |
| 216 PacketList priority_packet_list_; | 215 PacketList priority_packet_list_; |
| 217 | 216 |
| 218 struct PacketSendRecord { | 217 struct PacketSendRecord; |
| 219 PacketSendRecord(); | 218 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_; | 219 PacketSendHistory send_history_; |
| 229 PacketSendHistory send_history_buffer_; | 220 PacketSendHistory send_history_buffer_; |
| 230 // Records the last byte sent for payload with a specific SSRC. | 221 |
| 231 std::map<uint32_t, int64_t> last_byte_sent_; | 222 struct RtpSession; |
| 223 using SessionMap = std::map<uint32_t, RtpSession>; |
| 224 // Records all the cast sessions with the sender SSRC as the key. These |
| 225 // sessions are in sync with those in CastTransportImpl. |
| 226 SessionMap sessions_; |
| 227 |
| 228 // Records the last byte sent for audio payload. |
| 229 int64_t last_byte_sent_for_audio_; |
| 232 | 230 |
| 233 size_t target_burst_size_; | 231 size_t target_burst_size_; |
| 234 size_t max_burst_size_; | 232 size_t max_burst_size_; |
| 235 | 233 |
| 236 // Maximum burst size for the next three bursts. | 234 // Maximum burst size for the next three bursts. |
| 237 size_t current_max_burst_size_; | 235 size_t current_max_burst_size_; |
| 238 size_t next_max_burst_size_; | 236 size_t next_max_burst_size_; |
| 239 size_t next_next_max_burst_size_; | 237 size_t next_next_max_burst_size_; |
| 240 // Number of packets already sent in the current burst. | 238 // Number of packets already sent in the current burst. |
| 241 size_t current_burst_size_; | 239 size_t current_burst_size_; |
| 242 // This is when the current burst ends. | 240 // This is when the current burst ends. |
| 243 base::TimeTicks burst_end_; | 241 base::TimeTicks burst_end_; |
| 244 | 242 |
| 245 State state_; | 243 State state_; |
| 246 | 244 |
| 247 bool has_reached_upper_bound_once_; | 245 bool has_reached_upper_bound_once_; |
| 248 | 246 |
| 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. | 247 // NOTE: Weak pointers must be invalidated before all other member variables. |
| 255 base::WeakPtrFactory<PacedSender> weak_factory_; | 248 base::WeakPtrFactory<PacedSender> weak_factory_; |
| 256 | 249 |
| 257 DISALLOW_COPY_AND_ASSIGN(PacedSender); | 250 DISALLOW_COPY_AND_ASSIGN(PacedSender); |
| 258 }; | 251 }; |
| 259 | 252 |
| 260 } // namespace cast | 253 } // namespace cast |
| 261 } // namespace media | 254 } // namespace media |
| 262 | 255 |
| 263 #endif // MEDIA_CAST_NET_PACING_PACED_SENDER_H_ | 256 #endif // MEDIA_CAST_NET_PACING_PACED_SENDER_H_ |
| OLD | NEW |