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(
const StreamControls& controls,
bool user_gesture,
GenerateStreamCallback callback,
const MediaDeviceSaltAndOrigin& salt_and_origin) {
MediaDeviceSaltAndOrigin salt_and_origin) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
if (!MediaStreamManager::IsOriginAllowed(render_process_id_,
salt_and_origin.origin)) {
......@@ -136,9 +136,8 @@ void MediaStreamDispatcherHost::DoGenerateStream(
}
media_stream_manager_->GenerateStream(
render_process_id_, render_frame_id_, salt_and_origin.device_id_salt,
page_request_id, controls, salt_and_origin.origin, user_gesture,
std::move(callback),
render_process_id_, render_frame_id_, page_request_id, controls,
std::move(salt_and_origin), user_gesture, std::move(callback),
base::BindRepeating(&MediaStreamDispatcherHost::OnDeviceStopped,
weak_factory_.GetWeakPtr()));
}
......@@ -178,7 +177,7 @@ void MediaStreamDispatcherHost::DoOpenDevice(
const std::string& device_id,
MediaStreamType type,
OpenDeviceCallback callback,
const MediaDeviceSaltAndOrigin& salt_and_origin) {
MediaDeviceSaltAndOrigin salt_and_origin) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
if (!MediaStreamManager::IsOriginAllowed(render_process_id_,
salt_and_origin.origin)) {
......@@ -188,9 +187,8 @@ void MediaStreamDispatcherHost::DoOpenDevice(
}
media_stream_manager_->OpenDevice(
render_process_id_, render_frame_id_, salt_and_origin.device_id_salt,
page_request_id, device_id, type, salt_and_origin.origin,
std::move(callback),
render_process_id_, render_frame_id_, page_request_id, device_id, type,
std::move(salt_and_origin), std::move(callback),
base::BindRepeating(&MediaStreamDispatcherHost::OnDeviceStopped,
weak_factory_.GetWeakPtr()));
}
......
......@@ -72,12 +72,12 @@ class CONTENT_EXPORT MediaStreamDispatcherHost
const StreamControls& controls,
bool user_gesture,
GenerateStreamCallback callback,
const MediaDeviceSaltAndOrigin& salt_and_origin);
MediaDeviceSaltAndOrigin salt_and_origin);
void DoOpenDevice(int32_t request_id,
const std::string& device_id,
MediaStreamType type,
OpenDeviceCallback callback,
const MediaDeviceSaltAndOrigin& salt_and_origin);
MediaDeviceSaltAndOrigin salt_and_origin);
void OnDeviceStopped(const std::string& label,
const MediaStreamDevice& device);
......
......@@ -861,14 +861,21 @@ TEST_F(MediaStreamDispatcherHostTest, Salt) {
EXPECT_EQ(host_->video_devices_.size(), 1u);
const std::string label1 = host_->label_;
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;
// Generate second stream.
OpenVideoDeviceAndWaitForResult(kPageRequestId, device_id1);
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 std::string label2 = host_->label_;
EXPECT_EQ(device_id1, device_id2);
EXPECT_EQ(group_id1, group_id2);
EXPECT_NE(session_id1, session_id2);
EXPECT_NE(label1, label2);
......@@ -879,6 +886,7 @@ TEST_F(MediaStreamDispatcherHostTest, Salt) {
// Last open device ID and session are from the second stream.
EXPECT_EQ(session_id2, host_->opened_device_.session_id);
EXPECT_EQ(device_id2, host_->opened_device_.id);
EXPECT_EQ(group_id2, host_->opened_device_.group_id);
}
}; // namespace content
......@@ -42,6 +42,7 @@
#include "base/single_thread_task_runner.h"
#include "base/threading/thread.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_stream_provider.h"
#include "content/common/content_export.h"
......@@ -159,10 +160,9 @@ class CONTENT_EXPORT MediaStreamManager
// is set to receive device stopped notifications.
void GenerateStream(int render_process_id,
int render_frame_id,
const std::string& salt,
int page_request_id,
const StreamControls& controls,
const url::Origin& security_origin,
MediaDeviceSaltAndOrigin salt_and_origin,
bool user_gesture,
GenerateStreamCallback generate_stream_cb,
DeviceStoppedCallback device_stopped_cb);
......@@ -191,11 +191,10 @@ class CONTENT_EXPORT MediaStreamManager
// request is identified using string returned to the caller.
void OpenDevice(int render_process_id,
int render_frame_id,
const std::string& salt,
int page_request_id,
const std::string& device_id,
MediaStreamType type,
const url::Origin& security_origin,
MediaDeviceSaltAndOrigin salt_and_origin,
OpenDeviceCallback open_device_cb,
DeviceStoppedCallback device_stopped_cb);
......@@ -322,8 +321,7 @@ class CONTENT_EXPORT MediaStreamManager
// Helpers.
// Checks if all devices that was requested in the request identififed by
// |label| has been opened and set the request state accordingly.
void HandleRequestDone(const std::string& label,
DeviceRequest* request);
void HandleRequestDone(const std::string& label, DeviceRequest* request);
// 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
/// doesn't use any devices as a consequence, the request is deleted.
......@@ -394,8 +392,7 @@ class CONTENT_EXPORT MediaStreamManager
// valid alternate device ID.
// Returns false if the required device ID is present and invalid.
// Otherwise, if no valid device is found, device_id is unchanged.
bool PickDeviceId(const std::string& salt,
const url::Origin& security_origin,
bool PickDeviceId(const MediaDeviceSaltAndOrigin& salt_and_origin,
const TrackControls& controls,
const MediaDeviceInfoArray& devices,
std::string* device_id) const;
......@@ -417,7 +414,8 @@ class CONTENT_EXPORT MediaStreamManager
gfx::NativeViewId window_id);
// 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);
void DoNativeLogCallbackUnregistration(int renderer_host_id);
......
......@@ -153,10 +153,11 @@ class VideoCaptureTest : public testing::Test,
{
base::RunLoop run_loop;
media_stream_manager_->OpenDevice(
render_process_id, render_frame_id,
browser_context_.GetMediaDeviceIDSalt(), page_request_id,
render_process_id, render_frame_id, page_request_id,
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::Unretained(this), run_loop.QuitClosure()),
MediaStreamManager::DeviceStoppedCallback());
......
......@@ -3,7 +3,7 @@
// found in the LICENSE file.
// 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/public/common/media_stream_request.h"
......@@ -23,6 +23,7 @@ IPC_ENUM_TRAITS_MAX_VALUE(media::VideoFacingMode,
IPC_STRUCT_TRAITS_BEGIN(content::MediaStreamDevice)
IPC_STRUCT_TRAITS_MEMBER(type)
IPC_STRUCT_TRAITS_MEMBER(id)
IPC_STRUCT_TRAITS_MEMBER(group_id)
IPC_STRUCT_TRAITS_MEMBER(video_facing)
IPC_STRUCT_TRAITS_MEMBER(matched_output_device_id)
IPC_STRUCT_TRAITS_MEMBER(name)
......
......@@ -41,11 +41,17 @@ MediaStreamDevice::MediaStreamDevice(MediaStreamType type,
video_facing(media::MEDIA_VIDEO_FACING_NONE),
name(name) {}
MediaStreamDevice::MediaStreamDevice(MediaStreamType type,
const std::string& id,
const std::string& name,
media::VideoFacingMode facing)
: type(type), id(id), video_facing(facing), name(name) {}
MediaStreamDevice::MediaStreamDevice(
MediaStreamType type,
const std::string& id,
const std::string& 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,
const std::string& id,
......
......@@ -91,10 +91,12 @@ struct CONTENT_EXPORT MediaStreamDevice {
const std::string& id,
const std::string& name);
MediaStreamDevice(MediaStreamType type,
const std::string& id,
const std::string& name,
media::VideoFacingMode facing);
MediaStreamDevice(
MediaStreamType type,
const std::string& id,
const std::string& name,
media::VideoFacingMode facing,
const base::Optional<std::string>& group_id = base::nullopt);
MediaStreamDevice(MediaStreamType type,
const std::string& id,
......@@ -118,6 +120,9 @@ struct CONTENT_EXPORT MediaStreamDevice {
// The facing mode for video capture device.
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).
// Only applicable to audio devices.
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