fake_media_engine.cc (24747B)
1 /* 2 * Copyright 2018 The WebRTC project authors. All Rights Reserved. 3 * 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. 9 */ 10 11 #include "media/base/fake_media_engine.h" 12 13 #include <cstddef> 14 #include <cstdint> 15 #include <functional> 16 #include <map> 17 #include <memory> 18 #include <optional> 19 #include <string> 20 #include <utility> 21 #include <vector> 22 23 #include "absl/strings/match.h" 24 #include "api/audio/audio_device.h" 25 #include "api/audio_codecs/audio_codec_pair_id.h" 26 #include "api/audio_options.h" 27 #include "api/call/audio_sink.h" 28 #include "api/crypto/crypto_options.h" 29 #include "api/environment/environment.h" 30 #include "api/field_trials_view.h" 31 #include "api/make_ref_counted.h" 32 #include "api/rtp_parameters.h" 33 #include "api/scoped_refptr.h" 34 #include "api/task_queue/task_queue_base.h" 35 #include "api/transport/rtp/rtp_source.h" 36 #include "api/video/recordable_encoded_frame.h" 37 #include "api/video/video_bitrate_allocator_factory.h" 38 #include "api/video/video_sink_interface.h" 39 #include "api/video/video_source_interface.h" 40 #include "call/audio_state.h" 41 #include "call/call.h" 42 #include "media/base/audio_source.h" 43 #include "media/base/codec.h" 44 #include "media/base/media_channel.h" 45 #include "media/base/media_config.h" 46 #include "media/base/media_engine.h" 47 #include "media/base/stream_params.h" 48 #include "rtc_base/checks.h" 49 #include "rtc_base/system/file_wrapper.h" 50 51 namespace webrtc { 52 53 FakeVoiceMediaReceiveChannel::DtmfInfo::DtmfInfo(uint32_t ssrc, 54 int event_code, 55 int duration) 56 : ssrc(ssrc), event_code(event_code), duration(duration) {} 57 58 FakeVoiceMediaReceiveChannel::VoiceChannelAudioSink::VoiceChannelAudioSink( 59 AudioSource* source) 60 : source_(source) { 61 source_->SetSink(this); 62 } 63 FakeVoiceMediaReceiveChannel::VoiceChannelAudioSink::~VoiceChannelAudioSink() { 64 if (source_) { 65 source_->SetSink(nullptr); 66 } 67 } 68 void FakeVoiceMediaReceiveChannel::VoiceChannelAudioSink::OnData( 69 const void* /* audio_data */, 70 int /* bits_per_sample */, 71 int /* sample_rate */, 72 size_t /* number_of_channels */, 73 size_t /* number_of_frames */, 74 std::optional<int64_t> /* absolute_capture_timestamp_ms */) {} 75 void FakeVoiceMediaReceiveChannel::VoiceChannelAudioSink::OnClose() { 76 source_ = nullptr; 77 } 78 AudioSource* FakeVoiceMediaReceiveChannel::VoiceChannelAudioSink::source() 79 const { 80 return source_; 81 } 82 83 FakeVoiceMediaReceiveChannel::FakeVoiceMediaReceiveChannel( 84 const AudioOptions& options, 85 TaskQueueBase* network_thread) 86 : RtpReceiveChannelHelper<VoiceMediaReceiveChannelInterface>( 87 network_thread), 88 max_bps_(-1) { 89 output_scalings_[0] = 1.0; // For default channel. 90 SetOptions(options); 91 } 92 FakeVoiceMediaReceiveChannel::~FakeVoiceMediaReceiveChannel() = default; 93 const std::vector<Codec>& FakeVoiceMediaReceiveChannel::recv_codecs() const { 94 return recv_codecs_; 95 } 96 const std::vector<FakeVoiceMediaReceiveChannel::DtmfInfo>& 97 FakeVoiceMediaReceiveChannel::dtmf_info_queue() const { 98 return dtmf_info_queue_; 99 } 100 const AudioOptions& FakeVoiceMediaReceiveChannel::options() const { 101 return options_; 102 } 103 int FakeVoiceMediaReceiveChannel::max_bps() const { 104 return max_bps_; 105 } 106 bool FakeVoiceMediaReceiveChannel::SetReceiverParameters( 107 const AudioReceiverParameters& params) { 108 set_recv_rtcp_parameters(params.rtcp); 109 return (SetRecvCodecs(params.codecs) && 110 SetRecvRtpHeaderExtensions(params.extensions)); 111 } 112 void FakeVoiceMediaReceiveChannel::SetPlayout(bool playout) { 113 set_playout(playout); 114 } 115 bool FakeVoiceMediaReceiveChannel::HasSource(uint32_t ssrc) const { 116 return local_sinks_.find(ssrc) != local_sinks_.end(); 117 } 118 bool FakeVoiceMediaReceiveChannel::AddRecvStream(const StreamParams& sp) { 119 if (!RtpReceiveChannelHelper< 120 VoiceMediaReceiveChannelInterface>::AddRecvStream(sp)) 121 return false; 122 output_scalings_[sp.first_ssrc()] = 1.0; 123 output_delays_[sp.first_ssrc()] = 0; 124 return true; 125 } 126 bool FakeVoiceMediaReceiveChannel::RemoveRecvStream(uint32_t ssrc) { 127 if (!RtpReceiveChannelHelper< 128 VoiceMediaReceiveChannelInterface>::RemoveRecvStream(ssrc)) 129 return false; 130 output_scalings_.erase(ssrc); 131 output_delays_.erase(ssrc); 132 return true; 133 } 134 bool FakeVoiceMediaReceiveChannel::SetOutputVolume(uint32_t ssrc, 135 double volume) { 136 if (output_scalings_.find(ssrc) != output_scalings_.end()) { 137 output_scalings_[ssrc] = volume; 138 return true; 139 } 140 return false; 141 } 142 bool FakeVoiceMediaReceiveChannel::SetDefaultOutputVolume(double volume) { 143 for (auto& entry : output_scalings_) { 144 entry.second = volume; 145 } 146 return true; 147 } 148 bool FakeVoiceMediaReceiveChannel::GetOutputVolume(uint32_t ssrc, 149 double* volume) { 150 if (output_scalings_.find(ssrc) == output_scalings_.end()) 151 return false; 152 *volume = output_scalings_[ssrc]; 153 return true; 154 } 155 bool FakeVoiceMediaReceiveChannel::SetBaseMinimumPlayoutDelayMs(uint32_t ssrc, 156 int delay_ms) { 157 if (output_delays_.find(ssrc) == output_delays_.end()) { 158 return false; 159 } else { 160 output_delays_[ssrc] = delay_ms; 161 return true; 162 } 163 } 164 std::optional<int> FakeVoiceMediaReceiveChannel::GetBaseMinimumPlayoutDelayMs( 165 uint32_t ssrc) const { 166 const auto it = output_delays_.find(ssrc); 167 if (it != output_delays_.end()) { 168 return it->second; 169 } 170 return std::nullopt; 171 } 172 bool FakeVoiceMediaReceiveChannel::GetStats( 173 VoiceMediaReceiveInfo* /* info */, 174 bool /* get_and_clear_legacy_stats */) { 175 return false; 176 } 177 void FakeVoiceMediaReceiveChannel::SetRawAudioSink( 178 uint32_t /* ssrc */, 179 std::unique_ptr<AudioSinkInterface> sink) { 180 sink_ = std::move(sink); 181 } 182 void FakeVoiceMediaReceiveChannel::SetDefaultRawAudioSink( 183 std::unique_ptr<AudioSinkInterface> sink) { 184 sink_ = std::move(sink); 185 } 186 std::vector<RtpSource> FakeVoiceMediaReceiveChannel::GetSources( 187 uint32_t /* ssrc */) const { 188 return std::vector<RtpSource>(); 189 } 190 bool FakeVoiceMediaReceiveChannel::SetRecvCodecs( 191 const std::vector<Codec>& codecs) { 192 if (fail_set_recv_codecs()) { 193 // Fake the failure in SetRecvCodecs. 194 return false; 195 } 196 recv_codecs_ = codecs; 197 return true; 198 } 199 bool FakeVoiceMediaReceiveChannel::SetMaxSendBandwidth(int bps) { 200 max_bps_ = bps; 201 return true; 202 } 203 bool FakeVoiceMediaReceiveChannel::SetOptions(const AudioOptions& options) { 204 // Does a "merge" of current options and set options. 205 options_.SetAll(options); 206 return true; 207 } 208 209 FakeVoiceMediaSendChannel::DtmfInfo::DtmfInfo(uint32_t ssrc, 210 int event_code, 211 int duration) 212 : ssrc(ssrc), event_code(event_code), duration(duration) {} 213 214 FakeVoiceMediaSendChannel::VoiceChannelAudioSink::VoiceChannelAudioSink( 215 AudioSource* source) 216 : source_(source) { 217 source_->SetSink(this); 218 } 219 FakeVoiceMediaSendChannel::VoiceChannelAudioSink::~VoiceChannelAudioSink() { 220 if (source_) { 221 source_->SetSink(nullptr); 222 } 223 } 224 void FakeVoiceMediaSendChannel::VoiceChannelAudioSink::OnData( 225 const void* /* audio_data */, 226 int /* bits_per_sample */, 227 int /* sample_rate */, 228 size_t /* number_of_channels */, 229 size_t /* number_of_frames */, 230 std::optional<int64_t> /* absolute_capture_timestamp_ms */) {} 231 void FakeVoiceMediaSendChannel::VoiceChannelAudioSink::OnClose() { 232 source_ = nullptr; 233 } 234 AudioSource* FakeVoiceMediaSendChannel::VoiceChannelAudioSink::source() const { 235 return source_; 236 } 237 238 FakeVoiceMediaSendChannel::FakeVoiceMediaSendChannel( 239 const AudioOptions& options, 240 TaskQueueBase* network_thread) 241 : RtpSendChannelHelper<VoiceMediaSendChannelInterface>(network_thread), 242 max_bps_(-1) { 243 output_scalings_[0] = 1.0; // For default channel. 244 SetOptions(options); 245 } 246 FakeVoiceMediaSendChannel::~FakeVoiceMediaSendChannel() = default; 247 const std::vector<Codec>& FakeVoiceMediaSendChannel::send_codecs() const { 248 return send_codecs_; 249 } 250 std::optional<Codec> FakeVoiceMediaSendChannel::GetSendCodec() const { 251 if (!send_codecs_.empty()) { 252 return send_codecs_.front(); 253 } 254 return std::nullopt; 255 } 256 const std::vector<FakeVoiceMediaSendChannel::DtmfInfo>& 257 FakeVoiceMediaSendChannel::dtmf_info_queue() const { 258 return dtmf_info_queue_; 259 } 260 const AudioOptions& FakeVoiceMediaSendChannel::options() const { 261 return options_; 262 } 263 int FakeVoiceMediaSendChannel::max_bps() const { 264 return max_bps_; 265 } 266 bool FakeVoiceMediaSendChannel::SetSenderParameters( 267 const AudioSenderParameter& params) { 268 set_send_rtcp_parameters(params.rtcp); 269 SetExtmapAllowMixed(params.extmap_allow_mixed); 270 return (SetSendCodecs(params.codecs) && 271 SetSendRtpHeaderExtensions(params.extensions) && 272 SetMaxSendBandwidth(params.max_bandwidth_bps) && 273 SetOptions(params.options)); 274 } 275 void FakeVoiceMediaSendChannel::SetSend(bool send) { 276 set_sending(send); 277 } 278 bool FakeVoiceMediaSendChannel::SetAudioSend(uint32_t ssrc, 279 bool enable, 280 const AudioOptions* options, 281 AudioSource* source) { 282 if (!SetLocalSource(ssrc, source)) { 283 return false; 284 } 285 if (!RtpSendChannelHelper<VoiceMediaSendChannelInterface>::MuteStream( 286 ssrc, !enable)) { 287 return false; 288 } 289 if (enable && options) { 290 return SetOptions(*options); 291 } 292 return true; 293 } 294 bool FakeVoiceMediaSendChannel::HasSource(uint32_t ssrc) const { 295 return local_sinks_.find(ssrc) != local_sinks_.end(); 296 } 297 bool FakeVoiceMediaSendChannel::CanInsertDtmf() { 298 for (std::vector<Codec>::const_iterator it = send_codecs_.begin(); 299 it != send_codecs_.end(); ++it) { 300 // Find the DTMF telephone event "codec". 301 if (absl::EqualsIgnoreCase(it->name, "telephone-event")) { 302 return true; 303 } 304 } 305 return false; 306 } 307 bool FakeVoiceMediaSendChannel::InsertDtmf(uint32_t ssrc, 308 int event_code, 309 int duration) { 310 dtmf_info_queue_.push_back(DtmfInfo(ssrc, event_code, duration)); 311 return true; 312 } 313 bool FakeVoiceMediaSendChannel::GetOutputVolume(uint32_t ssrc, double* volume) { 314 if (output_scalings_.find(ssrc) == output_scalings_.end()) 315 return false; 316 *volume = output_scalings_[ssrc]; 317 return true; 318 } 319 bool FakeVoiceMediaSendChannel::GetStats(VoiceMediaSendInfo* /* info */) { 320 return false; 321 } 322 bool FakeVoiceMediaSendChannel::SetSendCodecs( 323 const std::vector<Codec>& codecs) { 324 if (fail_set_send_codecs()) { 325 // Fake the failure in SetSendCodecs. 326 return false; 327 } 328 send_codecs_ = codecs; 329 return true; 330 } 331 bool FakeVoiceMediaSendChannel::SetMaxSendBandwidth(int bps) { 332 max_bps_ = bps; 333 return true; 334 } 335 bool FakeVoiceMediaSendChannel::SetOptions(const AudioOptions& options) { 336 // Does a "merge" of current options and set options. 337 options_.SetAll(options); 338 return true; 339 } 340 bool FakeVoiceMediaSendChannel::SetLocalSource(uint32_t ssrc, 341 AudioSource* source) { 342 auto it = local_sinks_.find(ssrc); 343 if (source) { 344 if (it != local_sinks_.end()) { 345 RTC_CHECK(it->second->source() == source); 346 } else { 347 local_sinks_.insert(std::make_pair( 348 ssrc, std::make_unique<VoiceChannelAudioSink>(source))); 349 } 350 } else { 351 if (it != local_sinks_.end()) { 352 local_sinks_.erase(it); 353 } 354 } 355 return true; 356 } 357 358 bool CompareDtmfInfo(const FakeVoiceMediaSendChannel::DtmfInfo& info, 359 uint32_t ssrc, 360 int event_code, 361 int duration) { 362 return (info.duration == duration && info.event_code == event_code && 363 info.ssrc == ssrc); 364 } 365 366 FakeVideoMediaSendChannel::FakeVideoMediaSendChannel( 367 const VideoOptions& options, 368 TaskQueueBase* network_thread) 369 : RtpSendChannelHelper<VideoMediaSendChannelInterface>(network_thread), 370 max_bps_(-1) { 371 SetOptions(options); 372 } 373 FakeVideoMediaSendChannel::~FakeVideoMediaSendChannel() = default; 374 const std::vector<Codec>& FakeVideoMediaSendChannel::send_codecs() const { 375 return send_codecs_; 376 } 377 const std::vector<Codec>& FakeVideoMediaSendChannel::codecs() const { 378 return send_codecs(); 379 } 380 const VideoOptions& FakeVideoMediaSendChannel::options() const { 381 return options_; 382 } 383 int FakeVideoMediaSendChannel::max_bps() const { 384 return max_bps_; 385 } 386 bool FakeVideoMediaSendChannel::SetSenderParameters( 387 const VideoSenderParameters& params) { 388 set_send_rtcp_parameters(params.rtcp); 389 SetExtmapAllowMixed(params.extmap_allow_mixed); 390 return (SetSendCodecs(params.codecs) && 391 SetSendRtpHeaderExtensions(params.extensions) && 392 SetMaxSendBandwidth(params.max_bandwidth_bps)); 393 } 394 std::optional<Codec> FakeVideoMediaSendChannel::GetSendCodec() const { 395 if (send_codecs_.empty()) { 396 return std::nullopt; 397 } 398 return send_codecs_[0]; 399 } 400 bool FakeVideoMediaSendChannel::SetSend(bool send) { 401 return set_sending(send); 402 } 403 bool FakeVideoMediaSendChannel::SetVideoSend( 404 uint32_t ssrc, 405 const VideoOptions* options, 406 VideoSourceInterface<VideoFrame>* source) { 407 if (options) { 408 if (!SetOptions(*options)) { 409 return false; 410 } 411 } 412 sources_[ssrc] = source; 413 return true; 414 } 415 bool FakeVideoMediaSendChannel::HasSource(uint32_t ssrc) const { 416 return sources_.find(ssrc) != sources_.end() && sources_.at(ssrc) != nullptr; 417 } 418 void FakeVideoMediaSendChannel::FillBitrateInfo( 419 BandwidthEstimationInfo* /* bwe_info */) {} 420 bool FakeVideoMediaSendChannel::GetStats(VideoMediaSendInfo* /* info */) { 421 return false; 422 } 423 bool FakeVideoMediaSendChannel::SetSendCodecs( 424 const std::vector<Codec>& codecs) { 425 if (fail_set_send_codecs()) { 426 // Fake the failure in SetSendCodecs. 427 return false; 428 } 429 send_codecs_ = codecs; 430 431 return true; 432 } 433 bool FakeVideoMediaSendChannel::SetOptions(const VideoOptions& options) { 434 options_ = options; 435 return true; 436 } 437 438 bool FakeVideoMediaSendChannel::SetMaxSendBandwidth(int bps) { 439 max_bps_ = bps; 440 return true; 441 } 442 void FakeVideoMediaSendChannel::GenerateSendKeyFrame( 443 uint32_t /* ssrc */, 444 const std::vector<std::string>& /* rids */) {} 445 446 FakeVideoMediaReceiveChannel::FakeVideoMediaReceiveChannel( 447 const VideoOptions& options, 448 TaskQueueBase* network_thread) 449 : RtpReceiveChannelHelper<VideoMediaReceiveChannelInterface>( 450 network_thread), 451 max_bps_(-1) { 452 SetOptions(options); 453 } 454 FakeVideoMediaReceiveChannel::~FakeVideoMediaReceiveChannel() = default; 455 const std::vector<Codec>& FakeVideoMediaReceiveChannel::recv_codecs() const { 456 return recv_codecs_; 457 } 458 bool FakeVideoMediaReceiveChannel::rendering() const { 459 return playout(); 460 } 461 const VideoOptions& FakeVideoMediaReceiveChannel::options() const { 462 return options_; 463 } 464 const std::map<uint32_t, VideoSinkInterface<VideoFrame>*>& 465 FakeVideoMediaReceiveChannel::sinks() const { 466 return sinks_; 467 } 468 int FakeVideoMediaReceiveChannel::max_bps() const { 469 return max_bps_; 470 } 471 bool FakeVideoMediaReceiveChannel::SetReceiverParameters( 472 const VideoReceiverParameters& params) { 473 set_recv_rtcp_parameters(params.rtcp); 474 return (SetRecvCodecs(params.codecs) && 475 SetRecvRtpHeaderExtensions(params.extensions)); 476 } 477 bool FakeVideoMediaReceiveChannel::SetSink( 478 uint32_t ssrc, 479 VideoSinkInterface<VideoFrame>* sink) { 480 auto it = sinks_.find(ssrc); 481 if (it == sinks_.end()) { 482 return false; 483 } 484 it->second = sink; 485 return true; 486 } 487 void FakeVideoMediaReceiveChannel::SetDefaultSink( 488 VideoSinkInterface<VideoFrame>* /* sink */) {} 489 bool FakeVideoMediaReceiveChannel::HasSink(uint32_t ssrc) const { 490 return sinks_.find(ssrc) != sinks_.end() && sinks_.at(ssrc) != nullptr; 491 } 492 bool FakeVideoMediaReceiveChannel::HasSource(uint32_t ssrc) const { 493 return sources_.find(ssrc) != sources_.end() && sources_.at(ssrc) != nullptr; 494 } 495 bool FakeVideoMediaReceiveChannel::AddRecvStream(const StreamParams& sp) { 496 if (!RtpReceiveChannelHelper< 497 VideoMediaReceiveChannelInterface>::AddRecvStream(sp)) 498 return false; 499 sinks_[sp.first_ssrc()] = nullptr; 500 output_delays_[sp.first_ssrc()] = 0; 501 return true; 502 } 503 bool FakeVideoMediaReceiveChannel::RemoveRecvStream(uint32_t ssrc) { 504 if (!RtpReceiveChannelHelper< 505 VideoMediaReceiveChannelInterface>::RemoveRecvStream(ssrc)) 506 return false; 507 sinks_.erase(ssrc); 508 output_delays_.erase(ssrc); 509 return true; 510 } 511 std::vector<RtpSource> FakeVideoMediaReceiveChannel::GetSources( 512 uint32_t /* ssrc */) const { 513 return {}; 514 } 515 bool FakeVideoMediaReceiveChannel::SetBaseMinimumPlayoutDelayMs(uint32_t ssrc, 516 int delay_ms) { 517 if (output_delays_.find(ssrc) == output_delays_.end()) { 518 return false; 519 } else { 520 output_delays_[ssrc] = delay_ms; 521 return true; 522 } 523 } 524 std::optional<int> FakeVideoMediaReceiveChannel::GetBaseMinimumPlayoutDelayMs( 525 uint32_t ssrc) const { 526 const auto it = output_delays_.find(ssrc); 527 if (it != output_delays_.end()) { 528 return it->second; 529 } 530 return std::nullopt; 531 } 532 bool FakeVideoMediaReceiveChannel::SetRecvCodecs( 533 const std::vector<Codec>& codecs) { 534 if (fail_set_recv_codecs()) { 535 // Fake the failure in SetRecvCodecs. 536 return false; 537 } 538 recv_codecs_ = codecs; 539 return true; 540 } 541 bool FakeVideoMediaReceiveChannel::SetOptions(const VideoOptions& options) { 542 options_ = options; 543 return true; 544 } 545 546 bool FakeVideoMediaReceiveChannel::SetMaxSendBandwidth(int bps) { 547 max_bps_ = bps; 548 return true; 549 } 550 551 void FakeVideoMediaReceiveChannel::SetRecordableEncodedFrameCallback( 552 uint32_t /* ssrc */, 553 std::function<void(const RecordableEncodedFrame&)> /* callback */) {} 554 555 void FakeVideoMediaReceiveChannel::ClearRecordableEncodedFrameCallback( 556 uint32_t /* ssrc */) {} 557 558 void FakeVideoMediaReceiveChannel::RequestRecvKeyFrame(uint32_t /* ssrc */) {} 559 560 bool FakeVideoMediaReceiveChannel::GetStats(VideoMediaReceiveInfo* /* info */) { 561 return false; 562 } 563 564 FakeVoiceEngine::FakeVoiceEngine() 565 : encoder_factory_(make_ref_counted<FakeVoiceEncoderFactory>(this)), 566 decoder_factory_(make_ref_counted<FakeVoiceDecoderFactory>(this)) { 567 // Add a fake audio codec. Note that the name must not be "" as there are 568 // sanity checks against that. 569 SetCodecs({CreateAudioCodec(101, "fake_audio_codec", 8000, 1)}); 570 } 571 void FakeVoiceEngine::Init() {} 572 scoped_refptr<AudioState> FakeVoiceEngine::GetAudioState() const { 573 return scoped_refptr<AudioState>(); 574 } 575 std::unique_ptr<VoiceMediaSendChannelInterface> 576 FakeVoiceEngine::CreateSendChannel(const Environment& /*env*/, 577 Call* call, 578 const MediaConfig& /* config */, 579 const AudioOptions& options, 580 const CryptoOptions& /* crypto_options */, 581 AudioCodecPairId /* codec_pair_id */) { 582 std::unique_ptr<FakeVoiceMediaSendChannel> ch = 583 std::make_unique<FakeVoiceMediaSendChannel>(options, 584 call->network_thread()); 585 return ch; 586 } 587 std::unique_ptr<VoiceMediaReceiveChannelInterface> 588 FakeVoiceEngine::CreateReceiveChannel(const Environment& /*env*/, 589 Call* call, 590 const MediaConfig& /* config */, 591 const AudioOptions& options, 592 const CryptoOptions& /* crypto_options */, 593 AudioCodecPairId /* codec_pair_id */) { 594 std::unique_ptr<FakeVoiceMediaReceiveChannel> ch = 595 std::make_unique<FakeVoiceMediaReceiveChannel>(options, 596 call->network_thread()); 597 return ch; 598 } 599 const std::vector<Codec>& FakeVoiceEngine::LegacySendCodecs() const { 600 return send_codecs_; 601 } 602 const std::vector<Codec>& FakeVoiceEngine::LegacyRecvCodecs() const { 603 return recv_codecs_; 604 } 605 void FakeVoiceEngine::SetCodecs(const std::vector<Codec>& codecs) { 606 send_codecs_ = codecs; 607 recv_codecs_ = codecs; 608 } 609 void FakeVoiceEngine::SetRecvCodecs(const std::vector<Codec>& codecs) { 610 recv_codecs_ = codecs; 611 } 612 void FakeVoiceEngine::SetSendCodecs(const std::vector<Codec>& codecs) { 613 send_codecs_ = codecs; 614 } 615 int FakeVoiceEngine::GetInputLevel() { 616 return 0; 617 } 618 bool FakeVoiceEngine::StartAecDump(FileWrapper /* file */, 619 int64_t /* max_size_bytes */) { 620 return false; 621 } 622 std::optional<AudioDeviceModule::Stats> FakeVoiceEngine::GetAudioDeviceStats() { 623 return std::nullopt; 624 } 625 void FakeVoiceEngine::StopAecDump() {} 626 627 std::vector<RtpHeaderExtensionCapability> 628 FakeVoiceEngine::GetRtpHeaderExtensions( 629 const FieldTrialsView* field_trials) const { 630 return header_extensions_; 631 } 632 633 void FakeVoiceEngine::SetRtpHeaderExtensions( 634 std::vector<RtpHeaderExtensionCapability> header_extensions) { 635 header_extensions_ = std::move(header_extensions); 636 } 637 638 FakeVideoEngine::FakeVideoEngine() : capture_(false) { 639 // Add a fake video codec. Note that the name must not be "" as there are 640 // sanity checks against that. 641 send_codecs_.push_back(CreateVideoCodec(111, "fake_video_codec")); 642 recv_codecs_.push_back(CreateVideoCodec(111, "fake_video_codec")); 643 } 644 bool FakeVideoEngine::SetOptions(const VideoOptions& options) { 645 options_ = options; 646 return true; 647 } 648 std::unique_ptr<VideoMediaSendChannelInterface> 649 FakeVideoEngine::CreateSendChannel( 650 const Environment& /* env */, 651 Call* call, 652 const MediaConfig& /* config */, 653 const VideoOptions& options, 654 const CryptoOptions& /* crypto_options */, 655 VideoBitrateAllocatorFactory* /* video_bitrate_allocator_factory */) { 656 std::unique_ptr<FakeVideoMediaSendChannel> ch = 657 std::make_unique<FakeVideoMediaSendChannel>(options, 658 call->network_thread()); 659 return ch; 660 } 661 std::unique_ptr<VideoMediaReceiveChannelInterface> 662 FakeVideoEngine::CreateReceiveChannel( 663 const Environment& /* env */, 664 Call* call, 665 const MediaConfig& /* config */, 666 const VideoOptions& options, 667 const CryptoOptions& /* crypto_options */) { 668 std::unique_ptr<FakeVideoMediaReceiveChannel> ch = 669 std::make_unique<FakeVideoMediaReceiveChannel>(options, 670 call->network_thread()); 671 return ch; 672 } 673 std::vector<Codec> FakeVideoEngine::LegacySendCodecs(bool use_rtx) const { 674 if (use_rtx) { 675 return send_codecs_; 676 } else { 677 std::vector<Codec> non_rtx_codecs; 678 for (auto& codec : send_codecs_) { 679 if (codec.name != "rtx") { 680 non_rtx_codecs.push_back(codec); 681 } 682 } 683 return non_rtx_codecs; 684 } 685 } 686 687 std::vector<Codec> FakeVideoEngine::LegacyRecvCodecs(bool /* use_rtx */) const { 688 return recv_codecs_; 689 } 690 691 void FakeVideoEngine::SetSendCodecs(const std::vector<Codec>& codecs) { 692 send_codecs_ = codecs; 693 } 694 695 void FakeVideoEngine::SetRecvCodecs(const std::vector<Codec>& codecs) { 696 recv_codecs_ = codecs; 697 } 698 699 bool FakeVideoEngine::SetCapture(bool capture) { 700 capture_ = capture; 701 return true; 702 } 703 std::vector<RtpHeaderExtensionCapability> 704 FakeVideoEngine::GetRtpHeaderExtensions( 705 const FieldTrialsView* field_trials) const { 706 return header_extensions_; 707 } 708 void FakeVideoEngine::SetRtpHeaderExtensions( 709 std::vector<RtpHeaderExtensionCapability> header_extensions) { 710 header_extensions_ = std::move(header_extensions); 711 } 712 713 FakeMediaEngine::FakeMediaEngine() 714 : CompositeMediaEngine(std::make_unique<FakeVoiceEngine>(), 715 std::make_unique<FakeVideoEngine>()), 716 voice_(static_cast<FakeVoiceEngine*>(&voice())), 717 video_(static_cast<FakeVideoEngine*>(&video())) {} 718 FakeMediaEngine::~FakeMediaEngine() {} 719 void FakeMediaEngine::SetAudioCodecs(const std::vector<Codec>& codecs) { 720 voice_->SetCodecs(codecs); 721 } 722 void FakeMediaEngine::SetAudioRecvCodecs(const std::vector<Codec>& codecs) { 723 voice_->SetRecvCodecs(codecs); 724 } 725 void FakeMediaEngine::SetAudioSendCodecs(const std::vector<Codec>& codecs) { 726 voice_->SetSendCodecs(codecs); 727 } 728 void FakeMediaEngine::SetVideoCodecs(const std::vector<Codec>& codecs) { 729 video_->SetSendCodecs(codecs); 730 video_->SetRecvCodecs(codecs); 731 } 732 void FakeMediaEngine::SetVideoRecvCodecs(const std::vector<Codec>& codecs) { 733 video_->SetRecvCodecs(codecs); 734 } 735 void FakeMediaEngine::SetVideoSendCodecs(const std::vector<Codec>& codecs) { 736 video_->SetSendCodecs(codecs); 737 } 738 739 } // namespace webrtc