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

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 "hxtypes.h"
  36. #include "hxresult.h"
  37. #include "hxassert.h"
  38. #include "hxwintyp.h"
  39. #include "hxcom.h"
  40. #include "hxcomm.h"
  41. #include "ihxpckts.h"
  42. #include "hxplugn.h"
  43. #include "hxengin.h"
  44. #include "hxerror.h"
  45. #include "hxformt.h"
  46. #include "hxslist.h"
  47. #include "dllaccesbridge.h"
  48. #include "dllpath.h"
  49. #include "hxacodec.h"
  50. #include "hxstrutl.h"
  51. #include "mp4adec.h"
  52. #if defined(HELIX_FEATURE_AUDIO_CODEC_AMRNB)
  53. #include "amrdecinfo.h"
  54. #endif
  55. #if defined(HELIX_FEATURE_AUDIO_CODEC_AMRWB)
  56. #include "amrwbdecinfo.h"
  57. #endif
  58. #if defined(HELIX_FEATURE_AUDIO_CODEC_RAAC)
  59. #include "raacdecinfo.h"
  60. #endif
  61. #if defined(HELIX_FEATURE_AUDIO_CODEC_AAC)
  62. #include "aacdecinfo.h"
  63. #endif
  64. #if defined(HELIX_FEATURE_AUDIO_CODEC_MP3)
  65. #include "mp3decinfo.h"
  66. #endif
  67. #if defined(HELIX_FEATURE_AUDIO_RALF)
  68. #include "losslessdecinfo.h"
  69. #endif
  70. /****************************************************************************
  71.  *  Method:
  72.  *    CMP4ADecoder::CMP4ADecoder
  73.  *
  74.  */
  75. CMP4ADecoder::CMP4ADecoder()
  76.     : m_pCodecAccess(NULL)
  77.     , m_pDecoderInfo(NULL)
  78. {
  79.     // Register the decoder info with m_decInfoStore
  80.     RegisterDecoderInfo();
  81.     // Null out lib name string
  82.     memset(&m_szAUStr[0], 0, MAX_LIBNAME_SIZE);
  83. }
  84. /****************************************************************************
  85.  *  Method:
  86.  *    CMP4ADecoder::~CMP4ADecoder
  87.  *
  88.  */
  89. CMP4ADecoder::~CMP4ADecoder()
  90. {
  91.     Close();
  92. }
  93. void CMP4ADecoder::RegisterDecoderInfo()
  94. {
  95. #if defined(HELIX_FEATURE_AUDIO_CODEC_RAAC)
  96.     m_decInfoStore.RegisterInfo(new CRAACDecInfo);
  97. #endif // defined(HELIX_FEATURE_AUDIO_CODEC_RAAC)
  98. #if defined(HELIX_FEATURE_AUDIO_CODEC_AAC)
  99.     // Register AAC library name function
  100.     m_decInfoStore.RegisterInfo(new CAACDecInfo);
  101. #endif // defined(HELIX_FEATURE_AUDIO_CODEC_AAC)
  102. #if defined(HELIX_FEATURE_AUDIO_CODEC_AMRNB)
  103.     // Register AMR-NB library name function
  104.     m_decInfoStore.RegisterInfo(new CAMRNBDecInfo);
  105. #endif // defined(HELIX_FEATURE_AUDIO_CODEC_AMRNB)
  106. #if defined(HELIX_FEATURE_AUDIO_CODEC_AMRWB)
  107.     // Register AMR-WB library name function
  108.     m_decInfoStore.RegisterInfo(new CAMRWBDecInfo);
  109. #endif // defined(HELIX_FEATURE_AUDIO_CODEC_AMRWB)
  110. #if defined(HELIX_FEATURE_AUDIO_CODEC_MP3)
  111.     // Register MP3 library name function
  112.     m_decInfoStore.RegisterInfo(new CMP3DecInfo);
  113. #endif // defined(HELIX_FEATURE_AUDIO_CODEC_MP3)
  114.     // Register ALSD/lossless library name function
  115. #if defined(HELIX_FEATURE_AUDIO_RALF)
  116.     m_decInfoStore.RegisterInfo(new CLosslessDecInfo);
  117. #endif // HELIX_FEATURE_AUDIO_RALF
  118. }
  119. HX_RESULT CMP4ADecoder::Close(void)
  120. {
  121.     HX_DELETE(m_pCodecAccess);
  122.     return HXR_OK;
  123. }
  124. /****************************************************************************
  125.  *  Method:
  126.  *    CMP4ADecoder::CMP4ADecoder
  127.  *
  128.  */
  129. HX_RESULT CMP4ADecoder::Open(IHXValues* pHeader,
  130.      IHXAudioDecoder** pOutAudioDecoder,
  131.      IUnknown* pContext)
  132. {
  133.     HX_RESULT retVal = HXR_FAIL;
  134.     if (pHeader && pOutAudioDecoder)
  135.     {
  136.         // Close the decoder
  137.         Close();
  138.         // Get the mime type
  139.         IHXBuffer* pMimeType = NULL;
  140.         pHeader->GetPropertyCString("MimeType", pMimeType);
  141.         if (pMimeType)
  142.         {
  143.     char pOSLibName[MAX_LIBNAME_SIZE]; /* Flawfinder: ignore */
  144.             m_pDecoderInfo = m_decInfoStore.GetInfoFirst((const char*) pMimeType->GetBuffer());
  145.             while (m_pDecoderInfo)
  146.             {
  147.                 if (OS_BuildLibName(m_pDecoderInfo->GetLibName(),
  148.                                     pOSLibName,
  149.                                     MAX_LIBNAME_SIZE))
  150.                 {
  151.                     retVal = HXR_OUTOFMEMORY;
  152.                     if (!m_pCodecAccess)
  153.                     {
  154.                         // DLLAccess should be used to provide cross-platform support
  155.                         m_pCodecAccess = new DLLAccessBridge(pOSLibName, 
  156.      DLLTYPE_CODEC, 
  157.      pContext);
  158.                     }
  159.                     if (m_pCodecAccess)
  160.                     {
  161.                         retVal = HXR_REQUEST_UPGRADE;
  162.                         if (m_pCodecAccess->isOpen())
  163.                         {
  164.                             // we got a module so get the symbols we need
  165.                             FPRACreateDecoderInstance fpRACreateDecoderInstance = NULL;
  166.                             fpRACreateDecoderInstance = (FPRACreateDecoderInstance) 
  167.                                 m_pCodecAccess->getSymbol("RACreateDecoderInstance");
  168.                             if (fpRACreateDecoderInstance)
  169.                             {
  170.                                 IHXAudioDecoder* pAudioDecoder = NULL;
  171.                                 retVal = (*fpRACreateDecoderInstance)(IID_IHXAudioDecoder,
  172.                                                                       (IUnknown**) &pAudioDecoder);
  173.                                 if (SUCCEEDED(retVal))
  174.                                 {
  175.                                     retVal = CheckDecoder(pAudioDecoder);
  176.                                     if (SUCCEEDED(retVal))
  177.                                     {
  178.                                         // Set the out parameter
  179.                                         pAudioDecoder->AddRef();
  180.                                         *pOutAudioDecoder = pAudioDecoder;
  181.                                     }
  182.                                 }
  183.                                 HX_RELEASE(pAudioDecoder);
  184.                             }
  185.                         }
  186.                     }
  187.                 }
  188. if (SUCCEEDED(retVal))
  189. {
  190.     break;
  191. }
  192. HX_DELETE(m_pCodecAccess);
  193. m_pDecoderInfo = m_decInfoStore.GetInfoNext((const char*) pMimeType->GetBuffer());
  194.             }
  195.         }
  196.         HX_RELEASE(pMimeType);
  197.     }
  198.     return retVal;
  199. }
  200. #if defined(WIN32) || defined(_WIN32) || defined(_SYMBIAN)
  201. static const char z_dllSuffix[] = ".DLL";
  202. #elif defined(_MAC_UNIX)
  203. static const char z_dllSuffix[] = ".bundle";
  204. #elif _MACINTOSH 
  205. #if defined(_CARBON)
  206. #ifdef _MAC_MACHO
  207. static const char z_dllSuffix[] = ".bundle";
  208. #else
  209. static const char z_dllSuffix[] = ".shlb";
  210. #endif
  211. #else // _CARBON
  212. static const char z_dllSuffix[] = ".DLL";
  213. #endif // _CARBON
  214. #elif defined (_UNIX)
  215.     //
  216.     // codecs are named like this :XXXX.so" where XXXX is the
  217.     // codec id string
  218.     //
  219. static const char z_dllSuffix[] = ".so";
  220. #elif defined (_OPENWAVE)
  221. // currently it doesn't support dynamic loading lib, so N/A
  222. static const char z_dllSuffix[] = "";
  223. #endif
  224. /****************************************************************************
  225.  *  Method:
  226.  *    CMP4ADecoder::OS_BuildLibName
  227.  */
  228. BOOL CMP4ADecoder::OS_BuildLibName(const char* pLibName, 
  229.    char *pOSLibName, 
  230.    UINT32 ulBufLen)
  231. {
  232.     BOOL bRetVal = FALSE;
  233.     if (pOSLibName && pLibName)
  234.     {
  235. #if defined(HELIX_FEATURE_AUTOUPGRADE)
  236.         // Copy the base file name into the AU String (just
  237. // in case we need it)
  238. SafeStrCpy(m_szAUStr, pLibName, MAX_LIBNAME_SIZE);
  239. #endif /* #if defined(HELIX_FEATURE_AUTOUPGRADE) */
  240. SafeStrCpy(pOSLibName, pLibName, MAX_LIBNAME_SIZE);
  241. // Now append the filename suffix
  242. SafeStrCat(pOSLibName, z_dllSuffix, ulBufLen);
  243. bRetVal = TRUE;
  244.     }
  245.     return bRetVal;
  246. }