miccapture.h 941 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #ifndef MICCAPTURE_H
  2. #define MICCAPTURE_H
  3. #include "thread.h"
  4. #include "types.h"
  5. #include "alsa/asoundlib.h"
  6. class MicCapture : public Thread
  7. {
  8. public:
  9. virtual ~MicCapture();
  10. static MicCapture *instance();
  11. void stopRecordSound()
  12. {
  13. mStop = true;
  14. }
  15. void resumeRecordSound()
  16. {
  17. mStop = false;
  18. }
  19. int initDevice();
  20. void Release();
  21. int recSound(byte *data, uint len);
  22. protected:
  23. virtual void run();
  24. private:
  25. MicCapture();
  26. int readMicData(Buffer &);
  27. uint timeStamp();
  28. int xrunRecover(snd_pcm_t *handle, int err);
  29. private:
  30. static MicCapture *mInstance;
  31. snd_pcm_t *mCaptureHandle;
  32. pthread_mutex_t mDeviceMutex; //设备使用互斥锁
  33. char mDevice[256];
  34. int mBufferSize;
  35. int mFrameSize;
  36. MediaParam mParam;
  37. Buffer mData;
  38. unsigned char mAudio[2048];
  39. int mlength ;
  40. bool mStop;
  41. };
  42. #endif // MICCAPTURE_H