blob: d5198fe64f1901e003df4822939834dcf1bcef6a [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
Sebastian Janssonfa0aa392018-11-16 09:54:32 +010013#include <utility>
14
Åsa Persson23eba222018-10-02 14:47:06 +020015#include "api/video/video_bitrate_allocation.h"
16#include "rtc_base/stringencode.h"
17
skvladdc1c62c2016-03-16 19:07:43 -070018namespace cricket {
19
Paulina Hensman11b34f42018-04-09 14:24:52 +020020RtpCapabilities::RtpCapabilities() = default;
21RtpCapabilities::~RtpCapabilities() = default;
22
skvladdc1c62c2016-03-16 19:07:43 -070023webrtc::RtpParameters CreateRtpParametersWithOneEncoding() {
24 webrtc::RtpParameters parameters;
25 webrtc::RtpEncodingParameters encoding;
26 parameters.encodings.push_back(encoding);
27 return parameters;
28}
29
Zach Stein3ca452b2018-01-18 10:01:24 -080030webrtc::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 Castellidacec712018-05-24 16:24:21 +020041 parameters.rtcp.cname = sp.cname;
Zach Stein3ca452b2018-01-18 10:01:24 -080042 return parameters;
43}
44
Florent Castelli892acf02018-10-01 22:47:20 +020045webrtc::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 Persson23eba222018-10-02 14:47:06 +020087 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 Castelli892acf02018-10-01 22:47:20 +0200105 }
106 return webrtc::RTCError::OK();
107}
108
Sebastian Janssonfa0aa392018-11-16 09:54:32 +0100109CompositeMediaEngine::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
115CompositeMediaEngine::~CompositeMediaEngine() = default;
116
117bool CompositeMediaEngine::Init() {
118 voice().Init();
119 return true;
120}
121
Sebastian Janssonfa0aa392018-11-16 09:54:32 +0100122VoiceEngineInterface& CompositeMediaEngine::voice() {
123 return *voice_engine_.get();
124}
125
126VideoEngineInterface& CompositeMediaEngine::video() {
127 return *video_engine_.get();
128}
129
130const VoiceEngineInterface& CompositeMediaEngine::voice() const {
131 return *voice_engine_.get();
132}
133
134const VideoEngineInterface& CompositeMediaEngine::video() const {
135 return *video_engine_.get();
136}
137
Henrik Kjellanderb2528562016-03-29 17:47:19 +0200138}; // namespace cricket