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
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 @@ 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 @@ 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 @@ // 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 @@ 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 @@ // 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;