blob: 79436375bd33486c79278ec965d50cb829d3a5b5 [file] [log] [blame]
Shuzhen Wang316781a2020-08-18 18:11:01 -07001/*
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#ifndef ANDROID_SERVICE_UTILS_SESSION_STATS_BUILDER_H
18#define ANDROID_SERVICE_UTILS_SESSION_STATS_BUILDER_H
19
20#include <utils/Errors.h>
21
22#include <mutex>
23#include <map>
24
25namespace android {
26
27// Helper class to build stream stats
28struct StreamStats {
29 int64_t mRequestedFrameCount;
30 int64_t mDroppedFrameCount;
31 bool mCounterStopped;
32 int32_t mStartLatencyMs;
33
34 StreamStats() : mRequestedFrameCount(0),
35 mDroppedFrameCount(0),
36 mCounterStopped(false),
37 mStartLatencyMs(0) {}
38};
39
40// Helper class to build session stats
41class SessionStatsBuilder {
42public:
43
44 status_t addStream(int streamId);
45 status_t removeStream(int streamId);
46
47 // Return the session statistics and reset the internal states.
48 void buildAndReset(/*out*/int64_t* requestCount,
49 /*out*/int64_t* errorResultCount,
50 /*out*/bool* deviceError,
51 /*out*/std::map<int, StreamStats> *statsMap);
52
53 // Stream specific counter
54 void startCounter(int streamId);
55 void stopCounter(int streamId);
56 void incCounter(int streamId, bool dropped, int32_t captureLatencyMs);
57
58 // Session specific counter
59 void stopCounter();
60 void incResultCounter(bool dropped);
61 void onDeviceError();
62
63 SessionStatsBuilder() : mRequestCount(0), mErrorResultCount(0),
64 mCounterStopped(false), mDeviceError(false) {}
65private:
66 std::mutex mLock;
67 int64_t mRequestCount;
68 int64_t mErrorResultCount;
69 bool mCounterStopped;
70 bool mDeviceError;
71 // Map from stream id to stream statistics
72 std::map<int, StreamStats> mStatsMap;
73};
74
75}; // namespace android
76
77#endif // ANDROID_SERVICE_UTILS_SESSION_STATS_BUILDER_H