audio_transport_impl.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
  3. *
  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
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #ifndef AUDIO_AUDIO_TRANSPORT_IMPL_H_
  11. #define AUDIO_AUDIO_TRANSPORT_IMPL_H_
  12. #include <vector>
  13. #include "api/audio/audio_mixer.h"
  14. #include "api/scoped_refptr.h"
  15. #include "common_audio/resampler/include/push_resampler.h"
  16. #include "modules/audio_device/include/audio_device.h"
  17. #include "modules/audio_processing/include/audio_processing.h"
  18. #include "modules/audio_processing/typing_detection.h"
  19. #include "rtc_base/constructor_magic.h"
  20. #include "rtc_base/critical_section.h"
  21. #include "rtc_base/thread_annotations.h"
  22. namespace webrtc {
  23. class AudioSender;
  24. class AudioTransportImpl : public AudioTransport {
  25. public:
  26. AudioTransportImpl(AudioMixer* mixer, AudioProcessing* audio_processing);
  27. ~AudioTransportImpl() override;
  28. int32_t RecordedDataIsAvailable(const void* audioSamples,
  29. const size_t nSamples,
  30. const size_t nBytesPerSample,
  31. const size_t nChannels,
  32. const uint32_t samplesPerSec,
  33. const uint32_t totalDelayMS,
  34. const int32_t clockDrift,
  35. const uint32_t currentMicLevel,
  36. const bool keyPressed,
  37. uint32_t& newMicLevel) override;
  38. int32_t NeedMorePlayData(const size_t nSamples,
  39. const size_t nBytesPerSample,
  40. const size_t nChannels,
  41. const uint32_t samplesPerSec,
  42. void* audioSamples,
  43. size_t& nSamplesOut,
  44. int64_t* elapsed_time_ms,
  45. int64_t* ntp_time_ms) override;
  46. void PullRenderData(int bits_per_sample,
  47. int sample_rate,
  48. size_t number_of_channels,
  49. size_t number_of_frames,
  50. void* audio_data,
  51. int64_t* elapsed_time_ms,
  52. int64_t* ntp_time_ms) override;
  53. void UpdateAudioSenders(std::vector<AudioSender*> senders,
  54. int send_sample_rate_hz,
  55. size_t send_num_channels);
  56. void SetStereoChannelSwapping(bool enable);
  57. bool typing_noise_detected() const;
  58. private:
  59. // Shared.
  60. AudioProcessing* audio_processing_ = nullptr;
  61. // Capture side.
  62. rtc::CriticalSection capture_lock_;
  63. std::vector<AudioSender*> audio_senders_ RTC_GUARDED_BY(capture_lock_);
  64. int send_sample_rate_hz_ RTC_GUARDED_BY(capture_lock_) = 8000;
  65. size_t send_num_channels_ RTC_GUARDED_BY(capture_lock_) = 1;
  66. bool typing_noise_detected_ RTC_GUARDED_BY(capture_lock_) = false;
  67. bool swap_stereo_channels_ RTC_GUARDED_BY(capture_lock_) = false;
  68. PushResampler<int16_t> capture_resampler_;
  69. TypingDetection typing_detection_;
  70. // Render side.
  71. rtc::scoped_refptr<AudioMixer> mixer_;
  72. AudioFrame mixed_frame_;
  73. // Converts mixed audio to the audio device output rate.
  74. PushResampler<int16_t> render_resampler_;
  75. RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(AudioTransportImpl);
  76. };
  77. } // namespace webrtc
  78. #endif // AUDIO_AUDIO_TRANSPORT_IMPL_H_