blob: aaca55c62d153a034966e7b6302654493337ab37 [file] [log] [blame]
jlmiller@webrtc.org5f93d0a2015-01-20 21:36:13 +00001/*
kjellander1afca732016-02-07 20:46:45 -08002 * Copyright (c) 2004 The WebRTC project authors. All Rights Reserved.
jlmiller@webrtc.org5f93d0a2015-01-20 21:36:13 +00003 *
kjellander1afca732016-02-07 20:46:45 -08004 * 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.org5f93d0a2015-01-20 21:36:13 +00009 */
henrike@webrtc.org28e20752013-07-10 00:45:36 +000010
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "media/base/mediaengine.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000012
skvladdc1c62c2016-03-16 19:07:43 -070013namespace cricket {
14
Paulina Hensman11b34f42018-04-09 14:24:52 +020015RtpCapabilities::RtpCapabilities() = default;
16RtpCapabilities::~RtpCapabilities() = default;
17
skvladdc1c62c2016-03-16 19:07:43 -070018webrtc::RtpParameters CreateRtpParametersWithOneEncoding() {
19 webrtc::RtpParameters parameters;
20 webrtc::RtpEncodingParameters encoding;
21 parameters.encodings.push_back(encoding);
22 return parameters;
23}
24
Zach Stein3ca452b2018-01-18 10:01:24 -080025webrtc::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 Castellidacec712018-05-24 16:24:21 +020036 parameters.rtcp.cname = sp.cname;
Zach Stein3ca452b2018-01-18 10:01:24 -080037 return parameters;
38}
39
Florent Castelli892acf02018-10-01 22:47:20 +020040webrtc::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 Kjellanderb2528562016-03-29 17:47:19 +020086}; // namespace cricket