tor-browser

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

h264_profile_level_id.h (3228B)


      1 /*
      2 *  Copyright (c) 2021 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_H264_PROFILE_LEVEL_ID_H_
     12 #define API_VIDEO_CODECS_H264_PROFILE_LEVEL_ID_H_
     13 
     14 #include <optional>
     15 #include <string>
     16 
     17 #include "api/rtp_parameters.h"
     18 #include "rtc_base/system/rtc_export.h"
     19 
     20 namespace webrtc {
     21 
     22 enum class H264Profile {
     23  kProfileConstrainedBaseline,
     24  kProfileBaseline,
     25  kProfileMain,
     26  kProfileConstrainedHigh,
     27  kProfileHigh,
     28  kProfilePredictiveHigh444,
     29 };
     30 
     31 // All values are equal to ten times the level number, except level 1b which is
     32 // special.
     33 enum class H264Level {
     34  kLevel1_b = 0,
     35  kLevel1 = 10,
     36  kLevel1_1 = 11,
     37  kLevel1_2 = 12,
     38  kLevel1_3 = 13,
     39  kLevel2 = 20,
     40  kLevel2_1 = 21,
     41  kLevel2_2 = 22,
     42  kLevel3 = 30,
     43  kLevel3_1 = 31,
     44  kLevel3_2 = 32,
     45  kLevel4 = 40,
     46  kLevel4_1 = 41,
     47  kLevel4_2 = 42,
     48  kLevel5 = 50,
     49  kLevel5_1 = 51,
     50  kLevel5_2 = 52
     51 };
     52 
     53 struct H264ProfileLevelId {
     54  constexpr H264ProfileLevelId(H264Profile profile, H264Level level)
     55      : profile(profile), level(level) {}
     56  H264Profile profile;
     57  H264Level level;
     58 };
     59 
     60 // Parse profile level id that is represented as a string of 3 hex bytes.
     61 // Nothing will be returned if the string is not a recognized H264
     62 // profile level id.
     63 std::optional<H264ProfileLevelId> ParseH264ProfileLevelId(const char* str);
     64 
     65 // Parse profile level id that is represented as a string of 3 hex bytes
     66 // contained in an SDP key-value map. A default profile level id will be
     67 // returned if the profile-level-id key is missing. Nothing will be returned if
     68 // the key is present but the string is invalid.
     69 RTC_EXPORT std::optional<H264ProfileLevelId> ParseSdpForH264ProfileLevelId(
     70    const CodecParameterMap& params);
     71 
     72 // Given that a decoder supports up to a given frame size (in pixels) at up to a
     73 // given number of frames per second, return the highest H.264 level where it
     74 // can guarantee that it will be able to support all valid encoded streams that
     75 // are within that level.
     76 RTC_EXPORT std::optional<H264Level> H264SupportedLevel(
     77    int max_frame_pixel_count,
     78    float max_fps);
     79 
     80 // Returns canonical string representation as three hex bytes of the profile
     81 // level id, or returns nothing for invalid profile level ids.
     82 RTC_EXPORT std::optional<std::string> H264ProfileLevelIdToString(
     83    const H264ProfileLevelId& profile_level_id);
     84 
     85 // Returns true if the parameters have the same H264 profile (Baseline, High,
     86 // etc).
     87 RTC_EXPORT bool H264IsSameProfile(const CodecParameterMap& params1,
     88                                  const CodecParameterMap& params2);
     89 // Returns true if the parameters have the same H264 profile (Baseline, High,
     90 // etc) and same level.
     91 RTC_EXPORT bool H264IsSameProfileAndLevel(const CodecParameterMap& params1,
     92                                          const CodecParameterMap& params2);
     93 
     94 }  // namespace webrtc
     95 
     96 #endif  // API_VIDEO_CODECS_H264_PROFILE_LEVEL_ID_H_