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