• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2004 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 #ifndef MEDIA_BASE_FAKE_MEDIA_ENGINE_H_
12 #define MEDIA_BASE_FAKE_MEDIA_ENGINE_H_
13 
14 #include <list>
15 #include <map>
16 #include <memory>
17 #include <set>
18 #include <string>
19 #include <tuple>
20 #include <vector>
21 
22 #include "absl/algorithm/container.h"
23 #include "api/call/audio_sink.h"
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"
29 #include "modules/audio_processing/include/audio_processing.h"
30 #include "rtc_base/copy_on_write_buffer.h"
31 #include "rtc_base/network_route.h"
32 
33 using webrtc::RtpExtension;
34 
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.
42 template <class Base>
43 class RtpHelper : public Base {
44  public:
RtpHelper()45   RtpHelper()
46       : sending_(false),
47         playout_(false),
48         fail_set_send_codecs_(false),
49         fail_set_recv_codecs_(false),
50         send_ssrc_(0),
51         ready_to_send_(false),
52         transport_overhead_per_packet_(0),
53         num_network_route_changes_(0) {}
54   virtual ~RtpHelper() = default;
recv_extensions()55   const std::vector<RtpExtension>& recv_extensions() {
56     return recv_extensions_;
57   }
send_extensions()58   const std::vector<RtpExtension>& send_extensions() {
59     return send_extensions_;
60   }
sending()61   bool sending() const { return sending_; }
playout()62   bool playout() const { return playout_; }
rtp_packets()63   const std::list<std::string>& rtp_packets() const { return rtp_packets_; }
rtcp_packets()64   const std::list<std::string>& rtcp_packets() const { return rtcp_packets_; }
65 
SendRtp(const void * data,size_t len,const rtc::PacketOptions & options)66   bool SendRtp(const void* data,
67                size_t len,
68                const rtc::PacketOptions& options) {
69     if (!sending_) {
70       return false;
71     }
72     rtc::CopyOnWriteBuffer packet(reinterpret_cast<const uint8_t*>(data), len,
73                                   kMaxRtpPacketLen);
74     return Base::SendPacket(&packet, options);
75   }
SendRtcp(const void * data,size_t len)76   bool SendRtcp(const void* data, size_t len) {
77     rtc::CopyOnWriteBuffer packet(reinterpret_cast<const uint8_t*>(data), len,
78                                   kMaxRtpPacketLen);
79     return Base::SendRtcp(&packet, rtc::PacketOptions());
80   }
81 
CheckRtp(const void * data,size_t len)82   bool CheckRtp(const void* data, size_t len) {
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   }
CheckRtcp(const void * data,size_t len)91   bool CheckRtcp(const void* data, size_t len) {
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   }
CheckNoRtp()100   bool CheckNoRtp() { return rtp_packets_.empty(); }
CheckNoRtcp()101   bool CheckNoRtcp() { return rtcp_packets_.empty(); }
set_fail_set_send_codecs(bool fail)102   void set_fail_set_send_codecs(bool fail) { fail_set_send_codecs_ = fail; }
set_fail_set_recv_codecs(bool fail)103   void set_fail_set_recv_codecs(bool fail) { fail_set_recv_codecs_ = fail; }
AddSendStream(const StreamParams & sp)104   virtual bool AddSendStream(const StreamParams& sp) {
105     if (absl::c_linear_search(send_streams_, sp)) {
106       return false;
107     }
108     send_streams_.push_back(sp);
109     rtp_send_parameters_[sp.first_ssrc()] =
110         CreateRtpParametersWithEncodings(sp);
111     return true;
112   }
RemoveSendStream(uint32_t ssrc)113   virtual bool RemoveSendStream(uint32_t ssrc) {
114     auto parameters_iterator = rtp_send_parameters_.find(ssrc);
115     if (parameters_iterator != rtp_send_parameters_.end()) {
116       rtp_send_parameters_.erase(parameters_iterator);
117     }
118     return RemoveStreamBySsrc(&send_streams_, ssrc);
119   }
ResetUnsignaledRecvStream()120   virtual void ResetUnsignaledRecvStream() {}
121 
AddRecvStream(const StreamParams & sp)122   virtual bool AddRecvStream(const StreamParams& sp) {
123     if (absl::c_linear_search(receive_streams_, sp)) {
124       return false;
125     }
126     receive_streams_.push_back(sp);
127     rtp_receive_parameters_[sp.first_ssrc()] =
128         CreateRtpParametersWithEncodings(sp);
129     return true;
130   }
RemoveRecvStream(uint32_t ssrc)131   virtual bool RemoveRecvStream(uint32_t ssrc) {
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     }
136     return RemoveStreamBySsrc(&receive_streams_, ssrc);
137   }
138 
GetRtpSendParameters(uint32_t ssrc)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()) {
142       return parameters_iterator->second;
143     }
144     return webrtc::RtpParameters();
145   }
SetRtpSendParameters(uint32_t ssrc,const webrtc::RtpParameters & parameters)146   virtual webrtc::RTCError SetRtpSendParameters(
147       uint32_t ssrc,
148       const webrtc::RtpParameters& parameters) {
149     auto parameters_iterator = rtp_send_parameters_.find(ssrc);
150     if (parameters_iterator != rtp_send_parameters_.end()) {
151       auto result = CheckRtpParametersInvalidModificationAndValues(
152           parameters_iterator->second, parameters);
153       if (!result.ok())
154         return result;
155 
156       parameters_iterator->second = parameters;
157       return webrtc::RTCError::OK();
158     }
159     // Replicate the behavior of the real media channel: return false
160     // when setting parameters for unknown SSRCs.
161     return webrtc::RTCError(webrtc::RTCErrorType::INTERNAL_ERROR);
162   }
163 
GetRtpReceiveParameters(uint32_t ssrc)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   }
GetDefaultRtpReceiveParameters()171   virtual webrtc::RtpParameters GetDefaultRtpReceiveParameters() const {
172     return webrtc::RtpParameters();
173   }
174 
IsStreamMuted(uint32_t ssrc)175   bool IsStreamMuted(uint32_t ssrc) const {
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   }
send_streams()184   const std::vector<StreamParams>& send_streams() const {
185     return send_streams_;
186   }
recv_streams()187   const std::vector<StreamParams>& recv_streams() const {
188     return receive_streams_;
189   }
HasRecvStream(uint32_t ssrc)190   bool HasRecvStream(uint32_t ssrc) const {
191     return GetStreamBySsrc(receive_streams_, ssrc) != nullptr;
192   }
HasSendStream(uint32_t ssrc)193   bool HasSendStream(uint32_t ssrc) const {
194     return GetStreamBySsrc(send_streams_, ssrc) != nullptr;
195   }
196   // TODO(perkj): This is to support legacy unit test that only check one
197   // sending stream.
send_ssrc()198   uint32_t send_ssrc() const {
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.
rtcp_cname()206   const std::string rtcp_cname() {
207     if (send_streams_.empty())
208       return "";
209     return send_streams_[0].cname;
210   }
send_rtcp_parameters()211   const RtcpParameters& send_rtcp_parameters() { return send_rtcp_parameters_; }
recv_rtcp_parameters()212   const RtcpParameters& recv_rtcp_parameters() { return recv_rtcp_parameters_; }
213 
ready_to_send()214   bool ready_to_send() const { return ready_to_send_; }
215 
transport_overhead_per_packet()216   int transport_overhead_per_packet() const {
217     return transport_overhead_per_packet_;
218   }
219 
last_network_route()220   rtc::NetworkRoute last_network_route() const { return last_network_route_; }
num_network_route_changes()221   int num_network_route_changes() const { return num_network_route_changes_; }
set_num_network_route_changes(int changes)222   void set_num_network_route_changes(int changes) {
223     num_network_route_changes_ = changes;
224   }
225 
OnRtcpPacketReceived(rtc::CopyOnWriteBuffer * packet,int64_t packet_time_us)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 
231  protected:
MuteStream(uint32_t ssrc,bool mute)232   bool MuteStream(uint32_t ssrc, bool mute) {
233     if (!HasSendStream(ssrc) && ssrc != 0) {
234       return false;
235     }
236     if (mute) {
237       muted_streams_.insert(ssrc);
238     } else {
239       muted_streams_.erase(ssrc);
240     }
241     return true;
242   }
set_sending(bool send)243   bool set_sending(bool send) {
244     sending_ = send;
245     return true;
246   }
set_playout(bool playout)247   void set_playout(bool playout) { playout_ = playout; }
SetRecvRtpHeaderExtensions(const std::vector<RtpExtension> & extensions)248   bool SetRecvRtpHeaderExtensions(const std::vector<RtpExtension>& extensions) {
249     recv_extensions_ = extensions;
250     return true;
251   }
SetSendExtmapAllowMixed(bool extmap_allow_mixed)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   }
SetSendRtpHeaderExtensions(const std::vector<RtpExtension> & extensions)258   bool SetSendRtpHeaderExtensions(const std::vector<RtpExtension>& extensions) {
259     send_extensions_ = extensions;
260     return true;
261   }
set_send_rtcp_parameters(const RtcpParameters & params)262   void set_send_rtcp_parameters(const RtcpParameters& params) {
263     send_rtcp_parameters_ = params;
264   }
set_recv_rtcp_parameters(const RtcpParameters & params)265   void set_recv_rtcp_parameters(const RtcpParameters& params) {
266     recv_rtcp_parameters_ = params;
267   }
OnPacketReceived(rtc::CopyOnWriteBuffer packet,int64_t packet_time_us)268   virtual void OnPacketReceived(rtc::CopyOnWriteBuffer packet,
269                                 int64_t packet_time_us) {
270     rtp_packets_.push_back(std::string(packet.cdata<char>(), packet.size()));
271   }
OnReadyToSend(bool ready)272   virtual void OnReadyToSend(bool ready) { ready_to_send_ = ready; }
273 
OnNetworkRouteChanged(const std::string & transport_name,const rtc::NetworkRoute & network_route)274   virtual void OnNetworkRouteChanged(const std::string& transport_name,
275                                      const rtc::NetworkRoute& network_route) {
276     last_network_route_ = network_route;
277     ++num_network_route_changes_;
278     transport_overhead_per_packet_ = network_route.packet_overhead;
279   }
fail_set_send_codecs()280   bool fail_set_send_codecs() const { return fail_set_send_codecs_; }
fail_set_recv_codecs()281   bool fail_set_recv_codecs() const { return fail_set_recv_codecs_; }
282 
283  private:
284   bool sending_;
285   bool playout_;
286   std::vector<RtpExtension> recv_extensions_;
287   std::vector<RtpExtension> send_extensions_;
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_;
292   RtcpParameters send_rtcp_parameters_;
293   RtcpParameters recv_rtcp_parameters_;
294   std::set<uint32_t> muted_streams_;
295   std::map<uint32_t, webrtc::RtpParameters> rtp_send_parameters_;
296   std::map<uint32_t, webrtc::RtpParameters> rtp_receive_parameters_;
297   bool fail_set_send_codecs_;
298   bool fail_set_recv_codecs_;
299   uint32_t send_ssrc_;
300   std::string rtcp_cname_;
301   bool ready_to_send_;
302   int transport_overhead_per_packet_;
303   rtc::NetworkRoute last_network_route_;
304   int num_network_route_changes_;
305 };
306 
307 class FakeVoiceMediaChannel : public RtpHelper<VoiceMediaChannel> {
308  public:
309   struct DtmfInfo {
310     DtmfInfo(uint32_t ssrc, int event_code, int duration);
311     uint32_t ssrc;
312     int event_code;
313     int duration;
314   };
315   explicit FakeVoiceMediaChannel(FakeVoiceEngine* engine,
316                                  const AudioOptions& options);
317   ~FakeVoiceMediaChannel();
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;
325 
326   bool SetRecvParameters(const AudioRecvParameters& params) override;
327 
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;
334 
335   bool HasSource(uint32_t ssrc) const;
336 
337   bool AddRecvStream(const StreamParams& sp) override;
338   bool RemoveRecvStream(uint32_t ssrc) override;
339 
340   bool CanInsertDtmf() override;
341   bool InsertDtmf(uint32_t ssrc, int event_code, int duration) override;
342 
343   bool SetOutputVolume(uint32_t ssrc, double volume) override;
344   bool SetDefaultOutputVolume(double volume) override;
345 
346   bool GetOutputVolume(uint32_t ssrc, double* volume);
347 
348   bool SetBaseMinimumPlayoutDelayMs(uint32_t ssrc, int delay_ms) override;
349   absl::optional<int> GetBaseMinimumPlayoutDelayMs(
350       uint32_t ssrc) const override;
351 
352   bool GetStats(VoiceMediaInfo* info) override;
353 
354   void SetRawAudioSink(
355       uint32_t ssrc,
356       std::unique_ptr<webrtc::AudioSinkInterface> sink) override;
357   void SetDefaultRawAudioSink(
358       std::unique_ptr<webrtc::AudioSinkInterface> sink) override;
359 
360   std::vector<webrtc::RtpSource> GetSources(uint32_t ssrc) const override;
361 
362  private:
363   class VoiceChannelAudioSink : public AudioSource::Sink {
364    public:
365     explicit VoiceChannelAudioSink(AudioSource* source);
366     ~VoiceChannelAudioSink() override;
367     void OnData(const void* audio_data,
368                 int bits_per_sample,
369                 int sample_rate,
370                 size_t number_of_channels,
371                 size_t number_of_frames,
372                 absl::optional<int64_t> absolute_capture_timestamp_ms) override;
373     void OnClose() override;
374     AudioSource* source() const;
375 
376    private:
377     AudioSource* source_;
378   };
379 
380   bool SetRecvCodecs(const std::vector<AudioCodec>& codecs);
381   bool SetSendCodecs(const std::vector<AudioCodec>& codecs);
382   bool SetMaxSendBandwidth(int bps);
383   bool SetOptions(const AudioOptions& options);
384   bool SetLocalSource(uint32_t ssrc, AudioSource* source);
385 
386   FakeVoiceEngine* engine_;
387   std::vector<AudioCodec> recv_codecs_;
388   std::vector<AudioCodec> send_codecs_;
389   std::map<uint32_t, double> output_scalings_;
390   std::map<uint32_t, int> output_delays_;
391   std::vector<DtmfInfo> dtmf_info_queue_;
392   AudioOptions options_;
393   std::map<uint32_t, std::unique_ptr<VoiceChannelAudioSink>> local_sinks_;
394   std::unique_ptr<webrtc::AudioSinkInterface> sink_;
395   int max_bps_;
396 };
397 
398 // A helper function to compare the FakeVoiceMediaChannel::DtmfInfo.
399 bool CompareDtmfInfo(const FakeVoiceMediaChannel::DtmfInfo& info,
400                      uint32_t ssrc,
401                      int event_code,
402                      int duration);
403 
404 class FakeVideoMediaChannel : public RtpHelper<VideoMediaChannel> {
405  public:
406   FakeVideoMediaChannel(FakeVideoEngine* engine, const VideoOptions& options);
407 
408   ~FakeVideoMediaChannel();
409 
410   const std::vector<VideoCodec>& recv_codecs() const;
411   const std::vector<VideoCodec>& send_codecs() const;
412   const std::vector<VideoCodec>& codecs() const;
413   bool rendering() const;
414   const VideoOptions& options() const;
415   const std::map<uint32_t, rtc::VideoSinkInterface<webrtc::VideoFrame>*>&
416   sinks() const;
417   int max_bps() const;
418   bool SetSendParameters(const VideoSendParameters& params) override;
419   bool SetRecvParameters(const VideoRecvParameters& params) override;
420   bool AddSendStream(const StreamParams& sp) override;
421   bool RemoveSendStream(uint32_t ssrc) override;
422 
423   bool GetSendCodec(VideoCodec* send_codec) override;
424   bool SetSink(uint32_t ssrc,
425                rtc::VideoSinkInterface<webrtc::VideoFrame>* sink) override;
426   void SetDefaultSink(
427       rtc::VideoSinkInterface<webrtc::VideoFrame>* sink) override;
428   bool HasSink(uint32_t ssrc) const;
429 
430   bool SetSend(bool send) override;
431   bool SetVideoSend(
432       uint32_t ssrc,
433       const VideoOptions* options,
434       rtc::VideoSourceInterface<webrtc::VideoFrame>* source) override;
435 
436   bool HasSource(uint32_t ssrc) const;
437   bool AddRecvStream(const StreamParams& sp) override;
438   bool RemoveRecvStream(uint32_t ssrc) override;
439 
440   void FillBitrateInfo(BandwidthEstimationInfo* bwe_info) override;
441   bool GetStats(VideoMediaInfo* info) override;
442 
443   std::vector<webrtc::RtpSource> GetSources(uint32_t ssrc) const override;
444 
445   bool SetBaseMinimumPlayoutDelayMs(uint32_t ssrc, int delay_ms) override;
446   absl::optional<int> GetBaseMinimumPlayoutDelayMs(
447       uint32_t ssrc) const override;
448 
449   void SetRecordableEncodedFrameCallback(
450       uint32_t ssrc,
451       std::function<void(const webrtc::RecordableEncodedFrame&)> callback)
452       override;
453   void ClearRecordableEncodedFrameCallback(uint32_t ssrc) override;
454   void GenerateKeyFrame(uint32_t ssrc) override;
455 
456  private:
457   bool SetRecvCodecs(const std::vector<VideoCodec>& codecs);
458   bool SetSendCodecs(const std::vector<VideoCodec>& codecs);
459   bool SetOptions(const VideoOptions& options);
460   bool SetMaxSendBandwidth(int bps);
461 
462   FakeVideoEngine* engine_;
463   std::vector<VideoCodec> recv_codecs_;
464   std::vector<VideoCodec> send_codecs_;
465   std::map<uint32_t, rtc::VideoSinkInterface<webrtc::VideoFrame>*> sinks_;
466   std::map<uint32_t, rtc::VideoSourceInterface<webrtc::VideoFrame>*> sources_;
467   std::map<uint32_t, int> output_delays_;
468   VideoOptions options_;
469   int max_bps_;
470 };
471 
472 // Dummy option class, needed for the DataTraits abstraction in
473 // channel_unittest.c.
474 class DataOptions {};
475 
476 class FakeDataMediaChannel : public RtpHelper<DataMediaChannel> {
477  public:
478   explicit FakeDataMediaChannel(void* unused, const DataOptions& options);
479   ~FakeDataMediaChannel();
480   const std::vector<DataCodec>& recv_codecs() const;
481   const std::vector<DataCodec>& send_codecs() const;
482   const std::vector<DataCodec>& codecs() const;
483   int max_bps() const;
484 
485   bool SetSendParameters(const DataSendParameters& params) override;
486   bool SetRecvParameters(const DataRecvParameters& params) override;
487   bool SetSend(bool send) override;
488   bool SetReceive(bool receive) override;
489   bool AddRecvStream(const StreamParams& sp) override;
490   bool RemoveRecvStream(uint32_t ssrc) override;
491 
492   bool SendData(const SendDataParams& params,
493                 const rtc::CopyOnWriteBuffer& payload,
494                 SendDataResult* result) override;
495 
496   SendDataParams last_sent_data_params();
497   std::string last_sent_data();
498   bool is_send_blocked();
499   void set_send_blocked(bool blocked);
500 
501  private:
502   bool SetRecvCodecs(const std::vector<DataCodec>& codecs);
503   bool SetSendCodecs(const std::vector<DataCodec>& codecs);
504   bool SetMaxSendBandwidth(int bps);
505 
506   std::vector<DataCodec> recv_codecs_;
507   std::vector<DataCodec> send_codecs_;
508   SendDataParams last_sent_data_params_;
509   std::string last_sent_data_;
510   bool send_blocked_;
511   int max_bps_;
512 };
513 
514 class FakeVoiceEngine : public VoiceEngineInterface {
515  public:
516   FakeVoiceEngine();
517   void Init() override;
518   rtc::scoped_refptr<webrtc::AudioState> GetAudioState() const override;
519 
520   VoiceMediaChannel* CreateMediaChannel(
521       webrtc::Call* call,
522       const MediaConfig& config,
523       const AudioOptions& options,
524       const webrtc::CryptoOptions& crypto_options) override;
525   FakeVoiceMediaChannel* GetChannel(size_t index);
526   void UnregisterChannel(VoiceMediaChannel* channel);
527 
528   // TODO(ossu): For proper testing, These should either individually settable
529   //             or the voice engine should reference mockable factories.
530   const std::vector<AudioCodec>& send_codecs() const override;
531   const std::vector<AudioCodec>& recv_codecs() const override;
532   void SetCodecs(const std::vector<AudioCodec>& codecs);
533   void SetRecvCodecs(const std::vector<AudioCodec>& codecs);
534   void SetSendCodecs(const std::vector<AudioCodec>& codecs);
535   int GetInputLevel();
536   bool StartAecDump(webrtc::FileWrapper file, int64_t max_size_bytes) override;
537   void StopAecDump() override;
538   std::vector<webrtc::RtpHeaderExtensionCapability> GetRtpHeaderExtensions()
539       const override;
540   void SetRtpHeaderExtensions(
541       std::vector<webrtc::RtpHeaderExtensionCapability> header_extensions);
542 
543  private:
544   std::vector<FakeVoiceMediaChannel*> channels_;
545   std::vector<AudioCodec> recv_codecs_;
546   std::vector<AudioCodec> send_codecs_;
547   bool fail_create_channel_;
548   std::vector<webrtc::RtpHeaderExtensionCapability> header_extensions_;
549 
550   friend class FakeMediaEngine;
551 };
552 
553 class FakeVideoEngine : public VideoEngineInterface {
554  public:
555   FakeVideoEngine();
556   bool SetOptions(const VideoOptions& options);
557   VideoMediaChannel* CreateMediaChannel(
558       webrtc::Call* call,
559       const MediaConfig& config,
560       const VideoOptions& options,
561       const webrtc::CryptoOptions& crypto_options,
562       webrtc::VideoBitrateAllocatorFactory* video_bitrate_allocator_factory)
563       override;
564   FakeVideoMediaChannel* GetChannel(size_t index);
565   void UnregisterChannel(VideoMediaChannel* channel);
566   std::vector<VideoCodec> send_codecs() const override;
567   std::vector<VideoCodec> recv_codecs() const override;
568   void SetSendCodecs(const std::vector<VideoCodec>& codecs);
569   void SetRecvCodecs(const std::vector<VideoCodec>& codecs);
570   bool SetCapture(bool capture);
571   std::vector<webrtc::RtpHeaderExtensionCapability> GetRtpHeaderExtensions()
572       const override;
573   void SetRtpHeaderExtensions(
574       std::vector<webrtc::RtpHeaderExtensionCapability> header_extensions);
575 
576  private:
577   std::vector<FakeVideoMediaChannel*> channels_;
578   std::vector<VideoCodec> send_codecs_;
579   std::vector<VideoCodec> recv_codecs_;
580   bool capture_;
581   VideoOptions options_;
582   bool fail_create_channel_;
583   std::vector<webrtc::RtpHeaderExtensionCapability> header_extensions_;
584 
585   friend class FakeMediaEngine;
586 };
587 
588 class FakeMediaEngine : public CompositeMediaEngine {
589  public:
590   FakeMediaEngine();
591 
592   ~FakeMediaEngine() override;
593 
594   void SetAudioCodecs(const std::vector<AudioCodec>& codecs);
595   void SetAudioRecvCodecs(const std::vector<AudioCodec>& codecs);
596   void SetAudioSendCodecs(const std::vector<AudioCodec>& codecs);
597   void SetVideoCodecs(const std::vector<VideoCodec>& codecs);
598 
599   FakeVoiceMediaChannel* GetVoiceChannel(size_t index);
600   FakeVideoMediaChannel* GetVideoChannel(size_t index);
601 
602   void set_fail_create_channel(bool fail);
603 
604  private:
605   FakeVoiceEngine* const voice_;
606   FakeVideoEngine* const video_;
607 };
608 
609 // Have to come afterwards due to declaration order
610 
611 class FakeDataEngine : public DataEngineInterface {
612  public:
613   DataMediaChannel* CreateChannel(const MediaConfig& config) override;
614 
615   FakeDataMediaChannel* GetChannel(size_t index);
616 
617   void UnregisterChannel(DataMediaChannel* channel);
618 
619   void SetDataCodecs(const std::vector<DataCodec>& data_codecs);
620 
621   const std::vector<DataCodec>& data_codecs() override;
622 
623  private:
624   std::vector<FakeDataMediaChannel*> channels_;
625   std::vector<DataCodec> data_codecs_;
626 };
627 
628 }  // namespace cricket
629 
630 #endif  // MEDIA_BASE_FAKE_MEDIA_ENGINE_H_
631