2024-09-04 17:57:23 +08:00
|
|
|
#include "BoostLog.h"
|
|
|
|
#include "DateTime.h"
|
|
|
|
#include "main.h"
|
|
|
|
#include <filesystem>
|
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
void RecorderTask::run() {
|
|
|
|
std::ostringstream oss;
|
2024-09-06 16:35:51 +08:00
|
|
|
oss << DumpPath << "/" << DateTime::currentDateTime().toString("%Y%m%d%H%M%S") << ".pcm";
|
2024-09-04 17:57:23 +08:00
|
|
|
auto filePath = oss.str();
|
|
|
|
m_ofs = std::make_shared<std::ofstream>(filePath, std::ofstream::binary);
|
|
|
|
|
|
|
|
RkAudio::Format format;
|
|
|
|
format.channels = 2;
|
|
|
|
format.period = 64;
|
|
|
|
m_input = std::make_shared<RkAudio::Input>();
|
|
|
|
m_input->setDataCallback(
|
|
|
|
[this](const RkAudio::Frame &frame) { m_ofs->write(reinterpret_cast<const char *>(frame.data), frame.byteSize); });
|
|
|
|
|
|
|
|
if (m_input->open(format, false)) {
|
|
|
|
LOG(info) << "open record succeed, path: " << filePath;
|
|
|
|
} else {
|
|
|
|
LOG(info) << "open record failed.";
|
|
|
|
}
|
|
|
|
}
|