/****************************************************************************
|
*
|
* Copyright (C) 2000-2001 RealNetworks, Inc. All rights reserved.
|
*
|
* This program is free software. It may be distributed under the terms
|
* in the file LICENSE, found in the top level of the source distribution.
|
*
|
*/
|
|
#ifndef _RTSPPROT_H
|
#define _RTSPPROT_H
|
|
#include "MyList.h"
|
#include "RtspMsg.h"
|
|
enum RtspErr
|
{
|
RTSPE_NONE,
|
RTSPE_CLOSED,
|
RTSPE_NOTRAN,
|
RTSPE_MAX
|
};
|
|
class CRtspProtocolResponse
|
{
|
public:
|
CRtspProtocolResponse(void) {}
|
virtual ~CRtspProtocolResponse(void) {}
|
|
virtual void OnError(RtspErr err) = 0;
|
|
virtual void OnDescribeRequest(CRtspRequestMsg* pMsg) = 0;
|
virtual void OnAnnounceRequest(CRtspRequestMsg* pMsg) = 0;
|
virtual void OnGetParamRequest(CRtspRequestMsg* pMsg) = 0;
|
virtual void OnSetParamRequest(CRtspRequestMsg* pMsg) = 0;
|
virtual void OnOptionsRequest( CRtspRequestMsg* pMsg) = 0;
|
virtual void OnPauseRequest(CRtspRequestMsg* pMsg) = 0;
|
virtual void OnPlayRequest(CRtspRequestMsg* pMsg) = 0;
|
virtual void OnRecordRequest(CRtspRequestMsg* pMsg) = 0;
|
virtual void OnRedirectRequest(CRtspRequestMsg* pMsg) = 0;
|
virtual void OnSetupRequest(CRtspRequestMsg* pMsg) = 0;
|
virtual void OnTeardownRequest(CRtspRequestMsg* pMsg) = 0;
|
virtual void OnExtensionRequest(CRtspRequestMsg* pMsg) = 0;
|
|
virtual void OnDescribeResponse(CRtspResponseMsg* pMsg) = 0;
|
virtual void OnAnnounceResponse(CRtspResponseMsg* pMsg) = 0;
|
virtual void OnGetParamResponse(CRtspResponseMsg* pMsg) = 0;
|
virtual void OnSetParamResponse(CRtspResponseMsg* pMsg) = 0;
|
virtual void OnOptionsResponse(CRtspResponseMsg* pMsg) = 0;
|
virtual void OnPauseResponse(CRtspResponseMsg* pMsg) = 0;
|
virtual void OnPlayResponse(CRtspResponseMsg* pMsg) = 0;
|
virtual void OnRecordResponse(CRtspResponseMsg* pMsg) = 0;
|
virtual void OnRedirectResponse(CRtspResponseMsg* pMsg) = 0;
|
virtual void OnSetupResponse(CRtspResponseMsg* pMsg) = 0;
|
virtual void OnTeardownResponse(CRtspResponseMsg* pMsg) = 0;
|
virtual void OnExtensionResponse(CRtspResponseMsg* pMsg) = 0;
|
};
|
|
#define FUDGE 16
|
#define A_LINE_MAX_LEN 2048
|
#define RTSP_CRLF "\r\n"
|
|
class CRtspProtocol
|
{
|
public:
|
CRtspProtocol(CRtspProtocolResponse* pResponse);
|
virtual ~CRtspProtocol(void);
|
|
UINT32 GetNextCseq(void) {return ++m_CSeqSend;}
|
|
void ResetCseq(){m_CSeqSend=0;}
|
|
//Translate message struct into ASCII string. WARNNING: free pDataStr dynamic pointer after call it.
|
int Encoder(const CRtspMsg* pRtspMsg, char* &pDataStr, int &DataLen);
|
int DecoderAndDrvie(int sockfd, const char* pDataBuf, int DataLen, CRtspMsg* &pRtspMsg, char SrcIP[], UINT16 SrcPort, int &Code, const char* &pNextPacketPos);
|
int DecoderAndDrvie(const char* pDataBuf, int DataLen, CRtspMsg* &pRtspMsg, int &Code, char SrcIP[], UINT16 SrcPort);
|
int DecoderAndDrvie(const char* pDataBuf, int DataLen, CRtspMsg* &pRtspMsg, int &Code);
|
|
int HandleReadCmd(char ALine[], CRtspMsg* &pRtspMsg, int &Code);
|
bool handleAuthenticationFailure(CRtspMsg* &pRtspMsg, char *paramsStr);
|
int HandleReadHdr(char ALine[], CRtspMsg* &pRtspMsg, int &Code);
|
int HandleReadBody(char* pBody, int BodyLen, CRtspMsg* &pRtspMsg, int &Code);
|
int DispatchMessage(CRtspMsg* &pRtspMsg, int &Code);
|
|
public:
|
class CRtspRequestTag
|
{
|
public:
|
CRtspRequestTag(UINT32 cseq, RtspVerb verb) : m_cseq(cseq), m_verb(verb) {}
|
|
//XXX: Keep rtsp version, url, etc...?
|
UINT32 m_cseq;
|
RtspVerb m_verb;
|
};
|
typedef TDoubleList<CRtspRequestTag> CRtspRequestTagList;
|
|
MyList<CRtspRequestTag> RequestTagListQueue;
|
|
private:
|
enum ReadState {
|
stFail, //Unrecoverable error occurred
|
stSync, //Trying to resync
|
stReady, //Waiting for a command
|
stPkt, //Reading interleaved packet
|
stCmd, //Reading command (request or response line)
|
stHdr, //Reading headers
|
stBody, //Reading body (entity)
|
stDispatch, //Fully formed message
|
stREADSTATE_LAST
|
};
|
|
CRtspProtocolResponse* m_pResponse;
|
|
UINT32 m_CSeqSend; //Our next cseq
|
UINT32 m_CSeqRecv; //Peer's last cseq
|
};
|
|
#endif //#ifndef _RTSPPROT_H
|