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

Symbian

开发平台:

Visual C++

  1. /*============================================================================*
  2.  *
  3.  * (c) 1995-2002 RealNetworks, Inc. Patents pending. All rights reserved.
  4.  *
  5.  *============================================================================*/
  6. /*
  7.  *  Description:
  8.  *
  9.  */
  10. #include <e32svr.h>
  11. #include <apmrec.h>
  12. #include <apmstd.h>
  13. #include "hxassert.h"
  14. //#include "debug.h"
  15. #include "hxsym_mimetypes.h"
  16. #include "recog_util.h"
  17. #include "rm_recog.h"
  18. //
  19. // some constants
  20. //
  21. // UID
  22. const TUid KUidMimeRealMediaRecognizer={0x10009D0D};
  23. // min and max buffer length required to recognize file datatype
  24. const TInt KMinBufferLength=4;
  25. const TInt KMaxBufferLength=256;
  26. //
  27. // list of mimetypes we recognize
  28. //
  29. const TUint8* const k_dataTypes[] =
  30. {
  31. // basic datatypes always recognized
  32. HXSYM_MIMETYPE_RM,
  33. HXSYM_MIMETYPE_RAM,
  34. HXSYM_MIMETYPE_SDP,
  35. HXSYM_MIMETYPE_AMR,
  36. // mp3
  37. #if defined(HELIX_FEATURE_AUDIO_MPA_LAYER3)
  38. HXSYM_MIMETYPE_MP3,
  39. #endif
  40. // 3gpp
  41. #if defined(HELIX_FEATURE_3GPP)
  42. HXSYM_MIMETYPE_3GPAUDIO,
  43. HXSYM_MIMETYPE_3GPVIDEO,
  44. HXSYM_MIMETYPE_MP4AUDIO,
  45. HXSYM_MIMETYPE_MP4VIDEO,
  46. #endif
  47. // smil
  48. #if defined(HELIX_FEATURE_SMIL2)
  49. HXSYM_MIMETYPE_SMIL
  50. #endif
  51. };
  52. #define ARRAY_COUNT(x) (sizeof(x) / sizeof(x[0]))
  53. const TUint MIMETYPE_COUNT = ARRAY_COUNT(k_dataTypes);
  54. CApaRealMediaRecognizer::CApaRealMediaRecognizer()
  55. : CApaDataRecognizerType(KUidMimeRealMediaRecognizer, CApaDataRecognizerType::EHigh)
  56. {
  57.    iCountDataTypes =  MIMETYPE_COUNT;
  58. }
  59. TUint CApaRealMediaRecognizer::PreferredBufSize()
  60. {
  61.     return KMaxBufferLength;
  62. }
  63. TDataType CApaRealMediaRecognizer::SupportedDataTypeL(TInt aIndex) const
  64. {
  65.     HX_ASSERT(aIndex < MIMETYPE_COUNT);
  66.     return TDataType(_L8(k_dataTypes[aIndex]));
  67. }
  68. void CApaRealMediaRecognizer::DoRecognizeL(const TDesC& aName,
  69.    const TDesC8& aBuffer)
  70. {
  71.     iConfidence = ENotRecognized;
  72.     _LIT(KRtspScheme, "rtsp");
  73.     // first check name for scheme ('rtsp://')
  74.     if(RecogUtil::FindScheme(KRtspScheme, aName))
  75.     {
  76.         iDataType = TDataType(_L8(HXSYM_MIMETYPE_RM));
  77.         iConfidence = ECertain;
  78.     }
  79.     else
  80.     {
  81.         // not a scheme; look at buffer...
  82.         TInt length=aBuffer.Length();
  83.         if (length>=KMinBufferLength)
  84.         {
  85.             // HXSYM_MIMETYPE_RM
  86.             if ((iConfidence = RecogUtil::IsRMFile(aName, aBuffer)) != ENotRecognized)
  87.             {
  88.         iDataType=TDataType(_L8(HXSYM_MIMETYPE_RM));
  89.             }
  90.             // HXSYM_MIMETYPE_SMIL
  91.             else if ((iConfidence = RecogUtil::IsSMILFile(aName, aBuffer)) != ENotRecognized)
  92.             {
  93.                 iDataType=TDataType(_L8(HXSYM_MIMETYPE_SMIL));
  94.             }
  95.             // HXSYM_MIMETYPE_SDP
  96.     else if ((iConfidence = RecogUtil::IsSDPFile(aName, aBuffer)) != ENotRecognized)
  97.     {
  98. iDataType=TDataType(_L8(HXSYM_MIMETYPE_SDP));
  99.             }
  100.             // HXSYM_MIMETYPE_RAM
  101.             else if ((iConfidence = RecogUtil::IsRAMFile(aName, aBuffer)) != ENotRecognized)
  102.             {
  103.         iDataType=TDataType(_L8(HXSYM_MIMETYPE_RAM));
  104.             }
  105.             // HXSYM_MIMETYPE_AMR
  106.             else if ((iConfidence = RecogUtil::IsAMRFile(aName, aBuffer)) != ENotRecognized)
  107.             {
  108.         iDataType=TDataType(_L8(HXSYM_MIMETYPE_AMR));
  109.             }
  110.             #if defined(HELIX_FEATURE_3GPP)
  111.             // HXSYM_MIMETYPE_3GPAUDIO/VIDEO
  112.             else if (RecogUtil::Is3GPPFile(aName, aBuffer) != ENotRecognized)
  113.             {
  114.         if ((iConfidence = RecogUtil::IsMPEG4Audio(aName, aBuffer)) != ENotRecognized)
  115.                 {
  116.             iDataType=TDataType(_L8(HXSYM_MIMETYPE_3GPAUDIO));
  117.                 }
  118.         else
  119.         {
  120.             iDataType=TDataType(_L8(HXSYM_MIMETYPE_3GPVIDEO));
  121.             iConfidence = EProbable;
  122.         }
  123.             }
  124.             // HXSYM_MIMETYPE_MP4AUDIO/VIDEO
  125.             else if (RecogUtil::IsMPEG4File(aName, aBuffer) != ENotRecognized)
  126.             {
  127.         if ((iConfidence = RecogUtil::IsMPEG4Audio(aName, aBuffer)) != ENotRecognized)
  128.                 {
  129.             iDataType=TDataType(_L8(HXSYM_MIMETYPE_MP4AUDIO));
  130.                 }
  131.         else
  132.         {
  133.             iDataType=TDataType(_L8(HXSYM_MIMETYPE_MP4VIDEO));
  134.             iConfidence = EProbable;
  135.         }
  136.             }
  137. //HELIX_FEATURE_3GPP
  138. #endif
  139. #if defined(HELIX_FEATURE_AUDIO_MPA_LAYER3)
  140.             // HXSYM_MIMETYPE_MP3
  141.             else if ((iConfidence = RecogUtil::IsMP3File(aName, aBuffer)) != ENotRecognized)
  142.             {
  143. iDataType=TDataType(_L8(HXSYM_MIMETYPE_MP3));
  144.             }
  145. #endif
  146. #if !defined(HELIX_FEATURE_SMIL2)
  147.             // HXSYM_MIMETYPE_SMIL
  148.             if (iDataType==TDataType(_L8(HXSYM_MIMETYPE_SMIL)))
  149.             {
  150. iConfidence = ENotRecognized;
  151.     }
  152. #endif
  153.         }
  154.     }
  155. }
  156. EXPORT_C CApaDataRecognizerType* CreateRecognizer()
  157. // The gate function - ordinal 1
  158. //
  159. {
  160.     CApaDataRecognizerType* thing=new CApaRealMediaRecognizer();
  161.     return thing;
  162. }
  163. GLDEF_C TInt E32Dll(TDllReason /*aReason*/)
  164. //
  165. // DLL entry point
  166. //
  167. {
  168.     return KErrNone;
  169. }