1/*
2 * Copyright 2016, 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 <gui/bufferqueue/1.0/H2BGraphicBufferProducer.h>
18#include <media/omx/1.0/WOmx.h>
19#include <media/omx/1.0/WOmxNode.h>
20#include <media/omx/1.0/WOmxObserver.h>
21#include <media/omx/1.0/WGraphicBufferSource.h>
22#include <media/omx/1.0/Conversion.h>
23
24namespace android {
25namespace hardware {
26namespace media {
27namespace omx {
28namespace V1_0 {
29namespace utils {
30
31using ::android::hardware::graphics::bufferqueue::V1_0::utils::
32        H2BGraphicBufferProducer;
33typedef ::android::hardware::graphics::bufferqueue::V1_0::IGraphicBufferProducer
34        HGraphicBufferProducer;
35
36// LWOmx
37LWOmx::LWOmx(sp<IOmx> const& base) : mBase(base) {
38}
39
40status_t LWOmx::listNodes(List<IOMX::ComponentInfo>* list) {
41    status_t fnStatus;
42    status_t transStatus = toStatusT(mBase->listNodes(
43            [&fnStatus, list](
44                    Status status,
45                    hidl_vec<IOmx::ComponentInfo> const& nodeList) {
46                fnStatus = toStatusT(status);
47                list->clear();
48                for (size_t i = 0; i < nodeList.size(); ++i) {
49                    auto newInfo = list->insert(
50                            list->end(), IOMX::ComponentInfo());
51                    convertTo(&*newInfo, nodeList[i]);
52                }
53            }));
54    return transStatus == NO_ERROR ? fnStatus : transStatus;
55}
56
57status_t LWOmx::allocateNode(
58        char const* name,
59        sp<IOMXObserver> const& observer,
60        sp<IOMXNode>* omxNode) {
61    status_t fnStatus;
62    status_t transStatus = toStatusT(mBase->allocateNode(
63            name, new TWOmxObserver(observer),
64            [&fnStatus, omxNode](Status status, sp<IOmxNode> const& node) {
65                fnStatus = toStatusT(status);
66                *omxNode = new LWOmxNode(node);
67            }));
68    return transStatus == NO_ERROR ? fnStatus : transStatus;
69}
70
71status_t LWOmx::createInputSurface(
72        sp<::android::IGraphicBufferProducer>* bufferProducer,
73        sp<::android::IGraphicBufferSource>* bufferSource) {
74    status_t fnStatus;
75    status_t transStatus = toStatusT(mBase->createInputSurface(
76            [&fnStatus, bufferProducer, bufferSource] (
77                    Status status,
78                    sp<HGraphicBufferProducer> const& tProducer,
79                    sp<IGraphicBufferSource> const& tSource) {
80                fnStatus = toStatusT(status);
81                *bufferProducer = new H2BGraphicBufferProducer(tProducer);
82                *bufferSource = new LWGraphicBufferSource(tSource);
83            }));
84    return transStatus == NO_ERROR ? fnStatus : transStatus;
85}
86
87}  // namespace utils
88}  // namespace V1_0
89}  // namespace omx
90}  // namespace media
91}  // namespace hardware
92}  // namespace android
93