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