Commit 6b396491 authored by Guido Urdaneta's avatar Guido Urdaneta Committed by Commit Bot

Support all constrainable properties for audio tracks in MediaStreamTrack.getSettings().

Intent to Ship thread:
https://groups.google.com/a/chromium.org/forum/#!msg/blink-dev/wJwVSo52Dno/CjrUTTuyBAAJ

Bug: 731170
Change-Id: I53274b2bf5a622cb50d4b59f521bf56160172b61
Reviewed-on: https://chromium-review.googlesource.com/1100884
Commit-Queue: Guido Urdaneta <guidou@chromium.org>
Reviewed-by: default avatarHarald Alvestrand <hta@chromium.org>
Reviewed-by: default avatarPhilip Jägenstedt <foolip@chromium.org>
Cr-Commit-Position: refs/heads/master@{#569288}
parent 5879a9d2
...@@ -18,8 +18,10 @@ ...@@ -18,8 +18,10 @@
#include "content/renderer/media/stream/media_stream_source.h" #include "content/renderer/media/stream/media_stream_source.h"
#include "content/renderer/media/stream/media_stream_video_source.h" #include "content/renderer/media/stream/media_stream_video_source.h"
#include "content/renderer/media/stream/media_stream_video_track.h" #include "content/renderer/media/stream/media_stream_video_track.h"
#include "content/renderer/media/stream/processed_local_audio_source.h"
#include "content/renderer/media/stream/webaudio_media_stream_source.h" #include "content/renderer/media/stream/webaudio_media_stream_source.h"
#include "content/renderer/media/webrtc_local_audio_source_provider.h" #include "content/renderer/media/webrtc_local_audio_source_provider.h"
#include "media/base/sample_format.h"
#include "third_party/blink/public/platform/web_media_constraints.h" #include "third_party/blink/public/platform/web_media_constraints.h"
#include "third_party/blink/public/platform/web_media_stream.h" #include "third_party/blink/public/platform/web_media_stream.h"
#include "third_party/blink/public/platform/web_media_stream_source.h" #include "third_party/blink/public/platform/web_media_stream_source.h"
...@@ -189,4 +191,28 @@ void MediaStreamCenter::DidStopMediaStreamSource( ...@@ -189,4 +191,28 @@ void MediaStreamCenter::DidStopMediaStreamSource(
source->StopSource(); source->StopSource();
} }
void MediaStreamCenter::GetSourceSettings(
const blink::WebMediaStreamSource& web_source,
blink::WebMediaStreamTrack::Settings& settings) {
MediaStreamAudioSource* const source =
MediaStreamAudioSource::From(web_source);
if (!source)
return;
media::AudioParameters audio_parameters = source->GetAudioParameters();
settings.sample_rate = audio_parameters.sample_rate();
// kSampleFormatS16 is the format used for all audio input streams.
settings.sample_size =
media::SampleFormatToBitsPerChannel(media::kSampleFormatS16);
settings.channel_count = audio_parameters.channels();
settings.latency = audio_parameters.GetBufferDuration().InSecondsF();
ProcessedLocalAudioSource* const processed_source =
ProcessedLocalAudioSource::From(source);
settings.volume = processed_source
? static_cast<double>(processed_source->Volume()) /
processed_source->MaxVolume()
: 1.0;
}
} // namespace content } // namespace content
...@@ -44,6 +44,10 @@ class CONTENT_EXPORT MediaStreamCenter : public blink::WebMediaStreamCenter { ...@@ -44,6 +44,10 @@ class CONTENT_EXPORT MediaStreamCenter : public blink::WebMediaStreamCenter {
void DidStopMediaStreamSource( void DidStopMediaStreamSource(
const blink::WebMediaStreamSource& web_source) override; const blink::WebMediaStreamSource& web_source) override;
void GetSourceSettings(
const blink::WebMediaStreamSource& web_source,
blink::WebMediaStreamTrack::Settings& settings) override;
DISALLOW_COPY_AND_ASSIGN(MediaStreamCenter); DISALLOW_COPY_AND_ASSIGN(MediaStreamCenter);
}; };
......
...@@ -75,4 +75,36 @@ ...@@ -75,4 +75,36 @@
} }
}); });
}, 'groupId is correctly reported by getSettings() for all devices'); }, 'groupId is correctly reported by getSettings() for all devices');
promise_test(t => {
return navigator.mediaDevices.getUserMedia({audio: true}).then(stream => {
let settings = stream.getAudioTracks()[0].getSettings();
assert_equals(typeof(settings.deviceId), "string",
"deviceId should exist and it should be a string.");
assert_equals(typeof(settings.groupId), "string",
"groupId should exist and it should be a string.");
assert_equals(typeof(settings.volume), "number",
"volume should exist and it should be a number.");
assert_true(settings.volume >= 0.0 && settings.volume <= 1.0,
"volume should be a number in the range [0.0, 1.0].");
assert_equals(typeof(settings.sampleRate), "number",
"sampleRate should exist and it should be a number.");
assert_true(settings.sampleRate > 0, "sampleRate should be positive.");
assert_equals(typeof(settings.sampleSize), "number",
"sampleSize should exist and it should be a number.");
assert_true(settings.sampleSize > 0, "sampleSize should be positive.");
assert_equals(typeof(settings.echoCancellation), "boolean",
"echoCancellation should exist and it should be a boolean.");
assert_equals(typeof(settings.autoGainControl), "boolean",
"autoGainControl should exist and it should be a boolean.");
assert_equals(typeof(settings.noiseSuppression), "boolean",
"noiseSuppression should exist and it should be a boolean.");
assert_equals(typeof(settings.latency), "number",
"latency should exist and it should be a number.");
assert_true(settings.latency >= 0, "latency should not be negative.");
assert_equals(typeof(settings.channelCount), "number",
"channelCount should exist and it should be a number.");
assert_true(settings.channelCount > 0, "channelCount should be positive.");
});
}, 'audio properties are reported by getSettings()');
</script> </script>
...@@ -31,6 +31,8 @@ ...@@ -31,6 +31,8 @@
#ifndef THIRD_PARTY_BLINK_PUBLIC_PLATFORM_WEB_MEDIA_STREAM_CENTER_H_ #ifndef THIRD_PARTY_BLINK_PUBLIC_PLATFORM_WEB_MEDIA_STREAM_CENTER_H_
#define THIRD_PARTY_BLINK_PUBLIC_PLATFORM_WEB_MEDIA_STREAM_CENTER_H_ #define THIRD_PARTY_BLINK_PUBLIC_PLATFORM_WEB_MEDIA_STREAM_CENTER_H_
#include "third_party/blink/public/platform/web_media_stream_track.h"
namespace blink { namespace blink {
class WebAudioSourceProvider; class WebAudioSourceProvider;
...@@ -51,6 +53,8 @@ class WebMediaStreamCenter { ...@@ -51,6 +53,8 @@ class WebMediaStreamCenter {
// Source functionality. // Source functionality.
virtual void DidStopMediaStreamSource(const WebMediaStreamSource&) {} virtual void DidStopMediaStreamSource(const WebMediaStreamSource&) {}
virtual void GetSourceSettings(const WebMediaStreamSource&,
WebMediaStreamTrack::Settings&) {}
// Caller must take the ownership of the returned |WebAudioSourceProvider| // Caller must take the ownership of the returned |WebAudioSourceProvider|
// object. // object.
......
...@@ -50,6 +50,11 @@ class WebMediaStreamTrack { ...@@ -50,6 +50,11 @@ class WebMediaStreamTrack {
bool HasHeight() const { return height >= 0; } bool HasHeight() const { return height >= 0; }
bool HasAspectRatio() const { return aspect_ratio >= 0.0; } bool HasAspectRatio() const { return aspect_ratio >= 0.0; }
bool HasFacingMode() const { return facing_mode != FacingMode::kNone; } bool HasFacingMode() const { return facing_mode != FacingMode::kNone; }
bool HasSampleRate() const { return sample_rate >= 0; }
bool HasSampleSize() const { return sample_size >= 0; }
bool HasChannelCount() const { return channel_count >= 0; }
bool HasLatency() const { return latency >= 0; }
bool HasVolume() const { return volume >= 0; }
bool HasVideoKind() const { return !video_kind.IsNull(); } bool HasVideoKind() const { return !video_kind.IsNull(); }
bool HasFocalLengthX() const { return focal_length_x >= 0.0; } bool HasFocalLengthX() const { return focal_length_x >= 0.0; }
bool HasFocalLengthY() const { return focal_length_y >= 0.0; } bool HasFocalLengthY() const { return focal_length_y >= 0.0; }
...@@ -68,6 +73,12 @@ class WebMediaStreamTrack { ...@@ -68,6 +73,12 @@ class WebMediaStreamTrack {
base::Optional<bool> auto_gain_control; base::Optional<bool> auto_gain_control;
base::Optional<bool> noise_supression; base::Optional<bool> noise_supression;
WebString echo_cancellation_type; WebString echo_cancellation_type;
long sample_rate = -1;
long sample_size = -1;
long channel_count = -1;
double latency = -1.0;
double volume = -1.0;
// Media Capture Depth Stream Extensions. // Media Capture Depth Stream Extensions.
WebString video_kind; WebString video_kind;
double focal_length_x = -1.0; double focal_length_x = -1.0;
......
...@@ -475,6 +475,17 @@ void MediaStreamTrack::getSettings(MediaTrackSettings& settings) { ...@@ -475,6 +475,17 @@ void MediaStreamTrack::getSettings(MediaTrackSettings& settings) {
settings.setEchoCancellationType(platform_settings.echo_cancellation_type); settings.setEchoCancellationType(platform_settings.echo_cancellation_type);
} }
if (platform_settings.HasSampleRate())
settings.setSampleRate(platform_settings.sample_rate);
if (platform_settings.HasSampleSize())
settings.setSampleSize(platform_settings.sample_size);
if (platform_settings.HasChannelCount())
settings.setChannelCount(platform_settings.channel_count);
if (platform_settings.HasLatency())
settings.setLatency(platform_settings.latency);
if (platform_settings.HasVolume())
settings.setVolume(platform_settings.volume);
if (image_capture_) if (image_capture_)
image_capture_->GetMediaTrackSettings(settings); image_capture_->GetMediaTrackSettings(settings);
} }
......
...@@ -10,19 +10,17 @@ dictionary MediaTrackSettings { ...@@ -10,19 +10,17 @@ dictionary MediaTrackSettings {
double aspectRatio; double aspectRatio;
double frameRate; double frameRate;
DOMString facingMode; DOMString facingMode;
// volume, sampleRate and sampleSize are not implemented. double volume;
// double volume; long sampleRate;
// long sampleRate; long sampleSize;
// long sampleSize;
boolean echoCancellation; boolean echoCancellation;
boolean autoGainControl; boolean autoGainControl;
boolean noiseSuppression; boolean noiseSuppression;
[OriginTrialEnabled=ExperimentalHardwareEchoCancellation] DOMString echoCancellationType; double latency;
// latency and channelCount are not implemented. long channelCount;
// double latency;
// long channelCount;
DOMString deviceId; DOMString deviceId;
DOMString groupId; DOMString groupId;
[OriginTrialEnabled=ExperimentalHardwareEchoCancellation] DOMString echoCancellationType;
// Media Capture Depth Stream Extensions // Media Capture Depth Stream Extensions
// https://w3c.github.io/mediacapture-depth/#mediatracksettings-dictionary // https://w3c.github.io/mediacapture-depth/#mediatracksettings-dictionary
// TODO(aleksandar.stojiljkovic): videoKind, depthNear, depthFar, // TODO(aleksandar.stojiljkovic): videoKind, depthNear, depthFar,
......
...@@ -39,7 +39,6 @@ ...@@ -39,7 +39,6 @@
#include "third_party/blink/public/platform/web_media_stream.h" #include "third_party/blink/public/platform/web_media_stream.h"
#include "third_party/blink/public/platform/web_media_stream_center.h" #include "third_party/blink/public/platform/web_media_stream_center.h"
#include "third_party/blink/public/platform/web_media_stream_source.h" #include "third_party/blink/public/platform/web_media_stream_source.h"
#include "third_party/blink/public/platform/web_media_stream_track.h"
#include "third_party/blink/renderer/platform/mediastream/media_stream_descriptor.h" #include "third_party/blink/renderer/platform/mediastream/media_stream_descriptor.h"
#include "third_party/blink/renderer/platform/mediastream/media_stream_web_audio_source.h" #include "third_party/blink/renderer/platform/mediastream/media_stream_web_audio_source.h"
#include "third_party/blink/renderer/platform/wtf/assertions.h" #include "third_party/blink/renderer/platform/wtf/assertions.h"
...@@ -113,4 +112,11 @@ void MediaStreamCenter::DidStopMediaStreamSource(MediaStreamSource* source) { ...@@ -113,4 +112,11 @@ void MediaStreamCenter::DidStopMediaStreamSource(MediaStreamSource* source) {
private_->DidStopMediaStreamSource(source); private_->DidStopMediaStreamSource(source);
} }
void MediaStreamCenter::GetSourceSettings(
MediaStreamSource* source,
WebMediaStreamTrack::Settings& settings) {
if (private_)
private_->GetSourceSettings(source, settings);
}
} // namespace blink } // namespace blink
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/scoped_refptr.h" #include "base/memory/scoped_refptr.h"
#include "third_party/blink/public/platform/web_media_stream_track.h"
#include "third_party/blink/renderer/platform/heap/handle.h" #include "third_party/blink/renderer/platform/heap/handle.h"
#include "third_party/blink/renderer/platform/platform_export.h" #include "third_party/blink/renderer/platform/platform_export.h"
#include "third_party/blink/renderer/platform/wtf/allocator.h" #include "third_party/blink/renderer/platform/wtf/allocator.h"
...@@ -68,6 +69,8 @@ class PLATFORM_EXPORT MediaStreamCenter { ...@@ -68,6 +69,8 @@ class PLATFORM_EXPORT MediaStreamCenter {
void DidStopMediaStreamSource(MediaStreamSource*); void DidStopMediaStreamSource(MediaStreamSource*);
void GetSourceSettings(MediaStreamSource*, WebMediaStreamTrack::Settings&);
private: private:
MediaStreamCenter(); MediaStreamCenter();
......
...@@ -29,6 +29,8 @@ ...@@ -29,6 +29,8 @@
*/ */
#include "third_party/blink/renderer/platform/mediastream/media_stream_source.h" #include "third_party/blink/renderer/platform/mediastream/media_stream_source.h"
#include "third_party/blink/renderer/platform/mediastream/media_stream_center.h"
#include "third_party/blink/renderer/platform/wtf/assertions.h" #include "third_party/blink/renderer/platform/wtf/assertions.h"
namespace blink { namespace blink {
...@@ -146,6 +148,8 @@ void MediaStreamSource::GetSettings(WebMediaStreamTrack::Settings& settings) { ...@@ -146,6 +148,8 @@ void MediaStreamSource::GetSettings(WebMediaStreamTrack::Settings& settings) {
settings.auto_gain_control = *auto_gain_control_; settings.auto_gain_control = *auto_gain_control_;
if (noise_supression_) if (noise_supression_)
settings.noise_supression = *noise_supression_; settings.noise_supression = *noise_supression_;
MediaStreamCenter::Instance().GetSourceSettings(this, settings);
} }
void MediaStreamSource::SetAudioFormat(size_t number_of_channels, void MediaStreamSource::SetAudioFormat(size_t number_of_channels,
......
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