|
|
@@ -29,7 +29,7 @@ FileMuxer::~FileMuxer() {
|
|
|
ErrorCode FileMuxer::initialize(const MuxerParams& params) {
|
|
|
if (params.type != MuxerType::FILE_MUXER) {
|
|
|
AV_LOGGER_ERROR("参数类型不是文件复用器");
|
|
|
- return ErrorCode::INVALID_ARGUMENT;
|
|
|
+ return ErrorCode::INVALID_PARAMS;
|
|
|
}
|
|
|
|
|
|
fileMuxerParams_ = static_cast<const FileMuxerParams&>(params);
|
|
|
@@ -40,7 +40,7 @@ ErrorCode FileMuxer::initialize(const MuxerParams& params) {
|
|
|
|
|
|
// 调用父类的initialize方法来处理streams
|
|
|
ErrorCode result = AbstractMuxer::initialize(params);
|
|
|
- if (result != ErrorCode::OK) {
|
|
|
+ if (result != ErrorCode::SUCCESS) {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
@@ -52,7 +52,7 @@ ErrorCode FileMuxer::initialize(const MuxerParams& params) {
|
|
|
}
|
|
|
|
|
|
ErrorCode validateResult = validateFilePath(currentOutputFile_);
|
|
|
- if (validateResult != ErrorCode::OK) {
|
|
|
+ if (validateResult != ErrorCode::SUCCESS) {
|
|
|
return validateResult;
|
|
|
}
|
|
|
|
|
|
@@ -70,7 +70,7 @@ ErrorCode FileMuxer::initialize(const MuxerParams& params) {
|
|
|
|
|
|
AV_LOGGER_INFOF("文件复用器初始化成功: {}", currentOutputFile_);
|
|
|
|
|
|
- return ErrorCode::OK;
|
|
|
+ return ErrorCode::SUCCESS;
|
|
|
}
|
|
|
|
|
|
ErrorCode FileMuxer::start() {
|
|
|
@@ -80,12 +80,12 @@ ErrorCode FileMuxer::start() {
|
|
|
}
|
|
|
|
|
|
ErrorCode result = setupOutput();
|
|
|
- if (result != ErrorCode::OK) {
|
|
|
+ if (result != ErrorCode::SUCCESS) {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
result = writeHeader();
|
|
|
- if (result != ErrorCode::OK) {
|
|
|
+ if (result != ErrorCode::SUCCESS) {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
@@ -98,7 +98,7 @@ ErrorCode FileMuxer::start() {
|
|
|
fileStartTime_ = std::chrono::steady_clock::now();
|
|
|
AV_LOGGER_INFO("文件复用器已启动");
|
|
|
|
|
|
- return ErrorCode::OK;
|
|
|
+ return ErrorCode::SUCCESS;
|
|
|
} catch (const std::exception& e) {
|
|
|
AV_LOGGER_ERRORF("启动写入线程失败: {}", e.what());
|
|
|
return ErrorCode::THREAD_ERROR;
|
|
|
@@ -107,7 +107,7 @@ ErrorCode FileMuxer::start() {
|
|
|
|
|
|
ErrorCode FileMuxer::stop() {
|
|
|
if (getState() != MuxerState::STARTED && getState() != MuxerState::PAUSED) {
|
|
|
- return ErrorCode::OK;
|
|
|
+ return ErrorCode::SUCCESS;
|
|
|
}
|
|
|
|
|
|
// 停止写入线程
|
|
|
@@ -123,14 +123,14 @@ ErrorCode FileMuxer::stop() {
|
|
|
|
|
|
// 写入文件尾
|
|
|
ErrorCode result = writeTrailer();
|
|
|
- if (result != ErrorCode::OK) {
|
|
|
+ if (result != ErrorCode::SUCCESS) {
|
|
|
AV_LOGGER_ERRORF("写入文件尾失败: {}", static_cast<int>(result));
|
|
|
}
|
|
|
|
|
|
setState(MuxerState::STOPPED);
|
|
|
AV_LOGGER_INFO("文件复用器已停止");
|
|
|
|
|
|
- return ErrorCode::OK;
|
|
|
+ return ErrorCode::SUCCESS;
|
|
|
}
|
|
|
|
|
|
ErrorCode FileMuxer::close() {
|
|
|
@@ -155,7 +155,7 @@ ErrorCode FileMuxer::close() {
|
|
|
ErrorCode FileMuxer::writePacket(AVPacket* packet) {
|
|
|
if (!packet) {
|
|
|
AV_LOGGER_ERROR("包指针为空");
|
|
|
- return ErrorCode::INVALID_ARGUMENT;
|
|
|
+ return ErrorCode::INVALID_PARAMS;
|
|
|
}
|
|
|
|
|
|
if (getState() != MuxerState::STARTED) {
|
|
|
@@ -180,7 +180,7 @@ ErrorCode FileMuxer::writePacket(AVPacket* packet) {
|
|
|
AVPacket* packetCopy = av_packet_alloc();
|
|
|
if (!packetCopy) {
|
|
|
AV_LOGGER_ERROR("分配包内存失败");
|
|
|
- return ErrorCode::OUT_OF_MEMORY;
|
|
|
+ return ErrorCode::MEMORY_ALLOC_FAILED;
|
|
|
}
|
|
|
|
|
|
int ret = av_packet_ref(packetCopy, packet);
|
|
|
@@ -201,13 +201,13 @@ ErrorCode FileMuxer::writePacket(AVPacket* packet) {
|
|
|
|
|
|
queueCondition_.notify_one();
|
|
|
|
|
|
- return ErrorCode::OK;
|
|
|
+ return ErrorCode::SUCCESS;
|
|
|
}
|
|
|
|
|
|
ErrorCode FileMuxer::writeFrame(AVFrame* frame, int streamIndex) {
|
|
|
if (!frame) {
|
|
|
AV_LOGGER_ERROR("帧指针为空");
|
|
|
- return ErrorCode::INVALID_ARGUMENT;
|
|
|
+ return ErrorCode::INVALID_PARAMS;
|
|
|
}
|
|
|
|
|
|
// 这里需要编码器将帧编码为包,然后调用writePacket
|
|
|
@@ -219,7 +219,7 @@ ErrorCode FileMuxer::writeFrame(AVFrame* frame, int streamIndex) {
|
|
|
|
|
|
ErrorCode FileMuxer::flush() {
|
|
|
if (!formatCtx_) {
|
|
|
- return ErrorCode::OK;
|
|
|
+ return ErrorCode::SUCCESS;
|
|
|
}
|
|
|
|
|
|
std::lock_guard<std::mutex> lock(fileMutex_);
|
|
|
@@ -237,7 +237,7 @@ ErrorCode FileMuxer::flush() {
|
|
|
lastFlushTime_ = std::chrono::steady_clock::now();
|
|
|
AV_LOGGER_DEBUG("复用器已刷新");
|
|
|
|
|
|
- return ErrorCode::OK;
|
|
|
+ return ErrorCode::SUCCESS;
|
|
|
}
|
|
|
|
|
|
ErrorCode FileMuxer::addStream(const StreamInfo& streamInfo) {
|
|
|
@@ -265,7 +265,7 @@ ErrorCode FileMuxer::addStream(const StreamInfo& streamInfo) {
|
|
|
streamInfo.index, static_cast<int>(streamInfo.type),
|
|
|
streamInfo.codecName);
|
|
|
|
|
|
- return ErrorCode::OK;
|
|
|
+ return ErrorCode::SUCCESS;
|
|
|
}
|
|
|
|
|
|
ErrorCode FileMuxer::setOutputFile(const std::string& filename) {
|
|
|
@@ -275,7 +275,7 @@ ErrorCode FileMuxer::setOutputFile(const std::string& filename) {
|
|
|
}
|
|
|
|
|
|
ErrorCode result = validateFilePath(filename);
|
|
|
- if (result != ErrorCode::OK) {
|
|
|
+ if (result != ErrorCode::SUCCESS) {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
@@ -284,7 +284,7 @@ ErrorCode FileMuxer::setOutputFile(const std::string& filename) {
|
|
|
|
|
|
AV_LOGGER_INFOF("输出文件已设置为: {}", filename);
|
|
|
|
|
|
- return ErrorCode::OK;
|
|
|
+ return ErrorCode::SUCCESS;
|
|
|
}
|
|
|
|
|
|
std::string FileMuxer::getOutputFile() const {
|
|
|
@@ -312,7 +312,7 @@ ErrorCode FileMuxer::enableSegmentation(bool enable, int duration) {
|
|
|
|
|
|
AV_LOGGER_INFOF("Segmentation {}: duration={}s", enable ? "enabled" : "disabled", duration);
|
|
|
|
|
|
- return ErrorCode::OK;
|
|
|
+ return ErrorCode::SUCCESS;
|
|
|
}
|
|
|
|
|
|
ErrorCode FileMuxer::forceNewSegment() {
|
|
|
@@ -344,14 +344,14 @@ ErrorCode FileMuxer::setFastStart(bool enable) {
|
|
|
|
|
|
AV_LOGGER_INFOF("Fast start {}", enable ? "enabled" : "disabled");
|
|
|
|
|
|
- return ErrorCode::OK;
|
|
|
+ return ErrorCode::SUCCESS;
|
|
|
}
|
|
|
|
|
|
ErrorCode FileMuxer::setMovFlags(int flags) {
|
|
|
fileMuxerParams_.movFlags = flags;
|
|
|
AV_LOGGER_INFOF("MOV标志已设置为: 0x{:X}", flags);
|
|
|
|
|
|
- return ErrorCode::OK;
|
|
|
+ return ErrorCode::SUCCESS;
|
|
|
}
|
|
|
|
|
|
ErrorCode FileMuxer::setupOutput() {
|
|
|
@@ -374,7 +374,7 @@ ErrorCode FileMuxer::setupOutput() {
|
|
|
|
|
|
// 设置流
|
|
|
ErrorCode result = setupStreams();
|
|
|
- if (result != ErrorCode::OK) {
|
|
|
+ if (result != ErrorCode::SUCCESS) {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
@@ -416,12 +416,12 @@ ErrorCode FileMuxer::writeHeader() {
|
|
|
|
|
|
AV_LOGGER_INFO("文件头已写入");
|
|
|
|
|
|
- return ErrorCode::OK;
|
|
|
+ return ErrorCode::SUCCESS;
|
|
|
}
|
|
|
|
|
|
ErrorCode FileMuxer::writeTrailer() {
|
|
|
if (!formatCtx_) {
|
|
|
- return ErrorCode::OK;
|
|
|
+ return ErrorCode::SUCCESS;
|
|
|
}
|
|
|
|
|
|
std::lock_guard<std::mutex> lock(fileMutex_);
|
|
|
@@ -434,7 +434,7 @@ ErrorCode FileMuxer::writeTrailer() {
|
|
|
|
|
|
AV_LOGGER_INFO("文件尾已写入");
|
|
|
|
|
|
- return ErrorCode::OK;
|
|
|
+ return ErrorCode::SUCCESS;
|
|
|
}
|
|
|
|
|
|
ErrorCode FileMuxer::openOutputFile() {
|
|
|
@@ -461,12 +461,12 @@ ErrorCode FileMuxer::openOutputFile() {
|
|
|
currentFileSize_ = 0;
|
|
|
AV_LOGGER_INFOF("输出文件已打开: {}", currentOutputFile_);
|
|
|
|
|
|
- return ErrorCode::OK;
|
|
|
+ return ErrorCode::SUCCESS;
|
|
|
}
|
|
|
|
|
|
ErrorCode FileMuxer::closeOutputFile() {
|
|
|
if (!formatCtx_) {
|
|
|
- return ErrorCode::OK;
|
|
|
+ return ErrorCode::SUCCESS;
|
|
|
}
|
|
|
|
|
|
std::lock_guard<std::mutex> lock(fileMutex_);
|
|
|
@@ -485,23 +485,23 @@ ErrorCode FileMuxer::closeOutputFile() {
|
|
|
|
|
|
AV_LOGGER_INFO("输出文件已关闭");
|
|
|
|
|
|
- return ErrorCode::OK;
|
|
|
+ return ErrorCode::SUCCESS;
|
|
|
}
|
|
|
|
|
|
ErrorCode FileMuxer::createNewSegment() {
|
|
|
if (!segmentationEnabled_) {
|
|
|
- return ErrorCode::OK;
|
|
|
+ return ErrorCode::SUCCESS;
|
|
|
}
|
|
|
|
|
|
// 写入当前段的尾部
|
|
|
ErrorCode result = writeTrailer();
|
|
|
- if (result != ErrorCode::OK) {
|
|
|
+ if (result != ErrorCode::SUCCESS) {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
// 关闭当前文件
|
|
|
result = closeOutputFile();
|
|
|
- if (result != ErrorCode::OK) {
|
|
|
+ if (result != ErrorCode::SUCCESS) {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
@@ -514,13 +514,13 @@ ErrorCode FileMuxer::createNewSegment() {
|
|
|
|
|
|
// 重新设置输出
|
|
|
result = setupOutput();
|
|
|
- if (result != ErrorCode::OK) {
|
|
|
+ if (result != ErrorCode::SUCCESS) {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
// 写入新段的头部
|
|
|
result = writeHeader();
|
|
|
- if (result != ErrorCode::OK) {
|
|
|
+ if (result != ErrorCode::SUCCESS) {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
@@ -528,7 +528,7 @@ ErrorCode FileMuxer::createNewSegment() {
|
|
|
|
|
|
AV_LOGGER_INFOF("创建新段: {}", currentOutputFile_);
|
|
|
|
|
|
- return ErrorCode::OK;
|
|
|
+ return ErrorCode::SUCCESS;
|
|
|
}
|
|
|
|
|
|
ErrorCode FileMuxer::setupStreams() {
|
|
|
@@ -546,7 +546,7 @@ ErrorCode FileMuxer::setupStreams() {
|
|
|
|
|
|
AV_LOGGER_INFOF("已设置 {} 个流", streams_.size());
|
|
|
|
|
|
- return ErrorCode::OK;
|
|
|
+ return ErrorCode::SUCCESS;
|
|
|
}
|
|
|
|
|
|
AVStream* FileMuxer::createAVStream(const StreamInfo& streamInfo) {
|
|
|
@@ -591,7 +591,7 @@ AVStream* FileMuxer::createAVStream(const StreamInfo& streamInfo) {
|
|
|
|
|
|
ErrorCode FileMuxer::processPacket(AVPacket* packet) {
|
|
|
if (!packet || !formatCtx_) {
|
|
|
- return ErrorCode::INVALID_ARGUMENT;
|
|
|
+ return ErrorCode::INVALID_PARAMS;
|
|
|
}
|
|
|
|
|
|
// 检查流索引
|
|
|
@@ -604,7 +604,7 @@ ErrorCode FileMuxer::processPacket(AVPacket* packet) {
|
|
|
// 检查是否需要创建新段
|
|
|
if (shouldCreateNewSegment()) {
|
|
|
ErrorCode result = createNewSegment();
|
|
|
- if (result != ErrorCode::OK) {
|
|
|
+ if (result != ErrorCode::SUCCESS) {
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
@@ -643,7 +643,7 @@ ErrorCode FileMuxer::writePacketInternal(AVPacket* packet) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- return ErrorCode::OK;
|
|
|
+ return ErrorCode::SUCCESS;
|
|
|
}
|
|
|
|
|
|
void FileMuxer::writeThreadFunc() {
|
|
|
@@ -671,7 +671,7 @@ void FileMuxer::writeThreadFunc() {
|
|
|
|
|
|
if (item && item->packet) {
|
|
|
ErrorCode result = processPacket(item->packet);
|
|
|
- if (result != ErrorCode::OK) {
|
|
|
+ if (result != ErrorCode::SUCCESS) {
|
|
|
onError(result, "写入包失败");
|
|
|
}
|
|
|
}
|
|
|
@@ -740,7 +740,7 @@ bool FileMuxer::shouldCreateNewSegment() const {
|
|
|
ErrorCode FileMuxer::validateFilePath(const std::string& path) {
|
|
|
if (path.empty()) {
|
|
|
AV_LOGGER_ERROR("文件路径不能为空");
|
|
|
- return ErrorCode::INVALID_ARGUMENT;
|
|
|
+ return ErrorCode::INVALID_PARAMS;
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
@@ -764,7 +764,7 @@ ErrorCode FileMuxer::validateFilePath(const std::string& path) {
|
|
|
return ErrorCode::INVALID_PATH;
|
|
|
}
|
|
|
|
|
|
- return ErrorCode::OK;
|
|
|
+ return ErrorCode::SUCCESS;
|
|
|
}
|
|
|
|
|
|
bool FileMuxer::validateParams(const MuxerParams& params) {
|
|
|
@@ -822,7 +822,7 @@ std::unique_ptr<FileMuxer> FileMuxer::FileMuxerFactory::createFileMuxer(const st
|
|
|
params.format = AbstractMuxer::getFormatFromExtension(filename);
|
|
|
|
|
|
ErrorCode result = muxer->initialize(params);
|
|
|
- if (result != ErrorCode::OK) {
|
|
|
+ if (result != ErrorCode::SUCCESS) {
|
|
|
AV_LOGGER_ERRORF("创建文件复用器失败: {}", static_cast<int>(result));
|
|
|
return nullptr;
|
|
|
}
|
|
|
@@ -848,7 +848,7 @@ std::unique_ptr<FileMuxer> FileMuxer::FileMuxerFactory::createSegmentedMuxer(con
|
|
|
params.format = AbstractMuxer::getFormatFromExtension(firstFile);
|
|
|
|
|
|
ErrorCode result = muxer->initialize(params);
|
|
|
- if (result != ErrorCode::OK) {
|
|
|
+ if (result != ErrorCode::SUCCESS) {
|
|
|
AV_LOGGER_ERRORF("创建分段复用器失败: {}", static_cast<int>(result));
|
|
|
return nullptr;
|
|
|
}
|