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/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/thread_task_runner_handle.h" | 8 #include "base/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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 51 cast_transport_host_filter_->Send( | 51 cast_transport_host_filter_->Send( |
| 52 new CastMsg_RawEvents(channel_id_, *packet_events, *frame_events)); | 52 new CastMsg_RawEvents(channel_id_, *packet_events, *frame_events)); |
| 53 } | 53 } |
| 54 | 54 |
| 55 void TransportClient::ProcessRtpPacket( | 55 void TransportClient::ProcessRtpPacket( |
| 56 std::unique_ptr<media::cast::Packet> packet) { | 56 std::unique_ptr<media::cast::Packet> packet) { |
| 57 cast_transport_host_filter_->Send( | 57 cast_transport_host_filter_->Send( |
| 58 new CastMsg_ReceivedPacket(channel_id_, *packet)); | 58 new CastMsg_ReceivedPacket(channel_id_, *packet)); |
| 59 } | 59 } |
| 60 | 60 |
| 61 class RtcpClient : public media::cast::RtpSenderRtcpClient { | |
| 62 public: | |
| 63 RtcpClient(int32_t channel_id, | |
| 64 uint32_t rtp_sender_ssrc, | |
| 65 cast::CastTransportHostFilter* cast_transport_host_filter) | |
|
miu
2016/04/15 23:14:39
Should the third arg be of type base::WeakPtr<cast
xjz
2016/04/20 01:09:02
Done. Use weak ptr.
| |
| 66 : channel_id_(channel_id), | |
| 67 rtp_sender_ssrc_(rtp_sender_ssrc), | |
| 68 cast_transport_host_filter_(cast_transport_host_filter) {} | |
| 69 | |
| 70 void OnCastMessageReceived( | |
| 71 const media::cast::RtcpCastMessage& cast_message) override { | |
| 72 cast_transport_host_filter_->Send(new CastMsg_RtcpCastMessage( | |
| 73 channel_id_, rtp_sender_ssrc_, cast_message)); | |
| 74 } | |
| 75 | |
| 76 void OnRttReceived(base::TimeDelta round_trip_time) override { | |
| 77 cast_transport_host_filter_->Send( | |
| 78 new CastMsg_Rtt(channel_id_, rtp_sender_ssrc_, round_trip_time)); | |
| 79 } | |
| 80 | |
| 81 void OnPliReceived() override { | |
| 82 cast_transport_host_filter_->Send( | |
| 83 new CastMsg_Pli(channel_id_, rtp_sender_ssrc_)); | |
| 84 } | |
| 85 | |
| 86 private: | |
| 87 int32_t channel_id_; | |
|
miu
2016/04/15 23:14:39
Please make these three members const.
xjz
2016/04/20 01:09:02
Done.
| |
| 88 uint32_t rtp_sender_ssrc_; | |
| 89 cast::CastTransportHostFilter* cast_transport_host_filter_; | |
| 90 | |
| 91 DISALLOW_COPY_AND_ASSIGN(RtcpClient); | |
| 92 }; | |
| 93 | |
| 61 } // namespace | 94 } // namespace |
| 62 | 95 |
| 63 namespace cast { | 96 namespace cast { |
| 64 | 97 |
| 65 CastTransportHostFilter::CastTransportHostFilter() | 98 CastTransportHostFilter::CastTransportHostFilter() |
| 66 : BrowserMessageFilter(CastMsgStart), | 99 : BrowserMessageFilter(CastMsgStart), |
| 67 weak_factory_(this) {} | 100 weak_factory_(this) {} |
| 68 | 101 |
| 69 CastTransportHostFilter::~CastTransportHostFilter() {} | 102 CastTransportHostFilter::~CastTransportHostFilter() {} |
| 70 | 103 |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 96 IPC_MESSAGE_HANDLER(CastHostMsg_AddRtcpEvents, OnAddRtcpEvents) | 129 IPC_MESSAGE_HANDLER(CastHostMsg_AddRtcpEvents, OnAddRtcpEvents) |
| 97 IPC_MESSAGE_HANDLER(CastHostMsg_AddRtpReceiverReport, | 130 IPC_MESSAGE_HANDLER(CastHostMsg_AddRtpReceiverReport, |
| 98 OnAddRtpReceiverReport) | 131 OnAddRtpReceiverReport) |
| 99 IPC_MESSAGE_HANDLER(CastHostMsg_SendRtcpFromRtpReceiver, | 132 IPC_MESSAGE_HANDLER(CastHostMsg_SendRtcpFromRtpReceiver, |
| 100 OnSendRtcpFromRtpReceiver) | 133 OnSendRtcpFromRtpReceiver) |
| 101 IPC_MESSAGE_UNHANDLED(handled = false) | 134 IPC_MESSAGE_UNHANDLED(handled = false) |
| 102 IPC_END_MESSAGE_MAP() | 135 IPC_END_MESSAGE_MAP() |
| 103 return handled; | 136 return handled; |
| 104 } | 137 } |
| 105 | 138 |
| 106 void CastTransportHostFilter::SendRtt(int32_t channel_id, | |
| 107 uint32_t rtp_sender_ssrc, | |
| 108 base::TimeDelta rtt) { | |
| 109 Send(new CastMsg_Rtt(channel_id, rtp_sender_ssrc, rtt)); | |
| 110 } | |
| 111 | |
| 112 void CastTransportHostFilter::SendCastMessage( | |
| 113 int32_t channel_id, | |
| 114 uint32_t rtp_sender_ssrc, | |
| 115 const media::cast::RtcpCastMessage& cast_message) { | |
| 116 Send(new CastMsg_RtcpCastMessage(channel_id, rtp_sender_ssrc, cast_message)); | |
| 117 } | |
| 118 | |
| 119 void CastTransportHostFilter::SendReceivedPli(int32_t channel_id, | |
| 120 uint32_t rtp_sender_ssrc) { | |
| 121 Send(new CastMsg_Pli(channel_id, rtp_sender_ssrc)); | |
| 122 } | |
| 123 | |
| 124 void CastTransportHostFilter::OnNew(int32_t channel_id, | 139 void CastTransportHostFilter::OnNew(int32_t channel_id, |
| 125 const net::IPEndPoint& local_end_point, | 140 const net::IPEndPoint& local_end_point, |
| 126 const net::IPEndPoint& remote_end_point, | 141 const net::IPEndPoint& remote_end_point, |
| 127 const base::DictionaryValue& options) { | 142 const base::DictionaryValue& options) { |
| 128 if (!power_save_blocker_) { | 143 if (!power_save_blocker_) { |
| 129 DVLOG(1) << ("Preventing the application from being suspended while one or " | 144 DVLOG(1) << ("Preventing the application from being suspended while one or " |
| 130 "more transports are active for Cast Streaming."); | 145 "more transports are active for Cast Streaming."); |
| 131 power_save_blocker_ = content::PowerSaveBlocker::Create( | 146 power_save_blocker_ = content::PowerSaveBlocker::Create( |
| 132 content::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, | 147 content::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, |
| 133 content::PowerSaveBlocker::kReasonOther, | 148 content::PowerSaveBlocker::kReasonOther, |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 164 } | 179 } |
| 165 | 180 |
| 166 if (id_map_.IsEmpty()) { | 181 if (id_map_.IsEmpty()) { |
| 167 DVLOG_IF(1, power_save_blocker_) << | 182 DVLOG_IF(1, power_save_blocker_) << |
| 168 ("Releasing the block on application suspension since no transports " | 183 ("Releasing the block on application suspension since no transports " |
| 169 "are active anymore for Cast Streaming."); | 184 "are active anymore for Cast Streaming."); |
| 170 power_save_blocker_.reset(); | 185 power_save_blocker_.reset(); |
| 171 } | 186 } |
| 172 } | 187 } |
| 173 | 188 |
| 174 void CastTransportHostFilter::OnInitializeAudio( | 189 void CastTransportHostFilter::OnInitializeAudio( |
|
miu
2016/04/15 23:14:39
side note: Notice how OnInitializeAudio() is ident
xjz
2016/04/20 01:09:02
Sounds great! Add a todo comment.
| |
| 175 int32_t channel_id, | 190 int32_t channel_id, |
| 176 const media::cast::CastTransportRtpConfig& config) { | 191 const media::cast::CastTransportRtpConfig& config) { |
| 177 media::cast::CastTransport* sender = id_map_.Lookup(channel_id); | 192 media::cast::CastTransport* sender = id_map_.Lookup(channel_id); |
| 178 if (sender) { | 193 if (sender) { |
| 179 sender->InitializeAudio( | 194 sender->InitializeAudio(config, base::WrapUnique(new RtcpClient( |
| 180 config, base::Bind(&CastTransportHostFilter::SendCastMessage, | 195 channel_id, config.ssrc, this))); |
| 181 weak_factory_.GetWeakPtr(), channel_id, config.ssrc), | |
| 182 base::Bind(&CastTransportHostFilter::SendRtt, | |
| 183 weak_factory_.GetWeakPtr(), channel_id, config.ssrc), | |
| 184 base::Bind(&CastTransportHostFilter::SendReceivedPli, | |
| 185 weak_factory_.GetWeakPtr(), channel_id, config.ssrc)); | |
| 186 } else { | 196 } else { |
| 187 DVLOG(1) | 197 DVLOG(1) |
| 188 << "CastTransportHostFilter::OnInitializeAudio on non-existing channel"; | 198 << "CastTransportHostFilter::OnInitializeAudio on non-existing channel"; |
| 189 } | 199 } |
| 190 } | 200 } |
| 191 | 201 |
| 192 void CastTransportHostFilter::OnInitializeVideo( | 202 void CastTransportHostFilter::OnInitializeVideo( |
| 193 int32_t channel_id, | 203 int32_t channel_id, |
| 194 const media::cast::CastTransportRtpConfig& config) { | 204 const media::cast::CastTransportRtpConfig& config) { |
| 195 media::cast::CastTransport* sender = id_map_.Lookup(channel_id); | 205 media::cast::CastTransport* sender = id_map_.Lookup(channel_id); |
| 196 if (sender) { | 206 if (sender) { |
| 197 sender->InitializeVideo( | 207 sender->InitializeVideo(config, base::WrapUnique(new RtcpClient( |
| 198 config, base::Bind(&CastTransportHostFilter::SendCastMessage, | 208 channel_id, config.ssrc, this))); |
| 199 weak_factory_.GetWeakPtr(), channel_id, config.ssrc), | |
| 200 base::Bind(&CastTransportHostFilter::SendRtt, | |
| 201 weak_factory_.GetWeakPtr(), channel_id, config.ssrc), | |
| 202 base::Bind(&CastTransportHostFilter::SendReceivedPli, | |
| 203 weak_factory_.GetWeakPtr(), channel_id, config.ssrc)); | |
| 204 } else { | 209 } else { |
| 205 DVLOG(1) | 210 DVLOG(1) |
| 206 << "CastTransportHostFilter::OnInitializeVideo on non-existing channel"; | 211 << "CastTransportHostFilter::OnInitializeVideo on non-existing channel"; |
| 207 } | 212 } |
| 208 } | 213 } |
| 209 | 214 |
| 210 void CastTransportHostFilter::OnInsertFrame( | 215 void CastTransportHostFilter::OnInsertFrame( |
| 211 int32_t channel_id, | 216 int32_t channel_id, |
| 212 uint32_t ssrc, | 217 uint32_t ssrc, |
| 213 const media::cast::EncodedFrame& frame) { | 218 const media::cast::EncodedFrame& frame) { |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 343 if (sender) { | 348 if (sender) { |
| 344 sender->SendRtcpFromRtpReceiver(); | 349 sender->SendRtcpFromRtpReceiver(); |
| 345 } else { | 350 } else { |
| 346 DVLOG(1) | 351 DVLOG(1) |
| 347 << "CastTransportHostFilter::OnSendRtcpFromRtpReceiver " | 352 << "CastTransportHostFilter::OnSendRtcpFromRtpReceiver " |
| 348 << "on non-existing channel"; | 353 << "on non-existing channel"; |
| 349 } | 354 } |
| 350 } | 355 } |
| 351 | 356 |
| 352 } // namespace cast | 357 } // namespace cast |
| OLD | NEW |