blob: 57d0c7eb63ad2db0bc42ca367912a9dde52daa29 [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#include "Connection.h"
18
19namespace android {
20namespace hardware {
21namespace media {
22namespace bufferpool {
23namespace V2_0 {
24namespace implementation {
25
26// Methods from ::android::hardware::media::bufferpool::V2_0::IConnection follow.
27Return<void> Connection::fetch(uint64_t transactionId, uint32_t bufferId, fetch_cb _hidl_cb) {
28 ResultStatus status = ResultStatus::CRITICAL_ERROR;
29 if (mInitialized && mAccessor) {
30 if (bufferId != SYNC_BUFFERID) {
31 const native_handle_t *handle = nullptr;
32 status = mAccessor->fetch(
33 mConnectionId, transactionId, bufferId, &handle);
34 if (status == ResultStatus::OK) {
Steven Morelandff224622019-04-24 16:58:40 -070035 Buffer buffer = {};
36 buffer.id = bufferId;
37 buffer.buffer = handle;
38 _hidl_cb(status, buffer);
Sungtak Leebbe37b62018-08-29 15:15:48 -070039 return Void();
40 }
41 } else {
42 mAccessor->cleanUp(false);
43 }
44 }
Steven Morelandff224622019-04-24 16:58:40 -070045
46 Buffer buffer = {};
47 buffer.id = 0;
48 buffer.buffer = nullptr;
49
50 _hidl_cb(status, buffer);
Sungtak Leebbe37b62018-08-29 15:15:48 -070051 return Void();
52}
53
54Connection::Connection() : mInitialized(false), mConnectionId(-1LL) {}
55
56Connection::~Connection() {
57 if (mInitialized && mAccessor) {
58 mAccessor->close(mConnectionId);
59 }
60}
61
62void Connection::initialize(
63 const sp<Accessor>& accessor, ConnectionId connectionId) {
64 if (!mInitialized) {
65 mAccessor = accessor;
66 mConnectionId = connectionId;
67 mInitialized = true;
68 }
69}
70
Sungtak Leec7f9e2c2018-09-14 16:23:40 -070071ResultStatus Connection::flush() {
72 if (mInitialized && mAccessor) {
73 return mAccessor->flush();
74 }
75 return ResultStatus::CRITICAL_ERROR;
76}
77
Sungtak Leebbe37b62018-08-29 15:15:48 -070078ResultStatus Connection::allocate(
79 const std::vector<uint8_t> &params, BufferId *bufferId,
80 const native_handle_t **handle) {
81 if (mInitialized && mAccessor) {
82 return mAccessor->allocate(mConnectionId, params, bufferId, handle);
83 }
84 return ResultStatus::CRITICAL_ERROR;
85}
86
87void Connection::cleanUp(bool clearCache) {
88 if (mInitialized && mAccessor) {
89 mAccessor->cleanUp(clearCache);
90 }
91}
92
93// Methods from ::android::hidl::base::V1_0::IBase follow.
94
95//IConnection* HIDL_FETCH_IConnection(const char* /* name */) {
96// return new Connection();
97//}
98
99} // namespace implementation
100} // namespace V2_0
101} // namespace bufferpool
102} // namespace media
103} // namespace hardware
104} // namespace android