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_STREAMING_RECEIVER_MESSAGE_H_ 6 #define CAST_STREAMING_RECEIVER_MESSAGE_H_ 7 8 #include <memory> 9 #include <string> 10 #include <vector> 11 12 #include "absl/types/variant.h" 13 #include "cast/streaming/answer_messages.h" 14 #include "json/value.h" 15 #include "util/osp_logging.h" 16 17 namespace openscreen { 18 namespace cast { 19 20 struct ReceiverWifiStatus { 21 Json::Value ToJson() const; 22 static ErrorOr<ReceiverWifiStatus> Parse(const Json::Value& value); 23 24 // Current WiFi signal to noise ratio in decibels. 25 double wifi_snr = 0.0; 26 27 // Min, max, average, and current bandwidth in bps in order of the WiFi link. 28 // Example: [1200, 1300, 1250, 1230]. 29 std::vector<int32_t> wifi_speed; 30 }; 31 32 struct ReceiverCapability { 33 static constexpr int kRemotingVersionUnknown = -1; 34 35 Json::Value ToJson() const; 36 static ErrorOr<ReceiverCapability> Parse(const Json::Value& value); 37 38 // The remoting version that the receiver uses. 39 int remoting_version = kRemotingVersionUnknown; 40 41 // Set of capabilities (e.g., ac3, 4k, hevc, vp9, dolby_vision, etc.). 42 std::vector<std::string> media_capabilities; 43 }; 44 45 struct ReceiverError { 46 Json::Value ToJson() const; 47 static ErrorOr<ReceiverError> Parse(const Json::Value& value); 48 49 // Error code. 50 int32_t code = -1; 51 52 // Error description. 53 std::string description; 54 }; 55 56 struct ReceiverMessage { 57 public: 58 // Receiver response message type. 59 enum class Type { 60 // Unknown message type. 61 kUnknown, 62 63 // Response to OFFER message. 64 kAnswer, 65 66 // Response to GET_STATUS message. 67 kStatusResponse, 68 69 // Response to GET_CAPABILITIES message. 70 kCapabilitiesResponse, 71 72 // Rpc binary messages. The payload is base64-encoded. 73 kRpc, 74 }; 75 76 static ErrorOr<ReceiverMessage> Parse(const Json::Value& value); 77 ErrorOr<Json::Value> ToJson() const; 78 79 Type type = Type::kUnknown; 80 81 int32_t sequence_number = -1; 82 83 bool valid = false; 84 85 absl::variant<absl::monostate, 86 Answer, 87 std::string, 88 ReceiverWifiStatus, 89 ReceiverCapability, 90 ReceiverError> 91 body; 92 }; 93 94 } // namespace cast 95 } // namespace openscreen 96 97 #endif // CAST_STREAMING_RECEIVER_MESSAGE_H_ 98