aboutsummaryrefslogtreecommitdiff
path: root/components/V4L2Decoder.cpp
diff options
context:
space:
mode:
authorChih-Yu Huang <akahuang@google.com>2021-06-07 11:40:13 +0900
committerChih-Yu Huang <akahuang@google.com>2021-10-20 14:24:07 +0900
commit783186680c63be066f1822982c77a732b4514333 (patch)
tree4f2de25bd0e0390a69b84380b44212787708a678 /components/V4L2Decoder.cpp
parent86d595844d43782f64a2adbe0b9c08b57374261a (diff)
downloadv4l2_codec2-783186680c63be066f1822982c77a732b4514333.tar.gz
Bug: None Test: mmm external/v4l2_codec2 Change-Id: I21d5d30ce32279dfb1cbe2b40d435d2e9707f5aa
Diffstat (limited to 'components/V4L2Decoder.cpp')
-rw-r--r--components/V4L2Decoder.cpp30
1 files changed, 19 insertions, 11 deletions
diff --git a/components/V4L2Decoder.cpp b/components/V4L2Decoder.cpp
index d694837..18d62d2 100644
--- a/components/V4L2Decoder.cpp
+++ b/components/V4L2Decoder.cpp
@@ -9,6 +9,7 @@
#include <stdint.h>
+#include <algorithm>
#include <vector>
#include <base/bind.h>
@@ -48,12 +49,13 @@ uint32_t VideoCodecToV4L2PixFmt(VideoCodec codec) {
// static
std::unique_ptr<VideoDecoder> V4L2Decoder::Create(
- const VideoCodec& codec, const size_t inputBufferSize, GetPoolCB getPoolCb,
- OutputCB outputCb, ErrorCB errorCb, scoped_refptr<::base::SequencedTaskRunner> taskRunner) {
+ const VideoCodec& codec, const size_t inputBufferSize, const size_t minNumOutputBuffers,
+ GetPoolCB getPoolCb, OutputCB outputCb, ErrorCB errorCb,
+ scoped_refptr<::base::SequencedTaskRunner> taskRunner) {
std::unique_ptr<V4L2Decoder> decoder =
::base::WrapUnique<V4L2Decoder>(new V4L2Decoder(taskRunner));
- if (!decoder->start(codec, inputBufferSize, std::move(getPoolCb), std::move(outputCb),
- std::move(errorCb))) {
+ if (!decoder->start(codec, inputBufferSize, minNumOutputBuffers, std::move(getPoolCb),
+ std::move(outputCb), std::move(errorCb))) {
return nullptr;
}
return decoder;
@@ -89,12 +91,14 @@ V4L2Decoder::~V4L2Decoder() {
}
}
-bool V4L2Decoder::start(const VideoCodec& codec, const size_t inputBufferSize, GetPoolCB getPoolCb,
- OutputCB outputCb, ErrorCB errorCb) {
- ALOGV("%s(codec=%s, inputBufferSize=%zu)", __func__, VideoCodecToString(codec),
- inputBufferSize);
+bool V4L2Decoder::start(const VideoCodec& codec, const size_t inputBufferSize,
+ const size_t minNumOutputBuffers, GetPoolCB getPoolCb, OutputCB outputCb,
+ ErrorCB errorCb) {
+ ALOGV("%s(codec=%s, inputBufferSize=%zu, minNumOutputBuffers=%zu)", __func__,
+ VideoCodecToString(codec), inputBufferSize, minNumOutputBuffers);
ALOG_ASSERT(mTaskRunner->RunsTasksInCurrentSequence());
+ mMinNumOutputBuffers = minNumOutputBuffers;
mGetPoolCb = std::move(getPoolCb);
mOutputCb = std::move(outputCb);
mErrorCb = std::move(errorCb);
@@ -188,7 +192,7 @@ bool V4L2Decoder::setupInputFormat(const uint32_t inputPixelFormat, const size_t
return true;
}
-void V4L2Decoder::decode(std::unique_ptr<BitstreamBuffer> buffer, DecodeCB decodeCb) {
+void V4L2Decoder::decode(std::unique_ptr<ConstBitstreamBuffer> buffer, DecodeCB decodeCb) {
ALOGV("%s(id=%d)", __func__, buffer->id);
ALOG_ASSERT(mTaskRunner->RunsTasksInCurrentSequence());
@@ -296,7 +300,7 @@ void V4L2Decoder::pumpDecodeRequest() {
inputBuffer->setPlaneDataOffset(0, request.buffer->offset);
inputBuffer->setPlaneBytesUsed(0, request.buffer->offset + request.buffer->size);
std::vector<int> fds;
- fds.push_back(std::move(request.buffer->dmabuf_fd));
+ fds.push_back(std::move(request.buffer->dmabuf.handle()->data[0]));
if (!std::move(*inputBuffer).queueDMABuf(fds)) {
ALOGE("%s(): Failed to QBUF to input queue, bitstreamId=%d", __func__, bitstreamId);
onError();
@@ -330,6 +334,7 @@ void V4L2Decoder::flush() {
}
// Streamoff both V4L2 queues to drop input and output buffers.
+ const bool isOutputStreaming = mOutputQueue->isStreaming();
mDevice->stopPolling();
mOutputQueue->streamoff();
mFrameAtDevice.clear();
@@ -337,7 +342,9 @@ void V4L2Decoder::flush() {
// Streamon both V4L2 queues.
mInputQueue->streamon();
- mOutputQueue->streamon();
+ if (isOutputStreaming) {
+ mOutputQueue->streamon();
+ }
// If there is no free buffer at mOutputQueue, tryFetchVideoFrame() should be triggerred after
// a buffer is DQBUF from output queue. Now all the buffers are dropped at mOutputQueue, we
@@ -496,6 +503,7 @@ bool V4L2Decoder::changeResolution() {
if (!format || !numOutputBuffers) {
return false;
}
+ *numOutputBuffers = std::max(*numOutputBuffers, mMinNumOutputBuffers);
const ui::Size codedSize(format->fmt.pix_mp.width, format->fmt.pix_mp.height);
if (!setupOutputFormat(codedSize)) {