av1_profile.cc (2000B)
1 /* 2 * Copyright (c) 2022 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 #include "api/video_codecs/av1_profile.h" 12 13 #include <map> 14 #include <optional> 15 #include <string> 16 17 #include "absl/strings/string_view.h" 18 #include "api/rtp_parameters.h" 19 #include "media/base/media_constants.h" 20 #include "rtc_base/string_to_number.h" 21 22 namespace webrtc { 23 24 absl::string_view AV1ProfileToString(AV1Profile profile) { 25 switch (profile) { 26 case AV1Profile::kProfile0: 27 return "0"; 28 case AV1Profile::kProfile1: 29 return "1"; 30 case AV1Profile::kProfile2: 31 return "2"; 32 } 33 return "0"; 34 } 35 36 std::optional<AV1Profile> StringToAV1Profile(absl::string_view str) { 37 const std::optional<int> i = StringToNumber<int>(str); 38 if (!i.has_value()) 39 return std::nullopt; 40 41 switch (i.value()) { 42 case 0: 43 return AV1Profile::kProfile0; 44 case 1: 45 return AV1Profile::kProfile1; 46 case 2: 47 return AV1Profile::kProfile2; 48 default: 49 return std::nullopt; 50 } 51 } 52 53 std::optional<AV1Profile> ParseSdpForAV1Profile( 54 const CodecParameterMap& params) { 55 const auto profile_it = params.find(kAv1FmtpProfile); 56 if (profile_it == params.end()) 57 return AV1Profile::kProfile0; 58 const std::string& profile_str = profile_it->second; 59 return StringToAV1Profile(profile_str); 60 } 61 62 bool AV1IsSameProfile(const CodecParameterMap& params1, 63 const CodecParameterMap& params2) { 64 const std::optional<AV1Profile> profile = ParseSdpForAV1Profile(params1); 65 const std::optional<AV1Profile> other_profile = 66 ParseSdpForAV1Profile(params2); 67 return profile && other_profile && profile == other_profile; 68 } 69 70 } // namespace webrtc