blob: e19cb675c46df23163c41960b33fadfe500302cb [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_CONNECTION_H
18#define ANDROID_HARDWARE_MEDIA_BUFFERPOOL_V1_0_CONNECTION_H
19
20#include <android/hardware/media/bufferpool/1.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 V1_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::V1_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::V1_0::IConnection follow.
44 Return<void> fetch(uint64_t transactionId, uint32_t bufferId, fetch_cb _hidl_cb) override;
45
46 /**
47 * Allocates a buffer using the specified parameters. Recycles a buffer if
48 * it is possible. The returned buffer can be transferred to other remote
49 * clients(Connection).
50 *
51 * @param params allocation parameters.
52 * @param bufferId Id of the allocated buffer.
53 * @param handle native handle of the allocated buffer.
54 *
55 * @return OK if a buffer is successfully allocated.
56 * NO_MEMORY when there is no memory.
57 * CRITICAL_ERROR otherwise.
58 */
59 ResultStatus allocate(const std::vector<uint8_t> &params,
60 BufferId *bufferId, const native_handle_t **handle);
61
62 /**
63 * Processes pending buffer status messages and performs periodic cache cleaning
64 * from bufferpool.
65 *
66 * @param clearCache if clearCache is true, bufferpool frees all buffers
67 * waiting to be recycled.
68 */
69 void cleanUp(bool clearCache);
70
71 /** Destructs a connection. */
72 ~Connection();
73
74 /** Creates a connection. */
75 Connection();
76
77 /**
78 * Initializes with the specified buffer pool and the connection id.
79 * The connection id should be unique in the whole system.
80 *
81 * @param accessor the specified buffer pool.
82 * @param connectionId Id.
83 */
84 void initialize(const sp<Accessor> &accessor, ConnectionId connectionId);
85
86 enum : uint32_t {
87 SYNC_BUFFERID = UINT32_MAX,
88 };
89
90private:
91 bool mInitialized;
92 sp<Accessor> mAccessor;
93 ConnectionId mConnectionId;
94};
95
96} // namespace implementation
97} // namespace V1_0
98} // namespace bufferpool
99} // namespace media
100} // namespace hardware
101} // namespace android
102
103#endif // ANDROID_HARDWARE_MEDIA_BUFFERPOOL_V1_0_CONNECTION_H