xref: /aosp_15_r20/external/openscreen/cast/streaming/receiver_message.h (revision 3f982cf4871df8771c9d4abe6e9a6f8d829b2736)
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 enum class MediaCapability {
21   kAudio,
22   kAac,
23   kOpus,
24   kVideo,
25   k4k,
26   kH264,
27   kVp8,
28   kVp9,
29   kHevc,
30   kAv1
31 };
32 
33 struct ReceiverCapability {
34   static constexpr int kRemotingVersionUnknown = -1;
35 
36   Json::Value ToJson() const;
37   static ErrorOr<ReceiverCapability> Parse(const Json::Value& value);
38 
39   // The remoting version that the receiver uses.
40   int remoting_version = kRemotingVersionUnknown;
41 
42   // Set of capabilities (e.g., ac3, 4k, hevc, vp9, dolby_vision, etc.).
43   std::vector<MediaCapability> media_capabilities;
44 };
45 
46 struct ReceiverError {
47   Json::Value ToJson() const;
48   static ErrorOr<ReceiverError> Parse(const Json::Value& value);
49 
50   // Error code.
51   // TODO(issuetracker.google.com/184766188): Error codes should be well
52   // defined.
53   int32_t code = -1;
54 
55   // Error description.
56   std::string description;
57 };
58 
59 struct ReceiverMessage {
60  public:
61   // Receiver response message type.
62   enum class Type {
63     // Unknown message type.
64     kUnknown,
65 
66     // Response to OFFER message.
67     kAnswer,
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::vector<uint8_t>,  // Binary-encoded RPC message.
88                 ReceiverCapability,
89                 ReceiverError>
90       body;
91 };
92 
93 }  // namespace cast
94 }  // namespace openscreen
95 
96 #endif  // CAST_STREAMING_RECEIVER_MESSAGE_H_
97