Ray Essick | 2e9c63b | 2017-03-29 15:16:44 -0700 | [diff] [blame] | 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 | |
| 47 | MetricsSummarizerPlayer::MetricsSummarizerPlayer(const char *key) |
| 48 | : MetricsSummarizer(key) |
| 49 | { |
| 50 | ALOGV("MetricsSummarizerPlayer::MetricsSummarizerPlayer"); |
| 51 | setIgnorables(player_ignorable); |
| 52 | } |
| 53 | |
Ray Essick | 96eaaac | 2017-08-31 11:45:05 -0700 | [diff] [blame] | 54 | // NB: this is also called for the first time -- so summation == item |
| 55 | // Not sure if we need a flag for that or not. |
| 56 | // In this particular mergeRecord() code -- we're' ok for this. |
Ray Essick | 2e9c63b | 2017-03-29 15:16:44 -0700 | [diff] [blame] | 57 | void MetricsSummarizerPlayer::mergeRecord(MediaAnalyticsItem &summation, MediaAnalyticsItem &item) { |
| 58 | |
| 59 | ALOGV("MetricsSummarizerPlayer::mergeRecord()"); |
| 60 | |
Ray Essick | 96eaaac | 2017-08-31 11:45:05 -0700 | [diff] [blame] | 61 | |
Ray Essick | 2e9c63b | 2017-03-29 15:16:44 -0700 | [diff] [blame] | 62 | int64_t duration = 0; |
| 63 | if (item.getInt64("android.media.mediaplayer.durationMs", &duration)) { |
| 64 | ALOGV("found durationMs of %" PRId64, duration); |
Ray Essick | 96eaaac | 2017-08-31 11:45:05 -0700 | [diff] [blame] | 65 | minMaxVar64(summation, "android.media.mediaplayer.durationMs", duration); |
Ray Essick | 2e9c63b | 2017-03-29 15:16:44 -0700 | [diff] [blame] | 66 | } |
Ray Essick | 96eaaac | 2017-08-31 11:45:05 -0700 | [diff] [blame] | 67 | |
Ray Essick | 2e9c63b | 2017-03-29 15:16:44 -0700 | [diff] [blame] | 68 | int64_t playing = 0; |
Ray Essick | 96eaaac | 2017-08-31 11:45:05 -0700 | [diff] [blame] | 69 | if (item.getInt64("android.media.mediaplayer.playingMs", &playing)) { |
Ray Essick | 2e9c63b | 2017-03-29 15:16:44 -0700 | [diff] [blame] | 70 | ALOGV("found playingMs of %" PRId64, playing); |
Ray Essick | 96eaaac | 2017-08-31 11:45:05 -0700 | [diff] [blame] | 71 | } |
| 72 | if (playing >= 0) { |
| 73 | minMaxVar64(summation,"android.media.mediaplayer.playingMs",playing); |
| 74 | } |
| 75 | |
Ray Essick | 2e9c63b | 2017-03-29 15:16:44 -0700 | [diff] [blame] | 76 | int64_t frames = 0; |
Ray Essick | 96eaaac | 2017-08-31 11:45:05 -0700 | [diff] [blame] | 77 | if (item.getInt64("android.media.mediaplayer.frames", &frames)) { |
Ray Essick | 2e9c63b | 2017-03-29 15:16:44 -0700 | [diff] [blame] | 78 | ALOGV("found framess of %" PRId64, frames); |
Ray Essick | 96eaaac | 2017-08-31 11:45:05 -0700 | [diff] [blame] | 79 | } |
| 80 | if (frames >= 0) { |
| 81 | minMaxVar64(summation,"android.media.mediaplayer.frames",frames); |
| 82 | } |
| 83 | |
Ray Essick | 2e9c63b | 2017-03-29 15:16:44 -0700 | [diff] [blame] | 84 | int64_t dropped = 0; |
Ray Essick | 96eaaac | 2017-08-31 11:45:05 -0700 | [diff] [blame] | 85 | if (item.getInt64("android.media.mediaplayer.dropped", &dropped)) { |
Ray Essick | 2e9c63b | 2017-03-29 15:16:44 -0700 | [diff] [blame] | 86 | ALOGV("found dropped of %" PRId64, dropped); |
Ray Essick | 96eaaac | 2017-08-31 11:45:05 -0700 | [diff] [blame] | 87 | } |
| 88 | if (dropped >= 0) { |
| 89 | minMaxVar64(summation,"android.media.mediaplayer.dropped",dropped); |
| 90 | } |
Ray Essick | 2e9c63b | 2017-03-29 15:16:44 -0700 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | } // namespace android |