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

init

上级 978e8480
#pragma GCC diagnostic ignored "-Wunused-private-field" #pragma GCC diagnostic ignored "-Wunused-private-field"
#pragma GCC diagnostic ignored "-Wunused-variable" #pragma GCC diagnostic ignored "-Wunused-variable"
#include <stdlib.h> #include <stdlib.h>
#include <string> #include <string>
#include <thread> #include <thread>
...@@ -47,7 +46,7 @@ private: ...@@ -47,7 +46,7 @@ private:
while(!inited) { while(!inited) {
// TODO: req config // TODO: req config
bool found = false; bool found = false;
try{ try {
config = json::parse(cloudutils::config); config = json::parse(cloudutils::config);
spdlog::info("config: {:s}", config.dump()); spdlog::info("config: {:s}", config.dump());
json evpusher; json evpusher;
...@@ -108,7 +107,8 @@ private: ...@@ -108,7 +107,8 @@ private:
return 0; return 0;
} }
int ping(){ int ping()
{
// send hello to router // send hello to router
int ret = 0; int ret = 0;
vector<vector<uint8_t> >body; vector<vector<uint8_t> >body;
...@@ -121,7 +121,8 @@ private: ...@@ -121,7 +121,8 @@ private:
if(ret < 0) { if(ret < 0) {
spdlog::error("evpusher {} {} failed to send multiple: {}", devSn, iid, zmq_strerror(zmq_errno())); spdlog::error("evpusher {} {} failed to send multiple: {}", devSn, iid, zmq_strerror(zmq_errno()));
//TODO: //TODO:
}else{ }
else {
spdlog::info("evpusher {} {} sent hello to router: {}", devSn, iid, mgrSn); spdlog::info("evpusher {} {} sent hello to router: {}", devSn, iid, mgrSn);
} }
...@@ -162,7 +163,7 @@ private: ...@@ -162,7 +163,7 @@ private:
} }
//ping //ping
ret = ping(); ret = ping();
thPing = thread([&,this](){ thPing = thread([&,this]() {
while(true) { while(true) {
this_thread::sleep_for(chrono::seconds(EV_HEARTBEAT_SECONDS-2)); this_thread::sleep_for(chrono::seconds(EV_HEARTBEAT_SECONDS-2));
ping(); ping();
...@@ -174,7 +175,8 @@ private: ...@@ -174,7 +175,8 @@ private:
return ret; return ret;
} }
int getInputFormat(){ int getInputFormat()
{
int ret = 0; int ret = 0;
// req avformatcontext packet // req avformatcontext packet
// send hello to puller // send hello to puller
...@@ -205,20 +207,24 @@ private: ...@@ -205,20 +207,24 @@ private:
} }
this_thread::sleep_for(chrono::seconds(5)); this_thread::sleep_for(chrono::seconds(5));
failedCnt++; failedCnt++;
}else{ }
else {
spdlog::error("evpusher {} {}, received bad size zmq msg for avformatctx: {}", devSn, iid, v.size()); spdlog::error("evpusher {} {}, received bad size zmq msg for avformatctx: {}", devSn, iid, v.size());
} }
}else if(body2str(v[0]) != pullerGid) { }
else if(body2str(v[0]) != pullerGid) {
spdlog::error("evpusher {} {}, invalid sender for avformatctx: {}, should be: {}", devSn, iid, body2str(v[0]), pullerGid); spdlog::error("evpusher {} {}, invalid sender for avformatctx: {}, should be: {}", devSn, iid, body2str(v[0]), pullerGid);
}else{ }
try{ else {
try {
auto cmd = json::parse(body2str(v[1])); auto cmd = json::parse(body2str(v[1]));
if(cmd["type"].get<string>() == EV_MSG_META_AVFORMATCTX){ if(cmd["type"].get<string>() == EV_MSG_META_AVFORMATCTX) {
pAVFormatInput = (AVFormatContext *)malloc(sizeof(AVFormatContext)); pAVFormatInput = (AVFormatContext *)malloc(sizeof(AVFormatContext));
AVFormatCtxSerializer::decode((char *)(v[2].data()), v[2].size(), pAVFormatInput); AVFormatCtxSerializer::decode((char *)(v[2].data()), v[2].size(), pAVFormatInput);
gotFormat = true; gotFormat = true;
} }
}catch(exception &e) { }
catch(exception &e) {
spdlog::error("evpusher {} {}, exception in parsing avformatctx packet: {}", devSn, iid, e.what()); spdlog::error("evpusher {} {}, exception in parsing avformatctx packet: {}", devSn, iid, e.what());
} }
} }
...@@ -277,7 +283,7 @@ private: ...@@ -277,7 +283,7 @@ private:
av_dump_format(pAVFormatRemux, 0, urlOut.c_str(), 1); av_dump_format(pAVFormatRemux, 0, urlOut.c_str(), 1);
if (!(pAVFormatRemux->oformat->flags & AVFMT_NOFILE)) { if (!(pAVFormatRemux->oformat->flags & AVFMT_NOFILE)) {
spdlog::error("evpusher {} {} failed allocating output stream", devSn ,iid); spdlog::error("evpusher {} {} failed allocating output stream", devSn,iid);
ret = avio_open2(&pAVFormatRemux->pb, urlOut.c_str(), AVIO_FLAG_WRITE, NULL, &pOptsRemux); ret = avio_open2(&pAVFormatRemux->pb, urlOut.c_str(), AVIO_FLAG_WRITE, NULL, &pOptsRemux);
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);
...@@ -299,10 +305,10 @@ private: ...@@ -299,10 +305,10 @@ private:
return ret; return ret;
} }
void freeStream(){ void freeStream()
// close output context
if(pAVFormatRemux)
{ {
// close output context
if(pAVFormatRemux) {
if(pAVFormatRemux->pb) { if(pAVFormatRemux->pb) {
avio_closep(&pAVFormatRemux->pb); avio_closep(&pAVFormatRemux->pb);
} }
...@@ -362,7 +368,6 @@ protected: ...@@ -362,7 +368,6 @@ protected:
out_stream = pAVFormatRemux->streams[packet.stream_index]; out_stream = pAVFormatRemux->streams[packet.stream_index];
//calc pts //calc pts
{
if(pktCnt % (18*60*5) == 0) { if(pktCnt % (18*60*5) == 0) {
spdlog::info("seq: {:lld}, pts: {:lld}, dts: {:lld}, dur: {:lld}, idx: {:d}", pktCnt, packet.pts, packet.dts, packet.duration, packet.stream_index); spdlog::info("seq: {:lld}, pts: {:lld}, dts: {:lld}, dur: {:lld}, idx: {:d}", pktCnt, packet.pts, packet.dts, packet.duration, packet.stream_index);
} }
...@@ -372,13 +377,13 @@ protected: ...@@ -372,13 +377,13 @@ protected:
packet.dts = 0; packet.dts = 0;
packet.duration = 0; packet.duration = 0;
packet.pos = -1; packet.pos = -1;
}else{ }
else {
packet.pts = av_rescale_q_rnd(packet.pts, in_stream->time_base, out_stream->time_base, (AVRounding)(AV_ROUND_NEAR_INF | AV_ROUND_PASS_MINMAX)); packet.pts = av_rescale_q_rnd(packet.pts, in_stream->time_base, out_stream->time_base, (AVRounding)(AV_ROUND_NEAR_INF | AV_ROUND_PASS_MINMAX));
packet.dts = av_rescale_q_rnd(packet.dts, in_stream->time_base, out_stream->time_base, (AVRounding)(AV_ROUND_NEAR_INF | AV_ROUND_PASS_MINMAX)); packet.dts = av_rescale_q_rnd(packet.dts, in_stream->time_base, out_stream->time_base, (AVRounding)(AV_ROUND_NEAR_INF | AV_ROUND_PASS_MINMAX));
packet.duration = av_rescale_q(packet.duration, in_stream->time_base, out_stream->time_base); packet.duration = av_rescale_q(packet.duration, in_stream->time_base, out_stream->time_base);
packet.pos = -1; packet.pos = -1;
} }
}
ret = av_interleaved_write_frame(pAVFormatRemux, &packet); ret = av_interleaved_write_frame(pAVFormatRemux, &packet);
av_packet_unref(&packet); av_packet_unref(&packet);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论