Skip to content

Commit

Permalink
Merge pull request #615 from knnniggett/rtsp
Browse files Browse the repository at this point in the history
Rtsp
  • Loading branch information
connortechnology committed Dec 4, 2014
2 parents d7e0855 + 97ee989 commit ba7230e
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 19 deletions.
57 changes: 41 additions & 16 deletions src/zm_rtsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ int RtspThread::run()

uint32_t rtpClock = 0;
std::string trackUrl = mUrl;
std::string controlUrl;

_AVCODECID codecId;

Expand All @@ -412,7 +413,7 @@ int RtspThread::run()
#endif
{
// Check if control Url is absolute or relative
std::string controlUrl = mediaDesc->getControlUrl();
controlUrl = mediaDesc->getControlUrl();
if (std::equal(trackUrl.begin(), trackUrl.end(), controlUrl.begin()))
{
trackUrl = controlUrl;
Expand Down Expand Up @@ -556,27 +557,51 @@ int RtspThread::run()
{
if ( ( lines[i].size() > 9 ) && ( lines[i].substr( 0, 9 ) == "RTP-Info:" ) )
rtpInfo = trimSpaces( lines[i].substr( 9 ) );
// Check for a timeout again. Some rtsp devices don't send a timeout until after the PLAY command is sent
if ( ( lines[i].size() > 8 ) && ( lines[i].substr( 0, 8 ) == "Session:" ) && ( timeout == 0 ) )
{
StringVector sessionLine = split( lines[i].substr(9), ";" );
if ( sessionLine.size() == 2 )
sscanf( trimSpaces( sessionLine[1] ).c_str(), "timeout=%d", &timeout );
if ( timeout > 0 )
Debug( 2, "Got timeout %d secs from PLAY command response", timeout );
}
}

if ( rtpInfo.empty() )
Fatal( "Unable to get RTP Info identifier from response '%s'", response.c_str() );

Debug( 2, "Got RTP Info %s", rtpInfo.c_str() );

int seq = 0;
unsigned long rtpTime = 0;
parts = split( rtpInfo.c_str(), ";" );
for ( size_t i = 0; i < parts.size(); i++ )
StringVector streams;
if ( rtpInfo.empty() )
{
if ( startsWith( parts[i], "seq=" ) )
{
StringVector subparts = split( parts[i], "=" );
seq = strtol( subparts[1].c_str(), NULL, 10 );
}
else if ( startsWith( parts[i], "rtptime=" ) )
Debug( 1, "RTP Info Empty. Starting values for Sequence and Rtptime shall be zero.");
}
else
{
Debug( 2, "Got RTP Info %s", rtpInfo.c_str() );
// More than one stream can be included in the RTP Info
streams = split( rtpInfo.c_str(), "," );
for ( size_t i = 0; i < streams.size(); i++ )
{
StringVector subparts = split( parts[i], "=" );
rtpTime = strtol( subparts[1].c_str(), NULL, 10 );
// We want the stream that matches the trackUrl we are using
if ( streams[i].find(controlUrl.c_str()) != std::string::npos )
{
// Parse the sequence and rtptime values
parts = split( streams[i].c_str(), ";" );
for ( size_t j = 0; j < parts.size(); j++ )
{
if ( startsWith( parts[j], "seq=" ) )
{
StringVector subparts = split( parts[j], "=" );
seq = strtol( subparts[1].c_str(), NULL, 10 );
}
else if ( startsWith( parts[j], "rtptime=" ) )
{
StringVector subparts = split( parts[j], "=" );
rtpTime = strtol( subparts[1].c_str(), NULL, 10 );
}
}
break;
}
}
}

Expand Down
12 changes: 9 additions & 3 deletions src/zm_sdp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ SessionDescriptor::DynamicPayloadDesc SessionDescriptor::smDynamicPayloads[] = {
{ "MP4V-ES", AVMEDIA_TYPE_VIDEO, AV_CODEC_ID_MPEG4 },
{ "mpeg4-generic", AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_AAC },
{ "H264", AVMEDIA_TYPE_VIDEO, AV_CODEC_ID_H264 },
{ "AMR", AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_AMR_NB }
{ "AMR", AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_AMR_NB },
{ "vnd.onvif.metadata", AVMEDIA_TYPE_DATA, AV_CODEC_ID_NONE }
};
#else
SessionDescriptor::StaticPayloadDesc SessionDescriptor::smStaticPayloads[] = {
Expand Down Expand Up @@ -95,7 +96,8 @@ SessionDescriptor::DynamicPayloadDesc SessionDescriptor::smDynamicPayloads[] = {
{ "MP4V-ES", CODEC_TYPE_VIDEO, CODEC_ID_MPEG4 },
{ "mpeg4-generic", CODEC_TYPE_AUDIO, CODEC_ID_AAC },
{ "H264", CODEC_TYPE_VIDEO, CODEC_ID_H264 },
{ "AMR", CODEC_TYPE_AUDIO, CODEC_ID_AMR_NB }
{ "AMR", CODEC_TYPE_AUDIO, CODEC_ID_AMR_NB },
{ "vnd.onvif.metadata", CODEC_TYPE_DATA, CODEC_ID_NONE }
};
#endif

Expand Down Expand Up @@ -326,7 +328,7 @@ SessionDescriptor::SessionDescriptor( const std::string &url, const std::string
if ( tokens.size() < 4 )
throw Exception( "Can't parse SDP media description '"+line+"'" );
std::string mediaType = tokens[0];
if ( mediaType != "audio" && mediaType != "video" )
if ( mediaType != "audio" && mediaType != "video" && mediaType != "application" )
throw Exception( "Unsupported media type '"+mediaType+"' in SDP media attribute '"+line+"'" );
StringVector portTokens = split( tokens[1], "/" );
int mediaPort = atoi(portTokens[0].c_str());
Expand Down Expand Up @@ -383,11 +385,15 @@ AVFormatContext *SessionDescriptor::generateFormatContext() const
stream->codec->codec_type = AVMEDIA_TYPE_VIDEO;
else if ( mediaDesc->getType() == "audio" )
stream->codec->codec_type = AVMEDIA_TYPE_AUDIO;
else if ( mediaDesc->getType() == "application" )
stream->codec->codec_type = AVMEDIA_TYPE_DATA;
#else
if ( mediaDesc->getType() == "video" )
stream->codec->codec_type = CODEC_TYPE_VIDEO;
else if ( mediaDesc->getType() == "audio" )
stream->codec->codec_type = CODEC_TYPE_AUDIO;
else if ( mediaDesc->getType() == "application" )
stream->codec->codec_type = CODEC_TYPE_DATA;
#endif

if ( mediaDesc->getPayloadType() < PAYLOAD_TYPE_DYNAMIC )
Expand Down

0 comments on commit ba7230e

Please sign in to comment.