aboutsummaryrefslogtreecommitdiff
path: root/cast/standalone_receiver
diff options
context:
space:
mode:
Diffstat (limited to 'cast/standalone_receiver')
-rw-r--r--cast/standalone_receiver/cast_service.cc41
-rw-r--r--cast/standalone_receiver/cast_service.h26
-rw-r--r--cast/standalone_receiver/main.cc41
-rw-r--r--cast/standalone_receiver/mirroring_application.cc12
-rw-r--r--cast/standalone_receiver/streaming_playback_controller.cc8
-rw-r--r--cast/standalone_receiver/streaming_playback_controller.h5
6 files changed, 80 insertions, 53 deletions
diff --git a/cast/standalone_receiver/cast_service.cc b/cast/standalone_receiver/cast_service.cc
index efab229b..28e6c65c 100644
--- a/cast/standalone_receiver/cast_service.cc
+++ b/cast/standalone_receiver/cast_service.cc
@@ -37,28 +37,27 @@ discovery::Config MakeDiscoveryConfig(const InterfaceInfo& interface) {
} // namespace
-CastService::CastService(TaskRunner* task_runner,
- const InterfaceInfo& interface,
- GeneratedCredentials credentials,
- const std::string& friendly_name,
- const std::string& model_name,
- bool enable_discovery)
- : local_endpoint_(DetermineEndpoint(interface)),
- credentials_(std::move(credentials)),
- agent_(task_runner, credentials_.provider.get()),
- mirroring_application_(task_runner, local_endpoint_.address, &agent_),
+CastService::CastService(CastService::Configuration config)
+ : local_endpoint_(DetermineEndpoint(config.interface)),
+ credentials_(std::move(config.credentials)),
+ agent_(config.task_runner, credentials_.provider.get()),
+ mirroring_application_(config.task_runner,
+ local_endpoint_.address,
+ &agent_),
socket_factory_(&agent_, agent_.cast_socket_client()),
connection_factory_(
- TlsConnectionFactory::CreateFactory(&socket_factory_, task_runner)),
- discovery_service_(enable_discovery ? discovery::CreateDnsSdService(
- task_runner,
- this,
- MakeDiscoveryConfig(interface))
- : LazyDeletedDiscoveryService()),
+ TlsConnectionFactory::CreateFactory(&socket_factory_,
+ config.task_runner)),
+ discovery_service_(config.enable_discovery
+ ? discovery::CreateDnsSdService(
+ config.task_runner,
+ this,
+ MakeDiscoveryConfig(config.interface))
+ : LazyDeletedDiscoveryService()),
discovery_publisher_(
discovery_service_
? MakeSerialDelete<discovery::DnsSdServicePublisher<ServiceInfo>>(
- task_runner,
+ config.task_runner,
discovery_service_.get(),
kCastV2ServiceId,
ServiceInfoToDnsSdInstance)
@@ -69,11 +68,11 @@ CastService::CastService(TaskRunner* task_runner,
if (discovery_publisher_) {
ServiceInfo info;
info.port = local_endpoint_.port;
- info.unique_id = HexEncode(interface.hardware_address);
- info.friendly_name = friendly_name;
- info.model_name = model_name;
+ info.unique_id = HexEncode(config.interface.hardware_address);
+ info.friendly_name = config.friendly_name;
+ info.model_name = config.model_name;
info.capabilities = kHasVideoOutput | kHasAudioOutput;
- Error error = discovery_publisher_->Register(info);
+ const Error error = discovery_publisher_->Register(info);
if (!error.ok()) {
OnFatalError(std::move(error));
}
diff --git a/cast/standalone_receiver/cast_service.h b/cast/standalone_receiver/cast_service.h
index 99137de2..c210b433 100644
--- a/cast/standalone_receiver/cast_service.h
+++ b/cast/standalone_receiver/cast_service.h
@@ -41,13 +41,27 @@ namespace cast {
// * Publishes over mDNS to be discoverable to all senders on the same LAN.
class CastService final : public discovery::ReportingClient {
public:
- CastService(TaskRunner* task_runner,
- const InterfaceInfo& interface,
- GeneratedCredentials credentials,
- const std::string& friendly_name,
- const std::string& model_name,
- bool enable_discovery = true);
+ struct Configuration {
+ // The task runner to be used for async calls.
+ TaskRunner* task_runner;
+ // The interface the cast service is running on.
+ InterfaceInfo interface;
+
+ // The credentials that the cast service should use for TLS.
+ GeneratedCredentials credentials;
+
+ // The friendly name to be used for broadcasting.
+ std::string friendly_name;
+
+ // The model name to be used for broadcasting.
+ std::string model_name;
+
+ // Whether we should broadcast over mDNS/DNS-SD.
+ bool enable_discovery = true;
+ };
+
+ explicit CastService(Configuration config);
~CastService() final;
private:
diff --git a/cast/standalone_receiver/main.cc b/cast/standalone_receiver/main.cc
index 8dd0f37a..d66d70e6 100644
--- a/cast/standalone_receiver/main.cc
+++ b/cast/standalone_receiver/main.cc
@@ -67,6 +67,11 @@ options:
-v, --verbose: Enable verbose logging.
-h, --help: Show this help message.
+
+ -x, --disable-discovery: Disable discovery, useful for platforms like Mac OS
+ where our implementation is incompatible with
+ the native Bonjour service.
+
)";
std::cerr << StringPrintf(kTemplate, argv0);
@@ -95,30 +100,22 @@ InterfaceInfo GetInterfaceInfoFromName(const char* name) {
return interface_info;
}
-void RunCastService(TaskRunnerImpl* task_runner,
- const InterfaceInfo& interface,
- GeneratedCredentials creds,
- const std::string& friendly_name,
- const std::string& model_name,
- bool discovery_enabled) {
+void RunCastService(TaskRunnerImpl* runner, CastService::Configuration config) {
std::unique_ptr<CastService> service;
- task_runner->PostTask([&] {
- service = std::make_unique<CastService>(task_runner, interface,
- std::move(creds), friendly_name,
- model_name, discovery_enabled);
- });
+ runner->PostTask(
+ [&] { service = std::make_unique<CastService>(std::move(config)); });
OSP_LOG_INFO << "CastService is running. CTRL-C (SIGINT), or send a "
"SIGTERM to exit.";
- task_runner->RunUntilSignaled();
+ runner->RunUntilSignaled();
// Spin the TaskRunner to execute destruction/shutdown tasks.
OSP_LOG_INFO << "Shutting down...";
- task_runner->PostTask([&] {
+ runner->PostTask([&] {
service.reset();
- task_runner->RequestStopSoon();
+ runner->RequestStopSoon();
});
- task_runner->RunUntilStopped();
+ runner->RunUntilStopped();
OSP_LOG_INFO << "Bye!";
}
@@ -160,7 +157,7 @@ int RunStandaloneReceiver(int argc, char* argv[]) {
{nullptr, 0, nullptr, 0}};
bool is_verbose = false;
- bool discovery_enabled = true;
+ bool enable_discovery = true;
std::string private_key_path;
std::string developer_certificate_path;
std::string friendly_name = "Cast Standalone Receiver";
@@ -168,7 +165,7 @@ int RunStandaloneReceiver(int argc, char* argv[]) {
bool should_generate_credentials = false;
std::unique_ptr<TextTraceLoggingPlatform> trace_logger;
int ch = -1;
- while ((ch = getopt_long(argc, argv, "p:d:f:m:gtvhx", kArgumentOptions,
+ while ((ch = getopt_long(argc, argv, "p:d:f:m:grtvhx", kArgumentOptions,
nullptr)) != -1) {
switch (ch) {
case 'p':
@@ -193,7 +190,7 @@ int RunStandaloneReceiver(int argc, char* argv[]) {
is_verbose = true;
break;
case 'x':
- discovery_enabled = false;
+ enable_discovery = false;
break;
case 'h':
LogUsage(argv[0]);
@@ -234,14 +231,16 @@ int RunStandaloneReceiver(int argc, char* argv[]) {
<< "Hardware address is empty. Either you are on a loopback device "
"or getting the network interface information failed somehow. "
"Discovery publishing will be disabled.";
- discovery_enabled = false;
+ enable_discovery = false;
}
auto* const task_runner = new TaskRunnerImpl(&Clock::now);
PlatformClientPosix::Create(milliseconds(50),
std::unique_ptr<TaskRunnerImpl>(task_runner));
- RunCastService(task_runner, interface, std::move(creds.value()),
- friendly_name, model_name, discovery_enabled);
+ RunCastService(task_runner,
+ CastService::Configuration{
+ task_runner, interface, std::move(creds.value()),
+ friendly_name, model_name, enable_discovery});
PlatformClientPosix::ShutDown();
return 0;
diff --git a/cast/standalone_receiver/mirroring_application.cc b/cast/standalone_receiver/mirroring_application.cc
index b654e010..83921d76 100644
--- a/cast/standalone_receiver/mirroring_application.cc
+++ b/cast/standalone_receiver/mirroring_application.cc
@@ -4,6 +4,8 @@
#include "cast/standalone_receiver/mirroring_application.h"
+#include <utility>
+
#include "cast/common/public/message_port.h"
#include "cast/streaming/constants.h"
#include "cast/streaming/environment.h"
@@ -53,9 +55,13 @@ bool MirroringApplication::Launch(const std::string& app_id,
IPEndpoint{interface_address_, kDefaultCastStreamingPort});
controller_ =
std::make_unique<StreamingPlaybackController>(task_runner_, this);
- current_session_ = std::make_unique<ReceiverSession>(
- controller_.get(), environment_.get(), message_port,
- ReceiverSession::Preferences{});
+
+ ReceiverSession::Preferences preferences;
+ preferences.remoting =
+ std::make_unique<ReceiverSession::RemotingPreferences>();
+ current_session_ =
+ std::make_unique<ReceiverSession>(controller_.get(), environment_.get(),
+ message_port, std::move(preferences));
return true;
}
diff --git a/cast/standalone_receiver/streaming_playback_controller.cc b/cast/standalone_receiver/streaming_playback_controller.cc
index 4c3f627b..918653f5 100644
--- a/cast/standalone_receiver/streaming_playback_controller.cc
+++ b/cast/standalone_receiver/streaming_playback_controller.cc
@@ -83,6 +83,14 @@ void StreamingPlaybackController::OnNegotiated(
#endif // defined(CAST_STANDALONE_RECEIVER_HAVE_EXTERNAL_LIBS)
}
+void StreamingPlaybackController::OnRemotingNegotiated(
+ const ReceiverSession* session,
+ ReceiverSession::RemotingNegotiation negotiation) {
+ // TODO(issuetracker.google.com/190078859): need ability to initialize
+ // remoting codecs.
+ OSP_UNIMPLEMENTED();
+}
+
void StreamingPlaybackController::OnReceiversDestroying(
const ReceiverSession* session,
ReceiversDestroyingReason reason) {
diff --git a/cast/standalone_receiver/streaming_playback_controller.h b/cast/standalone_receiver/streaming_playback_controller.h
index d2ab72f2..5a743bf6 100644
--- a/cast/standalone_receiver/streaming_playback_controller.h
+++ b/cast/standalone_receiver/streaming_playback_controller.h
@@ -35,10 +35,11 @@ class StreamingPlaybackController final : public ReceiverSession::Client {
// ReceiverSession::Client overrides.
void OnNegotiated(const ReceiverSession* session,
ReceiverSession::ConfiguredReceivers receivers) override;
-
+ void OnRemotingNegotiated(
+ const ReceiverSession* session,
+ ReceiverSession::RemotingNegotiation negotiation) override;
void OnReceiversDestroying(const ReceiverSession* session,
ReceiversDestroyingReason reason) override;
-
void OnError(const ReceiverSession* session, Error error) override;
private: