tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

h265_profile_tier_level.h (4480B)


      1 /*
      2 *  Copyright (c) 2023 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_H265_PROFILE_TIER_LEVEL_H_
     12 #define API_VIDEO_CODECS_H265_PROFILE_TIER_LEVEL_H_
     13 
     14 #include <optional>
     15 #include <string>
     16 
     17 #include "api/rtp_parameters.h"
     18 #include "api/video/resolution.h"
     19 #include "rtc_base/system/rtc_export.h"
     20 
     21 namespace webrtc {
     22 
     23 // Profiles can be found at:
     24 // https://www.itu.int/rec/T-REC-H.265
     25 // The enum values match the number specified in the SDP.
     26 enum class H265Profile {
     27  kProfileMain = 1,
     28  kProfileMain10 = 2,
     29  kProfileMainStill = 3,
     30  kProfileRangeExtensions = 4,
     31  kProfileHighThroughput = 5,
     32  kProfileMultiviewMain = 6,
     33  kProfileScalableMain = 7,
     34  kProfile3dMain = 8,
     35  kProfileScreenContentCoding = 9,
     36  kProfileScalableRangeExtensions = 10,
     37  kProfileHighThroughputScreenContentCoding = 11,
     38 };
     39 
     40 // Tiers can be found at https://www.itu.int/rec/T-REC-H.265
     41 enum class H265Tier {
     42  kTier0,
     43  kTier1,
     44 };
     45 
     46 // All values are equal to 30 times the level number.
     47 enum class H265Level {
     48  kLevel1 = 30,
     49  kLevel2 = 60,
     50  kLevel2_1 = 63,
     51  kLevel3 = 90,
     52  kLevel3_1 = 93,
     53  kLevel4 = 120,
     54  kLevel4_1 = 123,
     55  kLevel5 = 150,
     56  kLevel5_1 = 153,
     57  kLevel5_2 = 156,
     58  kLevel6 = 180,
     59  kLevel6_1 = 183,
     60  kLevel6_2 = 186,
     61 };
     62 
     63 struct H265ProfileTierLevel {
     64  constexpr H265ProfileTierLevel(H265Profile profile,
     65                                 H265Tier tier,
     66                                 H265Level level)
     67      : profile(profile), tier(tier), level(level) {}
     68  H265Profile profile;
     69  H265Tier tier;
     70  H265Level level;
     71 };
     72 
     73 // Helper function to convert H265Profile to std::string.
     74 RTC_EXPORT std::string H265ProfileToString(H265Profile profile);
     75 
     76 // Helper function to convert H265Tier to std::string.
     77 RTC_EXPORT std::string H265TierToString(H265Tier tier);
     78 
     79 // Helper function to convert H265Level to std::string.
     80 RTC_EXPORT std::string H265LevelToString(H265Level level);
     81 
     82 // Helper function to get H265Profile from profile string.
     83 RTC_EXPORT std::optional<H265Profile> StringToH265Profile(
     84    const std::string& profile);
     85 
     86 // Helper function to get H265Tier from tier string.
     87 RTC_EXPORT std::optional<H265Tier> StringToH265Tier(const std::string& tier);
     88 
     89 // Helper function to get H265Level from level string.
     90 RTC_EXPORT std::optional<H265Level> StringToH265Level(const std::string& level);
     91 
     92 // Given that a decoder supports up to a give frame size(in pixels) at up to a
     93 // given number of frames per second, return the highest H.265 level where it
     94 // can guranatee that it will be able to support all valid encoded streams that
     95 // are within that level.
     96 RTC_EXPORT std::optional<H265Level> GetSupportedH265Level(
     97    const Resolution& resolution,
     98    float max_fps);
     99 
    100 // Parses an SDP key-value map of format parameters to retrive an H265
    101 // profile/tier/level. Returns an H265ProfileTierlevel by setting its
    102 // members. profile defaults to `kProfileMain` if no profile-id is specified.
    103 // tier defaults to "kTier0" if no tier-flag is specified.
    104 // level defaults to "kLevel3_1" if no level-id is specified.
    105 // Returns empty value if any of the profile/tier/level key is present but
    106 // contains an invalid value.
    107 RTC_EXPORT std::optional<H265ProfileTierLevel> ParseSdpForH265ProfileTierLevel(
    108    const CodecParameterMap& params);
    109 
    110 // Returns true if the parameters have the same H265 profile/tier/level or
    111 // neither contains an H265 profile/tier/level, otherwise false.
    112 RTC_EXPORT bool H265IsSameProfileTierLevel(const CodecParameterMap& params1,
    113                                           const CodecParameterMap& params2);
    114 
    115 // Returns true if the parameters have the same H265 profile, or neither
    116 // contains an H265 profile, otherwise false.
    117 RTC_EXPORT bool H265IsSameProfile(const CodecParameterMap& params1,
    118                                  const CodecParameterMap& params2);
    119 
    120 // Returns true if the parameters have the same H265 tier, or neither
    121 // contains an H265 tier, otherwise false.
    122 RTC_EXPORT bool H265IsSameTier(const CodecParameterMap& params1,
    123                               const CodecParameterMap& params2);
    124 
    125 }  // namespace webrtc
    126 
    127 #endif  // API_VIDEO_CODECS_H265_PROFILE_TIER_LEVEL_H_