Skip to content

Commit

Permalink
cleanup & keep one constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
mpromonet committed May 1, 2024
1 parent ca98ba0 commit 834115d
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 64 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ccpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4
- name: cmake
run: cmake .
- name: make
Expand Down
File renamed without changes.
5 changes: 1 addition & 4 deletions inc/rtspconnectionclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ class RTSPConnection
RTSP_CALLBACK(DESCRIBE, resultCode, resultString);
RTSP_CALLBACK(SETUP, resultCode, resultString);
RTSP_CALLBACK(PLAY, resultCode, resultString);
RTSP_CALLBACK(PAUSE, resultCode, resultString);
RTSP_CALLBACK(TEARDOWN, resultCode, resultString);

TASK_CALLBACK(RTSPConnection::RTSPClientConnection,ConnectionTimeout);
Expand All @@ -117,15 +116,13 @@ class RTSPConnection
MediaSubsessionIterator* m_subSessionIter;
Callback* m_callback;
unsigned int m_nbPacket;
int m_playforinit;
double m_nptStartTime;
std::string m_clockStartTime;

};

public:
RTSPConnection(Environment& env, Callback* callback, const char* rtspURL, const std::map<std::string,std::string> & opts, int verbosityLevel = 1);
RTSPConnection(Environment& env, Callback* callback, const char* rtspURL, int timeout = 5, int rtptransport = RTPUDPUNICAST, int verbosityLevel = 1);
RTSPConnection(Environment& env, Callback* callback, const char* rtspURL, const std::map<std::string,std::string> & opts = std::map<std::string,std::string>(), int verbosityLevel = 1);
virtual ~RTSPConnection();

void start(unsigned int delay = 0);
Expand Down
14 changes: 8 additions & 6 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,10 @@ int main(int argc, char *argv[])
{
// default value
int timeout = 10;
int rtptransport = RTSPConnection::RTPUDPUNICAST;
std::string rtptransport = "udp";
int logLevel = 255;
std::string output;
std::map<std::string,std::string> opts;

// decode args
int c = 0;
Expand All @@ -164,20 +165,21 @@ int main(int argc, char *argv[])
case 't': timeout= atoi(optarg); break;
case 'o': output = optarg; break;

case 'M': rtptransport = RTSPConnection::RTPUDPMULTICAST; break;
case 'T': rtptransport = RTSPConnection::RTPOVERTCP; break;
case 'H': rtptransport = RTSPConnection::RTPOVERHTTP; break;
case 'M': rtptransport = "multicast"; break;
case 'T': rtptransport = "tcp" ; break;
case 'H': rtptransport = "http" ; break;
}
}
opts["timeout"] = std::to_string(timeout);
opts["rtptransport"] = rtptransport;

if (optind<argc)
{
Environment env(stop);
std::string url = argv[optind];
if ( (url.find("rtsp://") == 0) || (url.find("rtsps://") == 0) ) {
RTSPCallback cb(output);
RTSPConnection rtspClient(env, &cb, url.c_str(), timeout, rtptransport, logLevel);
rtspClient.start();
RTSPConnection rtspClient(env, &cb, url.c_str(), opts, logLevel);

signal(SIGINT, sig_handler);
std::cout << "Start mainloop" << std::endl;
Expand Down
57 changes: 4 additions & 53 deletions src/rtspconnectionclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,6 @@
#include <sstream>


RTSPConnection::RTSPConnection(Environment& env, Callback* callback, const char* rtspURL, int timeout, int rtptransport, int verbosityLevel)
: m_startCallbackTask(NULL)
, m_stopCallbackTask(NULL)
, m_env(env)
, m_callback(callback)
, m_url(rtspURL)
, m_timeout(timeout)
, m_rtptransport(rtptransport)
, m_verbosity(verbosityLevel)
, m_rtspClient(NULL)
{
}

RTSPConnection::RTSPConnection(Environment& env, Callback* callback, const char* rtspURL, const std::map<std::string,std::string> & opts, int verbosityLevel)
: m_startCallbackTask(NULL)
, m_stopCallbackTask(NULL)
Expand Down Expand Up @@ -93,7 +80,7 @@ int getHttpTunnelPort(int rtptransport, const char* rtspURL)
if (pos != std::string::npos) {
url.erase(0,pos+1);
httpTunnelPort = std::stoi(url);
}
}
}
return httpTunnelPort;
}
Expand Down Expand Up @@ -165,7 +152,6 @@ std::string getParamValue(const std::string& url, const std::string& param) {
void RTSPConnection::RTSPClientConnection::setNptstartTime()
{
m_nptStartTime = 0;
m_playforinit = 0;
m_clockStartTime = "";
std::string urlStr = m_connection.getUrl();

Expand Down Expand Up @@ -223,15 +209,12 @@ void RTSPConnection::RTSPClientConnection::sendNextCommand()
envir() << " clockstarttime is given read video from it :: m_clockStartTime " << m_clockStartTime.c_str() << "\n";
}
if (m_clockStartTime != "") {
m_playforinit = 1;
this->sendPlayCommand(*m_session, continueAfterPLAY, m_clockStartTime.c_str());
}
else if (m_nptStartTime > 0) {
m_playforinit = 1;
this->sendPlayCommand(*m_session, continueAfterPLAY, m_nptStartTime);
}
else {
m_playforinit = 0;
this->sendPlayCommand(*m_session, continueAfterPLAY);
}
}
Expand Down Expand Up @@ -311,48 +294,16 @@ void RTSPConnection::RTSPClientConnection::continueAfterPLAY(int resultCode, cha
}
else
{
if (m_playforinit > 0)
if (fVerbosityLevel > 1)
{
envir() << "PLAY INIT OK" << "\n";
this->sendPauseCommand(*m_session, continueAfterPAUSE);
}
else {
if (fVerbosityLevel > 1)
{
envir() << "PLAY OK" << "\n";
}
m_DataArrivalTimeoutTask = envir().taskScheduler().scheduleDelayedTask(m_timeout*1000000, TaskDataArrivalTimeout, this);
envir() << "PLAY OK" << "\n";
}
m_DataArrivalTimeoutTask = envir().taskScheduler().scheduleDelayedTask(m_timeout*1000000, TaskDataArrivalTimeout, this);
}
envir().taskScheduler().unscheduleDelayedTask(m_ConnectionTimeoutTask);
delete[] resultString;
}

void RTSPConnection::RTSPClientConnection::continueAfterPAUSE(int resultCode, char* resultString)
{
if (resultCode != 0)
{
envir() << "Failed to PLAUSE: " << resultString << "\n";
m_callback->onError(m_connection, resultString);
}
else if (m_playforinit > 0)
{
m_playforinit = 0;
if (m_clockStartTime != "") {
envir() << " continueAfterPAUSE m_clockStartTime " << m_clockStartTime.c_str() << "\n";
this->sendPlayCommand(*m_session, continueAfterPLAY, m_clockStartTime.c_str());
}
else if (m_nptStartTime > 0) {
envir() << " continueAfterPAUSE m_nptStartTime: " << m_nptStartTime << "\n";
this->sendPlayCommand(*m_session, continueAfterPLAY, m_nptStartTime);
}
else {
this->sendPlayCommand(*m_session, continueAfterPLAY);
}
}
delete[] resultString;
}

void RTSPConnection::RTSPClientConnection::continueAfterTEARDOWN(int resultCode, char* resultString)
{
if (resultCode != 0)
Expand Down

0 comments on commit 834115d

Please sign in to comment.