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 | |
Sebastian Jansson | fa0aa39 | 2018-11-16 09:54:32 +0100 | [diff] [blame^] | 13 | #include <utility> |
| 14 | |
Åsa Persson | 23eba22 | 2018-10-02 14:47:06 +0200 | [diff] [blame] | 15 | #include "api/video/video_bitrate_allocation.h" |
| 16 | #include "rtc_base/stringencode.h" |
| 17 | |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 18 | namespace cricket { |
| 19 | |
Paulina Hensman | 11b34f4 | 2018-04-09 14:24:52 +0200 | [diff] [blame] | 20 | RtpCapabilities::RtpCapabilities() = default; |
| 21 | RtpCapabilities::~RtpCapabilities() = default; |
| 22 | |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 23 | webrtc::RtpParameters CreateRtpParametersWithOneEncoding() { |
| 24 | webrtc::RtpParameters parameters; |
| 25 | webrtc::RtpEncodingParameters encoding; |
| 26 | parameters.encodings.push_back(encoding); |
| 27 | return parameters; |
| 28 | } |
| 29 | |
Zach Stein | 3ca452b | 2018-01-18 10:01:24 -0800 | [diff] [blame] | 30 | webrtc::RtpParameters CreateRtpParametersWithEncodings(StreamParams sp) { |
| 31 | std::vector<uint32_t> primary_ssrcs; |
| 32 | sp.GetPrimarySsrcs(&primary_ssrcs); |
| 33 | size_t encoding_count = primary_ssrcs.size(); |
| 34 | |
| 35 | std::vector<webrtc::RtpEncodingParameters> encodings(encoding_count); |
| 36 | for (size_t i = 0; i < encodings.size(); ++i) { |
| 37 | encodings[i].ssrc = primary_ssrcs[i]; |
| 38 | } |
| 39 | webrtc::RtpParameters parameters; |
| 40 | parameters.encodings = encodings; |
Florent Castelli | dacec71 | 2018-05-24 16:24:21 +0200 | [diff] [blame] | 41 | parameters.rtcp.cname = sp.cname; |
Zach Stein | 3ca452b | 2018-01-18 10:01:24 -0800 | [diff] [blame] | 42 | return parameters; |
| 43 | } |
| 44 | |
Florent Castelli | 892acf0 | 2018-10-01 22:47:20 +0200 | [diff] [blame] | 45 | webrtc::RTCError ValidateRtpParameters( |
| 46 | const webrtc::RtpParameters& old_rtp_parameters, |
| 47 | const webrtc::RtpParameters& rtp_parameters) { |
| 48 | using webrtc::RTCErrorType; |
| 49 | if (rtp_parameters.encodings.size() != old_rtp_parameters.encodings.size()) { |
| 50 | LOG_AND_RETURN_ERROR( |
| 51 | RTCErrorType::INVALID_MODIFICATION, |
| 52 | "Attempted to set RtpParameters with different encoding count"); |
| 53 | } |
| 54 | if (rtp_parameters.rtcp != old_rtp_parameters.rtcp) { |
| 55 | LOG_AND_RETURN_ERROR( |
| 56 | RTCErrorType::INVALID_MODIFICATION, |
| 57 | "Attempted to set RtpParameters with modified RTCP parameters"); |
| 58 | } |
| 59 | if (rtp_parameters.header_extensions != |
| 60 | old_rtp_parameters.header_extensions) { |
| 61 | LOG_AND_RETURN_ERROR( |
| 62 | RTCErrorType::INVALID_MODIFICATION, |
| 63 | "Attempted to set RtpParameters with modified header extensions"); |
| 64 | } |
| 65 | |
| 66 | for (size_t i = 0; i < rtp_parameters.encodings.size(); ++i) { |
| 67 | if (rtp_parameters.encodings[i].ssrc != |
| 68 | old_rtp_parameters.encodings[i].ssrc) { |
| 69 | LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_MODIFICATION, |
| 70 | "Attempted to set RtpParameters with modified SSRC"); |
| 71 | } |
| 72 | if (rtp_parameters.encodings[i].bitrate_priority <= 0) { |
| 73 | LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_RANGE, |
| 74 | "Attempted to set RtpParameters bitrate_priority to " |
| 75 | "an invalid number. bitrate_priority must be > 0."); |
| 76 | } |
| 77 | |
| 78 | if (rtp_parameters.encodings[i].min_bitrate_bps && |
| 79 | rtp_parameters.encodings[i].max_bitrate_bps) { |
| 80 | if (*rtp_parameters.encodings[i].max_bitrate_bps < |
| 81 | *rtp_parameters.encodings[i].min_bitrate_bps) { |
| 82 | LOG_AND_RETURN_ERROR(webrtc::RTCErrorType::INVALID_RANGE, |
| 83 | "Attempted to set RtpParameters min bitrate " |
| 84 | "larger than max bitrate."); |
| 85 | } |
| 86 | } |
Åsa Persson | 23eba22 | 2018-10-02 14:47:06 +0200 | [diff] [blame] | 87 | if (rtp_parameters.encodings[i].num_temporal_layers) { |
| 88 | if (*rtp_parameters.encodings[i].num_temporal_layers < 1 || |
| 89 | *rtp_parameters.encodings[i].num_temporal_layers > |
| 90 | webrtc::kMaxTemporalStreams) { |
| 91 | LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_RANGE, |
| 92 | "Attempted to set RtpParameters " |
| 93 | "num_temporal_layers to an invalid number."); |
| 94 | } |
| 95 | } |
| 96 | if (i > 0 && (rtp_parameters.encodings[i].num_temporal_layers != |
| 97 | rtp_parameters.encodings[i - 1].num_temporal_layers)) { |
| 98 | LOG_AND_RETURN_ERROR( |
| 99 | RTCErrorType::INVALID_MODIFICATION, |
| 100 | "Attempted to set RtpParameters num_temporal_layers " |
| 101 | "at encoding layer i: " + |
| 102 | rtc::ToString(i) + |
| 103 | " to a different value than other encoding layers."); |
| 104 | } |
Florent Castelli | 892acf0 | 2018-10-01 22:47:20 +0200 | [diff] [blame] | 105 | } |
| 106 | return webrtc::RTCError::OK(); |
| 107 | } |
| 108 | |
Sebastian Jansson | fa0aa39 | 2018-11-16 09:54:32 +0100 | [diff] [blame^] | 109 | CompositeMediaEngine::CompositeMediaEngine( |
| 110 | std::unique_ptr<VoiceEngineInterface> voice_engine, |
| 111 | std::unique_ptr<VideoEngineInterface> video_engine) |
| 112 | : voice_engine_(std::move(voice_engine)), |
| 113 | video_engine_(std::move(video_engine)) {} |
| 114 | |
| 115 | CompositeMediaEngine::~CompositeMediaEngine() = default; |
| 116 | |
| 117 | bool CompositeMediaEngine::Init() { |
| 118 | voice().Init(); |
| 119 | return true; |
| 120 | } |
| 121 | |
| 122 | rtc::scoped_refptr<webrtc::AudioState> CompositeMediaEngine::GetAudioState() |
| 123 | const { |
| 124 | return voice().GetAudioState(); |
| 125 | } |
| 126 | |
| 127 | VoiceMediaChannel* CompositeMediaEngine::CreateChannel( |
| 128 | webrtc::Call* call, |
| 129 | const MediaConfig& config, |
| 130 | const AudioOptions& options, |
| 131 | const webrtc::CryptoOptions& crypto_options) { |
| 132 | return voice().CreateMediaChannel(call, config, options, crypto_options); |
| 133 | } |
| 134 | |
| 135 | VideoMediaChannel* CompositeMediaEngine::CreateVideoChannel( |
| 136 | webrtc::Call* call, |
| 137 | const MediaConfig& config, |
| 138 | const VideoOptions& options, |
| 139 | const webrtc::CryptoOptions& crypto_options) { |
| 140 | return video().CreateMediaChannel(call, config, options, crypto_options); |
| 141 | } |
| 142 | |
| 143 | const std::vector<AudioCodec>& CompositeMediaEngine::audio_send_codecs() { |
| 144 | return voice().send_codecs(); |
| 145 | } |
| 146 | |
| 147 | const std::vector<AudioCodec>& CompositeMediaEngine::audio_recv_codecs() { |
| 148 | return voice().recv_codecs(); |
| 149 | } |
| 150 | |
| 151 | RtpCapabilities CompositeMediaEngine::GetAudioCapabilities() { |
| 152 | return voice().GetCapabilities(); |
| 153 | } |
| 154 | |
| 155 | std::vector<VideoCodec> CompositeMediaEngine::video_codecs() { |
| 156 | return video().codecs(); |
| 157 | } |
| 158 | |
| 159 | RtpCapabilities CompositeMediaEngine::GetVideoCapabilities() { |
| 160 | return video().GetCapabilities(); |
| 161 | } |
| 162 | |
| 163 | bool CompositeMediaEngine::StartAecDump(rtc::PlatformFile file, |
| 164 | int64_t max_size_bytes) { |
| 165 | return voice().StartAecDump(file, max_size_bytes); |
| 166 | } |
| 167 | |
| 168 | void CompositeMediaEngine::StopAecDump() { |
| 169 | voice().StopAecDump(); |
| 170 | } |
| 171 | |
| 172 | VoiceEngineInterface& CompositeMediaEngine::voice() { |
| 173 | return *voice_engine_.get(); |
| 174 | } |
| 175 | |
| 176 | VideoEngineInterface& CompositeMediaEngine::video() { |
| 177 | return *video_engine_.get(); |
| 178 | } |
| 179 | |
| 180 | const VoiceEngineInterface& CompositeMediaEngine::voice() const { |
| 181 | return *voice_engine_.get(); |
| 182 | } |
| 183 | |
| 184 | const VideoEngineInterface& CompositeMediaEngine::video() const { |
| 185 | return *video_engine_.get(); |
| 186 | } |
| 187 | |
Henrik Kjellander | b252856 | 2016-03-29 17:47:19 +0200 | [diff] [blame] | 188 | }; // namespace cricket |