RTSP: Choose random port, extra debugging messages
This commit is contained in:
parent
b068d53e2a
commit
ad31299def
1 changed files with 18 additions and 9 deletions
|
@ -12,6 +12,7 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
@ -116,26 +117,34 @@ int RTSP_Handler( Socket::Connection conn ) {
|
||||||
} else {
|
} else {
|
||||||
HTTP_S.SetHeader( "CSeq", HTTP_R.GetHeader( "CSeq" ).c_str() );
|
HTTP_S.SetHeader( "CSeq", HTTP_R.GetHeader( "CSeq" ).c_str() );
|
||||||
HTTP_S.SetHeader( "Session", time(NULL) );
|
HTTP_S.SetHeader( "Session", time(NULL) );
|
||||||
/// \todo "Random" generation of server_ports
|
|
||||||
/// \todo Add support for audio
|
/// \todo Add support for audio
|
||||||
// if( HTTP_R.url.find( "audio" ) != std::string::npos ) {
|
// if( HTTP_R.url.find( "audio" ) != std::string::npos ) {
|
||||||
// HTTP_S.SetHeader( "Transport", HTTP_R.GetHeader( "Transport" ) + ";server_port=50002-50003" );
|
// HTTP_S.SetHeader( "Transport", HTTP_R.GetHeader( "Transport" ) + ";server_port=50002-50003" );
|
||||||
// } else {
|
// } else {
|
||||||
//send video data
|
|
||||||
HTTP_S.SetHeader( "Transport", HTTP_R.GetHeader( "Transport" ) + ";server_port=50000-50001" );
|
|
||||||
//Stub data for testing purposes. This should now be extracted somehow from DTSC::DTMI
|
//Stub data for testing purposes. This should now be extracted somehow from DTSC::DTMI
|
||||||
VideoParams.SetOwnTimestampUnit( ( 1.0 / 29.917 ) * 90000.0 );
|
VideoParams.SetOwnTimestampUnit( ( 1.0 / 29.917 ) * 90000.0 );
|
||||||
VideoParams.SetMaximumPacketSize( 10000 );
|
VideoParams.SetMaximumPacketSize( 10000 );
|
||||||
//pick the right port here
|
|
||||||
VideoTransParams.SetPortbase( 50000 );
|
|
||||||
//create a JRTPlib session
|
//create a JRTPlib session
|
||||||
int VideoStatus = VideoSession.Create( VideoParams, &VideoTransParams, jrtplib::RTPTransmitter::IPv6UDPProto );
|
int VideoStatus;
|
||||||
|
uint16_t pbase;
|
||||||
|
//after 20 retries, just give up, most ports are likely in use
|
||||||
|
int retries = 20;
|
||||||
|
do {
|
||||||
|
//pick the right port here in the range 5000 to 5000 + 2 * 500 = 6000
|
||||||
|
pbase = 5000 + 2 * (rand() % 500);
|
||||||
|
VideoTransParams.SetPortbase( pbase );
|
||||||
|
VideoStatus = VideoSession.Create( VideoParams, &VideoTransParams, jrtplib::RTPTransmitter::IPv6UDPProto );
|
||||||
|
} while(VideoStatus < 0 && --retries > 0);
|
||||||
if( VideoStatus < 0 ) {
|
if( VideoStatus < 0 ) {
|
||||||
std::cerr << jrtplib::RTPGetErrorString( VideoStatus ) << std::endl;
|
std::cerr << "Video session could not be created: " << jrtplib::RTPGetErrorString( VideoStatus ) << std::endl;
|
||||||
exit( -1 );
|
exit( -1 );
|
||||||
} else {
|
} else {
|
||||||
std::cerr << "Created video session\n";
|
std::cerr << "Created video session using ports " << pbase << " and " << (pbase+1) << "\n";
|
||||||
}
|
}
|
||||||
|
//send video data
|
||||||
|
std::stringstream transport;
|
||||||
|
transport << HTTP_R.GetHeader( "Transport" ) << ";server_port=" << pbase << "-" << (pbase+1);
|
||||||
|
HTTP_S.SetHeader( "Transport", transport.str() );
|
||||||
|
|
||||||
/// \todo Connect with clients other than localhost
|
/// \todo Connect with clients other than localhost
|
||||||
uint8_t localip[32];
|
uint8_t localip[32];
|
||||||
|
@ -147,7 +156,7 @@ int RTSP_Handler( Socket::Connection conn ) {
|
||||||
//add the destination address to the VideoSession
|
//add the destination address to the VideoSession
|
||||||
VideoStatus = VideoSession.AddDestination(addr);
|
VideoStatus = VideoSession.AddDestination(addr);
|
||||||
if (VideoStatus < 0) {
|
if (VideoStatus < 0) {
|
||||||
std::cerr << jrtplib::RTPGetErrorString(VideoStatus) << std::endl;
|
std::cerr << "Destination could not be set: " << jrtplib::RTPGetErrorString(VideoStatus) << std::endl;
|
||||||
exit(-1);
|
exit(-1);
|
||||||
} else {
|
} else {
|
||||||
std::cerr << "Destination Set\n";
|
std::cerr << "Destination Set\n";
|
||||||
|
|
Loading…
Add table
Reference in a new issue