blob: 80fd43e93fcce4b4b015e2e19a0128b993d791f1 [file] [log] [blame]
Sungtak Lee8fc3ca42022-12-07 07:45:45 +00001/*
Sungtak Lee76937c62022-12-07 11:42:03 +00002 * Copyright (C) 2022 The Android Open Source Project
Sungtak Lee8fc3ca42022-12-07 07:45:45 +00003 *
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 Lee76937c62022-12-07 11:42:03 +000017#pragma once
Sungtak Lee8fc3ca42022-12-07 07:45:45 +000018
19#include <memory>
Sungtak Lee76937c62022-12-07 11:42:03 +000020#include <aidl/android/hardware/media/bufferpool2/IAccessor.h>
21#include <aidl/android/hardware/media/bufferpool2/IObserver.h>
22#include <bufferpool2/BufferPoolTypes.h>
Sungtak Lee8fc3ca42022-12-07 07:45:45 +000023
Sungtak Lee76937c62022-12-07 11:42:03 +000024namespace aidl::android::hardware::media::bufferpool2::implementation {
Sungtak Lee8fc3ca42022-12-07 07:45:45 +000025
Sungtak Lee76937c62022-12-07 11:42:03 +000026using aidl::android::hardware::media::bufferpool2::IAccessor;
27using aidl::android::hardware::media::bufferpool2::IObserver;
28
29struct Accessor;
Sungtak Lee8fc3ca42022-12-07 07:45:45 +000030
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 */
36class BufferPoolClient {
37public:
38 /**
39 * Creates a buffer pool client from a local buffer pool
40 * (via ClientManager#create).
41 */
Sungtak Lee76937c62022-12-07 11:42:03 +000042 explicit BufferPoolClient(const std::shared_ptr<Accessor> &accessor,
43 const std::shared_ptr<IObserver> &observer);
Sungtak Lee8fc3ca42022-12-07 07:45:45 +000044
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 Lee76937c62022-12-07 11:42:03 +000051 explicit BufferPoolClient(const std::shared_ptr<IAccessor> &accessor,
52 const std::shared_ptr<IObserver> &observer);
Sungtak Lee8fc3ca42022-12-07 07:45:45 +000053
54 /** Destructs a buffer pool client. */
55 ~BufferPoolClient();
56
57private:
58 bool isValid();
59
60 bool isLocal();
61
Sungtak Lee76937c62022-12-07 11:42:03 +000062 bool isActive(int64_t *lastTransactionMs, bool clearCache);
Sungtak Lee8fc3ca42022-12-07 07:45:45 +000063
64 ConnectionId getConnectionId();
65
Sungtak Lee76937c62022-12-07 11:42:03 +000066 BufferPoolStatus getAccessor(std::shared_ptr<IAccessor> *accessor);
Sungtak Lee8fc3ca42022-12-07 07:45:45 +000067
68 void receiveInvalidation(uint32_t msgId);
69
Sungtak Lee76937c62022-12-07 11:42:03 +000070 BufferPoolStatus flush();
Sungtak Lee8fc3ca42022-12-07 07:45:45 +000071
Sungtak Lee76937c62022-12-07 11:42:03 +000072 BufferPoolStatus allocate(const std::vector<uint8_t> &params,
Sungtak Lee8fc3ca42022-12-07 07:45:45 +000073 native_handle_t **handle,
74 std::shared_ptr<BufferPoolData> *buffer);
75
Sungtak Lee76937c62022-12-07 11:42:03 +000076 BufferPoolStatus receive(TransactionId transactionId,
Sungtak Lee8fc3ca42022-12-07 07:45:45 +000077 BufferId bufferId,
Sungtak Lee76937c62022-12-07 11:42:03 +000078 int64_t timestampMs,
Sungtak Lee8fc3ca42022-12-07 07:45:45 +000079 native_handle_t **handle,
80 std::shared_ptr<BufferPoolData> *buffer);
81
Sungtak Lee76937c62022-12-07 11:42:03 +000082 BufferPoolStatus postSend(ConnectionId receiver,
Sungtak Lee8fc3ca42022-12-07 07:45:45 +000083 const std::shared_ptr<BufferPoolData> &buffer,
84 TransactionId *transactionId,
Sungtak Lee76937c62022-12-07 11:42:03 +000085 int64_t *timestampMs);
Sungtak Lee8fc3ca42022-12-07 07:45:45 +000086
87 class Impl;
88 std::shared_ptr<Impl> mImpl;
89
90 friend struct ClientManager;
91 friend struct Observer;
92};
93
Sungtak Lee76937c62022-12-07 11:42:03 +000094} // namespace aidl::android::hardware::bufferpool2::implementation