mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-07-04 09:47:33 +08:00
解决编译错误以及运行期bug
This commit is contained in:
@@ -3,7 +3,7 @@ find_package(SDL QUIET)
|
||||
if(SDL_FOUND)
|
||||
include_directories(${SDL_INCLUDE_DIR})
|
||||
list(APPEND LINK_LIB_LIST ${SDL_LIBRARY})
|
||||
message(STATUS "找到SDL")
|
||||
message(STATUS " found SDL")
|
||||
endif()
|
||||
|
||||
#查找ffmpeg/libutil是否安装
|
||||
@@ -11,7 +11,7 @@ find_package(AVUTIL QUIET)
|
||||
if(AVUTIL_FOUND)
|
||||
include_directories(${AVUTIL_INCLUDE_DIR})
|
||||
list(APPEND LINK_LIB_LIST ${AVUTIL_LIBRARIES})
|
||||
message(STATUS "找到libutil")
|
||||
message(STATUS " found libutil")
|
||||
endif()
|
||||
|
||||
#查找ffmpeg/libavcodec是否安装
|
||||
@@ -19,31 +19,23 @@ find_package(AVCODEC QUIET)
|
||||
if(AVCODEC_FOUND)
|
||||
include_directories(${AVCODEC_INCLUDE_DIR})
|
||||
list(APPEND LINK_LIB_LIST ${AVCODEC_LIBRARIES})
|
||||
message(STATUS "找到libavcodec")
|
||||
message(STATUS " found libavcodec")
|
||||
endif()
|
||||
|
||||
aux_source_directory(. TEST_SRC_LIST)
|
||||
#如果ffmpeg/libavcodec ffmpeg/libavcodec SDL 都安装了则编译 test_player
|
||||
if(SDL_FOUND AND AVCODEC_FOUND AND AVUTIL_FOUND)
|
||||
message(STATUS "test_player被编译")
|
||||
message(STATUS "test_player will be compiled")
|
||||
else()
|
||||
message(STATUS "test_player被忽略,如需编译,请先安装sdl ffmpeg/libavcodec ffmpeg/libavcodec")
|
||||
message(STATUS "test_player ingored, please install sdl ffmpeg/libavcodec ffmpeg/libavcodec")
|
||||
list(REMOVE_ITEM TEST_SRC_LIST ./test_player.cpp)
|
||||
endif()
|
||||
|
||||
foreach(TEST_SRC ${TEST_SRC_LIST})
|
||||
STRING(REGEX REPLACE "^\\./|\\.c[a-zA-Z0-9_]*$" "" TEST_EXE_NAME ${TEST_SRC})
|
||||
message(STATUS "添加测试程序:${TEST_EXE_NAME}")
|
||||
message(STATUS "add test:${TEST_EXE_NAME}")
|
||||
add_executable(${TEST_EXE_NAME} ${TEST_SRC})
|
||||
|
||||
if(ANDROID)
|
||||
target_link_libraries(${TEST_EXE_NAME} ${CMAKE_PROJECT_NAME}_static ${LINK_LIB_LIST})
|
||||
elseif(WIN32)
|
||||
target_link_libraries(${TEST_EXE_NAME} ${CMAKE_PROJECT_NAME}_shared ${LINK_LIB_LIST} )
|
||||
else()
|
||||
target_link_libraries(${TEST_EXE_NAME} ${CMAKE_PROJECT_NAME}_shared ${LINK_LIB_LIST} pthread)
|
||||
endif()
|
||||
|
||||
target_link_libraries(${TEST_EXE_NAME} ${LINK_LIB_LIST})
|
||||
endforeach()
|
||||
|
||||
|
||||
|
||||
@@ -42,26 +42,27 @@ using namespace ZL::DEV;
|
||||
|
||||
//推流器,保持强引用
|
||||
RtmpPusher::Ptr pusher;
|
||||
|
||||
//声明函数
|
||||
void rePushDelay(const string &app,const string &stream,const string &url);
|
||||
void rePushDelay(const string &app, const string &stream, const string &url);
|
||||
|
||||
//创建推流器并开始推流
|
||||
void createPusher(const string &app,const string &stream,const string &url){
|
||||
void createPusher(const string &app, const string &stream, const string &url) {
|
||||
//创建推流器并绑定一个RtmpMediaSource
|
||||
pusher.reset(new RtmpPusher(DEFAULT_VHOST,app.data(), stream.data()));
|
||||
pusher.reset(new RtmpPusher(DEFAULT_VHOST, app.data(), stream.data()));
|
||||
//设置推流中断处理逻辑
|
||||
pusher->setOnShutdown([app,stream, url](const SockException &ex) {
|
||||
pusher->setOnShutdown([app, stream, url](const SockException &ex) {
|
||||
WarnL << "Server connection is closed:" << ex.getErrCode() << " " << ex.what();
|
||||
//重试
|
||||
rePushDelay(app,stream, url);
|
||||
rePushDelay(app, stream, url);
|
||||
});
|
||||
//设置发布结果处理逻辑
|
||||
pusher->setOnPublished([app,stream, url](const SockException &ex) {
|
||||
pusher->setOnPublished([app, stream, url](const SockException &ex) {
|
||||
if (ex) {
|
||||
WarnL << "Publish fail:" << ex.getErrCode() << " " << ex.what();
|
||||
//如果发布失败,就重试
|
||||
rePushDelay(app,stream, url);
|
||||
}else {
|
||||
rePushDelay(app, stream, url);
|
||||
} else {
|
||||
InfoL << "Publish success,Please play with player:" << url;
|
||||
}
|
||||
});
|
||||
@@ -69,61 +70,58 @@ void createPusher(const string &app,const string &stream,const string &url){
|
||||
}
|
||||
|
||||
//推流失败或断开延迟2秒后重试推流
|
||||
void rePushDelay(const string &app,const string &stream,const string &url){
|
||||
//上次延时两秒的任务可能还没执行,所以我们要先取消上次任务
|
||||
AsyncTaskThread::Instance().CancelTask(0);
|
||||
//2秒后执行重新推流的任务
|
||||
AsyncTaskThread::Instance().DoTaskDelay(0, 2000, [app, stream,url]() {
|
||||
InfoL << "Re-Publishing...";
|
||||
//重新推流
|
||||
createPusher(app,stream,url);
|
||||
//此任务不重复
|
||||
void rePushDelay(const string &app, const string &stream, const string &url) {
|
||||
//上次延时两秒的任务可能还没执行,所以我们要先取消上次任务
|
||||
AsyncTaskThread::Instance().CancelTask(0);
|
||||
//2秒后执行重新推流的任务
|
||||
AsyncTaskThread::Instance().DoTaskDelay(0, 2000, [app, stream, url]() {
|
||||
InfoL << "Re-Publishing...";
|
||||
//重新推流
|
||||
createPusher(app, stream, url);
|
||||
//此任务不重复
|
||||
return false;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
//这里才是真正执行main函数,你可以把函数名(domain)改成main,然后就可以输入自定义url了
|
||||
int domain(int argc, const char *argv[]) {
|
||||
//设置退出信号处理函数
|
||||
signal(SIGINT, [](int){EventPoller::Instance().shutdown();});
|
||||
//设置日志
|
||||
Logger::Instance().add(std::make_shared<ConsoleChannel>("stdout", LTrace));
|
||||
Logger::Instance().setWriter(std::make_shared<AsyncLogWriter>());
|
||||
int domain(const string &playUrl, const string &pushUrl) {
|
||||
//设置退出信号处理函数
|
||||
signal(SIGINT, [](int) { EventPoller::Instance().shutdown(); });
|
||||
//设置日志
|
||||
Logger::Instance().add(std::make_shared<ConsoleChannel>("stdout", LTrace));
|
||||
Logger::Instance().setWriter(std::make_shared<AsyncLogWriter>());
|
||||
|
||||
string playUrl = argv[1];
|
||||
string pushUrl = argv[2];
|
||||
{
|
||||
//拉一个流,生成一个RtmpMediaSource,源的名称是"app/stream"
|
||||
//你也可以以其他方式生成RtmpMediaSource,比如说MP4文件(请查看test_rtmpPusherMp4.cpp代码)
|
||||
PlayerProxy::Ptr player(new PlayerProxy(DEFAULT_VHOST, "app", "stream"));
|
||||
player->play(playUrl.data());
|
||||
|
||||
//拉一个流,生成一个RtmpMediaSource,源的名称是"app/stream"
|
||||
//你也可以以其他方式生成RtmpMediaSource,比如说MP4文件(请查看test_rtmpPusherMp4.cpp代码)
|
||||
PlayerProxy::Ptr player(new PlayerProxy(DEFAULT_VHOST,"app", "stream"));
|
||||
player->play(playUrl.data());
|
||||
//监听RtmpMediaSource注册事件,在PlayerProxy播放成功后触发
|
||||
NoticeCenter::Instance().addListener(nullptr, Config::Broadcast::kBroadcastMediaChanged,
|
||||
[pushUrl](BroadcastMediaChangedArgs) {
|
||||
//媒体源"app/stream"已经注册,这时方可新建一个RtmpPusher对象并绑定该媒体源
|
||||
if(bRegist && schema == RTMP_SCHEMA){
|
||||
createPusher(app, stream, pushUrl);
|
||||
}
|
||||
});
|
||||
|
||||
//监听RtmpMediaSource注册事件,在PlayerProxy播放成功后触发
|
||||
NoticeCenter::Instance().addListener(nullptr, Config::Broadcast::kBroadcastMediaChanged, [pushUrl](BroadcastMediaChangedArgs) {
|
||||
//媒体源"app/stream"已经注册,这时方可新建一个RtmpPusher对象并绑定该媒体源
|
||||
createPusher(app,stream,pushUrl);
|
||||
});
|
||||
//事件轮询
|
||||
EventPoller::Instance().runLoop();
|
||||
}
|
||||
//删除事件监听
|
||||
NoticeCenter::Instance().delListener(nullptr);
|
||||
|
||||
//事件轮询
|
||||
EventPoller::Instance().runLoop();
|
||||
//删除事件监听
|
||||
NoticeCenter::Instance().delListener(nullptr);
|
||||
//销毁代理播放器、推流器
|
||||
player.reset();
|
||||
pusher.reset();
|
||||
|
||||
//清理程序
|
||||
EventPoller::Destory();
|
||||
AsyncTaskThread::Destory();
|
||||
Logger::Destory();
|
||||
return 0;
|
||||
//清理程序
|
||||
EventPoller::Destory();
|
||||
AsyncTaskThread::Destory();
|
||||
Logger::Destory();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main(int argc,char *argv[]){
|
||||
const char *argList[] = {argv[0],"rtmp://live.hkstv.hk.lxdns.com/live/hks",argv[1]};
|
||||
return domain(3,argList);
|
||||
int main(int argc, char *argv[]) {
|
||||
return domain("rtmp://live.hkstv.hk.lxdns.com/live/hks", "rtmp://jizan.iok.la/live/stream");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -48,7 +48,6 @@ RtmpPusher::Ptr pusher;
|
||||
void rePushDelay(const string &app,const string &stream,const string &url);
|
||||
void createPusher(const string &app,const string &stream,const string &url);
|
||||
|
||||
|
||||
//创建推流器并开始推流
|
||||
void createPusher(const string &app,const string &stream,const string &url){
|
||||
auto rtmpSrc = dynamic_pointer_cast<RtmpMediaSource>(MediaReader::onMakeMediaSource(RTMP_SCHEMA,DEFAULT_VHOST,app,stream));
|
||||
@@ -94,18 +93,13 @@ void rePushDelay(const string &app,const string &stream,const string &url){
|
||||
}
|
||||
|
||||
//这里才是真正执行main函数,你可以把函数名(domain)改成main,然后就可以输入自定义url了
|
||||
int domain(int argc,const char *argv[]){
|
||||
int domain(const string & filePath,const string & pushUrl){
|
||||
//设置退出信号处理函数
|
||||
signal(SIGINT, [](int){EventPoller::Instance().shutdown();});
|
||||
//设置日志
|
||||
Logger::Instance().add(std::make_shared<ConsoleChannel>("stdout", LTrace));
|
||||
Logger::Instance().setWriter(std::make_shared<AsyncLogWriter>());
|
||||
|
||||
//filePath同时也是流id
|
||||
string filePath = argv[1];
|
||||
//推流地址
|
||||
string pushUrl = argv[2];
|
||||
|
||||
//录像应用名称默认为record
|
||||
string appName = mINI::Instance()[Config::Record::kAppName];
|
||||
//app必须record,filePath(流id)为相对于httpRoot/record的路径,否则MediaReader会找到不该文件
|
||||
@@ -131,8 +125,7 @@ int domain(int argc,const char *argv[]){
|
||||
int main(int argc,char *argv[]){
|
||||
//MP4文件需要放置在 httpRoot/record目录下,文件负载必须为h264+aac
|
||||
//可以使用test_server生成的mp4文件
|
||||
const char *argList[] = {argv[0],"app/stream/2017-09-30/12-55-38.mp4","rtmp://jizan.iok.la/live/test"};
|
||||
return domain(3,argList);
|
||||
return domain("app/stream/2017-09-30/12-55-38.mp4","rtmp://jizan.iok.la/live/test");
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user