/******************************************************************************
|
* FILE: RtspClientSession.h
|
* Description:
|
* Interface for rtsp client session class.
|
*
|
* Modified Code History
|
* Mark Date By Modification Reason
|
*******************************************************************************
|
* 01 2013/5/28 songxw Initial creation.
|
******************************************************************************/
|
#if !defined(__RTSP_CLIENT_SESSION_H__)
|
#define __RTSP_CLIENT_SESSION_H__
|
|
using namespace std;
|
|
#include <poll.h>
|
#include "TypeDef.h"
|
#include "str.h"
|
#include "TcpTransport.h"
|
#include "RtspProt.h"
|
#include "MyThread.h"
|
#include "TcpStreamTrans.h"
|
#include "UdpStreamTrans.h"
|
|
#include "jthread.h"
|
using namespace jthread;
|
|
|
#define RTSP_USER_AGENT "XSipGW(RtspClient)"
|
|
|
//¶Ë¿Ú·ÖÅ䷶Χ
|
#define RTSP_CLIENT_SESSION_BEGIN_PORT 31000
|
#define RTSP_CLIENT_SESSION_END_PORT (RTSP_CLIENT_SESSION_BEGIN_PORT + 1000)
|
#define RTSP_MESSAGE_MAX_LEN (20 * 1024) //K
|
#define RTSP_KEEPALIVE_TIME 60
|
|
|
/* ÏûÏ¢¹ý³ÌµÄ¼Ç¼Êý¾Ý */
|
class CContextData
|
{
|
public:
|
CContextData(void)
|
{
|
StatusCode = 0;
|
ServerPort = 0;
|
ClientPort = 0;
|
strServerIp = "";
|
strClientIp = "";
|
}
|
~CContextData(void) {}
|
|
UINT32 StatusCode; //×îÐÂÏûÏ¢»ØÓ¦Â룬Ö÷ҪΪ½â¾öRTSPÇëÇó»ØÓ¦Óûص÷·½Ê½£¬Ö÷Òª¹¤×÷Á÷³Ì²»Äܵõ½¡£
|
|
CString StrUrl; //ÇëÇóURL
|
CString SessionID; //ȇȡID
|
// CString StrVStreamUrl; //ÊÓÆµÁ÷±ê¼ÇµÄURL
|
CString StrVStream; //ÊÓÆµÁ÷±ê¼Ç
|
CString StrAStream; //ÒôƵÁ÷±ê¼Ç
|
|
UINT16 ServerPort; //Ô¶¶Ë(É豸)ýÌå¶Ë¿Ú
|
UINT16 ClientPort; //±¾µØÃ½Ìå¶Ë¿Ú
|
|
string strServerIp; //Á÷ýÌå·¢ËͶ˵ÄipµØÖ·
|
string strClientIp; //Á÷ýÌå½âÎö¶ËµÄipµØÖ·
|
};
|
|
/* Rtsp client session interface class */
|
class CRtspClientSession : public CRtspProtocolResponse
|
{
|
public:
|
CRtspClientSession();
|
~CRtspClientSession(void);
|
|
private:
|
//»ñÈ¡±¾µØipµØÖ·
|
static int GetLocalIP(char *address, int size);
|
//²é¿´¶Ë¿ÚÊÇ·ñ±»Õ¼ÓÃ
|
static bool PortIsOccupied(const UINT16 PId);
|
static bool AllocatePortID(UINT16 &PId); //Note: PId is export variable.
|
//¹¹ÔìÈÏÖ¤ÐÅÏ¢£¬Ìáǰlive555
|
char* createAuthenticatorString(char *cmd, char *url);
|
public:
|
#if 0
|
//Ïß³ÌÆô¶¯
|
void* Thread(void);
|
//Ï߳̽áÊø
|
void ThreadQuit(void);
|
#endif
|
public:
|
//Method API for RTSP
|
//·¢ËÍrtspµÄOPTIONSÐÒé
|
int Options(const char* pUrl);
|
//·¢ËÍrtspµÄDESCRIBEÐÒé
|
int Describe(const char* pUrl, bool bAuth = false);
|
//·¢ËÍrtspµÄSETUPÐÒé
|
int Setup(const CString& SessionID, const CString StreamId, bool bCreateTcpSvr = false);
|
//·¢ËÍrtspµÄPLAYÐÒé
|
int Play(const CString& SessionID, int ctrltype = 0, double ctrlparam = 0);
|
//·¢ËÍrtspµÄPAUSEÐÒé
|
int Pause(const CString& SessionID);
|
//·¢ËÍrtspµÄTEARDOWNÐÒé
|
int Teardown(const CString& SessionID, const CString StreamId);
|
//·¢ËÍrtspµÄGETPARAMÐÒé
|
int GetParam(const CString& SessionID);
|
public:
|
//¹ý³ÌÊý¾Ý
|
CContextData CnxData;
|
CTcpTransport* pTcpTransport; //TCPÐÒéÁ¬½Ó
|
|
CTcpStreamTrans *m_pTcpStreamTrans; //TCP ÂëÁ÷½ÓÊÕ
|
CUdpStreamTrans *m_pUdpStreamTrans; //UDP½ÓÊÕÂëÁ÷
|
protected:
|
virtual void OnError(RtspErr error) {}
|
|
//ÇëÇó½øÀ´
|
void OnOptionsRequest( CRtspRequestMsg* pMsg) {}
|
void OnDescribeRequest(CRtspRequestMsg* pMsg) {}
|
void OnAnnounceRequest(CRtspRequestMsg* pMsg) {}
|
void OnGetParamRequest(CRtspRequestMsg* pMsg) {}
|
void OnSetParamRequest(CRtspRequestMsg* pMsg) {}
|
void OnSetupRequest(CRtspRequestMsg* pMsg) {}
|
void OnPlayRequest(CRtspRequestMsg* pMsg) {}
|
void OnPauseRequest(CRtspRequestMsg* pMsg) {}
|
void OnRecordRequest(CRtspRequestMsg* pMsg) {}
|
void OnRedirectRequest(CRtspRequestMsg* pMsg) {}
|
void OnTeardownRequest(CRtspRequestMsg* pMsg) {}
|
void OnExtensionRequest(CRtspRequestMsg* pMsg) {}
|
|
//ÏìÓ¦½øÀ´
|
//´¦ÀíOPTINSµÄ·µ»ØÐÅÏ¢
|
void OnOptionsResponse(CRtspResponseMsg* pMsg);
|
void OnDescribeResponse(CRtspResponseMsg* pMsg);
|
void OnAnnounceResponse(CRtspResponseMsg* pMsg);
|
void OnGetParamResponse(CRtspResponseMsg* pMsg);
|
void OnSetParamResponse(CRtspResponseMsg* pMsg);
|
void OnSetupResponse(CRtspResponseMsg* pMsg);
|
void OnPlayResponse(CRtspResponseMsg* pMsg);
|
void OnPauseResponse(CRtspResponseMsg* pMsg);
|
void OnRecordResponse(CRtspResponseMsg* pMsg);
|
void OnRedirectResponse(CRtspResponseMsg* pMsg);
|
void OnTeardownResponse(CRtspResponseMsg* pMsg);
|
void OnExtensionResponse(CRtspResponseMsg* pMsg);
|
private:
|
//RTSPÐÒéÐÄÌø±¥ºÍº¯Êý
|
bool KeepAliveSession(void);
|
//ÇëÇóÏûÏ¢±àÂë¡¢·¢Ëͺ͵ȴý»ØÓ¦
|
int DoWork(CRtspRequestMsg& ReqMsg);
|
//·¢ËÍÊý¾Ý
|
int SendData(const char* pBuf, int Len, const int WaitForTimeout = 5/*s*/);
|
int ReadData(const char* pBuf, int BufLen, const int WaitForTimeout = 5/*s*/);
|
int ReadRtspData(UINT8 *pBuf, int BufLen);
|
public:
|
//ÉèÖÃRTSPµÄÐÅÏ¢
|
void SetRtspSessionInfo(const char *url, const char *username, const char *passwd, bool bauth)
|
{
|
if(url != NULL && strlen(url) > 0)
|
{
|
strncpy2(m_RtspUrl, url, HTTP_URL_MAX_LEN);
|
}
|
|
if(username != NULL && strlen(username) > 0)
|
{
|
strncpy2(m_UserName, username, HTTP_URL_MAX_LEN);
|
}
|
|
if(passwd != NULL && strlen(passwd) > 0)
|
{
|
strncpy2(m_Passwd, passwd, HTTP_URL_MAX_LEN);
|
}
|
m_bSetAuth = bauth;
|
|
if (bauth == true)
|
{
|
m_Authenticator.setUsernameAndPassword(username, passwd);
|
}
|
}
|
private:
|
bool m_bExitFlag;
|
//Rtsp protocol stack
|
CRtspProtocol* pRtspProt; //rtspÐÒé½âÎö
|
|
char m_RtspUrl[HTTP_URL_MAX_LEN + 1];//rtspµÄurl
|
char m_UserName[USERNAME_MAX_LEN+1];//rtspÇëÇóµÄusername
|
char m_Passwd[PASSWD_MAX_LEN+1];//rtspÇëÇóµÄÃÜÂë
|
bool m_bSetAuth; //ÊÇ·ñÐèÒªÈÏÖ¤
|
|
CAuthenticator m_Authenticator; //ÈÏÖ¤ÐÅÏ¢Àà
|
bool m_bSupportsGetParam; //ÊÇ·ñÖ§³ÖGETPARAM £¬ÓÃÓÚÐÒéÐÄÌø
|
|
int SendKeepAliveTime;
|
//Buffer³¤¶È
|
char DataBuf[RTSP_MESSAGE_MAX_LEN + 1];
|
public:
|
//DevCorpID_E DevCorpID;
|
int Channel; //É豸ͨµÀ
|
//Rtsp Session ID
|
CString SessionID;
|
bool bAudio; //ÒôƵ¿ª¹Ø
|
CString StrVStream; //ÊÓÆµÁ÷±ê¼Ç
|
CString StrAStream; //ÒôƵÁ÷±ê¼Ç
|
public:
|
//Port rule
|
static UINT16 RtspBeginPort;
|
static UINT16 RtspEndPort;
|
static UINT16 RtspCurrentPort; //Current specify port to allocate
|
};
|
|
#endif //#if !defined(__RTSP_CLIENT_SESSION_H__)
|