Chromium Code Reviews| 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/thread_task_runner_handle.h" | 7 #include "base/thread_task_runner_handle.h" |
| 8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/common/cast_messages.h" | 9 #include "chrome/common/cast_messages.h" |
| 10 #include "components/net_log/chrome_net_log.h" | 10 #include "components/net_log/chrome_net_log.h" |
| 11 #include "content/public/browser/power_save_blocker.h" | 11 #include "content/public/browser/power_save_blocker.h" |
| 12 #include "media/cast/net/cast_transport_sender.h" | 12 #include "media/cast/net/cast_transport_sender.h" |
| 13 | 13 |
| 14 namespace { | 14 namespace { |
| 15 | 15 |
| 16 // How often to send raw events. | 16 // How often to send raw events. |
| 17 const int kSendRawEventsIntervalSecs = 1; | 17 const int kSendRawEventsIntervalSecs = 1; |
| 18 | 18 |
| 19 } | 19 } // namespace |
| 20 | 20 |
| 21 namespace cast { | 21 namespace cast { |
| 22 | 22 |
| 23 CastTransportHostFilter::CastTransportHostFilter() | 23 CastTransportHostFilter::CastTransportHostFilter() |
| 24 : BrowserMessageFilter(CastMsgStart), | 24 : BrowserMessageFilter(CastMsgStart), |
| 25 weak_factory_(this) {} | 25 weak_factory_(this) {} |
| 26 | 26 |
| 27 CastTransportHostFilter::~CastTransportHostFilter() {} | 27 CastTransportHostFilter::~CastTransportHostFilter() {} |
| 28 | 28 |
| 29 bool CastTransportHostFilter::OnMessageReceived(const IPC::Message& message) { | 29 bool CastTransportHostFilter::OnMessageReceived(const IPC::Message& message) { |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 42 OnCancelSendingFrames) | 42 OnCancelSendingFrames) |
| 43 IPC_MESSAGE_HANDLER(CastHostMsg_AddValidSsrc, | 43 IPC_MESSAGE_HANDLER(CastHostMsg_AddValidSsrc, |
| 44 OnAddValidSsrc) | 44 OnAddValidSsrc) |
| 45 IPC_MESSAGE_HANDLER(CastHostMsg_SendRtcpFromRtpReceiver, | 45 IPC_MESSAGE_HANDLER(CastHostMsg_SendRtcpFromRtpReceiver, |
| 46 OnSendRtcpFromRtpReceiver) | 46 OnSendRtcpFromRtpReceiver) |
| 47 IPC_MESSAGE_UNHANDLED(handled = false); | 47 IPC_MESSAGE_UNHANDLED(handled = false); |
| 48 IPC_END_MESSAGE_MAP(); | 48 IPC_END_MESSAGE_MAP(); |
| 49 return handled; | 49 return handled; |
| 50 } | 50 } |
| 51 | 51 |
| 52 void CastTransportHostFilter::ReceivedPacket( | 52 void CastTransportHostFilter::OnStatusChange( |
| 53 int32 channel_id, | 53 media::cast::CastTransportStatus status) { |
| 54 scoped_ptr<media::cast::Packet> packet) { | 54 Send(new CastMsg_NotifyStatusChange(channel_id_, status)); |
| 55 Send(new CastMsg_ReceivedPacket(channel_id, *packet)); | |
| 56 } | 55 } |
| 57 | 56 |
| 58 void CastTransportHostFilter::NotifyStatusChange( | 57 void CastTransportHostFilter::OnReceivedLoggingEvents( |
| 59 int32 channel_id, | |
| 60 media::cast::CastTransportStatus status) { | |
| 61 Send(new CastMsg_NotifyStatusChange(channel_id, status)); | |
| 62 } | |
| 63 | |
| 64 void CastTransportHostFilter::SendRawEvents( | |
| 65 int32 channel_id, | |
| 66 scoped_ptr<std::vector<media::cast::FrameEvent>> frame_events, | 58 scoped_ptr<std::vector<media::cast::FrameEvent>> frame_events, |
| 67 scoped_ptr<std::vector<media::cast::PacketEvent>> packet_events) { | 59 scoped_ptr<std::vector<media::cast::PacketEvent>> packet_events) { |
| 68 if (frame_events->empty() && packet_events->empty()) | 60 if (frame_events->empty() && packet_events->empty()) |
| 69 return; | 61 return; |
| 70 Send(new CastMsg_RawEvents(channel_id, *packet_events, *frame_events)); | 62 Send(new CastMsg_RawEvents(channel_id_, *packet_events, *frame_events)); |
| 63 } | |
| 64 | |
| 65 void CastTransportHostFilter::OnReceivedPackets( | |
| 66 scoped_ptr<media::cast::Packet> packet) { | |
| 67 Send(new CastMsg_ReceivedPacket(channel_id_, *packet)); | |
| 71 } | 68 } |
| 72 | 69 |
| 73 void CastTransportHostFilter::SendRtt(int32 channel_id, | 70 void CastTransportHostFilter::SendRtt(int32 channel_id, |
| 74 uint32 ssrc, | 71 uint32 ssrc, |
| 75 base::TimeDelta rtt) { | 72 base::TimeDelta rtt) { |
| 76 Send(new CastMsg_Rtt(channel_id, ssrc, rtt)); | 73 Send(new CastMsg_Rtt(channel_id, ssrc, rtt)); |
| 77 } | 74 } |
| 78 | 75 |
| 79 void CastTransportHostFilter::SendCastMessage( | 76 void CastTransportHostFilter::SendCastMessage( |
| 80 int32 channel_id, | 77 int32 channel_id, |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 95 content::PowerSaveBlocker::Create( | 92 content::PowerSaveBlocker::Create( |
| 96 content::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, | 93 content::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, |
| 97 content::PowerSaveBlocker::kReasonOther, | 94 content::PowerSaveBlocker::kReasonOther, |
| 98 "Cast is streaming content to a remote receiver").Pass(); | 95 "Cast is streaming content to a remote receiver").Pass(); |
| 99 } | 96 } |
| 100 | 97 |
| 101 if (id_map_.Lookup(channel_id)) { | 98 if (id_map_.Lookup(channel_id)) { |
| 102 id_map_.Remove(channel_id); | 99 id_map_.Remove(channel_id); |
| 103 } | 100 } |
| 104 | 101 |
| 102 channel_id_ = channel_id; | |
|
Irfan
2015/12/16 19:44:34
as we discussed, this creates a problem since we w
xjz
2015/12/16 21:58:01
I prefer the second approach, unless there are rea
| |
| 103 media::cast::CastTransportSender::CreateParams transport_params( | |
| 104 g_browser_process->net_log(), &clock_, local_end_point, remote_end_point, | |
| 105 this, base::TimeDelta::FromSeconds(kSendRawEventsIntervalSecs), | |
| 106 make_scoped_ptr(options.DeepCopy()), base::ThreadTaskRunnerHandle::Get()); | |
| 105 scoped_ptr<media::cast::CastTransportSender> sender = | 107 scoped_ptr<media::cast::CastTransportSender> sender = |
| 106 media::cast::CastTransportSender::Create( | 108 media::cast::CastTransportSender::Create(transport_params); |
| 107 g_browser_process->net_log(), | |
| 108 &clock_, | |
| 109 local_end_point, | |
| 110 remote_end_point, | |
| 111 make_scoped_ptr(options.DeepCopy()), | |
| 112 base::Bind(&CastTransportHostFilter::NotifyStatusChange, | |
| 113 weak_factory_.GetWeakPtr(), | |
| 114 channel_id), | |
| 115 base::Bind(&CastTransportHostFilter::SendRawEvents, | |
| 116 weak_factory_.GetWeakPtr(), | |
| 117 channel_id), | |
| 118 base::TimeDelta::FromSeconds(kSendRawEventsIntervalSecs), | |
| 119 base::Bind(&CastTransportHostFilter::ReceivedPacket, | |
| 120 weak_factory_.GetWeakPtr(), | |
| 121 channel_id), | |
| 122 base::ThreadTaskRunnerHandle::Get()); | |
| 123 id_map_.AddWithID(sender.release(), channel_id); | 109 id_map_.AddWithID(sender.release(), channel_id); |
| 124 } | 110 } |
| 125 | 111 |
| 126 void CastTransportHostFilter::OnDelete(int32 channel_id) { | 112 void CastTransportHostFilter::OnDelete(int32 channel_id) { |
| 127 media::cast::CastTransportSender* sender = id_map_.Lookup(channel_id); | 113 media::cast::CastTransportSender* sender = id_map_.Lookup(channel_id); |
| 128 if (sender) { | 114 if (sender) { |
| 129 id_map_.Remove(channel_id); | 115 id_map_.Remove(channel_id); |
| 130 } else { | 116 } else { |
| 131 DVLOG(1) << "CastTransportHostFilter::Delete called " | 117 DVLOG(1) << "CastTransportHostFilter::Delete called " |
| 132 << "on non-existing channel"; | 118 << "on non-existing channel"; |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 258 params.rtp_receiver_statistics.get()); | 244 params.rtp_receiver_statistics.get()); |
| 259 } else { | 245 } else { |
| 260 DVLOG(1) | 246 DVLOG(1) |
| 261 << "CastTransportHostFilter::OnSendRtcpFromRtpReceiver " | 247 << "CastTransportHostFilter::OnSendRtcpFromRtpReceiver " |
| 262 << "on non-existing channel"; | 248 << "on non-existing channel"; |
| 263 } | 249 } |
| 264 } | 250 } |
| 265 | 251 |
| 266 | 252 |
| 267 } // namespace cast | 253 } // namespace cast |
| OLD | NEW |