Skip to content

Commit

Permalink
Move CastStreamingSessionClient to //components/cast_streaming
Browse files Browse the repository at this point in the history
This CL makes the following changes:
- Moves CastStreamingSessionClient to
  //components/cast_streaming/browser
- Creates a public interface for the above class in /public
- Adds a wrapper around this class in //fuchsia to simplify use of fidl
  as was previously used in CastStreamingSessionClient.

Bug: 1208194
Change-Id: I46358db1605841ed3acb02e358c413da5cbc7589
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2895461
Commit-Queue: Ryan Keane <rwkeane@google.com>
Reviewed-by: Fabrice de Gans <fdegans@chromium.org>
Cr-Commit-Position: refs/heads/master@{#885727}
  • Loading branch information
Ryan Keane authored and Chromium LUCI CQ committed May 22, 2021
1 parent a09bf7e commit 27e97c5
Show file tree
Hide file tree
Showing 16 changed files with 214 additions and 93 deletions.
28 changes: 25 additions & 3 deletions components/cast_streaming/browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,28 @@ source_set("core") {
}

source_set("receiver_session") {
deps = [
":core",
":streaming_session",
"//base",
"//media",
"//media/mojo/common",
"//media/mojo/mojom",
"//mojo/public/cpp/system",
]
public_deps = [
"//components/cast_streaming/mojo:mojom",
"//third_party/openscreen/src/cast/common:channel",
]
visibility = [ ":*" ]
public = [ "public/receiver_session.h" ]
sources = [
"receiver_session_impl.cc",
"receiver_session_impl.h",
]
}

source_set("streaming_session") {
deps = [
":core",
"//base",
Expand All @@ -44,9 +66,9 @@ source_set("receiver_session") {
]
public_deps = [ "//components/cast/message_port" ]
visibility = [ ":*" ]
public = [ "public/cast_streaming_session.h" ]
sources = [
"cast_streaming_session.cc",
"cast_streaming_session.h",
"stream_consumer.cc",
"stream_consumer.h",
]
Expand Down Expand Up @@ -101,7 +123,7 @@ source_set("test_sender") {
source_set("test_receiver") {
testonly = true
deps = [
":receiver_session",
":streaming_session",
"//base",
"//components/openscreen_platform",
"//media",
Expand All @@ -123,7 +145,7 @@ source_set("test_receiver") {
test("e2e_tests") {
deps = [
":core",
":receiver_session",
":streaming_session",
":test_receiver",
":test_sender",
"//base/test:test_support",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/cast_streaming/browser/public/cast_streaming_session.h"
#include "components/cast_streaming/browser/cast_streaming_session.h"

#include "base/bind.h"
#include "base/timer/timer.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_CAST_STREAMING_BROWSER_PUBLIC_CAST_STREAMING_SESSION_H_
#define COMPONENTS_CAST_STREAMING_BROWSER_PUBLIC_CAST_STREAMING_SESSION_H_
#ifndef COMPONENTS_CAST_STREAMING_BROWSER_CAST_STREAMING_SESSION_H_
#define COMPONENTS_CAST_STREAMING_BROWSER_CAST_STREAMING_SESSION_H_

#include <memory>

Expand Down Expand Up @@ -92,4 +92,4 @@ class CastStreamingSession {

} // namespace cast_streaming

#endif // COMPONENTS_CAST_STREAMING_BROWSER_PUBLIC_CAST_STREAMING_SESSION_H_
#endif // COMPONENTS_CAST_STREAMING_BROWSER_CAST_STREAMING_SESSION_H_
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/cast_streaming/browser/public/cast_streaming_session.h"
#include "components/cast_streaming/browser/cast_streaming_session.h"

#include "base/run_loop.h"
#include "base/test/task_environment.h"
Expand Down
45 changes: 45 additions & 0 deletions components/cast_streaming/browser/public/receiver_session.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_CAST_STREAMING_BROWSER_PUBLIC_RECEIVER_SESSION_H_
#define COMPONENTS_CAST_STREAMING_BROWSER_PUBLIC_RECEIVER_SESSION_H_

#include <memory>

#include "base/callback.h"
#include "components/cast_streaming/mojo/cast_streaming_session.mojom.h"
#include "mojo/public/cpp/bindings/associated_remote.h"

namespace cast_api_bindings {
class MessagePort;
}

namespace cast_streaming {

// This interface handles a single Cast Streaming Receiver Session over a given
// |message_port| and with a given |cast_streaming_receiver|. On destruction,
// the Cast Streaming Receiver Session will be terminated if it was ever
// started.
class ReceiverSession {
public:
using MessagePortProvider =
base::OnceCallback<std::unique_ptr<cast_api_bindings::MessagePort>()>;

virtual ~ReceiverSession() = default;

static std::unique_ptr<ReceiverSession> Create(
MessagePortProvider message_port_provider);

// Sets up the CastStreamingReceiver mojo remote. This will immediately call
// CastStreamingReceiver::EnableReceiver(). Upon receiving the callback for
// this method, the Cast Streaming Receiver Session will be started and audio
// and/or video frames will be sent over a Mojo channel.
virtual void SetCastStreamingReceiver(
mojo::AssociatedRemote<mojom::CastStreamingReceiver>
cast_streaming_receiver) = 0;
};

} // namespace cast_streaming

#endif // COMPONENTS_CAST_STREAMING_BROWSER_PUBLIC_RECEIVER_SESSION_H_
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,31 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "fuchsia/engine/browser/cast_streaming_session_client.h"
#include "components/cast_streaming/browser/receiver_session_impl.h"

#include "base/threading/sequenced_task_runner_handle.h"
#include "components/cast/message_port/message_port_fuchsia.h"
#include "media/base/audio_decoder_config.h"
#include "media/base/video_decoder_config.h"
#include "media/mojo/mojom/media_types.mojom.h"

CastStreamingSessionClient::CastStreamingSessionClient(
fidl::InterfaceRequest<fuchsia::web::MessagePort> message_port_request)
: message_port_request_(std::move(message_port_request)) {}
namespace cast_streaming {

CastStreamingSessionClient::~CastStreamingSessionClient() = default;
// static
std::unique_ptr<ReceiverSession> ReceiverSession::Create(
ReceiverSession::MessagePortProvider message_port_provider) {
return std::make_unique<ReceiverSessionImpl>(
std::move(message_port_provider));
}

ReceiverSessionImpl::ReceiverSessionImpl(
ReceiverSession::MessagePortProvider message_port_provider)
: message_port_provider_(std::move(message_port_provider)) {
DCHECK(message_port_provider_);
}

void CastStreamingSessionClient::StartMojoConnection(
ReceiverSessionImpl::~ReceiverSessionImpl() = default;

void ReceiverSessionImpl::SetCastStreamingReceiver(
mojo::AssociatedRemote<mojom::CastStreamingReceiver>
cast_streaming_receiver) {
DVLOG(1) << __func__;
Expand All @@ -26,21 +36,19 @@ void CastStreamingSessionClient::StartMojoConnection(
// AssociatedRemote, is owned by |this| and will be torn-down at the same time
// as |this|.
cast_streaming_receiver_->EnableReceiver(base::BindOnce(
&CastStreamingSessionClient::OnReceiverEnabled, base::Unretained(this)));
&ReceiverSessionImpl::OnReceiverEnabled, base::Unretained(this)));
cast_streaming_receiver_.set_disconnect_handler(base::BindOnce(
&CastStreamingSessionClient::OnMojoDisconnect, base::Unretained(this)));
&ReceiverSessionImpl::OnMojoDisconnect, base::Unretained(this)));
}

void CastStreamingSessionClient::OnReceiverEnabled() {
void ReceiverSessionImpl::OnReceiverEnabled() {
DVLOG(1) << __func__;
DCHECK(message_port_request_);
cast_streaming_session_.Start(this,
cast_api_bindings::MessagePortFuchsia::Create(
std::move(message_port_request_)),
DCHECK(message_port_provider_);
cast_streaming_session_.Start(this, std::move(message_port_provider_).Run(),
base::SequencedTaskRunnerHandle::Get());
}

void CastStreamingSessionClient::OnSessionInitialization(
void ReceiverSessionImpl::OnSessionInitialization(
absl::optional<cast_streaming::CastStreamingSession::AudioStreamInfo>
audio_stream_info,
absl::optional<cast_streaming::CastStreamingSession::VideoStreamInfo>
Expand Down Expand Up @@ -68,21 +76,21 @@ void CastStreamingSessionClient::OnSessionInitialization(
std::move(mojo_audio_stream_info), std::move(mojo_video_stream_info));
}

void CastStreamingSessionClient::OnAudioBufferReceived(
void ReceiverSessionImpl::OnAudioBufferReceived(
media::mojom::DecoderBufferPtr buffer) {
DVLOG(3) << __func__;
DCHECK(audio_remote_);
audio_remote_->ProvideBuffer(std::move(buffer));
}

void CastStreamingSessionClient::OnVideoBufferReceived(
void ReceiverSessionImpl::OnVideoBufferReceived(
media::mojom::DecoderBufferPtr buffer) {
DVLOG(3) << __func__;
DCHECK(video_remote_);
video_remote_->ProvideBuffer(std::move(buffer));
}

void CastStreamingSessionClient::OnSessionReinitialization(
void ReceiverSessionImpl::OnSessionReinitialization(
absl::optional<cast_streaming::CastStreamingSession::AudioStreamInfo>
audio_stream_info,
absl::optional<cast_streaming::CastStreamingSession::VideoStreamInfo>
Expand All @@ -101,7 +109,7 @@ void CastStreamingSessionClient::OnSessionReinitialization(
}
}

void CastStreamingSessionClient::OnSessionEnded() {
void ReceiverSessionImpl::OnSessionEnded() {
DVLOG(1) << __func__;

// Tear down the Mojo connection.
Expand All @@ -115,14 +123,12 @@ void CastStreamingSessionClient::OnSessionEnded() {
video_remote_.reset();
}

void CastStreamingSessionClient::OnMojoDisconnect() {
void ReceiverSessionImpl::OnMojoDisconnect() {
DVLOG(1) << __func__;

if (message_port_request_) {
// Close the MessagePort if the Cast Streaming Session was never started.
message_port_request_.Close(ZX_ERR_PEER_CLOSED);
cast_streaming_receiver_.reset();
return;
// Close the underlying connection.
if (message_port_provider_) {
std::move(message_port_provider_).Run().reset();
}

// Close the Cast Streaming Session. OnSessionEnded() will be called as part
Expand All @@ -133,3 +139,5 @@ void CastStreamingSessionClient::OnMojoDisconnect() {
audio_remote_.reset();
video_remote_.reset();
}

} // namespace cast_streaming
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,33 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef FUCHSIA_ENGINE_BROWSER_CAST_STREAMING_SESSION_CLIENT_H_
#define FUCHSIA_ENGINE_BROWSER_CAST_STREAMING_SESSION_CLIENT_H_
#ifndef COMPONENTS_CAST_STREAMING_BROWSER_RECEIVER_SESSION_IMPL_H_
#define COMPONENTS_CAST_STREAMING_BROWSER_RECEIVER_SESSION_IMPL_H_

#include <fuchsia/web/cpp/fidl.h>

#include "components/cast_streaming/browser/public/cast_streaming_session.h"
#include "components/cast_streaming/browser/cast_streaming_session.h"
#include "components/cast_streaming/browser/public/receiver_session.h"
#include "components/cast_streaming/mojo/cast_streaming_session.mojom.h"
#include "mojo/public/cpp/bindings/associated_remote.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "third_party/abseil-cpp/absl/types/optional.h"

namespace cast_streaming {

// Owns the CastStreamingSession and sends buffers to the renderer process via
// a Mojo service.
//
// TODO(crbug.com/1208194): Move this class to //components/cast_streaming,
class CastStreamingSessionClient
: public cast_streaming::CastStreamingSession::Client {
class ReceiverSessionImpl : public cast_streaming::CastStreamingSession::Client,
public ReceiverSession {
public:
explicit CastStreamingSessionClient(
fidl::InterfaceRequest<fuchsia::web::MessagePort> message_port_request);
~CastStreamingSessionClient() final;
explicit ReceiverSessionImpl(MessagePortProvider message_port_provider);
~ReceiverSessionImpl() final;

CastStreamingSessionClient(const CastStreamingSessionClient&) = delete;
CastStreamingSessionClient& operator=(const CastStreamingSessionClient&) =
delete;
ReceiverSessionImpl(const ReceiverSessionImpl&) = delete;
ReceiverSessionImpl& operator=(const ReceiverSessionImpl&) = delete;

void StartMojoConnection(mojo::AssociatedRemote<mojom::CastStreamingReceiver>
cast_streaming_receiver);
// ReceiverSession implementation.
void SetCastStreamingReceiver(
mojo::AssociatedRemote<mojom::CastStreamingReceiver>
cast_streaming_receiver) override;

private:
// Handler for |cast_streaming_receiver_| disconnect.
Expand All @@ -53,12 +52,17 @@ class CastStreamingSessionClient
video_stream_info) final;
void OnSessionEnded() final;

fidl::InterfaceRequest<fuchsia::web::MessagePort> message_port_request_;
// Populated in the ctor, and empty following a call to either
// OnReceiverEnabled() or OnMojoDisconnect().
MessagePortProvider message_port_provider_;

mojo::AssociatedRemote<mojom::CastStreamingReceiver> cast_streaming_receiver_;
cast_streaming::CastStreamingSession cast_streaming_session_;

mojo::Remote<mojom::CastStreamingBufferReceiver> audio_remote_;
mojo::Remote<mojom::CastStreamingBufferReceiver> video_remote_;
};

#endif // FUCHSIA_ENGINE_BROWSER_CAST_STREAMING_SESSION_CLIENT_H_
} // namespace cast_streaming

#endif // COMPONENTS_CAST_STREAMING_BROWSER_RECEIVER_SESSION_IMPL_H_
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include "base/callback.h"
#include "components/cast/message_port/message_port.h"
#include "components/cast_streaming/browser/public/cast_streaming_session.h"
#include "components/cast_streaming/browser/cast_streaming_session.h"
#include "media/mojo/common/mojo_decoder_buffer_converter.h"
#include "third_party/abseil-cpp/absl/types/optional.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "base/bind.h"
#include "base/test/launcher/unit_test_launcher.h"
#include "base/test/test_suite.h"
#include "components/cast_streaming/browser/public/cast_streaming_session.h"
#include "components/cast_streaming/browser/cast_streaming_session.h"
#include "mojo/core/embedder/embedder.h"

int main(int argc, char** argv) {
Expand Down
5 changes: 3 additions & 2 deletions fuchsia/engine/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ component("web_engine_core") {
"//base",
"//base:base_static",
"//base/util/memory_pressure",
"//components/cast/message_port:message_port_fuchsia",
"//components/cast_streaming/browser",
"//components/cast_streaming/mojo:mojom",
"//components/cast_streaming/renderer",
Expand Down Expand Up @@ -190,8 +191,6 @@ component("web_engine_core") {
"browser/accessibility_bridge.h",
"browser/ax_tree_converter.cc",
"browser/ax_tree_converter.h",
"browser/cast_streaming_session_client.cc",
"browser/cast_streaming_session_client.h",
"browser/content_directory_loader_factory.cc",
"browser/content_directory_loader_factory.h",
"browser/context_impl.cc",
Expand All @@ -218,6 +217,8 @@ component("web_engine_core") {
"browser/navigation_policy_handler.h",
"browser/navigation_policy_throttle.cc",
"browser/navigation_policy_throttle.h",
"browser/receiver_session_client.cc",
"browser/receiver_session_client.h",
"browser/theme_manager.cc",
"browser/theme_manager.h",
"browser/url_request_rewrite_rules_manager.cc",
Expand Down
1 change: 1 addition & 0 deletions fuchsia/engine/browser/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ include_rules = [
"+services/metrics/public/cpp/ukm_source_id.h",
"+services/network/public/mojom",
"+third_party/blink/public",
"+third_party/openscreen/src",
"+third_party/widevine/cdm",
"+ui/accessibility",
"+ui/aura",
Expand Down
Loading

0 comments on commit 27e97c5

Please sign in to comment.