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