blob: 03499f23c958cb2b33d96730eae1aca1b00665bb [file] [log] [blame]
Pawin Vongmasaeeac97b2017-01-18 05:03:07 -08001/*
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 Vongmasa223b8e32017-02-22 20:32:25 -080017#define LOG_TAG "WOmxBufferProducer-utils"
18
Pawin Vongmasaac7d4122017-03-01 05:48:42 -080019#include <utils/Log.h>
Pawin Vongmasa223b8e32017-02-22 20:32:25 -080020
Pawin Vongmasaac7d4122017-03-01 05:48:42 -080021#include <media/omx/1.0/WOmxBufferProducer.h>
22#include <media/omx/1.0/WOmxProducerListener.h>
23#include <media/omx/1.0/Conversion.h>
Pawin Vongmasaeeac97b2017-01-18 05:03:07 -080024
25namespace android {
26namespace hardware {
27namespace media {
28namespace omx {
29namespace V1_0 {
30namespace utils {
31
32// TWOmxBufferProducer
33TWOmxBufferProducer::TWOmxBufferProducer(
34 sp<IGraphicBufferProducer> const& base):
35 mBase(base) {
36}
37
38Return<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
48Return<Status> TWOmxBufferProducer::setMaxDequeuedBufferCount(
49 int32_t maxDequeuedBuffers) {
50 return toStatus(mBase->setMaxDequeuedBufferCount(
51 static_cast<int>(maxDequeuedBuffers)));
52}
53
54Return<Status> TWOmxBufferProducer::setAsyncMode(bool async) {
55 return toStatus(mBase->setAsyncMode(async));
56}
57
58Return<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 Vongmasaeeac97b2017-01-18 05:03:07 -080070 hidl_handle tFence;
Pawin Vongmasaeeac97b2017-01-18 05:03:07 -080071 FrameEventHistoryDelta tOutTimestamps;
Pawin Vongmasa223b8e32017-02-22 20:32:25 -080072
73 native_handle_t* nh = nullptr;
74 if ((fence == nullptr) || !wrapAs(&tFence, &nh, *fence)) {
Pawin Vongmasaac7d4122017-03-01 05:48:42 -080075 ALOGE("TWOmxBufferProducer::dequeueBuffer - Invalid output fence");
Pawin Vongmasa223b8e32017-02-22 20:32:25 -080076 _hidl_cb(toStatus(status),
77 static_cast<int32_t>(slot),
78 tFence,
79 tOutTimestamps);
80 return Void();
81 }
Pawin Vongmasaeeac97b2017-01-18 05:03:07 -080082 std::vector<std::vector<native_handle_t*> > nhAA;
83 if (getFrameTimestamps && !wrapAs(&tOutTimestamps, &nhAA, outTimestamps)) {
Pawin Vongmasaac7d4122017-03-01 05:48:42 -080084 ALOGE("TWOmxBufferProducer::dequeueBuffer - Invalid output timestamps");
Pawin Vongmasa223b8e32017-02-22 20:32:25 -080085 _hidl_cb(toStatus(status),
86 static_cast<int32_t>(slot),
87 tFence,
88 tOutTimestamps);
Pawin Vongmasaeeac97b2017-01-18 05:03:07 -080089 native_handle_delete(nh);
Pawin Vongmasa223b8e32017-02-22 20:32:25 -080090 return Void();
Pawin Vongmasaeeac97b2017-01-18 05:03:07 -080091 }
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 Vongmasa223b8e32017-02-22 20:32:25 -0800101 native_handle_delete(handle);
Pawin Vongmasaeeac97b2017-01-18 05:03:07 -0800102 }
103 }
104 }
105 return Void();
106}
107
108Return<Status> TWOmxBufferProducer::detachBuffer(int32_t slot) {
109 return toStatus(mBase->detachBuffer(slot));
110}
111
112Return<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 Vongmasaeeac97b2017-01-18 05:03:07 -0800117 AnwBuffer tBuffer;
Pawin Vongmasaeeac97b2017-01-18 05:03:07 -0800118 hidl_handle tFence;
Pawin Vongmasa223b8e32017-02-22 20:32:25 -0800119
120 if (outBuffer == nullptr) {
Pawin Vongmasaac7d4122017-03-01 05:48:42 -0800121 ALOGE("TWOmxBufferProducer::detachNextBuffer - Invalid output buffer");
Pawin Vongmasa223b8e32017-02-22 20:32:25 -0800122 _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 Vongmasaac7d4122017-03-01 05:48:42 -0800128 ALOGE("TWOmxBufferProducer::detachNextBuffer - Invalid output fence");
Pawin Vongmasa223b8e32017-02-22 20:32:25 -0800129 _hidl_cb(toStatus(status), tBuffer, tFence);
130 return Void();
Pawin Vongmasaeeac97b2017-01-18 05:03:07 -0800131 }
132
133 _hidl_cb(toStatus(status), tBuffer, tFence);
134 native_handle_delete(nh);
135 return Void();
136}
137
138Return<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 Vongmasaac7d4122017-03-01 05:48:42 -0800144 ALOGE("TWOmxBufferProducer::attachBuffer - "
145 "Invalid input native window buffer");
Pawin Vongmasa223b8e32017-02-22 20:32:25 -0800146 _hidl_cb(toStatus(BAD_VALUE), -1);
147 return Void();
Pawin Vongmasaeeac97b2017-01-18 05:03:07 -0800148 }
149 status_t status = mBase->attachBuffer(&outSlot, lBuffer);
150
151 _hidl_cb(toStatus(status), static_cast<int32_t>(outSlot));
152 return Void();
153}
154
155Return<void> TWOmxBufferProducer::queueBuffer(
156 int32_t slot, const QueueBufferInput& input,
157 queueBuffer_cb _hidl_cb) {
Pawin Vongmasa223b8e32017-02-22 20:32:25 -0800158 QueueBufferOutput tOutput;
Pawin Vongmasaeeac97b2017-01-18 05:03:07 -0800159 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 Vongmasaac7d4122017-03-01 05:48:42 -0800165 ALOGE("TWOmxBufferProducer::queueBuffer - Invalid input");
Pawin Vongmasa223b8e32017-02-22 20:32:25 -0800166 _hidl_cb(toStatus(BAD_VALUE), tOutput);
167 return Void();
Pawin Vongmasaeeac97b2017-01-18 05:03:07 -0800168 }
169 IGraphicBufferProducer::QueueBufferOutput lOutput;
170 status_t status = mBase->queueBuffer(
171 static_cast<int>(slot), lInput, &lOutput);
172
Pawin Vongmasaeeac97b2017-01-18 05:03:07 -0800173 std::vector<std::vector<native_handle_t*> > nhAA;
174 if (!wrapAs(&tOutput, &nhAA, lOutput)) {
Pawin Vongmasaac7d4122017-03-01 05:48:42 -0800175 ALOGE("TWOmxBufferProducer::queueBuffer - Invalid output");
Pawin Vongmasa223b8e32017-02-22 20:32:25 -0800176 _hidl_cb(toStatus(BAD_VALUE), tOutput);
177 return Void();
Pawin Vongmasaeeac97b2017-01-18 05:03:07 -0800178 }
179
180 _hidl_cb(toStatus(status), tOutput);
181 for (auto& nhA : nhAA) {
182 for (auto& nh : nhA) {
Pawin Vongmasa223b8e32017-02-22 20:32:25 -0800183 native_handle_delete(nh);
Pawin Vongmasaeeac97b2017-01-18 05:03:07 -0800184 }
185 }
186 return Void();
187}
188
189Return<Status> TWOmxBufferProducer::cancelBuffer(
190 int32_t slot, const hidl_handle& fence) {
191 sp<Fence> lFence = new Fence();
192 if (!convertTo(lFence.get(), fence)) {
Pawin Vongmasaac7d4122017-03-01 05:48:42 -0800193 ALOGE("TWOmxBufferProducer::cancelBuffer - Invalid input fence");
Pawin Vongmasa223b8e32017-02-22 20:32:25 -0800194 return toStatus(BAD_VALUE);
Pawin Vongmasaeeac97b2017-01-18 05:03:07 -0800195 }
196 return toStatus(mBase->cancelBuffer(static_cast<int>(slot), lFence));
197}
198
199Return<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
206Return<void> TWOmxBufferProducer::connect(
207 const sp<IOmxProducerListener>& listener,
208 int32_t api, bool producerControlledByApp, connect_cb _hidl_cb) {
Pawin Vongmasa8ff40182017-02-07 02:22:34 -0800209 sp<IProducerListener> lListener = listener == nullptr ?
210 nullptr : new LWOmxProducerListener(listener);
Pawin Vongmasaeeac97b2017-01-18 05:03:07 -0800211 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 Vongmasaac7d4122017-03-01 05:48:42 -0800220 ALOGE("TWOmxBufferProducer::connect - Invalid output");
Pawin Vongmasa223b8e32017-02-22 20:32:25 -0800221 _hidl_cb(toStatus(status), tOutput);
222 return Void();
Pawin Vongmasaeeac97b2017-01-18 05:03:07 -0800223 }
224
225 _hidl_cb(toStatus(status), tOutput);
226 for (auto& nhA : nhAA) {
227 for (auto& nh : nhA) {
Pawin Vongmasa223b8e32017-02-22 20:32:25 -0800228 native_handle_delete(nh);
Pawin Vongmasaeeac97b2017-01-18 05:03:07 -0800229 }
230 }
231 return Void();
232}
233
234Return<Status> TWOmxBufferProducer::disconnect(
235 int32_t api, DisconnectMode mode) {
236 return toStatus(mBase->disconnect(
237 static_cast<int>(api),
238 toGuiDisconnectMode(mode)));
239}
240
241Return<Status> TWOmxBufferProducer::setSidebandStream(const hidl_handle& stream) {
242 return toStatus(mBase->setSidebandStream(NativeHandle::create(
243 native_handle_clone(stream), true)));
244}
245
246Return<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
255Return<Status> TWOmxBufferProducer::allowAllocation(bool allow) {
256 return toStatus(mBase->allowAllocation(allow));
257}
258
259Return<Status> TWOmxBufferProducer::setGenerationNumber(uint32_t generationNumber) {
260 return toStatus(mBase->setGenerationNumber(generationNumber));
261}
262
263Return<void> TWOmxBufferProducer::getConsumerName(getConsumerName_cb _hidl_cb) {
264 _hidl_cb(mBase->getConsumerName().string());
265 return Void();
266}
267
268Return<Status> TWOmxBufferProducer::setSharedBufferMode(bool sharedBufferMode) {
269 return toStatus(mBase->setSharedBufferMode(sharedBufferMode));
270}
271
272Return<Status> TWOmxBufferProducer::setAutoRefresh(bool autoRefresh) {
273 return toStatus(mBase->setAutoRefresh(autoRefresh));
274}
275
276Return<Status> TWOmxBufferProducer::setDequeueTimeout(int64_t timeoutNs) {
277 return toStatus(mBase->setDequeueTimeout(timeoutNs));
278}
279
280Return<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 Vongmasa223b8e32017-02-22 20:32:25 -0800289 if (lOutBuffer != nullptr) {
290 wrapAs(&tOutBuffer, *lOutBuffer);
291 }
Pawin Vongmasaeeac97b2017-01-18 05:03:07 -0800292 hidl_handle tOutFence;
Pawin Vongmasa223b8e32017-02-22 20:32:25 -0800293 native_handle_t* nh = nullptr;
294 if ((lOutFence == nullptr) || !wrapAs(&tOutFence, &nh, *lOutFence)) {
Pawin Vongmasaac7d4122017-03-01 05:48:42 -0800295 ALOGE("TWOmxBufferProducer::getLastQueuedBuffer - "
296 "Invalid output fence");
Pawin Vongmasa223b8e32017-02-22 20:32:25 -0800297 _hidl_cb(toStatus(status),
298 tOutBuffer,
299 tOutFence,
300 hidl_array<float, 16>());
301 return Void();
Pawin Vongmasaeeac97b2017-01-18 05:03:07 -0800302 }
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
310Return<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 Vongmasaac7d4122017-03-01 05:48:42 -0800318 ALOGE("TWOmxBufferProducer::getFrameTimestamps - "
319 "Invalid output frame timestamps");
Pawin Vongmasa223b8e32017-02-22 20:32:25 -0800320 _hidl_cb(tDelta);
321 return Void();
Pawin Vongmasaeeac97b2017-01-18 05:03:07 -0800322 }
323
324 _hidl_cb(tDelta);
325 for (auto& nhA : nhAA) {
326 for (auto& nh : nhA) {
Pawin Vongmasa223b8e32017-02-22 20:32:25 -0800327 native_handle_delete(nh);
Pawin Vongmasaeeac97b2017-01-18 05:03:07 -0800328 }
329 }
330 return Void();
331}
332
333Return<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
342LWOmxBufferProducer::LWOmxBufferProducer(sp<IOmxBufferProducer> const& base) :
343 mBase(base) {
344}
345
346status_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
360status_t LWOmxBufferProducer::setMaxDequeuedBufferCount(
361 int maxDequeuedBuffers) {
362 return toStatusT(mBase->setMaxDequeuedBufferCount(
363 static_cast<int32_t>(maxDequeuedBuffers)));
364}
365
366status_t LWOmxBufferProducer::setAsyncMode(bool async) {
367 return toStatusT(mBase->setAsyncMode(async));
368}
369
370status_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 Vongmasaac7d4122017-03-01 05:48:42 -0800387 ALOGE("LWOmxBufferProducer::dequeueBuffer - "
388 "Invalid output fence");
Pawin Vongmasaeeac97b2017-01-18 05:03:07 -0800389 fnStatus = fnStatus == NO_ERROR ? BAD_VALUE : fnStatus;
390 }
391 if (outTimestamps && !convertTo(outTimestamps, tTs)) {
Pawin Vongmasaac7d4122017-03-01 05:48:42 -0800392 ALOGE("LWOmxBufferProducer::dequeueBuffer - "
393 "Invalid output timestamps");
Pawin Vongmasaeeac97b2017-01-18 05:03:07 -0800394 fnStatus = fnStatus == NO_ERROR ? BAD_VALUE : fnStatus;
395 }
396 }));
397 return transStatus == NO_ERROR ? fnStatus : transStatus;
398}
399
400status_t LWOmxBufferProducer::detachBuffer(int slot) {
401 return toStatusT(mBase->detachBuffer(static_cast<int>(slot)));
402}
403
404status_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 Vongmasaac7d4122017-03-01 05:48:42 -0800416 ALOGE("LWOmxBufferProducer::detachNextBuffer - "
417 "Invalid output fence");
Pawin Vongmasaeeac97b2017-01-18 05:03:07 -0800418 fnStatus = fnStatus == NO_ERROR ? BAD_VALUE : fnStatus;
419 }
420 if (!convertTo(outBuffer->get(), tBuffer)) {
Pawin Vongmasaac7d4122017-03-01 05:48:42 -0800421 ALOGE("LWOmxBufferProducer::detachNextBuffer - "
422 "Invalid output buffer");
Pawin Vongmasaeeac97b2017-01-18 05:03:07 -0800423 fnStatus = fnStatus == NO_ERROR ? BAD_VALUE : fnStatus;
424 }
425 }));
426 return transStatus == NO_ERROR ? fnStatus : transStatus;
427}
428
429status_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
442status_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 Vongmasaac7d4122017-03-01 05:48:42 -0800449 ALOGE("LWOmxBufferProducer::queueBuffer - Invalid input");
Pawin Vongmasaeeac97b2017-01-18 05:03:07 -0800450 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 Vongmasaac7d4122017-03-01 05:48:42 -0800459 ALOGE("LWOmxBufferProducer::queueBuffer - "
460 "Invalid output");
Pawin Vongmasaeeac97b2017-01-18 05:03:07 -0800461 fnStatus = fnStatus == NO_ERROR ? BAD_VALUE : fnStatus;
462 }
463 }));
464 native_handle_delete(nh);
465 return transStatus == NO_ERROR ? fnStatus : transStatus;
466}
467
468status_t LWOmxBufferProducer::cancelBuffer(int slot, const sp<Fence>& fence) {
469 hidl_handle tFence;
Pawin Vongmasa223b8e32017-02-22 20:32:25 -0800470 native_handle_t* nh = nullptr;
471 if ((fence == nullptr) || !wrapAs(&tFence, &nh, *fence)) {
Pawin Vongmasaac7d4122017-03-01 05:48:42 -0800472 ALOGE("LWOmxBufferProducer::cancelBuffer - Invalid input fence");
Pawin Vongmasaeeac97b2017-01-18 05:03:07 -0800473 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
482int 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
493status_t LWOmxBufferProducer::connect(
494 const sp<IProducerListener>& listener, int api,
495 bool producerControlledByApp, QueueBufferOutput* output) {
Pawin Vongmasa8ff40182017-02-07 02:22:34 -0800496 sp<IOmxProducerListener> tListener = listener == nullptr ?
497 nullptr : new TWOmxProducerListener(listener);
Pawin Vongmasaeeac97b2017-01-18 05:03:07 -0800498 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 Vongmasaac7d4122017-03-01 05:48:42 -0800506 ALOGE("LWOmxBufferProducer::connect - Invalid output");
Pawin Vongmasaeeac97b2017-01-18 05:03:07 -0800507 fnStatus = fnStatus == NO_ERROR ? BAD_VALUE : fnStatus;
508 }
509 }));
510 return transStatus == NO_ERROR ? fnStatus : transStatus;
511}
512
513status_t LWOmxBufferProducer::disconnect(int api, DisconnectMode mode) {
514 return toStatusT(mBase->disconnect(
515 static_cast<int32_t>(api), toOmxDisconnectMode(mode)));
516}
517
518status_t LWOmxBufferProducer::setSidebandStream(
519 const sp<NativeHandle>& stream) {
520 return toStatusT(mBase->setSidebandStream(stream->handle()));
521}
522
523void 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
529status_t LWOmxBufferProducer::allowAllocation(bool allow) {
530 return toStatusT(mBase->allowAllocation(allow));
531}
532
533status_t LWOmxBufferProducer::setGenerationNumber(uint32_t generationNumber) {
534 return toStatusT(mBase->setGenerationNumber(generationNumber));
535}
536
537String8 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
545status_t LWOmxBufferProducer::setSharedBufferMode(bool sharedBufferMode) {
546 return toStatusT(mBase->setSharedBufferMode(sharedBufferMode));
547}
548
549status_t LWOmxBufferProducer::setAutoRefresh(bool autoRefresh) {
550 return toStatusT(mBase->setAutoRefresh(autoRefresh));
551}
552
553status_t LWOmxBufferProducer::setDequeueTimeout(nsecs_t timeout) {
554 return toStatusT(mBase->setDequeueTimeout(static_cast<int64_t>(timeout)));
555}
556
557status_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 Vongmasaac7d4122017-03-01 05:48:42 -0800571 ALOGE("LWOmxBufferProducer::getLastQueuedBuffer - "
572 "Invalid output buffer");
Pawin Vongmasaeeac97b2017-01-18 05:03:07 -0800573 fnStatus = fnStatus == NO_ERROR ? BAD_VALUE : fnStatus;
574 }
575 *outFence = new Fence();
576 if (!convertTo(outFence->get(), fence)) {
Pawin Vongmasaac7d4122017-03-01 05:48:42 -0800577 ALOGE("LWOmxBufferProducer::getLastQueuedBuffer - "
578 "Invalid output fence");
Pawin Vongmasaeeac97b2017-01-18 05:03:07 -0800579 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
588void LWOmxBufferProducer::getFrameTimestamps(FrameEventHistoryDelta* outDelta) {
589 mBase->getFrameTimestamps([outDelta] (
590 IOmxBufferProducer::FrameEventHistoryDelta const& tDelta) {
591 convertTo(outDelta, tDelta);
592 });
593}
594
595status_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 Vongmasaeeac97b2017-01-18 05:03:07 -0800605} // namespace utils
606} // namespace V1_0
607} // namespace omx
608} // namespace media
609} // namespace hardware
610} // namespace android