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 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 } | 246 } |
247 | 247 |
248 virtual bool SetRecvParameters(const AudioRecvParameters& params) { | 248 virtual bool SetRecvParameters(const AudioRecvParameters& params) { |
249 return (SetRecvCodecs(params.codecs) && | 249 return (SetRecvCodecs(params.codecs) && |
250 SetRecvRtpHeaderExtensions(params.extensions)); | 250 SetRecvRtpHeaderExtensions(params.extensions)); |
251 } | 251 } |
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 void SetSend(bool send) { set_sending(send); } |
257 return set_sending(flag != SEND_NOTHING); | |
258 } | |
259 virtual bool SetAudioSend(uint32_t ssrc, | 257 virtual bool SetAudioSend(uint32_t ssrc, |
260 bool enable, | 258 bool enable, |
261 const AudioOptions* options, | 259 const AudioOptions* options, |
262 AudioRenderer* renderer) { | 260 AudioSource* source) { |
263 if (!SetLocalRenderer(ssrc, renderer)) { | 261 if (!SetLocalSource(ssrc, source)) { |
264 return false; | 262 return false; |
265 } | 263 } |
266 if (!RtpHelper<VoiceMediaChannel>::MuteStream(ssrc, !enable)) { | 264 if (!RtpHelper<VoiceMediaChannel>::MuteStream(ssrc, !enable)) { |
267 return false; | 265 return false; |
268 } | 266 } |
269 if (enable && options) { | 267 if (enable && options) { |
270 return SetOptions(*options); | 268 return SetOptions(*options); |
271 } | 269 } |
272 return true; | 270 return true; |
273 } | 271 } |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 | 329 |
332 virtual bool GetStats(VoiceMediaInfo* info) { return false; } | 330 virtual bool GetStats(VoiceMediaInfo* info) { return false; } |
333 | 331 |
334 virtual void SetRawAudioSink( | 332 virtual void SetRawAudioSink( |
335 uint32_t ssrc, | 333 uint32_t ssrc, |
336 std::unique_ptr<webrtc::AudioSinkInterface> sink) { | 334 std::unique_ptr<webrtc::AudioSinkInterface> sink) { |
337 sink_ = std::move(sink); | 335 sink_ = std::move(sink); |
338 } | 336 } |
339 | 337 |
340 private: | 338 private: |
341 class VoiceChannelAudioSink : public AudioRenderer::Sink { | 339 class VoiceChannelAudioSink : public AudioSource::Sink { |
342 public: | 340 public: |
343 explicit VoiceChannelAudioSink(AudioRenderer* renderer) | 341 explicit VoiceChannelAudioSink(AudioSource* source) : source_(source) { |
344 : renderer_(renderer) { | 342 source_->SetSink(this); |
345 renderer_->SetSink(this); | |
346 } | 343 } |
347 virtual ~VoiceChannelAudioSink() { | 344 virtual ~VoiceChannelAudioSink() { |
348 if (renderer_) { | 345 if (source_) { |
349 renderer_->SetSink(NULL); | 346 source_->SetSink(nullptr); |
350 } | 347 } |
351 } | 348 } |
352 void OnData(const void* audio_data, | 349 void OnData(const void* audio_data, |
353 int bits_per_sample, | 350 int bits_per_sample, |
354 int sample_rate, | 351 int sample_rate, |
355 size_t number_of_channels, | 352 size_t number_of_channels, |
356 size_t number_of_frames) override {} | 353 size_t number_of_frames) override {} |
357 void OnClose() override { renderer_ = NULL; } | 354 void OnClose() override { source_ = nullptr; } |
358 AudioRenderer* renderer() const { return renderer_; } | 355 AudioSource* source() const { return source_; } |
359 | 356 |
360 private: | 357 private: |
361 AudioRenderer* renderer_; | 358 AudioSource* source_; |
362 }; | 359 }; |
363 | 360 |
364 bool SetRecvCodecs(const std::vector<AudioCodec>& codecs) { | 361 bool SetRecvCodecs(const std::vector<AudioCodec>& codecs) { |
365 if (fail_set_recv_codecs()) { | 362 if (fail_set_recv_codecs()) { |
366 // Fake the failure in SetRecvCodecs. | 363 // Fake the failure in SetRecvCodecs. |
367 return false; | 364 return false; |
368 } | 365 } |
369 recv_codecs_ = codecs; | 366 recv_codecs_ = codecs; |
370 return true; | 367 return true; |
371 } | 368 } |
372 bool SetSendCodecs(const std::vector<AudioCodec>& codecs) { | 369 bool SetSendCodecs(const std::vector<AudioCodec>& codecs) { |
373 if (fail_set_send_codecs()) { | 370 if (fail_set_send_codecs()) { |
374 // Fake the failure in SetSendCodecs. | 371 // Fake the failure in SetSendCodecs. |
375 return false; | 372 return false; |
376 } | 373 } |
377 send_codecs_ = codecs; | 374 send_codecs_ = codecs; |
378 return true; | 375 return true; |
379 } | 376 } |
380 bool SetMaxSendBandwidth(int bps) { return true; } | 377 bool SetMaxSendBandwidth(int bps) { return true; } |
381 bool SetOptions(const AudioOptions& options) { | 378 bool SetOptions(const AudioOptions& options) { |
382 // Does a "merge" of current options and set options. | 379 // Does a "merge" of current options and set options. |
383 options_.SetAll(options); | 380 options_.SetAll(options); |
384 return true; | 381 return true; |
385 } | 382 } |
386 bool SetLocalRenderer(uint32_t ssrc, AudioRenderer* renderer) { | 383 bool SetLocalSource(uint32_t ssrc, AudioSource* source) { |
387 auto it = local_renderers_.find(ssrc); | 384 auto it = local_sinks_.find(ssrc); |
388 if (renderer) { | 385 if (source) { |
389 if (it != local_renderers_.end()) { | 386 if (it != local_sinks_.end()) { |
390 ASSERT(it->second->renderer() == renderer); | 387 ASSERT(it->second->source() == source); |
391 } else { | 388 } else { |
392 local_renderers_.insert(std::make_pair( | 389 local_sinks_.insert( |
393 ssrc, new VoiceChannelAudioSink(renderer))); | 390 std::make_pair(ssrc, new VoiceChannelAudioSink(source))); |
394 } | 391 } |
395 } else { | 392 } else { |
396 if (it != local_renderers_.end()) { | 393 if (it != local_sinks_.end()) { |
397 delete it->second; | 394 delete it->second; |
398 local_renderers_.erase(it); | 395 local_sinks_.erase(it); |
399 } | 396 } |
400 } | 397 } |
401 return true; | 398 return true; |
402 } | 399 } |
403 | 400 |
404 FakeVoiceEngine* engine_; | 401 FakeVoiceEngine* engine_; |
405 std::vector<AudioCodec> recv_codecs_; | 402 std::vector<AudioCodec> recv_codecs_; |
406 std::vector<AudioCodec> send_codecs_; | 403 std::vector<AudioCodec> send_codecs_; |
407 std::map<uint32_t, double> output_scalings_; | 404 std::map<uint32_t, double> output_scalings_; |
408 std::vector<DtmfInfo> dtmf_info_queue_; | 405 std::vector<DtmfInfo> dtmf_info_queue_; |
409 int time_since_last_typing_; | 406 int time_since_last_typing_; |
410 AudioOptions options_; | 407 AudioOptions options_; |
411 std::map<uint32_t, VoiceChannelAudioSink*> local_renderers_; | 408 std::map<uint32_t, VoiceChannelAudioSink*> local_sinks_; |
412 std::unique_ptr<webrtc::AudioSinkInterface> sink_; | 409 std::unique_ptr<webrtc::AudioSinkInterface> sink_; |
413 }; | 410 }; |
414 | 411 |
415 // A helper function to compare the FakeVoiceMediaChannel::DtmfInfo. | 412 // A helper function to compare the FakeVoiceMediaChannel::DtmfInfo. |
416 inline bool CompareDtmfInfo(const FakeVoiceMediaChannel::DtmfInfo& info, | 413 inline bool CompareDtmfInfo(const FakeVoiceMediaChannel::DtmfInfo& info, |
417 uint32_t ssrc, | 414 uint32_t ssrc, |
418 int event_code, | 415 int event_code, |
419 int duration) { | 416 int duration) { |
420 return (info.duration == duration && info.event_code == event_code && | 417 return (info.duration == duration && info.event_code == event_code && |
421 info.ssrc == ssrc); | 418 info.ssrc == ssrc); |
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
869 | 866 |
870 private: | 867 private: |
871 std::vector<FakeDataMediaChannel*> channels_; | 868 std::vector<FakeDataMediaChannel*> channels_; |
872 std::vector<DataCodec> data_codecs_; | 869 std::vector<DataCodec> data_codecs_; |
873 DataChannelType last_channel_type_; | 870 DataChannelType last_channel_type_; |
874 }; | 871 }; |
875 | 872 |
876 } // namespace cricket | 873 } // namespace cricket |
877 | 874 |
878 #endif // WEBRTC_MEDIA_BASE_FAKEMEDIAENGINE_H_ | 875 #endif // WEBRTC_MEDIA_BASE_FAKEMEDIAENGINE_H_ |
OLD | NEW |