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 |
11 #ifndef WEBRTC_MEDIA_BASE_FAKEMEDIAENGINE_H_ | 11 #ifndef WEBRTC_MEDIA_BASE_FAKEMEDIAENGINE_H_ |
12 #define WEBRTC_MEDIA_BASE_FAKEMEDIAENGINE_H_ | 12 #define WEBRTC_MEDIA_BASE_FAKEMEDIAENGINE_H_ |
13 | 13 |
14 #include <list> | 14 #include <list> |
15 #include <map> | 15 #include <map> |
16 #include <memory> | 16 #include <memory> |
17 #include <set> | 17 #include <set> |
18 #include <string> | 18 #include <string> |
19 #include <vector> | 19 #include <vector> |
20 | 20 |
21 #include "webrtc/audio_sink.h" | 21 #include "webrtc/audio_sink.h" |
22 #include "webrtc/base/buffer.h" | 22 #include "webrtc/base/buffer.h" |
23 #include "webrtc/base/stringutils.h" | 23 #include "webrtc/base/stringutils.h" |
24 #include "webrtc/media/base/audiorenderer.h" | 24 #include "webrtc/media/base/audiosource.h" |
25 #include "webrtc/media/base/mediaengine.h" | 25 #include "webrtc/media/base/mediaengine.h" |
26 #include "webrtc/media/base/rtputils.h" | 26 #include "webrtc/media/base/rtputils.h" |
27 #include "webrtc/media/base/streamparams.h" | 27 #include "webrtc/media/base/streamparams.h" |
28 #include "webrtc/p2p/base/sessiondescription.h" | 28 #include "webrtc/p2p/base/sessiondescription.h" |
29 | 29 |
30 namespace cricket { | 30 namespace cricket { |
31 | 31 |
32 class FakeMediaEngine; | 32 class FakeMediaEngine; |
33 class FakeVideoEngine; | 33 class FakeVideoEngine; |
34 class FakeVoiceEngine; | 34 class FakeVoiceEngine; |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 virtual bool SetPlayout(bool playout) { | 252 virtual bool SetPlayout(bool playout) { |
253 set_playout(playout); | 253 set_playout(playout); |
254 return true; | 254 return true; |
255 } | 255 } |
256 virtual bool SetSend(SendFlags flag) { | 256 virtual bool SetSend(SendFlags flag) { |
257 return set_sending(flag != SEND_NOTHING); | 257 return set_sending(flag != SEND_NOTHING); |
258 } | 258 } |
259 virtual bool SetAudioSend(uint32_t ssrc, | 259 virtual bool SetAudioSend(uint32_t ssrc, |
260 bool enable, | 260 bool enable, |
261 const AudioOptions* options, | 261 const AudioOptions* options, |
262 AudioRenderer* renderer) { | 262 AudioSource* source) { |
263 if (!SetLocalRenderer(ssrc, renderer)) { | 263 if (!SetLocalSource(ssrc, source)) { |
264 return false; | 264 return false; |
265 } | 265 } |
266 if (!RtpHelper<VoiceMediaChannel>::MuteStream(ssrc, !enable)) { | 266 if (!RtpHelper<VoiceMediaChannel>::MuteStream(ssrc, !enable)) { |
267 return false; | 267 return false; |
268 } | 268 } |
269 if (enable && options) { | 269 if (enable && options) { |
270 return SetOptions(*options); | 270 return SetOptions(*options); |
271 } | 271 } |
272 return true; | 272 return true; |
273 } | 273 } |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 | 331 |
332 virtual bool GetStats(VoiceMediaInfo* info) { return false; } | 332 virtual bool GetStats(VoiceMediaInfo* info) { return false; } |
333 | 333 |
334 virtual void SetRawAudioSink( | 334 virtual void SetRawAudioSink( |
335 uint32_t ssrc, | 335 uint32_t ssrc, |
336 std::unique_ptr<webrtc::AudioSinkInterface> sink) { | 336 std::unique_ptr<webrtc::AudioSinkInterface> sink) { |
337 sink_ = std::move(sink); | 337 sink_ = std::move(sink); |
338 } | 338 } |
339 | 339 |
340 private: | 340 private: |
341 class VoiceChannelAudioSink : public AudioRenderer::Sink { | 341 class VoiceChannelAudioSink : public AudioSource::Sink { |
342 public: | 342 public: |
343 explicit VoiceChannelAudioSink(AudioRenderer* renderer) | 343 explicit VoiceChannelAudioSink(AudioSource* source) : source_(source) { |
344 : renderer_(renderer) { | 344 source_->SetSink(this); |
345 renderer_->SetSink(this); | |
346 } | 345 } |
347 virtual ~VoiceChannelAudioSink() { | 346 virtual ~VoiceChannelAudioSink() { |
348 if (renderer_) { | 347 if (source_) { |
349 renderer_->SetSink(NULL); | 348 source_->SetSink(nullptr); |
350 } | 349 } |
351 } | 350 } |
352 void OnData(const void* audio_data, | 351 void OnData(const void* audio_data, |
353 int bits_per_sample, | 352 int bits_per_sample, |
354 int sample_rate, | 353 int sample_rate, |
355 size_t number_of_channels, | 354 size_t number_of_channels, |
356 size_t number_of_frames) override {} | 355 size_t number_of_frames) override {} |
357 void OnClose() override { renderer_ = NULL; } | 356 void OnClose() override { source_ = nullptr; } |
358 AudioRenderer* renderer() const { return renderer_; } | 357 AudioSource* source() const { return source_; } |
359 | 358 |
360 private: | 359 private: |
361 AudioRenderer* renderer_; | 360 AudioSource* source_; |
362 }; | 361 }; |
363 | 362 |
364 bool SetRecvCodecs(const std::vector<AudioCodec>& codecs) { | 363 bool SetRecvCodecs(const std::vector<AudioCodec>& codecs) { |
365 if (fail_set_recv_codecs()) { | 364 if (fail_set_recv_codecs()) { |
366 // Fake the failure in SetRecvCodecs. | 365 // Fake the failure in SetRecvCodecs. |
367 return false; | 366 return false; |
368 } | 367 } |
369 recv_codecs_ = codecs; | 368 recv_codecs_ = codecs; |
370 return true; | 369 return true; |
371 } | 370 } |
372 bool SetSendCodecs(const std::vector<AudioCodec>& codecs) { | 371 bool SetSendCodecs(const std::vector<AudioCodec>& codecs) { |
373 if (fail_set_send_codecs()) { | 372 if (fail_set_send_codecs()) { |
374 // Fake the failure in SetSendCodecs. | 373 // Fake the failure in SetSendCodecs. |
375 return false; | 374 return false; |
376 } | 375 } |
377 send_codecs_ = codecs; | 376 send_codecs_ = codecs; |
378 return true; | 377 return true; |
379 } | 378 } |
380 bool SetMaxSendBandwidth(int bps) { return true; } | 379 bool SetMaxSendBandwidth(int bps) { return true; } |
381 bool SetOptions(const AudioOptions& options) { | 380 bool SetOptions(const AudioOptions& options) { |
382 // Does a "merge" of current options and set options. | 381 // Does a "merge" of current options and set options. |
383 options_.SetAll(options); | 382 options_.SetAll(options); |
384 return true; | 383 return true; |
385 } | 384 } |
386 bool SetLocalRenderer(uint32_t ssrc, AudioRenderer* renderer) { | 385 bool SetLocalSource(uint32_t ssrc, AudioSource* source) { |
387 auto it = local_renderers_.find(ssrc); | 386 auto it = local_sinks_.find(ssrc); |
388 if (renderer) { | 387 if (source) { |
389 if (it != local_renderers_.end()) { | 388 if (it != local_sinks_.end()) { |
390 ASSERT(it->second->renderer() == renderer); | 389 ASSERT(it->second->source() == source); |
391 } else { | 390 } else { |
392 local_renderers_.insert(std::make_pair( | 391 local_sinks_.insert( |
393 ssrc, new VoiceChannelAudioSink(renderer))); | 392 std::make_pair(ssrc, new VoiceChannelAudioSink(source))); |
394 } | 393 } |
395 } else { | 394 } else { |
396 if (it != local_renderers_.end()) { | 395 if (it != local_sinks_.end()) { |
397 delete it->second; | 396 delete it->second; |
398 local_renderers_.erase(it); | 397 local_sinks_.erase(it); |
399 } | 398 } |
400 } | 399 } |
401 return true; | 400 return true; |
402 } | 401 } |
403 | 402 |
404 FakeVoiceEngine* engine_; | 403 FakeVoiceEngine* engine_; |
405 std::vector<AudioCodec> recv_codecs_; | 404 std::vector<AudioCodec> recv_codecs_; |
406 std::vector<AudioCodec> send_codecs_; | 405 std::vector<AudioCodec> send_codecs_; |
407 std::map<uint32_t, double> output_scalings_; | 406 std::map<uint32_t, double> output_scalings_; |
408 std::vector<DtmfInfo> dtmf_info_queue_; | 407 std::vector<DtmfInfo> dtmf_info_queue_; |
409 int time_since_last_typing_; | 408 int time_since_last_typing_; |
410 AudioOptions options_; | 409 AudioOptions options_; |
411 std::map<uint32_t, VoiceChannelAudioSink*> local_renderers_; | 410 std::map<uint32_t, VoiceChannelAudioSink*> local_sinks_; |
412 std::unique_ptr<webrtc::AudioSinkInterface> sink_; | 411 std::unique_ptr<webrtc::AudioSinkInterface> sink_; |
413 }; | 412 }; |
414 | 413 |
415 // A helper function to compare the FakeVoiceMediaChannel::DtmfInfo. | 414 // A helper function to compare the FakeVoiceMediaChannel::DtmfInfo. |
416 inline bool CompareDtmfInfo(const FakeVoiceMediaChannel::DtmfInfo& info, | 415 inline bool CompareDtmfInfo(const FakeVoiceMediaChannel::DtmfInfo& info, |
417 uint32_t ssrc, | 416 uint32_t ssrc, |
418 int event_code, | 417 int event_code, |
419 int duration) { | 418 int duration) { |
420 return (info.duration == duration && info.event_code == event_code && | 419 return (info.duration == duration && info.event_code == event_code && |
421 info.ssrc == ssrc); | 420 info.ssrc == ssrc); |
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
869 | 868 |
870 private: | 869 private: |
871 std::vector<FakeDataMediaChannel*> channels_; | 870 std::vector<FakeDataMediaChannel*> channels_; |
872 std::vector<DataCodec> data_codecs_; | 871 std::vector<DataCodec> data_codecs_; |
873 DataChannelType last_channel_type_; | 872 DataChannelType last_channel_type_; |
874 }; | 873 }; |
875 | 874 |
876 } // namespace cricket | 875 } // namespace cricket |
877 | 876 |
878 #endif // WEBRTC_MEDIA_BASE_FAKEMEDIAENGINE_H_ | 877 #endif // WEBRTC_MEDIA_BASE_FAKEMEDIAENGINE_H_ |
OLD | NEW |