提交 19f909dd authored 作者: blu's avatar blu

init

上级 9ea27184
...@@ -174,12 +174,8 @@ private: ...@@ -174,12 +174,8 @@ private:
return ret; return ret;
} }
int getInputFormat(){
int setupStream()
{
int ret = 0; int ret = 0;
AVDictionary *pOptsRemux = NULL;
// req avformatcontext packet // req avformatcontext packet
// send hello to puller // send hello to puller
spdlog::info("evpusher {} {} send hello to puller: {}", devSn, iid, pullerGid); spdlog::info("evpusher {} {} send hello to puller: {}", devSn, iid, pullerGid);
...@@ -227,8 +223,14 @@ private: ...@@ -227,8 +223,14 @@ private:
} }
} }
} }
return ret;
// }
int setupStream()
{
int ret = 0;
AVDictionary *pOptsRemux = NULL;
ret = avformat_alloc_output_context2(&pAVFormatRemux, NULL, "rtsp", urlOut.c_str()); ret = avformat_alloc_output_context2(&pAVFormatRemux, NULL, "rtsp", urlOut.c_str());
if (ret < 0) { if (ret < 0) {
spdlog::error("evpusher {} {} failed create avformatcontext for output: %s", devSn, iid, av_err2str(ret)); spdlog::error("evpusher {} {} failed create avformatcontext for output: %s", devSn, iid, av_err2str(ret));
...@@ -296,6 +298,26 @@ private: ...@@ -296,6 +298,26 @@ private:
return ret; return ret;
} }
void freeStream(){
// close output context
if(pAVFormatRemux)
{
if(pAVFormatRemux->pb) {
avio_closep(&pAVFormatRemux->pb);
}
avformat_free_context(pAVFormatRemux);
}
pAVFormatRemux = NULL;
// free avformatcontex
if(pAVFormatInput != NULL) {
AVFormatCtxSerializer::freeCtx(pAVFormatInput);
pAVFormatInput = NULL;
}
pAVFormatInput = NULL;
}
protected: protected:
void run() void run()
{ {
...@@ -354,8 +376,17 @@ protected: ...@@ -354,8 +376,17 @@ protected:
ret = av_interleaved_write_frame(pAVFormatRemux, &packet); ret = av_interleaved_write_frame(pAVFormatRemux, &packet);
av_packet_unref(&packet); av_packet_unref(&packet);
if (ret < 0) { if (ret < 0) {
spdlog::error("error muxing packet: {}", av_err2str(ret)); spdlog::error("error muxing packet: {}, {}, {}, {}, restreaming...", av_err2str(ret), packet.dts, packet.pts, packet.dts==AV_NOPTS_VALUE);
exit(1); if(pktCnt != 0 && packet.pts == AV_NOPTS_VALUE) {
// reset
av_write_trailer(pAVFormatRemux);
this_thread::sleep_for(chrono::seconds(5));
freeStream();
getInputFormat();
setupStream();
pktCnt = 0;
continue;
}
} }
} }
av_write_trailer(pAVFormatRemux); av_write_trailer(pAVFormatRemux);
...@@ -373,6 +404,7 @@ public: ...@@ -373,6 +404,7 @@ public:
{ {
init(); init();
setupMq(); setupMq();
getInputFormat();
setupStream(); setupStream();
} }
...@@ -394,11 +426,8 @@ public: ...@@ -394,11 +426,8 @@ public:
zmq_ctx_destroy(pSub); zmq_ctx_destroy(pSub);
pDealerCtx = NULL; pDealerCtx = NULL;
} }
// free avformatcontex
if(pAVFormatInput != NULL) { freeStream();
AVFormatCtxSerializer::freeCtx(pAVFormatInput);
pAVFormatInput = NULL;
}
} }
}; };
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论