rtsppars.cpp
来自「symbian 下的helix player源代码」· C++ 代码 · 共 912 行 · 第 1/2 页
CPP
912 行
/* ***** BEGIN LICENSE BLOCK *****
* Source last modified: $Id: rtsppars.cpp,v 1.9.30.1 2004/07/09 02:04:52 hubbe Exp $
*
* Portions Copyright (c) 1995-2004 RealNetworks, Inc. All Rights Reserved.
*
* The contents of this file, and the files included with this file,
* are subject to the current version of the RealNetworks Public
* Source License (the "RPSL") available at
* http://www.helixcommunity.org/content/rpsl unless you have licensed
* the file under the current version of the RealNetworks Community
* Source License (the "RCSL") available at
* http://www.helixcommunity.org/content/rcsl, in which case the RCSL
* will apply. You may also obtain the license terms directly from
* RealNetworks. You may not use this file except in compliance with
* the RPSL or, if you have a valid RCSL with RealNetworks applicable
* to this file, the RCSL. Please see the applicable RPSL or RCSL for
* the rights, obligations and limitations governing use of the
* contents of the file.
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU General Public License Version 2 or later (the
* "GPL") in which case the provisions of the GPL are applicable
* instead of those above. If you wish to allow use of your version of
* this file only under the terms of the GPL, and not to allow others
* to use your version of this file under the terms of either the RPSL
* or RCSL, indicate your decision by deleting the provisions above
* and replace them with the notice and other provisions required by
* the GPL. If you do not delete the provisions above, a recipient may
* use your version of this file under the terms of any one of the
* RPSL, the RCSL or the GPL.
*
* This file is part of the Helix DNA Technology. RealNetworks is the
* developer of the Original Code and owns the copyrights in the
* portions it created.
*
* This file, and the files included with this file, is distributed
* and made available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY
* KIND, EITHER EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET
* ENJOYMENT OR NON-INFRINGEMENT.
*
* Technology Compatibility Kit Test Suite(s) Location:
* http://www.helixcommunity.org/content/tck
*
* Contributor(s):
*
* ***** END LICENSE BLOCK ***** */
//#include "hlxclib/stdlib.h"
//#include "hlxclib/stdio.h"
#include "hxcom.h"
#include "hxtypes.h"
#include "hxassert.h"
#include "debug.h"
#include "hxstrutl.h"
#include "hxstring.h"
#include "hxslist.h"
#include "mimehead.h"
#include "rtsppars.h"
#include "smpte.h"
#include "nptime.h"
#include "rtspmsg.h"
#include "chxpckts.h"
#include "hxauth.h"
#include "hxheap.h"
#ifdef _DEBUG
#undef HX_THIS_FILE
static const char HX_THIS_FILE[] = __FILE__;
#endif
RTSPParser::RTSPParser()
{
}
RTSPParser::~RTSPParser()
{
clearMessageLines();
}
/*
* Extract major/minor version info
*/
int
RTSPParser::parseProtocolVersion(const CHXString& prot,
int& majorVersion, int& minorVersion)
{
if(strncasecmp(prot, "RTSP/", 5) != 0)
return 0;
int nVerOffset = prot.Find('.');
if(nVerOffset > 5)
{
CHXString majVersion = prot.Mid(5, nVerOffset-5);
majorVersion = (int)strtol(majVersion, 0, 10);
CHXString minVersion = prot.Mid(nVerOffset+1);
minorVersion = (int)strtol(minVersion, 0, 10);
return 1;
}
return 0;
}
/*
* Parse option in form 'value *[;name[=value]]'
*/
int
RTSPParser::parseHeaderValue(const char* pValue, MIMEHeader* pHeader)
{
if(strlen(pValue) == 0)
return 0;
MIMEInputStream input(pValue, strlen(pValue));
MIMEScanner scanner(input);
MIMEHeaderValue* pHeaderValue = 0;
MIMEToken tok = scanner.nextToken(";=");
while(tok.hasValue())
{
if(!pHeaderValue)
{
CHXString attribute = tok.value();
pHeaderValue = new MIMEHeaderValue;
if(!pHeaderValue)
{
return 0;
}
if(tok.lastChar() == '=')
{
tok = scanner.nextToken(";");
CHXString value = tok.value();
pHeaderValue->addParameter(attribute, value);
}
else
{
pHeaderValue->addParameter(attribute);
}
}
else if(tok.lastChar() == '=')
{
CHXString attribute = tok.value();
tok = scanner.nextToken(";");
CHXString value = tok.value();
pHeaderValue->addParameter(attribute, value);
}
else
{
CHXString attribute = tok.value();
pHeaderValue->addParameter(attribute, "");
}
tok = scanner.nextToken("=;");
}
if(pHeaderValue)
pHeader->addHeaderValue(pHeaderValue);
return 0;
}
int
RTSPParser::parseRangeValue(const char* pValue, MIMEHeader* pHeader)
{
MIMEInputStream input(pValue, strlen(pValue));
MIMEScanner scanner(input);
MIMEToken nextTok = scanner.nextToken("=");
if(strcasecmp(nextTok.value(), "smpte") == 0)
{
UINT32 tBegin = RTSP_PLAY_RANGE_BLANK;
UINT32 tEnd = RTSP_PLAY_RANGE_BLANK;
nextTok = scanner.nextToken("-");
if(nextTok.hasValue())
{
SMPTETimeCode tCode1(nextTok.value());
tBegin = UINT32(tCode1);
}
if((nextTok.lastChar() != MIMEToken::T_EOL) ||
(nextTok.lastChar() != MIMEToken::T_EOF))
{
nextTok = scanner.nextToken("\n");
if(nextTok.hasValue())
{
SMPTETimeCode tCode2(nextTok.value());
tEnd = UINT32(tCode2);
}
}
pHeader->addHeaderValue(new RTSPRange(tBegin, tEnd,
RTSPRange::TR_SMPTE));
}
else if(strcasecmp(nextTok.value(), "npt") == 0)
{
UINT32 tBegin = RTSP_PLAY_RANGE_BLANK;
UINT32 tEnd = RTSP_PLAY_RANGE_BLANK;
nextTok = scanner.nextToken("-");
if(nextTok.hasValue())
{
NPTime t1(nextTok.value());
tBegin = UINT32(t1);
}
if((nextTok.lastChar() != MIMEToken::T_EOL) ||
(nextTok.lastChar() != MIMEToken::T_EOF))
{
nextTok = scanner.nextToken("\n");
if(nextTok.hasValue())
{
NPTime t2(nextTok.value());
tEnd = UINT32(t2);
}
}
pHeader->addHeaderValue(new RTSPRange(tBegin, tEnd,
RTSPRange::TR_NPT));
}
else if(strcasecmp(nextTok.value(), "clock") == 0)
{
//XXXBAB fill this in
}
return 0;
}
int
RTSPParser::parseAuthenticationValue(const char* pValue, MIMEHeader* pHeader)
{
MIMEInputStream input(pValue, strlen(pValue));
MIMEScanner scanner(input);
MIMEToken nextTok = scanner.nextToken(" ");
if(strcasecmp(nextTok.value(), "HXPrivate") == 0)
{
nextTok = scanner.nextToken("=");
if(strcasecmp(nextTok.value(), "nonce") == 0)
{
nextTok = scanner.nextToken();
pHeader->addHeaderValue(new RTSPAuthentication(nextTok.value(),
RTSPAuthentication::AU_HX_PRIVATE));
}
}
return 0;
}
int
RTSPParser::parsePEPInfoHeaderValues(const char* pValue, MIMEHeader* pHeader)
{
MIMEInputStream input(pValue, strlen(pValue));
MIMEScanner scanner(input);
BOOL bStrengthMust = FALSE;
MIMEToken nextTok = scanner.nextToken(" {}");
while(nextTok.lastChar() != MIMEToken::T_EOF)
{
if(strcasecmp(nextTok.value(), "strength") == 0)
{
nextTok = scanner.nextToken(" }");
if(strcasecmp(nextTok.value(), "must") == 0)
{
bStrengthMust = TRUE;
break;
}
}
nextTok = scanner.nextToken(" {}");
}
pHeader->addHeaderValue(new RTSPPEPInfo(bStrengthMust));
return 0;
}
int
RTSPParser::parseRTPInfoHeaderValues(const char* pValue, MIMEHeader* pHeader)
{
// There is a bug in RFC2326 related to the ambiguity of "url=" parameter in
// RTP-Info. More details can be found at:
// http://sourceforge.net/tracker/index.php?func=detail&group_id=23194&atid=377744&aid=448521
//
// For now, we only can do the best we can:
// 1. find stream URL entry based on ",url="
// 2. read "url", "seq" and "rtptime" within the stream URL entry
if (!pValue || 0 == strlen(pValue))
{
return 0;
}
const char* pCurrentEntry = NULL;
const char* pNextEntry = NULL;
CHXString value = pValue;
CHXString entry;
pCurrentEntry = strstr(pValue, "url=");
// RTP-Info starts with "url="
HX_ASSERT(pCurrentEntry == pValue);
while (pNextEntry = NextRTPInfoEntry(pCurrentEntry+4, "url=", ','))
{
// retreive stream URL entry
entry = value.Mid(pCurrentEntry - pValue, pNextEntry - pCurrentEntry);
// retrieve "url", "seq" and "rtptime"
SetRTPInfoEntry(entry, pHeader);
pCurrentEntry = pNextEntry;
}
entry = value.Mid(pCurrentEntry - pValue);
SetRTPInfoEntry(entry, pHeader);
return 0;
}
const char*
RTSPParser::NextRTPInfoEntry(const char* pValue, const char* pTarget, const char cDelimiter)
{
const char* pEntry = NULL;
while (pEntry = strstr(pValue, pTarget))
{
const char* pTemp = pEntry;
// a valid entry should begin with:
// ",url=" OR ", url="
// rewind and skip all the spaces in between
while (*(--pTemp) == ' ') {}
// the first non-space character should be the delimiter
if (*pTemp == cDelimiter)
{
break;
}
// not valid entry, keep looking
else
{
pValue = pEntry + strlen(pTarget);
}
}
return pEntry;
}
int
RTSPParser::ReadRTPInfoEntry(CHXString in,
INT32 i,
INT32 length,
CHXString& out)
{
UINT32 ulLength = 0;
CHXString temp;
if (length > 0)
{
temp = in.Mid(i, length);
}
else
{
temp = in.Mid(i);
}
temp.TrimLeft();
temp.TrimRight();
ulLength = temp.GetLength();
// remove trailing ',' or ';' in case there is any
if (temp[ulLength-1] == ',' || temp[ulLength-1] == ';')
{
out = temp.Mid(0, ulLength-1);
out.TrimRight();
}
else
{
out = temp;
}
return 0;
}
int
RTSPParser::SetRTPInfoEntry(CHXString in, MIMEHeader* pHeader)
{
INT32 lURL = -1, lSeq = -1, lRTPTime = -1;
CHXString URLValue, SeqValue, RTPTimeValue;
MIMEHeaderValue* pHeaderValue = new MIMEHeaderValue;
const char* pIn = (const char*)in;
const char* pSeq = NextRTPInfoEntry(pIn, "seq=", ';');
const char* pRTPTime = NextRTPInfoEntry(pIn, "rtptime=", ';');
lURL = in.Find("url=");
HX_ASSERT(lURL == 0);
if (pSeq)
{
lSeq = pSeq - pIn;
}
if (pRTPTime)
{
lRTPTime = pRTPTime - pIn;
}
// both seq and rtptime are present
if (lSeq > 0 && lRTPTime > 0)
{
// url;seq;rtptime
if (lRTPTime > lSeq)
{
ReadRTPInfoEntry(in, lURL+4, lSeq-lURL-5, URLValue);
ReadRTPInfoEntry(in, lSeq+4, lRTPTime-lSeq-5, SeqValue);
ReadRTPInfoEntry(in, lRTPTime+8, -1, RTPTimeValue);
}
// url;rtptime;seq
else
{
ReadRTPInfoEntry(in, lURL+4, lRTPTime-lURL-5, URLValue);
ReadRTPInfoEntry(in, lRTPTime+8, lSeq-lRTPTime-9, RTPTimeValue);
ReadRTPInfoEntry(in, lSeq+4, -1, SeqValue);
}
}
// url;seq
else if (lSeq > 0)
{
ReadRTPInfoEntry(in, lURL+4, lSeq-lURL-5, URLValue);
ReadRTPInfoEntry(in, lSeq+4, -1, SeqValue);
}
// url;rtptime
else if (lRTPTime > 0)
{
ReadRTPInfoEntry(in, lURL+4, lRTPTime-lURL-5, URLValue);
ReadRTPInfoEntry(in, lRTPTime+8, -1, RTPTimeValue);
}
// invalid case, either seq or rtptime has to be present
else
{
HX_ASSERT(FALSE);
}
if (!URLValue.IsEmpty())
{
pHeaderValue->addParameter("url", URLValue);
}
if (!SeqValue.IsEmpty())
{
pHeaderValue->addParameter("seq", SeqValue);
}
if (!RTPTimeValue.IsEmpty())
{
pHeaderValue->addParameter("rtptime", RTPTimeValue);
}
pHeader->addHeaderValue(pHeaderValue);
return 0;
}
int
RTSPParser::parseBackChannelValue(const char* pValue, MIMEHeader* pHeader)
{
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?