UnityAudioTrackSource.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #pragma once
  2. #include <mutex>
  3. #include <api/media_stream_interface.h>
  4. #include <pc/local_audio_source.h>
  5. namespace unity
  6. {
  7. namespace webrtc
  8. {
  9. using namespace ::webrtc;
  10. class UnityAudioTrackSource : public LocalAudioSource
  11. {
  12. public:
  13. static rtc::scoped_refptr<UnityAudioTrackSource> Create();
  14. static rtc::scoped_refptr<UnityAudioTrackSource> Create(const cricket::AudioOptions& audio_options);
  15. const cricket::AudioOptions options() const override { return _options; }
  16. void AddSink(AudioTrackSinkInterface* sink) override;
  17. void RemoveSink(AudioTrackSinkInterface* sink) override;
  18. void PushAudioData(const float* pAudioData, int nSampleRate, size_t nNumChannels, size_t nNumFrames);
  19. protected:
  20. UnityAudioTrackSource();
  21. UnityAudioTrackSource(const cricket::AudioOptions& audio_options);
  22. ~UnityAudioTrackSource() override;
  23. private:
  24. std::vector<int16_t> _convertedAudioData;
  25. std::vector<AudioTrackSinkInterface*> _arrSink;
  26. std::mutex _mutex;
  27. cricket::AudioOptions _options;
  28. int _sampleRate = 0;
  29. size_t _numChannels = 0;
  30. size_t _numFrames = 0;
  31. };
  32. } // end namespace webrtc
  33. } // end namespace unity