Skip to content

Commit

Permalink
move multicast url decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
mpromonet committed Feb 17, 2024
1 parent 0645e3c commit e2ad168
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 28 deletions.
37 changes: 36 additions & 1 deletion inc/V4l2RTSPServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,42 @@ class V4l2RTSPServer {
return this->addSession(url, subSession);
}


void decodeMulticastUrl(const std::string & maddr, in_addr & destinationAddress, unsigned short & rtpPortNum, unsigned short & rtcpPortNum)
{
std::istringstream is(maddr);
std::string ip;
getline(is, ip, ':');
if (!ip.empty())
{
destinationAddress.s_addr = inet_addr(ip.c_str());
} else {
destinationAddress.s_addr = chooseRandomIPv4SSMAddress(*this->env());
}

rtpPortNum = 20000;
std::string port;
getline(is, port, ':');
if (!port.empty())
{
rtpPortNum = atoi(port.c_str());
}
rtcpPortNum = rtpPortNum+1;
getline(is, port, ':');
if (!port.empty())
{
rtcpPortNum = atoi(port.c_str());
}
}

ServerMediaSession* AddMulticastSession(const std::string& url, std::string& multicasturi, StreamReplicator* videoReplicator, StreamReplicator* audioReplicator) {
struct in_addr destinationAddress;
unsigned short rtpPortNum;
unsigned short rtcpPortNum;
this->decodeMulticastUrl(multicasturi, destinationAddress, rtpPortNum, rtcpPortNum);
multicasturi = inet_ntoa(destinationAddress) + std::string(":") + std::to_string(rtpPortNum) + std::string(":") + std::to_string(rtcpPortNum);
return this->AddMulticastSession(url, destinationAddress, rtpPortNum, rtcpPortNum, videoReplicator, audioReplicator);
}

// -----------------------------------------
// get rtsp url
// -----------------------------------------
Expand Down
30 changes: 3 additions & 27 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,29 +45,6 @@ void sighandler(int n)
quit =1;
}

// -------------------------------------------------------
// decode multicast url <group>:<rtp_port>:<rtcp_port>
// -------------------------------------------------------
void decodeMulticastUrl(const std::string & maddr, in_addr & destinationAddress, unsigned short & rtpPortNum, unsigned short & rtcpPortNum)
{
std::istringstream is(maddr);
std::string ip;
getline(is, ip, ':');
if (!ip.empty())
{
destinationAddress.s_addr = inet_addr(ip.c_str());
}

std::string port;
getline(is, port, ':');
rtpPortNum = 20000;
if (!port.empty())
{
rtpPortNum = atoi(port.c_str());
}
rtcpPortNum = rtpPortNum+1;
}

// -------------------------------------------------------
// split video,audio device
// -------------------------------------------------------
Expand Down Expand Up @@ -280,10 +257,9 @@ int main(int argc, char** argv)
{
// decode multicast info
struct in_addr destinationAddress;
destinationAddress.s_addr = chooseRandomIPv4SSMAddress(*rtspServer.env());
unsigned short rtpPortNum = 20000;
unsigned short rtcpPortNum = rtpPortNum+1;
decodeMulticastUrl(maddr, destinationAddress, rtpPortNum, rtcpPortNum);
unsigned short rtpPortNum;
unsigned short rtcpPortNum;
rtspServer.decodeMulticastUrl(maddr, destinationAddress, rtpPortNum, rtcpPortNum);

std::list<V4l2Output*> outList;
int nbSource = 0;
Expand Down

0 comments on commit e2ad168

Please sign in to comment.