Merge "Fixed WV metrics YAML formating." into udc-dev

This commit is contained in:
Alex Dale
2023-04-24 22:04:34 +00:00
committed by Android (Google) Code Review
3 changed files with 457 additions and 303 deletions

View File

@@ -43,6 +43,41 @@ using ::aidl::android::hardware::drm::Uuid;
WVGenericCryptoInterface WVDrmFactory::sOemCryptoInterface;
namespace {
void PrintStream(int fd, std::stringstream& ss) {
const std::string content = ss.str();
dprintf(fd, "%s", content.c_str());
}
void FormatIndent(int fd, size_t indent) {
const size_t kMaxIndent = 60;
const size_t real_indent = std::min(indent, kMaxIndent);
char buffer[kMaxIndent + 1];
memset(buffer, ' ', real_indent);
buffer[real_indent] = 0;
dprintf(fd, "%s", buffer);
if (real_indent < indent) FormatIndent(fd, indent - real_indent);
}
void FormatWvMetricsSnapshotItem(int fd, size_t parent_indent,
drm_metrics::WvCdmMetrics& metrics,
size_t item_index) {
const size_t indent = parent_indent + 2;
// TODO(b/239462891): Provide identifier and timestamp for metrics.
// Serialized proto size.
FormatIndent(fd, parent_indent); // First parameter uses indent + list tick.
dprintf(fd, "- serialized_proto_bytes: %zu # [%zu]\n",
metrics.ByteSizeLong(), item_index);
FormatIndent(fd, indent);
dprintf(fd, "cdm_metrics:\n");
std::stringstream ss;
wv_metrics::FormatWvCdmMetrics(metrics, indent, ss);
PrintStream(fd, ss);
}
} // namespace
bool WVDrmFactory::isCryptoSchemeSupported(const Uuid& in_uuid) {
return isWidevineUUID(in_uuid.uuid.data());
}
@@ -182,25 +217,30 @@ void WVDrmFactory::printCdmMetrics(int fd) {
bool full_list_returned = true;
wvcdm::CdmResponseType result =
cdm->GetMetrics(&metrics, &full_list_returned);
if (metrics.empty()) {
dprintf(fd,
" error_message: Metrics not available, please retry while streaming a video.\n");
} else if (!full_list_returned) {
dprintf(fd,
" error_message: Not all metrics are returned due to some GetMetric error, "
"please check logcat for possible GetMetric errors.\n");
}
if (result == wvcdm::NO_ERROR) {
for (auto& metric : metrics) {
dprintf(fd, " - serialized_proto_bytes: %zu\n", metric.ByteSizeLong());
string formatted;
wv_metrics::FormatWvCdmMetrics(metric, formatted);
dprintf(fd, "%s\n", formatted.c_str());
}
if (result != wvcdm::NO_ERROR) {
dprintf(fd, " live_metrics:\n");
dprintf(fd, " error_message: \"%s\"\n", result.ToString().c_str());
dprintf(fd, " error_code: %d\n", static_cast<int>(result.code()));
} else if (metrics.empty()) {
// YAML does not support empty property values.
const char kNoMetricsMessage[] =
"Metrics not available, please retry while streaming a video.";
dprintf(fd, " live_metrics: [] # %s\n", kNoMetricsMessage);
} else {
dprintf(fd, " error_message: %s\n", result.GetCodeString());
dprintf(fd, " error_code: %d\n", result.ToInt());
dprintf(fd, " live_metrics: ");
if (full_list_returned) {
dprintf(fd, "# count = %zu\n", metrics.size());
} else {
const char kPartialListMessage[] =
"Some metrics are missing due to an internal error, "
"check logs for details.";
dprintf(fd, "# count = %zu, %s\n", metrics.size(), kPartialListMessage);
}
for (size_t i = 0; i < metrics.size(); i++) {
FormatWvMetricsSnapshotItem(fd, 2, metrics[i], i);
}
}
// TODO(b/270166158): Print metrics history.
}
void WVDrmFactory::printCdmProperties(int fd) {