| 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" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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::ReceivedPacket( |
| 53 int32 channel_id, | 53 int32_t channel_id, |
| 54 scoped_ptr<media::cast::Packet> packet) { | 54 scoped_ptr<media::cast::Packet> packet) { |
| 55 Send(new CastMsg_ReceivedPacket(channel_id, *packet)); | 55 Send(new CastMsg_ReceivedPacket(channel_id, *packet)); |
| 56 } | 56 } |
| 57 | 57 |
| 58 void CastTransportHostFilter::NotifyStatusChange( | 58 void CastTransportHostFilter::NotifyStatusChange( |
| 59 int32 channel_id, | 59 int32_t channel_id, |
| 60 media::cast::CastTransportStatus status) { | 60 media::cast::CastTransportStatus status) { |
| 61 Send(new CastMsg_NotifyStatusChange(channel_id, status)); | 61 Send(new CastMsg_NotifyStatusChange(channel_id, status)); |
| 62 } | 62 } |
| 63 | 63 |
| 64 void CastTransportHostFilter::SendRawEvents( | 64 void CastTransportHostFilter::SendRawEvents( |
| 65 int32 channel_id, | 65 int32_t channel_id, |
| 66 scoped_ptr<std::vector<media::cast::FrameEvent>> frame_events, | 66 scoped_ptr<std::vector<media::cast::FrameEvent>> frame_events, |
| 67 scoped_ptr<std::vector<media::cast::PacketEvent>> packet_events) { | 67 scoped_ptr<std::vector<media::cast::PacketEvent>> packet_events) { |
| 68 if (frame_events->empty() && packet_events->empty()) | 68 if (frame_events->empty() && packet_events->empty()) |
| 69 return; | 69 return; |
| 70 Send(new CastMsg_RawEvents(channel_id, *packet_events, *frame_events)); | 70 Send(new CastMsg_RawEvents(channel_id, *packet_events, *frame_events)); |
| 71 } | 71 } |
| 72 | 72 |
| 73 void CastTransportHostFilter::SendRtt(int32 channel_id, | 73 void CastTransportHostFilter::SendRtt(int32_t channel_id, |
| 74 uint32 ssrc, | 74 uint32_t ssrc, |
| 75 base::TimeDelta rtt) { | 75 base::TimeDelta rtt) { |
| 76 Send(new CastMsg_Rtt(channel_id, ssrc, rtt)); | 76 Send(new CastMsg_Rtt(channel_id, ssrc, rtt)); |
| 77 } | 77 } |
| 78 | 78 |
| 79 void CastTransportHostFilter::SendCastMessage( | 79 void CastTransportHostFilter::SendCastMessage( |
| 80 int32 channel_id, | 80 int32_t channel_id, |
| 81 uint32 ssrc, | 81 uint32_t ssrc, |
| 82 const media::cast::RtcpCastMessage& cast_message) { | 82 const media::cast::RtcpCastMessage& cast_message) { |
| 83 Send(new CastMsg_RtcpCastMessage(channel_id, ssrc, cast_message)); | 83 Send(new CastMsg_RtcpCastMessage(channel_id, ssrc, cast_message)); |
| 84 } | 84 } |
| 85 | 85 |
| 86 void CastTransportHostFilter::OnNew( | 86 void CastTransportHostFilter::OnNew(int32_t channel_id, |
| 87 int32 channel_id, | 87 const net::IPEndPoint& local_end_point, |
| 88 const net::IPEndPoint& local_end_point, | 88 const net::IPEndPoint& remote_end_point, |
| 89 const net::IPEndPoint& remote_end_point, | 89 const base::DictionaryValue& options) { |
| 90 const base::DictionaryValue& options) { | |
| 91 if (!power_save_blocker_) { | 90 if (!power_save_blocker_) { |
| 92 DVLOG(1) << ("Preventing the application from being suspended while one or " | 91 DVLOG(1) << ("Preventing the application from being suspended while one or " |
| 93 "more transports are active for Cast Streaming."); | 92 "more transports are active for Cast Streaming."); |
| 94 power_save_blocker_ = | 93 power_save_blocker_ = |
| 95 content::PowerSaveBlocker::Create( | 94 content::PowerSaveBlocker::Create( |
| 96 content::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, | 95 content::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, |
| 97 content::PowerSaveBlocker::kReasonOther, | 96 content::PowerSaveBlocker::kReasonOther, |
| 98 "Cast is streaming content to a remote receiver").Pass(); | 97 "Cast is streaming content to a remote receiver").Pass(); |
| 99 } | 98 } |
| 100 | 99 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 116 weak_factory_.GetWeakPtr(), | 115 weak_factory_.GetWeakPtr(), |
| 117 channel_id), | 116 channel_id), |
| 118 base::TimeDelta::FromSeconds(kSendRawEventsIntervalSecs), | 117 base::TimeDelta::FromSeconds(kSendRawEventsIntervalSecs), |
| 119 base::Bind(&CastTransportHostFilter::ReceivedPacket, | 118 base::Bind(&CastTransportHostFilter::ReceivedPacket, |
| 120 weak_factory_.GetWeakPtr(), | 119 weak_factory_.GetWeakPtr(), |
| 121 channel_id), | 120 channel_id), |
| 122 base::ThreadTaskRunnerHandle::Get()); | 121 base::ThreadTaskRunnerHandle::Get()); |
| 123 id_map_.AddWithID(sender.release(), channel_id); | 122 id_map_.AddWithID(sender.release(), channel_id); |
| 124 } | 123 } |
| 125 | 124 |
| 126 void CastTransportHostFilter::OnDelete(int32 channel_id) { | 125 void CastTransportHostFilter::OnDelete(int32_t channel_id) { |
| 127 media::cast::CastTransportSender* sender = id_map_.Lookup(channel_id); | 126 media::cast::CastTransportSender* sender = id_map_.Lookup(channel_id); |
| 128 if (sender) { | 127 if (sender) { |
| 129 id_map_.Remove(channel_id); | 128 id_map_.Remove(channel_id); |
| 130 } else { | 129 } else { |
| 131 DVLOG(1) << "CastTransportHostFilter::Delete called " | 130 DVLOG(1) << "CastTransportHostFilter::Delete called " |
| 132 << "on non-existing channel"; | 131 << "on non-existing channel"; |
| 133 } | 132 } |
| 134 | 133 |
| 135 if (id_map_.IsEmpty()) { | 134 if (id_map_.IsEmpty()) { |
| 136 DVLOG_IF(1, power_save_blocker_) << | 135 DVLOG_IF(1, power_save_blocker_) << |
| 137 ("Releasing the block on application suspension since no transports " | 136 ("Releasing the block on application suspension since no transports " |
| 138 "are active anymore for Cast Streaming."); | 137 "are active anymore for Cast Streaming."); |
| 139 power_save_blocker_.reset(); | 138 power_save_blocker_.reset(); |
| 140 } | 139 } |
| 141 } | 140 } |
| 142 | 141 |
| 143 void CastTransportHostFilter::OnInitializeAudio( | 142 void CastTransportHostFilter::OnInitializeAudio( |
| 144 int32 channel_id, | 143 int32_t channel_id, |
| 145 const media::cast::CastTransportRtpConfig& config) { | 144 const media::cast::CastTransportRtpConfig& config) { |
| 146 media::cast::CastTransportSender* sender = id_map_.Lookup(channel_id); | 145 media::cast::CastTransportSender* sender = id_map_.Lookup(channel_id); |
| 147 if (sender) { | 146 if (sender) { |
| 148 sender->InitializeAudio( | 147 sender->InitializeAudio( |
| 149 config, | 148 config, |
| 150 base::Bind(&CastTransportHostFilter::SendCastMessage, | 149 base::Bind(&CastTransportHostFilter::SendCastMessage, |
| 151 weak_factory_.GetWeakPtr(), | 150 weak_factory_.GetWeakPtr(), |
| 152 channel_id, config.ssrc), | 151 channel_id, config.ssrc), |
| 153 base::Bind(&CastTransportHostFilter::SendRtt, | 152 base::Bind(&CastTransportHostFilter::SendRtt, |
| 154 weak_factory_.GetWeakPtr(), | 153 weak_factory_.GetWeakPtr(), |
| 155 channel_id, config.ssrc)); | 154 channel_id, config.ssrc)); |
| 156 } else { | 155 } else { |
| 157 DVLOG(1) | 156 DVLOG(1) |
| 158 << "CastTransportHostFilter::OnInitializeAudio on non-existing channel"; | 157 << "CastTransportHostFilter::OnInitializeAudio on non-existing channel"; |
| 159 } | 158 } |
| 160 } | 159 } |
| 161 | 160 |
| 162 void CastTransportHostFilter::OnInitializeVideo( | 161 void CastTransportHostFilter::OnInitializeVideo( |
| 163 int32 channel_id, | 162 int32_t channel_id, |
| 164 const media::cast::CastTransportRtpConfig& config) { | 163 const media::cast::CastTransportRtpConfig& config) { |
| 165 media::cast::CastTransportSender* sender = id_map_.Lookup(channel_id); | 164 media::cast::CastTransportSender* sender = id_map_.Lookup(channel_id); |
| 166 if (sender) { | 165 if (sender) { |
| 167 sender->InitializeVideo( | 166 sender->InitializeVideo( |
| 168 config, | 167 config, |
| 169 base::Bind(&CastTransportHostFilter::SendCastMessage, | 168 base::Bind(&CastTransportHostFilter::SendCastMessage, |
| 170 weak_factory_.GetWeakPtr(), | 169 weak_factory_.GetWeakPtr(), |
| 171 channel_id, config.ssrc), | 170 channel_id, config.ssrc), |
| 172 base::Bind(&CastTransportHostFilter::SendRtt, | 171 base::Bind(&CastTransportHostFilter::SendRtt, |
| 173 weak_factory_.GetWeakPtr(), | 172 weak_factory_.GetWeakPtr(), |
| 174 channel_id, config.ssrc)); | 173 channel_id, config.ssrc)); |
| 175 } else { | 174 } else { |
| 176 DVLOG(1) | 175 DVLOG(1) |
| 177 << "CastTransportHostFilter::OnInitializeVideo on non-existing channel"; | 176 << "CastTransportHostFilter::OnInitializeVideo on non-existing channel"; |
| 178 } | 177 } |
| 179 } | 178 } |
| 180 | 179 |
| 181 void CastTransportHostFilter::OnInsertFrame( | 180 void CastTransportHostFilter::OnInsertFrame( |
| 182 int32 channel_id, | 181 int32_t channel_id, |
| 183 uint32 ssrc, | 182 uint32_t ssrc, |
| 184 const media::cast::EncodedFrame& frame) { | 183 const media::cast::EncodedFrame& frame) { |
| 185 media::cast::CastTransportSender* sender = id_map_.Lookup(channel_id); | 184 media::cast::CastTransportSender* sender = id_map_.Lookup(channel_id); |
| 186 if (sender) { | 185 if (sender) { |
| 187 sender->InsertFrame(ssrc, frame); | 186 sender->InsertFrame(ssrc, frame); |
| 188 } else { | 187 } else { |
| 189 DVLOG(1) | 188 DVLOG(1) |
| 190 << "CastTransportHostFilter::OnInsertFrame on non-existing channel"; | 189 << "CastTransportHostFilter::OnInsertFrame on non-existing channel"; |
| 191 } | 190 } |
| 192 } | 191 } |
| 193 | 192 |
| 194 void CastTransportHostFilter::OnCancelSendingFrames( | 193 void CastTransportHostFilter::OnCancelSendingFrames( |
| 195 int32 channel_id, uint32 ssrc, | 194 int32_t channel_id, |
| 196 const std::vector<uint32>& frame_ids) { | 195 uint32_t ssrc, |
| 196 const std::vector<uint32_t>& frame_ids) { |
| 197 media::cast::CastTransportSender* sender = id_map_.Lookup(channel_id); | 197 media::cast::CastTransportSender* sender = id_map_.Lookup(channel_id); |
| 198 if (sender) { | 198 if (sender) { |
| 199 sender->CancelSendingFrames(ssrc, frame_ids); | 199 sender->CancelSendingFrames(ssrc, frame_ids); |
| 200 } else { | 200 } else { |
| 201 DVLOG(1) | 201 DVLOG(1) |
| 202 << "CastTransportHostFilter::OnCancelSendingFrames " | 202 << "CastTransportHostFilter::OnCancelSendingFrames " |
| 203 << "on non-existing channel"; | 203 << "on non-existing channel"; |
| 204 } | 204 } |
| 205 } | 205 } |
| 206 | 206 |
| 207 void CastTransportHostFilter::OnResendFrameForKickstart( | 207 void CastTransportHostFilter::OnResendFrameForKickstart(int32_t channel_id, |
| 208 int32 channel_id, uint32 ssrc, uint32 frame_id) { | 208 uint32_t ssrc, |
| 209 uint32_t frame_id) { |
| 209 media::cast::CastTransportSender* sender = id_map_.Lookup(channel_id); | 210 media::cast::CastTransportSender* sender = id_map_.Lookup(channel_id); |
| 210 if (sender) { | 211 if (sender) { |
| 211 sender->ResendFrameForKickstart(ssrc, frame_id); | 212 sender->ResendFrameForKickstart(ssrc, frame_id); |
| 212 } else { | 213 } else { |
| 213 DVLOG(1) | 214 DVLOG(1) |
| 214 << "CastTransportHostFilter::OnResendFrameForKickstart " | 215 << "CastTransportHostFilter::OnResendFrameForKickstart " |
| 215 << "on non-existing channel"; | 216 << "on non-existing channel"; |
| 216 } | 217 } |
| 217 } | 218 } |
| 218 | 219 |
| 219 void CastTransportHostFilter::OnSendSenderReport( | 220 void CastTransportHostFilter::OnSendSenderReport( |
| 220 int32 channel_id, | 221 int32_t channel_id, |
| 221 uint32 ssrc, | 222 uint32_t ssrc, |
| 222 base::TimeTicks current_time, | 223 base::TimeTicks current_time, |
| 223 uint32 current_time_as_rtp_timestamp) { | 224 uint32_t current_time_as_rtp_timestamp) { |
| 224 media::cast::CastTransportSender* sender = id_map_.Lookup(channel_id); | 225 media::cast::CastTransportSender* sender = id_map_.Lookup(channel_id); |
| 225 if (sender) { | 226 if (sender) { |
| 226 sender->SendSenderReport(ssrc, | 227 sender->SendSenderReport(ssrc, |
| 227 current_time, | 228 current_time, |
| 228 current_time_as_rtp_timestamp); | 229 current_time_as_rtp_timestamp); |
| 229 } else { | 230 } else { |
| 230 DVLOG(1) | 231 DVLOG(1) |
| 231 << "CastTransportHostFilter::OnSendSenderReport " | 232 << "CastTransportHostFilter::OnSendSenderReport " |
| 232 << "on non-existing channel"; | 233 << "on non-existing channel"; |
| 233 } | 234 } |
| 234 } | 235 } |
| 235 | 236 |
| 236 void CastTransportHostFilter::OnAddValidSsrc(int32 channel_id, uint32 ssrc) { | 237 void CastTransportHostFilter::OnAddValidSsrc(int32_t channel_id, |
| 238 uint32_t ssrc) { |
| 237 media::cast::CastTransportSender* sender = id_map_.Lookup(channel_id); | 239 media::cast::CastTransportSender* sender = id_map_.Lookup(channel_id); |
| 238 if (sender) { | 240 if (sender) { |
| 239 sender->AddValidSsrc(ssrc); | 241 sender->AddValidSsrc(ssrc); |
| 240 } else { | 242 } else { |
| 241 DVLOG(1) | 243 DVLOG(1) |
| 242 << "CastTransportHostFilter::OnAddValidSsrc " | 244 << "CastTransportHostFilter::OnAddValidSsrc " |
| 243 << "on non-existing channel"; | 245 << "on non-existing channel"; |
| 244 } | 246 } |
| 245 } | 247 } |
| 246 | 248 |
| 247 void CastTransportHostFilter::OnSendRtcpFromRtpReceiver( | 249 void CastTransportHostFilter::OnSendRtcpFromRtpReceiver( |
| 248 int32 channel_id, | 250 int32_t channel_id, |
| 249 const media::cast::SendRtcpFromRtpReceiver_Params& params) { | 251 const media::cast::SendRtcpFromRtpReceiver_Params& params) { |
| 250 media::cast::CastTransportSender* sender = id_map_.Lookup(channel_id); | 252 media::cast::CastTransportSender* sender = id_map_.Lookup(channel_id); |
| 251 if (sender) { | 253 if (sender) { |
| 252 sender->SendRtcpFromRtpReceiver(params.ssrc, | 254 sender->SendRtcpFromRtpReceiver(params.ssrc, |
| 253 params.sender_ssrc, | 255 params.sender_ssrc, |
| 254 params.time_data, | 256 params.time_data, |
| 255 params.cast_message.get(), | 257 params.cast_message.get(), |
| 256 params.target_delay, | 258 params.target_delay, |
| 257 params.rtcp_events.get(), | 259 params.rtcp_events.get(), |
| 258 params.rtp_receiver_statistics.get()); | 260 params.rtp_receiver_statistics.get()); |
| 259 } else { | 261 } else { |
| 260 DVLOG(1) | 262 DVLOG(1) |
| 261 << "CastTransportHostFilter::OnSendRtcpFromRtpReceiver " | 263 << "CastTransportHostFilter::OnSendRtcpFromRtpReceiver " |
| 262 << "on non-existing channel"; | 264 << "on non-existing channel"; |
| 263 } | 265 } |
| 264 } | 266 } |
| 265 | 267 |
| 266 | 268 |
| 267 } // namespace cast | 269 } // namespace cast |
| OLD | NEW |