video_decode_stats_db.cc 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. // Copyright 2017 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "media/capabilities/video_decode_stats_db.h"
  5. #include "base/check_op.h"
  6. #include "base/format_macros.h"
  7. #include "base/strings/stringprintf.h"
  8. #include "media/capabilities/bucket_utility.h"
  9. namespace media {
  10. // static
  11. VideoDecodeStatsDB::VideoDescKey
  12. VideoDecodeStatsDB::VideoDescKey::MakeBucketedKey(
  13. VideoCodecProfile codec_profile,
  14. const gfx::Size& size,
  15. int frame_rate,
  16. std::string key_system,
  17. bool use_hw_secure_codecs) {
  18. // Bucket size and framerate to prevent an explosion of one-off values in the
  19. // database and add basic guards against fingerprinting.
  20. return VideoDescKey(codec_profile, GetSizeBucket(size),
  21. GetFpsBucket(frame_rate), key_system,
  22. use_hw_secure_codecs);
  23. }
  24. VideoDecodeStatsDB::VideoDescKey::VideoDescKey(VideoCodecProfile codec_profile,
  25. const gfx::Size& size,
  26. int frame_rate,
  27. std::string key_system,
  28. bool use_hw_secure_codecs)
  29. : codec_profile(codec_profile),
  30. size(size),
  31. frame_rate(frame_rate),
  32. key_system(key_system),
  33. use_hw_secure_codecs(use_hw_secure_codecs) {
  34. // use_hw_secure_codecs = true -> we must have a key system.
  35. DCHECK(!use_hw_secure_codecs || !key_system.empty());
  36. }
  37. std::string VideoDecodeStatsDB::VideoDescKey::Serialize() const {
  38. std::string video_part =
  39. base::StringPrintf("%d|%s|%d", static_cast<int>(codec_profile),
  40. size.ToString().c_str(), frame_rate);
  41. // NOTE: |eme_part| should be completely empty for non-EME stats to preserve
  42. // backward compat with pre-EME clear stats.
  43. std::string eme_part;
  44. if (!key_system.empty()) {
  45. static const char kIsHwSecure[] = "is_hw_secure";
  46. static const char kNotHwSecure[] = "not_hw_secure";
  47. eme_part =
  48. base::StringPrintf("|%s|%s", key_system.c_str(),
  49. use_hw_secure_codecs ? kIsHwSecure : kNotHwSecure);
  50. }
  51. return video_part + eme_part;
  52. }
  53. std::string VideoDecodeStatsDB::VideoDescKey::ToLogString() const {
  54. return "Key {" + Serialize() + "}";
  55. }
  56. VideoDecodeStatsDB::DecodeStatsEntry::DecodeStatsEntry(
  57. uint64_t frames_decoded,
  58. uint64_t frames_dropped,
  59. uint64_t frames_power_efficient)
  60. : frames_decoded(frames_decoded),
  61. frames_dropped(frames_dropped),
  62. frames_power_efficient(frames_power_efficient) {
  63. DCHECK_GE(frames_decoded, 0u);
  64. DCHECK_GE(frames_dropped, 0u);
  65. DCHECK_GE(frames_power_efficient, 0u);
  66. }
  67. VideoDecodeStatsDB::DecodeStatsEntry::DecodeStatsEntry(
  68. const DecodeStatsEntry& entry) = default;
  69. VideoDecodeStatsDB::DecodeStatsEntry&
  70. VideoDecodeStatsDB::DecodeStatsEntry::operator=(const DecodeStatsEntry& entry) =
  71. default;
  72. std::string VideoDecodeStatsDB::DecodeStatsEntry::ToLogString() const {
  73. return base::StringPrintf(
  74. "DecodeStatsEntry {frames decoded:%" PRIu64 ", dropped:%" PRIu64
  75. ", power efficient:%" PRIu64 "}",
  76. frames_decoded, frames_dropped, frames_power_efficient);
  77. }
  78. VideoDecodeStatsDB::DecodeStatsEntry& VideoDecodeStatsDB::DecodeStatsEntry::
  79. operator+=(const DecodeStatsEntry& right) {
  80. DCHECK_GE(right.frames_decoded, 0u);
  81. DCHECK_GE(right.frames_dropped, 0u);
  82. DCHECK_GE(right.frames_power_efficient, 0u);
  83. frames_decoded += right.frames_decoded;
  84. frames_dropped += right.frames_dropped;
  85. frames_power_efficient += right.frames_power_efficient;
  86. return *this;
  87. }
  88. bool operator==(const VideoDecodeStatsDB::VideoDescKey& x,
  89. const VideoDecodeStatsDB::VideoDescKey& y) {
  90. return x.codec_profile == y.codec_profile && x.size == y.size &&
  91. x.frame_rate == y.frame_rate && x.key_system == y.key_system &&
  92. x.use_hw_secure_codecs == y.use_hw_secure_codecs;
  93. }
  94. bool operator!=(const VideoDecodeStatsDB::VideoDescKey& x,
  95. const VideoDecodeStatsDB::VideoDescKey& y) {
  96. return !(x == y);
  97. }
  98. bool operator==(const VideoDecodeStatsDB::DecodeStatsEntry& x,
  99. const VideoDecodeStatsDB::DecodeStatsEntry& y) {
  100. return x.frames_decoded == y.frames_decoded &&
  101. x.frames_dropped == y.frames_dropped &&
  102. x.frames_power_efficient == y.frames_power_efficient;
  103. }
  104. bool operator!=(const VideoDecodeStatsDB::DecodeStatsEntry& x,
  105. const VideoDecodeStatsDB::DecodeStatsEntry& y) {
  106. return !(x == y);
  107. }
  108. } // namespace media