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 |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 DtmfInfo(uint32_t ssrc, int event_code, int duration) | 257 DtmfInfo(uint32_t ssrc, int event_code, int duration) |
258 : ssrc(ssrc), | 258 : ssrc(ssrc), |
259 event_code(event_code), | 259 event_code(event_code), |
260 duration(duration) {} | 260 duration(duration) {} |
261 uint32_t ssrc; | 261 uint32_t ssrc; |
262 int event_code; | 262 int event_code; |
263 int duration; | 263 int duration; |
264 }; | 264 }; |
265 explicit FakeVoiceMediaChannel(FakeVoiceEngine* engine, | 265 explicit FakeVoiceMediaChannel(FakeVoiceEngine* engine, |
266 const AudioOptions& options) | 266 const AudioOptions& options) |
267 : engine_(engine), time_since_last_typing_(-1), max_bps_(-1) { | 267 : engine_(engine), time_since_last_typing_(-1) { |
268 output_scalings_[0] = 1.0; // For default channel. | 268 output_scalings_[0] = 1.0; // For default channel. |
269 SetOptions(options); | 269 SetOptions(options); |
270 } | 270 } |
271 ~FakeVoiceMediaChannel(); | 271 ~FakeVoiceMediaChannel(); |
272 const std::vector<AudioCodec>& recv_codecs() const { return recv_codecs_; } | 272 const std::vector<AudioCodec>& recv_codecs() const { return recv_codecs_; } |
273 const std::vector<AudioCodec>& send_codecs() const { return send_codecs_; } | 273 const std::vector<AudioCodec>& send_codecs() const { return send_codecs_; } |
274 const std::vector<AudioCodec>& codecs() const { return send_codecs(); } | 274 const std::vector<AudioCodec>& codecs() const { return send_codecs(); } |
275 const std::vector<DtmfInfo>& dtmf_info_queue() const { | 275 const std::vector<DtmfInfo>& dtmf_info_queue() const { |
276 return dtmf_info_queue_; | 276 return dtmf_info_queue_; |
277 } | 277 } |
278 const AudioOptions& options() const { return options_; } | 278 const AudioOptions& options() const { return options_; } |
279 int max_bps() const { return max_bps_; } | 279 rtc::Optional<int> max_bps() const { return max_bps_; } |
280 virtual bool SetSendParameters(const AudioSendParameters& params) { | 280 virtual bool SetSendParameters(const AudioSendParameters& params) { |
281 return (SetSendCodecs(params.codecs) && | 281 return (SetSendCodecs(params.codecs) && |
282 SetSendRtpHeaderExtensions(params.extensions) && | 282 SetSendRtpHeaderExtensions(params.extensions) && |
283 SetMaxSendBandwidth(params.max_bandwidth_bps) && | 283 SetMaxSendBitrate(params.max_bitrate_bps) && |
284 SetOptions(params.options)); | 284 SetOptions(params.options)); |
285 } | 285 } |
286 | 286 |
287 virtual bool SetRecvParameters(const AudioRecvParameters& params) { | 287 virtual bool SetRecvParameters(const AudioRecvParameters& params) { |
288 return (SetRecvCodecs(params.codecs) && | 288 return (SetRecvCodecs(params.codecs) && |
289 SetRecvRtpHeaderExtensions(params.extensions)); | 289 SetRecvRtpHeaderExtensions(params.extensions)); |
290 } | 290 } |
291 | 291 |
292 virtual bool SetPlayout(bool playout) { | 292 virtual bool SetPlayout(bool playout) { |
293 set_playout(playout); | 293 set_playout(playout); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 return true; | 407 return true; |
408 } | 408 } |
409 bool SetSendCodecs(const std::vector<AudioCodec>& codecs) { | 409 bool SetSendCodecs(const std::vector<AudioCodec>& codecs) { |
410 if (fail_set_send_codecs()) { | 410 if (fail_set_send_codecs()) { |
411 // Fake the failure in SetSendCodecs. | 411 // Fake the failure in SetSendCodecs. |
412 return false; | 412 return false; |
413 } | 413 } |
414 send_codecs_ = codecs; | 414 send_codecs_ = codecs; |
415 return true; | 415 return true; |
416 } | 416 } |
417 bool SetMaxSendBandwidth(int bps) { | 417 bool SetMaxSendBitrate(rtc::Optional<int> bps) { |
418 max_bps_ = bps; | 418 max_bps_ = bps; |
419 return true; | 419 return true; |
420 } | 420 } |
421 bool SetOptions(const AudioOptions& options) { | 421 bool SetOptions(const AudioOptions& options) { |
422 // Does a "merge" of current options and set options. | 422 // Does a "merge" of current options and set options. |
423 options_.SetAll(options); | 423 options_.SetAll(options); |
424 return true; | 424 return true; |
425 } | 425 } |
426 bool SetLocalSource(uint32_t ssrc, AudioSource* source) { | 426 bool SetLocalSource(uint32_t ssrc, AudioSource* source) { |
427 auto it = local_sinks_.find(ssrc); | 427 auto it = local_sinks_.find(ssrc); |
(...skipping 15 matching lines...) Expand all Loading... |
443 | 443 |
444 FakeVoiceEngine* engine_; | 444 FakeVoiceEngine* engine_; |
445 std::vector<AudioCodec> recv_codecs_; | 445 std::vector<AudioCodec> recv_codecs_; |
446 std::vector<AudioCodec> send_codecs_; | 446 std::vector<AudioCodec> send_codecs_; |
447 std::map<uint32_t, double> output_scalings_; | 447 std::map<uint32_t, double> output_scalings_; |
448 std::vector<DtmfInfo> dtmf_info_queue_; | 448 std::vector<DtmfInfo> dtmf_info_queue_; |
449 int time_since_last_typing_; | 449 int time_since_last_typing_; |
450 AudioOptions options_; | 450 AudioOptions options_; |
451 std::map<uint32_t, VoiceChannelAudioSink*> local_sinks_; | 451 std::map<uint32_t, VoiceChannelAudioSink*> local_sinks_; |
452 std::unique_ptr<webrtc::AudioSinkInterface> sink_; | 452 std::unique_ptr<webrtc::AudioSinkInterface> sink_; |
453 int max_bps_; | 453 rtc::Optional<int> max_bps_; |
454 }; | 454 }; |
455 | 455 |
456 // A helper function to compare the FakeVoiceMediaChannel::DtmfInfo. | 456 // A helper function to compare the FakeVoiceMediaChannel::DtmfInfo. |
457 inline bool CompareDtmfInfo(const FakeVoiceMediaChannel::DtmfInfo& info, | 457 inline bool CompareDtmfInfo(const FakeVoiceMediaChannel::DtmfInfo& info, |
458 uint32_t ssrc, | 458 uint32_t ssrc, |
459 int event_code, | 459 int event_code, |
460 int duration) { | 460 int duration) { |
461 return (info.duration == duration && info.event_code == event_code && | 461 return (info.duration == duration && info.event_code == event_code && |
462 info.ssrc == ssrc); | 462 info.ssrc == ssrc); |
463 } | 463 } |
464 | 464 |
465 class FakeVideoMediaChannel : public RtpHelper<VideoMediaChannel> { | 465 class FakeVideoMediaChannel : public RtpHelper<VideoMediaChannel> { |
466 public: | 466 public: |
467 explicit FakeVideoMediaChannel(FakeVideoEngine* engine, | 467 explicit FakeVideoMediaChannel(FakeVideoEngine* engine, |
468 const VideoOptions& options) | 468 const VideoOptions& options) |
469 : engine_(engine), max_bps_(-1) { | 469 : engine_(engine) { |
470 SetOptions(options); | 470 SetOptions(options); |
471 } | 471 } |
472 | 472 |
473 ~FakeVideoMediaChannel(); | 473 ~FakeVideoMediaChannel(); |
474 | 474 |
475 const std::vector<VideoCodec>& recv_codecs() const { return recv_codecs_; } | 475 const std::vector<VideoCodec>& recv_codecs() const { return recv_codecs_; } |
476 const std::vector<VideoCodec>& send_codecs() const { return send_codecs_; } | 476 const std::vector<VideoCodec>& send_codecs() const { return send_codecs_; } |
477 const std::vector<VideoCodec>& codecs() const { return send_codecs(); } | 477 const std::vector<VideoCodec>& codecs() const { return send_codecs(); } |
478 bool rendering() const { return playout(); } | 478 bool rendering() const { return playout(); } |
479 const VideoOptions& options() const { return options_; } | 479 const VideoOptions& options() const { return options_; } |
480 const std::map<uint32_t, rtc::VideoSinkInterface<VideoFrame>*>& sinks() | 480 const std::map<uint32_t, rtc::VideoSinkInterface<VideoFrame>*>& sinks() |
481 const { | 481 const { |
482 return sinks_; | 482 return sinks_; |
483 } | 483 } |
484 int max_bps() const { return max_bps_; } | 484 rtc::Optional<int> max_bps() const { return max_bps_; } |
485 virtual bool SetSendParameters(const VideoSendParameters& params) { | 485 virtual bool SetSendParameters(const VideoSendParameters& params) { |
486 return (SetSendCodecs(params.codecs) && | 486 return (SetSendCodecs(params.codecs) && |
487 SetSendRtpHeaderExtensions(params.extensions) && | 487 SetSendRtpHeaderExtensions(params.extensions) && |
488 SetMaxSendBandwidth(params.max_bandwidth_bps)); | 488 SetMaxSendBitrate(params.max_bitrate_bps)); |
489 } | 489 } |
490 virtual bool SetRecvParameters(const VideoRecvParameters& params) { | 490 virtual bool SetRecvParameters(const VideoRecvParameters& params) { |
491 return (SetRecvCodecs(params.codecs) && | 491 return (SetRecvCodecs(params.codecs) && |
492 SetRecvRtpHeaderExtensions(params.extensions)); | 492 SetRecvRtpHeaderExtensions(params.extensions)); |
493 } | 493 } |
494 virtual bool AddSendStream(const StreamParams& sp) { | 494 virtual bool AddSendStream(const StreamParams& sp) { |
495 return RtpHelper<VideoMediaChannel>::AddSendStream(sp); | 495 return RtpHelper<VideoMediaChannel>::AddSendStream(sp); |
496 } | 496 } |
497 virtual bool RemoveSendStream(uint32_t ssrc) { | 497 virtual bool RemoveSendStream(uint32_t ssrc) { |
498 return RtpHelper<VideoMediaChannel>::RemoveSendStream(ssrc); | 498 return RtpHelper<VideoMediaChannel>::RemoveSendStream(ssrc); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
564 return false; | 564 return false; |
565 } | 565 } |
566 send_codecs_ = codecs; | 566 send_codecs_ = codecs; |
567 | 567 |
568 return true; | 568 return true; |
569 } | 569 } |
570 bool SetOptions(const VideoOptions& options) { | 570 bool SetOptions(const VideoOptions& options) { |
571 options_ = options; | 571 options_ = options; |
572 return true; | 572 return true; |
573 } | 573 } |
574 bool SetMaxSendBandwidth(int bps) { | 574 bool SetMaxSendBitrate(rtc::Optional<int> bps) { |
575 max_bps_ = bps; | 575 max_bps_ = bps; |
576 return true; | 576 return true; |
577 } | 577 } |
578 | 578 |
579 FakeVideoEngine* engine_; | 579 FakeVideoEngine* engine_; |
580 std::vector<VideoCodec> recv_codecs_; | 580 std::vector<VideoCodec> recv_codecs_; |
581 std::vector<VideoCodec> send_codecs_; | 581 std::vector<VideoCodec> send_codecs_; |
582 std::map<uint32_t, rtc::VideoSinkInterface<VideoFrame>*> sinks_; | 582 std::map<uint32_t, rtc::VideoSinkInterface<VideoFrame>*> sinks_; |
583 std::map<uint32_t, VideoCapturer*> capturers_; | 583 std::map<uint32_t, VideoCapturer*> capturers_; |
584 VideoOptions options_; | 584 VideoOptions options_; |
585 int max_bps_; | 585 rtc::Optional<int> max_bps_; |
586 }; | 586 }; |
587 | 587 |
588 // Dummy option class, needed for the DataTraits abstraction in | 588 // Dummy option class, needed for the DataTraits abstraction in |
589 // channel_unittest.c. | 589 // channel_unittest.c. |
590 class DataOptions {}; | 590 class DataOptions {}; |
591 | 591 |
592 class FakeDataMediaChannel : public RtpHelper<DataMediaChannel> { | 592 class FakeDataMediaChannel : public RtpHelper<DataMediaChannel> { |
593 public: | 593 public: |
594 explicit FakeDataMediaChannel(void* unused, const DataOptions& options) | 594 explicit FakeDataMediaChannel(void* unused, const DataOptions& options) |
595 : send_blocked_(false), max_bps_(-1) {} | 595 : send_blocked_(false) {} |
596 ~FakeDataMediaChannel() {} | 596 ~FakeDataMediaChannel() {} |
597 const std::vector<DataCodec>& recv_codecs() const { return recv_codecs_; } | 597 const std::vector<DataCodec>& recv_codecs() const { return recv_codecs_; } |
598 const std::vector<DataCodec>& send_codecs() const { return send_codecs_; } | 598 const std::vector<DataCodec>& send_codecs() const { return send_codecs_; } |
599 const std::vector<DataCodec>& codecs() const { return send_codecs(); } | 599 const std::vector<DataCodec>& codecs() const { return send_codecs(); } |
600 int max_bps() const { return max_bps_; } | 600 rtc::Optional<int> max_bps() const { return max_bps_; } |
601 | 601 |
602 virtual bool SetSendParameters(const DataSendParameters& params) { | 602 virtual bool SetSendParameters(const DataSendParameters& params) { |
603 return (SetSendCodecs(params.codecs) && | 603 return (SetSendCodecs(params.codecs) && |
604 SetMaxSendBandwidth(params.max_bandwidth_bps)); | 604 SetMaxSendBitrate(params.max_bitrate_bps)); |
605 } | 605 } |
606 virtual bool SetRecvParameters(const DataRecvParameters& params) { | 606 virtual bool SetRecvParameters(const DataRecvParameters& params) { |
607 return SetRecvCodecs(params.codecs); | 607 return SetRecvCodecs(params.codecs); |
608 } | 608 } |
609 virtual bool SetSend(bool send) { return set_sending(send); } | 609 virtual bool SetSend(bool send) { return set_sending(send); } |
610 virtual bool SetReceive(bool receive) { | 610 virtual bool SetReceive(bool receive) { |
611 set_playout(receive); | 611 set_playout(receive); |
612 return true; | 612 return true; |
613 } | 613 } |
614 virtual bool AddRecvStream(const StreamParams& sp) { | 614 virtual bool AddRecvStream(const StreamParams& sp) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
650 return true; | 650 return true; |
651 } | 651 } |
652 bool SetSendCodecs(const std::vector<DataCodec>& codecs) { | 652 bool SetSendCodecs(const std::vector<DataCodec>& codecs) { |
653 if (fail_set_send_codecs()) { | 653 if (fail_set_send_codecs()) { |
654 // Fake the failure in SetSendCodecs. | 654 // Fake the failure in SetSendCodecs. |
655 return false; | 655 return false; |
656 } | 656 } |
657 send_codecs_ = codecs; | 657 send_codecs_ = codecs; |
658 return true; | 658 return true; |
659 } | 659 } |
660 bool SetMaxSendBandwidth(int bps) { | 660 bool SetMaxSendBitrate(rtc::Optional<int> bps) { |
661 max_bps_ = bps; | 661 max_bps_ = bps; |
662 return true; | 662 return true; |
663 } | 663 } |
664 | 664 |
665 std::vector<DataCodec> recv_codecs_; | 665 std::vector<DataCodec> recv_codecs_; |
666 std::vector<DataCodec> send_codecs_; | 666 std::vector<DataCodec> send_codecs_; |
667 SendDataParams last_sent_data_params_; | 667 SendDataParams last_sent_data_params_; |
668 std::string last_sent_data_; | 668 std::string last_sent_data_; |
669 bool send_blocked_; | 669 bool send_blocked_; |
670 int max_bps_; | 670 rtc::Optional<int> max_bps_; |
671 }; | 671 }; |
672 | 672 |
673 // A base class for all of the shared parts between FakeVoiceEngine | 673 // A base class for all of the shared parts between FakeVoiceEngine |
674 // and FakeVideoEngine. | 674 // and FakeVideoEngine. |
675 class FakeBaseEngine { | 675 class FakeBaseEngine { |
676 public: | 676 public: |
677 FakeBaseEngine() | 677 FakeBaseEngine() |
678 : options_changed_(false), | 678 : options_changed_(false), |
679 fail_create_channel_(false) {} | 679 fail_create_channel_(false) {} |
680 void set_fail_create_channel(bool fail) { fail_create_channel_ = fail; } | 680 void set_fail_create_channel(bool fail) { fail_create_channel_ = fail; } |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
906 | 906 |
907 private: | 907 private: |
908 std::vector<FakeDataMediaChannel*> channels_; | 908 std::vector<FakeDataMediaChannel*> channels_; |
909 std::vector<DataCodec> data_codecs_; | 909 std::vector<DataCodec> data_codecs_; |
910 DataChannelType last_channel_type_; | 910 DataChannelType last_channel_type_; |
911 }; | 911 }; |
912 | 912 |
913 } // namespace cricket | 913 } // namespace cricket |
914 | 914 |
915 #endif // WEBRTC_MEDIA_BASE_FAKEMEDIAENGINE_H_ | 915 #endif // WEBRTC_MEDIA_BASE_FAKEMEDIAENGINE_H_ |
OLD | NEW |