• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/receiver_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   struct Configuration {
45     // The task runner to be used for async calls.
46     TaskRunner* task_runner;
47 
48     // The interface the cast service is running on.
49     InterfaceInfo interface;
50 
51     // The credentials that the cast service should use for TLS.
52     GeneratedCredentials credentials;
53 
54     // The friendly name to be used for broadcasting.
55     std::string friendly_name;
56 
57     // The model name to be used for broadcasting.
58     std::string model_name;
59 
60     // Whether we should broadcast over mDNS/DNS-SD.
61     bool enable_discovery = true;
62   };
63 
64   explicit CastService(Configuration config);
65   ~CastService() final;
66 
67  private:
68   using LazyDeletedDiscoveryService = SerialDeletePtr<discovery::DnsSdService>;
69   using LazyDeletedDiscoveryPublisher =
70       SerialDeletePtr<discovery::DnsSdServicePublisher<ReceiverInfo>>;
71 
72   // discovery::ReportingClient overrides.
73   void OnFatalError(Error error) final;
74   void OnRecoverableError(Error error) final;
75 
76   const IPEndpoint local_endpoint_;
77   const GeneratedCredentials credentials_;
78 
79   ApplicationAgent agent_;
80   MirroringApplication mirroring_application_;
81   ReceiverSocketFactory socket_factory_;
82   std::unique_ptr<TlsConnectionFactory> connection_factory_;
83 
84   LazyDeletedDiscoveryService discovery_service_;
85   LazyDeletedDiscoveryPublisher discovery_publisher_;
86 };
87 
88 }  // namespace cast
89 }  // namespace openscreen
90 
91 #endif  // CAST_STANDALONE_RECEIVER_CAST_SERVICE_H_
92