transbuf.h
上传用户:zhongxx05
上传日期:2007-06-06
资源大小:33641k
文件大小:10k
源码类别:

Symbian

开发平台:

C/C++

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