RTSP: Blokkerig beeld, hapert veel, maar iig hebben we bewegend beeld
This commit is contained in:
parent
8511419cb7
commit
dd2222d748
1 changed files with 45 additions and 85 deletions
|
@ -22,6 +22,8 @@
|
|||
//JRTPLIB
|
||||
#include "rtp.h"
|
||||
|
||||
/// Reads a single NALU from std::cin. Expected is H.264 Bytestream format.
|
||||
/// \return The Nalu data.
|
||||
std::string ReadNALU( ) {
|
||||
static char Separator[3] = { (char)0x00, (char)0x00, (char)0x01 };
|
||||
std::string Buffer;
|
||||
|
@ -39,16 +41,9 @@ std::string ReadNALU( ) {
|
|||
/// The main function of the connector
|
||||
/// \param conn A connection with the client
|
||||
int RTSP_Handler( Socket::Connection conn ) {
|
||||
bool ready4data = false;
|
||||
FLV::Tag tag;///< Temporary tag buffer for incoming video data.
|
||||
bool PlayVideo = false;
|
||||
bool PlayAudio = true;
|
||||
bool InitVideo = false;
|
||||
bool InitAudio = true;
|
||||
bool VideoMeta = false;
|
||||
int RTPClientPort;
|
||||
int RTCPClientPort;
|
||||
bool inited;
|
||||
jrtplib::RTPSession VideoSession;
|
||||
jrtplib::RTPSessionParams VideoParams;
|
||||
jrtplib::RTPUDPv4TransmissionParams VideoTransParams;
|
||||
|
@ -59,13 +54,13 @@ int RTSP_Handler( Socket::Connection conn ) {
|
|||
while(conn.connected() && !FLV::Parse_Error) {
|
||||
if( HTTP_R.Read(conn ) ) {
|
||||
fprintf( stderr, "REQUEST:\n%s\n", HTTP_R.BuildRequest().c_str() );
|
||||
if( HTTP_R.GetHeader( "User-Agent" ).find( "RealMedia Player Version" ) != std::string::npos) {
|
||||
PerRequest = true;
|
||||
}
|
||||
// if( HTTP_R.GetHeader( "User-Agent" ).find( "RealMedia Player Version" ) != std::string::npos) {
|
||||
// PerRequest = true;
|
||||
// }
|
||||
HTTP_S.protocol = "RTSP/1.0";
|
||||
if( HTTP_R.method == "OPTIONS" ) {
|
||||
HTTP_S.SetHeader( "CSeq", HTTP_R.GetHeader( "CSeq" ).c_str() );
|
||||
HTTP_S.SetHeader( "Public", "DESCRIBE, SETUP, TEARDOWN, PLAY" );
|
||||
HTTP_S.SetHeader( "Public", "OPTIONS, DESCRIBE, SETUP, TEARDOWN, PLAY" );
|
||||
HTTP_S.SetBody( "\r\n\r\n" );
|
||||
fprintf( stderr, "RESPONSE:\n%s\n", HTTP_S.BuildResponse( "200", "OK" ).c_str() );
|
||||
conn.write( HTTP_S.BuildResponse( "200", "OK" ) );
|
||||
|
@ -76,7 +71,9 @@ int RTSP_Handler( Socket::Connection conn ) {
|
|||
} else {
|
||||
HTTP_S.SetHeader( "CSeq", HTTP_R.GetHeader( "CSeq" ).c_str() );
|
||||
HTTP_S.SetHeader( "Content-Type", "application/sdp" );
|
||||
HTTP_S.SetBody( "v=0\r\no=- 0 0 IN IP4 ddvtech.com\r\ns=Fifa Test\r\nc=IN IP4 127.0.0.1\r\nt=0 0\r\na=recvonly\r\nm=video 0 RTP/AVP 98\r\na=rtpmap:98 H264/700000\r\n\r\n" );//a=fmtp:98 packetization-mode=1\r\n\r\n" );
|
||||
/// \todo Retrieve presence of video and audio data, and process into response
|
||||
/// \todo Retrieve Packetization mode ( is 1 for now ). Where can I retrieve this?
|
||||
HTTP_S.SetBody( "v=0\r\no=- 0 0 IN IP4 ddvtech.com\r\ns=Fifa Test\r\nc=IN IP4 127.0.0.1\r\nt=0 0\r\na=recvonly\r\nm=video 0 RTP/AVP 98\r\na=control:rtsp://localhost/fifa/video\r\na=rtpmap:98 H264/90000\r\na=fmtp:98 packetization-mode=1\r\nm=audio 0 RTP/AVP 96\r\na=control:rtsp://localhost/fifa/audio\r\na=rtpmap:96 mpeg4-generic/16000/2\r\n\r\n");
|
||||
fprintf( stderr, "RESPONSE:\n%s\n", HTTP_S.BuildResponse( "200", "OK" ).c_str() );
|
||||
conn.write( HTTP_S.BuildResponse( "200", "OK" ) );
|
||||
}
|
||||
|
@ -84,16 +81,44 @@ int RTSP_Handler( Socket::Connection conn ) {
|
|||
std::string temp = HTTP_R.GetHeader("Transport");
|
||||
int ClientRTPLoc = temp.find( "client_port=" ) + 12;
|
||||
int PortSpacer = temp.find( "-", ClientRTPLoc );
|
||||
int PortEnd = ( temp.find( ";", PortSpacer ) );
|
||||
RTPClientPort = atoi( temp.substr( ClientRTPLoc, ( PortSpacer - ClientRTPLoc ) ).c_str() );
|
||||
RTCPClientPort = atoi( temp.substr( PortSpacer + 1 , ( PortEnd - ( PortSpacer + 1 ) ) ).c_str() );
|
||||
int RTPClientPort = atoi( temp.substr( ClientRTPLoc, ( PortSpacer - ClientRTPLoc ) ).c_str() );
|
||||
if( HTTP_S.GetHeader( "Session" ) != "" ) {
|
||||
fprintf( stderr, "RESPONSE:\n%s\n", HTTP_S.BuildResponse( "459", "Aggregate Operation Not Allowed" ).c_str() );
|
||||
conn.write( HTTP_S.BuildResponse( "459", "Aggregate Operation Not Allowed" ) );
|
||||
} else {
|
||||
HTTP_S.SetHeader( "CSeq", HTTP_R.GetHeader( "CSeq" ).c_str() );
|
||||
HTTP_S.SetHeader( "Session", time(NULL) );
|
||||
HTTP_S.SetHeader( "Transport", HTTP_R.GetHeader( "Transport" ) + ";server_port=50000-50001" );
|
||||
/// \todo "Random" generation of server_ports
|
||||
if( HTTP_R.url.find( "audio" ) != std::string::npos ) {
|
||||
HTTP_S.SetHeader( "Transport", HTTP_R.GetHeader( "Transport" ) + ";server_port=50002-50003" );
|
||||
} else {
|
||||
HTTP_S.SetHeader( "Transport", HTTP_R.GetHeader( "Transport" ) + ";server_port=50000-50001" );
|
||||
VideoParams.SetOwnTimestampUnit( ( 1.0 / 29.917 ) * 90000.0 );
|
||||
VideoParams.SetMaximumPacketSize( 10000 );
|
||||
//pick the right port here
|
||||
VideoTransParams.SetPortbase( 50000 );
|
||||
int VideoStatus = VideoSession.Create( VideoParams, &VideoTransParams );
|
||||
if( VideoStatus < 0 ) {
|
||||
std::cerr << jrtplib::RTPGetErrorString( VideoStatus ) << std::endl;
|
||||
exit( -1 );
|
||||
} else {
|
||||
std::cerr << "Created video session\n";
|
||||
}
|
||||
/// \todo retrieve other client than localhost --> Socket::Connection has no support for this yet?
|
||||
uint8_t localip[]={127,0,0,1};
|
||||
jrtplib::RTPIPv4Address addr(localip,RTPClientPort);
|
||||
|
||||
VideoStatus = VideoSession.AddDestination(addr);
|
||||
if (VideoStatus < 0) {
|
||||
std::cerr << jrtplib::RTPGetErrorString(VideoStatus) << std::endl;
|
||||
exit(-1);
|
||||
} else {
|
||||
std::cerr << "Destination Set\n";
|
||||
}
|
||||
VideoSession.SetDefaultPayloadType(98);
|
||||
VideoSession.SetDefaultMark(false);
|
||||
VideoSession.SetDefaultTimestampIncrement( ( 1.0 / 29.917 ) * 90000 );
|
||||
}
|
||||
HTTP_S.SetBody( "\r\n\r\n" );
|
||||
fprintf( stderr, "RESPONSE:\n%s\n", HTTP_S.BuildResponse( "200", "OK" ).c_str() );
|
||||
conn.write( HTTP_S.BuildResponse( "200", "OK" ) );
|
||||
|
@ -127,85 +152,20 @@ int RTSP_Handler( Socket::Connection conn ) {
|
|||
if( PerRequest ) {
|
||||
conn.close();
|
||||
}
|
||||
/* if( ( PlayVideo ) && !inited ) {
|
||||
ss = Socket::Connection("/tmp/shared_socket_fifa");
|
||||
if (!ss.connected()){
|
||||
#if DEBUG >= 1
|
||||
fprintf(stderr, "Could not connect to server!\n");
|
||||
#endif
|
||||
conn.close();
|
||||
break;
|
||||
}
|
||||
#if DEBUG >= 3
|
||||
fprintf(stderr, "Everything connected, starting to send video data...\n");
|
||||
#endif
|
||||
inited = true;
|
||||
}*/
|
||||
}
|
||||
if( PlayVideo ) {
|
||||
if( !InitVideo ) {
|
||||
VideoParams.SetOwnTimestampUnit( 1.0/90000.0 );
|
||||
VideoParams.SetMaximumPacketSize( 10000 );
|
||||
VideoTransParams.SetPortbase( 50000 );
|
||||
int VideoStatus = VideoSession.Create( VideoParams, &VideoTransParams );
|
||||
if( VideoStatus < 0 ) {
|
||||
std::cerr << jrtplib::RTPGetErrorString( VideoStatus ) << std::endl;
|
||||
exit( -1 );
|
||||
} else {
|
||||
std::cerr << "Created video session\n";
|
||||
}
|
||||
uint8_t localip[]={127,0,0,1};
|
||||
jrtplib::RTPIPv4Address addr(localip,RTPClientPort);
|
||||
|
||||
VideoStatus = VideoSession.AddDestination(addr);
|
||||
if (VideoStatus < 0) {
|
||||
std::cerr << jrtplib::RTPGetErrorString(VideoStatus) << std::endl;
|
||||
exit(-1);
|
||||
} else {
|
||||
std::cerr << "Destination Set\n";
|
||||
}
|
||||
VideoSession.SetDefaultPayloadType(98);
|
||||
VideoSession.SetDefaultMark(false);
|
||||
VideoSession.SetDefaultTimestampIncrement(0);
|
||||
InitVideo = true;
|
||||
}
|
||||
// std::cerr << "Retrieving NALU from stdin\n";
|
||||
/// \todo Select correct source
|
||||
std::string VideoBuf = ReadNALU( );
|
||||
if( VideoBuf == "" ) {
|
||||
jrtplib::RTPTime delay = jrtplib::RTPTime(10.0);
|
||||
VideoSession.BYEDestroy(delay,"Out of data",11);
|
||||
conn.close();
|
||||
} else {
|
||||
// std::cerr << "NALU Retrieved:\n";
|
||||
// std::cerr << "\t" << (int)VideoBuf[0] << " " << (int)VideoBuf[2]
|
||||
// << " " << (int)VideoBuf[3] << " " << (int)VideoBuf[4] << "\n";
|
||||
VideoSession.SendPacket( VideoBuf.c_str(), VideoBuf.size(), 98, false, ( 700000.0 / VideoBuf.size() ) );
|
||||
VideoSession.SendPacket( VideoBuf.c_str(), VideoBuf.size() );//, 98, true, ( 1.0 / 29.917 ) );
|
||||
// jrtplib::RTPTime delay( 1.0 / 29.917 );
|
||||
// jrtplib::RTPTime::Wait( delay );
|
||||
}
|
||||
}
|
||||
/*
|
||||
switch (ss.ready()){
|
||||
case -1:
|
||||
conn.close();
|
||||
#if DEBUG >= 1
|
||||
fprintf(stderr, "Source socket is disconnected.\n");
|
||||
#endif
|
||||
break;
|
||||
case 0: break;//not ready yet
|
||||
default:
|
||||
if (tag.SockLoader(ss)){//able to read a full packet?
|
||||
if( tag.data[ 0 ] == 0x09 ) {
|
||||
if( ( ( tag.data[ 11 ] & 0x0F ) == 7 ) ) { //&& ( tag.data[ 12 ] == 1 ) ) {
|
||||
fprintf(stderr, "Video contains NALU\n" );
|
||||
}
|
||||
}
|
||||
if( tag.data[ 0 ] == 0x08 ) {
|
||||
if( ( tag.data[ 11 ] == 0xAF ) && ( tag.data[ 12 ] == 0x01 ) ) {
|
||||
fprintf(stderr, "Audio Contains Raw AAC\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}*/
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue