internetradio2.0/settingssrc/ircodecmanager.cpp
changeset 0 09774dfdd46b
equal deleted inserted replaced
-1:000000000000 0:09774dfdd46b
       
     1 /*
       
     2 * Copyright (c) 2008 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:  Maintains the set of supported codecs
       
    15 *
       
    16 */
       
    17 
       
    18 #include <e32base.h>
       
    19 
       
    20 #include <eikenv.h>
       
    21 #include <f32file.h>
       
    22 
       
    23 
       
    24 #include "ircodecmanager.h"
       
    25 #include "irdebug.h"
       
    26 
       
    27 // ---------------------------------------------------------------------------
       
    28 // CIRCodecManager::NewL
       
    29 // ---------------------------------------------------------------------------
       
    30 //
       
    31 CIRCodecManager* CIRCodecManager::NewL()
       
    32     {
       
    33     CIRCodecManager* self = CIRCodecManager::NewLC();
       
    34     CleanupStack::Pop( self );
       
    35     return self;
       
    36     }
       
    37 
       
    38 // ---------------------------------------------------------------------------
       
    39 // CIRCodecManager::NewLC
       
    40 // ---------------------------------------------------------------------------
       
    41 //
       
    42 CIRCodecManager* CIRCodecManager::NewLC()
       
    43     {
       
    44     CIRCodecManager* self = new (ELeave) CIRCodecManager();
       
    45     CleanupStack::PushL( self );
       
    46     self->ConstructL();
       
    47     return self;
       
    48     }
       
    49 
       
    50 // ---------------------------------------------------------------------------
       
    51 // CIRCodecManager::CIRCodecManager
       
    52 // ---------------------------------------------------------------------------
       
    53 //
       
    54 CIRCodecManager::CIRCodecManager()
       
    55     {
       
    56     }
       
    57 
       
    58 // ---------------------------------------------------------------------------
       
    59 // CIRCodecManager::~CIRCodecManager
       
    60 // ---------------------------------------------------------------------------
       
    61 //
       
    62 CIRCodecManager::~CIRCodecManager()
       
    63     {
       
    64     iSupportedDataTypes.Reset();
       
    65     }
       
    66 
       
    67 // ---------------------------------------------------------------------------
       
    68 // CIRCodecManager::ConstructL
       
    69 // ---------------------------------------------------------------------------
       
    70 //
       
    71 void CIRCodecManager::ConstructL()
       
    72     {
       
    73     IRLOG_DEBUG( "CIRCodecManager::ConstructL" );
       
    74     LoadSupportedCodecsL();
       
    75     IRLOG_DEBUG( "CIRCodecManager::ConstructL - Exiting." );
       
    76     }
       
    77 
       
    78 // ---------------------------------------------------------------------------
       
    79 // CIRCodecManager::IsSupportedCodec
       
    80 // ---------------------------------------------------------------------------
       
    81 //
       
    82 TBool CIRCodecManager::IsSupportedCodec( TFourCC aCodec ) const
       
    83     {
       
    84     IRLOG_DEBUG( "CIRCodecManager::::IsSupportedCodec" );
       
    85     TBool supported( EFalse );
       
    86     if ( iSupportedDataTypes.Find( aCodec ) != KErrNotFound )
       
    87         {
       
    88         supported = ETrue;
       
    89         }
       
    90     IRLOG_INFO3( "CIRCodecManager::IsSupportedCodec - Returning %d for codec %d",
       
    91                   supported, aCodec.FourCC() );
       
    92     return supported;
       
    93     }
       
    94 
       
    95 // ---------------------------------------------------------------------------
       
    96 // CIRCodecManager::InitializeComplete
       
    97 // ---------------------------------------------------------------------------
       
    98 //
       
    99 void CIRCodecManager::InitializeComplete(TInt /* aError */)
       
   100     {
       
   101     }
       
   102 
       
   103 // ---------------------------------------------------------------------------
       
   104 // CIRCodecManager::ToneFinished
       
   105 // ---------------------------------------------------------------------------
       
   106 //
       
   107 void CIRCodecManager::ToneFinished(TInt /* aError */)
       
   108     {
       
   109     }
       
   110 
       
   111 // ---------------------------------------------------------------------------
       
   112 // CIRCodecManager::BufferToBeFilled
       
   113 // ---------------------------------------------------------------------------
       
   114 //
       
   115 void CIRCodecManager::BufferToBeFilled(CMMFBuffer* /* aBuffer */ )
       
   116     {
       
   117     }
       
   118 
       
   119 // ---------------------------------------------------------------------------
       
   120 // CIRCodecManager::PlayError
       
   121 // ---------------------------------------------------------------------------
       
   122 //
       
   123 void CIRCodecManager::PlayError(TInt /* aError */ )
       
   124     {
       
   125     }
       
   126 
       
   127 // ---------------------------------------------------------------------------
       
   128 // CIRCodecManager::BufferToBeEmptied
       
   129 // ---------------------------------------------------------------------------
       
   130 //
       
   131 void CIRCodecManager::BufferToBeEmptied(CMMFBuffer* /* aBuffer */ )
       
   132     {
       
   133     }
       
   134 
       
   135 // ---------------------------------------------------------------------------
       
   136 // CIRCodecManager::RecordError
       
   137 // ---------------------------------------------------------------------------
       
   138 //
       
   139 void CIRCodecManager::RecordError(TInt /* aError */ )
       
   140     {
       
   141     }
       
   142 
       
   143 // ---------------------------------------------------------------------------
       
   144 // CIRCodecManager::ConvertError
       
   145 // ---------------------------------------------------------------------------
       
   146 //
       
   147 void CIRCodecManager::ConvertError(TInt /* aError */ )
       
   148     {
       
   149     }
       
   150 
       
   151 // ---------------------------------------------------------------------------
       
   152 // CIRCodecManager::DeviceMessage
       
   153 // ---------------------------------------------------------------------------
       
   154 //
       
   155 void CIRCodecManager::DeviceMessage(TUid /* aMessageType */, const TDesC8& /* aMsg */ )
       
   156     {
       
   157     }
       
   158 
       
   159 // ---------------------------------------------------------------------------
       
   160 // CIRCodecManager::LoadSupportedCodecsL
       
   161 // ---------------------------------------------------------------------------
       
   162 //
       
   163 void CIRCodecManager::LoadSupportedCodecsL()
       
   164     {
       
   165     IRLOG_DEBUG( "CIRCodecManager::LoadSupportedCodecsL" );
       
   166     CMMFDevSound* devSound = CMMFDevSound::NewL();
       
   167     CleanupStack::PushL( devSound );
       
   168     TMMFPrioritySettings prioritySettings;
       
   169 
       
   170     prioritySettings.iPriority = 0;
       
   171     prioritySettings.iPref = EMdaPriorityPreferenceNone;
       
   172     prioritySettings.iState = EMMFStatePlaying;
       
   173 
       
   174     devSound->GetSupportedInputDataTypesL( iSupportedDataTypes, prioritySettings );
       
   175     CleanupStack::PopAndDestroy( devSound );
       
   176 
       
   177     // CMMFDevSound returns also other codecs than those supported by IR.
       
   178     TInt tempCount = iSupportedDataTypes.Count();
       
   179     IRRDEBUG2("CIRCodecManager::LoadSupportedCodecsL() - codecs count = %d",tempCount);
       
   180     for ( TInt i = iSupportedDataTypes.Count() - 1; i >= 0; i-- )
       
   181         {
       
   182         if ( !VerifySupportL( iSupportedDataTypes[i] ) )
       
   183             {
       
   184             IRLOG_DEBUG2( "CIRCodecManager::LoadSupportedCodecsL - %x not supported.",
       
   185                         iSupportedDataTypes[i].FourCC() );
       
   186             iSupportedDataTypes.Remove( i );
       
   187             }
       
   188         else
       
   189             {
       
   190             IRLOG_INFO2( "CIRCodecManager::LoadSupportedCodecsL - %x supported.",
       
   191                         iSupportedDataTypes[i].FourCC() );
       
   192             }
       
   193         }
       
   194 
       
   195 #ifdef __WINS__
       
   196     // In emulator there is typically only 16 bit PCM supported.
       
   197     if ( iSupportedDataTypes.Count() == 0 )
       
   198         {
       
   199         TFourCC codec( KMMFFourCCCodeMP3 );
       
   200         iSupportedDataTypes.Append( codec );
       
   201         }
       
   202 #endif
       
   203 
       
   204 
       
   205     IRLOG_DEBUG( "CIRCodecManager::LoadSupportedCodecsL - Exiting." );
       
   206     }
       
   207 
       
   208 // ---------------------------------------------------------------------------
       
   209 // CIRCodecManager::VerifySupportL
       
   210 // ---------------------------------------------------------------------------
       
   211 //
       
   212 TBool CIRCodecManager::VerifySupportL( TFourCC aCodec )
       
   213     {
       
   214     IRLOG_DEBUG2( "CIRCodecManager::VefifySupportL - aCodec=%x", aCodec.FourCC() );
       
   215     TInt supported( EFalse );
       
   216     switch( aCodec.FourCC() )
       
   217         {
       
   218 #ifndef __SERIES60_30__
       
   219         case KMMFFourCCCodeWMA: // fall through
       
   220 #endif
       
   221         case KMMFFourCCCodeAAC: // fall through
       
   222         case KMMFFourCCCodeMP3:
       
   223             supported = ETrue;
       
   224             break;
       
   225         default:
       
   226             break;
       
   227         }
       
   228     if ( supported )
       
   229         {
       
   230         // Test initialisation to see that the codec really is supported.
       
   231         CMMFDevSound* devSound = CMMFDevSound::NewL();
       
   232         CleanupStack::PushL( devSound );
       
   233 
       
   234         TMMFState mmfState( EMMFStatePlaying );
       
   235         TRAPD( err, devSound->InitializeL( *this, aCodec, mmfState ) );
       
   236         if ( err != KErrNone )
       
   237             {
       
   238             supported = EFalse;
       
   239             }
       
   240         CleanupStack::PopAndDestroy( devSound );
       
   241         }
       
   242     IRLOG_DEBUG( "CIRCodecManager::VefifySupportL" );
       
   243     return supported;
       
   244     }
       
   245 
       
   246