提交 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];
...@@ -472,32 +485,39 @@ protected: ...@@ -472,32 +485,39 @@ protected:
// lastPts = packet.dts; // lastPts = packet.dts;
// } // }
// spdlog::info("evpusher {} packet new pts: {} dts: {}", selfId, packet.pts, packet.dts); // spdlog::info("evpusher {} packet new pts: {} dts: {}", selfId, packet.pts, packet.dts);
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++;
json meta; if(ret != -22){
json data; string msg = fmt::format("evpusher {} error write stream, restreaming: {} ,{}", selfId, ret, av_err2str(ret));
data["msg"] = msg; //if(failedCnt % 2 == 0) {
data["modId"] = selfId; json meta;
data["type"] = EV_MSG_META_TYPE_REPORT; json data;
data["level"] = EV_MSG_META_VALUE_REPORT_LEVEL_ERROR; data["msg"] = msg;
meta["type"] = EV_MSG_META_TYPE_REPORT; data["modId"] = selfId;
meta["value"] = EV_MSG_META_VALUE_REPORT_LEVEL_ERROR; data["type"] = EV_MSG_META_TYPE_REPORT;
z_send(pDaemon, "evcloudsvc", meta.dump(), data.dump()); data["level"] = EV_MSG_META_VALUE_REPORT_LEVEL_ERROR;
meta["type"] = EV_MSG_META_TYPE_REPORT;
spdlog::error("evpusher {} error muxing packet: {}, {}, {}, {}, restreaming...", selfId, av_err2str(ret), packet.dts, packet.pts, packet.dts==AV_NOPTS_VALUE); meta["value"] = EV_MSG_META_VALUE_REPORT_LEVEL_ERROR;
if(packet.pts == AV_NOPTS_VALUE) { z_send(pDaemon, "evcloudsvc", meta.dump(), data.dump());
// reset // }
// av_write_trailer(pAVFormatRemux);
freeStream(); spdlog::error(msg);
getInputFormat(); if(packet.pts == AV_NOPTS_VALUE) {
setupStream(); // reset
pktCnt = 0; // av_write_trailer(pAVFormatRemux);
continue; freeStream();
} getInputFormat();
setupStream();
pktCnt = 0;
bInited = false;
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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论