blob: d69f566e1047c53ebbf83a0fa2af13f9061af810 [file] [log] [blame]
Emircan Uysaler98badbc2018-06-28 10:59:02 -07001/*
Johannes Kronc3fcee72021-04-19 09:09:26 +02002 * Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
Emircan Uysaler98badbc2018-06-28 10:59:02 -07003 *
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 Kronc3fcee72021-04-19 09:09:26 +020011#include "api/video_codecs/vp9_profile.h"
Emircan Uysaler98badbc2018-06-28 10:59:02 -070012
Yves Gerey3e707812018-11-28 16:47:49 +010013#include <map>
14#include <utility>
15
Emircan Uysaler98badbc2018-06-28 10:59:02 -070016#include "rtc_base/string_to_number.h"
17
18namespace webrtc {
19
20// Profile information for VP9 video.
Philipp Hancke5526e452018-09-26 09:32:07 +020021const char kVP9FmtpProfileId[] = "profile-id";
Emircan Uysaler98badbc2018-06-28 10:59:02 -070022
23std::string VP9ProfileToString(VP9Profile profile) {
24 switch (profile) {
25 case VP9Profile::kProfile0:
26 return "0";
Johannes Kron7ff63552020-06-11 13:41:06 +020027 case VP9Profile::kProfile1:
28 return "1";
Emircan Uysaler98badbc2018-06-28 10:59:02 -070029 case VP9Profile::kProfile2:
30 return "2";
31 }
32 return "0";
33}
34
35absl::optional<VP9Profile> StringToVP9Profile(const std::string& str) {
36 const absl::optional<int> i = rtc::StringToNumber<int>(str);
37 if (!i.has_value())
38 return absl::nullopt;
39
40 switch (i.value()) {
41 case 0:
42 return VP9Profile::kProfile0;
Johannes Kron7ff63552020-06-11 13:41:06 +020043 case 1:
44 return VP9Profile::kProfile1;
Emircan Uysaler98badbc2018-06-28 10:59:02 -070045 case 2:
46 return VP9Profile::kProfile2;
47 default:
48 return absl::nullopt;
49 }
50 return absl::nullopt;
51}
52
53absl::optional<VP9Profile> ParseSdpForVP9Profile(
54 const SdpVideoFormat::Parameters& params) {
55 const auto profile_it = params.find(kVP9FmtpProfileId);
56 if (profile_it == params.end())
57 return VP9Profile::kProfile0;
58 const std::string& profile_str = profile_it->second;
59 return StringToVP9Profile(profile_str);
60}
61
Johannes Kronc3fcee72021-04-19 09:09:26 +020062bool VP9IsSameProfile(const SdpVideoFormat::Parameters& params1,
Emircan Uysaler98badbc2018-06-28 10:59:02 -070063 const SdpVideoFormat::Parameters& params2) {
Danil Chapovalov065a52a2018-07-09 10:58:54 +020064 const absl::optional<VP9Profile> profile = ParseSdpForVP9Profile(params1);
65 const absl::optional<VP9Profile> other_profile =
Emircan Uysaler98badbc2018-06-28 10:59:02 -070066 ParseSdpForVP9Profile(params2);
67 return profile && other_profile && profile == other_profile;
68}
69
70} // namespace webrtc