Skip to content
Snippets Groups Projects
Commit 79dd1273 authored by David Stevens's avatar David Stevens Committed by Chih-Yu Huang
Browse files

components: Set InputBufferManager interval

InputBufferManager notifies the codec2 framework when the component no
longer has any references to an input buffer. While a dedicated release
notification is necessary in some circumstances, the release can usually
be done when the corresponding work item is completed, to reduce the
amount of IPC. This change sets the notification interval used by
InputBufferManager to reduce how often a dedicated release notification
is sent.

Bug: 172184040
Test: tast run DUT arc.VideoDecodeAccel.vp8_vm

Change-Id: Id6371d328bb00730b50d3b3075eccf4010554f27
parent 81a632ec
No related branches found
No related tags found
No related merge requests found
......@@ -20,6 +20,9 @@ enum class VideoCodec {
};
const char* VideoCodecToString(VideoCodec codec);
constexpr std::initializer_list<VideoCodec> kAllCodecs = {VideoCodec::H264, VideoCodec::VP8,
VideoCodec::VP9};
// Enumeration of supported pixel format. The value should be the same as
// ::android::hardware::graphics::common::V1_0::PixelFormat.
using HPixelFormat = ::android::hardware::graphics::common::V1_0::PixelFormat;
......
......@@ -3,7 +3,7 @@ cc_library {
vendor: true,
defaults: [
"libcodec2-impl-defaults",
"libcodec2-hidl-defaults",
],
srcs: [
......
......@@ -9,6 +9,7 @@
#include <C2ComponentFactory.h>
#include <SimpleC2Interface.h>
#include <codec2/hidl/1.0/InputBufferManager.h>
#include <log/log.h>
#include <util/C2InterfaceHelper.h>
......@@ -47,6 +48,25 @@ V4L2ComponentFactory::V4L2ComponentFactory(const char* componentName, bool isEnc
return;
}
mReflector = std::static_pointer_cast<C2ReflectorHelper>(componentStore->getParamReflector());
{
using namespace ::android::hardware::media::c2::V1_0;
// To minimize IPC, we generally want the codec2 framework to release and
// recycle input buffers when the corresponding work item is done. However,
// sometimes it is necessary to provide more input to unblock a decoder.
//
// Optimally we would configure this on a per-context basis. However, the
// InputBufferManager is a process-wide singleton, so we need to configure it
// pessimistically. Basing the interval on frame timing can be suboptimal if
// the decoded output isn't being displayed, but that's not a primary use case
// and few videos will actually rely on this behavior.
constexpr nsecs_t kMinFrameIntervalNs = 1000000000ull / 60;
uint32_t delayCount = 0;
for (auto c : kAllCodecs) {
delayCount = std::max(delayCount, V4L2DecodeInterface::getOutputDelay(c));
}
utils::InputBufferManager::setNotificationInterval(delayCount * kMinFrameIntervalNs / 2);
}
}
V4L2ComponentFactory::~V4L2ComponentFactory() = default;
......
......@@ -49,22 +49,6 @@ size_t calculateInputBufferSize(size_t area) {
if (area > k1080pArea) return kInputBufferSizeFor4K;
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
......@@ -350,4 +334,19 @@ c2_status_t V4L2DecodeInterface::queryColorAspects(
return status;
}
uint32_t V4L2DecodeInterface::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 android
......@@ -30,6 +30,8 @@ public:
media::Size getMaxSize() const { return mMaxSize; }
media::Size getMinSize() const { return mMinSize; }
static uint32_t getOutputDelay(VideoCodec codec);
size_t getInputBufferSize() const;
c2_status_t queryColorAspects(
std::shared_ptr<C2StreamColorAspectsInfo::output>* targetColorAspects);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment