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 | |
Sungtak Lee | 76937c6 | 2022-12-07 11:42:03 +0000 | [diff] [blame] | 19 | #include <memory> |
Sungtak Lee | 8fc3ca4 | 2022-12-07 07:45:45 +0000 | [diff] [blame] | 20 | |
Sungtak Lee | 76937c6 | 2022-12-07 11:42:03 +0000 | [diff] [blame] | 21 | #include <aidl/android/hardware/media/bufferpool2/BnConnection.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 | struct Accessor; |
| 27 | |
| 28 | struct Connection : public BnConnection { |
| 29 | // Methods from ::aidl::android::hardware::media::bufferpool2::IConnection. |
| 30 | ::ndk::ScopedAStatus fetch(const std::vector<::aidl::android::hardware::media::bufferpool2::IConnection::FetchInfo>& in_fetchInfos, std::vector<::aidl::android::hardware::media::bufferpool2::IConnection::FetchResult>* _aidl_return) override; |
| 31 | |
| 32 | // Methods from ::aidl::android::hardware::media::bufferpool2::IConnection. |
| 33 | ::ndk::ScopedAStatus sync() override; |
Sungtak Lee | 8fc3ca4 | 2022-12-07 07:45:45 +0000 | [diff] [blame] | 34 | |
| 35 | /** |
| 36 | * Invalidates all buffers which are active and/or are ready to be recycled. |
| 37 | */ |
Sungtak Lee | 76937c6 | 2022-12-07 11:42:03 +0000 | [diff] [blame] | 38 | BufferPoolStatus flush(); |
Sungtak Lee | 8fc3ca4 | 2022-12-07 07:45:45 +0000 | [diff] [blame] | 39 | |
| 40 | /** |
| 41 | * Allocates a buffer using the specified parameters. Recycles a buffer if |
| 42 | * it is possible. The returned buffer can be transferred to other remote |
| 43 | * clients(Connection). |
| 44 | * |
| 45 | * @param params allocation parameters. |
| 46 | * @param bufferId Id of the allocated buffer. |
| 47 | * @param handle native handle of the allocated buffer. |
| 48 | * |
| 49 | * @return OK if a buffer is successfully allocated. |
| 50 | * NO_MEMORY when there is no memory. |
| 51 | * CRITICAL_ERROR otherwise. |
| 52 | */ |
Sungtak Lee | 76937c6 | 2022-12-07 11:42:03 +0000 | [diff] [blame] | 53 | BufferPoolStatus allocate(const std::vector<uint8_t> ¶ms, |
Sungtak Lee | 8fc3ca4 | 2022-12-07 07:45:45 +0000 | [diff] [blame] | 54 | BufferId *bufferId, const native_handle_t **handle); |
| 55 | |
| 56 | /** |
| 57 | * Processes pending buffer status messages and performs periodic cache cleaning |
| 58 | * from bufferpool. |
| 59 | * |
| 60 | * @param clearCache if clearCache is true, bufferpool frees all buffers |
| 61 | * waiting to be recycled. |
| 62 | */ |
| 63 | void cleanUp(bool clearCache); |
| 64 | |
| 65 | /** Destructs a connection. */ |
| 66 | ~Connection(); |
| 67 | |
| 68 | /** Creates a connection. */ |
| 69 | Connection(); |
| 70 | |
| 71 | /** |
| 72 | * Initializes with the specified buffer pool and the connection id. |
| 73 | * The connection id should be unique in the whole system. |
| 74 | * |
| 75 | * @param accessor the specified buffer pool. |
| 76 | * @param connectionId Id. |
| 77 | */ |
Sungtak Lee | 76937c6 | 2022-12-07 11:42:03 +0000 | [diff] [blame] | 78 | void initialize(const std::shared_ptr<Accessor> &accessor, ConnectionId connectionId); |
Sungtak Lee | 8fc3ca4 | 2022-12-07 07:45:45 +0000 | [diff] [blame] | 79 | |
| 80 | enum : uint32_t { |
| 81 | SYNC_BUFFERID = UINT32_MAX, |
| 82 | }; |
| 83 | |
| 84 | private: |
| 85 | bool mInitialized; |
Sungtak Lee | 76937c6 | 2022-12-07 11:42:03 +0000 | [diff] [blame] | 86 | std::shared_ptr<Accessor> mAccessor; |
Sungtak Lee | 8fc3ca4 | 2022-12-07 07:45:45 +0000 | [diff] [blame] | 87 | ConnectionId mConnectionId; |
Sungtak Lee | 76937c6 | 2022-12-07 11:42:03 +0000 | [diff] [blame] | 88 | |
| 89 | bool fetch( |
| 90 | uint64_t transactionId, |
| 91 | uint32_t bufferId, |
| 92 | std::vector<::aidl::android::hardware::media::bufferpool2::IConnection::FetchResult> |
| 93 | *result); |
Sungtak Lee | 8fc3ca4 | 2022-12-07 07:45:45 +0000 | [diff] [blame] | 94 | }; |
| 95 | |
Sungtak Lee | 76937c6 | 2022-12-07 11:42:03 +0000 | [diff] [blame] | 96 | } // namespace aidl::android::hardware::media::bufferpool2::implementation |