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

init

上级 c8c148d7
...@@ -89,7 +89,7 @@ private: ...@@ -89,7 +89,7 @@ private:
void *pPubCtx = NULL; // for packets publishing void *pPubCtx = NULL; // for packets publishing
void *pPub = NULL; void *pPub = NULL;
AVFormatContext *pAVFormatInput = NULL; AVFormatContext *pAVFormatInput = NULL;
string urlIn, urlPub; string urlIn, urlPub, urlRep;
int *streamList = NULL, numStreams = 0; int *streamList = NULL, numStreams = 0;
public: public:
...@@ -130,6 +130,12 @@ protected: ...@@ -130,6 +130,12 @@ protected:
spdlog::error("failed create avformatcontext for output: {}", av_err2str(AVERROR(ENOMEM))); spdlog::error("failed create avformatcontext for output: {}", av_err2str(AVERROR(ENOMEM)));
} }
// serialize formatctx to bytes
char *pBytes = NULL;
ret = AVFormatCtxSerializer::encode(pAVFormatInput, &pBytes);
auto repSrv = RepSrv(urlRep, pBytes, ret);
repSrv.detach();
// find all video & audio streams for remuxing // find all video & audio streams for remuxing
int i = 0, streamIdx = 0; int i = 0, streamIdx = 0;
for (; i < pAVFormatInput->nb_streams; i++) { for (; i < pAVFormatInput->nb_streams; i++) {
...@@ -144,10 +150,8 @@ protected: ...@@ -144,10 +150,8 @@ protected:
streamList[i] = streamIdx++; streamList[i] = streamIdx++;
} }
bool bStopSig = false; bool bStopSig = false;
int pktCnt = 0; uint64_t pktCnt = 0;
while (true) { while (true) {
if(checkStop() == true) { if(checkStop() == true) {
bStopSig = true; bStopSig = true;
...@@ -167,9 +171,11 @@ protected: ...@@ -167,9 +171,11 @@ protected:
av_packet_unref(&packet); av_packet_unref(&packet);
continue; continue;
} }
if(pktCnt % 1024 == 0) {
spdlog::info("pktCnt: {:d}", pktCnt);
}
pktCnt++; pktCnt++;
packet.stream_index = streamList[packet.stream_index]; packet.stream_index = streamList[packet.stream_index];
/* copy packet */ /* copy packet */
...@@ -187,6 +193,7 @@ protected: ...@@ -187,6 +193,7 @@ protected:
av_packet_unref(&packet); av_packet_unref(&packet);
} }
free(pBytes);
// TODO: // TODO:
if(ret < 0 && !bStopSig) { if(ret < 0 && !bStopSig) {
// reconnect // reconnect
...@@ -215,10 +222,11 @@ private: ...@@ -215,10 +222,11 @@ private:
json data = jr["data"]["services"]["evpuller"]; json data = jr["data"]["services"]["evpuller"];
urlIn = "rtsp://" + user + ":" + passwd + "@"+ ipc + "/h264/ch1/sub/av_stream"; urlIn = "rtsp://" + user + ":" + passwd + "@"+ ipc + "/h264/ch1/sub/av_stream";
urlPub = string("tcp://") +data["addr"].get<string>() + ":" + to_string(data["port-pub"]); urlPub = string("tcp://") +data["addr"].get<string>() + ":" + to_string(data["port-pub"]);
urlRep = string("tcp://") +data["addr"].get<string>() + ":" + to_string(data["port-rep"]);
} }
catch(exception &e) { catch(exception &e) {
bcnt = true; bcnt = true;
spdlog::error(e.what()); spdlog::error("exception in EvPuller.init {:s} retrying", e.what());
} }
if(bcnt) { if(bcnt) {
this_thread::sleep_for(chrono::milliseconds(1000*20)); this_thread::sleep_for(chrono::milliseconds(1000*20));
......
...@@ -34,10 +34,8 @@ private: ...@@ -34,10 +34,8 @@ private:
AVFormatContext *pAVFormatRemux = NULL; AVFormatContext *pAVFormatRemux = NULL;
AVFormatContext *pAVFormatInput = NULL; AVFormatContext *pAVFormatInput = NULL;
int getEnv(){ int init(){
// TODO:
//urlOut = getenv("URL_OUT");
//urlIn=
urlOut = (char*)"rtsp://40.73.41.176:554/test1"; urlOut = (char*)"rtsp://40.73.41.176:554/test1";
return 0; return 0;
} }
...@@ -81,10 +79,6 @@ private: ...@@ -81,10 +79,6 @@ private:
avlogThrow(NULL, AV_LOG_FATAL, "Failed to retrieve input stream information"); avlogThrow(NULL, AV_LOG_FATAL, "Failed to retrieve input stream information");
} }
//avformat_close_input(&pAVFormatInput);
pAVFormatInput->flags = AVFMT_FLAG_NOBUFFER | AVFMT_FLAG_FLUSH_PACKETS;
ret = avformat_alloc_output_context2(&pAVFormatRemux, NULL, "rtsp", urlOut); ret = avformat_alloc_output_context2(&pAVFormatRemux, NULL, "rtsp", urlOut);
if (ret < 0) { if (ret < 0) {
avlogThrow(NULL, AV_LOG_FATAL, "failed create avformatcontext for output: %s", av_err2str(ret)); avlogThrow(NULL, AV_LOG_FATAL, "failed create avformatcontext for output: %s", av_err2str(ret));
...@@ -217,7 +211,7 @@ protected: ...@@ -217,7 +211,7 @@ protected:
public: public:
PacketPusher() PacketPusher()
{ {
getEnv(); init();
setupMq(); setupMq();
setupStream(); setupStream();
} }
......
...@@ -256,7 +256,7 @@ namespace cloudutils ...@@ -256,7 +256,7 @@ namespace cloudutils
"code":0, "code":0,
"time":0, "time":0,
"data":{ "data":{
"ipc":"192.168.0.23", "ipc":"172.31.0.51",
"username":"admin", "username":"admin",
"password":"FWBWTU", "password":"FWBWTU",
"services":{ "services":{
...@@ -293,7 +293,7 @@ namespace cloudutils ...@@ -293,7 +293,7 @@ namespace cloudutils
} }
} }
*/ */
const char *config = "{\"code\":0,\"time\":0,\"data\":{\"ipc\":\"192.168.0.23\",\"username\":\"admin\",\"password\":\"FWBWTU\",\"services\":{\"evmgr\":{\"sn\":\"ILS-1\",\"addr\":\"0.0.0.0\",\"port-pub\":5556,\"port-rep\":5557,\"iid\":1},\"evpuller\":{\"sn\":\"ILS-2\",\"addr\":\"0.0.0.0\",\"port-pub\":5556,\"port-rep\":5557,\"iid\":2},\"evslicer\":[{\"sn\":\"ILS-3\",\"addr\":\"192.168.0.25\",\"iid\":3}],\"evml\":[{\"feature\":\"motion\",\"sn\":\"ILS-4\",\"addr\":\"192.168.0.26\",\"iid\":4}]}}}"; const char *config = "{\"code\":0,\"time\":0,\"data\":{\"ipc\":\"172.31.0.51\",\"username\":\"admin\",\"password\":\"FWBWTU\",\"services\":{\"evmgr\":{\"sn\":\"ILS-1\",\"addr\":\"0.0.0.0\",\"port-pub\":5556,\"port-rep\":5557,\"iid\":1},\"evpuller\":{\"sn\":\"ILS-2\",\"addr\":\"0.0.0.0\",\"port-pub\":5556,\"port-rep\":5557,\"iid\":2},\"evslicer\":[{\"sn\":\"ILS-3\",\"addr\":\"192.168.0.25\",\"iid\":3}],\"evml\":[{\"feature\":\"motion\",\"sn\":\"ILS-4\",\"addr\":\"192.168.0.26\",\"iid\":4}]}}}";
json registry(const char *sn, const char *scn, int iid) json registry(const char *sn, const char *scn, int iid)
{ {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论