recorder.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. #ifndef AV_RECORDER_H
  2. #define AV_RECORDER_H
  3. /**
  4. * AV录制器模块
  5. *
  6. * 这个模块提供了完整的音视频录制功能,基于AV模块的现有组件构建。
  7. * 主要特性:
  8. * - 音频录制:支持多设备采集、混音、实时编码
  9. * - 视频录制:支持屏幕录制、窗口采集、摄像头录制
  10. * - 音视频同步:提供精确的音视频同步机制
  11. * - 模块化设计:可独立使用音频或视频录制器
  12. * - 高性能:多线程处理,支持硬件加速
  13. *
  14. * 使用示例:
  15. *
  16. * // 音频录制
  17. * auto audioRecorder = RecorderFactoryImpl::createAudioRecorder();
  18. * AudioRecorderParams audioParams;
  19. * audioParams.outputPath = "output.mp4";
  20. * audioParams.sampleRate = 44100;
  21. * audioParams.channels = 2;
  22. * audioRecorder->initialize(audioParams);
  23. * audioRecorder->startRecording();
  24. *
  25. * // 视频录制
  26. * auto videoRecorder = RecorderFactoryImpl::createVideoRecorder();
  27. * VideoRecorderParams videoParams;
  28. * videoParams.outputPath = "output.mp4";
  29. * videoParams.width = 1920;
  30. * videoParams.height = 1080;
  31. * videoParams.frameRate = 30;
  32. * videoRecorder->initialize(videoParams);
  33. * videoRecorder->startRecording();
  34. *
  35. * // 音视频同步录制
  36. * auto avRecorder = RecorderFactoryImpl::createAVRecorder();
  37. * AVRecorderParams avParams;
  38. * avParams.outputPath = "output.mp4";
  39. * avParams.enableAudio = true;
  40. * avParams.enableVideo = true;
  41. * avParams.enableSync = true;
  42. * avRecorder->initialize(avParams);
  43. * avRecorder->startRecording();
  44. */
  45. // 核心接口
  46. #include "recorder_abstract_recorder.h"
  47. // 具体实现
  48. #include "recorder_audio_recorder.h"
  49. #include "recorder_video_recorder.h"
  50. #include "recorder_av_recorder.h"
  51. namespace av {
  52. namespace recorder {
  53. /**
  54. * 录制器模块版本信息
  55. */
  56. struct RecorderVersion {
  57. static constexpr int MAJOR = 1;
  58. static constexpr int MINOR = 0;
  59. static constexpr int PATCH = 0;
  60. static std::string toString() {
  61. return std::to_string(MAJOR) + "." +
  62. std::to_string(MINOR) + "." +
  63. std::to_string(PATCH);
  64. }
  65. };
  66. /**
  67. * 录制器模块初始化
  68. */
  69. class RecorderModule {
  70. public:
  71. /**
  72. * 初始化录制器模块
  73. */
  74. static ErrorCode initialize();
  75. /**
  76. * 清理录制器模块
  77. */
  78. static void cleanup();
  79. /**
  80. * 获取模块版本
  81. */
  82. static std::string getVersion() {
  83. return RecorderVersion::toString();
  84. }
  85. /**
  86. * 检查模块是否已初始化
  87. */
  88. static bool isInitialized();
  89. /**
  90. * 获取支持的录制格式
  91. */
  92. static std::vector<std::string> getSupportedFormats();
  93. /**
  94. * 获取支持的音频编码器
  95. */
  96. static std::vector<std::string> getSupportedAudioCodecs();
  97. /**
  98. * 获取支持的视频编码器
  99. */
  100. static std::vector<std::string> getSupportedVideoCodecs();
  101. private:
  102. static bool initialized_;
  103. };
  104. /**
  105. * 便利函数
  106. */
  107. namespace utils {
  108. /**
  109. * 创建音频录制器的便利函数
  110. */
  111. inline std::unique_ptr<AudioRecorder> createAudioRecorder() {
  112. return RecorderFactoryImpl::createAudioRecorder();
  113. }
  114. /**
  115. * 创建视频录制器的便利函数
  116. */
  117. inline std::unique_ptr<VideoRecorder> createVideoRecorder() {
  118. return RecorderFactoryImpl::createVideoRecorder();
  119. }
  120. /**
  121. * 创建音视频录制器的便利函数
  122. */
  123. inline std::unique_ptr<AVRecorder> createAVRecorder() {
  124. return RecorderFactoryImpl::createAVRecorder();
  125. }
  126. /**
  127. * 获取默认音频参数
  128. */
  129. AudioRecorderParams getDefaultAudioParams();
  130. /**
  131. * 获取默认视频参数
  132. */
  133. VideoRecorderParams getDefaultVideoParams();
  134. /**
  135. * 获取默认音视频参数
  136. */
  137. AVRecorderParams getDefaultAVParams();
  138. /**
  139. * 检查输出路径是否有效
  140. */
  141. bool isValidOutputPath(const std::string& path);
  142. /**
  143. * 获取推荐的录制参数(基于系统性能)
  144. */
  145. VideoRecorderParams getRecommendedVideoParams();
  146. } // namespace utils
  147. } // namespace recorder
  148. } // namespace av
  149. #endif // AV_RECORDER_H