Home | History | Annotate | Download | only in bufferpool
      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_V1_0_BUFFERPOOLTYPES_H
     18 #define ANDROID_HARDWARE_MEDIA_BUFFERPOOL_V1_0_BUFFERPOOLTYPES_H
     19 
     20 #include <android/hardware/media/bufferpool/1.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 (at) 1.0).
     34     int64_t mConnectionId;
     35     // BufferId
     36     uint32_t mId;
     37 
     38     BufferPoolData() : mConnectionId(0), mId(0) {}
     39 
     40     BufferPoolData(
     41             int64_t connectionId, uint32_t id)
     42             : mConnectionId(connectionId), mId(id) {}
     43 
     44     ~BufferPoolData() {}
     45 };
     46 
     47 namespace V1_0 {
     48 namespace implementation {
     49 
     50 using ::android::hardware::kSynchronizedReadWrite;
     51 
     52 typedef uint32_t BufferId;
     53 typedef uint64_t TransactionId;
     54 typedef int64_t ConnectionId;
     55 
     56 enum : ConnectionId {
     57     INVALID_CONNECTIONID = 0,
     58 };
     59 
     60 typedef android::hardware::MessageQueue<BufferStatusMessage, kSynchronizedReadWrite> BufferStatusQueue;
     61 typedef BufferStatusQueue::Descriptor QueueDescriptor;
     62 
     63 /**
     64  * Allocation wrapper class for buffer pool.
     65  */
     66 struct BufferPoolAllocation {
     67     const native_handle_t *mHandle;
     68 
     69     const native_handle_t *handle() {
     70         return mHandle;
     71     }
     72 
     73     BufferPoolAllocation(const native_handle_t *handle) : mHandle(handle) {}
     74 
     75     ~BufferPoolAllocation() {};
     76 };
     77 
     78 /**
     79  * Allocator wrapper class for buffer pool.
     80  */
     81 class BufferPoolAllocator {
     82 public:
     83 
     84     /**
     85      * Allocate an allocation(buffer) for buffer pool.
     86      *
     87      * @param params    allocation parameters
     88      * @param alloc     created allocation
     89      * @param allocSize size of created allocation
     90      *
     91      * @return OK when an allocation is created successfully.
     92      */
     93     virtual ResultStatus allocate(
     94             const std::vector<uint8_t> &params,
     95             std::shared_ptr<BufferPoolAllocation> *alloc,
     96             size_t *allocSize) = 0;
     97 
     98     /**
     99      * Returns whether allocation parameters of an old allocation are
    100      * compatible with new allocation parameters.
    101      */
    102     virtual bool compatible(const std::vector<uint8_t> &newParams,
    103                             const std::vector<uint8_t> &oldParams) = 0;
    104 
    105 protected:
    106     BufferPoolAllocator() = default;
    107 
    108     virtual ~BufferPoolAllocator() = default;
    109 };
    110 
    111 }  // namespace implementation
    112 }  // namespace V1_0
    113 }  // namespace bufferpool
    114 }  // namespace media
    115 }  // namespace hardware
    116 }  // namespace android
    117 
    118 #endif  // ANDROID_HARDWARE_MEDIA_BUFFERPOOL_V1_0_BUFFERPOOLTYPES_H
    119