VP9 parser: undo r34393 and fix incorrect return statement.
Some code was deleted in
https://webrtc-review.googlesource.com/c/src/+/224266/2/modules/video_coding/utility/vp9_uncompressed_header_parser.cc
since it was detected as unreachable.
The root cause was an early return that should have been a
RETURN_IF_FALSE(x).
Bug: webrtc:12924
Change-Id: Ifadded9bbb4748d56cf65c30fd8f87e92fde10d8
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/225040
Commit-Queue: Erik Språng <sprang@webrtc.org>
Reviewed-by: Philip Eliasson <philipel@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#34422}
diff --git a/modules/video_coding/BUILD.gn b/modules/video_coding/BUILD.gn
index b28517e..50f2e8d 100644
--- a/modules/video_coding/BUILD.gn
+++ b/modules/video_coding/BUILD.gn
@@ -985,6 +985,7 @@
"utility/qp_parser_unittest.cc",
"utility/quality_scaler_unittest.cc",
"utility/simulcast_rate_allocator_unittest.cc",
+ "utility/vp9_uncompressed_header_parser_unittest.cc",
"video_codec_initializer_unittest.cc",
"video_receiver_unittest.cc",
]
diff --git a/modules/video_coding/utility/vp9_uncompressed_header_parser.cc b/modules/video_coding/utility/vp9_uncompressed_header_parser.cc
index 34b1528..07ba325 100644
--- a/modules/video_coding/utility/vp9_uncompressed_header_parser.cc
+++ b/modules/video_coding/utility/vp9_uncompressed_header_parser.cc
@@ -300,7 +300,12 @@
}
bool Vp9ReadSegmentationParams(BitstreamReader* br) {
- return br->IfNextBoolean([&] { // segmentation_enabled
+ constexpr int kVp9MaxSegments = 8;
+ constexpr int kVp9SegLvlMax = 4;
+ constexpr int kSegmentationFeatureBits[kVp9SegLvlMax] = {8, 6, 2, 0};
+ constexpr bool kSegmentationFeatureSigned[kVp9SegLvlMax] = {1, 1, 0, 0};
+
+ RETURN_IF_FALSE(br->IfNextBoolean([&] { // segmentation_enabled
return br->IfNextBoolean([&] { // update_map
// Consume probs.
for (int i = 0; i < 7; ++i) {
@@ -316,6 +321,19 @@
return true;
});
});
+ }));
+
+ return br->IfNextBoolean([&] {
+ RETURN_IF_FALSE(br->ConsumeBits(1)); // abs_or_delta
+ for (int i = 0; i < kVp9MaxSegments; ++i) {
+ for (int j = 0; j < kVp9SegLvlMax; ++j) {
+ RETURN_IF_FALSE(br->IfNextBoolean([&] { // feature_enabled
+ return br->ConsumeBits(kSegmentationFeatureBits[j] +
+ kSegmentationFeatureSigned[j]);
+ }));
+ }
+ }
+ return true;
});
}
diff --git a/modules/video_coding/utility/vp9_uncompressed_header_parser_unittest.cc b/modules/video_coding/utility/vp9_uncompressed_header_parser_unittest.cc
new file mode 100644
index 0000000..b69b45d
--- /dev/null
+++ b/modules/video_coding/utility/vp9_uncompressed_header_parser_unittest.cc
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#include "modules/video_coding/utility/vp9_uncompressed_header_parser.h"
+
+#include "test/gmock.h"
+#include "test/gtest.h"
+
+namespace webrtc {
+namespace vp9 {
+
+TEST(Vp9UncompressedHeaderParserTest, FrameWithSegmentation) {
+ // Uncompressed header from a frame generated with libvpx.
+ // Encoded QVGA frame (SL0 of a VGA frame) that includes a segmentation.
+ const uint8_t kHeader[] = {
+ 0x87, 0x01, 0x00, 0x00, 0x02, 0x7e, 0x01, 0xdf, 0x02, 0x7f, 0x01, 0xdf,
+ 0xc6, 0x87, 0x04, 0x83, 0x83, 0x2e, 0x46, 0x60, 0x20, 0x38, 0x0c, 0x06,
+ 0x03, 0xcd, 0x80, 0xc0, 0x60, 0x9f, 0xc5, 0x46, 0x00, 0x00, 0x00, 0x00,
+ 0x2e, 0x73, 0xb7, 0xee, 0x22, 0x06, 0x81, 0x82, 0xd4, 0xef, 0xc3, 0x58,
+ 0x1f, 0x12, 0xd2, 0x7b, 0x28, 0x1f, 0x80, 0xfc, 0x07, 0xe0, 0x00, 0x00};
+
+ absl::optional<FrameInfo> frame_info =
+ ParseIntraFrameInfo(kHeader, sizeof(kHeader));
+ // Segmentation info is not actually populated in FrameInfo struct, but it
+ // needs to be parsed otherwise we end up on the wrong offset. The check for
+ // segmentation is thus that we have a valid return value.
+ ASSERT_TRUE(frame_info.has_value());
+
+ EXPECT_EQ(frame_info->is_keyframe, false);
+ EXPECT_EQ(frame_info->error_resilient, true);
+ EXPECT_EQ(frame_info->show_frame, true);
+ EXPECT_EQ(frame_info->base_qp, 185);
+ EXPECT_EQ(frame_info->frame_width, 320);
+ EXPECT_EQ(frame_info->frame_height, 240);
+ EXPECT_EQ(frame_info->render_width, 640);
+ EXPECT_EQ(frame_info->render_height, 480);
+}
+
+} // namespace vp9
+} // namespace webrtc