// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "cast/streaming/public/answer_messages.h" #include <string_view> #include <utility> #include "absl/strings/str_split.h" #include "cast/streaming/public/constants.h" #include "platform/base/error.h" #include "util/enum_name_table.h" #include "util/json/json_helpers.h" #include "util/osp_logging.h" #include "util/string_parse.h" #include "util/stringprintf.h" namespace openscreen::cast { namespace { /// Constraint properties. // Audio constraints. See properties below. static constexpr char kAudio[] = …; // Video constraints. See properties below. static constexpr char kVideo[] = …; // An optional field representing the minimum bits per second. If not specified // by the receiver, the sender will use kDefaultAudioMinBitRate and // kDefaultVideoMinBitRate, which represent the true operational minimum. static constexpr char kMinBitRate[] = …; // Maximum encoded bits per second. This is the lower of (1) the max capability // of the decoder, or (2) the max data transfer rate. static constexpr char kMaxBitRate[] = …; // Maximum supported end-to-end latency, in milliseconds. Proportional to the // size of the data buffers in the receiver. static constexpr char kMaxDelay[] = …; /// Video constraint properties. // Maximum pixel rate (width * height * framerate). Is often less than // multiplying the fields in maxDimensions. This field is used to set the // maximum processing rate. static constexpr char kMaxPixelsPerSecond[] = …; // Minimum dimensions. If omitted, the sender will assume a reasonable minimum // with the same aspect ratio as maxDimensions, as close to 320*180 as possible. // Should reflect the true operational minimum. static constexpr char kMinResolution[] = …; // Maximum dimensions, not necessarily ideal dimensions. static constexpr char kMaxDimensions[] = …; /// Audio constraint properties. // Maximum supported sampling frequency (not necessarily ideal). static constexpr char kMaxSampleRate[] = …; // Maximum number of audio channels (1 is mono, 2 is stereo, etc.). static constexpr char kMaxChannels[] = …; /// Display description properties // If this optional field is included in the ANSWER message, the receiver is // attached to a fixed display that has the given dimensions and frame rate // configuration. These may exceed, be the same, or be less than the values in // constraints. If undefined, we assume the display is not fixed (e.g. a Google // Hangouts UI panel). static constexpr char kDimensions[] = …; // An optional field. When missing and dimensions are specified, the sender // will assume square pixels and the dimensions imply the aspect ratio of the // fixed display. WHen present and dimensions are also specified, implies the // pixels are not square. static constexpr char kAspectRatio[] = …; // The delimeter used for the aspect ratio format ("A:B"). static constexpr char kAspectRatioDelimiter[] = …; // Sets the aspect ratio constraints. Value must be either "sender" or // "receiver", see kScalingSender and kScalingReceiver below. static constexpr char kScaling[] = …; // scaling = "sender" means that the sender must provide video frames of a fixed // aspect ratio. In this case, the dimensions object must be passed or an error // case will occur. static constexpr char kScalingSender[] = …; // scaling = "receiver" means that the sender may send arbitrarily sized frames, // and the receiver will handle scaling and letterboxing as necessary. static constexpr char kScalingReceiver[] = …; /// Answer properties. // A number specifying the UDP port used for all streams in this session. // Must have a value between kUdpPortMin and kUdpPortMax. static constexpr char kUdpPort[] = …; static constexpr int kUdpPortMin = …; static constexpr int kUdpPortMax = …; // Numbers specifying the indexes chosen from the offer message. static constexpr char kSendIndexes[] = …; // uint32_t values specifying the RTP SSRC values used to send the RTCP feedback // of the stream indicated in kSendIndexes. static constexpr char kSsrcs[] = …; // Provides detailed maximum and minimum capabilities of the receiver for // processing the selected streams. The sender may alter video resolution and // frame rate throughout the session, and the constraints here determine how // much data volume is allowed. static constexpr char kConstraints[] = …; // Provides details about the display on the receiver. static constexpr char kDisplay[] = …; // std::optional array of numbers specifying the indexes of streams that will // send event logs through RTCP. static constexpr char kReceiverRtcpEventLog[] = …; // OPtional array of numbers specifying the indexes of streams that will use // DSCP values specified in the OFFER message for RTCP packets. static constexpr char kReceiverRtcpDscp[] = …; // If this optional field is present the receiver supports the specific // RTP extensions (such as adaptive playout delay). static constexpr char kRtpExtensions[] = …; EnumNameTable<AspectRatioConstraint, 2> kAspectRatioConstraintNames{ … }; Json::Value AspectRatioConstraintToJson(AspectRatioConstraint aspect_ratio) { … } bool TryParseAspectRatioConstraint(const Json::Value& value, AspectRatioConstraint* out) { … } template <typename T> bool ParseOptional(const Json::Value& value, std::optional<T>* out) { … } } // namespace // static bool AspectRatio::TryParse(const Json::Value& value, AspectRatio* out) { … } bool AspectRatio::IsValid() const { … } // static bool AudioConstraints::TryParse(const Json::Value& root, AudioConstraints* out) { … } Json::Value AudioConstraints::ToJson() const { … } bool AudioConstraints::IsValid() const { … } // static bool VideoConstraints::TryParse(const Json::Value& root, VideoConstraints* out) { … } bool VideoConstraints::IsValid() const { … } Json::Value VideoConstraints::ToJson() const { … } // static bool Constraints::TryParse(const Json::Value& root, Constraints* out) { … } bool Constraints::IsValid() const { … } Json::Value Constraints::ToJson() const { … } // static bool DisplayDescription::TryParse(const Json::Value& root, DisplayDescription* out) { … } bool DisplayDescription::IsValid() const { … } Json::Value DisplayDescription::ToJson() const { … } bool Answer::TryParse(const Json::Value& root, Answer* out) { … } bool Answer::IsValid() const { … } Json::Value Answer::ToJson() const { … } } // namespace openscreen::cast