forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
video_decode_stats_db.h
91 lines (75 loc) · 3.59 KB
/
video_decode_stats_db.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef MEDIA_CAPABILITIES_VIDEO_DECODE_STATS_DB_H_
#define MEDIA_CAPABILITIES_VIDEO_DECODE_STATS_DB_H_
#include <memory>
#include "base/callback.h"
#include "base/macros.h"
#include "media/base/media_export.h"
#include "media/base/video_codecs.h"
#include "ui/gfx/geometry/size.h"
namespace media {
// This defines the interface to be used by various media capabilities services
// to store/retrieve video decoding performance statistics.
class MEDIA_EXPORT VideoDecodeStatsDB {
public:
// Simple description of video decode complexity, serving as a key to look up
// associated DecodeStatsEntries in the database.
struct MEDIA_EXPORT VideoDescKey {
static VideoDescKey MakeBucketedKey(VideoCodecProfile codec_profile,
const gfx::Size& size,
int frame_rate);
const VideoCodecProfile codec_profile;
const gfx::Size size;
const int frame_rate;
private:
VideoDescKey(VideoCodecProfile codec_profile,
const gfx::Size& size,
int frame_rate);
};
// DecodeStatsEntry saved to identify the capabilities related to a given
// |VideoDescKey|.
struct MEDIA_EXPORT DecodeStatsEntry {
DecodeStatsEntry(uint64_t frames_decoded,
uint64_t frames_dropped,
uint64_t frames_decoded_power_efficient);
uint64_t frames_decoded;
uint64_t frames_dropped;
uint64_t frames_decoded_power_efficient;
};
virtual ~VideoDecodeStatsDB() = default;
// Run asynchronous initialization of database. Initialization must complete
// before calling other APIs. Initialization must be RE-RUN after calling
// DestroyStats() and receiving its completion callback. |init_cb| must not be
// a null callback.
virtual void Initialize(base::OnceCallback<void(bool)> init_cb) = 0;
// Appends `stats` to existing entry associated with `key`. Will create a new
// entry if none exists. The operation is asynchronous. The caller should be
// aware of potential race conditions when calling this method for the same
// `key` very close to other calls. `append_done_cb` will be run with a bool
// to indicate whether the save succeeded.
using AppendDecodeStatsCB = base::OnceCallback<void(bool)>;
virtual void AppendDecodeStats(const VideoDescKey& key,
const DecodeStatsEntry& entry,
AppendDecodeStatsCB append_done_cb) = 0;
// Returns the stats associated with `key`. The `get_stats_cb` will receive
// the stats in addition to a boolean signaling if the call was successful.
// DecodeStatsEntry can be nullptr if there was no data associated with `key`.
using GetDecodeStatsCB =
base::OnceCallback<void(bool, std::unique_ptr<DecodeStatsEntry>)>;
virtual void GetDecodeStats(const VideoDescKey& key,
GetDecodeStatsCB get_stats_cb) = 0;
// Clear all statistics by DESTROYING the underlying the database.
// DO NOT use the database until |callback| is run. When finished, users must
// RE-RUN Initialize() before performing further I/O.
virtual void DestroyStats(base::OnceClosure destroy_done_cb) = 0;
};
// Factory interface to create a DB instance.
class MEDIA_EXPORT VideoDecodeStatsDBFactory {
public:
virtual ~VideoDecodeStatsDBFactory() {}
virtual std::unique_ptr<VideoDecodeStatsDB> CreateDB() = 0;
};
} // namespace media
#endif // MEDIA_CAPABILITIES_VIDEO_DECODE_STATS_DB_H_