blob: ad4cfce59029b435a9c148545928857652aa9e8e [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>
Brian Lindahl778b15a2023-05-13 07:42:13 -060026#include <string>
Ray Essick6ce27e52019-02-15 10:58:05 -080027#include <string.h>
28#include <sys/stat.h>
29#include <sys/time.h>
30#include <sys/types.h>
31#include <unistd.h>
32
Vova Sharaienkof58455a2022-09-24 01:47:23 +000033#include <stats_media_metrics.h>
Brian Lindahlc935ee22021-06-08 09:57:07 +020034#include <stats_event.h>
Ray Essick6ce27e52019-02-15 10:58:05 -080035
Brian Lindahl778b15a2023-05-13 07:42:13 -060036#include <frameworks/proto_logging/stats/message/mediametrics_message.pb.h>
37#include <mediametricsservice/cleaner.h>
38#include <mediametricsservice/iface_statsd.h>
39#include <mediametricsservice/MediaMetricsService.h>
40#include <mediametricsservice/StringUtils.h>
41#include <mediametricsservice/ValidateId.h>
Ray Essick6ce27e52019-02-15 10:58:05 -080042
43namespace android {
44
Brian Lindahl590e3852023-05-05 15:21:58 -060045using stats::media_metrics::stats_write;
46using stats::media_metrics::MEDIA_CODEC_RENDERED;
47using stats::media_metrics::MEDIA_CODEC_RENDERED__CODEC__CODEC_UNKNOWN;
48using stats::media_metrics::MEDIA_CODEC_RENDERED__RESOLUTION__RESOLUTION_INVALID;
49using stats::media_metrics::MEDIA_CODEC_RENDERED__RESOLUTION__RESOLUTION_ZERO;
50using stats::media_metrics::MEDIA_CODEC_RENDERED__CONTENT_FRAMERATE__FRAMERATE_UNKNOWN;
51using stats::media_metrics::MEDIA_CODEC_RENDERED__CONTENT_FRAMERATE__FRAMERATE_UNDETERMINED;
52using stats::media_metrics::MEDIA_CODEC_RENDERED__CONTENT_FRAMERATE__FRAMERATE_24_3_2_PULLDOWN;
53using stats::media_metrics::MEDIA_CODEC_RENDERED__HDR_FORMAT__HDR_FORMAT_NONE;
54using stats::media_metrics::MEDIA_CODEC_RENDERED__HDR_FORMAT__HDR_FORMAT_HLG;
55using stats::media_metrics::MEDIA_CODEC_RENDERED__HDR_FORMAT__HDR_FORMAT_HDR10;
56using stats::media_metrics::MEDIA_CODEC_RENDERED__HDR_FORMAT__HDR_FORMAT_HDR10_PLUS;
57using stats::media_metrics::MEDIA_CODEC_RENDERED__HDR_FORMAT__HDR_FORMAT_DOLBY_VISION;
58
59static const int BITRATE_UNKNOWN =
60 stats::media_metrics::MEDIA_CODEC_RENDERED__BITRATE__BITRATE_UNKNOWN;
61
62static const std::pair<char const *, int> CODEC_LOOKUP[] = {
63 { "avc", stats::media_metrics::MEDIA_CODEC_RENDERED__CODEC__CODEC_AVC },
64 { "h264", stats::media_metrics::MEDIA_CODEC_RENDERED__CODEC__CODEC_AVC },
65 { "hevc", stats::media_metrics::MEDIA_CODEC_RENDERED__CODEC__CODEC_HEVC },
66 { "h265", stats::media_metrics::MEDIA_CODEC_RENDERED__CODEC__CODEC_HEVC },
67 { "vp8", stats::media_metrics::MEDIA_CODEC_RENDERED__CODEC__CODEC_VP8 },
68 { "vp9", stats::media_metrics::MEDIA_CODEC_RENDERED__CODEC__CODEC_VP9 },
69 { "av1", stats::media_metrics::MEDIA_CODEC_RENDERED__CODEC__CODEC_AV1 },
70 { "av01", stats::media_metrics::MEDIA_CODEC_RENDERED__CODEC__CODEC_AV1 },
71 { "dolby-vision", stats::media_metrics::MEDIA_CODEC_RENDERED__CODEC__CODEC_HEVC },
72};
73
74static const int32_t RESOLUTION_LOOKUP[] = {
75 stats::media_metrics::MEDIA_CODEC_RENDERED__RESOLUTION__RESOLUTION_MAX_SIZE,
76 stats::media_metrics::MEDIA_CODEC_RENDERED__RESOLUTION__RESOLUTION_32K,
77 stats::media_metrics::MEDIA_CODEC_RENDERED__RESOLUTION__RESOLUTION_16K,
78 stats::media_metrics::MEDIA_CODEC_RENDERED__RESOLUTION__RESOLUTION_8K_UHD,
79 stats::media_metrics::MEDIA_CODEC_RENDERED__RESOLUTION__RESOLUTION_8K_UHD_ALMOST,
80 stats::media_metrics::MEDIA_CODEC_RENDERED__RESOLUTION__RESOLUTION_4K_UHD_ALMOST,
81 stats::media_metrics::MEDIA_CODEC_RENDERED__RESOLUTION__RESOLUTION_1440X2560,
82 stats::media_metrics::MEDIA_CODEC_RENDERED__RESOLUTION__RESOLUTION_1080X2400,
83 stats::media_metrics::MEDIA_CODEC_RENDERED__RESOLUTION__RESOLUTION_1080X2340,
84 stats::media_metrics::MEDIA_CODEC_RENDERED__RESOLUTION__RESOLUTION_1080P_FHD,
85 stats::media_metrics::MEDIA_CODEC_RENDERED__RESOLUTION__RESOLUTION_1080P_FHD_ALMOST,
86 stats::media_metrics::MEDIA_CODEC_RENDERED__RESOLUTION__RESOLUTION_720P_HD,
87 stats::media_metrics::MEDIA_CODEC_RENDERED__RESOLUTION__RESOLUTION_720P_HD_ALMOST,
88 stats::media_metrics::MEDIA_CODEC_RENDERED__RESOLUTION__RESOLUTION_576X1024,
89 stats::media_metrics::MEDIA_CODEC_RENDERED__RESOLUTION__RESOLUTION_540X960,
90 stats::media_metrics::MEDIA_CODEC_RENDERED__RESOLUTION__RESOLUTION_480X854,
91 stats::media_metrics::MEDIA_CODEC_RENDERED__RESOLUTION__RESOLUTION_480X640,
92 stats::media_metrics::MEDIA_CODEC_RENDERED__RESOLUTION__RESOLUTION_360X640,
93 stats::media_metrics::MEDIA_CODEC_RENDERED__RESOLUTION__RESOLUTION_352X640,
94 stats::media_metrics::MEDIA_CODEC_RENDERED__RESOLUTION__RESOLUTION_VERY_LOW,
95 stats::media_metrics::MEDIA_CODEC_RENDERED__RESOLUTION__RESOLUTION_SMALLEST,
96 stats::media_metrics::MEDIA_CODEC_RENDERED__RESOLUTION__RESOLUTION_ZERO,
97};
98
99static const int32_t FRAMERATE_LOOKUP[] = {
100 stats::media_metrics::MEDIA_CODEC_RENDERED__CONTENT_FRAMERATE__FRAMERATE_24,
101 stats::media_metrics::MEDIA_CODEC_RENDERED__CONTENT_FRAMERATE__FRAMERATE_25,
102 stats::media_metrics::MEDIA_CODEC_RENDERED__CONTENT_FRAMERATE__FRAMERATE_30,
103 stats::media_metrics::MEDIA_CODEC_RENDERED__CONTENT_FRAMERATE__FRAMERATE_50,
104 stats::media_metrics::MEDIA_CODEC_RENDERED__CONTENT_FRAMERATE__FRAMERATE_60,
105 stats::media_metrics::MEDIA_CODEC_RENDERED__CONTENT_FRAMERATE__FRAMERATE_120,
106};
107
108static int32_t getMetricsCodecEnum(const std::string &mime, const std::string &componentName) {
109 for (const auto & codecStrAndEnum : CODEC_LOOKUP) {
110 if (strcasestr(mime.c_str(), codecStrAndEnum.first) != nullptr ||
111 strcasestr(componentName.c_str(), codecStrAndEnum.first) != nullptr) {
112 return codecStrAndEnum.second;
113 }
114 }
115 return MEDIA_CODEC_RENDERED__CODEC__CODEC_UNKNOWN;
116}
117
118static int32_t getMetricsResolutionEnum(int32_t width, int32_t height) {
119 if (width == 0 || height == 0) {
120 return MEDIA_CODEC_RENDERED__RESOLUTION__RESOLUTION_ZERO;
121 }
122 int64_t pixels = int64_t(width) * height / 1000;
123 if (width < 0 || height < 0 || pixels > RESOLUTION_LOOKUP[0]) {
124 return MEDIA_CODEC_RENDERED__RESOLUTION__RESOLUTION_INVALID;
125 }
126 for (int32_t resolutionEnum : RESOLUTION_LOOKUP) {
127 if (pixels > resolutionEnum) {
128 return resolutionEnum;
129 }
130 }
131 return MEDIA_CODEC_RENDERED__RESOLUTION__RESOLUTION_ZERO;
132}
133
134static int32_t getMetricsFramerateEnum(float inFramerate) {
135 if (inFramerate == -1.0f) {
136 return MEDIA_CODEC_RENDERED__CONTENT_FRAMERATE__FRAMERATE_UNDETERMINED;
137 }
138 if (inFramerate == -2.0f) {
139 return MEDIA_CODEC_RENDERED__CONTENT_FRAMERATE__FRAMERATE_24_3_2_PULLDOWN;
140 }
141 int framerate = int(inFramerate * 100); // Table is in hundredths of frames per second
142 static const int framerateTolerance = 40; // Tolerance is 0.4 frames per second - table is 100s
143 for (int32_t framerateEnum : FRAMERATE_LOOKUP) {
144 if (abs(framerate - framerateEnum) < framerateTolerance) {
145 return framerateEnum;
146 }
147 }
148 return MEDIA_CODEC_RENDERED__CONTENT_FRAMERATE__FRAMERATE_UNKNOWN;
149}
150
151static int32_t getMetricsHdrFormatEnum(std::string &mime, std::string &componentName,
152 int32_t configColorTransfer, int32_t parsedColorTransfer,
153 int32_t hdr10StaticInfo, int32_t hdr10PlusInfo) {
154 if (hdr10PlusInfo) {
155 return MEDIA_CODEC_RENDERED__HDR_FORMAT__HDR_FORMAT_HDR10_PLUS;
156 }
157 if (hdr10StaticInfo) {
158 return MEDIA_CODEC_RENDERED__HDR_FORMAT__HDR_FORMAT_HDR10;
159 }
160 // 7 = COLOR_TRANSFER_HLG in MediaCodecConstants.h
161 if (configColorTransfer == 7 || parsedColorTransfer == 7) {
162 return MEDIA_CODEC_RENDERED__HDR_FORMAT__HDR_FORMAT_HLG;
163 }
164 if (strcasestr(mime.c_str(), "dolby-vision") != nullptr ||
165 strcasestr(componentName.c_str(), "dvhe") != nullptr ||
166 strcasestr(componentName.c_str(), "dvav") != nullptr ||
167 strcasestr(componentName.c_str(), "dav1") != nullptr) {
168 return MEDIA_CODEC_RENDERED__HDR_FORMAT__HDR_FORMAT_DOLBY_VISION;
169 }
170 return MEDIA_CODEC_RENDERED__HDR_FORMAT__HDR_FORMAT_NONE;
171}
172
173static void parseVector(const std::string &str, std::vector<int32_t> *vector) {
Brian Lindahl778b15a2023-05-13 07:42:13 -0600174 if (!mediametrics::stringutils::parseVector(str, vector)) {
175 ALOGE("failed to parse integer vector from '%s'", str.c_str());
Brian Lindahl590e3852023-05-05 15:21:58 -0600176 }
177}
178
Andy Hung5be90c82021-03-30 14:30:20 -0700179bool statsd_codec(const std::shared_ptr<const mediametrics::Item>& item,
180 const std::shared_ptr<mediametrics::StatsdLog>& statsdLog)
Ray Essick6ce27e52019-02-15 10:58:05 -0800181{
Andy Hung3ab1b322020-05-18 10:47:31 -0700182 if (item == nullptr) return false;
Ray Essick6ce27e52019-02-15 10:58:05 -0800183
Brian Lindahlc935ee22021-06-08 09:57:07 +0200184 AStatsEvent* event = AStatsEvent_obtain();
Vova Sharaienkof58455a2022-09-24 01:47:23 +0000185 AStatsEvent_setAtomId(event, stats::media_metrics::MEDIA_CODEC_REPORTED);
Brian Lindahlc935ee22021-06-08 09:57:07 +0200186
Brian Lindahl590e3852023-05-05 15:21:58 -0600187 const nsecs_t timestampNanos = MediaMetricsService::roundTime(item->getTimestamp());
188 AStatsEvent_writeInt64(event, timestampNanos);
Brian Lindahlc935ee22021-06-08 09:57:07 +0200189
Brian Lindahl590e3852023-05-05 15:21:58 -0600190 std::string packageName = item->getPkgName();
191 AStatsEvent_writeString(event, packageName.c_str());
Brian Lindahlc935ee22021-06-08 09:57:07 +0200192
Brian Lindahl590e3852023-05-05 15:21:58 -0600193 int64_t packageVersionCode = item->getPkgVersionCode();
194 AStatsEvent_writeInt64(event, packageVersionCode);
Brian Lindahlc935ee22021-06-08 09:57:07 +0200195
Brian Lindahl590e3852023-05-05 15:21:58 -0600196 int64_t mediaApexVersion = 0;
197 AStatsEvent_writeInt64(event, mediaApexVersion);
Ray Essick6ce27e52019-02-15 10:58:05 -0800198
199 // the rest into our own proto
200 //
Dichen Zhangb8f23c52021-03-22 00:56:29 -0700201 ::android::stats::mediametrics_message::CodecData metrics_proto;
Ray Essick6ce27e52019-02-15 10:58:05 -0800202
203 // flesh out the protobuf we'll hand off with our data
204 //
George Burgess IV0d814432019-10-23 11:32:26 -0700205 std::string codec;
206 if (item->getString("android.media.mediacodec.codec", &codec)) {
Andy Hung5be90c82021-03-30 14:30:20 -0700207 metrics_proto.set_codec(codec);
Ray Essick6ce27e52019-02-15 10:58:05 -0800208 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200209 AStatsEvent_writeString(event, codec.c_str());
Andy Hung5be90c82021-03-30 14:30:20 -0700210
George Burgess IV0d814432019-10-23 11:32:26 -0700211 std::string mime;
212 if (item->getString("android.media.mediacodec.mime", &mime)) {
Andy Hung5be90c82021-03-30 14:30:20 -0700213 metrics_proto.set_mime(mime);
Ray Essick6ce27e52019-02-15 10:58:05 -0800214 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200215 AStatsEvent_writeString(event, mime.c_str());
Andy Hung5be90c82021-03-30 14:30:20 -0700216
George Burgess IV0d814432019-10-23 11:32:26 -0700217 std::string mode;
Brian Lindahlc935ee22021-06-08 09:57:07 +0200218 if (item->getString("android.media.mediacodec.mode", &mode)) {
Andy Hung5be90c82021-03-30 14:30:20 -0700219 metrics_proto.set_mode(mode);
Ray Essick6ce27e52019-02-15 10:58:05 -0800220 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200221 AStatsEvent_writeString(event, mode.c_str());
Andy Hung5be90c82021-03-30 14:30:20 -0700222
Brian Lindahl590e3852023-05-05 15:21:58 -0600223 int32_t isEncoder = -1;
224 if (item->getInt32("android.media.mediacodec.encoder", &isEncoder)) {
225 metrics_proto.set_encoder(isEncoder);
Ray Essick6ce27e52019-02-15 10:58:05 -0800226 }
Brian Lindahl590e3852023-05-05 15:21:58 -0600227 AStatsEvent_writeInt32(event, isEncoder);
Andy Hung5be90c82021-03-30 14:30:20 -0700228
Brian Lindahl590e3852023-05-05 15:21:58 -0600229 int32_t isSecure = -1;
230 if (item->getInt32("android.media.mediacodec.secure", &isSecure)) {
231 metrics_proto.set_secure(isSecure);
Ray Essick6ce27e52019-02-15 10:58:05 -0800232 }
Brian Lindahl590e3852023-05-05 15:21:58 -0600233 AStatsEvent_writeInt32(event, isSecure);
234
235 int32_t isHardware = -1;
236 item->getInt32("android.media.mediacodec.hardware", &isHardware);
237 // not logged to MediaCodecReported or MediametricsCodecReported
238
239 int32_t isTunneled = -1;
240 item->getInt32("android.media.mediacodec.tunneled", &isTunneled);
241 // not logged to MediaCodecReported or MediametricsCodecReported
Andy Hung5be90c82021-03-30 14:30:20 -0700242
Ray Essick6ce27e52019-02-15 10:58:05 -0800243 int32_t width = -1;
Brian Lindahlc935ee22021-06-08 09:57:07 +0200244 if (item->getInt32("android.media.mediacodec.width", &width)) {
Ray Essick6ce27e52019-02-15 10:58:05 -0800245 metrics_proto.set_width(width);
246 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200247 AStatsEvent_writeInt32(event, width);
Andy Hung5be90c82021-03-30 14:30:20 -0700248
Ray Essick6ce27e52019-02-15 10:58:05 -0800249 int32_t height = -1;
Brian Lindahlc935ee22021-06-08 09:57:07 +0200250 if (item->getInt32("android.media.mediacodec.height", &height)) {
Ray Essick6ce27e52019-02-15 10:58:05 -0800251 metrics_proto.set_height(height);
252 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200253 AStatsEvent_writeInt32(event, height);
Andy Hung5be90c82021-03-30 14:30:20 -0700254
Ray Essick6ce27e52019-02-15 10:58:05 -0800255 int32_t rotation = -1;
Brian Lindahlc935ee22021-06-08 09:57:07 +0200256 if (item->getInt32("android.media.mediacodec.rotation-degrees", &rotation)) {
Ray Essick6ce27e52019-02-15 10:58:05 -0800257 metrics_proto.set_rotation(rotation);
258 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200259 AStatsEvent_writeInt32(event, rotation);
260
Ray Essick6ce27e52019-02-15 10:58:05 -0800261 int32_t crypto = -1;
Brian Lindahlc935ee22021-06-08 09:57:07 +0200262 if (item->getInt32("android.media.mediacodec.crypto", &crypto)) {
Ray Essick6ce27e52019-02-15 10:58:05 -0800263 metrics_proto.set_crypto(crypto);
264 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200265 AStatsEvent_writeInt32(event, crypto);
Andy Hung5be90c82021-03-30 14:30:20 -0700266
Ray Essick6ce27e52019-02-15 10:58:05 -0800267 int32_t profile = -1;
Brian Lindahlc935ee22021-06-08 09:57:07 +0200268 if (item->getInt32("android.media.mediacodec.profile", &profile)) {
Ray Essick6ce27e52019-02-15 10:58:05 -0800269 metrics_proto.set_profile(profile);
270 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200271 AStatsEvent_writeInt32(event, profile);
Andy Hung5be90c82021-03-30 14:30:20 -0700272
Ray Essick6ce27e52019-02-15 10:58:05 -0800273 int32_t level = -1;
Brian Lindahlc935ee22021-06-08 09:57:07 +0200274 if (item->getInt32("android.media.mediacodec.level", &level)) {
Ray Essick6ce27e52019-02-15 10:58:05 -0800275 metrics_proto.set_level(level);
276 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200277 AStatsEvent_writeInt32(event, level);
278
Andy Hung5be90c82021-03-30 14:30:20 -0700279
Brian Lindahl590e3852023-05-05 15:21:58 -0600280 int32_t maxWidth = -1;
281 if ( item->getInt32("android.media.mediacodec.maxwidth", &maxWidth)) {
282 metrics_proto.set_max_width(maxWidth);
Ray Essick6ce27e52019-02-15 10:58:05 -0800283 }
Brian Lindahl590e3852023-05-05 15:21:58 -0600284 AStatsEvent_writeInt32(event, maxWidth);
Andy Hung5be90c82021-03-30 14:30:20 -0700285
Brian Lindahl590e3852023-05-05 15:21:58 -0600286 int32_t maxHeight = -1;
287 if ( item->getInt32("android.media.mediacodec.maxheight", &maxHeight)) {
288 metrics_proto.set_max_height(maxHeight);
Ray Essick6ce27e52019-02-15 10:58:05 -0800289 }
Brian Lindahl590e3852023-05-05 15:21:58 -0600290 AStatsEvent_writeInt32(event, maxHeight);
Andy Hung5be90c82021-03-30 14:30:20 -0700291
Brian Lindahl590e3852023-05-05 15:21:58 -0600292 int32_t errorCode = -1;
293 if ( item->getInt32("android.media.mediacodec.errcode", &errorCode)) {
294 metrics_proto.set_error_code(errorCode);
Ray Essick6ce27e52019-02-15 10:58:05 -0800295 }
Brian Lindahl590e3852023-05-05 15:21:58 -0600296 AStatsEvent_writeInt32(event, errorCode);
Andy Hung5be90c82021-03-30 14:30:20 -0700297
Brian Lindahl590e3852023-05-05 15:21:58 -0600298 std::string errorState;
299 if ( item->getString("android.media.mediacodec.errstate", &errorState)) {
300 metrics_proto.set_error_state(errorState);
Ray Essick6ce27e52019-02-15 10:58:05 -0800301 }
Brian Lindahl590e3852023-05-05 15:21:58 -0600302 AStatsEvent_writeString(event, errorState.c_str());
Andy Hung5be90c82021-03-30 14:30:20 -0700303
Brian Lindahl590e3852023-05-05 15:21:58 -0600304 int64_t latencyMax = -1;
305 if (item->getInt64("android.media.mediacodec.latency.max", &latencyMax)) {
306 metrics_proto.set_latency_max(latencyMax);
Ray Essick6ce27e52019-02-15 10:58:05 -0800307 }
Brian Lindahl590e3852023-05-05 15:21:58 -0600308 AStatsEvent_writeInt64(event, latencyMax);
Andy Hung5be90c82021-03-30 14:30:20 -0700309
Brian Lindahl590e3852023-05-05 15:21:58 -0600310 int64_t latencyMin = -1;
311 if (item->getInt64("android.media.mediacodec.latency.min", &latencyMin)) {
312 metrics_proto.set_latency_min(latencyMin);
Ray Essick6ce27e52019-02-15 10:58:05 -0800313 }
Brian Lindahl590e3852023-05-05 15:21:58 -0600314 AStatsEvent_writeInt64(event, latencyMin);
Andy Hung5be90c82021-03-30 14:30:20 -0700315
Brian Lindahl590e3852023-05-05 15:21:58 -0600316 int64_t latencyAvg = -1;
317 if (item->getInt64("android.media.mediacodec.latency.avg", &latencyAvg)) {
318 metrics_proto.set_latency_avg(latencyAvg);
Ray Essick6ce27e52019-02-15 10:58:05 -0800319 }
Brian Lindahl590e3852023-05-05 15:21:58 -0600320 AStatsEvent_writeInt64(event, latencyAvg);
Andy Hung5be90c82021-03-30 14:30:20 -0700321
Brian Lindahl590e3852023-05-05 15:21:58 -0600322 int64_t latencyCount = -1;
323 if (item->getInt64("android.media.mediacodec.latency.n", &latencyCount)) {
324 metrics_proto.set_latency_count(latencyCount);
Ray Essick6ce27e52019-02-15 10:58:05 -0800325 }
Brian Lindahl590e3852023-05-05 15:21:58 -0600326 AStatsEvent_writeInt64(event, latencyCount);
Andy Hung5be90c82021-03-30 14:30:20 -0700327
Brian Lindahl590e3852023-05-05 15:21:58 -0600328 int64_t latencyUnknown = -1;
329 if (item->getInt64("android.media.mediacodec.latency.unknown", &latencyUnknown)) {
330 metrics_proto.set_latency_unknown(latencyUnknown);
Ray Essick6ce27e52019-02-15 10:58:05 -0800331 }
Brian Lindahl590e3852023-05-05 15:21:58 -0600332 AStatsEvent_writeInt64(event, latencyUnknown);
Andy Hung5be90c82021-03-30 14:30:20 -0700333
Brian Lindahl590e3852023-05-05 15:21:58 -0600334 int32_t queueSecureInputBufferError = -1;
Andy Hung5be90c82021-03-30 14:30:20 -0700335 if (item->getInt32("android.media.mediacodec.queueSecureInputBufferError",
Brian Lindahl590e3852023-05-05 15:21:58 -0600336 &queueSecureInputBufferError)) {
337 metrics_proto.set_queue_secure_input_buffer_error(queueSecureInputBufferError);
Edwin Wong4f105392020-02-12 14:55:00 -0800338 }
Brian Lindahl590e3852023-05-05 15:21:58 -0600339 AStatsEvent_writeInt32(event, queueSecureInputBufferError);
Andy Hung5be90c82021-03-30 14:30:20 -0700340
Brian Lindahl590e3852023-05-05 15:21:58 -0600341 int32_t queueInputBufferError = -1;
342 if (item->getInt32("android.media.mediacodec.queueInputBufferError", &queueInputBufferError)) {
343 metrics_proto.set_queue_input_buffer_error(queueInputBufferError);
Edwin Wong4f105392020-02-12 14:55:00 -0800344 }
Brian Lindahl590e3852023-05-05 15:21:58 -0600345 AStatsEvent_writeInt32(event, queueInputBufferError);
Ray Essick6ce27e52019-02-15 10:58:05 -0800346
Brian Lindahl590e3852023-05-05 15:21:58 -0600347 std::string bitrateMode;
348 if (item->getString("android.media.mediacodec.bitrate_mode", &bitrateMode)) {
349 metrics_proto.set_bitrate_mode(bitrateMode);
Ray Essicka21a3d32020-05-10 21:08:10 -0700350 }
Brian Lindahl590e3852023-05-05 15:21:58 -0600351 AStatsEvent_writeString(event, bitrateMode.c_str());
Andy Hung5be90c82021-03-30 14:30:20 -0700352
Ray Essicka21a3d32020-05-10 21:08:10 -0700353 int32_t bitrate = -1;
354 if (item->getInt32("android.media.mediacodec.bitrate", &bitrate)) {
355 metrics_proto.set_bitrate(bitrate);
356 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200357 AStatsEvent_writeInt32(event, bitrate);
Andy Hung5be90c82021-03-30 14:30:20 -0700358
Brian Lindahl590e3852023-05-05 15:21:58 -0600359 int64_t lifetimeMillis = -1;
360 if (item->getInt64("android.media.mediacodec.lifetimeMs", &lifetimeMillis)) {
361 lifetimeMillis = mediametrics::bucket_time_minutes(lifetimeMillis);
362 metrics_proto.set_lifetime_millis(lifetimeMillis);
Ray Essicka21a3d32020-05-10 21:08:10 -0700363 }
Brian Lindahl590e3852023-05-05 15:21:58 -0600364 AStatsEvent_writeInt64(event, lifetimeMillis);
Ray Essicka21a3d32020-05-10 21:08:10 -0700365
Brian Lindahl590e3852023-05-05 15:21:58 -0600366 int64_t playbackDurationSec = -1;
367 item->getInt64("android.media.mediacodec.playback-duration-sec", &playbackDurationSec);
Brian Lindahlc935ee22021-06-08 09:57:07 +0200368 // DO NOT record playback-duration in the metrics_proto - it should only
369 // exist in the flattened atom
Brian Lindahl590e3852023-05-05 15:21:58 -0600370 AStatsEvent_writeInt64(event, playbackDurationSec);
Brian Lindahlc935ee22021-06-08 09:57:07 +0200371
372 std::string sessionId;
373 if (item->getString("android.media.mediacodec.log-session-id", &sessionId)) {
Andy Hungc9b6f8b2021-07-08 10:17:55 -0700374 sessionId = mediametrics::ValidateId::get()->validateId(sessionId);
Brian Lindahlc935ee22021-06-08 09:57:07 +0200375 metrics_proto.set_log_session_id(sessionId);
376 }
Ray Essicke5d245f2022-04-06 11:13:34 -0700377 AStatsEvent_writeString(event, sessionId.c_str());
Brian Lindahlc935ee22021-06-08 09:57:07 +0200378
Dichen Zhang0de05752021-04-21 19:47:07 -0700379 int32_t channelCount = -1;
Brian Lindahlc935ee22021-06-08 09:57:07 +0200380 if (item->getInt32("android.media.mediacodec.channelCount", &channelCount)) {
Dichen Zhang0de05752021-04-21 19:47:07 -0700381 metrics_proto.set_channel_count(channelCount);
382 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200383 AStatsEvent_writeInt32(event, channelCount);
Ray Essick87913312021-03-02 10:45:54 -0800384
Dichen Zhang0de05752021-04-21 19:47:07 -0700385 int32_t sampleRate = -1;
Brian Lindahlc935ee22021-06-08 09:57:07 +0200386 if (item->getInt32("android.media.mediacodec.sampleRate", &sampleRate)) {
Dichen Zhang0de05752021-04-21 19:47:07 -0700387 metrics_proto.set_sample_rate(sampleRate);
388 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200389 AStatsEvent_writeInt32(event, sampleRate);
Dichen Zhang0de05752021-04-21 19:47:07 -0700390
Ray Essick87913312021-03-02 10:45:54 -0800391 // TODO PWG may want these fuzzed up a bit to obscure some precision
Dichen Zhang0de05752021-04-21 19:47:07 -0700392 int64_t bytes = -1;
Brian Lindahlc935ee22021-06-08 09:57:07 +0200393 if (item->getInt64("android.media.mediacodec.vencode.bytes", &bytes)) {
Dichen Zhang0de05752021-04-21 19:47:07 -0700394 metrics_proto.set_video_encode_bytes(bytes);
395 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200396 AStatsEvent_writeInt64(event, bytes);
Dichen Zhang0de05752021-04-21 19:47:07 -0700397
Dichen Zhang0de05752021-04-21 19:47:07 -0700398 int64_t frames = -1;
Brian Lindahlc935ee22021-06-08 09:57:07 +0200399 if (item->getInt64("android.media.mediacodec.vencode.frames", &frames)) {
Dichen Zhang0de05752021-04-21 19:47:07 -0700400 metrics_proto.set_video_encode_frames(frames);
401 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200402 AStatsEvent_writeInt64(event, frames);
Dichen Zhang0de05752021-04-21 19:47:07 -0700403
Dichen Zhang0de05752021-04-21 19:47:07 -0700404 int64_t inputBytes = -1;
Brian Lindahlc935ee22021-06-08 09:57:07 +0200405 if (item->getInt64("android.media.mediacodec.video.input.bytes", &inputBytes)) {
Dichen Zhang0de05752021-04-21 19:47:07 -0700406 metrics_proto.set_video_input_bytes(inputBytes);
407 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200408 AStatsEvent_writeInt64(event, inputBytes);
Dichen Zhang0de05752021-04-21 19:47:07 -0700409
Dichen Zhang0de05752021-04-21 19:47:07 -0700410 int64_t inputFrames = -1;
Brian Lindahlc935ee22021-06-08 09:57:07 +0200411 if (item->getInt64("android.media.mediacodec.video.input.frames", &inputFrames)) {
Dichen Zhang0de05752021-04-21 19:47:07 -0700412 metrics_proto.set_video_input_frames(inputFrames);
413 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200414 AStatsEvent_writeInt64(event, inputFrames);
Ray Essick87913312021-03-02 10:45:54 -0800415
Brian Lindahlc935ee22021-06-08 09:57:07 +0200416 int64_t durationUs = -1;
417 if (item->getInt64("android.media.mediacodec.vencode.durationUs", &durationUs)) {
418 metrics_proto.set_video_encode_duration_us(durationUs);
419 }
420 AStatsEvent_writeInt64(event, durationUs);
421
422 int32_t colorFormat = -1;
423 if (item->getInt32("android.media.mediacodec.color-format", &colorFormat)) {
424 metrics_proto.set_color_format(colorFormat);
425 }
426 AStatsEvent_writeInt32(event, colorFormat);
427
428 double frameRate = -1.0;
429 if (item->getDouble("android.media.mediacodec.frame-rate", &frameRate)) {
430 metrics_proto.set_frame_rate(frameRate);
431 }
432 AStatsEvent_writeFloat(event, (float) frameRate);
433
434 double captureRate = -1.0;
435 if (item->getDouble("android.media.mediacodec.capture-rate", &captureRate)) {
436 metrics_proto.set_capture_rate(captureRate);
437 }
438 AStatsEvent_writeFloat(event, (float) captureRate);
439
440 double operatingRate = -1.0;
441 if (item->getDouble("android.media.mediacodec.operating-rate", &operatingRate)) {
442 metrics_proto.set_operating_rate(operatingRate);
443 }
444 AStatsEvent_writeFloat(event, (float) operatingRate);
445
446 int32_t priority = -1;
447 if (item->getInt32("android.media.mediacodec.priority", &priority)) {
448 metrics_proto.set_priority(priority);
449 }
450 AStatsEvent_writeInt32(event, priority);
451
452 int32_t qpIMin = -1;
453 if (item->getInt32("android.media.mediacodec.video-qp-i-min", &qpIMin)) {
454 metrics_proto.set_video_qp_i_min(qpIMin);
455 }
456 AStatsEvent_writeInt32(event, qpIMin);
457
458 int32_t qpIMax = -1;
459 if (item->getInt32("android.media.mediacodec.video-qp-i-max", &qpIMax)) {
460 metrics_proto.set_video_qp_i_max(qpIMax);
461 }
462 AStatsEvent_writeInt32(event, qpIMax);
463
464 int32_t qpPMin = -1;
465 if (item->getInt32("android.media.mediacodec.video-qp-p-min", &qpPMin)) {
466 metrics_proto.set_video_qp_p_min(qpPMin);
467 }
468 AStatsEvent_writeInt32(event, qpPMin);
469
470 int32_t qpPMax = -1;
471 if (item->getInt32("android.media.mediacodec.video-qp-p-max", &qpPMax)) {
472 metrics_proto.set_video_qp_p_max(qpPMax);
473 }
474 AStatsEvent_writeInt32(event, qpPMax);
475
476 int32_t qpBMin = -1;
477 if (item->getInt32("android.media.mediacodec.video-qp-b-min", &qpBMin)) {
478 metrics_proto.set_video_qp_b_min(qpBMin);
479 }
480 AStatsEvent_writeInt32(event, qpBMin);
481
482 int32_t qpBMax = -1;
483 if (item->getInt32("android.media.mediacodec.video-qp-b-max", &qpBMax)) {
484 metrics_proto.set_video_qp_b_max(qpBMax);
485 }
486 AStatsEvent_writeInt32(event, qpBMax);
487
Dichen Zhange5bad782021-04-28 12:11:35 -0700488 int32_t originalBitrate = -1;
Brian Lindahlc935ee22021-06-08 09:57:07 +0200489 if (item->getInt32("android.media.mediacodec.original.bitrate", &originalBitrate)) {
Dichen Zhange5bad782021-04-28 12:11:35 -0700490 metrics_proto.set_original_bitrate(originalBitrate);
491 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200492 AStatsEvent_writeInt32(event, originalBitrate);
Dichen Zhange5bad782021-04-28 12:11:35 -0700493
Dichen Zhang57be6302021-05-18 18:20:31 -0700494 int32_t shapingEnhanced = -1;
495 if ( item->getInt32("android.media.mediacodec.shaped", &shapingEnhanced)) {
496 metrics_proto.set_shaping_enhanced(shapingEnhanced);
497 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200498 AStatsEvent_writeInt32(event, shapingEnhanced);
Dichen Zhang57be6302021-05-18 18:20:31 -0700499
Dichen Zhang57be6302021-05-18 18:20:31 -0700500 int32_t qpIMinOri = -1;
501 if ( item->getInt32("android.media.mediacodec.original-video-qp-i-min", &qpIMinOri)) {
502 metrics_proto.set_original_video_qp_i_min(qpIMinOri);
503 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200504 AStatsEvent_writeInt32(event, qpIMinOri);
Dichen Zhang57be6302021-05-18 18:20:31 -0700505
Dichen Zhang57be6302021-05-18 18:20:31 -0700506 int32_t qpIMaxOri = -1;
507 if ( item->getInt32("android.media.mediacodec.original-video-qp-i-max", &qpIMaxOri)) {
508 metrics_proto.set_original_video_qp_i_max(qpIMaxOri);
509 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200510 AStatsEvent_writeInt32(event, qpIMaxOri);
Dichen Zhang57be6302021-05-18 18:20:31 -0700511
Dichen Zhang57be6302021-05-18 18:20:31 -0700512 int32_t qpPMinOri = -1;
513 if ( item->getInt32("android.media.mediacodec.original-video-qp-p-min", &qpPMinOri)) {
514 metrics_proto.set_original_video_qp_p_min(qpPMinOri);
515 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200516 AStatsEvent_writeInt32(event, qpPMinOri);
Dichen Zhang57be6302021-05-18 18:20:31 -0700517
Dichen Zhang57be6302021-05-18 18:20:31 -0700518 int32_t qpPMaxOri = -1;
519 if ( item->getInt32("android.media.mediacodec.original-video-qp-p-max", &qpPMaxOri)) {
520 metrics_proto.set_original_video_qp_p_max(qpPMaxOri);
521 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200522 AStatsEvent_writeInt32(event, qpPMaxOri);
Dichen Zhang57be6302021-05-18 18:20:31 -0700523
Dichen Zhang57be6302021-05-18 18:20:31 -0700524 int32_t qpBMinOri = -1;
525 if ( item->getInt32("android.media.mediacodec.original-video-qp-b-min", &qpBMinOri)) {
Brian Lindahlc935ee22021-06-08 09:57:07 +0200526 metrics_proto.set_original_video_qp_b_min(qpBMinOri);
Dichen Zhang57be6302021-05-18 18:20:31 -0700527 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200528 AStatsEvent_writeInt32(event, qpBMinOri);
Dichen Zhang57be6302021-05-18 18:20:31 -0700529
Dichen Zhang57be6302021-05-18 18:20:31 -0700530 int32_t qpBMaxOri = -1;
531 if ( item->getInt32("android.media.mediacodec.original-video-qp-b-max", &qpBMaxOri)) {
532 metrics_proto.set_original_video_qp_b_max(qpBMaxOri);
533 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200534 AStatsEvent_writeInt32(event, qpBMaxOri);
535
Songyue Han4c1e5372022-04-13 21:11:23 +0000536 int32_t configColorStandard = -1;
537 if (item->getInt32("android.media.mediacodec.config-color-standard", &configColorStandard)) {
538 metrics_proto.set_config_color_standard(configColorStandard);
539 }
540 AStatsEvent_writeInt32(event, configColorStandard);
Songyue Han3be67f22022-01-20 22:04:10 +0000541
Songyue Han4c1e5372022-04-13 21:11:23 +0000542 int32_t configColorRange = -1;
543 if (item->getInt32("android.media.mediacodec.config-color-range", &configColorRange)) {
544 metrics_proto.set_config_color_range(configColorRange);
545 }
546 AStatsEvent_writeInt32(event, configColorRange);
Songyue Han3be67f22022-01-20 22:04:10 +0000547
Songyue Han4c1e5372022-04-13 21:11:23 +0000548 int32_t configColorTransfer = -1;
549 if (item->getInt32("android.media.mediacodec.config-color-transfer", &configColorTransfer)) {
550 metrics_proto.set_config_color_transfer(configColorTransfer);
551 }
552 AStatsEvent_writeInt32(event, configColorTransfer);
Songyue Han3be67f22022-01-20 22:04:10 +0000553
Songyue Han4c1e5372022-04-13 21:11:23 +0000554 int32_t parsedColorStandard = -1;
555 if (item->getInt32("android.media.mediacodec.parsed-color-standard", &parsedColorStandard)) {
556 metrics_proto.set_parsed_color_standard(parsedColorStandard);
557 }
558 AStatsEvent_writeInt32(event, parsedColorStandard);
Songyue Han3be67f22022-01-20 22:04:10 +0000559
Songyue Han4c1e5372022-04-13 21:11:23 +0000560 int32_t parsedColorRange = -1;
561 if (item->getInt32("android.media.mediacodec.parsed-color-range", &parsedColorRange)) {
562 metrics_proto.set_parsed_color_range(parsedColorRange);
563 }
564 AStatsEvent_writeInt32(event, parsedColorRange);
Songyue Han3be67f22022-01-20 22:04:10 +0000565
Songyue Han4c1e5372022-04-13 21:11:23 +0000566 int32_t parsedColorTransfer = -1;
567 if (item->getInt32("android.media.mediacodec.parsed-color-transfer", &parsedColorTransfer)) {
568 metrics_proto.set_parsed_color_transfer(parsedColorTransfer);
569 }
570 AStatsEvent_writeInt32(event, parsedColorTransfer);
Songyue Han3be67f22022-01-20 22:04:10 +0000571
Songyue Han4c1e5372022-04-13 21:11:23 +0000572 int32_t hdrStaticInfo = -1;
573 if (item->getInt32("android.media.mediacodec.hdr-static-info", &hdrStaticInfo)) {
574 metrics_proto.set_hdr_static_info(hdrStaticInfo);
575 }
576 AStatsEvent_writeInt32(event, hdrStaticInfo);
577
578 int32_t hdr10PlusInfo = -1;
579 if (item->getInt32("android.media.mediacodec.hdr10-plus-info", &hdr10PlusInfo)) {
580 metrics_proto.set_hdr10_plus_info(hdr10PlusInfo);
581 }
582 AStatsEvent_writeInt32(event, hdr10PlusInfo);
583
Songyue Han6dc32102023-01-04 21:42:52 +0000584 int32_t hdrFormat = -1;
Songyue Han4c1e5372022-04-13 21:11:23 +0000585 if (item->getInt32("android.media.mediacodec.hdr-format", &hdrFormat)) {
586 metrics_proto.set_hdr_format(hdrFormat);
587 }
588 AStatsEvent_writeInt32(event, hdrFormat);
Songyue Han3be67f22022-01-20 22:04:10 +0000589
Girish4e531c82023-02-17 00:36:29 +0000590 int64_t codecId = 0;
591 if (item->getInt64("android.media.mediacodec.id", &codecId)) {
592 metrics_proto.set_codec_id(codecId);
593 }
594 AStatsEvent_writeInt64(event, codecId);
595
Songyue Han6dc32102023-01-04 21:42:52 +0000596 int32_t arrayMode = -1;
597 if (item->getInt32("android.media.mediacodec.array-mode", &arrayMode)) {
598 metrics_proto.set_array_mode(arrayMode);
599 }
600 AStatsEvent_writeInt32(event, arrayMode);
601
602 int32_t operationMode = -1;
603 if (item->getInt32("android.media.mediacodec.operation-mode", &operationMode)) {
604 metrics_proto.set_operation_mode(operationMode);
605 }
606 AStatsEvent_writeInt32(event, operationMode);
607
608 int32_t outputSurface = -1;
609 if (item->getInt32("android.media.mediacodec.output-surface", &outputSurface)) {
610 metrics_proto.set_output_surface(outputSurface);
611 }
612 AStatsEvent_writeInt32(event, outputSurface);
613
614 int32_t appMaxInputSize = -1;
615 if (item->getInt32("android.media.mediacodec.app-max-input-size", &appMaxInputSize)) {
616 metrics_proto.set_app_max_input_size(appMaxInputSize);
617 }
618 AStatsEvent_writeInt32(event, appMaxInputSize);
619
620 int32_t usedMaxInputSize = -1;
621 if (item->getInt32("android.media.mediacodec.used-max-input-size", &usedMaxInputSize)) {
622 metrics_proto.set_used_max_input_size(usedMaxInputSize);
623 }
624 AStatsEvent_writeInt32(event, usedMaxInputSize);
625
626 int32_t codecMaxInputSize = -1;
627 if (item->getInt32("android.media.mediacodec.codec-max-input-size", &codecMaxInputSize)) {
628 metrics_proto.set_codec_max_input_size(codecMaxInputSize);
629 }
630 AStatsEvent_writeInt32(event, codecMaxInputSize);
631
632 int32_t flushCount = -1;
633 if (item->getInt32("android.media.mediacodec.flush-count", &flushCount)) {
634 metrics_proto.set_flush_count(flushCount);
635 }
636 AStatsEvent_writeInt32(event, flushCount);
637
638 int32_t setSurfaceCount = -1;
639 if (item->getInt32("android.media.mediacodec.set-surface-count", &setSurfaceCount)) {
640 metrics_proto.set_set_surface_count(setSurfaceCount);
641 }
642 AStatsEvent_writeInt32(event, setSurfaceCount);
643
644 int32_t resolutionChangeCount = -1;
645 if (item->getInt32("android.media.mediacodec.resolution-change-count",
646 &resolutionChangeCount)) {
647 metrics_proto.set_resolution_change_count(resolutionChangeCount);
648 }
649 AStatsEvent_writeInt32(event, resolutionChangeCount);
650
Brian Lindahl590e3852023-05-05 15:21:58 -0600651 int64_t firstRenderTimeUs = -1;
652 item->getInt64("android.media.mediacodec.first-render-time-us", &firstRenderTimeUs);
653 int64_t framesReleased = -1;
654 item->getInt64("android.media.mediacodec.frames-released", &framesReleased);
655 int64_t framesRendered = -1;
656 item->getInt64("android.media.mediacodec.frames-rendered", &framesRendered);
657 int64_t framesDropped = -1;
658 item->getInt64("android.media.mediacodec.frames-dropped", &framesDropped);
659 int64_t framesSkipped = -1;
660 item->getInt64("android.media.mediacodec.frames-skipped", &framesSkipped);
661 double framerateContent = -1;
662 item->getDouble("android.media.mediacodec.framerate-content", &framerateContent);
663 double framerateActual = -1;
664 item->getDouble("android.media.mediacodec.framerate-actual", &framerateActual);
665 int64_t freezeScore = -1;
666 item->getInt64("android.media.mediacodec.freeze-score", &freezeScore);
667 double freezeRate = -1;
668 item->getDouble("android.media.mediacodec.freeze-rate", &freezeRate);
669 std::string freezeScoreHistogramStr;
670 item->getString("android.media.mediacodec.freeze-score-histogram", &freezeScoreHistogramStr);
671 std::string freezeScoreHistogramBucketsStr;
672 item->getString("android.media.mediacodec.freeze-score-histogram-buckets",
673 &freezeScoreHistogramBucketsStr);
674 std::string freezeDurationMsHistogramStr;
675 item->getString("android.media.mediacodec.freeze-duration-ms-histogram",
676 &freezeDurationMsHistogramStr);
677 std::string freezeDurationMsHistogramBucketsStr;
678 item->getString("android.media.mediacodec.freeze-duration-ms-histogram-buckets",
679 &freezeDurationMsHistogramBucketsStr);
680 std::string freezeDistanceMsHistogramStr;
681 item->getString("android.media.mediacodec.freeze-distance-ms-histogram",
682 &freezeDistanceMsHistogramStr);
683 std::string freezeDistanceMsHistogramBucketsStr;
684 item->getString("android.media.mediacodec.freeze-distance-ms-histogram-buckets",
685 &freezeDistanceMsHistogramBucketsStr);
686 int64_t judderScore = -1;
687 item->getInt64("android.media.mediacodec.judder-score", &judderScore);
688 double judderRate = -1;
689 item->getDouble("android.media.mediacodec.judder-rate", &judderRate);
690 std::string judderScoreHistogramStr;
691 item->getString("android.media.mediacodec.judder-score-histogram", &judderScoreHistogramStr);
692 std::string judderScoreHistogramBucketsStr;
693 item->getString("android.media.mediacodec.judder-score-histogram-buckets",
694 &judderScoreHistogramBucketsStr);
695
Brian Lindahlc935ee22021-06-08 09:57:07 +0200696 int err = AStatsEvent_write(event);
697 if (err < 0) {
698 ALOGE("Failed to write codec metrics to statsd (%d)", err);
699 }
700 AStatsEvent_release(event);
Dichen Zhang57be6302021-05-18 18:20:31 -0700701
Brian Lindahl590e3852023-05-05 15:21:58 -0600702 if (framesRendered > 0) {
703 int32_t statsUid = item->getUid();
704 int64_t statsCodecId = codecId;
705 char const *statsLogSessionId = sessionId.c_str();
706 int32_t statsIsHardware = isHardware;
707 int32_t statsIsSecure = isSecure;
708 int32_t statsIsTunneled = isTunneled;
709 int32_t statsCodec = getMetricsCodecEnum(mime, codec);
710 int32_t statsResolution = getMetricsResolutionEnum(width, height);
711 int32_t statsBitrate = BITRATE_UNKNOWN;
712 int32_t statsContentFramerate = getMetricsFramerateEnum(framerateContent);
713 int32_t statsActualFramerate = getMetricsFramerateEnum(framerateActual);
714 int32_t statsHdrFormat = getMetricsHdrFormatEnum(mime, codec, configColorTransfer,
715 parsedColorTransfer, hdrStaticInfo,
716 hdr10PlusInfo);
717 int64_t statsFirstRenderTimeUs = firstRenderTimeUs;
718 int64_t statsPlaybackDurationSeconds = playbackDurationSec;
719 int64_t statsFramesTotal = framesReleased + framesSkipped;
720 int64_t statsFramesReleased = framesReleased;
721 int64_t statsFramesRendered = framesRendered;
722 int64_t statsFramesDropped = framesDropped;
723 int64_t statsFramesSkipped = framesSkipped;
724 float statsFrameDropRate = float(double(framesDropped) / statsFramesTotal);
725 float statsFrameSkipRate = float(double(framesSkipped) / statsFramesTotal);
726 float statsFrameSkipDropRate = float(double(framesSkipped + framesDropped) /
727 statsFramesTotal);
728 int64_t statsFreezeScore = freezeScore;
729 float statsFreezeRate = freezeRate;
730 std::vector<int32_t> statsFreezeDurationMsHistogram;
731 parseVector(freezeDurationMsHistogramStr, &statsFreezeDurationMsHistogram);
732 std::vector<int32_t> statsFreezeDurationMsHistogramBuckets;
733 parseVector(freezeDurationMsHistogramBucketsStr, &statsFreezeDurationMsHistogramBuckets);
734 std::vector<int32_t> statsFreezeDistanceMsHistogram;
735 parseVector(freezeDistanceMsHistogramStr, &statsFreezeDistanceMsHistogram);
736 std::vector<int32_t> statsFreezeDistanceMsHistogramBuckets;
737 parseVector(freezeDistanceMsHistogramBucketsStr, &statsFreezeDistanceMsHistogramBuckets);
738 int64_t statsJudderScore = judderScore;
739 float statsJudderRate = judderRate;
740 std::vector<int32_t> statsJudderScoreHistogram;
741 parseVector(judderScoreHistogramStr, &statsJudderScoreHistogram);
742 std::vector<int32_t> statsJudderScoreHistogramBuckets;
743 parseVector(judderScoreHistogramBucketsStr, &statsJudderScoreHistogramBuckets);
744 int result = stats_write(
745 MEDIA_CODEC_RENDERED,
746 statsUid,
747 statsCodecId,
748 statsLogSessionId,
749 statsIsHardware,
750 statsIsSecure,
751 statsIsTunneled,
752 statsCodec,
753 statsResolution,
754 statsBitrate,
755 statsContentFramerate,
756 statsActualFramerate,
757 statsHdrFormat,
758 statsFirstRenderTimeUs,
759 statsPlaybackDurationSeconds,
760 statsFramesTotal,
761 statsFramesReleased,
762 statsFramesRendered,
763 statsFramesDropped,
764 statsFramesSkipped,
765 statsFrameDropRate,
766 statsFrameSkipRate,
767 statsFrameSkipDropRate,
768 statsFreezeScore,
769 statsFreezeRate,
770 statsFreezeDurationMsHistogram,
771 statsFreezeDurationMsHistogramBuckets,
772 statsFreezeDistanceMsHistogram,
773 statsFreezeDistanceMsHistogramBuckets,
774 statsJudderScore,
775 statsJudderRate,
776 statsJudderScoreHistogram,
777 statsJudderScoreHistogramBuckets);
778 ALOGE_IF(result < 0, "Failed to record MEDIA_CODEC_RENDERED atom (%d)", result);
779 }
780
Ray Essick6ce27e52019-02-15 10:58:05 -0800781 std::string serialized;
782 if (!metrics_proto.SerializeToString(&serialized)) {
783 ALOGE("Failed to serialize codec metrics");
784 return false;
785 }
Brian Lindahl590e3852023-05-05 15:21:58 -0600786 const stats::media_metrics::BytesField bf_serialized(serialized.c_str(), serialized.size());
Vova Sharaienkof58455a2022-09-24 01:47:23 +0000787 const int result = stats::media_metrics::stats_write(stats::media_metrics::MEDIAMETRICS_CODEC_REPORTED,
Brian Lindahl590e3852023-05-05 15:21:58 -0600788 timestampNanos, packageName.c_str(), packageVersionCode,
789 mediaApexVersion,
Andy Hung5be90c82021-03-30 14:30:20 -0700790 bf_serialized);
Brian Lindahlc935ee22021-06-08 09:57:07 +0200791
Andy Hung5be90c82021-03-30 14:30:20 -0700792 std::stringstream log;
793 log << "result:" << result << " {"
794 << " mediametrics_codec_reported:"
Vova Sharaienkof58455a2022-09-24 01:47:23 +0000795 << stats::media_metrics::MEDIAMETRICS_CODEC_REPORTED
Brian Lindahl590e3852023-05-05 15:21:58 -0600796 << " timestamp_nanos:" << timestampNanos
797 << " package_name:" << packageName
798 << " package_version_code:" << packageVersionCode
799 << " media_apex_version:" << mediaApexVersion
Andy Hung5be90c82021-03-30 14:30:20 -0700800 << " codec:" << codec
801 << " mime:" << mime
802 << " mode:" << mode
Brian Lindahl590e3852023-05-05 15:21:58 -0600803 << " encoder:" << isEncoder
804 << " secure:" << isSecure
Andy Hung5be90c82021-03-30 14:30:20 -0700805 << " width:" << width
806 << " height:" << height
807 << " rotation:" << rotation
808 << " crypto:" << crypto
809 << " profile:" << profile
Andy Hung5be90c82021-03-30 14:30:20 -0700810 << " level:" << level
Brian Lindahl590e3852023-05-05 15:21:58 -0600811 << " max_width:" << maxWidth
812 << " max_height:" << maxHeight
813 << " error_code:" << errorCode
814 << " error_state:" << errorState
815 << " latency_max:" << latencyMax
816 << " latency_min:" << latencyMin
817 << " latency_avg:" << latencyAvg
818 << " latency_count:" << latencyCount
819 << " latency_unknown:" << latencyUnknown
820 << " queue_input_buffer_error:" << queueInputBufferError
821 << " queue_secure_input_buffer_error:" << queueSecureInputBufferError
822 << " bitrate_mode:" << bitrateMode
Andy Hung5be90c82021-03-30 14:30:20 -0700823 << " bitrate:" << bitrate
Dichen Zhang57be6302021-05-18 18:20:31 -0700824 << " original_bitrate:" << originalBitrate
Brian Lindahl590e3852023-05-05 15:21:58 -0600825 << " lifetime_millis:" << lifetimeMillis
826 << " playback_duration_seconds:" << playbackDurationSec
Dichen Zhang57be6302021-05-18 18:20:31 -0700827 << " log_session_id:" << sessionId
828 << " channel_count:" << channelCount
829 << " sample_rate:" << sampleRate
830 << " encode_bytes:" << bytes
831 << " encode_frames:" << frames
832 << " encode_duration_us:" << durationUs
833 << " color_format:" << colorFormat
834 << " frame_rate:" << frameRate
835 << " capture_rate:" << captureRate
836 << " operating_rate:" << operatingRate
837 << " priority:" << priority
838 << " shaping_enhanced:" << shapingEnhanced
Dichen Zhang57be6302021-05-18 18:20:31 -0700839 << " qp_i_min:" << qpIMin
840 << " qp_i_max:" << qpIMax
841 << " qp_p_min:" << qpPMin
842 << " qp_p_max:" << qpPMax
843 << " qp_b_min:" << qpBMin
844 << " qp_b_max:" << qpBMax
845 << " original_qp_i_min:" << qpIMinOri
846 << " original_qp_i_max:" << qpIMaxOri
847 << " original_qp_p_min:" << qpPMinOri
848 << " original_qp_p_max:" << qpPMaxOri
849 << " original_qp_b_min:" << qpBMinOri
850 << " original_qp_b_max:" << qpBMaxOri
Andy Hung5be90c82021-03-30 14:30:20 -0700851 << " }";
Vova Sharaienkof58455a2022-09-24 01:47:23 +0000852 statsdLog->log(stats::media_metrics::MEDIAMETRICS_CODEC_REPORTED, log.str());
Brian Lindahlc935ee22021-06-08 09:57:07 +0200853
854
Ray Essick6ce27e52019-02-15 10:58:05 -0800855 return true;
856}
857
Andy Hung3ab1b322020-05-18 10:47:31 -0700858} // namespace android