Pawin Vongmasa | eeac97b | 2017-01-18 05:03:07 -0800 | [diff] [blame] | 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 | |
Pawin Vongmasa | 223b8e3 | 2017-02-22 20:32:25 -0800 | [diff] [blame] | 17 | #define LOG_TAG "WOmxBufferProducer-utils" |
| 18 | |
Pawin Vongmasa | ac7d412 | 2017-03-01 05:48:42 -0800 | [diff] [blame] | 19 | #include <utils/Log.h> |
Pawin Vongmasa | 223b8e3 | 2017-02-22 20:32:25 -0800 | [diff] [blame] | 20 | |
Pawin Vongmasa | ac7d412 | 2017-03-01 05:48:42 -0800 | [diff] [blame] | 21 | #include <media/omx/1.0/WOmxBufferProducer.h> |
| 22 | #include <media/omx/1.0/WOmxProducerListener.h> |
| 23 | #include <media/omx/1.0/Conversion.h> |
Pawin Vongmasa | eeac97b | 2017-01-18 05:03:07 -0800 | [diff] [blame] | 24 | |
| 25 | namespace android { |
| 26 | namespace hardware { |
| 27 | namespace media { |
| 28 | namespace omx { |
| 29 | namespace V1_0 { |
| 30 | namespace utils { |
| 31 | |
| 32 | // TWOmxBufferProducer |
| 33 | TWOmxBufferProducer::TWOmxBufferProducer( |
| 34 | sp<IGraphicBufferProducer> const& base): |
| 35 | mBase(base) { |
| 36 | } |
| 37 | |
| 38 | Return<void> TWOmxBufferProducer::requestBuffer( |
| 39 | int32_t slot, requestBuffer_cb _hidl_cb) { |
| 40 | sp<GraphicBuffer> buf; |
| 41 | status_t status = mBase->requestBuffer(slot, &buf); |
| 42 | AnwBuffer anwBuffer; |
| 43 | wrapAs(&anwBuffer, *buf); |
| 44 | _hidl_cb(toStatus(status), anwBuffer); |
| 45 | return Void(); |
| 46 | } |
| 47 | |
| 48 | Return<Status> TWOmxBufferProducer::setMaxDequeuedBufferCount( |
| 49 | int32_t maxDequeuedBuffers) { |
| 50 | return toStatus(mBase->setMaxDequeuedBufferCount( |
| 51 | static_cast<int>(maxDequeuedBuffers))); |
| 52 | } |
| 53 | |
| 54 | Return<Status> TWOmxBufferProducer::setAsyncMode(bool async) { |
| 55 | return toStatus(mBase->setAsyncMode(async)); |
| 56 | } |
| 57 | |
| 58 | Return<void> TWOmxBufferProducer::dequeueBuffer( |
| 59 | uint32_t width, uint32_t height, |
| 60 | PixelFormat format, uint32_t usage, |
| 61 | bool getFrameTimestamps, dequeueBuffer_cb _hidl_cb) { |
| 62 | int slot; |
| 63 | sp<Fence> fence; |
| 64 | ::android::FrameEventHistoryDelta outTimestamps; |
| 65 | status_t status = mBase->dequeueBuffer( |
| 66 | &slot, &fence, |
| 67 | width, height, |
| 68 | static_cast<::android::PixelFormat>(format), usage, |
| 69 | getFrameTimestamps ? &outTimestamps : nullptr); |
Pawin Vongmasa | eeac97b | 2017-01-18 05:03:07 -0800 | [diff] [blame] | 70 | hidl_handle tFence; |
Pawin Vongmasa | eeac97b | 2017-01-18 05:03:07 -0800 | [diff] [blame] | 71 | FrameEventHistoryDelta tOutTimestamps; |
Pawin Vongmasa | 223b8e3 | 2017-02-22 20:32:25 -0800 | [diff] [blame] | 72 | |
| 73 | native_handle_t* nh = nullptr; |
| 74 | if ((fence == nullptr) || !wrapAs(&tFence, &nh, *fence)) { |
Pawin Vongmasa | ac7d412 | 2017-03-01 05:48:42 -0800 | [diff] [blame] | 75 | ALOGE("TWOmxBufferProducer::dequeueBuffer - Invalid output fence"); |
Pawin Vongmasa | 223b8e3 | 2017-02-22 20:32:25 -0800 | [diff] [blame] | 76 | _hidl_cb(toStatus(status), |
| 77 | static_cast<int32_t>(slot), |
| 78 | tFence, |
| 79 | tOutTimestamps); |
| 80 | return Void(); |
| 81 | } |
Pawin Vongmasa | eeac97b | 2017-01-18 05:03:07 -0800 | [diff] [blame] | 82 | std::vector<std::vector<native_handle_t*> > nhAA; |
| 83 | if (getFrameTimestamps && !wrapAs(&tOutTimestamps, &nhAA, outTimestamps)) { |
Pawin Vongmasa | ac7d412 | 2017-03-01 05:48:42 -0800 | [diff] [blame] | 84 | ALOGE("TWOmxBufferProducer::dequeueBuffer - Invalid output timestamps"); |
Pawin Vongmasa | 223b8e3 | 2017-02-22 20:32:25 -0800 | [diff] [blame] | 85 | _hidl_cb(toStatus(status), |
| 86 | static_cast<int32_t>(slot), |
| 87 | tFence, |
| 88 | tOutTimestamps); |
Pawin Vongmasa | eeac97b | 2017-01-18 05:03:07 -0800 | [diff] [blame] | 89 | native_handle_delete(nh); |
Pawin Vongmasa | 223b8e3 | 2017-02-22 20:32:25 -0800 | [diff] [blame] | 90 | return Void(); |
Pawin Vongmasa | eeac97b | 2017-01-18 05:03:07 -0800 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | _hidl_cb(toStatus(status), |
| 94 | static_cast<int32_t>(slot), |
| 95 | tFence, |
| 96 | tOutTimestamps); |
| 97 | native_handle_delete(nh); |
| 98 | if (getFrameTimestamps) { |
| 99 | for (auto& nhA : nhAA) { |
| 100 | for (auto& handle : nhA) { |
Pawin Vongmasa | 223b8e3 | 2017-02-22 20:32:25 -0800 | [diff] [blame] | 101 | native_handle_delete(handle); |
Pawin Vongmasa | eeac97b | 2017-01-18 05:03:07 -0800 | [diff] [blame] | 102 | } |
| 103 | } |
| 104 | } |
| 105 | return Void(); |
| 106 | } |
| 107 | |
| 108 | Return<Status> TWOmxBufferProducer::detachBuffer(int32_t slot) { |
| 109 | return toStatus(mBase->detachBuffer(slot)); |
| 110 | } |
| 111 | |
| 112 | Return<void> TWOmxBufferProducer::detachNextBuffer( |
| 113 | detachNextBuffer_cb _hidl_cb) { |
| 114 | sp<GraphicBuffer> outBuffer; |
| 115 | sp<Fence> outFence; |
| 116 | status_t status = mBase->detachNextBuffer(&outBuffer, &outFence); |
Pawin Vongmasa | eeac97b | 2017-01-18 05:03:07 -0800 | [diff] [blame] | 117 | AnwBuffer tBuffer; |
Pawin Vongmasa | eeac97b | 2017-01-18 05:03:07 -0800 | [diff] [blame] | 118 | hidl_handle tFence; |
Pawin Vongmasa | 223b8e3 | 2017-02-22 20:32:25 -0800 | [diff] [blame] | 119 | |
| 120 | if (outBuffer == nullptr) { |
Pawin Vongmasa | ac7d412 | 2017-03-01 05:48:42 -0800 | [diff] [blame] | 121 | ALOGE("TWOmxBufferProducer::detachNextBuffer - Invalid output buffer"); |
Pawin Vongmasa | 223b8e3 | 2017-02-22 20:32:25 -0800 | [diff] [blame] | 122 | _hidl_cb(toStatus(status), tBuffer, tFence); |
| 123 | return Void(); |
| 124 | } |
| 125 | wrapAs(&tBuffer, *outBuffer); |
| 126 | native_handle_t* nh = nullptr; |
| 127 | if ((outFence != nullptr) && !wrapAs(&tFence, &nh, *outFence)) { |
Pawin Vongmasa | ac7d412 | 2017-03-01 05:48:42 -0800 | [diff] [blame] | 128 | ALOGE("TWOmxBufferProducer::detachNextBuffer - Invalid output fence"); |
Pawin Vongmasa | 223b8e3 | 2017-02-22 20:32:25 -0800 | [diff] [blame] | 129 | _hidl_cb(toStatus(status), tBuffer, tFence); |
| 130 | return Void(); |
Pawin Vongmasa | eeac97b | 2017-01-18 05:03:07 -0800 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | _hidl_cb(toStatus(status), tBuffer, tFence); |
| 134 | native_handle_delete(nh); |
| 135 | return Void(); |
| 136 | } |
| 137 | |
| 138 | Return<void> TWOmxBufferProducer::attachBuffer( |
| 139 | const AnwBuffer& buffer, |
| 140 | attachBuffer_cb _hidl_cb) { |
| 141 | int outSlot; |
| 142 | sp<GraphicBuffer> lBuffer = new GraphicBuffer(); |
| 143 | if (!convertTo(lBuffer.get(), buffer)) { |
Pawin Vongmasa | ac7d412 | 2017-03-01 05:48:42 -0800 | [diff] [blame] | 144 | ALOGE("TWOmxBufferProducer::attachBuffer - " |
| 145 | "Invalid input native window buffer"); |
Pawin Vongmasa | 223b8e3 | 2017-02-22 20:32:25 -0800 | [diff] [blame] | 146 | _hidl_cb(toStatus(BAD_VALUE), -1); |
| 147 | return Void(); |
Pawin Vongmasa | eeac97b | 2017-01-18 05:03:07 -0800 | [diff] [blame] | 148 | } |
| 149 | status_t status = mBase->attachBuffer(&outSlot, lBuffer); |
| 150 | |
| 151 | _hidl_cb(toStatus(status), static_cast<int32_t>(outSlot)); |
| 152 | return Void(); |
| 153 | } |
| 154 | |
| 155 | Return<void> TWOmxBufferProducer::queueBuffer( |
| 156 | int32_t slot, const QueueBufferInput& input, |
| 157 | queueBuffer_cb _hidl_cb) { |
Pawin Vongmasa | 223b8e3 | 2017-02-22 20:32:25 -0800 | [diff] [blame] | 158 | QueueBufferOutput tOutput; |
Pawin Vongmasa | eeac97b | 2017-01-18 05:03:07 -0800 | [diff] [blame] | 159 | IGraphicBufferProducer::QueueBufferInput lInput( |
| 160 | 0, false, HAL_DATASPACE_UNKNOWN, |
| 161 | ::android::Rect(0, 0, 1, 1), |
| 162 | NATIVE_WINDOW_SCALING_MODE_FREEZE, |
| 163 | 0, ::android::Fence::NO_FENCE); |
| 164 | if (!convertTo(&lInput, input)) { |
Pawin Vongmasa | ac7d412 | 2017-03-01 05:48:42 -0800 | [diff] [blame] | 165 | ALOGE("TWOmxBufferProducer::queueBuffer - Invalid input"); |
Pawin Vongmasa | 223b8e3 | 2017-02-22 20:32:25 -0800 | [diff] [blame] | 166 | _hidl_cb(toStatus(BAD_VALUE), tOutput); |
| 167 | return Void(); |
Pawin Vongmasa | eeac97b | 2017-01-18 05:03:07 -0800 | [diff] [blame] | 168 | } |
| 169 | IGraphicBufferProducer::QueueBufferOutput lOutput; |
| 170 | status_t status = mBase->queueBuffer( |
| 171 | static_cast<int>(slot), lInput, &lOutput); |
| 172 | |
Pawin Vongmasa | eeac97b | 2017-01-18 05:03:07 -0800 | [diff] [blame] | 173 | std::vector<std::vector<native_handle_t*> > nhAA; |
| 174 | if (!wrapAs(&tOutput, &nhAA, lOutput)) { |
Pawin Vongmasa | ac7d412 | 2017-03-01 05:48:42 -0800 | [diff] [blame] | 175 | ALOGE("TWOmxBufferProducer::queueBuffer - Invalid output"); |
Pawin Vongmasa | 223b8e3 | 2017-02-22 20:32:25 -0800 | [diff] [blame] | 176 | _hidl_cb(toStatus(BAD_VALUE), tOutput); |
| 177 | return Void(); |
Pawin Vongmasa | eeac97b | 2017-01-18 05:03:07 -0800 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | _hidl_cb(toStatus(status), tOutput); |
| 181 | for (auto& nhA : nhAA) { |
| 182 | for (auto& nh : nhA) { |
Pawin Vongmasa | 223b8e3 | 2017-02-22 20:32:25 -0800 | [diff] [blame] | 183 | native_handle_delete(nh); |
Pawin Vongmasa | eeac97b | 2017-01-18 05:03:07 -0800 | [diff] [blame] | 184 | } |
| 185 | } |
| 186 | return Void(); |
| 187 | } |
| 188 | |
| 189 | Return<Status> TWOmxBufferProducer::cancelBuffer( |
| 190 | int32_t slot, const hidl_handle& fence) { |
| 191 | sp<Fence> lFence = new Fence(); |
| 192 | if (!convertTo(lFence.get(), fence)) { |
Pawin Vongmasa | ac7d412 | 2017-03-01 05:48:42 -0800 | [diff] [blame] | 193 | ALOGE("TWOmxBufferProducer::cancelBuffer - Invalid input fence"); |
Pawin Vongmasa | 223b8e3 | 2017-02-22 20:32:25 -0800 | [diff] [blame] | 194 | return toStatus(BAD_VALUE); |
Pawin Vongmasa | eeac97b | 2017-01-18 05:03:07 -0800 | [diff] [blame] | 195 | } |
| 196 | return toStatus(mBase->cancelBuffer(static_cast<int>(slot), lFence)); |
| 197 | } |
| 198 | |
| 199 | Return<void> TWOmxBufferProducer::query(int32_t what, query_cb _hidl_cb) { |
| 200 | int lValue; |
| 201 | int lReturn = mBase->query(static_cast<int>(what), &lValue); |
| 202 | _hidl_cb(static_cast<int32_t>(lReturn), static_cast<int32_t>(lValue)); |
| 203 | return Void(); |
| 204 | } |
| 205 | |
| 206 | Return<void> TWOmxBufferProducer::connect( |
| 207 | const sp<IOmxProducerListener>& listener, |
| 208 | int32_t api, bool producerControlledByApp, connect_cb _hidl_cb) { |
Pawin Vongmasa | 8ff4018 | 2017-02-07 02:22:34 -0800 | [diff] [blame] | 209 | sp<IProducerListener> lListener = listener == nullptr ? |
| 210 | nullptr : new LWOmxProducerListener(listener); |
Pawin Vongmasa | eeac97b | 2017-01-18 05:03:07 -0800 | [diff] [blame] | 211 | IGraphicBufferProducer::QueueBufferOutput lOutput; |
| 212 | status_t status = mBase->connect(lListener, |
| 213 | static_cast<int>(api), |
| 214 | producerControlledByApp, |
| 215 | &lOutput); |
| 216 | |
| 217 | QueueBufferOutput tOutput; |
| 218 | std::vector<std::vector<native_handle_t*> > nhAA; |
| 219 | if (!wrapAs(&tOutput, &nhAA, lOutput)) { |
Pawin Vongmasa | ac7d412 | 2017-03-01 05:48:42 -0800 | [diff] [blame] | 220 | ALOGE("TWOmxBufferProducer::connect - Invalid output"); |
Pawin Vongmasa | 223b8e3 | 2017-02-22 20:32:25 -0800 | [diff] [blame] | 221 | _hidl_cb(toStatus(status), tOutput); |
| 222 | return Void(); |
Pawin Vongmasa | eeac97b | 2017-01-18 05:03:07 -0800 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | _hidl_cb(toStatus(status), tOutput); |
| 226 | for (auto& nhA : nhAA) { |
| 227 | for (auto& nh : nhA) { |
Pawin Vongmasa | 223b8e3 | 2017-02-22 20:32:25 -0800 | [diff] [blame] | 228 | native_handle_delete(nh); |
Pawin Vongmasa | eeac97b | 2017-01-18 05:03:07 -0800 | [diff] [blame] | 229 | } |
| 230 | } |
| 231 | return Void(); |
| 232 | } |
| 233 | |
| 234 | Return<Status> TWOmxBufferProducer::disconnect( |
| 235 | int32_t api, DisconnectMode mode) { |
| 236 | return toStatus(mBase->disconnect( |
| 237 | static_cast<int>(api), |
| 238 | toGuiDisconnectMode(mode))); |
| 239 | } |
| 240 | |
| 241 | Return<Status> TWOmxBufferProducer::setSidebandStream(const hidl_handle& stream) { |
| 242 | return toStatus(mBase->setSidebandStream(NativeHandle::create( |
| 243 | native_handle_clone(stream), true))); |
| 244 | } |
| 245 | |
| 246 | Return<void> TWOmxBufferProducer::allocateBuffers( |
| 247 | uint32_t width, uint32_t height, PixelFormat format, uint32_t usage) { |
| 248 | mBase->allocateBuffers( |
| 249 | width, height, |
| 250 | static_cast<::android::PixelFormat>(format), |
| 251 | usage); |
| 252 | return Void(); |
| 253 | } |
| 254 | |
| 255 | Return<Status> TWOmxBufferProducer::allowAllocation(bool allow) { |
| 256 | return toStatus(mBase->allowAllocation(allow)); |
| 257 | } |
| 258 | |
| 259 | Return<Status> TWOmxBufferProducer::setGenerationNumber(uint32_t generationNumber) { |
| 260 | return toStatus(mBase->setGenerationNumber(generationNumber)); |
| 261 | } |
| 262 | |
| 263 | Return<void> TWOmxBufferProducer::getConsumerName(getConsumerName_cb _hidl_cb) { |
| 264 | _hidl_cb(mBase->getConsumerName().string()); |
| 265 | return Void(); |
| 266 | } |
| 267 | |
| 268 | Return<Status> TWOmxBufferProducer::setSharedBufferMode(bool sharedBufferMode) { |
| 269 | return toStatus(mBase->setSharedBufferMode(sharedBufferMode)); |
| 270 | } |
| 271 | |
| 272 | Return<Status> TWOmxBufferProducer::setAutoRefresh(bool autoRefresh) { |
| 273 | return toStatus(mBase->setAutoRefresh(autoRefresh)); |
| 274 | } |
| 275 | |
| 276 | Return<Status> TWOmxBufferProducer::setDequeueTimeout(int64_t timeoutNs) { |
| 277 | return toStatus(mBase->setDequeueTimeout(timeoutNs)); |
| 278 | } |
| 279 | |
| 280 | Return<void> TWOmxBufferProducer::getLastQueuedBuffer( |
| 281 | getLastQueuedBuffer_cb _hidl_cb) { |
| 282 | sp<GraphicBuffer> lOutBuffer = new GraphicBuffer(); |
| 283 | sp<Fence> lOutFence = new Fence(); |
| 284 | float lOutTransformMatrix[16]; |
| 285 | status_t status = mBase->getLastQueuedBuffer( |
| 286 | &lOutBuffer, &lOutFence, lOutTransformMatrix); |
| 287 | |
| 288 | AnwBuffer tOutBuffer; |
Pawin Vongmasa | 223b8e3 | 2017-02-22 20:32:25 -0800 | [diff] [blame] | 289 | if (lOutBuffer != nullptr) { |
| 290 | wrapAs(&tOutBuffer, *lOutBuffer); |
| 291 | } |
Pawin Vongmasa | eeac97b | 2017-01-18 05:03:07 -0800 | [diff] [blame] | 292 | hidl_handle tOutFence; |
Pawin Vongmasa | 223b8e3 | 2017-02-22 20:32:25 -0800 | [diff] [blame] | 293 | native_handle_t* nh = nullptr; |
| 294 | if ((lOutFence == nullptr) || !wrapAs(&tOutFence, &nh, *lOutFence)) { |
Pawin Vongmasa | ac7d412 | 2017-03-01 05:48:42 -0800 | [diff] [blame] | 295 | ALOGE("TWOmxBufferProducer::getLastQueuedBuffer - " |
| 296 | "Invalid output fence"); |
Pawin Vongmasa | 223b8e3 | 2017-02-22 20:32:25 -0800 | [diff] [blame] | 297 | _hidl_cb(toStatus(status), |
| 298 | tOutBuffer, |
| 299 | tOutFence, |
| 300 | hidl_array<float, 16>()); |
| 301 | return Void(); |
Pawin Vongmasa | eeac97b | 2017-01-18 05:03:07 -0800 | [diff] [blame] | 302 | } |
| 303 | hidl_array<float, 16> tOutTransformMatrix(lOutTransformMatrix); |
| 304 | |
| 305 | _hidl_cb(toStatus(status), tOutBuffer, tOutFence, tOutTransformMatrix); |
| 306 | native_handle_delete(nh); |
| 307 | return Void(); |
| 308 | } |
| 309 | |
| 310 | Return<void> TWOmxBufferProducer::getFrameTimestamps( |
| 311 | getFrameTimestamps_cb _hidl_cb) { |
| 312 | ::android::FrameEventHistoryDelta lDelta; |
| 313 | mBase->getFrameTimestamps(&lDelta); |
| 314 | |
| 315 | FrameEventHistoryDelta tDelta; |
| 316 | std::vector<std::vector<native_handle_t*> > nhAA; |
| 317 | if (!wrapAs(&tDelta, &nhAA, lDelta)) { |
Pawin Vongmasa | ac7d412 | 2017-03-01 05:48:42 -0800 | [diff] [blame] | 318 | ALOGE("TWOmxBufferProducer::getFrameTimestamps - " |
| 319 | "Invalid output frame timestamps"); |
Pawin Vongmasa | 223b8e3 | 2017-02-22 20:32:25 -0800 | [diff] [blame] | 320 | _hidl_cb(tDelta); |
| 321 | return Void(); |
Pawin Vongmasa | eeac97b | 2017-01-18 05:03:07 -0800 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | _hidl_cb(tDelta); |
| 325 | for (auto& nhA : nhAA) { |
| 326 | for (auto& nh : nhA) { |
Pawin Vongmasa | 223b8e3 | 2017-02-22 20:32:25 -0800 | [diff] [blame] | 327 | native_handle_delete(nh); |
Pawin Vongmasa | eeac97b | 2017-01-18 05:03:07 -0800 | [diff] [blame] | 328 | } |
| 329 | } |
| 330 | return Void(); |
| 331 | } |
| 332 | |
| 333 | Return<void> TWOmxBufferProducer::getUniqueId(getUniqueId_cb _hidl_cb) { |
| 334 | uint64_t outId; |
| 335 | status_t status = mBase->getUniqueId(&outId); |
| 336 | _hidl_cb(toStatus(status), outId); |
| 337 | return Void(); |
| 338 | } |
| 339 | |
| 340 | // LWOmxBufferProducer |
| 341 | |
| 342 | LWOmxBufferProducer::LWOmxBufferProducer(sp<IOmxBufferProducer> const& base) : |
| 343 | mBase(base) { |
| 344 | } |
| 345 | |
| 346 | status_t LWOmxBufferProducer::requestBuffer(int slot, sp<GraphicBuffer>* buf) { |
| 347 | *buf = new GraphicBuffer(); |
| 348 | status_t fnStatus; |
| 349 | status_t transStatus = toStatusT(mBase->requestBuffer( |
| 350 | static_cast<int32_t>(slot), |
| 351 | [&fnStatus, &buf] (Status status, AnwBuffer const& buffer) { |
| 352 | fnStatus = toStatusT(status); |
| 353 | if (!convertTo(buf->get(), buffer)) { |
| 354 | fnStatus = fnStatus == NO_ERROR ? BAD_VALUE : fnStatus; |
| 355 | } |
| 356 | })); |
| 357 | return transStatus == NO_ERROR ? fnStatus : transStatus; |
| 358 | } |
| 359 | |
| 360 | status_t LWOmxBufferProducer::setMaxDequeuedBufferCount( |
| 361 | int maxDequeuedBuffers) { |
| 362 | return toStatusT(mBase->setMaxDequeuedBufferCount( |
| 363 | static_cast<int32_t>(maxDequeuedBuffers))); |
| 364 | } |
| 365 | |
| 366 | status_t LWOmxBufferProducer::setAsyncMode(bool async) { |
| 367 | return toStatusT(mBase->setAsyncMode(async)); |
| 368 | } |
| 369 | |
| 370 | status_t LWOmxBufferProducer::dequeueBuffer( |
| 371 | int* slot, sp<Fence>* fence, |
| 372 | uint32_t w, uint32_t h, ::android::PixelFormat format, |
| 373 | uint32_t usage, FrameEventHistoryDelta* outTimestamps) { |
| 374 | *fence = new Fence(); |
| 375 | status_t fnStatus; |
| 376 | status_t transStatus = toStatusT(mBase->dequeueBuffer( |
| 377 | w, h, static_cast<PixelFormat>(format), usage, |
| 378 | outTimestamps != nullptr, |
| 379 | [&fnStatus, slot, fence, outTimestamps] ( |
| 380 | Status status, |
| 381 | int32_t tSlot, |
| 382 | hidl_handle const& tFence, |
| 383 | IOmxBufferProducer::FrameEventHistoryDelta const& tTs) { |
| 384 | fnStatus = toStatusT(status); |
| 385 | *slot = tSlot; |
| 386 | if (!convertTo(fence->get(), tFence)) { |
Pawin Vongmasa | ac7d412 | 2017-03-01 05:48:42 -0800 | [diff] [blame] | 387 | ALOGE("LWOmxBufferProducer::dequeueBuffer - " |
| 388 | "Invalid output fence"); |
Pawin Vongmasa | eeac97b | 2017-01-18 05:03:07 -0800 | [diff] [blame] | 389 | fnStatus = fnStatus == NO_ERROR ? BAD_VALUE : fnStatus; |
| 390 | } |
| 391 | if (outTimestamps && !convertTo(outTimestamps, tTs)) { |
Pawin Vongmasa | ac7d412 | 2017-03-01 05:48:42 -0800 | [diff] [blame] | 392 | ALOGE("LWOmxBufferProducer::dequeueBuffer - " |
| 393 | "Invalid output timestamps"); |
Pawin Vongmasa | eeac97b | 2017-01-18 05:03:07 -0800 | [diff] [blame] | 394 | fnStatus = fnStatus == NO_ERROR ? BAD_VALUE : fnStatus; |
| 395 | } |
| 396 | })); |
| 397 | return transStatus == NO_ERROR ? fnStatus : transStatus; |
| 398 | } |
| 399 | |
| 400 | status_t LWOmxBufferProducer::detachBuffer(int slot) { |
| 401 | return toStatusT(mBase->detachBuffer(static_cast<int>(slot))); |
| 402 | } |
| 403 | |
| 404 | status_t LWOmxBufferProducer::detachNextBuffer( |
| 405 | sp<GraphicBuffer>* outBuffer, sp<Fence>* outFence) { |
| 406 | *outBuffer = new GraphicBuffer(); |
| 407 | *outFence = new Fence(); |
| 408 | status_t fnStatus; |
| 409 | status_t transStatus = toStatusT(mBase->detachNextBuffer( |
| 410 | [&fnStatus, outBuffer, outFence] ( |
| 411 | Status status, |
| 412 | AnwBuffer const& tBuffer, |
| 413 | hidl_handle const& tFence) { |
| 414 | fnStatus = toStatusT(status); |
| 415 | if (!convertTo(outFence->get(), tFence)) { |
Pawin Vongmasa | ac7d412 | 2017-03-01 05:48:42 -0800 | [diff] [blame] | 416 | ALOGE("LWOmxBufferProducer::detachNextBuffer - " |
| 417 | "Invalid output fence"); |
Pawin Vongmasa | eeac97b | 2017-01-18 05:03:07 -0800 | [diff] [blame] | 418 | fnStatus = fnStatus == NO_ERROR ? BAD_VALUE : fnStatus; |
| 419 | } |
| 420 | if (!convertTo(outBuffer->get(), tBuffer)) { |
Pawin Vongmasa | ac7d412 | 2017-03-01 05:48:42 -0800 | [diff] [blame] | 421 | ALOGE("LWOmxBufferProducer::detachNextBuffer - " |
| 422 | "Invalid output buffer"); |
Pawin Vongmasa | eeac97b | 2017-01-18 05:03:07 -0800 | [diff] [blame] | 423 | fnStatus = fnStatus == NO_ERROR ? BAD_VALUE : fnStatus; |
| 424 | } |
| 425 | })); |
| 426 | return transStatus == NO_ERROR ? fnStatus : transStatus; |
| 427 | } |
| 428 | |
| 429 | status_t LWOmxBufferProducer::attachBuffer( |
| 430 | int* outSlot, const sp<GraphicBuffer>& buffer) { |
| 431 | AnwBuffer tBuffer; |
| 432 | wrapAs(&tBuffer, *buffer); |
| 433 | status_t fnStatus; |
| 434 | status_t transStatus = toStatusT(mBase->attachBuffer(tBuffer, |
| 435 | [&fnStatus, outSlot] (Status status, int32_t slot) { |
| 436 | fnStatus = toStatusT(status); |
| 437 | *outSlot = slot; |
| 438 | })); |
| 439 | return transStatus == NO_ERROR ? fnStatus : transStatus; |
| 440 | } |
| 441 | |
| 442 | status_t LWOmxBufferProducer::queueBuffer( |
| 443 | int slot, |
| 444 | const QueueBufferInput& input, |
| 445 | QueueBufferOutput* output) { |
| 446 | IOmxBufferProducer::QueueBufferInput tInput; |
| 447 | native_handle_t* nh; |
| 448 | if (!wrapAs(&tInput, &nh, input)) { |
Pawin Vongmasa | ac7d412 | 2017-03-01 05:48:42 -0800 | [diff] [blame] | 449 | ALOGE("LWOmxBufferProducer::queueBuffer - Invalid input"); |
Pawin Vongmasa | eeac97b | 2017-01-18 05:03:07 -0800 | [diff] [blame] | 450 | return BAD_VALUE; |
| 451 | } |
| 452 | status_t fnStatus; |
| 453 | status_t transStatus = toStatusT(mBase->queueBuffer(slot, tInput, |
| 454 | [&fnStatus, output] ( |
| 455 | Status status, |
| 456 | IOmxBufferProducer::QueueBufferOutput const& tOutput) { |
| 457 | fnStatus = toStatusT(status); |
| 458 | if (!convertTo(output, tOutput)) { |
Pawin Vongmasa | ac7d412 | 2017-03-01 05:48:42 -0800 | [diff] [blame] | 459 | ALOGE("LWOmxBufferProducer::queueBuffer - " |
| 460 | "Invalid output"); |
Pawin Vongmasa | eeac97b | 2017-01-18 05:03:07 -0800 | [diff] [blame] | 461 | fnStatus = fnStatus == NO_ERROR ? BAD_VALUE : fnStatus; |
| 462 | } |
| 463 | })); |
| 464 | native_handle_delete(nh); |
| 465 | return transStatus == NO_ERROR ? fnStatus : transStatus; |
| 466 | } |
| 467 | |
| 468 | status_t LWOmxBufferProducer::cancelBuffer(int slot, const sp<Fence>& fence) { |
| 469 | hidl_handle tFence; |
Pawin Vongmasa | 223b8e3 | 2017-02-22 20:32:25 -0800 | [diff] [blame] | 470 | native_handle_t* nh = nullptr; |
| 471 | if ((fence == nullptr) || !wrapAs(&tFence, &nh, *fence)) { |
Pawin Vongmasa | ac7d412 | 2017-03-01 05:48:42 -0800 | [diff] [blame] | 472 | ALOGE("LWOmxBufferProducer::cancelBuffer - Invalid input fence"); |
Pawin Vongmasa | eeac97b | 2017-01-18 05:03:07 -0800 | [diff] [blame] | 473 | return BAD_VALUE; |
| 474 | } |
| 475 | |
| 476 | status_t status = toStatusT(mBase->cancelBuffer( |
| 477 | static_cast<int32_t>(slot), tFence)); |
| 478 | native_handle_delete(nh); |
| 479 | return status; |
| 480 | } |
| 481 | |
| 482 | int LWOmxBufferProducer::query(int what, int* value) { |
| 483 | int result; |
| 484 | status_t transStatus = toStatusT(mBase->query( |
| 485 | static_cast<int32_t>(what), |
| 486 | [&result, value] (int32_t tResult, int32_t tValue) { |
| 487 | result = static_cast<int>(tResult); |
| 488 | *value = static_cast<int>(tValue); |
| 489 | })); |
| 490 | return transStatus == NO_ERROR ? result : static_cast<int>(transStatus); |
| 491 | } |
| 492 | |
| 493 | status_t LWOmxBufferProducer::connect( |
| 494 | const sp<IProducerListener>& listener, int api, |
| 495 | bool producerControlledByApp, QueueBufferOutput* output) { |
Pawin Vongmasa | 8ff4018 | 2017-02-07 02:22:34 -0800 | [diff] [blame] | 496 | sp<IOmxProducerListener> tListener = listener == nullptr ? |
| 497 | nullptr : new TWOmxProducerListener(listener); |
Pawin Vongmasa | eeac97b | 2017-01-18 05:03:07 -0800 | [diff] [blame] | 498 | status_t fnStatus; |
| 499 | status_t transStatus = toStatusT(mBase->connect( |
| 500 | tListener, static_cast<int32_t>(api), producerControlledByApp, |
| 501 | [&fnStatus, output] ( |
| 502 | Status status, |
| 503 | IOmxBufferProducer::QueueBufferOutput const& tOutput) { |
| 504 | fnStatus = toStatusT(status); |
| 505 | if (!convertTo(output, tOutput)) { |
Pawin Vongmasa | ac7d412 | 2017-03-01 05:48:42 -0800 | [diff] [blame] | 506 | ALOGE("LWOmxBufferProducer::connect - Invalid output"); |
Pawin Vongmasa | eeac97b | 2017-01-18 05:03:07 -0800 | [diff] [blame] | 507 | fnStatus = fnStatus == NO_ERROR ? BAD_VALUE : fnStatus; |
| 508 | } |
| 509 | })); |
| 510 | return transStatus == NO_ERROR ? fnStatus : transStatus; |
| 511 | } |
| 512 | |
| 513 | status_t LWOmxBufferProducer::disconnect(int api, DisconnectMode mode) { |
| 514 | return toStatusT(mBase->disconnect( |
| 515 | static_cast<int32_t>(api), toOmxDisconnectMode(mode))); |
| 516 | } |
| 517 | |
| 518 | status_t LWOmxBufferProducer::setSidebandStream( |
| 519 | const sp<NativeHandle>& stream) { |
| 520 | return toStatusT(mBase->setSidebandStream(stream->handle())); |
| 521 | } |
| 522 | |
| 523 | void LWOmxBufferProducer::allocateBuffers(uint32_t width, uint32_t height, |
| 524 | ::android::PixelFormat format, uint32_t usage) { |
| 525 | mBase->allocateBuffers( |
| 526 | width, height, static_cast<PixelFormat>(format), usage); |
| 527 | } |
| 528 | |
| 529 | status_t LWOmxBufferProducer::allowAllocation(bool allow) { |
| 530 | return toStatusT(mBase->allowAllocation(allow)); |
| 531 | } |
| 532 | |
| 533 | status_t LWOmxBufferProducer::setGenerationNumber(uint32_t generationNumber) { |
| 534 | return toStatusT(mBase->setGenerationNumber(generationNumber)); |
| 535 | } |
| 536 | |
| 537 | String8 LWOmxBufferProducer::getConsumerName() const { |
| 538 | String8 lName; |
| 539 | mBase->getConsumerName([&lName] (hidl_string const& name) { |
| 540 | lName = name.c_str(); |
| 541 | }); |
| 542 | return lName; |
| 543 | } |
| 544 | |
| 545 | status_t LWOmxBufferProducer::setSharedBufferMode(bool sharedBufferMode) { |
| 546 | return toStatusT(mBase->setSharedBufferMode(sharedBufferMode)); |
| 547 | } |
| 548 | |
| 549 | status_t LWOmxBufferProducer::setAutoRefresh(bool autoRefresh) { |
| 550 | return toStatusT(mBase->setAutoRefresh(autoRefresh)); |
| 551 | } |
| 552 | |
| 553 | status_t LWOmxBufferProducer::setDequeueTimeout(nsecs_t timeout) { |
| 554 | return toStatusT(mBase->setDequeueTimeout(static_cast<int64_t>(timeout))); |
| 555 | } |
| 556 | |
| 557 | status_t LWOmxBufferProducer::getLastQueuedBuffer( |
| 558 | sp<GraphicBuffer>* outBuffer, |
| 559 | sp<Fence>* outFence, |
| 560 | float outTransformMatrix[16]) { |
| 561 | status_t fnStatus; |
| 562 | status_t transStatus = toStatusT(mBase->getLastQueuedBuffer( |
| 563 | [&fnStatus, outBuffer, outFence, &outTransformMatrix] ( |
| 564 | Status status, |
| 565 | AnwBuffer const& buffer, |
| 566 | hidl_handle const& fence, |
| 567 | hidl_array<float, 16> const& transformMatrix) { |
| 568 | fnStatus = toStatusT(status); |
| 569 | *outBuffer = new GraphicBuffer(); |
| 570 | if (!convertTo(outBuffer->get(), buffer)) { |
Pawin Vongmasa | ac7d412 | 2017-03-01 05:48:42 -0800 | [diff] [blame] | 571 | ALOGE("LWOmxBufferProducer::getLastQueuedBuffer - " |
| 572 | "Invalid output buffer"); |
Pawin Vongmasa | eeac97b | 2017-01-18 05:03:07 -0800 | [diff] [blame] | 573 | fnStatus = fnStatus == NO_ERROR ? BAD_VALUE : fnStatus; |
| 574 | } |
| 575 | *outFence = new Fence(); |
| 576 | if (!convertTo(outFence->get(), fence)) { |
Pawin Vongmasa | ac7d412 | 2017-03-01 05:48:42 -0800 | [diff] [blame] | 577 | ALOGE("LWOmxBufferProducer::getLastQueuedBuffer - " |
| 578 | "Invalid output fence"); |
Pawin Vongmasa | eeac97b | 2017-01-18 05:03:07 -0800 | [diff] [blame] | 579 | fnStatus = fnStatus == NO_ERROR ? BAD_VALUE : fnStatus; |
| 580 | } |
| 581 | std::copy(transformMatrix.data(), |
| 582 | transformMatrix.data() + 16, |
| 583 | outTransformMatrix); |
| 584 | })); |
| 585 | return transStatus == NO_ERROR ? fnStatus : transStatus; |
| 586 | } |
| 587 | |
| 588 | void LWOmxBufferProducer::getFrameTimestamps(FrameEventHistoryDelta* outDelta) { |
| 589 | mBase->getFrameTimestamps([outDelta] ( |
| 590 | IOmxBufferProducer::FrameEventHistoryDelta const& tDelta) { |
| 591 | convertTo(outDelta, tDelta); |
| 592 | }); |
| 593 | } |
| 594 | |
| 595 | status_t LWOmxBufferProducer::getUniqueId(uint64_t* outId) const { |
| 596 | status_t fnStatus; |
| 597 | status_t transStatus = toStatusT(mBase->getUniqueId( |
| 598 | [&fnStatus, outId] (Status status, uint64_t id) { |
| 599 | fnStatus = toStatusT(status); |
| 600 | *outId = id; |
| 601 | })); |
| 602 | return transStatus == NO_ERROR ? fnStatus : transStatus; |
| 603 | } |
| 604 | |
Pawin Vongmasa | eeac97b | 2017-01-18 05:03:07 -0800 | [diff] [blame] | 605 | } // namespace utils |
| 606 | } // namespace V1_0 |
| 607 | } // namespace omx |
| 608 | } // namespace media |
| 609 | } // namespace hardware |
| 610 | } // namespace android |