transbuf.h
上传用户:dangjiwu
上传日期:2013-07-19
资源大小:42019k
文件大小:11k
源码类别:

Symbian

开发平台:

Visual C++

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Source last modified: $Id: transbuf.h,v 1.6.2.1 2004/07/09 02:04:37 hubbe Exp $
  3.  * 
  4.  * Portions Copyright (c) 1995-2004 RealNetworks, Inc. All Rights Reserved.
  5.  * 
  6.  * The contents of this file, and the files included with this file,
  7.  * are subject to the current version of the RealNetworks Public
  8.  * Source License (the "RPSL") available at
  9.  * http://www.helixcommunity.org/content/rpsl unless you have licensed
  10.  * the file under the current version of the RealNetworks Community
  11.  * Source License (the "RCSL") available at
  12.  * http://www.helixcommunity.org/content/rcsl, in which case the RCSL
  13.  * will apply. You may also obtain the license terms directly from
  14.  * RealNetworks.  You may not use this file except in compliance with
  15.  * the RPSL or, if you have a valid RCSL with RealNetworks applicable
  16.  * to this file, the RCSL.  Please see the applicable RPSL or RCSL for
  17.  * the rights, obligations and limitations governing use of the
  18.  * contents of the file.
  19.  * 
  20.  * Alternatively, the contents of this file may be used under the
  21.  * terms of the GNU General Public License Version 2 or later (the
  22.  * "GPL") in which case the provisions of the GPL are applicable
  23.  * instead of those above. If you wish to allow use of your version of
  24.  * this file only under the terms of the GPL, and not to allow others
  25.  * to use your version of this file under the terms of either the RPSL
  26.  * or RCSL, indicate your decision by deleting the provisions above
  27.  * and replace them with the notice and other provisions required by
  28.  * the GPL. If you do not delete the provisions above, a recipient may
  29.  * use your version of this file under the terms of any one of the
  30.  * RPSL, the RCSL or the GPL.
  31.  * 
  32.  * This file is part of the Helix DNA Technology. RealNetworks is the
  33.  * developer of the Original Code and owns the copyrights in the
  34.  * portions it created.
  35.  * 
  36.  * This file, and the files included with this file, is distributed
  37.  * and made available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY
  38.  * KIND, EITHER EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS
  39.  * ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES
  40.  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET
  41.  * ENJOYMENT OR NON-INFRINGEMENT.
  42.  * 
  43.  * Technology Compatibility Kit Test Suite(s) Location:
  44.  *    http://www.helixcommunity.org/content/tck
  45.  * 
  46.  * Contributor(s):
  47.  * 
  48.  * ***** END LICENSE BLOCK ***** */
  49. #ifndef _TRANSPORT_BUFFER_H_
  50. #define _TRANSPORT_BUFFER_H_
  51. #include "hxpends.h"
  52. #include "hxbitset.h"
  53. #include "timeval.h"
  54. #include "hxtbuf.h"
  55. #include "cachobj.h"
  56. #include "hxthread.h"
  57. class HX_deque;
  58. class ClientPacket;
  59. class RTSPTransport;
  60. class PendingPacket
  61. {
  62.   public:
  63.     PendingPacket(UINT32 ulSeqNo, UINT32 arrivalTime);
  64.     ~PendingPacket();
  65.     UINT32 m_ulSequenceNumber;
  66.     UINT32 m_ulNumPktsBehind;
  67.     UINT32 m_ulArrivalTime;
  68. };
  69. typedef enum
  70. {
  71.     TRANSBUF_INITIALIZING,
  72.     TRANSBUF_FILLING,
  73.     TRANSBUF_READY
  74. } TRANSBUF_STATUS;
  75. class BufferTimer
  76. {
  77. public:
  78.     BufferTimer() {};
  79.     ~BufferTimer() {};
  80.     Timeval m_StartTime;
  81.     Timeval m_PreviousTime;
  82.     Timeval m_LastTime;
  83.     Timeval m_PauseTime;
  84. };
  85. class RTSPTransportBuffer
  86. {
  87. public:
  88.     
  89.     RTSPTransportBuffer(RTSPTransport* pOwner, UINT16 uStreamNumber,
  90.                         UINT32 bufferDuration, UINT32 maxBufferDuration,
  91.                         UINT32 growthRate, UINT32 wrapSequenceNumber);
  92.     ~RTSPTransportBuffer();
  93.     void Reset();
  94.     void Grow();
  95.     void SetEndPacket(UINT16 uSeqNo,
  96.              UINT16 uReliableSeqNo,
  97.              BOOL   bPacketSent,
  98.              UINT32 uTimestamp);
  99.     void InformSourceStopped(void);
  100.     void InformTimestampRange(UINT32 ulStartTimestamp,
  101.      UINT32 ulEndTimestamp,
  102.      UINT32 ulEndDelayTolerance = 0);
  103.     HX_RESULT Init(UINT16 uSeqNo);
  104.     HX_RESULT Add(ClientPacket* pPacket);
  105.     HX_RESULT Insert(ClientPacket* pPacket);
  106.     HX_RESULT Flush();
  107.     HX_RESULT GetPacket(ClientPacket*& pPacket);
  108.     HX_RESULT StartPackets();
  109.     HX_RESULT StopPackets();
  110.     void ReleasePackets();
  111.     HX_RESULT GetStatus(UINT16& uStatusCode, 
  112.           UINT16& ulPercentDone);
  113.     HX_RESULT GetCurrentBuffering(INT64&  llLowestTimestamp, 
  114.     INT64&  llHighestTimestamp,
  115.     UINT32& ulNumBytes,
  116.     BOOL&   bDone);
  117.     
  118.     BOOL IsSourceDone(void) {return m_bIsEnded;};
  119.     HX_RESULT UpdateStatistics(ULONG32& ulNormal,
  120.                  ULONG32& ulLost,
  121.                  ULONG32& ulLate,
  122.                  ULONG32& ulResendRequested,
  123.                  ULONG32& ulResendReceived,
  124.                  ULONG32& ulAvgBandwidth,
  125.                  ULONG32& ulCurBandwidth,
  126.  ULONG32& ulTotal30,
  127.  ULONG32& ulLost30,
  128.  ULONG32& ulDuplicate,
  129.  ULONG32& ulOutOfOrder);
  130.     HX_RESULT SetupForACKPacket(UINT16& uSeqNo,
  131.                   CHXBitset& pBitset,
  132.                   UINT16& uBitCount,
  133.                   BOOL& didACK,
  134.                   BOOL& bLostHigh,
  135.                   BOOL& bNeedAnotherACK);
  136.     UINT32 GetIndex(UINT32 uBaseSequenceNumber, UINT16 uSeqNo);
  137.     UINT32 GetPacketIndex(UINT16 uSeqNo);
  138.     UINT32 GetSeekIndex(UINT16 uSeqNo);
  139.     UINT32 GetACKIndex(UINT16 uSeqNo);
  140.     void InitTimer();
  141.     void InitializeTime(BufferTimer* Timer);
  142.     void UpdateTime(BufferTimer* Timer);
  143.     void SetMulticast();
  144.     void SetLive() { m_bIsLive = TRUE; }
  145.     Timeval GetTime(BufferTimer* Timer);
  146.     Timeval GetTime();
  147.     Timeval AdjustedStartTime(BufferTimer* Timer);
  148.     Timeval AdjustedLastTime(BufferTimer* Timer);
  149.     void Pause();
  150.     void Resume();
  151.     void SanitizePacketQueue();
  152.     void CheckForSourceDone();
  153.     void UpdateStatsFromPacket(ClientPacket* pPacket);
  154.     void SeekFlush();
  155.     void SetBufferDepth(UINT32 uMilliseconds);
  156.     void EnterPrefetch(void);
  157.     void LeavePrefetch(void);
  158.     void DoPrefetch(void);
  159.     void EnterFastStart(void) { m_bFastStart = TRUE; };
  160.     void LeaveFastStart(void) { m_bFastStart = FALSE; };
  161.     HX_RESULT GetPacketFromCache(ClientPacket*& pPacket);
  162.     HX_RESULT GetPacketFromQueue(ClientPacket*& pPacket);
  163.     HX_RESULT           GetTransportBufferInfo(UINT32& ulLowestTimestamp,
  164.        UINT32& ulHighestTimestamp,
  165.        UINT32& ulBytesBuffered);
  166.     BOOL                OverByteLimit() const;
  167.     void                SetByteLimit(UINT32 ulByteLimit);
  168.     UINT32              GetByteLimit() const;
  169.     void                ConvertToDroppedPkt(ClientPacket*& pPacket);
  170.     void Func();
  171. private:
  172.     class RTSPTransportBufferCallback : public IHXCallback
  173.     {
  174.     public:
  175.         RTSPTransportBuffer*  m_pTransBuff;
  176.    
  177.         RTSPTransportBufferCallback(RTSPTransportBuffer* pTransBuff);
  178.         //IUnknown methods
  179.         STDMETHOD(QueryInterface) (THIS_ REFIID riid, void** ppvObj);
  180.         STDMETHOD_(ULONG32,AddRef) (THIS);
  181.         STDMETHOD_(ULONG32,Release) (THIS);
  182.         //IRMACallback methods
  183.         STDMETHOD(Func) (THIS); 
  184.         void Clear();
  185.     protected:
  186.         ~RTSPTransportBufferCallback();
  187.         LONG32 m_lRefCount;
  188.     };
  189.     CallbackHandle               m_CallbackHandle;
  190.     RTSPTransportBufferCallback* m_pCallBack;
  191.     HXMutex*                     m_pPendingLock;
  192.     
  193.     //To keep track of packets we think might be lost.
  194.     CHXSimpleList  m_PendingPackets;
  195.     IHXScheduler* m_pScheduler;
  196. #if defined(HELIX_FEATURE_FIFOCACHE)
  197.     IHXFIFOCache* m_pFIFOCache;
  198. #else
  199.     void* m_pFIFOCache;
  200. #endif /* HELIX_FEATURE_FIFOCACHE */
  201.     RTSPTransport* m_pOwner;
  202.     UINT16 m_uStreamNumber;
  203.     HX_deque* m_pPacketDeque;
  204.     CHXSimpleList m_pHoldList;
  205.     TRANSBUF_STATUS m_status;
  206.     BOOL m_bPrefetch;
  207.     BOOL m_bFastStart;
  208.     BOOL m_bCacheIsEmpty;
  209.     BOOL m_bIsInitialized;
  210.     BOOL m_bWaitingForSeekFlush;
  211.     BOOL m_bWaitingForLiveSeekFlush;
  212.     BOOL m_bFlushHolding;
  213.     BOOL m_bIsEnded;
  214.     BOOL m_bQueueIsEmpty;
  215.     BOOL m_bStreamBegin;
  216.     BOOL m_bStreamDone;
  217.     BOOL m_bSourceStopped;
  218.     BOOL m_bACKDone;
  219.     BOOL m_bStreamDoneSent;
  220.     BOOL m_bPaused;
  221.     BOOL m_bPausedHack;
  222.     UINT32 m_ulTSRollOver;
  223.     UINT32 m_bufferDuration;
  224.     UINT32 m_maxBufferDuration;
  225.     UINT32 m_growthRate;
  226.     UINT32 m_wrapSequenceNumber;
  227.     UINT32 m_ulFrontTimeStampCached;
  228.     UINT32 m_ulRearTimeStampCached;
  229.     UINT16 m_uReliableSeqNo;
  230.     UINT16 m_uEndReliableSeqNo;
  231.     UINT16 m_uFirstSequenceNumber;
  232.     UINT16 m_uLastSequenceNumber;
  233.     UINT16 m_uACKSequenceNumber;
  234.     UINT16 m_uEndSequenceNumber;
  235.     UINT16 m_uSeekSequenceNumber;
  236.     UINT16 m_uSeekCount;
  237.     UINT32 m_uNormal;
  238.     UINT32 m_ulDuplicate;
  239.     UINT32 m_ulOutOfOrder;
  240.     UINT32 m_uLost;
  241.     UINT32 m_uLate;
  242.     UINT32 m_ulIndex30;
  243.     UINT32 m_ulTotal30[30];
  244.     UINT32 m_ulLost30[30];
  245.     UINT32 m_uResendRequested;
  246.     UINT32 m_uResendReceived;
  247.     INT64 m_uByteCount;
  248.     INT64 m_uLastByteCount;
  249.     UINT32 m_uAvgBandwidth;
  250.     UINT32 m_uCurBandwidth;
  251.     UINT32 m_ulLastLost30;
  252.     UINT32 m_ulLastTotal30;
  253.     UINT32 m_uLastTimestamp;
  254.     UINT32 m_uStartTimestamp;
  255.     UINT32 m_uEndTimestamp;
  256.     UINT32 m_ulEndDelayTolerance;
  257.     BOOL m_bExpectedTSRangeSet;
  258.     BufferTimer m_StatisticsTime;
  259.     BufferTimer m_PacketTime;
  260.     BufferTimer m_LastPacketTime;
  261.     BOOL m_bPacketsStarted;
  262.     UINT32 m_ulCurrentQueueByteCount;
  263.     UINT32 m_ulCurrentCacheByteCount;
  264.     BOOL m_bAtLeastOnePacketReceived;
  265.     BOOL m_bAtLeastOneResetHandled;
  266.     UINT32 m_ulFirstTimestampReceived;
  267.     UINT32 m_ulLastTimestampReceived;
  268.     UINT32 m_ulBufferingStartTime;
  269.     UINT32 m_ulLastGrowTime;
  270.     BOOL m_bMulticast;
  271.     BOOL m_bMulticastReset;
  272.     BOOL m_bMulticastReliableSeqNoSet;
  273.     BOOL m_bIsLive;
  274.     BOOL m_bSparseStream;
  275.     UINT32              m_ulByteLimit; /* Max number of bytes allowed in
  276. * in queue. 0 means unlimited
  277. */
  278. };
  279. inline UINT32
  280. RTSPTransportBuffer::GetPacketIndex(UINT16 uSeqNo)
  281. {
  282.     return GetIndex(m_uFirstSequenceNumber, uSeqNo);
  283. }
  284. inline UINT32
  285. RTSPTransportBuffer::GetSeekIndex(UINT16 uSeqNo)
  286. {
  287.     return GetIndex(m_uSeekSequenceNumber, uSeqNo);
  288. }
  289. inline UINT32
  290. RTSPTransportBuffer::GetACKIndex(UINT16 uSeqNo)
  291. {
  292.     return GetIndex(m_uACKSequenceNumber, uSeqNo);
  293. }
  294. inline void                
  295. RTSPTransportBuffer::SetByteLimit(UINT32 ulByteLimit)
  296. {
  297.     m_ulByteLimit = ulByteLimit;
  298. }
  299. inline UINT32
  300. RTSPTransportBuffer::GetByteLimit() const
  301. {
  302.     return m_ulByteLimit;
  303. }
  304. #endif /* _TRANSPORT_BUFFER_H_ */