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 | } |
Saurav Das | 749f660 | 2019-12-04 09:31:36 -0800 | [diff] [blame^] | 171 | virtual webrtc::RtpParameters GetDefaultRtpReceiveParameters() const { |
| 172 | return webrtc::RtpParameters(); |
| 173 | } |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 174 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 175 | bool IsStreamMuted(uint32_t ssrc) const { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 176 | bool ret = muted_streams_.find(ssrc) != muted_streams_.end(); |
| 177 | // If |ssrc = 0| check if the first send stream is muted. |
| 178 | if (!ret && ssrc == 0 && !send_streams_.empty()) { |
| 179 | return muted_streams_.find(send_streams_[0].first_ssrc()) != |
| 180 | muted_streams_.end(); |
| 181 | } |
| 182 | return ret; |
| 183 | } |
| 184 | const std::vector<StreamParams>& send_streams() const { |
| 185 | return send_streams_; |
| 186 | } |
| 187 | const std::vector<StreamParams>& recv_streams() const { |
| 188 | return receive_streams_; |
| 189 | } |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 190 | bool HasRecvStream(uint32_t ssrc) const { |
tommi@webrtc.org | 586f2ed | 2015-01-22 23:00:41 +0000 | [diff] [blame] | 191 | return GetStreamBySsrc(receive_streams_, ssrc) != nullptr; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 192 | } |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 193 | bool HasSendStream(uint32_t ssrc) const { |
tommi@webrtc.org | 586f2ed | 2015-01-22 23:00:41 +0000 | [diff] [blame] | 194 | return GetStreamBySsrc(send_streams_, ssrc) != nullptr; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 195 | } |
| 196 | // TODO(perkj): This is to support legacy unit test that only check one |
| 197 | // sending stream. |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 198 | uint32_t send_ssrc() const { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 199 | if (send_streams_.empty()) |
| 200 | return 0; |
| 201 | return send_streams_[0].first_ssrc(); |
| 202 | } |
| 203 | |
| 204 | // TODO(perkj): This is to support legacy unit test that only check one |
| 205 | // sending stream. |
| 206 | const std::string rtcp_cname() { |
| 207 | if (send_streams_.empty()) |
| 208 | return ""; |
| 209 | return send_streams_[0].cname; |
| 210 | } |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 211 | const RtcpParameters& send_rtcp_parameters() { return send_rtcp_parameters_; } |
| 212 | const RtcpParameters& recv_rtcp_parameters() { return recv_rtcp_parameters_; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 213 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 214 | bool ready_to_send() const { return ready_to_send_; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 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 | |
Sebastian Jansson | 1b83a9e | 2019-09-18 18:22:12 +0200 | [diff] [blame] | 226 | void OnRtcpPacketReceived(rtc::CopyOnWriteBuffer* packet, |
| 227 | int64_t packet_time_us) { |
| 228 | rtcp_packets_.push_back(std::string(packet->cdata<char>(), packet->size())); |
| 229 | } |
| 230 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 231 | protected: |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 232 | bool MuteStream(uint32_t ssrc, bool mute) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 233 | if (!HasSendStream(ssrc) && ssrc != 0) { |
solenberg | 1dd98f3 | 2015-09-10 01:57:14 -0700 | [diff] [blame] | 234 | return false; |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 235 | } |
| 236 | if (mute) { |
solenberg | 1dd98f3 | 2015-09-10 01:57:14 -0700 | [diff] [blame] | 237 | muted_streams_.insert(ssrc); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 238 | } else { |
solenberg | 1dd98f3 | 2015-09-10 01:57:14 -0700 | [diff] [blame] | 239 | muted_streams_.erase(ssrc); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 240 | } |
solenberg | 1dd98f3 | 2015-09-10 01:57:14 -0700 | [diff] [blame] | 241 | return true; |
| 242 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 243 | bool set_sending(bool send) { |
| 244 | sending_ = send; |
| 245 | return true; |
| 246 | } |
| 247 | void set_playout(bool playout) { playout_ = playout; } |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 248 | bool SetRecvRtpHeaderExtensions(const std::vector<RtpExtension>& extensions) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 249 | recv_extensions_ = extensions; |
| 250 | return true; |
| 251 | } |
Johannes Kron | 9190b82 | 2018-10-29 11:22:05 +0100 | [diff] [blame] | 252 | bool SetSendExtmapAllowMixed(bool extmap_allow_mixed) { |
| 253 | if (Base::ExtmapAllowMixed() != extmap_allow_mixed) { |
| 254 | Base::SetExtmapAllowMixed(extmap_allow_mixed); |
| 255 | } |
| 256 | return true; |
| 257 | } |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 258 | bool SetSendRtpHeaderExtensions(const std::vector<RtpExtension>& extensions) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 259 | send_extensions_ = extensions; |
| 260 | return true; |
| 261 | } |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 262 | void set_send_rtcp_parameters(const RtcpParameters& params) { |
| 263 | send_rtcp_parameters_ = params; |
| 264 | } |
| 265 | void set_recv_rtcp_parameters(const RtcpParameters& params) { |
| 266 | recv_rtcp_parameters_ = params; |
| 267 | } |
Amit Hilbuch | e7a5f7b | 2019-03-12 11:10:27 -0700 | [diff] [blame] | 268 | virtual void OnPacketReceived(rtc::CopyOnWriteBuffer packet, |
Niels Möller | e693381 | 2018-11-05 13:01:41 +0100 | [diff] [blame] | 269 | int64_t packet_time_us) { |
Amit Hilbuch | e7a5f7b | 2019-03-12 11:10:27 -0700 | [diff] [blame] | 270 | rtp_packets_.push_back(std::string(packet.cdata<char>(), packet.size())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 271 | } |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 272 | virtual void OnReadyToSend(bool ready) { ready_to_send_ = ready; } |
michaelt | 79e0588 | 2016-11-08 02:50:09 -0800 | [diff] [blame] | 273 | |
Honghai Zhang | cc411c0 | 2016-03-29 17:27:21 -0700 | [diff] [blame] | 274 | virtual void OnNetworkRouteChanged(const std::string& transport_name, |
Honghai Zhang | 0e533ef | 2016-04-19 15:41:36 -0700 | [diff] [blame] | 275 | const rtc::NetworkRoute& network_route) { |
Honghai Zhang | cc411c0 | 2016-03-29 17:27:21 -0700 | [diff] [blame] | 276 | last_network_route_ = network_route; |
| 277 | ++num_network_route_changes_; |
Zhi Huang | 5f5918f | 2017-11-12 17:26:23 -0800 | [diff] [blame] | 278 | transport_overhead_per_packet_ = network_route.packet_overhead; |
Honghai Zhang | cc411c0 | 2016-03-29 17:27:21 -0700 | [diff] [blame] | 279 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 280 | bool fail_set_send_codecs() const { return fail_set_send_codecs_; } |
| 281 | bool fail_set_recv_codecs() const { return fail_set_recv_codecs_; } |
| 282 | |
| 283 | private: |
| 284 | bool sending_; |
| 285 | bool playout_; |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 286 | std::vector<RtpExtension> recv_extensions_; |
| 287 | std::vector<RtpExtension> send_extensions_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 288 | std::list<std::string> rtp_packets_; |
| 289 | std::list<std::string> rtcp_packets_; |
| 290 | std::vector<StreamParams> send_streams_; |
| 291 | std::vector<StreamParams> receive_streams_; |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 292 | RtcpParameters send_rtcp_parameters_; |
| 293 | RtcpParameters recv_rtcp_parameters_; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 294 | std::set<uint32_t> muted_streams_; |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 295 | std::map<uint32_t, webrtc::RtpParameters> rtp_send_parameters_; |
| 296 | std::map<uint32_t, webrtc::RtpParameters> rtp_receive_parameters_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 297 | bool fail_set_send_codecs_; |
| 298 | bool fail_set_recv_codecs_; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 299 | uint32_t send_ssrc_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 300 | std::string rtcp_cname_; |
| 301 | bool ready_to_send_; |
michaelt | 79e0588 | 2016-11-08 02:50:09 -0800 | [diff] [blame] | 302 | int transport_overhead_per_packet_; |
Honghai Zhang | 0e533ef | 2016-04-19 15:41:36 -0700 | [diff] [blame] | 303 | rtc::NetworkRoute last_network_route_; |
sprang | db2a9fc | 2017-08-09 06:42:32 -0700 | [diff] [blame] | 304 | int num_network_route_changes_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 305 | }; |
| 306 | |
| 307 | class FakeVoiceMediaChannel : public RtpHelper<VoiceMediaChannel> { |
| 308 | public: |
| 309 | struct DtmfInfo { |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 310 | DtmfInfo(uint32_t ssrc, int event_code, int 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, |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 316 | const AudioOptions& options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 317 | ~FakeVoiceMediaChannel(); |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 318 | const std::vector<AudioCodec>& recv_codecs() const; |
| 319 | const std::vector<AudioCodec>& send_codecs() const; |
| 320 | const std::vector<AudioCodec>& codecs() const; |
| 321 | const std::vector<DtmfInfo>& dtmf_info_queue() const; |
| 322 | const AudioOptions& options() const; |
| 323 | int max_bps() const; |
| 324 | bool SetSendParameters(const AudioSendParameters& params) override; |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 325 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 326 | bool SetRecvParameters(const AudioRecvParameters& params) override; |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 327 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 328 | void SetPlayout(bool playout) override; |
| 329 | void SetSend(bool send) override; |
| 330 | bool SetAudioSend(uint32_t ssrc, |
| 331 | bool enable, |
| 332 | const AudioOptions* options, |
| 333 | AudioSource* source) override; |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 334 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 335 | bool HasSource(uint32_t ssrc) const; |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 336 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 337 | bool AddRecvStream(const StreamParams& sp) override; |
| 338 | bool RemoveRecvStream(uint32_t ssrc) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 339 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 340 | bool CanInsertDtmf() override; |
| 341 | bool InsertDtmf(uint32_t ssrc, int event_code, int duration) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 342 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 343 | bool SetOutputVolume(uint32_t ssrc, double volume) override; |
Saurav Das | 749f660 | 2019-12-04 09:31:36 -0800 | [diff] [blame^] | 344 | bool SetDefaultOutputVolume(double volume) override; |
| 345 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 346 | bool GetOutputVolume(uint32_t ssrc, double* volume); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 347 | |
Ruslan Burakov | 7ea4605 | 2019-02-16 02:07:05 +0100 | [diff] [blame] | 348 | bool SetBaseMinimumPlayoutDelayMs(uint32_t ssrc, int delay_ms) override; |
| 349 | absl::optional<int> GetBaseMinimumPlayoutDelayMs( |
| 350 | uint32_t ssrc) const override; |
| 351 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 352 | bool GetStats(VoiceMediaInfo* info) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 353 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 354 | void SetRawAudioSink( |
Tommi | f888bb5 | 2015-12-12 01:37:01 +0100 | [diff] [blame] | 355 | uint32_t ssrc, |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 356 | std::unique_ptr<webrtc::AudioSinkInterface> sink) override; |
Saurav Das | 749f660 | 2019-12-04 09:31:36 -0800 | [diff] [blame^] | 357 | void SetDefaultRawAudioSink( |
| 358 | std::unique_ptr<webrtc::AudioSinkInterface> sink) override; |
Tommi | f888bb5 | 2015-12-12 01:37:01 +0100 | [diff] [blame] | 359 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 360 | std::vector<webrtc::RtpSource> GetSources(uint32_t ssrc) const override; |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 361 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 362 | private: |
Taylor Brandstetter | 1a018dc | 2016-03-08 12:37:39 -0800 | [diff] [blame] | 363 | class VoiceChannelAudioSink : public AudioSource::Sink { |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 +0000 | [diff] [blame] | 364 | public: |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 365 | explicit VoiceChannelAudioSink(AudioSource* source); |
| 366 | ~VoiceChannelAudioSink() override; |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 367 | void OnData(const void* audio_data, |
| 368 | int bits_per_sample, |
| 369 | int sample_rate, |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 370 | size_t number_of_channels, |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 371 | size_t number_of_frames) override; |
| 372 | void OnClose() override; |
| 373 | AudioSource* source() const; |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 +0000 | [diff] [blame] | 374 | |
| 375 | private: |
Taylor Brandstetter | 1a018dc | 2016-03-08 12:37:39 -0800 | [diff] [blame] | 376 | AudioSource* source_; |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 +0000 | [diff] [blame] | 377 | }; |
| 378 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 379 | bool SetRecvCodecs(const std::vector<AudioCodec>& codecs); |
| 380 | bool SetSendCodecs(const std::vector<AudioCodec>& codecs); |
| 381 | bool SetMaxSendBandwidth(int bps); |
| 382 | bool SetOptions(const AudioOptions& options); |
| 383 | bool SetLocalSource(uint32_t ssrc, AudioSource* source); |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 +0000 | [diff] [blame] | 384 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 385 | FakeVoiceEngine* engine_; |
| 386 | std::vector<AudioCodec> recv_codecs_; |
| 387 | std::vector<AudioCodec> send_codecs_; |
solenberg | 4bac9c5 | 2015-10-09 02:32:53 -0700 | [diff] [blame] | 388 | std::map<uint32_t, double> output_scalings_; |
Ruslan Burakov | 7ea4605 | 2019-02-16 02:07:05 +0100 | [diff] [blame] | 389 | std::map<uint32_t, int> output_delays_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 390 | std::vector<DtmfInfo> dtmf_info_queue_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 391 | AudioOptions options_; |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 392 | std::map<uint32_t, std::unique_ptr<VoiceChannelAudioSink>> local_sinks_; |
kwiberg | 686a8ef | 2016-02-26 03:00:35 -0800 | [diff] [blame] | 393 | std::unique_ptr<webrtc::AudioSinkInterface> sink_; |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 394 | int max_bps_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 395 | }; |
| 396 | |
| 397 | // A helper function to compare the FakeVoiceMediaChannel::DtmfInfo. |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 398 | bool CompareDtmfInfo(const FakeVoiceMediaChannel::DtmfInfo& info, |
| 399 | uint32_t ssrc, |
| 400 | int event_code, |
| 401 | int duration); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 402 | |
| 403 | class FakeVideoMediaChannel : public RtpHelper<VideoMediaChannel> { |
| 404 | public: |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 405 | FakeVideoMediaChannel(FakeVideoEngine* engine, const VideoOptions& options); |
buildbot@webrtc.org | 1ecbe45 | 2014-10-14 20:29:28 +0000 | [diff] [blame] | 406 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 407 | ~FakeVideoMediaChannel(); |
| 408 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 409 | const std::vector<VideoCodec>& recv_codecs() const; |
| 410 | const std::vector<VideoCodec>& send_codecs() const; |
| 411 | const std::vector<VideoCodec>& codecs() const; |
| 412 | bool rendering() const; |
| 413 | const VideoOptions& options() const; |
nisse | acd935b | 2016-11-11 03:55:13 -0800 | [diff] [blame] | 414 | const std::map<uint32_t, rtc::VideoSinkInterface<webrtc::VideoFrame>*>& |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 415 | sinks() const; |
| 416 | int max_bps() const; |
| 417 | bool SetSendParameters(const VideoSendParameters& params) override; |
| 418 | bool SetRecvParameters(const VideoRecvParameters& params) override; |
| 419 | bool AddSendStream(const StreamParams& sp) override; |
| 420 | bool RemoveSendStream(uint32_t ssrc) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 421 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 422 | bool GetSendCodec(VideoCodec* send_codec) override; |
nisse | 08582ff | 2016-02-04 01:24:52 -0800 | [diff] [blame] | 423 | bool SetSink(uint32_t ssrc, |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 424 | rtc::VideoSinkInterface<webrtc::VideoFrame>* sink) override; |
Saurav Das | 749f660 | 2019-12-04 09:31:36 -0800 | [diff] [blame^] | 425 | void SetDefaultSink( |
| 426 | rtc::VideoSinkInterface<webrtc::VideoFrame>* sink) override; |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 427 | bool HasSink(uint32_t ssrc) const; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 428 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 429 | bool SetSend(bool send) override; |
deadbeef | 5a4a75a | 2016-06-02 16:23:38 -0700 | [diff] [blame] | 430 | bool SetVideoSend( |
| 431 | uint32_t ssrc, |
deadbeef | 5a4a75a | 2016-06-02 16:23:38 -0700 | [diff] [blame] | 432 | const VideoOptions* options, |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 433 | rtc::VideoSourceInterface<webrtc::VideoFrame>* source) override; |
nisse | 2ded9b1 | 2016-04-08 02:23:55 -0700 | [diff] [blame] | 434 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 435 | bool HasSource(uint32_t ssrc) const; |
| 436 | bool AddRecvStream(const StreamParams& sp) override; |
| 437 | bool RemoveRecvStream(uint32_t ssrc) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 438 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 439 | void FillBitrateInfo(BandwidthEstimationInfo* bwe_info) override; |
| 440 | bool GetStats(VideoMediaInfo* info) 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 | std::vector<webrtc::RtpSource> GetSources(uint32_t ssrc) const override; |
Jonas Oreland | 49ac595 | 2018-09-26 16:04:32 +0200 | [diff] [blame] | 443 | |
Ruslan Burakov | 493a650 | 2019-02-27 15:32:48 +0100 | [diff] [blame] | 444 | bool SetBaseMinimumPlayoutDelayMs(uint32_t ssrc, int delay_ms) override; |
| 445 | absl::optional<int> GetBaseMinimumPlayoutDelayMs( |
| 446 | uint32_t ssrc) const override; |
| 447 | |
Markus Handell | 32565f6 | 2019-12-04 10:58:17 +0100 | [diff] [blame] | 448 | void SetRecordableEncodedFrameCallback( |
| 449 | uint32_t ssrc, |
| 450 | std::function<void(const webrtc::RecordableEncodedFrame&)> callback) |
| 451 | override; |
| 452 | void ClearRecordableEncodedFrameCallback(uint32_t ssrc) override; |
| 453 | void GenerateKeyFrame(uint32_t ssrc) override; |
| 454 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 455 | private: |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 456 | bool SetRecvCodecs(const std::vector<VideoCodec>& codecs); |
| 457 | bool SetSendCodecs(const std::vector<VideoCodec>& codecs); |
| 458 | bool SetOptions(const VideoOptions& options); |
| 459 | bool SetMaxSendBandwidth(int bps); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 460 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 461 | FakeVideoEngine* engine_; |
| 462 | std::vector<VideoCodec> recv_codecs_; |
| 463 | std::vector<VideoCodec> send_codecs_; |
nisse | acd935b | 2016-11-11 03:55:13 -0800 | [diff] [blame] | 464 | std::map<uint32_t, rtc::VideoSinkInterface<webrtc::VideoFrame>*> sinks_; |
| 465 | std::map<uint32_t, rtc::VideoSourceInterface<webrtc::VideoFrame>*> sources_; |
Ruslan Burakov | 493a650 | 2019-02-27 15:32:48 +0100 | [diff] [blame] | 466 | std::map<uint32_t, int> output_delays_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 467 | VideoOptions options_; |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 468 | int max_bps_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 469 | }; |
| 470 | |
nisse | 0510331 | 2016-03-16 02:22:50 -0700 | [diff] [blame] | 471 | // Dummy option class, needed for the DataTraits abstraction in |
| 472 | // channel_unittest.c. |
| 473 | class DataOptions {}; |
| 474 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 475 | class FakeDataMediaChannel : public RtpHelper<DataMediaChannel> { |
| 476 | public: |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 477 | explicit FakeDataMediaChannel(void* unused, const DataOptions& options); |
| 478 | ~FakeDataMediaChannel(); |
| 479 | const std::vector<DataCodec>& recv_codecs() const; |
| 480 | const std::vector<DataCodec>& send_codecs() const; |
| 481 | const std::vector<DataCodec>& codecs() const; |
| 482 | int max_bps() const; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 483 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 484 | bool SetSendParameters(const DataSendParameters& params) override; |
| 485 | bool SetRecvParameters(const DataRecvParameters& params) override; |
| 486 | bool SetSend(bool send) override; |
| 487 | bool SetReceive(bool receive) override; |
| 488 | bool AddRecvStream(const StreamParams& sp) override; |
| 489 | bool RemoveRecvStream(uint32_t ssrc) 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 | bool SendData(const SendDataParams& params, |
| 492 | const rtc::CopyOnWriteBuffer& payload, |
| 493 | SendDataResult* result) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 494 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 495 | SendDataParams last_sent_data_params(); |
| 496 | std::string last_sent_data(); |
| 497 | bool is_send_blocked(); |
| 498 | void set_send_blocked(bool blocked); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 499 | |
| 500 | private: |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 501 | bool SetRecvCodecs(const std::vector<DataCodec>& codecs); |
| 502 | bool SetSendCodecs(const std::vector<DataCodec>& codecs); |
| 503 | bool SetMaxSendBandwidth(int bps); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 504 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 505 | std::vector<DataCodec> recv_codecs_; |
| 506 | std::vector<DataCodec> send_codecs_; |
| 507 | SendDataParams last_sent_data_params_; |
| 508 | std::string last_sent_data_; |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 509 | bool send_blocked_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 510 | int max_bps_; |
| 511 | }; |
| 512 | |
Sebastian Jansson | 84848f2 | 2018-11-16 10:40:36 +0100 | [diff] [blame] | 513 | class FakeVoiceEngine : public VoiceEngineInterface { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 514 | public: |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 515 | FakeVoiceEngine(); |
Sebastian Jansson | 84848f2 | 2018-11-16 10:40:36 +0100 | [diff] [blame] | 516 | RtpCapabilities GetCapabilities() const override; |
| 517 | void Init() override; |
| 518 | rtc::scoped_refptr<webrtc::AudioState> GetAudioState() const override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 519 | |
Sebastian Jansson | 84848f2 | 2018-11-16 10:40:36 +0100 | [diff] [blame] | 520 | VoiceMediaChannel* CreateMediaChannel( |
| 521 | webrtc::Call* call, |
| 522 | const MediaConfig& config, |
| 523 | const AudioOptions& options, |
| 524 | const webrtc::CryptoOptions& crypto_options) override; |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 525 | FakeVoiceMediaChannel* GetChannel(size_t index); |
| 526 | void UnregisterChannel(VoiceMediaChannel* channel); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 527 | |
ossu | dedfd28 | 2016-06-14 07:12:39 -0700 | [diff] [blame] | 528 | // TODO(ossu): For proper testing, These should either individually settable |
| 529 | // or the voice engine should reference mockable factories. |
Sebastian Jansson | 84848f2 | 2018-11-16 10:40:36 +0100 | [diff] [blame] | 530 | const std::vector<AudioCodec>& send_codecs() const override; |
| 531 | const std::vector<AudioCodec>& recv_codecs() const override; |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 532 | void SetCodecs(const std::vector<AudioCodec>& codecs); |
Florent Castelli | 2d9d82e | 2019-04-23 19:25:51 +0200 | [diff] [blame] | 533 | void SetRecvCodecs(const std::vector<AudioCodec>& codecs); |
| 534 | void SetSendCodecs(const std::vector<AudioCodec>& codecs); |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 535 | int GetInputLevel(); |
Niels Möller | e8e4dc4 | 2019-06-11 14:04:16 +0200 | [diff] [blame] | 536 | bool StartAecDump(webrtc::FileWrapper file, int64_t max_size_bytes) override; |
Sebastian Jansson | 84848f2 | 2018-11-16 10:40:36 +0100 | [diff] [blame] | 537 | void StopAecDump() override; |
ivoc | 112a3d8 | 2015-10-16 02:22:18 -0700 | [diff] [blame] | 538 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 539 | private: |
| 540 | std::vector<FakeVoiceMediaChannel*> channels_; |
Florent Castelli | 2d9d82e | 2019-04-23 19:25:51 +0200 | [diff] [blame] | 541 | std::vector<AudioCodec> recv_codecs_; |
| 542 | std::vector<AudioCodec> send_codecs_; |
Sebastian Jansson | 7e6b528 | 2018-10-23 14:04:07 +0200 | [diff] [blame] | 543 | bool fail_create_channel_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 544 | |
| 545 | friend class FakeMediaEngine; |
| 546 | }; |
| 547 | |
Sebastian Jansson | 84848f2 | 2018-11-16 10:40:36 +0100 | [diff] [blame] | 548 | class FakeVideoEngine : public VideoEngineInterface { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 549 | public: |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 550 | FakeVideoEngine(); |
Sebastian Jansson | 84848f2 | 2018-11-16 10:40:36 +0100 | [diff] [blame] | 551 | RtpCapabilities GetCapabilities() const override; |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 552 | bool SetOptions(const VideoOptions& options); |
Sebastian Jansson | 84848f2 | 2018-11-16 10:40:36 +0100 | [diff] [blame] | 553 | VideoMediaChannel* CreateMediaChannel( |
| 554 | webrtc::Call* call, |
| 555 | const MediaConfig& config, |
| 556 | const VideoOptions& options, |
Jonas Oreland | a3aa9bd | 2019-04-17 07:38:40 +0200 | [diff] [blame] | 557 | const webrtc::CryptoOptions& crypto_options, |
| 558 | webrtc::VideoBitrateAllocatorFactory* video_bitrate_allocator_factory) |
| 559 | override; |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 560 | FakeVideoMediaChannel* GetChannel(size_t index); |
| 561 | void UnregisterChannel(VideoMediaChannel* channel); |
Sebastian Jansson | 84848f2 | 2018-11-16 10:40:36 +0100 | [diff] [blame] | 562 | std::vector<VideoCodec> codecs() const override; |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 563 | void SetCodecs(const std::vector<VideoCodec> codecs); |
| 564 | bool SetCapture(bool capture); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 565 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 566 | private: |
| 567 | std::vector<FakeVideoMediaChannel*> channels_; |
| 568 | std::vector<VideoCodec> codecs_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 569 | bool capture_; |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 570 | VideoOptions options_; |
Sebastian Jansson | 7e6b528 | 2018-10-23 14:04:07 +0200 | [diff] [blame] | 571 | bool fail_create_channel_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 572 | |
| 573 | friend class FakeMediaEngine; |
| 574 | }; |
| 575 | |
Sebastian Jansson | fa0aa39 | 2018-11-16 09:54:32 +0100 | [diff] [blame] | 576 | class FakeMediaEngine : public CompositeMediaEngine { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 577 | public: |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 578 | FakeMediaEngine(); |
magjed | 2475ae2 | 2017-09-12 04:42:15 -0700 | [diff] [blame] | 579 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 580 | ~FakeMediaEngine() override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 581 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 582 | void SetAudioCodecs(const std::vector<AudioCodec>& codecs); |
Florent Castelli | 2d9d82e | 2019-04-23 19:25:51 +0200 | [diff] [blame] | 583 | void SetAudioRecvCodecs(const std::vector<AudioCodec>& codecs); |
| 584 | void SetAudioSendCodecs(const std::vector<AudioCodec>& codecs); |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 585 | void SetVideoCodecs(const std::vector<VideoCodec>& codecs); |
| 586 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 587 | FakeVoiceMediaChannel* GetVoiceChannel(size_t index); |
| 588 | FakeVideoMediaChannel* GetVideoChannel(size_t index); |
isheriff | a1c548b | 2016-05-31 16:12:24 -0700 | [diff] [blame] | 589 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 590 | void set_fail_create_channel(bool fail); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 591 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 592 | private: |
| 593 | FakeVoiceEngine* const voice_; |
| 594 | FakeVideoEngine* const video_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 595 | }; |
| 596 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 597 | // Have to come afterwards due to declaration order |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 598 | |
| 599 | class FakeDataEngine : public DataEngineInterface { |
| 600 | public: |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 601 | DataMediaChannel* CreateChannel(const MediaConfig& config) override; |
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 | FakeDataMediaChannel* GetChannel(size_t index); |
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 | void UnregisterChannel(DataMediaChannel* channel); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 606 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 607 | void SetDataCodecs(const std::vector<DataCodec>& data_codecs); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 608 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 609 | const std::vector<DataCodec>& data_codecs() override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 610 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 611 | private: |
| 612 | std::vector<FakeDataMediaChannel*> channels_; |
| 613 | std::vector<DataCodec> data_codecs_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 614 | }; |
| 615 | |
| 616 | } // namespace cricket |
| 617 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 618 | #endif // MEDIA_BASE_FAKE_MEDIA_ENGINE_H_ |