Update VideoCapturerTrackSourceTest to deliver frames via TaskQueue.
This is inline with how other peerconnection tests run. Bug: webrtc:8848 Change-Id: Idd32a1000f00e3620220527fd60b83c6f03fdcaa Reviewed-on: https://webrtc-review.googlesource.com/48140 Reviewed-by: Per Kjellander <perkj@webrtc.org> Commit-Queue: Tommi <tommi@webrtc.org> Cr-Commit-Position: refs/heads/master@{#21935}
This commit is contained in:
@ -499,6 +499,7 @@ if (rtc_include_tests) {
|
||||
"../rtc_base:rtc_base_approved",
|
||||
"../rtc_base:rtc_base_tests_main",
|
||||
"../rtc_base:rtc_base_tests_utils",
|
||||
"../rtc_base:rtc_task_queue_api",
|
||||
"../system_wrappers:metrics_default",
|
||||
"../system_wrappers:runtime_enabled_features_default",
|
||||
"../test:audio_codec_mocks",
|
||||
|
@ -18,13 +18,18 @@
|
||||
#include "media/base/fakevideocapturer.h"
|
||||
#include "media/base/fakevideorenderer.h"
|
||||
#include "pc/videocapturertracksource.h"
|
||||
#include "rtc_base/arraysize.h"
|
||||
#include "rtc_base/event.h"
|
||||
#include "rtc_base/gunit.h"
|
||||
#include "rtc_base/task_queue.h"
|
||||
|
||||
using cricket::FOURCC_I420;
|
||||
using cricket::VideoFormat;
|
||||
using webrtc::FakeConstraints;
|
||||
using webrtc::VideoCapturerTrackSource;
|
||||
using webrtc::MediaConstraintsInterface;
|
||||
using webrtc::MediaSourceInterface;
|
||||
using webrtc::ObserverInterface;
|
||||
using webrtc::VideoCapturerTrackSource;
|
||||
using webrtc::VideoTrackSourceInterface;
|
||||
|
||||
namespace {
|
||||
@ -42,23 +47,13 @@ class TestVideoCapturer : public cricket::FakeVideoCapturer {
|
||||
public:
|
||||
explicit TestVideoCapturer(bool is_screencast)
|
||||
: FakeVideoCapturer(is_screencast), test_without_formats_(false) {
|
||||
std::vector<cricket::VideoFormat> formats;
|
||||
formats.push_back(
|
||||
cricket::VideoFormat(1280, 720, cricket::VideoFormat::FpsToInterval(30),
|
||||
cricket::FOURCC_I420));
|
||||
formats.push_back(
|
||||
cricket::VideoFormat(640, 480, cricket::VideoFormat::FpsToInterval(30),
|
||||
cricket::FOURCC_I420));
|
||||
formats.push_back(
|
||||
cricket::VideoFormat(640, 400, cricket::VideoFormat::FpsToInterval(30),
|
||||
cricket::FOURCC_I420));
|
||||
formats.push_back(
|
||||
cricket::VideoFormat(320, 240, cricket::VideoFormat::FpsToInterval(30),
|
||||
cricket::FOURCC_I420));
|
||||
formats.push_back(
|
||||
cricket::VideoFormat(352, 288, cricket::VideoFormat::FpsToInterval(30),
|
||||
cricket::FOURCC_I420));
|
||||
ResetSupportedFormats(formats);
|
||||
static const auto fps = VideoFormat::FpsToInterval(30);
|
||||
static const VideoFormat formats[] = {
|
||||
{1280, 720, fps, FOURCC_I420}, {640, 480, fps, FOURCC_I420},
|
||||
{640, 400, fps, FOURCC_I420}, {320, 240, fps, FOURCC_I420},
|
||||
{352, 288, fps, FOURCC_I420},
|
||||
};
|
||||
ResetSupportedFormats({&formats[0], &formats[arraysize(formats)]});
|
||||
}
|
||||
|
||||
// This function is used for resetting the supported capture formats and
|
||||
@ -67,22 +62,21 @@ class TestVideoCapturer : public cricket::FakeVideoCapturer {
|
||||
// Chrome implementation.
|
||||
void TestWithoutCameraFormats() {
|
||||
test_without_formats_ = true;
|
||||
std::vector<cricket::VideoFormat> formats;
|
||||
std::vector<VideoFormat> formats;
|
||||
ResetSupportedFormats(formats);
|
||||
}
|
||||
|
||||
virtual cricket::CaptureState Start(
|
||||
const cricket::VideoFormat& capture_format) {
|
||||
virtual cricket::CaptureState Start(const VideoFormat& capture_format) {
|
||||
if (test_without_formats_) {
|
||||
std::vector<cricket::VideoFormat> formats;
|
||||
std::vector<VideoFormat> formats;
|
||||
formats.push_back(capture_format);
|
||||
ResetSupportedFormats(formats);
|
||||
}
|
||||
return FakeVideoCapturer::Start(capture_format);
|
||||
}
|
||||
|
||||
virtual bool GetBestCaptureFormat(const cricket::VideoFormat& desired,
|
||||
cricket::VideoFormat* best_format) {
|
||||
virtual bool GetBestCaptureFormat(const VideoFormat& desired,
|
||||
VideoFormat* best_format) {
|
||||
if (test_without_formats_) {
|
||||
*best_format = desired;
|
||||
return true;
|
||||
@ -131,6 +125,16 @@ class VideoCapturerTrackSourceTest : public testing::Test {
|
||||
source_->AddOrUpdateSink(&renderer_, rtc::VideoSinkWants());
|
||||
}
|
||||
|
||||
void CaptureSingleFrame() {
|
||||
rtc::Event event(false, false);
|
||||
task_queue_.PostTask([this, &event]() {
|
||||
ASSERT_TRUE(capturer_->CaptureFrame());
|
||||
event.Set();
|
||||
});
|
||||
event.Wait(rtc::Event::kForever);
|
||||
}
|
||||
|
||||
rtc::TaskQueue task_queue_{"VideoCapturerTrackSourceTest"};
|
||||
std::unique_ptr<cricket::VideoCapturer> capturer_cleanup_;
|
||||
TestVideoCapturer* capturer_;
|
||||
cricket::FakeVideoRenderer renderer_;
|
||||
@ -147,7 +151,7 @@ TEST_F(VideoCapturerTrackSourceTest, CapturerStartStop) {
|
||||
EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(),
|
||||
kMaxWaitMs);
|
||||
|
||||
ASSERT_TRUE(capturer_->CaptureFrame());
|
||||
CaptureSingleFrame();
|
||||
EXPECT_EQ(1, renderer_.num_rendered_frames());
|
||||
|
||||
capturer_->Stop();
|
||||
@ -178,7 +182,7 @@ TEST_F(VideoCapturerTrackSourceTest, MandatoryConstraintCif5Fps) {
|
||||
CreateVideoCapturerSource(&constraints);
|
||||
EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(),
|
||||
kMaxWaitMs);
|
||||
const cricket::VideoFormat* format = capturer_->GetCaptureFormat();
|
||||
const VideoFormat* format = capturer_->GetCaptureFormat();
|
||||
ASSERT_TRUE(format != NULL);
|
||||
EXPECT_EQ(352, format->width);
|
||||
EXPECT_EQ(288, format->height);
|
||||
@ -198,7 +202,7 @@ TEST_F(VideoCapturerTrackSourceTest, MandatoryMinVgaOptional720P) {
|
||||
CreateVideoCapturerSource(&constraints);
|
||||
EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(),
|
||||
kMaxWaitMs);
|
||||
const cricket::VideoFormat* format = capturer_->GetCaptureFormat();
|
||||
const VideoFormat* format = capturer_->GetCaptureFormat();
|
||||
ASSERT_TRUE(format != NULL);
|
||||
EXPECT_EQ(1280, format->width);
|
||||
EXPECT_EQ(720, format->height);
|
||||
@ -219,7 +223,7 @@ TEST_F(VideoCapturerTrackSourceTest, MandatoryAspectRatio4To3) {
|
||||
CreateVideoCapturerSource(&constraints);
|
||||
EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(),
|
||||
kMaxWaitMs);
|
||||
const cricket::VideoFormat* format = capturer_->GetCaptureFormat();
|
||||
const VideoFormat* format = capturer_->GetCaptureFormat();
|
||||
ASSERT_TRUE(format != NULL);
|
||||
EXPECT_EQ(640, format->width);
|
||||
EXPECT_EQ(480, format->height);
|
||||
@ -244,7 +248,7 @@ TEST_F(VideoCapturerTrackSourceTest, OptionalAspectRatioTooHigh) {
|
||||
CreateVideoCapturerSource(&constraints);
|
||||
EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(),
|
||||
kMaxWaitMs);
|
||||
const cricket::VideoFormat* format = capturer_->GetCaptureFormat();
|
||||
const VideoFormat* format = capturer_->GetCaptureFormat();
|
||||
ASSERT_TRUE(format != NULL);
|
||||
double aspect_ratio = static_cast<double>(format->width) / format->height;
|
||||
EXPECT_LT(aspect_ratio, 2);
|
||||
@ -258,7 +262,7 @@ TEST_F(VideoCapturerTrackSourceTest, NoCameraCapability) {
|
||||
CreateVideoCapturerSource();
|
||||
EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(),
|
||||
kMaxWaitMs);
|
||||
const cricket::VideoFormat* format = capturer_->GetCaptureFormat();
|
||||
const VideoFormat* format = capturer_->GetCaptureFormat();
|
||||
ASSERT_TRUE(format != NULL);
|
||||
EXPECT_EQ(640, format->width);
|
||||
EXPECT_EQ(480, format->height);
|
||||
@ -280,7 +284,7 @@ TEST_F(VideoCapturerTrackSourceTest, NoCameraCapability16To9Ratio) {
|
||||
CreateVideoCapturerSource(&constraints);
|
||||
EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(),
|
||||
kMaxWaitMs);
|
||||
const cricket::VideoFormat* format = capturer_->GetCaptureFormat();
|
||||
const VideoFormat* format = capturer_->GetCaptureFormat();
|
||||
double aspect_ratio = static_cast<double>(format->width) / format->height;
|
||||
EXPECT_LE(requested_aspect_ratio, aspect_ratio);
|
||||
}
|
||||
@ -395,7 +399,7 @@ TEST_F(VideoCapturerTrackSourceTest, MixedOptionsAndConstraints) {
|
||||
CreateVideoCapturerSource(&constraints);
|
||||
EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(),
|
||||
kMaxWaitMs);
|
||||
const cricket::VideoFormat* format = capturer_->GetCaptureFormat();
|
||||
const VideoFormat* format = capturer_->GetCaptureFormat();
|
||||
ASSERT_TRUE(format != NULL);
|
||||
EXPECT_EQ(352, format->width);
|
||||
EXPECT_EQ(288, format->height);
|
||||
@ -414,7 +418,7 @@ TEST_F(VideoCapturerTrackSourceTest, ScreencastResolutionNoConstraint) {
|
||||
ASSERT_TRUE(source_->is_screencast());
|
||||
EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(),
|
||||
kMaxWaitMs);
|
||||
const cricket::VideoFormat* format = capturer_->GetCaptureFormat();
|
||||
const VideoFormat* format = capturer_->GetCaptureFormat();
|
||||
ASSERT_TRUE(format != NULL);
|
||||
EXPECT_EQ(640, format->width);
|
||||
EXPECT_EQ(480, format->height);
|
||||
@ -435,7 +439,7 @@ TEST_F(VideoCapturerTrackSourceTest, ScreencastResolutionWithConstraint) {
|
||||
ASSERT_TRUE(source_->is_screencast());
|
||||
EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(),
|
||||
kMaxWaitMs);
|
||||
const cricket::VideoFormat* format = capturer_->GetCaptureFormat();
|
||||
const VideoFormat* format = capturer_->GetCaptureFormat();
|
||||
ASSERT_TRUE(format != NULL);
|
||||
EXPECT_EQ(480, format->width);
|
||||
EXPECT_EQ(270, format->height);
|
||||
@ -459,7 +463,7 @@ TEST_F(VideoCapturerTrackSourceTest, OptionalSubOneFpsConstraints) {
|
||||
CreateVideoCapturerSource(&constraints);
|
||||
EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(),
|
||||
kMaxWaitMs);
|
||||
const cricket::VideoFormat* format = capturer_->GetCaptureFormat();
|
||||
const VideoFormat* format = capturer_->GetCaptureFormat();
|
||||
ASSERT_TRUE(format != NULL);
|
||||
EXPECT_EQ(1, format->framerate());
|
||||
}
|
||||
|
Reference in New Issue
Block a user