audio_frame_observer.cpp 643 B

123456789101112131415161718192021222324252627
  1. #include "pch.h"
  2. #include <mutex>
  3. #include "../common/comm.h"
  4. #include "audio_frame_observer.h"
  5. void AudioFrameObserver::SetCallback(
  6. AudioFrameReadyCallback callback) {
  7. std::lock_guard<std::mutex> lock(mutex_);
  8. callback_ = std::move(callback);
  9. }
  10. void AudioFrameObserver::OnData(const void* audio_data,
  11. int bits_per_sample,
  12. int sample_rate,
  13. size_t number_of_channels,
  14. size_t number_of_frames) {
  15. if (!callback_) {
  16. return;
  17. }
  18. std::lock_guard<std::mutex> lock(mutex_);
  19. if (!callback_)
  20. return;
  21. callback_(audio_data, bits_per_sample, sample_rate,
  22. static_cast<int>(number_of_channels),
  23. static_cast<int>(number_of_frames));
  24. }