blob: f543425cae038c29901e485468e2d118462c149d [file] [log] [blame]
Santiago Seifert4b3ee1c2020-08-11 17:58:41 +01001/*
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 Huang6adacdb2020-11-25 02:49:32 -080034#include "frameworks/proto_logging/stats/enums/stats/mediametrics/mediametrics.pb.h"
Santiago Seifert4b3ee1c2020-08-11 17:58:41 +010035#include "iface_statsd.h"
36
37namespace android {
38
Andy Hung5be90c82021-03-30 14:30:20 -070039bool statsd_mediaparser(const std::shared_ptr<const mediametrics::Item>& item,
40 const std::shared_ptr<mediametrics::StatsdLog>& statsdLog)
Santiago Seifert4b3ee1c2020-08-11 17:58:41 +010041{
Andy Hung5be90c82021-03-30 14:30:20 -070042 static constexpr bool enabled_statsd = true; // TODO: Remove, dup with dump2StatsdInternal().
43 if (item == nullptr) return false;
Santiago Seifert4b3ee1c2020-08-11 17:58:41 +010044
Andy Hung5be90c82021-03-30 14:30:20 -070045 const nsecs_t timestamp_nanos = MediaMetricsService::roundTime(item->getTimestamp());
46 const std::string package_name = item->getPkgName();
47 const int64_t package_version_code = item->getPkgVersionCode();
Santiago Seifert4b3ee1c2020-08-11 17:58:41 +010048
49 std::string parserName;
50 item->getString("android.media.mediaparser.parserName", &parserName);
51
52 int32_t createdByName = -1;
53 item->getInt32("android.media.mediaparser.createdByName", &createdByName);
54
55 std::string parserPool;
56 item->getString("android.media.mediaparser.parserPool", &parserPool);
57
58 std::string lastException;
59 item->getString("android.media.mediaparser.lastException", &lastException);
60
61 int64_t resourceByteCount = -1;
62 item->getInt64("android.media.mediaparser.resourceByteCount", &resourceByteCount);
63
64 int64_t durationMillis = -1;
65 item->getInt64("android.media.mediaparser.durationMillis", &durationMillis);
66
67 std::string trackMimeTypes;
68 item->getString("android.media.mediaparser.trackMimeTypes", &trackMimeTypes);
69
70 std::string trackCodecs;
71 item->getString("android.media.mediaparser.trackCodecs", &trackCodecs);
72
73 std::string alteredParameters;
74 item->getString("android.media.mediaparser.alteredParameters", &alteredParameters);
75
76 int32_t videoWidth = -1;
77 item->getInt32("android.media.mediaparser.videoWidth", &videoWidth);
78
79 int32_t videoHeight = -1;
80 item->getInt32("android.media.mediaparser.videoHeight", &videoHeight);
81
82 if (enabled_statsd) {
83 (void) android::util::stats_write(android::util::MEDIAMETRICS_MEDIAPARSER_REPORTED,
Andy Hung5be90c82021-03-30 14:30:20 -070084 timestamp_nanos,
85 package_name.c_str(),
86 package_version_code,
Santiago Seifert4b3ee1c2020-08-11 17:58:41 +010087 parserName.c_str(),
88 createdByName,
89 parserPool.c_str(),
90 lastException.c_str(),
91 resourceByteCount,
92 durationMillis,
93 trackMimeTypes.c_str(),
94 trackCodecs.c_str(),
95 alteredParameters.c_str(),
96 videoWidth,
97 videoHeight);
98 } else {
99 ALOGV("NOT sending MediaParser media metrics.");
100 }
Andy Hung5be90c82021-03-30 14:30:20 -0700101 // TODO: Cleanup after playback_id is merged.
102 std::stringstream log;
103 log << "result:" << "(result)" << " {"
104 << " mediametrics_mediaparser_reported:"
105 << android::util::MEDIAMETRICS_MEDIAPARSER_REPORTED
106 << " timestamp_nanos:" << timestamp_nanos
107 << " package_name:" << package_name
108 << " package_version_code:" << package_version_code
109 << " parser_name:" << parserName
110 << " created_by_name:" << createdByName
111 << " parser_pool:" << parserPool
112 << " last_exception:" << lastException
113 << " resource_byte_count:" << resourceByteCount
114 << " duration_millis:" << durationMillis
115 << " track_mime_types:" << trackMimeTypes
116 << " track_codecs:" << trackCodecs
117 << " altered_parameters:" << alteredParameters
118 << " video_width:" << videoWidth
119 << " video_height:" << videoHeight
120 // TODO: Add MediaParser playback_id
121 // << " playback_id:" << playbackId
122 << " }";
123 statsdLog->log(android::util::MEDIAMETRICS_MEDIAPARSER_REPORTED, log.str());
Santiago Seifert4b3ee1c2020-08-11 17:58:41 +0100124 return true;
125}
126
127} // namespace android