media_perception: Add force_reopen_with_settings.

TEST=Verified that we can change the settings used for a video device
even after Chrome has opened that device.
BUG=chromium:956588

Change-Id: I9d412775396895c94a2b4e792217da11bae2e4c9
Reviewed-on: https://chromium-review.googlesource.com/1584426
Commit-Ready: Luke Sorenson <lasoren@google.com>
Tested-by: Luke Sorenson <lasoren@chromium.org>
Reviewed-by: Toni Baržić <tbarzic@chromium.org>
(cherry picked from commit 6393cc8d5b76d4ca1d30ec9e3183ab7942c3ee82)
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform2/+/1585255
Tested-by: Luke Sorenson <lasoren@google.com>
Reviewed-by: Luke Sorenson <lasoren@google.com>
Commit-Queue: Luke Sorenson <lasoren@google.com>
diff --git a/media_perception/fake_video_capture_service_client.cc b/media_perception/fake_video_capture_service_client.cc
index 6c70a2e..26d25ea 100644
--- a/media_perception/fake_video_capture_service_client.cc
+++ b/media_perception/fake_video_capture_service_client.cc
@@ -27,6 +27,8 @@
 
 void FakeVideoCaptureServiceClient::OpenDevice(
     const std::string& device_id,
+    bool force_reopen_with_settings,
+    const SerializedVideoStreamParams& capture_format,
     const OpenDeviceCallback& callback) {}
 
 bool FakeVideoCaptureServiceClient::IsVideoCaptureStartedForDevice(
diff --git a/media_perception/fake_video_capture_service_client.h b/media_perception/fake_video_capture_service_client.h
index 651f5a3..16ddd15 100644
--- a/media_perception/fake_video_capture_service_client.h
+++ b/media_perception/fake_video_capture_service_client.h
@@ -25,6 +25,8 @@
   bool IsConnected() override;
   void GetDevices(const GetDevicesCallback& callback) override;
   void OpenDevice(const std::string& device_id,
+                  bool force_reopen_with_settings,
+                  const SerializedVideoStreamParams& capture_format,
                   const OpenDeviceCallback& callback) override;
   bool IsVideoCaptureStartedForDevice(
       const std::string& device_id,
diff --git a/media_perception/mojo_connector.cc b/media_perception/mojo_connector.cc
index a456cdf..4bc7b2d 100644
--- a/media_perception/mojo_connector.cc
+++ b/media_perception/mojo_connector.cc
@@ -218,18 +218,20 @@
 
 void MojoConnector::OpenDevice(
     const std::string& device_id,
+    bool force_reopen_with_settings,
     std::shared_ptr<ReceiverImpl> receiver_impl,
     const VideoStreamParams& capture_format,
     const VideoCaptureServiceClient::OpenDeviceCallback& callback) {
   ipc_thread_.task_runner()->PostTask(
       FROM_HERE, base::Bind(&MojoConnector::OpenDeviceOnIpcThread,
                             base::Unretained(this),
-                            device_id, receiver_impl,
-                            capture_format, callback));
+                            device_id, force_reopen_with_settings,
+                            receiver_impl, capture_format, callback));
 }
 
 void MojoConnector::OpenDeviceOnIpcThread(
     const std::string& device_id,
+    bool force_reopen_with_settings,
     std::shared_ptr<ReceiverImpl> receiver_impl,
     const VideoStreamParams& capture_format,
     const VideoCaptureServiceClient::OpenDeviceCallback& callback) {
@@ -284,7 +286,7 @@
   device_it->second.video_source->CreatePushSubscription(
       receiver_impl->CreateInterfacePtr(),
       std::move(requested_settings),
-      /* force_reopen_with_new_settings */ false,
+      force_reopen_with_settings,
       mojo::MakeRequest(&device_it->second.push_video_stream_subscription),
       base::Bind(&MojoConnector::OnCreatePushSubscriptionCallback,
                  base::Unretained(this), device_id, callback));
diff --git a/media_perception/mojo_connector.h b/media_perception/mojo_connector.h
index 2d2e05b..0307e49 100644
--- a/media_perception/mojo_connector.h
+++ b/media_perception/mojo_connector.h
@@ -62,6 +62,7 @@
   // Attempts to acquire access to a video device.
   void OpenDevice(
       const std::string& device_id,
+      bool force_reopen_with_settings,
       std::shared_ptr<ReceiverImpl> receiver_impl,
       const VideoStreamParams& capture_format,
       const VideoCaptureServiceClient::OpenDeviceCallback& callback);
@@ -108,6 +109,7 @@
 
   void OpenDeviceOnIpcThread(
       const std::string& device_id,
+      bool force_reopen_with_settings,
       std::shared_ptr<ReceiverImpl> receiver_impl,
       const VideoStreamParams& capture_format,
       const VideoCaptureServiceClient::OpenDeviceCallback& callback);
diff --git a/media_perception/video_capture_service_client.h b/media_perception/video_capture_service_client.h
index ec6eda9..f2f5a66 100644
--- a/media_perception/video_capture_service_client.h
+++ b/media_perception/video_capture_service_client.h
@@ -62,8 +62,12 @@
   // Sets a device to be opened by the Video Capture Service with the exact
   // device_id specified. OpenDeviceCallback provides information on the success
   // or failure of the request.
+  // |force_reopen_with_settings| enables a client to command the VCS to reopen
+  // a video device with the requested settings. This should be used sparingly
+  // as it can disrupt the video experience for frontend facing applications.
   virtual void OpenDevice(
       const std::string& device_id,
+      bool force_reopen_with_settings,
       const SerializedVideoStreamParams& capture_format,
       const OpenDeviceCallback& callback) = 0;
 
diff --git a/media_perception/video_capture_service_client_impl.cc b/media_perception/video_capture_service_client_impl.cc
index eabd86b..a3d3fe1 100644
--- a/media_perception/video_capture_service_client_impl.cc
+++ b/media_perception/video_capture_service_client_impl.cc
@@ -41,6 +41,7 @@
 
 void VideoCaptureServiceClientImpl::OpenDevice(
     const std::string& device_id,
+    bool force_reopen_with_settings,
     const SerializedVideoStreamParams& capture_format,
     const OpenDeviceCallback& callback) {
   VideoStreamParams format = Serialized<VideoStreamParams>(
@@ -81,7 +82,7 @@
   device_id_to_receiver_map_.insert(
       std::make_pair(device_id, receiver_impl));
   mojo_connector_->OpenDevice(
-      device_id, receiver_impl, format,
+      device_id, force_reopen_with_settings, receiver_impl, format,
       std::bind(&VideoCaptureServiceClientImpl::OnOpenDeviceCallback,
                 this, callback, std::placeholders::_1,
                 std::placeholders::_2, std::placeholders::_3));
diff --git a/media_perception/video_capture_service_client_impl.h b/media_perception/video_capture_service_client_impl.h
index aa95230..15edb3c 100644
--- a/media_perception/video_capture_service_client_impl.h
+++ b/media_perception/video_capture_service_client_impl.h
@@ -35,6 +35,7 @@
   bool IsConnected() override;
   void GetDevices(const GetDevicesCallback& callback) override;
   void OpenDevice(const std::string& device_id,
+                  bool force_reopen_with_settings,
                   const SerializedVideoStreamParams& capture_format,
                   const OpenDeviceCallback& callback) override;
   bool IsVideoCaptureStartedForDevice(