1*d9f75844SAndroid Build Coastguard Worker /* 2*d9f75844SAndroid Build Coastguard Worker * Copyright (c) 2022 The WebRTC project authors. All Rights Reserved. 3*d9f75844SAndroid Build Coastguard Worker * 4*d9f75844SAndroid Build Coastguard Worker * Use of this source code is governed by a BSD-style license 5*d9f75844SAndroid Build Coastguard Worker * that can be found in the LICENSE file in the root of the source 6*d9f75844SAndroid Build Coastguard Worker * tree. An additional intellectual property rights grant can be found 7*d9f75844SAndroid Build Coastguard Worker * in the file PATENTS. All contributing project authors may 8*d9f75844SAndroid Build Coastguard Worker * be found in the AUTHORS file in the root of the source tree. 9*d9f75844SAndroid Build Coastguard Worker */ 10*d9f75844SAndroid Build Coastguard Worker 11*d9f75844SAndroid Build Coastguard Worker #include "api/video_codecs/av1_profile.h" 12*d9f75844SAndroid Build Coastguard Worker 13*d9f75844SAndroid Build Coastguard Worker #include <map> 14*d9f75844SAndroid Build Coastguard Worker #include <utility> 15*d9f75844SAndroid Build Coastguard Worker 16*d9f75844SAndroid Build Coastguard Worker #include "rtc_base/string_to_number.h" 17*d9f75844SAndroid Build Coastguard Worker 18*d9f75844SAndroid Build Coastguard Worker namespace webrtc { 19*d9f75844SAndroid Build Coastguard Worker 20*d9f75844SAndroid Build Coastguard Worker // Parameter name in the format parameter map for AV1 video. 21*d9f75844SAndroid Build Coastguard Worker const char kAV1FmtpProfile[] = "profile"; 22*d9f75844SAndroid Build Coastguard Worker AV1ProfileToString(AV1Profile profile)23*d9f75844SAndroid Build Coastguard Workerabsl::string_view AV1ProfileToString(AV1Profile profile) { 24*d9f75844SAndroid Build Coastguard Worker switch (profile) { 25*d9f75844SAndroid Build Coastguard Worker case AV1Profile::kProfile0: 26*d9f75844SAndroid Build Coastguard Worker return "0"; 27*d9f75844SAndroid Build Coastguard Worker case AV1Profile::kProfile1: 28*d9f75844SAndroid Build Coastguard Worker return "1"; 29*d9f75844SAndroid Build Coastguard Worker case AV1Profile::kProfile2: 30*d9f75844SAndroid Build Coastguard Worker return "2"; 31*d9f75844SAndroid Build Coastguard Worker } 32*d9f75844SAndroid Build Coastguard Worker return "0"; 33*d9f75844SAndroid Build Coastguard Worker } 34*d9f75844SAndroid Build Coastguard Worker StringToAV1Profile(absl::string_view str)35*d9f75844SAndroid Build Coastguard Workerabsl::optional<AV1Profile> StringToAV1Profile(absl::string_view str) { 36*d9f75844SAndroid Build Coastguard Worker const absl::optional<int> i = rtc::StringToNumber<int>(str); 37*d9f75844SAndroid Build Coastguard Worker if (!i.has_value()) 38*d9f75844SAndroid Build Coastguard Worker return absl::nullopt; 39*d9f75844SAndroid Build Coastguard Worker 40*d9f75844SAndroid Build Coastguard Worker switch (i.value()) { 41*d9f75844SAndroid Build Coastguard Worker case 0: 42*d9f75844SAndroid Build Coastguard Worker return AV1Profile::kProfile0; 43*d9f75844SAndroid Build Coastguard Worker case 1: 44*d9f75844SAndroid Build Coastguard Worker return AV1Profile::kProfile1; 45*d9f75844SAndroid Build Coastguard Worker case 2: 46*d9f75844SAndroid Build Coastguard Worker return AV1Profile::kProfile2; 47*d9f75844SAndroid Build Coastguard Worker default: 48*d9f75844SAndroid Build Coastguard Worker return absl::nullopt; 49*d9f75844SAndroid Build Coastguard Worker } 50*d9f75844SAndroid Build Coastguard Worker } 51*d9f75844SAndroid Build Coastguard Worker ParseSdpForAV1Profile(const SdpVideoFormat::Parameters & params)52*d9f75844SAndroid Build Coastguard Workerabsl::optional<AV1Profile> ParseSdpForAV1Profile( 53*d9f75844SAndroid Build Coastguard Worker const SdpVideoFormat::Parameters& params) { 54*d9f75844SAndroid Build Coastguard Worker const auto profile_it = params.find(kAV1FmtpProfile); 55*d9f75844SAndroid Build Coastguard Worker if (profile_it == params.end()) 56*d9f75844SAndroid Build Coastguard Worker return AV1Profile::kProfile0; 57*d9f75844SAndroid Build Coastguard Worker const std::string& profile_str = profile_it->second; 58*d9f75844SAndroid Build Coastguard Worker return StringToAV1Profile(profile_str); 59*d9f75844SAndroid Build Coastguard Worker } 60*d9f75844SAndroid Build Coastguard Worker AV1IsSameProfile(const SdpVideoFormat::Parameters & params1,const SdpVideoFormat::Parameters & params2)61*d9f75844SAndroid Build Coastguard Workerbool AV1IsSameProfile(const SdpVideoFormat::Parameters& params1, 62*d9f75844SAndroid Build Coastguard Worker const SdpVideoFormat::Parameters& params2) { 63*d9f75844SAndroid Build Coastguard Worker const absl::optional<AV1Profile> profile = ParseSdpForAV1Profile(params1); 64*d9f75844SAndroid Build Coastguard Worker const absl::optional<AV1Profile> other_profile = 65*d9f75844SAndroid Build Coastguard Worker ParseSdpForAV1Profile(params2); 66*d9f75844SAndroid Build Coastguard Worker return profile && other_profile && profile == other_profile; 67*d9f75844SAndroid Build Coastguard Worker } 68*d9f75844SAndroid Build Coastguard Worker 69*d9f75844SAndroid Build Coastguard Worker } // namespace webrtc 70