pxffcmgr.cpp
上传用户:zhongxx05
上传日期:2007-06-06
资源大小:33641k
文件大小:12k
源码类别:

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. // include
  36. #include "hxtypes.h"
  37. #include "hxwintyp.h"
  38. #include "hxcom.h"
  39. #include "hxplugn.h"
  40. #include "ihxpckts.h"
  41. // hxcont
  42. #include "hxslist.h"
  43. #include "hxmap.h"
  44. // hxmisc
  45. #include "unkimp.h"
  46. #include "baseobj.h"
  47. // pxcomlib
  48. #include "pxcmpmgr.h"
  49. #include "pxffmcod.h"
  50. #include "pxffcmgr.h"
  51. // hxdebug
  52. #include "hxheap.h"
  53. #ifdef _DEBUG
  54. #undef HX_THIS_FILE
  55. static char HX_THIS_FILE[] = __FILE__;
  56. #endif
  57. BEGIN_INTERFACE_LIST(PXFileFormatCodecManager)
  58. END_INTERFACE_LIST
  59. PXFileFormatCodecManager::PXFileFormatCodecManager()
  60. {
  61. }
  62. PXFileFormatCodecManager::~PXFileFormatCodecManager()
  63. {
  64. }
  65. BOOL PXFileFormatCodecManager::IsCodecPresent(const char* pszFileMime,
  66.                                               const char* pszFileName,
  67.                                               IHXBuffer* pBuffer)
  68. {
  69.     BOOL bRet = FALSE;
  70.     IHXRealPixFileFormatCodec* pCodec = NULL;
  71.     HX_RESULT                   retVal = GetCodec(pszFileMime, pszFileName,
  72.                                                   pBuffer, pCodec);
  73.     if (SUCCEEDED(retVal))
  74.     {
  75.         bRet = TRUE;
  76.     }
  77.     HX_RELEASE(pCodec);
  78.     return bRet;
  79. }
  80. HX_RESULT PXFileFormatCodecManager::GetCodec(const char*                      pszFileMime,
  81.                                              const char*                      pszFileName,
  82.                                              IHXBuffer*                      pBuffer,
  83.                                              REF(IHXRealPixFileFormatCodec*) rpCodec)
  84. {
  85.     HX_RESULT retVal = HXR_FAIL;
  86.     // Try and get the codec from the file mime type (i.e. - "image/gif")
  87.     if (pszFileMime)
  88.     {
  89.         retVal = GetCodecFromFileMimeType(pszFileMime, rpCodec);
  90.     }
  91.     // Try and get the codec from the file name (i.e. - "foo.gif")
  92.     if (FAILED(retVal) && pszFileName)
  93.     {
  94.         retVal = GetCodecFromFileExtension(pszFileName, rpCodec);
  95.     }
  96.     // Try and get the codec from the actual file content
  97.     if (FAILED(retVal) && pBuffer)
  98.     {
  99.         retVal = GetCodecFromContent(pBuffer, rpCodec);
  100.     }
  101.     return retVal;
  102. }
  103. HX_RESULT PXFileFormatCodecManager::GetID(IUnknown* pComponent, REF(const char*) rpszID)
  104. {
  105.     HX_RESULT retVal = HXR_FAIL;
  106.     if (pComponent)
  107.     {
  108.         IHXRealPixFileFormatCodec* pCodec = NULL;
  109.         retVal = pComponent->QueryInterface(IID_IHXRealPixFileFormatCodec,
  110.                                             (void**) &pCodec);
  111.         if (SUCCEEDED(retVal))
  112.         {
  113.             const char** ppFileExt   = NULL;
  114.             const char** ppFileMime  = NULL;
  115.             UINT32       ulStreamVer = 0;
  116.             UINT32       ulMaxPerImg = 0;
  117.             UINT32       ulMaxPerPck = 0;
  118.             retVal                   = pCodec->GetFileFormatCodecInfo(ppFileExt,
  119.                                                                       ppFileMime,
  120.                                                                       rpszID,
  121.                                                                       ulStreamVer,
  122.                                                                       ulMaxPerImg,
  123.                                                                       ulMaxPerPck);
  124.         }
  125.         HX_RELEASE(pCodec);
  126.     }
  127.     return retVal;
  128. }
  129. HX_RESULT PXFileFormatCodecManager::GetCodecFromFileMimeType(const char*                      pszFileMime,
  130.                                                              REF(IHXRealPixFileFormatCodec*) rpCodec)
  131. {
  132.     BOOL bFound = FALSE;
  133.     if (pszFileMime)
  134.     {
  135.         if (m_pComponentList)
  136.         {
  137.             LISTPOSITION pos = m_pComponentList->GetHeadPosition();
  138.             while (pos)
  139.             {
  140.                 IUnknown* pComponent = (IUnknown*) m_pComponentList->GetNext(pos);
  141.                 if (pComponent)
  142.                 {
  143.                     IHXRealPixFileFormatCodec* pCodec = NULL;
  144.                     pComponent->QueryInterface(IID_IHXRealPixFileFormatCodec,
  145.                                                (void**) &pCodec);
  146.                     if (pCodec)
  147.                     {
  148.                         const char** ppszFileExt   = NULL;
  149.                         const char** ppszFileMime  = NULL;
  150.                         const char*  pszStreamMime = NULL;
  151.                         UINT32       ulStreamVer   = 0;
  152.                         UINT32       ulMaxPerImg   = 0;
  153.                         UINT32       ulMaxPerPckt  = 0;
  154.                         pCodec->GetFileFormatCodecInfo(ppszFileExt, ppszFileMime,
  155.                                                        pszStreamMime, ulStreamVer,
  156.                                                        ulMaxPerImg, ulMaxPerPckt);
  157.                         if (ppszFileMime)
  158.                         {
  159.                             if (IsStringInArray(pszFileMime, ppszFileMime))
  160.                             {
  161.                                 HX_RELEASE(rpCodec);
  162.                                 rpCodec = pCodec;
  163.                                 rpCodec->AddRef();
  164.                                 bFound = TRUE;
  165.                             }
  166.                         }
  167.                     }
  168.                     HX_RELEASE(pCodec);
  169.                 }
  170.                 if (bFound)
  171.                 {
  172.                     break;
  173.                 }
  174.             }
  175.         }
  176.     }
  177.     
  178.     return (bFound ? HXR_OK : HXR_FAIL);
  179. }
  180. HX_RESULT PXFileFormatCodecManager::GetCodecFromFileExtension(const char*                      pszFileName,
  181.                                                               REF(IHXRealPixFileFormatCodec*) rpCodec)
  182. {
  183.     BOOL bFound = FALSE;
  184.     if (pszFileName)
  185.     {
  186.         // Get the file extension from the file name
  187.         CHXString cExt(pszFileName);
  188.         INT32 lQMark = cExt.Find('?');
  189.         if (lQMark >= 0)
  190.         {
  191.             cExt = cExt.Left(lQMark);
  192.         }
  193.         INT32 lPeriod = cExt.ReverseFind('.');
  194.         if (lPeriod >= 0)
  195.         {
  196.             cExt = cExt.Right(cExt.GetLength() - lPeriod - 1);
  197.             cExt.MakeLower();
  198.         }
  199.         if (cExt.GetLength() > 0)
  200.         {
  201.             if (m_pComponentList)
  202.             {
  203.                 LISTPOSITION pos = m_pComponentList->GetHeadPosition();
  204.                 while (pos)
  205.                 {
  206.                     IUnknown* pComponent = (IUnknown*) m_pComponentList->GetNext(pos);
  207.                     if (pComponent)
  208.                     {
  209.                         IHXRealPixFileFormatCodec* pCodec = NULL;
  210.                         pComponent->QueryInterface(IID_IHXRealPixFileFormatCodec,
  211.                                                    (void**) &pCodec);
  212.                         if (pCodec)
  213.                         {
  214.                             const char** ppszFileExt   = NULL;
  215.                             const char** ppszFileMime  = NULL;
  216.                             const char*  pszStreamMime = NULL;
  217.                             UINT32       ulStreamVer   = 0;
  218.                             UINT32       ulMaxPerImg   = 0;
  219.                             UINT32       ulMaxPerPckt  = 0;
  220.                             pCodec->GetFileFormatCodecInfo(ppszFileExt, ppszFileMime,
  221.                                                            pszStreamMime, ulStreamVer,
  222.                                                            ulMaxPerImg, ulMaxPerPckt);
  223.                             if (ppszFileExt)
  224.                             {
  225.                                 if (IsStringInArray((const char*) cExt, ppszFileExt))
  226.                                 {
  227.                                     HX_RELEASE(rpCodec);
  228.                                     rpCodec = pCodec;
  229.                                     rpCodec->AddRef();
  230.                                     bFound  = TRUE;
  231.                                 }
  232.                             }
  233.                         }
  234.                         HX_RELEASE(pCodec);
  235.                     }
  236.                     if (bFound)
  237.                     {
  238.                         break;
  239.                     }
  240.                 }
  241.             }
  242.         }
  243.     }
  244.     
  245.     return (bFound ? HXR_OK : HXR_FAIL);
  246. }
  247. HX_RESULT PXFileFormatCodecManager::GetCodecFromContent(IHXBuffer*                      pBuffer,
  248.                                                         REF(IHXRealPixFileFormatCodec*) rpCodec)
  249. {
  250.     BOOL bFound = FALSE;
  251.     if (pBuffer)
  252.     {
  253.         if (m_pComponentList)
  254.         {
  255.             LISTPOSITION pos = m_pComponentList->GetHeadPosition();
  256.             while (pos)
  257.             {
  258.                 IUnknown* pComponent = (IUnknown*) m_pComponentList->GetNext(pos);
  259.                 if (pComponent)
  260.                 {
  261.                     IHXRealPixFileFormatCodec* pCodec = NULL;
  262.                     pComponent->QueryInterface(IID_IHXRealPixFileFormatCodec,
  263.                                                (void**) &pCodec);
  264.                     if (pCodec)
  265.                     {
  266.                         if (pCodec->ValidInputData(pBuffer))
  267.                         {
  268.                             HX_RELEASE(rpCodec);
  269.                             rpCodec = pCodec;
  270.                             rpCodec->AddRef();
  271.                             bFound  = TRUE;
  272.                         }
  273.                     }
  274.                     HX_RELEASE(pCodec);
  275.                 }
  276.                 if (bFound)
  277.                 {
  278.                     break;
  279.                 }
  280.             }
  281.         }
  282.     }
  283.     
  284.     return (bFound ? HXR_OK : HXR_FAIL);
  285. }
  286. BOOL PXFileFormatCodecManager::IsStringInArray(const char*  pszStr,
  287.                                                const char** ppszStrArr)
  288. {
  289.     BOOL bMatch = FALSE;
  290.     if (pszStr && ppszStrArr)
  291.     {
  292.         while (*ppszStrArr)
  293.         {
  294.             if (!strcmp(pszStr, *ppszStrArr))
  295.             {
  296.                 bMatch = TRUE;
  297.                 break;
  298.             }
  299.             ppszStrArr++;
  300.         }
  301.     }
  302.     return bMatch;
  303. }