aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Staessens <dstaessens@google.com>2021-06-30 14:10:23 +0900
committerChih-Yu Huang <akahuang@google.com>2021-10-20 12:07:10 +0900
commit637be53d6520b22864d39cb64c46084ada247324 (patch)
tree241ee0c0971cbf314a58d2b1c337c3c4a774e1b8
parentdb6f790e0af3feaec78de19f4ae11fe33d9a9156 (diff)
downloadv4l2_codec2-637be53d6520b22864d39cb64c46084ada247324.tar.gz
v4l2_codec2 encoder: Don't parse H.264 NAL units when using VP8/9.
This CL changes the V4L2 encode component to not try to extract H.264 NAL units from an encoded VP8/9 video stream. Parsing for NAL units in a VP8/9 stream doesn't break encoding as an empty list is returned, but returning an empty config update to the mediacodec framework makes the GTS VP8 RtcVideoCodecTest fail. BUG: 191644279 BUG: 155138243 Test: media.gts.RtcVideoCodecTest#testDynamicBitrateChangeVp8 Change-Id: I789eb0c948afaea29e1595a503d63cd3788baf1b
-rw-r--r--components/V4L2EncodeComponent.cpp18
-rw-r--r--components/include/v4l2_codec2/components/V4L2EncodeComponent.h4
2 files changed, 14 insertions, 8 deletions
diff --git a/components/V4L2EncodeComponent.cpp b/components/V4L2EncodeComponent.cpp
index 459ac85..63672ce 100644
--- a/components/V4L2EncodeComponent.cpp
+++ b/components/V4L2EncodeComponent.cpp
@@ -186,6 +186,12 @@ std::unique_ptr<V4L2Encoder::InputFrame> CreateInputFrame(const C2ConstGraphicBl
format, index, timestamp);
}
+// Check whether the specified |profile| is an H.264 profile.
+bool IsH264Profile(C2Config::profile_t profile) {
+ return (profile >= C2Config::PROFILE_AVC_BASELINE &&
+ profile <= C2Config::PROFILE_AVC_ENHANCED_MULTIVIEW_DEPTH_HIGH);
+}
+
} // namespace
// static
@@ -617,14 +623,14 @@ bool V4L2EncodeComponent::initializeEncoder() {
ALOG_ASSERT(!mInputFormatConverter);
ALOG_ASSERT(!mEncoder);
- mCSDSubmitted = false;
-
// Get the requested profile and level.
C2Config::profile_t outputProfile = mInterface->getOutputProfile();
+ // CSD only needs to be extracted when using an H.264 profile.
+ mExtractCSD = IsH264Profile(outputProfile);
+
std::optional<uint8_t> h264Level;
- if (outputProfile >= C2Config::PROFILE_AVC_BASELINE &&
- outputProfile <= C2Config::PROFILE_AVC_ENHANCED_MULTIVIEW_DEPTH_HIGH) {
+ if (IsH264Profile(outputProfile)) {
h264Level = c2LevelToV4L2Level(mInterface->getOutputLevel());
}
@@ -869,7 +875,7 @@ void V4L2EncodeComponent::onOutputBufferDone(size_t dataSize, int64_t timestamp,
// If no CSD (content-specific-data, e.g. SPS for H.264) has been submitted yet, we expect this
// output block to contain CSD. We only submit the CSD once, even if it's attached to each key
// frame.
- if (!mCSDSubmitted) {
+ if (mExtractCSD) {
ALOGV("No CSD submitted yet, extracting CSD");
std::unique_ptr<C2StreamInitDataInfo::output> csd;
C2ReadView view = constBlock.map().get();
@@ -884,7 +890,7 @@ void V4L2EncodeComponent::onOutputBufferDone(size_t dataSize, int64_t timestamp,
LOG_ASSERT(!mWorkQueue.empty());
C2Work* work = mWorkQueue.front().get();
work->worklets.front()->output.configUpdate.push_back(std::move(csd));
- mCSDSubmitted = true;
+ mExtractCSD = false;
}
// Get the work item associated with the timestamp.
diff --git a/components/include/v4l2_codec2/components/V4L2EncodeComponent.h b/components/include/v4l2_codec2/components/V4L2EncodeComponent.h
index 4665ffa..9e7baf3 100644
--- a/components/include/v4l2_codec2/components/V4L2EncodeComponent.h
+++ b/components/include/v4l2_codec2/components/V4L2EncodeComponent.h
@@ -158,8 +158,8 @@ private:
// The framerate currently configured on the v4l2 device.
uint32_t mFramerate = 0;
- // Whether we extracted and submitted CSD (codec-specific data, e.g. H.264 SPS) to the framework.
- bool mCSDSubmitted = false;
+ // Whether we need to extract and submit CSD (codec-specific data, e.g. H.264 SPS).
+ bool mExtractCSD = false;
// The queue of encode work items currently being processed.
std::deque<std::unique_ptr<C2Work>> mWorkQueue;