Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(25)

Side by Side Diff: webrtc/media/base/fakemediaengine.h

Issue 2981513002: Wire up RTP keep-alive in ortc api. (Closed)
Patch Set: Test Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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...) Expand 10 before | Expand all | Expand 10 after
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...) Expand 10 before | Expand all | Expand 10 after
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) 526 : FakeVideoMediaChannel(engine,
522 : engine_(engine), max_bps_(-1) { 527 options,
528 std::unique_ptr<WebRtcVideoChannel>()) {}
529 FakeVideoMediaChannel(FakeVideoEngine* engine,
530 const VideoOptions& options,
531 std::unique_ptr<WebRtcVideoChannel> real_channel)
532 : engine_(engine), max_bps_(-1), real_channel_(std::move(real_channel)) {
523 SetOptions(options); 533 SetOptions(options);
524 } 534 }
525 535
526 ~FakeVideoMediaChannel(); 536 ~FakeVideoMediaChannel();
527 537
528 const std::vector<VideoCodec>& recv_codecs() const { return recv_codecs_; } 538 const std::vector<VideoCodec>& recv_codecs() const { return recv_codecs_; }
529 const std::vector<VideoCodec>& send_codecs() const { return send_codecs_; } 539 const std::vector<VideoCodec>& send_codecs() const { return send_codecs_; }
530 const std::vector<VideoCodec>& codecs() const { return send_codecs(); } 540 const std::vector<VideoCodec>& codecs() const { return send_codecs(); }
531 bool rendering() const { return playout(); } 541 bool rendering() const { return playout(); }
532 const VideoOptions& options() const { return options_; } 542 const VideoOptions& options() const { return options_; }
533 const std::map<uint32_t, rtc::VideoSinkInterface<webrtc::VideoFrame>*>& 543 const std::map<uint32_t, rtc::VideoSinkInterface<webrtc::VideoFrame>*>&
534 sinks() const { 544 sinks() const {
535 return sinks_; 545 return sinks_;
536 } 546 }
537 int max_bps() const { return max_bps_; } 547 int max_bps() const { return max_bps_; }
538 bool SetSendParameters(const VideoSendParameters& params) override { 548 bool SetSendParameters(const VideoSendParameters& params) override {
549 if (real_channel_)
550 real_channel_->SetSendParameters(params);
539 set_send_rtcp_parameters(params.rtcp); 551 set_send_rtcp_parameters(params.rtcp);
540 return (SetSendCodecs(params.codecs) && 552 return (SetSendCodecs(params.codecs) &&
541 SetSendRtpHeaderExtensions(params.extensions) && 553 SetSendRtpHeaderExtensions(params.extensions) &&
542 SetMaxSendBandwidth(params.max_bandwidth_bps)); 554 SetMaxSendBandwidth(params.max_bandwidth_bps));
543 } 555 }
544 bool SetRecvParameters(const VideoRecvParameters& params) override { 556 bool SetRecvParameters(const VideoRecvParameters& params) override {
545 set_recv_rtcp_parameters(params.rtcp); 557 set_recv_rtcp_parameters(params.rtcp);
546 return (SetRecvCodecs(params.codecs) && 558 return (SetRecvCodecs(params.codecs) &&
547 SetRecvRtpHeaderExtensions(params.extensions)); 559 SetRecvRtpHeaderExtensions(params.extensions));
548 } 560 }
549 bool AddSendStream(const StreamParams& sp) override { 561 bool AddSendStream(const StreamParams& sp) override {
562 if (real_channel_)
563 real_channel_->AddSendStream(sp);
550 return RtpHelper<VideoMediaChannel>::AddSendStream(sp); 564 return RtpHelper<VideoMediaChannel>::AddSendStream(sp);
551 } 565 }
552 bool RemoveSendStream(uint32_t ssrc) override { 566 bool RemoveSendStream(uint32_t ssrc) override {
567 if (real_channel_)
568 real_channel_->RemoveSendStream(ssrc);
553 return RtpHelper<VideoMediaChannel>::RemoveSendStream(ssrc); 569 return RtpHelper<VideoMediaChannel>::RemoveSendStream(ssrc);
554 } 570 }
555 571
556 bool GetSendCodec(VideoCodec* send_codec) override { 572 bool GetSendCodec(VideoCodec* send_codec) override {
557 if (send_codecs_.empty()) { 573 if (send_codecs_.empty()) {
558 return false; 574 return false;
559 } 575 }
560 *send_codec = send_codecs_[0]; 576 *send_codec = send_codecs_[0];
561 return true; 577 return true;
562 } 578 }
563 bool SetSink(uint32_t ssrc, 579 bool SetSink(uint32_t ssrc,
564 rtc::VideoSinkInterface<webrtc::VideoFrame>* sink) override { 580 rtc::VideoSinkInterface<webrtc::VideoFrame>* sink) override {
565 if (ssrc != 0 && sinks_.find(ssrc) == sinks_.end()) { 581 if (ssrc != 0 && sinks_.find(ssrc) == sinks_.end()) {
566 return false; 582 return false;
567 } 583 }
568 if (ssrc != 0) { 584 if (ssrc != 0) {
569 sinks_[ssrc] = sink; 585 sinks_[ssrc] = sink;
570 } 586 }
571 return true; 587 return true;
572 } 588 }
573 bool HasSink(uint32_t ssrc) const { 589 bool HasSink(uint32_t ssrc) const {
574 return sinks_.find(ssrc) != sinks_.end() && sinks_.at(ssrc) != nullptr; 590 return sinks_.find(ssrc) != sinks_.end() && sinks_.at(ssrc) != nullptr;
575 } 591 }
576 592
577 bool SetSend(bool send) override { return set_sending(send); } 593 bool SetSend(bool send) override {
594 if (real_channel_)
595 real_channel_->SetSend(send);
596 return set_sending(send);
597 }
598
578 bool SetVideoSend( 599 bool SetVideoSend(
579 uint32_t ssrc, 600 uint32_t ssrc,
580 bool enable, 601 bool enable,
581 const VideoOptions* options, 602 const VideoOptions* options,
582 rtc::VideoSourceInterface<webrtc::VideoFrame>* source) override { 603 rtc::VideoSourceInterface<webrtc::VideoFrame>* source) override {
604 if (real_channel_)
605 real_channel_->SetVideoSend(ssrc, enable, options, source);
606
583 if (!RtpHelper<VideoMediaChannel>::MuteStream(ssrc, !enable)) { 607 if (!RtpHelper<VideoMediaChannel>::MuteStream(ssrc, !enable)) {
584 return false; 608 return false;
585 } 609 }
586 if (enable && options) { 610 if (enable && options) {
587 if (!SetOptions(*options)) { 611 if (!SetOptions(*options)) {
588 return false; 612 return false;
589 } 613 }
590 } 614 }
591 sources_[ssrc] = source; 615 sources_[ssrc] = source;
592 return true; 616 return true;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 return true; 663 return true;
640 } 664 }
641 665
642 FakeVideoEngine* engine_; 666 FakeVideoEngine* engine_;
643 std::vector<VideoCodec> recv_codecs_; 667 std::vector<VideoCodec> recv_codecs_;
644 std::vector<VideoCodec> send_codecs_; 668 std::vector<VideoCodec> send_codecs_;
645 std::map<uint32_t, rtc::VideoSinkInterface<webrtc::VideoFrame>*> sinks_; 669 std::map<uint32_t, rtc::VideoSinkInterface<webrtc::VideoFrame>*> sinks_;
646 std::map<uint32_t, rtc::VideoSourceInterface<webrtc::VideoFrame>*> sources_; 670 std::map<uint32_t, rtc::VideoSourceInterface<webrtc::VideoFrame>*> sources_;
647 VideoOptions options_; 671 VideoOptions options_;
648 int max_bps_; 672 int max_bps_;
673 std::unique_ptr<WebRtcVideoChannel> real_channel_;
649 }; 674 };
650 675
651 // Dummy option class, needed for the DataTraits abstraction in 676 // Dummy option class, needed for the DataTraits abstraction in
652 // channel_unittest.c. 677 // channel_unittest.c.
653 class DataOptions {}; 678 class DataOptions {};
654 679
655 class FakeDataMediaChannel : public RtpHelper<DataMediaChannel> { 680 class FakeDataMediaChannel : public RtpHelper<DataMediaChannel> {
656 public: 681 public:
657 explicit FakeDataMediaChannel(void* unused, const DataOptions& options) 682 explicit FakeDataMediaChannel(void* unused, const DataOptions& options)
658 : send_blocked_(false), max_bps_(-1) {} 683 : send_blocked_(false), max_bps_(-1) {}
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
826 851
827 private: 852 private:
828 std::vector<FakeVoiceMediaChannel*> channels_; 853 std::vector<FakeVoiceMediaChannel*> channels_;
829 std::vector<AudioCodec> codecs_; 854 std::vector<AudioCodec> codecs_;
830 855
831 friend class FakeMediaEngine; 856 friend class FakeMediaEngine;
832 }; 857 };
833 858
834 class FakeVideoEngine : public FakeBaseEngine { 859 class FakeVideoEngine : public FakeBaseEngine {
835 public: 860 public:
836 FakeVideoEngine() : capture_(false) { 861 FakeVideoEngine() : capture_(false), create_real_channels_(false) {
837 // Add a fake video codec. Note that the name must not be "" as there are 862 // Add a fake video codec. Note that the name must not be "" as there are
838 // sanity checks against that. 863 // sanity checks against that.
839 codecs_.push_back(VideoCodec(0, "fake_video_codec")); 864 codecs_.push_back(VideoCodec(0, "fake_video_codec"));
840 } 865 }
866
841 void Init() {} 867 void Init() {}
868
842 bool SetOptions(const VideoOptions& options) { 869 bool SetOptions(const VideoOptions& options) {
843 options_ = options; 870 options_ = options;
844 options_changed_ = true; 871 options_changed_ = true;
845 return true; 872 return true;
846 } 873 }
847 874
848 VideoMediaChannel* CreateChannel(webrtc::Call* call, 875 VideoMediaChannel* CreateChannel(webrtc::Call* call,
849 const MediaConfig& config, 876 const MediaConfig& config,
850 const VideoOptions& options) { 877 const VideoOptions& options) {
851 if (fail_create_channel_) { 878 if (fail_create_channel_) {
852 return NULL; 879 return nullptr;
853 } 880 }
854 881
855 FakeVideoMediaChannel* ch = new FakeVideoMediaChannel(this, options); 882 channels_.emplace_back(new FakeVideoMediaChannel(
856 channels_.push_back(ch); 883 this, options,
857 return ch; 884 std::unique_ptr<WebRtcVideoChannel>(
885 create_real_channels_ ? new WebRtcVideoChannel(
886 call, config, options, nullptr, nullptr)
887 : nullptr)));
888 return channels_.back();
858 } 889 }
890
859 FakeVideoMediaChannel* GetChannel(size_t index) { 891 FakeVideoMediaChannel* GetChannel(size_t index) {
860 return (channels_.size() > index) ? channels_[index] : NULL; 892 return (channels_.size() > index) ? channels_[index] : nullptr;
861 } 893 }
894
862 void UnregisterChannel(VideoMediaChannel* channel) { 895 void UnregisterChannel(VideoMediaChannel* channel) {
863 channels_.erase(std::find(channels_.begin(), channels_.end(), channel)); 896 auto it = std::find(channels_.begin(), channels_.end(), channel);
897 RTC_DCHECK(it != channels_.end());
898 channels_.erase(it);
864 } 899 }
865 900
866 const std::vector<VideoCodec>& codecs() const { return codecs_; } 901 const std::vector<VideoCodec>& codecs() const { return codecs_; }
902
867 void SetCodecs(const std::vector<VideoCodec> codecs) { codecs_ = codecs; } 903 void SetCodecs(const std::vector<VideoCodec> codecs) { codecs_ = codecs; }
868 904
869 bool SetCapture(bool capture) { 905 bool SetCapture(bool capture) {
870 capture_ = capture; 906 capture_ = capture;
871 return true; 907 return true;
872 } 908 }
873 909
910 void SetCreateRealChannel(bool do_create) {
911 create_real_channels_ = do_create;
912 }
913
874 private: 914 private:
875 std::vector<FakeVideoMediaChannel*> channels_; 915 std::vector<FakeVideoMediaChannel*> channels_;
876 std::vector<VideoCodec> codecs_; 916 std::vector<VideoCodec> codecs_;
877 bool capture_; 917 bool capture_;
878 VideoOptions options_; 918 VideoOptions options_;
919 bool create_real_channels_;
879 920
880 friend class FakeMediaEngine; 921 friend class FakeMediaEngine;
881 }; 922 };
882 923
883 class FakeMediaEngine : 924 class FakeMediaEngine :
884 public CompositeMediaEngine<FakeVoiceEngine, FakeVideoEngine> { 925 public CompositeMediaEngine<FakeVoiceEngine, FakeVideoEngine> {
885 public: 926 public:
886 FakeMediaEngine() 927 FakeMediaEngine()
887 : CompositeMediaEngine<FakeVoiceEngine, FakeVideoEngine>(nullptr, 928 : CompositeMediaEngine<FakeVoiceEngine, FakeVideoEngine>(nullptr,
888 nullptr, 929 nullptr,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
927 bool options_changed() const { 968 bool options_changed() const {
928 return video_.options_changed_; 969 return video_.options_changed_;
929 } 970 }
930 void clear_options_changed() { 971 void clear_options_changed() {
931 video_.options_changed_ = false; 972 video_.options_changed_ = false;
932 } 973 }
933 void set_fail_create_channel(bool fail) { 974 void set_fail_create_channel(bool fail) {
934 voice_.set_fail_create_channel(fail); 975 voice_.set_fail_create_channel(fail);
935 video_.set_fail_create_channel(fail); 976 video_.set_fail_create_channel(fail);
936 } 977 }
978
979 FakeVideoEngine* GetVideoEngine() { return &video_; }
937 }; 980 };
938 981
939 // Have to come afterwards due to declaration order 982 // Have to come afterwards due to declaration order
940 inline FakeVoiceMediaChannel::~FakeVoiceMediaChannel() { 983 inline FakeVoiceMediaChannel::~FakeVoiceMediaChannel() {
941 if (engine_) { 984 if (engine_) {
942 engine_->UnregisterChannel(this); 985 engine_->UnregisterChannel(this);
943 } 986 }
944 } 987 }
945 988
946 inline FakeVideoMediaChannel::~FakeVideoMediaChannel() { 989 inline FakeVideoMediaChannel::~FakeVideoMediaChannel() {
(...skipping 27 matching lines...) Expand all
974 virtual const std::vector<DataCodec>& data_codecs() { return data_codecs_; } 1017 virtual const std::vector<DataCodec>& data_codecs() { return data_codecs_; }
975 1018
976 private: 1019 private:
977 std::vector<FakeDataMediaChannel*> channels_; 1020 std::vector<FakeDataMediaChannel*> channels_;
978 std::vector<DataCodec> data_codecs_; 1021 std::vector<DataCodec> data_codecs_;
979 }; 1022 };
980 1023
981 } // namespace cricket 1024 } // namespace cricket
982 1025
983 #endif // WEBRTC_MEDIA_BASE_FAKEMEDIAENGINE_H_ 1026 #endif // WEBRTC_MEDIA_BASE_FAKEMEDIAENGINE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698