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" |
Dichen Zhang | b8f23c5 | 2021-03-22 00:56:29 -0700 | [diff] [blame] | 37 | #include "frameworks/proto_logging/stats/message/mediametrics_message.pb.h" |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 38 | #include "iface_statsd.h" |
| 39 | |
| 40 | namespace android { |
| 41 | |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 42 | bool statsd_codec(const std::shared_ptr<const mediametrics::Item>& item, |
| 43 | const std::shared_ptr<mediametrics::StatsdLog>& statsdLog) |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 44 | { |
Andy Hung | 3ab1b32 | 2020-05-18 10:47:31 -0700 | [diff] [blame] | 45 | if (item == nullptr) return false; |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 46 | |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 47 | AStatsEvent* event = AStatsEvent_obtain(); |
| 48 | AStatsEvent_setAtomId(event, android::util::MEDIA_CODEC_REPORTED); |
| 49 | |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 50 | const nsecs_t timestamp_nanos = MediaMetricsService::roundTime(item->getTimestamp()); |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 51 | 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 Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 61 | |
| 62 | // the rest into our own proto |
| 63 | // |
Dichen Zhang | b8f23c5 | 2021-03-22 00:56:29 -0700 | [diff] [blame] | 64 | ::android::stats::mediametrics_message::CodecData metrics_proto; |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 65 | |
| 66 | // flesh out the protobuf we'll hand off with our data |
| 67 | // |
George Burgess IV | 0d81443 | 2019-10-23 11:32:26 -0700 | [diff] [blame] | 68 | std::string codec; |
| 69 | if (item->getString("android.media.mediacodec.codec", &codec)) { |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 70 | metrics_proto.set_codec(codec); |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 71 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 72 | AStatsEvent_writeString(event, codec.c_str()); |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 73 | |
George Burgess IV | 0d81443 | 2019-10-23 11:32:26 -0700 | [diff] [blame] | 74 | std::string mime; |
| 75 | if (item->getString("android.media.mediacodec.mime", &mime)) { |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 76 | metrics_proto.set_mime(mime); |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 77 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 78 | AStatsEvent_writeString(event, mime.c_str()); |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 79 | |
George Burgess IV | 0d81443 | 2019-10-23 11:32:26 -0700 | [diff] [blame] | 80 | std::string mode; |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 81 | if (item->getString("android.media.mediacodec.mode", &mode)) { |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 82 | metrics_proto.set_mode(mode); |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 83 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 84 | AStatsEvent_writeString(event, mode.c_str()); |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 85 | |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 86 | int32_t encoder = -1; |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 87 | if (item->getInt32("android.media.mediacodec.encoder", &encoder)) { |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 88 | metrics_proto.set_encoder(encoder); |
| 89 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 90 | AStatsEvent_writeInt32(event, encoder); |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 91 | |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 92 | int32_t secure = -1; |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 93 | if (item->getInt32("android.media.mediacodec.secure", &secure)) { |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 94 | metrics_proto.set_secure(secure); |
| 95 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 96 | AStatsEvent_writeInt32(event, secure); |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 97 | |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 98 | int32_t width = -1; |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 99 | if (item->getInt32("android.media.mediacodec.width", &width)) { |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 100 | metrics_proto.set_width(width); |
| 101 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 102 | AStatsEvent_writeInt32(event, width); |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 103 | |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 104 | int32_t height = -1; |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 105 | if (item->getInt32("android.media.mediacodec.height", &height)) { |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 106 | metrics_proto.set_height(height); |
| 107 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 108 | AStatsEvent_writeInt32(event, height); |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 109 | |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 110 | int32_t rotation = -1; |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 111 | if (item->getInt32("android.media.mediacodec.rotation-degrees", &rotation)) { |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 112 | metrics_proto.set_rotation(rotation); |
| 113 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 114 | AStatsEvent_writeInt32(event, rotation); |
| 115 | |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 116 | int32_t crypto = -1; |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 117 | if (item->getInt32("android.media.mediacodec.crypto", &crypto)) { |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 118 | metrics_proto.set_crypto(crypto); |
| 119 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 120 | AStatsEvent_writeInt32(event, crypto); |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 121 | |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 122 | int32_t profile = -1; |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 123 | if (item->getInt32("android.media.mediacodec.profile", &profile)) { |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 124 | metrics_proto.set_profile(profile); |
| 125 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 126 | AStatsEvent_writeInt32(event, profile); |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 127 | |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 128 | int32_t level = -1; |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 129 | if (item->getInt32("android.media.mediacodec.level", &level)) { |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 130 | metrics_proto.set_level(level); |
| 131 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 132 | AStatsEvent_writeInt32(event, level); |
| 133 | |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 134 | |
| 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 Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 138 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 139 | AStatsEvent_writeInt32(event, max_width); |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 140 | |
| 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 Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 144 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 145 | AStatsEvent_writeInt32(event, max_height); |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 146 | |
| 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 Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 150 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 151 | AStatsEvent_writeInt32(event, error_code); |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 152 | |
| 153 | std::string error_state; |
| 154 | if ( item->getString("android.media.mediacodec.errstate", &error_state)) { |
| 155 | metrics_proto.set_error_state(error_state); |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 156 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 157 | AStatsEvent_writeString(event, error_state.c_str()); |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 158 | |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 159 | int64_t latency_max = -1; |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 160 | if (item->getInt64("android.media.mediacodec.latency.max", &latency_max)) { |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 161 | metrics_proto.set_latency_max(latency_max); |
| 162 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 163 | AStatsEvent_writeInt64(event, latency_max); |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 164 | |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 165 | int64_t latency_min = -1; |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 166 | if (item->getInt64("android.media.mediacodec.latency.min", &latency_min)) { |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 167 | metrics_proto.set_latency_min(latency_min); |
| 168 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 169 | AStatsEvent_writeInt64(event, latency_min); |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 170 | |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 171 | int64_t latency_avg = -1; |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 172 | if (item->getInt64("android.media.mediacodec.latency.avg", &latency_avg)) { |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 173 | metrics_proto.set_latency_avg(latency_avg); |
| 174 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 175 | AStatsEvent_writeInt64(event, latency_avg); |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 176 | |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 177 | int64_t latency_count = -1; |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 178 | if (item->getInt64("android.media.mediacodec.latency.n", &latency_count)) { |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 179 | metrics_proto.set_latency_count(latency_count); |
| 180 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 181 | AStatsEvent_writeInt64(event, latency_count); |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 182 | |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 183 | int64_t latency_unknown = -1; |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 184 | if (item->getInt64("android.media.mediacodec.latency.unknown", &latency_unknown)) { |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 185 | metrics_proto.set_latency_unknown(latency_unknown); |
| 186 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 187 | AStatsEvent_writeInt64(event, latency_unknown); |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 188 | |
| 189 | int32_t queue_secure_input_buffer_error = -1; |
| 190 | if (item->getInt32("android.media.mediacodec.queueSecureInputBufferError", |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 191 | &queue_secure_input_buffer_error)) { |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 192 | 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] | 193 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 194 | AStatsEvent_writeInt32(event, queue_secure_input_buffer_error); |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 195 | |
| 196 | int32_t queue_input_buffer_error = -1; |
| 197 | if (item->getInt32("android.media.mediacodec.queueInputBufferError", |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 198 | &queue_input_buffer_error)) { |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 199 | metrics_proto.set_queue_input_buffer_error(queue_input_buffer_error); |
Edwin Wong | 4f10539 | 2020-02-12 14:55:00 -0800 | [diff] [blame] | 200 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 201 | AStatsEvent_writeInt32(event, queue_input_buffer_error); |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 202 | |
Ray Essick | a21a3d3 | 2020-05-10 21:08:10 -0700 | [diff] [blame] | 203 | std::string bitrate_mode; |
| 204 | if (item->getString("android.media.mediacodec.bitrate_mode", &bitrate_mode)) { |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 205 | metrics_proto.set_bitrate_mode(bitrate_mode); |
Ray Essick | a21a3d3 | 2020-05-10 21:08:10 -0700 | [diff] [blame] | 206 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 207 | AStatsEvent_writeString(event, bitrate_mode.c_str()); |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 208 | |
Ray Essick | a21a3d3 | 2020-05-10 21:08:10 -0700 | [diff] [blame] | 209 | int32_t bitrate = -1; |
| 210 | if (item->getInt32("android.media.mediacodec.bitrate", &bitrate)) { |
| 211 | metrics_proto.set_bitrate(bitrate); |
| 212 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 213 | AStatsEvent_writeInt32(event, bitrate); |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 214 | |
| 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 Essick | a21a3d3 | 2020-05-10 21:08:10 -0700 | [diff] [blame] | 219 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 220 | AStatsEvent_writeInt64(event, lifetime_millis); |
Ray Essick | a21a3d3 | 2020-05-10 21:08:10 -0700 | [diff] [blame] | 221 | |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 222 | 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 Zhang | 0de0575 | 2021-04-21 19:47:07 -0700 | [diff] [blame] | 234 | int32_t channelCount = -1; |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 235 | if (item->getInt32("android.media.mediacodec.channelCount", &channelCount)) { |
Dichen Zhang | 0de0575 | 2021-04-21 19:47:07 -0700 | [diff] [blame] | 236 | metrics_proto.set_channel_count(channelCount); |
| 237 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 238 | AStatsEvent_writeInt32(event, channelCount); |
Ray Essick | 8791331 | 2021-03-02 10:45:54 -0800 | [diff] [blame] | 239 | |
Dichen Zhang | 0de0575 | 2021-04-21 19:47:07 -0700 | [diff] [blame] | 240 | int32_t sampleRate = -1; |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 241 | if (item->getInt32("android.media.mediacodec.sampleRate", &sampleRate)) { |
Dichen Zhang | 0de0575 | 2021-04-21 19:47:07 -0700 | [diff] [blame] | 242 | metrics_proto.set_sample_rate(sampleRate); |
| 243 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 244 | AStatsEvent_writeInt32(event, sampleRate); |
Dichen Zhang | 0de0575 | 2021-04-21 19:47:07 -0700 | [diff] [blame] | 245 | |
Ray Essick | 8791331 | 2021-03-02 10:45:54 -0800 | [diff] [blame] | 246 | // 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] | 247 | int64_t bytes = -1; |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 248 | if (item->getInt64("android.media.mediacodec.vencode.bytes", &bytes)) { |
Dichen Zhang | 0de0575 | 2021-04-21 19:47:07 -0700 | [diff] [blame] | 249 | metrics_proto.set_video_encode_bytes(bytes); |
| 250 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 251 | AStatsEvent_writeInt64(event, bytes); |
Dichen Zhang | 0de0575 | 2021-04-21 19:47:07 -0700 | [diff] [blame] | 252 | |
Dichen Zhang | 0de0575 | 2021-04-21 19:47:07 -0700 | [diff] [blame] | 253 | int64_t frames = -1; |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 254 | if (item->getInt64("android.media.mediacodec.vencode.frames", &frames)) { |
Dichen Zhang | 0de0575 | 2021-04-21 19:47:07 -0700 | [diff] [blame] | 255 | metrics_proto.set_video_encode_frames(frames); |
| 256 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 257 | AStatsEvent_writeInt64(event, frames); |
Dichen Zhang | 0de0575 | 2021-04-21 19:47:07 -0700 | [diff] [blame] | 258 | |
Dichen Zhang | 0de0575 | 2021-04-21 19:47:07 -0700 | [diff] [blame] | 259 | int64_t inputBytes = -1; |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 260 | if (item->getInt64("android.media.mediacodec.video.input.bytes", &inputBytes)) { |
Dichen Zhang | 0de0575 | 2021-04-21 19:47:07 -0700 | [diff] [blame] | 261 | metrics_proto.set_video_input_bytes(inputBytes); |
| 262 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 263 | AStatsEvent_writeInt64(event, inputBytes); |
Dichen Zhang | 0de0575 | 2021-04-21 19:47:07 -0700 | [diff] [blame] | 264 | |
Dichen Zhang | 0de0575 | 2021-04-21 19:47:07 -0700 | [diff] [blame] | 265 | int64_t inputFrames = -1; |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 266 | if (item->getInt64("android.media.mediacodec.video.input.frames", &inputFrames)) { |
Dichen Zhang | 0de0575 | 2021-04-21 19:47:07 -0700 | [diff] [blame] | 267 | metrics_proto.set_video_input_frames(inputFrames); |
| 268 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 269 | AStatsEvent_writeInt64(event, inputFrames); |
Ray Essick | 8791331 | 2021-03-02 10:45:54 -0800 | [diff] [blame] | 270 | |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 271 | 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 Zhang | e5bad78 | 2021-04-28 12:11:35 -0700 | [diff] [blame] | 343 | int32_t originalBitrate = -1; |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 344 | if (item->getInt32("android.media.mediacodec.original.bitrate", &originalBitrate)) { |
Dichen Zhang | e5bad78 | 2021-04-28 12:11:35 -0700 | [diff] [blame] | 345 | metrics_proto.set_original_bitrate(originalBitrate); |
| 346 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 347 | AStatsEvent_writeInt32(event, originalBitrate); |
Dichen Zhang | e5bad78 | 2021-04-28 12:11:35 -0700 | [diff] [blame] | 348 | |
Dichen Zhang | 57be630 | 2021-05-18 18:20:31 -0700 | [diff] [blame] | 349 | int32_t shapingEnhanced = -1; |
| 350 | if ( item->getInt32("android.media.mediacodec.shaped", &shapingEnhanced)) { |
| 351 | metrics_proto.set_shaping_enhanced(shapingEnhanced); |
| 352 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 353 | AStatsEvent_writeInt32(event, shapingEnhanced); |
Dichen Zhang | 57be630 | 2021-05-18 18:20:31 -0700 | [diff] [blame] | 354 | |
Dichen Zhang | 57be630 | 2021-05-18 18:20:31 -0700 | [diff] [blame] | 355 | 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 Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 359 | AStatsEvent_writeInt32(event, qpIMinOri); |
Dichen Zhang | 57be630 | 2021-05-18 18:20:31 -0700 | [diff] [blame] | 360 | |
Dichen Zhang | 57be630 | 2021-05-18 18:20:31 -0700 | [diff] [blame] | 361 | 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 Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 365 | AStatsEvent_writeInt32(event, qpIMaxOri); |
Dichen Zhang | 57be630 | 2021-05-18 18:20:31 -0700 | [diff] [blame] | 366 | |
Dichen Zhang | 57be630 | 2021-05-18 18:20:31 -0700 | [diff] [blame] | 367 | 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 Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 371 | AStatsEvent_writeInt32(event, qpPMinOri); |
Dichen Zhang | 57be630 | 2021-05-18 18:20:31 -0700 | [diff] [blame] | 372 | |
Dichen Zhang | 57be630 | 2021-05-18 18:20:31 -0700 | [diff] [blame] | 373 | 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 Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 377 | AStatsEvent_writeInt32(event, qpPMaxOri); |
Dichen Zhang | 57be630 | 2021-05-18 18:20:31 -0700 | [diff] [blame] | 378 | |
Dichen Zhang | 57be630 | 2021-05-18 18:20:31 -0700 | [diff] [blame] | 379 | int32_t qpBMinOri = -1; |
| 380 | if ( item->getInt32("android.media.mediacodec.original-video-qp-b-min", &qpBMinOri)) { |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 381 | metrics_proto.set_original_video_qp_b_min(qpBMinOri); |
Dichen Zhang | 57be630 | 2021-05-18 18:20:31 -0700 | [diff] [blame] | 382 | } |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 383 | AStatsEvent_writeInt32(event, qpBMinOri); |
Dichen Zhang | 57be630 | 2021-05-18 18:20:31 -0700 | [diff] [blame] | 384 | |
Dichen Zhang | 57be630 | 2021-05-18 18:20:31 -0700 | [diff] [blame] | 385 | 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 Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 389 | 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 Zhang | 57be630 | 2021-05-18 18:20:31 -0700 | [diff] [blame] | 396 | |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 397 | std::string serialized; |
| 398 | if (!metrics_proto.SerializeToString(&serialized)) { |
| 399 | ALOGE("Failed to serialize codec metrics"); |
| 400 | return false; |
| 401 | } |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 402 | 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 Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 407 | |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 408 | 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 Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 416 | |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 417 | << " 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 Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 427 | |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 428 | << " 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 Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 438 | |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 439 | << " 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 Zhang | 57be630 | 2021-05-18 18:20:31 -0700 | [diff] [blame] | 443 | << " original_bitrate:" << originalBitrate |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 444 | << " lifetime_millis:" << lifetime_millis |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 445 | << " playback_duration_seconds:" << playback_duration_sec |
Dichen Zhang | 57be630 | 2021-05-18 18:20:31 -0700 | [diff] [blame] | 446 | << " 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 Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 471 | << " }"; |
| 472 | statsdLog->log(android::util::MEDIAMETRICS_CODEC_REPORTED, log.str()); |
Brian Lindahl | c935ee2 | 2021-06-08 09:57:07 +0200 | [diff] [blame^] | 473 | |
| 474 | |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 475 | return true; |
| 476 | } |
| 477 | |
Andy Hung | 3ab1b32 | 2020-05-18 10:47:31 -0700 | [diff] [blame] | 478 | } // namespace android |