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 <aidl/android/media/eco/BnECOServiceStatsProvider.h>
21 #include <aidl/android/media/eco/IECOService.h>
22 #include <aidl/android/media/eco/IECOSession.h>
23 #include <utils/Log.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 aidl::android::media::eco::BnECOServiceStatsProvider;
38 using aidl::android::media::eco::ECOData;
39 using aidl::android::media::eco::ECODataStatus;
40 using aidl::android::media::eco::IECOService;
41 using aidl::android::media::eco::IECOSession;
42 using ::ndk::ScopedAStatus;
43 
44 /**
45  * ECOServiceStatsProvider interface class.
46  */
47 class ECOServiceStatsProvider : public BnECOServiceStatsProvider {
48 public:
49     ECOServiceStatsProvider(int32_t width, int32_t height, bool isCameraRecording,
50                             std::shared_ptr<IECOSession>& session, const char* name);
~ECOServiceStatsProvider()51     virtual ~ECOServiceStatsProvider() {}
52 
53     virtual ScopedAStatus getType(int32_t* _aidl_return);
54     virtual ScopedAStatus getName(std::string* _aidl_return);
55     virtual ScopedAStatus getECOSession(::ndk::SpAIBinder* _aidl_return);
56     virtual ScopedAStatus isCameraRecording(bool* _aidl_return);
57 
58     // IBinder::DeathRecipient implementation
59     virtual void binderDied(const std::weak_ptr<AIBinder>& who);
60 
61     bool updateStats(const ECOData& data);
62     bool addProvider();
63     bool removeProvider();
64     float getFramerate(int64_t currTimestamp);
65     static std::shared_ptr<ECOServiceStatsProvider> create(int32_t width, int32_t height,
66                                                            bool isCameraRecording,
67                                                            const char* name);
68 
69 private:
70     int32_t mWidth = 0;
71     int32_t mHeight = 0;
72     bool mIsCameraRecording = false;
73     std::shared_ptr<IECOSession> mECOSession = nullptr;
74     const char* mProviderName = nullptr;
75     int64_t mLastFrameTimestamp = 0;
76 };
77 
78 }  // namespace eco
79 }  // namespace media
80 }  // namespace android
81 
82 #endif  // ANDROID_MEDIA_ECO_SERVICE_STATS_PROVIDER_H_
83