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 // NotificationObserver implementation. | |
| 181 void Observe(int type, | |
| 182 const NotificationSource& source, | |
| 183 const NotificationDetails& details) override; | |
| 184 void LogAndClearPlayersInRenderer(int render_process_id); | |
| 185 | |
| 186 void SavePlayerState(const media::MediaLogEvent& event, | |
| 187 int render_process_id); | |
| 188 MediaInternalsUMAHandler(); | |
|
DaleCurtis
2014/11/11 19:24:01
nit: constructor is usually first.
prabhur1
2014/11/12 21:32:37
Done.
| |
| 189 | |
| 190 private: | |
| 191 NotificationRegistrar registrar_; | |
| 192 | |
| 193 struct PipelineInfo { | |
| 194 media::PipelineStatus last_pipeline_status; | |
| 195 bool has_audio; | |
| 196 bool has_video; | |
| 197 std::string audio_codec_name; | |
| 198 std::string video_codec_name; | |
| 199 std::string video_decoder; | |
| 200 PipelineInfo(): last_pipeline_status(media::PIPELINE_OK), | |
| 201 has_audio(false), | |
| 202 has_video(false) {} | |
| 203 }; | |
| 204 | |
| 205 // Key is playerid | |
| 206 typedef std::map<int, PipelineInfo> PlayerInfoMap; | |
| 207 | |
| 208 // Key is renderer id | |
| 209 typedef std::map<int, PlayerInfoMap> RendererPlayerMap; | |
| 210 | |
| 211 // Stores player information per renderer | |
| 212 RendererPlayerMap renderer_info; | |
|
DaleCurtis
2014/11/11 19:24:01
Member variables should end in an underscore.
prabhur1
2014/11/12 21:32:37
Done.
| |
| 213 | |
| 214 void ReportUMAForPipelineStatus(const PipelineInfo& player_info); | |
| 215 }; | |
|
DaleCurtis
2014/11/11 19:24:01
Add DISALLOW_COPY_AND_ASSIGN(...);
prabhur1
2014/11/12 21:32:37
Done.
| |
| 216 | |
| 217 MediaInternals::MediaInternalsUMAHandler::MediaInternalsUMAHandler() { | |
| 218 registrar_.Add(this, | |
| 219 NOTIFICATION_RENDERER_PROCESS_TERMINATED, | |
| 220 NotificationService::AllBrowserContextsAndSources()); | |
| 221 } | |
| 222 | |
| 223 void MediaInternals::MediaInternalsUMAHandler::Observe(int type, | |
| 224 const NotificationSource& source, | |
| 225 const NotificationDetails& details) { | |
| 226 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 227 DCHECK_EQ(type, NOTIFICATION_RENDERER_PROCESS_TERMINATED); | |
| 228 RenderProcessHost* process = Source<RenderProcessHost>(source).ptr(); | |
| 229 LogAndClearPlayersInRenderer(process->GetID()); | |
| 230 } | |
| 231 | |
| 232 void MediaInternals::MediaInternalsUMAHandler::SavePlayerState( | |
| 233 const media::MediaLogEvent& event, int render_process_id) { | |
| 234 PlayerInfoMap& player_info = renderer_info[render_process_id]; | |
| 235 switch (event.type) { | |
| 236 case media::MediaLogEvent::WEBMEDIAPLAYER_CREATED: { | |
| 237 // Nothing to do here | |
| 238 break; | |
| 239 } | |
| 240 case media::MediaLogEvent::PIPELINE_ERROR: { | |
| 241 std::string status; | |
| 242 event.params.GetString("pipeline_error", &status); | |
| 243 media::MediaLog::StringToPipelineStatus( | |
| 244 status, player_info[event.id].last_pipeline_status); | |
| 245 break; | |
| 246 } | |
| 247 case media::MediaLogEvent::PROPERTY_CHANGE: | |
| 248 if (event.params.HasKey("found_audio_stream")) { | |
| 249 event.params.GetBoolean("found_audio_stream", | |
| 250 &player_info[event.id].has_audio); | |
| 251 } | |
| 252 if (event.params.HasKey("found_video_stream")) { | |
| 253 event.params.GetBoolean("found_video_stream", | |
| 254 &player_info[event.id].has_video); | |
| 255 } | |
| 256 if (event.params.HasKey("audio_codec_name")) { | |
| 257 event.params.GetString("audio_codec_name", | |
| 258 &player_info[event.id].audio_codec_name); | |
| 259 } | |
| 260 if (event.params.HasKey("video_codec_name")) { | |
| 261 event.params.GetString("video_codec_name", | |
| 262 &player_info[event.id].video_codec_name); | |
| 263 } | |
| 264 if (event.params.HasKey("video_decoder")) { | |
| 265 event.params.GetString("video_decoder", | |
| 266 &player_info[event.id].video_decoder); | |
| 267 } | |
| 268 break; | |
| 269 default: | |
| 270 break; | |
| 271 } | |
| 272 return; | |
| 273 } | |
| 274 | |
| 275 void MediaInternals::MediaInternalsUMAHandler::ReportUMAForPipelineStatus( | |
|
DaleCurtis
2014/11/11 19:24:01
Did git cl format produce this formatting? It seem
prabhur1
2014/11/12 21:32:37
Done.
| |
| 276 const PipelineInfo& player_info) { | |
| 277 if (player_info.has_video && player_info.has_audio) { | |
| 278 if (player_info.video_codec_name == "vp8") { | |
| 279 UMA_HISTOGRAM_ENUMERATION("Media.PipelineStatus.AudioVideo.VP8", | |
| 280 player_info.last_pipeline_status, | |
| 281 media::PIPELINE_STATUS_MAX + 1); | |
| 282 } else if (player_info.video_codec_name == "vp9") { | |
| 283 UMA_HISTOGRAM_ENUMERATION("Media.PipelineStatus.AudioVideo.VP9", | |
| 284 player_info.last_pipeline_status, | |
| 285 media::PIPELINE_STATUS_MAX + 1); | |
| 286 } else if (player_info.video_codec_name == "h264") { | |
| 287 if (player_info.video_decoder == "gpu") { | |
| 288 UMA_HISTOGRAM_ENUMERATION("Media.PipelineStatus.AudioVideo.HW.H264", | |
| 289 player_info.last_pipeline_status, | |
| 290 media::PIPELINE_STATUS_MAX + 1); | |
| 291 } | |
| 292 else { | |
| 293 UMA_HISTOGRAM_ENUMERATION("Media.PipelineStatus.AudioVideo.SW.H264", | |
| 294 player_info.last_pipeline_status, | |
| 295 media::PIPELINE_STATUS_MAX + 1); | |
| 296 } | |
| 297 } else { | |
| 298 UMA_HISTOGRAM_ENUMERATION("Media.PipelineStatus.AudioVideo", | |
| 299 player_info.last_pipeline_status, | |
| 300 media::PIPELINE_STATUS_MAX + 1); | |
| 301 } | |
| 302 } else if (player_info.has_audio) { | |
| 303 UMA_HISTOGRAM_ENUMERATION("Media.PipelineStatus.Audio", | |
| 304 player_info.last_pipeline_status, | |
| 305 media::PIPELINE_STATUS_MAX + 1); | |
| 306 } else if (player_info.has_video) { | |
| 307 UMA_HISTOGRAM_ENUMERATION("Media.PipelineStatus.Video", | |
| 308 player_info.last_pipeline_status, | |
| 309 media::PIPELINE_STATUS_MAX + 1); | |
| 310 } else { | |
| 311 UMA_HISTOGRAM_ENUMERATION("Media.PipelineStatus.Unsupported", | |
| 312 player_info.last_pipeline_status, | |
| 313 media::PIPELINE_STATUS_MAX + 1); | |
| 314 } | |
| 315 } | |
| 316 | |
| 317 void MediaInternals::MediaInternalsUMAHandler::LogAndClearPlayersInRenderer( | |
| 318 int render_process_id) { | |
| 319 auto players_it = renderer_info.find(render_process_id); | |
| 320 if (players_it == renderer_info.end()) | |
| 321 return; | |
| 322 auto it = players_it->second.begin(); | |
| 323 while (it != players_it->second.end()) { | |
|
DaleCurtis
2014/11/11 19:24:01
Note: You're modifying the structure you're iterat
prabhur1
2014/11/12 21:32:37
Acknowledged.
prabhur1
2014/11/12 21:32:37
Yep. it++ takes care of advancing the iterator bef
| |
| 324 ReportUMAForPipelineStatus(it->second); | |
| 325 players_it->second.erase(it++); | |
| 326 } | |
| 327 } | |
| 328 | |
| 173 MediaInternals* MediaInternals::GetInstance() { | 329 MediaInternals* MediaInternals::GetInstance() { |
| 174 return g_media_internals.Pointer(); | 330 return g_media_internals.Pointer(); |
| 175 } | 331 } |
| 176 | 332 |
| 177 MediaInternals::MediaInternals() : owner_ids_() {} | 333 MediaInternals::MediaInternals() : owner_ids_() { |
| 334 uma_handler.reset(new MediaInternalsUMAHandler()); | |
|
DaleCurtis
2014/11/11 19:24:01
Do this during the constructor variable initializa
prabhur1
2014/11/12 21:32:37
Done.
| |
| 335 } | |
| 336 | |
| 178 MediaInternals::~MediaInternals() {} | 337 MediaInternals::~MediaInternals() {} |
| 179 | 338 |
| 180 void MediaInternals::OnMediaEvents( | 339 void MediaInternals::OnMediaEvents( |
| 181 int render_process_id, const std::vector<media::MediaLogEvent>& events) { | 340 int render_process_id, const std::vector<media::MediaLogEvent>& events) { |
| 182 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 341 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 183 // Notify observers that |event| has occurred. | 342 // Notify observers that |event| has occurred. |
| 184 for (std::vector<media::MediaLogEvent>::const_iterator event = events.begin(); | 343 for (std::vector<media::MediaLogEvent>::const_iterator event = events.begin(); |
|
DaleCurtis
2014/11/11 19:24:01
This is a prime candidate for conversion to "auto"
prabhur1
2014/11/12 21:32:37
Done.
| |
| 185 event != events.end(); ++event) { | 344 event != events.end(); ++event) { |
| 186 base::DictionaryValue dict; | 345 base::DictionaryValue dict; |
| 187 dict.SetInteger("renderer", render_process_id); | 346 dict.SetInteger("renderer", render_process_id); |
| 188 dict.SetInteger("player", event->id); | 347 dict.SetInteger("player", event->id); |
| 189 dict.SetString("type", media::MediaLog::EventTypeToString(event->type)); | 348 dict.SetString("type", media::MediaLog::EventTypeToString(event->type)); |
| 190 | 349 |
| 191 // TODO(dalecurtis): This is technically not correct. TimeTicks "can't" be | 350 // 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. | 351 // converted to to a human readable time format. See base/time/time.h. |
| 193 const double ticks = event->time.ToInternalValue(); | 352 const double ticks = event->time.ToInternalValue(); |
| 194 const double ticks_millis = ticks / base::Time::kMicrosecondsPerMillisecond; | 353 const double ticks_millis = ticks / base::Time::kMicrosecondsPerMillisecond; |
| 195 dict.SetDouble("ticksMillis", ticks_millis); | 354 dict.SetDouble("ticksMillis", ticks_millis); |
| 196 dict.Set("params", event->params.DeepCopy()); | 355 dict.Set("params", event->params.DeepCopy()); |
| 197 SendUpdate(SerializeUpdate("media.onMediaEvent", &dict)); | 356 SendUpdate(SerializeUpdate("media.onMediaEvent", &dict)); |
| 357 uma_handler->SavePlayerState(*event, render_process_id); | |
| 198 } | 358 } |
| 199 } | 359 } |
| 200 | 360 |
| 201 void MediaInternals::AddUpdateCallback(const UpdateCallback& callback) { | 361 void MediaInternals::AddUpdateCallback(const UpdateCallback& callback) { |
| 202 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 362 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 203 update_callbacks_.push_back(callback); | 363 update_callbacks_.push_back(callback); |
| 204 } | 364 } |
| 205 | 365 |
| 206 void MediaInternals::RemoveUpdateCallback(const UpdateCallback& callback) { | 366 void MediaInternals::RemoveUpdateCallback(const UpdateCallback& callback) { |
| 207 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 367 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 300 const std::string& function, | 460 const std::string& function, |
| 301 const base::DictionaryValue* value) { | 461 const base::DictionaryValue* value) { |
| 302 SendUpdate(SerializeUpdate(function, value)); | 462 SendUpdate(SerializeUpdate(function, value)); |
| 303 | 463 |
| 304 base::AutoLock auto_lock(lock_); | 464 base::AutoLock auto_lock(lock_); |
| 305 scoped_ptr<base::Value> out_value; | 465 scoped_ptr<base::Value> out_value; |
| 306 CHECK(audio_streams_cached_data_.Remove(cache_key, &out_value)); | 466 CHECK(audio_streams_cached_data_.Remove(cache_key, &out_value)); |
| 307 } | 467 } |
| 308 | 468 |
| 309 } // namespace content | 469 } // namespace content |
| OLD | NEW |