henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +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. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +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. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
kjellander | a96e2d7 | 2016-02-04 23:52:28 -0800 | [diff] [blame] | 11 | #ifndef WEBRTC_MEDIA_BASE_FAKEMEDIAENGINE_H_ |
| 12 | #define WEBRTC_MEDIA_BASE_FAKEMEDIAENGINE_H_ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 13 | |
| 14 | #include <list> |
| 15 | #include <map> |
kwiberg | 686a8ef | 2016-02-26 03:00:35 -0800 | [diff] [blame] | 16 | #include <memory> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 17 | #include <set> |
| 18 | #include <string> |
| 19 | #include <vector> |
| 20 | |
kjellander | a69d973 | 2016-08-31 07:33:05 -0700 | [diff] [blame] | 21 | #include "webrtc/api/call/audio_sink.h" |
Taylor Brandstetter | 1a018dc | 2016-03-08 12:37:39 -0800 | [diff] [blame] | 22 | #include "webrtc/media/base/audiosource.h" |
kjellander | a96e2d7 | 2016-02-04 23:52:28 -0800 | [diff] [blame] | 23 | #include "webrtc/media/base/mediaengine.h" |
| 24 | #include "webrtc/media/base/rtputils.h" |
| 25 | #include "webrtc/media/base/streamparams.h" |
sprang | db2a9fc | 2017-08-09 06:42:32 -0700 | [diff] [blame] | 26 | #include "webrtc/media/engine/webrtcvideoengine.h" |
peah | a9cc40b | 2017-06-29 08:32:09 -0700 | [diff] [blame] | 27 | #include "webrtc/modules/audio_processing/include/audio_processing.h" |
Tommi | f888bb5 | 2015-12-12 01:37:01 +0100 | [diff] [blame] | 28 | #include "webrtc/p2p/base/sessiondescription.h" |
Edward Lemur | c20978e | 2017-07-06 19:44:34 +0200 | [diff] [blame] | 29 | #include "webrtc/rtc_base/checks.h" |
| 30 | #include "webrtc/rtc_base/copyonwritebuffer.h" |
| 31 | #include "webrtc/rtc_base/networkroute.h" |
sprang | db2a9fc | 2017-08-09 06:42:32 -0700 | [diff] [blame] | 32 | #include "webrtc/rtc_base/ptr_util.h" |
Edward Lemur | c20978e | 2017-07-06 19:44:34 +0200 | [diff] [blame] | 33 | #include "webrtc/rtc_base/stringutils.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 34 | |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 35 | using webrtc::RtpExtension; |
| 36 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 37 | namespace cricket { |
| 38 | |
| 39 | class FakeMediaEngine; |
| 40 | class FakeVideoEngine; |
| 41 | class FakeVoiceEngine; |
| 42 | |
| 43 | // A common helper class that handles sending and receiving RTP/RTCP packets. |
| 44 | template <class Base> class RtpHelper : public Base { |
| 45 | public: |
| 46 | RtpHelper() |
| 47 | : sending_(false), |
| 48 | playout_(false), |
| 49 | fail_set_send_codecs_(false), |
| 50 | fail_set_recv_codecs_(false), |
| 51 | send_ssrc_(0), |
sprang | db2a9fc | 2017-08-09 06:42:32 -0700 | [diff] [blame] | 52 | ready_to_send_(false), |
| 53 | transport_overhead_per_packet_(0), |
| 54 | num_network_route_changes_(0) {} |
| 55 | virtual ~RtpHelper() = default; |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 56 | const std::vector<RtpExtension>& recv_extensions() { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 57 | return recv_extensions_; |
| 58 | } |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 59 | const std::vector<RtpExtension>& send_extensions() { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 60 | return send_extensions_; |
| 61 | } |
| 62 | bool sending() const { return sending_; } |
| 63 | bool playout() const { return playout_; } |
| 64 | const std::list<std::string>& rtp_packets() const { return rtp_packets_; } |
| 65 | const std::list<std::string>& rtcp_packets() const { return rtcp_packets_; } |
| 66 | |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 67 | bool SendRtp(const void* data, |
| 68 | size_t len, |
| 69 | const rtc::PacketOptions& options) { |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 70 | if (!sending_) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 71 | return false; |
| 72 | } |
jbauch | eec21bd | 2016-03-20 06:15:43 -0700 | [diff] [blame] | 73 | rtc::CopyOnWriteBuffer packet(reinterpret_cast<const uint8_t*>(data), len, |
| 74 | kMaxRtpPacketLen); |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 75 | return Base::SendPacket(&packet, options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 76 | } |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 77 | bool SendRtcp(const void* data, size_t len) { |
jbauch | eec21bd | 2016-03-20 06:15:43 -0700 | [diff] [blame] | 78 | rtc::CopyOnWriteBuffer packet(reinterpret_cast<const uint8_t*>(data), len, |
| 79 | kMaxRtpPacketLen); |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 80 | return Base::SendRtcp(&packet, rtc::PacketOptions()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 81 | } |
| 82 | |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 83 | bool CheckRtp(const void* data, size_t len) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 84 | bool success = !rtp_packets_.empty(); |
| 85 | if (success) { |
| 86 | std::string packet = rtp_packets_.front(); |
| 87 | rtp_packets_.pop_front(); |
| 88 | success = (packet == std::string(static_cast<const char*>(data), len)); |
| 89 | } |
| 90 | return success; |
| 91 | } |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 92 | bool CheckRtcp(const void* data, size_t len) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 93 | bool success = !rtcp_packets_.empty(); |
| 94 | if (success) { |
| 95 | std::string packet = rtcp_packets_.front(); |
| 96 | rtcp_packets_.pop_front(); |
| 97 | success = (packet == std::string(static_cast<const char*>(data), len)); |
| 98 | } |
| 99 | return success; |
| 100 | } |
| 101 | bool CheckNoRtp() { return rtp_packets_.empty(); } |
| 102 | bool CheckNoRtcp() { return rtcp_packets_.empty(); } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 103 | void set_fail_set_send_codecs(bool fail) { fail_set_send_codecs_ = fail; } |
| 104 | void set_fail_set_recv_codecs(bool fail) { fail_set_recv_codecs_ = fail; } |
| 105 | virtual bool AddSendStream(const StreamParams& sp) { |
| 106 | if (std::find(send_streams_.begin(), send_streams_.end(), sp) != |
| 107 | send_streams_.end()) { |
| 108 | return false; |
| 109 | } |
| 110 | send_streams_.push_back(sp); |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 111 | rtp_send_parameters_[sp.first_ssrc()] = |
| 112 | CreateRtpParametersWithOneEncoding(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 113 | return true; |
| 114 | } |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 115 | virtual bool RemoveSendStream(uint32_t ssrc) { |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 116 | auto parameters_iterator = rtp_send_parameters_.find(ssrc); |
| 117 | if (parameters_iterator != rtp_send_parameters_.end()) { |
| 118 | rtp_send_parameters_.erase(parameters_iterator); |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 119 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 120 | return RemoveStreamBySsrc(&send_streams_, ssrc); |
| 121 | } |
| 122 | virtual bool AddRecvStream(const StreamParams& sp) { |
| 123 | if (std::find(receive_streams_.begin(), receive_streams_.end(), sp) != |
| 124 | receive_streams_.end()) { |
| 125 | return false; |
| 126 | } |
| 127 | receive_streams_.push_back(sp); |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 128 | rtp_receive_parameters_[sp.first_ssrc()] = |
| 129 | CreateRtpParametersWithOneEncoding(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 130 | return true; |
| 131 | } |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 132 | virtual bool RemoveRecvStream(uint32_t ssrc) { |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 133 | auto parameters_iterator = rtp_receive_parameters_.find(ssrc); |
| 134 | if (parameters_iterator != rtp_receive_parameters_.end()) { |
| 135 | rtp_receive_parameters_.erase(parameters_iterator); |
| 136 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 137 | return RemoveStreamBySsrc(&receive_streams_, ssrc); |
| 138 | } |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 139 | |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 140 | virtual webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const { |
| 141 | auto parameters_iterator = rtp_send_parameters_.find(ssrc); |
| 142 | if (parameters_iterator != rtp_send_parameters_.end()) { |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 143 | return parameters_iterator->second; |
| 144 | } |
| 145 | return webrtc::RtpParameters(); |
| 146 | } |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 147 | virtual bool SetRtpSendParameters(uint32_t ssrc, |
| 148 | const webrtc::RtpParameters& parameters) { |
| 149 | auto parameters_iterator = rtp_send_parameters_.find(ssrc); |
| 150 | if (parameters_iterator != rtp_send_parameters_.end()) { |
| 151 | parameters_iterator->second = parameters; |
| 152 | return true; |
| 153 | } |
| 154 | // Replicate the behavior of the real media channel: return false |
| 155 | // when setting parameters for unknown SSRCs. |
| 156 | return false; |
| 157 | } |
| 158 | |
| 159 | virtual webrtc::RtpParameters GetRtpReceiveParameters(uint32_t ssrc) const { |
| 160 | auto parameters_iterator = rtp_receive_parameters_.find(ssrc); |
| 161 | if (parameters_iterator != rtp_receive_parameters_.end()) { |
| 162 | return parameters_iterator->second; |
| 163 | } |
| 164 | return webrtc::RtpParameters(); |
| 165 | } |
| 166 | virtual bool SetRtpReceiveParameters( |
| 167 | uint32_t ssrc, |
| 168 | const webrtc::RtpParameters& parameters) { |
| 169 | auto parameters_iterator = rtp_receive_parameters_.find(ssrc); |
| 170 | if (parameters_iterator != rtp_receive_parameters_.end()) { |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 171 | parameters_iterator->second = parameters; |
| 172 | return true; |
| 173 | } |
| 174 | // Replicate the behavior of the real media channel: return false |
| 175 | // when setting parameters for unknown SSRCs. |
| 176 | return false; |
| 177 | } |
| 178 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 179 | bool IsStreamMuted(uint32_t ssrc) const { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 180 | bool ret = muted_streams_.find(ssrc) != muted_streams_.end(); |
| 181 | // If |ssrc = 0| check if the first send stream is muted. |
| 182 | if (!ret && ssrc == 0 && !send_streams_.empty()) { |
| 183 | return muted_streams_.find(send_streams_[0].first_ssrc()) != |
| 184 | muted_streams_.end(); |
| 185 | } |
| 186 | return ret; |
| 187 | } |
| 188 | const std::vector<StreamParams>& send_streams() const { |
| 189 | return send_streams_; |
| 190 | } |
| 191 | const std::vector<StreamParams>& recv_streams() const { |
| 192 | return receive_streams_; |
| 193 | } |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 194 | bool HasRecvStream(uint32_t ssrc) const { |
tommi@webrtc.org | 586f2ed | 2015-01-22 23:00:41 +0000 | [diff] [blame] | 195 | return GetStreamBySsrc(receive_streams_, ssrc) != nullptr; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 196 | } |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 197 | bool HasSendStream(uint32_t ssrc) const { |
tommi@webrtc.org | 586f2ed | 2015-01-22 23:00:41 +0000 | [diff] [blame] | 198 | return GetStreamBySsrc(send_streams_, ssrc) != nullptr; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 199 | } |
| 200 | // TODO(perkj): This is to support legacy unit test that only check one |
| 201 | // sending stream. |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 202 | uint32_t send_ssrc() const { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 203 | if (send_streams_.empty()) |
| 204 | return 0; |
| 205 | return send_streams_[0].first_ssrc(); |
| 206 | } |
| 207 | |
| 208 | // TODO(perkj): This is to support legacy unit test that only check one |
| 209 | // sending stream. |
| 210 | const std::string rtcp_cname() { |
| 211 | if (send_streams_.empty()) |
| 212 | return ""; |
| 213 | return send_streams_[0].cname; |
| 214 | } |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 215 | const RtcpParameters& send_rtcp_parameters() { return send_rtcp_parameters_; } |
| 216 | const RtcpParameters& recv_rtcp_parameters() { return recv_rtcp_parameters_; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 217 | |
| 218 | bool ready_to_send() const { |
| 219 | return ready_to_send_; |
| 220 | } |
| 221 | |
michaelt | 79e0588 | 2016-11-08 02:50:09 -0800 | [diff] [blame] | 222 | int transport_overhead_per_packet() const { |
| 223 | return transport_overhead_per_packet_; |
| 224 | } |
| 225 | |
Honghai Zhang | 0e533ef | 2016-04-19 15:41:36 -0700 | [diff] [blame] | 226 | rtc::NetworkRoute last_network_route() const { return last_network_route_; } |
Honghai Zhang | cc411c0 | 2016-03-29 17:27:21 -0700 | [diff] [blame] | 227 | int num_network_route_changes() const { return num_network_route_changes_; } |
| 228 | void set_num_network_route_changes(int changes) { |
| 229 | num_network_route_changes_ = changes; |
| 230 | } |
| 231 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 232 | protected: |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 233 | bool MuteStream(uint32_t ssrc, bool mute) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 234 | if (!HasSendStream(ssrc) && ssrc != 0) { |
solenberg | 1dd98f3 | 2015-09-10 01:57:14 -0700 | [diff] [blame] | 235 | return false; |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 236 | } |
| 237 | if (mute) { |
solenberg | 1dd98f3 | 2015-09-10 01:57:14 -0700 | [diff] [blame] | 238 | muted_streams_.insert(ssrc); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 239 | } else { |
solenberg | 1dd98f3 | 2015-09-10 01:57:14 -0700 | [diff] [blame] | 240 | muted_streams_.erase(ssrc); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 241 | } |
solenberg | 1dd98f3 | 2015-09-10 01:57:14 -0700 | [diff] [blame] | 242 | return true; |
| 243 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 244 | bool set_sending(bool send) { |
| 245 | sending_ = send; |
| 246 | return true; |
| 247 | } |
| 248 | void set_playout(bool playout) { playout_ = playout; } |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 249 | bool SetRecvRtpHeaderExtensions(const std::vector<RtpExtension>& extensions) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 250 | recv_extensions_ = extensions; |
| 251 | return true; |
| 252 | } |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 253 | bool SetSendRtpHeaderExtensions(const std::vector<RtpExtension>& extensions) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 254 | send_extensions_ = extensions; |
| 255 | return true; |
| 256 | } |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 257 | void set_send_rtcp_parameters(const RtcpParameters& params) { |
| 258 | send_rtcp_parameters_ = params; |
| 259 | } |
| 260 | void set_recv_rtcp_parameters(const RtcpParameters& params) { |
| 261 | recv_rtcp_parameters_ = params; |
| 262 | } |
jbauch | eec21bd | 2016-03-20 06:15:43 -0700 | [diff] [blame] | 263 | virtual void OnPacketReceived(rtc::CopyOnWriteBuffer* packet, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 264 | const rtc::PacketTime& packet_time) { |
Karl Wiberg | 9478437 | 2015-04-20 14:03:07 +0200 | [diff] [blame] | 265 | rtp_packets_.push_back(std::string(packet->data<char>(), packet->size())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 266 | } |
jbauch | eec21bd | 2016-03-20 06:15:43 -0700 | [diff] [blame] | 267 | virtual void OnRtcpReceived(rtc::CopyOnWriteBuffer* packet, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 268 | const rtc::PacketTime& packet_time) { |
Karl Wiberg | 9478437 | 2015-04-20 14:03:07 +0200 | [diff] [blame] | 269 | rtcp_packets_.push_back(std::string(packet->data<char>(), packet->size())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 270 | } |
| 271 | virtual void OnReadyToSend(bool ready) { |
| 272 | ready_to_send_ = ready; |
| 273 | } |
michaelt | 79e0588 | 2016-11-08 02:50:09 -0800 | [diff] [blame] | 274 | virtual void OnTransportOverheadChanged(int transport_overhead_per_packet) { |
| 275 | transport_overhead_per_packet_ = transport_overhead_per_packet; |
| 276 | } |
| 277 | |
Honghai Zhang | cc411c0 | 2016-03-29 17:27:21 -0700 | [diff] [blame] | 278 | virtual void OnNetworkRouteChanged(const std::string& transport_name, |
Honghai Zhang | 0e533ef | 2016-04-19 15:41:36 -0700 | [diff] [blame] | 279 | const rtc::NetworkRoute& network_route) { |
Honghai Zhang | cc411c0 | 2016-03-29 17:27:21 -0700 | [diff] [blame] | 280 | last_network_route_ = network_route; |
| 281 | ++num_network_route_changes_; |
| 282 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 283 | bool fail_set_send_codecs() const { return fail_set_send_codecs_; } |
| 284 | bool fail_set_recv_codecs() const { return fail_set_recv_codecs_; } |
| 285 | |
| 286 | private: |
| 287 | bool sending_; |
| 288 | bool playout_; |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 289 | std::vector<RtpExtension> recv_extensions_; |
| 290 | std::vector<RtpExtension> send_extensions_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 291 | std::list<std::string> rtp_packets_; |
| 292 | std::list<std::string> rtcp_packets_; |
| 293 | std::vector<StreamParams> send_streams_; |
| 294 | std::vector<StreamParams> receive_streams_; |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 295 | RtcpParameters send_rtcp_parameters_; |
| 296 | RtcpParameters recv_rtcp_parameters_; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 297 | std::set<uint32_t> muted_streams_; |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 298 | std::map<uint32_t, webrtc::RtpParameters> rtp_send_parameters_; |
| 299 | std::map<uint32_t, webrtc::RtpParameters> rtp_receive_parameters_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 300 | bool fail_set_send_codecs_; |
| 301 | bool fail_set_recv_codecs_; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 302 | uint32_t send_ssrc_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 303 | std::string rtcp_cname_; |
| 304 | bool ready_to_send_; |
michaelt | 79e0588 | 2016-11-08 02:50:09 -0800 | [diff] [blame] | 305 | int transport_overhead_per_packet_; |
Honghai Zhang | 0e533ef | 2016-04-19 15:41:36 -0700 | [diff] [blame] | 306 | rtc::NetworkRoute last_network_route_; |
sprang | db2a9fc | 2017-08-09 06:42:32 -0700 | [diff] [blame] | 307 | int num_network_route_changes_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 308 | }; |
| 309 | |
| 310 | class FakeVoiceMediaChannel : public RtpHelper<VoiceMediaChannel> { |
| 311 | public: |
| 312 | struct DtmfInfo { |
solenberg | 1d63dd0 | 2015-12-02 12:35:09 -0800 | [diff] [blame] | 313 | DtmfInfo(uint32_t ssrc, int event_code, int duration) |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 314 | : ssrc(ssrc), |
| 315 | event_code(event_code), |
solenberg | 1d63dd0 | 2015-12-02 12:35:09 -0800 | [diff] [blame] | 316 | duration(duration) {} |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 317 | uint32_t ssrc; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 318 | int event_code; |
| 319 | int duration; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 320 | }; |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 321 | explicit FakeVoiceMediaChannel(FakeVoiceEngine* engine, |
| 322 | const AudioOptions& options) |
solenberg | 55c5be0 | 2017-02-10 01:20:25 -0800 | [diff] [blame] | 323 | : engine_(engine), max_bps_(-1) { |
solenberg | 4bac9c5 | 2015-10-09 02:32:53 -0700 | [diff] [blame] | 324 | output_scalings_[0] = 1.0; // For default channel. |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 325 | SetOptions(options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 326 | } |
| 327 | ~FakeVoiceMediaChannel(); |
| 328 | const std::vector<AudioCodec>& recv_codecs() const { return recv_codecs_; } |
| 329 | const std::vector<AudioCodec>& send_codecs() const { return send_codecs_; } |
| 330 | const std::vector<AudioCodec>& codecs() const { return send_codecs(); } |
| 331 | const std::vector<DtmfInfo>& dtmf_info_queue() const { |
| 332 | return dtmf_info_queue_; |
| 333 | } |
| 334 | const AudioOptions& options() const { return options_; } |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 335 | int max_bps() const { return max_bps_; } |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 336 | virtual bool SetSendParameters(const AudioSendParameters& params) { |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 337 | set_send_rtcp_parameters(params.rtcp); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 338 | return (SetSendCodecs(params.codecs) && |
| 339 | SetSendRtpHeaderExtensions(params.extensions) && |
| 340 | SetMaxSendBandwidth(params.max_bandwidth_bps) && |
| 341 | SetOptions(params.options)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 342 | } |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 343 | |
| 344 | virtual bool SetRecvParameters(const AudioRecvParameters& params) { |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 345 | set_recv_rtcp_parameters(params.rtcp); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 346 | return (SetRecvCodecs(params.codecs) && |
| 347 | SetRecvRtpHeaderExtensions(params.extensions)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 348 | } |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 349 | |
aleloi | 84ef615 | 2016-08-04 05:28:21 -0700 | [diff] [blame] | 350 | virtual void SetPlayout(bool playout) { set_playout(playout); } |
Taylor Brandstetter | 1a018dc | 2016-03-08 12:37:39 -0800 | [diff] [blame] | 351 | virtual void SetSend(bool send) { set_sending(send); } |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 352 | virtual bool SetAudioSend(uint32_t ssrc, |
| 353 | bool enable, |
solenberg | 1dd98f3 | 2015-09-10 01:57:14 -0700 | [diff] [blame] | 354 | const AudioOptions* options, |
Taylor Brandstetter | 1a018dc | 2016-03-08 12:37:39 -0800 | [diff] [blame] | 355 | AudioSource* source) { |
| 356 | if (!SetLocalSource(ssrc, source)) { |
solenberg | 1dd98f3 | 2015-09-10 01:57:14 -0700 | [diff] [blame] | 357 | return false; |
| 358 | } |
solenberg | dfc8f4f | 2015-10-01 02:31:10 -0700 | [diff] [blame] | 359 | if (!RtpHelper<VoiceMediaChannel>::MuteStream(ssrc, !enable)) { |
solenberg | 1dd98f3 | 2015-09-10 01:57:14 -0700 | [diff] [blame] | 360 | return false; |
| 361 | } |
solenberg | dfc8f4f | 2015-10-01 02:31:10 -0700 | [diff] [blame] | 362 | if (enable && options) { |
solenberg | 1dd98f3 | 2015-09-10 01:57:14 -0700 | [diff] [blame] | 363 | return SetOptions(*options); |
| 364 | } |
| 365 | return true; |
| 366 | } |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 367 | |
| 368 | bool HasSource(uint32_t ssrc) const { |
| 369 | return local_sinks_.find(ssrc) != local_sinks_.end(); |
| 370 | } |
| 371 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 372 | virtual bool AddRecvStream(const StreamParams& sp) { |
| 373 | if (!RtpHelper<VoiceMediaChannel>::AddRecvStream(sp)) |
| 374 | return false; |
solenberg | 4bac9c5 | 2015-10-09 02:32:53 -0700 | [diff] [blame] | 375 | output_scalings_[sp.first_ssrc()] = 1.0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 376 | return true; |
| 377 | } |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 378 | virtual bool RemoveRecvStream(uint32_t ssrc) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 379 | if (!RtpHelper<VoiceMediaChannel>::RemoveRecvStream(ssrc)) |
| 380 | return false; |
| 381 | output_scalings_.erase(ssrc); |
| 382 | return true; |
| 383 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 384 | |
| 385 | virtual bool GetActiveStreams(AudioInfo::StreamList* streams) { return true; } |
| 386 | virtual int GetOutputLevel() { return 0; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 387 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 388 | virtual bool CanInsertDtmf() { |
| 389 | for (std::vector<AudioCodec>::const_iterator it = send_codecs_.begin(); |
| 390 | it != send_codecs_.end(); ++it) { |
| 391 | // Find the DTMF telephone event "codec". |
| 392 | if (_stricmp(it->name.c_str(), "telephone-event") == 0) { |
| 393 | return true; |
| 394 | } |
| 395 | } |
| 396 | return false; |
| 397 | } |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 398 | virtual bool InsertDtmf(uint32_t ssrc, |
| 399 | int event_code, |
solenberg | 1d63dd0 | 2015-12-02 12:35:09 -0800 | [diff] [blame] | 400 | int duration) { |
| 401 | dtmf_info_queue_.push_back(DtmfInfo(ssrc, event_code, duration)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 402 | return true; |
| 403 | } |
| 404 | |
solenberg | 4bac9c5 | 2015-10-09 02:32:53 -0700 | [diff] [blame] | 405 | virtual bool SetOutputVolume(uint32_t ssrc, double volume) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 406 | if (0 == ssrc) { |
solenberg | 4bac9c5 | 2015-10-09 02:32:53 -0700 | [diff] [blame] | 407 | std::map<uint32_t, double>::iterator it; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 408 | for (it = output_scalings_.begin(); it != output_scalings_.end(); ++it) { |
solenberg | 4bac9c5 | 2015-10-09 02:32:53 -0700 | [diff] [blame] | 409 | it->second = volume; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 410 | } |
| 411 | return true; |
| 412 | } else if (output_scalings_.find(ssrc) != output_scalings_.end()) { |
solenberg | 4bac9c5 | 2015-10-09 02:32:53 -0700 | [diff] [blame] | 413 | output_scalings_[ssrc] = volume; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 414 | return true; |
| 415 | } |
| 416 | return false; |
| 417 | } |
solenberg | 4bac9c5 | 2015-10-09 02:32:53 -0700 | [diff] [blame] | 418 | bool GetOutputVolume(uint32_t ssrc, double* volume) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 419 | if (output_scalings_.find(ssrc) == output_scalings_.end()) |
| 420 | return false; |
solenberg | 4bac9c5 | 2015-10-09 02:32:53 -0700 | [diff] [blame] | 421 | *volume = output_scalings_[ssrc]; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 422 | return true; |
| 423 | } |
| 424 | |
| 425 | virtual bool GetStats(VoiceMediaInfo* info) { return false; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 426 | |
Tommi | f888bb5 | 2015-12-12 01:37:01 +0100 | [diff] [blame] | 427 | virtual void SetRawAudioSink( |
| 428 | uint32_t ssrc, |
kwiberg | 686a8ef | 2016-02-26 03:00:35 -0800 | [diff] [blame] | 429 | std::unique_ptr<webrtc::AudioSinkInterface> sink) { |
deadbeef | 2d110be | 2016-01-13 12:00:26 -0800 | [diff] [blame] | 430 | sink_ = std::move(sink); |
Tommi | f888bb5 | 2015-12-12 01:37:01 +0100 | [diff] [blame] | 431 | } |
| 432 | |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 433 | virtual std::vector<webrtc::RtpSource> GetSources(uint32_t ssrc) const { |
| 434 | return std::vector<webrtc::RtpSource>(); |
| 435 | } |
| 436 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 437 | private: |
Taylor Brandstetter | 1a018dc | 2016-03-08 12:37:39 -0800 | [diff] [blame] | 438 | class VoiceChannelAudioSink : public AudioSource::Sink { |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 +0000 | [diff] [blame] | 439 | public: |
Taylor Brandstetter | 1a018dc | 2016-03-08 12:37:39 -0800 | [diff] [blame] | 440 | explicit VoiceChannelAudioSink(AudioSource* source) : source_(source) { |
| 441 | source_->SetSink(this); |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 +0000 | [diff] [blame] | 442 | } |
| 443 | virtual ~VoiceChannelAudioSink() { |
Taylor Brandstetter | 1a018dc | 2016-03-08 12:37:39 -0800 | [diff] [blame] | 444 | if (source_) { |
| 445 | source_->SetSink(nullptr); |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 +0000 | [diff] [blame] | 446 | } |
| 447 | } |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 448 | void OnData(const void* audio_data, |
| 449 | int bits_per_sample, |
| 450 | int sample_rate, |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 451 | size_t number_of_channels, |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 452 | size_t number_of_frames) override {} |
Taylor Brandstetter | 1a018dc | 2016-03-08 12:37:39 -0800 | [diff] [blame] | 453 | void OnClose() override { source_ = nullptr; } |
| 454 | AudioSource* source() const { return source_; } |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 +0000 | [diff] [blame] | 455 | |
| 456 | private: |
Taylor Brandstetter | 1a018dc | 2016-03-08 12:37:39 -0800 | [diff] [blame] | 457 | AudioSource* source_; |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 +0000 | [diff] [blame] | 458 | }; |
| 459 | |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 460 | bool SetRecvCodecs(const std::vector<AudioCodec>& codecs) { |
| 461 | if (fail_set_recv_codecs()) { |
| 462 | // Fake the failure in SetRecvCodecs. |
| 463 | return false; |
| 464 | } |
| 465 | recv_codecs_ = codecs; |
| 466 | return true; |
| 467 | } |
| 468 | bool SetSendCodecs(const std::vector<AudioCodec>& codecs) { |
| 469 | if (fail_set_send_codecs()) { |
| 470 | // Fake the failure in SetSendCodecs. |
| 471 | return false; |
| 472 | } |
| 473 | send_codecs_ = codecs; |
| 474 | return true; |
| 475 | } |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 476 | bool SetMaxSendBandwidth(int bps) { |
| 477 | max_bps_ = bps; |
| 478 | return true; |
| 479 | } |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 480 | bool SetOptions(const AudioOptions& options) { |
| 481 | // Does a "merge" of current options and set options. |
| 482 | options_.SetAll(options); |
| 483 | return true; |
| 484 | } |
Taylor Brandstetter | 1a018dc | 2016-03-08 12:37:39 -0800 | [diff] [blame] | 485 | bool SetLocalSource(uint32_t ssrc, AudioSource* source) { |
| 486 | auto it = local_sinks_.find(ssrc); |
| 487 | if (source) { |
| 488 | if (it != local_sinks_.end()) { |
nisse | c16fa5e | 2017-02-07 07:18:43 -0800 | [diff] [blame] | 489 | RTC_CHECK(it->second->source() == source); |
solenberg | 1dd98f3 | 2015-09-10 01:57:14 -0700 | [diff] [blame] | 490 | } else { |
Taylor Brandstetter | 1a018dc | 2016-03-08 12:37:39 -0800 | [diff] [blame] | 491 | local_sinks_.insert( |
| 492 | std::make_pair(ssrc, new VoiceChannelAudioSink(source))); |
solenberg | 1dd98f3 | 2015-09-10 01:57:14 -0700 | [diff] [blame] | 493 | } |
| 494 | } else { |
Taylor Brandstetter | 1a018dc | 2016-03-08 12:37:39 -0800 | [diff] [blame] | 495 | if (it != local_sinks_.end()) { |
solenberg | 1dd98f3 | 2015-09-10 01:57:14 -0700 | [diff] [blame] | 496 | delete it->second; |
Taylor Brandstetter | 1a018dc | 2016-03-08 12:37:39 -0800 | [diff] [blame] | 497 | local_sinks_.erase(it); |
solenberg | 1dd98f3 | 2015-09-10 01:57:14 -0700 | [diff] [blame] | 498 | } |
| 499 | } |
| 500 | return true; |
| 501 | } |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 +0000 | [diff] [blame] | 502 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 503 | FakeVoiceEngine* engine_; |
| 504 | std::vector<AudioCodec> recv_codecs_; |
| 505 | std::vector<AudioCodec> send_codecs_; |
solenberg | 4bac9c5 | 2015-10-09 02:32:53 -0700 | [diff] [blame] | 506 | std::map<uint32_t, double> output_scalings_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 507 | std::vector<DtmfInfo> dtmf_info_queue_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 508 | AudioOptions options_; |
Taylor Brandstetter | 1a018dc | 2016-03-08 12:37:39 -0800 | [diff] [blame] | 509 | std::map<uint32_t, VoiceChannelAudioSink*> local_sinks_; |
kwiberg | 686a8ef | 2016-02-26 03:00:35 -0800 | [diff] [blame] | 510 | std::unique_ptr<webrtc::AudioSinkInterface> sink_; |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 511 | int max_bps_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 512 | }; |
| 513 | |
| 514 | // A helper function to compare the FakeVoiceMediaChannel::DtmfInfo. |
| 515 | inline bool CompareDtmfInfo(const FakeVoiceMediaChannel::DtmfInfo& info, |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 516 | uint32_t ssrc, |
| 517 | int event_code, |
solenberg | 1d63dd0 | 2015-12-02 12:35:09 -0800 | [diff] [blame] | 518 | int duration) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 519 | return (info.duration == duration && info.event_code == event_code && |
solenberg | 1d63dd0 | 2015-12-02 12:35:09 -0800 | [diff] [blame] | 520 | info.ssrc == ssrc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 521 | } |
| 522 | |
| 523 | class FakeVideoMediaChannel : public RtpHelper<VideoMediaChannel> { |
| 524 | public: |
sprang | db2a9fc | 2017-08-09 06:42:32 -0700 | [diff] [blame] | 525 | FakeVideoMediaChannel(FakeVideoEngine* engine, const VideoOptions& options) |
Peter Boström | a6c39d9 | 2016-02-01 19:30:33 +0100 | [diff] [blame] | 526 | : engine_(engine), max_bps_(-1) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 527 | SetOptions(options); |
| 528 | } |
buildbot@webrtc.org | 1ecbe45 | 2014-10-14 20:29:28 +0000 | [diff] [blame] | 529 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 530 | ~FakeVideoMediaChannel(); |
| 531 | |
| 532 | const std::vector<VideoCodec>& recv_codecs() const { return recv_codecs_; } |
| 533 | const std::vector<VideoCodec>& send_codecs() const { return send_codecs_; } |
| 534 | const std::vector<VideoCodec>& codecs() const { return send_codecs(); } |
| 535 | bool rendering() const { return playout(); } |
| 536 | const VideoOptions& options() const { return options_; } |
nisse | acd935b | 2016-11-11 03:55:13 -0800 | [diff] [blame] | 537 | const std::map<uint32_t, rtc::VideoSinkInterface<webrtc::VideoFrame>*>& |
| 538 | sinks() const { |
nisse | 08582ff | 2016-02-04 01:24:52 -0800 | [diff] [blame] | 539 | return sinks_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 540 | } |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 541 | int max_bps() const { return max_bps_; } |
nisse | ef8b61e | 2016-04-29 06:09:15 -0700 | [diff] [blame] | 542 | bool SetSendParameters(const VideoSendParameters& params) override { |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 543 | set_send_rtcp_parameters(params.rtcp); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 544 | return (SetSendCodecs(params.codecs) && |
| 545 | SetSendRtpHeaderExtensions(params.extensions) && |
nisse | 0510331 | 2016-03-16 02:22:50 -0700 | [diff] [blame] | 546 | SetMaxSendBandwidth(params.max_bandwidth_bps)); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 547 | } |
nisse | ef8b61e | 2016-04-29 06:09:15 -0700 | [diff] [blame] | 548 | bool SetRecvParameters(const VideoRecvParameters& params) override { |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 549 | set_recv_rtcp_parameters(params.rtcp); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 550 | return (SetRecvCodecs(params.codecs) && |
| 551 | SetRecvRtpHeaderExtensions(params.extensions)); |
| 552 | } |
nisse | ef8b61e | 2016-04-29 06:09:15 -0700 | [diff] [blame] | 553 | bool AddSendStream(const StreamParams& sp) override { |
Peter Boström | ce23bee | 2016-02-02 14:14:30 +0100 | [diff] [blame] | 554 | return RtpHelper<VideoMediaChannel>::AddSendStream(sp); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 555 | } |
nisse | ef8b61e | 2016-04-29 06:09:15 -0700 | [diff] [blame] | 556 | bool RemoveSendStream(uint32_t ssrc) override { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 557 | return RtpHelper<VideoMediaChannel>::RemoveSendStream(ssrc); |
| 558 | } |
| 559 | |
nisse | ef8b61e | 2016-04-29 06:09:15 -0700 | [diff] [blame] | 560 | bool GetSendCodec(VideoCodec* send_codec) override { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 561 | if (send_codecs_.empty()) { |
| 562 | return false; |
| 563 | } |
| 564 | *send_codec = send_codecs_[0]; |
| 565 | return true; |
| 566 | } |
nisse | 08582ff | 2016-02-04 01:24:52 -0800 | [diff] [blame] | 567 | bool SetSink(uint32_t ssrc, |
nisse | acd935b | 2016-11-11 03:55:13 -0800 | [diff] [blame] | 568 | rtc::VideoSinkInterface<webrtc::VideoFrame>* sink) override { |
nisse | 08582ff | 2016-02-04 01:24:52 -0800 | [diff] [blame] | 569 | if (ssrc != 0 && sinks_.find(ssrc) == sinks_.end()) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 570 | return false; |
| 571 | } |
| 572 | if (ssrc != 0) { |
nisse | 08582ff | 2016-02-04 01:24:52 -0800 | [diff] [blame] | 573 | sinks_[ssrc] = sink; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 574 | } |
| 575 | return true; |
| 576 | } |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 577 | bool HasSink(uint32_t ssrc) const { |
| 578 | return sinks_.find(ssrc) != sinks_.end() && sinks_.at(ssrc) != nullptr; |
| 579 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 580 | |
nisse | ef8b61e | 2016-04-29 06:09:15 -0700 | [diff] [blame] | 581 | bool SetSend(bool send) override { return set_sending(send); } |
deadbeef | 5a4a75a | 2016-06-02 16:23:38 -0700 | [diff] [blame] | 582 | bool SetVideoSend( |
| 583 | uint32_t ssrc, |
| 584 | bool enable, |
| 585 | const VideoOptions* options, |
nisse | acd935b | 2016-11-11 03:55:13 -0800 | [diff] [blame] | 586 | rtc::VideoSourceInterface<webrtc::VideoFrame>* source) override { |
solenberg | dfc8f4f | 2015-10-01 02:31:10 -0700 | [diff] [blame] | 587 | if (!RtpHelper<VideoMediaChannel>::MuteStream(ssrc, !enable)) { |
solenberg | 1dd98f3 | 2015-09-10 01:57:14 -0700 | [diff] [blame] | 588 | return false; |
| 589 | } |
solenberg | dfc8f4f | 2015-10-01 02:31:10 -0700 | [diff] [blame] | 590 | if (enable && options) { |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 591 | if (!SetOptions(*options)) { |
| 592 | return false; |
| 593 | } |
solenberg | 1dd98f3 | 2015-09-10 01:57:14 -0700 | [diff] [blame] | 594 | } |
nisse | 2ded9b1 | 2016-04-08 02:23:55 -0700 | [diff] [blame] | 595 | sources_[ssrc] = source; |
deadbeef | 5a4a75a | 2016-06-02 16:23:38 -0700 | [diff] [blame] | 596 | return true; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 597 | } |
nisse | 2ded9b1 | 2016-04-08 02:23:55 -0700 | [diff] [blame] | 598 | |
| 599 | bool HasSource(uint32_t ssrc) const { |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 600 | return sources_.find(ssrc) != sources_.end() && |
| 601 | sources_.at(ssrc) != nullptr; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 602 | } |
nisse | ef8b61e | 2016-04-29 06:09:15 -0700 | [diff] [blame] | 603 | bool AddRecvStream(const StreamParams& sp) override { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 604 | if (!RtpHelper<VideoMediaChannel>::AddRecvStream(sp)) |
| 605 | return false; |
nisse | 08582ff | 2016-02-04 01:24:52 -0800 | [diff] [blame] | 606 | sinks_[sp.first_ssrc()] = NULL; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 607 | return true; |
| 608 | } |
nisse | ef8b61e | 2016-04-29 06:09:15 -0700 | [diff] [blame] | 609 | bool RemoveRecvStream(uint32_t ssrc) override { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 610 | if (!RtpHelper<VideoMediaChannel>::RemoveRecvStream(ssrc)) |
| 611 | return false; |
nisse | 08582ff | 2016-02-04 01:24:52 -0800 | [diff] [blame] | 612 | sinks_.erase(ssrc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 613 | return true; |
| 614 | } |
| 615 | |
stefan | f79ade1 | 2017-06-02 06:44:03 -0700 | [diff] [blame] | 616 | void FillBitrateInfo(BandwidthEstimationInfo* bwe_info) override {} |
nisse | ef8b61e | 2016-04-29 06:09:15 -0700 | [diff] [blame] | 617 | bool GetStats(VideoMediaInfo* info) override { return false; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 618 | |
| 619 | private: |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 620 | bool SetRecvCodecs(const std::vector<VideoCodec>& codecs) { |
| 621 | if (fail_set_recv_codecs()) { |
| 622 | // Fake the failure in SetRecvCodecs. |
| 623 | return false; |
| 624 | } |
| 625 | recv_codecs_ = codecs; |
| 626 | return true; |
| 627 | } |
| 628 | bool SetSendCodecs(const std::vector<VideoCodec>& codecs) { |
| 629 | if (fail_set_send_codecs()) { |
| 630 | // Fake the failure in SetSendCodecs. |
| 631 | return false; |
| 632 | } |
| 633 | send_codecs_ = codecs; |
| 634 | |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 635 | return true; |
| 636 | } |
| 637 | bool SetOptions(const VideoOptions& options) { |
| 638 | options_ = options; |
| 639 | return true; |
| 640 | } |
| 641 | bool SetMaxSendBandwidth(int bps) { |
| 642 | max_bps_ = bps; |
| 643 | return true; |
| 644 | } |
| 645 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 646 | FakeVideoEngine* engine_; |
| 647 | std::vector<VideoCodec> recv_codecs_; |
| 648 | std::vector<VideoCodec> send_codecs_; |
nisse | acd935b | 2016-11-11 03:55:13 -0800 | [diff] [blame] | 649 | std::map<uint32_t, rtc::VideoSinkInterface<webrtc::VideoFrame>*> sinks_; |
| 650 | std::map<uint32_t, rtc::VideoSourceInterface<webrtc::VideoFrame>*> sources_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 651 | VideoOptions options_; |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 652 | int max_bps_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 653 | }; |
| 654 | |
nisse | 0510331 | 2016-03-16 02:22:50 -0700 | [diff] [blame] | 655 | // Dummy option class, needed for the DataTraits abstraction in |
| 656 | // channel_unittest.c. |
| 657 | class DataOptions {}; |
| 658 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 659 | class FakeDataMediaChannel : public RtpHelper<DataMediaChannel> { |
| 660 | public: |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 661 | explicit FakeDataMediaChannel(void* unused, const DataOptions& options) |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 662 | : send_blocked_(false), max_bps_(-1) {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 663 | ~FakeDataMediaChannel() {} |
| 664 | const std::vector<DataCodec>& recv_codecs() const { return recv_codecs_; } |
| 665 | const std::vector<DataCodec>& send_codecs() const { return send_codecs_; } |
| 666 | const std::vector<DataCodec>& codecs() const { return send_codecs(); } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 667 | int max_bps() const { return max_bps_; } |
| 668 | |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 669 | virtual bool SetSendParameters(const DataSendParameters& params) { |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 670 | set_send_rtcp_parameters(params.rtcp); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 671 | return (SetSendCodecs(params.codecs) && |
| 672 | SetMaxSendBandwidth(params.max_bandwidth_bps)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 673 | } |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 674 | virtual bool SetRecvParameters(const DataRecvParameters& params) { |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 675 | set_recv_rtcp_parameters(params.rtcp); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 676 | return SetRecvCodecs(params.codecs); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 677 | } |
| 678 | virtual bool SetSend(bool send) { return set_sending(send); } |
| 679 | virtual bool SetReceive(bool receive) { |
| 680 | set_playout(receive); |
| 681 | return true; |
| 682 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 683 | virtual bool AddRecvStream(const StreamParams& sp) { |
| 684 | if (!RtpHelper<DataMediaChannel>::AddRecvStream(sp)) |
| 685 | return false; |
| 686 | return true; |
| 687 | } |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 688 | virtual bool RemoveRecvStream(uint32_t ssrc) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 689 | if (!RtpHelper<DataMediaChannel>::RemoveRecvStream(ssrc)) |
| 690 | return false; |
| 691 | return true; |
| 692 | } |
| 693 | |
| 694 | virtual bool SendData(const SendDataParams& params, |
jbauch | eec21bd | 2016-03-20 06:15:43 -0700 | [diff] [blame] | 695 | const rtc::CopyOnWriteBuffer& payload, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 696 | SendDataResult* result) { |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 697 | if (send_blocked_) { |
| 698 | *result = SDR_BLOCK; |
| 699 | return false; |
| 700 | } else { |
| 701 | last_sent_data_params_ = params; |
Karl Wiberg | 9478437 | 2015-04-20 14:03:07 +0200 | [diff] [blame] | 702 | last_sent_data_ = std::string(payload.data<char>(), payload.size()); |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 703 | return true; |
| 704 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 705 | } |
| 706 | |
| 707 | SendDataParams last_sent_data_params() { return last_sent_data_params_; } |
| 708 | std::string last_sent_data() { return last_sent_data_; } |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 709 | bool is_send_blocked() { return send_blocked_; } |
| 710 | void set_send_blocked(bool blocked) { send_blocked_ = blocked; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 711 | |
| 712 | private: |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 713 | bool SetRecvCodecs(const std::vector<DataCodec>& codecs) { |
| 714 | if (fail_set_recv_codecs()) { |
| 715 | // Fake the failure in SetRecvCodecs. |
| 716 | return false; |
| 717 | } |
| 718 | recv_codecs_ = codecs; |
| 719 | return true; |
| 720 | } |
| 721 | bool SetSendCodecs(const std::vector<DataCodec>& codecs) { |
| 722 | if (fail_set_send_codecs()) { |
| 723 | // Fake the failure in SetSendCodecs. |
| 724 | return false; |
| 725 | } |
| 726 | send_codecs_ = codecs; |
| 727 | return true; |
| 728 | } |
| 729 | bool SetMaxSendBandwidth(int bps) { |
| 730 | max_bps_ = bps; |
| 731 | return true; |
| 732 | } |
| 733 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 734 | std::vector<DataCodec> recv_codecs_; |
| 735 | std::vector<DataCodec> send_codecs_; |
| 736 | SendDataParams last_sent_data_params_; |
| 737 | std::string last_sent_data_; |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 738 | bool send_blocked_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 739 | int max_bps_; |
| 740 | }; |
| 741 | |
| 742 | // A base class for all of the shared parts between FakeVoiceEngine |
| 743 | // and FakeVideoEngine. |
| 744 | class FakeBaseEngine { |
| 745 | public: |
| 746 | FakeBaseEngine() |
solenberg | bd13838 | 2015-11-20 16:08:07 -0800 | [diff] [blame] | 747 | : options_changed_(false), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 748 | fail_create_channel_(false) {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 749 | void set_fail_create_channel(bool fail) { fail_create_channel_ = fail; } |
| 750 | |
Stefan Holmer | 9d69c3f | 2015-12-07 10:45:43 +0100 | [diff] [blame] | 751 | RtpCapabilities GetCapabilities() const { return capabilities_; } |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 752 | void set_rtp_header_extensions(const std::vector<RtpExtension>& extensions) { |
Stefan Holmer | 9d69c3f | 2015-12-07 10:45:43 +0100 | [diff] [blame] | 753 | capabilities_.header_extensions = extensions; |
henrike@webrtc.org | 79047f9 | 2014-03-06 23:46:59 +0000 | [diff] [blame] | 754 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 755 | |
isheriff | a1c548b | 2016-05-31 16:12:24 -0700 | [diff] [blame] | 756 | void set_rtp_header_extensions( |
| 757 | const std::vector<cricket::RtpHeaderExtension>& extensions) { |
| 758 | for (const cricket::RtpHeaderExtension& ext : extensions) { |
| 759 | RtpExtension webrtc_ext; |
| 760 | webrtc_ext.uri = ext.uri; |
| 761 | webrtc_ext.id = ext.id; |
| 762 | capabilities_.header_extensions.push_back(webrtc_ext); |
| 763 | } |
| 764 | } |
| 765 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 766 | protected: |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 767 | // Flag used by optionsmessagehandler_unittest for checking whether any |
| 768 | // relevant setting has been updated. |
| 769 | // TODO(thaloun): Replace with explicit checks of before & after values. |
| 770 | bool options_changed_; |
| 771 | bool fail_create_channel_; |
Stefan Holmer | 9d69c3f | 2015-12-07 10:45:43 +0100 | [diff] [blame] | 772 | RtpCapabilities capabilities_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 773 | }; |
| 774 | |
| 775 | class FakeVoiceEngine : public FakeBaseEngine { |
| 776 | public: |
magjed | 2475ae2 | 2017-09-12 04:42:15 -0700 | [diff] [blame^] | 777 | FakeVoiceEngine() { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 778 | // Add a fake audio codec. Note that the name must not be "" as there are |
| 779 | // sanity checks against that. |
deadbeef | 67cf2c1 | 2016-04-13 10:07:16 -0700 | [diff] [blame] | 780 | codecs_.push_back(AudioCodec(101, "fake_audio_codec", 0, 0, 1)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 781 | } |
deadbeef | eb02c03 | 2017-06-15 08:29:25 -0700 | [diff] [blame] | 782 | void Init() {} |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 783 | rtc::scoped_refptr<webrtc::AudioState> GetAudioState() const { |
| 784 | return rtc::scoped_refptr<webrtc::AudioState>(); |
| 785 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 786 | |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 787 | VoiceMediaChannel* CreateChannel(webrtc::Call* call, |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 788 | const MediaConfig& config, |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 789 | const AudioOptions& options) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 790 | if (fail_create_channel_) { |
Jelena Marusic | c28a896 | 2015-05-29 15:05:44 +0200 | [diff] [blame] | 791 | return nullptr; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 792 | } |
| 793 | |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 794 | FakeVoiceMediaChannel* ch = new FakeVoiceMediaChannel(this, options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 795 | channels_.push_back(ch); |
| 796 | return ch; |
| 797 | } |
| 798 | FakeVoiceMediaChannel* GetChannel(size_t index) { |
| 799 | return (channels_.size() > index) ? channels_[index] : NULL; |
| 800 | } |
| 801 | void UnregisterChannel(VoiceMediaChannel* channel) { |
| 802 | channels_.erase(std::find(channels_.begin(), channels_.end(), channel)); |
| 803 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 804 | |
ossu | dedfd28 | 2016-06-14 07:12:39 -0700 | [diff] [blame] | 805 | // TODO(ossu): For proper testing, These should either individually settable |
| 806 | // or the voice engine should reference mockable factories. |
| 807 | const std::vector<AudioCodec>& send_codecs() { return codecs_; } |
| 808 | const std::vector<AudioCodec>& recv_codecs() { return codecs_; } |
| 809 | void SetCodecs(const std::vector<AudioCodec>& codecs) { codecs_ = codecs; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 810 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 811 | int GetInputLevel() { return 0; } |
| 812 | |
ivoc | d66b44d | 2016-01-15 03:06:36 -0800 | [diff] [blame] | 813 | bool StartAecDump(rtc::PlatformFile file, int64_t max_size_bytes) { |
| 814 | return false; |
| 815 | } |
wu@webrtc.org | a989080 | 2013-12-13 00:21:03 +0000 | [diff] [blame] | 816 | |
ivoc | 797ef12 | 2015-10-22 03:25:41 -0700 | [diff] [blame] | 817 | void StopAecDump() {} |
| 818 | |
ivoc | c1513ee | 2016-05-13 08:30:39 -0700 | [diff] [blame] | 819 | bool StartRtcEventLog(rtc::PlatformFile file, int64_t max_size_bytes) { |
| 820 | return false; |
| 821 | } |
ivoc | 112a3d8 | 2015-10-16 02:22:18 -0700 | [diff] [blame] | 822 | |
| 823 | void StopRtcEventLog() {} |
| 824 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 825 | private: |
| 826 | std::vector<FakeVoiceMediaChannel*> channels_; |
| 827 | std::vector<AudioCodec> codecs_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 828 | |
| 829 | friend class FakeMediaEngine; |
| 830 | }; |
| 831 | |
| 832 | class FakeVideoEngine : public FakeBaseEngine { |
| 833 | public: |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 834 | FakeVideoEngine() : capture_(false) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 835 | // Add a fake video codec. Note that the name must not be "" as there are |
| 836 | // sanity checks against that. |
perkj | 2675274 | 2016-10-24 01:21:16 -0700 | [diff] [blame] | 837 | codecs_.push_back(VideoCodec(0, "fake_video_codec")); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 838 | } |
sprang | db2a9fc | 2017-08-09 06:42:32 -0700 | [diff] [blame] | 839 | |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 840 | bool SetOptions(const VideoOptions& options) { |
| 841 | options_ = options; |
| 842 | options_changed_ = true; |
| 843 | return true; |
| 844 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 845 | |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 846 | VideoMediaChannel* CreateChannel(webrtc::Call* call, |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 847 | const MediaConfig& config, |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 848 | const VideoOptions& options) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 849 | if (fail_create_channel_) { |
sprang | db2a9fc | 2017-08-09 06:42:32 -0700 | [diff] [blame] | 850 | return nullptr; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 851 | } |
| 852 | |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 853 | FakeVideoMediaChannel* ch = new FakeVideoMediaChannel(this, options); |
sprang | db2a9fc | 2017-08-09 06:42:32 -0700 | [diff] [blame] | 854 | channels_.emplace_back(ch); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 855 | return ch; |
| 856 | } |
sprang | db2a9fc | 2017-08-09 06:42:32 -0700 | [diff] [blame] | 857 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 858 | FakeVideoMediaChannel* GetChannel(size_t index) { |
sprang | db2a9fc | 2017-08-09 06:42:32 -0700 | [diff] [blame] | 859 | return (channels_.size() > index) ? channels_[index] : nullptr; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 860 | } |
sprang | db2a9fc | 2017-08-09 06:42:32 -0700 | [diff] [blame] | 861 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 862 | void UnregisterChannel(VideoMediaChannel* channel) { |
sprang | db2a9fc | 2017-08-09 06:42:32 -0700 | [diff] [blame] | 863 | auto it = std::find(channels_.begin(), channels_.end(), channel); |
| 864 | RTC_DCHECK(it != channels_.end()); |
| 865 | channels_.erase(it); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 866 | } |
| 867 | |
| 868 | const std::vector<VideoCodec>& codecs() const { return codecs_; } |
sprang | db2a9fc | 2017-08-09 06:42:32 -0700 | [diff] [blame] | 869 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 870 | void SetCodecs(const std::vector<VideoCodec> codecs) { codecs_ = codecs; } |
| 871 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 872 | bool SetCapture(bool capture) { |
| 873 | capture_ = capture; |
| 874 | return true; |
| 875 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 876 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 877 | private: |
| 878 | std::vector<FakeVideoMediaChannel*> channels_; |
| 879 | std::vector<VideoCodec> codecs_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 880 | bool capture_; |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 881 | VideoOptions options_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 882 | |
| 883 | friend class FakeMediaEngine; |
| 884 | }; |
| 885 | |
| 886 | class FakeMediaEngine : |
| 887 | public CompositeMediaEngine<FakeVoiceEngine, FakeVideoEngine> { |
| 888 | public: |
ossu | 29b1a8d | 2016-06-13 07:34:51 -0700 | [diff] [blame] | 889 | FakeMediaEngine() |
magjed | 2475ae2 | 2017-09-12 04:42:15 -0700 | [diff] [blame^] | 890 | : CompositeMediaEngine<FakeVoiceEngine, FakeVideoEngine>(std::tuple<>(), |
| 891 | std::tuple<>()) { |
| 892 | } |
| 893 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 894 | virtual ~FakeMediaEngine() {} |
| 895 | |
henrike@webrtc.org | 79047f9 | 2014-03-06 23:46:59 +0000 | [diff] [blame] | 896 | void SetAudioCodecs(const std::vector<AudioCodec>& codecs) { |
magjed | 2475ae2 | 2017-09-12 04:42:15 -0700 | [diff] [blame^] | 897 | voice().SetCodecs(codecs); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 898 | } |
henrike@webrtc.org | 79047f9 | 2014-03-06 23:46:59 +0000 | [diff] [blame] | 899 | void SetVideoCodecs(const std::vector<VideoCodec>& codecs) { |
magjed | 2475ae2 | 2017-09-12 04:42:15 -0700 | [diff] [blame^] | 900 | video().SetCodecs(codecs); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 901 | } |
| 902 | |
henrike@webrtc.org | 79047f9 | 2014-03-06 23:46:59 +0000 | [diff] [blame] | 903 | void SetAudioRtpHeaderExtensions( |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 904 | const std::vector<RtpExtension>& extensions) { |
magjed | 2475ae2 | 2017-09-12 04:42:15 -0700 | [diff] [blame^] | 905 | voice().set_rtp_header_extensions(extensions); |
henrike@webrtc.org | 79047f9 | 2014-03-06 23:46:59 +0000 | [diff] [blame] | 906 | } |
| 907 | void SetVideoRtpHeaderExtensions( |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 908 | const std::vector<RtpExtension>& extensions) { |
magjed | 2475ae2 | 2017-09-12 04:42:15 -0700 | [diff] [blame^] | 909 | video().set_rtp_header_extensions(extensions); |
henrike@webrtc.org | 79047f9 | 2014-03-06 23:46:59 +0000 | [diff] [blame] | 910 | } |
| 911 | |
isheriff | a1c548b | 2016-05-31 16:12:24 -0700 | [diff] [blame] | 912 | void SetAudioRtpHeaderExtensions( |
| 913 | const std::vector<cricket::RtpHeaderExtension>& extensions) { |
magjed | 2475ae2 | 2017-09-12 04:42:15 -0700 | [diff] [blame^] | 914 | voice().set_rtp_header_extensions(extensions); |
isheriff | a1c548b | 2016-05-31 16:12:24 -0700 | [diff] [blame] | 915 | } |
| 916 | void SetVideoRtpHeaderExtensions( |
| 917 | const std::vector<cricket::RtpHeaderExtension>& extensions) { |
magjed | 2475ae2 | 2017-09-12 04:42:15 -0700 | [diff] [blame^] | 918 | video().set_rtp_header_extensions(extensions); |
isheriff | a1c548b | 2016-05-31 16:12:24 -0700 | [diff] [blame] | 919 | } |
| 920 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 921 | FakeVoiceMediaChannel* GetVoiceChannel(size_t index) { |
magjed | 2475ae2 | 2017-09-12 04:42:15 -0700 | [diff] [blame^] | 922 | return voice().GetChannel(index); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 923 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 924 | FakeVideoMediaChannel* GetVideoChannel(size_t index) { |
magjed | 2475ae2 | 2017-09-12 04:42:15 -0700 | [diff] [blame^] | 925 | return video().GetChannel(index); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 926 | } |
| 927 | |
magjed | 2475ae2 | 2017-09-12 04:42:15 -0700 | [diff] [blame^] | 928 | bool capture() const { return video().capture_; } |
| 929 | bool options_changed() const { return video().options_changed_; } |
| 930 | void clear_options_changed() { video().options_changed_ = false; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 931 | void set_fail_create_channel(bool fail) { |
magjed | 2475ae2 | 2017-09-12 04:42:15 -0700 | [diff] [blame^] | 932 | voice().set_fail_create_channel(fail); |
| 933 | video().set_fail_create_channel(fail); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 934 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 935 | }; |
| 936 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 937 | // Have to come afterwards due to declaration order |
| 938 | inline FakeVoiceMediaChannel::~FakeVoiceMediaChannel() { |
| 939 | if (engine_) { |
| 940 | engine_->UnregisterChannel(this); |
| 941 | } |
| 942 | } |
| 943 | |
| 944 | inline FakeVideoMediaChannel::~FakeVideoMediaChannel() { |
| 945 | if (engine_) { |
| 946 | engine_->UnregisterChannel(this); |
| 947 | } |
| 948 | } |
| 949 | |
| 950 | class FakeDataEngine : public DataEngineInterface { |
| 951 | public: |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 952 | FakeDataEngine(){}; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 953 | |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 954 | virtual DataMediaChannel* CreateChannel(const MediaConfig& config) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 955 | FakeDataMediaChannel* ch = new FakeDataMediaChannel(this, DataOptions()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 956 | channels_.push_back(ch); |
| 957 | return ch; |
| 958 | } |
| 959 | |
| 960 | FakeDataMediaChannel* GetChannel(size_t index) { |
| 961 | return (channels_.size() > index) ? channels_[index] : NULL; |
| 962 | } |
| 963 | |
| 964 | void UnregisterChannel(DataMediaChannel* channel) { |
| 965 | channels_.erase(std::find(channels_.begin(), channels_.end(), channel)); |
| 966 | } |
| 967 | |
| 968 | virtual void SetDataCodecs(const std::vector<DataCodec>& data_codecs) { |
| 969 | data_codecs_ = data_codecs; |
| 970 | } |
| 971 | |
| 972 | virtual const std::vector<DataCodec>& data_codecs() { return data_codecs_; } |
| 973 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 974 | private: |
| 975 | std::vector<FakeDataMediaChannel*> channels_; |
| 976 | std::vector<DataCodec> data_codecs_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 977 | }; |
| 978 | |
| 979 | } // namespace cricket |
| 980 | |
kjellander | a96e2d7 | 2016-02-04 23:52:28 -0800 | [diff] [blame] | 981 | #endif // WEBRTC_MEDIA_BASE_FAKEMEDIAENGINE_H_ |