1 // Copyright 2019 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_COMMON_PUBLIC_RECEIVER_INFO_H_ 6 #define CAST_COMMON_PUBLIC_RECEIVER_INFO_H_ 7 8 #include <memory> 9 #include <string> 10 #include <utility> 11 12 #include "discovery/dnssd/public/dns_sd_instance.h" 13 #include "discovery/dnssd/public/dns_sd_instance_endpoint.h" 14 #include "platform/base/ip_address.h" 15 16 namespace openscreen { 17 namespace cast { 18 19 // Constants to identify a CastV2 instance with DNS-SD. 20 constexpr char kCastV2ServiceId[] = "_googlecast._tcp"; 21 constexpr char kCastV2DomainId[] = "local"; 22 23 // Constants to be used as keys when storing data inside of a DNS-SD TXT record. 24 constexpr char kUniqueIdKey[] = "id"; 25 constexpr char kVersionKey[] = "ve"; 26 constexpr char kCapabilitiesKey[] = "ca"; 27 constexpr char kStatusKey[] = "st"; 28 constexpr char kFriendlyNameKey[] = "fn"; 29 constexpr char kModelNameKey[] = "md"; 30 31 // This represents the ‘st’ flag in the CastV2 TXT record. 32 enum ReceiverStatus { 33 // The receiver is idle and does not need to be connected now. 34 kIdle = 0, 35 36 // The receiver is hosting an activity and invites the sender to join. The 37 // receiver should connect to the running activity using the channel 38 // establishment protocol, and then query the activity to determine the next 39 // step, such as showing a description of the activity and prompting the user 40 // to launch the corresponding app. 41 kBusy = 1, 42 kJoin = kBusy 43 }; 44 45 constexpr uint8_t kCurrentCastVersion = 2; 46 47 // Bits in the ‘ca’ bitfield, per the CastV2 spec. 48 constexpr uint64_t kHasVideoOutput = 1 << 0; 49 constexpr uint64_t kHasVideoInput = 1 << 1; 50 constexpr uint64_t kHasAudioOutput = 1 << 2; 51 constexpr uint64_t kHasAudioIntput = 1 << 3; 52 constexpr uint64_t kIsDevModeEnabled = 1 << 4; 53 54 constexpr uint64_t kNoCapabilities = 0; 55 56 // This is the top-level receiver info class for CastV2. It describes a specific 57 // service instance. 58 struct ReceiverInfo { 59 // returns the instance id associated with this ReceiverInfo instance. 60 const std::string& GetInstanceId() const; 61 62 // Returns whether all fields of this ReceiverInfo are valid. 63 bool IsValid() const; 64 65 // Addresses for the service. Present if an address of this address type 66 // exists and empty otherwise. When publishing a service instance, these 67 // values will be overridden based on |network_config| values provided in the 68 // discovery::Config object used to initialize discovery. 69 IPAddress v4_address; 70 IPAddress v6_address; 71 72 // Port at which this service can be reached. 73 uint16_t port; 74 75 // A UUID for the Cast receiver. This should be a universally unique 76 // identifier for the receiver, and should (but does not have to be) be stable 77 // across factory resets. 78 std::string unique_id; 79 80 // Cast protocol version supported. Begins at 2 and is incremented by 1 with 81 // each version. 82 uint8_t protocol_version = kCurrentCastVersion; 83 84 // Bitfield of ReceiverCapabilities supported by this service instance. 85 uint64_t capabilities = kNoCapabilities; 86 87 // Status of the service instance. 88 ReceiverStatus status = ReceiverStatus::kIdle; 89 90 // The model name of the receiver, e.g. “Eureka v1”, “Mollie”. 91 std::string model_name; 92 93 // The friendly name of the receiver, e.g. “Living Room TV". 94 std::string friendly_name; 95 96 private: 97 mutable std::string instance_id_ = ""; 98 }; 99 100 inline bool operator==(const ReceiverInfo& lhs, const ReceiverInfo& rhs) { 101 return lhs.v4_address == rhs.v4_address && lhs.v6_address == rhs.v6_address && 102 lhs.port == rhs.port && lhs.unique_id == rhs.unique_id && 103 lhs.protocol_version == rhs.protocol_version && 104 lhs.capabilities == rhs.capabilities && lhs.status == rhs.status && 105 lhs.model_name == rhs.model_name && 106 lhs.friendly_name == rhs.friendly_name; 107 } 108 109 inline bool operator!=(const ReceiverInfo& lhs, const ReceiverInfo& rhs) { 110 return !(lhs == rhs); 111 } 112 113 // Functions responsible for converting between CastV2 and DNS-SD 114 // representations of a service instance. 115 discovery::DnsSdInstance ReceiverInfoToDnsSdInstance( 116 const ReceiverInfo& service); 117 118 ErrorOr<ReceiverInfo> DnsSdInstanceEndpointToReceiverInfo( 119 const discovery::DnsSdInstanceEndpoint& endpoint); 120 121 } // namespace cast 122 } // namespace openscreen 123 124 #endif // CAST_COMMON_PUBLIC_RECEIVER_INFO_H_ 125