Commit b9487f88 authored by hta's avatar hta Committed by Commit bot

Apply new-style constraints to video_source.

This CL reimplements the algorithms presently used for selection
in terms of the new form constraints.
A new mock constraints factory is also added.

BUG=543997

Review URL: https://codereview.chromium.org/1617243005

Cr-Commit-Position: refs/heads/master@{#372082}
parent a9422c2d
......@@ -780,6 +780,7 @@
'renderer/media/media_stream_video_renderer_sink_unittest.cc',
'renderer/media/media_stream_video_source_unittest.cc',
'renderer/media/media_stream_video_track_unittest.cc',
'renderer/media/mock_constraint_factory.cc',
'renderer/media/mock_media_constraint_factory.cc',
'renderer/media/mock_media_stream_registry.cc',
'renderer/media/mock_media_stream_registry.h',
......
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <stddef.h>
#include "base/macros.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "content/renderer/media/media_stream_audio_processor_options.h"
#include "content/renderer/media/mock_constraint_factory.h"
#include "third_party/libjingle/source/talk/app/webrtc/mediaconstraintsinterface.h"
namespace content {
MockConstraintFactory::MockConstraintFactory() {}
MockConstraintFactory::~MockConstraintFactory() {}
blink::WebMediaTrackConstraintSet& MockConstraintFactory::AddAdvanced() {
advanced_.emplace_back();
return advanced_.back();
}
blink::WebMediaConstraints MockConstraintFactory::CreateWebMediaConstraints()
const {
blink::WebMediaConstraints constraints;
constraints.initialize(basic_, advanced_);
return constraints;
}
} // namespace content
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_RENDERER_MEDIA_MOCK_CONSTRAINT_FACTORY_H_
#define CONTENT_RENDERER_MEDIA_MOCK_CONSTRAINT_FACTORY_H_
#include <string>
#include <vector>
#include "third_party/WebKit/public/platform/WebMediaConstraints.h"
namespace content {
class MockConstraintFactory {
public:
MockConstraintFactory();
~MockConstraintFactory();
blink::WebMediaConstraints CreateWebMediaConstraints() const;
blink::WebMediaTrackConstraintSet& basic() { return basic_; }
blink::WebMediaTrackConstraintSet& AddAdvanced();
private:
blink::WebMediaTrackConstraintSet basic_;
std::vector<blink::WebMediaTrackConstraintSet> advanced_;
DISALLOW_COPY_AND_ASSIGN(MockConstraintFactory);
};
} // namespace content
#endif // CONTENT_RENDERER_MEDIA_MOCK_CONSTRAINT_FACTORY_H_
......@@ -334,7 +334,7 @@
}
function failedCallback(error) {
failTest('GetUserMedia call failed with code ' + error.code);
failTest('GetUserMedia call failed with error name ' + error.name);
}
function attachMediaStream(stream, videoElement) {
......@@ -502,7 +502,8 @@
if (++attempt > maxAttempts) {
clearInterval(detectorInterval);
failTest("Aspect ratio corrupted. X " + maxLightGreenPixelsX +
" Y " + maxLightGreenPixelsY);
" Y " + maxLightGreenPixelsY + " width " + width +
" height " + height);
}
else {
// We have a bad aspect ratio now; give a chance to shape up.
......
......@@ -72,3 +72,21 @@ TEST(MediaTrackConstraintsTest, ConstraintName)
blink::BooleanConstraint boolConstraint(theName);
EXPECT_EQ(theName, boolConstraint.name());
}
TEST(MediaTrackConstraintsTest, MandatoryChecks)
{
blink::WebMediaTrackConstraintSet theSet;
std::string foundName;
EXPECT_FALSE(theSet.hasMandatory());
EXPECT_FALSE(theSet.hasMandatoryOutsideSet({ "width" }, foundName));
EXPECT_FALSE(theSet.width.hasMandatory());
theSet.width.setMax(240);
EXPECT_TRUE(theSet.width.hasMandatory());
EXPECT_TRUE(theSet.hasMandatory());
EXPECT_FALSE(theSet.hasMandatoryOutsideSet({ "width" }, foundName));
EXPECT_TRUE(theSet.hasMandatoryOutsideSet({ "height" }, foundName));
EXPECT_EQ("width", foundName);
theSet.googPayloadPadding.setExact(true);
EXPECT_TRUE(theSet.hasMandatoryOutsideSet({ "width" }, foundName));
EXPECT_EQ("googPayloadPadding", foundName);
}
......@@ -186,6 +186,11 @@ bool LongConstraint::isEmpty() const
return !m_hasMin && !m_hasMax && !m_hasExact && !m_hasIdeal;
}
bool LongConstraint::hasMandatory() const
{
return m_hasMin || m_hasMax || m_hasExact;
}
const double DoubleConstraint::kConstraintEpsilon = 0.00001;
DoubleConstraint::DoubleConstraint(const char* name)
......@@ -220,6 +225,11 @@ bool DoubleConstraint::isEmpty() const
return !m_hasMin && !m_hasMax && !m_hasExact && !m_hasIdeal;
}
bool DoubleConstraint::hasMandatory() const
{
return m_hasMin || m_hasMax || m_hasExact;
}
StringConstraint::StringConstraint(const char* name)
: BaseConstraint(name)
, m_exact()
......@@ -245,6 +255,11 @@ bool StringConstraint::isEmpty() const
return m_exact.isEmpty() && m_ideal.isEmpty();
}
bool StringConstraint::hasMandatory() const
{
return !m_exact.isEmpty();
}
const WebVector<WebString>& StringConstraint::exact() const
{
return m_exact;
......@@ -277,6 +292,11 @@ bool BooleanConstraint::isEmpty() const
return !m_hasIdeal && !m_hasExact;
}
bool BooleanConstraint::hasMandatory() const
{
return m_hasExact;
}
WebMediaTrackConstraintSet::WebMediaTrackConstraintSet()
: width("width")
, height("height")
......@@ -332,24 +352,59 @@ WebMediaTrackConstraintSet::WebMediaTrackConstraintSet()
{
}
std::vector<const BaseConstraint*> WebMediaTrackConstraintSet::allConstraints() const
{
const BaseConstraint* temp[] = {
&width, &height, &aspectRatio, &frameRate, &facingMode, &volume,
&sampleRate, &sampleSize, &echoCancellation, &latency, &channelCount,
&deviceId, &groupId, &mediaStreamSource, &renderToAssociatedSink,
&hotwordEnabled, &googEchoCancellation,
&googExperimentalEchoCancellation, &googAutoGainControl,
&googExperimentalAutoGainControl, &googNoiseSuppression,
&googHighpassFilter, &googTypingNoiseDetection,
&googExperimentalNoiseSuppression, &googBeamforming,
&googArrayGeometry, &googAudioMirroring, &googDAEchoCancellation,
&googAecDump, &googNoiseReduction, &offerToReceiveAudio,
&offerToReceiveVideo, &voiceActivityDetection, &iceRestart,
&googUseRtpMux, &enableDtlsSrtp, &enableRtpDataChannels,
&enableDscp, &enableIPv6, &googEnableVideoSuspendBelowMinBitrate,
&googNumUnsignalledRecvStreams, &googCombinedAudioVideoBwe,
&googScreencastMinBitrate, &googCpuOveruseDetection,
&googCpuUnderuseThreshold, &googCpuOveruseThreshold,
&googCpuUnderuseEncodeRsdThreshold, &googCpuOveruseEncodeRsdThreshold,
&googCpuOveruseEncodeUsage, &googHighStartBitrate, &googPayloadPadding
};
const int elementCount = sizeof(temp) / sizeof(temp[0]);
return std::vector<const BaseConstraint*>(&temp[0], &temp[elementCount]);
}
bool WebMediaTrackConstraintSet::isEmpty() const
{
return width.isEmpty() && height.isEmpty() && aspectRatio.isEmpty()
&& frameRate.isEmpty() && facingMode.isEmpty() && volume.isEmpty()
&& sampleRate.isEmpty() && sampleSize.isEmpty()
&& echoCancellation.isEmpty() && latency.isEmpty()
&& channelCount.isEmpty() && deviceId.isEmpty() && groupId.isEmpty()
&& mediaStreamSource.isEmpty() && renderToAssociatedSink.isEmpty()
&& hotwordEnabled.isEmpty() && googEchoCancellation.isEmpty()
&& googExperimentalEchoCancellation.isEmpty()
&& googAutoGainControl.isEmpty()
&& googExperimentalAutoGainControl.isEmpty()
&& googNoiseSuppression.isEmpty()
&& googHighpassFilter.isEmpty()
&& googTypingNoiseDetection.isEmpty()
&& googExperimentalNoiseSuppression.isEmpty()
&& googBeamforming.isEmpty() && googArrayGeometry.isEmpty()
&& googAudioMirroring.isEmpty();
for (const auto& constraint : allConstraints()) {
if (!constraint->isEmpty())
return false;
}
return true;
}
bool WebMediaTrackConstraintSet::hasMandatoryOutsideSet(const std::vector<std::string>& goodNames, std::string& foundName) const
{
for (const auto& constraint : allConstraints()) {
if (constraint->hasMandatory()) {
if (std::find(goodNames.begin(), goodNames.end(), constraint->name())
== goodNames.end()) {
foundName = constraint->name();
return true;
}
}
}
return false;
}
bool WebMediaTrackConstraintSet::hasMandatory() const
{
std::string dummyString;
return hasMandatoryOutsideSet(std::vector<std::string>(), dummyString);
}
// WebMediaConstraints
......
......@@ -37,6 +37,8 @@
#include "WebString.h"
#include "WebVector.h"
#include <vector>
namespace blink {
class WebMediaConstraintsPrivate;
......@@ -46,7 +48,8 @@ public:
explicit BaseConstraint(const char* name);
virtual ~BaseConstraint();
virtual bool isEmpty() const = 0;
const char* name()
virtual bool hasMandatory() const = 0;
const char* name() const
{
return m_name;
}
......@@ -84,6 +87,11 @@ public:
bool matches(long value) const;
bool isEmpty() const override;
bool hasMandatory() const override;
bool hasMin() const { return m_hasMin; }
long min() const { return m_min; }
bool hasMax() const { return m_hasMax; }
long max() const { return m_max; }
private:
long m_min;
......@@ -131,6 +139,11 @@ public:
bool matches(double value) const;
bool isEmpty() const override;
bool hasMandatory() const override;
bool hasMin() const { return m_hasMin; }
double min() const { return m_min; }
bool hasMax() const { return m_hasMax; }
double max() const { return m_max; }
private:
double m_min;
......@@ -167,6 +180,7 @@ public:
bool matches(WebString value) const;
bool isEmpty() const override;
bool hasMandatory() const override;
const WebVector<WebString>& exact() const;
const WebVector<WebString>& ideal() const;
......@@ -193,6 +207,7 @@ public:
bool matches(bool value) const;
bool isEmpty() const override;
bool hasMandatory() const override;
private:
unsigned m_ideal : 1;
......@@ -260,6 +275,11 @@ public:
BooleanConstraint googPayloadPadding;
BLINK_PLATFORM_EXPORT bool isEmpty() const;
BLINK_PLATFORM_EXPORT bool hasMandatory() const;
BLINK_PLATFORM_EXPORT bool hasMandatoryOutsideSet(const std::vector<std::string>&, std::string&) const;
private:
std::vector<const BaseConstraint*> allConstraints() const;
};
// Old type/value form of constraint. Will be deprecated.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment