jlmiller@webrtc.org | 5f93d0a | 2015-01-20 21:36:13 +0000 | [diff] [blame] | 1 | /* |
kjellander | 1afca73 | 2016-02-07 20:46:45 -0800 | [diff] [blame] | 2 | * Copyright (c) 2004 The WebRTC project authors. All Rights Reserved. |
jlmiller@webrtc.org | 5f93d0a | 2015-01-20 21:36:13 +0000 | [diff] [blame] | 3 | * |
kjellander | 1afca73 | 2016-02-07 20:46:45 -0800 | [diff] [blame] | 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. |
jlmiller@webrtc.org | 5f93d0a | 2015-01-20 21:36:13 +0000 | [diff] [blame] | 9 | */ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "media/base/mediaengine.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 12 | |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 13 | namespace cricket { |
| 14 | |
Paulina Hensman | 11b34f4 | 2018-04-09 14:24:52 +0200 | [diff] [blame] | 15 | RtpCapabilities::RtpCapabilities() = default; |
| 16 | RtpCapabilities::~RtpCapabilities() = default; |
| 17 | |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 18 | webrtc::RtpParameters CreateRtpParametersWithOneEncoding() { |
| 19 | webrtc::RtpParameters parameters; |
| 20 | webrtc::RtpEncodingParameters encoding; |
| 21 | parameters.encodings.push_back(encoding); |
| 22 | return parameters; |
| 23 | } |
| 24 | |
Zach Stein | 3ca452b | 2018-01-18 10:01:24 -0800 | [diff] [blame] | 25 | webrtc::RtpParameters CreateRtpParametersWithEncodings(StreamParams sp) { |
| 26 | std::vector<uint32_t> primary_ssrcs; |
| 27 | sp.GetPrimarySsrcs(&primary_ssrcs); |
| 28 | size_t encoding_count = primary_ssrcs.size(); |
| 29 | |
| 30 | std::vector<webrtc::RtpEncodingParameters> encodings(encoding_count); |
| 31 | for (size_t i = 0; i < encodings.size(); ++i) { |
| 32 | encodings[i].ssrc = primary_ssrcs[i]; |
| 33 | } |
| 34 | webrtc::RtpParameters parameters; |
| 35 | parameters.encodings = encodings; |
Florent Castelli | dacec71 | 2018-05-24 16:24:21 +0200 | [diff] [blame] | 36 | parameters.rtcp.cname = sp.cname; |
Zach Stein | 3ca452b | 2018-01-18 10:01:24 -0800 | [diff] [blame] | 37 | return parameters; |
| 38 | } |
| 39 | |
Florent Castelli | 892acf0 | 2018-10-01 22:47:20 +0200 | [diff] [blame^] | 40 | webrtc::RTCError ValidateRtpParameters( |
| 41 | const webrtc::RtpParameters& old_rtp_parameters, |
| 42 | const webrtc::RtpParameters& rtp_parameters) { |
| 43 | using webrtc::RTCErrorType; |
| 44 | if (rtp_parameters.encodings.size() != old_rtp_parameters.encodings.size()) { |
| 45 | LOG_AND_RETURN_ERROR( |
| 46 | RTCErrorType::INVALID_MODIFICATION, |
| 47 | "Attempted to set RtpParameters with different encoding count"); |
| 48 | } |
| 49 | if (rtp_parameters.rtcp != old_rtp_parameters.rtcp) { |
| 50 | LOG_AND_RETURN_ERROR( |
| 51 | RTCErrorType::INVALID_MODIFICATION, |
| 52 | "Attempted to set RtpParameters with modified RTCP parameters"); |
| 53 | } |
| 54 | if (rtp_parameters.header_extensions != |
| 55 | old_rtp_parameters.header_extensions) { |
| 56 | LOG_AND_RETURN_ERROR( |
| 57 | RTCErrorType::INVALID_MODIFICATION, |
| 58 | "Attempted to set RtpParameters with modified header extensions"); |
| 59 | } |
| 60 | |
| 61 | for (size_t i = 0; i < rtp_parameters.encodings.size(); ++i) { |
| 62 | if (rtp_parameters.encodings[i].ssrc != |
| 63 | old_rtp_parameters.encodings[i].ssrc) { |
| 64 | LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_MODIFICATION, |
| 65 | "Attempted to set RtpParameters with modified SSRC"); |
| 66 | } |
| 67 | if (rtp_parameters.encodings[i].bitrate_priority <= 0) { |
| 68 | LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_RANGE, |
| 69 | "Attempted to set RtpParameters bitrate_priority to " |
| 70 | "an invalid number. bitrate_priority must be > 0."); |
| 71 | } |
| 72 | |
| 73 | if (rtp_parameters.encodings[i].min_bitrate_bps && |
| 74 | rtp_parameters.encodings[i].max_bitrate_bps) { |
| 75 | if (*rtp_parameters.encodings[i].max_bitrate_bps < |
| 76 | *rtp_parameters.encodings[i].min_bitrate_bps) { |
| 77 | LOG_AND_RETURN_ERROR(webrtc::RTCErrorType::INVALID_RANGE, |
| 78 | "Attempted to set RtpParameters min bitrate " |
| 79 | "larger than max bitrate."); |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | return webrtc::RTCError::OK(); |
| 84 | } |
| 85 | |
Henrik Kjellander | b252856 | 2016-03-29 17:47:19 +0200 | [diff] [blame] | 86 | }; // namespace cricket |