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