blob: a0b8f16ae3aec56baf49f3296902bdf4bfd9dad5 [file] [log] [blame]
Ray Essick6ce27e52019-02-15 10:58:05 -08001/*
2 * Copyright (C) 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17//#define LOG_NDEBUG 0
18#define LOG_TAG "statsd_codec"
19#include <utils/Log.h>
20
21#include <dirent.h>
22#include <inttypes.h>
23#include <pthread.h>
24#include <pwd.h>
25#include <stdint.h>
26#include <string.h>
27#include <sys/stat.h>
28#include <sys/time.h>
29#include <sys/types.h>
30#include <unistd.h>
31
Vova Sharaienkof58455a2022-09-24 01:47:23 +000032#include <stats_media_metrics.h>
Brian Lindahlc935ee22021-06-08 09:57:07 +020033#include <stats_event.h>
Ray Essick6ce27e52019-02-15 10:58:05 -080034
Ray Essick5a557292020-06-10 21:31:33 -070035#include "cleaner.h"
Ray Essick40e8e5e2019-12-05 20:19:40 -080036#include "MediaMetricsService.h"
Andy Hungc9b6f8b2021-07-08 10:17:55 -070037#include "ValidateId.h"
Dichen Zhangb8f23c52021-03-22 00:56:29 -070038#include "frameworks/proto_logging/stats/message/mediametrics_message.pb.h"
Ray Essick6ce27e52019-02-15 10:58:05 -080039#include "iface_statsd.h"
40
41namespace android {
42
Brian Lindahl590e3852023-05-05 15:21:58 -060043using stats::media_metrics::stats_write;
44using stats::media_metrics::MEDIA_CODEC_RENDERED;
45using stats::media_metrics::MEDIA_CODEC_RENDERED__CODEC__CODEC_UNKNOWN;
46using stats::media_metrics::MEDIA_CODEC_RENDERED__RESOLUTION__RESOLUTION_INVALID;
47using stats::media_metrics::MEDIA_CODEC_RENDERED__RESOLUTION__RESOLUTION_ZERO;
48using stats::media_metrics::MEDIA_CODEC_RENDERED__CONTENT_FRAMERATE__FRAMERATE_UNKNOWN;
49using stats::media_metrics::MEDIA_CODEC_RENDERED__CONTENT_FRAMERATE__FRAMERATE_UNDETERMINED;
50using stats::media_metrics::MEDIA_CODEC_RENDERED__CONTENT_FRAMERATE__FRAMERATE_24_3_2_PULLDOWN;
51using stats::media_metrics::MEDIA_CODEC_RENDERED__HDR_FORMAT__HDR_FORMAT_NONE;
52using stats::media_metrics::MEDIA_CODEC_RENDERED__HDR_FORMAT__HDR_FORMAT_HLG;
53using stats::media_metrics::MEDIA_CODEC_RENDERED__HDR_FORMAT__HDR_FORMAT_HDR10;
54using stats::media_metrics::MEDIA_CODEC_RENDERED__HDR_FORMAT__HDR_FORMAT_HDR10_PLUS;
55using stats::media_metrics::MEDIA_CODEC_RENDERED__HDR_FORMAT__HDR_FORMAT_DOLBY_VISION;
56
57static const int BITRATE_UNKNOWN =
58 stats::media_metrics::MEDIA_CODEC_RENDERED__BITRATE__BITRATE_UNKNOWN;
59
60static const std::pair<char const *, int> CODEC_LOOKUP[] = {
61 { "avc", stats::media_metrics::MEDIA_CODEC_RENDERED__CODEC__CODEC_AVC },
62 { "h264", stats::media_metrics::MEDIA_CODEC_RENDERED__CODEC__CODEC_AVC },
63 { "hevc", stats::media_metrics::MEDIA_CODEC_RENDERED__CODEC__CODEC_HEVC },
64 { "h265", stats::media_metrics::MEDIA_CODEC_RENDERED__CODEC__CODEC_HEVC },
65 { "vp8", stats::media_metrics::MEDIA_CODEC_RENDERED__CODEC__CODEC_VP8 },
66 { "vp9", stats::media_metrics::MEDIA_CODEC_RENDERED__CODEC__CODEC_VP9 },
67 { "av1", stats::media_metrics::MEDIA_CODEC_RENDERED__CODEC__CODEC_AV1 },
68 { "av01", stats::media_metrics::MEDIA_CODEC_RENDERED__CODEC__CODEC_AV1 },
69 { "dolby-vision", stats::media_metrics::MEDIA_CODEC_RENDERED__CODEC__CODEC_HEVC },
70};
71
72static const int32_t RESOLUTION_LOOKUP[] = {
73 stats::media_metrics::MEDIA_CODEC_RENDERED__RESOLUTION__RESOLUTION_MAX_SIZE,
74 stats::media_metrics::MEDIA_CODEC_RENDERED__RESOLUTION__RESOLUTION_32K,
75 stats::media_metrics::MEDIA_CODEC_RENDERED__RESOLUTION__RESOLUTION_16K,
76 stats::media_metrics::MEDIA_CODEC_RENDERED__RESOLUTION__RESOLUTION_8K_UHD,
77 stats::media_metrics::MEDIA_CODEC_RENDERED__RESOLUTION__RESOLUTION_8K_UHD_ALMOST,
78 stats::media_metrics::MEDIA_CODEC_RENDERED__RESOLUTION__RESOLUTION_4K_UHD_ALMOST,
79 stats::media_metrics::MEDIA_CODEC_RENDERED__RESOLUTION__RESOLUTION_1440X2560,
80 stats::media_metrics::MEDIA_CODEC_RENDERED__RESOLUTION__RESOLUTION_1080X2400,
81 stats::media_metrics::MEDIA_CODEC_RENDERED__RESOLUTION__RESOLUTION_1080X2340,
82 stats::media_metrics::MEDIA_CODEC_RENDERED__RESOLUTION__RESOLUTION_1080P_FHD,
83 stats::media_metrics::MEDIA_CODEC_RENDERED__RESOLUTION__RESOLUTION_1080P_FHD_ALMOST,
84 stats::media_metrics::MEDIA_CODEC_RENDERED__RESOLUTION__RESOLUTION_720P_HD,
85 stats::media_metrics::MEDIA_CODEC_RENDERED__RESOLUTION__RESOLUTION_720P_HD_ALMOST,
86 stats::media_metrics::MEDIA_CODEC_RENDERED__RESOLUTION__RESOLUTION_576X1024,
87 stats::media_metrics::MEDIA_CODEC_RENDERED__RESOLUTION__RESOLUTION_540X960,
88 stats::media_metrics::MEDIA_CODEC_RENDERED__RESOLUTION__RESOLUTION_480X854,
89 stats::media_metrics::MEDIA_CODEC_RENDERED__RESOLUTION__RESOLUTION_480X640,
90 stats::media_metrics::MEDIA_CODEC_RENDERED__RESOLUTION__RESOLUTION_360X640,
91 stats::media_metrics::MEDIA_CODEC_RENDERED__RESOLUTION__RESOLUTION_352X640,
92 stats::media_metrics::MEDIA_CODEC_RENDERED__RESOLUTION__RESOLUTION_VERY_LOW,
93 stats::media_metrics::MEDIA_CODEC_RENDERED__RESOLUTION__RESOLUTION_SMALLEST,
94 stats::media_metrics::MEDIA_CODEC_RENDERED__RESOLUTION__RESOLUTION_ZERO,
95};
96
97static const int32_t FRAMERATE_LOOKUP[] = {
98 stats::media_metrics::MEDIA_CODEC_RENDERED__CONTENT_FRAMERATE__FRAMERATE_24,
99 stats::media_metrics::MEDIA_CODEC_RENDERED__CONTENT_FRAMERATE__FRAMERATE_25,
100 stats::media_metrics::MEDIA_CODEC_RENDERED__CONTENT_FRAMERATE__FRAMERATE_30,
101 stats::media_metrics::MEDIA_CODEC_RENDERED__CONTENT_FRAMERATE__FRAMERATE_50,
102 stats::media_metrics::MEDIA_CODEC_RENDERED__CONTENT_FRAMERATE__FRAMERATE_60,
103 stats::media_metrics::MEDIA_CODEC_RENDERED__CONTENT_FRAMERATE__FRAMERATE_120,
104};
105
106static int32_t getMetricsCodecEnum(const std::string &mime, const std::string &componentName) {
107 for (const auto & codecStrAndEnum : CODEC_LOOKUP) {
108 if (strcasestr(mime.c_str(), codecStrAndEnum.first) != nullptr ||
109 strcasestr(componentName.c_str(), codecStrAndEnum.first) != nullptr) {
110 return codecStrAndEnum.second;
111 }
112 }
113 return MEDIA_CODEC_RENDERED__CODEC__CODEC_UNKNOWN;
114}
115
116static int32_t getMetricsResolutionEnum(int32_t width, int32_t height) {
117 if (width == 0 || height == 0) {
118 return MEDIA_CODEC_RENDERED__RESOLUTION__RESOLUTION_ZERO;
119 }
120 int64_t pixels = int64_t(width) * height / 1000;
121 if (width < 0 || height < 0 || pixels > RESOLUTION_LOOKUP[0]) {
122 return MEDIA_CODEC_RENDERED__RESOLUTION__RESOLUTION_INVALID;
123 }
124 for (int32_t resolutionEnum : RESOLUTION_LOOKUP) {
125 if (pixels > resolutionEnum) {
126 return resolutionEnum;
127 }
128 }
129 return MEDIA_CODEC_RENDERED__RESOLUTION__RESOLUTION_ZERO;
130}
131
132static int32_t getMetricsFramerateEnum(float inFramerate) {
133 if (inFramerate == -1.0f) {
134 return MEDIA_CODEC_RENDERED__CONTENT_FRAMERATE__FRAMERATE_UNDETERMINED;
135 }
136 if (inFramerate == -2.0f) {
137 return MEDIA_CODEC_RENDERED__CONTENT_FRAMERATE__FRAMERATE_24_3_2_PULLDOWN;
138 }
139 int framerate = int(inFramerate * 100); // Table is in hundredths of frames per second
140 static const int framerateTolerance = 40; // Tolerance is 0.4 frames per second - table is 100s
141 for (int32_t framerateEnum : FRAMERATE_LOOKUP) {
142 if (abs(framerate - framerateEnum) < framerateTolerance) {
143 return framerateEnum;
144 }
145 }
146 return MEDIA_CODEC_RENDERED__CONTENT_FRAMERATE__FRAMERATE_UNKNOWN;
147}
148
149static int32_t getMetricsHdrFormatEnum(std::string &mime, std::string &componentName,
150 int32_t configColorTransfer, int32_t parsedColorTransfer,
151 int32_t hdr10StaticInfo, int32_t hdr10PlusInfo) {
152 if (hdr10PlusInfo) {
153 return MEDIA_CODEC_RENDERED__HDR_FORMAT__HDR_FORMAT_HDR10_PLUS;
154 }
155 if (hdr10StaticInfo) {
156 return MEDIA_CODEC_RENDERED__HDR_FORMAT__HDR_FORMAT_HDR10;
157 }
158 // 7 = COLOR_TRANSFER_HLG in MediaCodecConstants.h
159 if (configColorTransfer == 7 || parsedColorTransfer == 7) {
160 return MEDIA_CODEC_RENDERED__HDR_FORMAT__HDR_FORMAT_HLG;
161 }
162 if (strcasestr(mime.c_str(), "dolby-vision") != nullptr ||
163 strcasestr(componentName.c_str(), "dvhe") != nullptr ||
164 strcasestr(componentName.c_str(), "dvav") != nullptr ||
165 strcasestr(componentName.c_str(), "dav1") != nullptr) {
166 return MEDIA_CODEC_RENDERED__HDR_FORMAT__HDR_FORMAT_DOLBY_VISION;
167 }
168 return MEDIA_CODEC_RENDERED__HDR_FORMAT__HDR_FORMAT_NONE;
169}
170
171static void parseVector(const std::string &str, std::vector<int32_t> *vector) {
172 char valueStr[12] = {};
173 int i = 0;
174 for (char const * p = str.c_str(); *p != 0; ++p) {
175 if (*p == ',' || *p == '{' || *p == '}') {
176 valueStr[i] = 0;
177 int64_t value = strtol(valueStr, nullptr, 10);
178 if (value >= std::numeric_limits<int32_t>::max() ||
179 value <= std::numeric_limits<int32_t>::min() ||
180 value == 0) {
181 ALOGE("failed to parse integer vector at '%s' from '%s'", p, str.c_str());
182 return;
183 }
184 vector->push_back(int32_t(value));
185 i = valueStr[0] = 0;
186 } else {
187 valueStr[i++] = *p;
188 if (i == sizeof(valueStr) - 1) { // -1 because we need space for a null terminator
189 ALOGE("failed to parse integer vector at '%s' from '%s'", p, str.c_str());
190 return;
191 }
192 }
193 }
194}
195
Andy Hung5be90c82021-03-30 14:30:20 -0700196bool statsd_codec(const std::shared_ptr<const mediametrics::Item>& item,
197 const std::shared_ptr<mediametrics::StatsdLog>& statsdLog)
Ray Essick6ce27e52019-02-15 10:58:05 -0800198{
Andy Hung3ab1b322020-05-18 10:47:31 -0700199 if (item == nullptr) return false;
Ray Essick6ce27e52019-02-15 10:58:05 -0800200
Brian Lindahlc935ee22021-06-08 09:57:07 +0200201 AStatsEvent* event = AStatsEvent_obtain();
Vova Sharaienkof58455a2022-09-24 01:47:23 +0000202 AStatsEvent_setAtomId(event, stats::media_metrics::MEDIA_CODEC_REPORTED);
Brian Lindahlc935ee22021-06-08 09:57:07 +0200203
Brian Lindahl590e3852023-05-05 15:21:58 -0600204 const nsecs_t timestampNanos = MediaMetricsService::roundTime(item->getTimestamp());
205 AStatsEvent_writeInt64(event, timestampNanos);
Brian Lindahlc935ee22021-06-08 09:57:07 +0200206
Brian Lindahl590e3852023-05-05 15:21:58 -0600207 std::string packageName = item->getPkgName();
208 AStatsEvent_writeString(event, packageName.c_str());
Brian Lindahlc935ee22021-06-08 09:57:07 +0200209
Brian Lindahl590e3852023-05-05 15:21:58 -0600210 int64_t packageVersionCode = item->getPkgVersionCode();
211 AStatsEvent_writeInt64(event, packageVersionCode);
Brian Lindahlc935ee22021-06-08 09:57:07 +0200212
Brian Lindahl590e3852023-05-05 15:21:58 -0600213 int64_t mediaApexVersion = 0;
214 AStatsEvent_writeInt64(event, mediaApexVersion);
Ray Essick6ce27e52019-02-15 10:58:05 -0800215
216 // the rest into our own proto
217 //
Dichen Zhangb8f23c52021-03-22 00:56:29 -0700218 ::android::stats::mediametrics_message::CodecData metrics_proto;
Ray Essick6ce27e52019-02-15 10:58:05 -0800219
220 // flesh out the protobuf we'll hand off with our data
221 //
George Burgess IV0d814432019-10-23 11:32:26 -0700222 std::string codec;
223 if (item->getString("android.media.mediacodec.codec", &codec)) {
Andy Hung5be90c82021-03-30 14:30:20 -0700224 metrics_proto.set_codec(codec);
Ray Essick6ce27e52019-02-15 10:58:05 -0800225 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200226 AStatsEvent_writeString(event, codec.c_str());
Andy Hung5be90c82021-03-30 14:30:20 -0700227
George Burgess IV0d814432019-10-23 11:32:26 -0700228 std::string mime;
229 if (item->getString("android.media.mediacodec.mime", &mime)) {
Andy Hung5be90c82021-03-30 14:30:20 -0700230 metrics_proto.set_mime(mime);
Ray Essick6ce27e52019-02-15 10:58:05 -0800231 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200232 AStatsEvent_writeString(event, mime.c_str());
Andy Hung5be90c82021-03-30 14:30:20 -0700233
George Burgess IV0d814432019-10-23 11:32:26 -0700234 std::string mode;
Brian Lindahlc935ee22021-06-08 09:57:07 +0200235 if (item->getString("android.media.mediacodec.mode", &mode)) {
Andy Hung5be90c82021-03-30 14:30:20 -0700236 metrics_proto.set_mode(mode);
Ray Essick6ce27e52019-02-15 10:58:05 -0800237 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200238 AStatsEvent_writeString(event, mode.c_str());
Andy Hung5be90c82021-03-30 14:30:20 -0700239
Brian Lindahl590e3852023-05-05 15:21:58 -0600240 int32_t isEncoder = -1;
241 if (item->getInt32("android.media.mediacodec.encoder", &isEncoder)) {
242 metrics_proto.set_encoder(isEncoder);
Ray Essick6ce27e52019-02-15 10:58:05 -0800243 }
Brian Lindahl590e3852023-05-05 15:21:58 -0600244 AStatsEvent_writeInt32(event, isEncoder);
Andy Hung5be90c82021-03-30 14:30:20 -0700245
Brian Lindahl590e3852023-05-05 15:21:58 -0600246 int32_t isSecure = -1;
247 if (item->getInt32("android.media.mediacodec.secure", &isSecure)) {
248 metrics_proto.set_secure(isSecure);
Ray Essick6ce27e52019-02-15 10:58:05 -0800249 }
Brian Lindahl590e3852023-05-05 15:21:58 -0600250 AStatsEvent_writeInt32(event, isSecure);
251
252 int32_t isHardware = -1;
253 item->getInt32("android.media.mediacodec.hardware", &isHardware);
254 // not logged to MediaCodecReported or MediametricsCodecReported
255
256 int32_t isTunneled = -1;
257 item->getInt32("android.media.mediacodec.tunneled", &isTunneled);
258 // not logged to MediaCodecReported or MediametricsCodecReported
Andy Hung5be90c82021-03-30 14:30:20 -0700259
Ray Essick6ce27e52019-02-15 10:58:05 -0800260 int32_t width = -1;
Brian Lindahlc935ee22021-06-08 09:57:07 +0200261 if (item->getInt32("android.media.mediacodec.width", &width)) {
Ray Essick6ce27e52019-02-15 10:58:05 -0800262 metrics_proto.set_width(width);
263 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200264 AStatsEvent_writeInt32(event, width);
Andy Hung5be90c82021-03-30 14:30:20 -0700265
Ray Essick6ce27e52019-02-15 10:58:05 -0800266 int32_t height = -1;
Brian Lindahlc935ee22021-06-08 09:57:07 +0200267 if (item->getInt32("android.media.mediacodec.height", &height)) {
Ray Essick6ce27e52019-02-15 10:58:05 -0800268 metrics_proto.set_height(height);
269 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200270 AStatsEvent_writeInt32(event, height);
Andy Hung5be90c82021-03-30 14:30:20 -0700271
Ray Essick6ce27e52019-02-15 10:58:05 -0800272 int32_t rotation = -1;
Brian Lindahlc935ee22021-06-08 09:57:07 +0200273 if (item->getInt32("android.media.mediacodec.rotation-degrees", &rotation)) {
Ray Essick6ce27e52019-02-15 10:58:05 -0800274 metrics_proto.set_rotation(rotation);
275 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200276 AStatsEvent_writeInt32(event, rotation);
277
Ray Essick6ce27e52019-02-15 10:58:05 -0800278 int32_t crypto = -1;
Brian Lindahlc935ee22021-06-08 09:57:07 +0200279 if (item->getInt32("android.media.mediacodec.crypto", &crypto)) {
Ray Essick6ce27e52019-02-15 10:58:05 -0800280 metrics_proto.set_crypto(crypto);
281 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200282 AStatsEvent_writeInt32(event, crypto);
Andy Hung5be90c82021-03-30 14:30:20 -0700283
Ray Essick6ce27e52019-02-15 10:58:05 -0800284 int32_t profile = -1;
Brian Lindahlc935ee22021-06-08 09:57:07 +0200285 if (item->getInt32("android.media.mediacodec.profile", &profile)) {
Ray Essick6ce27e52019-02-15 10:58:05 -0800286 metrics_proto.set_profile(profile);
287 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200288 AStatsEvent_writeInt32(event, profile);
Andy Hung5be90c82021-03-30 14:30:20 -0700289
Ray Essick6ce27e52019-02-15 10:58:05 -0800290 int32_t level = -1;
Brian Lindahlc935ee22021-06-08 09:57:07 +0200291 if (item->getInt32("android.media.mediacodec.level", &level)) {
Ray Essick6ce27e52019-02-15 10:58:05 -0800292 metrics_proto.set_level(level);
293 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200294 AStatsEvent_writeInt32(event, level);
295
Andy Hung5be90c82021-03-30 14:30:20 -0700296
Brian Lindahl590e3852023-05-05 15:21:58 -0600297 int32_t maxWidth = -1;
298 if ( item->getInt32("android.media.mediacodec.maxwidth", &maxWidth)) {
299 metrics_proto.set_max_width(maxWidth);
Ray Essick6ce27e52019-02-15 10:58:05 -0800300 }
Brian Lindahl590e3852023-05-05 15:21:58 -0600301 AStatsEvent_writeInt32(event, maxWidth);
Andy Hung5be90c82021-03-30 14:30:20 -0700302
Brian Lindahl590e3852023-05-05 15:21:58 -0600303 int32_t maxHeight = -1;
304 if ( item->getInt32("android.media.mediacodec.maxheight", &maxHeight)) {
305 metrics_proto.set_max_height(maxHeight);
Ray Essick6ce27e52019-02-15 10:58:05 -0800306 }
Brian Lindahl590e3852023-05-05 15:21:58 -0600307 AStatsEvent_writeInt32(event, maxHeight);
Andy Hung5be90c82021-03-30 14:30:20 -0700308
Brian Lindahl590e3852023-05-05 15:21:58 -0600309 int32_t errorCode = -1;
310 if ( item->getInt32("android.media.mediacodec.errcode", &errorCode)) {
311 metrics_proto.set_error_code(errorCode);
Ray Essick6ce27e52019-02-15 10:58:05 -0800312 }
Brian Lindahl590e3852023-05-05 15:21:58 -0600313 AStatsEvent_writeInt32(event, errorCode);
Andy Hung5be90c82021-03-30 14:30:20 -0700314
Brian Lindahl590e3852023-05-05 15:21:58 -0600315 std::string errorState;
316 if ( item->getString("android.media.mediacodec.errstate", &errorState)) {
317 metrics_proto.set_error_state(errorState);
Ray Essick6ce27e52019-02-15 10:58:05 -0800318 }
Brian Lindahl590e3852023-05-05 15:21:58 -0600319 AStatsEvent_writeString(event, errorState.c_str());
Andy Hung5be90c82021-03-30 14:30:20 -0700320
Brian Lindahl590e3852023-05-05 15:21:58 -0600321 int64_t latencyMax = -1;
322 if (item->getInt64("android.media.mediacodec.latency.max", &latencyMax)) {
323 metrics_proto.set_latency_max(latencyMax);
Ray Essick6ce27e52019-02-15 10:58:05 -0800324 }
Brian Lindahl590e3852023-05-05 15:21:58 -0600325 AStatsEvent_writeInt64(event, latencyMax);
Andy Hung5be90c82021-03-30 14:30:20 -0700326
Brian Lindahl590e3852023-05-05 15:21:58 -0600327 int64_t latencyMin = -1;
328 if (item->getInt64("android.media.mediacodec.latency.min", &latencyMin)) {
329 metrics_proto.set_latency_min(latencyMin);
Ray Essick6ce27e52019-02-15 10:58:05 -0800330 }
Brian Lindahl590e3852023-05-05 15:21:58 -0600331 AStatsEvent_writeInt64(event, latencyMin);
Andy Hung5be90c82021-03-30 14:30:20 -0700332
Brian Lindahl590e3852023-05-05 15:21:58 -0600333 int64_t latencyAvg = -1;
334 if (item->getInt64("android.media.mediacodec.latency.avg", &latencyAvg)) {
335 metrics_proto.set_latency_avg(latencyAvg);
Ray Essick6ce27e52019-02-15 10:58:05 -0800336 }
Brian Lindahl590e3852023-05-05 15:21:58 -0600337 AStatsEvent_writeInt64(event, latencyAvg);
Andy Hung5be90c82021-03-30 14:30:20 -0700338
Brian Lindahl590e3852023-05-05 15:21:58 -0600339 int64_t latencyCount = -1;
340 if (item->getInt64("android.media.mediacodec.latency.n", &latencyCount)) {
341 metrics_proto.set_latency_count(latencyCount);
Ray Essick6ce27e52019-02-15 10:58:05 -0800342 }
Brian Lindahl590e3852023-05-05 15:21:58 -0600343 AStatsEvent_writeInt64(event, latencyCount);
Andy Hung5be90c82021-03-30 14:30:20 -0700344
Brian Lindahl590e3852023-05-05 15:21:58 -0600345 int64_t latencyUnknown = -1;
346 if (item->getInt64("android.media.mediacodec.latency.unknown", &latencyUnknown)) {
347 metrics_proto.set_latency_unknown(latencyUnknown);
Ray Essick6ce27e52019-02-15 10:58:05 -0800348 }
Brian Lindahl590e3852023-05-05 15:21:58 -0600349 AStatsEvent_writeInt64(event, latencyUnknown);
Andy Hung5be90c82021-03-30 14:30:20 -0700350
Brian Lindahl590e3852023-05-05 15:21:58 -0600351 int32_t queueSecureInputBufferError = -1;
Andy Hung5be90c82021-03-30 14:30:20 -0700352 if (item->getInt32("android.media.mediacodec.queueSecureInputBufferError",
Brian Lindahl590e3852023-05-05 15:21:58 -0600353 &queueSecureInputBufferError)) {
354 metrics_proto.set_queue_secure_input_buffer_error(queueSecureInputBufferError);
Edwin Wong4f105392020-02-12 14:55:00 -0800355 }
Brian Lindahl590e3852023-05-05 15:21:58 -0600356 AStatsEvent_writeInt32(event, queueSecureInputBufferError);
Andy Hung5be90c82021-03-30 14:30:20 -0700357
Brian Lindahl590e3852023-05-05 15:21:58 -0600358 int32_t queueInputBufferError = -1;
359 if (item->getInt32("android.media.mediacodec.queueInputBufferError", &queueInputBufferError)) {
360 metrics_proto.set_queue_input_buffer_error(queueInputBufferError);
Edwin Wong4f105392020-02-12 14:55:00 -0800361 }
Brian Lindahl590e3852023-05-05 15:21:58 -0600362 AStatsEvent_writeInt32(event, queueInputBufferError);
Ray Essick6ce27e52019-02-15 10:58:05 -0800363
Brian Lindahl590e3852023-05-05 15:21:58 -0600364 std::string bitrateMode;
365 if (item->getString("android.media.mediacodec.bitrate_mode", &bitrateMode)) {
366 metrics_proto.set_bitrate_mode(bitrateMode);
Ray Essicka21a3d32020-05-10 21:08:10 -0700367 }
Brian Lindahl590e3852023-05-05 15:21:58 -0600368 AStatsEvent_writeString(event, bitrateMode.c_str());
Andy Hung5be90c82021-03-30 14:30:20 -0700369
Ray Essicka21a3d32020-05-10 21:08:10 -0700370 int32_t bitrate = -1;
371 if (item->getInt32("android.media.mediacodec.bitrate", &bitrate)) {
372 metrics_proto.set_bitrate(bitrate);
373 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200374 AStatsEvent_writeInt32(event, bitrate);
Andy Hung5be90c82021-03-30 14:30:20 -0700375
Brian Lindahl590e3852023-05-05 15:21:58 -0600376 int64_t lifetimeMillis = -1;
377 if (item->getInt64("android.media.mediacodec.lifetimeMs", &lifetimeMillis)) {
378 lifetimeMillis = mediametrics::bucket_time_minutes(lifetimeMillis);
379 metrics_proto.set_lifetime_millis(lifetimeMillis);
Ray Essicka21a3d32020-05-10 21:08:10 -0700380 }
Brian Lindahl590e3852023-05-05 15:21:58 -0600381 AStatsEvent_writeInt64(event, lifetimeMillis);
Ray Essicka21a3d32020-05-10 21:08:10 -0700382
Brian Lindahl590e3852023-05-05 15:21:58 -0600383 int64_t playbackDurationSec = -1;
384 item->getInt64("android.media.mediacodec.playback-duration-sec", &playbackDurationSec);
Brian Lindahlc935ee22021-06-08 09:57:07 +0200385 // DO NOT record playback-duration in the metrics_proto - it should only
386 // exist in the flattened atom
Brian Lindahl590e3852023-05-05 15:21:58 -0600387 AStatsEvent_writeInt64(event, playbackDurationSec);
Brian Lindahlc935ee22021-06-08 09:57:07 +0200388
389 std::string sessionId;
390 if (item->getString("android.media.mediacodec.log-session-id", &sessionId)) {
Andy Hungc9b6f8b2021-07-08 10:17:55 -0700391 sessionId = mediametrics::ValidateId::get()->validateId(sessionId);
Brian Lindahlc935ee22021-06-08 09:57:07 +0200392 metrics_proto.set_log_session_id(sessionId);
393 }
Ray Essicke5d245f2022-04-06 11:13:34 -0700394 AStatsEvent_writeString(event, sessionId.c_str());
Brian Lindahlc935ee22021-06-08 09:57:07 +0200395
Dichen Zhang0de05752021-04-21 19:47:07 -0700396 int32_t channelCount = -1;
Brian Lindahlc935ee22021-06-08 09:57:07 +0200397 if (item->getInt32("android.media.mediacodec.channelCount", &channelCount)) {
Dichen Zhang0de05752021-04-21 19:47:07 -0700398 metrics_proto.set_channel_count(channelCount);
399 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200400 AStatsEvent_writeInt32(event, channelCount);
Ray Essick87913312021-03-02 10:45:54 -0800401
Dichen Zhang0de05752021-04-21 19:47:07 -0700402 int32_t sampleRate = -1;
Brian Lindahlc935ee22021-06-08 09:57:07 +0200403 if (item->getInt32("android.media.mediacodec.sampleRate", &sampleRate)) {
Dichen Zhang0de05752021-04-21 19:47:07 -0700404 metrics_proto.set_sample_rate(sampleRate);
405 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200406 AStatsEvent_writeInt32(event, sampleRate);
Dichen Zhang0de05752021-04-21 19:47:07 -0700407
Ray Essick87913312021-03-02 10:45:54 -0800408 // TODO PWG may want these fuzzed up a bit to obscure some precision
Dichen Zhang0de05752021-04-21 19:47:07 -0700409 int64_t bytes = -1;
Brian Lindahlc935ee22021-06-08 09:57:07 +0200410 if (item->getInt64("android.media.mediacodec.vencode.bytes", &bytes)) {
Dichen Zhang0de05752021-04-21 19:47:07 -0700411 metrics_proto.set_video_encode_bytes(bytes);
412 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200413 AStatsEvent_writeInt64(event, bytes);
Dichen Zhang0de05752021-04-21 19:47:07 -0700414
Dichen Zhang0de05752021-04-21 19:47:07 -0700415 int64_t frames = -1;
Brian Lindahlc935ee22021-06-08 09:57:07 +0200416 if (item->getInt64("android.media.mediacodec.vencode.frames", &frames)) {
Dichen Zhang0de05752021-04-21 19:47:07 -0700417 metrics_proto.set_video_encode_frames(frames);
418 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200419 AStatsEvent_writeInt64(event, frames);
Dichen Zhang0de05752021-04-21 19:47:07 -0700420
Dichen Zhang0de05752021-04-21 19:47:07 -0700421 int64_t inputBytes = -1;
Brian Lindahlc935ee22021-06-08 09:57:07 +0200422 if (item->getInt64("android.media.mediacodec.video.input.bytes", &inputBytes)) {
Dichen Zhang0de05752021-04-21 19:47:07 -0700423 metrics_proto.set_video_input_bytes(inputBytes);
424 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200425 AStatsEvent_writeInt64(event, inputBytes);
Dichen Zhang0de05752021-04-21 19:47:07 -0700426
Dichen Zhang0de05752021-04-21 19:47:07 -0700427 int64_t inputFrames = -1;
Brian Lindahlc935ee22021-06-08 09:57:07 +0200428 if (item->getInt64("android.media.mediacodec.video.input.frames", &inputFrames)) {
Dichen Zhang0de05752021-04-21 19:47:07 -0700429 metrics_proto.set_video_input_frames(inputFrames);
430 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200431 AStatsEvent_writeInt64(event, inputFrames);
Ray Essick87913312021-03-02 10:45:54 -0800432
Brian Lindahlc935ee22021-06-08 09:57:07 +0200433 int64_t durationUs = -1;
434 if (item->getInt64("android.media.mediacodec.vencode.durationUs", &durationUs)) {
435 metrics_proto.set_video_encode_duration_us(durationUs);
436 }
437 AStatsEvent_writeInt64(event, durationUs);
438
439 int32_t colorFormat = -1;
440 if (item->getInt32("android.media.mediacodec.color-format", &colorFormat)) {
441 metrics_proto.set_color_format(colorFormat);
442 }
443 AStatsEvent_writeInt32(event, colorFormat);
444
445 double frameRate = -1.0;
446 if (item->getDouble("android.media.mediacodec.frame-rate", &frameRate)) {
447 metrics_proto.set_frame_rate(frameRate);
448 }
449 AStatsEvent_writeFloat(event, (float) frameRate);
450
451 double captureRate = -1.0;
452 if (item->getDouble("android.media.mediacodec.capture-rate", &captureRate)) {
453 metrics_proto.set_capture_rate(captureRate);
454 }
455 AStatsEvent_writeFloat(event, (float) captureRate);
456
457 double operatingRate = -1.0;
458 if (item->getDouble("android.media.mediacodec.operating-rate", &operatingRate)) {
459 metrics_proto.set_operating_rate(operatingRate);
460 }
461 AStatsEvent_writeFloat(event, (float) operatingRate);
462
463 int32_t priority = -1;
464 if (item->getInt32("android.media.mediacodec.priority", &priority)) {
465 metrics_proto.set_priority(priority);
466 }
467 AStatsEvent_writeInt32(event, priority);
468
469 int32_t qpIMin = -1;
470 if (item->getInt32("android.media.mediacodec.video-qp-i-min", &qpIMin)) {
471 metrics_proto.set_video_qp_i_min(qpIMin);
472 }
473 AStatsEvent_writeInt32(event, qpIMin);
474
475 int32_t qpIMax = -1;
476 if (item->getInt32("android.media.mediacodec.video-qp-i-max", &qpIMax)) {
477 metrics_proto.set_video_qp_i_max(qpIMax);
478 }
479 AStatsEvent_writeInt32(event, qpIMax);
480
481 int32_t qpPMin = -1;
482 if (item->getInt32("android.media.mediacodec.video-qp-p-min", &qpPMin)) {
483 metrics_proto.set_video_qp_p_min(qpPMin);
484 }
485 AStatsEvent_writeInt32(event, qpPMin);
486
487 int32_t qpPMax = -1;
488 if (item->getInt32("android.media.mediacodec.video-qp-p-max", &qpPMax)) {
489 metrics_proto.set_video_qp_p_max(qpPMax);
490 }
491 AStatsEvent_writeInt32(event, qpPMax);
492
493 int32_t qpBMin = -1;
494 if (item->getInt32("android.media.mediacodec.video-qp-b-min", &qpBMin)) {
495 metrics_proto.set_video_qp_b_min(qpBMin);
496 }
497 AStatsEvent_writeInt32(event, qpBMin);
498
499 int32_t qpBMax = -1;
500 if (item->getInt32("android.media.mediacodec.video-qp-b-max", &qpBMax)) {
501 metrics_proto.set_video_qp_b_max(qpBMax);
502 }
503 AStatsEvent_writeInt32(event, qpBMax);
504
Dichen Zhange5bad782021-04-28 12:11:35 -0700505 int32_t originalBitrate = -1;
Brian Lindahlc935ee22021-06-08 09:57:07 +0200506 if (item->getInt32("android.media.mediacodec.original.bitrate", &originalBitrate)) {
Dichen Zhange5bad782021-04-28 12:11:35 -0700507 metrics_proto.set_original_bitrate(originalBitrate);
508 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200509 AStatsEvent_writeInt32(event, originalBitrate);
Dichen Zhange5bad782021-04-28 12:11:35 -0700510
Dichen Zhang57be6302021-05-18 18:20:31 -0700511 int32_t shapingEnhanced = -1;
512 if ( item->getInt32("android.media.mediacodec.shaped", &shapingEnhanced)) {
513 metrics_proto.set_shaping_enhanced(shapingEnhanced);
514 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200515 AStatsEvent_writeInt32(event, shapingEnhanced);
Dichen Zhang57be6302021-05-18 18:20:31 -0700516
Dichen Zhang57be6302021-05-18 18:20:31 -0700517 int32_t qpIMinOri = -1;
518 if ( item->getInt32("android.media.mediacodec.original-video-qp-i-min", &qpIMinOri)) {
519 metrics_proto.set_original_video_qp_i_min(qpIMinOri);
520 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200521 AStatsEvent_writeInt32(event, qpIMinOri);
Dichen Zhang57be6302021-05-18 18:20:31 -0700522
Dichen Zhang57be6302021-05-18 18:20:31 -0700523 int32_t qpIMaxOri = -1;
524 if ( item->getInt32("android.media.mediacodec.original-video-qp-i-max", &qpIMaxOri)) {
525 metrics_proto.set_original_video_qp_i_max(qpIMaxOri);
526 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200527 AStatsEvent_writeInt32(event, qpIMaxOri);
Dichen Zhang57be6302021-05-18 18:20:31 -0700528
Dichen Zhang57be6302021-05-18 18:20:31 -0700529 int32_t qpPMinOri = -1;
530 if ( item->getInt32("android.media.mediacodec.original-video-qp-p-min", &qpPMinOri)) {
531 metrics_proto.set_original_video_qp_p_min(qpPMinOri);
532 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200533 AStatsEvent_writeInt32(event, qpPMinOri);
Dichen Zhang57be6302021-05-18 18:20:31 -0700534
Dichen Zhang57be6302021-05-18 18:20:31 -0700535 int32_t qpPMaxOri = -1;
536 if ( item->getInt32("android.media.mediacodec.original-video-qp-p-max", &qpPMaxOri)) {
537 metrics_proto.set_original_video_qp_p_max(qpPMaxOri);
538 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200539 AStatsEvent_writeInt32(event, qpPMaxOri);
Dichen Zhang57be6302021-05-18 18:20:31 -0700540
Dichen Zhang57be6302021-05-18 18:20:31 -0700541 int32_t qpBMinOri = -1;
542 if ( item->getInt32("android.media.mediacodec.original-video-qp-b-min", &qpBMinOri)) {
Brian Lindahlc935ee22021-06-08 09:57:07 +0200543 metrics_proto.set_original_video_qp_b_min(qpBMinOri);
Dichen Zhang57be6302021-05-18 18:20:31 -0700544 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200545 AStatsEvent_writeInt32(event, qpBMinOri);
Dichen Zhang57be6302021-05-18 18:20:31 -0700546
Dichen Zhang57be6302021-05-18 18:20:31 -0700547 int32_t qpBMaxOri = -1;
548 if ( item->getInt32("android.media.mediacodec.original-video-qp-b-max", &qpBMaxOri)) {
549 metrics_proto.set_original_video_qp_b_max(qpBMaxOri);
550 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200551 AStatsEvent_writeInt32(event, qpBMaxOri);
552
Songyue Han4c1e5372022-04-13 21:11:23 +0000553 int32_t configColorStandard = -1;
554 if (item->getInt32("android.media.mediacodec.config-color-standard", &configColorStandard)) {
555 metrics_proto.set_config_color_standard(configColorStandard);
556 }
557 AStatsEvent_writeInt32(event, configColorStandard);
Songyue Han3be67f22022-01-20 22:04:10 +0000558
Songyue Han4c1e5372022-04-13 21:11:23 +0000559 int32_t configColorRange = -1;
560 if (item->getInt32("android.media.mediacodec.config-color-range", &configColorRange)) {
561 metrics_proto.set_config_color_range(configColorRange);
562 }
563 AStatsEvent_writeInt32(event, configColorRange);
Songyue Han3be67f22022-01-20 22:04:10 +0000564
Songyue Han4c1e5372022-04-13 21:11:23 +0000565 int32_t configColorTransfer = -1;
566 if (item->getInt32("android.media.mediacodec.config-color-transfer", &configColorTransfer)) {
567 metrics_proto.set_config_color_transfer(configColorTransfer);
568 }
569 AStatsEvent_writeInt32(event, configColorTransfer);
Songyue Han3be67f22022-01-20 22:04:10 +0000570
Songyue Han4c1e5372022-04-13 21:11:23 +0000571 int32_t parsedColorStandard = -1;
572 if (item->getInt32("android.media.mediacodec.parsed-color-standard", &parsedColorStandard)) {
573 metrics_proto.set_parsed_color_standard(parsedColorStandard);
574 }
575 AStatsEvent_writeInt32(event, parsedColorStandard);
Songyue Han3be67f22022-01-20 22:04:10 +0000576
Songyue Han4c1e5372022-04-13 21:11:23 +0000577 int32_t parsedColorRange = -1;
578 if (item->getInt32("android.media.mediacodec.parsed-color-range", &parsedColorRange)) {
579 metrics_proto.set_parsed_color_range(parsedColorRange);
580 }
581 AStatsEvent_writeInt32(event, parsedColorRange);
Songyue Han3be67f22022-01-20 22:04:10 +0000582
Songyue Han4c1e5372022-04-13 21:11:23 +0000583 int32_t parsedColorTransfer = -1;
584 if (item->getInt32("android.media.mediacodec.parsed-color-transfer", &parsedColorTransfer)) {
585 metrics_proto.set_parsed_color_transfer(parsedColorTransfer);
586 }
587 AStatsEvent_writeInt32(event, parsedColorTransfer);
Songyue Han3be67f22022-01-20 22:04:10 +0000588
Songyue Han4c1e5372022-04-13 21:11:23 +0000589 int32_t hdrStaticInfo = -1;
590 if (item->getInt32("android.media.mediacodec.hdr-static-info", &hdrStaticInfo)) {
591 metrics_proto.set_hdr_static_info(hdrStaticInfo);
592 }
593 AStatsEvent_writeInt32(event, hdrStaticInfo);
594
595 int32_t hdr10PlusInfo = -1;
596 if (item->getInt32("android.media.mediacodec.hdr10-plus-info", &hdr10PlusInfo)) {
597 metrics_proto.set_hdr10_plus_info(hdr10PlusInfo);
598 }
599 AStatsEvent_writeInt32(event, hdr10PlusInfo);
600
Songyue Han6dc32102023-01-04 21:42:52 +0000601 int32_t hdrFormat = -1;
Songyue Han4c1e5372022-04-13 21:11:23 +0000602 if (item->getInt32("android.media.mediacodec.hdr-format", &hdrFormat)) {
603 metrics_proto.set_hdr_format(hdrFormat);
604 }
605 AStatsEvent_writeInt32(event, hdrFormat);
Songyue Han3be67f22022-01-20 22:04:10 +0000606
Girish4e531c82023-02-17 00:36:29 +0000607 int64_t codecId = 0;
608 if (item->getInt64("android.media.mediacodec.id", &codecId)) {
609 metrics_proto.set_codec_id(codecId);
610 }
611 AStatsEvent_writeInt64(event, codecId);
612
Songyue Han6dc32102023-01-04 21:42:52 +0000613 int32_t arrayMode = -1;
614 if (item->getInt32("android.media.mediacodec.array-mode", &arrayMode)) {
615 metrics_proto.set_array_mode(arrayMode);
616 }
617 AStatsEvent_writeInt32(event, arrayMode);
618
619 int32_t operationMode = -1;
620 if (item->getInt32("android.media.mediacodec.operation-mode", &operationMode)) {
621 metrics_proto.set_operation_mode(operationMode);
622 }
623 AStatsEvent_writeInt32(event, operationMode);
624
625 int32_t outputSurface = -1;
626 if (item->getInt32("android.media.mediacodec.output-surface", &outputSurface)) {
627 metrics_proto.set_output_surface(outputSurface);
628 }
629 AStatsEvent_writeInt32(event, outputSurface);
630
631 int32_t appMaxInputSize = -1;
632 if (item->getInt32("android.media.mediacodec.app-max-input-size", &appMaxInputSize)) {
633 metrics_proto.set_app_max_input_size(appMaxInputSize);
634 }
635 AStatsEvent_writeInt32(event, appMaxInputSize);
636
637 int32_t usedMaxInputSize = -1;
638 if (item->getInt32("android.media.mediacodec.used-max-input-size", &usedMaxInputSize)) {
639 metrics_proto.set_used_max_input_size(usedMaxInputSize);
640 }
641 AStatsEvent_writeInt32(event, usedMaxInputSize);
642
643 int32_t codecMaxInputSize = -1;
644 if (item->getInt32("android.media.mediacodec.codec-max-input-size", &codecMaxInputSize)) {
645 metrics_proto.set_codec_max_input_size(codecMaxInputSize);
646 }
647 AStatsEvent_writeInt32(event, codecMaxInputSize);
648
649 int32_t flushCount = -1;
650 if (item->getInt32("android.media.mediacodec.flush-count", &flushCount)) {
651 metrics_proto.set_flush_count(flushCount);
652 }
653 AStatsEvent_writeInt32(event, flushCount);
654
655 int32_t setSurfaceCount = -1;
656 if (item->getInt32("android.media.mediacodec.set-surface-count", &setSurfaceCount)) {
657 metrics_proto.set_set_surface_count(setSurfaceCount);
658 }
659 AStatsEvent_writeInt32(event, setSurfaceCount);
660
661 int32_t resolutionChangeCount = -1;
662 if (item->getInt32("android.media.mediacodec.resolution-change-count",
663 &resolutionChangeCount)) {
664 metrics_proto.set_resolution_change_count(resolutionChangeCount);
665 }
666 AStatsEvent_writeInt32(event, resolutionChangeCount);
667
Brian Lindahl590e3852023-05-05 15:21:58 -0600668 int64_t firstRenderTimeUs = -1;
669 item->getInt64("android.media.mediacodec.first-render-time-us", &firstRenderTimeUs);
670 int64_t framesReleased = -1;
671 item->getInt64("android.media.mediacodec.frames-released", &framesReleased);
672 int64_t framesRendered = -1;
673 item->getInt64("android.media.mediacodec.frames-rendered", &framesRendered);
674 int64_t framesDropped = -1;
675 item->getInt64("android.media.mediacodec.frames-dropped", &framesDropped);
676 int64_t framesSkipped = -1;
677 item->getInt64("android.media.mediacodec.frames-skipped", &framesSkipped);
678 double framerateContent = -1;
679 item->getDouble("android.media.mediacodec.framerate-content", &framerateContent);
680 double framerateActual = -1;
681 item->getDouble("android.media.mediacodec.framerate-actual", &framerateActual);
682 int64_t freezeScore = -1;
683 item->getInt64("android.media.mediacodec.freeze-score", &freezeScore);
684 double freezeRate = -1;
685 item->getDouble("android.media.mediacodec.freeze-rate", &freezeRate);
686 std::string freezeScoreHistogramStr;
687 item->getString("android.media.mediacodec.freeze-score-histogram", &freezeScoreHistogramStr);
688 std::string freezeScoreHistogramBucketsStr;
689 item->getString("android.media.mediacodec.freeze-score-histogram-buckets",
690 &freezeScoreHistogramBucketsStr);
691 std::string freezeDurationMsHistogramStr;
692 item->getString("android.media.mediacodec.freeze-duration-ms-histogram",
693 &freezeDurationMsHistogramStr);
694 std::string freezeDurationMsHistogramBucketsStr;
695 item->getString("android.media.mediacodec.freeze-duration-ms-histogram-buckets",
696 &freezeDurationMsHistogramBucketsStr);
697 std::string freezeDistanceMsHistogramStr;
698 item->getString("android.media.mediacodec.freeze-distance-ms-histogram",
699 &freezeDistanceMsHistogramStr);
700 std::string freezeDistanceMsHistogramBucketsStr;
701 item->getString("android.media.mediacodec.freeze-distance-ms-histogram-buckets",
702 &freezeDistanceMsHistogramBucketsStr);
703 int64_t judderScore = -1;
704 item->getInt64("android.media.mediacodec.judder-score", &judderScore);
705 double judderRate = -1;
706 item->getDouble("android.media.mediacodec.judder-rate", &judderRate);
707 std::string judderScoreHistogramStr;
708 item->getString("android.media.mediacodec.judder-score-histogram", &judderScoreHistogramStr);
709 std::string judderScoreHistogramBucketsStr;
710 item->getString("android.media.mediacodec.judder-score-histogram-buckets",
711 &judderScoreHistogramBucketsStr);
712
Brian Lindahlc935ee22021-06-08 09:57:07 +0200713 int err = AStatsEvent_write(event);
714 if (err < 0) {
715 ALOGE("Failed to write codec metrics to statsd (%d)", err);
716 }
717 AStatsEvent_release(event);
Dichen Zhang57be6302021-05-18 18:20:31 -0700718
Brian Lindahl590e3852023-05-05 15:21:58 -0600719 if (framesRendered > 0) {
720 int32_t statsUid = item->getUid();
721 int64_t statsCodecId = codecId;
722 char const *statsLogSessionId = sessionId.c_str();
723 int32_t statsIsHardware = isHardware;
724 int32_t statsIsSecure = isSecure;
725 int32_t statsIsTunneled = isTunneled;
726 int32_t statsCodec = getMetricsCodecEnum(mime, codec);
727 int32_t statsResolution = getMetricsResolutionEnum(width, height);
728 int32_t statsBitrate = BITRATE_UNKNOWN;
729 int32_t statsContentFramerate = getMetricsFramerateEnum(framerateContent);
730 int32_t statsActualFramerate = getMetricsFramerateEnum(framerateActual);
731 int32_t statsHdrFormat = getMetricsHdrFormatEnum(mime, codec, configColorTransfer,
732 parsedColorTransfer, hdrStaticInfo,
733 hdr10PlusInfo);
734 int64_t statsFirstRenderTimeUs = firstRenderTimeUs;
735 int64_t statsPlaybackDurationSeconds = playbackDurationSec;
736 int64_t statsFramesTotal = framesReleased + framesSkipped;
737 int64_t statsFramesReleased = framesReleased;
738 int64_t statsFramesRendered = framesRendered;
739 int64_t statsFramesDropped = framesDropped;
740 int64_t statsFramesSkipped = framesSkipped;
741 float statsFrameDropRate = float(double(framesDropped) / statsFramesTotal);
742 float statsFrameSkipRate = float(double(framesSkipped) / statsFramesTotal);
743 float statsFrameSkipDropRate = float(double(framesSkipped + framesDropped) /
744 statsFramesTotal);
745 int64_t statsFreezeScore = freezeScore;
746 float statsFreezeRate = freezeRate;
747 std::vector<int32_t> statsFreezeDurationMsHistogram;
748 parseVector(freezeDurationMsHistogramStr, &statsFreezeDurationMsHistogram);
749 std::vector<int32_t> statsFreezeDurationMsHistogramBuckets;
750 parseVector(freezeDurationMsHistogramBucketsStr, &statsFreezeDurationMsHistogramBuckets);
751 std::vector<int32_t> statsFreezeDistanceMsHistogram;
752 parseVector(freezeDistanceMsHistogramStr, &statsFreezeDistanceMsHistogram);
753 std::vector<int32_t> statsFreezeDistanceMsHistogramBuckets;
754 parseVector(freezeDistanceMsHistogramBucketsStr, &statsFreezeDistanceMsHistogramBuckets);
755 int64_t statsJudderScore = judderScore;
756 float statsJudderRate = judderRate;
757 std::vector<int32_t> statsJudderScoreHistogram;
758 parseVector(judderScoreHistogramStr, &statsJudderScoreHistogram);
759 std::vector<int32_t> statsJudderScoreHistogramBuckets;
760 parseVector(judderScoreHistogramBucketsStr, &statsJudderScoreHistogramBuckets);
761 int result = stats_write(
762 MEDIA_CODEC_RENDERED,
763 statsUid,
764 statsCodecId,
765 statsLogSessionId,
766 statsIsHardware,
767 statsIsSecure,
768 statsIsTunneled,
769 statsCodec,
770 statsResolution,
771 statsBitrate,
772 statsContentFramerate,
773 statsActualFramerate,
774 statsHdrFormat,
775 statsFirstRenderTimeUs,
776 statsPlaybackDurationSeconds,
777 statsFramesTotal,
778 statsFramesReleased,
779 statsFramesRendered,
780 statsFramesDropped,
781 statsFramesSkipped,
782 statsFrameDropRate,
783 statsFrameSkipRate,
784 statsFrameSkipDropRate,
785 statsFreezeScore,
786 statsFreezeRate,
787 statsFreezeDurationMsHistogram,
788 statsFreezeDurationMsHistogramBuckets,
789 statsFreezeDistanceMsHistogram,
790 statsFreezeDistanceMsHistogramBuckets,
791 statsJudderScore,
792 statsJudderRate,
793 statsJudderScoreHistogram,
794 statsJudderScoreHistogramBuckets);
795 ALOGE_IF(result < 0, "Failed to record MEDIA_CODEC_RENDERED atom (%d)", result);
796 }
797
Ray Essick6ce27e52019-02-15 10:58:05 -0800798 std::string serialized;
799 if (!metrics_proto.SerializeToString(&serialized)) {
800 ALOGE("Failed to serialize codec metrics");
801 return false;
802 }
Brian Lindahl590e3852023-05-05 15:21:58 -0600803 const stats::media_metrics::BytesField bf_serialized(serialized.c_str(), serialized.size());
Vova Sharaienkof58455a2022-09-24 01:47:23 +0000804 const int result = stats::media_metrics::stats_write(stats::media_metrics::MEDIAMETRICS_CODEC_REPORTED,
Brian Lindahl590e3852023-05-05 15:21:58 -0600805 timestampNanos, packageName.c_str(), packageVersionCode,
806 mediaApexVersion,
Andy Hung5be90c82021-03-30 14:30:20 -0700807 bf_serialized);
Brian Lindahlc935ee22021-06-08 09:57:07 +0200808
Andy Hung5be90c82021-03-30 14:30:20 -0700809 std::stringstream log;
810 log << "result:" << result << " {"
811 << " mediametrics_codec_reported:"
Vova Sharaienkof58455a2022-09-24 01:47:23 +0000812 << stats::media_metrics::MEDIAMETRICS_CODEC_REPORTED
Brian Lindahl590e3852023-05-05 15:21:58 -0600813 << " timestamp_nanos:" << timestampNanos
814 << " package_name:" << packageName
815 << " package_version_code:" << packageVersionCode
816 << " media_apex_version:" << mediaApexVersion
Andy Hung5be90c82021-03-30 14:30:20 -0700817 << " codec:" << codec
818 << " mime:" << mime
819 << " mode:" << mode
Brian Lindahl590e3852023-05-05 15:21:58 -0600820 << " encoder:" << isEncoder
821 << " secure:" << isSecure
Andy Hung5be90c82021-03-30 14:30:20 -0700822 << " width:" << width
823 << " height:" << height
824 << " rotation:" << rotation
825 << " crypto:" << crypto
826 << " profile:" << profile
Andy Hung5be90c82021-03-30 14:30:20 -0700827 << " level:" << level
Brian Lindahl590e3852023-05-05 15:21:58 -0600828 << " max_width:" << maxWidth
829 << " max_height:" << maxHeight
830 << " error_code:" << errorCode
831 << " error_state:" << errorState
832 << " latency_max:" << latencyMax
833 << " latency_min:" << latencyMin
834 << " latency_avg:" << latencyAvg
835 << " latency_count:" << latencyCount
836 << " latency_unknown:" << latencyUnknown
837 << " queue_input_buffer_error:" << queueInputBufferError
838 << " queue_secure_input_buffer_error:" << queueSecureInputBufferError
839 << " bitrate_mode:" << bitrateMode
Andy Hung5be90c82021-03-30 14:30:20 -0700840 << " bitrate:" << bitrate
Dichen Zhang57be6302021-05-18 18:20:31 -0700841 << " original_bitrate:" << originalBitrate
Brian Lindahl590e3852023-05-05 15:21:58 -0600842 << " lifetime_millis:" << lifetimeMillis
843 << " playback_duration_seconds:" << playbackDurationSec
Dichen Zhang57be6302021-05-18 18:20:31 -0700844 << " log_session_id:" << sessionId
845 << " channel_count:" << channelCount
846 << " sample_rate:" << sampleRate
847 << " encode_bytes:" << bytes
848 << " encode_frames:" << frames
849 << " encode_duration_us:" << durationUs
850 << " color_format:" << colorFormat
851 << " frame_rate:" << frameRate
852 << " capture_rate:" << captureRate
853 << " operating_rate:" << operatingRate
854 << " priority:" << priority
855 << " shaping_enhanced:" << shapingEnhanced
Dichen Zhang57be6302021-05-18 18:20:31 -0700856 << " qp_i_min:" << qpIMin
857 << " qp_i_max:" << qpIMax
858 << " qp_p_min:" << qpPMin
859 << " qp_p_max:" << qpPMax
860 << " qp_b_min:" << qpBMin
861 << " qp_b_max:" << qpBMax
862 << " original_qp_i_min:" << qpIMinOri
863 << " original_qp_i_max:" << qpIMaxOri
864 << " original_qp_p_min:" << qpPMinOri
865 << " original_qp_p_max:" << qpPMaxOri
866 << " original_qp_b_min:" << qpBMinOri
867 << " original_qp_b_max:" << qpBMaxOri
Andy Hung5be90c82021-03-30 14:30:20 -0700868 << " }";
Vova Sharaienkof58455a2022-09-24 01:47:23 +0000869 statsdLog->log(stats::media_metrics::MEDIAMETRICS_CODEC_REPORTED, log.str());
Brian Lindahlc935ee22021-06-08 09:57:07 +0200870
871
Ray Essick6ce27e52019-02-15 10:58:05 -0800872 return true;
873}
874
Andy Hung3ab1b322020-05-18 10:47:31 -0700875} // namespace android