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

Symbian

开发平台:

Visual C++

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Source last modified: $Id: hxcommn.cpp,v 1.10.18.2 2004/07/09 02:06:33 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. #include "hxtypes.h"
  50. #include "hxcom.h"
  51. #include "hxresult.h"
  52. #include "hxstrutl.h"
  53. #include "hxstring.h"
  54. #include "hxcomm.h"
  55. #include "ihxpckts.h"
  56. #include "hxfiles.h"
  57. #include "hxcore.h"
  58. #include "hxmon.h"
  59. #include "hxplugn.h"
  60. #include "hxvalue.h"
  61. #include "hxcache.h"
  62. #include "hxtbuf.h"
  63. #include "cachobj.h"
  64. #include "smartptr.h"
  65. #include "miscsp.h"
  66. #include "unkimp.h"
  67. //#include "rncont.h"
  68. #include "hxlist.h"
  69. //#include "rnmap.h"
  70. #include "chxfgbuf.h"
  71. #include "chxpckts.h"
  72. #include "watchlst.h"
  73. #include "hxclreg.h"
  74. #include "hxrquest.h"
  75. #include "hxvalues.h"
  76. #if defined(_WINDOWS) && !defined(_WINCE)
  77. #ifdef _WIN32
  78. #include <vfw.h>
  79. #else
  80. #include <windows.h>
  81. #include <drawdib.h>
  82. #endif /* _WIN32 */
  83. #endif /* _WINDOWS */
  84. // Needed for CHXSiteWindowed
  85. #include "hxwintyp.h"
  86. #include "chxxtype.h"
  87. #include "hxwin.h"
  88. #include "hxengin.h"
  89. #include "hxsite2.h"
  90. #include "hxslist.h"
  91. //#include "hxcodec.h"
  92. #include "hxvsurf.h"
  93. #include "hxvctrl.h"
  94. #include "dllacces.h"
  95. #include "dllaccesserver.h"
  96. #include "dllpath.h"
  97. #if defined(HELIX_FEATURE_FILESYSTEMMGR)
  98. #include "hxfsmgr.h"
  99. #endif
  100. #include "hxmisus.h"
  101. //#include "rmafsmgr.h"
  102. #include "hxcommn.h"
  103. //#include "plgnhand.h"
  104. #include "plghand2.h"
  105. #include "hxplugn.h"
  106. #include "hxgrpen2.h"
  107. #include "chxuuid.h"
  108. //#include "rmargn.h"
  109. //#include "hxausvc.h"
  110. #include "hxmutex.h"
  111. #include "chxminiccf.h"
  112. #include "hxheap.h"
  113. #ifdef _DEBUG
  114. #undef HX_THIS_FILE
  115. static const char HX_THIS_FILE[] = __FILE__;
  116. #endif
  117. HXCommonClassFactory::HXCommonClassFactory(IUnknown* pContext) :
  118.      m_lRefCount (0)
  119.     ,m_pContext(pContext)
  120.     ,m_pMiniCCF(new CHXMiniCCF())
  121. {
  122.     if (m_pContext)
  123.     {
  124. m_pContext->AddRef();
  125.     }
  126.     if (m_pMiniCCF)
  127.     {
  128. m_pMiniCCF->AddRef();
  129.     }
  130. }
  131. HXCommonClassFactory::~HXCommonClassFactory()
  132.     Close();
  133. }
  134. void
  135. HXCommonClassFactory::Close()
  136.     HX_RELEASE(m_pContext);
  137.     HX_RELEASE(m_pMiniCCF);
  138. }
  139. /*
  140.  * IUnknown methods
  141.  */
  142. /////////////////////////////////////////////////////////////////////////
  143. // Method:
  144. // IUnknown::QueryInterface
  145. // Purpose:
  146. // Implement this to export the interfaces supported by your 
  147. // object.
  148. //
  149. STDMETHODIMP HXCommonClassFactory::QueryInterface(REFIID riid, void** ppvObj)
  150. {
  151.     QInterfaceList qiList[] =
  152.         {
  153.             { GET_IIDHANDLE(IID_IHXCommonClassFactory), (IHXCommonClassFactory*)this },
  154.             { GET_IIDHANDLE(IID_IUnknown), (IUnknown*)(IHXCommonClassFactory*)this },
  155.         };
  156.     
  157.     return ::QIFind(qiList, QILISTSIZE(qiList), riid, ppvObj);
  158. }
  159. /////////////////////////////////////////////////////////////////////////
  160. // Method:
  161. // IUnknown::AddRef
  162. // Purpose:
  163. // Everyone usually implements this the same... feel free to use
  164. // this implementation.
  165. //
  166. STDMETHODIMP_(ULONG32) HXCommonClassFactory::AddRef()
  167. {
  168.     return InterlockedIncrement(&m_lRefCount);
  169. }
  170. /////////////////////////////////////////////////////////////////////////
  171. // Method:
  172. // IUnknown::Release
  173. // Purpose:
  174. // Everyone usually implements this the same... feel free to use
  175. // this implementation.
  176. //
  177. STDMETHODIMP_(ULONG32) HXCommonClassFactory::Release()
  178. {
  179.     if (InterlockedDecrement(&m_lRefCount) > 0)
  180.     {
  181. return m_lRefCount;
  182.     }
  183.     delete this;
  184.     return 0;
  185. }
  186. /************************************************************************
  187.  * Method:
  188.  * IHXController::CreateInstance
  189.  * Purpose:
  190.  * Creates instances of common objects supported by the system,
  191.  * like IHXBuffer, IHXPacket, IHXValues, etc.
  192.  *
  193.  * This method is similar to Window's CoCreateInstance() in its 
  194.  * purpose, except that it only creates objects of a well known
  195.  * types.
  196.  *
  197.  * NOTE: Aggregation is never used. Therefore and outer unknown is
  198.  * not passed to this function, and you do not need to code for this
  199.  * situation.
  200.  */
  201. STDMETHODIMP HXCommonClassFactory::CreateInstance
  202. (
  203.     REFCLSID /*IN*/ rclsid,
  204.     void** /*OUT*/ ppUnknown
  205. )
  206. {
  207.     if (m_pMiniCCF)
  208.     {
  209. HX_RESULT res = m_pMiniCCF->CreateInstance(rclsid, ppUnknown);
  210. if (HXR_NOINTERFACE != res)
  211. {
  212.     return res;
  213. }
  214.     }
  215.     if (IsEqualCLSID(rclsid, CLSID_IHXPacket))
  216.     {
  217. *ppUnknown = (IUnknown*)(IHXPacket*)(new CHXPacket());
  218.         if( !*ppUnknown )
  219.         {
  220.             return HXR_OUTOFMEMORY;
  221.         }
  222. ((IUnknown*)*ppUnknown)->AddRef();
  223. return HXR_OK;
  224.     }
  225.     else if (IsEqualCLSID(rclsid, CLSID_IHXRTPPacket))
  226.     {
  227. *ppUnknown = (IUnknown*)(IHXRTPPacket*)(new CHXRTPPacket());
  228.         if( !*ppUnknown )
  229.         {
  230.             return HXR_OUTOFMEMORY;
  231.         }
  232. ((IUnknown*)*ppUnknown)->AddRef();
  233. return HXR_OK;
  234.     }
  235.     else if(IsEqualCLSID(rclsid, CLSID_IHXRequest))
  236.     {
  237. *ppUnknown = (IUnknown*)(IHXRequest*)(new CHXRequest());
  238.         if( !*ppUnknown )
  239.         {
  240.             return HXR_OUTOFMEMORY;
  241.         }
  242. ((IUnknown*)*ppUnknown)->AddRef();
  243. return HXR_OK;
  244.     }
  245. #if defined(HELIX_FEATURE_FIFOCACHE)
  246.     else if(IsEqualCLSID(rclsid, CLSID_IHXFIFOCache))
  247.     {
  248. *ppUnknown = (IUnknown*)(IHXFIFOCache*)(new HXFIFOCache());
  249.         if( !*ppUnknown )
  250.         {
  251.             return HXR_OUTOFMEMORY;
  252.         }
  253. ((IUnknown*)*ppUnknown)->AddRef();
  254. return HXR_OK;
  255.     }
  256. #endif /* HELIX_FEATURE_FIFOCACHE */
  257. #if defined(HELIX_FEATURE_REGION)
  258. #ifdef _WIN32
  259.     else if(IsEqualCLSID(rclsid, CLSID_IHXRegion))
  260.     {
  261. HXRegion *pRegion = new HXRegion();
  262.         if( !pRegion )
  263.         {
  264.             return HXR_OUTOFMEMORY;
  265.         }
  266. return pRegion->QueryInterface(IID_IUnknown, (void**) ppUnknown);
  267.     }
  268. #endif
  269. #endif /* HELIX_FEATURE_REGION */
  270. #if defined(HELIX_FEATURE_FRAGMENTBUFFER)
  271.     else if (IsEqualCLSID(rclsid, CLSID_IHXFragmentedBuffer))
  272.     {
  273. return CHXFragmentedBuffer::CreateInstance((IUnknown**)ppUnknown);
  274.     }
  275. #endif /* HELIX_FEATURE_FRAGMENTBUFFER */
  276.     else if(IsEqualCLSID(rclsid, CLSID_IHXKeyValueList))
  277.     {
  278. *ppUnknown = (IUnknown*)(IHXKeyValueList*)(new CKeyValueList());
  279.         if( !*ppUnknown )
  280.         {
  281.             return HXR_OUTOFMEMORY;
  282.         }
  283. ((IUnknown*)*ppUnknown)->AddRef();
  284. return HXR_OK;
  285.     }
  286. #if defined(HELIX_FEATURE_FILESYSTEMMGR)
  287.     else if (IsEqualCLSID(rclsid, CLSID_IHXFileSystemManager))
  288.     {
  289. *ppUnknown = (IUnknown*)(IHXFileSystemManager*)(new HXFileSystemManager(m_pContext));
  290.         if( !*ppUnknown )
  291.         {
  292.             return HXR_OUTOFMEMORY;
  293.         }
  294. ((IUnknown*)*ppUnknown)->AddRef();
  295. return HXR_OK;
  296.     }
  297. #endif /* HELIX_FEATURE_FILESYSTEMMGR */
  298.     else if (IsEqualCLSID(rclsid, CLSID_IHXMutex))
  299.     {
  300.         CHXMutex *pMutex = new CHXMutex();
  301.         if (pMutex)
  302.         {
  303.             return pMutex->QueryInterface(IID_IUnknown, (void**) ppUnknown);
  304.         }
  305.     }
  306. // Unix now implements this as a factory plugin.  Windows and Mac may
  307. // do so someday too.
  308. #if (defined (_WINDOWS) || defined (_MACINTOSH)) && !defined(_WINCE)
  309.     else if(IsEqualCLSID(rclsid, CLSID_IHXSiteWindowed))
  310.     {
  311. {
  312.     IHXPreferences* pPreferences = NULL;
  313.     IHXBuffer* pBuffer = NULL;
  314.     BOOL bUseNewSite = TRUE;
  315.     if (HXR_OK == m_pContext->QueryInterface(IID_IHXPreferences,(void**)&pPreferences))
  316.     {   
  317. if (pPreferences->ReadPref("UseHXVideo", pBuffer) == HXR_OK)
  318. {
  319.     bUseNewSite = (::atoi((char*) pBuffer->GetBuffer()) == 1);
  320.     HX_RELEASE(pBuffer);
  321. }
  322. HX_RELEASE(pPreferences);
  323.     }
  324.     if (bUseNewSite)
  325.     {
  326. goto classFactory;
  327.     }
  328. }
  329. #ifdef _WIN32
  330.         // Can not use the plugin handler to create the 
  331.         // site, since it uses the same class ID as 
  332.         // pnvideo, and the plugin handler gets REALLY
  333.         // confused.
  334.         // futher we can not use DLL access, since we WANT to keep
  335.         // a reference on the DLL object created.
  336.         UINT32 uDLLNameLen = 256;
  337.         char    szDllName[256]; /* Flawfinder: ignore */
  338.         DLLAccess::CreateName("pnol", "pnoldvideo", szDllName, uDLLNameLen);
  339.         const char* pPath = NULL;
  340.         CHXString fileName;
  341.         pPath = GetDLLAccessPath()->GetPath(DLLTYPE_PLUGIN);
  342.         fileName = pPath;
  343.         fileName += "\";
  344.         fileName += szDllName;
  345.         HINSTANCE hinst = LoadLibrary(fileName);
  346.         FPCREATEINSTANCE fpCreateInstance = (FPCREATEINSTANCE) GetProcAddress(hinst, HXCREATEINSTANCESTR);
  347.         *ppUnknown = 0;
  348.         if (fpCreateInstance)
  349.         {
  350.             fpCreateInstance((IUnknown**) ppUnknown);
  351.             IHXPlugin* pPlug = NULL;
  352.             if (HXR_OK == (*(IUnknown**)ppUnknown)->QueryInterface(IID_IHXPlugin, (void**)&pPlug))
  353.             {
  354.                 pPlug->InitPlugin(m_pContext);
  355.                 HX_RELEASE(*(IUnknown**)ppUnknown);
  356.                 fpCreateInstance((IUnknown**) ppUnknown);
  357.             }
  358.             return HXR_OK;
  359.         }
  360.         return HXR_FAIL;
  361.     }
  362. #endif
  363. #ifdef _MACINTOSH
  364.     goto classFactory;
  365. /*
  366.     {
  367.     *ppUnknown = (IUnknown*)(IHXSiteWindowed*)(new CHXSiteWindowed(m_pContext));
  368. }
  369. return ((IUnknown*)*ppUnknown)->QueryInterface(IID_IHXSiteWindowed,
  370. (void**)ppUnknown);
  371. */
  372.     }
  373. #endif
  374. #endif
  375. #if defined(HELIX_FEATURE_VIDEO) && defined (HELIX_FEATURE_MISU)
  376.     else if(IsEqualCLSID(rclsid, CLSID_IHXMultiInstanceSiteUserSupplier))
  377.     {
  378. *ppUnknown = (IUnknown*)(IHXMultiInstanceSiteUserSupplier*)(new CHXMultiInstanceSiteUserSupplier());
  379.         if( !*ppUnknown )
  380.         {
  381.             return HXR_OUTOFMEMORY;
  382.         }
  383. return ((IUnknown*)*ppUnknown)->
  384.     QueryInterface(IID_IHXMultiInstanceSiteUserSupplier,
  385. (void**)ppUnknown);
  386.     }
  387. #endif /* HELIX_FEATURE_VIDEO */
  388. #if !defined(_STATICALLY_LINKED)
  389.     else if(IsEqualCLSID(rclsid, CLSID_IHXPluginGroupEnumerator))
  390.     {
  391. IHXPlugin2Handler* pPlugin2Handler = NULL;
  392. m_pContext->QueryInterface
  393. (
  394.     IID_IHXPlugin2Handler,
  395.     (void**)&pPlugin2Handler
  396. );
  397. *ppUnknown = (IUnknown*)(IHXPluginGroupEnumerator*)
  398. (
  399.     new CHXPlugin2GroupEnumerator(pPlugin2Handler)
  400. );
  401.         if( !*ppUnknown )
  402.         {
  403.             return HXR_OUTOFMEMORY;
  404.         }
  405. HX_RELEASE(pPlugin2Handler);
  406. return ((IUnknown*)*ppUnknown)->QueryInterface
  407. (
  408.     IID_IHXPluginGroupEnumerator,
  409.     (void**)ppUnknown
  410. );
  411.     }
  412. #endif /* _STATICALLY_LINKED */
  413.     else if (IsEqualCLSID(rclsid, CLSID_IHXDllAccess))
  414.     {
  415. *ppUnknown = (IUnknown*)(IHXDllAccess*)(new DLLAccessServer);
  416. if (*ppUnknown)
  417. {
  418.     ((IUnknown*)*ppUnknown)->AddRef();
  419.     return HXR_OK;
  420. }
  421. return HXR_OUTOFMEMORY;
  422.     }
  423.     else
  424.     {
  425. classFactory:
  426. // Try the factory plugins
  427. IHXPlugin2Handler* pPlugin2Handler = NULL;
  428. m_pContext->QueryInterface
  429. (
  430.     IID_IHXPlugin2Handler,
  431.     (void**)&pPlugin2Handler
  432. );
  433. *ppUnknown = NULL;
  434. IUnknown* pIUnknownInstance = NULL;
  435. if(pPlugin2Handler)
  436. {
  437.     if 
  438.     (
  439. SUCCEEDED
  440. (
  441.     pPlugin2Handler->FindImplementationFromClassID
  442.     (
  443. rclsid, 
  444. pIUnknownInstance
  445.     )
  446. )
  447.     )
  448.     {
  449. *ppUnknown = pIUnknownInstance;
  450. HX_RELEASE(pPlugin2Handler);
  451. return HXR_OK;
  452.     }
  453. }
  454. #if defined(HELIX_FEATURE_PLUGINHANDLER1)
  455. else
  456. {   // The encoder still uses the old PluginHandler..
  457.     // Try the factory plugins
  458.     PluginHandler* pPluginHandler = NULL;
  459.     m_pContext->QueryInterface
  460.     (
  461. IID_IHXPluginHandler,
  462. (void**)&pPluginHandler
  463.     );
  464.     *ppUnknown = NULL;
  465.     if(pPluginHandler)
  466.     {
  467. PluginHandler::Factory* pFactories;
  468. PluginHandler::Plugin*  pPlugin;
  469. CHXSimpleList::Iterator i;
  470. pFactories = pPluginHandler->m_factory_handler;
  471. for(i = pFactories->m_pPlugins->Begin();
  472.     i != pFactories->m_pPlugins->End();
  473.     ++i)
  474. {
  475.     IUnknown* pInstance = 0;
  476.     pPlugin = (PluginHandler::Plugin*)(*i);
  477.     pPlugin->GetInstance(&pInstance);
  478.     if(pInstance)
  479.     {
  480. HX_RESULT res;
  481. IHXPlugin* pFPlugin = 0;
  482. res = pInstance->QueryInterface(IID_IHXPlugin,
  483. (void**)&pFPlugin);
  484. if(res == HXR_OK)
  485. {
  486.     IHXCommonClassFactory* pClassFactory;
  487.     pFPlugin->InitPlugin(m_pContext);
  488.     pFPlugin->Release();
  489.     res = pInstance->QueryInterface(
  490. IID_IHXCommonClassFactory,
  491. (void**)&pClassFactory);
  492.     if(HXR_OK == res)
  493.     {
  494. res = pClassFactory->CreateInstance(rclsid,
  495.    ppUnknown);
  496. if(HXR_OK != res)
  497.     *ppUnknown = NULL;
  498. pClassFactory->Release();
  499.     }
  500. }
  501. pInstance->Release();
  502. pPlugin->ReleaseInstance();
  503. if(*ppUnknown)
  504. {
  505.     return HXR_OK;
  506. }
  507.     }
  508. }
  509.     }
  510.     HX_RELEASE(pPluginHandler);
  511. }
  512. #endif /* HELIX_FEATURE_PLUGINHANDLER1 */
  513. HX_RELEASE(pPlugin2Handler);
  514.     }
  515.  
  516.     *ppUnknown = NULL;
  517.     return HXR_NOINTERFACE;
  518. }
  519. /************************************************************************
  520.  *  Method:
  521.  * IHXController::CreateInstanceAggregatable
  522.  *  Purpose:
  523.  * Creates instances of common objects supported by the system,
  524.  * like IHXBuffer, IHXPacket, IHXValues, etc.
  525.  *
  526.  * This method is similar to Window's CoCreateInstance() in its 
  527.  * purpose, except that it only creates objects of a well known
  528.  * types.
  529.  *
  530.  * NOTE 1: Unlike CreateInstance, this method will create internal
  531.  * objects that support Aggregation.
  532.  *
  533.  * NOTE 2: The output interface is always the non-delegating 
  534.  * IUnknown.
  535.  */
  536. STDMETHODIMP HXCommonClassFactory::CreateInstanceAggregatable
  537. (
  538.     REFCLSID     /*IN*/ rclsid,
  539.     REF(IUnknown*)  /*OUT*/ pUnknown,
  540.     IUnknown*     /*IN*/ pUnkOuter
  541. )
  542. {
  543.     pUnknown = NULL;
  544.     return HXR_NOINTERFACE;
  545. }