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

Symbian

开发平台:

Visual C++

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