Refactor creation of ColorSpace test data

Bug: webrtc:8651
Change-Id: I2ebb5fcdc260af19d04513ab5f3d76f81a3b4ca9
Reviewed-on: https://webrtc-review.googlesource.com/c/114282
Reviewed-by: Magnus Jedvert <magjed@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Commit-Queue: Johannes Kron <kron@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#26012}
This commit is contained in:
Johannes Kron 2018-12-14 10:14:07 +01:00 committed by Commit Bot
parent 25aefd3584
commit f1ab9b9b3b
9 changed files with 94 additions and 87 deletions

View File

@ -0,0 +1,22 @@
# Copyright (c) 2018 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.
import("../../webrtc.gni")
if (rtc_include_tests) {
rtc_source_set("utilities") {
testonly = true
sources = [
"utilities.cc",
"utilities.h",
]
deps = [
"../../api/video:video_frame",
]
}
}

View File

@ -0,0 +1,42 @@
/*
* Copyright (c) 2018 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 "common_video/test/utilities.h"
namespace webrtc {
HdrMetadata CreateTestHdrMetadata() {
// Random but reasonable (in the sense of a valid range) HDR metadata.
HdrMetadata hdr_metadata;
hdr_metadata.mastering_metadata.luminance_max = 2000.0;
hdr_metadata.mastering_metadata.luminance_min = 2.0001;
hdr_metadata.mastering_metadata.primary_r.x = 0.3003;
hdr_metadata.mastering_metadata.primary_r.y = 0.4004;
hdr_metadata.mastering_metadata.primary_g.x = 0.3201;
hdr_metadata.mastering_metadata.primary_g.y = 0.4604;
hdr_metadata.mastering_metadata.primary_b.x = 0.3409;
hdr_metadata.mastering_metadata.primary_b.y = 0.4907;
hdr_metadata.mastering_metadata.white_point.x = 0.4103;
hdr_metadata.mastering_metadata.white_point.y = 0.4806;
hdr_metadata.max_content_light_level = 2345;
hdr_metadata.max_frame_average_light_level = 1789;
return hdr_metadata;
}
ColorSpace CreateTestColorSpace(bool with_hdr_metadata) {
HdrMetadata hdr_metadata = CreateTestHdrMetadata();
return ColorSpace(
ColorSpace::PrimaryID::kBT709, ColorSpace::TransferID::kGAMMA22,
ColorSpace::MatrixID::kSMPTE2085, ColorSpace::RangeID::kFull,
ColorSpace::ChromaSiting::kCollocated,
ColorSpace::ChromaSiting::kCollocated,
with_hdr_metadata ? &hdr_metadata : nullptr);
}
} // namespace webrtc

View File

@ -0,0 +1,22 @@
/*
* Copyright (c) 2018 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.
*/
#ifndef COMMON_VIDEO_TEST_UTILITIES_H_
#define COMMON_VIDEO_TEST_UTILITIES_H_
#include "api/video/color_space.h"
namespace webrtc {
HdrMetadata CreateTestHdrMetadata();
ColorSpace CreateTestColorSpace(bool with_hdr_metadata);
} // namespace webrtc
#endif // COMMON_VIDEO_TEST_UTILITIES_H_

View File

@ -431,6 +431,7 @@ if (rtc_include_tests) {
"../../api/video_codecs:video_codecs_api",
"../../call:rtp_receiver",
"../../common_video:common_video",
"../../common_video/test:utilities",
"../../logging:mocks",
"../../logging:rtc_event_log_api",
"../../rtc_base:checks",

View File

@ -10,6 +10,7 @@
#include "modules/rtp_rtcp/source/rtp_packet_received.h"
#include "modules/rtp_rtcp/source/rtp_packet_to_send.h"
#include "common_video/test/utilities.h"
#include "modules/rtp_rtcp/include/rtp_header_extension_map.h"
#include "modules/rtp_rtcp/source/rtp_header_extensions.h"
#include "rtc_base/random.h"
@ -186,34 +187,6 @@ constexpr uint8_t kPacketWithLegacyTimingExtension[] = {
0x00, 0x00, 0x00, 0x00};
// clang-format on
HdrMetadata CreateTestHdrMetadata() {
// Random but reasonable HDR metadata.
HdrMetadata hdr_metadata;
hdr_metadata.mastering_metadata.luminance_max = 2000.0;
hdr_metadata.mastering_metadata.luminance_min = 2.0001;
hdr_metadata.mastering_metadata.primary_r.x = 0.3003;
hdr_metadata.mastering_metadata.primary_r.y = 0.4004;
hdr_metadata.mastering_metadata.primary_g.x = 0.3201;
hdr_metadata.mastering_metadata.primary_g.y = 0.4604;
hdr_metadata.mastering_metadata.primary_b.x = 0.3409;
hdr_metadata.mastering_metadata.primary_b.y = 0.4907;
hdr_metadata.mastering_metadata.white_point.x = 0.4103;
hdr_metadata.mastering_metadata.white_point.y = 0.4806;
hdr_metadata.max_content_light_level = 2345;
hdr_metadata.max_frame_average_light_level = 1789;
return hdr_metadata;
}
ColorSpace CreateTestColorSpace(bool with_hdr_metadata) {
HdrMetadata hdr_metadata = CreateTestHdrMetadata();
return ColorSpace(
ColorSpace::PrimaryID::kBT709, ColorSpace::TransferID::kGAMMA22,
ColorSpace::MatrixID::kSMPTE2085, ColorSpace::RangeID::kFull,
ColorSpace::ChromaSiting::kCollocated,
ColorSpace::ChromaSiting::kCollocated,
with_hdr_metadata ? &hdr_metadata : nullptr);
}
void TestCreateAndParseColorSpaceExtension(bool with_hdr_metadata) {
// Create packet with extension.
RtpPacket::ExtensionManager extensions(/*extmap-allow-mixed=*/true);

View File

@ -813,6 +813,7 @@ if (rtc_include_tests) {
"../../api/video_codecs:rtc_software_fallback_wrappers",
"../../api/video_codecs:video_codecs_api",
"../../common_video",
"../../common_video/test:utilities",
"../../media:rtc_h264_profile_id",
"../../media:rtc_internal_video_codecs",
"../../media:rtc_media_base",

View File

@ -11,6 +11,7 @@
#include "api/video/color_space.h"
#include "api/video/i420_buffer.h"
#include "common_video/libyuv/include/webrtc_libyuv.h"
#include "common_video/test/utilities.h"
#include "media/base/vp9_profile.h"
#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
#include "modules/video_coding/codecs/test/video_codec_unittest.h"
@ -105,34 +106,6 @@ class TestVp9Impl : public VideoCodecUnitTest {
codec_settings_.spatialLayers[i] = layers[i];
}
}
HdrMetadata CreateTestHdrMetadata() const {
// Random but reasonable HDR metadata.
HdrMetadata hdr_metadata;
hdr_metadata.mastering_metadata.luminance_max = 2000.0;
hdr_metadata.mastering_metadata.luminance_min = 2.0001;
hdr_metadata.mastering_metadata.primary_r.x = 0.30;
hdr_metadata.mastering_metadata.primary_r.y = 0.40;
hdr_metadata.mastering_metadata.primary_g.x = 0.32;
hdr_metadata.mastering_metadata.primary_g.y = 0.46;
hdr_metadata.mastering_metadata.primary_b.x = 0.34;
hdr_metadata.mastering_metadata.primary_b.y = 0.49;
hdr_metadata.mastering_metadata.white_point.x = 0.41;
hdr_metadata.mastering_metadata.white_point.y = 0.48;
hdr_metadata.max_content_light_level = 2345;
hdr_metadata.max_frame_average_light_level = 1789;
return hdr_metadata;
}
ColorSpace CreateTestColorSpace() const {
HdrMetadata hdr_metadata = CreateTestHdrMetadata();
ColorSpace color_space(
ColorSpace::PrimaryID::kBT709, ColorSpace::TransferID::kGAMMA22,
ColorSpace::MatrixID::kSMPTE2085, ColorSpace::RangeID::kFull,
ColorSpace::ChromaSiting::kCollocated,
ColorSpace::ChromaSiting::kCollocated, &hdr_metadata);
return color_space;
}
};
// Disabled on ios as flake, see https://crbug.com/webrtc/7057
@ -201,7 +174,7 @@ TEST_F(TestVp9Impl, EncodedColorSpaceEqualsInputColorSpace) {
EXPECT_FALSE(encoded_frame.ColorSpace());
// Video frame with explicit color space information.
ColorSpace color_space = CreateTestColorSpace();
ColorSpace color_space = CreateTestColorSpace(/*with_hdr_metadata=*/true);
VideoFrame input_frame_w_hdr =
VideoFrame::Builder()
.set_video_frame_buffer(input_frame->video_frame_buffer())
@ -234,7 +207,7 @@ TEST_F(TestVp9Impl, DecodedHdrMetadataEqualsEncodedHdrMetadata) {
EXPECT_FALSE(decoded_frame->color_space()->hdr_metadata());
// Encoded frame with explicit color space information.
ColorSpace color_space = CreateTestColorSpace();
ColorSpace color_space = CreateTestColorSpace(/*with_hdr_metadata=*/true);
encoded_frame.SetColorSpace(&color_space);
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
decoder_->Decode(encoded_frame, false, nullptr, 0));

View File

@ -510,6 +510,7 @@ if (rtc_include_tests) {
"../call:simulated_packet_receiver",
"../call:video_stream_api",
"../common_video",
"../common_video/test:utilities",
"../logging:rtc_event_log_api",
"../media:rtc_audio_video",
"../media:rtc_internal_video_codecs",

View File

@ -12,6 +12,7 @@
#include "api/test/video/function_video_encoder_factory.h"
#include "api/video/color_space.h"
#include "api/video/video_rotation.h"
#include "common_video/test/utilities.h"
#include "media/engine/internaldecoderfactory.h"
#include "media/engine/internalencoderfactory.h"
#include "modules/video_coding/codecs/h264/include/h264.h"
@ -25,35 +26,6 @@
#include "test/gtest.h"
namespace webrtc {
namespace {
HdrMetadata CreateTestHdrMetadata() {
// Random but reasonable HDR metadata.
HdrMetadata hdr_metadata;
hdr_metadata.mastering_metadata.luminance_max = 2000.0;
hdr_metadata.mastering_metadata.luminance_min = 2.0001;
hdr_metadata.mastering_metadata.primary_r.x = 0.3003;
hdr_metadata.mastering_metadata.primary_r.y = 0.4004;
hdr_metadata.mastering_metadata.primary_g.x = 0.3201;
hdr_metadata.mastering_metadata.primary_g.y = 0.4604;
hdr_metadata.mastering_metadata.primary_b.x = 0.3409;
hdr_metadata.mastering_metadata.primary_b.y = 0.4907;
hdr_metadata.mastering_metadata.white_point.x = 0.4103;
hdr_metadata.mastering_metadata.white_point.y = 0.4806;
hdr_metadata.max_content_light_level = 2345;
hdr_metadata.max_frame_average_light_level = 1789;
return hdr_metadata;
}
ColorSpace CreateTestColorSpace(bool with_hdr_metadata) {
HdrMetadata hdr_metadata = CreateTestHdrMetadata();
return ColorSpace(
ColorSpace::PrimaryID::kBT709, ColorSpace::TransferID::kGAMMA22,
ColorSpace::MatrixID::kSMPTE2085, ColorSpace::RangeID::kFull,
ColorSpace::ChromaSiting::kCollocated,
ColorSpace::ChromaSiting::kCollocated,
with_hdr_metadata ? &hdr_metadata : nullptr);
}
} // namespace
class CodecEndToEndTest : public test::CallTest,
public testing::WithParamInterface<std::string> {