提交 16035989 authored 作者: blu's avatar blu

feature: report msg

上级 9b652a29
...@@ -30,7 +30,6 @@ private: ...@@ -30,7 +30,6 @@ 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,8 +302,25 @@ private: ...@@ -303,8 +302,25 @@ private:
int setupStream() int setupStream()
{ {
int ret = 0; int ret = -1;
AVDictionary *pOptsRemux = nullptr;
string proto = urlOut.substr(0, 4); string proto = urlOut.substr(0, 4);
int cnt = 0;
while(ret < 0)
{
if(cnt > 3) {
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());
exit(1);
}
if(proto == "rtsp") { if(proto == "rtsp") {
// rtsp tcp // rtsp tcp
if(av_dict_set(&pOptsRemux, "rtsp_transport", "tcp", 0) < 0) { if(av_dict_set(&pOptsRemux, "rtsp_transport", "tcp", 0) < 0) {
...@@ -372,10 +388,32 @@ private: ...@@ -372,10 +388,32 @@ private:
if (ret < 0) { if (ret < 0) {
spdlog::error("evpusher {} {} could not open output file '%s'", devSn, iid, urlOut); spdlog::error("evpusher {} {} could not open output file '%s'", devSn, iid, urlOut);
// TODO: message report to cloud // TODO: message report to cloud
string msg = fmt::format("evpusher {} failed to open output 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); exit(1);
} }
} }
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, ret, av_err2str(ret));
spdlog::error(msg);
}
cnt++;
}
return ret; return ret;
} }
...@@ -405,12 +443,6 @@ protected: ...@@ -405,12 +443,6 @@ 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) {
...@@ -440,30 +472,6 @@ protected: ...@@ -440,30 +472,6 @@ 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];
...@@ -488,13 +496,9 @@ protected: ...@@ -488,13 +496,9 @@ 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
failedCnt++;
if(ret != -22){
string msg = fmt::format("evpusher {} error write stream, restreaming: {} ,{}", selfId, ret, av_err2str(ret)); 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;
...@@ -504,7 +508,6 @@ protected: ...@@ -504,7 +508,6 @@ 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(msg); spdlog::error(msg);
if(packet.pts == AV_NOPTS_VALUE) { if(packet.pts == AV_NOPTS_VALUE) {
...@@ -514,12 +517,10 @@ protected: ...@@ -514,12 +517,10 @@ protected:
getInputFormat(); getInputFormat();
setupStream(); setupStream();
pktCnt = 0; pktCnt = 0;
bInited = false;
continue; continue;
} }
} }
} }
}
av_write_trailer(pAVFormatRemux); av_write_trailer(pAVFormatRemux);
} }
...@@ -593,7 +594,9 @@ public: ...@@ -593,7 +594,9 @@ public:
thEdgeMsgHandler.detach(); thEdgeMsgHandler.detach();
getInputFormat(); getInputFormat();
//setupStream(); ret = 0;
setupStream();
} }
~EvPusher() ~EvPusher()
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论