1*d9f75844SAndroid Build Coastguard Worker /* 2*d9f75844SAndroid Build Coastguard Worker * Copyright (c) 2021 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/vp9_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 // Profile information for VP9 video. 21*d9f75844SAndroid Build Coastguard Worker const char kVP9FmtpProfileId[] = "profile-id"; 22*d9f75844SAndroid Build Coastguard Worker VP9ProfileToString(VP9Profile profile)23*d9f75844SAndroid Build Coastguard Workerstd::string VP9ProfileToString(VP9Profile profile) { 24*d9f75844SAndroid Build Coastguard Worker switch (profile) { 25*d9f75844SAndroid Build Coastguard Worker case VP9Profile::kProfile0: 26*d9f75844SAndroid Build Coastguard Worker return "0"; 27*d9f75844SAndroid Build Coastguard Worker case VP9Profile::kProfile1: 28*d9f75844SAndroid Build Coastguard Worker return "1"; 29*d9f75844SAndroid Build Coastguard Worker case VP9Profile::kProfile2: 30*d9f75844SAndroid Build Coastguard Worker return "2"; 31*d9f75844SAndroid Build Coastguard Worker case VP9Profile::kProfile3: 32*d9f75844SAndroid Build Coastguard Worker return "3"; 33*d9f75844SAndroid Build Coastguard Worker } 34*d9f75844SAndroid Build Coastguard Worker return "0"; 35*d9f75844SAndroid Build Coastguard Worker } 36*d9f75844SAndroid Build Coastguard Worker StringToVP9Profile(const std::string & str)37*d9f75844SAndroid Build Coastguard Workerabsl::optional<VP9Profile> StringToVP9Profile(const std::string& str) { 38*d9f75844SAndroid Build Coastguard Worker const absl::optional<int> i = rtc::StringToNumber<int>(str); 39*d9f75844SAndroid Build Coastguard Worker if (!i.has_value()) 40*d9f75844SAndroid Build Coastguard Worker return absl::nullopt; 41*d9f75844SAndroid Build Coastguard Worker 42*d9f75844SAndroid Build Coastguard Worker switch (i.value()) { 43*d9f75844SAndroid Build Coastguard Worker case 0: 44*d9f75844SAndroid Build Coastguard Worker return VP9Profile::kProfile0; 45*d9f75844SAndroid Build Coastguard Worker case 1: 46*d9f75844SAndroid Build Coastguard Worker return VP9Profile::kProfile1; 47*d9f75844SAndroid Build Coastguard Worker case 2: 48*d9f75844SAndroid Build Coastguard Worker return VP9Profile::kProfile2; 49*d9f75844SAndroid Build Coastguard Worker case 3: 50*d9f75844SAndroid Build Coastguard Worker return VP9Profile::kProfile3; 51*d9f75844SAndroid Build Coastguard Worker default: 52*d9f75844SAndroid Build Coastguard Worker return absl::nullopt; 53*d9f75844SAndroid Build Coastguard Worker } 54*d9f75844SAndroid Build Coastguard Worker } 55*d9f75844SAndroid Build Coastguard Worker ParseSdpForVP9Profile(const SdpVideoFormat::Parameters & params)56*d9f75844SAndroid Build Coastguard Workerabsl::optional<VP9Profile> ParseSdpForVP9Profile( 57*d9f75844SAndroid Build Coastguard Worker const SdpVideoFormat::Parameters& params) { 58*d9f75844SAndroid Build Coastguard Worker const auto profile_it = params.find(kVP9FmtpProfileId); 59*d9f75844SAndroid Build Coastguard Worker if (profile_it == params.end()) 60*d9f75844SAndroid Build Coastguard Worker return VP9Profile::kProfile0; 61*d9f75844SAndroid Build Coastguard Worker const std::string& profile_str = profile_it->second; 62*d9f75844SAndroid Build Coastguard Worker return StringToVP9Profile(profile_str); 63*d9f75844SAndroid Build Coastguard Worker } 64*d9f75844SAndroid Build Coastguard Worker VP9IsSameProfile(const SdpVideoFormat::Parameters & params1,const SdpVideoFormat::Parameters & params2)65*d9f75844SAndroid Build Coastguard Workerbool VP9IsSameProfile(const SdpVideoFormat::Parameters& params1, 66*d9f75844SAndroid Build Coastguard Worker const SdpVideoFormat::Parameters& params2) { 67*d9f75844SAndroid Build Coastguard Worker const absl::optional<VP9Profile> profile = ParseSdpForVP9Profile(params1); 68*d9f75844SAndroid Build Coastguard Worker const absl::optional<VP9Profile> other_profile = 69*d9f75844SAndroid Build Coastguard Worker ParseSdpForVP9Profile(params2); 70*d9f75844SAndroid Build Coastguard Worker return profile && other_profile && profile == other_profile; 71*d9f75844SAndroid Build Coastguard Worker } 72*d9f75844SAndroid Build Coastguard Worker 73*d9f75844SAndroid Build Coastguard Worker } // namespace webrtc 74