blob: d14b804d7c32034aeac2c5347fcd05b7f569b255 [file] [log] [blame]
Ray Essick6ce27e52019-02-15 10:58:05 -08001/*
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_extractor"
19#include <utils/Log.h>
20
Ray Essick6ce27e52019-02-15 10:58:05 -080021#include <stdint.h>
22#include <string.h>
Ray Essick6ce27e52019-02-15 10:58:05 -080023
24#include <statslog.h>
25
Santiago Seifert17c72bb2020-11-11 23:49:28 +000026#include <media/stagefright/RemoteMediaExtractor.h>
Ray Essick40e8e5e2019-12-05 20:19:40 -080027#include "MediaMetricsService.h"
Jeffrey Huang6adacdb2020-11-25 02:49:32 -080028#include "frameworks/proto_logging/stats/enums/stats/mediametrics/mediametrics.pb.h"
Ray Essick6ce27e52019-02-15 10:58:05 -080029#include "iface_statsd.h"
30
31namespace android {
32
Ray Essickf27e9872019-12-07 06:28:46 -080033bool statsd_extractor(const mediametrics::Item *item)
Ray Essick6ce27e52019-02-15 10:58:05 -080034{
Andy Hung3ab1b322020-05-18 10:47:31 -070035 if (item == nullptr) return false;
Ray Essick6ce27e52019-02-15 10:58:05 -080036
37 // these go into the statsd wrapper
Ray Essickf27e9872019-12-07 06:28:46 -080038 const nsecs_t timestamp = MediaMetricsService::roundTime(item->getTimestamp());
Ray Essick6ce27e52019-02-15 10:58:05 -080039 std::string pkgName = item->getPkgName();
40 int64_t pkgVersionCode = item->getPkgVersionCode();
41 int64_t mediaApexVersion = 0;
42
43
44 // the rest into our own proto
45 //
46 ::android::stats::mediametrics::ExtractorData metrics_proto;
47
48 // flesh out the protobuf we'll hand off with our data
49 //
50
51 // android.media.mediaextractor.fmt string
George Burgess IV0d814432019-10-23 11:32:26 -070052 std::string fmt;
Santiago Seifert17c72bb2020-11-11 23:49:28 +000053 if (item->getString(RemoteMediaExtractor::kExtractorFormat, &fmt)) {
George Burgess IV0d814432019-10-23 11:32:26 -070054 metrics_proto.set_format(std::move(fmt));
Ray Essick6ce27e52019-02-15 10:58:05 -080055 }
56 // android.media.mediaextractor.mime string
George Burgess IV0d814432019-10-23 11:32:26 -070057 std::string mime;
Santiago Seifert17c72bb2020-11-11 23:49:28 +000058 if (item->getString(RemoteMediaExtractor::kExtractorMime, &mime)) {
George Burgess IV0d814432019-10-23 11:32:26 -070059 metrics_proto.set_mime(std::move(mime));
Ray Essick6ce27e52019-02-15 10:58:05 -080060 }
61 // android.media.mediaextractor.ntrk int32
62 int32_t ntrk = -1;
Santiago Seifert17c72bb2020-11-11 23:49:28 +000063 if (item->getInt32(RemoteMediaExtractor::kExtractorTracks, &ntrk)) {
Ray Essick6ce27e52019-02-15 10:58:05 -080064 metrics_proto.set_tracks(ntrk);
65 }
66
Santiago Seifert17c72bb2020-11-11 23:49:28 +000067 // android.media.mediaextractor.entry int32
68 int32_t entry_point_int;
69 if (item->getInt32(RemoteMediaExtractor::kExtractorEntryPoint,
70 &entry_point_int)) {
71 using stats::mediametrics::ExtractorData;
72 ExtractorData::EntryPoint entry_point;
73 switch (static_cast<IMediaExtractor::EntryPoint>(entry_point_int)) {
74 case IMediaExtractor::EntryPoint::SDK:
75 entry_point =
76 ExtractorData::EntryPoint::ExtractorData_EntryPoint_SDK;
77 break;
78 case IMediaExtractor::EntryPoint::NDK_WITH_JVM:
79 entry_point =
80 ExtractorData::EntryPoint
81 ::ExtractorData_EntryPoint_NDK_WITH_JVM;
82 break;
83 case IMediaExtractor::EntryPoint::NDK_NO_JVM:
84 entry_point =
85 ExtractorData::EntryPoint
86 ::ExtractorData_EntryPoint_NDK_NO_JVM;
87 break;
88 case IMediaExtractor::EntryPoint::OTHER:
89 entry_point =
90 ExtractorData::EntryPoint
91 ::ExtractorData_EntryPoint_OTHER;
92 break;
93 default:
94 entry_point =
95 ExtractorData::EntryPoint::ExtractorData_EntryPoint_UNSET;
96 }
97 metrics_proto.set_entry_point(entry_point);
98 }
99
Ray Essick6ce27e52019-02-15 10:58:05 -0800100 std::string serialized;
101 if (!metrics_proto.SerializeToString(&serialized)) {
102 ALOGE("Failed to serialize extractor metrics");
103 return false;
104 }
105
106 if (enabled_statsd) {
107 android::util::BytesField bf_serialized( serialized.c_str(), serialized.size());
108 (void)android::util::stats_write(android::util::MEDIAMETRICS_EXTRACTOR_REPORTED,
109 timestamp, pkgName.c_str(), pkgVersionCode,
110 mediaApexVersion,
111 bf_serialized);
112
113 } else {
114 ALOGV("NOT sending: private data (len=%zu)", strlen(serialized.c_str()));
115 }
116
Ray Essick6ce27e52019-02-15 10:58:05 -0800117 return true;
118}
119
Andy Hung3ab1b322020-05-18 10:47:31 -0700120} // namespace android