Commit 814d076a authored by Guido Urdaneta's avatar Guido Urdaneta Committed by Commit Bot

Make MediaStreamManager/Dispatcher report device group ID.

This change is in anticipation to add full support for the
constrainable groupId property in MediaStreamTrack.getSettings() and
MediaDevices.getUserMedia().

See follow-up CL: crrev.com/c/1019323

Drive-by: Fix minor whitespace/style issues.

Bug: 833333
Change-Id: I821d2e34f7684dd1c0f8692e6219360cc1a77f66
Reviewed-on: https://chromium-review.googlesource.com/1021772
Commit-Queue: Guido Urdaneta <guidou@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarHarald Alvestrand <hta@chromium.org>
Cr-Commit-Position: refs/heads/master@{#555701}
parent 7a28724a
...@@ -126,7 +126,7 @@ void MediaStreamDispatcherHost::DoGenerateStream( ...@@ -126,7 +126,7 @@ void MediaStreamDispatcherHost::DoGenerateStream(
const StreamControls& controls, const StreamControls& controls,
bool user_gesture, bool user_gesture,
GenerateStreamCallback callback, GenerateStreamCallback callback,
const MediaDeviceSaltAndOrigin& salt_and_origin) { MediaDeviceSaltAndOrigin salt_and_origin) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
if (!MediaStreamManager::IsOriginAllowed(render_process_id_, if (!MediaStreamManager::IsOriginAllowed(render_process_id_,
salt_and_origin.origin)) { salt_and_origin.origin)) {
...@@ -136,9 +136,8 @@ void MediaStreamDispatcherHost::DoGenerateStream( ...@@ -136,9 +136,8 @@ void MediaStreamDispatcherHost::DoGenerateStream(
} }
media_stream_manager_->GenerateStream( media_stream_manager_->GenerateStream(
render_process_id_, render_frame_id_, salt_and_origin.device_id_salt, render_process_id_, render_frame_id_, page_request_id, controls,
page_request_id, controls, salt_and_origin.origin, user_gesture, std::move(salt_and_origin), user_gesture, std::move(callback),
std::move(callback),
base::BindRepeating(&MediaStreamDispatcherHost::OnDeviceStopped, base::BindRepeating(&MediaStreamDispatcherHost::OnDeviceStopped,
weak_factory_.GetWeakPtr())); weak_factory_.GetWeakPtr()));
} }
...@@ -178,7 +177,7 @@ void MediaStreamDispatcherHost::DoOpenDevice( ...@@ -178,7 +177,7 @@ void MediaStreamDispatcherHost::DoOpenDevice(
const std::string& device_id, const std::string& device_id,
MediaStreamType type, MediaStreamType type,
OpenDeviceCallback callback, OpenDeviceCallback callback,
const MediaDeviceSaltAndOrigin& salt_and_origin) { MediaDeviceSaltAndOrigin salt_and_origin) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
if (!MediaStreamManager::IsOriginAllowed(render_process_id_, if (!MediaStreamManager::IsOriginAllowed(render_process_id_,
salt_and_origin.origin)) { salt_and_origin.origin)) {
...@@ -188,9 +187,8 @@ void MediaStreamDispatcherHost::DoOpenDevice( ...@@ -188,9 +187,8 @@ void MediaStreamDispatcherHost::DoOpenDevice(
} }
media_stream_manager_->OpenDevice( media_stream_manager_->OpenDevice(
render_process_id_, render_frame_id_, salt_and_origin.device_id_salt, render_process_id_, render_frame_id_, page_request_id, device_id, type,
page_request_id, device_id, type, salt_and_origin.origin, std::move(salt_and_origin), std::move(callback),
std::move(callback),
base::BindRepeating(&MediaStreamDispatcherHost::OnDeviceStopped, base::BindRepeating(&MediaStreamDispatcherHost::OnDeviceStopped,
weak_factory_.GetWeakPtr())); weak_factory_.GetWeakPtr()));
} }
......
...@@ -72,12 +72,12 @@ class CONTENT_EXPORT MediaStreamDispatcherHost ...@@ -72,12 +72,12 @@ class CONTENT_EXPORT MediaStreamDispatcherHost
const StreamControls& controls, const StreamControls& controls,
bool user_gesture, bool user_gesture,
GenerateStreamCallback callback, GenerateStreamCallback callback,
const MediaDeviceSaltAndOrigin& salt_and_origin); MediaDeviceSaltAndOrigin salt_and_origin);
void DoOpenDevice(int32_t request_id, void DoOpenDevice(int32_t request_id,
const std::string& device_id, const std::string& device_id,
MediaStreamType type, MediaStreamType type,
OpenDeviceCallback callback, OpenDeviceCallback callback,
const MediaDeviceSaltAndOrigin& salt_and_origin); MediaDeviceSaltAndOrigin salt_and_origin);
void OnDeviceStopped(const std::string& label, void OnDeviceStopped(const std::string& label,
const MediaStreamDevice& device); const MediaStreamDevice& device);
......
...@@ -861,14 +861,21 @@ TEST_F(MediaStreamDispatcherHostTest, Salt) { ...@@ -861,14 +861,21 @@ TEST_F(MediaStreamDispatcherHostTest, Salt) {
EXPECT_EQ(host_->video_devices_.size(), 1u); EXPECT_EQ(host_->video_devices_.size(), 1u);
const std::string label1 = host_->label_; const std::string label1 = host_->label_;
const std::string device_id1 = host_->video_devices_.front().id; const std::string device_id1 = host_->video_devices_.front().id;
EXPECT_TRUE(host_->video_devices_.front().group_id.has_value());
const std::string group_id1 = *host_->video_devices_.front().group_id;
EXPECT_FALSE(group_id1.empty());
const int session_id1 = host_->video_devices_.front().session_id; const int session_id1 = host_->video_devices_.front().session_id;
// Generate second stream. // Generate second stream.
OpenVideoDeviceAndWaitForResult(kPageRequestId, device_id1); OpenVideoDeviceAndWaitForResult(kPageRequestId, device_id1);
const std::string device_id2 = host_->opened_device_.id; const std::string device_id2 = host_->opened_device_.id;
EXPECT_TRUE(host_->opened_device_.group_id.has_value());
const std::string group_id2 = *host_->opened_device_.group_id;
EXPECT_FALSE(group_id2.empty());
const int session_id2 = host_->opened_device_.session_id; const int session_id2 = host_->opened_device_.session_id;
const std::string label2 = host_->label_; const std::string label2 = host_->label_;
EXPECT_EQ(device_id1, device_id2); EXPECT_EQ(device_id1, device_id2);
EXPECT_EQ(group_id1, group_id2);
EXPECT_NE(session_id1, session_id2); EXPECT_NE(session_id1, session_id2);
EXPECT_NE(label1, label2); EXPECT_NE(label1, label2);
...@@ -879,6 +886,7 @@ TEST_F(MediaStreamDispatcherHostTest, Salt) { ...@@ -879,6 +886,7 @@ TEST_F(MediaStreamDispatcherHostTest, Salt) {
// Last open device ID and session are from the second stream. // Last open device ID and session are from the second stream.
EXPECT_EQ(session_id2, host_->opened_device_.session_id); EXPECT_EQ(session_id2, host_->opened_device_.session_id);
EXPECT_EQ(device_id2, host_->opened_device_.id); EXPECT_EQ(device_id2, host_->opened_device_.id);
EXPECT_EQ(group_id2, host_->opened_device_.group_id);
} }
}; // namespace content }; // namespace content
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
#include "base/threading/thread.h" #include "base/threading/thread.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "content/browser/media/media_devices_util.h"
#include "content/browser/renderer_host/media/media_devices_manager.h" #include "content/browser/renderer_host/media/media_devices_manager.h"
#include "content/browser/renderer_host/media/media_stream_provider.h" #include "content/browser/renderer_host/media/media_stream_provider.h"
#include "content/common/content_export.h" #include "content/common/content_export.h"
...@@ -159,10 +160,9 @@ class CONTENT_EXPORT MediaStreamManager ...@@ -159,10 +160,9 @@ class CONTENT_EXPORT MediaStreamManager
// is set to receive device stopped notifications. // is set to receive device stopped notifications.
void GenerateStream(int render_process_id, void GenerateStream(int render_process_id,
int render_frame_id, int render_frame_id,
const std::string& salt,
int page_request_id, int page_request_id,
const StreamControls& controls, const StreamControls& controls,
const url::Origin& security_origin, MediaDeviceSaltAndOrigin salt_and_origin,
bool user_gesture, bool user_gesture,
GenerateStreamCallback generate_stream_cb, GenerateStreamCallback generate_stream_cb,
DeviceStoppedCallback device_stopped_cb); DeviceStoppedCallback device_stopped_cb);
...@@ -191,11 +191,10 @@ class CONTENT_EXPORT MediaStreamManager ...@@ -191,11 +191,10 @@ class CONTENT_EXPORT MediaStreamManager
// request is identified using string returned to the caller. // request is identified using string returned to the caller.
void OpenDevice(int render_process_id, void OpenDevice(int render_process_id,
int render_frame_id, int render_frame_id,
const std::string& salt,
int page_request_id, int page_request_id,
const std::string& device_id, const std::string& device_id,
MediaStreamType type, MediaStreamType type,
const url::Origin& security_origin, MediaDeviceSaltAndOrigin salt_and_origin,
OpenDeviceCallback open_device_cb, OpenDeviceCallback open_device_cb,
DeviceStoppedCallback device_stopped_cb); DeviceStoppedCallback device_stopped_cb);
...@@ -322,8 +321,7 @@ class CONTENT_EXPORT MediaStreamManager ...@@ -322,8 +321,7 @@ class CONTENT_EXPORT MediaStreamManager
// Helpers. // Helpers.
// Checks if all devices that was requested in the request identififed by // Checks if all devices that was requested in the request identififed by
// |label| has been opened and set the request state accordingly. // |label| has been opened and set the request state accordingly.
void HandleRequestDone(const std::string& label, void HandleRequestDone(const std::string& label, DeviceRequest* request);
DeviceRequest* request);
// Stop the use of the device associated with |session_id| of type |type| in // Stop the use of the device associated with |session_id| of type |type| in
// all |requests_|. The device is removed from the request. If a request // all |requests_|. The device is removed from the request. If a request
/// doesn't use any devices as a consequence, the request is deleted. /// doesn't use any devices as a consequence, the request is deleted.
...@@ -394,8 +392,7 @@ class CONTENT_EXPORT MediaStreamManager ...@@ -394,8 +392,7 @@ class CONTENT_EXPORT MediaStreamManager
// valid alternate device ID. // valid alternate device ID.
// Returns false if the required device ID is present and invalid. // Returns false if the required device ID is present and invalid.
// Otherwise, if no valid device is found, device_id is unchanged. // Otherwise, if no valid device is found, device_id is unchanged.
bool PickDeviceId(const std::string& salt, bool PickDeviceId(const MediaDeviceSaltAndOrigin& salt_and_origin,
const url::Origin& security_origin,
const TrackControls& controls, const TrackControls& controls,
const MediaDeviceInfoArray& devices, const MediaDeviceInfoArray& devices,
std::string* device_id) const; std::string* device_id) const;
...@@ -417,7 +414,8 @@ class CONTENT_EXPORT MediaStreamManager ...@@ -417,7 +414,8 @@ class CONTENT_EXPORT MediaStreamManager
gfx::NativeViewId window_id); gfx::NativeViewId window_id);
// Runs on the IO thread and does the actual [un]registration of callbacks. // Runs on the IO thread and does the actual [un]registration of callbacks.
void DoNativeLogCallbackRegistration(int renderer_host_id, void DoNativeLogCallbackRegistration(
int renderer_host_id,
const base::Callback<void(const std::string&)>& callback); const base::Callback<void(const std::string&)>& callback);
void DoNativeLogCallbackUnregistration(int renderer_host_id); void DoNativeLogCallbackUnregistration(int renderer_host_id);
......
...@@ -153,10 +153,11 @@ class VideoCaptureTest : public testing::Test, ...@@ -153,10 +153,11 @@ class VideoCaptureTest : public testing::Test,
{ {
base::RunLoop run_loop; base::RunLoop run_loop;
media_stream_manager_->OpenDevice( media_stream_manager_->OpenDevice(
render_process_id, render_frame_id, render_process_id, render_frame_id, page_request_id,
browser_context_.GetMediaDeviceIDSalt(), page_request_id,
video_devices[0].device_id, MEDIA_DEVICE_VIDEO_CAPTURE, video_devices[0].device_id, MEDIA_DEVICE_VIDEO_CAPTURE,
security_origin, MediaDeviceSaltAndOrigin{browser_context_.GetMediaDeviceIDSalt(),
browser_context_.GetMediaDeviceIDSalt(),
security_origin},
base::BindOnce(&VideoCaptureTest::OnDeviceOpened, base::BindOnce(&VideoCaptureTest::OnDeviceOpened,
base::Unretained(this), run_loop.QuitClosure()), base::Unretained(this), run_loop.QuitClosure()),
MediaStreamManager::DeviceStoppedCallback()); MediaStreamManager::DeviceStoppedCallback());
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
// IPC messages for the media streaming. // IPC messages for the media streaming.
// Multiply-included message file, hence no include guard. // no-include-guard-because-multiply-included
#include "content/common/content_export.h" #include "content/common/content_export.h"
#include "content/public/common/media_stream_request.h" #include "content/public/common/media_stream_request.h"
...@@ -23,6 +23,7 @@ IPC_ENUM_TRAITS_MAX_VALUE(media::VideoFacingMode, ...@@ -23,6 +23,7 @@ IPC_ENUM_TRAITS_MAX_VALUE(media::VideoFacingMode,
IPC_STRUCT_TRAITS_BEGIN(content::MediaStreamDevice) IPC_STRUCT_TRAITS_BEGIN(content::MediaStreamDevice)
IPC_STRUCT_TRAITS_MEMBER(type) IPC_STRUCT_TRAITS_MEMBER(type)
IPC_STRUCT_TRAITS_MEMBER(id) IPC_STRUCT_TRAITS_MEMBER(id)
IPC_STRUCT_TRAITS_MEMBER(group_id)
IPC_STRUCT_TRAITS_MEMBER(video_facing) IPC_STRUCT_TRAITS_MEMBER(video_facing)
IPC_STRUCT_TRAITS_MEMBER(matched_output_device_id) IPC_STRUCT_TRAITS_MEMBER(matched_output_device_id)
IPC_STRUCT_TRAITS_MEMBER(name) IPC_STRUCT_TRAITS_MEMBER(name)
......
...@@ -41,11 +41,17 @@ MediaStreamDevice::MediaStreamDevice(MediaStreamType type, ...@@ -41,11 +41,17 @@ MediaStreamDevice::MediaStreamDevice(MediaStreamType type,
video_facing(media::MEDIA_VIDEO_FACING_NONE), video_facing(media::MEDIA_VIDEO_FACING_NONE),
name(name) {} name(name) {}
MediaStreamDevice::MediaStreamDevice(MediaStreamType type, MediaStreamDevice::MediaStreamDevice(
const std::string& id, MediaStreamType type,
const std::string& name, const std::string& id,
media::VideoFacingMode facing) const std::string& name,
: type(type), id(id), video_facing(facing), name(name) {} media::VideoFacingMode facing,
const base::Optional<std::string>& group_id)
: type(type),
id(id),
video_facing(facing),
group_id(group_id),
name(name) {}
MediaStreamDevice::MediaStreamDevice(MediaStreamType type, MediaStreamDevice::MediaStreamDevice(MediaStreamType type,
const std::string& id, const std::string& id,
......
...@@ -91,10 +91,12 @@ struct CONTENT_EXPORT MediaStreamDevice { ...@@ -91,10 +91,12 @@ struct CONTENT_EXPORT MediaStreamDevice {
const std::string& id, const std::string& id,
const std::string& name); const std::string& name);
MediaStreamDevice(MediaStreamType type, MediaStreamDevice(
const std::string& id, MediaStreamType type,
const std::string& name, const std::string& id,
media::VideoFacingMode facing); const std::string& name,
media::VideoFacingMode facing,
const base::Optional<std::string>& group_id = base::nullopt);
MediaStreamDevice(MediaStreamType type, MediaStreamDevice(MediaStreamType type,
const std::string& id, const std::string& id,
...@@ -118,6 +120,9 @@ struct CONTENT_EXPORT MediaStreamDevice { ...@@ -118,6 +120,9 @@ struct CONTENT_EXPORT MediaStreamDevice {
// The facing mode for video capture device. // The facing mode for video capture device.
media::VideoFacingMode video_facing; media::VideoFacingMode video_facing;
// The device's group ID.
base::Optional<std::string> group_id;
// The device id of a matched output device if any (otherwise empty). // The device id of a matched output device if any (otherwise empty).
// Only applicable to audio devices. // Only applicable to audio devices.
base::Optional<std::string> matched_output_device_id; base::Optional<std::string> matched_output_device_id;
......
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