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

Symbian

开发平台:

Visual C++

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Source last modified: $Id: chxpckts.h,v 1.4.32.3 2004/07/09 01:45:51 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 _HXPCKTS_H_
  50. #include "hxcppflags.h"
  51. #ifndef HX_CPP_BASIC_TEMPLATES
  52. #include "old_hxpckts.h"
  53. #else
  54. #define _HXPCKTS_H_
  55. #include "assocvector.h"
  56. #include "hxtypes.h"
  57. #include "hlxclib/string.h"
  58. #include "hxmap.h"
  59. #include "ihxpckts.h"
  60. #include "hxbuffer.h" /* For all the places that just include this */
  61. struct HXPacketInfo
  62. {
  63.     UINT8   lost;
  64.     UINT8   ASMFlags;
  65.     UINT16  ASMRuleNumber;
  66.     UINT16  streamNum;
  67.     UINT32  time;
  68. };
  69. /****************************************************************************
  70.  * 
  71.  *        Class:
  72.  *
  73.  *                CHXPacket
  74.  *
  75.  *        Purpose:
  76.  *
  77.  *                PN implementation of a basic packet.
  78.  *
  79.  */
  80. class CHXPacket : public IHXRTPPacket
  81. {
  82. protected:
  83.     LONG32                m_lRefCount;
  84.     IHXBuffer*                m_pBuffer;
  85.     ULONG32                m_ulTime;
  86.     UINT16                m_uStreamNumber;        
  87.     UINT8                m_unASMFlags;
  88.     UINT16                m_unASMRuleNumber;
  89.     BOOL                m_bIsLost;
  90.     
  91.     ~CHXPacket()
  92.     {
  93.         if (m_pBuffer)
  94.         {
  95.             m_pBuffer->Release();
  96.         }
  97.     };
  98.     
  99.     inline HX_RESULT _Get(
  100.         IHXBuffer*& pBuffer, 
  101.         ULONG32 &ulTime,
  102.         UINT16 &uStreamNumber,
  103.         UINT8 &unASMFlags,
  104.         UINT16 &unASMRuleNumber);
  105.     inline HX_RESULT _Set(
  106.            IHXBuffer* pBuffer, 
  107.            ULONG32 ulTime,
  108.            UINT16 uStreamNumber,
  109.            UINT8 unASMFlags,
  110.            UINT16 unASMRuleNumber);
  111. public:
  112.     CHXPacket()
  113.         : m_lRefCount(0)
  114.         , m_pBuffer(NULL)
  115.         , m_ulTime(0)
  116.         , m_uStreamNumber(0)
  117.         , m_unASMFlags(0)
  118.         , m_unASMRuleNumber(0)
  119.         , m_bIsLost(FALSE)
  120.     {
  121.         ;
  122.     }
  123.     /*
  124.      *        IUnknown methods
  125.      */
  126.     STDMETHOD(QueryInterface)        (THIS_
  127.                                 REFIID riid,
  128.                                 void** ppvObj);
  129.     STDMETHOD_(ULONG32,AddRef)        (THIS);
  130.     STDMETHOD_(ULONG32,Release)        (THIS);
  131.     /*
  132.      *        IHXPacket methods
  133.      */
  134.     STDMETHOD(Get)  (THIS_
  135.                     REF(IHXBuffer*)        pBuffer, 
  136.                     REF(ULONG32)                ulTime,
  137.                     REF(UINT16)                uStreamNumber,
  138.                     REF(UINT8)                unASMFlags,
  139.                     REF(UINT16)                unASMRuleNumber);
  140.     STDMETHOD_(IHXBuffer*,GetBuffer)                (THIS);
  141.     STDMETHOD_(ULONG32,GetTime)                        (THIS);
  142.     STDMETHOD_(UINT16,GetStreamNumber)                (THIS);
  143.     STDMETHOD_(UINT8,GetASMFlags)                (THIS);
  144.     STDMETHOD_(UINT16,GetASMRuleNumber)                (THIS);
  145.     STDMETHOD_(BOOL,IsLost)                        (THIS);
  146.     STDMETHOD(SetAsLost)                        (THIS);
  147.     STDMETHOD(Set)                                (THIS_
  148.                                                 IHXBuffer*                pBuffer, 
  149.                                                 ULONG32                        ulTime,
  150.                                                 UINT16                        uStreamNumber,
  151.                                                 UINT8                        unASMFlags,
  152.                                                 UINT16                        unASMRuleNumber);
  153.     /*
  154.      *        IHXPacket methods
  155.      */
  156.    STDMETHOD(GetRTP)                                (THIS_
  157.                                                 REF(IHXBuffer*)        pBuffer, 
  158.                                                 REF(ULONG32)                ulTime,
  159.                                                 REF(ULONG32)                ulRTPTime,
  160.                                                 REF(UINT16)                uStreamNumber,
  161.                                                 REF(UINT8)                unASMFlags,
  162.                                                 REF(UINT16)                unASMRuleNumber);
  163.    STDMETHOD_(ULONG32,GetRTPTime)                (THIS);
  164.    STDMETHOD(SetRTP)                                (THIS_
  165.                                                 IHXBuffer*                pBuffer, 
  166.                                                 ULONG32                        ulTime,
  167.                                                 ULONG32                        ulRTPTime,
  168.                                                 UINT16                        uStreamNumber,
  169.                                                 UINT8                        unASMFlags,
  170.                                                 UINT16                        unASMRuleNumber);
  171.    // serialization method
  172.    static void        Pack        (IHXPacket* pPacket, char* pData, UINT32& ulSize);
  173.    static void        UnPack        (IHXPacket*& pPacket, char* pData, UINT32 ulSize);
  174. };
  175. /****************************************************************************
  176.  * 
  177.  *        Class:
  178.  *
  179.  *                CHXRTPPacket
  180.  *
  181.  *        Purpose:
  182.  *
  183.  *                PN implementation of a RTP packet.
  184.  *
  185.  */
  186. class CHXRTPPacket : public CHXPacket
  187. {
  188. protected:
  189.     ULONG32                        m_ulRTPTime;
  190.     ~CHXRTPPacket()
  191.     {
  192.         ;
  193.     }
  194. public:
  195.     CHXRTPPacket()
  196.         : m_ulRTPTime(0)
  197.     {
  198.         ;
  199.     }
  200.     /*
  201.      *        IUnknown methods - override
  202.      */
  203.     STDMETHOD(QueryInterface)        (THIS_
  204.                                 REFIID riid,
  205.                                 void** ppvObj);
  206.     STDMETHOD_(ULONG32,Release)        (THIS);
  207.     /*
  208.      *        IHXPacket methods - override
  209.      */
  210.     STDMETHOD(Set)                                (THIS_
  211.                                                 IHXBuffer*                pBuffer, 
  212.                                                 ULONG32                        ulTime,
  213.                                                 UINT16                        uStreamNumber,
  214.                                                 UINT8                        unASMFlags,
  215.                                                 UINT16                        unASMRuleNumber);
  216.     /*
  217.      *        IHXRTPPacket methods - override
  218.      */
  219.     STDMETHOD(GetRTP)                                (THIS_
  220.                                                 REF(IHXBuffer*)        pBuffer, 
  221.                                                 REF(ULONG32)                ulTime,
  222.                                                 REF(ULONG32)                ulRTPTime,
  223.                                                 REF(UINT16)                uStreamNumber,
  224.                                                 REF(UINT8)                unASMFlags,
  225.                                                 REF(UINT16)                unASMRuleNumber);
  226.     STDMETHOD_(ULONG32,GetRTPTime)                (THIS);
  227.     STDMETHOD(SetRTP)                                (THIS_
  228.                                                 IHXBuffer*                pBuffer, 
  229.                                                 ULONG32                        ulTime,
  230.                                                 ULONG32                        ulRTPTime,
  231.                                                 UINT16                        uStreamNumber,
  232.                                                 UINT8                        unASMFlags,
  233.                                                 UINT16                        unASMRuleNumber);
  234. };
  235. class _CStoreName
  236. {
  237. public:
  238.     _CStoreName();
  239.     virtual ~_CStoreName();
  240.     const CHXString& GetName() const;
  241.     void SetName(const char* szName);
  242. private:
  243.     CHXString m_strName;
  244. };
  245. class _CStoreNameUINT32Pair : public _CStoreName
  246. {
  247. public:
  248.     _CStoreNameUINT32Pair();
  249.     ~_CStoreNameUINT32Pair();
  250.     UINT32 GetValue();
  251.     void SetValue(UINT32 ulValue);
  252. private:
  253.     UINT32 m_ulValue;
  254. };
  255. class _CStoreNameBufferPair : public _CStoreName
  256. {
  257. public:
  258.     _CStoreNameBufferPair();
  259.     ~_CStoreNameBufferPair();
  260.     IHXBuffer* GetValue();
  261.     void SetValue(IHXBuffer* pbufValue);
  262. private:
  263.     IHXBuffer* m_pbufValue;
  264. };
  265. /****************************************************************************
  266.  * 
  267.  *        Class:
  268.  *
  269.  *                CHXHeader
  270.  *
  271.  *        Purpose:
  272.  *
  273.  *                PN implementation of a basic header.
  274.  *
  275.  */
  276. class CHXHeader : public IHXValues
  277. {
  278. private:
  279.     INT32                        m_lRefCount;
  280.     struct CValue
  281.     {
  282.         UINT32 m_lVal;
  283.         BOOL m_lValValid;
  284.         IHXBuffer* m_pIBuffer;
  285.         IHXBuffer* m_pIString;
  286.         const char* m_Key;
  287.         CValue() : m_lValValid(FALSE), m_pIBuffer(NULL), 
  288.             m_pIString(NULL), m_Key(NULL)
  289.         {
  290.         }
  291.         CValue(CValue const& rhs)
  292.         :   m_lVal(rhs.m_lVal), 
  293.             m_lValValid(rhs.m_lValValid), 
  294.             m_pIBuffer(rhs.m_pIBuffer),
  295.             m_pIString(rhs.m_pIString), 
  296.             m_Key(rhs.m_Key)
  297.         {
  298.             if (m_pIBuffer) m_pIBuffer->AddRef();
  299.             if (m_pIString) m_pIString->AddRef();
  300.         }
  301.         CValue& operator= (CValue const&);
  302.         ~CValue();
  303.         HX_RESULT Get(IHXBuffer* CValue::*pMem, IHXBuffer*& value) const
  304.         {
  305.             if (!(this->*pMem)) return HXR_FAIL;
  306.             value = this->*pMem;
  307.             value->AddRef ();
  308.             return HXR_OK;
  309.         }
  310.         
  311.         HX_RESULT Get(UINT32 CValue::*pMem, UINT32& value) const
  312.         {
  313.             HX_ASSERT(pMem == &CValue::m_lVal);
  314.             if (!m_lValValid) return HXR_FAIL;
  315.             value = m_lVal;
  316.             return HXR_OK;
  317.         }
  318.         
  319.         void Set(IHXBuffer* CValue::*pMem, IHXBuffer* value)
  320.         {
  321.             HX_ASSERT(value);
  322.             HX_RELEASE (this->*pMem);
  323.             this->*pMem = value;
  324.             value->AddRef();
  325.         }
  326.         
  327.         void Set(UINT32 CValue::*pMem, UINT32 value)
  328.         {
  329.                 m_lVal = value;
  330.                 m_lValValid = TRUE;
  331.         }
  332.         
  333.         void Swap(CValue& rhs)
  334.         {
  335.             std::swap(m_lVal, rhs.m_lVal);
  336.             std::swap(m_lValValid, rhs.m_lValValid);
  337.             std::swap(m_pIBuffer, rhs.m_pIBuffer);
  338.             std::swap(m_pIString, rhs.m_pIString);
  339.             std::swap(m_Key, rhs.m_Key);
  340.         }
  341.     };
  342.     struct MyCompare : public std::binary_function<const char*, const char*, bool>
  343.     {
  344.         char m_PreserveCase;
  345.         
  346.         explicit MyCompare(char PreserveCase) : m_PreserveCase(PreserveCase) 
  347.         {
  348.         }
  349.         bool operator()(const char* p1, const char* p2) const;
  350.     };
  351.     
  352.     typedef Loki::AssocVector<const char*, CValue, MyCompare> Map;
  353.     //typedef std::map<std::string, CValue/*, MyCompare*/> Map;
  354.     Map m_Map;
  355.     template <typename TVal>
  356.     HX_RESULT GetProperty(
  357.         const char* pPropertyName,
  358.         TVal CValue::*pMem,
  359.         TVal& value)
  360.     {
  361.         HX_ASSERT(pPropertyName);
  362.         //HX_ASSERT(pMem);
  363.         Map::const_iterator i = m_Map.find(pPropertyName);
  364.         return (i == m_Map.end()) ? HXR_FAIL : i->second.Get(pMem, value);
  365.     }
  366.     
  367.     template <typename TVal>
  368.     HX_RESULT SetProperty(
  369.             const char* pPropertyName,
  370.             TVal CValue::*pMem,
  371.             TVal value)
  372.     {
  373.         HX_ASSERT(pPropertyName);
  374.         Map::iterator i = m_Map.find(pPropertyName);
  375.         CValue* pVal; // uninitialized
  376.         if (i == m_Map.end())
  377.         {
  378.             char* pTmp = new char[strlen(pPropertyName)+1];
  379.             strcpy(pTmp, pPropertyName); /* Flawfinder: ignore */
  380.     pVal = &m_Map[pTmp];
  381.             pVal->m_Key = pTmp;
  382.         }
  383.         else
  384.         {
  385.             pVal = &i->second;
  386.         }
  387.         pVal->Set(pMem, value);
  388.         
  389.         return HXR_OK;
  390.     }
  391.     
  392.     template <typename TVal>
  393.     HX_RESULT GetNextProperty(
  394.             const char*& pPropertyName,
  395.             TVal CValue::*pMem,
  396.             TVal& value,
  397.             Map::const_iterator& iter)
  398.     {
  399.             for (; iter != m_Map.end(); ++iter)
  400.             {
  401.                     if (SUCCEEDED(iter->second.Get(pMem, value)))
  402.                     {
  403.                             pPropertyName = iter->second.m_Key;
  404.                             return HXR_OK;
  405.                     }
  406.             }
  407.             return HXR_FAIL;
  408.     }
  409.         Map::const_iterator 
  410.                 m_ULONG32Position,
  411.                 m_BufferPosition,
  412.                 m_CStringPosition;
  413.         ~CHXHeader();
  414.         PRIVATE_DESTRUCTORS_ARE_NOT_A_CRIME
  415. protected:
  416. #if 0
  417. // function to encode CString property escape sequences
  418.         IHXBuffer*                encodeCString(IHXBuffer* pBuffer);
  419. // function to encode buffer property int MIME Base64
  420.         IHXBuffer*                encodeBuffer(IHXBuffer* pBuffer);
  421. #endif
  422. public:
  423.         CHXHeader()
  424.                 : m_lRefCount(0)
  425.                 , m_Map(MyCompare(FALSE)) // case-insensitive by default
  426.         {
  427.                 m_ULONG32Position = m_BufferPosition = m_CStringPosition = m_Map.end();
  428.         }
  429.     /*
  430.      *        IUnknown methods
  431.      */
  432.     STDMETHOD(QueryInterface)                (THIS_
  433.                                         REFIID riid,
  434.                                         void** ppvObj);
  435.     STDMETHOD_(ULONG32,AddRef)                (THIS);
  436.     STDMETHOD_(ULONG32,Release)                (THIS);
  437.     /*
  438.      *        IHXValues methods
  439.      */
  440.     STDMETHOD(SetPropertyULONG32)        (THIS_
  441.                                         const char*         pPropertyName,
  442.                                         ULONG32                 uPropertyValue);
  443.     STDMETHOD(GetPropertyULONG32)        (THIS_
  444.                                         const char*         pPropertyName,
  445.                                         REF(ULONG32)         uPropertyValue);
  446.     STDMETHOD(GetFirstPropertyULONG32)        (THIS_
  447.                                         REF(const char*) pPropertyName,
  448.                                         REF(ULONG32)         uPropertyValue);
  449.     STDMETHOD(GetNextPropertyULONG32)        (THIS_
  450.                                         REF(const char*) pPropertyName,
  451.                                         REF(ULONG32)         uPropertyValue);
  452.     STDMETHOD(SetPropertyBuffer)        (THIS_
  453.                                         const char*         pPropertyName,
  454.                                         IHXBuffer*         pPropertyValue);
  455.     STDMETHOD(GetPropertyBuffer)        (THIS_
  456.                                         const char*         pPropertyName,
  457.                                         REF(IHXBuffer*) pPropertyValue);
  458. #if 0
  459.     STDMETHOD(GetEncodedPropertyBuffer)        (THIS_
  460.                                         const char*         pPropertyName,
  461.                                         REF(IHXBuffer*) pPropertyValue);
  462. #endif
  463.     STDMETHOD(GetFirstPropertyBuffer)        (THIS_
  464.                                         REF(const char*) pPropertyName,
  465.                                         REF(IHXBuffer*) pPropertyValue);
  466.     STDMETHOD(GetNextPropertyBuffer)        (THIS_
  467.                                         REF(const char*) pPropertyName,
  468.                                         REF(IHXBuffer*) pPropertyValue);
  469.     STDMETHOD(SetPropertyCString)        (THIS_
  470.                                         const char*         pPropertyName,
  471.                                         IHXBuffer*         pPropertyValue);
  472.     STDMETHOD(GetPropertyCString)        (THIS_
  473.                                         const char*         pPropertyName,
  474.                                         REF(IHXBuffer*) pPropertyValue);
  475. #if 0
  476.     STDMETHOD(GetEncodedPropertyCString)(THIS_
  477.                                         const char*         pPropertyName,
  478.                                         REF(IHXBuffer*) pPropertyValue);
  479. #endif
  480.     STDMETHOD(GetFirstPropertyCString)        (THIS_
  481.                                         REF(const char*) pPropertyName,
  482.                                         REF(IHXBuffer*) pPropertyValue);
  483.     STDMETHOD(GetNextPropertyCString)        (THIS_
  484.                                         REF(const char*) pPropertyName,
  485.                                         REF(IHXBuffer*) pPropertyValue);
  486.     void PreserveCase(BOOL bPreserve);
  487. public:
  488.     static void mergeHeaders
  489.     (
  490.         IHXValues* pIHXValuesDestHeaders, 
  491.         IHXValues* pIHXValuesSourceHeaders
  492.     );
  493. };
  494. #endif
  495. #endif /* _HXPCKTS_H_ */