Santiago Seifert | 4b3ee1c | 2020-08-11 17:58:41 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2020 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_TAG "statsd_mediaparser" |
| 18 | #include <utils/Log.h> |
| 19 | |
| 20 | #include <dirent.h> |
| 21 | #include <inttypes.h> |
| 22 | #include <pthread.h> |
| 23 | #include <pwd.h> |
| 24 | #include <stdint.h> |
| 25 | #include <string.h> |
| 26 | #include <sys/stat.h> |
| 27 | #include <sys/time.h> |
| 28 | #include <sys/types.h> |
| 29 | #include <unistd.h> |
| 30 | |
| 31 | #include <statslog.h> |
| 32 | |
| 33 | #include "MediaMetricsService.h" |
Jeffrey Huang | 6adacdb | 2020-11-25 02:49:32 -0800 | [diff] [blame] | 34 | #include "frameworks/proto_logging/stats/enums/stats/mediametrics/mediametrics.pb.h" |
Santiago Seifert | 4b3ee1c | 2020-08-11 17:58:41 +0100 | [diff] [blame] | 35 | #include "iface_statsd.h" |
| 36 | |
| 37 | namespace android { |
| 38 | |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 39 | bool statsd_mediaparser(const std::shared_ptr<const mediametrics::Item>& item, |
| 40 | const std::shared_ptr<mediametrics::StatsdLog>& statsdLog) |
Santiago Seifert | 4b3ee1c | 2020-08-11 17:58:41 +0100 | [diff] [blame] | 41 | { |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 42 | if (item == nullptr) return false; |
Santiago Seifert | 4b3ee1c | 2020-08-11 17:58:41 +0100 | [diff] [blame] | 43 | |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 44 | const nsecs_t timestamp_nanos = MediaMetricsService::roundTime(item->getTimestamp()); |
| 45 | const std::string package_name = item->getPkgName(); |
| 46 | const int64_t package_version_code = item->getPkgVersionCode(); |
Santiago Seifert | 4b3ee1c | 2020-08-11 17:58:41 +0100 | [diff] [blame] | 47 | |
| 48 | std::string parserName; |
| 49 | item->getString("android.media.mediaparser.parserName", &parserName); |
| 50 | |
| 51 | int32_t createdByName = -1; |
| 52 | item->getInt32("android.media.mediaparser.createdByName", &createdByName); |
| 53 | |
| 54 | std::string parserPool; |
| 55 | item->getString("android.media.mediaparser.parserPool", &parserPool); |
| 56 | |
| 57 | std::string lastException; |
| 58 | item->getString("android.media.mediaparser.lastException", &lastException); |
| 59 | |
| 60 | int64_t resourceByteCount = -1; |
| 61 | item->getInt64("android.media.mediaparser.resourceByteCount", &resourceByteCount); |
| 62 | |
| 63 | int64_t durationMillis = -1; |
| 64 | item->getInt64("android.media.mediaparser.durationMillis", &durationMillis); |
| 65 | |
| 66 | std::string trackMimeTypes; |
| 67 | item->getString("android.media.mediaparser.trackMimeTypes", &trackMimeTypes); |
| 68 | |
| 69 | std::string trackCodecs; |
| 70 | item->getString("android.media.mediaparser.trackCodecs", &trackCodecs); |
| 71 | |
| 72 | std::string alteredParameters; |
| 73 | item->getString("android.media.mediaparser.alteredParameters", &alteredParameters); |
| 74 | |
| 75 | int32_t videoWidth = -1; |
| 76 | item->getInt32("android.media.mediaparser.videoWidth", &videoWidth); |
| 77 | |
| 78 | int32_t videoHeight = -1; |
| 79 | item->getInt32("android.media.mediaparser.videoHeight", &videoHeight); |
| 80 | |
Santiago Seifert | a3a96a4 | 2021-04-21 13:51:38 +0100 | [diff] [blame] | 81 | std::string logSessionId; |
| 82 | item->getString("android.media.mediaparser.logSessionId", &logSessionId); |
| 83 | |
Andy Hung | dad9ae8 | 2021-05-06 10:56:41 -0700 | [diff] [blame] | 84 | int result = android::util::stats_write(android::util::MEDIAMETRICS_MEDIAPARSER_REPORTED, |
| 85 | timestamp_nanos, |
| 86 | package_name.c_str(), |
| 87 | package_version_code, |
| 88 | parserName.c_str(), |
| 89 | createdByName, |
| 90 | parserPool.c_str(), |
| 91 | lastException.c_str(), |
| 92 | resourceByteCount, |
| 93 | durationMillis, |
| 94 | trackMimeTypes.c_str(), |
| 95 | trackCodecs.c_str(), |
| 96 | alteredParameters.c_str(), |
| 97 | videoWidth, |
| 98 | videoHeight, |
| 99 | logSessionId.c_str()); |
| 100 | |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 101 | std::stringstream log; |
Andy Hung | dad9ae8 | 2021-05-06 10:56:41 -0700 | [diff] [blame] | 102 | log << "result:" << result << " {" |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 103 | << " mediametrics_mediaparser_reported:" |
| 104 | << android::util::MEDIAMETRICS_MEDIAPARSER_REPORTED |
| 105 | << " timestamp_nanos:" << timestamp_nanos |
| 106 | << " package_name:" << package_name |
| 107 | << " package_version_code:" << package_version_code |
| 108 | << " parser_name:" << parserName |
| 109 | << " created_by_name:" << createdByName |
| 110 | << " parser_pool:" << parserPool |
| 111 | << " last_exception:" << lastException |
| 112 | << " resource_byte_count:" << resourceByteCount |
| 113 | << " duration_millis:" << durationMillis |
| 114 | << " track_mime_types:" << trackMimeTypes |
| 115 | << " track_codecs:" << trackCodecs |
| 116 | << " altered_parameters:" << alteredParameters |
| 117 | << " video_width:" << videoWidth |
| 118 | << " video_height:" << videoHeight |
Santiago Seifert | a3a96a4 | 2021-04-21 13:51:38 +0100 | [diff] [blame] | 119 | << " log_session_id:" << logSessionId |
Andy Hung | 5be90c8 | 2021-03-30 14:30:20 -0700 | [diff] [blame] | 120 | << " }"; |
| 121 | statsdLog->log(android::util::MEDIAMETRICS_MEDIAPARSER_REPORTED, log.str()); |
Santiago Seifert | 4b3ee1c | 2020-08-11 17:58:41 +0100 | [diff] [blame] | 122 | return true; |
| 123 | } |
| 124 | |
| 125 | } // namespace android |