blob: 8507749849f33794cadbe45cee7e233202e6b076 [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_CONNECTION_H
18#define ANDROID_HARDWARE_MEDIA_BUFFERPOOL_V2_0_CONNECTION_H
19
20#include <android/hardware/media/bufferpool/2.0/IConnection.h>
21#include <bufferpool/BufferPoolTypes.h>
22#include <hidl/MQDescriptor.h>
23#include <hidl/Status.h>
24#include "Accessor.h"
25
26namespace android {
27namespace hardware {
28namespace media {
29namespace bufferpool {
30namespace V2_0 {
31namespace implementation {
32
33using ::android::hardware::hidl_array;
34using ::android::hardware::hidl_memory;
35using ::android::hardware::hidl_string;
36using ::android::hardware::hidl_vec;
37using ::android::hardware::media::bufferpool::V2_0::implementation::Accessor;
38using ::android::hardware::Return;
39using ::android::hardware::Void;
40using ::android::sp;
41
42struct Connection : public IConnection {
43 // Methods from ::android::hardware::media::bufferpool::V2_0::IConnection follow.
44 Return<void> fetch(uint64_t transactionId, uint32_t bufferId, fetch_cb _hidl_cb) override;
45
46 /**
Sungtak Leec7f9e2c2018-09-14 16:23:40 -070047 * Invalidates all buffers which are active and/or are ready to be recycled.
48 */
49 ResultStatus flush();
50
51 /**
Sungtak Leebbe37b62018-08-29 15:15:48 -070052 * Allocates a buffer using the specified parameters. Recycles a buffer if
53 * it is possible. The returned buffer can be transferred to other remote
54 * clients(Connection).
55 *
56 * @param params allocation parameters.
57 * @param bufferId Id of the allocated buffer.
58 * @param handle native handle of the allocated buffer.
59 *
60 * @return OK if a buffer is successfully allocated.
61 * NO_MEMORY when there is no memory.
62 * CRITICAL_ERROR otherwise.
63 */
64 ResultStatus allocate(const std::vector<uint8_t> &params,
65 BufferId *bufferId, const native_handle_t **handle);
66
67 /**
68 * Processes pending buffer status messages and performs periodic cache cleaning
69 * from bufferpool.
70 *
71 * @param clearCache if clearCache is true, bufferpool frees all buffers
72 * waiting to be recycled.
73 */
74 void cleanUp(bool clearCache);
75
76 /** Destructs a connection. */
77 ~Connection();
78
79 /** Creates a connection. */
80 Connection();
81
82 /**
83 * Initializes with the specified buffer pool and the connection id.
84 * The connection id should be unique in the whole system.
85 *
86 * @param accessor the specified buffer pool.
87 * @param connectionId Id.
88 */
89 void initialize(const sp<Accessor> &accessor, ConnectionId connectionId);
90
91 enum : uint32_t {
92 SYNC_BUFFERID = UINT32_MAX,
93 };
94
95private:
96 bool mInitialized;
97 sp<Accessor> mAccessor;
98 ConnectionId mConnectionId;
99};
100
101} // namespace implementation
102} // namespace V2_0
103} // namespace bufferpool
104} // namespace media
105} // namespace hardware
106} // namespace android
107
108#endif // ANDROID_HARDWARE_MEDIA_BUFFERPOOL_V2_0_CONNECTION_H