fake_media_engine.h 22 KB

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