OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2004 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2004 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #ifndef WEBRTC_MEDIA_BASE_FAKEMEDIAENGINE_H_ | 11 #ifndef WEBRTC_MEDIA_BASE_FAKEMEDIAENGINE_H_ |
12 #define WEBRTC_MEDIA_BASE_FAKEMEDIAENGINE_H_ | 12 #define WEBRTC_MEDIA_BASE_FAKEMEDIAENGINE_H_ |
13 | 13 |
14 #include <list> | 14 #include <list> |
15 #include <map> | 15 #include <map> |
16 #include <memory> | 16 #include <memory> |
17 #include <set> | 17 #include <set> |
18 #include <string> | 18 #include <string> |
19 #include <vector> | 19 #include <vector> |
20 | 20 |
21 #include "webrtc/api/call/audio_sink.h" | 21 #include "webrtc/api/call/audio_sink.h" |
22 #include "webrtc/media/base/audiosource.h" | 22 #include "webrtc/media/base/audiosource.h" |
23 #include "webrtc/media/base/mediaengine.h" | 23 #include "webrtc/media/base/mediaengine.h" |
24 #include "webrtc/media/base/rtputils.h" | 24 #include "webrtc/media/base/rtputils.h" |
25 #include "webrtc/media/base/streamparams.h" | 25 #include "webrtc/media/base/streamparams.h" |
| 26 #include "webrtc/media/engine/webrtcvideoengine.h" |
26 #include "webrtc/modules/audio_processing/include/audio_processing.h" | 27 #include "webrtc/modules/audio_processing/include/audio_processing.h" |
27 #include "webrtc/p2p/base/sessiondescription.h" | 28 #include "webrtc/p2p/base/sessiondescription.h" |
28 #include "webrtc/rtc_base/checks.h" | 29 #include "webrtc/rtc_base/checks.h" |
29 #include "webrtc/rtc_base/copyonwritebuffer.h" | 30 #include "webrtc/rtc_base/copyonwritebuffer.h" |
30 #include "webrtc/rtc_base/networkroute.h" | 31 #include "webrtc/rtc_base/networkroute.h" |
| 32 #include "webrtc/rtc_base/ptr_util.h" |
31 #include "webrtc/rtc_base/stringutils.h" | 33 #include "webrtc/rtc_base/stringutils.h" |
32 | 34 |
33 using webrtc::RtpExtension; | 35 using webrtc::RtpExtension; |
34 | 36 |
35 namespace cricket { | 37 namespace cricket { |
36 | 38 |
37 class FakeMediaEngine; | 39 class FakeMediaEngine; |
38 class FakeVideoEngine; | 40 class FakeVideoEngine; |
39 class FakeVoiceEngine; | 41 class FakeVoiceEngine; |
40 | 42 |
41 // A common helper class that handles sending and receiving RTP/RTCP packets. | 43 // A common helper class that handles sending and receiving RTP/RTCP packets. |
42 template <class Base> class RtpHelper : public Base { | 44 template <class Base> class RtpHelper : public Base { |
43 public: | 45 public: |
44 RtpHelper() | 46 RtpHelper() |
45 : sending_(false), | 47 : sending_(false), |
46 playout_(false), | 48 playout_(false), |
47 fail_set_send_codecs_(false), | 49 fail_set_send_codecs_(false), |
48 fail_set_recv_codecs_(false), | 50 fail_set_recv_codecs_(false), |
49 send_ssrc_(0), | 51 send_ssrc_(0), |
50 ready_to_send_(false) {} | 52 ready_to_send_(false), |
| 53 transport_overhead_per_packet_(0), |
| 54 num_network_route_changes_(0) {} |
| 55 virtual ~RtpHelper() = default; |
51 const std::vector<RtpExtension>& recv_extensions() { | 56 const std::vector<RtpExtension>& recv_extensions() { |
52 return recv_extensions_; | 57 return recv_extensions_; |
53 } | 58 } |
54 const std::vector<RtpExtension>& send_extensions() { | 59 const std::vector<RtpExtension>& send_extensions() { |
55 return send_extensions_; | 60 return send_extensions_; |
56 } | 61 } |
57 bool sending() const { return sending_; } | 62 bool sending() const { return sending_; } |
58 bool playout() const { return playout_; } | 63 bool playout() const { return playout_; } |
59 const std::list<std::string>& rtp_packets() const { return rtp_packets_; } | 64 const std::list<std::string>& rtp_packets() const { return rtp_packets_; } |
60 const std::list<std::string>& rtcp_packets() const { return rtcp_packets_; } | 65 const std::list<std::string>& rtcp_packets() const { return rtcp_packets_; } |
(...skipping 231 matching lines...) Loading... |
292 std::set<uint32_t> muted_streams_; | 297 std::set<uint32_t> muted_streams_; |
293 std::map<uint32_t, webrtc::RtpParameters> rtp_send_parameters_; | 298 std::map<uint32_t, webrtc::RtpParameters> rtp_send_parameters_; |
294 std::map<uint32_t, webrtc::RtpParameters> rtp_receive_parameters_; | 299 std::map<uint32_t, webrtc::RtpParameters> rtp_receive_parameters_; |
295 bool fail_set_send_codecs_; | 300 bool fail_set_send_codecs_; |
296 bool fail_set_recv_codecs_; | 301 bool fail_set_recv_codecs_; |
297 uint32_t send_ssrc_; | 302 uint32_t send_ssrc_; |
298 std::string rtcp_cname_; | 303 std::string rtcp_cname_; |
299 bool ready_to_send_; | 304 bool ready_to_send_; |
300 int transport_overhead_per_packet_; | 305 int transport_overhead_per_packet_; |
301 rtc::NetworkRoute last_network_route_; | 306 rtc::NetworkRoute last_network_route_; |
302 int num_network_route_changes_ = 0; | 307 int num_network_route_changes_; |
303 }; | 308 }; |
304 | 309 |
305 class FakeVoiceMediaChannel : public RtpHelper<VoiceMediaChannel> { | 310 class FakeVoiceMediaChannel : public RtpHelper<VoiceMediaChannel> { |
306 public: | 311 public: |
307 struct DtmfInfo { | 312 struct DtmfInfo { |
308 DtmfInfo(uint32_t ssrc, int event_code, int duration) | 313 DtmfInfo(uint32_t ssrc, int event_code, int duration) |
309 : ssrc(ssrc), | 314 : ssrc(ssrc), |
310 event_code(event_code), | 315 event_code(event_code), |
311 duration(duration) {} | 316 duration(duration) {} |
312 uint32_t ssrc; | 317 uint32_t ssrc; |
(...skipping 197 matching lines...) Loading... |
510 inline bool CompareDtmfInfo(const FakeVoiceMediaChannel::DtmfInfo& info, | 515 inline bool CompareDtmfInfo(const FakeVoiceMediaChannel::DtmfInfo& info, |
511 uint32_t ssrc, | 516 uint32_t ssrc, |
512 int event_code, | 517 int event_code, |
513 int duration) { | 518 int duration) { |
514 return (info.duration == duration && info.event_code == event_code && | 519 return (info.duration == duration && info.event_code == event_code && |
515 info.ssrc == ssrc); | 520 info.ssrc == ssrc); |
516 } | 521 } |
517 | 522 |
518 class FakeVideoMediaChannel : public RtpHelper<VideoMediaChannel> { | 523 class FakeVideoMediaChannel : public RtpHelper<VideoMediaChannel> { |
519 public: | 524 public: |
520 explicit FakeVideoMediaChannel(FakeVideoEngine* engine, | 525 FakeVideoMediaChannel(FakeVideoEngine* engine, const VideoOptions& options) |
521 const VideoOptions& options) | |
522 : engine_(engine), max_bps_(-1) { | 526 : engine_(engine), max_bps_(-1) { |
523 SetOptions(options); | 527 SetOptions(options); |
524 } | 528 } |
525 | 529 |
526 ~FakeVideoMediaChannel(); | 530 ~FakeVideoMediaChannel(); |
527 | 531 |
528 const std::vector<VideoCodec>& recv_codecs() const { return recv_codecs_; } | 532 const std::vector<VideoCodec>& recv_codecs() const { return recv_codecs_; } |
529 const std::vector<VideoCodec>& send_codecs() const { return send_codecs_; } | 533 const std::vector<VideoCodec>& send_codecs() const { return send_codecs_; } |
530 const std::vector<VideoCodec>& codecs() const { return send_codecs(); } | 534 const std::vector<VideoCodec>& codecs() const { return send_codecs(); } |
531 bool rendering() const { return playout(); } | 535 bool rendering() const { return playout(); } |
(...skipping 299 matching lines...) Loading... |
831 friend class FakeMediaEngine; | 835 friend class FakeMediaEngine; |
832 }; | 836 }; |
833 | 837 |
834 class FakeVideoEngine : public FakeBaseEngine { | 838 class FakeVideoEngine : public FakeBaseEngine { |
835 public: | 839 public: |
836 FakeVideoEngine() : capture_(false) { | 840 FakeVideoEngine() : capture_(false) { |
837 // Add a fake video codec. Note that the name must not be "" as there are | 841 // Add a fake video codec. Note that the name must not be "" as there are |
838 // sanity checks against that. | 842 // sanity checks against that. |
839 codecs_.push_back(VideoCodec(0, "fake_video_codec")); | 843 codecs_.push_back(VideoCodec(0, "fake_video_codec")); |
840 } | 844 } |
| 845 |
841 void Init() {} | 846 void Init() {} |
| 847 |
842 bool SetOptions(const VideoOptions& options) { | 848 bool SetOptions(const VideoOptions& options) { |
843 options_ = options; | 849 options_ = options; |
844 options_changed_ = true; | 850 options_changed_ = true; |
845 return true; | 851 return true; |
846 } | 852 } |
847 | 853 |
848 VideoMediaChannel* CreateChannel(webrtc::Call* call, | 854 VideoMediaChannel* CreateChannel(webrtc::Call* call, |
849 const MediaConfig& config, | 855 const MediaConfig& config, |
850 const VideoOptions& options) { | 856 const VideoOptions& options) { |
851 if (fail_create_channel_) { | 857 if (fail_create_channel_) { |
852 return NULL; | 858 return nullptr; |
853 } | 859 } |
854 | 860 |
855 FakeVideoMediaChannel* ch = new FakeVideoMediaChannel(this, options); | 861 FakeVideoMediaChannel* ch = new FakeVideoMediaChannel(this, options); |
856 channels_.push_back(ch); | 862 channels_.emplace_back(ch); |
857 return ch; | 863 return ch; |
858 } | 864 } |
| 865 |
859 FakeVideoMediaChannel* GetChannel(size_t index) { | 866 FakeVideoMediaChannel* GetChannel(size_t index) { |
860 return (channels_.size() > index) ? channels_[index] : NULL; | 867 return (channels_.size() > index) ? channels_[index] : nullptr; |
861 } | 868 } |
| 869 |
862 void UnregisterChannel(VideoMediaChannel* channel) { | 870 void UnregisterChannel(VideoMediaChannel* channel) { |
863 channels_.erase(std::find(channels_.begin(), channels_.end(), channel)); | 871 auto it = std::find(channels_.begin(), channels_.end(), channel); |
| 872 RTC_DCHECK(it != channels_.end()); |
| 873 channels_.erase(it); |
864 } | 874 } |
865 | 875 |
866 const std::vector<VideoCodec>& codecs() const { return codecs_; } | 876 const std::vector<VideoCodec>& codecs() const { return codecs_; } |
| 877 |
867 void SetCodecs(const std::vector<VideoCodec> codecs) { codecs_ = codecs; } | 878 void SetCodecs(const std::vector<VideoCodec> codecs) { codecs_ = codecs; } |
868 | 879 |
869 bool SetCapture(bool capture) { | 880 bool SetCapture(bool capture) { |
870 capture_ = capture; | 881 capture_ = capture; |
871 return true; | 882 return true; |
872 } | 883 } |
873 | 884 |
874 private: | 885 private: |
875 std::vector<FakeVideoMediaChannel*> channels_; | 886 std::vector<FakeVideoMediaChannel*> channels_; |
876 std::vector<VideoCodec> codecs_; | 887 std::vector<VideoCodec> codecs_; |
(...skipping 97 matching lines...) Loading... |
974 virtual const std::vector<DataCodec>& data_codecs() { return data_codecs_; } | 985 virtual const std::vector<DataCodec>& data_codecs() { return data_codecs_; } |
975 | 986 |
976 private: | 987 private: |
977 std::vector<FakeDataMediaChannel*> channels_; | 988 std::vector<FakeDataMediaChannel*> channels_; |
978 std::vector<DataCodec> data_codecs_; | 989 std::vector<DataCodec> data_codecs_; |
979 }; | 990 }; |
980 | 991 |
981 } // namespace cricket | 992 } // namespace cricket |
982 | 993 |
983 #endif // WEBRTC_MEDIA_BASE_FAKEMEDIAENGINE_H_ | 994 #endif // WEBRTC_MEDIA_BASE_FAKEMEDIAENGINE_H_ |
OLD | NEW |