xref: /aosp_15_r20/external/webrtc/api/video_codecs/sdp_video_format.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #ifndef API_VIDEO_CODECS_SDP_VIDEO_FORMAT_H_
12 #define API_VIDEO_CODECS_SDP_VIDEO_FORMAT_H_
13 
14 #include <map>
15 #include <string>
16 
17 #include "absl/container/inlined_vector.h"
18 #include "absl/types/optional.h"
19 #include "api/array_view.h"
20 #include "api/video_codecs/scalability_mode.h"
21 #include "rtc_base/system/rtc_export.h"
22 
23 namespace webrtc {
24 
25 // SDP specification for a single video codec.
26 // NOTE: This class is still under development and may change without notice.
27 struct RTC_EXPORT SdpVideoFormat {
28   using Parameters = std::map<std::string, std::string>;
29 
30   explicit SdpVideoFormat(const std::string& name);
31   SdpVideoFormat(const std::string& name, const Parameters& parameters);
32   SdpVideoFormat(
33       const std::string& name,
34       const Parameters& parameters,
35       const absl::InlinedVector<ScalabilityMode, kScalabilityModeCount>&
36           scalability_modes);
37   SdpVideoFormat(const SdpVideoFormat&);
38   SdpVideoFormat(SdpVideoFormat&&);
39   SdpVideoFormat& operator=(const SdpVideoFormat&);
40   SdpVideoFormat& operator=(SdpVideoFormat&&);
41 
42   ~SdpVideoFormat();
43 
44   // Returns true if the SdpVideoFormats have the same names as well as codec
45   // specific parameters. Please note that two SdpVideoFormats can represent the
46   // same codec even though not all parameters are the same.
47   bool IsSameCodec(const SdpVideoFormat& other) const;
48   bool IsCodecInList(
49       rtc::ArrayView<const webrtc::SdpVideoFormat> formats) const;
50 
51   std::string ToString() const;
52 
53   friend RTC_EXPORT bool operator==(const SdpVideoFormat& a,
54                                     const SdpVideoFormat& b);
55   friend RTC_EXPORT bool operator!=(const SdpVideoFormat& a,
56                                     const SdpVideoFormat& b) {
57     return !(a == b);
58   }
59 
60   std::string name;
61   Parameters parameters;
62   absl::InlinedVector<ScalabilityMode, kScalabilityModeCount> scalability_modes;
63 };
64 
65 // For not so good reasons sometimes additional parameters are added to an
66 // SdpVideoFormat, which makes instances that should compare equal to not match
67 // anymore. Until we stop misusing SdpVideoFormats provide this convenience
68 // function to perform fuzzy matching.
69 absl::optional<SdpVideoFormat> FuzzyMatchSdpVideoFormat(
70     rtc::ArrayView<const SdpVideoFormat> supported_formats,
71     const SdpVideoFormat& format);
72 
73 }  // namespace webrtc
74 
75 #endif  // API_VIDEO_CODECS_SDP_VIDEO_FORMAT_H_
76