xref: /aosp_15_r20/external/openscreen/cast/streaming/constants.h (revision 3f982cf4871df8771c9d4abe6e9a6f8d829b2736)
1 // Copyright 2015 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_CONSTANTS_H_
6 #define CAST_STREAMING_CONSTANTS_H_
7 
8 ////////////////////////////////////////////////////////////////////////////////
9 // NOTE: This file should only contain constants that are reasonably globally
10 // used (i.e., by many modules, and in all or nearly all subdirs).  Do NOT add
11 // non-POD constants, functions, interfaces, or any logic to this module.
12 ////////////////////////////////////////////////////////////////////////////////
13 
14 #include <chrono>
15 #include <ratio>
16 
17 namespace openscreen {
18 namespace cast {
19 
20 // Mirroring App identifier.
21 constexpr char kMirroringAppId[] = "0F5096E8";
22 
23 // Mirroring App identifier for audio-only mirroring.
24 constexpr char kMirroringAudioOnlyAppId[] = "85CDB22F";
25 
26 // Default target playout delay. The playout delay is the window of time between
27 // capture from the source until presentation at the receiver.
28 constexpr std::chrono::milliseconds kDefaultTargetPlayoutDelay(400);
29 
30 // Default UDP port, bound at the Receiver, for Cast Streaming. An
31 // implementation is required to use the port specified by the Receiver in its
32 // ANSWER control message, which may or may not match this port number here.
33 constexpr int kDefaultCastStreamingPort = 2344;
34 
35 // Default TCP port, bound at the TLS server socket level, for Cast Streaming.
36 // An implementation must use the port specified in the DNS-SD published record
37 // for connecting over TLS, which may or may not match this port number here.
38 constexpr int kDefaultCastPort = 8010;
39 
40 // Target number of milliseconds between the sending of RTCP reports.  Both
41 // senders and receivers regularly send RTCP reports to their peer.
42 constexpr std::chrono::milliseconds kRtcpReportInterval(500);
43 
44 // This is an important system-wide constant.  This limits how much history
45 // the implementation must retain in order to process the acknowledgements of
46 // past frames.
47 //
48 // This value is carefully choosen such that it fits in the 8-bits range for
49 // frame IDs. It is also less than half of the full 8-bits range such that
50 // logic can handle wrap around and compare two frame IDs meaningfully.
51 constexpr int kMaxUnackedFrames = 120;
52 
53 // The network must support a packet size of at least this many bytes.
54 constexpr int kRequiredNetworkPacketSize = 256;
55 
56 // The spec declares RTP timestamps must always have a timebase of 90000 ticks
57 // per second for video.
58 constexpr int kRtpVideoTimebase = 90000;
59 
60 // Minimum resolution is 320x240.
61 constexpr int kMinVideoHeight = 240;
62 constexpr int kMinVideoWidth = 320;
63 
64 // The default frame rate for capture options is 30FPS.
65 constexpr int kDefaultFrameRate = 30;
66 
67 // The mirroring spec suggests 300kbps as the absolute minimum bitrate.
68 constexpr int kDefaultVideoMinBitRate = 300 * 1000;
69 
70 // Default video max bitrate is based on 1080P @ 30FPS, which can be played back
71 // at good quality around 10mbps.
72 constexpr int kDefaultVideoMaxBitRate = 10 * 1000 * 1000;
73 
74 // The mirroring control protocol specifies 32kbps as the absolute minimum
75 // for audio. Depending on the type of audio content (narrowband, fullband,
76 // etc.) Opus specifically can perform very well at this bitrate.
77 // See: https://research.google/pubs/pub41650/
78 constexpr int kDefaultAudioMinBitRate = 32 * 1000;
79 
80 // Opus generally sees little improvement above 192kbps, but some older codecs
81 // that we may consider supporting improve at up to 256kbps.
82 constexpr int kDefaultAudioMaxBitRate = 256 * 1000;
83 
84 // While generally audio should be captured at the maximum sample rate, 16kHz is
85 // the recommended absolute minimum.
86 constexpr int kDefaultAudioMinSampleRate = 16000;
87 
88 // The default audio sample rate is 48kHz, slightly higher than standard
89 // consumer audio.
90 constexpr int kDefaultAudioSampleRate = 48000;
91 
92 // The default audio number of channels is set to stereo.
93 constexpr int kDefaultAudioChannels = 2;
94 
95 // Default maximum delay for both audio and video. Used if the sender fails
96 // to provide any constraints.
97 constexpr std::chrono::milliseconds kDefaultMaxDelayMs(1500);
98 
99 // TODO(issuetracker.google.com/184189100): As part of updating remoting
100 // OFFER/ANSWER and capabilities exchange, remoting version should be updated
101 // to 3.
102 constexpr int kSupportedRemotingVersion = 2;
103 
104 // Codecs known and understood by cast senders and receivers. Note: receivers
105 // are required to implement the following codecs to be Cast V2 compliant: H264,
106 // VP8, AAC, Opus. Senders have to implement at least one codec from this
107 // list for audio or video to start a session.
108 // |kNotSpecified| is used in remoting to indicate that the stream is being
109 // remoted and is not specified as part of the OFFER message (indicated as
110 // "REMOTE_AUDIO" or "REMOTE_VIDEO").
111 enum class AudioCodec { kAac, kOpus, kNotSpecified };
112 enum class VideoCodec { kH264, kVp8, kHevc, kNotSpecified, kVp9, kAv1 };
113 
114 enum class CastMode : uint8_t { kMirroring, kRemoting };
115 
116 }  // namespace cast
117 }  // namespace openscreen
118 
119 #endif  // CAST_STREAMING_CONSTANTS_H_
120