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

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: rebase 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
« no previous file with comments | « talk/app/webrtc/statscollector_unittest.cc ('k') | talk/media/base/mediachannel.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 return ""; 163 return "";
174 return send_streams_[0].cname; 164 return send_streams_[0].cname;
175 } 165 }
176 166
177 bool ready_to_send() const { 167 bool ready_to_send() const {
178 return ready_to_send_; 168 return ready_to_send_;
179 } 169 }
180 170
181 protected: 171 protected:
182 bool MuteStream(uint32 ssrc, bool mute) { 172 bool MuteStream(uint32 ssrc, bool mute) {
183 if (!HasSendStream(ssrc) && ssrc != 0) 173 if (!HasSendStream(ssrc) && ssrc != 0) {
184 return false; 174 return false;
185 if (mute) 175 }
176 if (mute) {
186 muted_streams_.insert(ssrc); 177 muted_streams_.insert(ssrc);
187 else 178 } else {
188 muted_streams_.erase(ssrc); 179 muted_streams_.erase(ssrc);
180 }
189 return true; 181 return true;
190 } 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 22 matching lines...) Expand all
228 public: 230 public:
229 struct DtmfInfo { 231 struct DtmfInfo {
230 DtmfInfo(uint32 ssrc, int event_code, int duration, int flags) 232 DtmfInfo(uint32 ssrc, int event_code, int duration, int flags)
231 : ssrc(ssrc), event_code(event_code), duration(duration), flags(flags) { 233 : ssrc(ssrc), event_code(event_code), duration(duration), flags(flags) {
232 } 234 }
233 uint32 ssrc; 235 uint32 ssrc;
234 int event_code; 236 int event_code;
235 int duration; 237 int duration;
236 int flags; 238 int flags;
237 }; 239 };
238 explicit FakeVoiceMediaChannel(FakeVoiceEngine* engine) 240 explicit FakeVoiceMediaChannel(FakeVoiceEngine* engine,
241 const AudioOptions& options)
239 : engine_(engine), 242 : engine_(engine),
240 fail_set_send_(false), 243 fail_set_send_(false),
241 ringback_tone_ssrc_(0), 244 ringback_tone_ssrc_(0),
242 ringback_tone_play_(false), 245 ringback_tone_play_(false),
243 ringback_tone_loop_(false), 246 ringback_tone_loop_(false),
244 time_since_last_typing_(-1) { 247 time_since_last_typing_(-1) {
245 output_scalings_[0] = OutputScaling(); // For default channel. 248 output_scalings_[0] = OutputScaling(); // For default channel.
249 SetOptions(options);
246 } 250 }
247 ~FakeVoiceMediaChannel(); 251 ~FakeVoiceMediaChannel();
248 const std::vector<AudioCodec>& recv_codecs() const { return recv_codecs_; } 252 const std::vector<AudioCodec>& recv_codecs() const { return recv_codecs_; }
249 const std::vector<AudioCodec>& send_codecs() const { return send_codecs_; } 253 const std::vector<AudioCodec>& send_codecs() const { return send_codecs_; }
250 const std::vector<AudioCodec>& codecs() const { return send_codecs(); } 254 const std::vector<AudioCodec>& codecs() const { return send_codecs(); }
251 const std::vector<DtmfInfo>& dtmf_info_queue() const { 255 const std::vector<DtmfInfo>& dtmf_info_queue() const {
252 return dtmf_info_queue_; 256 return dtmf_info_queue_;
253 } 257 }
254 const AudioOptions& options() const { return options_; } 258 const AudioOptions& options() const { return options_; }
255 259
256 uint32 ringback_tone_ssrc() const { return ringback_tone_ssrc_; } 260 uint32 ringback_tone_ssrc() const { return ringback_tone_ssrc_; }
257 bool ringback_tone_play() const { return ringback_tone_play_; } 261 bool ringback_tone_play() const { return ringback_tone_play_; }
258 bool ringback_tone_loop() const { return ringback_tone_loop_; } 262 bool ringback_tone_loop() const { return ringback_tone_loop_; }
259 263
260 virtual bool SetRecvCodecs(const std::vector<AudioCodec>& codecs) { 264 virtual bool SetSendParameters(const AudioSendParameters& params) {
261 if (fail_set_recv_codecs()) { 265 return (SetSendCodecs(params.codecs) &&
262 // Fake the failure in SetRecvCodecs. 266 SetSendRtpHeaderExtensions(params.extensions) &&
263 return false; 267 SetMaxSendBandwidth(params.max_bandwidth_bps) &&
264 } 268 SetOptions(params.options));
265 recv_codecs_ = codecs;
266 return true;
267 } 269 }
268 virtual bool SetSendCodecs(const std::vector<AudioCodec>& codecs) { 270
269 if (fail_set_send_codecs()) { 271 virtual bool SetRecvParameters(const AudioRecvParameters& params) {
270 // Fake the failure in SetSendCodecs. 272 return (SetRecvCodecs(params.codecs) &&
271 return false; 273 SetRecvRtpHeaderExtensions(params.extensions));
272 }
273 send_codecs_ = codecs;
274 return true;
275 } 274 }
276 virtual bool SetPlayout(bool playout) { 275 virtual bool SetPlayout(bool playout) {
277 set_playout(playout); 276 set_playout(playout);
278 return true; 277 return true;
279 } 278 }
280 virtual bool SetSend(SendFlags flag) { 279 virtual bool SetSend(SendFlags flag) {
281 if (fail_set_send_) { 280 if (fail_set_send_) {
282 return false; 281 return false;
283 } 282 }
284 return set_sending(flag != SEND_NOTHING); 283 return set_sending(flag != SEND_NOTHING);
285 } 284 }
286 virtual bool SetAudioSend(uint32 ssrc, bool mute, 285 virtual bool SetAudioSend(uint32 ssrc, bool mute,
287 const AudioOptions* options, 286 const AudioOptions* options,
288 AudioRenderer* renderer) { 287 AudioRenderer* renderer) {
289 if (!SetLocalRenderer(ssrc, renderer)) { 288 if (!SetLocalRenderer(ssrc, renderer)) {
290 return false; 289 return false;
291 } 290 }
292 if (!RtpHelper<VoiceMediaChannel>::MuteStream(ssrc, mute)) { 291 if (!RtpHelper<VoiceMediaChannel>::MuteStream(ssrc, mute)) {
293 return false; 292 return false;
294 } 293 }
295 if (!mute && options) { 294 if (!mute && options) {
296 return SetOptions(*options); 295 return SetOptions(*options);
297 } 296 }
298 return true; 297 return true;
299 } 298 }
300 virtual bool SetMaxSendBandwidth(int bps) { return true; }
301 virtual bool AddRecvStream(const StreamParams& sp) { 299 virtual bool AddRecvStream(const StreamParams& sp) {
302 if (!RtpHelper<VoiceMediaChannel>::AddRecvStream(sp)) 300 if (!RtpHelper<VoiceMediaChannel>::AddRecvStream(sp))
303 return false; 301 return false;
304 output_scalings_[sp.first_ssrc()] = OutputScaling(); 302 output_scalings_[sp.first_ssrc()] = OutputScaling();
305 return true; 303 return true;
306 } 304 }
307 virtual bool RemoveRecvStream(uint32 ssrc) { 305 virtual bool RemoveRecvStream(uint32 ssrc) {
308 if (!RtpHelper<VoiceMediaChannel>::RemoveRecvStream(ssrc)) 306 if (!RtpHelper<VoiceMediaChannel>::RemoveRecvStream(ssrc))
309 return false; 307 return false;
310 output_scalings_.erase(ssrc); 308 output_scalings_.erase(ssrc);
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 *ssrc = 0; 390 *ssrc = 0;
393 *error = fail_set_send_ ? VoiceMediaChannel::ERROR_REC_DEVICE_OPEN_FAILED 391 *error = fail_set_send_ ? VoiceMediaChannel::ERROR_REC_DEVICE_OPEN_FAILED
394 : VoiceMediaChannel::ERROR_NONE; 392 : VoiceMediaChannel::ERROR_NONE;
395 } 393 }
396 394
397 void set_fail_set_send(bool fail) { fail_set_send_ = fail; } 395 void set_fail_set_send(bool fail) { fail_set_send_ = fail; }
398 void TriggerError(uint32 ssrc, VoiceMediaChannel::Error error) { 396 void TriggerError(uint32 ssrc, VoiceMediaChannel::Error error) {
399 VoiceMediaChannel::SignalMediaError(ssrc, error); 397 VoiceMediaChannel::SignalMediaError(ssrc, error);
400 } 398 }
401 399
402 virtual bool SetOptions(const AudioOptions& options) {
403 // Does a "merge" of current options and set options.
404 options_.SetAll(options);
405 return true;
406 }
407
408 private: 400 private:
409 struct OutputScaling { 401 struct OutputScaling {
410 OutputScaling() : left(1.0), right(1.0) {} 402 OutputScaling() : left(1.0), right(1.0) {}
411 double left, right; 403 double left, right;
412 }; 404 };
413 405
414 class VoiceChannelAudioSink : public AudioRenderer::Sink { 406 class VoiceChannelAudioSink : public AudioRenderer::Sink {
415 public: 407 public:
416 explicit VoiceChannelAudioSink(AudioRenderer* renderer) 408 explicit VoiceChannelAudioSink(AudioRenderer* renderer)
417 : renderer_(renderer) { 409 : renderer_(renderer) {
(...skipping 11 matching lines...) Expand all
429 int sample_rate, 421 int sample_rate,
430 int number_of_channels, 422 int number_of_channels,
431 size_t number_of_frames) override {} 423 size_t number_of_frames) override {}
432 void OnClose() override { renderer_ = NULL; } 424 void OnClose() override { renderer_ = NULL; }
433 AudioRenderer* renderer() const { return renderer_; } 425 AudioRenderer* renderer() const { return renderer_; }
434 426
435 private: 427 private:
436 AudioRenderer* renderer_; 428 AudioRenderer* renderer_;
437 }; 429 };
438 430
431 bool SetRecvCodecs(const std::vector<AudioCodec>& codecs) {
432 if (fail_set_recv_codecs()) {
433 // Fake the failure in SetRecvCodecs.
434 return false;
435 }
436 recv_codecs_ = codecs;
437 return true;
438 }
439 bool SetSendCodecs(const std::vector<AudioCodec>& codecs) {
440 if (fail_set_send_codecs()) {
441 // Fake the failure in SetSendCodecs.
442 return false;
443 }
444 send_codecs_ = codecs;
445 return true;
446 }
447 bool SetMaxSendBandwidth(int bps) { return true; }
448 bool SetOptions(const AudioOptions& options) {
449 // Does a "merge" of current options and set options.
450 options_.SetAll(options);
451 return true;
452 }
439 bool SetLocalRenderer(uint32 ssrc, AudioRenderer* renderer) { 453 bool SetLocalRenderer(uint32 ssrc, AudioRenderer* renderer) {
440 auto it = local_renderers_.find(ssrc); 454 auto it = local_renderers_.find(ssrc);
441 if (renderer) { 455 if (renderer) {
442 if (it != local_renderers_.end()) { 456 if (it != local_renderers_.end()) {
443 ASSERT(it->second->renderer() == renderer); 457 ASSERT(it->second->renderer() == renderer);
444 } else { 458 } else {
445 local_renderers_.insert(std::make_pair( 459 local_renderers_.insert(std::make_pair(
446 ssrc, new VoiceChannelAudioSink(renderer))); 460 ssrc, new VoiceChannelAudioSink(renderer)));
447 } 461 }
448 } else { 462 } else {
(...skipping 23 matching lines...) Expand all
472 // A helper function to compare the FakeVoiceMediaChannel::DtmfInfo. 486 // A helper function to compare the FakeVoiceMediaChannel::DtmfInfo.
473 inline bool CompareDtmfInfo(const FakeVoiceMediaChannel::DtmfInfo& info, 487 inline bool CompareDtmfInfo(const FakeVoiceMediaChannel::DtmfInfo& info,
474 uint32 ssrc, int event_code, int duration, 488 uint32 ssrc, int event_code, int duration,
475 int flags) { 489 int flags) {
476 return (info.duration == duration && info.event_code == event_code && 490 return (info.duration == duration && info.event_code == event_code &&
477 info.flags == flags && info.ssrc == ssrc); 491 info.flags == flags && info.ssrc == ssrc);
478 } 492 }
479 493
480 class FakeVideoMediaChannel : public RtpHelper<VideoMediaChannel> { 494 class FakeVideoMediaChannel : public RtpHelper<VideoMediaChannel> {
481 public: 495 public:
482 explicit FakeVideoMediaChannel(FakeVideoEngine* engine) 496 explicit FakeVideoMediaChannel(FakeVideoEngine* engine,
497 const VideoOptions& options)
483 : engine_(engine), 498 : engine_(engine),
484 sent_intra_frame_(false), 499 sent_intra_frame_(false),
485 requested_intra_frame_(false), 500 requested_intra_frame_(false),
486 max_bps_(-1) {} 501 max_bps_(-1) {
502 SetOptions(options);
503 }
487 504
488 ~FakeVideoMediaChannel(); 505 ~FakeVideoMediaChannel();
489 506
490 const std::vector<VideoCodec>& recv_codecs() const { return recv_codecs_; } 507 const std::vector<VideoCodec>& recv_codecs() const { return recv_codecs_; }
491 const std::vector<VideoCodec>& send_codecs() const { return send_codecs_; } 508 const std::vector<VideoCodec>& send_codecs() const { return send_codecs_; }
492 const std::vector<VideoCodec>& codecs() const { return send_codecs(); } 509 const std::vector<VideoCodec>& codecs() const { return send_codecs(); }
493 bool rendering() const { return playout(); } 510 bool rendering() const { return playout(); }
494 const VideoOptions& options() const { return options_; } 511 const VideoOptions& options() const { return options_; }
495 const std::map<uint32, VideoRenderer*>& renderers() const { 512 const std::map<uint32, VideoRenderer*>& renderers() const {
496 return renderers_; 513 return renderers_;
497 } 514 }
498 int max_bps() const { return max_bps_; } 515 int max_bps() const { return max_bps_; }
499 bool GetSendStreamFormat(uint32 ssrc, VideoFormat* format) { 516 bool GetSendStreamFormat(uint32 ssrc, VideoFormat* format) {
500 if (send_formats_.find(ssrc) == send_formats_.end()) { 517 if (send_formats_.find(ssrc) == send_formats_.end()) {
501 return false; 518 return false;
502 } 519 }
503 *format = send_formats_[ssrc]; 520 *format = send_formats_[ssrc];
504 return true; 521 return true;
505 } 522 }
506 virtual bool SetSendStreamFormat(uint32 ssrc, const VideoFormat& format) { 523 virtual bool SetSendStreamFormat(uint32 ssrc, const VideoFormat& format) {
507 if (send_formats_.find(ssrc) == send_formats_.end()) { 524 if (send_formats_.find(ssrc) == send_formats_.end()) {
508 return false; 525 return false;
509 } 526 }
510 send_formats_[ssrc] = format; 527 send_formats_[ssrc] = format;
511 return true; 528 return true;
512 } 529 }
530 virtual bool SetSendParameters(const VideoSendParameters& params) {
531 return (SetSendCodecs(params.codecs) &&
532 SetSendRtpHeaderExtensions(params.extensions) &&
533 SetMaxSendBandwidth(params.max_bandwidth_bps) &&
534 SetOptions(params.options));
535 }
513 536
537 virtual bool SetRecvParameters(const VideoRecvParameters& params) {
538 return (SetRecvCodecs(params.codecs) &&
539 SetRecvRtpHeaderExtensions(params.extensions));
540 }
514 virtual bool AddSendStream(const StreamParams& sp) { 541 virtual bool AddSendStream(const StreamParams& sp) {
515 if (!RtpHelper<VideoMediaChannel>::AddSendStream(sp)) { 542 if (!RtpHelper<VideoMediaChannel>::AddSendStream(sp)) {
516 return false; 543 return false;
517 } 544 }
518 SetSendStreamDefaultFormat(sp.first_ssrc()); 545 SetSendStreamDefaultFormat(sp.first_ssrc());
519 return true; 546 return true;
520 } 547 }
521 virtual bool RemoveSendStream(uint32 ssrc) { 548 virtual bool RemoveSendStream(uint32 ssrc) {
522 send_formats_.erase(ssrc); 549 send_formats_.erase(ssrc);
523 return RtpHelper<VideoMediaChannel>::RemoveSendStream(ssrc); 550 return RtpHelper<VideoMediaChannel>::RemoveSendStream(ssrc);
524 } 551 }
525 552
526 virtual bool SetRecvCodecs(const std::vector<VideoCodec>& codecs) {
527 if (fail_set_recv_codecs()) {
528 // Fake the failure in SetRecvCodecs.
529 return false;
530 }
531 recv_codecs_ = codecs;
532 return true;
533 }
534 virtual bool SetSendCodecs(const std::vector<VideoCodec>& codecs) {
535 if (fail_set_send_codecs()) {
536 // Fake the failure in SetSendCodecs.
537 return false;
538 }
539 send_codecs_ = codecs;
540
541 for (std::vector<StreamParams>::const_iterator it = send_streams().begin();
542 it != send_streams().end(); ++it) {
543 SetSendStreamDefaultFormat(it->first_ssrc());
544 }
545 return true;
546 }
547 virtual bool GetSendCodec(VideoCodec* send_codec) { 553 virtual bool GetSendCodec(VideoCodec* send_codec) {
548 if (send_codecs_.empty()) { 554 if (send_codecs_.empty()) {
549 return false; 555 return false;
550 } 556 }
551 *send_codec = send_codecs_[0]; 557 *send_codec = send_codecs_[0];
552 return true; 558 return true;
553 } 559 }
554 virtual bool SetRender(bool render) { 560 virtual bool SetRender(bool render) {
555 set_playout(render); 561 set_playout(render);
556 return true; 562 return true;
557 } 563 }
558 virtual bool SetRenderer(uint32 ssrc, VideoRenderer* r) { 564 virtual bool SetRenderer(uint32 ssrc, VideoRenderer* r) {
559 if (ssrc != 0 && renderers_.find(ssrc) == renderers_.end()) { 565 if (ssrc != 0 && renderers_.find(ssrc) == renderers_.end()) {
560 return false; 566 return false;
561 } 567 }
562 if (ssrc != 0) { 568 if (ssrc != 0) {
563 renderers_[ssrc] = r; 569 renderers_[ssrc] = r;
564 } 570 }
565 return true; 571 return true;
566 } 572 }
567 573
568 virtual bool SetSend(bool send) { return set_sending(send); } 574 virtual bool SetSend(bool send) { return set_sending(send); }
569 virtual bool SetVideoSend(uint32 ssrc, bool mute, 575 virtual bool SetVideoSend(uint32 ssrc, bool mute,
570 const VideoOptions* options) { 576 const VideoOptions* options) {
571 if (!RtpHelper<VideoMediaChannel>::MuteStream(ssrc, mute)) { 577 if (!RtpHelper<VideoMediaChannel>::MuteStream(ssrc, mute)) {
572 return false; 578 return false;
573 } 579 }
574 if (!mute && options) { 580 if (!mute && options) {
575 return SetOptions(*options); 581 return SetOptions(*options);
576 } else {
577 return true;
578 } 582 }
583 return true;
579 } 584 }
580 virtual bool SetCapturer(uint32 ssrc, VideoCapturer* capturer) { 585 virtual bool SetCapturer(uint32 ssrc, VideoCapturer* capturer) {
581 capturers_[ssrc] = capturer; 586 capturers_[ssrc] = capturer;
582 return true; 587 return true;
583 } 588 }
584 bool HasCapturer(uint32 ssrc) const { 589 bool HasCapturer(uint32 ssrc) const {
585 return capturers_.find(ssrc) != capturers_.end(); 590 return capturers_.find(ssrc) != capturers_.end();
586 } 591 }
587 virtual bool SetMaxSendBandwidth(int bps) {
588 max_bps_ = bps;
589 return true;
590 }
591 virtual bool AddRecvStream(const StreamParams& sp) { 592 virtual bool AddRecvStream(const StreamParams& sp) {
592 if (!RtpHelper<VideoMediaChannel>::AddRecvStream(sp)) 593 if (!RtpHelper<VideoMediaChannel>::AddRecvStream(sp))
593 return false; 594 return false;
594 renderers_[sp.first_ssrc()] = NULL; 595 renderers_[sp.first_ssrc()] = NULL;
595 return true; 596 return true;
596 } 597 }
597 virtual bool RemoveRecvStream(uint32 ssrc) { 598 virtual bool RemoveRecvStream(uint32 ssrc) {
598 if (!RtpHelper<VideoMediaChannel>::RemoveRecvStream(ssrc)) 599 if (!RtpHelper<VideoMediaChannel>::RemoveRecvStream(ssrc))
599 return false; 600 return false;
600 renderers_.erase(ssrc); 601 renderers_.erase(ssrc);
601 return true; 602 return true;
602 } 603 }
603 604
604 virtual bool GetStats(VideoMediaInfo* info) { return false; } 605 virtual bool GetStats(VideoMediaInfo* info) { return false; }
605 virtual bool SendIntraFrame() { 606 virtual bool SendIntraFrame() {
606 sent_intra_frame_ = true; 607 sent_intra_frame_ = true;
607 return true; 608 return true;
608 } 609 }
609 virtual bool RequestIntraFrame() { 610 virtual bool RequestIntraFrame() {
610 requested_intra_frame_ = true; 611 requested_intra_frame_ = true;
611 return true; 612 return true;
612 } 613 }
613 virtual bool SetOptions(const VideoOptions& options) {
614 options_ = options;
615 return true;
616 }
617 virtual void UpdateAspectRatio(int ratio_w, int ratio_h) {} 614 virtual void UpdateAspectRatio(int ratio_w, int ratio_h) {}
618 void set_sent_intra_frame(bool v) { sent_intra_frame_ = v; } 615 void set_sent_intra_frame(bool v) { sent_intra_frame_ = v; }
619 bool sent_intra_frame() const { return sent_intra_frame_; } 616 bool sent_intra_frame() const { return sent_intra_frame_; }
620 void set_requested_intra_frame(bool v) { requested_intra_frame_ = v; } 617 void set_requested_intra_frame(bool v) { requested_intra_frame_ = v; }
621 bool requested_intra_frame() const { return requested_intra_frame_; } 618 bool requested_intra_frame() const { return requested_intra_frame_; }
622 619
623 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
624 // Be default, each send stream uses the first send codec format. 651 // Be default, each send stream uses the first send codec format.
625 void SetSendStreamDefaultFormat(uint32 ssrc) { 652 void SetSendStreamDefaultFormat(uint32 ssrc) {
626 if (!send_codecs_.empty()) { 653 if (!send_codecs_.empty()) {
627 send_formats_[ssrc] = VideoFormat( 654 send_formats_[ssrc] = VideoFormat(
628 send_codecs_[0].width, send_codecs_[0].height, 655 send_codecs_[0].width, send_codecs_[0].height,
629 cricket::VideoFormat::FpsToInterval(send_codecs_[0].framerate), 656 cricket::VideoFormat::FpsToInterval(send_codecs_[0].framerate),
630 cricket::FOURCC_I420); 657 cricket::FOURCC_I420);
631 } 658 }
632 } 659 }
633 660
634 FakeVideoEngine* engine_; 661 FakeVideoEngine* engine_;
635 std::vector<VideoCodec> recv_codecs_; 662 std::vector<VideoCodec> recv_codecs_;
636 std::vector<VideoCodec> send_codecs_; 663 std::vector<VideoCodec> send_codecs_;
637 std::map<uint32, VideoRenderer*> renderers_; 664 std::map<uint32, VideoRenderer*> renderers_;
638 std::map<uint32, VideoFormat> send_formats_; 665 std::map<uint32, VideoFormat> send_formats_;
639 std::map<uint32, VideoCapturer*> capturers_; 666 std::map<uint32, VideoCapturer*> capturers_;
640 bool sent_intra_frame_; 667 bool sent_intra_frame_;
641 bool requested_intra_frame_; 668 bool requested_intra_frame_;
642 VideoOptions options_; 669 VideoOptions options_;
643 int max_bps_; 670 int max_bps_;
644 }; 671 };
645 672
646 class FakeDataMediaChannel : public RtpHelper<DataMediaChannel> { 673 class FakeDataMediaChannel : public RtpHelper<DataMediaChannel> {
647 public: 674 public:
648 explicit FakeDataMediaChannel(void* unused) 675 explicit FakeDataMediaChannel(void* unused, const DataOptions& options)
649 : send_blocked_(false), max_bps_(-1) {} 676 : send_blocked_(false), max_bps_(-1) {}
650 ~FakeDataMediaChannel() {} 677 ~FakeDataMediaChannel() {}
651 const std::vector<DataCodec>& recv_codecs() const { return recv_codecs_; } 678 const std::vector<DataCodec>& recv_codecs() const { return recv_codecs_; }
652 const std::vector<DataCodec>& send_codecs() const { return send_codecs_; } 679 const std::vector<DataCodec>& send_codecs() const { return send_codecs_; }
653 const std::vector<DataCodec>& codecs() const { return send_codecs(); } 680 const std::vector<DataCodec>& codecs() const { return send_codecs(); }
654 int max_bps() const { return max_bps_; } 681 int max_bps() const { return max_bps_; }
655 682
656 virtual bool SetRecvCodecs(const std::vector<DataCodec>& codecs) { 683 virtual bool SetSendParameters(const DataSendParameters& params) {
657 if (fail_set_recv_codecs()) { 684 return (SetSendCodecs(params.codecs) &&
658 // Fake the failure in SetRecvCodecs. 685 SetMaxSendBandwidth(params.max_bandwidth_bps));
659 return false;
660 }
661 recv_codecs_ = codecs;
662 return true;
663 } 686 }
664 virtual bool SetSendCodecs(const std::vector<DataCodec>& codecs) { 687 virtual bool SetRecvParameters(const DataRecvParameters& params) {
665 if (fail_set_send_codecs()) { 688 return SetRecvCodecs(params.codecs);
666 // Fake the failure in SetSendCodecs.
667 return false;
668 }
669 send_codecs_ = codecs;
670 return true;
671 } 689 }
672 virtual bool SetSend(bool send) { return set_sending(send); } 690 virtual bool SetSend(bool send) { return set_sending(send); }
673 virtual bool SetReceive(bool receive) { 691 virtual bool SetReceive(bool receive) {
674 set_playout(receive); 692 set_playout(receive);
675 return true; 693 return true;
676 } 694 }
677 virtual bool SetMaxSendBandwidth(int bps) {
678 max_bps_ = bps;
679 return true;
680 }
681 virtual bool AddRecvStream(const StreamParams& sp) { 695 virtual bool AddRecvStream(const StreamParams& sp) {
682 if (!RtpHelper<DataMediaChannel>::AddRecvStream(sp)) 696 if (!RtpHelper<DataMediaChannel>::AddRecvStream(sp))
683 return false; 697 return false;
684 return true; 698 return true;
685 } 699 }
686 virtual bool RemoveRecvStream(uint32 ssrc) { 700 virtual bool RemoveRecvStream(uint32 ssrc) {
687 if (!RtpHelper<DataMediaChannel>::RemoveRecvStream(ssrc)) 701 if (!RtpHelper<DataMediaChannel>::RemoveRecvStream(ssrc))
688 return false; 702 return false;
689 return true; 703 return true;
690 } 704 }
(...skipping 10 matching lines...) Expand all
701 return true; 715 return true;
702 } 716 }
703 } 717 }
704 718
705 SendDataParams last_sent_data_params() { return last_sent_data_params_; } 719 SendDataParams last_sent_data_params() { return last_sent_data_params_; }
706 std::string last_sent_data() { return last_sent_data_; } 720 std::string last_sent_data() { return last_sent_data_; }
707 bool is_send_blocked() { return send_blocked_; } 721 bool is_send_blocked() { return send_blocked_; }
708 void set_send_blocked(bool blocked) { send_blocked_ = blocked; } 722 void set_send_blocked(bool blocked) { send_blocked_ = blocked; }
709 723
710 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
711 std::vector<DataCodec> recv_codecs_; 746 std::vector<DataCodec> recv_codecs_;
712 std::vector<DataCodec> send_codecs_; 747 std::vector<DataCodec> send_codecs_;
713 SendDataParams last_sent_data_params_; 748 SendDataParams last_sent_data_params_;
714 std::string last_sent_data_; 749 std::string last_sent_data_;
715 bool send_blocked_; 750 bool send_blocked_;
716 int max_bps_; 751 int max_bps_;
717 }; 752 };
718 753
719 // A base class for all of the shared parts between FakeVoiceEngine 754 // A base class for all of the shared parts between FakeVoiceEngine
720 // and FakeVideoEngine. 755 // and FakeVideoEngine.
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
773 options_changed_ = true; 808 options_changed_ = true;
774 return true; 809 return true;
775 } 810 }
776 811
777 VoiceMediaChannel* CreateChannel(webrtc::Call* call, 812 VoiceMediaChannel* CreateChannel(webrtc::Call* call,
778 const AudioOptions& options) { 813 const AudioOptions& options) {
779 if (fail_create_channel_) { 814 if (fail_create_channel_) {
780 return nullptr; 815 return nullptr;
781 } 816 }
782 817
783 FakeVoiceMediaChannel* ch = new FakeVoiceMediaChannel(this); 818 FakeVoiceMediaChannel* ch = new FakeVoiceMediaChannel(this, options);
784 ch->SetOptions(options);
785 channels_.push_back(ch); 819 channels_.push_back(ch);
786 return ch; 820 return ch;
787 } 821 }
788 FakeVoiceMediaChannel* GetChannel(size_t index) { 822 FakeVoiceMediaChannel* GetChannel(size_t index) {
789 return (channels_.size() > index) ? channels_[index] : NULL; 823 return (channels_.size() > index) ? channels_[index] : NULL;
790 } 824 }
791 void UnregisterChannel(VoiceMediaChannel* channel) { 825 void UnregisterChannel(VoiceMediaChannel* channel) {
792 channels_.erase(std::find(channels_.begin(), channels_.end(), channel)); 826 channels_.erase(std::find(channels_.begin(), channels_.end(), channel));
793 } 827 }
794 828
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
885 const VideoEncoderConfig& default_encoder_config() const { 919 const VideoEncoderConfig& default_encoder_config() const {
886 return default_encoder_config_; 920 return default_encoder_config_;
887 } 921 }
888 922
889 VideoMediaChannel* CreateChannel(webrtc::Call* call, 923 VideoMediaChannel* CreateChannel(webrtc::Call* call,
890 const VideoOptions& options) { 924 const VideoOptions& options) {
891 if (fail_create_channel_) { 925 if (fail_create_channel_) {
892 return NULL; 926 return NULL;
893 } 927 }
894 928
895 FakeVideoMediaChannel* ch = new FakeVideoMediaChannel(this); 929 FakeVideoMediaChannel* ch = new FakeVideoMediaChannel(this, options);
896 ch->SetOptions(options);
897 channels_.push_back(ch); 930 channels_.push_back(ch);
898 return ch; 931 return ch;
899 } 932 }
900 FakeVideoMediaChannel* GetChannel(size_t index) { 933 FakeVideoMediaChannel* GetChannel(size_t index) {
901 return (channels_.size() > index) ? channels_[index] : NULL; 934 return (channels_.size() > index) ? channels_[index] : NULL;
902 } 935 }
903 void UnregisterChannel(VideoMediaChannel* channel) { 936 void UnregisterChannel(VideoMediaChannel* channel) {
904 channels_.erase(std::find(channels_.begin(), channels_.end(), channel)); 937 channels_.erase(std::find(channels_.begin(), channels_.end(), channel));
905 } 938 }
906 939
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
1028 engine_->UnregisterChannel(this); 1061 engine_->UnregisterChannel(this);
1029 } 1062 }
1030 } 1063 }
1031 1064
1032 class FakeDataEngine : public DataEngineInterface { 1065 class FakeDataEngine : public DataEngineInterface {
1033 public: 1066 public:
1034 FakeDataEngine() : last_channel_type_(DCT_NONE) {} 1067 FakeDataEngine() : last_channel_type_(DCT_NONE) {}
1035 1068
1036 virtual DataMediaChannel* CreateChannel(DataChannelType data_channel_type) { 1069 virtual DataMediaChannel* CreateChannel(DataChannelType data_channel_type) {
1037 last_channel_type_ = data_channel_type; 1070 last_channel_type_ = data_channel_type;
1038 FakeDataMediaChannel* ch = new FakeDataMediaChannel(this); 1071 FakeDataMediaChannel* ch = new FakeDataMediaChannel(this, DataOptions());
1039 channels_.push_back(ch); 1072 channels_.push_back(ch);
1040 return ch; 1073 return ch;
1041 } 1074 }
1042 1075
1043 FakeDataMediaChannel* GetChannel(size_t index) { 1076 FakeDataMediaChannel* GetChannel(size_t index) {
1044 return (channels_.size() > index) ? channels_[index] : NULL; 1077 return (channels_.size() > index) ? channels_[index] : NULL;
1045 } 1078 }
1046 1079
1047 void UnregisterChannel(DataMediaChannel* channel) { 1080 void UnregisterChannel(DataMediaChannel* channel) {
1048 channels_.erase(std::find(channels_.begin(), channels_.end(), channel)); 1081 channels_.erase(std::find(channels_.begin(), channels_.end(), channel));
1049 } 1082 }
1050 1083
1051 virtual void SetDataCodecs(const std::vector<DataCodec>& data_codecs) { 1084 virtual void SetDataCodecs(const std::vector<DataCodec>& data_codecs) {
1052 data_codecs_ = data_codecs; 1085 data_codecs_ = data_codecs;
1053 } 1086 }
1054 1087
1055 virtual const std::vector<DataCodec>& data_codecs() { return data_codecs_; } 1088 virtual const std::vector<DataCodec>& data_codecs() { return data_codecs_; }
1056 1089
1057 DataChannelType last_channel_type() const { return last_channel_type_; } 1090 DataChannelType last_channel_type() const { return last_channel_type_; }
1058 1091
1059 private: 1092 private:
1060 std::vector<FakeDataMediaChannel*> channels_; 1093 std::vector<FakeDataMediaChannel*> channels_;
1061 std::vector<DataCodec> data_codecs_; 1094 std::vector<DataCodec> data_codecs_;
1062 DataChannelType last_channel_type_; 1095 DataChannelType last_channel_type_;
1063 }; 1096 };
1064 1097
1065 } // namespace cricket 1098 } // namespace cricket
1066 1099
1067 #endif // TALK_MEDIA_BASE_FAKEMEDIAENGINE_H_ 1100 #endif // TALK_MEDIA_BASE_FAKEMEDIAENGINE_H_
OLDNEW
« no previous file with comments | « talk/app/webrtc/statscollector_unittest.cc ('k') | talk/media/base/mediachannel.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698