• 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 HARDWARE_GOOGLE_MEDIA_C2_V1_0_UTILS_INPUTSURFACE_H
18 #define HARDWARE_GOOGLE_MEDIA_C2_V1_0_UTILS_INPUTSURFACE_H
19 
20 #include <codec2/hidl/1.0/ComponentStore.h>
21 
22 #include <hardware/google/media/c2/1.0/IInputSurface.h>
23 #include <hardware/google/media/c2/1.0/IComponent.h>
24 
25 #include <android/hardware/graphics/bufferqueue/1.0/IGraphicBufferProducer.h>
26 #include <android/hardware/graphics/bufferqueue/1.0/IProducerListener.h>
27 #include <android/hardware/graphics/common/1.0/types.h>
28 #include <android/hardware/media/1.0/types.h>
29 
30 #include <gui/IGraphicBufferProducer.h>
31 #include <media/stagefright/bqhelper/GraphicBufferSource.h>
32 
33 #include <hidl/HidlSupport.h>
34 #include <hidl/Status.h>
35 
36 class C2ReflectorHelper;
37 
38 namespace hardware {
39 namespace google {
40 namespace media {
41 namespace c2 {
42 namespace V1_0 {
43 namespace utils {
44 
45 using ::android::hardware::hidl_handle;
46 using ::android::hardware::hidl_string;
47 using ::android::hardware::hidl_vec;
48 using ::android::hardware::Return;
49 using ::android::hardware::Void;
50 using ::android::sp;
51 
52 using ::android::hardware::graphics::common::V1_0::PixelFormat;
53 using ::android::hardware::media::V1_0::AnwBuffer;
54 
55 struct InputSurface : public IInputSurface {
56 
57     typedef ::android::hidl::base::V1_0::IBase IBase;
58 
59     typedef ::android::hardware::graphics::bufferqueue::V1_0::
60             IProducerListener HProducerListener;
61 
62     typedef ::android::
63             IGraphicBufferProducer BGraphicBufferProducer;
64 
65     typedef ::android::hardware::graphics::bufferqueue::V1_0::
66             IGraphicBufferProducer HGraphicBufferProducer;
67 
68     typedef ::android::
69             GraphicBufferSource GraphicBufferSource;
70 
71 // Type disambiguation
72 
73     typedef ::hardware::google::media::c2::V1_0::Status Status;
74 
75 // New methods from IInputSurface
76 
77     virtual Return<void> connectToComponent(
78             const sp<IComponent>& component,
79             connectToComponent_cb _hidl_cb) override;
80 
81     virtual Return<sp<IConfigurable>> getConfigurable() override;
82 
83 // Methods derived from IGraphicBufferProducer
84 
85     virtual Return<void> requestBuffer(
86             int32_t slot,
87             requestBuffer_cb _hidl_cb) override;
88 
89     virtual Return<int32_t> setMaxDequeuedBufferCount(
90             int32_t maxDequeuedBuffers) override;
91 
92     virtual Return<int32_t> setAsyncMode(
93             bool async) override;
94 
95     virtual Return<void> dequeueBuffer(
96             uint32_t width,
97             uint32_t height,
98             PixelFormat format,
99             uint32_t usage,
100             bool getFrameTimestamps,
101             dequeueBuffer_cb _hidl_cb) override;
102 
103     virtual Return<int32_t> detachBuffer(
104             int32_t slot) override;
105 
106     virtual Return<void> detachNextBuffer(
107             detachNextBuffer_cb _hidl_cb) override;
108 
109     virtual Return<void> attachBuffer(
110             const AnwBuffer& buffer,
111             attachBuffer_cb _hidl_cb) override;
112 
113     virtual Return<void> queueBuffer(
114             int32_t slot,
115             const QueueBufferInput& input,
116             queueBuffer_cb _hidl_cb) override;
117 
118     virtual Return<int32_t> cancelBuffer(
119             int32_t slot,
120             const hidl_handle& fence) override;
121 
122     virtual Return<void> query(
123             int32_t what,
124             query_cb _hidl_cb) override;
125 
126     virtual Return<void> connect(
127             const sp<HProducerListener>& listener,
128             int32_t api,
129             bool producerControlledByApp,
130             connect_cb _hidl_cb) override;
131 
132     virtual Return<int32_t> disconnect(
133             int32_t api,
134             DisconnectMode mode) override;
135 
136     virtual Return<int32_t> setSidebandStream(
137             const hidl_handle& stream) override;
138 
139     virtual Return<void> allocateBuffers(
140             uint32_t width,
141             uint32_t height,
142             PixelFormat format,
143             uint32_t usage) override;
144 
145     virtual Return<int32_t> allowAllocation(
146             bool allow) override;
147 
148     virtual Return<int32_t> setGenerationNumber(
149             uint32_t generationNumber) override;
150 
151     virtual Return<void> getConsumerName(
152             getConsumerName_cb _hidl_cb) override;
153 
154     virtual Return<int32_t> setSharedBufferMode(
155             bool sharedBufferMode) override;
156 
157     virtual Return<int32_t> setAutoRefresh(
158             bool autoRefresh) override;
159 
160     virtual Return<int32_t> setDequeueTimeout(
161             int64_t timeoutNs) override;
162 
163     virtual Return<void> getLastQueuedBuffer(
164             getLastQueuedBuffer_cb _hidl_cb) override;
165 
166     virtual Return<void> getFrameTimestamps(
167             getFrameTimestamps_cb _hidl_cb) override;
168 
169     virtual Return<void> getUniqueId(
170             getUniqueId_cb _hidl_cb) override;
171 
172     class ConfigurableImpl;
173 
174 protected:
175     sp<ComponentStore> mStore;
176     sp<HGraphicBufferProducer> mBase;
177     sp<GraphicBufferSource> mSource;
178     std::shared_ptr<ConfigurableImpl> mHelper;
179     sp<CachedConfigurable> mConfigurable;
180 
181     InputSurface(
182             const sp<ComponentStore>& store,
183             const std::shared_ptr<C2ReflectorHelper>& reflector,
184             const sp<HGraphicBufferProducer>& base,
185             const sp<GraphicBufferSource>& source);
186 
187     virtual ~InputSurface() override = default;
188 
189     friend struct ComponentStore;
190 };
191 
192 
193 }  // namespace utils
194 }  // namespace V1_0
195 }  // namespace c2
196 }  // namespace media
197 }  // namespace google
198 }  // namespace hardware
199 
200 #endif  // HARDWARE_GOOGLE_MEDIA_C2_V1_0_UTILS_INPUTSURFACE_H
201