mmfenh/advancedaudiocontroller/audiotonecontrollerplugin/ringtonerecognizer/src/recrt.cpp
changeset 0 71ca22bcf22a
equal deleted inserted replaced
-1:000000000000 0:71ca22bcf22a
       
     1 /*
       
     2 * Copyright (c) 2002-2006 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Implementation of RingToneRecognizer
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <apmrec.h>
       
    21 #include <apmstd.h>
       
    22 #include <implementationproxy.h>
       
    23 
       
    24 #include "recrt.h"
       
    25 
       
    26 // CONSTANTS
       
    27 const TUid KUidRingingToneRecognizer={0x100059EA};
       
    28 const TInt KMinBufferLength=3;					// minimum amount of file needed to determine a ringing tone IF it's not called .rng
       
    29 const TInt KMaxBufferLength=4;					// maximum amount of buffer space we will ever use
       
    30 const TInt KRecRtCommandByte=2;					// 00000010 = <command length>
       
    31 const TInt KRecRtUnicodeCommandByte=3;			// 00000011 = <command length> if unicode
       
    32 const TInt KRecRtProgrammingByte=74;			// 01001010 = <ringing-tone programming> + 0
       
    33 const TInt KRecRtSoundByte=58;					// 00111010 = <sound> + 0
       
    34 const TInt KRecRtUnicodeByte=68;				// 01000100 = <unicode> + 0
       
    35 const TInt KRecRtFileExtensionsMightBeValid=4;	// If the file name length > 4, the file extension might be valid
       
    36 
       
    37 _LIT(KRingToneExtension1, ".rng");
       
    38 _LIT(KRingToneExtension2, ".nrt");
       
    39 _LIT(KRingToneExtension3, ".ota");
       
    40 _LIT8(KDataTypeRingingTone,"application/vnd.nokia.ringing-tone");
       
    41 
       
    42 
       
    43 
       
    44 CApaRingingToneRecognizer::CApaRingingToneRecognizer()
       
    45     : CApaDataRecognizerType(KUidRingingToneRecognizer, CApaDataRecognizerType::ENormal)
       
    46     {
       
    47     iCountDataTypes=1;
       
    48     }
       
    49 
       
    50 CApaRingingToneRecognizer::~CApaRingingToneRecognizer()
       
    51     {
       
    52     // Do nothing
       
    53     }
       
    54 
       
    55 TUint CApaRingingToneRecognizer::PreferredBufSize()
       
    56     {
       
    57     return KMaxBufferLength;
       
    58     }
       
    59 
       
    60 TDataType CApaRingingToneRecognizer::SupportedDataTypeL(TInt /*aIndex*/) const
       
    61 	{
       
    62 //	__ASSERT_DEBUG(aIndex==0,User::Invariant());
       
    63 	return TDataType(KDataTypeRingingTone);
       
    64 	}
       
    65 
       
    66 void CApaRingingToneRecognizer::DoRecognizeL(const TDesC& aName, const TDesC8& aBuffer)
       
    67 {
       
    68 	TBool nameRecognized=EFalse;
       
    69 	if (aName.Length()>KRecRtFileExtensionsMightBeValid)
       
    70 	{
       
    71 		if ((aName.Right(KRecRtFileExtensionsMightBeValid).CompareF(KRingToneExtension1)==0) ||
       
    72 			(aName.Right(KRecRtFileExtensionsMightBeValid).CompareF(KRingToneExtension2)==0) ||
       
    73 			(aName.Right(KRecRtFileExtensionsMightBeValid).CompareF(KRingToneExtension3)==0))
       
    74 			nameRecognized=ETrue;
       
    75 	}
       
    76 
       
    77 	TInt length=aBuffer.Length();
       
    78 	if (length<KMinBufferLength)
       
    79 		return;		// too short to be a ring tone
       
    80 	TBool validChars=EFalse;
       
    81 
       
    82 	if(aBuffer[0] == KRecRtCommandByte )	//if it's a ring tone, it's not in unicode format
       
    83 	{
       
    84 		if (aBuffer[1] == KRecRtProgrammingByte && aBuffer[2] == KRecRtSoundByte)
       
    85 			validChars = ETrue;
       
    86 	}
       
    87 	else if (aBuffer[0] == KRecRtUnicodeCommandByte)	// if it's a ring tone, it is in unicode format	
       
    88 	{	
       
    89 		if (aBuffer[1] == KRecRtProgrammingByte && aBuffer[2] == KRecRtUnicodeByte && aBuffer[3] == KRecRtSoundByte)
       
    90 			validChars = ETrue;
       
    91 	}
       
    92 	else if(aBuffer[0] == 0x00 && aBuffer[1] == 0x11 && aBuffer[2] == 0x06)
       
    93 	{
       
    94 		validChars = ETrue;
       
    95 	}
       
    96 
       
    97 	if (!validChars)
       
    98 		return;		// not a ringing tone
       
    99 	else 
       
   100 	{
       
   101 		if (!nameRecognized)
       
   102 			iConfidence=EProbable;	// is probably a ringing tone
       
   103 		else
       
   104 			iConfidence=ECertain;	// is certainly a ringing tone
       
   105 		iDataType=TDataType(KDataTypeRingingTone);
       
   106 	}
       
   107 }
       
   108 
       
   109 
       
   110 
       
   111 CApaDataRecognizerType* CApaRingingToneRecognizer::CreateRecognizerL()
       
   112     {
       
   113     return new (ELeave) CApaRingingToneRecognizer();
       
   114     }
       
   115 
       
   116 const TImplementationProxy ImplementationTable[] =
       
   117     {
       
   118     IMPLEMENTATION_PROXY_ENTRY(KRingingToneRecognizerImplementationUid, CApaRingingToneRecognizer::CreateRecognizerL)
       
   119     };
       
   120 
       
   121 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
       
   122     {
       
   123     aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
       
   124     return ImplementationTable;
       
   125     }
       
   126 
       
   127 
       
   128 // End of file