blob: 76cac4b438342e0abe226a72765d04629d5823b7 [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
Åsa Persson23eba222018-10-02 14:47:06 +020013#include "api/video/video_bitrate_allocation.h"
14#include "rtc_base/stringencode.h"
15
skvladdc1c62c2016-03-16 19:07:43 -070016namespace cricket {
17
Paulina Hensman11b34f42018-04-09 14:24:52 +020018RtpCapabilities::RtpCapabilities() = default;
19RtpCapabilities::~RtpCapabilities() = default;
20
skvladdc1c62c2016-03-16 19:07:43 -070021webrtc::RtpParameters CreateRtpParametersWithOneEncoding() {
22 webrtc::RtpParameters parameters;
23 webrtc::RtpEncodingParameters encoding;
24 parameters.encodings.push_back(encoding);
25 return parameters;
26}
27
Zach Stein3ca452b2018-01-18 10:01:24 -080028webrtc::RtpParameters CreateRtpParametersWithEncodings(StreamParams sp) {
29 std::vector<uint32_t> primary_ssrcs;
30 sp.GetPrimarySsrcs(&primary_ssrcs);
31 size_t encoding_count = primary_ssrcs.size();
32
33 std::vector<webrtc::RtpEncodingParameters> encodings(encoding_count);
34 for (size_t i = 0; i < encodings.size(); ++i) {
35 encodings[i].ssrc = primary_ssrcs[i];
36 }
37 webrtc::RtpParameters parameters;
38 parameters.encodings = encodings;
Florent Castellidacec712018-05-24 16:24:21 +020039 parameters.rtcp.cname = sp.cname;
Zach Stein3ca452b2018-01-18 10:01:24 -080040 return parameters;
41}
42
Florent Castelli892acf02018-10-01 22:47:20 +020043webrtc::RTCError ValidateRtpParameters(
44 const webrtc::RtpParameters& old_rtp_parameters,
45 const webrtc::RtpParameters& rtp_parameters) {
46 using webrtc::RTCErrorType;
47 if (rtp_parameters.encodings.size() != old_rtp_parameters.encodings.size()) {
48 LOG_AND_RETURN_ERROR(
49 RTCErrorType::INVALID_MODIFICATION,
50 "Attempted to set RtpParameters with different encoding count");
51 }
52 if (rtp_parameters.rtcp != old_rtp_parameters.rtcp) {
53 LOG_AND_RETURN_ERROR(
54 RTCErrorType::INVALID_MODIFICATION,
55 "Attempted to set RtpParameters with modified RTCP parameters");
56 }
57 if (rtp_parameters.header_extensions !=
58 old_rtp_parameters.header_extensions) {
59 LOG_AND_RETURN_ERROR(
60 RTCErrorType::INVALID_MODIFICATION,
61 "Attempted to set RtpParameters with modified header extensions");
62 }
63
64 for (size_t i = 0; i < rtp_parameters.encodings.size(); ++i) {
65 if (rtp_parameters.encodings[i].ssrc !=
66 old_rtp_parameters.encodings[i].ssrc) {
67 LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_MODIFICATION,
68 "Attempted to set RtpParameters with modified SSRC");
69 }
70 if (rtp_parameters.encodings[i].bitrate_priority <= 0) {
71 LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_RANGE,
72 "Attempted to set RtpParameters bitrate_priority to "
73 "an invalid number. bitrate_priority must be > 0.");
74 }
75
76 if (rtp_parameters.encodings[i].min_bitrate_bps &&
77 rtp_parameters.encodings[i].max_bitrate_bps) {
78 if (*rtp_parameters.encodings[i].max_bitrate_bps <
79 *rtp_parameters.encodings[i].min_bitrate_bps) {
80 LOG_AND_RETURN_ERROR(webrtc::RTCErrorType::INVALID_RANGE,
81 "Attempted to set RtpParameters min bitrate "
82 "larger than max bitrate.");
83 }
84 }
Åsa Persson23eba222018-10-02 14:47:06 +020085 if (rtp_parameters.encodings[i].num_temporal_layers) {
86 if (*rtp_parameters.encodings[i].num_temporal_layers < 1 ||
87 *rtp_parameters.encodings[i].num_temporal_layers >
88 webrtc::kMaxTemporalStreams) {
89 LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_RANGE,
90 "Attempted to set RtpParameters "
91 "num_temporal_layers to an invalid number.");
92 }
93 }
94 if (i > 0 && (rtp_parameters.encodings[i].num_temporal_layers !=
95 rtp_parameters.encodings[i - 1].num_temporal_layers)) {
96 LOG_AND_RETURN_ERROR(
97 RTCErrorType::INVALID_MODIFICATION,
98 "Attempted to set RtpParameters num_temporal_layers "
99 "at encoding layer i: " +
100 rtc::ToString(i) +
101 " to a different value than other encoding layers.");
102 }
Florent Castelli892acf02018-10-01 22:47:20 +0200103 }
104 return webrtc::RTCError::OK();
105}
106
Henrik Kjellanderb2528562016-03-29 17:47:19 +0200107}; // namespace cricket