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