• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_STREAMING_OFFER_MESSAGES_H_
6 #define CAST_STREAMING_OFFER_MESSAGES_H_
7 
8 #include <chrono>
9 #include <string>
10 #include <vector>
11 
12 #include "absl/strings/string_view.h"
13 #include "absl/types/optional.h"
14 #include "cast/streaming/message_fields.h"
15 #include "cast/streaming/rtp_defines.h"
16 #include "cast/streaming/session_config.h"
17 #include "json/value.h"
18 #include "platform/base/error.h"
19 #include "util/simple_fraction.h"
20 
21 // This file contains the implementation of the Cast V2 Mirroring Control
22 // Protocol offer object definition.
23 namespace openscreen {
24 namespace cast {
25 
26 // If the target delay provided by the sender is not bounded by
27 // [kMinTargetDelay, kMaxTargetDelay], it will be set to
28 // kDefaultTargetPlayoutDelay.
29 constexpr auto kMinTargetPlayoutDelay = std::chrono::milliseconds(0);
30 constexpr auto kMaxTargetPlayoutDelay = std::chrono::milliseconds(5000);
31 
32 // If the sender provides an invalid maximum frame rate, it ill
33 // be set to kDefaultMaxFrameRate.
34 constexpr int kDefaultMaxFrameRate = 30;
35 
36 constexpr int kDefaultNumVideoChannels = 1;
37 constexpr int kDefaultNumAudioChannels = 2;
38 
39 // A stream, as detailed by the CastV2 protocol spec, is a segment of an
40 // offer message specifically representing a configuration object for
41 // a codec and its related fields, such as maximum bit rate, time base,
42 // and other fields.
43 // Composed classes include AudioStream and VideoStream, which contain
44 // fields specific to audio and video respectively.
45 struct Stream {
46   enum class Type : uint8_t { kAudioSource, kVideoSource };
47 
48   ErrorOr<Json::Value> ToJson() const;
49 
50   int index = 0;
51   Type type = {};
52 
53   // Default channel count is 1, e.g. for video.
54   int channels = 0;
55   RtpPayloadType rtp_payload_type = {};
56   Ssrc ssrc = {};
57   std::chrono::milliseconds target_delay = {};
58 
59   // AES Key and IV mask format is very strict: a 32 digit hex string that
60   // must be converted to a 16 digit byte array.
61   std::array<uint8_t, 16> aes_key = {};
62   std::array<uint8_t, 16> aes_iv_mask = {};
63   bool receiver_rtcp_event_log = {};
64   std::string receiver_rtcp_dscp = {};
65   int rtp_timebase = 0;
66 };
67 
68 struct AudioStream {
69   ErrorOr<Json::Value> ToJson() const;
70 
71   Stream stream = {};
72   AudioCodec codec;
73   int bit_rate = 0;
74 };
75 
76 struct Resolution {
77   ErrorOr<Json::Value> ToJson() const;
78 
79   int width = 0;
80   int height = 0;
81 };
82 
83 struct VideoStream {
84   ErrorOr<Json::Value> ToJson() const;
85 
86   Stream stream = {};
87   VideoCodec codec;
88   SimpleFraction max_frame_rate;
89   int max_bit_rate = 0;
90   std::string protection = {};
91   std::string profile = {};
92   std::string level = {};
93   std::vector<Resolution> resolutions = {};
94   std::string error_recovery_mode = {};
95 };
96 
97 enum class CastMode : uint8_t { kMirroring, kRemoting };
98 
99 struct Offer {
100   static ErrorOr<Offer> Parse(const Json::Value& root);
101   ErrorOr<Json::Value> ToJson() const;
102 
103   CastMode cast_mode = CastMode::kMirroring;
104   // This field is poorly named in the spec (receiverGetStatus), so we use
105   // a more descriptive name here.
106   bool supports_wifi_status_reporting = {};
107   std::vector<AudioStream> audio_streams = {};
108   std::vector<VideoStream> video_streams = {};
109 };
110 
111 }  // namespace cast
112 }  // namespace openscreen
113 
114 #endif  // CAST_STREAMING_OFFER_MESSAGES_H_
115