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 // This class maintains a send transport for audio and video in a Cast | 5 // This class maintains a send transport for audio and video in a Cast |
6 // Streaming session. | 6 // Streaming session. |
7 // Audio, video frames and RTCP messages are submitted to this object | 7 // Audio, video frames and RTCP messages are submitted to this object |
8 // and then packetized and paced to the underlying UDP socket. | 8 // and then packetized and paced to the underlying UDP socket. |
9 // | 9 // |
10 // The hierarchy of send transport in a Cast Streaming session: | 10 // The hierarchy of send transport in a Cast Streaming session: |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 #include "media/cast/net/rtp/rtp_sender.h" | 47 #include "media/cast/net/rtp/rtp_sender.h" |
48 #include "net/base/network_interfaces.h" | 48 #include "net/base/network_interfaces.h" |
49 | 49 |
50 namespace media { | 50 namespace media { |
51 namespace cast { | 51 namespace cast { |
52 | 52 |
53 class UdpTransport; | 53 class UdpTransport; |
54 | 54 |
55 class CastTransportSenderImpl : public CastTransportSender { | 55 class CastTransportSenderImpl : public CastTransportSender { |
56 public: | 56 public: |
57 // |external_transport| is only used for testing. | |
58 // |raw_events_callback|: Raw events will be returned on this callback | |
59 // which will be invoked every |raw_events_callback_interval|. | |
60 // This can be a null callback, i.e. if user is not interested in raw events. | |
61 // |raw_events_callback_interval|: This can be |base::TimeDelta()| if | |
62 // |raw_events_callback| is a null callback. | |
63 // |options| contains optional settings for the transport, possible | |
64 // keys are: | |
65 // "DSCP" (value ignored) | |
66 // - Turns DSCP on (higher IP Precedence and Type of Service). | |
67 // "disable_non_blocking_io" (value ignored) | |
68 // - Windows only. Turns off non-blocking IO for the socket. | |
69 // Note: Non-blocking IO is, by default, enabled on all platforms. | |
70 // "pacer_target_burst_size": int | |
71 // - Specifies how many packets to send per 10 ms ideally. | |
72 // "pacer_max_burst_size": int | |
73 // - Specifies how many pakcets to send per 10 ms, maximum. | |
74 // "send_buffer_min_size": int | |
75 // - Specifies the minimum socket send buffer size. | |
76 // "disable_wifi_scan" (value ignored) | |
77 // - Disable wifi scans while streaming. | |
78 // "media_streaming_mode" (value ignored) | |
79 // - Turn media streaming mode on. | |
80 // Note, these options may be ignored on some platforms. | |
81 // TODO(hubbe): Too many callbacks, replace with an interface. | |
82 // http://crbug.com/557477 | |
83 CastTransportSenderImpl( | 57 CastTransportSenderImpl( |
84 net::NetLog* net_log, | 58 base::TickClock* clock, // Owned by the caller. |
85 base::TickClock* clock, | 59 base::TimeDelta logging_flush_interval, |
86 const net::IPEndPoint& local_end_point, | 60 scoped_ptr<Client> client, |
87 const net::IPEndPoint& remote_end_point, | 61 scoped_ptr<PacketSender> transport, |
88 scoped_ptr<base::DictionaryValue> options, | 62 const scoped_refptr<base::SingleThreadTaskRunner>& transport_task_runner); |
89 const CastTransportStatusCallback& status_callback, | |
90 const BulkRawEventsCallback& raw_events_callback, | |
91 base::TimeDelta raw_events_callback_interval, | |
92 const scoped_refptr<base::SingleThreadTaskRunner>& transport_task_runner, | |
93 const PacketReceiverCallback& packet_callback, | |
94 PacketSender* external_transport); | |
95 | 63 |
96 ~CastTransportSenderImpl() final; | 64 ~CastTransportSenderImpl() final; |
97 | 65 |
98 // CastTransportSender implementation. | 66 // CastTransportSender implementation. |
99 void InitializeAudio(const CastTransportRtpConfig& config, | 67 void InitializeAudio(const CastTransportRtpConfig& config, |
100 const RtcpCastMessageCallback& cast_message_cb, | 68 const RtcpCastMessageCallback& cast_message_cb, |
101 const RtcpRttCallback& rtt_cb) final; | 69 const RtcpRttCallback& rtt_cb) final; |
102 void InitializeVideo(const CastTransportRtpConfig& config, | 70 void InitializeVideo(const CastTransportRtpConfig& config, |
103 const RtcpCastMessageCallback& cast_message_cb, | 71 const RtcpCastMessageCallback& cast_message_cb, |
104 const RtcpRttCallback& rtt_cb) final; | 72 const RtcpRttCallback& rtt_cb) final; |
105 void InsertFrame(uint32_t ssrc, const EncodedFrame& frame) final; | 73 void InsertFrame(uint32_t ssrc, const EncodedFrame& frame) final; |
106 | 74 |
107 void SendSenderReport(uint32_t ssrc, | 75 void SendSenderReport(uint32_t ssrc, |
108 base::TimeTicks current_time, | 76 base::TimeTicks current_time, |
109 RtpTimeTicks current_time_as_rtp_timestamp) final; | 77 RtpTimeTicks current_time_as_rtp_timestamp) final; |
110 | 78 |
111 void CancelSendingFrames(uint32_t ssrc, | 79 void CancelSendingFrames(uint32_t ssrc, |
112 const std::vector<uint32_t>& frame_ids) final; | 80 const std::vector<uint32_t>& frame_ids) final; |
113 | 81 |
114 void ResendFrameForKickstart(uint32_t ssrc, uint32_t frame_id) final; | 82 void ResendFrameForKickstart(uint32_t ssrc, uint32_t frame_id) final; |
115 | 83 |
116 PacketReceiverCallback PacketReceiverForTesting() final; | 84 PacketReceiverCallback PacketReceiverForTesting() final; |
117 | 85 |
| 86 // Possible keys of |options| handled here are: |
| 87 // "pacer_target_burst_size": int |
| 88 // - Specifies how many packets to send per 10 ms ideally. |
| 89 // "pacer_max_burst_size": int |
| 90 // - Specifies how many pakcets to send per 10 ms, maximum. |
| 91 // "send_buffer_min_size": int |
| 92 // - Specifies the minimum socket send buffer size. |
| 93 // "disable_wifi_scan" (value ignored) |
| 94 // - Disable wifi scans while streaming. |
| 95 // "media_streaming_mode" (value ignored) |
| 96 // - Turn media streaming mode on. |
| 97 // Note, these options may be ignored on some platforms. |
| 98 void SetOptions(const base::DictionaryValue& options) final; |
| 99 |
118 // CastTransportReceiver implementation. | 100 // CastTransportReceiver implementation. |
119 void AddValidSsrc(uint32_t ssrc) final; | 101 void AddValidSsrc(uint32_t ssrc) final; |
120 | 102 |
121 void SendRtcpFromRtpReceiver( | 103 void SendRtcpFromRtpReceiver( |
122 uint32_t ssrc, | 104 uint32_t ssrc, |
123 uint32_t sender_ssrc, | 105 uint32_t sender_ssrc, |
124 const RtcpTimeData& time_data, | 106 const RtcpTimeData& time_data, |
125 const RtcpCastMessage* cast_message, | 107 const RtcpCastMessage* cast_message, |
126 base::TimeDelta target_delay, | 108 base::TimeDelta target_delay, |
127 const ReceiverRtcpEventSubscriber::RtcpEvents* rtcp_events, | 109 const ReceiverRtcpEventSubscriber::RtcpEvents* rtcp_events, |
128 const RtpReceiverStatistics* rtp_receiver_statistics) final; | 110 const RtpReceiverStatistics* rtp_receiver_statistics) final; |
129 | 111 |
130 private: | 112 private: |
131 FRIEND_TEST_ALL_PREFIXES(CastTransportSenderImplTest, NacksCancelRetransmits); | 113 FRIEND_TEST_ALL_PREFIXES(CastTransportSenderImplTest, NacksCancelRetransmits); |
132 FRIEND_TEST_ALL_PREFIXES(CastTransportSenderImplTest, CancelRetransmits); | 114 FRIEND_TEST_ALL_PREFIXES(CastTransportSenderImplTest, CancelRetransmits); |
133 FRIEND_TEST_ALL_PREFIXES(CastTransportSenderImplTest, Kickstart); | 115 FRIEND_TEST_ALL_PREFIXES(CastTransportSenderImplTest, Kickstart); |
134 FRIEND_TEST_ALL_PREFIXES(CastTransportSenderImplTest, | 116 FRIEND_TEST_ALL_PREFIXES(CastTransportSenderImplTest, |
135 DedupRetransmissionWithAudio); | 117 DedupRetransmissionWithAudio); |
136 | 118 |
137 // Resend packets for the stream identified by |ssrc|. | 119 // Resend packets for the stream identified by |ssrc|. |
138 // If |cancel_rtx_if_not_in_list| is true then transmission of packets for the | 120 // If |cancel_rtx_if_not_in_list| is true then transmission of packets for the |
139 // frames but not in the list will be dropped. | 121 // frames but not in the list will be dropped. |
140 // See PacedSender::ResendPackets() to see how |dedup_info| works. | 122 // See PacedSender::ResendPackets() to see how |dedup_info| works. |
141 void ResendPackets(uint32_t ssrc, | 123 void ResendPackets(uint32_t ssrc, |
142 const MissingFramesAndPacketsMap& missing_packets, | 124 const MissingFramesAndPacketsMap& missing_packets, |
143 bool cancel_rtx_if_not_in_list, | 125 bool cancel_rtx_if_not_in_list, |
144 const DedupInfo& dedup_info); | 126 const DedupInfo& dedup_info); |
145 | 127 |
146 // If |raw_events_callback_| is non-null, calls it with events collected | 128 // If |logging_flush_interval| is set, this is called at approximate periodic |
147 // in |recent_frame_events_| and |recent_packet_events_| since last call. | 129 // intervals. |
148 void SendRawEvents(); | 130 void SendRawEvents(); |
149 | 131 |
150 // Called when a packet is received. | 132 // Called when a packet is received. |
151 bool OnReceivedPacket(scoped_ptr<Packet> packet); | 133 bool OnReceivedPacket(scoped_ptr<Packet> packet); |
152 | 134 |
153 // Called when a log message is received. | 135 // Called when a log message is received. |
154 void OnReceivedLogMessage(EventMediaType media_type, | 136 void OnReceivedLogMessage(EventMediaType media_type, |
155 const RtcpReceiverLogMessage& log); | 137 const RtcpReceiverLogMessage& log); |
156 | 138 |
157 // Called when a RTCP Cast message is received. | 139 // Called when a RTCP Cast message is received. |
158 void OnReceivedCastMessage(uint32_t ssrc, | 140 void OnReceivedCastMessage(uint32_t ssrc, |
159 const RtcpCastMessageCallback& cast_message_cb, | 141 const RtcpCastMessageCallback& cast_message_cb, |
160 const RtcpCastMessage& cast_message); | 142 const RtcpCastMessage& cast_message); |
161 | 143 |
162 base::TickClock* clock_; // Not owned by this class. | 144 base::TickClock* const clock_; // Not owned by this class. |
163 CastTransportStatusCallback status_callback_; | 145 const base::TimeDelta logging_flush_interval_; |
164 scoped_refptr<base::SingleThreadTaskRunner> transport_task_runner_; | 146 const scoped_ptr<Client> transport_client_; |
| 147 const scoped_ptr<PacketSender> transport_; |
| 148 const scoped_refptr<base::SingleThreadTaskRunner> transport_task_runner_; |
165 | 149 |
166 // FrameEvents and PacketEvents pending delivery via |raw_events_callback_|. | 150 // FrameEvents and PacketEvents pending delivery via raw events callback. |
167 // Do not add elements to these when |raw_events_callback_.is_null()|. | 151 // Do not add elements to these when |logging_flush_interval| is |
| 152 // |base::TimeDelta()|. |
168 std::vector<FrameEvent> recent_frame_events_; | 153 std::vector<FrameEvent> recent_frame_events_; |
169 std::vector<PacketEvent> recent_packet_events_; | 154 std::vector<PacketEvent> recent_packet_events_; |
170 | 155 |
171 // Interface to a UDP socket. | |
172 scoped_ptr<UdpTransport> transport_; | |
173 | |
174 // Packet sender that performs pacing. | 156 // Packet sender that performs pacing. |
175 PacedSender pacer_; | 157 PacedSender pacer_; |
176 | 158 |
177 // Packetizer for audio and video frames. | 159 // Packetizer for audio and video frames. |
178 scoped_ptr<RtpSender> audio_sender_; | 160 scoped_ptr<RtpSender> audio_sender_; |
179 scoped_ptr<RtpSender> video_sender_; | 161 scoped_ptr<RtpSender> video_sender_; |
180 | 162 |
181 // Maintains RTCP session for audio and video. | 163 // Maintains RTCP session for audio and video. |
182 scoped_ptr<SenderRtcpSession> audio_rtcp_session_; | 164 scoped_ptr<SenderRtcpSession> audio_rtcp_session_; |
183 scoped_ptr<SenderRtcpSession> video_rtcp_session_; | 165 scoped_ptr<SenderRtcpSession> video_rtcp_session_; |
184 | 166 |
185 // Encrypts data in EncodedFrames before they are sent. Note that it's | 167 // Encrypts data in EncodedFrames before they are sent. Note that it's |
186 // important for the encryption to happen here, in code that would execute in | 168 // important for the encryption to happen here, in code that would execute in |
187 // the main browser process, for security reasons. This helps to mitigate | 169 // the main browser process, for security reasons. This helps to mitigate |
188 // the damage that could be caused by a compromised renderer process. | 170 // the damage that could be caused by a compromised renderer process. |
189 TransportEncryptionHandler audio_encryptor_; | 171 TransportEncryptionHandler audio_encryptor_; |
190 TransportEncryptionHandler video_encryptor_; | 172 TransportEncryptionHandler video_encryptor_; |
191 | 173 |
192 BulkRawEventsCallback raw_events_callback_; | |
193 base::TimeDelta raw_events_callback_interval_; | |
194 | |
195 // Right after a frame is sent we record the number of bytes sent to the | 174 // Right after a frame is sent we record the number of bytes sent to the |
196 // socket. We record the corresponding bytes sent for the most recent ACKed | 175 // socket. We record the corresponding bytes sent for the most recent ACKed |
197 // audio packet. | 176 // audio packet. |
198 int64_t last_byte_acked_for_audio_; | 177 int64_t last_byte_acked_for_audio_; |
199 | 178 |
200 // Packets that don't match these ssrcs are ignored. | 179 // Packets that don't match these ssrcs are ignored. |
201 std::set<uint32_t> valid_ssrcs_; | 180 std::set<uint32_t> valid_ssrcs_; |
202 | 181 |
203 // Called with incoming packets. (Unless they match the | 182 // While non-null, global WiFi behavior modifications are in effect. This is |
204 // channels created by Initialize{Audio,Video}. | 183 // used, for example, to turn off WiFi scanning that tends to interfere with |
205 PacketReceiverCallback packet_callback_; | 184 // the reliability of UDP packet transmission. |
206 | |
207 scoped_ptr<net::ScopedWifiOptions> wifi_options_autoreset_; | 185 scoped_ptr<net::ScopedWifiOptions> wifi_options_autoreset_; |
208 | 186 |
209 base::WeakPtrFactory<CastTransportSenderImpl> weak_factory_; | 187 base::WeakPtrFactory<CastTransportSenderImpl> weak_factory_; |
210 | 188 |
211 DISALLOW_COPY_AND_ASSIGN(CastTransportSenderImpl); | 189 DISALLOW_COPY_AND_ASSIGN(CastTransportSenderImpl); |
212 }; | 190 }; |
213 | 191 |
214 } // namespace cast | 192 } // namespace cast |
215 } // namespace media | 193 } // namespace media |
216 | 194 |
217 #endif // MEDIA_CAST_NET_CAST_TRANSPORT_SENDER_IMPL_H_ | 195 #endif // MEDIA_CAST_NET_CAST_TRANSPORT_SENDER_IMPL_H_ |
OLD | NEW |