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 //#define LOG_NDEBUG 0
18 #define LOG_TAG "FakeECOServiceStatsProvider"
19
20 #include "FakeECOServiceStatsProvider.h"
21
22 #include <android-base/unique_fd.h>
23 #include <android/binder_auto_utils.h>
24 #include <android/binder_parcel.h>
25 #include <cutils/ashmem.h>
26 #include <gtest/gtest.h>
27 #include <math.h>
28 #include <stdlib.h>
29 #include <sys/mman.h>
30 #include <utils/Log.h>
31
32 namespace android {
33 namespace media {
34 namespace eco {
35
FakeECOServiceStatsProvider(int32_t width,int32_t height,bool isCameraRecording,float frameRate,std::shared_ptr<IECOSession> session)36 FakeECOServiceStatsProvider::FakeECOServiceStatsProvider(int32_t width, int32_t height,
37 bool isCameraRecording, float frameRate,
38 std::shared_ptr<IECOSession> session)
39 : mWidth(width),
40 mHeight(height),
41 mIsCameraRecording(isCameraRecording),
42 mFrameRate(frameRate),
43 mFrameNumber(0),
44 mECOSession(session) {
45 ALOGD("FakeECOServiceStatsProvider construct with w: %d, h: %d, isCameraRecording: %d, "
46 "frameRate: %f",
47 mWidth, mHeight, mIsCameraRecording, mFrameRate);
48 }
49
FakeECOServiceStatsProvider(int32_t width,int32_t height,bool isCameraRecording,float frameRate)50 FakeECOServiceStatsProvider::FakeECOServiceStatsProvider(int32_t width, int32_t height,
51 bool isCameraRecording, float frameRate)
52 : mWidth(width),
53 mHeight(height),
54 mIsCameraRecording(isCameraRecording),
55 mFrameRate(frameRate),
56 mFrameNumber(0) {
57 ALOGD("FakeECOServiceStatsProvider construct with w: %d, h: %d, isCameraRecording: %d, "
58 "frameRate: %f",
59 mWidth, mHeight, mIsCameraRecording, mFrameRate);
60 }
61
~FakeECOServiceStatsProvider()62 FakeECOServiceStatsProvider::~FakeECOServiceStatsProvider() {
63 ALOGD("FakeECOServiceStatsProvider destructor");
64 }
65
getType(int32_t *)66 ndk::ScopedAStatus FakeECOServiceStatsProvider::getType(int32_t* /*_aidl_return*/) {
67 return ndk::ScopedAStatus::ok();
68 }
69
getName(std::string * _aidl_return)70 ndk::ScopedAStatus FakeECOServiceStatsProvider::getName(std::string* _aidl_return) {
71 *_aidl_return = std::string("FakeECOServiceStatsProvider");
72 return ndk::ScopedAStatus::ok();
73 }
74
getECOSession(::ndk::SpAIBinder * _aidl_return)75 ndk::ScopedAStatus FakeECOServiceStatsProvider::getECOSession(::ndk::SpAIBinder* _aidl_return) {
76 *_aidl_return = mECOSession->asBinder();
77 return ndk::ScopedAStatus::ok();
78 }
79
injectSessionStats(const ECOData & stats)80 bool FakeECOServiceStatsProvider::injectSessionStats(const ECOData& stats) {
81 if (mECOSession == nullptr) return false;
82 ALOGD("injectSessionStats");
83 bool res;
84 mECOSession->pushNewStats(stats, &res);
85 return res;
86 }
87
injectFrameStats(const ECOData & stats)88 bool FakeECOServiceStatsProvider::injectFrameStats(const ECOData& stats) {
89 if (mECOSession == nullptr) return false;
90 ALOGD("injectPerFrameStats");
91 bool res;
92 mECOSession->pushNewStats(stats, &res);
93 return res;
94 }
95
96 // IBinder::DeathRecipient implementation
binderDied(const std::weak_ptr<AIBinder> &)97 void FakeECOServiceStatsProvider::binderDied(const std::weak_ptr<AIBinder>& /*who*/) {}
98
99 } // namespace eco
100 } // namespace media
101 } // namespace android
102