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 const UdpTransportParams& upd_transport_params, |
86 const net::IPEndPoint& local_end_point, | 61 base::TimeDelta logging_flush_interval, |
87 const net::IPEndPoint& remote_end_point, | |
88 scoped_ptr<base::DictionaryValue> options, | 62 scoped_ptr<base::DictionaryValue> options, |
89 const CastTransportStatusCallback& status_callback, | 63 scoped_ptr<Client> client, |
90 const BulkRawEventsCallback& raw_events_callback, | |
91 base::TimeDelta raw_events_callback_interval, | |
92 const scoped_refptr<base::SingleThreadTaskRunner>& transport_task_runner, | 64 const scoped_refptr<base::SingleThreadTaskRunner>& transport_task_runner, |
93 const PacketReceiverCallback& packet_callback, | |
94 PacketSender* external_transport); | 65 PacketSender* external_transport); |
95 | 66 |
96 ~CastTransportSenderImpl() final; | 67 ~CastTransportSenderImpl() final; |
97 | 68 |
98 // CastTransportSender implementation. | 69 // CastTransportSender implementation. |
99 void InitializeAudio(const CastTransportRtpConfig& config, | 70 void InitializeAudio(const CastTransportRtpConfig& config, |
100 const RtcpCastMessageCallback& cast_message_cb, | 71 const RtcpCastMessageCallback& cast_message_cb, |
101 const RtcpRttCallback& rtt_cb) final; | 72 const RtcpRttCallback& rtt_cb) final; |
102 void InitializeVideo(const CastTransportRtpConfig& config, | 73 void InitializeVideo(const CastTransportRtpConfig& config, |
103 const RtcpCastMessageCallback& cast_message_cb, | 74 const RtcpCastMessageCallback& cast_message_cb, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
136 | 107 |
137 // Resend packets for the stream identified by |ssrc|. | 108 // Resend packets for the stream identified by |ssrc|. |
138 // If |cancel_rtx_if_not_in_list| is true then transmission of packets for the | 109 // 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. | 110 // frames but not in the list will be dropped. |
140 // See PacedSender::ResendPackets() to see how |dedup_info| works. | 111 // See PacedSender::ResendPackets() to see how |dedup_info| works. |
141 void ResendPackets(uint32_t ssrc, | 112 void ResendPackets(uint32_t ssrc, |
142 const MissingFramesAndPacketsMap& missing_packets, | 113 const MissingFramesAndPacketsMap& missing_packets, |
143 bool cancel_rtx_if_not_in_list, | 114 bool cancel_rtx_if_not_in_list, |
144 const DedupInfo& dedup_info); | 115 const DedupInfo& dedup_info); |
145 | 116 |
146 // If |raw_events_callback_| is non-null, calls it with events collected | 117 // If |logging_flush_interval| is not |base::TimeDelta|, calls it with events |
miu
2016/01/16 02:28:42
nit: It would be sufficient to just say, "If |logg
xjz
2016/01/21 19:16:27
Done.
| |
147 // in |recent_frame_events_| and |recent_packet_events_| since last call. | 118 // collected in |logging_flush_interval| and |recent_packet_events_| since |
119 // last call. | |
148 void SendRawEvents(); | 120 void SendRawEvents(); |
149 | 121 |
150 // Called when a packet is received. | 122 // Called when a packet is received. |
151 bool OnReceivedPacket(scoped_ptr<Packet> packet); | 123 bool OnReceivedPacket(scoped_ptr<Packet> packet); |
152 | 124 |
153 // Called when a log message is received. | 125 // Called when a log message is received. |
154 void OnReceivedLogMessage(EventMediaType media_type, | 126 void OnReceivedLogMessage(EventMediaType media_type, |
155 const RtcpReceiverLogMessage& log); | 127 const RtcpReceiverLogMessage& log); |
156 | 128 |
157 // Called when a RTCP Cast message is received. | 129 // Called when a RTCP Cast message is received. |
158 void OnReceivedCastMessage(uint32_t ssrc, | 130 void OnReceivedCastMessage(uint32_t ssrc, |
159 const RtcpCastMessageCallback& cast_message_cb, | 131 const RtcpCastMessageCallback& cast_message_cb, |
160 const RtcpCastMessage& cast_message); | 132 const RtcpCastMessage& cast_message); |
161 | 133 |
134 // Used as status callback to create udp transport. | |
miu
2016/01/16 02:28:42
s/udp transport/UdpTransport/
xjz
2016/01/21 19:16:27
Done.
| |
135 void OnStatusChanged(CastTransportStatus status); | |
136 | |
137 scoped_ptr<Client> transport_client_; | |
miu
2016/01/16 02:28:42
Please preserve ordering (same order here as args)
xjz
2016/01/21 19:16:27
Done.
| |
162 base::TickClock* clock_; // Not owned by this class. | 138 base::TickClock* clock_; // Not owned by this class. |
miu
2016/01/16 02:28:42
Please add const here too: base::TickClock* const
xjz
2016/01/21 19:16:27
Done.
| |
163 CastTransportStatusCallback status_callback_; | 139 const scoped_refptr<base::SingleThreadTaskRunner> transport_task_runner_; |
164 scoped_refptr<base::SingleThreadTaskRunner> transport_task_runner_; | 140 const base::TimeDelta logging_flush_interval_; |
165 | 141 |
166 // FrameEvents and PacketEvents pending delivery via |raw_events_callback_|. | 142 // FrameEvents and PacketEvents pending delivery via raw events callback. |
167 // Do not add elements to these when |raw_events_callback_.is_null()|. | 143 // Do not add elements to these when |logging_flush_interval| is |
144 // |base::TimeDelta()|. | |
168 std::vector<FrameEvent> recent_frame_events_; | 145 std::vector<FrameEvent> recent_frame_events_; |
169 std::vector<PacketEvent> recent_packet_events_; | 146 std::vector<PacketEvent> recent_packet_events_; |
170 | 147 |
171 // Interface to a UDP socket. | 148 // Interface to a UDP socket. |
172 scoped_ptr<UdpTransport> transport_; | 149 scoped_ptr<UdpTransport> transport_; |
173 | 150 |
174 // Packet sender that performs pacing. | 151 // Packet sender that performs pacing. |
175 PacedSender pacer_; | 152 scoped_ptr<PacedSender> pacer_; |
miu
2016/01/16 02:28:42
I don't see why this was changed. Unless I'm miss
xjz
2016/01/21 19:16:27
This was changed because this can only be initiali
| |
176 | 153 |
177 // Packetizer for audio and video frames. | 154 // Packetizer for audio and video frames. |
178 scoped_ptr<RtpSender> audio_sender_; | 155 scoped_ptr<RtpSender> audio_sender_; |
179 scoped_ptr<RtpSender> video_sender_; | 156 scoped_ptr<RtpSender> video_sender_; |
180 | 157 |
181 // Maintains RTCP session for audio and video. | 158 // Maintains RTCP session for audio and video. |
182 scoped_ptr<SenderRtcpSession> audio_rtcp_session_; | 159 scoped_ptr<SenderRtcpSession> audio_rtcp_session_; |
183 scoped_ptr<SenderRtcpSession> video_rtcp_session_; | 160 scoped_ptr<SenderRtcpSession> video_rtcp_session_; |
184 | 161 |
185 // Encrypts data in EncodedFrames before they are sent. Note that it's | 162 // 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 | 163 // 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 | 164 // the main browser process, for security reasons. This helps to mitigate |
188 // the damage that could be caused by a compromised renderer process. | 165 // the damage that could be caused by a compromised renderer process. |
189 TransportEncryptionHandler audio_encryptor_; | 166 TransportEncryptionHandler audio_encryptor_; |
190 TransportEncryptionHandler video_encryptor_; | 167 TransportEncryptionHandler video_encryptor_; |
191 | 168 |
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 | 169 // 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 | 170 // socket. We record the corresponding bytes sent for the most recent ACKed |
197 // audio packet. | 171 // audio packet. |
198 int64_t last_byte_acked_for_audio_; | 172 int64_t last_byte_acked_for_audio_; |
199 | 173 |
200 // Packets that don't match these ssrcs are ignored. | 174 // Packets that don't match these ssrcs are ignored. |
201 std::set<uint32_t> valid_ssrcs_; | 175 std::set<uint32_t> valid_ssrcs_; |
202 | 176 |
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_; | 177 scoped_ptr<net::ScopedWifiOptions> wifi_options_autoreset_; |
208 | 178 |
209 base::WeakPtrFactory<CastTransportSenderImpl> weak_factory_; | 179 base::WeakPtrFactory<CastTransportSenderImpl> weak_factory_; |
210 | 180 |
211 DISALLOW_COPY_AND_ASSIGN(CastTransportSenderImpl); | 181 DISALLOW_COPY_AND_ASSIGN(CastTransportSenderImpl); |
212 }; | 182 }; |
213 | 183 |
214 } // namespace cast | 184 } // namespace cast |
215 } // namespace media | 185 } // namespace media |
216 | 186 |
217 #endif // MEDIA_CAST_NET_CAST_TRANSPORT_SENDER_IMPL_H_ | 187 #endif // MEDIA_CAST_NET_CAST_TRANSPORT_SENDER_IMPL_H_ |
OLD | NEW |