Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

50 řádky
1.3KB

  1. /*
  2. * Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
  3. *
  4. * This file is part of ZLMediaKit(https://github.com/ZLMediaKit/ZLMediaKit).
  5. *
  6. * Use of this source code is governed by MIT license that can be found in the
  7. * LICENSE file in the root of the source tree. All contributing project authors
  8. * may be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #ifndef SDLAUDIOMIXER_SDLAUDIODEVICE_H_
  11. #define SDLAUDIOMIXER_SDLAUDIODEVICE_H_
  12. #include <mutex>
  13. #include <memory>
  14. #include <stdexcept>
  15. #include <unordered_set>
  16. #define DEFAULT_SAMPLERATE 48000
  17. #define DEFAULT_FORMAT AUDIO_S16
  18. #define DEFAULT_CHANNEL 2
  19. #define DEFAULT_SAMPLES 2048
  20. class AudioSRC;
  21. //该对象主要实现sdl混音与播放
  22. class SDLAudioDevice : public std::enable_shared_from_this<SDLAudioDevice>{
  23. public:
  24. using Ptr = std::shared_ptr<SDLAudioDevice>;
  25. ~SDLAudioDevice();
  26. static SDLAudioDevice &Instance();
  27. void addChannel(AudioSRC *chn);
  28. void delChannel(AudioSRC *chn);
  29. private:
  30. SDLAudioDevice();
  31. void onReqPCM(char *stream, int len);
  32. private:
  33. std::shared_ptr<char> _play_buf;
  34. SDL_AudioSpec _audio_config;
  35. std::recursive_mutex _channel_mtx;
  36. std::unordered_set<AudioSRC *> _channels;
  37. };
  38. #endif /* SDLAUDIOMIXER_SDLAUDIODEVICE_H_ */