mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-15 14:50:39 +01:00

Bug: webrtc:10379 Change-Id: I079b419604bf4e9c1994fe203d7db131a0ccddb6 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/125920 Commit-Queue: Niels Moller <nisse@webrtc.org> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Reviewed-by: Kári Helgason <kthelgason@webrtc.org> Reviewed-by: Rasmus Brandt <brandtr@webrtc.org> Reviewed-by: Erik Språng <sprang@webrtc.org> Cr-Commit-Position: refs/heads/master@{#27022}
150 lines
6.1 KiB
C++
150 lines
6.1 KiB
C++
/*
|
|
* Copyright (c) 2017 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 <stdint.h>
|
|
#include <memory>
|
|
|
|
#include "absl/types/optional.h"
|
|
#include "api/video/color_space.h"
|
|
#include "api/video/encoded_image.h"
|
|
#include "api/video/video_frame.h"
|
|
#include "api/video_codecs/video_codec.h"
|
|
#include "api/video_codecs/video_decoder.h"
|
|
#include "api/video_codecs/video_encoder.h"
|
|
#include "common_types.h" // NOLINT(build/include)
|
|
#include "common_video/libyuv/include/webrtc_libyuv.h"
|
|
#include "common_video/test/utilities.h"
|
|
#include "media/base/codec.h"
|
|
#include "media/base/media_constants.h"
|
|
#include "modules/video_coding/codecs/h264/include/h264.h"
|
|
#include "modules/video_coding/codecs/test/video_codec_unittest.h"
|
|
#include "modules/video_coding/include/video_codec_interface.h"
|
|
#include "modules/video_coding/include/video_error_codes.h"
|
|
#include "test/gtest.h"
|
|
#include "test/video_codec_settings.h"
|
|
|
|
namespace webrtc {
|
|
|
|
class TestH264Impl : public VideoCodecUnitTest {
|
|
protected:
|
|
std::unique_ptr<VideoEncoder> CreateEncoder() override {
|
|
return H264Encoder::Create(cricket::VideoCodec(cricket::kH264CodecName));
|
|
}
|
|
|
|
std::unique_ptr<VideoDecoder> CreateDecoder() override {
|
|
return H264Decoder::Create();
|
|
}
|
|
|
|
void ModifyCodecSettings(VideoCodec* codec_settings) override {
|
|
webrtc::test::CodecSettings(kVideoCodecH264, codec_settings);
|
|
}
|
|
};
|
|
|
|
#ifdef WEBRTC_USE_H264
|
|
#define MAYBE_EncodeDecode EncodeDecode
|
|
#define MAYBE_DecodedQpEqualsEncodedQp DecodedQpEqualsEncodedQp
|
|
#define MAYBE_EncodedColorSpaceEqualsInputColorSpace \
|
|
EncodedColorSpaceEqualsInputColorSpace
|
|
#define MAYBE_DecodedColorSpaceEqualsEncodedColorSpace \
|
|
DecodedColorSpaceEqualsEncodedColorSpace
|
|
#else
|
|
#define MAYBE_EncodeDecode DISABLED_EncodeDecode
|
|
#define MAYBE_DecodedQpEqualsEncodedQp DISABLED_DecodedQpEqualsEncodedQp
|
|
#define MAYBE_EncodedColorSpaceEqualsInputColorSpace \
|
|
DISABLED_EncodedColorSpaceEqualsInputColorSpace
|
|
#define MAYBE_DecodedColorSpaceEqualsEncodedColorSpace \
|
|
DISABLED_DecodedColorSpaceEqualsEncodedColorSpace
|
|
#endif
|
|
|
|
TEST_F(TestH264Impl, MAYBE_EncodeDecode) {
|
|
VideoFrame* input_frame = NextInputFrame();
|
|
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, encoder_->Encode(*input_frame, nullptr));
|
|
EncodedImage encoded_frame;
|
|
CodecSpecificInfo codec_specific_info;
|
|
ASSERT_TRUE(WaitForEncodedFrame(&encoded_frame, &codec_specific_info));
|
|
// First frame should be a key frame.
|
|
encoded_frame._frameType = kVideoFrameKey;
|
|
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, decoder_->Decode(encoded_frame, false, 0));
|
|
std::unique_ptr<VideoFrame> decoded_frame;
|
|
absl::optional<uint8_t> decoded_qp;
|
|
ASSERT_TRUE(WaitForDecodedFrame(&decoded_frame, &decoded_qp));
|
|
ASSERT_TRUE(decoded_frame);
|
|
EXPECT_GT(I420PSNR(input_frame, decoded_frame.get()), 36);
|
|
|
|
const ColorSpace color_space = *decoded_frame->color_space();
|
|
EXPECT_EQ(ColorSpace::PrimaryID::kUnspecified, color_space.primaries());
|
|
EXPECT_EQ(ColorSpace::TransferID::kUnspecified, color_space.transfer());
|
|
EXPECT_EQ(ColorSpace::MatrixID::kUnspecified, color_space.matrix());
|
|
EXPECT_EQ(ColorSpace::RangeID::kInvalid, color_space.range());
|
|
EXPECT_EQ(ColorSpace::ChromaSiting::kUnspecified,
|
|
color_space.chroma_siting_horizontal());
|
|
EXPECT_EQ(ColorSpace::ChromaSiting::kUnspecified,
|
|
color_space.chroma_siting_vertical());
|
|
}
|
|
|
|
TEST_F(TestH264Impl, MAYBE_DecodedQpEqualsEncodedQp) {
|
|
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
|
|
encoder_->Encode(*NextInputFrame(), nullptr));
|
|
EncodedImage encoded_frame;
|
|
CodecSpecificInfo codec_specific_info;
|
|
ASSERT_TRUE(WaitForEncodedFrame(&encoded_frame, &codec_specific_info));
|
|
// First frame should be a key frame.
|
|
encoded_frame._frameType = kVideoFrameKey;
|
|
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, decoder_->Decode(encoded_frame, false, 0));
|
|
std::unique_ptr<VideoFrame> decoded_frame;
|
|
absl::optional<uint8_t> decoded_qp;
|
|
ASSERT_TRUE(WaitForDecodedFrame(&decoded_frame, &decoded_qp));
|
|
ASSERT_TRUE(decoded_frame);
|
|
ASSERT_TRUE(decoded_qp);
|
|
EXPECT_EQ(encoded_frame.qp_, *decoded_qp);
|
|
}
|
|
|
|
TEST_F(TestH264Impl, MAYBE_EncodedColorSpaceEqualsInputColorSpace) {
|
|
VideoFrame* input_frame = NextInputFrame();
|
|
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, encoder_->Encode(*input_frame, nullptr));
|
|
EncodedImage encoded_frame;
|
|
CodecSpecificInfo codec_specific_info;
|
|
ASSERT_TRUE(WaitForEncodedFrame(&encoded_frame, &codec_specific_info));
|
|
EXPECT_FALSE(encoded_frame.ColorSpace());
|
|
|
|
// Video frame with explicit color space information.
|
|
ColorSpace color_space = CreateTestColorSpace(/*with_hdr_metadata=*/false);
|
|
VideoFrame input_frame_w_color_space =
|
|
VideoFrame::Builder()
|
|
.set_video_frame_buffer(input_frame->video_frame_buffer())
|
|
.set_color_space(color_space)
|
|
.build();
|
|
|
|
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
|
|
encoder_->Encode(input_frame_w_color_space, nullptr));
|
|
ASSERT_TRUE(WaitForEncodedFrame(&encoded_frame, &codec_specific_info));
|
|
ASSERT_TRUE(encoded_frame.ColorSpace());
|
|
EXPECT_EQ(*encoded_frame.ColorSpace(), color_space);
|
|
}
|
|
|
|
TEST_F(TestH264Impl, MAYBE_DecodedColorSpaceEqualsEncodedColorSpace) {
|
|
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
|
|
encoder_->Encode(*NextInputFrame(), nullptr));
|
|
EncodedImage encoded_frame;
|
|
CodecSpecificInfo codec_specific_info;
|
|
ASSERT_TRUE(WaitForEncodedFrame(&encoded_frame, &codec_specific_info));
|
|
// Add color space to encoded frame.
|
|
ColorSpace color_space = CreateTestColorSpace(/*with_hdr_metadata=*/false);
|
|
encoded_frame.SetColorSpace(color_space);
|
|
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, decoder_->Decode(encoded_frame, false, 0));
|
|
std::unique_ptr<VideoFrame> decoded_frame;
|
|
absl::optional<uint8_t> decoded_qp;
|
|
ASSERT_TRUE(WaitForDecodedFrame(&decoded_frame, &decoded_qp));
|
|
ASSERT_TRUE(decoded_frame);
|
|
ASSERT_TRUE(decoded_frame->color_space());
|
|
EXPECT_EQ(color_space, *decoded_frame->color_space());
|
|
}
|
|
|
|
} // namespace webrtc
|