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 // A fake ECOServiceStatsProvider for testing ECOService and ECOSession. 18 19 #include <android-base/unique_fd.h> 20 #include <android/media/eco/BnECOServiceStatsProvider.h> 21 #include <binder/BinderService.h> 22 #include <binder/Parcel.h> 23 #include <binder/Parcelable.h> 24 #include <cutils/ashmem.h> 25 #include <gtest/gtest.h> 26 #include <math.h> 27 #include <stdlib.h> 28 #include <sys/mman.h> 29 #include <utils/Log.h> 30 31 #include <condition_variable> 32 #include <deque> 33 #include <list> 34 #include <memory> 35 #include <mutex> 36 #include <thread> 37 38 #include "eco/ECOData.h" 39 #include "eco/ECODataKey.h" 40 #include "eco/ECOService.h" 41 42 namespace android { 43 namespace media { 44 namespace eco { 45 46 using ::android::sp; 47 using ::android::binder::Status; 48 49 /** 50 * A fake ECOServiceStatsProvider. 51 * 52 * FakeECOServiceStatsProvider is a fake ECOServiceStatsProvider that used for testing. 53 */ 54 55 class FakeECOServiceStatsProvider : public BnECOServiceStatsProvider { 56 public: 57 FakeECOServiceStatsProvider(int32_t width, int32_t height, bool isCameraRecording, 58 float frameRate, android::sp<IECOSession> session); 59 60 FakeECOServiceStatsProvider(int32_t width, int32_t height, bool isCameraRecording, 61 float frameRate); 62 setECOSession(android::sp<IECOSession> session)63 void setECOSession(android::sp<IECOSession> session) { mECOSession = session; } 64 65 // Helper function to inject session stats to the FakeECOServiceStatsProvider so provider 66 // could push to the service. 67 bool injectSessionStats(const ECOData& stats); 68 69 // Helper function to inject each frame's stats to the FakeECOServiceStatsProvider so provider 70 // could push to the service. 71 bool injectFrameStats(const ECOData& stats); 72 73 /* Starts the FakeECOServiceStatsProvider */ 74 void start(); 75 76 /* Stops FakeECOServiceStatsProvider */ 77 void stop(); 78 79 virtual ~FakeECOServiceStatsProvider(); 80 81 virtual Status getType(int32_t* _aidl_return); 82 virtual Status getName(::android::String16* _aidl_return); 83 virtual Status getECOSession(::android::sp<::android::IBinder>* _aidl_return); 84 85 // IBinder::DeathRecipient implementation 86 virtual void binderDied(const wp<IBinder>& who); 87 88 private: 89 int32_t mWidth; 90 int32_t mHeight; 91 bool mIsCameraRecording; 92 float mFrameRate; 93 uint32_t mFrameNumber; 94 95 android::sp<IECOSession> mECOSession; 96 }; 97 98 } // namespace eco 99 } // namespace media 100 } // namespace android 101