blob: 62c3cec076b3bc0695bd9609616ef95056f8873a [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
Steve Anton10542f22019-01-11 09:11:00 -080011#include "media/base/media_engine.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000012
Yves Gerey3e707812018-11-28 16:47:49 +010013#include <stddef.h>
14#include <cstdint>
15#include <string>
Sebastian Janssonfa0aa392018-11-16 09:54:32 +010016#include <utility>
17
Åsa Persson23eba222018-10-02 14:47:06 +020018#include "api/video/video_bitrate_allocation.h"
Yves Gerey3e707812018-11-28 16:47:49 +010019#include "rtc_base/checks.h"
Steve Anton10542f22019-01-11 09:11:00 -080020#include "rtc_base/string_encode.h"
Åsa Persson23eba222018-10-02 14:47:06 +020021
skvladdc1c62c2016-03-16 19:07:43 -070022namespace cricket {
23
Paulina Hensman11b34f42018-04-09 14:24:52 +020024RtpCapabilities::RtpCapabilities() = default;
25RtpCapabilities::~RtpCapabilities() = default;
26
skvladdc1c62c2016-03-16 19:07:43 -070027webrtc::RtpParameters CreateRtpParametersWithOneEncoding() {
28 webrtc::RtpParameters parameters;
29 webrtc::RtpEncodingParameters encoding;
30 parameters.encodings.push_back(encoding);
31 return parameters;
32}
33
Zach Stein3ca452b2018-01-18 10:01:24 -080034webrtc::RtpParameters CreateRtpParametersWithEncodings(StreamParams sp) {
35 std::vector<uint32_t> primary_ssrcs;
36 sp.GetPrimarySsrcs(&primary_ssrcs);
37 size_t encoding_count = primary_ssrcs.size();
38
39 std::vector<webrtc::RtpEncodingParameters> encodings(encoding_count);
40 for (size_t i = 0; i < encodings.size(); ++i) {
41 encodings[i].ssrc = primary_ssrcs[i];
42 }
43 webrtc::RtpParameters parameters;
44 parameters.encodings = encodings;
Florent Castellidacec712018-05-24 16:24:21 +020045 parameters.rtcp.cname = sp.cname;
Zach Stein3ca452b2018-01-18 10:01:24 -080046 return parameters;
47}
48
Florent Castellic1a0bcb2019-01-29 14:26:48 +010049webrtc::RTCError CheckRtpParametersValues(
Florent Castelli892acf02018-10-01 22:47:20 +020050 const webrtc::RtpParameters& rtp_parameters) {
51 using webrtc::RTCErrorType;
Florent Castelli892acf02018-10-01 22:47:20 +020052
53 for (size_t i = 0; i < rtp_parameters.encodings.size(); ++i) {
Florent Castelli892acf02018-10-01 22:47:20 +020054 if (rtp_parameters.encodings[i].bitrate_priority <= 0) {
55 LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_RANGE,
56 "Attempted to set RtpParameters bitrate_priority to "
57 "an invalid number. bitrate_priority must be > 0.");
58 }
Florent Castellic1a0bcb2019-01-29 14:26:48 +010059 if (rtp_parameters.encodings[i].scale_resolution_down_by &&
60 *rtp_parameters.encodings[i].scale_resolution_down_by < 1.0) {
61 LOG_AND_RETURN_ERROR(
62 RTCErrorType::INVALID_RANGE,
63 "Attempted to set RtpParameters scale_resolution_down_by to an "
64 "invalid number. scale_resolution_down_by must be >= 1.0");
65 }
Florent Castelli892acf02018-10-01 22:47:20 +020066 if (rtp_parameters.encodings[i].min_bitrate_bps &&
67 rtp_parameters.encodings[i].max_bitrate_bps) {
68 if (*rtp_parameters.encodings[i].max_bitrate_bps <
69 *rtp_parameters.encodings[i].min_bitrate_bps) {
70 LOG_AND_RETURN_ERROR(webrtc::RTCErrorType::INVALID_RANGE,
71 "Attempted to set RtpParameters min bitrate "
72 "larger than max bitrate.");
73 }
74 }
Åsa Persson23eba222018-10-02 14:47:06 +020075 if (rtp_parameters.encodings[i].num_temporal_layers) {
76 if (*rtp_parameters.encodings[i].num_temporal_layers < 1 ||
77 *rtp_parameters.encodings[i].num_temporal_layers >
78 webrtc::kMaxTemporalStreams) {
79 LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_RANGE,
80 "Attempted to set RtpParameters "
81 "num_temporal_layers to an invalid number.");
82 }
83 }
84 if (i > 0 && (rtp_parameters.encodings[i].num_temporal_layers !=
85 rtp_parameters.encodings[i - 1].num_temporal_layers)) {
86 LOG_AND_RETURN_ERROR(
87 RTCErrorType::INVALID_MODIFICATION,
88 "Attempted to set RtpParameters num_temporal_layers "
89 "at encoding layer i: " +
90 rtc::ToString(i) +
91 " to a different value than other encoding layers.");
92 }
Florent Castelli892acf02018-10-01 22:47:20 +020093 }
Florent Castellic1a0bcb2019-01-29 14:26:48 +010094
Florent Castelli892acf02018-10-01 22:47:20 +020095 return webrtc::RTCError::OK();
96}
97
Florent Castellic1a0bcb2019-01-29 14:26:48 +010098webrtc::RTCError CheckRtpParametersInvalidModificationAndValues(
99 const webrtc::RtpParameters& old_rtp_parameters,
100 const webrtc::RtpParameters& rtp_parameters) {
101 using webrtc::RTCErrorType;
102 if (rtp_parameters.encodings.size() != old_rtp_parameters.encodings.size()) {
103 LOG_AND_RETURN_ERROR(
104 RTCErrorType::INVALID_MODIFICATION,
105 "Attempted to set RtpParameters with different encoding count");
106 }
107 if (rtp_parameters.rtcp != old_rtp_parameters.rtcp) {
108 LOG_AND_RETURN_ERROR(
109 RTCErrorType::INVALID_MODIFICATION,
110 "Attempted to set RtpParameters with modified RTCP parameters");
111 }
112 if (rtp_parameters.header_extensions !=
113 old_rtp_parameters.header_extensions) {
114 LOG_AND_RETURN_ERROR(
115 RTCErrorType::INVALID_MODIFICATION,
116 "Attempted to set RtpParameters with modified header extensions");
117 }
118
119 for (size_t i = 0; i < rtp_parameters.encodings.size(); ++i) {
120 if (rtp_parameters.encodings[i].ssrc !=
121 old_rtp_parameters.encodings[i].ssrc) {
122 LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_MODIFICATION,
123 "Attempted to set RtpParameters with modified SSRC");
124 }
125 }
126
127 return CheckRtpParametersValues(rtp_parameters);
128}
129
Sebastian Janssonfa0aa392018-11-16 09:54:32 +0100130CompositeMediaEngine::CompositeMediaEngine(
131 std::unique_ptr<VoiceEngineInterface> voice_engine,
132 std::unique_ptr<VideoEngineInterface> video_engine)
133 : voice_engine_(std::move(voice_engine)),
134 video_engine_(std::move(video_engine)) {}
135
136CompositeMediaEngine::~CompositeMediaEngine() = default;
137
138bool CompositeMediaEngine::Init() {
139 voice().Init();
140 return true;
141}
142
Sebastian Janssonfa0aa392018-11-16 09:54:32 +0100143VoiceEngineInterface& CompositeMediaEngine::voice() {
144 return *voice_engine_.get();
145}
146
147VideoEngineInterface& CompositeMediaEngine::video() {
148 return *video_engine_.get();
149}
150
151const VoiceEngineInterface& CompositeMediaEngine::voice() const {
152 return *voice_engine_.get();
153}
154
155const VideoEngineInterface& CompositeMediaEngine::video() const {
156 return *video_engine_.get();
157}
158
Henrik Kjellanderb2528562016-03-29 17:47:19 +0200159}; // namespace cricket