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 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 DtmfInfo(uint32_t ssrc, int event_code, int duration) | 243 DtmfInfo(uint32_t ssrc, int event_code, int duration) |
244 : ssrc(ssrc), | 244 : ssrc(ssrc), |
245 event_code(event_code), | 245 event_code(event_code), |
246 duration(duration) {} | 246 duration(duration) {} |
247 uint32_t ssrc; | 247 uint32_t ssrc; |
248 int event_code; | 248 int event_code; |
249 int duration; | 249 int duration; |
250 }; | 250 }; |
251 explicit FakeVoiceMediaChannel(FakeVoiceEngine* engine, | 251 explicit FakeVoiceMediaChannel(FakeVoiceEngine* engine, |
252 const AudioOptions& options) | 252 const AudioOptions& options) |
253 : engine_(engine), time_since_last_typing_(-1), max_bps_(-1) { | 253 : engine_(engine), time_since_last_typing_(-1) { |
254 output_scalings_[0] = 1.0; // For default channel. | 254 output_scalings_[0] = 1.0; // For default channel. |
255 SetOptions(options); | 255 SetOptions(options); |
256 } | 256 } |
257 ~FakeVoiceMediaChannel(); | 257 ~FakeVoiceMediaChannel(); |
258 const std::vector<AudioCodec>& recv_codecs() const { return recv_codecs_; } | 258 const std::vector<AudioCodec>& recv_codecs() const { return recv_codecs_; } |
259 const std::vector<AudioCodec>& send_codecs() const { return send_codecs_; } | 259 const std::vector<AudioCodec>& send_codecs() const { return send_codecs_; } |
260 const std::vector<AudioCodec>& codecs() const { return send_codecs(); } | 260 const std::vector<AudioCodec>& codecs() const { return send_codecs(); } |
261 const std::vector<DtmfInfo>& dtmf_info_queue() const { | 261 const std::vector<DtmfInfo>& dtmf_info_queue() const { |
262 return dtmf_info_queue_; | 262 return dtmf_info_queue_; |
263 } | 263 } |
264 const AudioOptions& options() const { return options_; } | 264 const AudioOptions& options() const { return options_; } |
265 int max_bps() const { return max_bps_; } | 265 rtc::Optional<int> max_bps() const { return max_bps_; } |
266 virtual bool SetSendParameters(const AudioSendParameters& params) { | 266 virtual bool SetSendParameters(const AudioSendParameters& params) { |
267 return (SetSendCodecs(params.codecs) && | 267 return (SetSendCodecs(params.codecs) && |
268 SetSendRtpHeaderExtensions(params.extensions) && | 268 SetSendRtpHeaderExtensions(params.extensions) && |
269 SetMaxSendBandwidth(params.max_bandwidth_bps) && | 269 SetMaxSendBitrate(params.max_bitrate_bps) && |
270 SetOptions(params.options)); | 270 SetOptions(params.options)); |
271 } | 271 } |
272 | 272 |
273 virtual bool SetRecvParameters(const AudioRecvParameters& params) { | 273 virtual bool SetRecvParameters(const AudioRecvParameters& params) { |
274 return (SetRecvCodecs(params.codecs) && | 274 return (SetRecvCodecs(params.codecs) && |
275 SetRecvRtpHeaderExtensions(params.extensions)); | 275 SetRecvRtpHeaderExtensions(params.extensions)); |
276 } | 276 } |
277 | 277 |
278 virtual bool SetPlayout(bool playout) { | 278 virtual bool SetPlayout(bool playout) { |
279 set_playout(playout); | 279 set_playout(playout); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 return true; | 393 return true; |
394 } | 394 } |
395 bool SetSendCodecs(const std::vector<AudioCodec>& codecs) { | 395 bool SetSendCodecs(const std::vector<AudioCodec>& codecs) { |
396 if (fail_set_send_codecs()) { | 396 if (fail_set_send_codecs()) { |
397 // Fake the failure in SetSendCodecs. | 397 // Fake the failure in SetSendCodecs. |
398 return false; | 398 return false; |
399 } | 399 } |
400 send_codecs_ = codecs; | 400 send_codecs_ = codecs; |
401 return true; | 401 return true; |
402 } | 402 } |
403 bool SetMaxSendBandwidth(int bps) { | 403 bool SetMaxSendBitrate(rtc::Optional<int> bps) { |
404 max_bps_ = bps; | 404 max_bps_ = bps; |
405 return true; | 405 return true; |
406 } | 406 } |
407 bool SetOptions(const AudioOptions& options) { | 407 bool SetOptions(const AudioOptions& options) { |
408 // Does a "merge" of current options and set options. | 408 // Does a "merge" of current options and set options. |
409 options_.SetAll(options); | 409 options_.SetAll(options); |
410 return true; | 410 return true; |
411 } | 411 } |
412 bool SetLocalSource(uint32_t ssrc, AudioSource* source) { | 412 bool SetLocalSource(uint32_t ssrc, AudioSource* source) { |
413 auto it = local_sinks_.find(ssrc); | 413 auto it = local_sinks_.find(ssrc); |
(...skipping 15 matching lines...) Expand all Loading... |
429 | 429 |
430 FakeVoiceEngine* engine_; | 430 FakeVoiceEngine* engine_; |
431 std::vector<AudioCodec> recv_codecs_; | 431 std::vector<AudioCodec> recv_codecs_; |
432 std::vector<AudioCodec> send_codecs_; | 432 std::vector<AudioCodec> send_codecs_; |
433 std::map<uint32_t, double> output_scalings_; | 433 std::map<uint32_t, double> output_scalings_; |
434 std::vector<DtmfInfo> dtmf_info_queue_; | 434 std::vector<DtmfInfo> dtmf_info_queue_; |
435 int time_since_last_typing_; | 435 int time_since_last_typing_; |
436 AudioOptions options_; | 436 AudioOptions options_; |
437 std::map<uint32_t, VoiceChannelAudioSink*> local_sinks_; | 437 std::map<uint32_t, VoiceChannelAudioSink*> local_sinks_; |
438 std::unique_ptr<webrtc::AudioSinkInterface> sink_; | 438 std::unique_ptr<webrtc::AudioSinkInterface> sink_; |
439 int max_bps_; | 439 rtc::Optional<int> max_bps_; |
440 }; | 440 }; |
441 | 441 |
442 // A helper function to compare the FakeVoiceMediaChannel::DtmfInfo. | 442 // A helper function to compare the FakeVoiceMediaChannel::DtmfInfo. |
443 inline bool CompareDtmfInfo(const FakeVoiceMediaChannel::DtmfInfo& info, | 443 inline bool CompareDtmfInfo(const FakeVoiceMediaChannel::DtmfInfo& info, |
444 uint32_t ssrc, | 444 uint32_t ssrc, |
445 int event_code, | 445 int event_code, |
446 int duration) { | 446 int duration) { |
447 return (info.duration == duration && info.event_code == event_code && | 447 return (info.duration == duration && info.event_code == event_code && |
448 info.ssrc == ssrc); | 448 info.ssrc == ssrc); |
449 } | 449 } |
450 | 450 |
451 class FakeVideoMediaChannel : public RtpHelper<VideoMediaChannel> { | 451 class FakeVideoMediaChannel : public RtpHelper<VideoMediaChannel> { |
452 public: | 452 public: |
453 explicit FakeVideoMediaChannel(FakeVideoEngine* engine, | 453 explicit FakeVideoMediaChannel(FakeVideoEngine* engine, |
454 const VideoOptions& options) | 454 const VideoOptions& options) |
455 : engine_(engine), max_bps_(-1) { | 455 : engine_(engine) { |
456 SetOptions(options); | 456 SetOptions(options); |
457 } | 457 } |
458 | 458 |
459 ~FakeVideoMediaChannel(); | 459 ~FakeVideoMediaChannel(); |
460 | 460 |
461 const std::vector<VideoCodec>& recv_codecs() const { return recv_codecs_; } | 461 const std::vector<VideoCodec>& recv_codecs() const { return recv_codecs_; } |
462 const std::vector<VideoCodec>& send_codecs() const { return send_codecs_; } | 462 const std::vector<VideoCodec>& send_codecs() const { return send_codecs_; } |
463 const std::vector<VideoCodec>& codecs() const { return send_codecs(); } | 463 const std::vector<VideoCodec>& codecs() const { return send_codecs(); } |
464 bool rendering() const { return playout(); } | 464 bool rendering() const { return playout(); } |
465 const VideoOptions& options() const { return options_; } | 465 const VideoOptions& options() const { return options_; } |
466 const std::map<uint32_t, rtc::VideoSinkInterface<VideoFrame>*>& sinks() | 466 const std::map<uint32_t, rtc::VideoSinkInterface<VideoFrame>*>& sinks() |
467 const { | 467 const { |
468 return sinks_; | 468 return sinks_; |
469 } | 469 } |
470 int max_bps() const { return max_bps_; } | 470 rtc::Optional<int> max_bps() const { return max_bps_; } |
471 virtual bool SetSendParameters(const VideoSendParameters& params) { | 471 virtual bool SetSendParameters(const VideoSendParameters& params) { |
472 return (SetSendCodecs(params.codecs) && | 472 return (SetSendCodecs(params.codecs) && |
473 SetSendRtpHeaderExtensions(params.extensions) && | 473 SetSendRtpHeaderExtensions(params.extensions) && |
474 SetMaxSendBandwidth(params.max_bandwidth_bps)); | 474 SetMaxSendBitrate(params.max_bitrate_bps)); |
475 } | 475 } |
476 virtual bool SetRecvParameters(const VideoRecvParameters& params) { | 476 virtual bool SetRecvParameters(const VideoRecvParameters& params) { |
477 return (SetRecvCodecs(params.codecs) && | 477 return (SetRecvCodecs(params.codecs) && |
478 SetRecvRtpHeaderExtensions(params.extensions)); | 478 SetRecvRtpHeaderExtensions(params.extensions)); |
479 } | 479 } |
480 virtual bool AddSendStream(const StreamParams& sp) { | 480 virtual bool AddSendStream(const StreamParams& sp) { |
481 return RtpHelper<VideoMediaChannel>::AddSendStream(sp); | 481 return RtpHelper<VideoMediaChannel>::AddSendStream(sp); |
482 } | 482 } |
483 virtual bool RemoveSendStream(uint32_t ssrc) { | 483 virtual bool RemoveSendStream(uint32_t ssrc) { |
484 return RtpHelper<VideoMediaChannel>::RemoveSendStream(ssrc); | 484 return RtpHelper<VideoMediaChannel>::RemoveSendStream(ssrc); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 return false; | 550 return false; |
551 } | 551 } |
552 send_codecs_ = codecs; | 552 send_codecs_ = codecs; |
553 | 553 |
554 return true; | 554 return true; |
555 } | 555 } |
556 bool SetOptions(const VideoOptions& options) { | 556 bool SetOptions(const VideoOptions& options) { |
557 options_ = options; | 557 options_ = options; |
558 return true; | 558 return true; |
559 } | 559 } |
560 bool SetMaxSendBandwidth(int bps) { | 560 bool SetMaxSendBitrate(rtc::Optional<int> bps) { |
561 max_bps_ = bps; | 561 max_bps_ = bps; |
562 return true; | 562 return true; |
563 } | 563 } |
564 | 564 |
565 FakeVideoEngine* engine_; | 565 FakeVideoEngine* engine_; |
566 std::vector<VideoCodec> recv_codecs_; | 566 std::vector<VideoCodec> recv_codecs_; |
567 std::vector<VideoCodec> send_codecs_; | 567 std::vector<VideoCodec> send_codecs_; |
568 std::map<uint32_t, rtc::VideoSinkInterface<VideoFrame>*> sinks_; | 568 std::map<uint32_t, rtc::VideoSinkInterface<VideoFrame>*> sinks_; |
569 std::map<uint32_t, VideoCapturer*> capturers_; | 569 std::map<uint32_t, VideoCapturer*> capturers_; |
570 VideoOptions options_; | 570 VideoOptions options_; |
571 int max_bps_; | 571 rtc::Optional<int> max_bps_; |
572 }; | 572 }; |
573 | 573 |
574 // Dummy option class, needed for the DataTraits abstraction in | 574 // Dummy option class, needed for the DataTraits abstraction in |
575 // channel_unittest.c. | 575 // channel_unittest.c. |
576 class DataOptions {}; | 576 class DataOptions {}; |
577 | 577 |
578 class FakeDataMediaChannel : public RtpHelper<DataMediaChannel> { | 578 class FakeDataMediaChannel : public RtpHelper<DataMediaChannel> { |
579 public: | 579 public: |
580 explicit FakeDataMediaChannel(void* unused, const DataOptions& options) | 580 explicit FakeDataMediaChannel(void* unused, const DataOptions& options) |
581 : send_blocked_(false), max_bps_(-1) {} | 581 : send_blocked_(false) {} |
582 ~FakeDataMediaChannel() {} | 582 ~FakeDataMediaChannel() {} |
583 const std::vector<DataCodec>& recv_codecs() const { return recv_codecs_; } | 583 const std::vector<DataCodec>& recv_codecs() const { return recv_codecs_; } |
584 const std::vector<DataCodec>& send_codecs() const { return send_codecs_; } | 584 const std::vector<DataCodec>& send_codecs() const { return send_codecs_; } |
585 const std::vector<DataCodec>& codecs() const { return send_codecs(); } | 585 const std::vector<DataCodec>& codecs() const { return send_codecs(); } |
586 int max_bps() const { return max_bps_; } | 586 rtc::Optional<int> max_bps() const { return max_bps_; } |
587 | 587 |
588 virtual bool SetSendParameters(const DataSendParameters& params) { | 588 virtual bool SetSendParameters(const DataSendParameters& params) { |
589 return (SetSendCodecs(params.codecs) && | 589 return (SetSendCodecs(params.codecs) && |
590 SetMaxSendBandwidth(params.max_bandwidth_bps)); | 590 SetMaxSendBitrate(params.max_bitrate_bps)); |
591 } | 591 } |
592 virtual bool SetRecvParameters(const DataRecvParameters& params) { | 592 virtual bool SetRecvParameters(const DataRecvParameters& params) { |
593 return SetRecvCodecs(params.codecs); | 593 return SetRecvCodecs(params.codecs); |
594 } | 594 } |
595 virtual bool SetSend(bool send) { return set_sending(send); } | 595 virtual bool SetSend(bool send) { return set_sending(send); } |
596 virtual bool SetReceive(bool receive) { | 596 virtual bool SetReceive(bool receive) { |
597 set_playout(receive); | 597 set_playout(receive); |
598 return true; | 598 return true; |
599 } | 599 } |
600 virtual bool AddRecvStream(const StreamParams& sp) { | 600 virtual bool AddRecvStream(const StreamParams& sp) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
636 return true; | 636 return true; |
637 } | 637 } |
638 bool SetSendCodecs(const std::vector<DataCodec>& codecs) { | 638 bool SetSendCodecs(const std::vector<DataCodec>& codecs) { |
639 if (fail_set_send_codecs()) { | 639 if (fail_set_send_codecs()) { |
640 // Fake the failure in SetSendCodecs. | 640 // Fake the failure in SetSendCodecs. |
641 return false; | 641 return false; |
642 } | 642 } |
643 send_codecs_ = codecs; | 643 send_codecs_ = codecs; |
644 return true; | 644 return true; |
645 } | 645 } |
646 bool SetMaxSendBandwidth(int bps) { | 646 bool SetMaxSendBitrate(rtc::Optional<int> bps) { |
647 max_bps_ = bps; | 647 max_bps_ = bps; |
648 return true; | 648 return true; |
649 } | 649 } |
650 | 650 |
651 std::vector<DataCodec> recv_codecs_; | 651 std::vector<DataCodec> recv_codecs_; |
652 std::vector<DataCodec> send_codecs_; | 652 std::vector<DataCodec> send_codecs_; |
653 SendDataParams last_sent_data_params_; | 653 SendDataParams last_sent_data_params_; |
654 std::string last_sent_data_; | 654 std::string last_sent_data_; |
655 bool send_blocked_; | 655 bool send_blocked_; |
656 int max_bps_; | 656 rtc::Optional<int> max_bps_; |
657 }; | 657 }; |
658 | 658 |
659 // A base class for all of the shared parts between FakeVoiceEngine | 659 // A base class for all of the shared parts between FakeVoiceEngine |
660 // and FakeVideoEngine. | 660 // and FakeVideoEngine. |
661 class FakeBaseEngine { | 661 class FakeBaseEngine { |
662 public: | 662 public: |
663 FakeBaseEngine() | 663 FakeBaseEngine() |
664 : options_changed_(false), | 664 : options_changed_(false), |
665 fail_create_channel_(false) {} | 665 fail_create_channel_(false) {} |
666 void set_fail_create_channel(bool fail) { fail_create_channel_ = fail; } | 666 void set_fail_create_channel(bool fail) { fail_create_channel_ = fail; } |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
892 | 892 |
893 private: | 893 private: |
894 std::vector<FakeDataMediaChannel*> channels_; | 894 std::vector<FakeDataMediaChannel*> channels_; |
895 std::vector<DataCodec> data_codecs_; | 895 std::vector<DataCodec> data_codecs_; |
896 DataChannelType last_channel_type_; | 896 DataChannelType last_channel_type_; |
897 }; | 897 }; |
898 | 898 |
899 } // namespace cricket | 899 } // namespace cricket |
900 | 900 |
901 #endif // WEBRTC_MEDIA_BASE_FAKEMEDIAENGINE_H_ | 901 #endif // WEBRTC_MEDIA_BASE_FAKEMEDIAENGINE_H_ |
OLD | NEW |