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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
45 #include "net/base/network_interfaces.h" | 45 #include "net/base/network_interfaces.h" |
46 | 46 |
47 namespace media { | 47 namespace media { |
48 namespace cast { | 48 namespace cast { |
49 | 49 |
50 class UdpTransport; | 50 class UdpTransport; |
51 | 51 |
52 class CastTransportSenderImpl : public CastTransportSender { | 52 class CastTransportSenderImpl : public CastTransportSender { |
53 public: | 53 public: |
54 // |external_transport| is only used for testing. | 54 // |external_transport| is only used for testing. |
55 // |raw_events_callback|: Raw events will be returned on this callback | 55 CastTransportSenderImpl(const CreateParams& params, |
56 // which will be invoked every |raw_events_callback_interval|. | 56 PacketSender* external_transport); |
57 // This can be a null callback, i.e. if user is not interested in raw events. | |
58 // |raw_events_callback_interval|: This can be |base::TimeDelta()| if | |
59 // |raw_events_callback| is a null callback. | |
60 // |options| contains optional settings for the transport, possible | |
61 // keys are: | |
62 // "DSCP" (value ignored) | |
63 // - Turns DSCP on (higher IP Precedence and Type of Service). | |
64 // "disable_non_blocking_io" (value ignored) | |
65 // - Windows only. Turns off non-blocking IO for the socket. | |
66 // Note: Non-blocking IO is, by default, enabled on all platforms. | |
67 // "pacer_target_burst_size": int | |
68 // - Specifies how many packets to send per 10 ms ideally. | |
69 // "pacer_max_burst_size": int | |
70 // - Specifies how many pakcets to send per 10 ms, maximum. | |
71 // "send_buffer_min_size": int | |
72 // - Specifies the minimum socket send buffer size. | |
73 // "disable_wifi_scan" (value ignored) | |
74 // - Disable wifi scans while streaming. | |
75 // "media_streaming_mode" (value ignored) | |
76 // - Turn media streaming mode on. | |
77 // Note, these options may be ignored on some platforms. | |
78 // TODO(hubbe): Too many callbacks, replace with an interface. | |
79 // http://crbug.com/557477 | |
80 CastTransportSenderImpl( | |
81 net::NetLog* net_log, | |
82 base::TickClock* clock, | |
83 const net::IPEndPoint& local_end_point, | |
84 const net::IPEndPoint& remote_end_point, | |
85 scoped_ptr<base::DictionaryValue> options, | |
86 const CastTransportStatusCallback& status_callback, | |
87 const BulkRawEventsCallback& raw_events_callback, | |
88 base::TimeDelta raw_events_callback_interval, | |
89 const scoped_refptr<base::SingleThreadTaskRunner>& transport_task_runner, | |
90 const PacketReceiverCallback& packet_callback, | |
91 PacketSender* external_transport); | |
92 | 57 |
93 ~CastTransportSenderImpl() final; | 58 ~CastTransportSenderImpl() final; |
94 | 59 |
95 // CastTransportSender implementation. | 60 // CastTransportSender implementation. |
96 void InitializeAudio(const CastTransportRtpConfig& config, | 61 void InitializeAudio(const CastTransportRtpConfig& config, |
97 const RtcpCastMessageCallback& cast_message_cb, | 62 const RtcpCastMessageCallback& cast_message_cb, |
98 const RtcpRttCallback& rtt_cb) final; | 63 const RtcpRttCallback& rtt_cb) final; |
99 void InitializeVideo(const CastTransportRtpConfig& config, | 64 void InitializeVideo(const CastTransportRtpConfig& config, |
100 const RtcpCastMessageCallback& cast_message_cb, | 65 const RtcpCastMessageCallback& cast_message_cb, |
101 const RtcpRttCallback& rtt_cb) final; | 66 const RtcpRttCallback& rtt_cb) final; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
133 | 98 |
134 // Resend packets for the stream identified by |ssrc|. | 99 // Resend packets for the stream identified by |ssrc|. |
135 // If |cancel_rtx_if_not_in_list| is true then transmission of packets for the | 100 // If |cancel_rtx_if_not_in_list| is true then transmission of packets for the |
136 // frames but not in the list will be dropped. | 101 // frames but not in the list will be dropped. |
137 // See PacedSender::ResendPackets() to see how |dedup_info| works. | 102 // See PacedSender::ResendPackets() to see how |dedup_info| works. |
138 void ResendPackets(uint32 ssrc, | 103 void ResendPackets(uint32 ssrc, |
139 const MissingFramesAndPacketsMap& missing_packets, | 104 const MissingFramesAndPacketsMap& missing_packets, |
140 bool cancel_rtx_if_not_in_list, | 105 bool cancel_rtx_if_not_in_list, |
141 const DedupInfo& dedup_info); | 106 const DedupInfo& dedup_info); |
142 | 107 |
143 // If |raw_events_callback_| is non-null, calls it with events collected | 108 // If |logging_flush_interval| is not |base::TimeDelta|, calls it with events |
imcheng
2015/12/17 00:18:11
s/base::TimeDelta|base::TimeDelta()
xjz
2015/12/17 22:54:58
Done.
| |
144 // in |recent_frame_events_| and |recent_packet_events_| since last call. | 109 // collected in |logging_flush_interval| and |recent_packet_events_| since |
110 // last call. | |
145 void SendRawEvents(); | 111 void SendRawEvents(); |
146 | 112 |
147 // Called when a packet is received. | 113 // Called when a packet is received. |
148 bool OnReceivedPacket(scoped_ptr<Packet> packet); | 114 bool OnReceivedPacket(scoped_ptr<Packet> packet); |
149 | 115 |
150 // Called when a log message is received. | 116 // Called when a log message is received. |
151 void OnReceivedLogMessage(EventMediaType media_type, | 117 void OnReceivedLogMessage(EventMediaType media_type, |
152 const RtcpReceiverLogMessage& log); | 118 const RtcpReceiverLogMessage& log); |
153 | 119 |
154 // Called when a RTCP Cast message is received. | 120 // Called when a RTCP Cast message is received. |
155 void OnReceivedCastMessage(uint32 ssrc, | 121 void OnReceivedCastMessage(uint32 ssrc, |
156 const RtcpCastMessageCallback& cast_message_cb, | 122 const RtcpCastMessageCallback& cast_message_cb, |
157 const RtcpCastMessage& cast_message); | 123 const RtcpCastMessage& cast_message); |
158 | 124 |
125 // Used as status callback to create udp transport. | |
126 void OnStatusChange(CastTransportStatus status); | |
127 | |
128 const CreateParams& transport_params_; | |
Irfan
2015/12/16 22:37:04
If we only pass raw pointer on client, we can get
imcheng
2015/12/17 00:18:11
Also, this shouldn't be a reference.
xjz
2015/12/17 22:54:58
Removed.
xjz
2015/12/17 22:54:58
I think we could do this, but might not be a good
| |
159 base::TickClock* clock_; // Not owned by this class. | 129 base::TickClock* clock_; // Not owned by this class. |
160 CastTransportStatusCallback status_callback_; | 130 const scoped_refptr<base::SingleThreadTaskRunner>& transport_task_runner_; |
imcheng
2015/12/17 00:18:11
This shouldn't be a reference.
xjz
2015/12/17 22:54:58
Done.
| |
161 scoped_refptr<base::SingleThreadTaskRunner> transport_task_runner_; | 131 base::TimeDelta logging_flush_interval_; |
imcheng
2015/12/17 00:18:11
const base::TimeDelta
xjz
2015/12/17 22:54:58
Done.
| |
162 | 132 |
163 // FrameEvents and PacketEvents pending delivery via |raw_events_callback_|. | 133 // FrameEvents and PacketEvents pending delivery via raw events callback. |
164 // Do not add elements to these when |raw_events_callback_.is_null()|. | 134 // Do not add elements to these when |logging_flush_interval| is |
135 // |base::TimeDelta()|. | |
165 std::vector<FrameEvent> recent_frame_events_; | 136 std::vector<FrameEvent> recent_frame_events_; |
166 std::vector<PacketEvent> recent_packet_events_; | 137 std::vector<PacketEvent> recent_packet_events_; |
167 | 138 |
168 // Interface to a UDP socket. | 139 // Interface to a UDP socket. |
169 scoped_ptr<UdpTransport> transport_; | 140 scoped_ptr<UdpTransport> transport_; |
170 | 141 |
171 // Packet sender that performs pacing. | 142 // Packet sender that performs pacing. |
172 PacedSender pacer_; | 143 scoped_ptr<PacedSender> pacer_; |
imcheng
2015/12/17 00:18:11
Why this change?
xjz
2015/12/17 22:54:58
It cannot be initialized in the initialization lis
| |
173 | 144 |
174 // Packetizer for audio and video frames. | 145 // Packetizer for audio and video frames. |
175 scoped_ptr<RtpSender> audio_sender_; | 146 scoped_ptr<RtpSender> audio_sender_; |
176 scoped_ptr<RtpSender> video_sender_; | 147 scoped_ptr<RtpSender> video_sender_; |
177 | 148 |
178 // Maintains RTCP session for audio and video. | 149 // Maintains RTCP session for audio and video. |
179 scoped_ptr<Rtcp> audio_rtcp_session_; | 150 scoped_ptr<Rtcp> audio_rtcp_session_; |
180 scoped_ptr<Rtcp> video_rtcp_session_; | 151 scoped_ptr<Rtcp> video_rtcp_session_; |
181 | 152 |
182 // Encrypts data in EncodedFrames before they are sent. Note that it's | 153 // Encrypts data in EncodedFrames before they are sent. Note that it's |
183 // important for the encryption to happen here, in code that would execute in | 154 // important for the encryption to happen here, in code that would execute in |
184 // the main browser process, for security reasons. This helps to mitigate | 155 // the main browser process, for security reasons. This helps to mitigate |
185 // the damage that could be caused by a compromised renderer process. | 156 // the damage that could be caused by a compromised renderer process. |
186 TransportEncryptionHandler audio_encryptor_; | 157 TransportEncryptionHandler audio_encryptor_; |
187 TransportEncryptionHandler video_encryptor_; | 158 TransportEncryptionHandler video_encryptor_; |
188 | 159 |
189 BulkRawEventsCallback raw_events_callback_; | |
190 base::TimeDelta raw_events_callback_interval_; | |
191 | |
192 // Right after a frame is sent we record the number of bytes sent to the | 160 // Right after a frame is sent we record the number of bytes sent to the |
193 // socket. We record the corresponding bytes sent for the most recent ACKed | 161 // socket. We record the corresponding bytes sent for the most recent ACKed |
194 // audio packet. | 162 // audio packet. |
195 int64 last_byte_acked_for_audio_; | 163 int64 last_byte_acked_for_audio_; |
196 | 164 |
197 // Packets that don't match these ssrcs are ignored. | 165 // Packets that don't match these ssrcs are ignored. |
198 std::set<uint32> valid_ssrcs_; | 166 std::set<uint32> valid_ssrcs_; |
199 | 167 |
200 // Called with incoming packets. (Unless they match the | |
201 // channels created by Initialize{Audio,Video}. | |
202 PacketReceiverCallback packet_callback_; | |
203 | |
204 scoped_ptr<net::ScopedWifiOptions> wifi_options_autoreset_; | 168 scoped_ptr<net::ScopedWifiOptions> wifi_options_autoreset_; |
205 | 169 |
206 base::WeakPtrFactory<CastTransportSenderImpl> weak_factory_; | 170 base::WeakPtrFactory<CastTransportSenderImpl> weak_factory_; |
207 | 171 |
208 DISALLOW_COPY_AND_ASSIGN(CastTransportSenderImpl); | 172 DISALLOW_COPY_AND_ASSIGN(CastTransportSenderImpl); |
209 }; | 173 }; |
210 | 174 |
211 } // namespace cast | 175 } // namespace cast |
212 } // namespace media | 176 } // namespace media |
213 | 177 |
214 #endif // MEDIA_CAST_NET_CAST_TRANSPORT_SENDER_IMPL_H_ | 178 #endif // MEDIA_CAST_NET_CAST_TRANSPORT_SENDER_IMPL_H_ |
OLD | NEW |