Emircan Uysaler | 98badbc | 2018-06-28 10:59:02 -0700 | [diff] [blame] | 1 | /* |
Johannes Kron | c3fcee7 | 2021-04-19 09:09:26 +0200 | [diff] [blame] | 2 | * Copyright (c) 2021 The WebRTC project authors. All Rights Reserved. |
Emircan Uysaler | 98badbc | 2018-06-28 10:59:02 -0700 | [diff] [blame] | 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 | |
Johannes Kron | c3fcee7 | 2021-04-19 09:09:26 +0200 | [diff] [blame] | 11 | #include "api/video_codecs/vp9_profile.h" |
Emircan Uysaler | 98badbc | 2018-06-28 10:59:02 -0700 | [diff] [blame] | 12 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 13 | #include <map> |
| 14 | #include <utility> |
| 15 | |
Emircan Uysaler | 98badbc | 2018-06-28 10:59:02 -0700 | [diff] [blame] | 16 | #include "rtc_base/string_to_number.h" |
| 17 | |
| 18 | namespace webrtc { |
| 19 | |
| 20 | // Profile information for VP9 video. |
Philipp Hancke | 5526e45 | 2018-09-26 09:32:07 +0200 | [diff] [blame] | 21 | const char kVP9FmtpProfileId[] = "profile-id"; |
Emircan Uysaler | 98badbc | 2018-06-28 10:59:02 -0700 | [diff] [blame] | 22 | |
| 23 | std::string VP9ProfileToString(VP9Profile profile) { |
| 24 | switch (profile) { |
| 25 | case VP9Profile::kProfile0: |
| 26 | return "0"; |
Johannes Kron | 7ff6355 | 2020-06-11 13:41:06 +0200 | [diff] [blame] | 27 | case VP9Profile::kProfile1: |
| 28 | return "1"; |
Emircan Uysaler | 98badbc | 2018-06-28 10:59:02 -0700 | [diff] [blame] | 29 | case VP9Profile::kProfile2: |
| 30 | return "2"; |
Sergio Garcia Murillo | 179f40e | 2022-06-22 14:42:48 +0200 | [diff] [blame] | 31 | case VP9Profile::kProfile3: |
| 32 | return "3"; |
Emircan Uysaler | 98badbc | 2018-06-28 10:59:02 -0700 | [diff] [blame] | 33 | } |
| 34 | return "0"; |
| 35 | } |
| 36 | |
| 37 | absl::optional<VP9Profile> StringToVP9Profile(const std::string& str) { |
| 38 | const absl::optional<int> i = rtc::StringToNumber<int>(str); |
| 39 | if (!i.has_value()) |
| 40 | return absl::nullopt; |
| 41 | |
| 42 | switch (i.value()) { |
| 43 | case 0: |
| 44 | return VP9Profile::kProfile0; |
Johannes Kron | 7ff6355 | 2020-06-11 13:41:06 +0200 | [diff] [blame] | 45 | case 1: |
| 46 | return VP9Profile::kProfile1; |
Emircan Uysaler | 98badbc | 2018-06-28 10:59:02 -0700 | [diff] [blame] | 47 | case 2: |
| 48 | return VP9Profile::kProfile2; |
Sergio Garcia Murillo | 179f40e | 2022-06-22 14:42:48 +0200 | [diff] [blame] | 49 | case 3: |
| 50 | return VP9Profile::kProfile3; |
Emircan Uysaler | 98badbc | 2018-06-28 10:59:02 -0700 | [diff] [blame] | 51 | default: |
| 52 | return absl::nullopt; |
| 53 | } |
Emircan Uysaler | 98badbc | 2018-06-28 10:59:02 -0700 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | absl::optional<VP9Profile> ParseSdpForVP9Profile( |
| 57 | const SdpVideoFormat::Parameters& params) { |
| 58 | const auto profile_it = params.find(kVP9FmtpProfileId); |
| 59 | if (profile_it == params.end()) |
| 60 | return VP9Profile::kProfile0; |
| 61 | const std::string& profile_str = profile_it->second; |
| 62 | return StringToVP9Profile(profile_str); |
| 63 | } |
| 64 | |
Johannes Kron | c3fcee7 | 2021-04-19 09:09:26 +0200 | [diff] [blame] | 65 | bool VP9IsSameProfile(const SdpVideoFormat::Parameters& params1, |
Emircan Uysaler | 98badbc | 2018-06-28 10:59:02 -0700 | [diff] [blame] | 66 | const SdpVideoFormat::Parameters& params2) { |
Danil Chapovalov | 065a52a | 2018-07-09 10:58:54 +0200 | [diff] [blame] | 67 | const absl::optional<VP9Profile> profile = ParseSdpForVP9Profile(params1); |
| 68 | const absl::optional<VP9Profile> other_profile = |
Emircan Uysaler | 98badbc | 2018-06-28 10:59:02 -0700 | [diff] [blame] | 69 | ParseSdpForVP9Profile(params2); |
| 70 | return profile && other_profile && profile == other_profile; |
| 71 | } |
| 72 | |
| 73 | } // namespace webrtc |