• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
26 namespace android {
27 namespace hardware {
28 namespace media {
29 namespace bufferpool {
30 namespace V1_0 {
31 namespace implementation {
32 
33 using ::android::hardware::hidl_array;
34 using ::android::hardware::hidl_memory;
35 using ::android::hardware::hidl_string;
36 using ::android::hardware::hidl_vec;
37 using ::android::hardware::media::bufferpool::V1_0::implementation::Accessor;
38 using ::android::hardware::Return;
39 using ::android::hardware::Void;
40 using ::android::sp;
41 
42 struct 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 
90 private:
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
104