提交 9b652a29 authored 作者: blu's avatar blu

feature: report msg

上级 d246d0a1
...@@ -30,6 +30,7 @@ private: ...@@ -30,6 +30,7 @@ private:
string urlOut, urlPub, urlDealer, devSn, pullerGid, mgrSn, selfId; string urlOut, urlPub, urlDealer, devSn, pullerGid, mgrSn, selfId;
int iid; int iid;
int *streamList = nullptr; int *streamList = nullptr;
AVDictionary *pOptsRemux = nullptr;
AVFormatContext *pAVFormatRemux = nullptr; AVFormatContext *pAVFormatRemux = nullptr;
AVFormatContext *pAVFormatInput = nullptr; AVFormatContext *pAVFormatInput = nullptr;
json config; json config;
...@@ -303,7 +304,6 @@ private: ...@@ -303,7 +304,6 @@ private:
int setupStream() int setupStream()
{ {
int ret = 0; int ret = 0;
AVDictionary *pOptsRemux = nullptr;
string proto = urlOut.substr(0, 4); string proto = urlOut.substr(0, 4);
if(proto == "rtsp") { if(proto == "rtsp") {
// rtsp tcp // rtsp tcp
...@@ -376,23 +376,6 @@ private: ...@@ -376,23 +376,6 @@ private:
} }
} }
ret = avformat_write_header(pAVFormatRemux, &pOptsRemux);
if (ret < 0) {
// TODO: report message to cloud
string msg = fmt::format("evpusher {} failed to write stream \"{}\": {}", selfId, urlOut, av_err2str(ret));
json meta;
json data;
data["msg"] = msg;
data["modId"] = selfId;
data["type"] = EV_MSG_META_TYPE_REPORT;
data["level"] = EV_MSG_META_VALUE_REPORT_LEVEL_FATAL;
meta["type"] = EV_MSG_META_TYPE_REPORT;
meta["value"] = EV_MSG_META_VALUE_REPORT_LEVEL_FATAL;
z_send(pDaemon, "evcloudsvc", meta.dump(), data.dump());
spdlog::error(msg);
exit(1);
}
return ret; return ret;
} }
...@@ -422,6 +405,12 @@ protected: ...@@ -422,6 +405,12 @@ protected:
zmq_msg_t msg; zmq_msg_t msg;
AVPacket packet; AVPacket packet;
uint64_t pktCnt = 0; uint64_t pktCnt = 0;
uint64_t failedCnt = 0, lastFailedCnt = 0;
// const uint64_t PKT_SKIP = 38;
bool bInited = false;
setupStream();
while (true) { while (true) {
ret =zmq_msg_init(&msg); ret =zmq_msg_init(&msg);
if(ret != 0) { if(ret != 0) {
...@@ -451,6 +440,30 @@ protected: ...@@ -451,6 +440,30 @@ protected:
zmq_msg_close(&msg); zmq_msg_close(&msg);
spdlog::debug("packet stream indx: {:d}", packet.stream_index); spdlog::debug("packet stream indx: {:d}", packet.stream_index);
if(!bInited) {
ret = avformat_write_header(pAVFormatRemux, &pOptsRemux);
// -1482175736, Server returned 4XX Client Error, but not one of 40{0,1,3,4}
// ignore 406 error
if (ret < 0 && ret != -1482175736) {
// TODO: report message to cloud
string msg = fmt::format("evpusher {} failed to write stream \"{}\": {}, {}", selfId, urlOut, ret, av_err2str(ret));
json meta;
json data;
data["msg"] = msg;
data["modId"] = selfId;
data["type"] = EV_MSG_META_TYPE_REPORT;
data["level"] = EV_MSG_META_VALUE_REPORT_LEVEL_FATAL;
meta["type"] = EV_MSG_META_TYPE_REPORT;
meta["value"] = EV_MSG_META_VALUE_REPORT_LEVEL_FATAL;
z_send(pDaemon, "evcloudsvc", meta.dump(), data.dump());
spdlog::error(msg);
exit(1);
}
bInited = true;
}
// relay // relay
AVStream *in_stream =NULL, *out_stream = nullptr; AVStream *in_stream =NULL, *out_stream = nullptr;
in_stream = pAVFormatInput->streams[packet.stream_index]; in_stream = pAVFormatInput->streams[packet.stream_index];
...@@ -475,9 +488,13 @@ protected: ...@@ -475,9 +488,13 @@ protected:
ret = av_interleaved_write_frame(pAVFormatRemux, &packet); ret = av_interleaved_write_frame(pAVFormatRemux, &packet);
av_packet_unref(&packet); av_packet_unref(&packet);
// error write stream, restreaming: -22 ,Invalid argument
if (ret < 0) { if (ret < 0) {
// TODO: report message to cloud // TODO: report message to cloud
string msg = fmt::format("evpusher {} error write stream, trying restreaming:{}", selfId, av_err2str(ret)); failedCnt++;
if(ret != -22){
string msg = fmt::format("evpusher {} error write stream, restreaming: {} ,{}", selfId, ret, av_err2str(ret));
//if(failedCnt % 2 == 0) {
json meta; json meta;
json data; json data;
data["msg"] = msg; data["msg"] = msg;
...@@ -487,8 +504,9 @@ protected: ...@@ -487,8 +504,9 @@ protected:
meta["type"] = EV_MSG_META_TYPE_REPORT; meta["type"] = EV_MSG_META_TYPE_REPORT;
meta["value"] = EV_MSG_META_VALUE_REPORT_LEVEL_ERROR; meta["value"] = EV_MSG_META_VALUE_REPORT_LEVEL_ERROR;
z_send(pDaemon, "evcloudsvc", meta.dump(), data.dump()); z_send(pDaemon, "evcloudsvc", meta.dump(), data.dump());
// }
spdlog::error("evpusher {} error muxing packet: {}, {}, {}, {}, restreaming...", selfId, av_err2str(ret), packet.dts, packet.pts, packet.dts==AV_NOPTS_VALUE); spdlog::error(msg);
if(packet.pts == AV_NOPTS_VALUE) { if(packet.pts == AV_NOPTS_VALUE) {
// reset // reset
// av_write_trailer(pAVFormatRemux); // av_write_trailer(pAVFormatRemux);
...@@ -496,10 +514,12 @@ protected: ...@@ -496,10 +514,12 @@ protected:
getInputFormat(); getInputFormat();
setupStream(); setupStream();
pktCnt = 0; pktCnt = 0;
bInited = false;
continue; continue;
} }
} }
} }
}
av_write_trailer(pAVFormatRemux); av_write_trailer(pAVFormatRemux);
} }
...@@ -573,7 +593,7 @@ public: ...@@ -573,7 +593,7 @@ public:
thEdgeMsgHandler.detach(); thEdgeMsgHandler.detach();
getInputFormat(); getInputFormat();
setupStream(); //setupStream();
} }
~EvPusher() ~EvPusher()
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论