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 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 11 | #ifndef MEDIA_BASE_FAKE_MEDIA_ENGINE_H_ |
| 12 | #define MEDIA_BASE_FAKE_MEDIA_ENGINE_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> |
Steve Anton | e78bcb9 | 2017-10-31 09:53:08 -0700 | [diff] [blame] | 19 | #include <tuple> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 20 | #include <vector> |
| 21 | |
Steve Anton | 2c9ebef | 2019-01-28 17:27:58 -0800 | [diff] [blame] | 22 | #include "absl/algorithm/container.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 23 | #include "api/call/audio_sink.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 24 | #include "media/base/audio_source.h" |
| 25 | #include "media/base/media_engine.h" |
| 26 | #include "media/base/rtp_utils.h" |
| 27 | #include "media/base/stream_params.h" |
| 28 | #include "media/engine/webrtc_video_engine.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 29 | #include "modules/audio_processing/include/audio_processing.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 30 | #include "rtc_base/copy_on_write_buffer.h" |
| 31 | #include "rtc_base/network_route.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 32 | |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 33 | using webrtc::RtpExtension; |
| 34 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 35 | namespace cricket { |
| 36 | |
| 37 | class FakeMediaEngine; |
| 38 | class FakeVideoEngine; |
| 39 | class FakeVoiceEngine; |
| 40 | |
| 41 | // A common helper class that handles sending and receiving RTP/RTCP packets. |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 42 | template <class Base> |
| 43 | class RtpHelper : public Base { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 44 | public: |
| 45 | RtpHelper() |
| 46 | : sending_(false), |
| 47 | playout_(false), |
| 48 | fail_set_send_codecs_(false), |
| 49 | fail_set_recv_codecs_(false), |
| 50 | send_ssrc_(0), |
sprang | db2a9fc | 2017-08-09 06:42:32 -0700 | [diff] [blame] | 51 | ready_to_send_(false), |
| 52 | transport_overhead_per_packet_(0), |
| 53 | num_network_route_changes_(0) {} |
| 54 | virtual ~RtpHelper() = default; |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 55 | const std::vector<RtpExtension>& recv_extensions() { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 56 | return recv_extensions_; |
| 57 | } |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 58 | const std::vector<RtpExtension>& send_extensions() { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 59 | return send_extensions_; |
| 60 | } |
| 61 | bool sending() const { return sending_; } |
| 62 | bool playout() const { return playout_; } |
| 63 | const std::list<std::string>& rtp_packets() const { return rtp_packets_; } |
| 64 | const std::list<std::string>& rtcp_packets() const { return rtcp_packets_; } |
| 65 | |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 66 | bool SendRtp(const void* data, |
| 67 | size_t len, |
| 68 | const rtc::PacketOptions& options) { |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 69 | if (!sending_) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 70 | return false; |
| 71 | } |
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::SendPacket(&packet, options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 75 | } |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 76 | bool SendRtcp(const void* data, size_t len) { |
jbauch | eec21bd | 2016-03-20 06:15:43 -0700 | [diff] [blame] | 77 | rtc::CopyOnWriteBuffer packet(reinterpret_cast<const uint8_t*>(data), len, |
| 78 | kMaxRtpPacketLen); |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 79 | return Base::SendRtcp(&packet, rtc::PacketOptions()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 80 | } |
| 81 | |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 82 | bool CheckRtp(const void* data, size_t len) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 83 | bool success = !rtp_packets_.empty(); |
| 84 | if (success) { |
| 85 | std::string packet = rtp_packets_.front(); |
| 86 | rtp_packets_.pop_front(); |
| 87 | success = (packet == std::string(static_cast<const char*>(data), len)); |
| 88 | } |
| 89 | return success; |
| 90 | } |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 91 | bool CheckRtcp(const void* data, size_t len) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 92 | bool success = !rtcp_packets_.empty(); |
| 93 | if (success) { |
| 94 | std::string packet = rtcp_packets_.front(); |
| 95 | rtcp_packets_.pop_front(); |
| 96 | success = (packet == std::string(static_cast<const char*>(data), len)); |
| 97 | } |
| 98 | return success; |
| 99 | } |
| 100 | bool CheckNoRtp() { return rtp_packets_.empty(); } |
| 101 | bool CheckNoRtcp() { return rtcp_packets_.empty(); } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 102 | void set_fail_set_send_codecs(bool fail) { fail_set_send_codecs_ = fail; } |
| 103 | void set_fail_set_recv_codecs(bool fail) { fail_set_recv_codecs_ = fail; } |
| 104 | virtual bool AddSendStream(const StreamParams& sp) { |
Steve Anton | 2c9ebef | 2019-01-28 17:27:58 -0800 | [diff] [blame] | 105 | if (absl::c_linear_search(send_streams_, sp)) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 106 | return false; |
| 107 | } |
| 108 | send_streams_.push_back(sp); |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 109 | rtp_send_parameters_[sp.first_ssrc()] = |
Seth Hampson | 2d2c888 | 2018-05-16 16:02:32 -0700 | [diff] [blame] | 110 | CreateRtpParametersWithEncodings(sp); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 111 | return true; |
| 112 | } |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 113 | virtual bool RemoveSendStream(uint32_t ssrc) { |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 114 | auto parameters_iterator = rtp_send_parameters_.find(ssrc); |
| 115 | if (parameters_iterator != rtp_send_parameters_.end()) { |
| 116 | rtp_send_parameters_.erase(parameters_iterator); |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 117 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 118 | return RemoveStreamBySsrc(&send_streams_, ssrc); |
| 119 | } |
Saurav Das | ff27da5 | 2019-09-20 11:05:30 -0700 | [diff] [blame^] | 120 | virtual void ResetUnsignaledRecvStream() {} |
| 121 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 122 | virtual bool AddRecvStream(const StreamParams& sp) { |
Steve Anton | 2c9ebef | 2019-01-28 17:27:58 -0800 | [diff] [blame] | 123 | if (absl::c_linear_search(receive_streams_, sp)) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 124 | return false; |
| 125 | } |
| 126 | receive_streams_.push_back(sp); |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 127 | rtp_receive_parameters_[sp.first_ssrc()] = |
Florent Castelli | 38332cd | 2018-11-20 14:08:06 +0100 | [diff] [blame] | 128 | CreateRtpParametersWithEncodings(sp); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 129 | return true; |
| 130 | } |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 131 | virtual bool RemoveRecvStream(uint32_t ssrc) { |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 132 | auto parameters_iterator = rtp_receive_parameters_.find(ssrc); |
| 133 | if (parameters_iterator != rtp_receive_parameters_.end()) { |
| 134 | rtp_receive_parameters_.erase(parameters_iterator); |
| 135 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 136 | return RemoveStreamBySsrc(&receive_streams_, ssrc); |
| 137 | } |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 138 | |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 139 | virtual webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const { |
| 140 | auto parameters_iterator = rtp_send_parameters_.find(ssrc); |
| 141 | if (parameters_iterator != rtp_send_parameters_.end()) { |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 142 | return parameters_iterator->second; |
| 143 | } |
| 144 | return webrtc::RtpParameters(); |
| 145 | } |
Zach Stein | ba37b4b | 2018-01-23 15:02:36 -0800 | [diff] [blame] | 146 | virtual webrtc::RTCError SetRtpSendParameters( |
| 147 | uint32_t ssrc, |
| 148 | const webrtc::RtpParameters& parameters) { |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 149 | auto parameters_iterator = rtp_send_parameters_.find(ssrc); |
| 150 | if (parameters_iterator != rtp_send_parameters_.end()) { |
Florent Castelli | c1a0bcb | 2019-01-29 14:26:48 +0100 | [diff] [blame] | 151 | auto result = CheckRtpParametersInvalidModificationAndValues( |
| 152 | parameters_iterator->second, parameters); |
Florent Castelli | 892acf0 | 2018-10-01 22:47:20 +0200 | [diff] [blame] | 153 | if (!result.ok()) |
| 154 | return result; |
| 155 | |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 156 | parameters_iterator->second = parameters; |
Zach Stein | ba37b4b | 2018-01-23 15:02:36 -0800 | [diff] [blame] | 157 | return webrtc::RTCError::OK(); |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 158 | } |
| 159 | // Replicate the behavior of the real media channel: return false |
| 160 | // when setting parameters for unknown SSRCs. |
Zach Stein | ba37b4b | 2018-01-23 15:02:36 -0800 | [diff] [blame] | 161 | return webrtc::RTCError(webrtc::RTCErrorType::INTERNAL_ERROR); |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | virtual webrtc::RtpParameters GetRtpReceiveParameters(uint32_t ssrc) const { |
| 165 | auto parameters_iterator = rtp_receive_parameters_.find(ssrc); |
| 166 | if (parameters_iterator != rtp_receive_parameters_.end()) { |
| 167 | return parameters_iterator->second; |
| 168 | } |
| 169 | return webrtc::RtpParameters(); |
| 170 | } |
| 171 | virtual bool SetRtpReceiveParameters( |
| 172 | uint32_t ssrc, |
| 173 | const webrtc::RtpParameters& parameters) { |
| 174 | auto parameters_iterator = rtp_receive_parameters_.find(ssrc); |
| 175 | if (parameters_iterator != rtp_receive_parameters_.end()) { |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 176 | parameters_iterator->second = parameters; |
| 177 | return true; |
| 178 | } |
| 179 | // Replicate the behavior of the real media channel: return false |
| 180 | // when setting parameters for unknown SSRCs. |
| 181 | return false; |
| 182 | } |
| 183 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 184 | bool IsStreamMuted(uint32_t ssrc) const { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 185 | bool ret = muted_streams_.find(ssrc) != muted_streams_.end(); |
| 186 | // If |ssrc = 0| check if the first send stream is muted. |
| 187 | if (!ret && ssrc == 0 && !send_streams_.empty()) { |
| 188 | return muted_streams_.find(send_streams_[0].first_ssrc()) != |
| 189 | muted_streams_.end(); |
| 190 | } |
| 191 | return ret; |
| 192 | } |
| 193 | const std::vector<StreamParams>& send_streams() const { |
| 194 | return send_streams_; |
| 195 | } |
| 196 | const std::vector<StreamParams>& recv_streams() const { |
| 197 | return receive_streams_; |
| 198 | } |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 199 | bool HasRecvStream(uint32_t ssrc) const { |
tommi@webrtc.org | 586f2ed | 2015-01-22 23:00:41 +0000 | [diff] [blame] | 200 | return GetStreamBySsrc(receive_streams_, ssrc) != nullptr; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 201 | } |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 202 | bool HasSendStream(uint32_t ssrc) const { |
tommi@webrtc.org | 586f2ed | 2015-01-22 23:00:41 +0000 | [diff] [blame] | 203 | return GetStreamBySsrc(send_streams_, ssrc) != nullptr; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 204 | } |
| 205 | // TODO(perkj): This is to support legacy unit test that only check one |
| 206 | // sending stream. |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 207 | uint32_t send_ssrc() const { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 208 | if (send_streams_.empty()) |
| 209 | return 0; |
| 210 | return send_streams_[0].first_ssrc(); |
| 211 | } |
| 212 | |
| 213 | // TODO(perkj): This is to support legacy unit test that only check one |
| 214 | // sending stream. |
| 215 | const std::string rtcp_cname() { |
| 216 | if (send_streams_.empty()) |
| 217 | return ""; |
| 218 | return send_streams_[0].cname; |
| 219 | } |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 220 | const RtcpParameters& send_rtcp_parameters() { return send_rtcp_parameters_; } |
| 221 | const RtcpParameters& recv_rtcp_parameters() { return recv_rtcp_parameters_; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 222 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 223 | bool ready_to_send() const { return ready_to_send_; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 224 | |
michaelt | 79e0588 | 2016-11-08 02:50:09 -0800 | [diff] [blame] | 225 | int transport_overhead_per_packet() const { |
| 226 | return transport_overhead_per_packet_; |
| 227 | } |
| 228 | |
Honghai Zhang | 0e533ef | 2016-04-19 15:41:36 -0700 | [diff] [blame] | 229 | rtc::NetworkRoute last_network_route() const { return last_network_route_; } |
Honghai Zhang | cc411c0 | 2016-03-29 17:27:21 -0700 | [diff] [blame] | 230 | int num_network_route_changes() const { return num_network_route_changes_; } |
| 231 | void set_num_network_route_changes(int changes) { |
| 232 | num_network_route_changes_ = changes; |
| 233 | } |
| 234 | |
Sebastian Jansson | 1b83a9e | 2019-09-18 18:22:12 +0200 | [diff] [blame] | 235 | void OnRtcpPacketReceived(rtc::CopyOnWriteBuffer* packet, |
| 236 | int64_t packet_time_us) { |
| 237 | rtcp_packets_.push_back(std::string(packet->cdata<char>(), packet->size())); |
| 238 | } |
| 239 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 240 | protected: |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 241 | bool MuteStream(uint32_t ssrc, bool mute) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 242 | if (!HasSendStream(ssrc) && ssrc != 0) { |
solenberg | 1dd98f3 | 2015-09-10 01:57:14 -0700 | [diff] [blame] | 243 | return false; |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 244 | } |
| 245 | if (mute) { |
solenberg | 1dd98f3 | 2015-09-10 01:57:14 -0700 | [diff] [blame] | 246 | muted_streams_.insert(ssrc); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 247 | } else { |
solenberg | 1dd98f3 | 2015-09-10 01:57:14 -0700 | [diff] [blame] | 248 | muted_streams_.erase(ssrc); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 249 | } |
solenberg | 1dd98f3 | 2015-09-10 01:57:14 -0700 | [diff] [blame] | 250 | return true; |
| 251 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 252 | bool set_sending(bool send) { |
| 253 | sending_ = send; |
| 254 | return true; |
| 255 | } |
| 256 | void set_playout(bool playout) { playout_ = playout; } |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 257 | bool SetRecvRtpHeaderExtensions(const std::vector<RtpExtension>& extensions) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 258 | recv_extensions_ = extensions; |
| 259 | return true; |
| 260 | } |
Johannes Kron | 9190b82 | 2018-10-29 11:22:05 +0100 | [diff] [blame] | 261 | bool SetSendExtmapAllowMixed(bool extmap_allow_mixed) { |
| 262 | if (Base::ExtmapAllowMixed() != extmap_allow_mixed) { |
| 263 | Base::SetExtmapAllowMixed(extmap_allow_mixed); |
| 264 | } |
| 265 | return true; |
| 266 | } |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 267 | bool SetSendRtpHeaderExtensions(const std::vector<RtpExtension>& extensions) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 268 | send_extensions_ = extensions; |
| 269 | return true; |
| 270 | } |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 271 | void set_send_rtcp_parameters(const RtcpParameters& params) { |
| 272 | send_rtcp_parameters_ = params; |
| 273 | } |
| 274 | void set_recv_rtcp_parameters(const RtcpParameters& params) { |
| 275 | recv_rtcp_parameters_ = params; |
| 276 | } |
Amit Hilbuch | e7a5f7b | 2019-03-12 11:10:27 -0700 | [diff] [blame] | 277 | virtual void OnPacketReceived(rtc::CopyOnWriteBuffer packet, |
Niels Möller | e693381 | 2018-11-05 13:01:41 +0100 | [diff] [blame] | 278 | int64_t packet_time_us) { |
Amit Hilbuch | e7a5f7b | 2019-03-12 11:10:27 -0700 | [diff] [blame] | 279 | rtp_packets_.push_back(std::string(packet.cdata<char>(), packet.size())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 280 | } |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 281 | virtual void OnReadyToSend(bool ready) { ready_to_send_ = ready; } |
michaelt | 79e0588 | 2016-11-08 02:50:09 -0800 | [diff] [blame] | 282 | |
Honghai Zhang | cc411c0 | 2016-03-29 17:27:21 -0700 | [diff] [blame] | 283 | virtual void OnNetworkRouteChanged(const std::string& transport_name, |
Honghai Zhang | 0e533ef | 2016-04-19 15:41:36 -0700 | [diff] [blame] | 284 | const rtc::NetworkRoute& network_route) { |
Honghai Zhang | cc411c0 | 2016-03-29 17:27:21 -0700 | [diff] [blame] | 285 | last_network_route_ = network_route; |
| 286 | ++num_network_route_changes_; |
Zhi Huang | 5f5918f | 2017-11-12 17:26:23 -0800 | [diff] [blame] | 287 | transport_overhead_per_packet_ = network_route.packet_overhead; |
Honghai Zhang | cc411c0 | 2016-03-29 17:27:21 -0700 | [diff] [blame] | 288 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 289 | bool fail_set_send_codecs() const { return fail_set_send_codecs_; } |
| 290 | bool fail_set_recv_codecs() const { return fail_set_recv_codecs_; } |
| 291 | |
| 292 | private: |
| 293 | bool sending_; |
| 294 | bool playout_; |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 295 | std::vector<RtpExtension> recv_extensions_; |
| 296 | std::vector<RtpExtension> send_extensions_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 297 | std::list<std::string> rtp_packets_; |
| 298 | std::list<std::string> rtcp_packets_; |
| 299 | std::vector<StreamParams> send_streams_; |
| 300 | std::vector<StreamParams> receive_streams_; |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 301 | RtcpParameters send_rtcp_parameters_; |
| 302 | RtcpParameters recv_rtcp_parameters_; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 303 | std::set<uint32_t> muted_streams_; |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 304 | std::map<uint32_t, webrtc::RtpParameters> rtp_send_parameters_; |
| 305 | std::map<uint32_t, webrtc::RtpParameters> rtp_receive_parameters_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 306 | bool fail_set_send_codecs_; |
| 307 | bool fail_set_recv_codecs_; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 308 | uint32_t send_ssrc_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 309 | std::string rtcp_cname_; |
| 310 | bool ready_to_send_; |
michaelt | 79e0588 | 2016-11-08 02:50:09 -0800 | [diff] [blame] | 311 | int transport_overhead_per_packet_; |
Honghai Zhang | 0e533ef | 2016-04-19 15:41:36 -0700 | [diff] [blame] | 312 | rtc::NetworkRoute last_network_route_; |
sprang | db2a9fc | 2017-08-09 06:42:32 -0700 | [diff] [blame] | 313 | int num_network_route_changes_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 314 | }; |
| 315 | |
| 316 | class FakeVoiceMediaChannel : public RtpHelper<VoiceMediaChannel> { |
| 317 | public: |
| 318 | struct DtmfInfo { |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 319 | DtmfInfo(uint32_t ssrc, int event_code, int duration); |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 320 | uint32_t ssrc; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 321 | int event_code; |
| 322 | int duration; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 323 | }; |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 324 | explicit FakeVoiceMediaChannel(FakeVoiceEngine* engine, |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 325 | const AudioOptions& options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 326 | ~FakeVoiceMediaChannel(); |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 327 | const std::vector<AudioCodec>& recv_codecs() const; |
| 328 | const std::vector<AudioCodec>& send_codecs() const; |
| 329 | const std::vector<AudioCodec>& codecs() const; |
| 330 | const std::vector<DtmfInfo>& dtmf_info_queue() const; |
| 331 | const AudioOptions& options() const; |
| 332 | int max_bps() const; |
| 333 | bool SetSendParameters(const AudioSendParameters& params) override; |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 334 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 335 | bool SetRecvParameters(const AudioRecvParameters& params) override; |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 336 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 337 | void SetPlayout(bool playout) override; |
| 338 | void SetSend(bool send) override; |
| 339 | bool SetAudioSend(uint32_t ssrc, |
| 340 | bool enable, |
| 341 | const AudioOptions* options, |
| 342 | AudioSource* source) override; |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 343 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 344 | bool HasSource(uint32_t ssrc) const; |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 345 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 346 | bool AddRecvStream(const StreamParams& sp) override; |
| 347 | bool RemoveRecvStream(uint32_t ssrc) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 348 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 349 | bool CanInsertDtmf() override; |
| 350 | bool InsertDtmf(uint32_t ssrc, int event_code, int duration) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 351 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 352 | bool SetOutputVolume(uint32_t ssrc, double volume) override; |
| 353 | bool GetOutputVolume(uint32_t ssrc, double* volume); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 354 | |
Ruslan Burakov | 7ea4605 | 2019-02-16 02:07:05 +0100 | [diff] [blame] | 355 | bool SetBaseMinimumPlayoutDelayMs(uint32_t ssrc, int delay_ms) override; |
| 356 | absl::optional<int> GetBaseMinimumPlayoutDelayMs( |
| 357 | uint32_t ssrc) const override; |
| 358 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 359 | bool GetStats(VoiceMediaInfo* info) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 360 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 361 | void SetRawAudioSink( |
Tommi | f888bb5 | 2015-12-12 01:37:01 +0100 | [diff] [blame] | 362 | uint32_t ssrc, |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 363 | std::unique_ptr<webrtc::AudioSinkInterface> sink) override; |
Tommi | f888bb5 | 2015-12-12 01:37:01 +0100 | [diff] [blame] | 364 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 365 | std::vector<webrtc::RtpSource> GetSources(uint32_t ssrc) const override; |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 366 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 367 | private: |
Taylor Brandstetter | 1a018dc | 2016-03-08 12:37:39 -0800 | [diff] [blame] | 368 | class VoiceChannelAudioSink : public AudioSource::Sink { |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 +0000 | [diff] [blame] | 369 | public: |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 370 | explicit VoiceChannelAudioSink(AudioSource* source); |
| 371 | ~VoiceChannelAudioSink() override; |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 372 | void OnData(const void* audio_data, |
| 373 | int bits_per_sample, |
| 374 | int sample_rate, |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 375 | size_t number_of_channels, |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 376 | size_t number_of_frames) override; |
| 377 | void OnClose() override; |
| 378 | AudioSource* source() const; |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 +0000 | [diff] [blame] | 379 | |
| 380 | private: |
Taylor Brandstetter | 1a018dc | 2016-03-08 12:37:39 -0800 | [diff] [blame] | 381 | AudioSource* source_; |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 +0000 | [diff] [blame] | 382 | }; |
| 383 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 384 | bool SetRecvCodecs(const std::vector<AudioCodec>& codecs); |
| 385 | bool SetSendCodecs(const std::vector<AudioCodec>& codecs); |
| 386 | bool SetMaxSendBandwidth(int bps); |
| 387 | bool SetOptions(const AudioOptions& options); |
| 388 | bool SetLocalSource(uint32_t ssrc, AudioSource* source); |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 +0000 | [diff] [blame] | 389 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 390 | FakeVoiceEngine* engine_; |
| 391 | std::vector<AudioCodec> recv_codecs_; |
| 392 | std::vector<AudioCodec> send_codecs_; |
solenberg | 4bac9c5 | 2015-10-09 02:32:53 -0700 | [diff] [blame] | 393 | std::map<uint32_t, double> output_scalings_; |
Ruslan Burakov | 7ea4605 | 2019-02-16 02:07:05 +0100 | [diff] [blame] | 394 | std::map<uint32_t, int> output_delays_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 395 | std::vector<DtmfInfo> dtmf_info_queue_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 396 | AudioOptions options_; |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 397 | std::map<uint32_t, std::unique_ptr<VoiceChannelAudioSink>> local_sinks_; |
kwiberg | 686a8ef | 2016-02-26 03:00:35 -0800 | [diff] [blame] | 398 | std::unique_ptr<webrtc::AudioSinkInterface> sink_; |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 399 | int max_bps_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 400 | }; |
| 401 | |
| 402 | // A helper function to compare the FakeVoiceMediaChannel::DtmfInfo. |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 403 | bool CompareDtmfInfo(const FakeVoiceMediaChannel::DtmfInfo& info, |
| 404 | uint32_t ssrc, |
| 405 | int event_code, |
| 406 | int duration); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 407 | |
| 408 | class FakeVideoMediaChannel : public RtpHelper<VideoMediaChannel> { |
| 409 | public: |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 410 | FakeVideoMediaChannel(FakeVideoEngine* engine, const VideoOptions& options); |
buildbot@webrtc.org | 1ecbe45 | 2014-10-14 20:29:28 +0000 | [diff] [blame] | 411 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 412 | ~FakeVideoMediaChannel(); |
| 413 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 414 | const std::vector<VideoCodec>& recv_codecs() const; |
| 415 | const std::vector<VideoCodec>& send_codecs() const; |
| 416 | const std::vector<VideoCodec>& codecs() const; |
| 417 | bool rendering() const; |
| 418 | const VideoOptions& options() const; |
nisse | acd935b | 2016-11-11 03:55:13 -0800 | [diff] [blame] | 419 | const std::map<uint32_t, rtc::VideoSinkInterface<webrtc::VideoFrame>*>& |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 420 | sinks() const; |
| 421 | int max_bps() const; |
| 422 | bool SetSendParameters(const VideoSendParameters& params) override; |
| 423 | bool SetRecvParameters(const VideoRecvParameters& params) override; |
| 424 | bool AddSendStream(const StreamParams& sp) override; |
| 425 | bool RemoveSendStream(uint32_t ssrc) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 426 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 427 | bool GetSendCodec(VideoCodec* send_codec) override; |
nisse | 08582ff | 2016-02-04 01:24:52 -0800 | [diff] [blame] | 428 | bool SetSink(uint32_t ssrc, |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 429 | rtc::VideoSinkInterface<webrtc::VideoFrame>* sink) override; |
| 430 | bool HasSink(uint32_t ssrc) const; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 431 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 432 | bool SetSend(bool send) override; |
deadbeef | 5a4a75a | 2016-06-02 16:23:38 -0700 | [diff] [blame] | 433 | bool SetVideoSend( |
| 434 | uint32_t ssrc, |
deadbeef | 5a4a75a | 2016-06-02 16:23:38 -0700 | [diff] [blame] | 435 | const VideoOptions* options, |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 436 | rtc::VideoSourceInterface<webrtc::VideoFrame>* source) override; |
nisse | 2ded9b1 | 2016-04-08 02:23:55 -0700 | [diff] [blame] | 437 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 438 | bool HasSource(uint32_t ssrc) const; |
| 439 | bool AddRecvStream(const StreamParams& sp) override; |
| 440 | bool RemoveRecvStream(uint32_t ssrc) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 441 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 442 | void FillBitrateInfo(BandwidthEstimationInfo* bwe_info) override; |
| 443 | bool GetStats(VideoMediaInfo* info) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 444 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 445 | std::vector<webrtc::RtpSource> GetSources(uint32_t ssrc) const override; |
Jonas Oreland | 49ac595 | 2018-09-26 16:04:32 +0200 | [diff] [blame] | 446 | |
Ruslan Burakov | 493a650 | 2019-02-27 15:32:48 +0100 | [diff] [blame] | 447 | bool SetBaseMinimumPlayoutDelayMs(uint32_t ssrc, int delay_ms) override; |
| 448 | absl::optional<int> GetBaseMinimumPlayoutDelayMs( |
| 449 | uint32_t ssrc) const override; |
| 450 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 451 | private: |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 452 | bool SetRecvCodecs(const std::vector<VideoCodec>& codecs); |
| 453 | bool SetSendCodecs(const std::vector<VideoCodec>& codecs); |
| 454 | bool SetOptions(const VideoOptions& options); |
| 455 | bool SetMaxSendBandwidth(int bps); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 456 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 457 | FakeVideoEngine* engine_; |
| 458 | std::vector<VideoCodec> recv_codecs_; |
| 459 | std::vector<VideoCodec> send_codecs_; |
nisse | acd935b | 2016-11-11 03:55:13 -0800 | [diff] [blame] | 460 | std::map<uint32_t, rtc::VideoSinkInterface<webrtc::VideoFrame>*> sinks_; |
| 461 | std::map<uint32_t, rtc::VideoSourceInterface<webrtc::VideoFrame>*> sources_; |
Ruslan Burakov | 493a650 | 2019-02-27 15:32:48 +0100 | [diff] [blame] | 462 | std::map<uint32_t, int> output_delays_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 463 | VideoOptions options_; |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 464 | int max_bps_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 465 | }; |
| 466 | |
nisse | 0510331 | 2016-03-16 02:22:50 -0700 | [diff] [blame] | 467 | // Dummy option class, needed for the DataTraits abstraction in |
| 468 | // channel_unittest.c. |
| 469 | class DataOptions {}; |
| 470 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 471 | class FakeDataMediaChannel : public RtpHelper<DataMediaChannel> { |
| 472 | public: |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 473 | explicit FakeDataMediaChannel(void* unused, const DataOptions& options); |
| 474 | ~FakeDataMediaChannel(); |
| 475 | const std::vector<DataCodec>& recv_codecs() const; |
| 476 | const std::vector<DataCodec>& send_codecs() const; |
| 477 | const std::vector<DataCodec>& codecs() const; |
| 478 | int max_bps() const; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 479 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 480 | bool SetSendParameters(const DataSendParameters& params) override; |
| 481 | bool SetRecvParameters(const DataRecvParameters& params) override; |
| 482 | bool SetSend(bool send) override; |
| 483 | bool SetReceive(bool receive) override; |
| 484 | bool AddRecvStream(const StreamParams& sp) override; |
| 485 | bool RemoveRecvStream(uint32_t ssrc) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 486 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 487 | bool SendData(const SendDataParams& params, |
| 488 | const rtc::CopyOnWriteBuffer& payload, |
| 489 | SendDataResult* result) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 490 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 491 | SendDataParams last_sent_data_params(); |
| 492 | std::string last_sent_data(); |
| 493 | bool is_send_blocked(); |
| 494 | void set_send_blocked(bool blocked); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 495 | |
| 496 | private: |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 497 | bool SetRecvCodecs(const std::vector<DataCodec>& codecs); |
| 498 | bool SetSendCodecs(const std::vector<DataCodec>& codecs); |
| 499 | bool SetMaxSendBandwidth(int bps); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 500 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 501 | std::vector<DataCodec> recv_codecs_; |
| 502 | std::vector<DataCodec> send_codecs_; |
| 503 | SendDataParams last_sent_data_params_; |
| 504 | std::string last_sent_data_; |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 505 | bool send_blocked_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 506 | int max_bps_; |
| 507 | }; |
| 508 | |
Sebastian Jansson | 84848f2 | 2018-11-16 10:40:36 +0100 | [diff] [blame] | 509 | class FakeVoiceEngine : public VoiceEngineInterface { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 510 | public: |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 511 | FakeVoiceEngine(); |
Sebastian Jansson | 84848f2 | 2018-11-16 10:40:36 +0100 | [diff] [blame] | 512 | RtpCapabilities GetCapabilities() const override; |
| 513 | void Init() override; |
| 514 | rtc::scoped_refptr<webrtc::AudioState> GetAudioState() const override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 515 | |
Sebastian Jansson | 84848f2 | 2018-11-16 10:40:36 +0100 | [diff] [blame] | 516 | VoiceMediaChannel* CreateMediaChannel( |
| 517 | webrtc::Call* call, |
| 518 | const MediaConfig& config, |
| 519 | const AudioOptions& options, |
| 520 | const webrtc::CryptoOptions& crypto_options) override; |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 521 | FakeVoiceMediaChannel* GetChannel(size_t index); |
| 522 | void UnregisterChannel(VoiceMediaChannel* channel); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 523 | |
ossu | dedfd28 | 2016-06-14 07:12:39 -0700 | [diff] [blame] | 524 | // TODO(ossu): For proper testing, These should either individually settable |
| 525 | // or the voice engine should reference mockable factories. |
Sebastian Jansson | 84848f2 | 2018-11-16 10:40:36 +0100 | [diff] [blame] | 526 | const std::vector<AudioCodec>& send_codecs() const override; |
| 527 | const std::vector<AudioCodec>& recv_codecs() const override; |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 528 | void SetCodecs(const std::vector<AudioCodec>& codecs); |
Florent Castelli | 2d9d82e | 2019-04-23 19:25:51 +0200 | [diff] [blame] | 529 | void SetRecvCodecs(const std::vector<AudioCodec>& codecs); |
| 530 | void SetSendCodecs(const std::vector<AudioCodec>& codecs); |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 531 | int GetInputLevel(); |
Niels Möller | e8e4dc4 | 2019-06-11 14:04:16 +0200 | [diff] [blame] | 532 | bool StartAecDump(webrtc::FileWrapper file, int64_t max_size_bytes) override; |
Sebastian Jansson | 84848f2 | 2018-11-16 10:40:36 +0100 | [diff] [blame] | 533 | void StopAecDump() override; |
ivoc | 112a3d8 | 2015-10-16 02:22:18 -0700 | [diff] [blame] | 534 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 535 | private: |
| 536 | std::vector<FakeVoiceMediaChannel*> channels_; |
Florent Castelli | 2d9d82e | 2019-04-23 19:25:51 +0200 | [diff] [blame] | 537 | std::vector<AudioCodec> recv_codecs_; |
| 538 | std::vector<AudioCodec> send_codecs_; |
Sebastian Jansson | 7e6b528 | 2018-10-23 14:04:07 +0200 | [diff] [blame] | 539 | bool fail_create_channel_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 540 | |
| 541 | friend class FakeMediaEngine; |
| 542 | }; |
| 543 | |
Sebastian Jansson | 84848f2 | 2018-11-16 10:40:36 +0100 | [diff] [blame] | 544 | class FakeVideoEngine : public VideoEngineInterface { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 545 | public: |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 546 | FakeVideoEngine(); |
Sebastian Jansson | 84848f2 | 2018-11-16 10:40:36 +0100 | [diff] [blame] | 547 | RtpCapabilities GetCapabilities() const override; |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 548 | bool SetOptions(const VideoOptions& options); |
Sebastian Jansson | 84848f2 | 2018-11-16 10:40:36 +0100 | [diff] [blame] | 549 | VideoMediaChannel* CreateMediaChannel( |
| 550 | webrtc::Call* call, |
| 551 | const MediaConfig& config, |
| 552 | const VideoOptions& options, |
Jonas Oreland | a3aa9bd | 2019-04-17 07:38:40 +0200 | [diff] [blame] | 553 | const webrtc::CryptoOptions& crypto_options, |
| 554 | webrtc::VideoBitrateAllocatorFactory* video_bitrate_allocator_factory) |
| 555 | override; |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 556 | FakeVideoMediaChannel* GetChannel(size_t index); |
| 557 | void UnregisterChannel(VideoMediaChannel* channel); |
Sebastian Jansson | 84848f2 | 2018-11-16 10:40:36 +0100 | [diff] [blame] | 558 | std::vector<VideoCodec> codecs() const override; |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 559 | void SetCodecs(const std::vector<VideoCodec> codecs); |
| 560 | bool SetCapture(bool capture); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 561 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 562 | private: |
| 563 | std::vector<FakeVideoMediaChannel*> channels_; |
| 564 | std::vector<VideoCodec> codecs_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 565 | bool capture_; |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 566 | VideoOptions options_; |
Sebastian Jansson | 7e6b528 | 2018-10-23 14:04:07 +0200 | [diff] [blame] | 567 | bool fail_create_channel_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 568 | |
| 569 | friend class FakeMediaEngine; |
| 570 | }; |
| 571 | |
Sebastian Jansson | fa0aa39 | 2018-11-16 09:54:32 +0100 | [diff] [blame] | 572 | class FakeMediaEngine : public CompositeMediaEngine { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 573 | public: |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 574 | FakeMediaEngine(); |
magjed | 2475ae2 | 2017-09-12 04:42:15 -0700 | [diff] [blame] | 575 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 576 | ~FakeMediaEngine() override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 577 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 578 | void SetAudioCodecs(const std::vector<AudioCodec>& codecs); |
Florent Castelli | 2d9d82e | 2019-04-23 19:25:51 +0200 | [diff] [blame] | 579 | void SetAudioRecvCodecs(const std::vector<AudioCodec>& codecs); |
| 580 | void SetAudioSendCodecs(const std::vector<AudioCodec>& codecs); |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 581 | void SetVideoCodecs(const std::vector<VideoCodec>& codecs); |
| 582 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 583 | FakeVoiceMediaChannel* GetVoiceChannel(size_t index); |
| 584 | FakeVideoMediaChannel* GetVideoChannel(size_t index); |
isheriff | a1c548b | 2016-05-31 16:12:24 -0700 | [diff] [blame] | 585 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 586 | void set_fail_create_channel(bool fail); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 587 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 588 | private: |
| 589 | FakeVoiceEngine* const voice_; |
| 590 | FakeVideoEngine* const video_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 591 | }; |
| 592 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 593 | // Have to come afterwards due to declaration order |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 594 | |
| 595 | class FakeDataEngine : public DataEngineInterface { |
| 596 | public: |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 597 | DataMediaChannel* CreateChannel(const MediaConfig& config) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 598 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 599 | FakeDataMediaChannel* GetChannel(size_t index); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 600 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 601 | void UnregisterChannel(DataMediaChannel* channel); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 602 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 603 | void SetDataCodecs(const std::vector<DataCodec>& data_codecs); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 604 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 605 | const std::vector<DataCodec>& data_codecs() override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 606 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 607 | private: |
| 608 | std::vector<FakeDataMediaChannel*> channels_; |
| 609 | std::vector<DataCodec> data_codecs_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 610 | }; |
| 611 | |
| 612 | } // namespace cricket |
| 613 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 614 | #endif // MEDIA_BASE_FAKE_MEDIA_ENGINE_H_ |