AudioTrackSinkAdapter.h 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #pragma once
  2. #include <mutex>
  3. #include <api/audio/audio_frame.h>
  4. #include <api/media_stream_interface.h>
  5. #include <common_audio/resampler/include/push_resampler.h>
  6. #include <common_audio/ring_buffer.h>
  7. namespace unity
  8. {
  9. namespace webrtc
  10. {
  11. using namespace ::webrtc;
  12. class AudioTrackSinkAdapter : public webrtc::AudioTrackSinkInterface
  13. {
  14. public:
  15. AudioTrackSinkAdapter();
  16. ~AudioTrackSinkAdapter() override;
  17. void OnData(
  18. const void* audio_data,
  19. int bits_per_sample,
  20. int sample_rate,
  21. size_t number_of_channels,
  22. size_t number_of_frames) override;
  23. void ProcessAudio(float* data, size_t length, size_t channels, int32_t sampleRate);
  24. private:
  25. void ResizeBuffer(size_t channels, int32_t sampleRate, size_t length);
  26. AudioFrame _frame;
  27. std::mutex _mutex;
  28. RingBuffer* _buffer;
  29. std::vector<int16_t> _bufferIn;
  30. PushResampler<int16_t> _resampler;
  31. };
  32. } // end namespace webrtc
  33. } // end namespace unity