aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandroid-build-team Robot <android-build-team-robot@google.com>2020-09-17 23:05:13 +0000
committerandroid-build-team Robot <android-build-team-robot@google.com>2020-09-17 23:05:13 +0000
commit8cf1e0e88715c9fcd358df6843f41184410387e6 (patch)
treeb207ce2b6cb08f3ba9b14ea81e060885101abb7a
parentf2b475e5adc5b2ab26bc4cf8f3ca0f1e1c02fed6 (diff)
parent25c3c32f40307e211630744ca03545c5bcaeb5fa (diff)
downloadv4l2_codec2-android11-qpr1-d-release.tar.gz
Change-Id: I57de2315d2b2ff3e914380693922c5d6923f27bf
-rw-r--r--components/V4L2Decoder.cpp77
-rw-r--r--components/include/v4l2_codec2/components/V4L2Decoder.h1
2 files changed, 50 insertions, 28 deletions
diff --git a/components/V4L2Decoder.cpp b/components/V4L2Decoder.cpp
index 0df4e50..d52bd6c 100644
--- a/components/V4L2Decoder.cpp
+++ b/components/V4L2Decoder.cpp
@@ -270,8 +270,9 @@ void V4L2Decoder::pumpDecodeRequest() {
auto request = std::move(mDecodeRequests.front());
mDecodeRequests.pop();
- ALOGV("QBUF to input queue, bitstreadId=%d", request.buffer->id);
- inputBuffer->SetTimeStamp({.tv_sec = request.buffer->id});
+ const int32_t bitstreamId = request.buffer->id;
+ ALOGV("QBUF to input queue, bitstreadId=%d", bitstreamId);
+ inputBuffer->SetTimeStamp({.tv_sec = bitstreamId});
size_t planeSize = inputBuffer->GetPlaneSize(0);
if (request.buffer->size > planeSize) {
ALOGE("The input size (%zu) is not enough, we need %zu", planeSize,
@@ -286,9 +287,13 @@ void V4L2Decoder::pumpDecodeRequest() {
inputBuffer->SetPlaneBytesUsed(0, request.buffer->offset + request.buffer->size);
std::vector<int> fds;
fds.push_back(std::move(request.buffer->dmabuf_fd));
- std::move(*inputBuffer).QueueDMABuf(fds);
+ if (!std::move(*inputBuffer).QueueDMABuf(fds)) {
+ ALOGE("%s(): Failed to QBUF to input queue, bitstreamId=%d", __func__, bitstreamId);
+ onError();
+ return;
+ }
- mPendingDecodeCbs.insert(std::make_pair(request.buffer->id, std::move(request.decodeCb)));
+ mPendingDecodeCbs.insert(std::make_pair(bitstreamId, std::move(request.decodeCb)));
}
}
@@ -387,15 +392,43 @@ void V4L2Decoder::serviceDeviceTask(bool event) {
outputDequeued = true;
+ const size_t bufferId = dequeuedBuffer->BufferId();
+ const int32_t bitstreamId = static_cast<int32_t>(dequeuedBuffer->GetTimeStamp().tv_sec);
+ const size_t bytesUsed = dequeuedBuffer->GetPlaneBytesUsed(0);
+ const bool isLast = dequeuedBuffer->IsLast();
ALOGV("DQBUF from output queue, bufferId=%zu, corresponding bitstreamId=%d, bytesused=%zu",
- dequeuedBuffer->BufferId(),
- static_cast<int32_t>(dequeuedBuffer->GetTimeStamp().tv_sec),
- dequeuedBuffer->GetPlaneBytesUsed(0));
- if (dequeuedBuffer->GetPlaneBytesUsed(0) > 0) {
- sendOutputBuffer(dequeuedBuffer);
+ bufferId, bitstreamId, bytesUsed);
+
+ // Get the corresponding VideoFrame of the dequeued buffer.
+ auto it = mFrameAtDevice.find(bufferId);
+ ALOG_ASSERT(it != mFrameAtDevice.end(), "buffer %zu is not found at mFrameAtDevice",
+ bufferId);
+ auto frame = std::move(it->second);
+ mFrameAtDevice.erase(it);
+
+ if (bytesUsed > 0) {
+ ALOGV("Send output frame(bitstreamId=%d) to client", bitstreamId);
+ frame->setBitstreamId(bitstreamId);
+ frame->setVisibleRect(mVisibleRect);
+ mOutputCb.Run(std::move(frame));
+ } else {
+ // Workaround(b/168750131): If the buffer is not enqueued before the next drain is done,
+ // then the driver will fail to notify EOS. So we recycle the buffer immediately.
+ ALOGV("Recycle empty buffer %zu back to V4L2 output queue.", bufferId);
+ dequeuedBuffer.reset();
+ auto outputBuffer = mOutputQueue->GetFreeBuffer(bufferId);
+ ALOG_ASSERT(outputBuffer, "V4L2 output queue slot %zu is not freed.", bufferId);
+
+ if (!std::move(*outputBuffer).QueueDMABuf(frame->getFDs())) {
+ ALOGE("%s(): Failed to recycle empty buffer to output queue.", __func__);
+ onError();
+ return;
+ }
+ mFrameAtDevice.insert(std::make_pair(bufferId, std::move(frame)));
}
- if (mDrainCb && dequeuedBuffer->IsLast()) {
- ALOGD("All buffers are drained.");
+
+ if (mDrainCb && isLast) {
+ ALOGV("All buffers are drained.");
sendV4L2DecoderCmd(true);
std::move(mDrainCb).Run(VideoDecoder::DecodeStatus::kOk);
setState(State::Idle);
@@ -422,21 +455,6 @@ void V4L2Decoder::serviceDeviceTask(bool event) {
}
}
-void V4L2Decoder::sendOutputBuffer(media::V4L2ReadableBufferRef buffer) {
- ALOGV("%s(bufferId=%zu)", __func__, buffer->BufferId());
- ALOG_ASSERT(mTaskRunner->RunsTasksInCurrentSequence());
-
- size_t bufferId = buffer->BufferId();
- auto it = mFrameAtDevice.find(bufferId);
- ALOG_ASSERT(it != mFrameAtDevice.end(), "buffer %zu is not found at mFrameAtDevice", bufferId);
- auto block = std::move(it->second);
- mFrameAtDevice.erase(it);
-
- block->setBitstreamId(buffer->GetTimeStamp().tv_sec);
- block->setVisibleRect(mVisibleRect);
- mOutputCb.Run(std::move(block));
-}
-
bool V4L2Decoder::dequeueResolutionChangeEvent() {
ALOGV("%s()", __func__);
ALOG_ASSERT(mTaskRunner->RunsTasksInCurrentSequence());
@@ -556,7 +574,12 @@ void V4L2Decoder::onVideoFrameReady(
uint32_t v4l2Id = outputBuffer->BufferId();
ALOGV("QBUF to output queue, blockId=%u, V4L2Id=%u", blockId, v4l2Id);
- std::move(*outputBuffer).QueueDMABuf(frame->getFDs());
+ if (!std::move(*outputBuffer).QueueDMABuf(frame->getFDs())) {
+ ALOGE("%s(): Failed to QBUF to output queue, blockId=%u, V4L2Id=%u", __func__, blockId,
+ v4l2Id);
+ onError();
+ return;
+ }
if (mFrameAtDevice.find(v4l2Id) != mFrameAtDevice.end()) {
ALOGE("%s(): V4L2 buffer %d already enqueued.", __func__, v4l2Id);
onError();
diff --git a/components/include/v4l2_codec2/components/V4L2Decoder.h b/components/include/v4l2_codec2/components/V4L2Decoder.h
index 5539042..bdddc7f 100644
--- a/components/include/v4l2_codec2/components/V4L2Decoder.h
+++ b/components/include/v4l2_codec2/components/V4L2Decoder.h
@@ -62,7 +62,6 @@ private:
void pumpDecodeRequest();
void serviceDeviceTask(bool event);
- void sendOutputBuffer(media::V4L2ReadableBufferRef buffer);
bool dequeueResolutionChangeEvent();
bool changeResolution();