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 #include "chrome/browser/media/cast_transport_host_filter.h" | 5 #include "chrome/browser/media/cast_transport_host_filter.h" |
6 | 6 |
7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
8 #include "base/threading/thread_task_runner_handle.h" | 8 #include "base/threading/thread_task_runner_handle.h" |
9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
10 #include "chrome/common/cast_messages.h" | 10 #include "chrome/common/cast_messages.h" |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
162 id_map_.Remove(channel_id); | 162 id_map_.Remove(channel_id); |
163 } | 163 } |
164 | 164 |
165 std::unique_ptr<media::cast::UdpTransport> udp_transport( | 165 std::unique_ptr<media::cast::UdpTransport> udp_transport( |
166 new media::cast::UdpTransport( | 166 new media::cast::UdpTransport( |
167 g_browser_process->net_log(), base::ThreadTaskRunnerHandle::Get(), | 167 g_browser_process->net_log(), base::ThreadTaskRunnerHandle::Get(), |
168 local_end_point, remote_end_point, | 168 local_end_point, remote_end_point, |
169 base::Bind(&CastTransportHostFilter::OnStatusChanged, | 169 base::Bind(&CastTransportHostFilter::OnStatusChanged, |
170 weak_factory_.GetWeakPtr(), channel_id))); | 170 weak_factory_.GetWeakPtr(), channel_id))); |
171 udp_transport->SetUdpOptions(options); | 171 udp_transport->SetUdpOptions(options); |
172 std::unique_ptr<media::cast::CastTransport> sender = | 172 std::unique_ptr<media::cast::CastTransport> transport = |
173 media::cast::CastTransport::Create( | 173 media::cast::CastTransport::Create( |
174 &clock_, base::TimeDelta::FromSeconds(kSendRawEventsIntervalSecs), | 174 &clock_, base::TimeDelta::FromSeconds(kSendRawEventsIntervalSecs), |
175 base::MakeUnique<TransportClient>(channel_id, this), | 175 base::MakeUnique<TransportClient>(channel_id, this), |
176 std::move(udp_transport), base::ThreadTaskRunnerHandle::Get()); | 176 std::move(udp_transport), base::ThreadTaskRunnerHandle::Get()); |
177 sender->SetOptions(options); | 177 transport->SetOptions(options); |
178 id_map_.AddWithID(sender.release(), channel_id); | 178 id_map_.AddWithID(transport.release(), channel_id); |
179 } | 179 } |
180 | 180 |
181 void CastTransportHostFilter::OnDelete(int32_t channel_id) { | 181 void CastTransportHostFilter::OnDelete(int32_t channel_id) { |
182 media::cast::CastTransport* sender = id_map_.Lookup(channel_id); | 182 media::cast::CastTransport* transport = id_map_.Lookup(channel_id); |
183 if (sender) { | 183 if (transport) { |
184 id_map_.Remove(channel_id); | 184 id_map_.Remove(channel_id); |
185 } else { | 185 } else { |
186 DVLOG(1) << "CastTransportHostFilter::Delete called " | 186 DVLOG(1) << "CastTransportHostFilter::Delete called " |
187 << "on non-existing channel"; | 187 << "on non-existing channel"; |
188 } | 188 } |
189 | 189 |
190 // Delete all existing remoting senders for this channel. | |
191 const auto entries = stream_id_map_.equal_range(channel_id); | |
192 for (auto it = entries.first; it != entries.second; ++it) { | |
193 if (remoting_sender_map_.Lookup(it->second)) { | |
194 DVLOG(3) << "Delete CastRemotingSender for stream: " << it->second; | |
195 remoting_sender_map_.Remove(it->second); | |
196 } | |
197 } | |
198 stream_id_map_.erase(channel_id); | |
199 | |
190 if (id_map_.IsEmpty()) { | 200 if (id_map_.IsEmpty()) { |
191 DVLOG_IF(1, power_save_blocker_) << | 201 DVLOG_IF(1, power_save_blocker_) << |
192 ("Releasing the block on application suspension since no transports " | 202 ("Releasing the block on application suspension since no transports " |
193 "are active anymore for Cast Streaming."); | 203 "are active anymore for Cast Streaming."); |
194 power_save_blocker_.reset(); | 204 power_save_blocker_.reset(); |
195 } | 205 } |
196 } | 206 } |
197 | 207 |
198 void CastTransportHostFilter::OnInitializeStream( | 208 void CastTransportHostFilter::OnInitializeStream( |
199 int32_t channel_id, | 209 int32_t channel_id, |
200 const media::cast::CastTransportRtpConfig& config) { | 210 const media::cast::CastTransportRtpConfig& config) { |
201 media::cast::CastTransport* sender = id_map_.Lookup(channel_id); | 211 media::cast::CastTransport* transport = id_map_.Lookup(channel_id); |
202 if (sender) { | 212 if (transport) { |
203 sender->InitializeStream( | 213 if (config.rtp_payload_type == media::cast::RtpPayloadType::REMOTE_AUDIO || |
204 config, base::MakeUnique<RtcpClient>(channel_id, config.ssrc, | 214 config.rtp_payload_type == media::cast::RtpPayloadType::REMOTE_VIDEO) { |
205 weak_factory_.GetWeakPtr())); | 215 // Create CastRemotingSender for this RTP stream. |
216 scoped_refptr<media::cast::CastEnvironment> cast_environment = | |
217 new media::cast::CastEnvironment( | |
218 std::unique_ptr<base::TickClock>(new base::DefaultTickClock()), | |
dcheng
2016/09/10 02:31:36
Nit: base::MakeUnique<base::DefaultTickClock>()
xjz
2016/09/12 18:22:05
Done.
| |
219 base::ThreadTaskRunnerHandle::Get(), | |
220 base::ThreadTaskRunnerHandle::Get(), | |
221 base::ThreadTaskRunnerHandle::Get()); | |
222 remoting_sender_map_.AddWithID( | |
223 new CastRemotingSender(cast_environment, transport, config), | |
dcheng
2016/09/10 02:31:36
Nit: std::move() this into CastRemotingSender.
xjz
2016/09/12 18:22:05
Done.
| |
224 config.rtp_stream_id); | |
225 DVLOG(3) << "Create CastRemotingSender for stream: " | |
226 << config.rtp_stream_id; | |
227 | |
228 stream_id_map_.insert( | |
229 std::pair<int32_t, int32_t>(channel_id, config.rtp_stream_id)); | |
dcheng
2016/09/10 02:31:36
Nit: std::make_pair()
xjz
2016/09/12 18:22:05
Done.
| |
230 } else { | |
231 transport->InitializeStream( | |
232 config, base::MakeUnique<RtcpClient>(channel_id, config.ssrc, | |
233 weak_factory_.GetWeakPtr())); | |
234 } | |
206 } else { | 235 } else { |
207 DVLOG(1) << "CastTransportHostFilter::OnInitializeStream on non-existing " | 236 DVLOG(1) << "CastTransportHostFilter::OnInitializeStream on non-existing " |
208 "channel"; | 237 "channel"; |
209 } | 238 } |
210 } | 239 } |
211 | 240 |
212 void CastTransportHostFilter::OnInsertFrame( | 241 void CastTransportHostFilter::OnInsertFrame( |
213 int32_t channel_id, | 242 int32_t channel_id, |
214 uint32_t ssrc, | 243 uint32_t ssrc, |
215 const media::cast::EncodedFrame& frame) { | 244 const media::cast::EncodedFrame& frame) { |
216 media::cast::CastTransport* sender = id_map_.Lookup(channel_id); | 245 media::cast::CastTransport* transport = id_map_.Lookup(channel_id); |
217 if (sender) { | 246 if (transport) { |
218 sender->InsertFrame(ssrc, frame); | 247 transport->InsertFrame(ssrc, frame); |
219 } else { | 248 } else { |
220 DVLOG(1) | 249 DVLOG(1) |
221 << "CastTransportHostFilter::OnInsertFrame on non-existing channel"; | 250 << "CastTransportHostFilter::OnInsertFrame on non-existing channel"; |
222 } | 251 } |
223 } | 252 } |
224 | 253 |
225 void CastTransportHostFilter::OnCancelSendingFrames( | 254 void CastTransportHostFilter::OnCancelSendingFrames( |
226 int32_t channel_id, | 255 int32_t channel_id, |
227 uint32_t ssrc, | 256 uint32_t ssrc, |
228 const std::vector<media::cast::FrameId>& frame_ids) { | 257 const std::vector<media::cast::FrameId>& frame_ids) { |
229 media::cast::CastTransport* sender = id_map_.Lookup(channel_id); | 258 media::cast::CastTransport* transport = id_map_.Lookup(channel_id); |
230 if (sender) { | 259 if (transport) { |
231 sender->CancelSendingFrames(ssrc, frame_ids); | 260 transport->CancelSendingFrames(ssrc, frame_ids); |
232 } else { | 261 } else { |
233 DVLOG(1) | 262 DVLOG(1) |
234 << "CastTransportHostFilter::OnCancelSendingFrames " | 263 << "CastTransportHostFilter::OnCancelSendingFrames " |
235 << "on non-existing channel"; | 264 << "on non-existing channel"; |
236 } | 265 } |
237 } | 266 } |
238 | 267 |
239 void CastTransportHostFilter::OnResendFrameForKickstart( | 268 void CastTransportHostFilter::OnResendFrameForKickstart( |
240 int32_t channel_id, | 269 int32_t channel_id, |
241 uint32_t ssrc, | 270 uint32_t ssrc, |
242 media::cast::FrameId frame_id) { | 271 media::cast::FrameId frame_id) { |
243 media::cast::CastTransport* sender = id_map_.Lookup(channel_id); | 272 media::cast::CastTransport* transport = id_map_.Lookup(channel_id); |
244 if (sender) { | 273 if (transport) { |
245 sender->ResendFrameForKickstart(ssrc, frame_id); | 274 transport->ResendFrameForKickstart(ssrc, frame_id); |
246 } else { | 275 } else { |
247 DVLOG(1) | 276 DVLOG(1) |
248 << "CastTransportHostFilter::OnResendFrameForKickstart " | 277 << "CastTransportHostFilter::OnResendFrameForKickstart " |
249 << "on non-existing channel"; | 278 << "on non-existing channel"; |
250 } | 279 } |
251 } | 280 } |
252 | 281 |
253 void CastTransportHostFilter::OnSendSenderReport( | 282 void CastTransportHostFilter::OnSendSenderReport( |
254 int32_t channel_id, | 283 int32_t channel_id, |
255 uint32_t ssrc, | 284 uint32_t ssrc, |
256 base::TimeTicks current_time, | 285 base::TimeTicks current_time, |
257 media::cast::RtpTimeTicks current_time_as_rtp_timestamp) { | 286 media::cast::RtpTimeTicks current_time_as_rtp_timestamp) { |
258 media::cast::CastTransport* sender = id_map_.Lookup(channel_id); | 287 media::cast::CastTransport* transport = id_map_.Lookup(channel_id); |
259 if (sender) { | 288 if (transport) { |
260 sender->SendSenderReport(ssrc, | 289 transport->SendSenderReport(ssrc, current_time, |
261 current_time, | 290 current_time_as_rtp_timestamp); |
262 current_time_as_rtp_timestamp); | |
263 } else { | 291 } else { |
264 DVLOG(1) | 292 DVLOG(1) |
265 << "CastTransportHostFilter::OnSendSenderReport " | 293 << "CastTransportHostFilter::OnSendSenderReport " |
266 << "on non-existing channel"; | 294 << "on non-existing channel"; |
267 } | 295 } |
268 } | 296 } |
269 | 297 |
270 void CastTransportHostFilter::OnAddValidRtpReceiver( | 298 void CastTransportHostFilter::OnAddValidRtpReceiver( |
271 int32_t channel_id, | 299 int32_t channel_id, |
272 uint32_t rtp_sender_ssrc, | 300 uint32_t rtp_sender_ssrc, |
273 uint32_t rtp_receiver_ssrc) { | 301 uint32_t rtp_receiver_ssrc) { |
274 media::cast::CastTransport* sender = id_map_.Lookup(channel_id); | 302 media::cast::CastTransport* transport = id_map_.Lookup(channel_id); |
275 if (sender) { | 303 if (transport) { |
276 sender->AddValidRtpReceiver(rtp_sender_ssrc, rtp_receiver_ssrc); | 304 transport->AddValidRtpReceiver(rtp_sender_ssrc, rtp_receiver_ssrc); |
277 } else { | 305 } else { |
278 DVLOG(1) << "CastTransportHostFilter::OnAddValidRtpReceiver " | 306 DVLOG(1) << "CastTransportHostFilter::OnAddValidRtpReceiver " |
279 << "on non-existing channel"; | 307 << "on non-existing channel"; |
280 } | 308 } |
281 } | 309 } |
282 | 310 |
283 void CastTransportHostFilter::OnInitializeRtpReceiverRtcpBuilder( | 311 void CastTransportHostFilter::OnInitializeRtpReceiverRtcpBuilder( |
284 int32_t channel_id, | 312 int32_t channel_id, |
285 uint32_t rtp_receiver_ssrc, | 313 uint32_t rtp_receiver_ssrc, |
286 const media::cast::RtcpTimeData& time_data) { | 314 const media::cast::RtcpTimeData& time_data) { |
287 media::cast::CastTransport* sender = id_map_.Lookup(channel_id); | 315 media::cast::CastTransport* transport = id_map_.Lookup(channel_id); |
288 if (sender) { | 316 if (transport) { |
289 sender->InitializeRtpReceiverRtcpBuilder(rtp_receiver_ssrc, time_data); | 317 transport->InitializeRtpReceiverRtcpBuilder(rtp_receiver_ssrc, time_data); |
290 } else { | 318 } else { |
291 DVLOG(1) << "CastTransportHostFilter::OnInitializeRtpReceiverRtcpBuilder " | 319 DVLOG(1) << "CastTransportHostFilter::OnInitializeRtpReceiverRtcpBuilder " |
292 << "on non-existing channel"; | 320 << "on non-existing channel"; |
293 } | 321 } |
294 } | 322 } |
295 | 323 |
296 void CastTransportHostFilter::OnAddCastFeedback( | 324 void CastTransportHostFilter::OnAddCastFeedback( |
297 int32_t channel_id, | 325 int32_t channel_id, |
298 const media::cast::RtcpCastMessage& cast_message, | 326 const media::cast::RtcpCastMessage& cast_message, |
299 base::TimeDelta target_delay) { | 327 base::TimeDelta target_delay) { |
300 media::cast::CastTransport* sender = id_map_.Lookup(channel_id); | 328 media::cast::CastTransport* transport = id_map_.Lookup(channel_id); |
301 if (sender) { | 329 if (transport) { |
302 sender->AddCastFeedback(cast_message, target_delay); | 330 transport->AddCastFeedback(cast_message, target_delay); |
303 } else { | 331 } else { |
304 DVLOG(1) << "CastTransportHostFilter::OnAddCastFeedback " | 332 DVLOG(1) << "CastTransportHostFilter::OnAddCastFeedback " |
305 << "on non-existing channel"; | 333 << "on non-existing channel"; |
306 } | 334 } |
307 } | 335 } |
308 | 336 |
309 void CastTransportHostFilter::OnAddPli( | 337 void CastTransportHostFilter::OnAddPli( |
310 int32_t channel_id, | 338 int32_t channel_id, |
311 const media::cast::RtcpPliMessage& pli_message) { | 339 const media::cast::RtcpPliMessage& pli_message) { |
312 media::cast::CastTransport* sender = id_map_.Lookup(channel_id); | 340 media::cast::CastTransport* transport = id_map_.Lookup(channel_id); |
313 if (sender) { | 341 if (transport) { |
314 sender->AddPli(pli_message); | 342 transport->AddPli(pli_message); |
315 } else { | 343 } else { |
316 DVLOG(1) << "CastTransportHostFilter::OnAddPli on non-existing channel"; | 344 DVLOG(1) << "CastTransportHostFilter::OnAddPli on non-existing channel"; |
317 } | 345 } |
318 } | 346 } |
319 | 347 |
320 void CastTransportHostFilter::OnAddRtcpEvents( | 348 void CastTransportHostFilter::OnAddRtcpEvents( |
321 int32_t channel_id, | 349 int32_t channel_id, |
322 const media::cast::ReceiverRtcpEventSubscriber::RtcpEvents& rtcp_events) { | 350 const media::cast::ReceiverRtcpEventSubscriber::RtcpEvents& rtcp_events) { |
323 media::cast::CastTransport* sender = id_map_.Lookup(channel_id); | 351 media::cast::CastTransport* transport = id_map_.Lookup(channel_id); |
324 if (sender) { | 352 if (transport) { |
325 sender->AddRtcpEvents(rtcp_events); | 353 transport->AddRtcpEvents(rtcp_events); |
326 } else { | 354 } else { |
327 DVLOG(1) << "CastTransportHostFilter::OnAddRtcpEvents " | 355 DVLOG(1) << "CastTransportHostFilter::OnAddRtcpEvents " |
328 << "on non-existing channel"; | 356 << "on non-existing channel"; |
329 } | 357 } |
330 } | 358 } |
331 | 359 |
332 void CastTransportHostFilter::OnAddRtpReceiverReport( | 360 void CastTransportHostFilter::OnAddRtpReceiverReport( |
333 int32_t channel_id, | 361 int32_t channel_id, |
334 const media::cast::RtcpReportBlock& rtp_receiver_report_block) { | 362 const media::cast::RtcpReportBlock& rtp_receiver_report_block) { |
335 media::cast::CastTransport* sender = id_map_.Lookup(channel_id); | 363 media::cast::CastTransport* transport = id_map_.Lookup(channel_id); |
336 if (sender) { | 364 if (transport) { |
337 sender->AddRtpReceiverReport(rtp_receiver_report_block); | 365 transport->AddRtpReceiverReport(rtp_receiver_report_block); |
338 } else { | 366 } else { |
339 DVLOG(1) << "CastTransportHostFilter::OnAddRtpReceiverReport " | 367 DVLOG(1) << "CastTransportHostFilter::OnAddRtpReceiverReport " |
340 << "on non-existing channel"; | 368 << "on non-existing channel"; |
341 } | 369 } |
342 } | 370 } |
343 | 371 |
344 void CastTransportHostFilter::OnSendRtcpFromRtpReceiver(int32_t channel_id) { | 372 void CastTransportHostFilter::OnSendRtcpFromRtpReceiver(int32_t channel_id) { |
345 media::cast::CastTransport* sender = id_map_.Lookup(channel_id); | 373 media::cast::CastTransport* transport = id_map_.Lookup(channel_id); |
346 if (sender) { | 374 if (transport) { |
347 sender->SendRtcpFromRtpReceiver(); | 375 transport->SendRtcpFromRtpReceiver(); |
348 } else { | 376 } else { |
349 DVLOG(1) | 377 DVLOG(1) |
350 << "CastTransportHostFilter::OnSendRtcpFromRtpReceiver " | 378 << "CastTransportHostFilter::OnSendRtcpFromRtpReceiver " |
351 << "on non-existing channel"; | 379 << "on non-existing channel"; |
352 } | 380 } |
353 } | 381 } |
354 | 382 |
355 } // namespace cast | 383 } // namespace cast |
OLD | NEW |