blob: a28a912762a729e62796740aeb84815c3b991c2a [file] [log] [blame]
Emircan Uysaler98badbc2018-06-28 10:59:02 -07001/*
2 * Copyright (c) 2018 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 "media/base/vp9_profile.h"
12
13#include "rtc_base/string_to_number.h"
14
15namespace webrtc {
16
17// Profile information for VP9 video.
18const char kVP9FmtpProfileId[] = "x-google-profile-id";
19
20std::string VP9ProfileToString(VP9Profile profile) {
21 switch (profile) {
22 case VP9Profile::kProfile0:
23 return "0";
24 case VP9Profile::kProfile2:
25 return "2";
26 }
27 return "0";
28}
29
30absl::optional<VP9Profile> StringToVP9Profile(const std::string& str) {
31 const absl::optional<int> i = rtc::StringToNumber<int>(str);
32 if (!i.has_value())
33 return absl::nullopt;
34
35 switch (i.value()) {
36 case 0:
37 return VP9Profile::kProfile0;
38 case 2:
39 return VP9Profile::kProfile2;
40 default:
41 return absl::nullopt;
42 }
43 return absl::nullopt;
44}
45
46absl::optional<VP9Profile> ParseSdpForVP9Profile(
47 const SdpVideoFormat::Parameters& params) {
48 const auto profile_it = params.find(kVP9FmtpProfileId);
49 if (profile_it == params.end())
50 return VP9Profile::kProfile0;
51 const std::string& profile_str = profile_it->second;
52 return StringToVP9Profile(profile_str);
53}
54
55bool IsSameVP9Profile(const SdpVideoFormat::Parameters& params1,
56 const SdpVideoFormat::Parameters& params2) {
Danil Chapovalov6f5b0f92018-07-09 10:58:54 +020057 const absl::optional<VP9Profile> profile = ParseSdpForVP9Profile(params1);
58 const absl::optional<VP9Profile> other_profile =
Emircan Uysaler98badbc2018-06-28 10:59:02 -070059 ParseSdpForVP9Profile(params2);
60 return profile && other_profile && profile == other_profile;
61}
62
63} // namespace webrtc