Commit 636394fb authored by Chandan Padhi's avatar Chandan Padhi Committed by Commit Bot

Introduce InputDeviceInfo interface

InputDeviceInfo extends MediaDeviceInfo and represents audio and video input
devices. These objects are the result of calling MediaDevices.enumerateDevices().
This interface gives access to the capabilities of the input device it represents
via getCapabilities() method which will be implemented in asubsequent CL.

Intent to implement and ship:
https://groups.google.com/a/chromium.org/forum/#!topic/blink-dev/h4sCuIqb_78

Bug: 817769
Change-Id: Ic9a016a05e622ee02b86d567f64c3ed84f0926c3
Reviewed-on: https://chromium-review.googlesource.com/942961
Commit-Queue: Guido Urdaneta <guidou@chromium.org>
Reviewed-by: default avatarGuido Urdaneta <guidou@chromium.org>
Reviewed-by: default avatarPhilip Jägenstedt <foolip@chromium.org>
Cr-Commit-Position: refs/heads/master@{#541772}
parent 43db8c36
......@@ -167,6 +167,7 @@ enum MediaDeviceKind {
"videoinput"
};
[Exposed=Window]
interface InputDeviceInfo : MediaDeviceInfo {
MediaTrackCapabilities getCapabilities();
};
......
This is a testharness.js-based test.
Found 135 tests; 118 PASS, 17 FAIL, 0 TIMEOUT, 0 NOTRUN.
Found 135 tests; 125 PASS, 10 FAIL, 0 TIMEOUT, 0 NOTRUN.
PASS Test driver
PASS Navigator interface: attribute mediaDevices
PASS Unscopable handled correctly for mediaDevices property on Navigator
......@@ -127,13 +127,13 @@ PASS MediaDeviceInfo interface: attribute groupId
PASS Unscopable handled correctly for groupId property on MediaDeviceInfo
PASS MediaDeviceInfo interface: operation toJSON()
PASS Unscopable handled correctly for toJSON() on MediaDeviceInfo
FAIL InputDeviceInfo interface: existence and properties of interface object assert_own_property: self does not have own property "InputDeviceInfo" expected property "InputDeviceInfo" missing
FAIL InputDeviceInfo interface object length assert_own_property: self does not have own property "InputDeviceInfo" expected property "InputDeviceInfo" missing
FAIL InputDeviceInfo interface object name assert_own_property: self does not have own property "InputDeviceInfo" expected property "InputDeviceInfo" missing
FAIL InputDeviceInfo interface: existence and properties of interface prototype object assert_own_property: self does not have own property "InputDeviceInfo" expected property "InputDeviceInfo" missing
FAIL InputDeviceInfo interface: existence and properties of interface prototype object's "constructor" property assert_own_property: self does not have own property "InputDeviceInfo" expected property "InputDeviceInfo" missing
FAIL InputDeviceInfo interface: existence and properties of interface prototype object's @@unscopables property assert_own_property: self does not have own property "InputDeviceInfo" expected property "InputDeviceInfo" missing
FAIL InputDeviceInfo interface: operation getCapabilities() assert_own_property: self does not have own property "InputDeviceInfo" expected property "InputDeviceInfo" missing
PASS InputDeviceInfo interface: existence and properties of interface object
PASS InputDeviceInfo interface object length
PASS InputDeviceInfo interface object name
PASS InputDeviceInfo interface: existence and properties of interface prototype object
PASS InputDeviceInfo interface: existence and properties of interface prototype object's "constructor" property
PASS InputDeviceInfo interface: existence and properties of interface prototype object's @@unscopables property
PASS InputDeviceInfo interface: operation getCapabilities()
PASS Unscopable handled correctly for getCapabilities() on InputDeviceInfo
Harness: the test ran to completion.
This is a testharness.js-based test.
Found 133 tests; 118 PASS, 15 FAIL, 0 TIMEOUT, 0 NOTRUN.
Found 134 tests; 126 PASS, 8 FAIL, 0 TIMEOUT, 0 NOTRUN.
PASS Test MediaDevices.enumerateDevices call and result. Types only.
PASS Navigator interface: attribute mediaDevices
PASS Unscopable handled correctly for mediaDevices property on Navigator
......@@ -117,21 +117,22 @@ PASS MediaDeviceInfo interface: attribute groupId
PASS Unscopable handled correctly for groupId property on MediaDeviceInfo
PASS MediaDeviceInfo interface: operation toJSON()
PASS Unscopable handled correctly for toJSON() on MediaDeviceInfo
PASS MediaDeviceInfo must be primary interface of _mediaInfo
PASS Stringification of _mediaInfo
PASS MediaDeviceInfo interface: _mediaInfo must inherit property "deviceId" with the proper type
PASS MediaDeviceInfo interface: _mediaInfo must inherit property "kind" with the proper type
PASS MediaDeviceInfo interface: _mediaInfo must inherit property "label" with the proper type
PASS MediaDeviceInfo interface: _mediaInfo must inherit property "groupId" with the proper type
PASS MediaDeviceInfo interface: _mediaInfo must inherit property "toJSON()" with the proper type
PASS Test default toJSON operation of MediaDeviceInfo
FAIL InputDeviceInfo interface: existence and properties of interface object assert_own_property: self does not have own property "InputDeviceInfo" expected property "InputDeviceInfo" missing
FAIL InputDeviceInfo interface object length assert_own_property: self does not have own property "InputDeviceInfo" expected property "InputDeviceInfo" missing
FAIL InputDeviceInfo interface object name assert_own_property: self does not have own property "InputDeviceInfo" expected property "InputDeviceInfo" missing
FAIL InputDeviceInfo interface: existence and properties of interface prototype object assert_own_property: self does not have own property "InputDeviceInfo" expected property "InputDeviceInfo" missing
FAIL InputDeviceInfo interface: existence and properties of interface prototype object's "constructor" property assert_own_property: self does not have own property "InputDeviceInfo" expected property "InputDeviceInfo" missing
FAIL InputDeviceInfo interface: existence and properties of interface prototype object's @@unscopables property assert_own_property: self does not have own property "InputDeviceInfo" expected property "InputDeviceInfo" missing
FAIL InputDeviceInfo interface: operation getCapabilities() assert_own_property: self does not have own property "InputDeviceInfo" expected property "InputDeviceInfo" missing
PASS InputDeviceInfo interface: existence and properties of interface object
PASS InputDeviceInfo interface object length
PASS InputDeviceInfo interface object name
PASS InputDeviceInfo interface: existence and properties of interface prototype object
PASS InputDeviceInfo interface: existence and properties of interface prototype object's "constructor" property
PASS InputDeviceInfo interface: existence and properties of interface prototype object's @@unscopables property
PASS InputDeviceInfo interface: operation getCapabilities()
PASS Unscopable handled correctly for getCapabilities() on InputDeviceInfo
PASS InputDeviceInfo must be primary interface of [object InputDeviceInfo]
PASS Stringification of [object InputDeviceInfo]
PASS InputDeviceInfo interface: [object InputDeviceInfo] must inherit property "getCapabilities()" with the proper type
PASS MediaDeviceInfo interface: [object InputDeviceInfo] must inherit property "deviceId" with the proper type
PASS MediaDeviceInfo interface: [object InputDeviceInfo] must inherit property "kind" with the proper type
PASS MediaDeviceInfo interface: [object InputDeviceInfo] must inherit property "label" with the proper type
PASS MediaDeviceInfo interface: [object InputDeviceInfo] must inherit property "groupId" with the proper type
PASS MediaDeviceInfo interface: [object InputDeviceInfo] must inherit property "toJSON()" with the proper type
PASS Test default toJSON operation of MediaDeviceInfo
Harness: the test ran to completion.
......@@ -34,15 +34,20 @@
return navigator.mediaDevices.enumerateDevices()
.then(function(list) {
if( list.length > 0 ) {
window._mediaInfo = list[0];
MDI_idl.add_objects({MediaDeviceInfo: ["_mediaInfo"]});
var kind = list[0].kind;
if (kind == "audioinput" ||
kind == "videoinput") {
MDI_idl.add_objects({InputDeviceInfo: [list[0]]});
} else if (kind == "audiooutput" ) {
MDI_idl.add_objects({MediaDeviceInfo: [list[0]]});
}
}
for(const media of list) {
if( media.kind == "audioinput" ||
if (media.kind == "audioinput" ||
media.kind == "videoinput") {
// TODO -- Check InputDeviceInfo IDL, getCapabilities()
} else if ( media.kind == "audiooutput" ) {
} else if (media.kind == "audiooutput" ) {
// TODO -- pass
} else {
assert_unreached("media.kind should be one of 'audioinput', 'videoinput', or 'audiooutput'.")
......
......@@ -20,20 +20,18 @@ test(function () {
assert_true(undefined !== navigator.mediaDevices.enumerateDevices, "navigator.mediaDevices.enumerateDevices exists");
var p = navigator.mediaDevices.enumerateDevices()
p.then(function(list){
for(let mediainfo of list){
// TODO check the type of mediainfo
for (let mediainfo of list) {
assert_true(undefined !== mediainfo.deviceId, "mediaInfo's deviceId should exist.");
assert_true(undefined !== mediainfo.kind, "mediaInfo's kind should exist.");
assert_true(undefined !== mediainfo.label, "mediaInfo's label should exist.");
assert_true(undefined !== mediainfo.groupId, "mediaInfo's groupId should exist.");
// TODO the values of some of those fields should be empty string by default if no permission has been requested.
if( mediainfo.kind == "audioinput" ||
if ( mediainfo.kind == "audioinput" ||
mediainfo.kind == "videoinput") {
// NOTE ALEX: looks like nobody has implemented that. How can I make it a separate test,
// ... to have better granularity?
// assert_true(undefined !== mediainfo.getCapabilities(), "MediaDeviceInfo.getCapabilities() exists.");
// var cap = mediainfo.getcapabilities();
} else if ( mediainfo.kind !== "audiooutput" ) {
assert_true(mediainfo instanceof InputDeviceInfo);
} else if ( mediainfo.kind == "audiooutput" ) {
assert_true(mediainfo instanceof MediaDeviceInfo);
} else {
assert_unreached("mediainfo.kind should be one of 'audioinput', 'videoinput', or 'audiooutput'.")
}
}
......
......@@ -3511,6 +3511,10 @@ interface InputDeviceCapabilities
attribute @@toStringTag
getter firesTouchEvents
method constructor
interface InputDeviceInfo : MediaDeviceInfo
attribute @@toStringTag
method constructor
method getCapabilities
interface InputEvent : UIEvent
attribute @@toStringTag
getter data
......
......@@ -3970,6 +3970,10 @@ interface InputDeviceCapabilities
attribute @@toStringTag
getter firesTouchEvents
method constructor
interface InputDeviceInfo : MediaDeviceInfo
attribute @@toStringTag
method constructor
method getCapabilities
interface InputEvent : UIEvent
attribute @@toStringTag
getter data
......
......@@ -9,6 +9,8 @@ blink_modules_sources("mediastream") {
"ApplyConstraintsRequest.cpp",
"ApplyConstraintsRequest.h",
"DOMWindowMediaStream.h",
"InputDeviceInfo.cpp",
"InputDeviceInfo.h",
"MediaConstraintsImpl.cpp",
"MediaConstraintsImpl.h",
"MediaDeviceInfo.cpp",
......
// Copyright 2018 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 "modules/mediastream/InputDeviceInfo.h"
#include "modules/mediastream/MediaTrackCapabilities.h"
namespace blink {
InputDeviceInfo* InputDeviceInfo::Create(const String& device_id,
const String& label,
const String& group_id,
MediaDeviceType device_type) {
return new InputDeviceInfo(device_id, label, group_id, device_type);
}
InputDeviceInfo::InputDeviceInfo(const String& device_id,
const String& label,
const String& group_id,
MediaDeviceType device_type)
: MediaDeviceInfo(device_id, label, group_id, device_type) {}
void InputDeviceInfo::getCapabilities(MediaTrackCapabilities& capabilities) {}
} // namespace blink
// Copyright 2018 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 InputDeviceInfo_h
#define InputDeviceInfo_h
#include "modules/mediastream/MediaDeviceInfo.h"
namespace blink {
class MediaTrackCapabilities;
class InputDeviceInfo final : public MediaDeviceInfo {
DEFINE_WRAPPERTYPEINFO();
public:
static InputDeviceInfo* Create(const String& device_id,
const String& label,
const String& group_id,
MediaDeviceType);
void getCapabilities(MediaTrackCapabilities&);
private:
InputDeviceInfo(const String& device_id,
const String& label,
const String& group_id,
MediaDeviceType);
};
} // namespace blink
#endif // InputDeviceInfo_h
// Copyright 2018 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.
// https://w3c.github.io/mediacapture-main/#dom-inputdeviceinfo
[Exposed=Window]
interface InputDeviceInfo : MediaDeviceInfo {
MediaTrackCapabilities getCapabilities();
};
......@@ -39,7 +39,7 @@ namespace blink {
class ScriptState;
class ScriptValue;
class MODULES_EXPORT MediaDeviceInfo final : public ScriptWrappable {
class MODULES_EXPORT MediaDeviceInfo : public ScriptWrappable {
DEFINE_WRAPPERTYPEINFO();
public:
......@@ -58,12 +58,13 @@ class MODULES_EXPORT MediaDeviceInfo final : public ScriptWrappable {
ScriptValue toJSONForBinding(ScriptState*);
private:
protected:
MediaDeviceInfo(const String& device_id,
const String& label,
const String& group_id,
MediaDeviceType);
private:
String device_id_;
String label_;
String group_id_;
......
......@@ -12,6 +12,7 @@
#include "core/dom/ExecutionContext.h"
#include "core/dom/events/Event.h"
#include "core/frame/LocalFrame.h"
#include "modules/mediastream/InputDeviceInfo.h"
#include "modules/mediastream/MediaErrorState.h"
#include "modules/mediastream/MediaStream.h"
#include "modules/mediastream/MediaStreamConstraints.h"
......@@ -269,9 +270,17 @@ void MediaDevices::DevicesEnumerated(
for (size_t i = 0;
i < static_cast<size_t>(MediaDeviceType::NUM_MEDIA_DEVICE_TYPES); ++i) {
for (const auto& device_info : enumeration[i]) {
media_devices.push_back(MediaDeviceInfo::Create(
device_info->device_id, device_info->label, device_info->group_id,
static_cast<MediaDeviceType>(i)));
MediaDeviceType device_type = static_cast<MediaDeviceType>(i);
if (device_type == MediaDeviceType::MEDIA_AUDIO_INPUT ||
device_type == MediaDeviceType::MEDIA_VIDEO_INPUT) {
media_devices.push_back(
InputDeviceInfo::Create(device_info->device_id, device_info->label,
device_info->group_id, device_type));
} else {
media_devices.push_back(
MediaDeviceInfo::Create(device_info->device_id, device_info->label,
device_info->group_id, device_type));
}
}
}
......
......@@ -184,6 +184,7 @@ modules_idl_files =
"mediasource/TrackDefault.idl",
"mediasource/TrackDefaultList.idl",
"mediasource/VideoPlaybackQuality.idl",
"mediastream/InputDeviceInfo.idl",
"mediastream/MediaDeviceInfo.idl",
"mediastream/MediaDevices.idl",
"mediastream/MediaStream.idl",
......
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