Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 1 | /* |
| 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 Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 33 | #include <stats_event.h> |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 34 | |
Ray Essick | 5a55729 | 2020-06-10 21:31:33 -0700 | [diff] [blame] | 35 | #include "cleaner.h" |
Ray Essick | 40e8e5e | 2019-12-05 20:19:40 -0800 | [diff] [blame] | 36 | #include "MediaMetricsService.h" |
Andy Hung | 11e60d7 | 2021-07-08 10:02:11 -0700 | [diff] [blame^] | 37 | #include "StringUtils.h" |
Dichen Zhang | b8f23c5 | 2021-03-22 00:56:29 -0700 | [diff] [blame] | 38 | #include "frameworks/proto_logging/stats/message/mediametrics_message.pb.h" |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 39 | #include "iface_statsd.h" |
| 40 | |
| 41 | namespace android { |
| 42 | |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 43 | bool statsd_codec(const std::shared_ptr<const mediametrics::Item>& item, |
| 44 | const std::shared_ptr<mediametrics::StatsdLog>& statsdLog) |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 45 | { |
Andy Hung | 3ab1b32 | 2020-05-18 10:47:31 -0700 | [diff] [blame] | 46 | if (item == nullptr) return false; |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 47 | |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 48 | AStatsEvent* event = AStatsEvent_obtain(); |
| 49 | AStatsEvent_setAtomId(event, android::util::MEDIA_CODEC_REPORTED); |
| 50 | |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 51 | const nsecs_t timestamp_nanos = MediaMetricsService::roundTime(item->getTimestamp()); |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 52 | AStatsEvent_writeInt64(event, timestamp_nanos); |
| 53 | |
| 54 | std::string package_name = item->getPkgName(); |
| 55 | AStatsEvent_writeString(event, package_name.c_str()); |
| 56 | |
| 57 | int64_t package_version_code = item->getPkgVersionCode(); |
| 58 | AStatsEvent_writeInt64(event, package_version_code); |
| 59 | |
| 60 | int64_t media_apex_version = 0; |
| 61 | AStatsEvent_writeInt64(event, media_apex_version); |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 62 | |
| 63 | // the rest into our own proto |
| 64 | // |
Dichen Zhang | b8f23c5 | 2021-03-22 00:56:29 -0700 | [diff] [blame] | 65 | ::android::stats::mediametrics_message::CodecData metrics_proto; |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 66 | |
| 67 | // flesh out the protobuf we'll hand off with our data |
| 68 | // |
George Burgess IV | 0d81443 | 2019-10-23 11:32:26 -0700 | [diff] [blame] | 69 | std::string codec; |
| 70 | if (item->getString("android.media.mediacodec.codec", &codec)) { |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 71 | metrics_proto.set_codec(codec); |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 72 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 73 | AStatsEvent_writeString(event, codec.c_str()); |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 74 | |
George Burgess IV | 0d81443 | 2019-10-23 11:32:26 -0700 | [diff] [blame] | 75 | std::string mime; |
| 76 | if (item->getString("android.media.mediacodec.mime", &mime)) { |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 77 | metrics_proto.set_mime(mime); |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 78 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 79 | AStatsEvent_writeString(event, mime.c_str()); |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 80 | |
George Burgess IV | 0d81443 | 2019-10-23 11:32:26 -0700 | [diff] [blame] | 81 | std::string mode; |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 82 | if (item->getString("android.media.mediacodec.mode", &mode)) { |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 83 | metrics_proto.set_mode(mode); |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 84 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 85 | AStatsEvent_writeString(event, mode.c_str()); |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 86 | |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 87 | int32_t encoder = -1; |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 88 | if (item->getInt32("android.media.mediacodec.encoder", &encoder)) { |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 89 | metrics_proto.set_encoder(encoder); |
| 90 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 91 | AStatsEvent_writeInt32(event, encoder); |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 92 | |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 93 | int32_t secure = -1; |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 94 | if (item->getInt32("android.media.mediacodec.secure", &secure)) { |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 95 | metrics_proto.set_secure(secure); |
| 96 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 97 | AStatsEvent_writeInt32(event, secure); |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 98 | |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 99 | int32_t width = -1; |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 100 | if (item->getInt32("android.media.mediacodec.width", &width)) { |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 101 | metrics_proto.set_width(width); |
| 102 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 103 | AStatsEvent_writeInt32(event, width); |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 104 | |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 105 | int32_t height = -1; |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 106 | if (item->getInt32("android.media.mediacodec.height", &height)) { |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 107 | metrics_proto.set_height(height); |
| 108 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 109 | AStatsEvent_writeInt32(event, height); |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 110 | |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 111 | int32_t rotation = -1; |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 112 | if (item->getInt32("android.media.mediacodec.rotation-degrees", &rotation)) { |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 113 | metrics_proto.set_rotation(rotation); |
| 114 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 115 | AStatsEvent_writeInt32(event, rotation); |
| 116 | |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 117 | int32_t crypto = -1; |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 118 | if (item->getInt32("android.media.mediacodec.crypto", &crypto)) { |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 119 | metrics_proto.set_crypto(crypto); |
| 120 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 121 | AStatsEvent_writeInt32(event, crypto); |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 122 | |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 123 | int32_t profile = -1; |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 124 | if (item->getInt32("android.media.mediacodec.profile", &profile)) { |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 125 | metrics_proto.set_profile(profile); |
| 126 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 127 | AStatsEvent_writeInt32(event, profile); |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 128 | |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 129 | int32_t level = -1; |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 130 | if (item->getInt32("android.media.mediacodec.level", &level)) { |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 131 | metrics_proto.set_level(level); |
| 132 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 133 | AStatsEvent_writeInt32(event, level); |
| 134 | |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 135 | |
| 136 | int32_t max_width = -1; |
| 137 | if ( item->getInt32("android.media.mediacodec.maxwidth", &max_width)) { |
| 138 | metrics_proto.set_max_width(max_width); |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 139 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 140 | AStatsEvent_writeInt32(event, max_width); |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 141 | |
| 142 | int32_t max_height = -1; |
| 143 | if ( item->getInt32("android.media.mediacodec.maxheight", &max_height)) { |
| 144 | metrics_proto.set_max_height(max_height); |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 145 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 146 | AStatsEvent_writeInt32(event, max_height); |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 147 | |
| 148 | int32_t error_code = -1; |
| 149 | if ( item->getInt32("android.media.mediacodec.errcode", &error_code)) { |
| 150 | metrics_proto.set_error_code(error_code); |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 151 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 152 | AStatsEvent_writeInt32(event, error_code); |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 153 | |
| 154 | std::string error_state; |
| 155 | if ( item->getString("android.media.mediacodec.errstate", &error_state)) { |
| 156 | metrics_proto.set_error_state(error_state); |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 157 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 158 | AStatsEvent_writeString(event, error_state.c_str()); |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 159 | |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 160 | int64_t latency_max = -1; |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 161 | if (item->getInt64("android.media.mediacodec.latency.max", &latency_max)) { |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 162 | metrics_proto.set_latency_max(latency_max); |
| 163 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 164 | AStatsEvent_writeInt64(event, latency_max); |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 165 | |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 166 | int64_t latency_min = -1; |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 167 | if (item->getInt64("android.media.mediacodec.latency.min", &latency_min)) { |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 168 | metrics_proto.set_latency_min(latency_min); |
| 169 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 170 | AStatsEvent_writeInt64(event, latency_min); |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 171 | |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 172 | int64_t latency_avg = -1; |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 173 | if (item->getInt64("android.media.mediacodec.latency.avg", &latency_avg)) { |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 174 | metrics_proto.set_latency_avg(latency_avg); |
| 175 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 176 | AStatsEvent_writeInt64(event, latency_avg); |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 177 | |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 178 | int64_t latency_count = -1; |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 179 | if (item->getInt64("android.media.mediacodec.latency.n", &latency_count)) { |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 180 | metrics_proto.set_latency_count(latency_count); |
| 181 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 182 | AStatsEvent_writeInt64(event, latency_count); |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 183 | |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 184 | int64_t latency_unknown = -1; |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 185 | if (item->getInt64("android.media.mediacodec.latency.unknown", &latency_unknown)) { |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 186 | metrics_proto.set_latency_unknown(latency_unknown); |
| 187 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 188 | AStatsEvent_writeInt64(event, latency_unknown); |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 189 | |
| 190 | int32_t queue_secure_input_buffer_error = -1; |
| 191 | if (item->getInt32("android.media.mediacodec.queueSecureInputBufferError", |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 192 | &queue_secure_input_buffer_error)) { |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 193 | metrics_proto.set_queue_secure_input_buffer_error(queue_secure_input_buffer_error); |
Edwin Wong | 4f10539 | 2020-02-12 14:55:00 -0800 | [diff] [blame] | 194 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 195 | AStatsEvent_writeInt32(event, queue_secure_input_buffer_error); |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 196 | |
| 197 | int32_t queue_input_buffer_error = -1; |
| 198 | if (item->getInt32("android.media.mediacodec.queueInputBufferError", |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 199 | &queue_input_buffer_error)) { |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 200 | metrics_proto.set_queue_input_buffer_error(queue_input_buffer_error); |
Edwin Wong | 4f10539 | 2020-02-12 14:55:00 -0800 | [diff] [blame] | 201 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 202 | AStatsEvent_writeInt32(event, queue_input_buffer_error); |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 203 | |
Ray Essick | a21a3d3 | 2020-05-10 21:08:10 -0700 | [diff] [blame] | 204 | std::string bitrate_mode; |
| 205 | if (item->getString("android.media.mediacodec.bitrate_mode", &bitrate_mode)) { |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 206 | metrics_proto.set_bitrate_mode(bitrate_mode); |
Ray Essick | a21a3d3 | 2020-05-10 21:08:10 -0700 | [diff] [blame] | 207 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 208 | AStatsEvent_writeString(event, bitrate_mode.c_str()); |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 209 | |
Ray Essick | a21a3d3 | 2020-05-10 21:08:10 -0700 | [diff] [blame] | 210 | int32_t bitrate = -1; |
| 211 | if (item->getInt32("android.media.mediacodec.bitrate", &bitrate)) { |
| 212 | metrics_proto.set_bitrate(bitrate); |
| 213 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 214 | AStatsEvent_writeInt32(event, bitrate); |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 215 | |
| 216 | int64_t lifetime_millis = -1; |
| 217 | if (item->getInt64("android.media.mediacodec.lifetimeMs", &lifetime_millis)) { |
| 218 | lifetime_millis = mediametrics::bucket_time_minutes(lifetime_millis); |
| 219 | metrics_proto.set_lifetime_millis(lifetime_millis); |
Ray Essick | a21a3d3 | 2020-05-10 21:08:10 -0700 | [diff] [blame] | 220 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 221 | AStatsEvent_writeInt64(event, lifetime_millis); |
Ray Essick | a21a3d3 | 2020-05-10 21:08:10 -0700 | [diff] [blame] | 222 | |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 223 | int64_t playback_duration_sec = -1; |
| 224 | item->getInt64("android.media.mediacodec.playback-duration-sec", &playback_duration_sec); |
| 225 | // DO NOT record playback-duration in the metrics_proto - it should only |
| 226 | // exist in the flattened atom |
| 227 | AStatsEvent_writeInt64(event, playback_duration_sec); |
| 228 | |
| 229 | std::string sessionId; |
| 230 | if (item->getString("android.media.mediacodec.log-session-id", &sessionId)) { |
Andy Hung | 11e60d7 | 2021-07-08 10:02:11 -0700 | [diff] [blame^] | 231 | sessionId = mediametrics::stringutils::sanitizeLogSessionId(sessionId); |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 232 | metrics_proto.set_log_session_id(sessionId); |
| 233 | } |
| 234 | AStatsEvent_writeString(event, codec.c_str()); |
| 235 | |
Dichen Zhang | 0de0575 | 2021-04-21 19:47:07 -0700 | [diff] [blame] | 236 | int32_t channelCount = -1; |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 237 | if (item->getInt32("android.media.mediacodec.channelCount", &channelCount)) { |
Dichen Zhang | 0de0575 | 2021-04-21 19:47:07 -0700 | [diff] [blame] | 238 | metrics_proto.set_channel_count(channelCount); |
| 239 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 240 | AStatsEvent_writeInt32(event, channelCount); |
Ray Essick | 8791331 | 2021-03-02 10:45:54 -0800 | [diff] [blame] | 241 | |
Dichen Zhang | 0de0575 | 2021-04-21 19:47:07 -0700 | [diff] [blame] | 242 | int32_t sampleRate = -1; |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 243 | if (item->getInt32("android.media.mediacodec.sampleRate", &sampleRate)) { |
Dichen Zhang | 0de0575 | 2021-04-21 19:47:07 -0700 | [diff] [blame] | 244 | metrics_proto.set_sample_rate(sampleRate); |
| 245 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 246 | AStatsEvent_writeInt32(event, sampleRate); |
Dichen Zhang | 0de0575 | 2021-04-21 19:47:07 -0700 | [diff] [blame] | 247 | |
Ray Essick | 8791331 | 2021-03-02 10:45:54 -0800 | [diff] [blame] | 248 | // TODO PWG may want these fuzzed up a bit to obscure some precision |
Dichen Zhang | 0de0575 | 2021-04-21 19:47:07 -0700 | [diff] [blame] | 249 | int64_t bytes = -1; |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 250 | if (item->getInt64("android.media.mediacodec.vencode.bytes", &bytes)) { |
Dichen Zhang | 0de0575 | 2021-04-21 19:47:07 -0700 | [diff] [blame] | 251 | metrics_proto.set_video_encode_bytes(bytes); |
| 252 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 253 | AStatsEvent_writeInt64(event, bytes); |
Dichen Zhang | 0de0575 | 2021-04-21 19:47:07 -0700 | [diff] [blame] | 254 | |
Dichen Zhang | 0de0575 | 2021-04-21 19:47:07 -0700 | [diff] [blame] | 255 | int64_t frames = -1; |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 256 | if (item->getInt64("android.media.mediacodec.vencode.frames", &frames)) { |
Dichen Zhang | 0de0575 | 2021-04-21 19:47:07 -0700 | [diff] [blame] | 257 | metrics_proto.set_video_encode_frames(frames); |
| 258 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 259 | AStatsEvent_writeInt64(event, frames); |
Dichen Zhang | 0de0575 | 2021-04-21 19:47:07 -0700 | [diff] [blame] | 260 | |
Dichen Zhang | 0de0575 | 2021-04-21 19:47:07 -0700 | [diff] [blame] | 261 | int64_t inputBytes = -1; |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 262 | if (item->getInt64("android.media.mediacodec.video.input.bytes", &inputBytes)) { |
Dichen Zhang | 0de0575 | 2021-04-21 19:47:07 -0700 | [diff] [blame] | 263 | metrics_proto.set_video_input_bytes(inputBytes); |
| 264 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 265 | AStatsEvent_writeInt64(event, inputBytes); |
Dichen Zhang | 0de0575 | 2021-04-21 19:47:07 -0700 | [diff] [blame] | 266 | |
Dichen Zhang | 0de0575 | 2021-04-21 19:47:07 -0700 | [diff] [blame] | 267 | int64_t inputFrames = -1; |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 268 | if (item->getInt64("android.media.mediacodec.video.input.frames", &inputFrames)) { |
Dichen Zhang | 0de0575 | 2021-04-21 19:47:07 -0700 | [diff] [blame] | 269 | metrics_proto.set_video_input_frames(inputFrames); |
| 270 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 271 | AStatsEvent_writeInt64(event, inputFrames); |
Ray Essick | 8791331 | 2021-03-02 10:45:54 -0800 | [diff] [blame] | 272 | |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 273 | int64_t durationUs = -1; |
| 274 | if (item->getInt64("android.media.mediacodec.vencode.durationUs", &durationUs)) { |
| 275 | metrics_proto.set_video_encode_duration_us(durationUs); |
| 276 | } |
| 277 | AStatsEvent_writeInt64(event, durationUs); |
| 278 | |
| 279 | int32_t colorFormat = -1; |
| 280 | if (item->getInt32("android.media.mediacodec.color-format", &colorFormat)) { |
| 281 | metrics_proto.set_color_format(colorFormat); |
| 282 | } |
| 283 | AStatsEvent_writeInt32(event, colorFormat); |
| 284 | |
| 285 | double frameRate = -1.0; |
| 286 | if (item->getDouble("android.media.mediacodec.frame-rate", &frameRate)) { |
| 287 | metrics_proto.set_frame_rate(frameRate); |
| 288 | } |
| 289 | AStatsEvent_writeFloat(event, (float) frameRate); |
| 290 | |
| 291 | double captureRate = -1.0; |
| 292 | if (item->getDouble("android.media.mediacodec.capture-rate", &captureRate)) { |
| 293 | metrics_proto.set_capture_rate(captureRate); |
| 294 | } |
| 295 | AStatsEvent_writeFloat(event, (float) captureRate); |
| 296 | |
| 297 | double operatingRate = -1.0; |
| 298 | if (item->getDouble("android.media.mediacodec.operating-rate", &operatingRate)) { |
| 299 | metrics_proto.set_operating_rate(operatingRate); |
| 300 | } |
| 301 | AStatsEvent_writeFloat(event, (float) operatingRate); |
| 302 | |
| 303 | int32_t priority = -1; |
| 304 | if (item->getInt32("android.media.mediacodec.priority", &priority)) { |
| 305 | metrics_proto.set_priority(priority); |
| 306 | } |
| 307 | AStatsEvent_writeInt32(event, priority); |
| 308 | |
| 309 | int32_t qpIMin = -1; |
| 310 | if (item->getInt32("android.media.mediacodec.video-qp-i-min", &qpIMin)) { |
| 311 | metrics_proto.set_video_qp_i_min(qpIMin); |
| 312 | } |
| 313 | AStatsEvent_writeInt32(event, qpIMin); |
| 314 | |
| 315 | int32_t qpIMax = -1; |
| 316 | if (item->getInt32("android.media.mediacodec.video-qp-i-max", &qpIMax)) { |
| 317 | metrics_proto.set_video_qp_i_max(qpIMax); |
| 318 | } |
| 319 | AStatsEvent_writeInt32(event, qpIMax); |
| 320 | |
| 321 | int32_t qpPMin = -1; |
| 322 | if (item->getInt32("android.media.mediacodec.video-qp-p-min", &qpPMin)) { |
| 323 | metrics_proto.set_video_qp_p_min(qpPMin); |
| 324 | } |
| 325 | AStatsEvent_writeInt32(event, qpPMin); |
| 326 | |
| 327 | int32_t qpPMax = -1; |
| 328 | if (item->getInt32("android.media.mediacodec.video-qp-p-max", &qpPMax)) { |
| 329 | metrics_proto.set_video_qp_p_max(qpPMax); |
| 330 | } |
| 331 | AStatsEvent_writeInt32(event, qpPMax); |
| 332 | |
| 333 | int32_t qpBMin = -1; |
| 334 | if (item->getInt32("android.media.mediacodec.video-qp-b-min", &qpBMin)) { |
| 335 | metrics_proto.set_video_qp_b_min(qpBMin); |
| 336 | } |
| 337 | AStatsEvent_writeInt32(event, qpBMin); |
| 338 | |
| 339 | int32_t qpBMax = -1; |
| 340 | if (item->getInt32("android.media.mediacodec.video-qp-b-max", &qpBMax)) { |
| 341 | metrics_proto.set_video_qp_b_max(qpBMax); |
| 342 | } |
| 343 | AStatsEvent_writeInt32(event, qpBMax); |
| 344 | |
Dichen Zhang | e5bad78 | 2021-04-28 12:11:35 -0700 | [diff] [blame] | 345 | int32_t originalBitrate = -1; |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 346 | if (item->getInt32("android.media.mediacodec.original.bitrate", &originalBitrate)) { |
Dichen Zhang | e5bad78 | 2021-04-28 12:11:35 -0700 | [diff] [blame] | 347 | metrics_proto.set_original_bitrate(originalBitrate); |
| 348 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 349 | AStatsEvent_writeInt32(event, originalBitrate); |
Dichen Zhang | e5bad78 | 2021-04-28 12:11:35 -0700 | [diff] [blame] | 350 | |
Dichen Zhang | 57be630 | 2021-05-18 18:20:31 -0700 | [diff] [blame] | 351 | int32_t shapingEnhanced = -1; |
| 352 | if ( item->getInt32("android.media.mediacodec.shaped", &shapingEnhanced)) { |
| 353 | metrics_proto.set_shaping_enhanced(shapingEnhanced); |
| 354 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 355 | AStatsEvent_writeInt32(event, shapingEnhanced); |
Dichen Zhang | 57be630 | 2021-05-18 18:20:31 -0700 | [diff] [blame] | 356 | |
Dichen Zhang | 57be630 | 2021-05-18 18:20:31 -0700 | [diff] [blame] | 357 | int32_t qpIMinOri = -1; |
| 358 | if ( item->getInt32("android.media.mediacodec.original-video-qp-i-min", &qpIMinOri)) { |
| 359 | metrics_proto.set_original_video_qp_i_min(qpIMinOri); |
| 360 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 361 | AStatsEvent_writeInt32(event, qpIMinOri); |
Dichen Zhang | 57be630 | 2021-05-18 18:20:31 -0700 | [diff] [blame] | 362 | |
Dichen Zhang | 57be630 | 2021-05-18 18:20:31 -0700 | [diff] [blame] | 363 | int32_t qpIMaxOri = -1; |
| 364 | if ( item->getInt32("android.media.mediacodec.original-video-qp-i-max", &qpIMaxOri)) { |
| 365 | metrics_proto.set_original_video_qp_i_max(qpIMaxOri); |
| 366 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 367 | AStatsEvent_writeInt32(event, qpIMaxOri); |
Dichen Zhang | 57be630 | 2021-05-18 18:20:31 -0700 | [diff] [blame] | 368 | |
Dichen Zhang | 57be630 | 2021-05-18 18:20:31 -0700 | [diff] [blame] | 369 | int32_t qpPMinOri = -1; |
| 370 | if ( item->getInt32("android.media.mediacodec.original-video-qp-p-min", &qpPMinOri)) { |
| 371 | metrics_proto.set_original_video_qp_p_min(qpPMinOri); |
| 372 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 373 | AStatsEvent_writeInt32(event, qpPMinOri); |
Dichen Zhang | 57be630 | 2021-05-18 18:20:31 -0700 | [diff] [blame] | 374 | |
Dichen Zhang | 57be630 | 2021-05-18 18:20:31 -0700 | [diff] [blame] | 375 | int32_t qpPMaxOri = -1; |
| 376 | if ( item->getInt32("android.media.mediacodec.original-video-qp-p-max", &qpPMaxOri)) { |
| 377 | metrics_proto.set_original_video_qp_p_max(qpPMaxOri); |
| 378 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 379 | AStatsEvent_writeInt32(event, qpPMaxOri); |
Dichen Zhang | 57be630 | 2021-05-18 18:20:31 -0700 | [diff] [blame] | 380 | |
Dichen Zhang | 57be630 | 2021-05-18 18:20:31 -0700 | [diff] [blame] | 381 | int32_t qpBMinOri = -1; |
| 382 | if ( item->getInt32("android.media.mediacodec.original-video-qp-b-min", &qpBMinOri)) { |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 383 | metrics_proto.set_original_video_qp_b_min(qpBMinOri); |
Dichen Zhang | 57be630 | 2021-05-18 18:20:31 -0700 | [diff] [blame] | 384 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 385 | AStatsEvent_writeInt32(event, qpBMinOri); |
Dichen Zhang | 57be630 | 2021-05-18 18:20:31 -0700 | [diff] [blame] | 386 | |
Dichen Zhang | 57be630 | 2021-05-18 18:20:31 -0700 | [diff] [blame] | 387 | int32_t qpBMaxOri = -1; |
| 388 | if ( item->getInt32("android.media.mediacodec.original-video-qp-b-max", &qpBMaxOri)) { |
| 389 | metrics_proto.set_original_video_qp_b_max(qpBMaxOri); |
| 390 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 391 | AStatsEvent_writeInt32(event, qpBMaxOri); |
| 392 | |
| 393 | int err = AStatsEvent_write(event); |
| 394 | if (err < 0) { |
| 395 | ALOGE("Failed to write codec metrics to statsd (%d)", err); |
| 396 | } |
| 397 | AStatsEvent_release(event); |
Dichen Zhang | 57be630 | 2021-05-18 18:20:31 -0700 | [diff] [blame] | 398 | |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 399 | std::string serialized; |
| 400 | if (!metrics_proto.SerializeToString(&serialized)) { |
| 401 | ALOGE("Failed to serialize codec metrics"); |
| 402 | return false; |
| 403 | } |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 404 | android::util::BytesField bf_serialized( serialized.c_str(), serialized.size()); |
| 405 | int result = android::util::stats_write(android::util::MEDIAMETRICS_CODEC_REPORTED, |
| 406 | timestamp_nanos, package_name.c_str(), package_version_code, |
| 407 | media_apex_version, |
| 408 | bf_serialized); |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 409 | |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 410 | std::stringstream log; |
| 411 | log << "result:" << result << " {" |
| 412 | << " mediametrics_codec_reported:" |
| 413 | << android::util::MEDIAMETRICS_CODEC_REPORTED |
| 414 | << " timestamp_nanos:" << timestamp_nanos |
| 415 | << " package_name:" << package_name |
| 416 | << " package_version_code:" << package_version_code |
| 417 | << " media_apex_version:" << media_apex_version |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 418 | |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 419 | << " codec:" << codec |
| 420 | << " mime:" << mime |
| 421 | << " mode:" << mode |
| 422 | << " encoder:" << encoder |
| 423 | << " secure:" << secure |
| 424 | << " width:" << width |
| 425 | << " height:" << height |
| 426 | << " rotation:" << rotation |
| 427 | << " crypto:" << crypto |
| 428 | << " profile:" << profile |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 429 | |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 430 | << " level:" << level |
| 431 | << " max_width:" << max_width |
| 432 | << " max_height:" << max_height |
| 433 | << " error_code:" << error_code |
| 434 | << " error_state:" << error_state |
| 435 | << " latency_max:" << latency_max |
| 436 | << " latency_min:" << latency_min |
| 437 | << " latency_avg:" << latency_avg |
| 438 | << " latency_count:" << latency_count |
| 439 | << " latency_unknown:" << latency_unknown |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 440 | |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 441 | << " queue_input_buffer_error:" << queue_input_buffer_error |
| 442 | << " queue_secure_input_buffer_error:" << queue_secure_input_buffer_error |
| 443 | << " bitrate_mode:" << bitrate_mode |
| 444 | << " bitrate:" << bitrate |
Dichen Zhang | 57be630 | 2021-05-18 18:20:31 -0700 | [diff] [blame] | 445 | << " original_bitrate:" << originalBitrate |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 446 | << " lifetime_millis:" << lifetime_millis |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 447 | << " playback_duration_seconds:" << playback_duration_sec |
Dichen Zhang | 57be630 | 2021-05-18 18:20:31 -0700 | [diff] [blame] | 448 | << " log_session_id:" << sessionId |
| 449 | << " channel_count:" << channelCount |
| 450 | << " sample_rate:" << sampleRate |
| 451 | << " encode_bytes:" << bytes |
| 452 | << " encode_frames:" << frames |
| 453 | << " encode_duration_us:" << durationUs |
| 454 | << " color_format:" << colorFormat |
| 455 | << " frame_rate:" << frameRate |
| 456 | << " capture_rate:" << captureRate |
| 457 | << " operating_rate:" << operatingRate |
| 458 | << " priority:" << priority |
| 459 | << " shaping_enhanced:" << shapingEnhanced |
| 460 | |
| 461 | << " qp_i_min:" << qpIMin |
| 462 | << " qp_i_max:" << qpIMax |
| 463 | << " qp_p_min:" << qpPMin |
| 464 | << " qp_p_max:" << qpPMax |
| 465 | << " qp_b_min:" << qpBMin |
| 466 | << " qp_b_max:" << qpBMax |
| 467 | << " original_qp_i_min:" << qpIMinOri |
| 468 | << " original_qp_i_max:" << qpIMaxOri |
| 469 | << " original_qp_p_min:" << qpPMinOri |
| 470 | << " original_qp_p_max:" << qpPMaxOri |
| 471 | << " original_qp_b_min:" << qpBMinOri |
| 472 | << " original_qp_b_max:" << qpBMaxOri |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 473 | << " }"; |
| 474 | statsdLog->log(android::util::MEDIAMETRICS_CODEC_REPORTED, log.str()); |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame] | 475 | |
| 476 | |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 477 | return true; |
| 478 | } |
| 479 | |
Andy Hung | 3ab1b32 | 2020-05-18 10:47:31 -0700 | [diff] [blame] | 480 | } // namespace android |