Sungtak Lee | 8fc3ca4 | 2022-12-07 07:45:45 +0000 | [diff] [blame] | 1 | /* |
Sungtak Lee | 76937c6 | 2022-12-07 11:42:03 +0000 | [diff] [blame] | 2 | * Copyright (C) 2022 The Android Open Source Project |
Sungtak Lee | 8fc3ca4 | 2022-12-07 07:45:45 +0000 | [diff] [blame] | 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 | |
Sungtak Lee | 76937c6 | 2022-12-07 11:42:03 +0000 | [diff] [blame] | 17 | #pragma once |
Sungtak Lee | 8fc3ca4 | 2022-12-07 07:45:45 +0000 | [diff] [blame] | 18 | |
| 19 | #include <memory> |
Sungtak Lee | 76937c6 | 2022-12-07 11:42:03 +0000 | [diff] [blame] | 20 | #include <aidl/android/hardware/media/bufferpool2/IAccessor.h> |
| 21 | #include <aidl/android/hardware/media/bufferpool2/IObserver.h> |
| 22 | #include <bufferpool2/BufferPoolTypes.h> |
Sungtak Lee | 8fc3ca4 | 2022-12-07 07:45:45 +0000 | [diff] [blame] | 23 | |
Sungtak Lee | 76937c6 | 2022-12-07 11:42:03 +0000 | [diff] [blame] | 24 | namespace aidl::android::hardware::media::bufferpool2::implementation { |
Sungtak Lee | 8fc3ca4 | 2022-12-07 07:45:45 +0000 | [diff] [blame] | 25 | |
Sungtak Lee | 76937c6 | 2022-12-07 11:42:03 +0000 | [diff] [blame] | 26 | using aidl::android::hardware::media::bufferpool2::IAccessor; |
| 27 | using aidl::android::hardware::media::bufferpool2::IObserver; |
| 28 | |
| 29 | struct Accessor; |
Sungtak Lee | 8fc3ca4 | 2022-12-07 07:45:45 +0000 | [diff] [blame] | 30 | |
| 31 | /** |
| 32 | * A buffer pool client for a buffer pool. For a specific buffer pool, at most |
| 33 | * one buffer pool client exists per process. This class will not be exposed |
| 34 | * outside. A buffer pool client will be used via ClientManager. |
| 35 | */ |
| 36 | class BufferPoolClient { |
| 37 | public: |
| 38 | /** |
| 39 | * Creates a buffer pool client from a local buffer pool |
| 40 | * (via ClientManager#create). |
| 41 | */ |
Sungtak Lee | 76937c6 | 2022-12-07 11:42:03 +0000 | [diff] [blame] | 42 | explicit BufferPoolClient(const std::shared_ptr<Accessor> &accessor, |
| 43 | const std::shared_ptr<IObserver> &observer); |
Sungtak Lee | 8fc3ca4 | 2022-12-07 07:45:45 +0000 | [diff] [blame] | 44 | |
| 45 | /** |
| 46 | * Creates a buffer pool client from a remote buffer pool |
| 47 | * (via ClientManager#registerSender). |
| 48 | * Note: A buffer pool client created with remote buffer pool cannot |
| 49 | * allocate a buffer. |
| 50 | */ |
Sungtak Lee | 76937c6 | 2022-12-07 11:42:03 +0000 | [diff] [blame] | 51 | explicit BufferPoolClient(const std::shared_ptr<IAccessor> &accessor, |
| 52 | const std::shared_ptr<IObserver> &observer); |
Sungtak Lee | 8fc3ca4 | 2022-12-07 07:45:45 +0000 | [diff] [blame] | 53 | |
| 54 | /** Destructs a buffer pool client. */ |
| 55 | ~BufferPoolClient(); |
| 56 | |
| 57 | private: |
| 58 | bool isValid(); |
| 59 | |
| 60 | bool isLocal(); |
| 61 | |
Sungtak Lee | 76937c6 | 2022-12-07 11:42:03 +0000 | [diff] [blame] | 62 | bool isActive(int64_t *lastTransactionMs, bool clearCache); |
Sungtak Lee | 8fc3ca4 | 2022-12-07 07:45:45 +0000 | [diff] [blame] | 63 | |
| 64 | ConnectionId getConnectionId(); |
| 65 | |
Sungtak Lee | 76937c6 | 2022-12-07 11:42:03 +0000 | [diff] [blame] | 66 | BufferPoolStatus getAccessor(std::shared_ptr<IAccessor> *accessor); |
Sungtak Lee | 8fc3ca4 | 2022-12-07 07:45:45 +0000 | [diff] [blame] | 67 | |
| 68 | void receiveInvalidation(uint32_t msgId); |
| 69 | |
Sungtak Lee | 76937c6 | 2022-12-07 11:42:03 +0000 | [diff] [blame] | 70 | BufferPoolStatus flush(); |
Sungtak Lee | 8fc3ca4 | 2022-12-07 07:45:45 +0000 | [diff] [blame] | 71 | |
Sungtak Lee | 76937c6 | 2022-12-07 11:42:03 +0000 | [diff] [blame] | 72 | BufferPoolStatus allocate(const std::vector<uint8_t> ¶ms, |
Sungtak Lee | 8fc3ca4 | 2022-12-07 07:45:45 +0000 | [diff] [blame] | 73 | native_handle_t **handle, |
| 74 | std::shared_ptr<BufferPoolData> *buffer); |
| 75 | |
Sungtak Lee | 76937c6 | 2022-12-07 11:42:03 +0000 | [diff] [blame] | 76 | BufferPoolStatus receive(TransactionId transactionId, |
Sungtak Lee | 8fc3ca4 | 2022-12-07 07:45:45 +0000 | [diff] [blame] | 77 | BufferId bufferId, |
Sungtak Lee | 76937c6 | 2022-12-07 11:42:03 +0000 | [diff] [blame] | 78 | int64_t timestampMs, |
Sungtak Lee | 8fc3ca4 | 2022-12-07 07:45:45 +0000 | [diff] [blame] | 79 | native_handle_t **handle, |
| 80 | std::shared_ptr<BufferPoolData> *buffer); |
| 81 | |
Sungtak Lee | 76937c6 | 2022-12-07 11:42:03 +0000 | [diff] [blame] | 82 | BufferPoolStatus postSend(ConnectionId receiver, |
Sungtak Lee | 8fc3ca4 | 2022-12-07 07:45:45 +0000 | [diff] [blame] | 83 | const std::shared_ptr<BufferPoolData> &buffer, |
| 84 | TransactionId *transactionId, |
Sungtak Lee | 76937c6 | 2022-12-07 11:42:03 +0000 | [diff] [blame] | 85 | int64_t *timestampMs); |
Sungtak Lee | 8fc3ca4 | 2022-12-07 07:45:45 +0000 | [diff] [blame] | 86 | |
| 87 | class Impl; |
| 88 | std::shared_ptr<Impl> mImpl; |
| 89 | |
| 90 | friend struct ClientManager; |
| 91 | friend struct Observer; |
| 92 | }; |
| 93 | |
Sungtak Lee | 76937c6 | 2022-12-07 11:42:03 +0000 | [diff] [blame] | 94 | } // namespace aidl::android::hardware::bufferpool2::implementation |