blob: e8d9ae67035e3319a858d41a414371ece6891232 [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 */
Sungtak Leec7f9e2c2018-09-14 16:23:40 -070052 explicit BufferPoolClient(const sp<Accessor> &accessor,
53 const sp<IObserver> &observer);
Sungtak Leebbe37b62018-08-29 15:15:48 -070054
55 /**
56 * Creates a buffer pool client from a remote buffer pool
57 * (via ClientManager#registerSender).
58 * Note: A buffer pool client created with remote buffer pool cannot
59 * allocate a buffer.
60 */
Sungtak Leec7f9e2c2018-09-14 16:23:40 -070061 explicit BufferPoolClient(const sp<IAccessor> &accessor,
62 const sp<IObserver> &observer);
Sungtak Leebbe37b62018-08-29 15:15:48 -070063
64 /** Destructs a buffer pool client. */
65 ~BufferPoolClient();
66
67private:
68 bool isValid();
69
70 bool isLocal();
71
72 bool isActive(int64_t *lastTransactionUs, bool clearCache);
73
74 ConnectionId getConnectionId();
75
76 ResultStatus getAccessor(sp<IAccessor> *accessor);
77
Sungtak Leec7f9e2c2018-09-14 16:23:40 -070078 void receiveInvalidation(uint32_t msgId);
79
80 ResultStatus flush();
81
Sungtak Leebbe37b62018-08-29 15:15:48 -070082 ResultStatus allocate(const std::vector<uint8_t> &params,
83 native_handle_t **handle,
84 std::shared_ptr<BufferPoolData> *buffer);
85
86 ResultStatus receive(TransactionId transactionId,
87 BufferId bufferId,
88 int64_t timestampUs,
89 native_handle_t **handle,
90 std::shared_ptr<BufferPoolData> *buffer);
91
92 ResultStatus postSend(ConnectionId receiver,
93 const std::shared_ptr<BufferPoolData> &buffer,
94 TransactionId *transactionId,
95 int64_t *timestampUs);
96
97 class Impl;
98 std::shared_ptr<Impl> mImpl;
99
100 friend struct ClientManager;
Sungtak Leec7f9e2c2018-09-14 16:23:40 -0700101 friend struct Observer;
Sungtak Leebbe37b62018-08-29 15:15:48 -0700102};
103
104} // namespace implementation
105} // namespace V2_0
106} // namespace bufferpool
107} // namespace media
108} // namespace hardware
109} // namespace android
110
111#endif // ANDROID_HARDWARE_MEDIA_BUFFERPOOL_V2_0_BUFFERPOOLCLIENT_H