internetradio2.0/mediaenginesrc/irmp3player.cpp
changeset 14 896e9dbc5f19
parent 12 608f67c22514
child 15 065198191975
equal deleted inserted replaced
12:608f67c22514 14:896e9dbc5f19
     1 /*
       
     2 * Copyright (c) 2006-2007 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:  ?Description
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <AudioPreference.h>
       
    20 
       
    21 #include "irbuffercontainer.h"
       
    22 #include "irctrlcmdobserver.h"
       
    23 #include "irdebug.h"
       
    24 #include "irmediaenginebuffer.h"
       
    25 #include "irmp3player.h"
       
    26 #include "irmp3playerlocal.h"
       
    27 
       
    28 #ifdef __WINS__
       
    29 #include "irtestingaudioplayer.h"
       
    30 #endif //__WINS__
       
    31 
       
    32 
       
    33 
       
    34 // Constants
       
    35 const TInt KZero = 0;
       
    36 const TInt KOne = 1;
       
    37 const TInt KTwo = 2;
       
    38 const TInt KThree = 3;
       
    39 
       
    40 const TInt KTwentyFour = 24;
       
    41 const TInt KSixteen = 16;
       
    42 const TInt KEight = 8;
       
    43 const TInt KSamplesPerFrame1 = 576;
       
    44 const TInt KSamplesPerFrame2 = 1152;
       
    45 const TInt KOneFourFour = 144;
       
    46 const TInt KThousand = 1000;
       
    47 
       
    48 // ============================ MEMBER FUNCTIONS ===============================
       
    49 
       
    50 // ---------------------------------------------------------------------------
       
    51 // Function : NewL
       
    52 // function returns an instance of CIRMP3Player
       
    53 // Two phase constructor
       
    54 // ---------------------------------------------------------------------------
       
    55 //
       
    56 CIRMP3Player* CIRMP3Player::NewL()
       
    57 	{
       
    58 	IRLOG_DEBUG( "CIRMP3Player::NewL" );
       
    59 	CIRMP3Player* self = CIRMP3Player::NewLC();
       
    60 	CleanupStack::Pop(self);
       
    61 	IRLOG_DEBUG( "CIRMP3Player::NewL - Exiting." );
       
    62 	return self;
       
    63 	}
       
    64 	
       
    65 // ---------------------------------------------------------------------------
       
    66 // Function : NewLC
       
    67 // function creates an instance of CIRMP3Player
       
    68 // Two phase constructor
       
    69 // ---------------------------------------------------------------------------
       
    70 //
       
    71 CIRMP3Player* CIRMP3Player::NewLC()
       
    72 	{
       
    73 	IRLOG_DEBUG( "CIRMP3Player::NewLC" );
       
    74 	CIRMP3Player* self = new (ELeave) CIRMP3Player;
       
    75 	CleanupStack::PushL(self);
       
    76 	self->ConstructL();
       
    77 	IRLOG_DEBUG( "CIRMP3Player::NewLC - Exiting." );
       
    78 	return self;
       
    79 	}
       
    80 
       
    81 // ---------------------------------------------------------------------------
       
    82 // Function : ~CIRMP3Player
       
    83 // Default Destructor
       
    84 // ---------------------------------------------------------------------------
       
    85 //
       
    86 CIRMP3Player::~CIRMP3Player()
       
    87 	{
       
    88 	IRLOG_DEBUG( "CIRMP3Player::~CIRMP3Player" );
       
    89 	//delete the instance of the player
       
    90 	delete iAudioPlayer;
       
    91 	
       
    92 #ifdef __WINS__
       
    93 	if(iTestingAudioPlayer)
       
    94 		{
       
    95 		iTestingAudioPlayer->Close();
       
    96 		delete iTestingAudioPlayer;
       
    97 		iTestingAudioPlayer = NULL;
       
    98 		}
       
    99 	CActiveScheduler::Delete(iTestingAudioPlayer);
       
   100 
       
   101 #endif //__WINS__
       
   102 
       
   103 	while(!iSinkBufferQ.IsEmpty())
       
   104 		{
       
   105 		//Deleting all the entries in sink buffers queue
       
   106 		iTempBufferHolder = iSinkBufferQ.First();
       
   107 		iSinkBufferQ.Remove(*iTempBufferHolder);
       
   108 		delete iTempBufferHolder;
       
   109 		}
       
   110 	while(!iSourceBufferQ.IsEmpty())
       
   111 		{
       
   112 		//deleting all the entries in source buffers queue
       
   113 		iTempBufferHolder = iSourceBufferQ.First();
       
   114 		iSourceBufferQ.Remove(*iTempBufferHolder);
       
   115 		delete iTempBufferHolder;
       
   116 		}
       
   117 	IRLOG_DEBUG( "CIRMP3Player::~CIRMP3Player - Exiting." );	
       
   118 	}
       
   119 									//Function for Play control
       
   120 
       
   121 // ---------------------------------------------------------------------------
       
   122 // Function : Play
       
   123 // function to which intiate the player
       
   124 // ---------------------------------------------------------------------------
       
   125 //
       
   126 void CIRMP3Player::Play()
       
   127 	{
       
   128 	IRLOG_DEBUG( "CIRMP3Player::Play" );
       
   129 	//! then we have to stop it then restart the play from begining
       
   130 	if ( EPlaying == iState )
       
   131 		{
       
   132 		//internally stopped before playing so no need of sending
       
   133 		//stop status		
       
   134 		iSkipPlayCompleted = ETrue;
       
   135 		
       
   136 #ifdef __WINS__
       
   137 		iTestingAudioPlayer->Stop();
       
   138 #else 
       
   139 		iAudioPlayer->Stop(); 
       
   140 #endif //__WINS__
       
   141 		
       
   142 		iSkipPlayCompleted = EFalse;		
       
   143 		}
       
   144 	iState = ENotReady;
       
   145 	iStopState = EFalse;
       
   146 	iBufferPercentage = KZeroPercentage;
       
   147 	
       
   148 	//note : using TRAP_IGNORE to suppress a codescanner warning
       
   149 	//"Ignoring the return value from Open() functions"
       
   150 	//this cannot be checked as this symbian API returns void
       
   151 #ifdef __WINS__
       
   152 	TRAP_IGNORE ( iTestingAudioPlayer->Open() );
       
   153 #else 
       
   154 	//opening the current player component
       
   155 	TRAP_IGNORE ( iAudioPlayer->Open(&iSettings) );
       
   156 #endif //__WINS__
       
   157 	iChannel->SentRequest(EPlayingState,KErrNone);	
       
   158 	IRLOG_DEBUG( "CIRMP3Player::Play - Exiting." );	
       
   159 	}
       
   160 
       
   161 // ---------------------------------------------------------------------------
       
   162 // Function : Stop
       
   163 // function to which stop the player
       
   164 // ---------------------------------------------------------------------------
       
   165 //
       
   166 void CIRMP3Player::Stop()
       
   167 	{
       
   168 	IRLOG_DEBUG( "CIRMP3Player::Stop" );	
       
   169 	//If the current state is playing 	
       
   170 	if ( EPlaying == iState )
       
   171 		{
       
   172 #ifdef __WINS__
       
   173 		iTestingAudioPlayer->Stop();
       
   174 #else
       
   175 		iAudioPlayer->Stop();	
       
   176 #endif //__WINS__
       
   177 		
       
   178 		}		
       
   179 	else
       
   180 		{
       
   181 	IRRDEBUG2("CIRMP3Player::Stop EStoppedPlaying", KNullDesC); 
       
   182 		//sending the updated status as stopped
       
   183 		iChannel->SentRequest( EStoppedPlaying, KErrNone );	
       
   184 		}		
       
   185 	iState = EReadyToPlay;
       
   186 	iStopState = ETrue;
       
   187 	IRLOG_DEBUG( "CIRMP3Player::Stop - Exiting." );	
       
   188 	}
       
   189 										
       
   190 										//Functions for Volume Control
       
   191 
       
   192 // ---------------------------------------------------------------------------
       
   193 // Function : SetVolume
       
   194 // function to set the volume 
       
   195 // ---------------------------------------------------------------------------
       
   196 //	
       
   197 void CIRMP3Player::SetVolume(TInt aVolume )
       
   198 	{	
       
   199 	IRLOG_DEBUG( "CIRMP3Player::SetVolume" );		
       
   200 	//! If volume should be less than maximum value and greater than or equal to zero then set the volume
       
   201 	if( KZeroVolume <= aVolume && iAudioPlayer->MaxVolume() >= aVolume )
       
   202 		{
       
   203 		iAudioPlayer->SetVolume( aVolume );	
       
   204 		iConfig.iVolume = iCurrentVolume = aVolume;
       
   205 		}		
       
   206 	IRLOG_DEBUG( "CIRMP3Player::SetVolume - Exiting." );	
       
   207 	}
       
   208 
       
   209 // ---------------------------------------------------------------------------
       
   210 // Function : MaxVolume
       
   211 // function to returns the maximum volume 
       
   212 // ---------------------------------------------------------------------------
       
   213 //
       
   214 TInt CIRMP3Player::MaxVolume() const
       
   215 	{
       
   216 	IRLOG_DEBUG( "CIRMP3Player::MaxVolume" );
       
   217 	return iAudioPlayer->MaxVolume();	
       
   218 	}
       
   219 
       
   220 // ---------------------------------------------------------------------------
       
   221 // Function : Volume
       
   222 // function to returns the volume, integer level of volume is the Output
       
   223 // ---------------------------------------------------------------------------
       
   224 //
       
   225 TInt CIRMP3Player::Volume() const
       
   226 	{
       
   227 	IRLOG_DEBUG( "CIRMP3Player::Volume" );
       
   228 	return iAudioPlayer->Volume();
       
   229 	}
       
   230 
       
   231 									//Intialization of Codec Settings
       
   232 
       
   233 // ---------------------------------------------------------------------------
       
   234 // Function: Intialize
       
   235 // Set the codec type and sampling rate channel of stream
       
   236 // This is set to initial settings which is required to start the player
       
   237 // ---------------------------------------------------------------------------
       
   238 //
       
   239 void CIRMP3Player::Intialize(TConfig& aConfig,TUint8* aInitParams,
       
   240 	CIRCtrlCmdObserver* aChannel)
       
   241 	{
       
   242 	IRLOG_DEBUG( "CIRMP3Player::Intialize" );
       
   243 	iInputBufferPtr = reinterpret_cast<TUint8*> (aInitParams); //instance of buffer
       
   244 	iConfig = aConfig; //! Set all the configuration information like volume
       
   245 	iPlayBufferSize = iConfig.iPlayBufferSize;
       
   246 	iInputBufferSize = iConfig.iPlayBufferCount*iPlayBufferSize;
       
   247     iBufferOffset = iPlayBufferSize;
       
   248 	iDataType.Set(KMMFFourCCCodeMP3); //! Set the data type as MP3
       
   249 	iChannel = reinterpret_cast<CIRCtrlCmdObserver*> (aChannel);
       
   250 	TRAPD(err,CreateBufferL()); // allocates buffer to the queue
       
   251 	if( err )
       
   252 		{
       
   253 	IRRDEBUG2("CIRMP3Player::Intialize - EError", KNullDesC);
       
   254 		iChannel->SentRequest( EError, KIRCtrlCmdGeneralPlayerError );
       
   255 		return;	
       
   256 		}
       
   257 	iChannel->SentRequest(EPlayerChanged,KErrNone);									//creates an instance of the player
       
   258 	IRLOG_DEBUG( "CIRMP3Player::Intialize - Exiting." );
       
   259 	}
       
   260 
       
   261 // ---------------------------------------------------------------------------
       
   262 // Function: StopPlayerBuffering
       
   263 // Function is used to stop buffering 
       
   264 // ---------------------------------------------------------------------------
       
   265 //
       
   266 void CIRMP3Player::StopPlayerBuffering()
       
   267 	{
       
   268 	IRLOG_DEBUG( "CIRMP3Player::StopPlayerBuffering" );
       
   269 	//stops the player from buffering
       
   270 	iStopPlayerBuffering = ETrue;	
       
   271 	}
       
   272 
       
   273 // ---------------------------------------------------------------------------
       
   274 // Function: BufferFilled
       
   275 // Function which is called when network gets the buffer filled with data
       
   276 // ---------------------------------------------------------------------------
       
   277 //
       
   278 void CIRMP3Player::BufferFilled()
       
   279 	{
       
   280 	IRLOG_DEBUG( "CIRMP3Player::BufferFilled" );
       
   281 	if( !iNewPlayer )
       
   282 		{
       
   283 		if( !iSourceBufferQ.IsEmpty() )
       
   284 			{
       
   285 			//! Initially all unfilled buffers are in source buffer Queue
       
   286 			//! Once the buffer in the source buffer queue is filled it is moved to queue of buffer
       
   287 			//! to the sink
       
   288 			iTempBufferHolder = iSourceBufferQ.First();
       
   289 			iSourceBufferQ.Remove(*iTempBufferHolder);
       
   290 			iSinkBufferQ.AddLast(*iTempBufferHolder);
       
   291 			}
       
   292 		}
       
   293 	
       
   294 	if( iFirstTime )
       
   295 		{
       
   296 		if( !iNewPlayer )
       
   297 			{
       
   298 			// During rebuffering only
       
   299 			if( !iSourceBufferQ.IsEmpty() ) 
       
   300 				{
       
   301 				//if source buffer is empty
       
   302 				//first buffer of source buffer is taken and refilled
       
   303 				iTempBufferHolder = iSourceBufferQ.First();							
       
   304 				iTempbuffer = iTempBufferHolder->Des();
       
   305 				iInputBuffer.Set(iTempbuffer,iPlayBufferSize,iPlayBufferSize);
       
   306 				if( iStopState )
       
   307 					{
       
   308                     IRLOG_DEBUG( "CIRMP3Player::BufferFilled - Exiting (1)." );
       
   309 					return;
       
   310 					}
       
   311 				if( !iStopPlayerBuffering )
       
   312 					{								
       
   313 					//Calls the fill the buffer for next subsequent times 
       
   314 					//until the source buffer queue is empty
       
   315 					iChannel->FilltheBuffer(iInputBuffer); 
       
   316 					}
       
   317 				else
       
   318 					{
       
   319                     IRLOG_DEBUG( "CIRMP3Player::BufferFilled - Exiting (2)." );
       
   320 					//if stopPlayerBuffering is set it has return without buffering
       
   321 					return;	
       
   322 					}
       
   323 				}
       
   324 			else
       
   325 				{
       
   326 				//once it is rebuffered it has trigger play
       
   327 				//it has to indicate that rebuffering has completed for client
       
   328 				
       
   329 				TInt err( KErrNone ); 
       
   330 				if( !iReBuffering )
       
   331 					{
       
   332 					GetMP3AudioProperties();
       
   333 					//Sets the audio properties of the player like sampling rate and channel
       
   334 					TRAP(err, iAudioPlayer->SetAudioPropertiesL(iSettings.iSampleRate,
       
   335 																iSettings.iChannels));
       
   336 					if ( err )
       
   337 						{
       
   338 					IRRDEBUG2("CIRMP3Player::BufferFilled - EError", KNullDesC);
       
   339 						iChannel->SentRequest( EError, KIRCtrlCmdGeneralPlayerError );	
       
   340                         IRLOG_DEBUG( "CIRMP3Player::BufferFilled - Exiting (3)." );
       
   341 						return;
       
   342 						}
       
   343 					}
       
   344 				iReBuffering = EFalse;
       
   345 				//buffer reached 100% headers are decoded ready to play			
       
   346 				iBufferPercentage = K100Percentage;
       
   347 				iChannel->SentRequest( EBufferFillStop, iBufferPercentage ); 
       
   348 				
       
   349 				if( !iSinkBufferQ.IsEmpty() )
       
   350 					{
       
   351 					iTempBufferHolder = iSinkBufferQ.First();	
       
   352 					}					
       
   353 				iTempbuffer = iTempBufferHolder->Des();
       
   354 				
       
   355 				//Take first source buffer queue to be filled
       
   356 				iInput.Set(iTempbuffer,iPlayBufferSize,iPlayBufferSize);
       
   357 				iFirstTime = EFalse;
       
   358 				iState = EPlaying;
       
   359 				if( !iStopState )
       
   360 					{
       
   361 
       
   362 #ifdef __WINS__
       
   363 					iTestingAudioPlayer->Write();
       
   364 #else
       
   365 					//writing to mmp based buffer to trigger play
       
   366 					TRAP(err,iAudioPlayer->WriteL(iInput));	
       
   367 
       
   368 					if( err )
       
   369 						{
       
   370 						//error condition
       
   371 			IRRDEBUG2("CIRMP3Player::BufferFilled - EError1", KNullDesC);
       
   372 						iChannel->SentRequest( EError, KIRCtrlCmdGeneralPlayerError );	
       
   373                         IRLOG_DEBUG( "CIRMP3Player::BufferFilled - Exiting (4)." );
       
   374 						return;
       
   375 						}
       
   376 #endif //__WINS__	
       
   377 					}
       
   378 				//! Calls the play for the first time after rebuffering
       
   379 			
       
   380 				}
       
   381 			}
       
   382 		else
       
   383 			{
       
   384 			//First time when the player is created
       
   385 			TInt err( KErrNone );
       
   386 			GetMP3AudioProperties();			
       
   387 				
       
   388 			//! Sets the audio properties of the player like sampling rate and channel
       
   389 			//Sets the audio properties of the player like sampling rate and channel
       
   390 			TRAP(err, iAudioPlayer->SetAudioPropertiesL(iSettings.iSampleRate,
       
   391 														iSettings.iChannels));
       
   392 			if ( err )
       
   393 				{
       
   394 		IRRDEBUG2("CIRMP3Player::BufferFilled - EError2", KNullDesC);
       
   395 				iChannel->SentRequest( EError, KIRCtrlCmdGeneralPlayerError );	
       
   396 	            IRLOG_DEBUG( "CIRMP3Player::BufferFilled - Exiting (5)." );
       
   397 				return;
       
   398 				}
       
   399 			//buffer percentage is 100%							
       
   400 			iBufferPercentage = K100Percentage;
       
   401 			//indicating it has rebuffered
       
   402 			iChannel->SentRequest( EBufferFadeInReady, iBufferPercentage ); 			
       
   403 			
       
   404 			if( !iSinkBufferQ.IsEmpty() )
       
   405 				{
       
   406 				iTempBufferHolder = iSinkBufferQ.First();
       
   407 				}
       
   408 			iTempbuffer = iTempBufferHolder->Des();
       
   409 			
       
   410 			//first buffer of sink is taken and played
       
   411 			iInput.Set(iTempbuffer,iPlayBufferSize,iPlayBufferSize);
       
   412 			iNewPlayer = EFalse;
       
   413 			iFirstTime = EFalse;
       
   414 			iState = EPlaying;
       
   415 			
       
   416 			//Calls the play for the first time
       
   417 			if( !iStopState )
       
   418 				{
       
   419 #ifdef __WINS__
       
   420 				iTestingAudioPlayer->Write();
       
   421 #else
       
   422 				//writing to MMF buffers
       
   423 				TRAP(err,iAudioPlayer->WriteL(iInput));	
       
   424 				if( err )
       
   425 					{
       
   426 			IRRDEBUG2("CIRMP3Player::BufferFilled - EError3", KNullDesC);
       
   427 					iChannel->SentRequest( EError, KIRCtrlCmdGeneralPlayerError );	
       
   428 					IRLOG_DEBUG( "CIRMP3Player::BufferFilled - Exiting (6)." );	
       
   429 					return;
       
   430 					}	
       
   431 #endif //__WINS__
       
   432 				}
       
   433 			}	
       
   434 		}		
       
   435 	IRLOG_DEBUG( "CIRMP3Player::BufferFilled - Exiting (7)." );
       
   436 	}
       
   437 
       
   438 // ---------------------------------------------------------------------------
       
   439 // Function: CIRMP3Player
       
   440 // This function is the default constructor
       
   441 // ---------------------------------------------------------------------------
       
   442 //
       
   443 CIRMP3Player::CIRMP3Player() : iInputBuffer(NULL,0,0), iInput(NULL,0,0)
       
   444 	{
       
   445 	IRLOG_DEBUG( "CIRMP3Player::CIRMP3Player" );
       
   446 	}
       
   447 
       
   448 // ---------------------------------------------------------------------------
       
   449 // Function: ConstructL
       
   450 // Two phase constructor is used to intialize data members
       
   451 // Function can leave if CMdaAudioOutputStream::NewL leaves
       
   452 // ---------------------------------------------------------------------------
       
   453 //
       
   454 void CIRMP3Player::ConstructL()
       
   455 	{
       
   456 	IRLOG_DEBUG( "CIRMP3Player::ConstructL" );
       
   457 
       
   458 	iAudioPlayer = CMdaAudioOutputStream::NewL(*this,KAudioPriorityRealOnePlayer,
       
   459 		(TMdaPriorityPreference)KAudioPrefRealOneStreaming );
       
   460 
       
   461 										//creates an instance of the player
       
   462 										
       
   463 #ifdef __WINS__			
       
   464 	iTestingAudioPlayer = CIRTestingAudioPlayer::NewL(*this);
       
   465 	CActiveScheduler::Add(iTestingAudioPlayer);
       
   466 #endif //__WINS__
       
   467 
       
   468 	TInt f_off = _FOFF(CIRBufferContainer,iLink); //for the buffer queue which is maintained
       
   469 
       
   470     iSinkBufferQ.SetOffset(f_off);	 //It is Queue of buffer used by media Sink
       
   471     iSourceBufferQ.SetOffset(f_off); // Source of buffer which is ready to fill
       
   472     
       
   473 	iNewPlayer = ETrue;	//indicates that this a newly created player
       
   474 	iStopPlayerBuffering = EFalse;	//indicates whether to stop buffering
       
   475 	iState = ENotReady;	//current state not ready	
       
   476 	iNeedReBuffering = EFalse;//if rebuffering is required this is to set true
       
   477 	iStopState = EFalse; //
       
   478 	IRLOG_DEBUG( "CIRMP3Player::ConstructL - Exiting." );	
       
   479 	}
       
   480 
       
   481 // ---------------------------------------------------------------------------
       
   482 // Function: CreateBufferL 
       
   483 // Created buffers in sink buffer queue and allocates memory to sink buffer queues
       
   484 // ---------------------------------------------------------------------------
       
   485 //
       
   486 void CIRMP3Player::CreateBufferL()
       
   487 	{
       
   488 	IRLOG_DEBUG( "CIRMP3Player::CreatebufferL" );	
       
   489 	TUint8* bufferaddress = iInputBufferPtr;
       
   490 	//! source buffers not created since initially all buffers are filled with data and is ready to play	
       
   491 	//! Created buffers in sink buffer queue and allocates memory to sink buffer queues
       
   492 	for(TInt buffercount = 0; buffercount < KIRInputBufferCount; buffercount++)
       
   493 		{		
       
   494 		iTempBufferHolder = CIRBufferContainer::NewL(bufferaddress,
       
   495 			iPlayBufferSize);
       
   496 		iSinkBufferQ.AddLast(*iTempBufferHolder);
       
   497 		bufferaddress += iBufferOffset;
       
   498 		}
       
   499 	IRLOG_DEBUG( "CIRMP3Player::CreatebufferL - Exiting." );	
       
   500 	}
       
   501 	
       
   502 // ---------------------------------------------------------------------------
       
   503 // Function: ReCreateBufferL 
       
   504 // Recreates buffers of source queue
       
   505 // ---------------------------------------------------------------------------
       
   506 //
       
   507 void CIRMP3Player::ReCreateBufferL()
       
   508 	{
       
   509 	IRLOG_DEBUG( "CIRMP3Player::ReCreateBufferL " );
       
   510 	while(!iSinkBufferQ.IsEmpty())
       
   511 		{
       
   512 		//Deleting all the entries in sink buffers queue
       
   513 		iTempBufferHolder = iSinkBufferQ.First();
       
   514 		iSinkBufferQ.Remove(*iTempBufferHolder);
       
   515 		delete iTempBufferHolder;
       
   516 		iTempBufferHolder = NULL;	
       
   517 		}
       
   518 	while(!iSourceBufferQ.IsEmpty())
       
   519 		{
       
   520 		//deleting all the entries in source buffers queue
       
   521 		iTempBufferHolder = iSourceBufferQ.First();
       
   522 		iSourceBufferQ.Remove(*iTempBufferHolder);
       
   523 		delete iTempBufferHolder;
       
   524 		iTempBufferHolder = NULL;	
       
   525 		}
       
   526 	TUint8* bufferaddress = iInputBufferPtr; 
       
   527 	//reallocates the buffer to source buffer queue
       
   528 	for(TInt buffercount = 0; buffercount < KIRInputBufferCount; buffercount++)
       
   529 		{		
       
   530 		iTempBufferHolder = CIRBufferContainer::NewL(bufferaddress,
       
   531 			iPlayBufferSize);
       
   532 		iSourceBufferQ.AddLast(*iTempBufferHolder);
       
   533 		bufferaddress += iBufferOffset;
       
   534 		}	
       
   535 	IRLOG_DEBUG( "CIRMP3Player::ReCreateBufferL - Exiting." );
       
   536 	}
       
   537 
       
   538 	
       
   539 // ---------------------------------------------------------------------------
       
   540 // Function: GetMP3AudioProperties
       
   541 // extract all the information required to start the play from the stream
       
   542 // ---------------------------------------------------------------------------
       
   543 //
       
   544 void CIRMP3Player::GetMP3AudioProperties()
       
   545 	{
       
   546 	IRLOG_DEBUG( "CIRMP3Player::GetMP3AudioProperties" );
       
   547 	//Decoding MP3 header		
       
   548 	DoFindnDecodeMP3Header();	
       
   549 	
       
   550 	//! Sets the sampling rate and channel information to data members
       
   551 	switch(iAudioInfo.iSamplingRate)
       
   552 		{
       
   553 		case EMp3SamplingFreq8000: //sampling frequency 8000
       
   554 			{	
       
   555 			iSettings.iSampleRate = TMdaAudioDataSettings::ESampleRate8000Hz;
       
   556 			}
       
   557 			break;
       
   558 		case EMp3SamplingFreq11025: //sampling frequency 11025
       
   559 			{			
       
   560 			iSettings.iSampleRate = TMdaAudioDataSettings::ESampleRate11025Hz;
       
   561 			}
       
   562 			break;
       
   563 		case EMp3SamplingFreq12000:	//sampling frequency 12000
       
   564 			{	
       
   565 			iSettings.iSampleRate = TMdaAudioDataSettings::ESampleRate12000Hz;
       
   566 			}
       
   567 			break;
       
   568 		case EMp3SamplingFreq16000:	//sampling frequency 16000
       
   569 			{			
       
   570 			iSettings.iSampleRate = TMdaAudioDataSettings::ESampleRate16000Hz;
       
   571 			}
       
   572 			break;
       
   573 		case EMp3SamplingFreq22050:	//sampling frequency 22050
       
   574 			{
       
   575 			iSettings.iSampleRate = TMdaAudioDataSettings::ESampleRate22050Hz;
       
   576 			}
       
   577 			break;
       
   578 		case EMp3SamplingFreq24000:	//sampling frequency 24000
       
   579 			{			
       
   580 			iSettings.iSampleRate = TMdaAudioDataSettings::ESampleRate24000Hz;
       
   581 			}
       
   582 			break;
       
   583 		case EMp3SamplingFreq32000:	//sampling frequency 32000
       
   584 			{
       
   585 			iSettings.iSampleRate = TMdaAudioDataSettings::ESampleRate32000Hz;
       
   586 			}
       
   587 			break;
       
   588 		case EMp3SamplingFreq44100:	//sampling frequency 44100
       
   589 			{			
       
   590 			iSettings.iSampleRate = TMdaAudioDataSettings::ESampleRate44100Hz;
       
   591 			}
       
   592 			break;
       
   593 		case EMp3SamplingFreq48000:	//sampling frequency 48000
       
   594 			{	
       
   595 			iSettings.iSampleRate = TMdaAudioDataSettings::ESampleRate48000Hz;
       
   596 			}
       
   597 			break;
       
   598 		default:	//default sampling frequency 22050
       
   599 			{	
       
   600 			iSettings.iSampleRate = TMdaAudioDataSettings::ESampleRate22050Hz;
       
   601 			}
       
   602 			break;	
       
   603 		}
       
   604 	//sets the channel information	
       
   605 	if( KMp3ChannelMono == iAudioInfo.iChannel ) //0 indicates mono
       
   606 		{
       
   607 		iSettings.iChannels = TMdaAudioDataSettings::EChannelsMono;	
       
   608 		}		
       
   609 	else	//else 1 it indicates it is stereo
       
   610 		{
       
   611 		iSettings.iChannels = TMdaAudioDataSettings::EChannelsStereo;	
       
   612 		}				
       
   613 	IRLOG_DEBUG( "CIRMP3Player::GetMP3AudioProperties - Exiting." );
       
   614 	}
       
   615 	
       
   616 // ---------------------------------------------------------------------------
       
   617 // Function: DoFindnDecodeMP3Header
       
   618 // Function is used to find the mp3 header and decode the mp3 header
       
   619 // This function do have hard coded values and these value remains as such
       
   620 // as long as the standard remains, so used as such
       
   621 // ---------------------------------------------------------------------------
       
   622 //
       
   623 void CIRMP3Player::DoFindnDecodeMP3Header()
       
   624 	{
       
   625 	IRLOG_DEBUG( "CIRMP3Player::DoFindnDecodeMP3Header" );
       
   626 	//first buffer is discarded
       
   627 	TUint8* input = iInputBufferPtr;
       
   628 	//end ptr is calculated
       
   629 	TUint8* endptr = iInputBufferPtr + iInputBufferSize;
       
   630 	
       
   631 	//holds the 4 bytes of data
       
   632 	TUint value = 0; //value zero is intialized
       
   633 	TBool headerfound = EFalse;
       
   634 	
       
   635 	//value are to hardcoded as this is the standard way of implement
       
   636 	// the MP3 header decoding
       
   637 	while( input < endptr && !headerfound )
       
   638 		{
       
   639 		//stepsuccess indicates the success in each step or stage of header decoding,
       
   640 		//incase of failure we will not go for next step
       
   641 		TBool stepsuccess = EFalse;
       
   642 		//initially no header is found
       
   643 		//assign the value to zero initially for clearing the value
       
   644 		//then assign next 32 bits of data to value	
       
   645 		value = 0; //value is cleared
       
   646 		value |= input[0]<<KTwentyFour; //first 8 bit is shift 24bits copied (or) to "value"
       
   647 		value |= input[1]<<KSixteen; //second 8 bit is shift 24bits copied (or) to "value"
       
   648 		value |= input[2]<<KEight;//third 8 bit is shift 24bits copied (or) to "value"
       
   649 		value |= input[KThree];//last 8 bit is shift 24bits copied (or) to "value"
       
   650 		
       
   651 		// sync bytes found
       
   652 		// for performance reasons check already that it is not data within an empty frame (all bits set)
       
   653 		// therefore check wether the bits for bitrate are all set -> means that this is no header
       
   654 		if ( (input[0] == 0xFF) && ( ( input[1] & 0xE0 ) == 0xE0 ) && ( ( input[2] & 0xF0 ) != 0xF0 ) )
       
   655 			{
       
   656 			//header is found
       
   657 			//first level of header decoding is success, so stepsuccess = ETrue
       
   658 			stepsuccess = ETrue;
       
   659 			//version information is stored in 2 bits starting from 19th bit of header
       
   660 			//two get only 2bits we are doing an AND operation with 0b011 (0x03)				
       
   661 			TInt index = (value >> 19) & 0x03;
       
   662 			//! Gets the version information of MPEG
       
   663 			
       
   664 			TInt version = index; 	 //MPEG 2.5 	00
       
   665 									 //reservered   01
       
   666 									 //MPEG 2       10
       
   667 									 //MPEG 1       11
       
   668 			//if header information is 0x01						 
       
   669 			iAudioInfo.iVersion = version;
       
   670 			if( 0x01 == iAudioInfo.iVersion ) 
       
   671 				{
       
   672 				//bit pattern 0x01 indicates that version is reserved 							  
       
   673 				// and is considered as incorrect header information
       
   674 				stepsuccess = EFalse;	
       
   675 				}
       
   676 				
       
   677 			else
       
   678 				{
       
   679 				//bit pattern 0x00 indictes MPEG version is 2.5
       
   680 				//bit pattern 0x10 indictes MPEG version is 2
       
   681 				//MPEG 2.5 (0x00) and MPEG 2 (0x10) version
       
   682 				if( (0x00 == iAudioInfo.iVersion) || 
       
   683 					(0x02 == iAudioInfo.iVersion) )
       
   684 					{
       
   685 					//576 samples per frame
       
   686 					//there is 576 samples per frame
       
   687 					iAudioInfo.iSamplesPerFrame = KSamplesPerFrame1;
       
   688 					}
       
   689 				else 
       
   690 					{
       
   691 					//MPEG 1 version (0x11) 
       
   692 					//for MPEG 1 there is 1152 samples per frame
       
   693 					iAudioInfo.iSamplesPerFrame = KSamplesPerFrame2;
       
   694 					}
       
   695 				}				
       
   696 				
       
   697 			if( stepsuccess )
       
   698 				{
       
   699 				//layer information from the header is obtained from 2 bits starting 17th Bit
       
   700 				//information is extracted to index. 				
       
   701 				index = ( value >> 17 ) & 0x03;     
       
   702 				if( 0x01 != index ) 	//Layer 3 check if its layer 2 to layer 1 								
       
   703 					{				    //we will consider the header is not proper
       
   704 					stepsuccess = EFalse;
       
   705 					}
       
   706 				else
       
   707 					{
       
   708 					iAudioInfo.iLayer = 2; //Layer 3
       
   709 					//for selection bitrate we have need a combination of MPEG version, layer information
       
   710 					//and selection bits. the selection bits starts from 12th bits of mp3 header
       
   711 					//the selection byte is extracted into the index		
       
   712 					index = (value >> 12) & 0x000F;
       
   713 					TInt versionindex = 0;
       
   714 					if( 0x11 == version )
       
   715 						{
       
   716 						//index of the array is 0
       
   717 						versionindex = 0;	
       
   718 						}
       
   719 					else
       
   720 						{
       
   721 						//index of array is 1
       
   722 						versionindex = 1;	
       
   723 						}
       
   724 					//getting the bit rate
       
   725 					iAudioInfo.iBitRate = 
       
   726 						KBitRate[versionindex][iAudioInfo.iLayer][index];  
       
   727 					if( iAudioInfo.iBitRate == 0 ) //since bit rate is zero we consider as header is not proper
       
   728 						{
       
   729 						stepsuccess = EFalse;
       
   730 						}						
       
   731 					}			
       
   732 				}
       
   733 				
       
   734 			if( stepsuccess )
       
   735 				{
       
   736 				//sampling rate is obtained by a combination of MPEG version and
       
   737 				//selection bits. There are 2 selection bits starting from 10th bit
       
   738 				//and is extracted (AND with 0x03) from header and stored in index 
       
   739 				index = ( value >> 10 ) & 0x03;
       
   740 				
       
   741 				//! Gets the sampling frequency				
       
   742 				iAudioInfo.iSamplingRate = 
       
   743 					KMP3SamplingRate[iAudioInfo.iVersion][index];
       
   744 				if( 0 == iAudioInfo.iSamplingRate ) //if sampling rate is 0 it is invalidated
       
   745 					{
       
   746 					stepsuccess = EFalse;	
       
   747 					}
       
   748 				//padding information is obtained from 9th bit of mp3 header
       
   749 				iAudioInfo.iPadding = (value >> 9) & 0x01; //padding
       
   750 				
       
   751 				//the information for selection of channel is stored in 2bits starting from 6th bit of
       
   752 				//mp3 header and is decoded and kept in index for selection of channel
       
   753 				index = ( value >> 6 ) & 0x0003;				
       
   754 				iAudioInfo.iChannel = KChannelInfo[index]; //0 for mono and 1 for stereo			
       
   755 				
       
   756 				//framesize = (144 * bitrate)/(padding + sampling rate)
       
   757 				if( stepsuccess )
       
   758 					{//multiplication of 1000 is to convert kbs to bs
       
   759 					iAudioInfo.iFrameSize = (KOneFourFour * iAudioInfo.iBitRate * KThousand)
       
   760 						/(iAudioInfo.iPadding + iAudioInfo.iSamplingRate);	
       
   761 					}
       
   762 				//cross checking the header with next header
       
   763 				//both sampling frequency matches the function will return ETrue else EFalse	
       
   764 				if( !CrossCheckHeader(input) ) 
       
   765 					{
       
   766 					stepsuccess = EFalse;
       
   767 					}
       
   768 				}
       
   769 			if( stepsuccess )
       
   770 				{
       
   771 				//header is found
       
   772 				headerfound = ETrue;	
       
   773 				}
       
   774 			else
       
   775 				{
       
   776 				//header is not found
       
   777 				input++;	
       
   778 				}
       
   779 			} // sync bytes found
       
   780 			else
       
   781 			{
       
   782 			//header sync bits doesn't match
       
   783 			input++;	
       
   784 			}
       
   785 		}
       
   786 	IRLOG_DEBUG( "CIRMP3Player::DoFindnDecodeMP3Header - Exiting." );
       
   787 	}
       
   788 	
       
   789 // ---------------------------------------------------------------------------
       
   790 // Function: CrossCheckHeader
       
   791 // Function is cross checks sampling rate  
       
   792 // This function do have hard coded values and these value remains as such
       
   793 // as long as the standard remains, so used as such
       
   794 // ---------------------------------------------------------------------------
       
   795 //
       
   796 TBool CIRMP3Player::CrossCheckHeader(TUint8* aInput)
       
   797 	{
       
   798 	IRLOG_DEBUG( "CIRMP3Player::CrossCheckHeader" );
       
   799 	if( !aInput )
       
   800 		{
       
   801 		return EFalse;
       
   802 		}
       
   803 	//next header is to taken
       
   804 	TUint8* input = aInput + iAudioInfo.iSamplesPerFrame;
       
   805 	TUint8* endptr = iInputBufferPtr + iInputBufferSize 
       
   806 		- KMp3FrameHeaderSize;
       
   807 	TUint32 samplingrate = 0;
       
   808 	TBool headerfound = EFalse;
       
   809 	
       
   810 	TUint value = 0;
       
   811 	TInt version = 0;
       
   812 	TUint channel = 0;
       
   813 	TUint layer = 0;
       
   814 	while( input < endptr && !headerfound )
       
   815 		{
       
   816 		//header is not found
       
   817 		TInt successheader = EFalse;
       
   818 		//assign the value to zero initially for clearing the value
       
   819 		//then assign next 32 bits of data to value			
       
   820 		value = 0;
       
   821 		value |= input[KZero]<<KTwentyFour;
       
   822 		value |= input[KOne]<<KSixteen;
       
   823 		value |= input[KTwo]<<KEight;
       
   824 		value |= input[KThree];
       
   825 			
       
   826 		// sync bytes found
       
   827 		// for performance reasons check already that it is not data within an empty frame (all bits set)
       
   828 		// therefore check wether the bits for bitrate are all set -> means that this is no header
       
   829 		if ( (input[0] == 0xFF) && ( ( input[1] & 0xE0 ) == 0xE0 ) && ( ( input[2] & 0xF0 ) != 0xF0 ) )
       
   830 			{
       
   831 			//header is obtained
       
   832 			successheader = ETrue;
       
   833 			//version information is stored in 2 bits starting from 19th bit of header
       
   834 			//two get only 2bits we are doing an AND operation with 0b011 (0x03)
       
   835 			TInt index = (value >> 19) & 0x03;
       
   836 			//! Gets the version information of MPEG
       
   837 			
       
   838 			version = index; 	 //MPEG 2.5 	00
       
   839 										 //reservered   01
       
   840 										 //MPEG 2       10
       
   841 										 //MPEG 1       11
       
   842 			//if header information is 0x01							 
       
   843 			if( 0x01 == version ) //indicates that version is reserved and is considered 
       
   844 				{				  //as incorrect header information
       
   845 				//header is not valid							  
       
   846 				successheader = EFalse;
       
   847 				input++;
       
   848 				headerfound = EFalse;	
       
   849 				}
       
   850 				
       
   851 			index = ( value >> 6 ) & 0x0003;
       
   852 			channel = KChannelInfo[index]; //0 for mono and 1 for stereo	
       
   853 			
       
   854 			index = ( value >> 17 ) & 0x03;
       
   855 			if ( index == 0x01 )
       
   856 				layer = 2;
       
   857 				
       
   858 			if( successheader )	
       
   859 				{
       
   860 				//sampling rate is obtained by a combination of MPEG version and
       
   861 				//selection bits. There are 2 selection bits starting from 10th bit
       
   862 				//and is extracted (AND with 0x03) from header and stored in index 
       
   863 				index = (value >> 10) & 0x03;				
       
   864 				//! Gets the sampling frequency				
       
   865 				samplingrate = KMP3SamplingRate[version][index];
       
   866 				if( 0 == samplingrate ) //if sampling rate is 0 it is invalidated
       
   867 					{
       
   868 					//header is not valid
       
   869 					input++;	
       
   870 					}
       
   871 				else
       
   872 					{
       
   873 					//header is obtained
       
   874 					headerfound = ETrue;	
       
   875 					}	
       
   876 				}					
       
   877 			} // sync bytes found
       
   878 			else
       
   879 			{
       
   880 			//header is not valid
       
   881 			input++;	
       
   882 			}
       
   883 		}
       
   884 	//if sampling rate match with one we initially decoded we return ETrue else EFalse
       
   885 	// version change never possible
       
   886 	// layer change never possible
       
   887 	// sampling rate change never possible
       
   888 	// from mono to stereo never possible
       
   889 	if ( iAudioInfo.iSamplingRate == samplingrate && iAudioInfo.iVersion == version
       
   890 			&& iAudioInfo.iChannel == channel
       
   891 		 	&& iAudioInfo.iLayer == layer )
       
   892 		{
       
   893 		IRLOG_DEBUG( "CIRMP3Player::CrossCheckHeader - Exiting (1)." );
       
   894 		return ETrue;	
       
   895 		}		
       
   896 	else
       
   897 		{
       
   898 		IRLOG_DEBUG( "CIRMP3Player::CrossCheckHeader - Exiting (2).");
       
   899 		return EFalse;	
       
   900 		}		
       
   901 	}
       
   902 
       
   903 	
       
   904 									//Call back functions
       
   905 
       
   906 // ---------------------------------------------------------------------------
       
   907 // Function: MaoscBufferCopied
       
   908 // call back to be implemented for using CMdaAudioOutputStream
       
   909 // Call as callback from the CMdaAudioOutputStream::WriteL
       
   910 // after frame work has copied stream to a buffer
       
   911 // ---------------------------------------------------------------------------
       
   912 //
       
   913 void CIRMP3Player::MaoscBufferCopied(TInt aError, const TDesC8& /*aBuffer*/)
       
   914 	{
       
   915 	IRLOG_DEBUG( "CIRMP3Player::MaoscBufferCopied" );	
       
   916 	if( aError )
       
   917 		{
       
   918 		IRLOG_ERROR2( "CIRMP3Player::MaoscBufferCopied - Error in buffering (%d)", aError );
       
   919 		//error in playing then return
       
   920 		IRRDEBUG2("CIRMP3Player::MaoscBufferCopied - EError", KNullDesC);
       
   921 		iChannel->SentRequest( EError, KIRCtrlCmdGeneralPlayerError );
       
   922 		return;
       
   923 		}
       
   924 	else
       
   925 		{
       
   926        if ( iCurrentVolume < iConfig.iVolume )
       
   927             {
       
   928             iCurrentVolume = iConfig.iVolume;
       
   929             IRLOG_INFO2( "CIRMP3Player::MaoscBufferCopied - Setting volume to %d", iCurrentVolume );
       
   930             iAudioPlayer->SetVolume( iCurrentVolume );
       
   931             }
       
   932 		if( iSinkBufferQ.IsEmpty() )
       
   933 			{
       
   934 			//previously played buffer is empty
       
   935 			//should never happen
       
   936 		IRRDEBUG2("CIRMP3Player::MaoscBufferCopied - EError1", KNullDesC);
       
   937 			iChannel->SentRequest( EError, KIRCtrlCmdGeneralPlayerError );
       
   938 			return;	
       
   939 			}
       
   940 		else
       
   941 			{
       
   942 			//previously played buffer is removed	
       
   943 			iTempBufferHolder = iSinkBufferQ.First();
       
   944 			//played buffer is removed from sink queue		
       
   945 			iSinkBufferQ.Remove(*iTempBufferHolder);
       
   946 			//removed buffer is appended to end of source queue
       
   947 			iSourceBufferQ.AddLast(*iTempBufferHolder);
       
   948 			
       
   949 			//the first buffer of the source buffer is given to refill					
       
   950 			if( !iSourceBufferQ.IsEmpty() )
       
   951 				{
       
   952 				iTempBufferHolder = iSourceBufferQ.First();	
       
   953 				}			
       
   954 			//if stop is called during rebuffering
       
   955 			if( !iStopPlayerBuffering )
       
   956 				{
       
   957 				// if player is stopped it has to stop buffering
       
   958 				iTempbuffer = iTempBufferHolder->Des();
       
   959 				iInputBuffer.Set(iTempbuffer,iPlayBufferSize,iPlayBufferSize); 
       
   960 				iChannel->FilltheBuffer(iInputBuffer);	
       
   961 				}
       
   962 			//if stop state we have to return
       
   963 			if( iStopState )
       
   964 				{
       
   965 				IRLOG_DEBUG( "CIRMP3Player::MaoscBufferCopied - Exiting (1)." );	
       
   966 				//should continue this loop unless play is triggered
       
   967 				return;	
       
   968 				}
       
   969 						
       
   970 			//plays buffer if there buffer to play
       
   971 			if( !iSinkBufferQ.IsEmpty() )
       
   972 				{
       
   973 				//sink Buffer queue has buffer to play
       
   974 				iTempBufferHolder = iSinkBufferQ.First();
       
   975 				iTempbuffer = iTempBufferHolder->Des();
       
   976 							
       
   977 				iInput.Set(iTempbuffer,iPlayBufferSize,iPlayBufferSize);				
       
   978 
       
   979 #ifdef __WINS__
       
   980 				iTestingAudioPlayer->Write();
       
   981 #else				
       
   982 				//writing to MMF buffer
       
   983 				TRAPD(err,iAudioPlayer->WriteL(iInput));
       
   984 
       
   985 				if( err )
       
   986 					{
       
   987 			IRRDEBUG2("CIRMP3Player::MaoscBufferCopied - EError2", KNullDesC);
       
   988 					//if playing failed
       
   989 					iChannel->SentRequest( EError, KIRCtrlCmdGeneralPlayerError );
       
   990 					return;	
       
   991 					}
       
   992 #endif //__WINS__
       
   993 				}
       
   994 			else
       
   995 				{
       
   996 				//rebuffering
       
   997 				if( !iStopPlayerBuffering )
       
   998 					{
       
   999 					//if sink buffer is empty
       
  1000 					//we have to rebuffer
       
  1001 					iReBuffering = ETrue;
       
  1002 					Play();
       
  1003 					}								
       
  1004 				}
       
  1005 			}
       
  1006 		}
       
  1007 	IRLOG_DEBUG( "CIRMP3Player::MaoscBufferCopied - Exiting (2)." );	
       
  1008 	}
       
  1009 
       
  1010 // ---------------------------------------------------------------------------
       
  1011 // Function: MaoscPlayComplete
       
  1012 // call back to implement for using CMdaAudioOutputStream
       
  1013 // Call as callback from the CMdaAudioOutputStream::WriteL
       
  1014 // after play is completed
       
  1015 // ---------------------------------------------------------------------------
       
  1016 //
       
  1017 void CIRMP3Player::MaoscPlayComplete(TInt aError)
       
  1018 	{
       
  1019 	IRLOG_DEBUG( "CIRMP3Player::MaoscPlayComplete" );
       
  1020 	if( !iSkipPlayCompleted )
       
  1021 		{
       
  1022 	IRRDEBUG2("CIRMP3Player::MaoscPlayComplete EStoppedPlaying", KNullDesC); 
       
  1023 
       
  1024 		//sending the stop status
       
  1025 		iChannel->SentRequest( EStoppedPlaying, aError );	
       
  1026 		}
       
  1027 	IRLOG_DEBUG( "CIRMP3Player::MaoscPlayComplete - Exiting." );
       
  1028 	}
       
  1029 
       
  1030 // ---------------------------------------------------------------------------
       
  1031 // Function: MaoscOpenComplete
       
  1032 // call back implemented for using CMdaAudioOutputStream
       
  1033 // Call as callback from the CMdaAudioOutputStream::Open
       
  1034 // ---------------------------------------------------------------------------
       
  1035 //
       
  1036 void CIRMP3Player::MaoscOpenComplete( TInt aError )
       
  1037 	{	
       
  1038 	IRLOG_DEBUG( "CIRMP3Player::MaoscOpenComplete" );
       
  1039 	if( aError )
       
  1040 		{		
       
  1041 		IRLOG_ERROR( "CIRMP3Player::MaoscOpenComplete - error end" );
       
  1042 		IRRDEBUG2("CIRMP3Player::MaoscOpenComplete - EError", KNullDesC);
       
  1043 		//open failed
       
  1044 		iChannel->SentRequest( EError, KIRCtrlCmdGeneralPlayerError );
       
  1045 		return;	
       
  1046 		}
       
  1047 	else
       
  1048 		{
       
  1049 		TInt err( KErrNone );
       
  1050 		
       
  1051 #ifdef __WINS__
       
  1052 	      err=0;
       
  1053 #else
       
  1054 		//Setting the data type of player as MP3
       
  1055 		TRAP(err, iAudioPlayer->SetDataTypeL(iDataType.FourCC()));  //set type the data as MP3 type
       
  1056 	      
       
  1057 		if ( err )
       
  1058 			{
       
  1059 			if ( KErrNotSupported == err )
       
  1060 				{
       
  1061 			IRRDEBUG2("CIRMP3Player::MaoscOpenComplete - EError1", KNullDesC);
       
  1062 				iChannel->SentRequest( EError, KErrNotSupported );
       
  1063 				}
       
  1064 			else
       
  1065 				{
       
  1066 			IRRDEBUG2("CIRMP3Player::MaoscOpenComplete - EError2", KNullDesC);
       
  1067 				iChannel->SentRequest( EError, KIRCtrlCmdGeneralPlayerError );
       
  1068 				}
       
  1069 			return;
       
  1070 			}
       
  1071 #endif //__WINS__
       
  1072 		
       
  1073 		
       
  1074 		//during rebuffering current volume is to be taken	
       
  1075 		if( iNeedReBuffering )
       
  1076 			{
       
  1077 			iConfig.iVolume = iChannel->FetchVolume();	
       
  1078 			}			
       
  1079 		
       
  1080 		//Computes the current volume and sets the volume
       
  1081 		TInt index = iAudioPlayer->MaxVolume()/KNoVolumeLevels;	
       
  1082 		iConfig.iVolume = iConfig.iVolume * index;
       
  1083 		//if the given volume is greater than max volume it made to maximum volume
       
  1084 		//this may happen if the first time volume exceeds the limits
       
  1085 		if( iConfig.iVolume > iAudioPlayer->MaxVolume() )
       
  1086 			{
       
  1087 			iConfig.iVolume = iAudioPlayer->MaxVolume();	
       
  1088 			}			
       
  1089 		//else if the given volume is less than zero it made to zero 
       
  1090 		//this may happen if the first time volume goes below the limits
       
  1091 		if( iConfig.iVolume < KZeroVolume )
       
  1092 			{
       
  1093 			iConfig.iVolume = KZeroVolume;	
       
  1094 			}			
       
  1095 		
       
  1096 		// The actual setting of the volume is delayed to MaoscBufferCopied method.
       
  1097 		// This was due to some error in N91 sound subsystem, which caused the
       
  1098 		// volume not to adjust in some cases. 
       
  1099 	    iCurrentVolume = 0;
       
  1100         iAudioPlayer->SetVolume( iCurrentVolume );
       
  1101 		
       
  1102 		iFirstTime = ETrue;
       
  1103 		iNeedReBuffering = ETrue;
       
  1104 		
       
  1105 		if( !iNewPlayer )
       
  1106 			{
       
  1107 			//player is rebuffering or stop and played
       
  1108 			TRAP(err,ReCreateBufferL());
       
  1109 			if ( err )
       
  1110 				{
       
  1111 				IRRDEBUG2("CIRMP3Player::MaoscOpenComplete - EError3", KNullDesC);
       
  1112 				iChannel->SentRequest( EError, KIRCtrlCmdGeneralPlayerError );	
       
  1113 				return;
       
  1114 				}
       
  1115 			
       
  1116 			//initiates the refilling of buffers
       
  1117 			iTempBufferHolder = iSourceBufferQ.First();
       
  1118 			iTempbuffer = iTempBufferHolder->Des();
       
  1119 			iInputBuffer.Set(iTempbuffer,iPlayBufferSize,iPlayBufferSize);			
       
  1120 			iChannel->SentRequest( EBufferFillStart, iBufferPercentage );
       
  1121 			//Call FilltheBuffer for first time 
       
  1122 			iChannel->FilltheBuffer(iInputBuffer);	//start fill the data	
       
  1123 			}
       
  1124 		else
       
  1125 			{
       
  1126 			//First time playing
       
  1127 			BufferFilled();
       
  1128 			}
       
  1129 		}
       
  1130 	IRLOG_DEBUG( "CIRMP3Player::MaoscOpenComplete - Exiting." );
       
  1131 	}
       
  1132 	
       
  1133 // ---------------------------------------------------------------------------
       
  1134 // CIRMP3Player::GetMediaClientInstance()
       
  1135 // Returns the Audio Player Instance
       
  1136 // ---------------------------------------------------------------------------
       
  1137 //
       
  1138 CMdaAudioOutputStream* CIRMP3Player::GetAudioPlayer()
       
  1139 	{
       
  1140 	IRLOG_DEBUG( "CIRMP3Player::GetMediaClientInstance " );
       
  1141 	return iAudioPlayer;	
       
  1142 	}