1 /* 2 * Copyright (c) 2019 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/sdp_fmtp_utils.h" 12 13 #include <map> 14 #include <utility> 15 16 #include "rtc_base/string_to_number.h" 17 18 namespace webrtc { 19 namespace { 20 // Max frame rate for VP8 and VP9 video. 21 const char kVPxFmtpMaxFrameRate[] = "max-fr"; 22 // Max frame size for VP8 and VP9 video. 23 const char kVPxFmtpMaxFrameSize[] = "max-fs"; 24 const int kVPxFmtpFrameSizeSubBlockPixels = 256; 25 ParsePositiveNumberFromParams(const SdpVideoFormat::Parameters & params,const char * parameter_name)26absl::optional<int> ParsePositiveNumberFromParams( 27 const SdpVideoFormat::Parameters& params, 28 const char* parameter_name) { 29 const auto max_frame_rate_it = params.find(parameter_name); 30 if (max_frame_rate_it == params.end()) 31 return absl::nullopt; 32 33 const absl::optional<int> i = 34 rtc::StringToNumber<int>(max_frame_rate_it->second); 35 if (!i.has_value() || i.value() <= 0) 36 return absl::nullopt; 37 return i; 38 } 39 40 } // namespace 41 ParseSdpForVPxMaxFrameRate(const SdpVideoFormat::Parameters & params)42absl::optional<int> ParseSdpForVPxMaxFrameRate( 43 const SdpVideoFormat::Parameters& params) { 44 return ParsePositiveNumberFromParams(params, kVPxFmtpMaxFrameRate); 45 } 46 ParseSdpForVPxMaxFrameSize(const SdpVideoFormat::Parameters & params)47absl::optional<int> ParseSdpForVPxMaxFrameSize( 48 const SdpVideoFormat::Parameters& params) { 49 const absl::optional<int> i = 50 ParsePositiveNumberFromParams(params, kVPxFmtpMaxFrameSize); 51 return i ? absl::make_optional(i.value() * kVPxFmtpFrameSizeSubBlockPixels) 52 : absl::nullopt; 53 } 54 55 } // namespace webrtc 56