Repo created

This commit is contained in:
Fr4nz D13trich 2025-11-22 14:04:28 +01:00
parent 81b91f4139
commit f8c34fa5ee
22732 changed files with 4815320 additions and 2 deletions

View file

@ -0,0 +1,56 @@
# 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")
rtc_library("rtc_api_video_unittests") {
testonly = true
sources = [
"color_space_unittest.cc",
"i210_buffer_unittest.cc",
"i410_buffer_unittest.cc",
"i422_buffer_unittest.cc",
"i444_buffer_unittest.cc",
"nv12_buffer_unittest.cc",
"video_adaptation_counters_unittest.cc",
"video_bitrate_allocation_unittest.cc",
]
deps = [
"..:video_adaptation",
"..:video_bitrate_allocation",
"..:video_frame",
"..:video_frame_i010",
"..:video_rtp_headers",
"../../../test:frame_utils",
"../../../test:test_support",
]
absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ]
}
rtc_source_set("mock_recordable_encoded_frame") {
testonly = true
visibility = [ "*" ]
sources = [ "mock_recordable_encoded_frame.h" ]
deps = [
"..:recordable_encoded_frame",
"../../../test:test_support",
]
}
rtc_source_set("video_frame_matchers") {
testonly = true
visibility = [ "*" ]
sources = [ "video_frame_matchers.h" ]
deps = [
"..:video_frame",
"../..:rtp_packet_info",
"../../../test:test_support",
]
}

View file

@ -0,0 +1,83 @@
/*
* 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 "api/video/color_space.h"
#include <stdint.h>
#include "test/gtest.h"
namespace webrtc {
TEST(ColorSpace, TestSettingPrimariesFromUint8) {
ColorSpace color_space;
EXPECT_TRUE(color_space.set_primaries_from_uint8(
static_cast<uint8_t>(ColorSpace::PrimaryID::kBT470BG)));
EXPECT_EQ(ColorSpace::PrimaryID::kBT470BG, color_space.primaries());
EXPECT_FALSE(color_space.set_primaries_from_uint8(3));
EXPECT_FALSE(color_space.set_primaries_from_uint8(23));
EXPECT_FALSE(color_space.set_primaries_from_uint8(64));
}
TEST(ColorSpace, TestSettingTransferFromUint8) {
ColorSpace color_space;
EXPECT_TRUE(color_space.set_transfer_from_uint8(
static_cast<uint8_t>(ColorSpace::TransferID::kBT2020_10)));
EXPECT_EQ(ColorSpace::TransferID::kBT2020_10, color_space.transfer());
EXPECT_FALSE(color_space.set_transfer_from_uint8(3));
EXPECT_FALSE(color_space.set_transfer_from_uint8(19));
EXPECT_FALSE(color_space.set_transfer_from_uint8(128));
}
TEST(ColorSpace, TestSettingMatrixFromUint8) {
ColorSpace color_space;
EXPECT_TRUE(color_space.set_matrix_from_uint8(
static_cast<uint8_t>(ColorSpace::MatrixID::kCDNCLS)));
EXPECT_EQ(ColorSpace::MatrixID::kCDNCLS, color_space.matrix());
EXPECT_FALSE(color_space.set_matrix_from_uint8(3));
EXPECT_FALSE(color_space.set_matrix_from_uint8(15));
EXPECT_FALSE(color_space.set_matrix_from_uint8(255));
}
TEST(ColorSpace, TestSettingRangeFromUint8) {
ColorSpace color_space;
EXPECT_TRUE(color_space.set_range_from_uint8(
static_cast<uint8_t>(ColorSpace::RangeID::kFull)));
EXPECT_EQ(ColorSpace::RangeID::kFull, color_space.range());
EXPECT_FALSE(color_space.set_range_from_uint8(4));
}
TEST(ColorSpace, TestSettingChromaSitingHorizontalFromUint8) {
ColorSpace color_space;
EXPECT_TRUE(color_space.set_chroma_siting_horizontal_from_uint8(
static_cast<uint8_t>(ColorSpace::ChromaSiting::kCollocated)));
EXPECT_EQ(ColorSpace::ChromaSiting::kCollocated,
color_space.chroma_siting_horizontal());
EXPECT_FALSE(color_space.set_chroma_siting_horizontal_from_uint8(3));
}
TEST(ColorSpace, TestSettingChromaSitingVerticalFromUint8) {
ColorSpace color_space;
EXPECT_TRUE(color_space.set_chroma_siting_vertical_from_uint8(
static_cast<uint8_t>(ColorSpace::ChromaSiting::kHalf)));
EXPECT_EQ(ColorSpace::ChromaSiting::kHalf,
color_space.chroma_siting_vertical());
EXPECT_FALSE(color_space.set_chroma_siting_vertical_from_uint8(3));
}
TEST(ColorSpace, TestAsStringFunction) {
ColorSpace color_space(
ColorSpace::PrimaryID::kBT709, ColorSpace::TransferID::kBT709,
ColorSpace::MatrixID::kBT709, ColorSpace::RangeID::kLimited);
EXPECT_EQ(
color_space.AsString(),
"{primaries:kBT709, transfer:kBT709, matrix:kBT709, range:kLimited}");
}
} // namespace webrtc

View file

@ -0,0 +1,126 @@
/*
* Copyright (c) 2022 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 "api/video/i210_buffer.h"
#include "api/video/i420_buffer.h"
#include "test/frame_utils.h"
#include "test/gmock.h"
#include "test/gtest.h"
namespace webrtc {
namespace {
int GetY(rtc::scoped_refptr<I210BufferInterface> buf, int col, int row) {
return buf->DataY()[row * buf->StrideY() + col];
}
int GetU(rtc::scoped_refptr<I210BufferInterface> buf, int col, int row) {
return buf->DataU()[row * buf->StrideU() + col];
}
int GetV(rtc::scoped_refptr<I210BufferInterface> buf, int col, int row) {
return buf->DataV()[row * buf->StrideV() + col];
}
void FillI210Buffer(rtc::scoped_refptr<I210Buffer> buf) {
const uint16_t Y = 4;
const uint16_t U = 8;
const uint16_t V = 16;
for (int row = 0; row < buf->height(); ++row) {
for (int col = 0; col < buf->width(); ++col) {
buf->MutableDataY()[row * buf->StrideY() + col] = Y;
}
}
for (int row = 0; row < buf->ChromaHeight(); ++row) {
for (int col = 0; col < buf->ChromaWidth(); ++col) {
buf->MutableDataU()[row * buf->StrideU() + col] = U;
buf->MutableDataV()[row * buf->StrideV() + col] = V;
}
}
}
} // namespace
TEST(I210BufferTest, InitialData) {
constexpr int stride = 3;
constexpr int halfstride = (stride + 1) >> 1;
constexpr int width = 3;
constexpr int halfwidth = (width + 1) >> 1;
constexpr int height = 3;
rtc::scoped_refptr<I210Buffer> i210_buffer(I210Buffer::Create(width, height));
EXPECT_EQ(width, i210_buffer->width());
EXPECT_EQ(height, i210_buffer->height());
EXPECT_EQ(stride, i210_buffer->StrideY());
EXPECT_EQ(halfstride, i210_buffer->StrideU());
EXPECT_EQ(halfstride, i210_buffer->StrideV());
EXPECT_EQ(halfwidth, i210_buffer->ChromaWidth());
EXPECT_EQ(height, i210_buffer->ChromaHeight());
}
TEST(I210BufferTest, ReadPixels) {
constexpr int width = 3;
constexpr int halfwidth = (width + 1) >> 1;
constexpr int height = 3;
rtc::scoped_refptr<I210Buffer> i210_buffer(I210Buffer::Create(width, height));
// Y = 4, U = 8, V = 16.
FillI210Buffer(i210_buffer);
for (int row = 0; row < height; row++) {
for (int col = 0; col < width; col++) {
EXPECT_EQ(4, GetY(i210_buffer, col, row));
}
}
for (int row = 0; row < height; row++) {
for (int col = 0; col < halfwidth; col++) {
EXPECT_EQ(8, GetU(i210_buffer, col, row));
EXPECT_EQ(16, GetV(i210_buffer, col, row));
}
}
}
TEST(I210BufferTest, ToI420) {
constexpr int width = 3;
constexpr int halfwidth = (width + 1) >> 1;
constexpr int height = 3;
constexpr int size = width * height;
constexpr int quartersize = (width + 1) / 2 * (height + 1) / 2;
rtc::scoped_refptr<I420Buffer> reference(I420Buffer::Create(width, height));
memset(reference->MutableDataY(), 1, size);
memset(reference->MutableDataU(), 2, quartersize);
memset(reference->MutableDataV(), 4, quartersize);
rtc::scoped_refptr<I210Buffer> i210_buffer(I210Buffer::Create(width, height));
// Y = 4, U = 8, V = 16.
FillI210Buffer(i210_buffer);
// Confirm YUV values are as expected.
for (int row = 0; row < height; row++) {
for (int col = 0; col < width; col++) {
EXPECT_EQ(4, GetY(i210_buffer, col, row));
}
}
for (int row = 0; row < height; row++) {
for (int col = 0; col < halfwidth; col++) {
EXPECT_EQ(8, GetU(i210_buffer, col, row));
EXPECT_EQ(16, GetV(i210_buffer, col, row));
}
}
rtc::scoped_refptr<I420BufferInterface> i420_buffer(i210_buffer->ToI420());
EXPECT_TRUE(test::FrameBufsEqual(reference, i420_buffer));
EXPECT_EQ(height, i420_buffer->height());
EXPECT_EQ(width, i420_buffer->width());
}
} // namespace webrtc

View file

@ -0,0 +1,120 @@
/*
* Copyright (c) 2023 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 "api/video/i410_buffer.h"
#include "api/video/i420_buffer.h"
#include "test/frame_utils.h"
#include "test/gmock.h"
#include "test/gtest.h"
namespace webrtc {
namespace {
constexpr uint16_t kYValue = 4;
constexpr uint16_t kUValue = 8;
constexpr uint16_t kVValue = 16;
int GetY(rtc::scoped_refptr<I410BufferInterface> buf, int col, int row) {
return buf->DataY()[row * buf->StrideY() + col];
}
int GetU(rtc::scoped_refptr<I410BufferInterface> buf, int col, int row) {
return buf->DataU()[row * buf->StrideU() + col];
}
int GetV(rtc::scoped_refptr<I410BufferInterface> buf, int col, int row) {
return buf->DataV()[row * buf->StrideV() + col];
}
void FillI410Buffer(rtc::scoped_refptr<I410Buffer> buf) {
for (int row = 0; row < buf->height(); ++row) {
for (int col = 0; col < buf->width(); ++col) {
buf->MutableDataY()[row * buf->StrideY() + col] = kYValue;
buf->MutableDataU()[row * buf->StrideU() + col] = kUValue;
buf->MutableDataV()[row * buf->StrideV() + col] = kVValue;
}
}
}
} // namespace
TEST(I410BufferTest, InitialData) {
constexpr int stride = 3;
constexpr int width = 3;
constexpr int height = 3;
rtc::scoped_refptr<I410Buffer> i410_buffer(I410Buffer::Create(width, height));
EXPECT_EQ(width, i410_buffer->width());
EXPECT_EQ(height, i410_buffer->height());
EXPECT_EQ(stride, i410_buffer->StrideY());
EXPECT_EQ(stride, i410_buffer->StrideU());
EXPECT_EQ(stride, i410_buffer->StrideV());
EXPECT_EQ(3, i410_buffer->ChromaWidth());
EXPECT_EQ(3, i410_buffer->ChromaHeight());
}
TEST(I410BufferTest, ReadPixels) {
constexpr int width = 3;
constexpr int height = 3;
rtc::scoped_refptr<I410Buffer> i410_buffer(I410Buffer::Create(width, height));
FillI410Buffer(i410_buffer);
for (int row = 0; row < height; row++) {
for (int col = 0; col < width; col++) {
EXPECT_EQ(kYValue, GetY(i410_buffer, col, row));
EXPECT_EQ(kUValue, GetU(i410_buffer, col, row));
EXPECT_EQ(kVValue, GetV(i410_buffer, col, row));
}
}
}
TEST(I410BufferTest, ToI420) {
// libyuv I410ToI420 only handles correctly even sizes and skips last row/col
// if odd.
constexpr int width = 4;
constexpr int height = 4;
constexpr int size_y = width * height;
constexpr int size_u = (width + 1) / 2 * (height + 1) / 2;
constexpr int size_v = (width + 1) / 2 * (height + 1) / 2;
rtc::scoped_refptr<I420Buffer> reference(I420Buffer::Create(width, height));
// I410 is 10-bit while I420 is 8 bit, so last 2 bits would be discarded.
memset(reference->MutableDataY(), kYValue >> 2, size_y);
memset(reference->MutableDataU(), kUValue >> 2, size_u);
memset(reference->MutableDataV(), kVValue >> 2, size_v);
rtc::scoped_refptr<I410Buffer> i410_buffer(I410Buffer::Create(width, height));
FillI410Buffer(i410_buffer);
// Confirm YUV values are as expected.
for (int row = 0; row < height; row++) {
for (int col = 0; col < width; col++) {
EXPECT_EQ(kYValue, GetY(i410_buffer, col, row));
EXPECT_EQ(kUValue, GetU(i410_buffer, col, row));
EXPECT_EQ(kVValue, GetV(i410_buffer, col, row));
}
}
rtc::scoped_refptr<I420BufferInterface> i420_buffer(i410_buffer->ToI420());
// Confirm YUV values are as expected.
for (int row = 0; row < height; row++) {
for (int col = 0; col < width; col++) {
EXPECT_EQ(1, i420_buffer->DataY()[row * i420_buffer->StrideY() + col]);
}
}
EXPECT_EQ(height, i420_buffer->height());
EXPECT_EQ(width, i420_buffer->width());
EXPECT_TRUE(test::FrameBufsEqual(reference, i420_buffer));
}
} // namespace webrtc

View file

@ -0,0 +1,128 @@
/*
* Copyright (c) 2022 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 "api/video/i422_buffer.h"
#include "api/video/i420_buffer.h"
#include "test/frame_utils.h"
#include "test/gmock.h"
#include "test/gtest.h"
namespace webrtc {
namespace {
int GetY(rtc::scoped_refptr<I422BufferInterface> buf, int col, int row) {
return buf->DataY()[row * buf->StrideY() + col];
}
int GetU(rtc::scoped_refptr<I422BufferInterface> buf, int col, int row) {
return buf->DataU()[row * buf->StrideU() + col];
}
int GetV(rtc::scoped_refptr<I422BufferInterface> buf, int col, int row) {
return buf->DataV()[row * buf->StrideV() + col];
}
void FillI422Buffer(rtc::scoped_refptr<I422Buffer> buf) {
const uint8_t Y = 1;
const uint8_t U = 2;
const uint8_t V = 3;
for (int row = 0; row < buf->height(); ++row) {
for (int col = 0; col < buf->width(); ++col) {
buf->MutableDataY()[row * buf->StrideY() + col] = Y;
}
}
for (int row = 0; row < buf->ChromaHeight(); ++row) {
for (int col = 0; col < buf->ChromaWidth(); ++col) {
buf->MutableDataU()[row * buf->StrideU() + col] = U;
buf->MutableDataV()[row * buf->StrideV() + col] = V;
}
}
}
} // namespace
TEST(I422BufferTest, InitialData) {
constexpr int stride = 3;
constexpr int halfstride = (stride + 1) >> 1;
constexpr int width = 3;
constexpr int halfwidth = (width + 1) >> 1;
constexpr int height = 3;
rtc::scoped_refptr<I422Buffer> i422_buffer(I422Buffer::Create(width, height));
EXPECT_EQ(width, i422_buffer->width());
EXPECT_EQ(height, i422_buffer->height());
EXPECT_EQ(stride, i422_buffer->StrideY());
EXPECT_EQ(halfstride, i422_buffer->StrideU());
EXPECT_EQ(halfstride, i422_buffer->StrideV());
EXPECT_EQ(halfwidth, i422_buffer->ChromaWidth());
EXPECT_EQ(height, i422_buffer->ChromaHeight());
}
TEST(I422BufferTest, ReadPixels) {
constexpr int width = 3;
constexpr int halfwidth = (width + 1) >> 1;
constexpr int height = 3;
rtc::scoped_refptr<I422Buffer> i422_buffer(I422Buffer::Create(width, height));
// Y = 1, U = 2, V = 3.
FillI422Buffer(i422_buffer);
for (int row = 0; row < height; row++) {
for (int col = 0; col < width; col++) {
EXPECT_EQ(1, GetY(i422_buffer, col, row));
}
}
for (int row = 0; row < height; row++) {
for (int col = 0; col < halfwidth; col++) {
EXPECT_EQ(2, GetU(i422_buffer, col, row));
EXPECT_EQ(3, GetV(i422_buffer, col, row));
}
}
}
TEST(I422BufferTest, ToI420) {
constexpr int width = 3;
constexpr int halfwidth = (width + 1) >> 1;
constexpr int height = 3;
constexpr int size = width * height;
constexpr int halfsize = (width + 1) / 2 * height;
constexpr int quartersize = (width + 1) / 2 * (height + 1) / 2;
rtc::scoped_refptr<I420Buffer> reference(I420Buffer::Create(width, height));
memset(reference->MutableDataY(), 8, size);
memset(reference->MutableDataU(), 4, quartersize);
memset(reference->MutableDataV(), 2, quartersize);
rtc::scoped_refptr<I422Buffer> i422_buffer(I422Buffer::Create(width, height));
// Convert the reference buffer to I422.
memset(i422_buffer->MutableDataY(), 8, size);
memset(i422_buffer->MutableDataU(), 4, halfsize);
memset(i422_buffer->MutableDataV(), 2, halfsize);
// Confirm YUV values are as expected.
for (int row = 0; row < height; row++) {
for (int col = 0; col < width; col++) {
EXPECT_EQ(8, GetY(i422_buffer, col, row));
}
}
for (int row = 0; row < height; row++) {
for (int col = 0; col < halfwidth; col++) {
EXPECT_EQ(4, GetU(i422_buffer, col, row));
EXPECT_EQ(2, GetV(i422_buffer, col, row));
}
}
rtc::scoped_refptr<I420BufferInterface> i420_buffer(i422_buffer->ToI420());
EXPECT_EQ(height, i420_buffer->height());
EXPECT_EQ(width, i420_buffer->width());
EXPECT_TRUE(test::FrameBufsEqual(reference, i420_buffer));
}
} // namespace webrtc

View file

@ -0,0 +1,112 @@
/*
* 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 "api/video/i444_buffer.h"
#include "api/video/i420_buffer.h"
#include "test/frame_utils.h"
#include "test/gmock.h"
#include "test/gtest.h"
namespace webrtc {
namespace {
int GetY(rtc::scoped_refptr<I444BufferInterface> buf, int col, int row) {
return buf->DataY()[row * buf->StrideY() + col];
}
int GetU(rtc::scoped_refptr<I444BufferInterface> buf, int col, int row) {
return buf->DataU()[row * buf->StrideU() + col];
}
int GetV(rtc::scoped_refptr<I444BufferInterface> buf, int col, int row) {
return buf->DataV()[row * buf->StrideV() + col];
}
void FillI444Buffer(rtc::scoped_refptr<I444Buffer> buf) {
const uint8_t Y = 1;
const uint8_t U = 2;
const uint8_t V = 3;
for (int row = 0; row < buf->height(); ++row) {
for (int col = 0; col < buf->width(); ++col) {
buf->MutableDataY()[row * buf->StrideY() + col] = Y;
buf->MutableDataU()[row * buf->StrideU() + col] = U;
buf->MutableDataV()[row * buf->StrideV() + col] = V;
}
}
}
} // namespace
TEST(I444BufferTest, InitialData) {
constexpr int stride = 3;
constexpr int width = 3;
constexpr int height = 3;
rtc::scoped_refptr<I444Buffer> i444_buffer(I444Buffer::Create(width, height));
EXPECT_EQ(width, i444_buffer->width());
EXPECT_EQ(height, i444_buffer->height());
EXPECT_EQ(stride, i444_buffer->StrideY());
EXPECT_EQ(stride, i444_buffer->StrideU());
EXPECT_EQ(stride, i444_buffer->StrideV());
EXPECT_EQ(3, i444_buffer->ChromaWidth());
EXPECT_EQ(3, i444_buffer->ChromaHeight());
}
TEST(I444BufferTest, ReadPixels) {
constexpr int width = 3;
constexpr int height = 3;
rtc::scoped_refptr<I444Buffer> i444_buffer(I444Buffer::Create(width, height));
// Y = 1, U = 2, V = 3.
FillI444Buffer(i444_buffer);
for (int row = 0; row < height; row++) {
for (int col = 0; col < width; col++) {
EXPECT_EQ(1, GetY(i444_buffer, col, row));
EXPECT_EQ(2, GetU(i444_buffer, col, row));
EXPECT_EQ(3, GetV(i444_buffer, col, row));
}
}
}
TEST(I444BufferTest, ToI420) {
constexpr int width = 3;
constexpr int height = 3;
constexpr int size_y = width * height;
constexpr int size_u = (width + 1) / 2 * (height + 1) / 2;
constexpr int size_v = (width + 1) / 2 * (height + 1) / 2;
rtc::scoped_refptr<I420Buffer> reference(I420Buffer::Create(width, height));
memset(reference->MutableDataY(), 8, size_y);
memset(reference->MutableDataU(), 4, size_u);
memset(reference->MutableDataV(), 2, size_v);
rtc::scoped_refptr<I444Buffer> i444_buffer(I444Buffer::Create(width, height));
// Convert the reference buffer to I444.
memset(i444_buffer->MutableDataY(), 8, size_y);
memset(i444_buffer->MutableDataU(), 4, size_y);
memset(i444_buffer->MutableDataV(), 2, size_y);
// Confirm YUV values are as expected.
for (int row = 0; row < height; row++) {
for (int col = 0; col < width; col++) {
EXPECT_EQ(8, GetY(i444_buffer, col, row));
EXPECT_EQ(4, GetU(i444_buffer, col, row));
EXPECT_EQ(2, GetV(i444_buffer, col, row));
}
}
rtc::scoped_refptr<I420BufferInterface> i420_buffer(i444_buffer->ToI420());
EXPECT_EQ(height, i420_buffer->height());
EXPECT_EQ(width, i420_buffer->width());
EXPECT_TRUE(test::FrameBufsEqual(reference, i420_buffer));
}
} // namespace webrtc

View file

@ -0,0 +1,34 @@
/*
* Copyright (c) 2019 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 API_VIDEO_TEST_MOCK_RECORDABLE_ENCODED_FRAME_H_
#define API_VIDEO_TEST_MOCK_RECORDABLE_ENCODED_FRAME_H_
#include "api/video/recordable_encoded_frame.h"
#include "test/gmock.h"
namespace webrtc {
class MockRecordableEncodedFrame : public RecordableEncodedFrame {
public:
MOCK_METHOD(rtc::scoped_refptr<const EncodedImageBufferInterface>,
encoded_buffer,
(),
(const, override));
MOCK_METHOD(absl::optional<webrtc::ColorSpace>,
color_space,
(),
(const, override));
MOCK_METHOD(VideoCodecType, codec, (), (const, override));
MOCK_METHOD(bool, is_key_frame, (), (const, override));
MOCK_METHOD(EncodedResolution, resolution, (), (const, override));
MOCK_METHOD(Timestamp, render_time, (), (const, override));
};
} // namespace webrtc
#endif // API_VIDEO_TEST_MOCK_RECORDABLE_ENCODED_FRAME_H_

View file

@ -0,0 +1,119 @@
/*
* Copyright (c) 2020 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 "api/video/nv12_buffer.h"
#include "api/video/i420_buffer.h"
#include "test/frame_utils.h"
#include "test/gmock.h"
#include "test/gtest.h"
namespace webrtc {
namespace {
int GetY(rtc::scoped_refptr<NV12BufferInterface> buf, int col, int row) {
return buf->DataY()[row * buf->StrideY() + col];
}
int GetU(rtc::scoped_refptr<NV12BufferInterface> buf, int col, int row) {
return buf->DataUV()[(row / 2) * buf->StrideUV() + (col / 2) * 2];
}
int GetV(rtc::scoped_refptr<NV12BufferInterface> buf, int col, int row) {
return buf->DataUV()[(row / 2) * buf->StrideUV() + (col / 2) * 2 + 1];
}
void FillNV12Buffer(rtc::scoped_refptr<NV12Buffer> buf) {
const uint8_t Y = 1;
const uint8_t U = 2;
const uint8_t V = 3;
for (int row = 0; row < buf->height(); ++row) {
for (int col = 0; col < buf->width(); ++col) {
buf->MutableDataY()[row * buf->StrideY() + col] = Y;
}
}
// Fill interleaving UV values.
for (int row = 0; row < buf->ChromaHeight(); row++) {
for (int col = 0; col < buf->StrideUV(); col += 2) {
int uv_index = row * buf->StrideUV() + col;
buf->MutableDataUV()[uv_index] = U;
buf->MutableDataUV()[uv_index + 1] = V;
}
}
}
} // namespace
TEST(NV12BufferTest, InitialData) {
constexpr int stride_y = 3;
constexpr int stride_uv = 4;
constexpr int width = 3;
constexpr int height = 3;
rtc::scoped_refptr<NV12Buffer> nv12_buffer(NV12Buffer::Create(width, height));
EXPECT_EQ(width, nv12_buffer->width());
EXPECT_EQ(height, nv12_buffer->height());
EXPECT_EQ(stride_y, nv12_buffer->StrideY());
EXPECT_EQ(stride_uv, nv12_buffer->StrideUV());
EXPECT_EQ(2, nv12_buffer->ChromaWidth());
EXPECT_EQ(2, nv12_buffer->ChromaHeight());
}
TEST(NV12BufferTest, ReadPixels) {
constexpr int width = 3;
constexpr int height = 3;
rtc::scoped_refptr<NV12Buffer> nv12_buffer(NV12Buffer::Create(width, height));
// Y = 1, U = 2, V = 3.
FillNV12Buffer(nv12_buffer);
for (int row = 0; row < height; row++) {
for (int col = 0; col < width; col++) {
EXPECT_EQ(1, GetY(nv12_buffer, col, row));
EXPECT_EQ(2, GetU(nv12_buffer, col, row));
EXPECT_EQ(3, GetV(nv12_buffer, col, row));
}
}
}
TEST(NV12BufferTest, ToI420) {
constexpr int width = 3;
constexpr int height = 3;
constexpr int size_y = width * height;
constexpr int size_u = (width + 1) / 2 * (height + 1) / 2;
constexpr int size_v = (width + 1) / 2 * (height + 1) / 2;
rtc::scoped_refptr<I420Buffer> reference(I420Buffer::Create(width, height));
memset(reference->MutableDataY(), 8, size_y);
memset(reference->MutableDataU(), 4, size_u);
memset(reference->MutableDataV(), 2, size_v);
rtc::scoped_refptr<NV12Buffer> nv12_buffer(NV12Buffer::Create(width, height));
// Convert the reference buffer to NV12.
memset(nv12_buffer->MutableDataY(), 8, size_y);
// Interleaving u/v values.
for (int i = 0; i < size_u + size_v; i += 2) {
nv12_buffer->MutableDataUV()[i] = 4;
nv12_buffer->MutableDataUV()[i + 1] = 2;
}
// Confirm YUV values are as expected.
for (int row = 0; row < height; row++) {
for (int col = 0; col < width; col++) {
EXPECT_EQ(8, GetY(nv12_buffer, col, row));
EXPECT_EQ(4, GetU(nv12_buffer, col, row));
EXPECT_EQ(2, GetV(nv12_buffer, col, row));
}
}
rtc::scoped_refptr<I420BufferInterface> i420_buffer(nv12_buffer->ToI420());
EXPECT_EQ(height, i420_buffer->height());
EXPECT_EQ(width, i420_buffer->width());
EXPECT_TRUE(test::FrameBufsEqual(reference, i420_buffer));
}
} // namespace webrtc

View file

@ -0,0 +1,32 @@
/*
* Copyright (c) 2020 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 "api/video/video_adaptation_counters.h"
#include "test/gtest.h"
namespace webrtc {
TEST(AdaptationCountersTest, Addition) {
VideoAdaptationCounters a{0, 0};
VideoAdaptationCounters b{1, 2};
VideoAdaptationCounters total = a + b;
EXPECT_EQ(1, total.resolution_adaptations);
EXPECT_EQ(2, total.fps_adaptations);
}
TEST(AdaptationCountersTest, Equality) {
VideoAdaptationCounters a{1, 2};
VideoAdaptationCounters b{2, 1};
EXPECT_EQ(a, a);
EXPECT_NE(a, b);
}
} // namespace webrtc

View file

@ -0,0 +1,64 @@
/*
* 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 "api/video/video_bitrate_allocation.h"
#include <vector>
#include "absl/types/optional.h"
#include "test/gtest.h"
namespace webrtc {
TEST(VideoBitrateAllocation, SimulcastTargetBitrate) {
VideoBitrateAllocation bitrate;
bitrate.SetBitrate(0, 0, 10000);
bitrate.SetBitrate(0, 1, 20000);
bitrate.SetBitrate(1, 0, 40000);
bitrate.SetBitrate(1, 1, 80000);
VideoBitrateAllocation layer0_bitrate;
layer0_bitrate.SetBitrate(0, 0, 10000);
layer0_bitrate.SetBitrate(0, 1, 20000);
VideoBitrateAllocation layer1_bitrate;
layer1_bitrate.SetBitrate(0, 0, 40000);
layer1_bitrate.SetBitrate(0, 1, 80000);
std::vector<absl::optional<VideoBitrateAllocation>> layer_allocations =
bitrate.GetSimulcastAllocations();
EXPECT_EQ(layer0_bitrate, layer_allocations[0]);
EXPECT_EQ(layer1_bitrate, layer_allocations[1]);
}
TEST(VideoBitrateAllocation, SimulcastTargetBitrateWithInactiveStream) {
// Create bitrate allocation with bitrate only for the first and third stream.
VideoBitrateAllocation bitrate;
bitrate.SetBitrate(0, 0, 10000);
bitrate.SetBitrate(0, 1, 20000);
bitrate.SetBitrate(2, 0, 40000);
bitrate.SetBitrate(2, 1, 80000);
VideoBitrateAllocation layer0_bitrate;
layer0_bitrate.SetBitrate(0, 0, 10000);
layer0_bitrate.SetBitrate(0, 1, 20000);
VideoBitrateAllocation layer2_bitrate;
layer2_bitrate.SetBitrate(0, 0, 40000);
layer2_bitrate.SetBitrate(0, 1, 80000);
std::vector<absl::optional<VideoBitrateAllocation>> layer_allocations =
bitrate.GetSimulcastAllocations();
EXPECT_EQ(layer0_bitrate, layer_allocations[0]);
EXPECT_FALSE(layer_allocations[1]);
EXPECT_EQ(layer2_bitrate, layer_allocations[2]);
}
} // namespace webrtc

View file

@ -0,0 +1,34 @@
/*
* Copyright (c) 2022 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 API_VIDEO_TEST_VIDEO_FRAME_MATCHERS_H_
#define API_VIDEO_TEST_VIDEO_FRAME_MATCHERS_H_
#include "api/rtp_packet_infos.h"
#include "api/video/video_frame.h"
#include "test/gmock.h"
namespace webrtc::test::video_frame_matchers {
MATCHER_P(Rotation, rotation, "") {
return ::testing::Matches(::testing::Eq(rotation))(arg.rotation());
}
MATCHER_P(NtpTimestamp, ntp_ts, "") {
return arg.ntp_time_ms() == ntp_ts.ms();
}
MATCHER_P(PacketInfos, m, "") {
return ::testing::Matches(m)(arg.packet_infos());
}
} // namespace webrtc::test::video_frame_matchers
#endif // API_VIDEO_TEST_VIDEO_FRAME_MATCHERS_H_