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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 if (audio_event_subscriber_.get()) { | 56 if (audio_event_subscriber_.get()) { |
57 cast_environment_->Logging()->RemoveRawEventSubscriber( | 57 cast_environment_->Logging()->RemoveRawEventSubscriber( |
58 audio_event_subscriber_.get()); | 58 audio_event_subscriber_.get()); |
59 } | 59 } |
60 if (video_event_subscriber_.get()) { | 60 if (video_event_subscriber_.get()) { |
61 cast_environment_->Logging()->RemoveRawEventSubscriber( | 61 cast_environment_->Logging()->RemoveRawEventSubscriber( |
62 video_event_subscriber_.get()); | 62 video_event_subscriber_.get()); |
63 } | 63 } |
64 } | 64 } |
65 | 65 |
66 void CastSessionDelegate::Initialize() { | 66 void CastSessionDelegate::Initialize( |
| 67 const media::cast::CastLoggingConfig& logging_config) { |
67 if (cast_environment_) | 68 if (cast_environment_) |
68 return; // Already initialized. | 69 return; // Already initialized. |
69 | 70 |
70 // CastSender uses the renderer's IO thread as the main thread. This reduces | 71 // CastSender uses the renderer's IO thread as the main thread. This reduces |
71 // thread hopping for incoming video frames and outgoing network packets. | 72 // thread hopping for incoming video frames and outgoing network packets. |
72 // There's no need to decode so no thread assigned for decoding. | 73 // There's no need to decode so no thread assigned for decoding. |
73 // Logging: enable raw events and stats collection. | |
74 cast_environment_ = new CastEnvironment( | 74 cast_environment_ = new CastEnvironment( |
75 scoped_ptr<base::TickClock>(new base::DefaultTickClock()).Pass(), | 75 scoped_ptr<base::TickClock>(new base::DefaultTickClock()).Pass(), |
76 base::MessageLoopProxy::current(), | 76 base::MessageLoopProxy::current(), |
77 g_cast_threads.Get().GetAudioEncodeMessageLoopProxy(), | 77 g_cast_threads.Get().GetAudioEncodeMessageLoopProxy(), |
78 NULL, | 78 NULL, |
79 g_cast_threads.Get().GetVideoEncodeMessageLoopProxy(), | 79 g_cast_threads.Get().GetVideoEncodeMessageLoopProxy(), |
80 NULL, | 80 NULL, |
81 base::MessageLoopProxy::current(), | 81 base::MessageLoopProxy::current(), |
82 media::cast::GetLoggingConfigWithRawEventsAndStatsEnabled()); | 82 logging_config); |
83 } | 83 } |
84 | 84 |
85 void CastSessionDelegate::StartAudio( | 85 void CastSessionDelegate::StartAudio( |
86 const AudioSenderConfig& config, | 86 const AudioSenderConfig& config, |
87 const FrameInputAvailableCallback& callback) { | 87 const FrameInputAvailableCallback& callback) { |
88 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 88 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
89 | 89 |
90 audio_config_.reset(new AudioSenderConfig(config)); | 90 audio_config_.reset(new AudioSenderConfig(config)); |
91 video_frame_input_available_callback_ = callback; | 91 video_frame_input_available_callback_ = callback; |
92 StartSendingInternal(); | 92 StartSendingInternal(); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 191 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
192 | 192 |
193 // No transport, wait. | 193 // No transport, wait. |
194 if (!transport_configured_) | 194 if (!transport_configured_) |
195 return; | 195 return; |
196 | 196 |
197 // No audio or video, wait. | 197 // No audio or video, wait. |
198 if (!audio_config_ || !video_config_) | 198 if (!audio_config_ || !video_config_) |
199 return; | 199 return; |
200 | 200 |
201 Initialize(); | 201 // Logging: enable raw events and stats collection. |
| 202 media::cast::CastLoggingConfig logging_config = |
| 203 media::cast::GetLoggingConfigWithRawEventsAndStatsEnabled(); |
| 204 Initialize(logging_config); |
202 | 205 |
203 // Rationale for using unretained: The callback cannot be called after the | 206 // Rationale for using unretained: The callback cannot be called after the |
204 // destruction of CastTransportSenderIPC, and they both share the same thread. | 207 // destruction of CastTransportSenderIPC, and they both share the same thread. |
205 cast_transport_.reset(new CastTransportSenderIPC( | 208 cast_transport_.reset(new CastTransportSenderIPC( |
206 local_endpoint_, | 209 local_endpoint_, |
207 remote_endpoint_, | 210 remote_endpoint_, |
208 base::Bind(&CastSessionDelegate::StatusNotificationCB, | 211 base::Bind(&CastSessionDelegate::StatusNotificationCB, |
209 base::Unretained(this)))); | 212 base::Unretained(this)), |
| 213 logging_config, |
| 214 base::Bind(&CastSessionDelegate::LogRawEvents, base::Unretained(this)))); |
210 | 215 |
211 // TODO(hubbe): set config.aes_key and config.aes_iv_mask. | 216 // TODO(hubbe): set config.aes_key and config.aes_iv_mask. |
212 if (audio_config_) { | 217 if (audio_config_) { |
213 media::cast::transport::CastTransportAudioConfig config; | 218 media::cast::transport::CastTransportAudioConfig config; |
214 config.base.ssrc = audio_config_->sender_ssrc; | 219 config.base.ssrc = audio_config_->sender_ssrc; |
215 config.codec = audio_config_->codec; | 220 config.codec = audio_config_->codec; |
216 config.base.rtp_config = audio_config_->rtp_config; | 221 config.base.rtp_config = audio_config_->rtp_config; |
217 config.frequency = audio_config_->frequency; | 222 config.frequency = audio_config_->frequency; |
218 config.channels = audio_config_->channels; | 223 config.channels = audio_config_->channels; |
219 cast_transport_->InitializeAudio(config); | 224 cast_transport_->InitializeAudio(config); |
(...skipping 25 matching lines...) Expand all Loading... |
245 if (result == media::cast::STATUS_INITIALIZED) { | 250 if (result == media::cast::STATUS_INITIALIZED) { |
246 if (!audio_frame_input_available_callback_.is_null()) { | 251 if (!audio_frame_input_available_callback_.is_null()) { |
247 audio_frame_input_available_callback_.Run(cast_sender_->frame_input()); | 252 audio_frame_input_available_callback_.Run(cast_sender_->frame_input()); |
248 } | 253 } |
249 if (!video_frame_input_available_callback_.is_null()) { | 254 if (!video_frame_input_available_callback_.is_null()) { |
250 video_frame_input_available_callback_.Run(cast_sender_->frame_input()); | 255 video_frame_input_available_callback_.Run(cast_sender_->frame_input()); |
251 } | 256 } |
252 } | 257 } |
253 } | 258 } |
254 | 259 |
| 260 void CastSessionDelegate::LogRawEvents( |
| 261 const std::vector<media::cast::PacketEvent>& packet_events) { |
| 262 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
| 263 |
| 264 for (std::vector<media::cast::PacketEvent>::const_iterator it = |
| 265 packet_events.begin(); |
| 266 it != packet_events.end(); |
| 267 ++it) { |
| 268 cast_environment_->Logging()->InsertPacketEvent(it->timestamp, |
| 269 it->type, |
| 270 it->rtp_timestamp, |
| 271 it->frame_id, |
| 272 it->packet_id, |
| 273 it->max_packet_id, |
| 274 it->size); |
| 275 } |
| 276 } |
OLD | NEW |