Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(39)

Side by Side Diff: content/browser/media/media_internals.cc

Issue 2517313002: Merge M56: "Add audio only watch time metrics." (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | media/base/media_log.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 double in_seconds; 328 double in_seconds;
329 const bool result = 329 const bool result =
330 event.params.GetDoubleWithoutPathExpansion(key, &in_seconds); 330 event.params.GetDoubleWithoutPathExpansion(key, &in_seconds);
331 DCHECK(result); 331 DCHECK(result);
332 *watch_time = base::TimeDelta::FromSecondsD(in_seconds); 332 *watch_time = base::TimeDelta::FromSecondsD(in_seconds);
333 333
334 DVLOG(2) << "Saved watch time for " << key << " of " << *watch_time; 334 DVLOG(2) << "Saved watch time for " << key << " of " << *watch_time;
335 } 335 }
336 336
337 enum class FinalizeType { EVERYTHING, POWER_ONLY }; 337 enum class FinalizeType { EVERYTHING, POWER_ONLY };
338 void FinalizeWatchTime(WatchTimeInfo* watch_time_info, 338 void FinalizeWatchTime(bool has_video,
339 WatchTimeInfo* watch_time_info,
339 FinalizeType finalize_type) { 340 FinalizeType finalize_type) {
340 // Use a macro instead of a function so we can use the histogram macro (which 341 // Use a macro instead of a function so we can use the histogram macro (which
341 // checks that the uma name is a static value). We use a custom time range for 342 // checks that the uma name is a static value). We use a custom time range for
342 // the histogram macro to capitalize on common expected watch times. 343 // the histogram macro to capitalize on common expected watch times.
343 #define MAYBE_RECORD_WATCH_TIME(uma_name, watch_time) \ 344 #define MAYBE_RECORD_WATCH_TIME(uma_name, watch_time) \
344 if (watch_time_info->watch_time != media::kNoTimestamp) { \ 345 if (watch_time_info->watch_time != media::kNoTimestamp) { \
345 UMA_HISTOGRAM_CUSTOM_TIMES( \ 346 UMA_HISTOGRAM_CUSTOM_TIMES( \
346 media::MediaLog::uma_name, watch_time_info->watch_time, \ 347 media::MediaLog::uma_name, watch_time_info->watch_time, \
347 base::TimeDelta::FromSeconds(7), base::TimeDelta::FromHours(10), 50); \ 348 base::TimeDelta::FromSeconds(7), base::TimeDelta::FromHours(10), 50); \
348 watch_time_info->watch_time = media::kNoTimestamp; \ 349 watch_time_info->watch_time = media::kNoTimestamp; \
349 } 350 }
350 351
351 if (finalize_type == FinalizeType::EVERYTHING) { 352 if (has_video) {
352 MAYBE_RECORD_WATCH_TIME(kWatchTimeAudioVideoAll, all_watch_time); 353 if (finalize_type == FinalizeType::EVERYTHING) {
353 MAYBE_RECORD_WATCH_TIME(kWatchTimeAudioVideoMse, mse_watch_time); 354 MAYBE_RECORD_WATCH_TIME(kWatchTimeAudioVideoAll, all_watch_time);
354 MAYBE_RECORD_WATCH_TIME(kWatchTimeAudioVideoEme, eme_watch_time); 355 MAYBE_RECORD_WATCH_TIME(kWatchTimeAudioVideoMse, mse_watch_time);
355 MAYBE_RECORD_WATCH_TIME(kWatchTimeAudioVideoSrc, src_watch_time); 356 MAYBE_RECORD_WATCH_TIME(kWatchTimeAudioVideoEme, eme_watch_time);
357 MAYBE_RECORD_WATCH_TIME(kWatchTimeAudioVideoSrc, src_watch_time);
358 } else {
359 DCHECK_EQ(finalize_type, FinalizeType::POWER_ONLY);
360 }
361 MAYBE_RECORD_WATCH_TIME(kWatchTimeAudioVideoBattery, battery_watch_time);
362 MAYBE_RECORD_WATCH_TIME(kWatchTimeAudioVideoAc, ac_watch_time);
356 } else { 363 } else {
357 DCHECK_EQ(finalize_type, FinalizeType::POWER_ONLY); 364 if (finalize_type == FinalizeType::EVERYTHING) {
365 MAYBE_RECORD_WATCH_TIME(kWatchTimeAudioAll, all_watch_time);
366 MAYBE_RECORD_WATCH_TIME(kWatchTimeAudioMse, mse_watch_time);
367 MAYBE_RECORD_WATCH_TIME(kWatchTimeAudioEme, eme_watch_time);
368 MAYBE_RECORD_WATCH_TIME(kWatchTimeAudioSrc, src_watch_time);
369 } else {
370 DCHECK_EQ(finalize_type, FinalizeType::POWER_ONLY);
371 }
372 MAYBE_RECORD_WATCH_TIME(kWatchTimeAudioBattery, battery_watch_time);
373 MAYBE_RECORD_WATCH_TIME(kWatchTimeAudioAc, ac_watch_time);
358 } 374 }
359 MAYBE_RECORD_WATCH_TIME(kWatchTimeAudioVideoBattery, battery_watch_time);
360 MAYBE_RECORD_WATCH_TIME(kWatchTimeAudioVideoAc, ac_watch_time);
361 #undef MAYBE_RECORD_WATCH_TIME 375 #undef MAYBE_RECORD_WATCH_TIME
362 } 376 }
363 377
364 // Key is player id. 378 // Key is player id.
365 typedef std::map<int, PipelineInfo> PlayerInfoMap; 379 typedef std::map<int, PipelineInfo> PlayerInfoMap;
366 380
367 // Key is renderer id. 381 // Key is renderer id.
368 typedef std::map<int, PlayerInfoMap> RendererPlayerMap; 382 typedef std::map<int, PlayerInfoMap> RendererPlayerMap;
369 383
370 // Stores player information per renderer. 384 // Stores player information per renderer.
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 previous_video_decoder != player_info[event.id].video_decoder) { 432 previous_video_decoder != player_info[event.id].video_decoder) {
419 player_info[event.id].video_decoder_changed = true; 433 player_info[event.id].video_decoder_changed = true;
420 } 434 }
421 } 435 }
422 if (event.params.HasKey("video_dds")) { 436 if (event.params.HasKey("video_dds")) {
423 event.params.GetBoolean("video_dds", &player_info[event.id].video_dds); 437 event.params.GetBoolean("video_dds", &player_info[event.id].video_dds);
424 } 438 }
425 break; 439 break;
426 case media::MediaLogEvent::Type::WATCH_TIME_UPDATE: { 440 case media::MediaLogEvent::Type::WATCH_TIME_UPDATE: {
427 DVLOG(2) << "Processing watch time update."; 441 DVLOG(2) << "Processing watch time update.";
428 WatchTimeInfo& wti = player_info[event.id].watch_time_info; 442 PipelineInfo& info = player_info[event.id];
443 WatchTimeInfo& wti = info.watch_time_info;
444 // Save audio only watch time information.
445 MaybeSaveWatchTime(event, media::MediaLog::kWatchTimeAudioAll,
446 &wti.all_watch_time);
447 MaybeSaveWatchTime(event, media::MediaLog::kWatchTimeAudioMse,
448 &wti.mse_watch_time);
449 MaybeSaveWatchTime(event, media::MediaLog::kWatchTimeAudioEme,
450 &wti.eme_watch_time);
451 MaybeSaveWatchTime(event, media::MediaLog::kWatchTimeAudioSrc,
452 &wti.src_watch_time);
453 MaybeSaveWatchTime(event, media::MediaLog::kWatchTimeAudioBattery,
454 &wti.battery_watch_time);
455 MaybeSaveWatchTime(event, media::MediaLog::kWatchTimeAudioAc,
456 &wti.ac_watch_time);
457
458 // Save audio+video watch time information.
429 MaybeSaveWatchTime(event, media::MediaLog::kWatchTimeAudioVideoAll, 459 MaybeSaveWatchTime(event, media::MediaLog::kWatchTimeAudioVideoAll,
430 &wti.all_watch_time); 460 &wti.all_watch_time);
431 MaybeSaveWatchTime(event, media::MediaLog::kWatchTimeAudioVideoMse, 461 MaybeSaveWatchTime(event, media::MediaLog::kWatchTimeAudioVideoMse,
432 &wti.mse_watch_time); 462 &wti.mse_watch_time);
433 MaybeSaveWatchTime(event, media::MediaLog::kWatchTimeAudioVideoEme, 463 MaybeSaveWatchTime(event, media::MediaLog::kWatchTimeAudioVideoEme,
434 &wti.eme_watch_time); 464 &wti.eme_watch_time);
435 MaybeSaveWatchTime(event, media::MediaLog::kWatchTimeAudioVideoSrc, 465 MaybeSaveWatchTime(event, media::MediaLog::kWatchTimeAudioVideoSrc,
436 &wti.src_watch_time); 466 &wti.src_watch_time);
437 MaybeSaveWatchTime(event, media::MediaLog::kWatchTimeAudioVideoBattery, 467 MaybeSaveWatchTime(event, media::MediaLog::kWatchTimeAudioVideoBattery,
438 &wti.battery_watch_time); 468 &wti.battery_watch_time);
439 MaybeSaveWatchTime(event, media::MediaLog::kWatchTimeAudioVideoAc, 469 MaybeSaveWatchTime(event, media::MediaLog::kWatchTimeAudioVideoAc,
440 &wti.ac_watch_time); 470 &wti.ac_watch_time);
441 471
442 if (event.params.HasKey(media::MediaLog::kWatchTimeFinalize)) { 472 if (event.params.HasKey(media::MediaLog::kWatchTimeFinalize)) {
443 bool should_finalize; 473 bool should_finalize;
444 DCHECK(event.params.GetBoolean(media::MediaLog::kWatchTimeFinalize, 474 DCHECK(event.params.GetBoolean(media::MediaLog::kWatchTimeFinalize,
445 &should_finalize) && 475 &should_finalize) &&
446 should_finalize); 476 should_finalize);
447 FinalizeWatchTime(&wti, FinalizeType::EVERYTHING); 477 FinalizeWatchTime(info.has_video, &wti, FinalizeType::EVERYTHING);
448 } else if (event.params.HasKey( 478 } else if (event.params.HasKey(
449 media::MediaLog::kWatchTimeFinalizePower)) { 479 media::MediaLog::kWatchTimeFinalizePower)) {
450 bool should_finalize; 480 bool should_finalize;
451 DCHECK(event.params.GetBoolean(media::MediaLog::kWatchTimeFinalizePower, 481 DCHECK(event.params.GetBoolean(media::MediaLog::kWatchTimeFinalizePower,
452 &should_finalize) && 482 &should_finalize) &&
453 should_finalize); 483 should_finalize);
454 FinalizeWatchTime(&wti, FinalizeType::POWER_ONLY); 484 FinalizeWatchTime(info.has_video, &wti, FinalizeType::POWER_ONLY);
455 } 485 }
456 break; 486 break;
457 } 487 }
458 case media::MediaLogEvent::Type::WEBMEDIAPLAYER_DESTROYED: { 488 case media::MediaLogEvent::Type::WEBMEDIAPLAYER_DESTROYED: {
459 // Upon player destruction report UMA data; if the player is not torn down 489 // Upon player destruction report UMA data; if the player is not torn down
460 // before process exit, it will be logged during OnProcessTerminated(). 490 // before process exit, it will be logged during OnProcessTerminated().
461 auto it = player_info.find(event.id); 491 auto it = player_info.find(event.id);
462 if (it == player_info.end()) 492 if (it == player_info.end())
463 break; 493 break;
464 494
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 void MediaInternals::MediaInternalsUMAHandler::OnProcessTerminated( 577 void MediaInternals::MediaInternalsUMAHandler::OnProcessTerminated(
548 int render_process_id) { 578 int render_process_id) {
549 DCHECK_CURRENTLY_ON(BrowserThread::UI); 579 DCHECK_CURRENTLY_ON(BrowserThread::UI);
550 580
551 auto players_it = renderer_info_.find(render_process_id); 581 auto players_it = renderer_info_.find(render_process_id);
552 if (players_it == renderer_info_.end()) 582 if (players_it == renderer_info_.end())
553 return; 583 return;
554 auto it = players_it->second.begin(); 584 auto it = players_it->second.begin();
555 while (it != players_it->second.end()) { 585 while (it != players_it->second.end()) {
556 ReportUMAForPipelineStatus(it->second); 586 ReportUMAForPipelineStatus(it->second);
557 FinalizeWatchTime(&(it->second.watch_time_info), FinalizeType::EVERYTHING); 587 FinalizeWatchTime(it->second.has_video, &(it->second.watch_time_info),
588 FinalizeType::EVERYTHING);
558 players_it->second.erase(it++); 589 players_it->second.erase(it++);
559 } 590 }
560 renderer_info_.erase(players_it); 591 renderer_info_.erase(players_it);
561 } 592 }
562 593
563 MediaInternals* MediaInternals::GetInstance() { 594 MediaInternals* MediaInternals::GetInstance() {
564 return g_media_internals.Pointer(); 595 return g_media_internals.Pointer();
565 } 596 }
566 597
567 MediaInternals::MediaInternals() 598 MediaInternals::MediaInternals()
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
811 audio_streams_cached_data_.GetDictionary(cache_key, &existing_dict)); 842 audio_streams_cached_data_.GetDictionary(cache_key, &existing_dict));
812 existing_dict->MergeDictionary(value); 843 existing_dict->MergeDictionary(value);
813 } 844 }
814 } 845 }
815 846
816 if (CanUpdate()) 847 if (CanUpdate())
817 SendUpdate(SerializeUpdate(function, value)); 848 SendUpdate(SerializeUpdate(function, value));
818 } 849 }
819 850
820 } // namespace content 851 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | media/base/media_log.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698