1 // Copyright 2020 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CAST_STANDALONE_RECEIVER_CAST_SERVICE_H_ 6 #define CAST_STANDALONE_RECEIVER_CAST_SERVICE_H_ 7 8 #include <memory> 9 #include <string> 10 11 #include "cast/common/public/service_info.h" 12 #include "cast/receiver/application_agent.h" 13 #include "cast/receiver/channel/static_credentials.h" 14 #include "cast/receiver/public/receiver_socket_factory.h" 15 #include "cast/standalone_receiver/mirroring_application.h" 16 #include "discovery/common/reporting_client.h" 17 #include "discovery/public/dns_sd_service_factory.h" 18 #include "discovery/public/dns_sd_service_publisher.h" 19 #include "platform/api/serial_delete_ptr.h" 20 #include "platform/base/error.h" 21 #include "platform/base/ip_address.h" 22 23 namespace openscreen { 24 25 struct InterfaceInfo; 26 class TaskRunner; 27 class TlsConnectionFactory; 28 29 namespace cast { 30 31 // Assembles all the necessary components and manages their lifetimes, to create 32 // a full Cast Receiver on the network, with the following overall 33 // functionality: 34 // 35 // * Listens for TCP connections on port 8010. 36 // * Establishes TLS tunneling over those connections. 37 // * Wraps a CastSocket API around the TLS connections. 38 // * Manages available receiver-side applications. 39 // * Provides a Cast V2 Mirroring application (media streaming playback in an 40 // on-screen window). 41 // * Publishes over mDNS to be discoverable to all senders on the same LAN. 42 class CastService final : public discovery::ReportingClient { 43 public: 44 CastService(TaskRunner* task_runner, 45 const InterfaceInfo& interface, 46 GeneratedCredentials credentials, 47 const std::string& friendly_name, 48 const std::string& model_name, 49 bool enable_discovery = true); 50 51 ~CastService() final; 52 53 private: 54 using LazyDeletedDiscoveryService = SerialDeletePtr<discovery::DnsSdService>; 55 using LazyDeletedDiscoveryPublisher = 56 SerialDeletePtr<discovery::DnsSdServicePublisher<ServiceInfo>>; 57 58 // discovery::ReportingClient overrides. 59 void OnFatalError(Error error) final; 60 void OnRecoverableError(Error error) final; 61 62 const IPEndpoint local_endpoint_; 63 const GeneratedCredentials credentials_; 64 65 ApplicationAgent agent_; 66 MirroringApplication mirroring_application_; 67 ReceiverSocketFactory socket_factory_; 68 std::unique_ptr<TlsConnectionFactory> connection_factory_; 69 70 LazyDeletedDiscoveryService discovery_service_; 71 LazyDeletedDiscoveryPublisher discovery_publisher_; 72 }; 73 74 } // namespace cast 75 } // namespace openscreen 76 77 #endif // CAST_STANDALONE_RECEIVER_CAST_SERVICE_H_ 78