blob: 91fcc1ea72f0eeb0c6a417d39278507823b32115 [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 Castelli892acf02018-10-01 22:47:20 +020049webrtc::RTCError ValidateRtpParameters(
50 const webrtc::RtpParameters& old_rtp_parameters,
51 const webrtc::RtpParameters& rtp_parameters) {
52 using webrtc::RTCErrorType;
53 if (rtp_parameters.encodings.size() != old_rtp_parameters.encodings.size()) {
54 LOG_AND_RETURN_ERROR(
55 RTCErrorType::INVALID_MODIFICATION,
56 "Attempted to set RtpParameters with different encoding count");
57 }
58 if (rtp_parameters.rtcp != old_rtp_parameters.rtcp) {
59 LOG_AND_RETURN_ERROR(
60 RTCErrorType::INVALID_MODIFICATION,
61 "Attempted to set RtpParameters with modified RTCP parameters");
62 }
63 if (rtp_parameters.header_extensions !=
64 old_rtp_parameters.header_extensions) {
65 LOG_AND_RETURN_ERROR(
66 RTCErrorType::INVALID_MODIFICATION,
67 "Attempted to set RtpParameters with modified header extensions");
68 }
69
70 for (size_t i = 0; i < rtp_parameters.encodings.size(); ++i) {
71 if (rtp_parameters.encodings[i].ssrc !=
72 old_rtp_parameters.encodings[i].ssrc) {
73 LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_MODIFICATION,
74 "Attempted to set RtpParameters with modified SSRC");
75 }
76 if (rtp_parameters.encodings[i].bitrate_priority <= 0) {
77 LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_RANGE,
78 "Attempted to set RtpParameters bitrate_priority to "
79 "an invalid number. bitrate_priority must be > 0.");
80 }
81
82 if (rtp_parameters.encodings[i].min_bitrate_bps &&
83 rtp_parameters.encodings[i].max_bitrate_bps) {
84 if (*rtp_parameters.encodings[i].max_bitrate_bps <
85 *rtp_parameters.encodings[i].min_bitrate_bps) {
86 LOG_AND_RETURN_ERROR(webrtc::RTCErrorType::INVALID_RANGE,
87 "Attempted to set RtpParameters min bitrate "
88 "larger than max bitrate.");
89 }
90 }
Åsa Persson23eba222018-10-02 14:47:06 +020091 if (rtp_parameters.encodings[i].num_temporal_layers) {
92 if (*rtp_parameters.encodings[i].num_temporal_layers < 1 ||
93 *rtp_parameters.encodings[i].num_temporal_layers >
94 webrtc::kMaxTemporalStreams) {
95 LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_RANGE,
96 "Attempted to set RtpParameters "
97 "num_temporal_layers to an invalid number.");
98 }
99 }
100 if (i > 0 && (rtp_parameters.encodings[i].num_temporal_layers !=
101 rtp_parameters.encodings[i - 1].num_temporal_layers)) {
102 LOG_AND_RETURN_ERROR(
103 RTCErrorType::INVALID_MODIFICATION,
104 "Attempted to set RtpParameters num_temporal_layers "
105 "at encoding layer i: " +
106 rtc::ToString(i) +
107 " to a different value than other encoding layers.");
108 }
Florent Castelli892acf02018-10-01 22:47:20 +0200109 }
110 return webrtc::RTCError::OK();
111}
112
Sebastian Janssonfa0aa392018-11-16 09:54:32 +0100113CompositeMediaEngine::CompositeMediaEngine(
114 std::unique_ptr<VoiceEngineInterface> voice_engine,
115 std::unique_ptr<VideoEngineInterface> video_engine)
116 : voice_engine_(std::move(voice_engine)),
117 video_engine_(std::move(video_engine)) {}
118
119CompositeMediaEngine::~CompositeMediaEngine() = default;
120
121bool CompositeMediaEngine::Init() {
122 voice().Init();
123 return true;
124}
125
Sebastian Janssonfa0aa392018-11-16 09:54:32 +0100126VoiceEngineInterface& CompositeMediaEngine::voice() {
127 return *voice_engine_.get();
128}
129
130VideoEngineInterface& CompositeMediaEngine::video() {
131 return *video_engine_.get();
132}
133
134const VoiceEngineInterface& CompositeMediaEngine::voice() const {
135 return *voice_engine_.get();
136}
137
138const VideoEngineInterface& CompositeMediaEngine::video() const {
139 return *video_engine_.get();
140}
141
Henrik Kjellanderb2528562016-03-29 17:47:19 +0200142}; // namespace cricket