audio_recorder.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #ifndef __AUDIO_RECORDER_H__
  2. #define __AUDIO_RECORDER_H__
  3. #include "capturer/audio/audio_capturer.h"
  4. #include "encoder/audio_mixer.h"
  5. #include "muxer/av_muxer.h"
  6. class AudioRecorder
  7. {
  8. public:
  9. AudioRecorder();
  10. ~AudioRecorder();
  11. struct Info
  12. {
  13. AudioMixer* mixer = nullptr;
  14. AvMuxer* muxer = nullptr;
  15. bool* isRecord = nullptr;
  16. int mixIndex;
  17. int* streamIndex = nullptr;
  18. };
  19. bool Open(const std::vector<AudioCapturer::Type>& deviceTypes,
  20. Encoder<MediaType::AUDIO>::Param& param,
  21. const uint32_t sampleRate = AUDIO_SAMPLE_RATE,
  22. const uint32_t channels = AUDIO_CHANNEL,
  23. const uint32_t bitsPerSample = 32,
  24. const AVSampleFormat format = AUDIO_FMT);
  25. bool LoadMuxer(AvMuxer& muxer);
  26. bool StartRecord();
  27. void StopRecord();
  28. void Close();
  29. auto GetCaptureInfo(int mixIndex) { return _mixer.GetInputInfo(mixIndex); }
  30. void SetVolumeScale(float scale, int mixIndex);
  31. private:
  32. std::vector<IAudioCapturer*> m_audioCapturers;
  33. AudioMixer _mixer;
  34. std::vector<Info> _infos;
  35. bool _isRecord = false;
  36. int _streamIndex;
  37. Encoder<MediaType::AUDIO>::Param _param;
  38. static void _Callback(void* data, size_t size, void* userInfo);
  39. AVSampleFormat _GetAVSampleFormat(int wBitsPerSample)
  40. {
  41. return wBitsPerSample == 16 ? AV_SAMPLE_FMT_S16 : AV_SAMPLE_FMT_S32;
  42. }
  43. };
  44. #endif