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_BUFFERPOOLCLIENT_H 18 #define ANDROID_HARDWARE_MEDIA_BUFFERPOOL_V2_0_BUFFERPOOLCLIENT_H 19 20 #include <memory> 21 #include <android/hardware/media/bufferpool/2.0/IAccessor.h> 22 #include <android/hardware/media/bufferpool/2.0/IConnection.h> 23 #include <android/hardware/media/bufferpool/2.0/IObserver.h> 24 #include <bufferpool/BufferPoolTypes.h> 25 #include <cutils/native_handle.h> 26 #include "Accessor.h" 27 28 namespace android { 29 namespace hardware { 30 namespace media { 31 namespace bufferpool { 32 namespace V2_0 { 33 namespace implementation { 34 35 using ::android::hardware::media::bufferpool::V2_0::IAccessor; 36 using ::android::hardware::media::bufferpool::V2_0::IConnection; 37 using ::android::hardware::media::bufferpool::V2_0::IObserver; 38 using ::android::hardware::media::bufferpool::V2_0::ResultStatus; 39 using ::android::sp; 40 41 /** 42 * A buffer pool client for a buffer pool. For a specific buffer pool, at most 43 * one buffer pool client exists per process. This class will not be exposed 44 * outside. A buffer pool client will be used via ClientManager. 45 */ 46 class BufferPoolClient { 47 public: 48 /** 49 * Creates a buffer pool client from a local buffer pool 50 * (via ClientManager#create). 51 */ 52 explicit BufferPoolClient(const sp<Accessor> &accessor, 53 const sp<IObserver> &observer); 54 55 /** 56 * Creates a buffer pool client from a remote buffer pool 57 * (via ClientManager#registerSender). 58 * Note: A buffer pool client created with remote buffer pool cannot 59 * allocate a buffer. 60 */ 61 explicit BufferPoolClient(const sp<IAccessor> &accessor, 62 const sp<IObserver> &observer); 63 64 /** Destructs a buffer pool client. */ 65 ~BufferPoolClient(); 66 67 private: 68 bool isValid(); 69 70 bool isLocal(); 71 72 bool isActive(int64_t *lastTransactionUs, bool clearCache); 73 74 ConnectionId getConnectionId(); 75 76 ResultStatus getAccessor(sp<IAccessor> *accessor); 77 78 void receiveInvalidation(uint32_t msgId); 79 80 ResultStatus flush(); 81 82 ResultStatus allocate(const std::vector<uint8_t> ¶ms, 83 native_handle_t **handle, 84 std::shared_ptr<BufferPoolData> *buffer); 85 86 ResultStatus receive(TransactionId transactionId, 87 BufferId bufferId, 88 int64_t timestampUs, 89 native_handle_t **handle, 90 std::shared_ptr<BufferPoolData> *buffer); 91 92 ResultStatus postSend(ConnectionId receiver, 93 const std::shared_ptr<BufferPoolData> &buffer, 94 TransactionId *transactionId, 95 int64_t *timestampUs); 96 97 class Impl; 98 std::shared_ptr<Impl> mImpl; 99 100 friend struct ClientManager; 101 friend struct Observer; 102 }; 103 104 } // namespace implementation 105 } // namespace V2_0 106 } // namespace bufferpool 107 } // namespace media 108 } // namespace hardware 109 } // namespace android 110 111 #endif // ANDROID_HARDWARE_MEDIA_BUFFERPOOL_V2_0_BUFFERPOOLCLIENT_H 112