|
|
@@ -1,29 +1,22 @@
|
|
|
-
|
|
|
-#include <windows.h>
|
|
|
-
|
|
|
-#include "MediaSourceRtsp.h"
|
|
|
-
|
|
|
-
|
|
|
-int main(int argc, char** argv)
|
|
|
+#include "MediaSourceMain.h"
|
|
|
+#include <conio.h>
|
|
|
+#define DELETE_OBJECT(obj) if (obj) { delete obj; obj = NULL; }
|
|
|
+#define mygetch getch
|
|
|
+AppClass::AppClass(std::string src, std::string dst, std::string transport)
|
|
|
+{
|
|
|
+ m_sSrc = src;
|
|
|
+ m_sDst = dst;
|
|
|
+ m_sTransport = transport;
|
|
|
+}
|
|
|
+void AppClass::Action()
|
|
|
{
|
|
|
-
|
|
|
- if (argc != 4) {
|
|
|
-
|
|
|
- printf("Failed\n");
|
|
|
- printf("RtspPush [src_rtsp] [out_rtsp] [tcp/udp]\n");
|
|
|
- printf("[src_rtsp] input rtsp\n");
|
|
|
- printf("[src_rtsp] output rtsp\n");
|
|
|
- return 0;
|
|
|
- }
|
|
|
-
|
|
|
CMediaSourceRtsp pusher;
|
|
|
- pusher.m_Input_rtsp = std::string(argv[1]);
|
|
|
- pusher.m_Output_rtsp = std::string(argv[2]);
|
|
|
+ pusher.m_Input_rtsp = m_sSrc;
|
|
|
+ pusher.m_Output_rtsp = m_sDst;
|
|
|
|
|
|
- std::string tcporudp = std::string(argv[3]);
|
|
|
- if ((tcporudp == "TCP") || (tcporudp == "tcp"))
|
|
|
+ if ((m_sTransport == "TCP") || (m_sTransport == "tcp"))
|
|
|
pusher.m_TcpOrudp = "tcp";
|
|
|
- if ((tcporudp == "UDP") || (tcporudp == "udp"))
|
|
|
+ if ((m_sTransport == "UDP") || (m_sTransport == "udp"))
|
|
|
pusher.m_TcpOrudp = "udp";
|
|
|
|
|
|
if (!pusher.OpenInput(pusher.m_Input_rtsp, pusher.m_TcpOrudp)) {
|
|
|
@@ -38,8 +31,8 @@ int main(int argc, char** argv)
|
|
|
|
|
|
int ret = -1;
|
|
|
|
|
|
- while (true) {
|
|
|
-
|
|
|
+ while (!IsAborted()) {
|
|
|
+
|
|
|
std::shared_ptr<AVPacket> packet = nullptr;
|
|
|
|
|
|
packet = pusher.ReadPacket();
|
|
|
@@ -52,14 +45,68 @@ int main(int argc, char** argv)
|
|
|
}
|
|
|
|
|
|
if ((packet) && (packet->stream_index == pusher.m_nVideoStream)) {
|
|
|
-
|
|
|
+
|
|
|
ret = pusher.WritePacket(packet);
|
|
|
|
|
|
if (ret < 0) {
|
|
|
-
|
|
|
+
|
|
|
pusher.CheckOutputNet();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+}
|
|
|
+std::string LoadConfigFile()
|
|
|
+{
|
|
|
+ FILE* pf = fopen("rtsp_config.config", "rb+");
|
|
|
+ if (!pf) {
|
|
|
+ printf("open rtsp_config.config failed\n");
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ fseek(pf, 0, SEEK_END);
|
|
|
+ long lSize = ftell(pf);
|
|
|
+ char* text = new char[lSize];
|
|
|
+ rewind(pf);
|
|
|
+ fread(text, sizeof(char), lSize, pf);
|
|
|
+ std::string filedata = std::string(text, lSize);
|
|
|
+ delete[] text;
|
|
|
+ fclose(pf);
|
|
|
+ return filedata;
|
|
|
+}
|
|
|
+
|
|
|
+int main(int argc, char** argv)
|
|
|
+{
|
|
|
+ std::string filedata = LoadConfigFile();
|
|
|
+ if (filedata == "") {
|
|
|
+ printf("load rtsp_config.config failed\n");
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ nlohmann::json j = nlohmann::json::parse(filedata);
|
|
|
+
|
|
|
+ std::vector<AppClass*> pApp;
|
|
|
+ for (int i = 0; i < j["config"].size(); i++) {
|
|
|
+ std::string src = j["config"][i]["src_rtsp"];
|
|
|
+ std::string dst = j["config"][i]["dst_rtsp"];
|
|
|
+ std::string transport = j["config"][i]["rtsp_transport"];
|
|
|
+
|
|
|
+ AppClass* p = new AppClass(src,dst,transport);
|
|
|
+ p->Start();
|
|
|
+ pApp.emplace_back(p);
|
|
|
+ }
|
|
|
+
|
|
|
+ char c;
|
|
|
+ while (1) {
|
|
|
+ c = mygetch();
|
|
|
+ if (c != 'q') {
|
|
|
+ std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ std::vector<AppClass*>::iterator iter = pApp.begin();
|
|
|
+ for (; iter != pApp.end();) {
|
|
|
+ DELETE_OBJECT((*iter));
|
|
|
+ iter = pApp.erase(iter);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
return 0;
|
|
|
}
|