| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- #include "code/muxer/muxer_file_muxer.h"
- #include "code/base/logger.h"
- #include <iostream>
- using namespace av::muxer;
- using namespace av;
- int main() {
- // 初始化日志
- Logger::instance().setLevel(LogLevel::DEBUG);
-
- std::cout << "测试 FileMuxer 初始化修复..." << std::endl;
-
- try {
- // 创建文件复用器
- FileMuxer muxer;
-
- // 测试1: 使用正确的 FileMuxerParams
- std::cout << "\n=== 测试1: 正确的 FileMuxerParams ===" << std::endl;
- FileMuxerParams correctParams;
- correctParams.type = MuxerType::FILE_MUXER;
- correctParams.outputPath = "./test_output.mp4";
- correctParams.outputFile = "./test_output.mp4";
- correctParams.format = "mp4";
- correctParams.overwrite = true;
-
- ErrorCode result = muxer.initialize(correctParams);
- if (result == ErrorCode::SUCCESS) {
- std::cout << "✓ 正确参数初始化成功!" << std::endl;
- } else {
- std::cout << "✗ 正确参数初始化失败,错误码: " << static_cast<int>(result) << std::endl;
- }
-
- muxer.close();
-
- // 测试2: 使用错误类型的 MuxerParams(基类)
- std::cout << "\n=== 测试2: 错误的 MuxerParams 类型 ===" << std::endl;
- MuxerParams wrongParams;
- wrongParams.type = MuxerType::FILE_MUXER; // 类型正确但实际是基类
- wrongParams.outputPath = "./test_output2.mp4";
-
- FileMuxer muxer2;
- result = muxer2.initialize(wrongParams);
- if (result != ErrorCode::SUCCESS) {
- std::cout << "✓ 错误参数类型被正确拒绝,错误码: " << static_cast<int>(result) << std::endl;
- } else {
- std::cout << "✗ 错误参数类型未被拒绝!" << std::endl;
- }
-
- // 测试3: 空输出路径
- std::cout << "\n=== 测试3: 空输出路径 ===" << std::endl;
- FileMuxerParams emptyPathParams;
- emptyPathParams.type = MuxerType::FILE_MUXER;
- emptyPathParams.outputPath = ""; // 空路径
- emptyPathParams.outputFile = ""; // 空文件
-
- FileMuxer muxer3;
- result = muxer3.initialize(emptyPathParams);
- if (result != ErrorCode::SUCCESS) {
- std::cout << "✓ 空路径参数被正确拒绝,错误码: " << static_cast<int>(result) << std::endl;
- } else {
- std::cout << "✗ 空路径参数未被拒绝!" << std::endl;
- }
-
- // 测试4: 错误的复用器类型
- std::cout << "\n=== 测试4: 错误的复用器类型 ===" << std::endl;
- FileMuxerParams wrongTypeParams;
- wrongTypeParams.type = MuxerType::STREAM_MUXER; // 错误的类型
- wrongTypeParams.outputPath = "./test_output4.mp4";
-
- FileMuxer muxer4;
- result = muxer4.initialize(wrongTypeParams);
- if (result != ErrorCode::SUCCESS) {
- std::cout << "✓ 错误复用器类型被正确拒绝,错误码: " << static_cast<int>(result) << std::endl;
- } else {
- std::cout << "✗ 错误复用器类型未被拒绝!" << std::endl;
- }
-
- } catch (const std::exception& e) {
- std::cout << "✗ 异常: " << e.what() << std::endl;
- return 1;
- }
-
- std::cout << "\n测试完成!" << std::endl;
- return 0;
- }
|