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

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

Issue 1327933002: Full impl of NnChannel::SetSendParameters and NnChannel::SetRecvParameters (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Got rid of SetChannelOptions Created 5 years, 3 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 * libjingle 2 * libjingle
3 * Copyright 2004 Google Inc. 3 * Copyright 2004 Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright notice, 8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer. 9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 bool success = !rtcp_packets_.empty(); 96 bool success = !rtcp_packets_.empty();
97 if (success) { 97 if (success) {
98 std::string packet = rtcp_packets_.front(); 98 std::string packet = rtcp_packets_.front();
99 rtcp_packets_.pop_front(); 99 rtcp_packets_.pop_front();
100 success = (packet == std::string(static_cast<const char*>(data), len)); 100 success = (packet == std::string(static_cast<const char*>(data), len));
101 } 101 }
102 return success; 102 return success;
103 } 103 }
104 bool CheckNoRtp() { return rtp_packets_.empty(); } 104 bool CheckNoRtp() { return rtp_packets_.empty(); }
105 bool CheckNoRtcp() { return rtcp_packets_.empty(); } 105 bool CheckNoRtcp() { return rtcp_packets_.empty(); }
106 virtual bool SetRecvRtpHeaderExtensions(
107 const std::vector<RtpHeaderExtension>& extensions) {
108 recv_extensions_ = extensions;
109 return true;
110 }
111 virtual bool SetSendRtpHeaderExtensions(
112 const std::vector<RtpHeaderExtension>& extensions) {
113 send_extensions_ = extensions;
114 return true;
115 }
116 void set_fail_set_send_codecs(bool fail) { fail_set_send_codecs_ = fail; } 106 void set_fail_set_send_codecs(bool fail) { fail_set_send_codecs_ = fail; }
117 void set_fail_set_recv_codecs(bool fail) { fail_set_recv_codecs_ = fail; } 107 void set_fail_set_recv_codecs(bool fail) { fail_set_recv_codecs_ = fail; }
118 virtual bool AddSendStream(const StreamParams& sp) { 108 virtual bool AddSendStream(const StreamParams& sp) {
119 if (std::find(send_streams_.begin(), send_streams_.end(), sp) != 109 if (std::find(send_streams_.begin(), send_streams_.end(), sp) !=
120 send_streams_.end()) { 110 send_streams_.end()) {
121 return false; 111 return false;
122 } 112 }
123 send_streams_.push_back(sp); 113 send_streams_.push_back(sp);
124 return true; 114 return true;
125 } 115 }
126 virtual bool RemoveSendStream(uint32 ssrc) { 116 virtual bool RemoveSendStream(uint32 ssrc) {
127 return RemoveStreamBySsrc(&send_streams_, ssrc); 117 return RemoveStreamBySsrc(&send_streams_, ssrc);
128 } 118 }
129 virtual bool AddRecvStream(const StreamParams& sp) { 119 virtual bool AddRecvStream(const StreamParams& sp) {
130 if (std::find(receive_streams_.begin(), receive_streams_.end(), sp) != 120 if (std::find(receive_streams_.begin(), receive_streams_.end(), sp) !=
131 receive_streams_.end()) { 121 receive_streams_.end()) {
132 return false; 122 return false;
133 } 123 }
134 receive_streams_.push_back(sp); 124 receive_streams_.push_back(sp);
135 return true; 125 return true;
136 } 126 }
137 virtual bool RemoveRecvStream(uint32 ssrc) { 127 virtual bool RemoveRecvStream(uint32 ssrc) {
138 return RemoveStreamBySsrc(&receive_streams_, ssrc); 128 return RemoveStreamBySsrc(&receive_streams_, ssrc);
139 } 129 }
140 virtual bool MuteStream(uint32 ssrc, bool on) {
141 if (!HasSendStream(ssrc) && ssrc != 0)
142 return false;
143 if (on)
144 muted_streams_.insert(ssrc);
145 else
146 muted_streams_.erase(ssrc);
147 return true;
148 }
149 bool IsStreamMuted(uint32 ssrc) const { 130 bool IsStreamMuted(uint32 ssrc) const {
150 bool ret = muted_streams_.find(ssrc) != muted_streams_.end(); 131 bool ret = muted_streams_.find(ssrc) != muted_streams_.end();
151 // If |ssrc = 0| check if the first send stream is muted. 132 // If |ssrc = 0| check if the first send stream is muted.
152 if (!ret && ssrc == 0 && !send_streams_.empty()) { 133 if (!ret && ssrc == 0 && !send_streams_.empty()) {
153 return muted_streams_.find(send_streams_[0].first_ssrc()) != 134 return muted_streams_.find(send_streams_[0].first_ssrc()) !=
154 muted_streams_.end(); 135 muted_streams_.end();
155 } 136 }
156 return ret; 137 return ret;
157 } 138 }
158 const std::vector<StreamParams>& send_streams() const { 139 const std::vector<StreamParams>& send_streams() const {
(...skipping 22 matching lines...) Expand all
181 if (send_streams_.empty()) 162 if (send_streams_.empty())
182 return ""; 163 return "";
183 return send_streams_[0].cname; 164 return send_streams_[0].cname;
184 } 165 }
185 166
186 bool ready_to_send() const { 167 bool ready_to_send() const {
187 return ready_to_send_; 168 return ready_to_send_;
188 } 169 }
189 170
190 protected: 171 protected:
172 bool MuteStream(uint32 ssrc, bool mute) {
173 if (!HasSendStream(ssrc) && ssrc != 0) {
174 return false;
175 }
176 if (mute) {
177 muted_streams_.insert(ssrc);
178 } else {
179 muted_streams_.erase(ssrc);
180 }
181 return true;
182 }
191 bool set_sending(bool send) { 183 bool set_sending(bool send) {
192 sending_ = send; 184 sending_ = send;
193 return true; 185 return true;
194 } 186 }
195 void set_playout(bool playout) { playout_ = playout; } 187 void set_playout(bool playout) { playout_ = playout; }
188 bool SetRecvRtpHeaderExtensions(
189 const std::vector<RtpHeaderExtension>& extensions) {
190 recv_extensions_ = extensions;
191 return true;
192 }
193 bool SetSendRtpHeaderExtensions(
194 const std::vector<RtpHeaderExtension>& extensions) {
195 send_extensions_ = extensions;
196 return true;
197 }
196 virtual void OnPacketReceived(rtc::Buffer* packet, 198 virtual void OnPacketReceived(rtc::Buffer* packet,
197 const rtc::PacketTime& packet_time) { 199 const rtc::PacketTime& packet_time) {
198 rtp_packets_.push_back(std::string(packet->data<char>(), packet->size())); 200 rtp_packets_.push_back(std::string(packet->data<char>(), packet->size()));
199 } 201 }
200 virtual void OnRtcpReceived(rtc::Buffer* packet, 202 virtual void OnRtcpReceived(rtc::Buffer* packet,
201 const rtc::PacketTime& packet_time) { 203 const rtc::PacketTime& packet_time) {
202 rtcp_packets_.push_back(std::string(packet->data<char>(), packet->size())); 204 rtcp_packets_.push_back(std::string(packet->data<char>(), packet->size()));
203 } 205 }
204 virtual void OnReadyToSend(bool ready) { 206 virtual void OnReadyToSend(bool ready) {
205 ready_to_send_ = ready; 207 ready_to_send_ = ready;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 const std::vector<AudioCodec>& codecs() const { return send_codecs(); } 252 const std::vector<AudioCodec>& codecs() const { return send_codecs(); }
251 const std::vector<DtmfInfo>& dtmf_info_queue() const { 253 const std::vector<DtmfInfo>& dtmf_info_queue() const {
252 return dtmf_info_queue_; 254 return dtmf_info_queue_;
253 } 255 }
254 const AudioOptions& options() const { return options_; } 256 const AudioOptions& options() const { return options_; }
255 257
256 uint32 ringback_tone_ssrc() const { return ringback_tone_ssrc_; } 258 uint32 ringback_tone_ssrc() const { return ringback_tone_ssrc_; }
257 bool ringback_tone_play() const { return ringback_tone_play_; } 259 bool ringback_tone_play() const { return ringback_tone_play_; }
258 bool ringback_tone_loop() const { return ringback_tone_loop_; } 260 bool ringback_tone_loop() const { return ringback_tone_loop_; }
259 261
260 virtual bool SetRecvCodecs(const std::vector<AudioCodec>& codecs) { 262 virtual bool SetSendParameters(const AudioSendParameters& params) {
261 if (fail_set_recv_codecs()) { 263 return (SetSendCodecs(params.codecs) &&
262 // Fake the failure in SetRecvCodecs. 264 SetSendRtpHeaderExtensions(params.extensions) &&
263 return false; 265 SetMaxSendBandwidth(params.max_bandwidth_bps) &&
264 } 266 SetOptions(params.options));
265 recv_codecs_ = codecs;
266 return true;
267 } 267 }
268 virtual bool SetSendCodecs(const std::vector<AudioCodec>& codecs) { 268
269 if (fail_set_send_codecs()) { 269 virtual bool SetRecvParameters(const AudioRecvParameters& params) {
270 // Fake the failure in SetSendCodecs. 270 return (SetRecvCodecs(params.codecs) &&
271 return false; 271 SetRecvRtpHeaderExtensions(params.extensions));
272 }
273 send_codecs_ = codecs;
274 return true;
275 } 272 }
276 virtual bool SetPlayout(bool playout) { 273 virtual bool SetPlayout(bool playout) {
277 set_playout(playout); 274 set_playout(playout);
278 return true; 275 return true;
279 } 276 }
280 virtual bool SetSend(SendFlags flag) { 277 virtual bool SetSend(SendFlags flag) {
281 if (fail_set_send_) { 278 if (fail_set_send_) {
282 return false; 279 return false;
283 } 280 }
284 return set_sending(flag != SEND_NOTHING); 281 return set_sending(flag != SEND_NOTHING);
285 } 282 }
286 virtual bool SetMaxSendBandwidth(int bps) { return true; } 283 virtual bool MuteStream(uint32 ssrc, bool mute, const AudioOptions* options) {
284 bool result = RtpHelper<VoiceMediaChannel>::MuteStream(ssrc, mute);
285 if (result && !mute && options) {
286 return SetOptions(*options);
287 } else {
288 return result;
289 }
290 }
287 virtual bool AddRecvStream(const StreamParams& sp) { 291 virtual bool AddRecvStream(const StreamParams& sp) {
288 if (!RtpHelper<VoiceMediaChannel>::AddRecvStream(sp)) 292 if (!RtpHelper<VoiceMediaChannel>::AddRecvStream(sp))
289 return false; 293 return false;
290 output_scalings_[sp.first_ssrc()] = OutputScaling(); 294 output_scalings_[sp.first_ssrc()] = OutputScaling();
291 return true; 295 return true;
292 } 296 }
293 virtual bool RemoveRecvStream(uint32 ssrc) { 297 virtual bool RemoveRecvStream(uint32 ssrc) {
294 if (!RtpHelper<VoiceMediaChannel>::RemoveRecvStream(ssrc)) 298 if (!RtpHelper<VoiceMediaChannel>::RemoveRecvStream(ssrc))
295 return false; 299 return false;
296 output_scalings_.erase(ssrc); 300 output_scalings_.erase(ssrc);
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 *ssrc = 0; 402 *ssrc = 0;
399 *error = fail_set_send_ ? VoiceMediaChannel::ERROR_REC_DEVICE_OPEN_FAILED 403 *error = fail_set_send_ ? VoiceMediaChannel::ERROR_REC_DEVICE_OPEN_FAILED
400 : VoiceMediaChannel::ERROR_NONE; 404 : VoiceMediaChannel::ERROR_NONE;
401 } 405 }
402 406
403 void set_fail_set_send(bool fail) { fail_set_send_ = fail; } 407 void set_fail_set_send(bool fail) { fail_set_send_ = fail; }
404 void TriggerError(uint32 ssrc, VoiceMediaChannel::Error error) { 408 void TriggerError(uint32 ssrc, VoiceMediaChannel::Error error) {
405 VoiceMediaChannel::SignalMediaError(ssrc, error); 409 VoiceMediaChannel::SignalMediaError(ssrc, error);
406 } 410 }
407 411
408 virtual bool SetOptions(const AudioOptions& options) {
409 // Does a "merge" of current options and set options.
410 options_.SetAll(options);
411 return true;
412 }
413 virtual bool GetOptions(AudioOptions* options) const { 412 virtual bool GetOptions(AudioOptions* options) const {
414 *options = options_; 413 *options = options_;
415 return true; 414 return true;
416 } 415 }
417 416
418 private: 417 private:
419 struct OutputScaling { 418 struct OutputScaling {
420 OutputScaling() : left(1.0), right(1.0) {} 419 OutputScaling() : left(1.0), right(1.0) {}
421 double left, right; 420 double left, right;
422 }; 421 };
(...skipping 16 matching lines...) Expand all
439 int sample_rate, 438 int sample_rate,
440 int number_of_channels, 439 int number_of_channels,
441 size_t number_of_frames) override {} 440 size_t number_of_frames) override {}
442 void OnClose() override { renderer_ = NULL; } 441 void OnClose() override { renderer_ = NULL; }
443 AudioRenderer* renderer() const { return renderer_; } 442 AudioRenderer* renderer() const { return renderer_; }
444 443
445 private: 444 private:
446 AudioRenderer* renderer_; 445 AudioRenderer* renderer_;
447 }; 446 };
448 447
448 bool SetRecvCodecs(const std::vector<AudioCodec>& codecs) {
449 if (fail_set_recv_codecs()) {
450 // Fake the failure in SetRecvCodecs.
451 return false;
452 }
453 recv_codecs_ = codecs;
454 return true;
455 }
456 bool SetSendCodecs(const std::vector<AudioCodec>& codecs) {
457 if (fail_set_send_codecs()) {
458 // Fake the failure in SetSendCodecs.
459 return false;
460 }
461 send_codecs_ = codecs;
462 return true;
463 }
464 bool SetMaxSendBandwidth(int bps) { return true; }
465 bool SetOptions(const AudioOptions& options) {
466 // Does a "merge" of current options and set options.
467 options_.SetAll(options);
468 return true;
469 }
449 470
450 FakeVoiceEngine* engine_; 471 FakeVoiceEngine* engine_;
451 std::vector<AudioCodec> recv_codecs_; 472 std::vector<AudioCodec> recv_codecs_;
452 std::vector<AudioCodec> send_codecs_; 473 std::vector<AudioCodec> send_codecs_;
453 std::map<uint32, OutputScaling> output_scalings_; 474 std::map<uint32, OutputScaling> output_scalings_;
454 std::vector<DtmfInfo> dtmf_info_queue_; 475 std::vector<DtmfInfo> dtmf_info_queue_;
455 bool fail_set_send_; 476 bool fail_set_send_;
456 uint32 ringback_tone_ssrc_; 477 uint32 ringback_tone_ssrc_;
457 bool ringback_tone_play_; 478 bool ringback_tone_play_;
458 bool ringback_tone_loop_; 479 bool ringback_tone_loop_;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 *format = send_formats_[ssrc]; 517 *format = send_formats_[ssrc];
497 return true; 518 return true;
498 } 519 }
499 virtual bool SetSendStreamFormat(uint32 ssrc, const VideoFormat& format) { 520 virtual bool SetSendStreamFormat(uint32 ssrc, const VideoFormat& format) {
500 if (send_formats_.find(ssrc) == send_formats_.end()) { 521 if (send_formats_.find(ssrc) == send_formats_.end()) {
501 return false; 522 return false;
502 } 523 }
503 send_formats_[ssrc] = format; 524 send_formats_[ssrc] = format;
504 return true; 525 return true;
505 } 526 }
527 virtual bool SetSendParameters(const VideoSendParameters& params) {
528 return (SetSendCodecs(params.codecs) &&
529 SetSendRtpHeaderExtensions(params.extensions) &&
530 SetMaxSendBandwidth(params.max_bandwidth_bps) &&
531 SetOptions(params.options));
532 }
506 533
534 virtual bool SetRecvParameters(const VideoRecvParameters& params) {
535 return (SetRecvCodecs(params.codecs) &&
536 SetRecvRtpHeaderExtensions(params.extensions));
537 }
507 virtual bool AddSendStream(const StreamParams& sp) { 538 virtual bool AddSendStream(const StreamParams& sp) {
508 if (!RtpHelper<VideoMediaChannel>::AddSendStream(sp)) { 539 if (!RtpHelper<VideoMediaChannel>::AddSendStream(sp)) {
509 return false; 540 return false;
510 } 541 }
511 SetSendStreamDefaultFormat(sp.first_ssrc()); 542 SetSendStreamDefaultFormat(sp.first_ssrc());
512 return true; 543 return true;
513 } 544 }
514 virtual bool RemoveSendStream(uint32 ssrc) { 545 virtual bool RemoveSendStream(uint32 ssrc) {
515 send_formats_.erase(ssrc); 546 send_formats_.erase(ssrc);
516 return RtpHelper<VideoMediaChannel>::RemoveSendStream(ssrc); 547 return RtpHelper<VideoMediaChannel>::RemoveSendStream(ssrc);
517 } 548 }
518 549
519 void DetachVoiceChannel() override {} 550 void DetachVoiceChannel() override {}
520 virtual bool SetRecvCodecs(const std::vector<VideoCodec>& codecs) {
521 if (fail_set_recv_codecs()) {
522 // Fake the failure in SetRecvCodecs.
523 return false;
524 }
525 recv_codecs_ = codecs;
526 return true;
527 }
528 virtual bool SetSendCodecs(const std::vector<VideoCodec>& codecs) {
529 if (fail_set_send_codecs()) {
530 // Fake the failure in SetSendCodecs.
531 return false;
532 }
533 send_codecs_ = codecs;
534
535 for (std::vector<StreamParams>::const_iterator it = send_streams().begin();
536 it != send_streams().end(); ++it) {
537 SetSendStreamDefaultFormat(it->first_ssrc());
538 }
539 return true;
540 }
541 virtual bool GetSendCodec(VideoCodec* send_codec) { 551 virtual bool GetSendCodec(VideoCodec* send_codec) {
542 if (send_codecs_.empty()) { 552 if (send_codecs_.empty()) {
543 return false; 553 return false;
544 } 554 }
545 *send_codec = send_codecs_[0]; 555 *send_codec = send_codecs_[0];
546 return true; 556 return true;
547 } 557 }
548 virtual bool SetRender(bool render) { 558 virtual bool SetRender(bool render) {
549 set_playout(render); 559 set_playout(render);
550 return true; 560 return true;
551 } 561 }
552 virtual bool SetRenderer(uint32 ssrc, VideoRenderer* r) { 562 virtual bool SetRenderer(uint32 ssrc, VideoRenderer* r) {
553 if (ssrc != 0 && renderers_.find(ssrc) == renderers_.end()) { 563 if (ssrc != 0 && renderers_.find(ssrc) == renderers_.end()) {
554 return false; 564 return false;
555 } 565 }
556 if (ssrc != 0) { 566 if (ssrc != 0) {
557 renderers_[ssrc] = r; 567 renderers_[ssrc] = r;
558 } 568 }
559 return true; 569 return true;
560 } 570 }
561 571
562 virtual bool SetSend(bool send) { return set_sending(send); } 572 virtual bool SetSend(bool send) { return set_sending(send); }
573 virtual bool MuteStream(uint32 ssrc, bool mute, const VideoOptions* options) {
574 bool result = RtpHelper<VideoMediaChannel>::MuteStream(ssrc, mute);
575 if (result && !mute && options) {
576 return SetOptions(*options);
577 } else {
578 return result;
579 }
580 }
563 virtual bool SetCapturer(uint32 ssrc, VideoCapturer* capturer) { 581 virtual bool SetCapturer(uint32 ssrc, VideoCapturer* capturer) {
564 capturers_[ssrc] = capturer; 582 capturers_[ssrc] = capturer;
565 return true; 583 return true;
566 } 584 }
567 bool HasCapturer(uint32 ssrc) const { 585 bool HasCapturer(uint32 ssrc) const {
568 return capturers_.find(ssrc) != capturers_.end(); 586 return capturers_.find(ssrc) != capturers_.end();
569 } 587 }
570 virtual bool SetMaxSendBandwidth(int bps) {
571 max_bps_ = bps;
572 return true;
573 }
574 virtual bool AddRecvStream(const StreamParams& sp) { 588 virtual bool AddRecvStream(const StreamParams& sp) {
575 if (!RtpHelper<VideoMediaChannel>::AddRecvStream(sp)) 589 if (!RtpHelper<VideoMediaChannel>::AddRecvStream(sp))
576 return false; 590 return false;
577 renderers_[sp.first_ssrc()] = NULL; 591 renderers_[sp.first_ssrc()] = NULL;
578 return true; 592 return true;
579 } 593 }
580 virtual bool RemoveRecvStream(uint32 ssrc) { 594 virtual bool RemoveRecvStream(uint32 ssrc) {
581 if (!RtpHelper<VideoMediaChannel>::RemoveRecvStream(ssrc)) 595 if (!RtpHelper<VideoMediaChannel>::RemoveRecvStream(ssrc))
582 return false; 596 return false;
583 renderers_.erase(ssrc); 597 renderers_.erase(ssrc);
584 return true; 598 return true;
585 } 599 }
586 600
587 virtual bool GetStats(VideoMediaInfo* info) { return false; } 601 virtual bool GetStats(VideoMediaInfo* info) { return false; }
588 virtual bool SendIntraFrame() { 602 virtual bool SendIntraFrame() {
589 sent_intra_frame_ = true; 603 sent_intra_frame_ = true;
590 return true; 604 return true;
591 } 605 }
592 virtual bool RequestIntraFrame() { 606 virtual bool RequestIntraFrame() {
593 requested_intra_frame_ = true; 607 requested_intra_frame_ = true;
594 return true; 608 return true;
595 } 609 }
596 virtual bool SetOptions(const VideoOptions& options) {
597 options_ = options;
598 return true;
599 }
600 virtual bool GetOptions(VideoOptions* options) const { 610 virtual bool GetOptions(VideoOptions* options) const {
601 *options = options_; 611 *options = options_;
602 return true; 612 return true;
603 } 613 }
604 virtual void UpdateAspectRatio(int ratio_w, int ratio_h) {} 614 virtual void UpdateAspectRatio(int ratio_w, int ratio_h) {}
605 void set_sent_intra_frame(bool v) { sent_intra_frame_ = v; } 615 void set_sent_intra_frame(bool v) { sent_intra_frame_ = v; }
606 bool sent_intra_frame() const { return sent_intra_frame_; } 616 bool sent_intra_frame() const { return sent_intra_frame_; }
607 void set_requested_intra_frame(bool v) { requested_intra_frame_ = v; } 617 void set_requested_intra_frame(bool v) { requested_intra_frame_ = v; }
608 bool requested_intra_frame() const { return requested_intra_frame_; } 618 bool requested_intra_frame() const { return requested_intra_frame_; }
609 619
610 private: 620 private:
621 bool SetRecvCodecs(const std::vector<VideoCodec>& codecs) {
622 if (fail_set_recv_codecs()) {
623 // Fake the failure in SetRecvCodecs.
624 return false;
625 }
626 recv_codecs_ = codecs;
627 return true;
628 }
629 bool SetSendCodecs(const std::vector<VideoCodec>& codecs) {
630 if (fail_set_send_codecs()) {
631 // Fake the failure in SetSendCodecs.
632 return false;
633 }
634 send_codecs_ = codecs;
635
636 for (std::vector<StreamParams>::const_iterator it = send_streams().begin();
637 it != send_streams().end(); ++it) {
638 SetSendStreamDefaultFormat(it->first_ssrc());
639 }
640 return true;
641 }
642 bool SetOptions(const VideoOptions& options) {
643 options_ = options;
644 return true;
645 }
646 bool SetMaxSendBandwidth(int bps) {
647 max_bps_ = bps;
648 return true;
649 }
650
611 // Be default, each send stream uses the first send codec format. 651 // Be default, each send stream uses the first send codec format.
612 void SetSendStreamDefaultFormat(uint32 ssrc) { 652 void SetSendStreamDefaultFormat(uint32 ssrc) {
613 if (!send_codecs_.empty()) { 653 if (!send_codecs_.empty()) {
614 send_formats_[ssrc] = VideoFormat( 654 send_formats_[ssrc] = VideoFormat(
615 send_codecs_[0].width, send_codecs_[0].height, 655 send_codecs_[0].width, send_codecs_[0].height,
616 cricket::VideoFormat::FpsToInterval(send_codecs_[0].framerate), 656 cricket::VideoFormat::FpsToInterval(send_codecs_[0].framerate),
617 cricket::FOURCC_I420); 657 cricket::FOURCC_I420);
618 } 658 }
619 } 659 }
620 660
(...skipping 12 matching lines...) Expand all
633 class FakeDataMediaChannel : public RtpHelper<DataMediaChannel> { 673 class FakeDataMediaChannel : public RtpHelper<DataMediaChannel> {
634 public: 674 public:
635 explicit FakeDataMediaChannel(void* unused) 675 explicit FakeDataMediaChannel(void* unused)
636 : send_blocked_(false), max_bps_(-1) {} 676 : send_blocked_(false), max_bps_(-1) {}
637 ~FakeDataMediaChannel() {} 677 ~FakeDataMediaChannel() {}
638 const std::vector<DataCodec>& recv_codecs() const { return recv_codecs_; } 678 const std::vector<DataCodec>& recv_codecs() const { return recv_codecs_; }
639 const std::vector<DataCodec>& send_codecs() const { return send_codecs_; } 679 const std::vector<DataCodec>& send_codecs() const { return send_codecs_; }
640 const std::vector<DataCodec>& codecs() const { return send_codecs(); } 680 const std::vector<DataCodec>& codecs() const { return send_codecs(); }
641 int max_bps() const { return max_bps_; } 681 int max_bps() const { return max_bps_; }
642 682
643 virtual bool SetRecvCodecs(const std::vector<DataCodec>& codecs) { 683 virtual bool SetSendParameters(const DataSendParameters& params) {
644 if (fail_set_recv_codecs()) { 684 return (SetSendCodecs(params.codecs) &&
645 // Fake the failure in SetRecvCodecs. 685 SetMaxSendBandwidth(params.max_bandwidth_bps));
646 return false;
647 }
648 recv_codecs_ = codecs;
649 return true;
650 } 686 }
651 virtual bool SetSendCodecs(const std::vector<DataCodec>& codecs) { 687 virtual bool SetRecvParameters(const DataRecvParameters& params) {
652 if (fail_set_send_codecs()) { 688 return SetRecvCodecs(params.codecs);
653 // Fake the failure in SetSendCodecs.
654 return false;
655 }
656 send_codecs_ = codecs;
657 return true;
658 } 689 }
659 virtual bool SetSend(bool send) { return set_sending(send); } 690 virtual bool SetSend(bool send) { return set_sending(send); }
660 virtual bool SetReceive(bool receive) { 691 virtual bool SetReceive(bool receive) {
661 set_playout(receive); 692 set_playout(receive);
662 return true; 693 return true;
663 } 694 }
664 virtual bool SetMaxSendBandwidth(int bps) {
665 max_bps_ = bps;
666 return true;
667 }
668 virtual bool AddRecvStream(const StreamParams& sp) { 695 virtual bool AddRecvStream(const StreamParams& sp) {
669 if (!RtpHelper<DataMediaChannel>::AddRecvStream(sp)) 696 if (!RtpHelper<DataMediaChannel>::AddRecvStream(sp))
670 return false; 697 return false;
671 return true; 698 return true;
672 } 699 }
673 virtual bool RemoveRecvStream(uint32 ssrc) { 700 virtual bool RemoveRecvStream(uint32 ssrc) {
674 if (!RtpHelper<DataMediaChannel>::RemoveRecvStream(ssrc)) 701 if (!RtpHelper<DataMediaChannel>::RemoveRecvStream(ssrc))
675 return false; 702 return false;
676 return true; 703 return true;
677 } 704 }
(...skipping 10 matching lines...) Expand all
688 return true; 715 return true;
689 } 716 }
690 } 717 }
691 718
692 SendDataParams last_sent_data_params() { return last_sent_data_params_; } 719 SendDataParams last_sent_data_params() { return last_sent_data_params_; }
693 std::string last_sent_data() { return last_sent_data_; } 720 std::string last_sent_data() { return last_sent_data_; }
694 bool is_send_blocked() { return send_blocked_; } 721 bool is_send_blocked() { return send_blocked_; }
695 void set_send_blocked(bool blocked) { send_blocked_ = blocked; } 722 void set_send_blocked(bool blocked) { send_blocked_ = blocked; }
696 723
697 private: 724 private:
725 bool SetRecvCodecs(const std::vector<DataCodec>& codecs) {
726 if (fail_set_recv_codecs()) {
727 // Fake the failure in SetRecvCodecs.
728 return false;
729 }
730 recv_codecs_ = codecs;
731 return true;
732 }
733 bool SetSendCodecs(const std::vector<DataCodec>& codecs) {
734 if (fail_set_send_codecs()) {
735 // Fake the failure in SetSendCodecs.
736 return false;
737 }
738 send_codecs_ = codecs;
739 return true;
740 }
741 bool SetMaxSendBandwidth(int bps) {
742 max_bps_ = bps;
743 return true;
744 }
745
698 std::vector<DataCodec> recv_codecs_; 746 std::vector<DataCodec> recv_codecs_;
699 std::vector<DataCodec> send_codecs_; 747 std::vector<DataCodec> send_codecs_;
700 SendDataParams last_sent_data_params_; 748 SendDataParams last_sent_data_params_;
701 std::string last_sent_data_; 749 std::string last_sent_data_;
702 bool send_blocked_; 750 bool send_blocked_;
703 int max_bps_; 751 int max_bps_;
704 }; 752 };
705 753
706 // A base class for all of the shared parts between FakeVoiceEngine 754 // A base class for all of the shared parts between FakeVoiceEngine
707 // and FakeVideoEngine. 755 // and FakeVideoEngine.
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 options_changed_ = true; 810 options_changed_ = true;
763 return true; 811 return true;
764 } 812 }
765 813
766 VoiceMediaChannel* CreateChannel(const AudioOptions& options) { 814 VoiceMediaChannel* CreateChannel(const AudioOptions& options) {
767 if (fail_create_channel_) { 815 if (fail_create_channel_) {
768 return nullptr; 816 return nullptr;
769 } 817 }
770 818
771 FakeVoiceMediaChannel* ch = new FakeVoiceMediaChannel(this); 819 FakeVoiceMediaChannel* ch = new FakeVoiceMediaChannel(this);
772 ch->SetOptions(options); 820 // TODO(solenberg): !!!!!! SetParameters with only options?
821 // ch->SetOptions(options);
pthatcher1 2015/09/04 23:21:16 The options don't matter until the other parameter
the sun 2015/09/11 15:03:03 Done.
773 channels_.push_back(ch); 822 channels_.push_back(ch);
774 return ch; 823 return ch;
775 } 824 }
776 FakeVoiceMediaChannel* GetChannel(size_t index) { 825 FakeVoiceMediaChannel* GetChannel(size_t index) {
777 return (channels_.size() > index) ? channels_[index] : NULL; 826 return (channels_.size() > index) ? channels_[index] : NULL;
778 } 827 }
779 void UnregisterChannel(VoiceMediaChannel* channel) { 828 void UnregisterChannel(VoiceMediaChannel* channel) {
780 channels_.erase(std::find(channels_.begin(), channels_.end(), channel)); 829 channels_.erase(std::find(channels_.begin(), channels_.end(), channel));
781 } 830 }
782 831
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
880 return default_encoder_config_; 929 return default_encoder_config_;
881 } 930 }
882 931
883 VideoMediaChannel* CreateChannel(const VideoOptions& options, 932 VideoMediaChannel* CreateChannel(const VideoOptions& options,
884 VoiceMediaChannel* channel) { 933 VoiceMediaChannel* channel) {
885 if (fail_create_channel_) { 934 if (fail_create_channel_) {
886 return NULL; 935 return NULL;
887 } 936 }
888 937
889 FakeVideoMediaChannel* ch = new FakeVideoMediaChannel(this); 938 FakeVideoMediaChannel* ch = new FakeVideoMediaChannel(this);
890 ch->SetOptions(options); 939 // TODO(solenberg): !!!!! SetParameters with only options?
940 // ch->SetOptions(options);
891 channels_.push_back(ch); 941 channels_.push_back(ch);
892 return ch; 942 return ch;
893 } 943 }
894 FakeVideoMediaChannel* GetChannel(size_t index) { 944 FakeVideoMediaChannel* GetChannel(size_t index) {
895 return (channels_.size() > index) ? channels_[index] : NULL; 945 return (channels_.size() > index) ? channels_[index] : NULL;
896 } 946 }
897 void UnregisterChannel(VideoMediaChannel* channel) { 947 void UnregisterChannel(VideoMediaChannel* channel) {
898 channels_.erase(std::find(channels_.begin(), channels_.end(), channel)); 948 channels_.erase(std::find(channels_.begin(), channels_.end(), channel));
899 } 949 }
900 950
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
1052 1102
1053 private: 1103 private:
1054 std::vector<FakeDataMediaChannel*> channels_; 1104 std::vector<FakeDataMediaChannel*> channels_;
1055 std::vector<DataCodec> data_codecs_; 1105 std::vector<DataCodec> data_codecs_;
1056 DataChannelType last_channel_type_; 1106 DataChannelType last_channel_type_;
1057 }; 1107 };
1058 1108
1059 } // namespace cricket 1109 } // namespace cricket
1060 1110
1061 #endif // TALK_MEDIA_BASE_FAKEMEDIAENGINE_H_ 1111 #endif // TALK_MEDIA_BASE_FAKEMEDIAENGINE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698