vp9_profile.cc (2103B)
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 #include "api/video_codecs/vp9_profile.h" 12 13 #include <map> 14 #include <optional> 15 #include <string> 16 17 #include "api/rtp_parameters.h" 18 #include "rtc_base/string_to_number.h" 19 20 namespace webrtc { 21 22 // Profile information for VP9 video. 23 const char kVP9FmtpProfileId[] = "profile-id"; 24 25 std::string VP9ProfileToString(VP9Profile profile) { 26 switch (profile) { 27 case VP9Profile::kProfile0: 28 return "0"; 29 case VP9Profile::kProfile1: 30 return "1"; 31 case VP9Profile::kProfile2: 32 return "2"; 33 case VP9Profile::kProfile3: 34 return "3"; 35 } 36 return "0"; 37 } 38 39 std::optional<VP9Profile> StringToVP9Profile(const std::string& str) { 40 const std::optional<int> i = StringToNumber<int>(str); 41 if (!i.has_value()) 42 return std::nullopt; 43 44 switch (i.value()) { 45 case 0: 46 return VP9Profile::kProfile0; 47 case 1: 48 return VP9Profile::kProfile1; 49 case 2: 50 return VP9Profile::kProfile2; 51 case 3: 52 return VP9Profile::kProfile3; 53 default: 54 return std::nullopt; 55 } 56 } 57 58 std::optional<VP9Profile> ParseSdpForVP9Profile( 59 const CodecParameterMap& params) { 60 const auto profile_it = params.find(kVP9FmtpProfileId); 61 if (profile_it == params.end()) 62 return VP9Profile::kProfile0; 63 const std::string& profile_str = profile_it->second; 64 return StringToVP9Profile(profile_str); 65 } 66 67 bool VP9IsSameProfile(const CodecParameterMap& params1, 68 const CodecParameterMap& params2) { 69 const std::optional<VP9Profile> profile = ParseSdpForVP9Profile(params1); 70 const std::optional<VP9Profile> other_profile = 71 ParseSdpForVP9Profile(params2); 72 return profile && other_profile && profile == other_profile; 73 } 74 75 } // namespace webrtc