• 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 ANDROID_HARDWARE_MEDIA_BUFFERPOOL_V2_0_BUFFERPOOLTYPES_H
18 #define ANDROID_HARDWARE_MEDIA_BUFFERPOOL_V2_0_BUFFERPOOLTYPES_H
19 
20 #include <android/hardware/media/bufferpool/2.0/types.h>
21 #include <cutils/native_handle.h>
22 #include <fmq/MessageQueue.h>
23 #include <hidl/MQDescriptor.h>
24 #include <hidl/Status.h>
25 
26 namespace android {
27 namespace hardware {
28 namespace media {
29 namespace bufferpool {
30 
31 struct BufferPoolData {
32     // For local use, to specify a bufferpool (client connection) for buffers.
33     // Return value from connect#IAccessor(android.hardware.media.bufferpool@2.0).
34     int64_t mConnectionId;
35     // BufferId
36     uint32_t mId;
37 
BufferPoolDataBufferPoolData38     BufferPoolData() : mConnectionId(0), mId(0) {}
39 
BufferPoolDataBufferPoolData40     BufferPoolData(
41             int64_t connectionId, uint32_t id)
42             : mConnectionId(connectionId), mId(id) {}
43 
~BufferPoolDataBufferPoolData44     ~BufferPoolData() {}
45 };
46 
47 namespace V2_0 {
48 namespace implementation {
49 
50 using ::android::hardware::kSynchronizedReadWrite;
51 using ::android::hardware::kUnsynchronizedWrite;
52 
53 typedef uint32_t BufferId;
54 typedef uint64_t TransactionId;
55 typedef int64_t ConnectionId;
56 
57 enum : ConnectionId {
58     INVALID_CONNECTIONID = 0,
59 };
60 
61 typedef android::hardware::MessageQueue<BufferStatusMessage, kSynchronizedReadWrite> BufferStatusQueue;
62 typedef BufferStatusQueue::Descriptor StatusDescriptor;
63 
64 typedef android::hardware::MessageQueue<BufferInvalidationMessage, kUnsynchronizedWrite>
65         BufferInvalidationQueue;
66 typedef BufferInvalidationQueue::Descriptor InvalidationDescriptor;
67 
68 /**
69  * Allocation wrapper class for buffer pool.
70  */
71 struct BufferPoolAllocation {
72     const native_handle_t *mHandle;
73 
handleBufferPoolAllocation74     const native_handle_t *handle() {
75         return mHandle;
76     }
77 
BufferPoolAllocationBufferPoolAllocation78     BufferPoolAllocation(const native_handle_t *handle) : mHandle(handle) {}
79 
~BufferPoolAllocationBufferPoolAllocation80     ~BufferPoolAllocation() {};
81 };
82 
83 /**
84  * Allocator wrapper class for buffer pool.
85  */
86 class BufferPoolAllocator {
87 public:
88 
89     /**
90      * Allocate an allocation(buffer) for buffer pool.
91      *
92      * @param params    allocation parameters
93      * @param alloc     created allocation
94      * @param allocSize size of created allocation
95      *
96      * @return OK when an allocation is created successfully.
97      */
98     virtual ResultStatus allocate(
99             const std::vector<uint8_t> &params,
100             std::shared_ptr<BufferPoolAllocation> *alloc,
101             size_t *allocSize) = 0;
102 
103     /**
104      * Returns whether allocation parameters of an old allocation are
105      * compatible with new allocation parameters.
106      */
107     virtual bool compatible(const std::vector<uint8_t> &newParams,
108                             const std::vector<uint8_t> &oldParams) = 0;
109 
110 protected:
111     BufferPoolAllocator() = default;
112 
113     virtual ~BufferPoolAllocator() = default;
114 };
115 
116 }  // namespace implementation
117 }  // namespace V2_0
118 }  // namespace bufferpool
119 }  // namespace media
120 }  // namespace hardware
121 }  // namespace android
122 
123 #endif  // ANDROID_HARDWARE_MEDIA_BUFFERPOOL_V2_0_BUFFERPOOLTYPES_H
124