| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/renderer/media/cast_session_delegate.h" | 5 #include "chrome/renderer/media/cast_session_delegate.h" |
| 6 | 6 |
| 7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/message_loop/message_loop_proxy.h" | 9 #include "base/message_loop/message_loop_proxy.h" |
| 10 #include "chrome/renderer/media/cast_threads.h" | 10 #include "chrome/renderer/media/cast_threads.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 | 38 |
| 39 // Allow about 9MB for audio event logs. Assume serialized log data for | 39 // Allow about 9MB for audio event logs. Assume serialized log data for |
| 40 // each frame will take up to 75 bytes. | 40 // each frame will take up to 75 bytes. |
| 41 const int kMaxAudioEventEntries = kMaxSerializedBytes / 75; | 41 const int kMaxAudioEventEntries = kMaxSerializedBytes / 75; |
| 42 | 42 |
| 43 } // namespace | 43 } // namespace |
| 44 | 44 |
| 45 CastSessionDelegate::CastSessionDelegate() | 45 CastSessionDelegate::CastSessionDelegate() |
| 46 : transport_configured_(false), | 46 : transport_configured_(false), |
| 47 io_message_loop_proxy_( | 47 io_message_loop_proxy_( |
| 48 content::RenderThread::Get()->GetIOMessageLoopProxy()) { | 48 content::RenderThread::Get()->GetIOMessageLoopProxy()), |
| 49 weak_factory_(this) { |
| 49 DCHECK(io_message_loop_proxy_); | 50 DCHECK(io_message_loop_proxy_); |
| 50 } | 51 } |
| 51 | 52 |
| 52 CastSessionDelegate::~CastSessionDelegate() { | 53 CastSessionDelegate::~CastSessionDelegate() { |
| 53 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 54 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
| 54 | 55 |
| 55 if (audio_event_subscriber_.get()) { | 56 if (audio_event_subscriber_.get()) { |
| 56 cast_environment_->Logging()->RemoveRawEventSubscriber( | 57 cast_environment_->Logging()->RemoveRawEventSubscriber( |
| 57 audio_event_subscriber_.get()); | 58 audio_event_subscriber_.get()); |
| 58 } | 59 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 void CastSessionDelegate::StartVideo( | 95 void CastSessionDelegate::StartVideo( |
| 95 const VideoSenderConfig& config, | 96 const VideoSenderConfig& config, |
| 96 const FrameInputAvailableCallback& callback) { | 97 const FrameInputAvailableCallback& callback) { |
| 97 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 98 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
| 98 audio_frame_input_available_callback_ = callback; | 99 audio_frame_input_available_callback_ = callback; |
| 99 | 100 |
| 100 video_config_.reset(new VideoSenderConfig(config)); | 101 video_config_.reset(new VideoSenderConfig(config)); |
| 101 StartSendingInternal(); | 102 StartSendingInternal(); |
| 102 } | 103 } |
| 103 | 104 |
| 104 void CastSessionDelegate::StartUDP( | 105 void CastSessionDelegate::StartUDP(const net::IPEndPoint& local_endpoint, |
| 105 const net::IPEndPoint& local_endpoint, | 106 const net::IPEndPoint& remote_endpoint) { |
| 106 const net::IPEndPoint& remote_endpoint) { | |
| 107 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 107 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
| 108 transport_configured_ = true; | 108 transport_configured_ = true; |
| 109 local_endpoint_ = local_endpoint; | 109 local_endpoint_ = local_endpoint; |
| 110 remote_endpoint_ = remote_endpoint; | 110 remote_endpoint_ = remote_endpoint; |
| 111 StartSendingInternal(); | 111 StartSendingInternal(); |
| 112 } | 112 } |
| 113 | 113 |
| 114 void CastSessionDelegate::ToggleLogging(bool is_audio, | 114 void CastSessionDelegate::ToggleLogging(bool is_audio, |
| 115 bool enable) { | 115 bool enable) { |
| 116 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 116 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 147 } | 147 } |
| 148 } | 148 } |
| 149 | 149 |
| 150 void CastSessionDelegate::GetEventLogsAndReset( | 150 void CastSessionDelegate::GetEventLogsAndReset( |
| 151 bool is_audio, const EventLogsCallback& callback) { | 151 bool is_audio, const EventLogsCallback& callback) { |
| 152 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 152 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
| 153 | 153 |
| 154 media::cast::EncodingEventSubscriber* subscriber = is_audio ? | 154 media::cast::EncodingEventSubscriber* subscriber = is_audio ? |
| 155 audio_event_subscriber_.get() : video_event_subscriber_.get(); | 155 audio_event_subscriber_.get() : video_event_subscriber_.get(); |
| 156 if (!subscriber) { | 156 if (!subscriber) { |
| 157 VLOG(2) << "Logging is currently disabled."; | |
| 158 callback.Run(make_scoped_ptr(new std::string).Pass()); | 157 callback.Run(make_scoped_ptr(new std::string).Pass()); |
| 159 return; | 158 return; |
| 160 } | 159 } |
| 161 | 160 |
| 162 media::cast::FrameEventMap frame_events; | 161 media::cast::FrameEventMap frame_events; |
| 163 media::cast::PacketEventMap packet_events; | 162 media::cast::PacketEventMap packet_events; |
| 164 media::cast::RtpTimestamp rtp_timestamp; | 163 media::cast::RtpTimestamp rtp_timestamp; |
| 165 | 164 |
| 166 subscriber->GetEventsAndReset(&frame_events, &packet_events, &rtp_timestamp); | 165 subscriber->GetEventsAndReset(&frame_events, &packet_events, &rtp_timestamp); |
| 167 | 166 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 194 // No transport, wait. | 193 // No transport, wait. |
| 195 if (!transport_configured_) | 194 if (!transport_configured_) |
| 196 return; | 195 return; |
| 197 | 196 |
| 198 // No audio or video, wait. | 197 // No audio or video, wait. |
| 199 if (!audio_config_ || !video_config_) | 198 if (!audio_config_ || !video_config_) |
| 200 return; | 199 return; |
| 201 | 200 |
| 202 Initialize(); | 201 Initialize(); |
| 203 | 202 |
| 204 media::cast::transport::CastTransportConfig config; | 203 // Rationale for using unretained: The callback cannot be called after the |
| 204 // destruction of CastTransportSenderIPC, and they both share the same thread. |
| 205 cast_transport_.reset(new CastTransportSenderIPC( |
| 206 local_endpoint_, |
| 207 remote_endpoint_, |
| 208 base::Bind(&CastSessionDelegate::StatusNotificationCB, |
| 209 base::Unretained(this)))); |
| 205 | 210 |
| 206 // TODO(hubbe): set config.aes_key and config.aes_iv_mask. | 211 // TODO(hubbe): set config.aes_key and config.aes_iv_mask. |
| 207 config.local_endpoint = local_endpoint_; | |
| 208 config.receiver_endpoint = remote_endpoint_; | |
| 209 if (audio_config_) { | 212 if (audio_config_) { |
| 210 config.audio_ssrc = audio_config_->sender_ssrc; | 213 media::cast::transport::CastTransportAudioConfig config; |
| 211 config.audio_codec = audio_config_->codec; | 214 config.base.ssrc = audio_config_->sender_ssrc; |
| 212 config.audio_rtp_config = audio_config_->rtp_config; | 215 config.codec = audio_config_->codec; |
| 213 config.audio_frequency = audio_config_->frequency; | 216 config.base.rtp_config = audio_config_->rtp_config; |
| 214 config.audio_channels = audio_config_->channels; | 217 config.frequency = audio_config_->frequency; |
| 218 config.channels = audio_config_->channels; |
| 219 cast_transport_->InitializeAudio(config); |
| 215 } | 220 } |
| 216 if (video_config_) { | 221 if (video_config_) { |
| 217 config.video_ssrc = video_config_->sender_ssrc; | 222 media::cast::transport::CastTransportVideoConfig config; |
| 218 config.video_codec = video_config_->codec; | 223 config.base.ssrc = video_config_->sender_ssrc; |
| 219 config.video_rtp_config = video_config_->rtp_config; | 224 config.codec = video_config_->codec; |
| 225 config.base.rtp_config = video_config_->rtp_config; |
| 226 cast_transport_->InitializeVideo(config); |
| 220 } | 227 } |
| 221 | 228 |
| 222 cast_transport_.reset(new CastTransportSenderIPC( | |
| 223 config, | |
| 224 base::Bind(&CastSessionDelegate::StatusNotificationCB, | |
| 225 base::Unretained(this)))); | |
| 226 | |
| 227 cast_sender_.reset(CastSender::CreateCastSender( | 229 cast_sender_.reset(CastSender::CreateCastSender( |
| 228 cast_environment_, | 230 cast_environment_, |
| 229 audio_config_.get(), | 231 audio_config_.get(), |
| 230 video_config_.get(), | 232 video_config_.get(), |
| 231 NULL, // GPU. | 233 NULL, // GPU. |
| 232 base::Bind(&CastSessionDelegate::InitializationResult, | 234 base::Bind(&CastSessionDelegate::InitializationResult, |
| 233 base::Unretained(this)), | 235 weak_factory_.GetWeakPtr()), |
| 234 cast_transport_.get())); | 236 cast_transport_.get())); |
| 235 cast_transport_->SetPacketReceiver(cast_sender_->packet_receiver()); | 237 cast_transport_->SetPacketReceiver(cast_sender_->packet_receiver()); |
| 236 } | 238 } |
| 237 | 239 |
| 238 void CastSessionDelegate::InitializationResult( | 240 void CastSessionDelegate::InitializationResult( |
| 239 media::cast::CastInitializationStatus result) const { | 241 media::cast::CastInitializationStatus result) const { |
| 240 DCHECK(cast_sender_); | 242 DCHECK(cast_sender_); |
| 241 | 243 |
| 242 // TODO(pwestin): handle the error codes. | 244 // TODO(pwestin): handle the error codes. |
| 243 if (result == media::cast::STATUS_INITIALIZED) { | 245 if (result == media::cast::STATUS_INITIALIZED) { |
| 244 if (!audio_frame_input_available_callback_.is_null()) { | 246 if (!audio_frame_input_available_callback_.is_null()) { |
| 245 audio_frame_input_available_callback_.Run(cast_sender_->frame_input()); | 247 audio_frame_input_available_callback_.Run(cast_sender_->frame_input()); |
| 246 } | 248 } |
| 247 if (!video_frame_input_available_callback_.is_null()) { | 249 if (!video_frame_input_available_callback_.is_null()) { |
| 248 video_frame_input_available_callback_.Run(cast_sender_->frame_input()); | 250 video_frame_input_available_callback_.Run(cast_sender_->frame_input()); |
| 249 } | 251 } |
| 250 } | 252 } |
| 251 } | 253 } |
| 252 | 254 |
| OLD | NEW |