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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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. | 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( | 58 CastTransportSenderImpl( |
84 net::NetLog* net_log, | 59 base::TickClock* clock, // Owned by the caller. |
85 base::TickClock* clock, | 60 base::TimeDelta logging_flush_interval, |
86 const net::IPEndPoint& local_end_point, | 61 scoped_ptr<Client> client, |
87 const net::IPEndPoint& remote_end_point, | 62 scoped_ptr<PacketSender> transport, |
88 scoped_ptr<base::DictionaryValue> options, | 63 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 | 64 |
96 ~CastTransportSenderImpl() final; | 65 ~CastTransportSenderImpl() final; |
97 | 66 |
98 // CastTransportSender implementation. | 67 // CastTransportSender implementation. |
99 void InitializeAudio(const CastTransportRtpConfig& config, | 68 void InitializeAudio(const CastTransportRtpConfig& config, |
100 const RtcpCastMessageCallback& cast_message_cb, | 69 const RtcpCastMessageCallback& cast_message_cb, |
101 const RtcpRttCallback& rtt_cb) final; | 70 const RtcpRttCallback& rtt_cb) final; |
102 void InitializeVideo(const CastTransportRtpConfig& config, | 71 void InitializeVideo(const CastTransportRtpConfig& config, |
103 const RtcpCastMessageCallback& cast_message_cb, | 72 const RtcpCastMessageCallback& cast_message_cb, |
104 const RtcpRttCallback& rtt_cb) final; | 73 const RtcpRttCallback& rtt_cb) final; |
105 void InsertFrame(uint32_t ssrc, const EncodedFrame& frame) final; | 74 void InsertFrame(uint32_t ssrc, const EncodedFrame& frame) final; |
106 | 75 |
107 void SendSenderReport(uint32_t ssrc, | 76 void SendSenderReport(uint32_t ssrc, |
108 base::TimeTicks current_time, | 77 base::TimeTicks current_time, |
109 RtpTimeTicks current_time_as_rtp_timestamp) final; | 78 RtpTimeTicks current_time_as_rtp_timestamp) final; |
110 | 79 |
111 void CancelSendingFrames(uint32_t ssrc, | 80 void CancelSendingFrames(uint32_t ssrc, |
112 const std::vector<uint32_t>& frame_ids) final; | 81 const std::vector<uint32_t>& frame_ids) final; |
113 | 82 |
114 void ResendFrameForKickstart(uint32_t ssrc, uint32_t frame_id) final; | 83 void ResendFrameForKickstart(uint32_t ssrc, uint32_t frame_id) final; |
115 | 84 |
116 PacketReceiverCallback PacketReceiverForTesting() final; | 85 PacketReceiverCallback PacketReceiverForTesting() final; |
117 | 86 |
87 PacedSender* GetPacedSender() final; | |
88 | |
89 void SetWifiOptions(int wifi_options) final; | |
90 | |
118 // CastTransportReceiver implementation. | 91 // CastTransportReceiver implementation. |
119 void AddValidSsrc(uint32_t ssrc) final; | 92 void AddValidSsrc(uint32_t ssrc) final; |
120 | 93 |
121 void SendRtcpFromRtpReceiver( | 94 void SendRtcpFromRtpReceiver( |
122 uint32_t ssrc, | 95 uint32_t ssrc, |
123 uint32_t sender_ssrc, | 96 uint32_t sender_ssrc, |
124 const RtcpTimeData& time_data, | 97 const RtcpTimeData& time_data, |
125 const RtcpCastMessage* cast_message, | 98 const RtcpCastMessage* cast_message, |
126 base::TimeDelta target_delay, | 99 base::TimeDelta target_delay, |
127 const ReceiverRtcpEventSubscriber::RtcpEvents* rtcp_events, | 100 const ReceiverRtcpEventSubscriber::RtcpEvents* rtcp_events, |
128 const RtpReceiverStatistics* rtp_receiver_statistics) final; | 101 const RtpReceiverStatistics* rtp_receiver_statistics) final; |
129 | 102 |
130 private: | 103 private: |
131 FRIEND_TEST_ALL_PREFIXES(CastTransportSenderImplTest, NacksCancelRetransmits); | 104 FRIEND_TEST_ALL_PREFIXES(CastTransportSenderImplTest, NacksCancelRetransmits); |
132 FRIEND_TEST_ALL_PREFIXES(CastTransportSenderImplTest, CancelRetransmits); | 105 FRIEND_TEST_ALL_PREFIXES(CastTransportSenderImplTest, CancelRetransmits); |
133 FRIEND_TEST_ALL_PREFIXES(CastTransportSenderImplTest, Kickstart); | 106 FRIEND_TEST_ALL_PREFIXES(CastTransportSenderImplTest, Kickstart); |
134 FRIEND_TEST_ALL_PREFIXES(CastTransportSenderImplTest, | 107 FRIEND_TEST_ALL_PREFIXES(CastTransportSenderImplTest, |
135 DedupRetransmissionWithAudio); | 108 DedupRetransmissionWithAudio); |
136 | 109 |
137 // Resend packets for the stream identified by |ssrc|. | 110 // Resend packets for the stream identified by |ssrc|. |
138 // If |cancel_rtx_if_not_in_list| is true then transmission of packets for the | 111 // 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. | 112 // frames but not in the list will be dropped. |
140 // See PacedSender::ResendPackets() to see how |dedup_info| works. | 113 // See PacedSender::ResendPackets() to see how |dedup_info| works. |
141 void ResendPackets(uint32_t ssrc, | 114 void ResendPackets(uint32_t ssrc, |
142 const MissingFramesAndPacketsMap& missing_packets, | 115 const MissingFramesAndPacketsMap& missing_packets, |
143 bool cancel_rtx_if_not_in_list, | 116 bool cancel_rtx_if_not_in_list, |
144 const DedupInfo& dedup_info); | 117 const DedupInfo& dedup_info); |
145 | 118 |
146 // If |raw_events_callback_| is non-null, calls it with events collected | 119 // If |logging_flush_interval| is set, this is called at approximate periodic |
147 // in |recent_frame_events_| and |recent_packet_events_| since last call. | 120 // intervals. |
148 void SendRawEvents(); | 121 void SendRawEvents(); |
149 | 122 |
150 // Called when a packet is received. | 123 // Called when a packet is received. |
151 bool OnReceivedPacket(scoped_ptr<Packet> packet); | 124 bool OnReceivedPacket(scoped_ptr<Packet> packet); |
152 | 125 |
153 // Called when a log message is received. | 126 // Called when a log message is received. |
154 void OnReceivedLogMessage(EventMediaType media_type, | 127 void OnReceivedLogMessage(EventMediaType media_type, |
155 const RtcpReceiverLogMessage& log); | 128 const RtcpReceiverLogMessage& log); |
156 | 129 |
157 // Called when a RTCP Cast message is received. | 130 // Called when a RTCP Cast message is received. |
158 void OnReceivedCastMessage(uint32_t ssrc, | 131 void OnReceivedCastMessage(uint32_t ssrc, |
159 const RtcpCastMessageCallback& cast_message_cb, | 132 const RtcpCastMessageCallback& cast_message_cb, |
160 const RtcpCastMessage& cast_message); | 133 const RtcpCastMessage& cast_message); |
161 | 134 |
162 base::TickClock* clock_; // Not owned by this class. | 135 base::TickClock* const clock_; // Not owned by this class. |
163 CastTransportStatusCallback status_callback_; | 136 const base::TimeDelta logging_flush_interval_; |
164 scoped_refptr<base::SingleThreadTaskRunner> transport_task_runner_; | 137 const scoped_ptr<Client> transport_client_; |
138 const scoped_ptr<PacketSender> transport_; | |
139 const scoped_refptr<base::SingleThreadTaskRunner> transport_task_runner_; | |
165 | 140 |
166 // FrameEvents and PacketEvents pending delivery via |raw_events_callback_|. | 141 // FrameEvents and PacketEvents pending delivery via raw events callback. |
167 // Do not add elements to these when |raw_events_callback_.is_null()|. | 142 // Do not add elements to these when |logging_flush_interval| is |
143 // |base::TimeDelta()|. | |
168 std::vector<FrameEvent> recent_frame_events_; | 144 std::vector<FrameEvent> recent_frame_events_; |
169 std::vector<PacketEvent> recent_packet_events_; | 145 std::vector<PacketEvent> recent_packet_events_; |
170 | 146 |
171 // Interface to a UDP socket. | |
172 scoped_ptr<UdpTransport> transport_; | |
173 | |
174 // Packet sender that performs pacing. | 147 // Packet sender that performs pacing. |
175 PacedSender pacer_; | 148 PacedSender pacer_; |
176 | 149 |
177 // Packetizer for audio and video frames. | 150 // Packetizer for audio and video frames. |
178 scoped_ptr<RtpSender> audio_sender_; | 151 scoped_ptr<RtpSender> audio_sender_; |
179 scoped_ptr<RtpSender> video_sender_; | 152 scoped_ptr<RtpSender> video_sender_; |
180 | 153 |
181 // Maintains RTCP session for audio and video. | 154 // Maintains RTCP session for audio and video. |
182 scoped_ptr<SenderRtcpSession> audio_rtcp_session_; | 155 scoped_ptr<SenderRtcpSession> audio_rtcp_session_; |
183 scoped_ptr<SenderRtcpSession> video_rtcp_session_; | 156 scoped_ptr<SenderRtcpSession> video_rtcp_session_; |
184 | 157 |
185 // Encrypts data in EncodedFrames before they are sent. Note that it's | 158 // 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 | 159 // 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 | 160 // the main browser process, for security reasons. This helps to mitigate |
188 // the damage that could be caused by a compromised renderer process. | 161 // the damage that could be caused by a compromised renderer process. |
189 TransportEncryptionHandler audio_encryptor_; | 162 TransportEncryptionHandler audio_encryptor_; |
190 TransportEncryptionHandler video_encryptor_; | 163 TransportEncryptionHandler video_encryptor_; |
191 | 164 |
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 | 165 // 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 | 166 // socket. We record the corresponding bytes sent for the most recent ACKed |
197 // audio packet. | 167 // audio packet. |
198 int64_t last_byte_acked_for_audio_; | 168 int64_t last_byte_acked_for_audio_; |
199 | 169 |
200 // Packets that don't match these ssrcs are ignored. | 170 // Packets that don't match these ssrcs are ignored. |
201 std::set<uint32_t> valid_ssrcs_; | 171 std::set<uint32_t> valid_ssrcs_; |
202 | 172 |
203 // Called with incoming packets. (Unless they match the | |
204 // channels created by Initialize{Audio,Video}. | |
205 PacketReceiverCallback packet_callback_; | |
206 | |
207 scoped_ptr<net::ScopedWifiOptions> wifi_options_autoreset_; | 173 scoped_ptr<net::ScopedWifiOptions> wifi_options_autoreset_; |
miu
2016/01/27 02:18:04
Please add a comment like: "While non-null, global
xjz
2016/01/30 01:19:26
Done.
| |
208 | 174 |
209 base::WeakPtrFactory<CastTransportSenderImpl> weak_factory_; | 175 base::WeakPtrFactory<CastTransportSenderImpl> weak_factory_; |
210 | 176 |
211 DISALLOW_COPY_AND_ASSIGN(CastTransportSenderImpl); | 177 DISALLOW_COPY_AND_ASSIGN(CastTransportSenderImpl); |
212 }; | 178 }; |
213 | 179 |
214 } // namespace cast | 180 } // namespace cast |
215 } // namespace media | 181 } // namespace media |
216 | 182 |
217 #endif // MEDIA_CAST_NET_CAST_TRANSPORT_SENDER_IMPL_H_ | 183 #endif // MEDIA_CAST_NET_CAST_TRANSPORT_SENDER_IMPL_H_ |
OLD | NEW |