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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 if (audio_event_subscriber_.get()) { | 52 if (audio_event_subscriber_.get()) { |
53 cast_environment_->Logging()->RemoveRawEventSubscriber( | 53 cast_environment_->Logging()->RemoveRawEventSubscriber( |
54 audio_event_subscriber_.get()); | 54 audio_event_subscriber_.get()); |
55 } | 55 } |
56 if (video_event_subscriber_.get()) { | 56 if (video_event_subscriber_.get()) { |
57 cast_environment_->Logging()->RemoveRawEventSubscriber( | 57 cast_environment_->Logging()->RemoveRawEventSubscriber( |
58 video_event_subscriber_.get()); | 58 video_event_subscriber_.get()); |
59 } | 59 } |
60 } | 60 } |
61 | 61 |
62 void CastSessionDelegate::Initialize() { | 62 void CastSessionDelegate::Initialize( |
| 63 const media::cast::CastLoggingConfig& logging_config) { |
63 if (cast_environment_) | 64 if (cast_environment_) |
64 return; // Already initialized. | 65 return; // Already initialized. |
65 | 66 |
66 // CastSender uses the renderer's IO thread as the main thread. This reduces | 67 // CastSender uses the renderer's IO thread as the main thread. This reduces |
67 // thread hopping for incoming video frames and outgoing network packets. | 68 // thread hopping for incoming video frames and outgoing network packets. |
68 // There's no need to decode so no thread assigned for decoding. | 69 // There's no need to decode so no thread assigned for decoding. |
69 // Get default logging: All disabled. | 70 // Get default logging: All disabled. |
70 cast_environment_ = new CastEnvironment( | 71 cast_environment_ = new CastEnvironment( |
71 scoped_ptr<base::TickClock>(new base::DefaultTickClock()).Pass(), | 72 scoped_ptr<base::TickClock>(new base::DefaultTickClock()).Pass(), |
72 base::MessageLoopProxy::current(), | 73 base::MessageLoopProxy::current(), |
73 g_cast_threads.Get().GetAudioEncodeMessageLoopProxy(), | 74 g_cast_threads.Get().GetAudioEncodeMessageLoopProxy(), |
74 NULL, | 75 NULL, |
75 g_cast_threads.Get().GetVideoEncodeMessageLoopProxy(), | 76 g_cast_threads.Get().GetVideoEncodeMessageLoopProxy(), |
76 NULL, | 77 NULL, |
77 base::MessageLoopProxy::current(), | 78 base::MessageLoopProxy::current(), |
78 media::cast::GetDefaultCastSenderLoggingConfig()); | 79 logging_config); |
79 } | 80 } |
80 | 81 |
81 void CastSessionDelegate::StartAudio( | 82 void CastSessionDelegate::StartAudio( |
82 const AudioSenderConfig& config, | 83 const AudioSenderConfig& config, |
83 const FrameInputAvailableCallback& callback) { | 84 const FrameInputAvailableCallback& callback) { |
84 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 85 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
85 | 86 |
86 audio_config_.reset(new AudioSenderConfig(config)); | 87 audio_config_.reset(new AudioSenderConfig(config)); |
87 video_frame_input_available_callback_ = callback; | 88 video_frame_input_available_callback_ = callback; |
88 StartSendingInternal(); | 89 StartSendingInternal(); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 129 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
129 | 130 |
130 // No transport, wait. | 131 // No transport, wait. |
131 if (!transport_configured_) | 132 if (!transport_configured_) |
132 return; | 133 return; |
133 | 134 |
134 // No audio or video, wait. | 135 // No audio or video, wait. |
135 if (!audio_config_ && !video_config_) | 136 if (!audio_config_ && !video_config_) |
136 return; | 137 return; |
137 | 138 |
138 Initialize(); | 139 // TODO(imcheng): Enable raw event and stats collection. |
| 140 media::cast::CastLoggingConfig logging_config = |
| 141 media::cast::GetDefaultCastSenderLoggingConfig(); |
139 | 142 |
140 media::cast::transport::CastTransportConfig config; | 143 Initialize(logging_config); |
141 | 144 |
142 // TODO(hubbe): set config.aes_key and config.aes_iv_mask. | 145 media::cast::transport::CastTransportConfig transport_config; |
143 config.local_endpoint = local_endpoint_; | 146 transport_config.enable_raw_event_logging = |
144 config.receiver_endpoint = remote_endpoint_; | 147 logging_config.enable_raw_data_collection; |
| 148 |
| 149 // TODO(hubbe): set transport_config.aes_key and transport_config.aes_iv_mask. |
| 150 transport_config.local_endpoint = local_endpoint_; |
| 151 transport_config.receiver_endpoint = remote_endpoint_; |
145 if (audio_config_) { | 152 if (audio_config_) { |
146 config.audio_ssrc = audio_config_->sender_ssrc; | 153 transport_config.audio_ssrc = audio_config_->sender_ssrc; |
147 config.audio_codec = audio_config_->codec; | 154 transport_config.audio_codec = audio_config_->codec; |
148 config.audio_rtp_config = audio_config_->rtp_config; | 155 transport_config.audio_rtp_config = audio_config_->rtp_config; |
149 config.audio_frequency = audio_config_->frequency; | 156 transport_config.audio_frequency = audio_config_->frequency; |
150 config.audio_channels = audio_config_->channels; | 157 transport_config.audio_channels = audio_config_->channels; |
151 | 158 |
152 if (!audio_event_subscriber_.get()) { | 159 if (!audio_event_subscriber_.get()) { |
153 audio_event_subscriber_.reset(new media::cast::EncodingEventSubscriber( | 160 audio_event_subscriber_.reset(new media::cast::EncodingEventSubscriber( |
154 media::cast::AUDIO_EVENT, kMaxAudioEventEntries)); | 161 media::cast::AUDIO_EVENT, kMaxAudioEventEntries)); |
155 cast_environment_->Logging()->AddRawEventSubscriber( | 162 cast_environment_->Logging()->AddRawEventSubscriber( |
156 audio_event_subscriber_.get()); | 163 audio_event_subscriber_.get()); |
157 } | 164 } |
158 } | 165 } |
159 if (video_config_) { | 166 if (video_config_) { |
160 config.video_ssrc = video_config_->sender_ssrc; | 167 transport_config.video_ssrc = video_config_->sender_ssrc; |
161 config.video_codec = video_config_->codec; | 168 transport_config.video_codec = video_config_->codec; |
162 config.video_rtp_config = video_config_->rtp_config; | 169 transport_config.video_rtp_config = video_config_->rtp_config; |
163 | 170 |
164 if (!video_event_subscriber_.get()) { | 171 if (!video_event_subscriber_.get()) { |
165 video_event_subscriber_.reset(new media::cast::EncodingEventSubscriber( | 172 video_event_subscriber_.reset(new media::cast::EncodingEventSubscriber( |
166 media::cast::VIDEO_EVENT, kMaxVideoEventEntries)); | 173 media::cast::VIDEO_EVENT, kMaxVideoEventEntries)); |
167 cast_environment_->Logging()->AddRawEventSubscriber( | 174 cast_environment_->Logging()->AddRawEventSubscriber( |
168 video_event_subscriber_.get()); | 175 video_event_subscriber_.get()); |
169 } | 176 } |
170 } | 177 } |
171 | 178 |
172 cast_transport_.reset(new CastTransportSenderIPC( | 179 cast_transport_.reset(new CastTransportSenderIPC( |
173 config, | 180 transport_config, |
174 base::Bind(&CastSessionDelegate::StatusNotificationCB, | 181 base::Bind(&CastSessionDelegate::StatusNotificationCB, |
175 base::Unretained(this)))); | 182 base::Unretained(this)), |
| 183 base::Bind(&CastSessionDelegate::LogRawEvents, base::Unretained(this)))); |
176 | 184 |
177 cast_sender_.reset(CastSender::CreateCastSender( | 185 cast_sender_.reset(CastSender::CreateCastSender( |
178 cast_environment_, | 186 cast_environment_, |
179 audio_config_.get(), | 187 audio_config_.get(), |
180 video_config_.get(), | 188 video_config_.get(), |
181 NULL, // GPU. | 189 NULL, // GPU. |
182 base::Bind(&CastSessionDelegate::InitializationResult, | 190 base::Bind(&CastSessionDelegate::InitializationResult, |
183 base::Unretained(this)), | 191 base::Unretained(this)), |
184 cast_transport_.get())); | 192 cast_transport_.get())); |
185 cast_transport_->SetPacketReceiver(cast_sender_->packet_receiver()); | 193 cast_transport_->SetPacketReceiver(cast_sender_->packet_receiver()); |
186 } | 194 } |
187 | 195 |
188 void CastSessionDelegate::InitializationResult( | 196 void CastSessionDelegate::InitializationResult( |
189 media::cast::CastInitializationStatus result) const { | 197 media::cast::CastInitializationStatus result) const { |
190 DCHECK(cast_sender_); | 198 DCHECK(cast_sender_); |
191 | 199 |
192 // TODO(pwestin): handle the error codes. | 200 // TODO(pwestin): handle the error codes. |
193 if (result == media::cast::STATUS_INITIALIZED) { | 201 if (result == media::cast::STATUS_INITIALIZED) { |
194 if (!audio_frame_input_available_callback_.is_null()) { | 202 if (!audio_frame_input_available_callback_.is_null()) { |
195 audio_frame_input_available_callback_.Run(cast_sender_->frame_input()); | 203 audio_frame_input_available_callback_.Run(cast_sender_->frame_input()); |
196 } | 204 } |
197 if (!video_frame_input_available_callback_.is_null()) { | 205 if (!video_frame_input_available_callback_.is_null()) { |
198 video_frame_input_available_callback_.Run(cast_sender_->frame_input()); | 206 video_frame_input_available_callback_.Run(cast_sender_->frame_input()); |
199 } | 207 } |
200 } | 208 } |
201 } | 209 } |
| 210 |
| 211 void CastSessionDelegate::LogRawEvents( |
| 212 const std::vector<media::cast::PacketEvent>& packet_events) { |
| 213 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
| 214 |
| 215 for (std::vector<media::cast::PacketEvent>::const_iterator it = |
| 216 packet_events.begin(); |
| 217 it != packet_events.end(); |
| 218 ++it) { |
| 219 cast_environment_->Logging()->InsertPacketEvent(it->timestamp, |
| 220 it->type, |
| 221 it->rtp_timestamp, |
| 222 it->frame_id, |
| 223 it->packet_id, |
| 224 it->max_packet_id, |
| 225 it->size); |
| 226 } |
| 227 } |
OLD | NEW |