Commit 24acfac5 authored by Guido Urdaneta's avatar Guido Urdaneta Committed by Commit Bot

Use session_id to find devices to stop in MediaStreamManager

In screen capture it is possible to have multiple sessions associated to
the same device in the same renderer process.
Prior to this CL, MSM::StopStreamDevice() received only the device ID,
which sometimes resulted in the wrong screen-capture tracks being stopped
on the renderer side.
This CL adds the session ID to the StopStreamDevice() so that only the
correct track is stopped.

Bug: 788400
Change-Id: If759af86fa9819e4c3574b2bc840ad45c3c924b7
Reviewed-on: https://chromium-review.googlesource.com/892859Reviewed-by: default avatarHenrik Boström <hbos@chromium.org>
Reviewed-by: default avatarTom Sepez <tsepez@chromium.org>
Commit-Queue: Guido Urdaneta <guidou@chromium.org>
Cr-Commit-Position: refs/heads/master@{#533828}
parent 4556c6b0
......@@ -168,13 +168,14 @@ void MediaStreamDispatcherHost::CancelRequest(int render_frame_id,
}
void MediaStreamDispatcherHost::StopStreamDevice(int32_t render_frame_id,
const std::string& device_id) {
const std::string& device_id,
int32_t session_id) {
DVLOG(1) << __func__ << " render_frame_id=" << render_frame_id
<< " device_id=" << device_id;
<< " device_id=" << device_id << " session_id=" << session_id;
DCHECK_CURRENTLY_ON(BrowserThread::IO);
media_stream_manager_->StopStreamDevice(render_process_id_, render_frame_id,
device_id);
device_id, session_id);
}
void MediaStreamDispatcherHost::OpenDevice(int32_t render_frame_id,
......
......@@ -63,7 +63,8 @@ class CONTENT_EXPORT MediaStreamDispatcherHost
GenerateStreamCallback callback) override;
void CancelRequest(int32_t render_frame_id, int32_t request_id) override;
void StopStreamDevice(int32_t render_frame_id,
const std::string& device_id) override;
const std::string& device_id,
int32_t session_id) override;
void OpenDevice(int32_t render_frame_id,
int32_t request_id,
const std::string& device_id,
......
......@@ -109,8 +109,10 @@ class MockMediaStreamDispatcherHost : public MediaStreamDispatcherHost,
}
void OnStopStreamDevice(int render_frame_id,
const std::string& device_id) {
MediaStreamDispatcherHost::StopStreamDevice(render_frame_id, device_id);
const std::string& device_id,
int session_id) {
MediaStreamDispatcherHost::StopStreamDevice(render_frame_id, device_id,
session_id);
}
void OnOpenDevice(int render_frame_id,
......@@ -710,7 +712,8 @@ TEST_F(MediaStreamDispatcherHostTest, StopDeviceInStream) {
std::string open_device_request_label = host_->label_;
// Stop the device in the MediaStream.
host_->OnStopStreamDevice(kRenderId, video_device.id);
host_->OnStopStreamDevice(kRenderId, video_device.id,
video_device.session_id);
EXPECT_EQ(0u, media_stream_manager_->GetDevicesOpenedByRequest(
stream_request_label).size());
......@@ -730,7 +733,8 @@ TEST_F(MediaStreamDispatcherHostTest, StopDeviceInStreamAndRestart) {
EXPECT_EQ(2u, media_stream_manager_->GetDevicesOpenedByRequest(
request_label1).size());
host_->OnStopStreamDevice(kRenderId, video_device.id);
host_->OnStopStreamDevice(kRenderId, video_device.id,
video_device.session_id);
EXPECT_EQ(1u, media_stream_manager_->GetDevicesOpenedByRequest(
request_label1).size());
......@@ -767,7 +771,8 @@ TEST_F(MediaStreamDispatcherHostTest,
// Stop the video stream device from stream 1 while waiting for the
// second stream to be generated.
host_->OnStopStreamDevice(kRenderId, host_->video_devices_[0].id);
host_->OnStopStreamDevice(kRenderId, host_->video_devices_[0].id,
host_->video_devices_[0].session_id);
run_loop1.Run();
EXPECT_EQ(host_->video_devices_.size(), 1u);
......
......@@ -681,10 +681,12 @@ void MediaStreamManager::CancelAllRequests(int render_process_id) {
void MediaStreamManager::StopStreamDevice(int render_process_id,
int render_frame_id,
const std::string& device_id) {
const std::string& device_id,
int session_id) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DVLOG(1) << "StopStreamDevice({render_frame_id = " << render_frame_id << "} "
<< ", {device_id = " << device_id << "})";
DVLOG(1) << "StopStreamDevice({render_frame_id = " << render_frame_id << "} "
<< ", {device_id = " << device_id << "}, session_id = " << session_id
<< "})";
// Find the first request for this |render_process_id| and |render_frame_id|
// of type MEDIA_GENERATE_STREAM that has requested to use |device_id| and
// stop it.
......@@ -697,7 +699,7 @@ void MediaStreamManager::StopStreamDevice(int render_process_id,
}
for (const MediaStreamDevice& device : request->devices) {
if (device.id == device_id) {
if (device.id == device_id && device.session_id == session_id) {
StopDevice(device.type, device.session_id);
return;
}
......
......@@ -181,7 +181,8 @@ class CONTENT_EXPORT MediaStreamManager
// been opened by a call to GenerateStream.
void StopStreamDevice(int render_process_id,
int render_frame_id,
const std::string& device_id);
const std::string& device_id,
int session_id);
// Open a device identified by |device_id|. |type| must be either
// MEDIA_DEVICE_AUDIO_CAPTURE or MEDIA_DEVICE_VIDEO_CAPTURE.
......
......@@ -76,7 +76,7 @@ interface MediaStreamDispatcherHost {
CancelRequest(int32 render_frame_id, int32 request_id);
// Closes a stream device that has been opened by GenerateStream.
StopStreamDevice(int32 render_frame_id, string device_id);
StopStreamDevice(int32 render_frame_id, string device_id, int32 session_id);
// Opens a device identified by |device_id|.
OpenDevice(int32 render_frame_id, int32 request_id, string device_id,
......
......@@ -68,15 +68,16 @@ void MockMojoMediaStreamDispatcherHost::CancelRequest(int32_t render_frame_id,
void MockMojoMediaStreamDispatcherHost::StopStreamDevice(
int32_t render_frame_id,
const std::string& device_id) {
const std::string& device_id,
int32_t session_id) {
for (const MediaStreamDevice& device : audio_devices_) {
if (device.id == device_id) {
if (device.id == device_id && device.session_id == session_id) {
++stop_audio_device_counter_;
return;
}
}
for (const MediaStreamDevice& device : video_devices_) {
if (device.id == device_id) {
if (device.id == device_id && device.session_id == session_id) {
++stop_video_device_counter_;
return;
}
......
......@@ -31,7 +31,8 @@ class MockMojoMediaStreamDispatcherHost
GenerateStreamCallback callback) override;
void CancelRequest(int32_t render_frame_id, int32_t request_id) override;
void StopStreamDevice(int32_t render_frame_id,
const std::string& device_id) override;
const std::string& device_id,
int32_t session_id) override;
void OpenDevice(int32_t render_frame_id,
int32_t request_id,
const std::string& device_id,
......
......@@ -636,15 +636,15 @@ void UserMediaProcessor::OnStreamGeneratedForCancelledRequest(
// Only stop the device if the device is not used in another MediaStream.
for (auto it = audio_devices.begin(); it != audio_devices.end(); ++it) {
if (!FindLocalSource(*it)) {
GetMediaStreamDispatcherHost()->StopStreamDevice(render_frame_id_,
it->id);
GetMediaStreamDispatcherHost()->StopStreamDevice(render_frame_id_, it->id,
it->session_id);
}
}
for (auto it = video_devices.begin(); it != video_devices.end(); ++it) {
if (!FindLocalSource(*it)) {
GetMediaStreamDispatcherHost()->StopStreamDevice(render_frame_id_,
it->id);
GetMediaStreamDispatcherHost()->StopStreamDevice(render_frame_id_, it->id,
it->session_id);
}
}
}
......@@ -1161,8 +1161,9 @@ void UserMediaProcessor::OnLocalSourceStopped(
MediaStreamSource* source_impl =
static_cast<MediaStreamSource*>(source.GetExtraData());
media_stream_device_observer_->RemoveStreamDevice(source_impl->device());
GetMediaStreamDispatcherHost()->StopStreamDevice(render_frame_id_,
source_impl->device().id);
GetMediaStreamDispatcherHost()->StopStreamDevice(
render_frame_id_, source_impl->device().id,
source_impl->device().session_id);
}
void UserMediaProcessor::StopLocalSource(
......@@ -1175,8 +1176,9 @@ void UserMediaProcessor::StopLocalSource(
if (notify_dispatcher) {
media_stream_device_observer_->RemoveStreamDevice(source_impl->device());
GetMediaStreamDispatcherHost()->StopStreamDevice(render_frame_id_,
source_impl->device().id);
GetMediaStreamDispatcherHost()->StopStreamDevice(
render_frame_id_, source_impl->device().id,
source_impl->device().session_id);
}
source_impl->ResetSourceStoppedCallback();
......
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