hxsm2.cpp
来自「symbian 下的helix player源代码」· C++ 代码 · 共 1,302 行 · 第 1/3 页
CPP
1,302 行
/* ***** BEGIN LICENSE BLOCK *****
* Source last modified: $Id: hxsm2.cpp,v 1.9.8.2 2004/07/09 02:05:30 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 "hxsm2.h"
#include "hxsmutil.h"
#include "ihxpckts.h"
#include "hxprefs.h"
#include "hxpref.h"
#include "hxbsrc.h" /* HXSource */
#include "asmrulep.h" /* ASMRuleBook */
#include "hxbuffer.h" /* CHXBuffer */
#include "chxpckts.h" /* CHXHeader */
#include "safestring.h" /* SafeSprintf */
#include "rtspif.h" /* RTSPSubscription */
class ASMStreamInfo2;
class ASMSourceInfo2
{
public:
ASMSourceInfo2(HXSource* pSource);
~ASMSourceInfo2();
UINT32 StreamCount() const;
ASMStreamInfo2* GetStream(UINT32 i);
UINT32& SubscribeBw();
UINT32& LastSetDelivery();
UINT32& MasterOffer();
BOOL IsMySource(HXSource* pSource);
BOOL IsLive();
BOOL IsPerfectPlay() const;
BOOL HasMasterRuleBook() const;
void DistributeBw();
CHXSimpleList* SubsChanges();
void SubscribeToChanges();
void SetDeliveryBw(UINT32 ulMaxBw);
void Done();
private:
HX_RESULT GetSubInfo(UINT32 ulBandwidth,
BOOL* pCurrentSubInfo);
UINT32 GetStreamBw(IHXValues* pProps,
UINT32 ulStreamIndex) const;
HXSource* m_pSource;
UINT32 m_ulStreamCount;
ASMStreamInfo2** m_pStreams;
UINT32 m_ulSubscribedBw;
UINT32 m_ulLastSetDelivery;
UINT32 m_ulMasterOffer;
BOOL m_bPerfectPlay;
ASMRuleBook* m_pMasterRuleBook;
IHXValues* m_pSubsVars;
CHXSimpleList m_subsChanges;
};
class ASMStreamInfo2
{
public:
ASMStreamInfo2(IUnknown* pStream);
~ASMStreamInfo2();
HX_RESULT GetBiasFactor(REF(INT32) lBiasFactor);
BOOL IsFixedBw() const;
UINT32 CurrentBw() const;
UINT32 StreamID() const;
void SetStreamOffer(UINT32 ulOffer);
void SelectBw(BOOL bPerfectPlay,
UINT32 ulAltOffer);
UINT32 ResistanceToLower() const;
void SelectNextLowerBw();
UINT32 GetLastBw() const;
void SubscribeToNewBw(UINT32 ulBw, CHXSimpleList* pSubChanges);
void SubscribeToChanges(CHXSimpleList* pSubChanges);
private:
void ComputeResistence(BOOL bPerfectPlay);
BOOL m_bFixedBwValid;
UINT32 m_ulFixedBandwidth;
UINT32 m_ulNumThresholds;
float* m_pThresholds;
UINT32 m_ulCurThresh;
UINT32 m_ulMaxEffectiveThreshold;
IHXStreamBandwidthBias* m_pBias;
IHXStreamBandwidthNegotiator* m_pNegotiator;
IHXAtomicRuleGather* m_pRuleGather;
UINT32 m_ulStreamID;
UINT32 m_ulStreamOffer; // From master rulebook
UINT32 m_ulOffer; // From SelectBw()
UINT32 m_ulResistanceToLower;
UINT32 m_ulLastBw;
};
class ASMStreamInfoItr
{
public:
ASMStreamInfoItr(CHXSimpleList* pSourceList);
ASMSourceInfo2* Source();
ASMStreamInfo2* Stream();
BOOL More() const;
void Next();
void Reset();
private:
void FindNextSource();
CHXSimpleList* m_pSourceList;
CHXSimpleList::Iterator m_itr;
UINT32 m_ulStream;
};
ASMStreamInfoItr::ASMStreamInfoItr(CHXSimpleList* pSourceList) :
m_pSourceList(pSourceList),
m_ulStream(0)
{
Reset();
}
ASMSourceInfo2* ASMStreamInfoItr::Source()
{
ASMSourceInfo2* pRet = 0;
if (More())
{
pRet = (ASMSourceInfo2*)(*m_itr);
}
return pRet;
}
ASMStreamInfo2* ASMStreamInfoItr::Stream()
{
ASMStreamInfo2* pRet = 0;
ASMSourceInfo2* pSrc = Source();
if (pSrc)
{
pRet = pSrc->GetStream(m_ulStream);
}
return pRet;
}
BOOL ASMStreamInfoItr::More() const
{
return (m_pSourceList &&
(m_itr != m_pSourceList->End()));
}
void ASMStreamInfoItr::Next()
{
if (More())
{
m_ulStream++;
if (m_ulStream == Source()->StreamCount())
{
// We are done with this source.
// Move onto the next one
m_ulStream = 0;
++m_itr;
FindNextSource();
}
}
}
void ASMStreamInfoItr::Reset()
{
if (m_pSourceList)
{
m_ulStream = 0;
m_itr = m_pSourceList->Begin();
FindNextSource();
}
}
void ASMStreamInfoItr::FindNextSource()
{
BOOL bDone = FALSE;
while(!bDone && m_itr != m_pSourceList->End())
{
ASMSourceInfo2* pSrc = (ASMSourceInfo2*)(*m_itr);
if (pSrc && pSrc->StreamCount() > 0)
{
bDone = TRUE;
}
else
{
++m_itr;
}
}
}
ASMSourceInfo2::ASMSourceInfo2(HXSource* pSource) :
m_pSource(pSource),
m_ulStreamCount(0),
m_pStreams(0),
m_ulSubscribedBw(0),
m_ulLastSetDelivery(0),
m_ulMasterOffer(0),
m_bPerfectPlay(FALSE),
m_pMasterRuleBook(0),
m_pSubsVars(0)
{
if (m_pSource)
{
m_pSource->AddRef();
m_bPerfectPlay = m_pSource->IsPerfectPlay();
m_ulStreamCount = pSource->GetStreamCount();
m_pStreams = new ASMStreamInfo2*[m_ulStreamCount];
if (m_pStreams)
{
for (UINT32 i = 0; i < m_ulStreamCount; i++)
{
IUnknown* pStream = 0;
HX_VERIFY(HXR_OK == pSource->GetStream(i, pStream));
m_pStreams[i] = new ASMStreamInfo2(pStream);
HX_RELEASE(pStream);
}
}
// Get Master Rulebook
if (pSource->m_pFileHeader)
{
IHXBuffer* pMasterRuleBook = NULL;
pSource->m_pFileHeader->
GetPropertyCString("ASMRuleBook", pMasterRuleBook);
if (pMasterRuleBook)
{
m_pMasterRuleBook = new ASMRuleBook
((const char *)pMasterRuleBook->GetBuffer());
}
HX_RELEASE(pMasterRuleBook);
}
}
}
ASMSourceInfo2::~ASMSourceInfo2()
{
if (m_pStreams)
{
for (UINT32 i = 0; i < m_ulStreamCount; i++)
{
delete m_pStreams[i];
m_pStreams[i] = 0;
}
delete [] m_pStreams;
}
HX_RELEASE(m_pSource);
HX_RELEASE(m_pSubsVars);
delete m_pMasterRuleBook;
m_pMasterRuleBook = 0;
}
inline
UINT32 ASMSourceInfo2::StreamCount() const
{
return m_ulStreamCount;
}
ASMStreamInfo2* ASMSourceInfo2::GetStream(UINT32 i)
{
ASMStreamInfo2* pRet = 0;
if (m_pStreams && (i < m_ulStreamCount))
{
pRet = m_pStreams[i];
}
return pRet;
}
inline
UINT32& ASMSourceInfo2::SubscribeBw()
{
return m_ulSubscribedBw;
}
inline
UINT32& ASMSourceInfo2::LastSetDelivery()
{
return m_ulLastSetDelivery;
}
inline
UINT32& ASMSourceInfo2::MasterOffer()
{
return m_ulMasterOffer;
}
inline
BOOL ASMSourceInfo2::IsMySource(HXSource* pSource)
{
return (m_pSource == pSource);
}
BOOL ASMSourceInfo2::IsLive()
{
BOOL bRet = FALSE;
if (m_pSource)
{
bRet = m_pSource->IsLive();
}
return bRet;
}
inline
BOOL ASMSourceInfo2::IsPerfectPlay() const
{
return m_bPerfectPlay;
}
inline
BOOL ASMSourceInfo2::HasMasterRuleBook() const
{
return (m_pMasterRuleBook != NULL);
}
void ASMSourceInfo2::DistributeBw()
{
if (m_pMasterRuleBook)
{
UINT32 ulRuleCount = m_pMasterRuleBook->GetNumRules();
BOOL* pCurrentSubInfo = new BOOL[ulRuleCount];
GetSubInfo(m_ulMasterOffer, pCurrentSubInfo);
for (UINT16 idxRule = 0; idxRule < ulRuleCount; idxRule++)
{
if (pCurrentSubInfo[idxRule])
{
IHXValues* pProps = 0;
// Set Distribution
m_pMasterRuleBook->GetProperties(idxRule, pProps);
for (UINT32 j = 0; j < m_ulStreamCount; j++)
{
UINT32 ulStreamBw = GetStreamBw(pProps, j);
m_pStreams[j]->SetStreamOffer(ulStreamBw);
}
HX_RELEASE(pProps);
break;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?