1 /*
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 #ifndef ANDROID_MEDIA_ECO_SERVICE_STATS_PROVIDER_H_
18 #define ANDROID_MEDIA_ECO_SERVICE_STATS_PROVIDER_H_
19 
20 #include <android/media/eco/BnECOServiceStatsProvider.h>
21 #include <android/media/eco/IECOSession.h>
22 #include <android/media/eco/IECOService.h>
23 #include <binder/BinderService.h>
24 
25 #include <condition_variable>
26 #include <memory>
27 #include <mutex>
28 #include <thread>
29 
30 #include "ECOData.h"
31 #include "ECOServiceConstants.h"
32 
33 namespace android {
34 namespace media {
35 namespace eco {
36 
37 using ::android::binder::Status;
38 
39 /**
40  * ECOServiceStatsProvider interface class.
41  */
42 class ECOServiceStatsProvider : public BinderService<IECOServiceStatsProvider>,
43                                 public BnECOServiceStatsProvider,
44                                 public virtual IBinder::DeathRecipient {
45     friend class BinderService<IECOServiceStatsProvider>;
46 
47 public:
~ECOServiceStatsProvider()48     virtual ~ECOServiceStatsProvider() {}
49 
50     virtual Status getType(int32_t* _aidl_return);
51     virtual Status getName(::android::String16* _aidl_return);
52     virtual Status getECOSession(::android::sp<::android::IBinder>* _aidl_return);
53     virtual Status isCameraRecording(bool* _aidl_return);
54 
55     // IBinder::DeathRecipient implementation
56     virtual void binderDied(const wp<IBinder>& who);
57 
58     bool updateStats(const ECOData& data);
59     bool addProvider();
60     bool removeProvider();
61     float getFramerate(int64_t currTimestamp);
62     static android::sp<ECOServiceStatsProvider> create(
63         int32_t width, int32_t height, bool isCameraRecording, const char* name);
64 
65 private:
66     ECOServiceStatsProvider(int32_t width, int32_t height, bool isCameraRecording,
67                             android::sp<IECOSession>& session, const char* name);
68     int32_t mWidth = 0;
69     int32_t mHeight = 0;
70     bool mIsCameraRecording = false;
71     android::sp<IECOSession> mECOSession = nullptr;
72     const char* mProviderName = nullptr;
73     int64_t mLastFrameTimestamp = 0;
74 };
75 
76 }  // namespace eco
77 }  // namespace media
78 }  // namespace android
79 
80 #endif  // ANDROID_MEDIA_ECO_SERVICE_STATS_PROVIDER_H_
81