| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- #ifndef __AUDIO_RECORDER_H__
- #define __AUDIO_RECORDER_H__
- #include "capturer/audio/audio_capturer.h"
- #include "encoder/audio_mixer.h"
- #include "muxer/av_muxer.h"
- #include "basic/timer.h"
- class AudioRecorder
- {
- public:
- AudioRecorder();
- ~AudioRecorder();
- struct Info
- {
- AudioMixer* mixer = nullptr;
- AvMuxer* muxer = nullptr;
- bool* isRecord = nullptr;
- int mixIndex;
- int* streamIndex = nullptr;
- };
- bool Open(const std::vector<AudioCapturer::Type>& deviceTypes,
- Encoder<MediaType::AUDIO>::Param& param,
- const uint32_t sampleRate = AUDIO_SAMPLE_RATE,
- const uint32_t channels = AUDIO_CHANNEL,
- const uint32_t bitsPerSample = 32,
- const AVSampleFormat format = AUDIO_FMT);
- bool LoadMuxer(AvMuxer& muxer);
- bool StartRecord();
- void StopRecord();
- void Close();
- void PullAndProcessAudio(); // 新增:主动拉取音频数据
- auto GetCaptureInfo(int mixIndex) { return _mixer.GetInputInfo(mixIndex); }
- void SetVolumeScale(float scale, int mixIndex);
- private:
- std::vector<IAudioCapturer*> m_audioCapturers;
- AudioMixer _mixer;
- std::vector<Info> _infos;
- bool _isRecord = false;
- int _streamIndex;
- Encoder<MediaType::AUDIO>::Param _param;
- Timer m_audioTimer; // 新增高精度定时器
- static constexpr int AUDIO_PULL_INTERVAL_MS = 10;
- static void _Callback(void* data, size_t size, void* userInfo);
- AVSampleFormat _GetAVSampleFormat(int wBitsPerSample)
- {
- return wBitsPerSample == 16 ? AV_SAMPLE_FMT_S16 : AV_SAMPLE_FMT_S32;
- }
- };
- #endif
|