Commit 1433dd1c authored by Xiangjun Zhang's avatar Xiangjun Zhang Committed by Commit Bot

Mirroring Service: Connect with CastRemotingConnector as requested.

This CL adds implementation to connect the CastRemotingConnector with
remoter when requested from Mirroring Service.

Bug: 734672
Change-Id: I213b4f06bdbd7ad188969310da867bf939cdd0f2
Reviewed-on: https://chromium-review.googlesource.com/1144409
Commit-Queue: Xiangjun Zhang <xjz@chromium.org>
Reviewed-by: default avatarYuri Wiitala <miu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#579297}
parent e744bb0a
......@@ -9,11 +9,14 @@
#include "base/memory/ref_counted.h"
#include "base/single_thread_task_runner.h"
#include "base/task_scheduler/post_task.h"
#include "chrome/browser/media/cast_remoting_connector.h"
#include "chrome/browser/net/default_network_context_params.h"
#include "components/mirroring/browser/single_client_video_capture_host.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/network_service_instance.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/video_capture_device_launcher.h"
#include "content/public/browser/web_contents.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
using content::BrowserThread;
......@@ -56,6 +59,14 @@ content::MediaStreamType ConvertVideoStreamType(
return content::MediaStreamType::MEDIA_NO_SERVICE;
}
// Get the content::WebContents associated with the given |id|.
content::WebContents* GetContents(
const content::WebContentsMediaCaptureId& id) {
return content::WebContents::FromRenderFrameHost(
content::RenderFrameHost::FromID(id.render_process_id,
id.main_render_frame_id));
}
} // namespace
CastMirroringServiceHost::CastMirroringServiceHost(
......@@ -106,7 +117,14 @@ void CastMirroringServiceHost::CreateAudioStream(
void CastMirroringServiceHost::ConnectToRemotingSource(
media::mojom::RemoterPtr remoter,
media::mojom::RemotingSourceRequest request) {
// TODO(xjz): Implementation will be added in a later CL.
if (source_media_id_.type == content::DesktopMediaID::TYPE_WEB_CONTENTS) {
content::WebContents* source_contents =
GetContents(source_media_id_.web_contents_id);
if (source_contents) {
CastRemotingConnector::Get(source_contents)
->ConnectWithMediaRemoter(std::move(remoter), std::move(request));
}
}
}
} // namespace mirroring
......@@ -72,8 +72,12 @@ class MediaRouter;
// Please see the unit tests in cast_remoting_connector_unittest.cc as a
// reference for how CastRemotingConnector and a MediaRemoter interact to
// start/execute/stop remoting sessions.
//
// TODO(xjz): Remove media::mojom::MirrorServiceRemotingSource interface and
// implementation after Mirroring Service is launched.
class CastRemotingConnector : public base::SupportsUserData::Data,
public media::mojom::MirrorServiceRemotingSource {
public media::mojom::MirrorServiceRemotingSource,
public media::mojom::RemotingSource {
public:
~CastRemotingConnector() final;
......@@ -98,6 +102,10 @@ class CastRemotingConnector : public base::SupportsUserData::Data,
// Called at the start of mirroring to reset the permission.
void ResetRemotingPermission();
// Used by Mirroring Service to connect the media remoter with this source.
void ConnectWithMediaRemoter(media::mojom::RemoterPtr remoter,
media::mojom::RemotingSourceRequest request);
private:
// Allow unit tests access to the private constructor and CreateBridge()
// method, since unit tests don't have a complete browser (i.e., with a
......@@ -135,12 +143,20 @@ class CastRemotingConnector : public base::SupportsUserData::Data,
void DeregisterBridge(RemotingBridge* bridge,
media::mojom::RemotingStopReason reason);
// media::mojom::MirrorServiceRemotingSource implementations.
// media::mojom::MirrorServiceRemotingSource implementation.
// media::mojom::RemotingSource implementation.
void OnSinkAvailable(media::mojom::RemotingSinkMetadataPtr metadata) override;
void OnMessageFromSink(const std::vector<uint8_t>& message) override;
void OnStopped(media::mojom::RemotingStopReason reason) override;
// media::mojom::MirrorServiceRemotingSource implementation.
void OnError() override;
// media::mojom::RemotingSource implementation.
void OnSinkGone() override;
void OnStarted() override;
void OnStartFailed(media::mojom::RemotingStartFailReason reason) override;
// These methods are called by RemotingBridge to forward media::mojom::Remoter
// calls from a source through to this connector. They ensure that only one
// source is allowed to be in a remoting session at a time, and that no source
......@@ -201,8 +217,12 @@ class CastRemotingConnector : public base::SupportsUserData::Data,
// pointing to the RemotingBridge being used to communicate with the source.
RemotingBridge* active_bridge_;
mojo::Binding<media::mojom::MirrorServiceRemotingSource> binding_;
media::mojom::MirrorServiceRemoterPtr remoter_;
// TODO(xjz): Remove these after Mirroring Service is launched.
mojo::Binding<media::mojom::MirrorServiceRemotingSource> deprecated_binding_;
media::mojom::MirrorServiceRemoterPtr deprecated_remoter_;
mojo::Binding<media::mojom::RemotingSource> binding_;
media::mojom::RemoterPtr remoter_;
// Permission is checked the first time remoting requested to start for each
// casting session.
......
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