2008-07-16 16:35:59 +08:00
|
|
|
//
|
2008-07-25 17:08:15 +08:00
|
|
|
// ZoneMinder RTSP Class Interface, $Date$, $Revision$
|
2008-07-25 17:33:23 +08:00
|
|
|
// Copyright (C) 2001-2008 Philip Coombes
|
2008-07-16 16:35:59 +08:00
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License
|
|
|
|
// as published by the Free Software Foundation; either version 2
|
|
|
|
// of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
//
|
|
|
|
|
2008-07-25 00:57:39 +08:00
|
|
|
#ifndef ZM_RTSP_H
|
|
|
|
#define ZM_RTSP_H
|
2008-07-16 16:35:59 +08:00
|
|
|
|
2008-07-25 17:00:23 +08:00
|
|
|
#include "zm.h"
|
|
|
|
#include "zm_ffmpeg.h"
|
2008-07-16 16:35:59 +08:00
|
|
|
#include "zm_comms.h"
|
|
|
|
#include "zm_thread.h"
|
|
|
|
#include "zm_rtp_source.h"
|
2014-04-29 05:37:31 +08:00
|
|
|
#include "zm_rtsp_auth.h"
|
2014-11-15 05:31:03 +08:00
|
|
|
#include "zm_sdp.h"
|
2008-07-16 16:35:59 +08:00
|
|
|
|
|
|
|
#include <set>
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
class RtspThread : public Thread
|
|
|
|
{
|
|
|
|
public:
|
2016-04-04 22:11:48 +08:00
|
|
|
typedef enum { RTP_UNICAST, RTP_MULTICAST, RTP_RTSP, RTP_RTSP_HTTP } RtspMethod;
|
|
|
|
typedef enum { UNDEFINED, UNICAST, MULTICAST } RtspDist;
|
2008-07-16 16:35:59 +08:00
|
|
|
|
|
|
|
private:
|
2016-04-04 22:11:48 +08:00
|
|
|
typedef std::set<int> PortSet;
|
|
|
|
typedef std::set<uint32_t> SsrcSet;
|
|
|
|
typedef std::map<uint32_t,RtpSource *> SourceMap;
|
2008-07-16 16:35:59 +08:00
|
|
|
|
|
|
|
private:
|
2016-04-04 22:11:48 +08:00
|
|
|
static int smMinDataPort;
|
|
|
|
static int smMaxDataPort;
|
|
|
|
static PortSet smLocalSsrcs;
|
|
|
|
static PortSet smAssignedPorts;
|
2008-07-16 16:35:59 +08:00
|
|
|
|
|
|
|
private:
|
2016-04-04 22:11:48 +08:00
|
|
|
int mId;
|
2015-11-05 14:19:58 +08:00
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
RtspMethod mMethod;
|
|
|
|
std::string mProtocol;
|
|
|
|
std::string mHost;
|
|
|
|
std::string mPort;
|
|
|
|
std::string mPath;
|
|
|
|
bool mRtspDescribe;
|
|
|
|
std::string mUrl;
|
|
|
|
|
|
|
|
// Reworked authentication system
|
|
|
|
// First try without authentication, even if we have a username and password
|
|
|
|
// on receiving a 401 response, select authentication method (basic or digest)
|
|
|
|
// fill required fields and set needAuth
|
|
|
|
// subsequent requests can set the required authentication header.
|
|
|
|
bool mNeedAuth;
|
|
|
|
int respCode;
|
|
|
|
zm::Authenticator* mAuthenticator;
|
2014-04-29 05:37:31 +08:00
|
|
|
|
2008-07-16 16:35:59 +08:00
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
std::string mHttpSession; ///< Only for RTSP over HTTP sessions
|
2008-07-16 16:35:59 +08:00
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
TcpInetClient mRtspSocket;
|
|
|
|
TcpInetClient mRtspSocket2;
|
2008-07-16 16:35:59 +08:00
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
SourceMap mSources;
|
2008-07-16 16:35:59 +08:00
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
SessionDescriptor *mSessDesc;
|
|
|
|
AVFormatContext *mFormatContext;
|
2008-07-16 16:35:59 +08:00
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
uint16_t mSeq;
|
|
|
|
uint32_t mSession;
|
|
|
|
uint32_t mSsrc;
|
2008-07-16 16:35:59 +08:00
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
int mRemotePorts[2];
|
|
|
|
int mRemoteChannels[2];
|
|
|
|
RtspDist mDist;
|
2008-07-16 16:35:59 +08:00
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
unsigned long mRtpTime;
|
2008-07-16 16:35:59 +08:00
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
bool mStop;
|
2008-07-16 16:35:59 +08:00
|
|
|
|
|
|
|
private:
|
2016-04-04 22:11:48 +08:00
|
|
|
bool sendCommand( std::string message );
|
|
|
|
bool recvResponse( std::string &response );
|
|
|
|
void checkAuthResponse(std::string &response);
|
2008-07-16 16:35:59 +08:00
|
|
|
|
|
|
|
public:
|
2016-04-04 22:11:48 +08:00
|
|
|
RtspThread( int id, RtspMethod method, const std::string &protocol, const std::string &host, const std::string &port, const std::string &path, const std::string &auth, bool rtsp_describe );
|
|
|
|
~RtspThread();
|
2008-07-16 16:35:59 +08:00
|
|
|
|
|
|
|
public:
|
2016-04-04 22:11:48 +08:00
|
|
|
int requestPorts();
|
|
|
|
void releasePorts( int port );
|
|
|
|
|
|
|
|
bool isValidSsrc( uint32_t ssrc );
|
|
|
|
bool updateSsrc( uint32_t ssrc, const RtpDataHeader *header );
|
|
|
|
|
|
|
|
uint32_t getSsrc() const
|
|
|
|
{
|
|
|
|
return( mSsrc );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool hasSources() const
|
|
|
|
{
|
|
|
|
return( !mSources.empty() );
|
|
|
|
}
|
|
|
|
|
|
|
|
AVFormatContext *getFormatContext()
|
|
|
|
{
|
|
|
|
return( mFormatContext );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool getFrame( Buffer &frame )
|
|
|
|
{
|
|
|
|
SourceMap::iterator iter = mSources.begin();
|
|
|
|
if ( iter == mSources.end() )
|
|
|
|
return( false );
|
|
|
|
return( iter->second->getFrame( frame ) );
|
|
|
|
}
|
|
|
|
int run();
|
|
|
|
void stop()
|
|
|
|
{
|
|
|
|
mStop = true;
|
|
|
|
}
|
|
|
|
bool stopped() const
|
|
|
|
{
|
|
|
|
return( mStop );
|
|
|
|
}
|
2016-05-06 20:32:21 +08:00
|
|
|
int getAddressFamily ()
|
|
|
|
{
|
|
|
|
return mRtspSocket.getDomain();
|
|
|
|
}
|
2008-07-16 16:35:59 +08:00
|
|
|
};
|
|
|
|
|
2008-07-25 00:57:39 +08:00
|
|
|
#endif // ZM_RTSP_H
|