1 /*
2 * Copyright (C) 2024 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 <inttypes.h>
18
19 #define LOG_TAG "AidlGraphicBufferSource"
20 //#define LOG_NDEBUG 0
21 #include <utils/Log.h>
22
23 #include <media/stagefright/bqhelper/ComponentWrapper.h>
24 #include <media/stagefright/bqhelper/GraphicBufferSource.h>
25 #include <media/stagefright/aidlpersistentsurface/AidlGraphicBufferSource.h>
26 #include <media/stagefright/aidlpersistentsurface/C2NodeDef.h>
27
28 namespace android::media {
29
30 namespace {
31
32 class AidlComponentWrapper : public ComponentWrapper {
33 public:
AidlComponentWrapper(const sp<IAidlNodeWrapper> & node)34 explicit AidlComponentWrapper(const sp<IAidlNodeWrapper> &node)
35 : mAidlNode(node) {}
36 virtual ~AidlComponentWrapper() = default;
37
submitBuffer(int32_t bufferId,const sp<GraphicBuffer> & buffer,int64_t timestamp,int fenceFd)38 status_t submitBuffer(
39 int32_t bufferId, const sp<GraphicBuffer> &buffer,
40 int64_t timestamp, int fenceFd) override {
41 return mAidlNode->submitBuffer(
42 bufferId, BUFFERFLAG_ENDOFFRAME, buffer, timestamp, fenceFd);
43 }
44
submitEos(int32_t bufferId)45 status_t submitEos(int32_t bufferId) override {
46 return mAidlNode->submitBuffer(
47 bufferId, BUFFERFLAG_ENDOFFRAME | BUFFERFLAG_EOS);
48 }
49
dispatchDataSpaceChanged(int32_t dataSpace,int32_t aspects,int32_t pixelFormat)50 void dispatchDataSpaceChanged(
51 int32_t dataSpace, int32_t aspects, int32_t pixelFormat) override {
52 mAidlNode->dispatchDataSpaceChanged(dataSpace, aspects, pixelFormat);
53 }
54
55 private:
56 sp<IAidlNodeWrapper> mAidlNode;
57
58 DISALLOW_EVIL_CONSTRUCTORS(AidlComponentWrapper);
59 };
60
61 } // namespace
62
onStart()63 ::ndk::ScopedAStatus AidlGraphicBufferSource::onStart() {
64 status_t err = start();
65 return (OK == err) ? ::ndk::ScopedAStatus::ok() :
66 ::ndk::ScopedAStatus::fromServiceSpecificError(err);
67 }
68
onStop()69 ::ndk::ScopedAStatus AidlGraphicBufferSource::onStop() {
70 status_t err = stop();
71 return (OK == err) ? ::ndk::ScopedAStatus::ok() :
72 ::ndk::ScopedAStatus::fromServiceSpecificError(err);
73 }
74
onRelease()75 ::ndk::ScopedAStatus AidlGraphicBufferSource::onRelease(){
76 status_t err = release();
77 return (OK == err) ? ::ndk::ScopedAStatus::ok() :
78 ::ndk::ScopedAStatus::fromServiceSpecificError(err);
79 }
80
configure(const sp<IAidlNodeWrapper> & aidlNode,int32_t dataSpace,int32_t bufferCount,uint32_t frameWidth,uint32_t frameHeight,uint64_t consumerUsage)81 status_t AidlGraphicBufferSource::configure(
82 const sp<IAidlNodeWrapper>& aidlNode,
83 int32_t dataSpace,
84 int32_t bufferCount,
85 uint32_t frameWidth,
86 uint32_t frameHeight,
87 uint64_t consumerUsage) {
88 if (aidlNode == NULL) {
89 return BAD_VALUE;
90 }
91
92 return GraphicBufferSource::configure(
93 new AidlComponentWrapper(aidlNode), dataSpace, bufferCount,
94 frameWidth, frameHeight, consumerUsage);
95 }
96
97 } // namespace android::media
98