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" |
11 #include "chrome/renderer/media/cast_transport_sender_ipc.h" | 11 #include "chrome/renderer/media/cast_transport_sender_ipc.h" |
12 #include "content/public/renderer/render_thread.h" | 12 #include "content/public/renderer/render_thread.h" |
13 #include "media/cast/cast_config.h" | 13 #include "media/cast/cast_config.h" |
14 #include "media/cast/cast_environment.h" | 14 #include "media/cast/cast_environment.h" |
15 #include "media/cast/cast_sender.h" | 15 #include "media/cast/cast_sender.h" |
16 #include "media/cast/logging/encoding_event_subscriber.h" | 16 #include "media/cast/logging/encoding_event_subscriber.h" |
17 #include "media/cast/logging/log_serializer.h" | 17 #include "media/cast/logging/log_serializer.h" |
18 #include "media/cast/logging/logging_defines.h" | 18 #include "media/cast/logging/logging_defines.h" |
| 19 #include "media/cast/logging/receiver_time_offset_estimator_impl.h" |
19 #include "media/cast/logging/stats_event_subscriber.h" | 20 #include "media/cast/logging/stats_event_subscriber.h" |
20 #include "media/cast/logging/stats_util.h" | |
21 #include "media/cast/transport/cast_transport_config.h" | 21 #include "media/cast/transport/cast_transport_config.h" |
22 #include "media/cast/transport/cast_transport_sender.h" | 22 #include "media/cast/transport/cast_transport_sender.h" |
23 | 23 |
24 using media::cast::AudioSenderConfig; | 24 using media::cast::AudioSenderConfig; |
25 using media::cast::CastEnvironment; | 25 using media::cast::CastEnvironment; |
26 using media::cast::CastSender; | 26 using media::cast::CastSender; |
27 using media::cast::VideoSenderConfig; | 27 using media::cast::VideoSenderConfig; |
28 | 28 |
29 static base::LazyInstance<CastThreads> g_cast_threads = | 29 static base::LazyInstance<CastThreads> g_cast_threads = |
30 LAZY_INSTANCE_INITIALIZER; | 30 LAZY_INSTANCE_INITIALIZER; |
(...skipping 15 matching lines...) Expand all Loading... |
46 : io_message_loop_proxy_( | 46 : io_message_loop_proxy_( |
47 content::RenderThread::Get()->GetIOMessageLoopProxy()), | 47 content::RenderThread::Get()->GetIOMessageLoopProxy()), |
48 weak_factory_(this) { | 48 weak_factory_(this) { |
49 DCHECK(io_message_loop_proxy_); | 49 DCHECK(io_message_loop_proxy_); |
50 } | 50 } |
51 | 51 |
52 CastSessionDelegate::~CastSessionDelegate() { | 52 CastSessionDelegate::~CastSessionDelegate() { |
53 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 53 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
54 | 54 |
55 if (cast_environment_.get()) { | 55 if (cast_environment_.get()) { |
| 56 if (receiver_offset_estimator_.get()) { |
| 57 cast_environment_->Logging()->RemoveRawEventSubscriber( |
| 58 receiver_offset_estimator_.get()); |
| 59 } |
56 if (audio_event_subscriber_.get()) { | 60 if (audio_event_subscriber_.get()) { |
57 cast_environment_->Logging()->RemoveRawEventSubscriber( | 61 cast_environment_->Logging()->RemoveRawEventSubscriber( |
58 audio_event_subscriber_.get()); | 62 audio_event_subscriber_.get()); |
59 } | 63 } |
60 if (video_event_subscriber_.get()) { | 64 if (video_event_subscriber_.get()) { |
61 cast_environment_->Logging()->RemoveRawEventSubscriber( | 65 cast_environment_->Logging()->RemoveRawEventSubscriber( |
62 video_event_subscriber_.get()); | 66 video_event_subscriber_.get()); |
63 } | 67 } |
64 } | 68 } |
65 } | 69 } |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 | 143 |
140 cast_sender_ = CastSender::Create(cast_environment_, cast_transport_.get()); | 144 cast_sender_ = CastSender::Create(cast_environment_, cast_transport_.get()); |
141 cast_transport_->SetPacketReceiver(cast_sender_->packet_receiver()); | 145 cast_transport_->SetPacketReceiver(cast_sender_->packet_receiver()); |
142 } | 146 } |
143 | 147 |
144 void CastSessionDelegate::ToggleLogging(bool is_audio, bool enable) { | 148 void CastSessionDelegate::ToggleLogging(bool is_audio, bool enable) { |
145 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 149 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
146 if (!cast_environment_.get()) | 150 if (!cast_environment_.get()) |
147 return; | 151 return; |
148 if (enable) { | 152 if (enable) { |
| 153 if (!receiver_offset_estimator_.get()) { |
| 154 receiver_offset_estimator_.reset( |
| 155 new media::cast::ReceiverTimeOffsetEstimatorImpl); |
| 156 cast_environment_->Logging()->AddRawEventSubscriber( |
| 157 receiver_offset_estimator_.get()); |
| 158 } |
149 if (is_audio) { | 159 if (is_audio) { |
150 if (!audio_event_subscriber_.get()) { | 160 if (!audio_event_subscriber_.get()) { |
151 audio_event_subscriber_.reset(new media::cast::EncodingEventSubscriber( | 161 audio_event_subscriber_.reset(new media::cast::EncodingEventSubscriber( |
152 media::cast::AUDIO_EVENT, kMaxAudioEventEntries)); | 162 media::cast::AUDIO_EVENT, kMaxAudioEventEntries)); |
153 cast_environment_->Logging()->AddRawEventSubscriber( | 163 cast_environment_->Logging()->AddRawEventSubscriber( |
154 audio_event_subscriber_.get()); | 164 audio_event_subscriber_.get()); |
155 } | 165 } |
156 if (!audio_stats_subscriber_.get()) { | 166 if (!audio_stats_subscriber_.get()) { |
157 audio_stats_subscriber_.reset( | 167 audio_stats_subscriber_.reset(new media::cast::StatsEventSubscriber( |
158 new media::cast::StatsEventSubscriber(media::cast::AUDIO_EVENT)); | 168 media::cast::AUDIO_EVENT, |
| 169 cast_environment_->Clock(), |
| 170 receiver_offset_estimator_.get())); |
159 cast_environment_->Logging()->AddRawEventSubscriber( | 171 cast_environment_->Logging()->AddRawEventSubscriber( |
160 audio_stats_subscriber_.get()); | 172 audio_stats_subscriber_.get()); |
161 } | 173 } |
162 } else { | 174 } else { |
163 if (!video_event_subscriber_.get()) { | 175 if (!video_event_subscriber_.get()) { |
164 video_event_subscriber_.reset(new media::cast::EncodingEventSubscriber( | 176 video_event_subscriber_.reset(new media::cast::EncodingEventSubscriber( |
165 media::cast::VIDEO_EVENT, kMaxVideoEventEntries)); | 177 media::cast::VIDEO_EVENT, kMaxVideoEventEntries)); |
166 cast_environment_->Logging()->AddRawEventSubscriber( | 178 cast_environment_->Logging()->AddRawEventSubscriber( |
167 video_event_subscriber_.get()); | 179 video_event_subscriber_.get()); |
168 } | 180 } |
169 if (!video_stats_subscriber_.get()) { | 181 if (!video_stats_subscriber_.get()) { |
170 video_stats_subscriber_.reset( | 182 video_stats_subscriber_.reset(new media::cast::StatsEventSubscriber( |
171 new media::cast::StatsEventSubscriber(media::cast::VIDEO_EVENT)); | 183 media::cast::VIDEO_EVENT, |
| 184 cast_environment_->Clock(), |
| 185 receiver_offset_estimator_.get())); |
172 cast_environment_->Logging()->AddRawEventSubscriber( | 186 cast_environment_->Logging()->AddRawEventSubscriber( |
173 video_stats_subscriber_.get()); | 187 video_stats_subscriber_.get()); |
174 } | 188 } |
175 } | 189 } |
176 } else { | 190 } else { |
| 191 if (receiver_offset_estimator_.get()) { |
| 192 cast_environment_->Logging()->RemoveRawEventSubscriber( |
| 193 receiver_offset_estimator_.get()); |
| 194 receiver_offset_estimator_.reset(); |
| 195 } |
| 196 |
177 if (is_audio) { | 197 if (is_audio) { |
178 if (audio_event_subscriber_.get()) { | 198 if (audio_event_subscriber_.get()) { |
179 cast_environment_->Logging()->RemoveRawEventSubscriber( | 199 cast_environment_->Logging()->RemoveRawEventSubscriber( |
180 audio_event_subscriber_.get()); | 200 audio_event_subscriber_.get()); |
181 audio_event_subscriber_.reset(); | 201 audio_event_subscriber_.reset(); |
182 } | 202 } |
183 if (audio_stats_subscriber_.get()) { | 203 if (audio_stats_subscriber_.get()) { |
184 cast_environment_->Logging()->RemoveRawEventSubscriber( | 204 cast_environment_->Logging()->RemoveRawEventSubscriber( |
185 audio_stats_subscriber_.get()); | 205 audio_stats_subscriber_.get()); |
186 audio_stats_subscriber_.reset(); | 206 audio_stats_subscriber_.reset(); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 | 263 |
244 void CastSessionDelegate::GetStatsAndReset(bool is_audio, | 264 void CastSessionDelegate::GetStatsAndReset(bool is_audio, |
245 const StatsCallback& callback) { | 265 const StatsCallback& callback) { |
246 media::cast::StatsEventSubscriber* subscriber = | 266 media::cast::StatsEventSubscriber* subscriber = |
247 is_audio ? audio_stats_subscriber_.get() : video_stats_subscriber_.get(); | 267 is_audio ? audio_stats_subscriber_.get() : video_stats_subscriber_.get(); |
248 if (!subscriber) { | 268 if (!subscriber) { |
249 callback.Run(make_scoped_ptr(new base::DictionaryValue).Pass()); | 269 callback.Run(make_scoped_ptr(new base::DictionaryValue).Pass()); |
250 return; | 270 return; |
251 } | 271 } |
252 | 272 |
253 media::cast::FrameStatsMap frame_stats; | 273 scoped_ptr<base::DictionaryValue> stats = subscriber->GetStats(); |
254 subscriber->GetFrameStats(&frame_stats); | |
255 media::cast::PacketStatsMap packet_stats; | |
256 subscriber->GetPacketStats(&packet_stats); | |
257 subscriber->Reset(); | 274 subscriber->Reset(); |
258 | 275 |
259 scoped_ptr<base::DictionaryValue> stats = media::cast::ConvertStats( | |
260 frame_stats, packet_stats); | |
261 | |
262 callback.Run(stats.Pass()); | 276 callback.Run(stats.Pass()); |
263 } | 277 } |
264 | 278 |
265 void CastSessionDelegate::StatusNotificationCB( | 279 void CastSessionDelegate::StatusNotificationCB( |
266 media::cast::transport::CastTransportStatus unused_status) { | 280 media::cast::transport::CastTransportStatus unused_status) { |
267 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 281 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
268 // TODO(hubbe): Call javascript UDPTransport error function. | 282 // TODO(hubbe): Call javascript UDPTransport error function. |
269 } | 283 } |
270 | 284 |
271 void CastSessionDelegate::InitializationResultCB( | 285 void CastSessionDelegate::InitializationResultCB( |
(...skipping 20 matching lines...) Expand all Loading... |
292 ++it) { | 306 ++it) { |
293 cast_environment_->Logging()->InsertPacketEvent(it->timestamp, | 307 cast_environment_->Logging()->InsertPacketEvent(it->timestamp, |
294 it->type, | 308 it->type, |
295 it->rtp_timestamp, | 309 it->rtp_timestamp, |
296 it->frame_id, | 310 it->frame_id, |
297 it->packet_id, | 311 it->packet_id, |
298 it->max_packet_id, | 312 it->max_packet_id, |
299 it->size); | 313 it->size); |
300 } | 314 } |
301 } | 315 } |
OLD | NEW |