Delete deprecated method PeerConnectionFactory::CreateVideoSource
Bug: webrtc:6353 Change-Id: Icb8847b234e7a844a4dff9ff44861f6967ac7b5b Reviewed-on: https://webrtc-review.googlesource.com/c/118661 Commit-Queue: Niels Moller <nisse@webrtc.org> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Reviewed-by: Steve Anton <steveanton@webrtc.org> Cr-Commit-Position: refs/heads/master@{#26587}
This commit is contained in:
parent
59ab1cf081
commit
260a71d47c
@ -25,11 +25,6 @@ namespace webrtc {
|
||||
// are called on is an implementation detail.
|
||||
BEGIN_SIGNALING_PROXY_MAP(PeerConnectionFactory)
|
||||
PROXY_SIGNALING_THREAD_DESTRUCTOR()
|
||||
// Use the overloads of CreateVideoSource that take raw VideoCapturer
|
||||
// pointers from PeerConnectionFactoryInterface.
|
||||
// TODO(deadbeef): Remove this using statement once those overloads are
|
||||
// removed.
|
||||
using PeerConnectionFactoryInterface::CreateVideoSource;
|
||||
PROXY_METHOD1(void, SetOptions, const Options&)
|
||||
PROXY_METHOD4(rtc::scoped_refptr<PeerConnectionInterface>,
|
||||
CreatePeerConnection,
|
||||
@ -53,13 +48,6 @@ PROXY_METHOD1(rtc::scoped_refptr<MediaStreamInterface>,
|
||||
PROXY_METHOD1(rtc::scoped_refptr<AudioSourceInterface>,
|
||||
CreateAudioSource,
|
||||
const cricket::AudioOptions&)
|
||||
PROXY_METHOD2(rtc::scoped_refptr<VideoTrackSourceInterface>,
|
||||
CreateVideoSource,
|
||||
std::unique_ptr<cricket::VideoCapturer>,
|
||||
const MediaConstraintsInterface*)
|
||||
PROXY_METHOD1(rtc::scoped_refptr<VideoTrackSourceInterface>,
|
||||
CreateVideoSource,
|
||||
std::unique_ptr<cricket::VideoCapturer>)
|
||||
PROXY_METHOD2(rtc::scoped_refptr<VideoTrackInterface>,
|
||||
CreateVideoTrack,
|
||||
const std::string&,
|
||||
|
||||
@ -235,23 +235,4 @@ RtpCapabilities PeerConnectionFactoryInterface::GetRtpReceiverCapabilities(
|
||||
return {};
|
||||
}
|
||||
|
||||
rtc::scoped_refptr<VideoTrackSourceInterface>
|
||||
PeerConnectionFactoryInterface::CreateVideoSource(
|
||||
std::unique_ptr<cricket::VideoCapturer> capturer) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
rtc::scoped_refptr<VideoTrackSourceInterface>
|
||||
PeerConnectionFactoryInterface::CreateVideoSource(
|
||||
std::unique_ptr<cricket::VideoCapturer> capturer,
|
||||
const MediaConstraintsInterface* constraints) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
rtc::scoped_refptr<VideoTrackSourceInterface>
|
||||
PeerConnectionFactoryInterface::CreateVideoSource(
|
||||
cricket::VideoCapturer* capturer) {
|
||||
return CreateVideoSource(std::unique_ptr<cricket::VideoCapturer>(capturer));
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
@ -96,9 +96,6 @@
|
||||
#include "api/turn_customizer.h"
|
||||
#include "logging/rtc_event_log/rtc_event_log_factory_interface.h"
|
||||
#include "media/base/media_config.h"
|
||||
// TODO(bugs.webrtc.org/6353): cricket::VideoCapturer is deprecated and should
|
||||
// be deleted from the PeerConnection api.
|
||||
#include "media/base/video_capturer.h" // nogncheck
|
||||
// TODO(bugs.webrtc.org/7447): We plan to provide a way to let applications
|
||||
// inject a PacketSocketFactory and/or NetworkManager, and not expose
|
||||
// PortAllocator in the PeerConnection api.
|
||||
@ -125,7 +122,6 @@ class AudioDeviceModule;
|
||||
class AudioMixer;
|
||||
class AudioProcessing;
|
||||
class DtlsTransportInterface;
|
||||
class MediaConstraintsInterface;
|
||||
class VideoDecoderFactory;
|
||||
class VideoEncoderFactory;
|
||||
|
||||
@ -1344,30 +1340,6 @@ class PeerConnectionFactoryInterface : public rtc::RefCountInterface {
|
||||
virtual rtc::scoped_refptr<AudioSourceInterface> CreateAudioSource(
|
||||
const cricket::AudioOptions& options) = 0;
|
||||
|
||||
// Creates a VideoTrackSourceInterface from |capturer|.
|
||||
// TODO(deadbeef): We should aim to remove cricket::VideoCapturer from the
|
||||
// API. It's mainly used as a wrapper around webrtc's provided
|
||||
// platform-specific capturers, but these should be refactored to use
|
||||
// VideoTrackSourceInterface directly.
|
||||
// TODO(deadbeef): Make pure virtual once downstream mock PC factory classes
|
||||
// are updated.
|
||||
virtual rtc::scoped_refptr<VideoTrackSourceInterface> CreateVideoSource(
|
||||
std::unique_ptr<cricket::VideoCapturer> capturer);
|
||||
|
||||
// A video source creator that allows selection of resolution and frame rate.
|
||||
// |constraints| decides video resolution and frame rate but can be null.
|
||||
// In the null case, use the version above.
|
||||
//
|
||||
// |constraints| is only used for the invocation of this method, and can
|
||||
// safely be destroyed afterwards.
|
||||
virtual rtc::scoped_refptr<VideoTrackSourceInterface> CreateVideoSource(
|
||||
std::unique_ptr<cricket::VideoCapturer> capturer,
|
||||
const MediaConstraintsInterface* constraints);
|
||||
|
||||
// Deprecated; please use the versions that take unique_ptrs above.
|
||||
// TODO(deadbeef): Remove these once safe to do so.
|
||||
virtual rtc::scoped_refptr<VideoTrackSourceInterface> CreateVideoSource(
|
||||
cricket::VideoCapturer* capturer);
|
||||
// Creates a new local VideoTrack. The same |source| can be used in several
|
||||
// tracks.
|
||||
virtual rtc::scoped_refptr<VideoTrackInterface> CreateVideoTrack(
|
||||
|
||||
@ -175,8 +175,6 @@ rtc_static_library("peerconnection") {
|
||||
"stream_collection.h",
|
||||
"track_media_info_map.cc",
|
||||
"track_media_info_map.h",
|
||||
"video_capturer_track_source.cc",
|
||||
"video_capturer_track_source.h",
|
||||
"video_track.cc",
|
||||
"video_track.h",
|
||||
"video_track_source.cc",
|
||||
@ -491,7 +489,6 @@ if (rtc_include_tests) {
|
||||
"test/fake_audio_capture_module_unittest.cc",
|
||||
"test/test_sdp_strings.h",
|
||||
"track_media_info_map_unittest.cc",
|
||||
"video_capturer_track_source_unittest.cc",
|
||||
"video_track_unittest.cc",
|
||||
"webrtc_sdp_unittest.cc",
|
||||
]
|
||||
|
||||
@ -43,7 +43,6 @@
|
||||
#include "pc/sctp_utils.h"
|
||||
#include "pc/sdp_utils.h"
|
||||
#include "pc/stream_collection.h"
|
||||
#include "pc/video_capturer_track_source.h"
|
||||
#include "pc/video_track.h"
|
||||
#include "rtc_base/bind.h"
|
||||
#include "rtc_base/checks.h"
|
||||
|
||||
@ -35,7 +35,6 @@
|
||||
#include "pc/local_audio_source.h"
|
||||
#include "pc/media_stream.h"
|
||||
#include "pc/peer_connection.h"
|
||||
#include "pc/video_capturer_track_source.h"
|
||||
#include "pc/video_track.h"
|
||||
#include "system_wrappers/include/field_trial.h"
|
||||
|
||||
@ -287,29 +286,6 @@ PeerConnectionFactory::CreateAudioSource(const cricket::AudioOptions& options) {
|
||||
return source;
|
||||
}
|
||||
|
||||
rtc::scoped_refptr<VideoTrackSourceInterface>
|
||||
PeerConnectionFactory::CreateVideoSource(
|
||||
std::unique_ptr<cricket::VideoCapturer> capturer,
|
||||
const MediaConstraintsInterface* constraints) {
|
||||
RTC_DCHECK(signaling_thread_->IsCurrent());
|
||||
rtc::scoped_refptr<VideoTrackSourceInterface> source(
|
||||
VideoCapturerTrackSource::Create(worker_thread_, std::move(capturer),
|
||||
constraints, false));
|
||||
return VideoTrackSourceProxy::Create(signaling_thread_, worker_thread_,
|
||||
source);
|
||||
}
|
||||
|
||||
rtc::scoped_refptr<VideoTrackSourceInterface>
|
||||
PeerConnectionFactory::CreateVideoSource(
|
||||
std::unique_ptr<cricket::VideoCapturer> capturer) {
|
||||
RTC_DCHECK(signaling_thread_->IsCurrent());
|
||||
rtc::scoped_refptr<VideoTrackSourceInterface> source(
|
||||
VideoCapturerTrackSource::Create(worker_thread_, std::move(capturer),
|
||||
false));
|
||||
return VideoTrackSourceProxy::Create(signaling_thread_, worker_thread_,
|
||||
source);
|
||||
}
|
||||
|
||||
bool PeerConnectionFactory::StartAecDump(rtc::PlatformFile file,
|
||||
int64_t max_size_bytes) {
|
||||
RTC_DCHECK(signaling_thread_->IsCurrent());
|
||||
|
||||
@ -35,12 +35,6 @@ class RtcEventLog;
|
||||
|
||||
class PeerConnectionFactory : public PeerConnectionFactoryInterface {
|
||||
public:
|
||||
// Use the overloads of CreateVideoSource that take raw VideoCapturer
|
||||
// pointers from PeerConnectionFactoryInterface.
|
||||
// TODO(deadbeef): Remove this using statement once those overloads are
|
||||
// removed.
|
||||
using PeerConnectionFactoryInterface::CreateVideoSource;
|
||||
|
||||
void SetOptions(const Options& options) override;
|
||||
|
||||
rtc::scoped_refptr<PeerConnectionInterface> CreatePeerConnection(
|
||||
@ -67,16 +61,6 @@ class PeerConnectionFactory : public PeerConnectionFactoryInterface {
|
||||
rtc::scoped_refptr<AudioSourceInterface> CreateAudioSource(
|
||||
const cricket::AudioOptions& options) override;
|
||||
|
||||
rtc::scoped_refptr<VideoTrackSourceInterface> CreateVideoSource(
|
||||
std::unique_ptr<cricket::VideoCapturer> capturer) override;
|
||||
// This version supports filtering on width, height and frame rate.
|
||||
// For the "constraints=null" case, use the version without constraints.
|
||||
// TODO(hta): Design a version without MediaConstraintsInterface.
|
||||
// https://bugs.chromium.org/p/webrtc/issues/detail?id=5617
|
||||
rtc::scoped_refptr<VideoTrackSourceInterface> CreateVideoSource(
|
||||
std::unique_ptr<cricket::VideoCapturer> capturer,
|
||||
const MediaConstraintsInterface* constraints) override;
|
||||
|
||||
rtc::scoped_refptr<VideoTrackInterface> CreateVideoTrack(
|
||||
const std::string& id,
|
||||
VideoTrackSourceInterface* video_source) override;
|
||||
|
||||
@ -1,402 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012 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 "pc/video_capturer_track_source.h"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "api/media_constraints_interface.h"
|
||||
#include "rtc_base/arraysize.h"
|
||||
#include "rtc_base/checks.h"
|
||||
|
||||
using cricket::CaptureState;
|
||||
using webrtc::MediaConstraintsInterface;
|
||||
using webrtc::MediaSourceInterface;
|
||||
|
||||
namespace {
|
||||
|
||||
const double kRoundingTruncation = 0.0005;
|
||||
|
||||
// Default resolution. If no constraint is specified, this is the resolution we
|
||||
// will use.
|
||||
static const cricket::VideoFormatPod kDefaultFormat = {
|
||||
640, 480, FPS_TO_INTERVAL(30), cricket::FOURCC_ANY};
|
||||
|
||||
// List of formats used if the camera doesn't support capability enumeration.
|
||||
static const cricket::VideoFormatPod kVideoFormats[] = {
|
||||
{1920, 1080, FPS_TO_INTERVAL(30), cricket::FOURCC_ANY},
|
||||
{1280, 720, FPS_TO_INTERVAL(30), cricket::FOURCC_ANY},
|
||||
{960, 720, FPS_TO_INTERVAL(30), cricket::FOURCC_ANY},
|
||||
{640, 360, FPS_TO_INTERVAL(30), cricket::FOURCC_ANY},
|
||||
{640, 480, FPS_TO_INTERVAL(30), cricket::FOURCC_ANY},
|
||||
{320, 240, FPS_TO_INTERVAL(30), cricket::FOURCC_ANY},
|
||||
{320, 180, FPS_TO_INTERVAL(30), cricket::FOURCC_ANY}};
|
||||
|
||||
MediaSourceInterface::SourceState GetReadyState(cricket::CaptureState state) {
|
||||
switch (state) {
|
||||
case cricket::CS_STARTING:
|
||||
return MediaSourceInterface::kInitializing;
|
||||
case cricket::CS_RUNNING:
|
||||
return MediaSourceInterface::kLive;
|
||||
case cricket::CS_FAILED:
|
||||
case cricket::CS_STOPPED:
|
||||
return MediaSourceInterface::kEnded;
|
||||
default:
|
||||
RTC_NOTREACHED() << "GetReadyState unknown state";
|
||||
}
|
||||
return MediaSourceInterface::kEnded;
|
||||
}
|
||||
|
||||
void SetUpperLimit(int new_limit, int* original_limit) {
|
||||
if (*original_limit < 0 || new_limit < *original_limit)
|
||||
*original_limit = new_limit;
|
||||
}
|
||||
|
||||
// Updates |format_upper_limit| from |constraint|.
|
||||
// If constraint.maxFoo is smaller than format_upper_limit.foo,
|
||||
// set format_upper_limit.foo to constraint.maxFoo.
|
||||
void SetUpperLimitFromConstraint(
|
||||
const MediaConstraintsInterface::Constraint& constraint,
|
||||
cricket::VideoFormat* format_upper_limit) {
|
||||
if (constraint.key == MediaConstraintsInterface::kMaxWidth) {
|
||||
int value = rtc::FromString<int>(constraint.value);
|
||||
SetUpperLimit(value, &(format_upper_limit->width));
|
||||
} else if (constraint.key == MediaConstraintsInterface::kMaxHeight) {
|
||||
int value = rtc::FromString<int>(constraint.value);
|
||||
SetUpperLimit(value, &(format_upper_limit->height));
|
||||
}
|
||||
}
|
||||
|
||||
// Fills |format_out| with the max width and height allowed by |constraints|.
|
||||
void FromConstraintsForScreencast(
|
||||
const MediaConstraintsInterface::Constraints& constraints,
|
||||
cricket::VideoFormat* format_out) {
|
||||
typedef MediaConstraintsInterface::Constraints::const_iterator
|
||||
ConstraintsIterator;
|
||||
|
||||
cricket::VideoFormat upper_limit(-1, -1, 0, 0);
|
||||
for (ConstraintsIterator constraints_it = constraints.begin();
|
||||
constraints_it != constraints.end(); ++constraints_it)
|
||||
SetUpperLimitFromConstraint(*constraints_it, &upper_limit);
|
||||
|
||||
if (upper_limit.width >= 0)
|
||||
format_out->width = upper_limit.width;
|
||||
if (upper_limit.height >= 0)
|
||||
format_out->height = upper_limit.height;
|
||||
}
|
||||
|
||||
// Returns true if |constraint| is fulfilled. |format_out| can differ from
|
||||
// |format_in| if the format is changed by the constraint. Ie - the frame rate
|
||||
// can be changed by setting maxFrameRate.
|
||||
bool NewFormatWithConstraints(
|
||||
const MediaConstraintsInterface::Constraint& constraint,
|
||||
const cricket::VideoFormat& format_in,
|
||||
bool mandatory,
|
||||
cricket::VideoFormat* format_out) {
|
||||
RTC_DCHECK(format_out != NULL);
|
||||
*format_out = format_in;
|
||||
|
||||
if (constraint.key == MediaConstraintsInterface::kMinWidth) {
|
||||
int value = rtc::FromString<int>(constraint.value);
|
||||
return (value <= format_in.width);
|
||||
} else if (constraint.key == MediaConstraintsInterface::kMaxWidth) {
|
||||
int value = rtc::FromString<int>(constraint.value);
|
||||
return (value >= format_in.width);
|
||||
} else if (constraint.key == MediaConstraintsInterface::kMinHeight) {
|
||||
int value = rtc::FromString<int>(constraint.value);
|
||||
return (value <= format_in.height);
|
||||
} else if (constraint.key == MediaConstraintsInterface::kMaxHeight) {
|
||||
int value = rtc::FromString<int>(constraint.value);
|
||||
return (value >= format_in.height);
|
||||
} else if (constraint.key == MediaConstraintsInterface::kMinFrameRate) {
|
||||
int value = rtc::FromString<int>(constraint.value);
|
||||
return (value <= cricket::VideoFormat::IntervalToFps(format_in.interval));
|
||||
} else if (constraint.key == MediaConstraintsInterface::kMaxFrameRate) {
|
||||
int value = rtc::FromString<int>(constraint.value);
|
||||
if (value == 0) {
|
||||
if (mandatory) {
|
||||
// TODO(ronghuawu): Convert the constraint value to float when sub-1fps
|
||||
// is supported by the capturer.
|
||||
return false;
|
||||
} else {
|
||||
value = 1;
|
||||
}
|
||||
}
|
||||
if (value <= cricket::VideoFormat::IntervalToFps(format_in.interval))
|
||||
format_out->interval = cricket::VideoFormat::FpsToInterval(value);
|
||||
return true;
|
||||
} else if (constraint.key == MediaConstraintsInterface::kMinAspectRatio) {
|
||||
double value = rtc::FromString<double>(constraint.value);
|
||||
// The aspect ratio in |constraint.value| has been converted to a string and
|
||||
// back to a double, so it may have a rounding error.
|
||||
// E.g if the value 1/3 is converted to a string, the string will not have
|
||||
// infinite length.
|
||||
// We add a margin of 0.0005 which is high enough to detect the same aspect
|
||||
// ratio but small enough to avoid matching wrong aspect ratios.
|
||||
double ratio = static_cast<double>(format_in.width) / format_in.height;
|
||||
return (value <= ratio + kRoundingTruncation);
|
||||
} else if (constraint.key == MediaConstraintsInterface::kMaxAspectRatio) {
|
||||
double value = rtc::FromString<double>(constraint.value);
|
||||
double ratio = static_cast<double>(format_in.width) / format_in.height;
|
||||
// Subtract 0.0005 to avoid rounding problems. Same as above.
|
||||
const double kRoundingTruncation = 0.0005;
|
||||
return (value >= ratio - kRoundingTruncation);
|
||||
} else if (constraint.key == MediaConstraintsInterface::kNoiseReduction) {
|
||||
// These are actually options, not constraints, so they can be satisfied
|
||||
// regardless of the format.
|
||||
return true;
|
||||
}
|
||||
RTC_LOG(LS_WARNING) << "Found unknown MediaStream constraint. Name:"
|
||||
<< constraint.key << " Value:" << constraint.value;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Removes cricket::VideoFormats from |formats| that don't meet |constraint|.
|
||||
void FilterFormatsByConstraint(
|
||||
const MediaConstraintsInterface::Constraint& constraint,
|
||||
bool mandatory,
|
||||
std::vector<cricket::VideoFormat>* formats) {
|
||||
std::vector<cricket::VideoFormat>::iterator format_it = formats->begin();
|
||||
while (format_it != formats->end()) {
|
||||
// Modify the format_it to fulfill the constraint if possible.
|
||||
// Delete it otherwise.
|
||||
if (!NewFormatWithConstraints(constraint, (*format_it), mandatory,
|
||||
&(*format_it))) {
|
||||
format_it = formats->erase(format_it);
|
||||
} else {
|
||||
++format_it;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Returns a vector of cricket::VideoFormat that best match |constraints|.
|
||||
std::vector<cricket::VideoFormat> FilterFormats(
|
||||
const MediaConstraintsInterface::Constraints& mandatory,
|
||||
const MediaConstraintsInterface::Constraints& optional,
|
||||
const std::vector<cricket::VideoFormat>& supported_formats) {
|
||||
typedef MediaConstraintsInterface::Constraints::const_iterator
|
||||
ConstraintsIterator;
|
||||
std::vector<cricket::VideoFormat> candidates = supported_formats;
|
||||
|
||||
for (ConstraintsIterator constraints_it = mandatory.begin();
|
||||
constraints_it != mandatory.end(); ++constraints_it)
|
||||
FilterFormatsByConstraint(*constraints_it, true, &candidates);
|
||||
|
||||
if (candidates.size() == 0)
|
||||
return candidates;
|
||||
|
||||
// Ok - all mandatory checked and we still have a candidate.
|
||||
// Let's try filtering using the optional constraints.
|
||||
for (ConstraintsIterator constraints_it = optional.begin();
|
||||
constraints_it != optional.end(); ++constraints_it) {
|
||||
std::vector<cricket::VideoFormat> current_candidates = candidates;
|
||||
FilterFormatsByConstraint(*constraints_it, false, ¤t_candidates);
|
||||
if (current_candidates.size() > 0) {
|
||||
candidates = current_candidates;
|
||||
}
|
||||
}
|
||||
|
||||
// We have done as good as we can to filter the supported resolutions.
|
||||
return candidates;
|
||||
}
|
||||
|
||||
// Find the format that best matches the default video size.
|
||||
// Constraints are optional and since the performance of a video call
|
||||
// might be bad due to bitrate limitations, CPU, and camera performance,
|
||||
// it is better to select a resolution that is as close as possible to our
|
||||
// default and still meets the contraints.
|
||||
const cricket::VideoFormat& GetBestCaptureFormat(
|
||||
const std::vector<cricket::VideoFormat>& formats) {
|
||||
RTC_DCHECK(formats.size() > 0);
|
||||
|
||||
int default_area = kDefaultFormat.width * kDefaultFormat.height;
|
||||
|
||||
std::vector<cricket::VideoFormat>::const_iterator it = formats.begin();
|
||||
std::vector<cricket::VideoFormat>::const_iterator best_it = formats.begin();
|
||||
int best_diff_area = std::abs(default_area - it->width * it->height);
|
||||
int64_t best_diff_interval = kDefaultFormat.interval;
|
||||
for (; it != formats.end(); ++it) {
|
||||
int diff_area = std::abs(default_area - it->width * it->height);
|
||||
int64_t diff_interval = std::abs(kDefaultFormat.interval - it->interval);
|
||||
if (diff_area < best_diff_area ||
|
||||
(diff_area == best_diff_area && diff_interval < best_diff_interval)) {
|
||||
best_diff_area = diff_area;
|
||||
best_diff_interval = diff_interval;
|
||||
best_it = it;
|
||||
}
|
||||
}
|
||||
return *best_it;
|
||||
}
|
||||
|
||||
// Set |option| to the highest-priority value of |key| in the constraints.
|
||||
// Return false if the key is mandatory, and the value is invalid.
|
||||
bool ExtractOption(const MediaConstraintsInterface* all_constraints,
|
||||
const std::string& key,
|
||||
absl::optional<bool>* option) {
|
||||
size_t mandatory = 0;
|
||||
bool value;
|
||||
if (FindConstraint(all_constraints, key, &value, &mandatory)) {
|
||||
*option = value;
|
||||
return true;
|
||||
}
|
||||
|
||||
return mandatory == 0;
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
rtc::scoped_refptr<VideoTrackSourceInterface> VideoCapturerTrackSource::Create(
|
||||
rtc::Thread* worker_thread,
|
||||
std::unique_ptr<cricket::VideoCapturer> capturer,
|
||||
const webrtc::MediaConstraintsInterface* constraints,
|
||||
bool remote) {
|
||||
RTC_DCHECK(worker_thread != NULL);
|
||||
RTC_DCHECK(capturer != nullptr);
|
||||
rtc::scoped_refptr<VideoCapturerTrackSource> source(
|
||||
new rtc::RefCountedObject<VideoCapturerTrackSource>(
|
||||
worker_thread, std::move(capturer), remote));
|
||||
source->Initialize(constraints);
|
||||
return source;
|
||||
}
|
||||
|
||||
rtc::scoped_refptr<VideoTrackSourceInterface> VideoCapturerTrackSource::Create(
|
||||
rtc::Thread* worker_thread,
|
||||
std::unique_ptr<cricket::VideoCapturer> capturer,
|
||||
bool remote) {
|
||||
RTC_DCHECK(worker_thread != NULL);
|
||||
RTC_DCHECK(capturer != nullptr);
|
||||
rtc::scoped_refptr<VideoCapturerTrackSource> source(
|
||||
new rtc::RefCountedObject<VideoCapturerTrackSource>(
|
||||
worker_thread, std::move(capturer), remote));
|
||||
source->Initialize(nullptr);
|
||||
return source;
|
||||
}
|
||||
|
||||
VideoCapturerTrackSource::VideoCapturerTrackSource(
|
||||
rtc::Thread* worker_thread,
|
||||
std::unique_ptr<cricket::VideoCapturer> capturer,
|
||||
bool remote)
|
||||
: VideoTrackSource(remote),
|
||||
signaling_thread_(rtc::Thread::Current()),
|
||||
worker_thread_(worker_thread),
|
||||
video_capturer_(std::move(capturer)),
|
||||
started_(false) {
|
||||
video_capturer_->SignalStateChange.connect(
|
||||
this, &VideoCapturerTrackSource::OnStateChange);
|
||||
}
|
||||
|
||||
VideoCapturerTrackSource::~VideoCapturerTrackSource() {
|
||||
video_capturer_->SignalStateChange.disconnect(this);
|
||||
Stop();
|
||||
}
|
||||
|
||||
void VideoCapturerTrackSource::Initialize(
|
||||
const webrtc::MediaConstraintsInterface* constraints) {
|
||||
std::vector<cricket::VideoFormat> formats =
|
||||
*video_capturer_->GetSupportedFormats();
|
||||
if (formats.empty()) {
|
||||
if (video_capturer_->IsScreencast()) {
|
||||
// The screen capturer can accept any resolution and we will derive the
|
||||
// format from the constraints if any.
|
||||
// Note that this only affects tab capturing, not desktop capturing,
|
||||
// since the desktop capturer does not respect the VideoFormat passed in.
|
||||
formats.push_back(cricket::VideoFormat(kDefaultFormat));
|
||||
} else {
|
||||
// The VideoCapturer implementation doesn't support capability
|
||||
// enumeration. We need to guess what the camera supports.
|
||||
for (uint32_t i = 0; i < arraysize(kVideoFormats); ++i) {
|
||||
formats.push_back(cricket::VideoFormat(kVideoFormats[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (constraints) {
|
||||
MediaConstraintsInterface::Constraints mandatory_constraints =
|
||||
constraints->GetMandatory();
|
||||
MediaConstraintsInterface::Constraints optional_constraints;
|
||||
optional_constraints = constraints->GetOptional();
|
||||
|
||||
if (video_capturer_->IsScreencast()) {
|
||||
// Use the maxWidth and maxHeight allowed by constraints for screencast.
|
||||
FromConstraintsForScreencast(mandatory_constraints, &(formats[0]));
|
||||
}
|
||||
|
||||
formats =
|
||||
FilterFormats(mandatory_constraints, optional_constraints, formats);
|
||||
}
|
||||
|
||||
if (formats.size() == 0) {
|
||||
RTC_LOG(LS_WARNING) << "Failed to find a suitable video format.";
|
||||
SetState(kEnded);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ExtractOption(constraints, MediaConstraintsInterface::kNoiseReduction,
|
||||
&needs_denoising_)) {
|
||||
RTC_LOG(LS_WARNING) << "Invalid mandatory value for"
|
||||
<< MediaConstraintsInterface::kNoiseReduction;
|
||||
SetState(kEnded);
|
||||
return;
|
||||
}
|
||||
|
||||
format_ = GetBestCaptureFormat(formats);
|
||||
// Start the camera with our best guess.
|
||||
if (!worker_thread_->Invoke<bool>(
|
||||
RTC_FROM_HERE, rtc::Bind(&cricket::VideoCapturer::StartCapturing,
|
||||
video_capturer_.get(), format_))) {
|
||||
SetState(kEnded);
|
||||
return;
|
||||
}
|
||||
started_ = true;
|
||||
// Initialize hasn't succeeded until a successful state change has occurred.
|
||||
}
|
||||
|
||||
bool VideoCapturerTrackSource::GetStats(Stats* stats) {
|
||||
return video_capturer_->GetInputSize(&stats->input_width,
|
||||
&stats->input_height);
|
||||
}
|
||||
|
||||
void VideoCapturerTrackSource::Stop() {
|
||||
if (!started_) {
|
||||
return;
|
||||
}
|
||||
started_ = false;
|
||||
worker_thread_->Invoke<void>(
|
||||
RTC_FROM_HERE,
|
||||
rtc::Bind(&cricket::VideoCapturer::Stop, video_capturer_.get()));
|
||||
}
|
||||
|
||||
// OnStateChange listens to the cricket::VideoCapturer::SignalStateChange.
|
||||
void VideoCapturerTrackSource::OnStateChange(
|
||||
cricket::VideoCapturer* capturer,
|
||||
cricket::CaptureState capture_state) {
|
||||
if (rtc::Thread::Current() != signaling_thread_) {
|
||||
// Use rtc::Unretained, because we don't want this to capture a reference
|
||||
// to ourselves. If our destructor is called while this task is executing,
|
||||
// that's fine; our AsyncInvoker destructor will wait for it to finish if
|
||||
// it isn't simply canceled.
|
||||
invoker_.AsyncInvoke<void>(
|
||||
RTC_FROM_HERE, signaling_thread_,
|
||||
rtc::Bind(&VideoCapturerTrackSource::OnStateChange,
|
||||
rtc::Unretained(this), capturer, capture_state));
|
||||
return;
|
||||
}
|
||||
|
||||
if (capturer == video_capturer_.get()) {
|
||||
SetState(GetReadyState(capture_state));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
@ -1,86 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012 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 PC_VIDEO_CAPTURER_TRACK_SOURCE_H_
|
||||
#define PC_VIDEO_CAPTURER_TRACK_SOURCE_H_
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "api/media_stream_interface.h"
|
||||
#include "media/base/video_capturer.h"
|
||||
#include "media/base/video_common.h"
|
||||
#include "pc/video_track_source.h"
|
||||
#include "rtc_base/async_invoker.h"
|
||||
#include "rtc_base/third_party/sigslot/sigslot.h"
|
||||
|
||||
// VideoCapturerTrackSource implements VideoTrackSourceInterface. It owns a
|
||||
// cricket::VideoCapturer and make sure the camera is started at a resolution
|
||||
// that honors the constraints.
|
||||
// The state is set depending on the result of starting the capturer.
|
||||
// If the constraint can't be met or the capturer fails to start, the state
|
||||
// transition to kEnded, otherwise it transitions to kLive.
|
||||
namespace webrtc {
|
||||
|
||||
class MediaConstraintsInterface;
|
||||
|
||||
class VideoCapturerTrackSource : public VideoTrackSource,
|
||||
public sigslot::has_slots<> {
|
||||
public:
|
||||
// Creates an instance of VideoCapturerTrackSource from |capturer|.
|
||||
// |constraints| can be NULL and in that case the camera is opened using a
|
||||
// default resolution.
|
||||
static rtc::scoped_refptr<VideoTrackSourceInterface> Create(
|
||||
rtc::Thread* worker_thread,
|
||||
std::unique_ptr<cricket::VideoCapturer> capturer,
|
||||
const webrtc::MediaConstraintsInterface* constraints,
|
||||
bool remote);
|
||||
|
||||
static rtc::scoped_refptr<VideoTrackSourceInterface> Create(
|
||||
rtc::Thread* worker_thread,
|
||||
std::unique_ptr<cricket::VideoCapturer> capturer,
|
||||
bool remote);
|
||||
|
||||
bool is_screencast() const final { return video_capturer_->IsScreencast(); }
|
||||
absl::optional<bool> needs_denoising() const final {
|
||||
return needs_denoising_;
|
||||
}
|
||||
|
||||
bool GetStats(Stats* stats) final;
|
||||
|
||||
protected:
|
||||
VideoCapturerTrackSource(rtc::Thread* worker_thread,
|
||||
std::unique_ptr<cricket::VideoCapturer> capturer,
|
||||
bool remote);
|
||||
virtual ~VideoCapturerTrackSource();
|
||||
|
||||
rtc::VideoSourceInterface<VideoFrame>* source() override {
|
||||
return video_capturer_.get();
|
||||
}
|
||||
|
||||
void Initialize(const webrtc::MediaConstraintsInterface* constraints);
|
||||
|
||||
private:
|
||||
void Stop();
|
||||
|
||||
void OnStateChange(cricket::VideoCapturer* capturer,
|
||||
cricket::CaptureState capture_state);
|
||||
|
||||
rtc::Thread* signaling_thread_;
|
||||
rtc::Thread* worker_thread_;
|
||||
rtc::AsyncInvoker invoker_;
|
||||
std::unique_ptr<cricket::VideoCapturer> video_capturer_;
|
||||
bool started_;
|
||||
cricket::VideoFormat format_;
|
||||
absl::optional<bool> needs_denoising_;
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // PC_VIDEO_CAPTURER_TRACK_SOURCE_H_
|
||||
@ -1,471 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012 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 <stddef.h>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "api/test/fake_constraints.h"
|
||||
#include "media/base/fake_video_capturer.h"
|
||||
#include "media/base/fake_video_renderer.h"
|
||||
#include "media/base/media_channel.h"
|
||||
#include "pc/video_capturer_track_source.h"
|
||||
#include "rtc_base/arraysize.h"
|
||||
#include "rtc_base/event.h"
|
||||
#include "rtc_base/gunit.h"
|
||||
#include "rtc_base/task_queue.h"
|
||||
#include "test/gtest.h"
|
||||
|
||||
using cricket::FOURCC_I420;
|
||||
using cricket::VideoFormat;
|
||||
using webrtc::FakeConstraints;
|
||||
using webrtc::MediaConstraintsInterface;
|
||||
using webrtc::MediaSourceInterface;
|
||||
using webrtc::ObserverInterface;
|
||||
using webrtc::VideoCapturerTrackSource;
|
||||
using webrtc::VideoTrackSourceInterface;
|
||||
|
||||
namespace {
|
||||
|
||||
// Max wait time for a test.
|
||||
const int kMaxWaitMs = 100;
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
// TestVideoCapturer extends cricket::FakeVideoCapturer so it can be used for
|
||||
// testing without known camera formats.
|
||||
// It keeps its own lists of cricket::VideoFormats for the unit tests in this
|
||||
// file.
|
||||
class TestVideoCapturer : public cricket::FakeVideoCapturer {
|
||||
public:
|
||||
explicit TestVideoCapturer(bool is_screencast)
|
||||
: FakeVideoCapturer(is_screencast), test_without_formats_(false) {
|
||||
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
|
||||
// simulating a cricket::VideoCapturer implementation that don't support
|
||||
// capture format enumeration. This is used to simulate the current
|
||||
// Chrome implementation.
|
||||
void TestWithoutCameraFormats() {
|
||||
test_without_formats_ = true;
|
||||
std::vector<VideoFormat> formats;
|
||||
ResetSupportedFormats(formats);
|
||||
}
|
||||
|
||||
virtual cricket::CaptureState Start(const VideoFormat& capture_format) {
|
||||
if (test_without_formats_) {
|
||||
std::vector<VideoFormat> formats;
|
||||
formats.push_back(capture_format);
|
||||
ResetSupportedFormats(formats);
|
||||
}
|
||||
return FakeVideoCapturer::Start(capture_format);
|
||||
}
|
||||
|
||||
virtual bool GetBestCaptureFormat(const VideoFormat& desired,
|
||||
VideoFormat* best_format) {
|
||||
if (test_without_formats_) {
|
||||
*best_format = desired;
|
||||
return true;
|
||||
}
|
||||
return FakeVideoCapturer::GetBestCaptureFormat(desired, best_format);
|
||||
}
|
||||
|
||||
private:
|
||||
bool test_without_formats_;
|
||||
};
|
||||
|
||||
class StateObserver : public ObserverInterface {
|
||||
public:
|
||||
explicit StateObserver(VideoTrackSourceInterface* source)
|
||||
: state_(source->state()), source_(source) {}
|
||||
virtual void OnChanged() { state_ = source_->state(); }
|
||||
MediaSourceInterface::SourceState state() const { return state_; }
|
||||
|
||||
private:
|
||||
MediaSourceInterface::SourceState state_;
|
||||
rtc::scoped_refptr<VideoTrackSourceInterface> source_;
|
||||
};
|
||||
|
||||
class VideoCapturerTrackSourceTest : public testing::Test {
|
||||
protected:
|
||||
VideoCapturerTrackSourceTest() { InitCapturer(false); }
|
||||
void InitCapturer(bool is_screencast) {
|
||||
capturer_ = new TestVideoCapturer(is_screencast);
|
||||
capturer_cleanup_.reset(capturer_);
|
||||
}
|
||||
|
||||
void InitScreencast() { InitCapturer(true); }
|
||||
|
||||
void CreateVideoCapturerSource() { CreateVideoCapturerSource(NULL); }
|
||||
|
||||
void CreateVideoCapturerSource(
|
||||
const webrtc::MediaConstraintsInterface* constraints) {
|
||||
source_ = VideoCapturerTrackSource::Create(rtc::Thread::Current(),
|
||||
std::move(capturer_cleanup_),
|
||||
constraints, false);
|
||||
|
||||
ASSERT_TRUE(source_.get() != NULL);
|
||||
|
||||
state_observer_.reset(new StateObserver(source_));
|
||||
source_->RegisterObserver(state_observer_.get());
|
||||
source_->AddOrUpdateSink(&renderer_, rtc::VideoSinkWants());
|
||||
}
|
||||
|
||||
void CaptureSingleFrame() {
|
||||
rtc::Event event;
|
||||
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_;
|
||||
std::unique_ptr<StateObserver> state_observer_;
|
||||
rtc::scoped_refptr<VideoTrackSourceInterface> source_;
|
||||
};
|
||||
|
||||
// Test that a VideoSource transition to kLive state when the capture
|
||||
// device have started and kEnded if it is stopped.
|
||||
// It also test that an output can receive video frames.
|
||||
TEST_F(VideoCapturerTrackSourceTest, CapturerStartStop) {
|
||||
// Initialize without constraints.
|
||||
CreateVideoCapturerSource();
|
||||
EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(),
|
||||
kMaxWaitMs);
|
||||
|
||||
CaptureSingleFrame();
|
||||
EXPECT_EQ(1, renderer_.num_rendered_frames());
|
||||
|
||||
capturer_->Stop();
|
||||
EXPECT_EQ_WAIT(MediaSourceInterface::kEnded, state_observer_->state(),
|
||||
kMaxWaitMs);
|
||||
}
|
||||
|
||||
// Test that a VideoSource transition to kEnded if the capture device
|
||||
// fails.
|
||||
TEST_F(VideoCapturerTrackSourceTest, CameraFailed) {
|
||||
CreateVideoCapturerSource();
|
||||
EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(),
|
||||
kMaxWaitMs);
|
||||
|
||||
capturer_->SignalStateChange(capturer_, cricket::CS_FAILED);
|
||||
EXPECT_EQ_WAIT(MediaSourceInterface::kEnded, state_observer_->state(),
|
||||
kMaxWaitMs);
|
||||
}
|
||||
|
||||
// Test that the capture output is CIF if we set max constraints to CIF.
|
||||
// and the capture device support CIF.
|
||||
TEST_F(VideoCapturerTrackSourceTest, MandatoryConstraintCif5Fps) {
|
||||
FakeConstraints constraints;
|
||||
constraints.AddMandatory(MediaConstraintsInterface::kMaxWidth, 352);
|
||||
constraints.AddMandatory(MediaConstraintsInterface::kMaxHeight, 288);
|
||||
constraints.AddMandatory(MediaConstraintsInterface::kMaxFrameRate, 5);
|
||||
|
||||
CreateVideoCapturerSource(&constraints);
|
||||
EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(),
|
||||
kMaxWaitMs);
|
||||
const VideoFormat* format = capturer_->GetCaptureFormat();
|
||||
ASSERT_TRUE(format != NULL);
|
||||
EXPECT_EQ(352, format->width);
|
||||
EXPECT_EQ(288, format->height);
|
||||
EXPECT_EQ(5, format->framerate());
|
||||
}
|
||||
|
||||
// Test that the capture output is 720P if the camera support it and the
|
||||
// optional constraint is set to 720P.
|
||||
TEST_F(VideoCapturerTrackSourceTest, MandatoryMinVgaOptional720P) {
|
||||
FakeConstraints constraints;
|
||||
constraints.AddMandatory(MediaConstraintsInterface::kMinWidth, 640);
|
||||
constraints.AddMandatory(MediaConstraintsInterface::kMinHeight, 480);
|
||||
constraints.AddOptional(MediaConstraintsInterface::kMinWidth, 1280);
|
||||
constraints.AddOptional(MediaConstraintsInterface::kMinAspectRatio,
|
||||
1280.0 / 720);
|
||||
|
||||
CreateVideoCapturerSource(&constraints);
|
||||
EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(),
|
||||
kMaxWaitMs);
|
||||
const VideoFormat* format = capturer_->GetCaptureFormat();
|
||||
ASSERT_TRUE(format != NULL);
|
||||
EXPECT_EQ(1280, format->width);
|
||||
EXPECT_EQ(720, format->height);
|
||||
EXPECT_EQ(30, format->framerate());
|
||||
}
|
||||
|
||||
// Test that the capture output have aspect ratio 4:3 if a mandatory constraint
|
||||
// require it even if an optional constraint request a higher resolution
|
||||
// that don't have this aspect ratio.
|
||||
TEST_F(VideoCapturerTrackSourceTest, MandatoryAspectRatio4To3) {
|
||||
FakeConstraints constraints;
|
||||
constraints.AddMandatory(MediaConstraintsInterface::kMinWidth, 640);
|
||||
constraints.AddMandatory(MediaConstraintsInterface::kMinHeight, 480);
|
||||
constraints.AddMandatory(MediaConstraintsInterface::kMaxAspectRatio,
|
||||
640.0 / 480);
|
||||
constraints.AddOptional(MediaConstraintsInterface::kMinWidth, 1280);
|
||||
|
||||
CreateVideoCapturerSource(&constraints);
|
||||
EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(),
|
||||
kMaxWaitMs);
|
||||
const VideoFormat* format = capturer_->GetCaptureFormat();
|
||||
ASSERT_TRUE(format != NULL);
|
||||
EXPECT_EQ(640, format->width);
|
||||
EXPECT_EQ(480, format->height);
|
||||
EXPECT_EQ(30, format->framerate());
|
||||
}
|
||||
|
||||
// Test that the source state transition to kEnded if the mandatory aspect ratio
|
||||
// is set higher than supported.
|
||||
TEST_F(VideoCapturerTrackSourceTest, MandatoryAspectRatioTooHigh) {
|
||||
FakeConstraints constraints;
|
||||
constraints.AddMandatory(MediaConstraintsInterface::kMinAspectRatio, 2);
|
||||
CreateVideoCapturerSource(&constraints);
|
||||
EXPECT_EQ_WAIT(MediaSourceInterface::kEnded, state_observer_->state(),
|
||||
kMaxWaitMs);
|
||||
}
|
||||
|
||||
// Test that the source ignores an optional aspect ratio that is higher than
|
||||
// supported.
|
||||
TEST_F(VideoCapturerTrackSourceTest, OptionalAspectRatioTooHigh) {
|
||||
FakeConstraints constraints;
|
||||
constraints.AddOptional(MediaConstraintsInterface::kMinAspectRatio, 2);
|
||||
CreateVideoCapturerSource(&constraints);
|
||||
EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(),
|
||||
kMaxWaitMs);
|
||||
const VideoFormat* format = capturer_->GetCaptureFormat();
|
||||
ASSERT_TRUE(format != NULL);
|
||||
double aspect_ratio = static_cast<double>(format->width) / format->height;
|
||||
EXPECT_LT(aspect_ratio, 2);
|
||||
}
|
||||
|
||||
// Test that the source starts video with the default resolution if the
|
||||
// camera doesn't support capability enumeration and there are no constraints.
|
||||
TEST_F(VideoCapturerTrackSourceTest, NoCameraCapability) {
|
||||
capturer_->TestWithoutCameraFormats();
|
||||
|
||||
CreateVideoCapturerSource();
|
||||
EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(),
|
||||
kMaxWaitMs);
|
||||
const VideoFormat* format = capturer_->GetCaptureFormat();
|
||||
ASSERT_TRUE(format != NULL);
|
||||
EXPECT_EQ(640, format->width);
|
||||
EXPECT_EQ(480, format->height);
|
||||
EXPECT_EQ(30, format->framerate());
|
||||
}
|
||||
|
||||
// Test that the source can start the video and get the requested aspect ratio
|
||||
// if the camera doesn't support capability enumeration and the aspect ratio is
|
||||
// set.
|
||||
TEST_F(VideoCapturerTrackSourceTest, NoCameraCapability16To9Ratio) {
|
||||
capturer_->TestWithoutCameraFormats();
|
||||
|
||||
FakeConstraints constraints;
|
||||
double requested_aspect_ratio = 640.0 / 360;
|
||||
constraints.AddMandatory(MediaConstraintsInterface::kMinWidth, 640);
|
||||
constraints.AddMandatory(MediaConstraintsInterface::kMinAspectRatio,
|
||||
requested_aspect_ratio);
|
||||
|
||||
CreateVideoCapturerSource(&constraints);
|
||||
EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(),
|
||||
kMaxWaitMs);
|
||||
const VideoFormat* format = capturer_->GetCaptureFormat();
|
||||
double aspect_ratio = static_cast<double>(format->width) / format->height;
|
||||
EXPECT_LE(requested_aspect_ratio, aspect_ratio);
|
||||
}
|
||||
|
||||
// Test that the source state transitions to kEnded if an unknown mandatory
|
||||
// constraint is found.
|
||||
TEST_F(VideoCapturerTrackSourceTest, InvalidMandatoryConstraint) {
|
||||
FakeConstraints constraints;
|
||||
constraints.AddMandatory("weird key", 640);
|
||||
|
||||
CreateVideoCapturerSource(&constraints);
|
||||
EXPECT_EQ_WAIT(MediaSourceInterface::kEnded, state_observer_->state(),
|
||||
kMaxWaitMs);
|
||||
}
|
||||
|
||||
// Test that the source ignores an unknown optional constraint.
|
||||
TEST_F(VideoCapturerTrackSourceTest, InvalidOptionalConstraint) {
|
||||
FakeConstraints constraints;
|
||||
constraints.AddOptional("weird key", 640);
|
||||
|
||||
CreateVideoCapturerSource(&constraints);
|
||||
EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(),
|
||||
kMaxWaitMs);
|
||||
}
|
||||
|
||||
TEST_F(VideoCapturerTrackSourceTest, SetValidDenoisingConstraint) {
|
||||
FakeConstraints constraints;
|
||||
constraints.AddMandatory(MediaConstraintsInterface::kNoiseReduction, "false");
|
||||
|
||||
CreateVideoCapturerSource(&constraints);
|
||||
|
||||
EXPECT_EQ(false, source_->needs_denoising());
|
||||
}
|
||||
|
||||
TEST_F(VideoCapturerTrackSourceTest, NoiseReductionConstraintNotSet) {
|
||||
FakeConstraints constraints;
|
||||
CreateVideoCapturerSource(&constraints);
|
||||
EXPECT_EQ(absl::nullopt, source_->needs_denoising());
|
||||
}
|
||||
|
||||
TEST_F(VideoCapturerTrackSourceTest,
|
||||
MandatoryDenoisingConstraintOverridesOptional) {
|
||||
FakeConstraints constraints;
|
||||
constraints.AddMandatory(MediaConstraintsInterface::kNoiseReduction, false);
|
||||
constraints.AddOptional(MediaConstraintsInterface::kNoiseReduction, true);
|
||||
|
||||
CreateVideoCapturerSource(&constraints);
|
||||
|
||||
EXPECT_EQ(false, source_->needs_denoising());
|
||||
}
|
||||
|
||||
TEST_F(VideoCapturerTrackSourceTest, NoiseReductionAndInvalidKeyOptional) {
|
||||
FakeConstraints constraints;
|
||||
constraints.AddOptional(MediaConstraintsInterface::kNoiseReduction, true);
|
||||
constraints.AddOptional("invalidKey", false);
|
||||
|
||||
CreateVideoCapturerSource(&constraints);
|
||||
|
||||
EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(),
|
||||
kMaxWaitMs);
|
||||
EXPECT_EQ(true, source_->needs_denoising());
|
||||
}
|
||||
|
||||
TEST_F(VideoCapturerTrackSourceTest, NoiseReductionAndInvalidKeyMandatory) {
|
||||
FakeConstraints constraints;
|
||||
constraints.AddMandatory(MediaConstraintsInterface::kNoiseReduction, false);
|
||||
constraints.AddMandatory("invalidKey", false);
|
||||
|
||||
CreateVideoCapturerSource(&constraints);
|
||||
|
||||
EXPECT_EQ_WAIT(MediaSourceInterface::kEnded, state_observer_->state(),
|
||||
kMaxWaitMs);
|
||||
EXPECT_EQ(absl::nullopt, source_->needs_denoising());
|
||||
}
|
||||
|
||||
TEST_F(VideoCapturerTrackSourceTest, InvalidDenoisingValueOptional) {
|
||||
FakeConstraints constraints;
|
||||
constraints.AddOptional(MediaConstraintsInterface::kNoiseReduction,
|
||||
"not a boolean");
|
||||
|
||||
CreateVideoCapturerSource(&constraints);
|
||||
|
||||
EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(),
|
||||
kMaxWaitMs);
|
||||
|
||||
EXPECT_EQ(absl::nullopt, source_->needs_denoising());
|
||||
}
|
||||
|
||||
TEST_F(VideoCapturerTrackSourceTest, InvalidDenoisingValueMandatory) {
|
||||
FakeConstraints constraints;
|
||||
// absl::optional constraints should be ignored if the mandatory constraints
|
||||
// fail.
|
||||
constraints.AddOptional(MediaConstraintsInterface::kNoiseReduction, "false");
|
||||
// Values are case-sensitive and must be all lower-case.
|
||||
constraints.AddMandatory(MediaConstraintsInterface::kNoiseReduction, "True");
|
||||
|
||||
CreateVideoCapturerSource(&constraints);
|
||||
|
||||
EXPECT_EQ_WAIT(MediaSourceInterface::kEnded, state_observer_->state(),
|
||||
kMaxWaitMs);
|
||||
EXPECT_EQ(absl::nullopt, source_->needs_denoising());
|
||||
}
|
||||
|
||||
TEST_F(VideoCapturerTrackSourceTest, MixedOptionsAndConstraints) {
|
||||
FakeConstraints constraints;
|
||||
constraints.AddMandatory(MediaConstraintsInterface::kMaxWidth, 352);
|
||||
constraints.AddMandatory(MediaConstraintsInterface::kMaxHeight, 288);
|
||||
constraints.AddOptional(MediaConstraintsInterface::kMaxFrameRate, 5);
|
||||
|
||||
constraints.AddMandatory(MediaConstraintsInterface::kNoiseReduction, false);
|
||||
constraints.AddOptional(MediaConstraintsInterface::kNoiseReduction, true);
|
||||
|
||||
CreateVideoCapturerSource(&constraints);
|
||||
EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(),
|
||||
kMaxWaitMs);
|
||||
const VideoFormat* format = capturer_->GetCaptureFormat();
|
||||
ASSERT_TRUE(format != NULL);
|
||||
EXPECT_EQ(352, format->width);
|
||||
EXPECT_EQ(288, format->height);
|
||||
EXPECT_EQ(5, format->framerate());
|
||||
|
||||
EXPECT_EQ(false, source_->needs_denoising());
|
||||
}
|
||||
|
||||
// Tests that the source starts video with the default resolution for
|
||||
// screencast if no constraint is set.
|
||||
TEST_F(VideoCapturerTrackSourceTest, ScreencastResolutionNoConstraint) {
|
||||
InitScreencast();
|
||||
capturer_->TestWithoutCameraFormats();
|
||||
|
||||
CreateVideoCapturerSource();
|
||||
ASSERT_TRUE(source_->is_screencast());
|
||||
EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(),
|
||||
kMaxWaitMs);
|
||||
const VideoFormat* format = capturer_->GetCaptureFormat();
|
||||
ASSERT_TRUE(format != NULL);
|
||||
EXPECT_EQ(640, format->width);
|
||||
EXPECT_EQ(480, format->height);
|
||||
EXPECT_EQ(30, format->framerate());
|
||||
}
|
||||
|
||||
// Tests that the source starts video with the max width and height set by
|
||||
// constraints for screencast.
|
||||
TEST_F(VideoCapturerTrackSourceTest, ScreencastResolutionWithConstraint) {
|
||||
FakeConstraints constraints;
|
||||
constraints.AddMandatory(MediaConstraintsInterface::kMaxWidth, 480);
|
||||
constraints.AddMandatory(MediaConstraintsInterface::kMaxHeight, 270);
|
||||
|
||||
InitScreencast();
|
||||
capturer_->TestWithoutCameraFormats();
|
||||
|
||||
CreateVideoCapturerSource(&constraints);
|
||||
ASSERT_TRUE(source_->is_screencast());
|
||||
EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(),
|
||||
kMaxWaitMs);
|
||||
const VideoFormat* format = capturer_->GetCaptureFormat();
|
||||
ASSERT_TRUE(format != NULL);
|
||||
EXPECT_EQ(480, format->width);
|
||||
EXPECT_EQ(270, format->height);
|
||||
EXPECT_EQ(30, format->framerate());
|
||||
}
|
||||
|
||||
TEST_F(VideoCapturerTrackSourceTest, MandatorySubOneFpsConstraints) {
|
||||
FakeConstraints constraints;
|
||||
constraints.AddMandatory(MediaConstraintsInterface::kMaxFrameRate, 0);
|
||||
|
||||
CreateVideoCapturerSource(&constraints);
|
||||
EXPECT_EQ_WAIT(MediaSourceInterface::kEnded, state_observer_->state(),
|
||||
kMaxWaitMs);
|
||||
ASSERT_TRUE(capturer_->GetCaptureFormat() == NULL);
|
||||
}
|
||||
|
||||
TEST_F(VideoCapturerTrackSourceTest, OptionalSubOneFpsConstraints) {
|
||||
FakeConstraints constraints;
|
||||
constraints.AddOptional(MediaConstraintsInterface::kMaxFrameRate, 0);
|
||||
|
||||
CreateVideoCapturerSource(&constraints);
|
||||
EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(),
|
||||
kMaxWaitMs);
|
||||
const VideoFormat* format = capturer_->GetCaptureFormat();
|
||||
ASSERT_TRUE(format != NULL);
|
||||
EXPECT_EQ(1, format->framerate());
|
||||
}
|
||||
@ -14,6 +14,7 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "api/media_constraints_interface.h"
|
||||
#include "api/peer_connection_interface.h"
|
||||
#include "sdk/android/src/jni/jni_helpers.h"
|
||||
#include "sdk/android/src/jni/pc/session_description.h"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user