BaseRecordThread.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #ifndef _BASERECORDTHREAD_H_
  2. #define _BASERECORDTHREAD_H_
  3. #include "GlobalVariable.h"
  4. #include "spdlog/spdlog.h"
  5. class QDateTime;
  6. struct AudioSrcData;
  7. class BaseRecordThread
  8. {
  9. public:
  10. BaseRecordThread(RecordThreadInfo_t& threadInfo);
  11. virtual ~BaseRecordThread();
  12. /* 线程任务函数,子类需要实现 */
  13. virtual void threadTask();
  14. /* 停止线程 */
  15. virtual void stopThread();
  16. /* 获取录音通道信息 */
  17. const RecordThreadInfo_t& getThreadInfo();
  18. /* 设置数据 */
  19. virtual bool setData(const AudioSrcData& srcData) = 0;
  20. protected:
  21. /* 任务函数 */
  22. virtual void task() = 0;
  23. /* 初始化数据 */
  24. virtual bool initData() = 0;
  25. /* 清除数据*/
  26. virtual void clearData() = 0;
  27. /* 根据当前时间和数据大小向前推算时间 */
  28. QDateTime previTime(QDateTime& currentTime, int64_t dataSize);
  29. /*根据当前时间和数据大小向后推算时间 */
  30. QDateTime nextTime(QDateTime& currentTime, int64_t dataSize);
  31. /* 计算出到下一个整点秒需要去掉多少个字节 */
  32. int32_t calculateOffsetToNextSecond(QDateTime& currentTime);
  33. protected:
  34. std::shared_ptr<spdlog::logger> m_logger = nullptr; /* 日志记录器 */
  35. RecordThreadInfo_t m_threadInfo; /* 线程信息 */
  36. std::atomic_bool m_isRunning = false; /* 线程运行标志 */
  37. std::string m_logBase; /* 日志基础信息 */
  38. int32_t m_oneSecondSize = 0; /* 每秒钟的音频数据大小 */
  39. /* 音频相关的默认参数 */
  40. int32_t m_sampleRate = 44100; /* 采样率 */
  41. uint16_t m_numChannels = 2; /* 声道数 */
  42. uint16_t m_bitsPerSample = 16; /* 每个采样点的位数 */
  43. };
  44. #endif // _BASERECORDTHREAD_H_