pcm_player.h 976 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #ifndef JNI_AUDIO_PCMPLAYER_H_
  2. #define JNI_AUDIO_PCMPLAYER_H_
  3. #include <stdio.h>
  4. #include <system/Thread.h>
  5. #include "audio_parameter.h"
  6. namespace base {
  7. class PCMPlayer {
  8. public:
  9. PCMPlayer(const AudioParameter& parameter);
  10. virtual ~PCMPlayer();
  11. enum class Status {
  12. Disabled,
  13. Normal,
  14. Paused,
  15. };
  16. int AddSamples(const char* data, ::size_t size);
  17. int Pause();
  18. int Resume();
  19. void Wait();
  20. void Reset();
  21. void Disable();
  22. int Enable();
  23. /**
  24. * vol 0.0 ~ 1.0
  25. */
  26. void SetVolume(float vol);
  27. void SetVolume2(int vol);
  28. bool GetMute();
  29. void SetMute(bool mute);
  30. private:
  31. void ResetWithoutLock();
  32. void SetMuteWithoutLock(bool mute);
  33. int DeviceEnable();
  34. int DevicePlaySamples(const char* data, size_t size);
  35. int DeviceWaitForPlayToEnd();
  36. int DeviceDisable();
  37. private:
  38. Mutex mutex_;
  39. int volume_;
  40. bool mute_;
  41. Status status_;
  42. AudioParameter* parameter_;
  43. };
  44. } /* namespace voip */
  45. #endif /* JNI_AUDIO_PCMPLAYER_H_ */