Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/media/media_internals.h" | 5 #include "content/browser/media/media_internals.h" |
| 6 | 6 |
| 7 #include "base/metrics/histogram.h" | |
| 7 #include "base/strings/string16.h" | 8 #include "base/strings/string16.h" |
| 8 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 9 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| 10 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
| 12 #include "content/public/browser/notification_observer.h" | |
| 13 #include "content/public/browser/notification_registrar.h" | |
| 14 #include "content/public/browser/notification_service.h" | |
| 15 #include "content/public/browser/notification_types.h" | |
| 16 #include "content/public/browser/render_process_host.h" | |
| 11 #include "content/public/browser/web_ui.h" | 17 #include "content/public/browser/web_ui.h" |
| 12 #include "media/audio/audio_parameters.h" | 18 #include "media/audio/audio_parameters.h" |
| 13 #include "media/base/media_log.h" | |
| 14 #include "media/base/media_log_event.h" | 19 #include "media/base/media_log_event.h" |
| 15 | 20 |
| 16 namespace { | 21 namespace { |
| 17 | 22 |
| 18 static base::LazyInstance<content::MediaInternals>::Leaky g_media_internals = | 23 static base::LazyInstance<content::MediaInternals>::Leaky g_media_internals = |
| 19 LAZY_INSTANCE_INITIALIZER; | 24 LAZY_INSTANCE_INITIALIZER; |
| 20 | 25 |
| 21 base::string16 SerializeUpdate(const std::string& function, | 26 base::string16 SerializeUpdate(const std::string& function, |
| 22 const base::Value* value) { | 27 const base::Value* value) { |
| 23 return content::WebUI::GetJavascriptCall( | 28 return content::WebUI::GetJavascriptCall( |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 163 FormatCacheKey(component_id), kAudioLogUpdateFunction, &dict); | 168 FormatCacheKey(component_id), kAudioLogUpdateFunction, &dict); |
| 164 } | 169 } |
| 165 | 170 |
| 166 void AudioLogImpl::StoreComponentMetadata(int component_id, | 171 void AudioLogImpl::StoreComponentMetadata(int component_id, |
| 167 base::DictionaryValue* dict) { | 172 base::DictionaryValue* dict) { |
| 168 dict->SetInteger("owner_id", owner_id_); | 173 dict->SetInteger("owner_id", owner_id_); |
| 169 dict->SetInteger("component_id", component_id); | 174 dict->SetInteger("component_id", component_id); |
| 170 dict->SetInteger("component_type", component_); | 175 dict->SetInteger("component_type", component_); |
| 171 } | 176 } |
| 172 | 177 |
| 178 class MediaInternals::MediaInternalsUMAHandler : public NotificationObserver { | |
| 179 public: | |
| 180 MediaInternalsUMAHandler(); | |
| 181 | |
| 182 // NotificationObserver implementation. | |
| 183 void Observe(int type, | |
| 184 const NotificationSource& source, | |
| 185 const NotificationDetails& details) override; | |
| 186 | |
| 187 // Reports the pipeline status to UMA for every player | |
| 188 // associated with the renderer process and then deletes the player state. | |
| 189 void LogAndClearPlayersInRenderer(int render_process_id); | |
| 190 | |
| 191 // Helper function to save the event payload to RendererPlayerMap. | |
| 192 void SavePlayerState(const media::MediaLogEvent& event, | |
| 193 int render_process_id); | |
| 194 | |
| 195 private: | |
| 196 NotificationRegistrar registrar_; | |
|
DaleCurtis
2014/11/12 22:29:25
Move down lower.
prabhur1
2014/11/12 23:26:33
ah..sorry about that!
| |
| 197 | |
| 198 struct PipelineInfo { | |
| 199 media::PipelineStatus last_pipeline_status; | |
| 200 bool has_audio; | |
| 201 bool has_video; | |
| 202 std::string audio_codec_name; | |
| 203 std::string video_codec_name; | |
| 204 std::string video_decoder; | |
| 205 PipelineInfo() | |
| 206 : last_pipeline_status(media::PIPELINE_OK), | |
| 207 has_audio(false), | |
| 208 has_video(false) {} | |
| 209 }; | |
| 210 | |
| 211 // Helper function to report PipelineStatus associated with a player to UMA. | |
| 212 void ReportUMAForPipelineStatus(const PipelineInfo& player_info); | |
| 213 | |
| 214 // Key is playerid | |
| 215 typedef std::map<int, PipelineInfo> PlayerInfoMap; | |
| 216 | |
| 217 // Key is renderer id | |
| 218 typedef std::map<int, PlayerInfoMap> RendererPlayerMap; | |
| 219 | |
| 220 // Stores player information per renderer | |
| 221 RendererPlayerMap renderer_info_; | |
| 222 | |
| 223 DISALLOW_COPY_AND_ASSIGN(MediaInternalsUMAHandler); | |
| 224 }; | |
| 225 | |
| 226 MediaInternals::MediaInternalsUMAHandler::MediaInternalsUMAHandler() { | |
| 227 registrar_.Add(this, NOTIFICATION_RENDERER_PROCESS_TERMINATED, | |
| 228 NotificationService::AllBrowserContextsAndSources()); | |
| 229 } | |
| 230 | |
| 231 void MediaInternals::MediaInternalsUMAHandler::Observe( | |
| 232 int type, | |
| 233 const NotificationSource& source, | |
| 234 const NotificationDetails& details) { | |
| 235 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 236 DCHECK_EQ(type, NOTIFICATION_RENDERER_PROCESS_TERMINATED); | |
| 237 RenderProcessHost* process = Source<RenderProcessHost>(source).ptr(); | |
| 238 LogAndClearPlayersInRenderer(process->GetID()); | |
| 239 } | |
| 240 | |
| 241 void MediaInternals::MediaInternalsUMAHandler::SavePlayerState( | |
| 242 const media::MediaLogEvent& event, | |
| 243 int render_process_id) { | |
| 244 PlayerInfoMap& player_info = renderer_info_[render_process_id]; | |
| 245 switch (event.type) { | |
| 246 case media::MediaLogEvent::WEBMEDIAPLAYER_CREATED: { | |
| 247 // Nothing to do here | |
| 248 break; | |
| 249 } | |
| 250 case media::MediaLogEvent::PIPELINE_ERROR: { | |
| 251 int status; | |
| 252 event.params.GetInteger("pipeline_error", &status); | |
| 253 player_info[event.id].last_pipeline_status = | |
| 254 static_cast<media::PipelineStatus>(status); | |
| 255 break; | |
| 256 } | |
| 257 case media::MediaLogEvent::PROPERTY_CHANGE: | |
| 258 if (event.params.HasKey("found_audio_stream")) { | |
| 259 event.params.GetBoolean("found_audio_stream", | |
| 260 &player_info[event.id].has_audio); | |
| 261 } | |
| 262 if (event.params.HasKey("found_video_stream")) { | |
| 263 event.params.GetBoolean("found_video_stream", | |
| 264 &player_info[event.id].has_video); | |
| 265 } | |
| 266 if (event.params.HasKey("audio_codec_name")) { | |
| 267 event.params.GetString("audio_codec_name", | |
| 268 &player_info[event.id].audio_codec_name); | |
| 269 } | |
| 270 if (event.params.HasKey("video_codec_name")) { | |
| 271 event.params.GetString("video_codec_name", | |
| 272 &player_info[event.id].video_codec_name); | |
| 273 } | |
| 274 if (event.params.HasKey("video_decoder")) { | |
| 275 event.params.GetString("video_decoder", | |
| 276 &player_info[event.id].video_decoder); | |
| 277 } | |
| 278 break; | |
| 279 default: | |
| 280 break; | |
| 281 } | |
| 282 return; | |
| 283 } | |
| 284 | |
| 285 void MediaInternals::MediaInternalsUMAHandler::ReportUMAForPipelineStatus( | |
| 286 const PipelineInfo& player_info) { | |
| 287 if (player_info.has_video && player_info.has_audio) { | |
| 288 if (player_info.video_codec_name == "vp8") { | |
| 289 UMA_HISTOGRAM_ENUMERATION("Media.PipelineStatus.AudioVideo.VP8", | |
| 290 player_info.last_pipeline_status, | |
| 291 media::PIPELINE_STATUS_MAX + 1); | |
| 292 } else if (player_info.video_codec_name == "vp9") { | |
| 293 UMA_HISTOGRAM_ENUMERATION("Media.PipelineStatus.AudioVideo.VP9", | |
| 294 player_info.last_pipeline_status, | |
| 295 media::PIPELINE_STATUS_MAX + 1); | |
| 296 } else if (player_info.video_codec_name == "h264") { | |
| 297 if (player_info.video_decoder == "gpu") { | |
| 298 UMA_HISTOGRAM_ENUMERATION("Media.PipelineStatus.AudioVideo.HW.H264", | |
| 299 player_info.last_pipeline_status, | |
| 300 media::PIPELINE_STATUS_MAX + 1); | |
| 301 } else { | |
| 302 UMA_HISTOGRAM_ENUMERATION("Media.PipelineStatus.AudioVideo.SW.H264", | |
| 303 player_info.last_pipeline_status, | |
| 304 media::PIPELINE_STATUS_MAX + 1); | |
| 305 } | |
| 306 } else { | |
| 307 UMA_HISTOGRAM_ENUMERATION("Media.PipelineStatus.AudioVideo", | |
| 308 player_info.last_pipeline_status, | |
| 309 media::PIPELINE_STATUS_MAX + 1); | |
| 310 } | |
| 311 } else if (player_info.has_audio) { | |
| 312 UMA_HISTOGRAM_ENUMERATION("Media.PipelineStatus.Audio", | |
| 313 player_info.last_pipeline_status, | |
| 314 media::PIPELINE_STATUS_MAX + 1); | |
| 315 } else if (player_info.has_video) { | |
| 316 UMA_HISTOGRAM_ENUMERATION("Media.PipelineStatus.Video", | |
| 317 player_info.last_pipeline_status, | |
| 318 media::PIPELINE_STATUS_MAX + 1); | |
| 319 } else { | |
| 320 UMA_HISTOGRAM_ENUMERATION("Media.PipelineStatus.Unsupported", | |
| 321 player_info.last_pipeline_status, | |
| 322 media::PIPELINE_STATUS_MAX + 1); | |
| 323 } | |
| 324 } | |
| 325 | |
| 326 void MediaInternals::MediaInternalsUMAHandler::LogAndClearPlayersInRenderer( | |
| 327 int render_process_id) { | |
| 328 auto players_it = renderer_info_.find(render_process_id); | |
| 329 if (players_it == renderer_info_.end()) | |
| 330 return; | |
| 331 auto it = players_it->second.begin(); | |
| 332 while (it != players_it->second.end()) { | |
| 333 ReportUMAForPipelineStatus(it->second); | |
| 334 players_it->second.erase(it++); | |
| 335 } | |
| 336 } | |
| 337 | |
| 173 MediaInternals* MediaInternals::GetInstance() { | 338 MediaInternals* MediaInternals::GetInstance() { |
| 174 return g_media_internals.Pointer(); | 339 return g_media_internals.Pointer(); |
| 175 } | 340 } |
| 176 | 341 |
| 177 MediaInternals::MediaInternals() : owner_ids_() {} | 342 MediaInternals::MediaInternals() |
| 343 : owner_ids_(), uma_handler_(new MediaInternalsUMAHandler()) { | |
| 344 } | |
| 345 | |
| 178 MediaInternals::~MediaInternals() {} | 346 MediaInternals::~MediaInternals() {} |
| 179 | 347 |
| 180 void MediaInternals::OnMediaEvents( | 348 void MediaInternals::OnMediaEvents( |
| 181 int render_process_id, const std::vector<media::MediaLogEvent>& events) { | 349 int render_process_id, const std::vector<media::MediaLogEvent>& events) { |
| 182 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 350 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 183 // Notify observers that |event| has occurred. | 351 // Notify observers that |event| has occurred. |
| 184 for (std::vector<media::MediaLogEvent>::const_iterator event = events.begin(); | 352 for (auto event = events.begin(); event != events.end(); ++event) { |
| 185 event != events.end(); ++event) { | |
| 186 base::DictionaryValue dict; | 353 base::DictionaryValue dict; |
| 187 dict.SetInteger("renderer", render_process_id); | 354 dict.SetInteger("renderer", render_process_id); |
| 188 dict.SetInteger("player", event->id); | 355 dict.SetInteger("player", event->id); |
| 189 dict.SetString("type", media::MediaLog::EventTypeToString(event->type)); | 356 dict.SetString("type", media::MediaLog::EventTypeToString(event->type)); |
| 190 | 357 |
| 191 // TODO(dalecurtis): This is technically not correct. TimeTicks "can't" be | 358 // TODO(dalecurtis): This is technically not correct. TimeTicks "can't" be |
| 192 // converted to to a human readable time format. See base/time/time.h. | 359 // converted to to a human readable time format. See base/time/time.h. |
| 193 const double ticks = event->time.ToInternalValue(); | 360 const double ticks = event->time.ToInternalValue(); |
| 194 const double ticks_millis = ticks / base::Time::kMicrosecondsPerMillisecond; | 361 const double ticks_millis = ticks / base::Time::kMicrosecondsPerMillisecond; |
| 195 dict.SetDouble("ticksMillis", ticks_millis); | 362 dict.SetDouble("ticksMillis", ticks_millis); |
| 196 dict.Set("params", event->params.DeepCopy()); | 363 |
| 364 // Convert PipelineStatus to human readable string | |
| 365 if (event->type == media::MediaLogEvent::PIPELINE_ERROR) { | |
| 366 int status; | |
| 367 event->params.GetInteger("pipeline_error", &status); | |
| 368 media::PipelineStatus error = static_cast<media::PipelineStatus>(status); | |
| 369 base::DictionaryValue error_status; | |
| 370 error_status.SetString("pipeline_error", | |
| 371 media::MediaLog::PipelineStatusToString(error)); | |
| 372 dict.Set("params", error_status.DeepCopy()); | |
|
DaleCurtis
2014/11/12 22:29:25
Does setting params.pipeline_error to the right st
prabhur1
2014/11/12 23:26:33
Done.
prabhur1
2014/11/12 23:26:33
Yes, that works.
| |
| 373 } else { | |
| 374 dict.Set("params", event->params.DeepCopy()); | |
| 375 } | |
| 376 | |
| 197 SendUpdate(SerializeUpdate("media.onMediaEvent", &dict)); | 377 SendUpdate(SerializeUpdate("media.onMediaEvent", &dict)); |
| 378 uma_handler_->SavePlayerState(*event, render_process_id); | |
| 198 } | 379 } |
| 199 } | 380 } |
| 200 | 381 |
| 201 void MediaInternals::AddUpdateCallback(const UpdateCallback& callback) { | 382 void MediaInternals::AddUpdateCallback(const UpdateCallback& callback) { |
| 202 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 383 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 203 update_callbacks_.push_back(callback); | 384 update_callbacks_.push_back(callback); |
| 204 } | 385 } |
| 205 | 386 |
| 206 void MediaInternals::RemoveUpdateCallback(const UpdateCallback& callback) { | 387 void MediaInternals::RemoveUpdateCallback(const UpdateCallback& callback) { |
| 207 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 388 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 300 const std::string& function, | 481 const std::string& function, |
| 301 const base::DictionaryValue* value) { | 482 const base::DictionaryValue* value) { |
| 302 SendUpdate(SerializeUpdate(function, value)); | 483 SendUpdate(SerializeUpdate(function, value)); |
| 303 | 484 |
| 304 base::AutoLock auto_lock(lock_); | 485 base::AutoLock auto_lock(lock_); |
| 305 scoped_ptr<base::Value> out_value; | 486 scoped_ptr<base::Value> out_value; |
| 306 CHECK(audio_streams_cached_data_.Remove(cache_key, &out_value)); | 487 CHECK(audio_streams_cached_data_.Remove(cache_key, &out_value)); |
| 307 } | 488 } |
| 308 | 489 |
| 309 } // namespace content | 490 } // namespace content |
| OLD | NEW |