Commit 5d31484d authored by Hirokazu Honda's avatar Hirokazu Honda Committed by Commit Bot

media/gpu/V4L2VEA: Don't inject SPS and PPS if they are already present

V4L2VEA prepends the latest SPS and PPS with IDR frame. V4L2VEA
does so whenever there is an IDR frame. A single bitstream buffer
returned by BitstreamBufferReady() may have two SPS and PPS, if
one buffer returned by an encoder driver contains SPS, PPS and
IDR frame.

Bug: b:143672449
Test: android.hardware.camera2.cts.RecordingTest#testBasicRecording
Change-Id: I559570df31de4684522f1b4b1db9a3277221f68e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1986690
Commit-Queue: Hirokazu Honda <hiroh@chromium.org>
Reviewed-by: default avatarDavid Staessens <dstaessens@chromium.org>
Reviewed-by: default avatarAlexandre Courbot <acourbot@chromium.org>
Cr-Commit-Position: refs/heads/master@{#728737}
parent 74d07cd8
...@@ -569,6 +569,8 @@ size_t V4L2VideoEncodeAccelerator::CopyIntoOutputBuffer( ...@@ -569,6 +569,8 @@ size_t V4L2VideoEncodeAccelerator::CopyIntoOutputBuffer(
parser.SetStream(bitstream_data, bitstream_size); parser.SetStream(bitstream_data, bitstream_size);
H264NALU nalu; H264NALU nalu;
bool inserted_sps = false;
bool inserted_pps = false;
while (parser.AdvanceToNextNALU(&nalu) == H264Parser::kOk) { while (parser.AdvanceToNextNALU(&nalu) == H264Parser::kOk) {
// nalu.size is always without the start code, regardless of the NALU type. // nalu.size is always without the start code, regardless of the NALU type.
if (nalu.size + kH264StartCodeSize > remaining_dst_size) { if (nalu.size + kH264StartCodeSize > remaining_dst_size) {
...@@ -582,6 +584,7 @@ size_t V4L2VideoEncodeAccelerator::CopyIntoOutputBuffer( ...@@ -582,6 +584,7 @@ size_t V4L2VideoEncodeAccelerator::CopyIntoOutputBuffer(
memcpy(cached_sps_.data(), nalu.data, nalu.size); memcpy(cached_sps_.data(), nalu.data, nalu.size);
cached_h264_header_size_ = cached_h264_header_size_ =
cached_sps_.size() + cached_pps_.size() + 2 * kH264StartCodeSize; cached_sps_.size() + cached_pps_.size() + 2 * kH264StartCodeSize;
inserted_sps = true;
break; break;
case H264NALU::kPPS: case H264NALU::kPPS:
...@@ -589,9 +592,14 @@ size_t V4L2VideoEncodeAccelerator::CopyIntoOutputBuffer( ...@@ -589,9 +592,14 @@ size_t V4L2VideoEncodeAccelerator::CopyIntoOutputBuffer(
memcpy(cached_pps_.data(), nalu.data, nalu.size); memcpy(cached_pps_.data(), nalu.data, nalu.size);
cached_h264_header_size_ = cached_h264_header_size_ =
cached_sps_.size() + cached_pps_.size() + 2 * kH264StartCodeSize; cached_sps_.size() + cached_pps_.size() + 2 * kH264StartCodeSize;
inserted_pps = true;
break; break;
case H264NALU::kIDRSlice: case H264NALU::kIDRSlice:
if (inserted_sps && inserted_pps) {
// Already inserted SPS and PPS. No need to inject.
break;
}
// Only inject if we have both headers cached, and enough space for both // Only inject if we have both headers cached, and enough space for both
// the headers and the NALU itself. // the headers and the NALU itself.
if (cached_sps_.empty() || cached_pps_.empty()) { if (cached_sps_.empty() || cached_pps_.empty()) {
...@@ -604,10 +612,14 @@ size_t V4L2VideoEncodeAccelerator::CopyIntoOutputBuffer( ...@@ -604,10 +612,14 @@ size_t V4L2VideoEncodeAccelerator::CopyIntoOutputBuffer(
break; break;
} }
CopyNALUPrependingStartCode(cached_sps_.data(), cached_sps_.size(), if (!inserted_sps) {
&dst_ptr, &remaining_dst_size); CopyNALUPrependingStartCode(cached_sps_.data(), cached_sps_.size(),
CopyNALUPrependingStartCode(cached_pps_.data(), cached_pps_.size(), &dst_ptr, &remaining_dst_size);
&dst_ptr, &remaining_dst_size); }
if (!inserted_pps) {
CopyNALUPrependingStartCode(cached_pps_.data(), cached_pps_.size(),
&dst_ptr, &remaining_dst_size);
}
VLOGF(2) << "Stream header injected before IDR"; VLOGF(2) << "Stream header injected before IDR";
break; break;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment