2014-08-07 04:47:36 +00:00
|
|
|
/*
|
2016-02-07 20:46:45 -08:00
|
|
|
* Copyright (c) 2010 The WebRTC project authors. All Rights Reserved.
|
2014-08-07 04:47:36 +00:00
|
|
|
*
|
2016-02-07 20:46:45 -08:00
|
|
|
* 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.
|
2014-08-07 04:47:36 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <limits.h> // For INT_MAX
|
2016-02-26 03:00:35 -08:00
|
|
|
|
2014-08-07 04:47:36 +00:00
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
2014-08-13 17:26:08 +00:00
|
|
|
#include "webrtc/base/gunit.h"
|
|
|
|
|
#include "webrtc/base/logging.h"
|
Move talk/media to webrtc/media
I removed the 'libjingle' target in talk/libjingle.gyp and replaced
all users of it with base/base.gyp:rtc_base. It seems the jsoncpp
and expat dependencies were not used by it's previous references.
The files in talk/media/testdata were uploaded to Google Storage and
added .sha1 files in resources/media instead of simply moving them.
The previously disabled warnings that were inherited from
talk/build/common.gypi are now replaced by target-specific disabling
of only the failing warnings. Additional disabling was needed since the stricter
compilation warnings that applies to code in webrtc/.
License headers will be updated in a follow-up CL in order to not
break Git history.
Other modifications:
* Updated the header guards.
* Sorted the includes using chromium/src/tools/sort-headers.py
except for these files:
talk/app/webrtc/peerconnectionendtoend_unittest.cc
talk/app/webrtc/java/jni/androidmediadecoder_jni.cc
talk/app/webrtc/java/jni/androidmediaencoder_jni.cc
webrtc/media/devices/win32devicemanager.cc.
* Unused GYP reference to libjingle_tests_additional_deps was removed.
* Removed duplicated GYP entries of
webrtc/base/testutils.cc
webrtc/base/testutils.h
The HAVE_WEBRTC_VIDEO and HAVE_WEBRTC_VOICE defines were used by only talk/media,
so they were moved to the media.gyp.
I also checked that none of
EXPAT_RELATIVE_PATH,
FEATURE_ENABLE_VOICEMAIL,
GTEST_RELATIVE_PATH,
JSONCPP_RELATIVE_PATH,
LOGGING=1,
SRTP_RELATIVE_PATH,
FEATURE_ENABLE_SSL,
FEATURE_ENABLE_VOICEMAIL,
FEATURE_ENABLE_PSTN,
HAVE_SCTP,
HAVE_SRTP,
are used by the talk/media code.
For Chromium, the following changes will need to be applied to the roll CL that updates the
DEPS for WebRTC and libjingle: https://codereview.chromium.org/1604303002/
BUG=webrtc:5420
NOPRESUBMIT=True
TBR=tommi@webrtc.org
Review URL: https://codereview.webrtc.org/1587193006
Cr-Commit-Position: refs/heads/master@{#11495}
2016-02-04 23:52:28 -08:00
|
|
|
#include "webrtc/media/base/fakevideocapturer.h"
|
|
|
|
|
#include "webrtc/media/base/mediachannel.h"
|
|
|
|
|
#include "webrtc/media/base/testutils.h"
|
|
|
|
|
#include "webrtc/media/base/videoadapter.h"
|
2014-08-07 04:47:36 +00:00
|
|
|
|
|
|
|
|
namespace cricket {
|
|
|
|
|
|
|
|
|
|
class VideoAdapterTest : public testing::Test {
|
|
|
|
|
public:
|
|
|
|
|
virtual void SetUp() {
|
2015-04-10 11:18:39 +02:00
|
|
|
capturer_.reset(new FakeVideoCapturer);
|
2014-08-07 04:47:36 +00:00
|
|
|
capture_format_ = capturer_->GetSupportedFormats()->at(0);
|
|
|
|
|
capture_format_.interval = VideoFormat::FpsToInterval(50);
|
2016-04-05 15:23:49 +02:00
|
|
|
adapter_.SetExpectedInputFrameInterval(capture_format_.interval);
|
2014-08-07 04:47:36 +00:00
|
|
|
|
2016-04-05 15:23:49 +02:00
|
|
|
listener_.reset(new VideoCapturerListener(&adapter_));
|
2014-08-07 04:47:36 +00:00
|
|
|
capturer_->SignalFrameCaptured.connect(
|
|
|
|
|
listener_.get(), &VideoCapturerListener::OnFrameCaptured);
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-27 18:16:13 +00:00
|
|
|
virtual void TearDown() {
|
|
|
|
|
// Explicitly disconnect the VideoCapturer before to avoid data races
|
|
|
|
|
// (frames delivered to VideoCapturerListener while it's being destructed).
|
|
|
|
|
capturer_->SignalFrameCaptured.disconnect_all();
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-07 04:47:36 +00:00
|
|
|
protected:
|
|
|
|
|
class VideoCapturerListener: public sigslot::has_slots<> {
|
|
|
|
|
public:
|
2014-08-26 12:33:18 +00:00
|
|
|
struct Stats {
|
|
|
|
|
int captured_frames;
|
|
|
|
|
int dropped_frames;
|
|
|
|
|
bool last_adapt_was_no_op;
|
|
|
|
|
|
|
|
|
|
int adapted_width;
|
|
|
|
|
int adapted_height;
|
|
|
|
|
};
|
|
|
|
|
|
2014-08-07 04:47:36 +00:00
|
|
|
explicit VideoCapturerListener(VideoAdapter* adapter)
|
|
|
|
|
: video_adapter_(adapter),
|
|
|
|
|
captured_frames_(0),
|
|
|
|
|
dropped_frames_(0),
|
|
|
|
|
last_adapt_was_no_op_(false) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OnFrameCaptured(VideoCapturer* capturer,
|
|
|
|
|
const CapturedFrame* captured_frame) {
|
2014-08-26 12:33:18 +00:00
|
|
|
rtc::CritScope lock(&crit_);
|
2015-03-24 15:18:39 +01:00
|
|
|
const int in_width = captured_frame->width;
|
|
|
|
|
const int in_height = abs(captured_frame->height);
|
|
|
|
|
const VideoFormat adapted_format =
|
|
|
|
|
video_adapter_->AdaptFrameResolution(in_width, in_height);
|
|
|
|
|
if (!adapted_format.IsSize0x0()) {
|
|
|
|
|
adapted_format_ = adapted_format;
|
|
|
|
|
last_adapt_was_no_op_ = (in_width == adapted_format.width &&
|
|
|
|
|
in_height == adapted_format.height);
|
2014-08-07 04:47:36 +00:00
|
|
|
} else {
|
|
|
|
|
++dropped_frames_;
|
|
|
|
|
}
|
|
|
|
|
++captured_frames_;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-26 12:33:18 +00:00
|
|
|
Stats GetStats() {
|
|
|
|
|
rtc::CritScope lock(&crit_);
|
|
|
|
|
Stats stats;
|
|
|
|
|
stats.captured_frames = captured_frames_;
|
|
|
|
|
stats.dropped_frames = dropped_frames_;
|
|
|
|
|
stats.last_adapt_was_no_op = last_adapt_was_no_op_;
|
2015-03-24 15:18:39 +01:00
|
|
|
if (!adapted_format_.IsSize0x0()) {
|
|
|
|
|
stats.adapted_width = adapted_format_.width;
|
|
|
|
|
stats.adapted_height = adapted_format_.height;
|
2014-08-26 12:33:18 +00:00
|
|
|
} else {
|
|
|
|
|
stats.adapted_width = stats.adapted_height = -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return stats;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-07 04:47:36 +00:00
|
|
|
private:
|
2014-08-26 12:33:18 +00:00
|
|
|
rtc::CriticalSection crit_;
|
2014-08-07 04:47:36 +00:00
|
|
|
VideoAdapter* video_adapter_;
|
2015-03-24 15:18:39 +01:00
|
|
|
VideoFormat adapted_format_;
|
2014-08-07 04:47:36 +00:00
|
|
|
int captured_frames_;
|
|
|
|
|
int dropped_frames_;
|
|
|
|
|
bool last_adapt_was_no_op_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2014-08-26 12:33:18 +00:00
|
|
|
void VerifyAdaptedResolution(const VideoCapturerListener::Stats& stats,
|
|
|
|
|
int width,
|
|
|
|
|
int height) {
|
|
|
|
|
EXPECT_EQ(width, stats.adapted_width);
|
|
|
|
|
EXPECT_EQ(height, stats.adapted_height);
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-26 03:00:35 -08:00
|
|
|
std::unique_ptr<FakeVideoCapturer> capturer_;
|
2016-04-05 15:23:49 +02:00
|
|
|
VideoAdapter adapter_;
|
2016-02-26 03:00:35 -08:00
|
|
|
std::unique_ptr<VideoCapturerListener> listener_;
|
2014-08-07 04:47:36 +00:00
|
|
|
VideoFormat capture_format_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Do not adapt the frame rate or the resolution. Expect no frame drop and no
|
|
|
|
|
// resolution change.
|
|
|
|
|
TEST_F(VideoAdapterTest, AdaptNothing) {
|
|
|
|
|
EXPECT_EQ(CS_RUNNING, capturer_->Start(capture_format_));
|
2015-04-10 11:18:39 +02:00
|
|
|
for (int i = 0; i < 10; ++i)
|
|
|
|
|
capturer_->CaptureFrame();
|
2014-08-07 04:47:36 +00:00
|
|
|
|
|
|
|
|
// Verify no frame drop and no resolution change.
|
2014-08-26 12:33:18 +00:00
|
|
|
VideoCapturerListener::Stats stats = listener_->GetStats();
|
|
|
|
|
EXPECT_GE(stats.captured_frames, 10);
|
|
|
|
|
EXPECT_EQ(0, stats.dropped_frames);
|
|
|
|
|
VerifyAdaptedResolution(stats, capture_format_.width, capture_format_.height);
|
|
|
|
|
EXPECT_TRUE(stats.last_adapt_was_no_op);
|
2014-08-07 04:47:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(VideoAdapterTest, AdaptZeroInterval) {
|
|
|
|
|
VideoFormat format = capturer_->GetSupportedFormats()->at(0);
|
|
|
|
|
format.interval = 0;
|
2016-04-05 15:23:49 +02:00
|
|
|
adapter_.OnOutputFormatRequest(format);
|
2014-08-07 04:47:36 +00:00
|
|
|
EXPECT_EQ(CS_RUNNING, capturer_->Start(capture_format_));
|
2015-04-10 11:18:39 +02:00
|
|
|
for (int i = 0; i < 10; ++i)
|
|
|
|
|
capturer_->CaptureFrame();
|
2014-08-07 04:47:36 +00:00
|
|
|
|
|
|
|
|
// Verify no crash and that frames aren't dropped.
|
2014-08-26 12:33:18 +00:00
|
|
|
VideoCapturerListener::Stats stats = listener_->GetStats();
|
|
|
|
|
EXPECT_GE(stats.captured_frames, 10);
|
|
|
|
|
EXPECT_EQ(0, stats.dropped_frames);
|
|
|
|
|
VerifyAdaptedResolution(stats, capture_format_.width, capture_format_.height);
|
2014-08-07 04:47:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Adapt the frame rate to be half of the capture rate at the beginning. Expect
|
|
|
|
|
// the number of dropped frames to be half of the number the captured frames.
|
|
|
|
|
TEST_F(VideoAdapterTest, AdaptFramerate) {
|
|
|
|
|
VideoFormat request_format = capture_format_;
|
|
|
|
|
request_format.interval *= 2;
|
2016-04-05 15:23:49 +02:00
|
|
|
adapter_.OnOutputFormatRequest(request_format);
|
2014-08-07 04:47:36 +00:00
|
|
|
EXPECT_EQ(CS_RUNNING, capturer_->Start(capture_format_));
|
2015-04-10 11:18:39 +02:00
|
|
|
for (int i = 0; i < 10; ++i)
|
|
|
|
|
capturer_->CaptureFrame();
|
2014-08-07 04:47:36 +00:00
|
|
|
|
|
|
|
|
// Verify frame drop and no resolution change.
|
2014-08-26 12:33:18 +00:00
|
|
|
VideoCapturerListener::Stats stats = listener_->GetStats();
|
|
|
|
|
EXPECT_GE(stats.captured_frames, 10);
|
|
|
|
|
EXPECT_EQ(stats.captured_frames / 2, stats.dropped_frames);
|
|
|
|
|
VerifyAdaptedResolution(stats, capture_format_.width, capture_format_.height);
|
2014-08-07 04:47:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Adapt the frame rate to be half of the capture rate at the beginning. Expect
|
|
|
|
|
// the number of dropped frames to be half of the number the captured frames.
|
|
|
|
|
TEST_F(VideoAdapterTest, AdaptFramerateVariable) {
|
|
|
|
|
VideoFormat request_format = capture_format_;
|
|
|
|
|
request_format.interval = request_format.interval * 3 / 2;
|
2016-04-05 15:23:49 +02:00
|
|
|
adapter_.OnOutputFormatRequest(request_format);
|
2014-08-07 04:47:36 +00:00
|
|
|
EXPECT_EQ(CS_RUNNING, capturer_->Start(capture_format_));
|
2015-04-10 11:18:39 +02:00
|
|
|
for (int i = 0; i < 30; ++i)
|
|
|
|
|
capturer_->CaptureFrame();
|
2014-08-07 04:47:36 +00:00
|
|
|
|
|
|
|
|
// Verify frame drop and no resolution change.
|
2014-08-26 12:33:18 +00:00
|
|
|
VideoCapturerListener::Stats stats = listener_->GetStats();
|
|
|
|
|
EXPECT_GE(stats.captured_frames, 30);
|
2014-08-07 04:47:36 +00:00
|
|
|
// Verify 2 / 3 kept (20) and 1 / 3 dropped (10).
|
2014-08-26 12:33:18 +00:00
|
|
|
EXPECT_EQ(stats.captured_frames * 1 / 3, stats.dropped_frames);
|
|
|
|
|
VerifyAdaptedResolution(stats, capture_format_.width, capture_format_.height);
|
2014-08-07 04:47:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Adapt the frame rate to be half of the capture rate after capturing no less
|
|
|
|
|
// than 10 frames. Expect no frame dropped before adaptation and frame dropped
|
|
|
|
|
// after adaptation.
|
|
|
|
|
TEST_F(VideoAdapterTest, AdaptFramerateOntheFly) {
|
|
|
|
|
VideoFormat request_format = capture_format_;
|
2016-04-05 15:23:49 +02:00
|
|
|
adapter_.OnOutputFormatRequest(request_format);
|
2014-08-07 04:47:36 +00:00
|
|
|
EXPECT_EQ(CS_RUNNING, capturer_->Start(capture_format_));
|
2015-04-10 11:18:39 +02:00
|
|
|
for (int i = 0; i < 10; ++i)
|
|
|
|
|
capturer_->CaptureFrame();
|
2014-08-07 04:47:36 +00:00
|
|
|
|
|
|
|
|
// Verify no frame drop before adaptation.
|
2014-08-26 12:33:18 +00:00
|
|
|
EXPECT_EQ(0, listener_->GetStats().dropped_frames);
|
2014-08-07 04:47:36 +00:00
|
|
|
|
|
|
|
|
// Adapat the frame rate.
|
|
|
|
|
request_format.interval *= 2;
|
2016-04-05 15:23:49 +02:00
|
|
|
adapter_.OnOutputFormatRequest(request_format);
|
2014-08-07 04:47:36 +00:00
|
|
|
|
2015-04-10 11:18:39 +02:00
|
|
|
for (int i = 0; i < 20; ++i)
|
|
|
|
|
capturer_->CaptureFrame();
|
2014-08-07 04:47:36 +00:00
|
|
|
|
|
|
|
|
// Verify frame drop after adaptation.
|
2014-08-26 12:33:18 +00:00
|
|
|
EXPECT_GT(listener_->GetStats().dropped_frames, 0);
|
2014-08-07 04:47:36 +00:00
|
|
|
}
|
|
|
|
|
|
2014-11-19 18:09:14 +00:00
|
|
|
// Set a very high output pixel resolution. Expect no resolution change.
|
|
|
|
|
TEST_F(VideoAdapterTest, AdaptFrameResolutionHighLimit) {
|
2016-04-05 15:23:49 +02:00
|
|
|
VideoFormat output_format = capture_format_;
|
|
|
|
|
output_format.width = 2560;
|
|
|
|
|
output_format.height = 2560;
|
|
|
|
|
adapter_.OnOutputFormatRequest(output_format);
|
|
|
|
|
VideoFormat adapted_format = adapter_.AdaptFrameResolution(
|
2014-11-19 18:09:14 +00:00
|
|
|
capture_format_.width, capture_format_.height);
|
|
|
|
|
EXPECT_EQ(capture_format_.width, adapted_format.width);
|
|
|
|
|
EXPECT_EQ(capture_format_.height, adapted_format.height);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Adapt the frame resolution to be the same as capture resolution. Expect no
|
|
|
|
|
// resolution change.
|
|
|
|
|
TEST_F(VideoAdapterTest, AdaptFrameResolutionIdentical) {
|
2016-04-05 15:23:49 +02:00
|
|
|
adapter_.OnOutputFormatRequest(capture_format_);
|
|
|
|
|
const VideoFormat adapted_format = adapter_.AdaptFrameResolution(
|
2014-11-19 18:09:14 +00:00
|
|
|
capture_format_.width, capture_format_.height);
|
|
|
|
|
EXPECT_EQ(capture_format_.width, adapted_format.width);
|
|
|
|
|
EXPECT_EQ(capture_format_.height, adapted_format.height);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Adapt the frame resolution to be a quarter of the capture resolution. Expect
|
|
|
|
|
// resolution change.
|
|
|
|
|
TEST_F(VideoAdapterTest, AdaptFrameResolutionQuarter) {
|
|
|
|
|
VideoFormat request_format = capture_format_;
|
|
|
|
|
request_format.width /= 2;
|
|
|
|
|
request_format.height /= 2;
|
2016-04-05 15:23:49 +02:00
|
|
|
adapter_.OnOutputFormatRequest(request_format);
|
|
|
|
|
const VideoFormat adapted_format = adapter_.AdaptFrameResolution(
|
2014-11-19 18:09:14 +00:00
|
|
|
request_format.width, request_format.height);
|
|
|
|
|
EXPECT_EQ(request_format.width, adapted_format.width);
|
|
|
|
|
EXPECT_EQ(request_format.height, adapted_format.height);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Adapt the pixel resolution to 0. Expect frame drop.
|
|
|
|
|
TEST_F(VideoAdapterTest, AdaptFrameResolutionDrop) {
|
2016-04-05 15:23:49 +02:00
|
|
|
VideoFormat output_format = capture_format_;
|
|
|
|
|
output_format.width = 0;
|
|
|
|
|
output_format.height = 0;
|
|
|
|
|
adapter_.OnOutputFormatRequest(output_format);
|
2014-11-19 18:09:14 +00:00
|
|
|
EXPECT_TRUE(
|
2016-04-05 15:23:49 +02:00
|
|
|
adapter_
|
|
|
|
|
.AdaptFrameResolution(capture_format_.width, capture_format_.height)
|
|
|
|
|
.IsSize0x0());
|
2014-11-19 18:09:14 +00:00
|
|
|
}
|
|
|
|
|
|
2014-08-07 04:47:36 +00:00
|
|
|
// Adapt the frame resolution to be a quarter of the capture resolution at the
|
|
|
|
|
// beginning. Expect resolution change.
|
|
|
|
|
TEST_F(VideoAdapterTest, AdaptResolution) {
|
|
|
|
|
VideoFormat request_format = capture_format_;
|
|
|
|
|
request_format.width /= 2;
|
|
|
|
|
request_format.height /= 2;
|
2016-04-05 15:23:49 +02:00
|
|
|
adapter_.OnOutputFormatRequest(request_format);
|
2014-08-07 04:47:36 +00:00
|
|
|
EXPECT_EQ(CS_RUNNING, capturer_->Start(capture_format_));
|
2015-04-10 11:18:39 +02:00
|
|
|
for (int i = 0; i < 10; ++i)
|
|
|
|
|
capturer_->CaptureFrame();
|
2014-08-07 04:47:36 +00:00
|
|
|
|
|
|
|
|
// Verify no frame drop and resolution change.
|
2014-08-26 12:33:18 +00:00
|
|
|
VideoCapturerListener::Stats stats = listener_->GetStats();
|
|
|
|
|
EXPECT_EQ(0, stats.dropped_frames);
|
|
|
|
|
VerifyAdaptedResolution(stats, request_format.width, request_format.height);
|
2014-08-07 04:47:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Adapt the frame resolution to be a quarter of the capture resolution after
|
|
|
|
|
// capturing no less than 10 frames. Expect no resolution change before
|
|
|
|
|
// adaptation and resolution change after adaptation.
|
|
|
|
|
TEST_F(VideoAdapterTest, AdaptResolutionOnTheFly) {
|
|
|
|
|
VideoFormat request_format = capture_format_;
|
2016-04-05 15:23:49 +02:00
|
|
|
adapter_.OnOutputFormatRequest(request_format);
|
2014-08-07 04:47:36 +00:00
|
|
|
EXPECT_EQ(CS_RUNNING, capturer_->Start(capture_format_));
|
2015-04-10 11:18:39 +02:00
|
|
|
for (int i = 0; i < 10; ++i)
|
|
|
|
|
capturer_->CaptureFrame();
|
2014-08-07 04:47:36 +00:00
|
|
|
|
|
|
|
|
// Verify no resolution change before adaptation.
|
2014-08-26 12:33:18 +00:00
|
|
|
VerifyAdaptedResolution(
|
|
|
|
|
listener_->GetStats(), request_format.width, request_format.height);
|
2014-08-07 04:47:36 +00:00
|
|
|
|
|
|
|
|
// Adapt the frame resolution.
|
|
|
|
|
request_format.width /= 2;
|
|
|
|
|
request_format.height /= 2;
|
2016-04-05 15:23:49 +02:00
|
|
|
adapter_.OnOutputFormatRequest(request_format);
|
2015-04-10 11:18:39 +02:00
|
|
|
for (int i = 0; i < 10; ++i)
|
|
|
|
|
capturer_->CaptureFrame();
|
2014-08-07 04:47:36 +00:00
|
|
|
|
|
|
|
|
// Verify resolution change after adaptation.
|
2014-08-26 12:33:18 +00:00
|
|
|
VerifyAdaptedResolution(
|
|
|
|
|
listener_->GetStats(), request_format.width, request_format.height);
|
2014-08-07 04:47:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Drop all frames.
|
|
|
|
|
TEST_F(VideoAdapterTest, DropAllFrames) {
|
|
|
|
|
VideoFormat format; // with resolution 0x0.
|
2016-04-05 15:23:49 +02:00
|
|
|
adapter_.OnOutputFormatRequest(format);
|
2014-08-07 04:47:36 +00:00
|
|
|
EXPECT_EQ(CS_RUNNING, capturer_->Start(capture_format_));
|
2015-04-10 11:18:39 +02:00
|
|
|
for (int i = 0; i < 10; ++i)
|
|
|
|
|
capturer_->CaptureFrame();
|
2014-08-07 04:47:36 +00:00
|
|
|
|
|
|
|
|
// Verify all frames are dropped.
|
2014-08-26 12:33:18 +00:00
|
|
|
VideoCapturerListener::Stats stats = listener_->GetStats();
|
|
|
|
|
EXPECT_GE(stats.captured_frames, 10);
|
|
|
|
|
EXPECT_EQ(stats.captured_frames, stats.dropped_frames);
|
2014-08-07 04:47:36 +00:00
|
|
|
}
|
|
|
|
|
|
2016-04-05 15:23:49 +02:00
|
|
|
TEST_F(VideoAdapterTest, TestOnOutputFormatRequest) {
|
|
|
|
|
VideoFormat format(640, 400, VideoFormat::FpsToInterval(30), 0);
|
|
|
|
|
adapter_.SetExpectedInputFrameInterval(VideoFormat::FpsToInterval(30));
|
|
|
|
|
VideoFormat out_format =
|
|
|
|
|
adapter_.AdaptFrameResolution(format.width, format.height);
|
|
|
|
|
EXPECT_EQ(format, adapter_.input_format());
|
|
|
|
|
EXPECT_EQ(format, out_format);
|
2014-08-07 04:47:36 +00:00
|
|
|
|
2016-04-05 15:23:49 +02:00
|
|
|
// Format request 640x400.
|
2014-08-07 04:47:36 +00:00
|
|
|
format.height = 400;
|
2016-04-05 15:23:49 +02:00
|
|
|
adapter_.OnOutputFormatRequest(format);
|
|
|
|
|
out_format = adapter_.AdaptFrameResolution(640, 400);
|
|
|
|
|
EXPECT_EQ(640, out_format.width);
|
|
|
|
|
EXPECT_EQ(400, out_format.height);
|
2014-08-07 04:47:36 +00:00
|
|
|
|
2016-04-05 15:23:49 +02:00
|
|
|
// Request 1280x720, higher than input. Adapt nothing.
|
2014-08-07 04:47:36 +00:00
|
|
|
format.width = 1280;
|
|
|
|
|
format.height = 720;
|
2016-04-05 15:23:49 +02:00
|
|
|
adapter_.OnOutputFormatRequest(format);
|
|
|
|
|
out_format = adapter_.AdaptFrameResolution(640, 400);
|
|
|
|
|
EXPECT_EQ(640, out_format.width);
|
|
|
|
|
EXPECT_EQ(400, out_format.height);
|
|
|
|
|
|
|
|
|
|
// Request 0x0.
|
2014-08-07 04:47:36 +00:00
|
|
|
format.width = 0;
|
|
|
|
|
format.height = 0;
|
2016-04-05 15:23:49 +02:00
|
|
|
adapter_.OnOutputFormatRequest(format);
|
|
|
|
|
out_format = adapter_.AdaptFrameResolution(640, 400);
|
|
|
|
|
EXPECT_TRUE(out_format.IsSize0x0());
|
2014-08-07 04:47:36 +00:00
|
|
|
|
2016-04-05 15:23:49 +02:00
|
|
|
// Request 320x200.
|
2014-08-07 04:47:36 +00:00
|
|
|
format.width = 320;
|
|
|
|
|
format.height = 200;
|
2016-04-05 15:23:49 +02:00
|
|
|
adapter_.OnOutputFormatRequest(format);
|
|
|
|
|
out_format = adapter_.AdaptFrameResolution(640, 400);
|
|
|
|
|
EXPECT_EQ(320, out_format.width);
|
|
|
|
|
EXPECT_EQ(200, out_format.height);
|
|
|
|
|
|
|
|
|
|
// Request resolution of 2 / 3. Expect adapt down. Scaling to 1/3 is not
|
|
|
|
|
// optimized and not allowed.
|
2014-08-07 04:47:36 +00:00
|
|
|
format.width = (640 * 2 + 1) / 3;
|
|
|
|
|
format.height = (400 * 2 + 1) / 3;
|
2016-04-05 15:23:49 +02:00
|
|
|
adapter_.OnOutputFormatRequest(format);
|
|
|
|
|
out_format = adapter_.AdaptFrameResolution(640, 400);
|
|
|
|
|
EXPECT_EQ(320, out_format.width);
|
|
|
|
|
EXPECT_EQ(200, out_format.height);
|
2014-08-07 04:47:36 +00:00
|
|
|
|
2016-04-05 15:23:49 +02:00
|
|
|
// Request resolution of 3 / 8. Expect adapt down.
|
2014-08-07 04:47:36 +00:00
|
|
|
format.width = 640 * 3 / 8;
|
|
|
|
|
format.height = 400 * 3 / 8;
|
2016-04-05 15:23:49 +02:00
|
|
|
adapter_.OnOutputFormatRequest(format);
|
|
|
|
|
out_format = adapter_.AdaptFrameResolution(640, 400);
|
|
|
|
|
EXPECT_EQ(640 * 3 / 8, out_format.width);
|
|
|
|
|
EXPECT_EQ(400 * 3 / 8, out_format.height);
|
2014-08-07 04:47:36 +00:00
|
|
|
|
2016-04-05 15:23:49 +02:00
|
|
|
// Switch back up. Expect adapt.
|
2014-08-07 04:47:36 +00:00
|
|
|
format.width = 320;
|
|
|
|
|
format.height = 200;
|
2016-04-05 15:23:49 +02:00
|
|
|
adapter_.OnOutputFormatRequest(format);
|
|
|
|
|
out_format = adapter_.AdaptFrameResolution(640, 400);
|
|
|
|
|
EXPECT_EQ(320, out_format.width);
|
|
|
|
|
EXPECT_EQ(200, out_format.height);
|
2014-08-07 04:47:36 +00:00
|
|
|
|
2016-04-05 15:23:49 +02:00
|
|
|
// Format request 480x300.
|
2014-08-07 04:47:36 +00:00
|
|
|
format.width = 480;
|
|
|
|
|
format.height = 300;
|
2016-04-05 15:23:49 +02:00
|
|
|
adapter_.OnOutputFormatRequest(format);
|
|
|
|
|
out_format = adapter_.AdaptFrameResolution(640, 400);
|
|
|
|
|
EXPECT_EQ(480, out_format.width);
|
|
|
|
|
EXPECT_EQ(300, out_format.height);
|
2014-08-07 04:47:36 +00:00
|
|
|
}
|
|
|
|
|
|
2016-04-05 15:23:49 +02:00
|
|
|
TEST_F(VideoAdapterTest, TestViewRequestPlusCameraSwitch) {
|
2014-08-07 04:47:36 +00:00
|
|
|
// Start at HD.
|
2016-04-05 15:23:49 +02:00
|
|
|
VideoFormat format(1280, 720, VideoFormat::FpsToInterval(30), 0);
|
|
|
|
|
adapter_.SetExpectedInputFrameInterval(VideoFormat::FpsToInterval(30));
|
|
|
|
|
VideoFormat out_format =
|
|
|
|
|
adapter_.AdaptFrameResolution(format.width, format.height);
|
|
|
|
|
EXPECT_EQ(format, adapter_.input_format());
|
|
|
|
|
EXPECT_EQ(out_format, adapter_.input_format());
|
|
|
|
|
|
|
|
|
|
// Format request for VGA.
|
2014-08-07 04:47:36 +00:00
|
|
|
format.width = 640;
|
|
|
|
|
format.height = 360;
|
2016-04-05 15:23:49 +02:00
|
|
|
adapter_.OnOutputFormatRequest(format);
|
|
|
|
|
out_format = adapter_.AdaptFrameResolution(1280, 720);
|
|
|
|
|
EXPECT_EQ(640, out_format.width);
|
|
|
|
|
EXPECT_EQ(360, out_format.height);
|
2014-08-07 04:47:36 +00:00
|
|
|
|
|
|
|
|
// Now, the camera reopens at VGA.
|
|
|
|
|
// Both the frame and the output format should be 640x360.
|
2016-04-05 15:23:49 +02:00
|
|
|
out_format = adapter_.AdaptFrameResolution(640, 360);
|
2015-03-24 15:18:39 +01:00
|
|
|
EXPECT_EQ(640, out_format.width);
|
|
|
|
|
EXPECT_EQ(360, out_format.height);
|
2014-08-07 04:47:36 +00:00
|
|
|
|
|
|
|
|
// And another view request comes in for 640x360, which should have no
|
|
|
|
|
// real impact.
|
2016-04-05 15:23:49 +02:00
|
|
|
adapter_.OnOutputFormatRequest(format);
|
|
|
|
|
out_format = adapter_.AdaptFrameResolution(640, 360);
|
|
|
|
|
EXPECT_EQ(640, out_format.width);
|
|
|
|
|
EXPECT_EQ(360, out_format.height);
|
2014-08-07 04:47:36 +00:00
|
|
|
}
|
|
|
|
|
|
2016-04-05 15:23:49 +02:00
|
|
|
TEST_F(VideoAdapterTest, TestVGAWidth) {
|
|
|
|
|
// Reqeuested Output format is 640x360.
|
|
|
|
|
VideoFormat format(640, 360, VideoFormat::FpsToInterval(30), FOURCC_I420);
|
|
|
|
|
adapter_.SetExpectedInputFrameInterval(VideoFormat::FpsToInterval(30));
|
|
|
|
|
adapter_.OnOutputFormatRequest(format);
|
2014-08-07 04:47:36 +00:00
|
|
|
|
2016-04-05 15:23:49 +02:00
|
|
|
VideoFormat out_format = adapter_.AdaptFrameResolution(640, 480);
|
2014-08-07 04:47:36 +00:00
|
|
|
// At this point, we have to adapt down to something lower.
|
2016-04-05 15:23:49 +02:00
|
|
|
EXPECT_EQ(480, out_format.width);
|
|
|
|
|
EXPECT_EQ(360, out_format.height);
|
2014-08-07 04:47:36 +00:00
|
|
|
|
|
|
|
|
// But if frames come in at 640x360, we shouldn't adapt them down.
|
2016-04-05 15:23:49 +02:00
|
|
|
out_format = adapter_.AdaptFrameResolution(640, 360);
|
2015-03-24 15:18:39 +01:00
|
|
|
EXPECT_EQ(640, out_format.width);
|
|
|
|
|
EXPECT_EQ(360, out_format.height);
|
2014-08-07 04:47:36 +00:00
|
|
|
|
2016-04-05 15:23:49 +02:00
|
|
|
out_format = adapter_.AdaptFrameResolution(640, 480);
|
|
|
|
|
EXPECT_EQ(480, out_format.width);
|
2015-03-24 15:18:39 +01:00
|
|
|
EXPECT_EQ(360, out_format.height);
|
2014-08-07 04:47:36 +00:00
|
|
|
}
|
|
|
|
|
|
2016-04-05 15:23:49 +02:00
|
|
|
TEST_F(VideoAdapterTest, TestOnResolutionRequestInSmallSteps) {
|
|
|
|
|
VideoFormat out_format = adapter_.AdaptFrameResolution(1280, 720);
|
|
|
|
|
EXPECT_EQ(1280, out_format.width);
|
|
|
|
|
EXPECT_EQ(720, out_format.height);
|
2014-08-07 04:47:36 +00:00
|
|
|
|
2016-04-05 15:23:49 +02:00
|
|
|
// Adapt down one step.
|
|
|
|
|
adapter_.OnResolutionRequest(rtc::Optional<int>(1280 * 720 - 1),
|
|
|
|
|
rtc::Optional<int>());
|
|
|
|
|
out_format = adapter_.AdaptFrameResolution(1280, 720);
|
|
|
|
|
EXPECT_EQ(960, out_format.width);
|
|
|
|
|
EXPECT_EQ(540, out_format.height);
|
2014-08-07 04:47:36 +00:00
|
|
|
|
2016-04-05 15:23:49 +02:00
|
|
|
// Adapt down one step more.
|
|
|
|
|
adapter_.OnResolutionRequest(rtc::Optional<int>(960 * 540 - 1),
|
|
|
|
|
rtc::Optional<int>());
|
|
|
|
|
out_format = adapter_.AdaptFrameResolution(1280, 720);
|
|
|
|
|
EXPECT_EQ(640, out_format.width);
|
|
|
|
|
EXPECT_EQ(360, out_format.height);
|
2014-08-07 04:47:36 +00:00
|
|
|
|
2016-04-05 15:23:49 +02:00
|
|
|
// Adapt down one step more.
|
|
|
|
|
adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 360 - 1),
|
|
|
|
|
rtc::Optional<int>());
|
|
|
|
|
out_format = adapter_.AdaptFrameResolution(1280, 720);
|
|
|
|
|
EXPECT_EQ(480, out_format.width);
|
|
|
|
|
EXPECT_EQ(270, out_format.height);
|
|
|
|
|
|
|
|
|
|
// Adapt up one step.
|
|
|
|
|
adapter_.OnResolutionRequest(rtc::Optional<int>(),
|
|
|
|
|
rtc::Optional<int>(480 * 270));
|
|
|
|
|
out_format = adapter_.AdaptFrameResolution(1280, 720);
|
|
|
|
|
EXPECT_EQ(640, out_format.width);
|
|
|
|
|
EXPECT_EQ(360, out_format.height);
|
2014-08-07 04:47:36 +00:00
|
|
|
|
2016-04-05 15:23:49 +02:00
|
|
|
// Adapt up one step more.
|
|
|
|
|
adapter_.OnResolutionRequest(rtc::Optional<int>(),
|
|
|
|
|
rtc::Optional<int>(640 * 360));
|
|
|
|
|
out_format = adapter_.AdaptFrameResolution(1280, 720);
|
|
|
|
|
EXPECT_EQ(960, out_format.width);
|
|
|
|
|
EXPECT_EQ(540, out_format.height);
|
|
|
|
|
|
|
|
|
|
// Adapt up one step more.
|
|
|
|
|
adapter_.OnResolutionRequest(rtc::Optional<int>(),
|
|
|
|
|
rtc::Optional<int>(960 * 720));
|
|
|
|
|
out_format = adapter_.AdaptFrameResolution(1280, 720);
|
|
|
|
|
EXPECT_EQ(1280, out_format.width);
|
|
|
|
|
EXPECT_EQ(720, out_format.height);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(VideoAdapterTest, TestOnResolutionRequestMaxZero) {
|
|
|
|
|
VideoFormat out_format = adapter_.AdaptFrameResolution(1280, 720);
|
|
|
|
|
EXPECT_EQ(1280, out_format.width);
|
|
|
|
|
EXPECT_EQ(720, out_format.height);
|
|
|
|
|
|
|
|
|
|
adapter_.OnResolutionRequest(rtc::Optional<int>(0), rtc::Optional<int>());
|
|
|
|
|
out_format = adapter_.AdaptFrameResolution(1280, 720);
|
|
|
|
|
EXPECT_EQ(0, out_format.width);
|
|
|
|
|
EXPECT_EQ(0, out_format.height);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(VideoAdapterTest, TestOnResolutionRequestInLargeSteps) {
|
|
|
|
|
adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 360 - 1),
|
|
|
|
|
rtc::Optional<int>());
|
|
|
|
|
VideoFormat out_format = adapter_.AdaptFrameResolution(1280, 720);
|
|
|
|
|
EXPECT_EQ(480, out_format.width);
|
|
|
|
|
EXPECT_EQ(270, out_format.height);
|
|
|
|
|
|
|
|
|
|
adapter_.OnResolutionRequest(rtc::Optional<int>(),
|
|
|
|
|
rtc::Optional<int>(960 * 720));
|
|
|
|
|
out_format = adapter_.AdaptFrameResolution(1280, 720);
|
|
|
|
|
EXPECT_EQ(1280, out_format.width);
|
|
|
|
|
EXPECT_EQ(720, out_format.height);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(VideoAdapterTest, TestOnOutputFormatRequestCapsMaxResolution) {
|
|
|
|
|
adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 360 - 1),
|
|
|
|
|
rtc::Optional<int>());
|
|
|
|
|
VideoFormat out_format = adapter_.AdaptFrameResolution(1280, 720);
|
|
|
|
|
EXPECT_EQ(480, out_format.width);
|
|
|
|
|
EXPECT_EQ(270, out_format.height);
|
|
|
|
|
|
|
|
|
|
VideoFormat new_format(640, 360, VideoFormat::FpsToInterval(30), FOURCC_I420);
|
|
|
|
|
adapter_.SetExpectedInputFrameInterval(VideoFormat::FpsToInterval(30));
|
|
|
|
|
adapter_.OnOutputFormatRequest(new_format);
|
|
|
|
|
out_format = adapter_.AdaptFrameResolution(1280, 720);
|
|
|
|
|
EXPECT_EQ(480, out_format.width);
|
|
|
|
|
EXPECT_EQ(270, out_format.height);
|
|
|
|
|
|
|
|
|
|
adapter_.OnResolutionRequest(rtc::Optional<int>(),
|
|
|
|
|
rtc::Optional<int>(960 * 720));
|
|
|
|
|
out_format = adapter_.AdaptFrameResolution(1280, 720);
|
|
|
|
|
EXPECT_EQ(640, out_format.width);
|
|
|
|
|
EXPECT_EQ(360, out_format.height);
|
2014-08-07 04:47:36 +00:00
|
|
|
}
|
|
|
|
|
|
2016-04-05 15:23:49 +02:00
|
|
|
TEST_F(VideoAdapterTest, TestOnResolutionRequestReset) {
|
|
|
|
|
VideoFormat out_format = adapter_.AdaptFrameResolution(1280, 720);
|
|
|
|
|
EXPECT_EQ(1280, out_format.width);
|
|
|
|
|
EXPECT_EQ(720, out_format.height);
|
2014-08-07 04:47:36 +00:00
|
|
|
|
2016-04-05 15:23:49 +02:00
|
|
|
adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 360 - 1),
|
|
|
|
|
rtc::Optional<int>());
|
|
|
|
|
out_format = adapter_.AdaptFrameResolution(1280, 720);
|
|
|
|
|
EXPECT_EQ(480, out_format.width);
|
|
|
|
|
EXPECT_EQ(270, out_format.height);
|
2014-08-07 04:47:36 +00:00
|
|
|
|
2016-04-05 15:23:49 +02:00
|
|
|
adapter_.OnResolutionRequest(rtc::Optional<int>(), rtc::Optional<int>());
|
|
|
|
|
out_format = adapter_.AdaptFrameResolution(1280, 720);
|
|
|
|
|
EXPECT_EQ(1280, out_format.width);
|
|
|
|
|
EXPECT_EQ(720, out_format.height);
|
2014-08-07 04:47:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace cricket
|