Test: unit tests Test: Google TV and Netflix Test: atest GtsMediaTestCases Bug: 216527109 Change-Id: I3fd02c2c60da588dba3db27cea3593de25a7180f
109 lines
3.8 KiB
C++
109 lines
3.8 KiB
C++
//
|
|
// Copyright 2021 Google LLC. All Rights Reserved. This file and proprietary
|
|
// source code may only be used and distributed under the Widevine License
|
|
// Agreement.
|
|
//
|
|
|
|
#ifndef WV_METRICS_ADAPTER_H_
|
|
#define WV_METRICS_ADAPTER_H_
|
|
|
|
#include <aidl/android/hardware/drm/DrmMetricGroup.h>
|
|
|
|
#include <vector>
|
|
|
|
#include "wv_metrics.pb.h"
|
|
|
|
namespace wvcdm {
|
|
|
|
class WvMetricsAdapter;
|
|
|
|
// This class is used to convert from the metrics.proto format for metrics
|
|
// to the format specified in the aidl.android.hardware.drm DrmMetricGroup
|
|
// type. This class converts the common metric types into a single group.
|
|
//
|
|
// Example:
|
|
// drm_metrics::DistributionMetric distribution;
|
|
// distribution.set_operation_count(1);
|
|
// WvMetricsGroupBuilder builder;
|
|
// builder.AddDistributions("test distribution", { distribution });
|
|
//
|
|
// DrmMetricGroup group = builder.Build();
|
|
class WvMetricsGroupBuilder {
|
|
public:
|
|
// Adds a group of distributions with the given base name.
|
|
void AddDistributions(
|
|
const std::string& name,
|
|
const google::protobuf::RepeatedPtrField<drm_metrics::DistributionMetric>&
|
|
distributions);
|
|
|
|
// Adds a group of counter metrics with the given base name.
|
|
void AddCounters(
|
|
const std::string& name,
|
|
const google::protobuf::RepeatedPtrField<drm_metrics::CounterMetric>&
|
|
counters);
|
|
|
|
// Adds a value metric.
|
|
void AddValue(const std::string& name,
|
|
const drm_metrics::ValueMetric& value_or_error);
|
|
|
|
// Builds the metric group containing all of the previously added metrics.
|
|
::aidl::android::hardware::drm::DrmMetricGroup Build();
|
|
|
|
private:
|
|
friend class WvMetricsAdapter;
|
|
std::vector<::aidl::android::hardware::drm::DrmMetric> metrics_;
|
|
|
|
WvMetricsGroupBuilder();
|
|
// Adds a distribution with the given name and distribution values.
|
|
void AddDistribution(const std::string& name,
|
|
const drm_metrics::DistributionMetric& distribution);
|
|
// Adds a counter metric
|
|
void AddCounter(const std::string& name,
|
|
const drm_metrics::CounterMetric& counter);
|
|
void AddAttributes(
|
|
const drm_metrics::Attributes& attributes_proto,
|
|
std::vector<::aidl::android::hardware::drm::DrmMetricNamedValue>*
|
|
attributes);
|
|
};
|
|
|
|
// This class handles adding the engine and session metric collections. This
|
|
// will generate one DrmMetricGroup for each EngineMetric added and one for
|
|
// each SessionMetric added. This class also supports a static utility method to
|
|
// convert a WvCdmMetrics proto to a vector of DrmMetricGroup instances.
|
|
class WvMetricsAdapter {
|
|
public:
|
|
// Utility method to quickly convert a WvCdmMetrics proto to a DrmMetricGroup
|
|
// vector.
|
|
static void ToWvMetrics(
|
|
const drm_metrics::WvCdmMetrics& proto_metrics,
|
|
std::vector<::aidl::android::hardware::drm::DrmMetricGroup>* wv_metrics);
|
|
|
|
WvMetricsAdapter();
|
|
~WvMetricsAdapter();
|
|
|
|
// Adds the EngineMetrics instance to the Adapter. It will be converted and
|
|
// stored. The converted metrics can be fetched via GetWvGroupVector.
|
|
void AddEngineMetrics(
|
|
const drm_metrics::WvCdmMetrics::EngineMetrics& proto_metrics);
|
|
|
|
// Adds the SessionMetrics instance to the Adapter. It will be converted and
|
|
// stored. The converted metrics can be fetched via GetWvGroupVector.
|
|
void AddSessionMetrics(
|
|
const drm_metrics::WvCdmMetrics::SessionMetrics& proto_metrics);
|
|
|
|
// Returns the converted DrmMetricGroup vector containing all of the
|
|
// previously added engine and session metrics collections.
|
|
const std::vector<::aidl::android::hardware::drm::DrmMetricGroup>
|
|
GetWvGroupVector();
|
|
|
|
private:
|
|
void AddCryptoMetrics(
|
|
const drm_metrics::WvCdmMetrics::CryptoMetrics& proto_metrics,
|
|
WvMetricsGroupBuilder* group_builder);
|
|
std::vector<::aidl::android::hardware::drm::DrmMetricGroup> group_vector_;
|
|
};
|
|
|
|
} // namespace wvcdm
|
|
|
|
#endif // WV_METRICS_ADAPTER_H_
|