V4L2DecodeInterface: add C2_PARAMKEY_OUTPUT_DELAY for H264
C2_PARAMKEY_OUTPUT_DELAY is the number of additional output frames
that needs to be generated before an output can be released by the
component.
H264 may reorder the output frames, so we set C2_PARAMKEY_OUTPUT_DELAY
to the possible maximum number of reoder frames.
Bug: 153403351
Test: pass E2E test TestSimpleDecode for H264
Change-Id: I13ad1dc60bb8674e09250163ec6c6b186fec26a4
diff --git a/components/V4L2DecodeInterface.cpp b/components/V4L2DecodeInterface.cpp
index c83d297..487a70f 100644
--- a/components/V4L2DecodeInterface.cpp
+++ b/components/V4L2DecodeInterface.cpp
@@ -56,6 +56,21 @@
return kInputBufferSizeFor1080p;
}
+uint32_t getOutputDelay(VideoCodec codec) {
+ switch (codec) {
+ case VideoCodec::H264:
+ // Due to frame reordering an H264 decoder might need multiple additional input frames to be
+ // queued before being able to output the associated decoded buffers. We need to tell the
+ // codec2 framework that it should not stop queuing new work items until the maximum number
+ // of frame reordering is reached, to avoid stalling the decoder.
+ return 16;
+ case VideoCodec::VP8:
+ return 0;
+ case VideoCodec::VP9:
+ return 0;
+ }
+}
+
} // namespace
// static
@@ -211,6 +226,10 @@
.withConstValue(
new C2StreamBufferTypeSetting::output(0u, C2BufferData::GRAPHIC))
.build());
+ addParameter(
+ DefineParam(mOutputDelay, C2_PARAMKEY_OUTPUT_DELAY)
+ .withConstValue(new C2PortDelayTuning::output(getOutputDelay(*mVideoCodec)))
+ .build());
addParameter(DefineParam(mInputMediaType, C2_PARAMKEY_INPUT_MEDIA_TYPE)
.withConstValue(AllocSharedString<C2PortMediaTypeSetting::input>(
diff --git a/components/include/v4l2_codec2/components/V4L2DecodeInterface.h b/components/include/v4l2_codec2/components/V4L2DecodeInterface.h
index 0abf4ec..46c565e 100644
--- a/components/include/v4l2_codec2/components/V4L2DecodeInterface.h
+++ b/components/include/v4l2_codec2/components/V4L2DecodeInterface.h
@@ -60,6 +60,10 @@
std::shared_ptr<C2PortMediaTypeSetting::input> mInputMediaType;
// The MIME type of output port; should be MEDIA_MIMETYPE_VIDEO_RAW.
std::shared_ptr<C2PortMediaTypeSetting::output> mOutputMediaType;
+ // The number of additional output frames that might need to be generated before an output
+ // buffer can be released by the component; only used for H264 because H264 may reorder the
+ // output frames.
+ std::shared_ptr<C2PortDelayTuning::output> mOutputDelay;
// The input codec profile and level. For now configuring this parameter is useless since
// the component always uses fixed codec profile to initialize accelerator. It is only used
// for the client to query supported profile and level values.