blob: 065c59457f83a9a59884d14477ffce8cfb02f50c [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
32#include <statslog.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"
Dichen Zhangb8f23c52021-03-22 00:56:29 -070037#include "frameworks/proto_logging/stats/message/mediametrics_message.pb.h"
Ray Essick6ce27e52019-02-15 10:58:05 -080038#include "iface_statsd.h"
39
40namespace android {
41
Andy Hung5be90c82021-03-30 14:30:20 -070042bool statsd_codec(const std::shared_ptr<const mediametrics::Item>& item,
43 const std::shared_ptr<mediametrics::StatsdLog>& statsdLog)
Ray Essick6ce27e52019-02-15 10:58:05 -080044{
Andy Hung3ab1b322020-05-18 10:47:31 -070045 if (item == nullptr) return false;
Ray Essick6ce27e52019-02-15 10:58:05 -080046
Brian Lindahlc935ee22021-06-08 09:57:07 +020047 AStatsEvent* event = AStatsEvent_obtain();
48 AStatsEvent_setAtomId(event, android::util::MEDIA_CODEC_REPORTED);
49
Andy Hung5be90c82021-03-30 14:30:20 -070050 const nsecs_t timestamp_nanos = MediaMetricsService::roundTime(item->getTimestamp());
Brian Lindahlc935ee22021-06-08 09:57:07 +020051 AStatsEvent_writeInt64(event, timestamp_nanos);
52
53 std::string package_name = item->getPkgName();
54 AStatsEvent_writeString(event, package_name.c_str());
55
56 int64_t package_version_code = item->getPkgVersionCode();
57 AStatsEvent_writeInt64(event, package_version_code);
58
59 int64_t media_apex_version = 0;
60 AStatsEvent_writeInt64(event, media_apex_version);
Ray Essick6ce27e52019-02-15 10:58:05 -080061
62 // the rest into our own proto
63 //
Dichen Zhangb8f23c52021-03-22 00:56:29 -070064 ::android::stats::mediametrics_message::CodecData metrics_proto;
Ray Essick6ce27e52019-02-15 10:58:05 -080065
66 // flesh out the protobuf we'll hand off with our data
67 //
George Burgess IV0d814432019-10-23 11:32:26 -070068 std::string codec;
69 if (item->getString("android.media.mediacodec.codec", &codec)) {
Andy Hung5be90c82021-03-30 14:30:20 -070070 metrics_proto.set_codec(codec);
Ray Essick6ce27e52019-02-15 10:58:05 -080071 }
Brian Lindahlc935ee22021-06-08 09:57:07 +020072 AStatsEvent_writeString(event, codec.c_str());
Andy Hung5be90c82021-03-30 14:30:20 -070073
George Burgess IV0d814432019-10-23 11:32:26 -070074 std::string mime;
75 if (item->getString("android.media.mediacodec.mime", &mime)) {
Andy Hung5be90c82021-03-30 14:30:20 -070076 metrics_proto.set_mime(mime);
Ray Essick6ce27e52019-02-15 10:58:05 -080077 }
Brian Lindahlc935ee22021-06-08 09:57:07 +020078 AStatsEvent_writeString(event, mime.c_str());
Andy Hung5be90c82021-03-30 14:30:20 -070079
George Burgess IV0d814432019-10-23 11:32:26 -070080 std::string mode;
Brian Lindahlc935ee22021-06-08 09:57:07 +020081 if (item->getString("android.media.mediacodec.mode", &mode)) {
Andy Hung5be90c82021-03-30 14:30:20 -070082 metrics_proto.set_mode(mode);
Ray Essick6ce27e52019-02-15 10:58:05 -080083 }
Brian Lindahlc935ee22021-06-08 09:57:07 +020084 AStatsEvent_writeString(event, mode.c_str());
Andy Hung5be90c82021-03-30 14:30:20 -070085
Ray Essick6ce27e52019-02-15 10:58:05 -080086 int32_t encoder = -1;
Brian Lindahlc935ee22021-06-08 09:57:07 +020087 if (item->getInt32("android.media.mediacodec.encoder", &encoder)) {
Ray Essick6ce27e52019-02-15 10:58:05 -080088 metrics_proto.set_encoder(encoder);
89 }
Brian Lindahlc935ee22021-06-08 09:57:07 +020090 AStatsEvent_writeInt32(event, encoder);
Andy Hung5be90c82021-03-30 14:30:20 -070091
Ray Essick6ce27e52019-02-15 10:58:05 -080092 int32_t secure = -1;
Brian Lindahlc935ee22021-06-08 09:57:07 +020093 if (item->getInt32("android.media.mediacodec.secure", &secure)) {
Ray Essick6ce27e52019-02-15 10:58:05 -080094 metrics_proto.set_secure(secure);
95 }
Brian Lindahlc935ee22021-06-08 09:57:07 +020096 AStatsEvent_writeInt32(event, secure);
Andy Hung5be90c82021-03-30 14:30:20 -070097
Ray Essick6ce27e52019-02-15 10:58:05 -080098 int32_t width = -1;
Brian Lindahlc935ee22021-06-08 09:57:07 +020099 if (item->getInt32("android.media.mediacodec.width", &width)) {
Ray Essick6ce27e52019-02-15 10:58:05 -0800100 metrics_proto.set_width(width);
101 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200102 AStatsEvent_writeInt32(event, width);
Andy Hung5be90c82021-03-30 14:30:20 -0700103
Ray Essick6ce27e52019-02-15 10:58:05 -0800104 int32_t height = -1;
Brian Lindahlc935ee22021-06-08 09:57:07 +0200105 if (item->getInt32("android.media.mediacodec.height", &height)) {
Ray Essick6ce27e52019-02-15 10:58:05 -0800106 metrics_proto.set_height(height);
107 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200108 AStatsEvent_writeInt32(event, height);
Andy Hung5be90c82021-03-30 14:30:20 -0700109
Ray Essick6ce27e52019-02-15 10:58:05 -0800110 int32_t rotation = -1;
Brian Lindahlc935ee22021-06-08 09:57:07 +0200111 if (item->getInt32("android.media.mediacodec.rotation-degrees", &rotation)) {
Ray Essick6ce27e52019-02-15 10:58:05 -0800112 metrics_proto.set_rotation(rotation);
113 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200114 AStatsEvent_writeInt32(event, rotation);
115
Ray Essick6ce27e52019-02-15 10:58:05 -0800116 int32_t crypto = -1;
Brian Lindahlc935ee22021-06-08 09:57:07 +0200117 if (item->getInt32("android.media.mediacodec.crypto", &crypto)) {
Ray Essick6ce27e52019-02-15 10:58:05 -0800118 metrics_proto.set_crypto(crypto);
119 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200120 AStatsEvent_writeInt32(event, crypto);
Andy Hung5be90c82021-03-30 14:30:20 -0700121
Ray Essick6ce27e52019-02-15 10:58:05 -0800122 int32_t profile = -1;
Brian Lindahlc935ee22021-06-08 09:57:07 +0200123 if (item->getInt32("android.media.mediacodec.profile", &profile)) {
Ray Essick6ce27e52019-02-15 10:58:05 -0800124 metrics_proto.set_profile(profile);
125 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200126 AStatsEvent_writeInt32(event, profile);
Andy Hung5be90c82021-03-30 14:30:20 -0700127
Ray Essick6ce27e52019-02-15 10:58:05 -0800128 int32_t level = -1;
Brian Lindahlc935ee22021-06-08 09:57:07 +0200129 if (item->getInt32("android.media.mediacodec.level", &level)) {
Ray Essick6ce27e52019-02-15 10:58:05 -0800130 metrics_proto.set_level(level);
131 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200132 AStatsEvent_writeInt32(event, level);
133
Andy Hung5be90c82021-03-30 14:30:20 -0700134
135 int32_t max_width = -1;
136 if ( item->getInt32("android.media.mediacodec.maxwidth", &max_width)) {
137 metrics_proto.set_max_width(max_width);
Ray Essick6ce27e52019-02-15 10:58:05 -0800138 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200139 AStatsEvent_writeInt32(event, max_width);
Andy Hung5be90c82021-03-30 14:30:20 -0700140
141 int32_t max_height = -1;
142 if ( item->getInt32("android.media.mediacodec.maxheight", &max_height)) {
143 metrics_proto.set_max_height(max_height);
Ray Essick6ce27e52019-02-15 10:58:05 -0800144 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200145 AStatsEvent_writeInt32(event, max_height);
Andy Hung5be90c82021-03-30 14:30:20 -0700146
147 int32_t error_code = -1;
148 if ( item->getInt32("android.media.mediacodec.errcode", &error_code)) {
149 metrics_proto.set_error_code(error_code);
Ray Essick6ce27e52019-02-15 10:58:05 -0800150 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200151 AStatsEvent_writeInt32(event, error_code);
Andy Hung5be90c82021-03-30 14:30:20 -0700152
153 std::string error_state;
154 if ( item->getString("android.media.mediacodec.errstate", &error_state)) {
155 metrics_proto.set_error_state(error_state);
Ray Essick6ce27e52019-02-15 10:58:05 -0800156 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200157 AStatsEvent_writeString(event, error_state.c_str());
Andy Hung5be90c82021-03-30 14:30:20 -0700158
Ray Essick6ce27e52019-02-15 10:58:05 -0800159 int64_t latency_max = -1;
Brian Lindahlc935ee22021-06-08 09:57:07 +0200160 if (item->getInt64("android.media.mediacodec.latency.max", &latency_max)) {
Ray Essick6ce27e52019-02-15 10:58:05 -0800161 metrics_proto.set_latency_max(latency_max);
162 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200163 AStatsEvent_writeInt64(event, latency_max);
Andy Hung5be90c82021-03-30 14:30:20 -0700164
Ray Essick6ce27e52019-02-15 10:58:05 -0800165 int64_t latency_min = -1;
Brian Lindahlc935ee22021-06-08 09:57:07 +0200166 if (item->getInt64("android.media.mediacodec.latency.min", &latency_min)) {
Ray Essick6ce27e52019-02-15 10:58:05 -0800167 metrics_proto.set_latency_min(latency_min);
168 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200169 AStatsEvent_writeInt64(event, latency_min);
Andy Hung5be90c82021-03-30 14:30:20 -0700170
Ray Essick6ce27e52019-02-15 10:58:05 -0800171 int64_t latency_avg = -1;
Brian Lindahlc935ee22021-06-08 09:57:07 +0200172 if (item->getInt64("android.media.mediacodec.latency.avg", &latency_avg)) {
Ray Essick6ce27e52019-02-15 10:58:05 -0800173 metrics_proto.set_latency_avg(latency_avg);
174 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200175 AStatsEvent_writeInt64(event, latency_avg);
Andy Hung5be90c82021-03-30 14:30:20 -0700176
Ray Essick6ce27e52019-02-15 10:58:05 -0800177 int64_t latency_count = -1;
Brian Lindahlc935ee22021-06-08 09:57:07 +0200178 if (item->getInt64("android.media.mediacodec.latency.n", &latency_count)) {
Ray Essick6ce27e52019-02-15 10:58:05 -0800179 metrics_proto.set_latency_count(latency_count);
180 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200181 AStatsEvent_writeInt64(event, latency_count);
Andy Hung5be90c82021-03-30 14:30:20 -0700182
Ray Essick6ce27e52019-02-15 10:58:05 -0800183 int64_t latency_unknown = -1;
Brian Lindahlc935ee22021-06-08 09:57:07 +0200184 if (item->getInt64("android.media.mediacodec.latency.unknown", &latency_unknown)) {
Ray Essick6ce27e52019-02-15 10:58:05 -0800185 metrics_proto.set_latency_unknown(latency_unknown);
186 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200187 AStatsEvent_writeInt64(event, latency_unknown);
Andy Hung5be90c82021-03-30 14:30:20 -0700188
189 int32_t queue_secure_input_buffer_error = -1;
190 if (item->getInt32("android.media.mediacodec.queueSecureInputBufferError",
Brian Lindahlc935ee22021-06-08 09:57:07 +0200191 &queue_secure_input_buffer_error)) {
Andy Hung5be90c82021-03-30 14:30:20 -0700192 metrics_proto.set_queue_secure_input_buffer_error(queue_secure_input_buffer_error);
Edwin Wong4f105392020-02-12 14:55:00 -0800193 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200194 AStatsEvent_writeInt32(event, queue_secure_input_buffer_error);
Andy Hung5be90c82021-03-30 14:30:20 -0700195
196 int32_t queue_input_buffer_error = -1;
197 if (item->getInt32("android.media.mediacodec.queueInputBufferError",
Brian Lindahlc935ee22021-06-08 09:57:07 +0200198 &queue_input_buffer_error)) {
Andy Hung5be90c82021-03-30 14:30:20 -0700199 metrics_proto.set_queue_input_buffer_error(queue_input_buffer_error);
Edwin Wong4f105392020-02-12 14:55:00 -0800200 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200201 AStatsEvent_writeInt32(event, queue_input_buffer_error);
Ray Essick6ce27e52019-02-15 10:58:05 -0800202
Ray Essicka21a3d32020-05-10 21:08:10 -0700203 std::string bitrate_mode;
204 if (item->getString("android.media.mediacodec.bitrate_mode", &bitrate_mode)) {
Andy Hung5be90c82021-03-30 14:30:20 -0700205 metrics_proto.set_bitrate_mode(bitrate_mode);
Ray Essicka21a3d32020-05-10 21:08:10 -0700206 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200207 AStatsEvent_writeString(event, bitrate_mode.c_str());
Andy Hung5be90c82021-03-30 14:30:20 -0700208
Ray Essicka21a3d32020-05-10 21:08:10 -0700209 int32_t bitrate = -1;
210 if (item->getInt32("android.media.mediacodec.bitrate", &bitrate)) {
211 metrics_proto.set_bitrate(bitrate);
212 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200213 AStatsEvent_writeInt32(event, bitrate);
Andy Hung5be90c82021-03-30 14:30:20 -0700214
215 int64_t lifetime_millis = -1;
216 if (item->getInt64("android.media.mediacodec.lifetimeMs", &lifetime_millis)) {
217 lifetime_millis = mediametrics::bucket_time_minutes(lifetime_millis);
218 metrics_proto.set_lifetime_millis(lifetime_millis);
Ray Essicka21a3d32020-05-10 21:08:10 -0700219 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200220 AStatsEvent_writeInt64(event, lifetime_millis);
Ray Essicka21a3d32020-05-10 21:08:10 -0700221
Brian Lindahlc935ee22021-06-08 09:57:07 +0200222 int64_t playback_duration_sec = -1;
223 item->getInt64("android.media.mediacodec.playback-duration-sec", &playback_duration_sec);
224 // DO NOT record playback-duration in the metrics_proto - it should only
225 // exist in the flattened atom
226 AStatsEvent_writeInt64(event, playback_duration_sec);
227
228 std::string sessionId;
229 if (item->getString("android.media.mediacodec.log-session-id", &sessionId)) {
230 metrics_proto.set_log_session_id(sessionId);
231 }
232 AStatsEvent_writeString(event, codec.c_str());
233
Dichen Zhang0de05752021-04-21 19:47:07 -0700234 int32_t channelCount = -1;
Brian Lindahlc935ee22021-06-08 09:57:07 +0200235 if (item->getInt32("android.media.mediacodec.channelCount", &channelCount)) {
Dichen Zhang0de05752021-04-21 19:47:07 -0700236 metrics_proto.set_channel_count(channelCount);
237 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200238 AStatsEvent_writeInt32(event, channelCount);
Ray Essick87913312021-03-02 10:45:54 -0800239
Dichen Zhang0de05752021-04-21 19:47:07 -0700240 int32_t sampleRate = -1;
Brian Lindahlc935ee22021-06-08 09:57:07 +0200241 if (item->getInt32("android.media.mediacodec.sampleRate", &sampleRate)) {
Dichen Zhang0de05752021-04-21 19:47:07 -0700242 metrics_proto.set_sample_rate(sampleRate);
243 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200244 AStatsEvent_writeInt32(event, sampleRate);
Dichen Zhang0de05752021-04-21 19:47:07 -0700245
Ray Essick87913312021-03-02 10:45:54 -0800246 // TODO PWG may want these fuzzed up a bit to obscure some precision
Dichen Zhang0de05752021-04-21 19:47:07 -0700247 int64_t bytes = -1;
Brian Lindahlc935ee22021-06-08 09:57:07 +0200248 if (item->getInt64("android.media.mediacodec.vencode.bytes", &bytes)) {
Dichen Zhang0de05752021-04-21 19:47:07 -0700249 metrics_proto.set_video_encode_bytes(bytes);
250 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200251 AStatsEvent_writeInt64(event, bytes);
Dichen Zhang0de05752021-04-21 19:47:07 -0700252
Dichen Zhang0de05752021-04-21 19:47:07 -0700253 int64_t frames = -1;
Brian Lindahlc935ee22021-06-08 09:57:07 +0200254 if (item->getInt64("android.media.mediacodec.vencode.frames", &frames)) {
Dichen Zhang0de05752021-04-21 19:47:07 -0700255 metrics_proto.set_video_encode_frames(frames);
256 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200257 AStatsEvent_writeInt64(event, frames);
Dichen Zhang0de05752021-04-21 19:47:07 -0700258
Dichen Zhang0de05752021-04-21 19:47:07 -0700259 int64_t inputBytes = -1;
Brian Lindahlc935ee22021-06-08 09:57:07 +0200260 if (item->getInt64("android.media.mediacodec.video.input.bytes", &inputBytes)) {
Dichen Zhang0de05752021-04-21 19:47:07 -0700261 metrics_proto.set_video_input_bytes(inputBytes);
262 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200263 AStatsEvent_writeInt64(event, inputBytes);
Dichen Zhang0de05752021-04-21 19:47:07 -0700264
Dichen Zhang0de05752021-04-21 19:47:07 -0700265 int64_t inputFrames = -1;
Brian Lindahlc935ee22021-06-08 09:57:07 +0200266 if (item->getInt64("android.media.mediacodec.video.input.frames", &inputFrames)) {
Dichen Zhang0de05752021-04-21 19:47:07 -0700267 metrics_proto.set_video_input_frames(inputFrames);
268 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200269 AStatsEvent_writeInt64(event, inputFrames);
Ray Essick87913312021-03-02 10:45:54 -0800270
Brian Lindahlc935ee22021-06-08 09:57:07 +0200271 int64_t durationUs = -1;
272 if (item->getInt64("android.media.mediacodec.vencode.durationUs", &durationUs)) {
273 metrics_proto.set_video_encode_duration_us(durationUs);
274 }
275 AStatsEvent_writeInt64(event, durationUs);
276
277 int32_t colorFormat = -1;
278 if (item->getInt32("android.media.mediacodec.color-format", &colorFormat)) {
279 metrics_proto.set_color_format(colorFormat);
280 }
281 AStatsEvent_writeInt32(event, colorFormat);
282
283 double frameRate = -1.0;
284 if (item->getDouble("android.media.mediacodec.frame-rate", &frameRate)) {
285 metrics_proto.set_frame_rate(frameRate);
286 }
287 AStatsEvent_writeFloat(event, (float) frameRate);
288
289 double captureRate = -1.0;
290 if (item->getDouble("android.media.mediacodec.capture-rate", &captureRate)) {
291 metrics_proto.set_capture_rate(captureRate);
292 }
293 AStatsEvent_writeFloat(event, (float) captureRate);
294
295 double operatingRate = -1.0;
296 if (item->getDouble("android.media.mediacodec.operating-rate", &operatingRate)) {
297 metrics_proto.set_operating_rate(operatingRate);
298 }
299 AStatsEvent_writeFloat(event, (float) operatingRate);
300
301 int32_t priority = -1;
302 if (item->getInt32("android.media.mediacodec.priority", &priority)) {
303 metrics_proto.set_priority(priority);
304 }
305 AStatsEvent_writeInt32(event, priority);
306
307 int32_t qpIMin = -1;
308 if (item->getInt32("android.media.mediacodec.video-qp-i-min", &qpIMin)) {
309 metrics_proto.set_video_qp_i_min(qpIMin);
310 }
311 AStatsEvent_writeInt32(event, qpIMin);
312
313 int32_t qpIMax = -1;
314 if (item->getInt32("android.media.mediacodec.video-qp-i-max", &qpIMax)) {
315 metrics_proto.set_video_qp_i_max(qpIMax);
316 }
317 AStatsEvent_writeInt32(event, qpIMax);
318
319 int32_t qpPMin = -1;
320 if (item->getInt32("android.media.mediacodec.video-qp-p-min", &qpPMin)) {
321 metrics_proto.set_video_qp_p_min(qpPMin);
322 }
323 AStatsEvent_writeInt32(event, qpPMin);
324
325 int32_t qpPMax = -1;
326 if (item->getInt32("android.media.mediacodec.video-qp-p-max", &qpPMax)) {
327 metrics_proto.set_video_qp_p_max(qpPMax);
328 }
329 AStatsEvent_writeInt32(event, qpPMax);
330
331 int32_t qpBMin = -1;
332 if (item->getInt32("android.media.mediacodec.video-qp-b-min", &qpBMin)) {
333 metrics_proto.set_video_qp_b_min(qpBMin);
334 }
335 AStatsEvent_writeInt32(event, qpBMin);
336
337 int32_t qpBMax = -1;
338 if (item->getInt32("android.media.mediacodec.video-qp-b-max", &qpBMax)) {
339 metrics_proto.set_video_qp_b_max(qpBMax);
340 }
341 AStatsEvent_writeInt32(event, qpBMax);
342
Dichen Zhange5bad782021-04-28 12:11:35 -0700343 int32_t originalBitrate = -1;
Brian Lindahlc935ee22021-06-08 09:57:07 +0200344 if (item->getInt32("android.media.mediacodec.original.bitrate", &originalBitrate)) {
Dichen Zhange5bad782021-04-28 12:11:35 -0700345 metrics_proto.set_original_bitrate(originalBitrate);
346 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200347 AStatsEvent_writeInt32(event, originalBitrate);
Dichen Zhange5bad782021-04-28 12:11:35 -0700348
Dichen Zhang57be6302021-05-18 18:20:31 -0700349 int32_t shapingEnhanced = -1;
350 if ( item->getInt32("android.media.mediacodec.shaped", &shapingEnhanced)) {
351 metrics_proto.set_shaping_enhanced(shapingEnhanced);
352 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200353 AStatsEvent_writeInt32(event, shapingEnhanced);
Dichen Zhang57be6302021-05-18 18:20:31 -0700354
Dichen Zhang57be6302021-05-18 18:20:31 -0700355 int32_t qpIMinOri = -1;
356 if ( item->getInt32("android.media.mediacodec.original-video-qp-i-min", &qpIMinOri)) {
357 metrics_proto.set_original_video_qp_i_min(qpIMinOri);
358 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200359 AStatsEvent_writeInt32(event, qpIMinOri);
Dichen Zhang57be6302021-05-18 18:20:31 -0700360
Dichen Zhang57be6302021-05-18 18:20:31 -0700361 int32_t qpIMaxOri = -1;
362 if ( item->getInt32("android.media.mediacodec.original-video-qp-i-max", &qpIMaxOri)) {
363 metrics_proto.set_original_video_qp_i_max(qpIMaxOri);
364 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200365 AStatsEvent_writeInt32(event, qpIMaxOri);
Dichen Zhang57be6302021-05-18 18:20:31 -0700366
Dichen Zhang57be6302021-05-18 18:20:31 -0700367 int32_t qpPMinOri = -1;
368 if ( item->getInt32("android.media.mediacodec.original-video-qp-p-min", &qpPMinOri)) {
369 metrics_proto.set_original_video_qp_p_min(qpPMinOri);
370 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200371 AStatsEvent_writeInt32(event, qpPMinOri);
Dichen Zhang57be6302021-05-18 18:20:31 -0700372
Dichen Zhang57be6302021-05-18 18:20:31 -0700373 int32_t qpPMaxOri = -1;
374 if ( item->getInt32("android.media.mediacodec.original-video-qp-p-max", &qpPMaxOri)) {
375 metrics_proto.set_original_video_qp_p_max(qpPMaxOri);
376 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200377 AStatsEvent_writeInt32(event, qpPMaxOri);
Dichen Zhang57be6302021-05-18 18:20:31 -0700378
Dichen Zhang57be6302021-05-18 18:20:31 -0700379 int32_t qpBMinOri = -1;
380 if ( item->getInt32("android.media.mediacodec.original-video-qp-b-min", &qpBMinOri)) {
Brian Lindahlc935ee22021-06-08 09:57:07 +0200381 metrics_proto.set_original_video_qp_b_min(qpBMinOri);
Dichen Zhang57be6302021-05-18 18:20:31 -0700382 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200383 AStatsEvent_writeInt32(event, qpBMinOri);
Dichen Zhang57be6302021-05-18 18:20:31 -0700384
Dichen Zhang57be6302021-05-18 18:20:31 -0700385 int32_t qpBMaxOri = -1;
386 if ( item->getInt32("android.media.mediacodec.original-video-qp-b-max", &qpBMaxOri)) {
387 metrics_proto.set_original_video_qp_b_max(qpBMaxOri);
388 }
Brian Lindahlc935ee22021-06-08 09:57:07 +0200389 AStatsEvent_writeInt32(event, qpBMaxOri);
390
391 int err = AStatsEvent_write(event);
392 if (err < 0) {
393 ALOGE("Failed to write codec metrics to statsd (%d)", err);
394 }
395 AStatsEvent_release(event);
Dichen Zhang57be6302021-05-18 18:20:31 -0700396
Ray Essick6ce27e52019-02-15 10:58:05 -0800397 std::string serialized;
398 if (!metrics_proto.SerializeToString(&serialized)) {
399 ALOGE("Failed to serialize codec metrics");
400 return false;
401 }
Andy Hung5be90c82021-03-30 14:30:20 -0700402 android::util::BytesField bf_serialized( serialized.c_str(), serialized.size());
403 int result = android::util::stats_write(android::util::MEDIAMETRICS_CODEC_REPORTED,
404 timestamp_nanos, package_name.c_str(), package_version_code,
405 media_apex_version,
406 bf_serialized);
Brian Lindahlc935ee22021-06-08 09:57:07 +0200407
Andy Hung5be90c82021-03-30 14:30:20 -0700408 std::stringstream log;
409 log << "result:" << result << " {"
410 << " mediametrics_codec_reported:"
411 << android::util::MEDIAMETRICS_CODEC_REPORTED
412 << " timestamp_nanos:" << timestamp_nanos
413 << " package_name:" << package_name
414 << " package_version_code:" << package_version_code
415 << " media_apex_version:" << media_apex_version
Ray Essick6ce27e52019-02-15 10:58:05 -0800416
Andy Hung5be90c82021-03-30 14:30:20 -0700417 << " codec:" << codec
418 << " mime:" << mime
419 << " mode:" << mode
420 << " encoder:" << encoder
421 << " secure:" << secure
422 << " width:" << width
423 << " height:" << height
424 << " rotation:" << rotation
425 << " crypto:" << crypto
426 << " profile:" << profile
Ray Essick6ce27e52019-02-15 10:58:05 -0800427
Andy Hung5be90c82021-03-30 14:30:20 -0700428 << " level:" << level
429 << " max_width:" << max_width
430 << " max_height:" << max_height
431 << " error_code:" << error_code
432 << " error_state:" << error_state
433 << " latency_max:" << latency_max
434 << " latency_min:" << latency_min
435 << " latency_avg:" << latency_avg
436 << " latency_count:" << latency_count
437 << " latency_unknown:" << latency_unknown
Ray Essick6ce27e52019-02-15 10:58:05 -0800438
Andy Hung5be90c82021-03-30 14:30:20 -0700439 << " queue_input_buffer_error:" << queue_input_buffer_error
440 << " queue_secure_input_buffer_error:" << queue_secure_input_buffer_error
441 << " bitrate_mode:" << bitrate_mode
442 << " bitrate:" << bitrate
Dichen Zhang57be6302021-05-18 18:20:31 -0700443 << " original_bitrate:" << originalBitrate
Andy Hung5be90c82021-03-30 14:30:20 -0700444 << " lifetime_millis:" << lifetime_millis
Brian Lindahlc935ee22021-06-08 09:57:07 +0200445 << " playback_duration_seconds:" << playback_duration_sec
Dichen Zhang57be6302021-05-18 18:20:31 -0700446 << " log_session_id:" << sessionId
447 << " channel_count:" << channelCount
448 << " sample_rate:" << sampleRate
449 << " encode_bytes:" << bytes
450 << " encode_frames:" << frames
451 << " encode_duration_us:" << durationUs
452 << " color_format:" << colorFormat
453 << " frame_rate:" << frameRate
454 << " capture_rate:" << captureRate
455 << " operating_rate:" << operatingRate
456 << " priority:" << priority
457 << " shaping_enhanced:" << shapingEnhanced
458
459 << " qp_i_min:" << qpIMin
460 << " qp_i_max:" << qpIMax
461 << " qp_p_min:" << qpPMin
462 << " qp_p_max:" << qpPMax
463 << " qp_b_min:" << qpBMin
464 << " qp_b_max:" << qpBMax
465 << " original_qp_i_min:" << qpIMinOri
466 << " original_qp_i_max:" << qpIMaxOri
467 << " original_qp_p_min:" << qpPMinOri
468 << " original_qp_p_max:" << qpPMaxOri
469 << " original_qp_b_min:" << qpBMinOri
470 << " original_qp_b_max:" << qpBMaxOri
Andy Hung5be90c82021-03-30 14:30:20 -0700471 << " }";
472 statsdLog->log(android::util::MEDIAMETRICS_CODEC_REPORTED, log.str());
Brian Lindahlc935ee22021-06-08 09:57:07 +0200473
474
Ray Essick6ce27e52019-02-15 10:58:05 -0800475 return true;
476}
477
Andy Hung3ab1b322020-05-18 10:47:31 -0700478} // namespace android