video_decode_stats_db.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. #ifndef MEDIA_CAPABILITIES_VIDEO_DECODE_STATS_DB_H_
  5. #define MEDIA_CAPABILITIES_VIDEO_DECODE_STATS_DB_H_
  6. #include <memory>
  7. #include <string>
  8. #include "base/callback_forward.h"
  9. #include "base/check.h"
  10. #include "media/base/media_export.h"
  11. #include "media/base/video_codecs.h"
  12. #include "ui/gfx/geometry/size.h"
  13. namespace media {
  14. // This defines the interface to be used by various media capabilities services
  15. // to store/retrieve video decoding performance statistics.
  16. class MEDIA_EXPORT VideoDecodeStatsDB {
  17. public:
  18. // Simple description of video decode complexity, serving as a key to look up
  19. // associated DecodeStatsEntries in the database.
  20. struct MEDIA_EXPORT VideoDescKey {
  21. static VideoDescKey MakeBucketedKey(VideoCodecProfile codec_profile,
  22. const gfx::Size& size,
  23. int frame_rate,
  24. std::string key_system,
  25. bool use_hw_secure_codecs);
  26. // Returns a concise string representation of the key for storing in DB.
  27. std::string Serialize() const;
  28. // For debug logging. NOT interchangeable with Serialize().
  29. std::string ToLogString() const;
  30. // Note: operator == and != are defined outside this class.
  31. const VideoCodecProfile codec_profile;
  32. const gfx::Size size;
  33. const int frame_rate;
  34. const std::string key_system;
  35. const bool use_hw_secure_codecs;
  36. private:
  37. // All key's should be "bucketed" using MakeBucketedKey(...).
  38. VideoDescKey(VideoCodecProfile codec_profile,
  39. const gfx::Size& size,
  40. int frame_rate,
  41. std::string key_system,
  42. bool use_hw_secure_codecs);
  43. };
  44. // DecodeStatsEntry saved to identify the capabilities related to a given
  45. // |VideoDescKey|.
  46. struct MEDIA_EXPORT DecodeStatsEntry {
  47. DecodeStatsEntry(uint64_t frames_decoded,
  48. uint64_t frames_dropped,
  49. uint64_t frames_power_efficient);
  50. DecodeStatsEntry(const DecodeStatsEntry& entry);
  51. DecodeStatsEntry& operator=(const DecodeStatsEntry& entry);
  52. // Add stats from |right| to |this| entry.
  53. DecodeStatsEntry& operator+=(const DecodeStatsEntry& right);
  54. // For debug logging.
  55. std::string ToLogString() const;
  56. // Note: operator == and != are defined outside this class.
  57. uint64_t frames_decoded;
  58. uint64_t frames_dropped;
  59. uint64_t frames_power_efficient;
  60. };
  61. virtual ~VideoDecodeStatsDB() = default;
  62. // Run asynchronous initialization of database. Initialization must complete
  63. // before calling other APIs. Initialization must be RE-RUN after calling
  64. // DestroyStats() and receiving its completion callback. |init_cb| must not be
  65. // a null callback.
  66. using InitializeCB = base::OnceCallback<void(bool)>;
  67. virtual void Initialize(InitializeCB init_cb) = 0;
  68. // Appends `stats` to existing entry associated with `key`. Will create a new
  69. // entry if none exists. The operation is asynchronous. The caller should be
  70. // aware of potential race conditions when calling this method for the same
  71. // `key` very close to other calls. `append_done_cb` will be run with a bool
  72. // to indicate whether the save succeeded.
  73. using AppendDecodeStatsCB = base::OnceCallback<void(bool)>;
  74. virtual void AppendDecodeStats(const VideoDescKey& key,
  75. const DecodeStatsEntry& entry,
  76. AppendDecodeStatsCB append_done_cb) = 0;
  77. // Returns the stats associated with `key`. The `get_stats_cb` will receive
  78. // the stats in addition to a boolean signaling if the call was successful.
  79. // DecodeStatsEntry can be nullptr if there was no data associated with `key`.
  80. using GetDecodeStatsCB =
  81. base::OnceCallback<void(bool, std::unique_ptr<DecodeStatsEntry>)>;
  82. virtual void GetDecodeStats(const VideoDescKey& key,
  83. GetDecodeStatsCB get_stats_cb) = 0;
  84. // Clear all statistics from the DB.
  85. virtual void ClearStats(base::OnceClosure clear_done_cb) = 0;
  86. };
  87. MEDIA_EXPORT bool operator==(const VideoDecodeStatsDB::VideoDescKey& x,
  88. const VideoDecodeStatsDB::VideoDescKey& y);
  89. MEDIA_EXPORT bool operator!=(const VideoDecodeStatsDB::VideoDescKey& x,
  90. const VideoDecodeStatsDB::VideoDescKey& y);
  91. MEDIA_EXPORT bool operator==(const VideoDecodeStatsDB::DecodeStatsEntry& x,
  92. const VideoDecodeStatsDB::DecodeStatsEntry& y);
  93. MEDIA_EXPORT bool operator!=(const VideoDecodeStatsDB::DecodeStatsEntry& x,
  94. const VideoDecodeStatsDB::DecodeStatsEntry& y);
  95. } // namespace media
  96. #endif // MEDIA_CAPABILITIES_VIDEO_DECODE_STATS_DB_H_