1 /* 2 * Copyright (C) 2022 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 #pragma once 18 19 #include <pthread.h> 20 #include <bufferpool2/BufferPoolTypes.h> 21 22 using aidl::android::hardware::media::bufferpool2::implementation:: 23 BufferPoolStatus; 24 using aidl::android::hardware::media::bufferpool2::implementation:: 25 BufferPoolAllocation; 26 using aidl::android::hardware::media::bufferpool2::implementation:: 27 BufferPoolAllocator; 28 using aidl::android::hardware::media::bufferpool2::ResultStatus; 29 30 struct IpcMutex { 31 pthread_mutex_t lock; 32 pthread_cond_t cond; 33 int counter = 0; 34 bool signalled = false; 35 36 void init(); 37 38 static IpcMutex *Import(void *mem); 39 }; 40 41 // buffer allocator for the tests 42 class TestBufferPoolAllocator : public BufferPoolAllocator { 43 public: TestBufferPoolAllocator()44 TestBufferPoolAllocator() {} 45 ~TestBufferPoolAllocator()46 ~TestBufferPoolAllocator() override {} 47 48 BufferPoolStatus allocate(const std::vector<uint8_t> ¶ms, 49 std::shared_ptr<BufferPoolAllocation> *alloc, 50 size_t *allocSize) override; 51 52 bool compatible(const std::vector<uint8_t> &newParams, 53 const std::vector<uint8_t> &oldParams) override; 54 55 static bool Fill(const native_handle_t *handle, const unsigned char val); 56 57 static bool Verify(const native_handle_t *handle, const unsigned char val); 58 59 static bool MapMemoryForMutex(const native_handle_t *handle, void **mem); 60 61 static bool UnmapMemoryForMutex(void *mem); 62 }; 63 64 // retrieve buffer allocator parameters 65 void getTestAllocatorParams(std::vector<uint8_t> *params); 66 67 void getIpcMutexParams(std::vector<uint8_t> *params); 68