mediadecode.h 962 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #ifndef MEDIADECODE_H
  2. #define MEDIADECODE_H
  3. #include "thread.h"
  4. #include "types.h"
  5. #include <list>
  6. #include <vector>
  7. #include <semaphore.h>
  8. #include "alsa/asoundlib.h"
  9. //using namespace std;
  10. class MediaDecode : public Thread
  11. {
  12. public:
  13. MediaDecode(const char *device = "default");
  14. virtual ~MediaDecode();
  15. bool initDevice();
  16. void Release();
  17. //设置音频参数
  18. void setMediaParam(const uint rate, const uint bits, const uint channels);
  19. int playSound(byte *data, uint len);
  20. // int playSound(Buffer &data);
  21. void stopPlaySound()
  22. {
  23. mStop = true;
  24. }
  25. void resumePlaySound()
  26. {
  27. mStop = false;
  28. }
  29. protected:
  30. virtual void run(); //线程执行函数
  31. private:
  32. int xrunRecover(snd_pcm_t *handle, int err);
  33. private:
  34. bool mStop;
  35. char *mPDevice;
  36. snd_pcm_t *mPlaybackHandle; //PCM设备句柄pcm.h
  37. MediaParam mParam;
  38. };
  39. #endif // MEDIADECODE_H