Santiago Seifert | 71b5dbf | 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" |
| 34 | #include "frameworks/base/core/proto/android/stats/mediametrics/mediametrics.pb.h" |
| 35 | #include "iface_statsd.h" |
| 36 | |
| 37 | namespace android { |
| 38 | |
| 39 | bool statsd_mediaparser(const mediametrics::Item *item) |
| 40 | { |
| 41 | if (item == nullptr) { |
| 42 | return false; |
| 43 | } |
| 44 | |
| 45 | // statsd wrapper data. |
| 46 | const nsecs_t timestamp = MediaMetricsService::roundTime(item->getTimestamp()); |
| 47 | std::string pkgName = item->getPkgName(); |
| 48 | int64_t pkgVersionCode = item->getPkgVersionCode(); |
| 49 | |
| 50 | std::string parserName; |
| 51 | item->getString("android.media.mediaparser.parserName", &parserName); |
| 52 | |
| 53 | int32_t createdByName = -1; |
| 54 | item->getInt32("android.media.mediaparser.createdByName", &createdByName); |
| 55 | |
| 56 | std::string parserPool; |
| 57 | item->getString("android.media.mediaparser.parserPool", &parserPool); |
| 58 | |
| 59 | std::string lastException; |
| 60 | item->getString("android.media.mediaparser.lastException", &lastException); |
| 61 | |
| 62 | int64_t resourceByteCount = -1; |
| 63 | item->getInt64("android.media.mediaparser.resourceByteCount", &resourceByteCount); |
| 64 | |
| 65 | int64_t durationMillis = -1; |
| 66 | item->getInt64("android.media.mediaparser.durationMillis", &durationMillis); |
| 67 | |
| 68 | std::string trackMimeTypes; |
| 69 | item->getString("android.media.mediaparser.trackMimeTypes", &trackMimeTypes); |
| 70 | |
| 71 | std::string trackCodecs; |
| 72 | item->getString("android.media.mediaparser.trackCodecs", &trackCodecs); |
| 73 | |
| 74 | std::string alteredParameters; |
| 75 | item->getString("android.media.mediaparser.alteredParameters", &alteredParameters); |
| 76 | |
| 77 | int32_t videoWidth = -1; |
| 78 | item->getInt32("android.media.mediaparser.videoWidth", &videoWidth); |
| 79 | |
| 80 | int32_t videoHeight = -1; |
| 81 | item->getInt32("android.media.mediaparser.videoHeight", &videoHeight); |
| 82 | |
| 83 | if (enabled_statsd) { |
| 84 | (void) android::util::stats_write(android::util::MEDIAMETRICS_MEDIAPARSER_REPORTED, |
| 85 | timestamp, |
| 86 | pkgName.c_str(), |
| 87 | pkgVersionCode, |
| 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 | } else { |
| 100 | ALOGV("NOT sending MediaParser media metrics."); |
| 101 | } |
| 102 | |
| 103 | return true; |
| 104 | } |
| 105 | |
| 106 | } // namespace android |