• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "StringUtils.h"
35 #include "frameworks/proto_logging/stats/enums/stats/mediametrics/mediametrics.pb.h"
36 #include "iface_statsd.h"
37 
38 namespace android {
39 
statsd_mediaparser(const std::shared_ptr<const mediametrics::Item> & item,const std::shared_ptr<mediametrics::StatsdLog> & statsdLog)40 bool statsd_mediaparser(const std::shared_ptr<const mediametrics::Item>& item,
41         const std::shared_ptr<mediametrics::StatsdLog>& statsdLog)
42 {
43     if (item == nullptr) return false;
44 
45     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();
48 
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     std::string logSessionId;
83     item->getString("android.media.mediaparser.logSessionId", &logSessionId);
84     logSessionId = mediametrics::stringutils::sanitizeLogSessionId(logSessionId);
85 
86     int result = android::util::stats_write(android::util::MEDIAMETRICS_MEDIAPARSER_REPORTED,
87                                timestamp_nanos,
88                                package_name.c_str(),
89                                package_version_code,
90                                parserName.c_str(),
91                                createdByName,
92                                parserPool.c_str(),
93                                lastException.c_str(),
94                                resourceByteCount,
95                                durationMillis,
96                                trackMimeTypes.c_str(),
97                                trackCodecs.c_str(),
98                                alteredParameters.c_str(),
99                                videoWidth,
100                                videoHeight,
101                                logSessionId.c_str());
102 
103     std::stringstream log;
104     log << "result:" << result << " {"
105             << " mediametrics_mediaparser_reported:"
106             << android::util::MEDIAMETRICS_MEDIAPARSER_REPORTED
107             << " timestamp_nanos:" << timestamp_nanos
108             << " package_name:" << package_name
109             << " package_version_code:" << package_version_code
110             << " parser_name:" << parserName
111             << " created_by_name:" << createdByName
112             << " parser_pool:" << parserPool
113             << " last_exception:" << lastException
114             << " resource_byte_count:" << resourceByteCount
115             << " duration_millis:" << durationMillis
116             << " track_mime_types:" << trackMimeTypes
117             << " track_codecs:" << trackCodecs
118             << " altered_parameters:" << alteredParameters
119             << " video_width:" << videoWidth
120             << " video_height:" << videoHeight
121             << " log_session_id:" << logSessionId
122             << " }";
123     statsdLog->log(android::util::MEDIAMETRICS_MEDIAPARSER_REPORTED, log.str());
124     return true;
125 }
126 
127 } // namespace android
128