audio_transport_impl.h 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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/synchronization/mutex.h"
  20. #include "rtc_base/thread_annotations.h"
  21. namespace webrtc {
  22. class AudioSender;
  23. class AudioTransportImpl : public AudioTransport {
  24. public:
  25. AudioTransportImpl(AudioMixer* mixer, AudioProcessing* audio_processing);
  26. AudioTransportImpl() = delete;
  27. AudioTransportImpl(const AudioTransportImpl&) = delete;
  28. AudioTransportImpl& operator=(const AudioTransportImpl&) = delete;
  29. ~AudioTransportImpl() override;
  30. int32_t RecordedDataIsAvailable(const void* audioSamples,
  31. const size_t nSamples,
  32. const size_t nBytesPerSample,
  33. const size_t nChannels,
  34. const uint32_t samplesPerSec,
  35. const uint32_t totalDelayMS,
  36. const int32_t clockDrift,
  37. const uint32_t currentMicLevel,
  38. const bool keyPressed,
  39. uint32_t& newMicLevel) override;
  40. int32_t NeedMorePlayData(const size_t nSamples,
  41. const size_t nBytesPerSample,
  42. const size_t nChannels,
  43. const uint32_t samplesPerSec,
  44. void* audioSamples,
  45. size_t& nSamplesOut,
  46. int64_t* elapsed_time_ms,
  47. int64_t* ntp_time_ms) override;
  48. void PullRenderData(int bits_per_sample,
  49. int sample_rate,
  50. size_t number_of_channels,
  51. size_t number_of_frames,
  52. void* audio_data,
  53. int64_t* elapsed_time_ms,
  54. int64_t* ntp_time_ms) override;
  55. void UpdateAudioSenders(std::vector<AudioSender*> senders,
  56. int send_sample_rate_hz,
  57. size_t send_num_channels);
  58. void SetStereoChannelSwapping(bool enable);
  59. bool typing_noise_detected() const;
  60. private:
  61. // Shared.
  62. AudioProcessing* audio_processing_ = nullptr;
  63. // Capture side.
  64. mutable Mutex capture_lock_;
  65. std::vector<AudioSender*> audio_senders_ RTC_GUARDED_BY(capture_lock_);
  66. int send_sample_rate_hz_ RTC_GUARDED_BY(capture_lock_) = 8000;
  67. size_t send_num_channels_ RTC_GUARDED_BY(capture_lock_) = 1;
  68. bool typing_noise_detected_ RTC_GUARDED_BY(capture_lock_) = false;
  69. bool swap_stereo_channels_ RTC_GUARDED_BY(capture_lock_) = false;
  70. PushResampler<int16_t> capture_resampler_;
  71. TypingDetection typing_detection_;
  72. // Render side.
  73. rtc::scoped_refptr<AudioMixer> mixer_;
  74. AudioFrame mixed_frame_;
  75. // Converts mixed audio to the audio device output rate.
  76. PushResampler<int16_t> render_resampler_;
  77. };
  78. } // namespace webrtc
  79. #endif // AUDIO_AUDIO_TRANSPORT_IMPL_H_