1 /*
2  *  Copyright (c) 2015 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/engine/fake_webrtc_call.h"
12 
13 #include <utility>
14 
15 #include "absl/algorithm/container.h"
16 #include "api/call/audio_sink.h"
17 #include "media/base/rtp_utils.h"
18 #include "rtc_base/checks.h"
19 #include "rtc_base/gunit.h"
20 
21 namespace cricket {
FakeAudioSendStream(int id,const webrtc::AudioSendStream::Config & config)22 FakeAudioSendStream::FakeAudioSendStream(
23     int id,
24     const webrtc::AudioSendStream::Config& config)
25     : id_(id), config_(config) {}
26 
Reconfigure(const webrtc::AudioSendStream::Config & config)27 void FakeAudioSendStream::Reconfigure(
28     const webrtc::AudioSendStream::Config& config) {
29   config_ = config;
30 }
31 
GetConfig() const32 const webrtc::AudioSendStream::Config& FakeAudioSendStream::GetConfig() const {
33   return config_;
34 }
35 
SetStats(const webrtc::AudioSendStream::Stats & stats)36 void FakeAudioSendStream::SetStats(
37     const webrtc::AudioSendStream::Stats& stats) {
38   stats_ = stats;
39 }
40 
41 FakeAudioSendStream::TelephoneEvent
GetLatestTelephoneEvent() const42 FakeAudioSendStream::GetLatestTelephoneEvent() const {
43   return latest_telephone_event_;
44 }
45 
SendTelephoneEvent(int payload_type,int payload_frequency,int event,int duration_ms)46 bool FakeAudioSendStream::SendTelephoneEvent(int payload_type,
47                                              int payload_frequency,
48                                              int event,
49                                              int duration_ms) {
50   latest_telephone_event_.payload_type = payload_type;
51   latest_telephone_event_.payload_frequency = payload_frequency;
52   latest_telephone_event_.event_code = event;
53   latest_telephone_event_.duration_ms = duration_ms;
54   return true;
55 }
56 
SetMuted(bool muted)57 void FakeAudioSendStream::SetMuted(bool muted) {
58   muted_ = muted;
59 }
60 
GetStats() const61 webrtc::AudioSendStream::Stats FakeAudioSendStream::GetStats() const {
62   return stats_;
63 }
64 
GetStats(bool) const65 webrtc::AudioSendStream::Stats FakeAudioSendStream::GetStats(
66     bool /*has_remote_tracks*/) const {
67   return stats_;
68 }
69 
FakeAudioReceiveStream(int id,const webrtc::AudioReceiveStream::Config & config)70 FakeAudioReceiveStream::FakeAudioReceiveStream(
71     int id,
72     const webrtc::AudioReceiveStream::Config& config)
73     : id_(id), config_(config) {}
74 
GetConfig() const75 const webrtc::AudioReceiveStream::Config& FakeAudioReceiveStream::GetConfig()
76     const {
77   return config_;
78 }
79 
SetStats(const webrtc::AudioReceiveStream::Stats & stats)80 void FakeAudioReceiveStream::SetStats(
81     const webrtc::AudioReceiveStream::Stats& stats) {
82   stats_ = stats;
83 }
84 
VerifyLastPacket(const uint8_t * data,size_t length) const85 bool FakeAudioReceiveStream::VerifyLastPacket(const uint8_t* data,
86                                               size_t length) const {
87   return last_packet_ == rtc::Buffer(data, length);
88 }
89 
DeliverRtp(const uint8_t * packet,size_t length,int64_t)90 bool FakeAudioReceiveStream::DeliverRtp(const uint8_t* packet,
91                                         size_t length,
92                                         int64_t /* packet_time_us */) {
93   ++received_packets_;
94   last_packet_.SetData(packet, length);
95   return true;
96 }
97 
Reconfigure(const webrtc::AudioReceiveStream::Config & config)98 void FakeAudioReceiveStream::Reconfigure(
99     const webrtc::AudioReceiveStream::Config& config) {
100   config_ = config;
101 }
102 
GetStats() const103 webrtc::AudioReceiveStream::Stats FakeAudioReceiveStream::GetStats() const {
104   return stats_;
105 }
106 
SetSink(webrtc::AudioSinkInterface * sink)107 void FakeAudioReceiveStream::SetSink(webrtc::AudioSinkInterface* sink) {
108   sink_ = sink;
109 }
110 
SetGain(float gain)111 void FakeAudioReceiveStream::SetGain(float gain) {
112   gain_ = gain;
113 }
114 
FakeVideoSendStream(webrtc::VideoSendStream::Config config,webrtc::VideoEncoderConfig encoder_config)115 FakeVideoSendStream::FakeVideoSendStream(
116     webrtc::VideoSendStream::Config config,
117     webrtc::VideoEncoderConfig encoder_config)
118     : sending_(false),
119       config_(std::move(config)),
120       codec_settings_set_(false),
121       resolution_scaling_enabled_(false),
122       framerate_scaling_enabled_(false),
123       source_(nullptr),
124       num_swapped_frames_(0) {
125   RTC_DCHECK(config.encoder_settings.encoder_factory != nullptr);
126   RTC_DCHECK(config.encoder_settings.bitrate_allocator_factory != nullptr);
127   ReconfigureVideoEncoder(std::move(encoder_config));
128 }
129 
~FakeVideoSendStream()130 FakeVideoSendStream::~FakeVideoSendStream() {
131   if (source_)
132     source_->RemoveSink(this);
133 }
134 
GetConfig() const135 const webrtc::VideoSendStream::Config& FakeVideoSendStream::GetConfig() const {
136   return config_;
137 }
138 
GetEncoderConfig() const139 const webrtc::VideoEncoderConfig& FakeVideoSendStream::GetEncoderConfig()
140     const {
141   return encoder_config_;
142 }
143 
GetVideoStreams() const144 const std::vector<webrtc::VideoStream>& FakeVideoSendStream::GetVideoStreams()
145     const {
146   return video_streams_;
147 }
148 
IsSending() const149 bool FakeVideoSendStream::IsSending() const {
150   return sending_;
151 }
152 
GetVp8Settings(webrtc::VideoCodecVP8 * settings) const153 bool FakeVideoSendStream::GetVp8Settings(
154     webrtc::VideoCodecVP8* settings) const {
155   if (!codec_settings_set_) {
156     return false;
157   }
158 
159   *settings = codec_specific_settings_.vp8;
160   return true;
161 }
162 
GetVp9Settings(webrtc::VideoCodecVP9 * settings) const163 bool FakeVideoSendStream::GetVp9Settings(
164     webrtc::VideoCodecVP9* settings) const {
165   if (!codec_settings_set_) {
166     return false;
167   }
168 
169   *settings = codec_specific_settings_.vp9;
170   return true;
171 }
172 
GetH264Settings(webrtc::VideoCodecH264 * settings) const173 bool FakeVideoSendStream::GetH264Settings(
174     webrtc::VideoCodecH264* settings) const {
175   if (!codec_settings_set_) {
176     return false;
177   }
178 
179   *settings = codec_specific_settings_.h264;
180   return true;
181 }
182 
GetNumberOfSwappedFrames() const183 int FakeVideoSendStream::GetNumberOfSwappedFrames() const {
184   return num_swapped_frames_;
185 }
186 
GetLastWidth() const187 int FakeVideoSendStream::GetLastWidth() const {
188   return last_frame_->width();
189 }
190 
GetLastHeight() const191 int FakeVideoSendStream::GetLastHeight() const {
192   return last_frame_->height();
193 }
194 
GetLastTimestamp() const195 int64_t FakeVideoSendStream::GetLastTimestamp() const {
196   RTC_DCHECK(last_frame_->ntp_time_ms() == 0);
197   return last_frame_->render_time_ms();
198 }
199 
OnFrame(const webrtc::VideoFrame & frame)200 void FakeVideoSendStream::OnFrame(const webrtc::VideoFrame& frame) {
201   ++num_swapped_frames_;
202   if (!last_frame_ || frame.width() != last_frame_->width() ||
203       frame.height() != last_frame_->height() ||
204       frame.rotation() != last_frame_->rotation()) {
205     video_streams_ = encoder_config_.video_stream_factory->CreateEncoderStreams(
206         frame.width(), frame.height(), encoder_config_);
207   }
208   last_frame_ = frame;
209 }
210 
SetStats(const webrtc::VideoSendStream::Stats & stats)211 void FakeVideoSendStream::SetStats(
212     const webrtc::VideoSendStream::Stats& stats) {
213   stats_ = stats;
214 }
215 
GetStats()216 webrtc::VideoSendStream::Stats FakeVideoSendStream::GetStats() {
217   return stats_;
218 }
219 
ReconfigureVideoEncoder(webrtc::VideoEncoderConfig config)220 void FakeVideoSendStream::ReconfigureVideoEncoder(
221     webrtc::VideoEncoderConfig config) {
222   int width, height;
223   if (last_frame_) {
224     width = last_frame_->width();
225     height = last_frame_->height();
226   } else {
227     width = height = 0;
228   }
229   video_streams_ =
230       config.video_stream_factory->CreateEncoderStreams(width, height, config);
231   if (config.encoder_specific_settings != NULL) {
232     const unsigned char num_temporal_layers = static_cast<unsigned char>(
233         video_streams_.back().num_temporal_layers.value_or(1));
234     if (config_.rtp.payload_name == "VP8") {
235       config.encoder_specific_settings->FillVideoCodecVp8(
236           &codec_specific_settings_.vp8);
237       if (!video_streams_.empty()) {
238         codec_specific_settings_.vp8.numberOfTemporalLayers =
239             num_temporal_layers;
240       }
241     } else if (config_.rtp.payload_name == "VP9") {
242       config.encoder_specific_settings->FillVideoCodecVp9(
243           &codec_specific_settings_.vp9);
244       if (!video_streams_.empty()) {
245         codec_specific_settings_.vp9.numberOfTemporalLayers =
246             num_temporal_layers;
247       }
248     } else if (config_.rtp.payload_name == "H264") {
249       config.encoder_specific_settings->FillVideoCodecH264(
250           &codec_specific_settings_.h264);
251       codec_specific_settings_.h264.numberOfTemporalLayers =
252           num_temporal_layers;
253     } else {
254       ADD_FAILURE() << "Unsupported encoder payload: "
255                     << config_.rtp.payload_name;
256     }
257   }
258   codec_settings_set_ = config.encoder_specific_settings != NULL;
259   encoder_config_ = std::move(config);
260   ++num_encoder_reconfigurations_;
261 }
262 
UpdateActiveSimulcastLayers(const std::vector<bool> active_layers)263 void FakeVideoSendStream::UpdateActiveSimulcastLayers(
264     const std::vector<bool> active_layers) {
265   sending_ = false;
266   for (const bool active_layer : active_layers) {
267     if (active_layer) {
268       sending_ = true;
269       break;
270     }
271   }
272 }
273 
Start()274 void FakeVideoSendStream::Start() {
275   sending_ = true;
276 }
277 
Stop()278 void FakeVideoSendStream::Stop() {
279   sending_ = false;
280 }
281 
AddAdaptationResource(rtc::scoped_refptr<webrtc::Resource> resource)282 void FakeVideoSendStream::AddAdaptationResource(
283     rtc::scoped_refptr<webrtc::Resource> resource) {}
284 
285 std::vector<rtc::scoped_refptr<webrtc::Resource>>
GetAdaptationResources()286 FakeVideoSendStream::GetAdaptationResources() {
287   return {};
288 }
289 
SetSource(rtc::VideoSourceInterface<webrtc::VideoFrame> * source,const webrtc::DegradationPreference & degradation_preference)290 void FakeVideoSendStream::SetSource(
291     rtc::VideoSourceInterface<webrtc::VideoFrame>* source,
292     const webrtc::DegradationPreference& degradation_preference) {
293   if (source_)
294     source_->RemoveSink(this);
295   source_ = source;
296   switch (degradation_preference) {
297     case webrtc::DegradationPreference::MAINTAIN_FRAMERATE:
298       resolution_scaling_enabled_ = true;
299       framerate_scaling_enabled_ = false;
300       break;
301     case webrtc::DegradationPreference::MAINTAIN_RESOLUTION:
302       resolution_scaling_enabled_ = false;
303       framerate_scaling_enabled_ = true;
304       break;
305     case webrtc::DegradationPreference::BALANCED:
306       resolution_scaling_enabled_ = true;
307       framerate_scaling_enabled_ = true;
308       break;
309     case webrtc::DegradationPreference::DISABLED:
310       resolution_scaling_enabled_ = false;
311       framerate_scaling_enabled_ = false;
312       break;
313   }
314   if (source)
315     source->AddOrUpdateSink(this, resolution_scaling_enabled_
316                                       ? sink_wants_
317                                       : rtc::VideoSinkWants());
318 }
319 
InjectVideoSinkWants(const rtc::VideoSinkWants & wants)320 void FakeVideoSendStream::InjectVideoSinkWants(
321     const rtc::VideoSinkWants& wants) {
322   sink_wants_ = wants;
323   source_->AddOrUpdateSink(this, wants);
324 }
325 
FakeVideoReceiveStream(webrtc::VideoReceiveStream::Config config)326 FakeVideoReceiveStream::FakeVideoReceiveStream(
327     webrtc::VideoReceiveStream::Config config)
328     : config_(std::move(config)),
329       receiving_(false),
330       num_added_secondary_sinks_(0),
331       num_removed_secondary_sinks_(0) {}
332 
GetConfig() const333 const webrtc::VideoReceiveStream::Config& FakeVideoReceiveStream::GetConfig()
334     const {
335   return config_;
336 }
337 
IsReceiving() const338 bool FakeVideoReceiveStream::IsReceiving() const {
339   return receiving_;
340 }
341 
InjectFrame(const webrtc::VideoFrame & frame)342 void FakeVideoReceiveStream::InjectFrame(const webrtc::VideoFrame& frame) {
343   config_.renderer->OnFrame(frame);
344 }
345 
GetStats() const346 webrtc::VideoReceiveStream::Stats FakeVideoReceiveStream::GetStats() const {
347   return stats_;
348 }
349 
Start()350 void FakeVideoReceiveStream::Start() {
351   receiving_ = true;
352 }
353 
Stop()354 void FakeVideoReceiveStream::Stop() {
355   receiving_ = false;
356 }
357 
SetStats(const webrtc::VideoReceiveStream::Stats & stats)358 void FakeVideoReceiveStream::SetStats(
359     const webrtc::VideoReceiveStream::Stats& stats) {
360   stats_ = stats;
361 }
362 
AddSecondarySink(webrtc::RtpPacketSinkInterface * sink)363 void FakeVideoReceiveStream::AddSecondarySink(
364     webrtc::RtpPacketSinkInterface* sink) {
365   ++num_added_secondary_sinks_;
366 }
367 
RemoveSecondarySink(const webrtc::RtpPacketSinkInterface * sink)368 void FakeVideoReceiveStream::RemoveSecondarySink(
369     const webrtc::RtpPacketSinkInterface* sink) {
370   ++num_removed_secondary_sinks_;
371 }
372 
GetNumAddedSecondarySinks() const373 int FakeVideoReceiveStream::GetNumAddedSecondarySinks() const {
374   return num_added_secondary_sinks_;
375 }
376 
GetNumRemovedSecondarySinks() const377 int FakeVideoReceiveStream::GetNumRemovedSecondarySinks() const {
378   return num_removed_secondary_sinks_;
379 }
380 
FakeFlexfecReceiveStream(const webrtc::FlexfecReceiveStream::Config & config)381 FakeFlexfecReceiveStream::FakeFlexfecReceiveStream(
382     const webrtc::FlexfecReceiveStream::Config& config)
383     : config_(config) {}
384 
385 const webrtc::FlexfecReceiveStream::Config&
GetConfig() const386 FakeFlexfecReceiveStream::GetConfig() const {
387   return config_;
388 }
389 
390 // TODO(brandtr): Implement when the stats have been designed.
GetStats() const391 webrtc::FlexfecReceiveStream::Stats FakeFlexfecReceiveStream::GetStats() const {
392   return webrtc::FlexfecReceiveStream::Stats();
393 }
394 
OnRtpPacket(const webrtc::RtpPacketReceived &)395 void FakeFlexfecReceiveStream::OnRtpPacket(const webrtc::RtpPacketReceived&) {
396   RTC_NOTREACHED() << "Not implemented.";
397 }
398 
FakeCall()399 FakeCall::FakeCall()
400     : audio_network_state_(webrtc::kNetworkUp),
401       video_network_state_(webrtc::kNetworkUp),
402       num_created_send_streams_(0),
403       num_created_receive_streams_(0) {}
404 
~FakeCall()405 FakeCall::~FakeCall() {
406   EXPECT_EQ(0u, video_send_streams_.size());
407   EXPECT_EQ(0u, audio_send_streams_.size());
408   EXPECT_EQ(0u, video_receive_streams_.size());
409   EXPECT_EQ(0u, audio_receive_streams_.size());
410 }
411 
GetVideoSendStreams()412 const std::vector<FakeVideoSendStream*>& FakeCall::GetVideoSendStreams() {
413   return video_send_streams_;
414 }
415 
GetVideoReceiveStreams()416 const std::vector<FakeVideoReceiveStream*>& FakeCall::GetVideoReceiveStreams() {
417   return video_receive_streams_;
418 }
419 
GetVideoReceiveStream(uint32_t ssrc)420 const FakeVideoReceiveStream* FakeCall::GetVideoReceiveStream(uint32_t ssrc) {
421   for (const auto* p : GetVideoReceiveStreams()) {
422     if (p->GetConfig().rtp.remote_ssrc == ssrc) {
423       return p;
424     }
425   }
426   return nullptr;
427 }
428 
GetAudioSendStreams()429 const std::vector<FakeAudioSendStream*>& FakeCall::GetAudioSendStreams() {
430   return audio_send_streams_;
431 }
432 
GetAudioSendStream(uint32_t ssrc)433 const FakeAudioSendStream* FakeCall::GetAudioSendStream(uint32_t ssrc) {
434   for (const auto* p : GetAudioSendStreams()) {
435     if (p->GetConfig().rtp.ssrc == ssrc) {
436       return p;
437     }
438   }
439   return nullptr;
440 }
441 
GetAudioReceiveStreams()442 const std::vector<FakeAudioReceiveStream*>& FakeCall::GetAudioReceiveStreams() {
443   return audio_receive_streams_;
444 }
445 
GetAudioReceiveStream(uint32_t ssrc)446 const FakeAudioReceiveStream* FakeCall::GetAudioReceiveStream(uint32_t ssrc) {
447   for (const auto* p : GetAudioReceiveStreams()) {
448     if (p->GetConfig().rtp.remote_ssrc == ssrc) {
449       return p;
450     }
451   }
452   return nullptr;
453 }
454 
455 const std::vector<FakeFlexfecReceiveStream*>&
GetFlexfecReceiveStreams()456 FakeCall::GetFlexfecReceiveStreams() {
457   return flexfec_receive_streams_;
458 }
459 
GetNetworkState(webrtc::MediaType media) const460 webrtc::NetworkState FakeCall::GetNetworkState(webrtc::MediaType media) const {
461   switch (media) {
462     case webrtc::MediaType::AUDIO:
463       return audio_network_state_;
464     case webrtc::MediaType::VIDEO:
465       return video_network_state_;
466     case webrtc::MediaType::DATA:
467     case webrtc::MediaType::ANY:
468       ADD_FAILURE() << "GetNetworkState called with unknown parameter.";
469       return webrtc::kNetworkDown;
470   }
471   // Even though all the values for the enum class are listed above,the compiler
472   // will emit a warning as the method may be called with a value outside of the
473   // valid enum range, unless this case is also handled.
474   ADD_FAILURE() << "GetNetworkState called with unknown parameter.";
475   return webrtc::kNetworkDown;
476 }
477 
CreateAudioSendStream(const webrtc::AudioSendStream::Config & config)478 webrtc::AudioSendStream* FakeCall::CreateAudioSendStream(
479     const webrtc::AudioSendStream::Config& config) {
480   FakeAudioSendStream* fake_stream =
481       new FakeAudioSendStream(next_stream_id_++, config);
482   audio_send_streams_.push_back(fake_stream);
483   ++num_created_send_streams_;
484   return fake_stream;
485 }
486 
DestroyAudioSendStream(webrtc::AudioSendStream * send_stream)487 void FakeCall::DestroyAudioSendStream(webrtc::AudioSendStream* send_stream) {
488   auto it = absl::c_find(audio_send_streams_,
489                          static_cast<FakeAudioSendStream*>(send_stream));
490   if (it == audio_send_streams_.end()) {
491     ADD_FAILURE() << "DestroyAudioSendStream called with unknown parameter.";
492   } else {
493     delete *it;
494     audio_send_streams_.erase(it);
495   }
496 }
497 
CreateAudioReceiveStream(const webrtc::AudioReceiveStream::Config & config)498 webrtc::AudioReceiveStream* FakeCall::CreateAudioReceiveStream(
499     const webrtc::AudioReceiveStream::Config& config) {
500   audio_receive_streams_.push_back(
501       new FakeAudioReceiveStream(next_stream_id_++, config));
502   ++num_created_receive_streams_;
503   return audio_receive_streams_.back();
504 }
505 
DestroyAudioReceiveStream(webrtc::AudioReceiveStream * receive_stream)506 void FakeCall::DestroyAudioReceiveStream(
507     webrtc::AudioReceiveStream* receive_stream) {
508   auto it = absl::c_find(audio_receive_streams_,
509                          static_cast<FakeAudioReceiveStream*>(receive_stream));
510   if (it == audio_receive_streams_.end()) {
511     ADD_FAILURE() << "DestroyAudioReceiveStream called with unknown parameter.";
512   } else {
513     delete *it;
514     audio_receive_streams_.erase(it);
515   }
516 }
517 
CreateVideoSendStream(webrtc::VideoSendStream::Config config,webrtc::VideoEncoderConfig encoder_config)518 webrtc::VideoSendStream* FakeCall::CreateVideoSendStream(
519     webrtc::VideoSendStream::Config config,
520     webrtc::VideoEncoderConfig encoder_config) {
521   FakeVideoSendStream* fake_stream =
522       new FakeVideoSendStream(std::move(config), std::move(encoder_config));
523   video_send_streams_.push_back(fake_stream);
524   ++num_created_send_streams_;
525   return fake_stream;
526 }
527 
DestroyVideoSendStream(webrtc::VideoSendStream * send_stream)528 void FakeCall::DestroyVideoSendStream(webrtc::VideoSendStream* send_stream) {
529   auto it = absl::c_find(video_send_streams_,
530                          static_cast<FakeVideoSendStream*>(send_stream));
531   if (it == video_send_streams_.end()) {
532     ADD_FAILURE() << "DestroyVideoSendStream called with unknown parameter.";
533   } else {
534     delete *it;
535     video_send_streams_.erase(it);
536   }
537 }
538 
CreateVideoReceiveStream(webrtc::VideoReceiveStream::Config config)539 webrtc::VideoReceiveStream* FakeCall::CreateVideoReceiveStream(
540     webrtc::VideoReceiveStream::Config config) {
541   video_receive_streams_.push_back(
542       new FakeVideoReceiveStream(std::move(config)));
543   ++num_created_receive_streams_;
544   return video_receive_streams_.back();
545 }
546 
DestroyVideoReceiveStream(webrtc::VideoReceiveStream * receive_stream)547 void FakeCall::DestroyVideoReceiveStream(
548     webrtc::VideoReceiveStream* receive_stream) {
549   auto it = absl::c_find(video_receive_streams_,
550                          static_cast<FakeVideoReceiveStream*>(receive_stream));
551   if (it == video_receive_streams_.end()) {
552     ADD_FAILURE() << "DestroyVideoReceiveStream called with unknown parameter.";
553   } else {
554     delete *it;
555     video_receive_streams_.erase(it);
556   }
557 }
558 
CreateFlexfecReceiveStream(const webrtc::FlexfecReceiveStream::Config & config)559 webrtc::FlexfecReceiveStream* FakeCall::CreateFlexfecReceiveStream(
560     const webrtc::FlexfecReceiveStream::Config& config) {
561   FakeFlexfecReceiveStream* fake_stream = new FakeFlexfecReceiveStream(config);
562   flexfec_receive_streams_.push_back(fake_stream);
563   ++num_created_receive_streams_;
564   return fake_stream;
565 }
566 
DestroyFlexfecReceiveStream(webrtc::FlexfecReceiveStream * receive_stream)567 void FakeCall::DestroyFlexfecReceiveStream(
568     webrtc::FlexfecReceiveStream* receive_stream) {
569   auto it =
570       absl::c_find(flexfec_receive_streams_,
571                    static_cast<FakeFlexfecReceiveStream*>(receive_stream));
572   if (it == flexfec_receive_streams_.end()) {
573     ADD_FAILURE()
574         << "DestroyFlexfecReceiveStream called with unknown parameter.";
575   } else {
576     delete *it;
577     flexfec_receive_streams_.erase(it);
578   }
579 }
580 
AddAdaptationResource(rtc::scoped_refptr<webrtc::Resource> resource)581 void FakeCall::AddAdaptationResource(
582     rtc::scoped_refptr<webrtc::Resource> resource) {}
583 
Receiver()584 webrtc::PacketReceiver* FakeCall::Receiver() {
585   return this;
586 }
587 
DeliverPacket(webrtc::MediaType media_type,rtc::CopyOnWriteBuffer packet,int64_t packet_time_us)588 FakeCall::DeliveryStatus FakeCall::DeliverPacket(webrtc::MediaType media_type,
589                                                  rtc::CopyOnWriteBuffer packet,
590                                                  int64_t packet_time_us) {
591   EXPECT_GE(packet.size(), 12u);
592   RTC_DCHECK(media_type == webrtc::MediaType::AUDIO ||
593              media_type == webrtc::MediaType::VIDEO);
594 
595   uint32_t ssrc;
596   if (!GetRtpSsrc(packet.cdata(), packet.size(), &ssrc))
597     return DELIVERY_PACKET_ERROR;
598 
599   if (media_type == webrtc::MediaType::VIDEO) {
600     for (auto receiver : video_receive_streams_) {
601       if (receiver->GetConfig().rtp.remote_ssrc == ssrc)
602         return DELIVERY_OK;
603     }
604   }
605   if (media_type == webrtc::MediaType::AUDIO) {
606     for (auto receiver : audio_receive_streams_) {
607       if (receiver->GetConfig().rtp.remote_ssrc == ssrc) {
608         receiver->DeliverRtp(packet.cdata(), packet.size(), packet_time_us);
609         return DELIVERY_OK;
610       }
611     }
612   }
613   return DELIVERY_UNKNOWN_SSRC;
614 }
615 
SetStats(const webrtc::Call::Stats & stats)616 void FakeCall::SetStats(const webrtc::Call::Stats& stats) {
617   stats_ = stats;
618 }
619 
GetNumCreatedSendStreams() const620 int FakeCall::GetNumCreatedSendStreams() const {
621   return num_created_send_streams_;
622 }
623 
GetNumCreatedReceiveStreams() const624 int FakeCall::GetNumCreatedReceiveStreams() const {
625   return num_created_receive_streams_;
626 }
627 
GetStats() const628 webrtc::Call::Stats FakeCall::GetStats() const {
629   return stats_;
630 }
631 
SignalChannelNetworkState(webrtc::MediaType media,webrtc::NetworkState state)632 void FakeCall::SignalChannelNetworkState(webrtc::MediaType media,
633                                          webrtc::NetworkState state) {
634   switch (media) {
635     case webrtc::MediaType::AUDIO:
636       audio_network_state_ = state;
637       break;
638     case webrtc::MediaType::VIDEO:
639       video_network_state_ = state;
640       break;
641     case webrtc::MediaType::DATA:
642     case webrtc::MediaType::ANY:
643       ADD_FAILURE()
644           << "SignalChannelNetworkState called with unknown parameter.";
645   }
646 }
647 
OnAudioTransportOverheadChanged(int transport_overhead_per_packet)648 void FakeCall::OnAudioTransportOverheadChanged(
649     int transport_overhead_per_packet) {}
650 
OnSentPacket(const rtc::SentPacket & sent_packet)651 void FakeCall::OnSentPacket(const rtc::SentPacket& sent_packet) {
652   last_sent_packet_ = sent_packet;
653   if (sent_packet.packet_id >= 0) {
654     last_sent_nonnegative_packet_id_ = sent_packet.packet_id;
655   }
656 }
657 
658 }  // namespace cricket
659