1 /*
2 * Copyright (C) 2017 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 "MetricsSummarizerPlayer"
18 #include <utils/Log.h>
19
20 #include <stdint.h>
21 #include <inttypes.h>
22
23 #include <utils/threads.h>
24 #include <utils/Errors.h>
25 #include <utils/KeyedVector.h>
26 #include <utils/String8.h>
27 #include <utils/List.h>
28
29 #include <media/IMediaAnalyticsService.h>
30
31 #include "MetricsSummarizer.h"
32 #include "MetricsSummarizerPlayer.h"
33
34
35
36
37 namespace android {
38
39 static const char *player_ignorable[] = {
40 "android.media.mediaplayer.durationMs",
41 "android.media.mediaplayer.playingMs",
42 "android.media.mediaplayer.frames",
43 "android.media.mediaplayer.dropped",
44 0
45 };
46
MetricsSummarizerPlayer(const char * key)47 MetricsSummarizerPlayer::MetricsSummarizerPlayer(const char *key)
48 : MetricsSummarizer(key)
49 {
50 ALOGV("MetricsSummarizerPlayer::MetricsSummarizerPlayer");
51 setIgnorables(player_ignorable);
52 }
53
mergeRecord(MediaAnalyticsItem & summation,MediaAnalyticsItem & item)54 void MetricsSummarizerPlayer::mergeRecord(MediaAnalyticsItem &summation, MediaAnalyticsItem &item) {
55
56 ALOGV("MetricsSummarizerPlayer::mergeRecord()");
57
58 //
59 // we sum time & frames.
60 // be careful about our special "-1" values that indicate 'unknown'
61 // treat those as 0 [basically, not summing them into the totals].
62 int64_t duration = 0;
63 if (item.getInt64("android.media.mediaplayer.durationMs", &duration)) {
64 ALOGV("found durationMs of %" PRId64, duration);
65 summation.addInt64("android.media.mediaplayer.durationMs",duration);
66 }
67 int64_t playing = 0;
68 if (item.getInt64("android.media.mediaplayer.playingMs", &playing))
69 ALOGV("found playingMs of %" PRId64, playing);
70 if (playing >= 0) {
71 summation.addInt64("android.media.mediaplayer.playingMs",playing);
72 }
73 int64_t frames = 0;
74 if (item.getInt64("android.media.mediaplayer.frames", &frames))
75 ALOGV("found framess of %" PRId64, frames);
76 if (frames >= 0) {
77 summation.addInt64("android.media.mediaplayer.frames",frames);
78 }
79 int64_t dropped = 0;
80 if (item.getInt64("android.media.mediaplayer.dropped", &dropped))
81 ALOGV("found dropped of %" PRId64, dropped);
82 if (dropped >= 0) {
83 summation.addInt64("android.media.mediaplayer.dropped",dropped);
84 }
85 }
86
87 } // namespace android
88