blob: 1889ea3ce1fca9efde5e27d9b2e9c2b62f664958 [file] [log] [blame]
Sungtak Leebbe37b62018-08-29 15:15:48 -07001/*
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>
Sungtak Leed491f1f2018-10-05 15:56:56 -070023#include <android/hardware/media/bufferpool/2.0/IObserver.h>
Sungtak Leebbe37b62018-08-29 15:15:48 -070024#include <bufferpool/BufferPoolTypes.h>
25#include <cutils/native_handle.h>
26#include "Accessor.h"
27
28namespace android {
29namespace hardware {
30namespace media {
31namespace bufferpool {
32namespace V2_0 {
33namespace implementation {
34
35using ::android::hardware::media::bufferpool::V2_0::IAccessor;
36using ::android::hardware::media::bufferpool::V2_0::IConnection;
Sungtak Leed491f1f2018-10-05 15:56:56 -070037using ::android::hardware::media::bufferpool::V2_0::IObserver;
Sungtak Leebbe37b62018-08-29 15:15:48 -070038using ::android::hardware::media::bufferpool::V2_0::ResultStatus;
39using ::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 */
46class BufferPoolClient {
47public:
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
54 /**
55 * Creates a buffer pool client from a remote buffer pool
56 * (via ClientManager#registerSender).
57 * Note: A buffer pool client created with remote buffer pool cannot
58 * allocate a buffer.
59 */
60 explicit BufferPoolClient(const sp<IAccessor> &accessor);
61
62 /** Destructs a buffer pool client. */
63 ~BufferPoolClient();
64
65private:
66 bool isValid();
67
68 bool isLocal();
69
70 bool isActive(int64_t *lastTransactionUs, bool clearCache);
71
72 ConnectionId getConnectionId();
73
74 ResultStatus getAccessor(sp<IAccessor> *accessor);
75
76 ResultStatus allocate(const std::vector<uint8_t> &params,
77 native_handle_t **handle,
78 std::shared_ptr<BufferPoolData> *buffer);
79
80 ResultStatus receive(TransactionId transactionId,
81 BufferId bufferId,
82 int64_t timestampUs,
83 native_handle_t **handle,
84 std::shared_ptr<BufferPoolData> *buffer);
85
86 ResultStatus postSend(ConnectionId receiver,
87 const std::shared_ptr<BufferPoolData> &buffer,
88 TransactionId *transactionId,
89 int64_t *timestampUs);
90
91 class Impl;
92 std::shared_ptr<Impl> mImpl;
93
94 friend struct ClientManager;
95};
96
97} // namespace implementation
98} // namespace V2_0
99} // namespace bufferpool
100} // namespace media
101} // namespace hardware
102} // namespace android
103
104#endif // ANDROID_HARDWARE_MEDIA_BUFFERPOOL_V2_0_BUFFERPOOLCLIENT_H