devsoundextensions/mmfcustominterfaces/WmaDecoderIntfc/WmaDecoderIntfcMsgHdlr/src/WmaDecoderIntfcMsgHdlr.cpp
changeset 0 40261b775718
equal deleted inserted replaced
-1:000000000000 0:40261b775718
       
     1 /*
       
     2 * Copyright (c) 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:   Message handler for WMA 10 Pro decoder custom interface.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    "WmaDecoderIntfcMsgs.h"
       
    22 #include    "WmaDecoderIntfcMsgHdlr.h"
       
    23 //#include "WmaDecoderIntfc.h"
       
    24 
       
    25 // EXTERNAL DATA STRUCTURES
       
    26 
       
    27 // EXTERNAL FUNCTION PROTOTYPES
       
    28 
       
    29 // CONSTANTS
       
    30 
       
    31 // MACROS
       
    32 
       
    33 // LOCAL CONSTANTS AND MACROS
       
    34 
       
    35 // MODULE DATA STRUCTURES
       
    36 
       
    37 // LOCAL FUNCTION PROTOTYPES
       
    38 
       
    39 // FORWARD DECLARATIONS
       
    40 
       
    41 // ============================= LOCAL FUNCTIONS ===============================
       
    42 
       
    43 // ============================ MEMBER FUNCTIONS ===============================
       
    44 
       
    45 //------------------------------------------------------------------------------
       
    46 // CWmaDecoderIntfcMsgHdlr::CWmaDecoderIntfcMsgHdlr
       
    47 // C++ default constructor can NOT contain any code, that might leave.
       
    48 //------------------------------------------------------------------------------
       
    49 CWmaDecoderIntfcMsgHdlr::CWmaDecoderIntfcMsgHdlr(
       
    50                               CWmaDecoderIntfc* aWmaDecoderConfigCI) :
       
    51 	CMMFObject(KUidWmaDecoderIntfc)
       
    52     {
       
    53     iWmaDecoderIntfcCI = aWmaDecoderConfigCI;
       
    54     }
       
    55 
       
    56 //------------------------------------------------------------------------------
       
    57 // CWmaDecoderIntfcMsgHdlr::ConstructL
       
    58 // Symbian 2nd phase constructor can leave.
       
    59 //------------------------------------------------------------------------------
       
    60 void CWmaDecoderIntfcMsgHdlr::ConstructL()
       
    61     {
       
    62     }
       
    63 
       
    64 //------------------------------------------------------------------------------
       
    65 // WmaDecoderIntfcMsgHdlr::NewL
       
    66 // Two-phased constructor.
       
    67 //------------------------------------------------------------------------------
       
    68 EXPORT_C CWmaDecoderIntfcMsgHdlr* CWmaDecoderIntfcMsgHdlr::NewL(
       
    69                                        TAny* aWmaDecoderConfigCI)
       
    70     {
       
    71     CWmaDecoderIntfc* WmaDecoderConfigCI =
       
    72                 (CWmaDecoderIntfc*)aWmaDecoderConfigCI;
       
    73     CWmaDecoderIntfcMsgHdlr* self =
       
    74                 new (ELeave) CWmaDecoderIntfcMsgHdlr(WmaDecoderConfigCI);
       
    75     CleanupStack::PushL( self );
       
    76     self->ConstructL();
       
    77     CleanupStack::Pop( self );
       
    78 
       
    79     return self;
       
    80     }
       
    81 
       
    82 //------------------------------------------------------------------------------
       
    83 // Destructor
       
    84 //------------------------------------------------------------------------------
       
    85 EXPORT_C CWmaDecoderIntfcMsgHdlr::~CWmaDecoderIntfcMsgHdlr()
       
    86 	{
       
    87     iSupportedFormats.Close();
       
    88     iSupportedTools.Close();
       
    89     iControllableTools.Close();
       
    90 
       
    91 	delete iDataCopyBuffer;
       
    92 	delete iWmaDecoderIntfcCI;
       
    93 	}
       
    94 
       
    95 //------------------------------------------------------------------------------
       
    96 // CWmaDecoderIntfcMsgHdlr::HandleRequest
       
    97 // Handles the messages from the proxy.
       
    98 //------------------------------------------------------------------------------ 
       
    99 EXPORT_C void CWmaDecoderIntfcMsgHdlr::HandleRequest(
       
   100                                             TMMFMessage& aMessage)
       
   101 	{
       
   102 	ASSERT(aMessage.Destination().InterfaceId() == KUidWmaDecoderIntfc);
       
   103 
       
   104 	TRAPD(error, DoHandleRequestL(aMessage));
       
   105 
       
   106 	if(error)
       
   107 		{
       
   108 		aMessage.Complete(error);
       
   109 		}
       
   110 	}
       
   111 
       
   112 //------------------------------------------------------------------------------
       
   113 // CWmaDecoderIntfcMsgHdlr::DoHandleRequestL
       
   114 // Determines which custom interface to call.
       
   115 //------------------------------------------------------------------------------
       
   116 void CWmaDecoderIntfcMsgHdlr::DoHandleRequestL(TMMFMessage& aMessage)
       
   117 	{
       
   118 	switch(aMessage.Function())
       
   119 		{
       
   120 		case EWmaGetSupportedFormats:
       
   121 			{
       
   122     		DoGetSupportedFormatsL(aMessage);
       
   123 			break;
       
   124 			}
       
   125 		case EWmaGetSupportedTools:
       
   126 			{
       
   127     		DoGetSupportedToolsL(aMessage);
       
   128 			break;
       
   129 			}
       
   130 		case EWmaGetSupportedMaxChannels:
       
   131 			{
       
   132     		DoGetSupportedMaxChannelsL(aMessage);
       
   133 			break;
       
   134 			}
       
   135 		case EWmaGetSupportedMaxBitrate:
       
   136 			{
       
   137     		DoGetSupportedMaxBitrateL(aMessage);
       
   138 			break;
       
   139 			}
       
   140 		case EWmaGetSupportedMaxSampleRate:
       
   141 			{
       
   142     		DoGetSupportedMaxSampleRateL(aMessage);
       
   143 			break;
       
   144 			}
       
   145 		case EWmaGetControllableTools:
       
   146 			{
       
   147     		DoGetControllableToolsL(aMessage);
       
   148 			break;
       
   149 			}
       
   150 		case EWmaGetAllMsg:
       
   151 			{
       
   152     		DoGetAllL(aMessage);
       
   153 			break;
       
   154 			}		
       
   155 		case EWmaApplyConfig:
       
   156 			{
       
   157     		DoApplyConfigL(aMessage);
       
   158 			break;
       
   159 			}
       
   160 		case EWmaGetNumOfSupportedFormats:
       
   161  			{
       
   162     		DoGetNumOfSupportedFormatsL(aMessage);
       
   163 			break;
       
   164 			}
       
   165    		case EWmaGetNumOfSupportedTools:
       
   166 			{
       
   167     		DoGetNumOfSupportedToolsL(aMessage);
       
   168 			break;
       
   169 			}		
       
   170 		case EWmaGetNumOfControllableTools:
       
   171    			{
       
   172     		DoGetNumOfControllableToolsL(aMessage);
       
   173 			break;
       
   174 			}
       
   175  
       
   176 		default:
       
   177 			{
       
   178 			aMessage.Complete(KErrNotSupported);
       
   179 			break;
       
   180 			}
       
   181 		}
       
   182 	}
       
   183 
       
   184 //------------------------------------------------------------------------------
       
   185 // CWmaDecoderIntfcMsgHdlr::DoGetSupportedFormatsL
       
   186 // Get supported formats.
       
   187 //------------------------------------------------------------------------------
       
   188 void CWmaDecoderIntfcMsgHdlr::DoGetSupportedFormatsL(TMMFMessage& aMessage)
       
   189 	{
       
   190 	if (!iDataCopyBuffer)
       
   191 		{
       
   192 		User::Leave(KErrNotReady);			
       
   193 		}
       
   194 	aMessage.WriteDataToClientL(iDataCopyBuffer->Ptr(0));
       
   195     aMessage.Complete(KErrNone);
       
   196     }
       
   197 
       
   198 //------------------------------------------------------------------------------
       
   199 // CWmaDecoderIntfcMsgHdlr::DoGetSupportedToolsL
       
   200 // Get supported tools.
       
   201 //------------------------------------------------------------------------------
       
   202 void CWmaDecoderIntfcMsgHdlr::DoGetSupportedToolsL(TMMFMessage& aMessage)
       
   203 	{
       
   204 	if (!iDataCopyBuffer)
       
   205 		{
       
   206 		User::Leave(KErrNotReady);			
       
   207 		}
       
   208 	aMessage.WriteDataToClientL(iDataCopyBuffer->Ptr(0));
       
   209     aMessage.Complete(KErrNone);
       
   210 	}
       
   211 	
       
   212 //------------------------------------------------------------------------------
       
   213 // CWmaDecoderIntfcMsgHdlr::DoGetSupportedMaxChannelsL
       
   214 // Get max number of channels.
       
   215 //------------------------------------------------------------------------------
       
   216 void CWmaDecoderIntfcMsgHdlr::DoGetSupportedMaxChannelsL(TMMFMessage& aMessage)
       
   217 	{
       
   218 	TUint maxChannels = 0;
       
   219 	TInt status = iWmaDecoderIntfcCI->GetSupportedMaxChannelsIn(maxChannels);
       
   220 
       
   221     TPckgBuf<TUint> pckg;
       
   222     pckg() = maxChannels;
       
   223 	aMessage.WriteDataToClientL(pckg);
       
   224     	
       
   225     aMessage.Complete(status);		
       
   226 	}
       
   227 
       
   228 //------------------------------------------------------------------------------
       
   229 // CWmaDecoderIntfcMsgHdlr::DoGetSupportedMaxBitrateL
       
   230 // Get supported max bit rates.
       
   231 //------------------------------------------------------------------------------
       
   232 void CWmaDecoderIntfcMsgHdlr::DoGetSupportedMaxBitrateL(TMMFMessage& aMessage)
       
   233 	{
       
   234 	TUint maxBitrate = 0;
       
   235 	TInt status = iWmaDecoderIntfcCI->GetSupportedMaxBitrate(maxBitrate);
       
   236 
       
   237    	TPckgBuf<TUint> pckg;
       
   238    	pckg() = maxBitrate;
       
   239     aMessage.WriteDataToClientL(pckg);
       
   240    
       
   241     aMessage.Complete(status);			
       
   242 	}
       
   243 
       
   244 //------------------------------------------------------------------------------
       
   245 // CWmaDecoderIntfcMsgHdlr::DoGetSupportedMaxSampleRateL
       
   246 // Get supported max sample rate.
       
   247 //------------------------------------------------------------------------------
       
   248 void CWmaDecoderIntfcMsgHdlr::DoGetSupportedMaxSampleRateL(TMMFMessage& aMessage)
       
   249 	{
       
   250 	TUint maxSamplerate = 0;
       
   251 	TInt status = iWmaDecoderIntfcCI->GetSupportedMaxSampleRate(maxSamplerate);
       
   252 
       
   253     TPckgBuf<TUint> pckg;
       
   254     pckg() = maxSamplerate;
       
   255 	aMessage.WriteDataToClientL(pckg);
       
   256     
       
   257     aMessage.Complete(status);		
       
   258 		
       
   259 	}
       
   260 
       
   261 //------------------------------------------------------------------------------
       
   262 // CWmaDecoderIntfcMsgHdlr::DoGetControllableToolsL
       
   263 // Get supported controllable tools.
       
   264 //------------------------------------------------------------------------------
       
   265 void CWmaDecoderIntfcMsgHdlr::DoGetControllableToolsL(TMMFMessage& aMessage)
       
   266 	{
       
   267 	if (!iDataCopyBuffer)
       
   268 		{
       
   269 		User::Leave(KErrNotReady);			
       
   270 		}
       
   271 	aMessage.WriteDataToClientL(iDataCopyBuffer->Ptr(0));
       
   272     aMessage.Complete(KErrNone);
       
   273 	}
       
   274 
       
   275 //------------------------------------------------------------------------------
       
   276 // CWmaDecoderIntfcMsgHdlr::DoGetAllL
       
   277 // Get all configure parameters.
       
   278 //------------------------------------------------------------------------------	
       
   279 void CWmaDecoderIntfcMsgHdlr::DoGetAllL(TMMFMessage& aMessage)
       
   280 	{
       
   281    	TPckgBuf<TAllParams> pckg;
       
   282 	CWmaDecoderIntfc::TFormat format;
       
   283 	TInt status = iWmaDecoderIntfcCI->GetFormat(format);
       
   284    	pckg().iCurrentFormat = format;
       
   285 	pckg().iCurrentFormatStatus = status;    	
       
   286 
       
   287     TUint bitsPerSample = 0;
       
   288     status = iWmaDecoderIntfcCI->GetBitsPerSampleIn(bitsPerSample);    	
       
   289     pckg().iCurrentBitsPerSample = bitsPerSample;
       
   290 	pckg().iCurrentBitsPerSampleStatus = status;    	
       
   291 
       
   292 	TUint numOfChannels = 0;
       
   293 	status = iWmaDecoderIntfcCI->GetNumOfChannelsIn(numOfChannels);
       
   294    	pckg().iCurrentNumChannelsIn = numOfChannels;
       
   295 	pckg().iCurrentNumChannelsInStatus = status;    	
       
   296 
       
   297 	TUint samplesPerSec = 0;
       
   298 	status = iWmaDecoderIntfcCI->GetSamplesPerSec (samplesPerSec);
       
   299    	pckg().iCurrentSamplesPerSec = samplesPerSec;
       
   300 	pckg().iCurrentSamplesPerSecStatus = status;    	
       
   301 
       
   302     TUint avgBytesPerSec = 0;
       
   303     status = iWmaDecoderIntfcCI->GetAvgBytesPerSec (avgBytesPerSec);
       
   304    	pckg().iCurrentAvgBytesPerSec = avgBytesPerSec;
       
   305 	pckg().iCurrentAvgBytesPerSecStatus = status;    	
       
   306 
       
   307 	TUint blockAlign = 0;
       
   308 	status = iWmaDecoderIntfcCI->GetBlockAlign (blockAlign) ;
       
   309    	pckg().iCurrentBlockAlign = blockAlign;
       
   310 	pckg().iCurrentBlockAlignStatus = status;    	
       
   311 
       
   312 	TUint encodeOpts = 0;
       
   313 	status = iWmaDecoderIntfcCI->GetEncodeOptions (encodeOpts);
       
   314    	pckg().iCurrentEncodeOptions = encodeOpts;
       
   315 	pckg().iCurrentEncodeOptionsStatus = status;    	
       
   316 
       
   317 	TUint encodeOpts1 = 0;
       
   318 	status = iWmaDecoderIntfcCI->GetEncodeOptions1 (encodeOpts1);
       
   319    	pckg().iCurrentEncodeOptions1 = encodeOpts1;
       
   320 	pckg().iCurrentEncodeOptions1Status = status;    
       
   321 		
       
   322 	TUint encodeOpts2 = 0;
       
   323 	status = iWmaDecoderIntfcCI->GetEncodeOptions2(encodeOpts2);
       
   324    	pckg().iCurrentEncodeOptions2 = encodeOpts2;
       
   325 	pckg().iCurrentEncodeOptions2Status = status;    	
       
   326    	
       
   327 	TUint channelMask = 0;
       
   328 	status = iWmaDecoderIntfcCI->GetChannelMaskIn (channelMask);
       
   329    	pckg().iCurrentChannelMask = channelMask;
       
   330 	pckg().iCurrentChannelMaskStatus = status;    	
       
   331    	
       
   332 	CWmaDecoderIntfc::TTool tool = CWmaDecoderIntfc::EToolOutput32Bit;
       
   333 	TBool able = EFalse;
       
   334 	status = iWmaDecoderIntfcCI->GetTool(tool, able);
       
   335    	pckg().iCurrentToolOutPut32Bit = able;
       
   336 	pckg().iCurrentToolOutPut32BitStatus = status;    	
       
   337    	
       
   338 	tool = CWmaDecoderIntfc::EDownMixToStereo;
       
   339 	status = iWmaDecoderIntfcCI->GetTool(tool, able);
       
   340    	pckg().iCurrentToolDownMixToStereo = able;
       
   341 	pckg().iCurrentToolDownMixToStereoStatus = status;    	
       
   342 	   	
       
   343 	tool = CWmaDecoderIntfc::ELostDataConcealment;
       
   344 	status = iWmaDecoderIntfcCI->GetTool(tool, able);
       
   345    	pckg().iCurrentToolLostDataConcealment = able;
       
   346 	pckg().iCurrentToolLostDataConcealmentStatus = status;    	
       
   347  
       
   348     aMessage.WriteDataToClientL(pckg);
       
   349     
       
   350     aMessage.Complete(KErrNone);
       
   351 	}
       
   352 
       
   353 
       
   354 //------------------------------------------------------------------------------
       
   355 // CWmaDecoderIntfcMsgHdlr::DoApplyConfigL
       
   356 // Handles the message from the proxy and calls the custom interface method
       
   357 // to commit configuration settings to the decoder.
       
   358 //------------------------------------------------------------------------------
       
   359 void CWmaDecoderIntfcMsgHdlr::DoApplyConfigL(TMMFMessage& aMessage)
       
   360     {
       
   361     TInt status = KErrNone;
       
   362 	TPckgBuf<TWmaDecoderConfig> pckgBuf;
       
   363 	
       
   364     aMessage.ReadData1FromClientL(pckgBuf);
       
   365 	
       
   366 	iWmaDecoderIntfcCI->SetFormat(pckgBuf().iFormat);
       
   367 	iWmaDecoderIntfcCI->SetBitsPerSampleIn(pckgBuf().iBitsPerSample);
       
   368 	iWmaDecoderIntfcCI->SetNumChannelsIn(pckgBuf().iNumChannelsIn);
       
   369 	iWmaDecoderIntfcCI->SetSamplesPerSec(pckgBuf().iSamplesPerSec);
       
   370 	iWmaDecoderIntfcCI->SetAvgBytesPerSec(pckgBuf().iAvgBytesPerSec);
       
   371 	iWmaDecoderIntfcCI->SetBlockAlign(pckgBuf().iBlockAlign);
       
   372 	iWmaDecoderIntfcCI->SetEncodeOptions(pckgBuf().iEncodeOptions);
       
   373 	iWmaDecoderIntfcCI->SetEncodeOptions1(pckgBuf().iEncodeOptions1);
       
   374 	iWmaDecoderIntfcCI->SetEncodeOptions2(pckgBuf().iEncodeOptions2);				
       
   375 	iWmaDecoderIntfcCI->SetChannelMaskIn(pckgBuf().iChannelMask);
       
   376 
       
   377     TBool able = pckgBuf().iToolOutPut32Bit;
       
   378     if (able)
       
   379     	{
       
   380     	iWmaDecoderIntfcCI->EnableTool(CWmaDecoderIntfc::EToolOutput32Bit);	
       
   381     	}
       
   382     else
       
   383     	{
       
   384     	iWmaDecoderIntfcCI->DisableTool(CWmaDecoderIntfc::EToolOutput32Bit);	
       
   385     	}
       
   386 
       
   387     able = pckgBuf().iToolDownMixToStereo;
       
   388     if (able)
       
   389     	{
       
   390     	iWmaDecoderIntfcCI->EnableTool(CWmaDecoderIntfc::EDownMixToStereo);	
       
   391     	}
       
   392     else
       
   393     	{
       
   394     	iWmaDecoderIntfcCI->DisableTool(CWmaDecoderIntfc::EDownMixToStereo);	
       
   395     	}
       
   396 
       
   397     able = pckgBuf().iToolLostDataConcealment;
       
   398     if (able)
       
   399     	{
       
   400     	iWmaDecoderIntfcCI->EnableTool(CWmaDecoderIntfc::ELostDataConcealment);	
       
   401     	}
       
   402     else
       
   403     	{
       
   404     	iWmaDecoderIntfcCI->DisableTool(CWmaDecoderIntfc::ELostDataConcealment);	
       
   405     	}
       
   406 
       
   407 	status = iWmaDecoderIntfcCI->ApplyConfig();
       
   408     aMessage.Complete(status);
       
   409     }
       
   410 
       
   411 //------------------------------------------------------------------------------
       
   412 // CWmaDecoderIntfcMsgHdlr::CreateBufFromUintArrayL
       
   413 // Utility function used to create a buffer and fill it with data from the
       
   414 // array passed in.
       
   415 //------------------------------------------------------------------------------
       
   416 void CWmaDecoderIntfcMsgHdlr::CreateBufFromUintArrayL(RArray<TUint>& aArray)
       
   417 	{
       
   418 	delete iDataCopyBuffer;
       
   419 	iDataCopyBuffer = NULL;
       
   420 	iDataCopyBuffer = CBufFlat::NewL(8);
       
   421 
       
   422 	RBufWriteStream stream;
       
   423 	stream.Open(*iDataCopyBuffer);
       
   424 	CleanupClosePushL(stream);
       
   425 
       
   426 	for (TInt i = 0; i < aArray.Count(); i++)
       
   427 	    {	    	    
       
   428 		stream.WriteUint32L(aArray[i]);
       
   429 	    }
       
   430 	    
       
   431 	CleanupStack::PopAndDestroy(&stream);
       
   432 	}	
       
   433 
       
   434 // ---------------------------------------------------------
       
   435 // CWmaDecoderIntfcMsgHdlr::DoGetNumOfSupportedFormatsL
       
   436 //
       
   437 // ---------------------------------------------------------
       
   438 //
       
   439 void CWmaDecoderIntfcMsgHdlr::DoGetNumOfSupportedFormatsL(TMMFMessage& aMessage)
       
   440 	{
       
   441 	iSupportedFormats.Reset();
       
   442 	TInt status = iWmaDecoderIntfcCI->GetSupportedFormats(iSupportedFormats);
       
   443 
       
   444 	CreateBufFromUintArrayL(reinterpret_cast<RArray<TUint>&>(iSupportedFormats));
       
   445     TPckgBuf<TUint> pckg;
       
   446    	pckg() = iSupportedFormats.Count();
       
   447     aMessage.WriteDataToClientL(pckg);
       
   448 	
       
   449     aMessage.Complete(status);
       
   450 	}
       
   451 
       
   452 // ---------------------------------------------------------
       
   453 // CWmaDecoderIntfcMsgHdlr::DoGetNumOfSupportedToolsL(
       
   454 // ---------------------------------------------------------
       
   455 //
       
   456 void CWmaDecoderIntfcMsgHdlr::DoGetNumOfSupportedToolsL(TMMFMessage& aMessage)
       
   457 	{
       
   458 	iSupportedTools.Reset();
       
   459 	TInt status = iWmaDecoderIntfcCI->GetSupportedTools(iSupportedTools);
       
   460 	CreateBufFromUintArrayL(reinterpret_cast<RArray<TUint>&>(iSupportedTools));
       
   461 
       
   462 	TPckgBuf<TUint> pckg;
       
   463     pckg() = iSupportedTools.Count();
       
   464 	aMessage.WriteDataToClientL(pckg);
       
   465     aMessage.Complete(status);
       
   466 	}
       
   467 
       
   468 // ---------------------------------------------------------
       
   469 // CWmaDecoderIntfcMsgHdlr::DoGetNumOfControllableToolsL
       
   470 // ---------------------------------------------------------
       
   471 //
       
   472 void CWmaDecoderIntfcMsgHdlr::DoGetNumOfControllableToolsL(TMMFMessage& aMessage)
       
   473 	{
       
   474 	iControllableTools.Reset();
       
   475 	TInt status = iWmaDecoderIntfcCI->GetControllableTools(iControllableTools);
       
   476 	CreateBufFromUintArrayL(reinterpret_cast<RArray<TUint>&>(iControllableTools));
       
   477 	TPckgBuf<TUint> pckg;
       
   478     pckg() = iControllableTools.Count();
       
   479 	aMessage.WriteDataToClientL(pckg); 
       
   480     aMessage.Complete(status);
       
   481 	}
       
   482 
       
   483 
       
   484 
       
   485 // End of File