internetradio2.0/mediaengineinc/iraacplayer.h
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 #ifndef IRAACPLAYER_H
       
    20 #define IRAACPLAYER_H
       
    21 
       
    22 #include <audio.h>
       
    23 #include <mdaaudiooutputstream.h>
       
    24 
       
    25 #include "ircontrolparams.h"
       
    26 #include "irmediaenginedef.h"
       
    27 #include "irmediaengineinterface.h"
       
    28 
       
    29 class CIRBufferContainer;
       
    30 
       
    31 //========================================class declaration CIRAACPlayer============================================
       
    32 
       
    33 /**
       
    34  * This class is the implementation of AAC/AAC+ format.This forms a part of
       
    35  * media engine which is implemented as an ECom plugin. The interface class
       
    36  * is irmediaengineinterface.h  The mime type of mp3 is used to load this
       
    37  * plugin mimetype : audio/aac or audio/accp This is to be passed as the   
       
    38  * default data while creation of player
       
    39  * 
       
    40  * @code
       
    41  *
       
    42  * //mimetype is buffer with audio/aac or audio/aacp as data
       
    43  * iPlayer = CIRMediaEngineInterface::NewL(mimetype);
       
    44  *
       
    45  * TConfig config;
       
    46  * config.iVolume = xxxxxx; //some integer value between 0 and Maximum Volume
       
    47  * TUint8* buffer; //is a buffer of size [KINPUT_BUFFER_SIZE] as defined in  IRMediaEngineBuffer.h
       
    48  *                 //this is should have filled buffer when you call Intialize
       
    49  * CIRCtrlCmdObserver* aChannel; //command channel dll's instant
       
    50  * TInt volume;
       
    51  * iPlayer->Intialize(config,buffer,channel);
       
    52  * iPlayer->Play();//to play
       
    53  * iPlayer->Stop();//to stop
       
    54  * iPlayer->SetVolume(volume);//set the volume
       
    55  * iPlayer->Volume;// returns current volume
       
    56  * iPlayer->MaxVolume();//return maximum volume
       
    57  * iPlayer->StopPlayerBuffering();//stop buffering if required
       
    58  * iPlayer->StartPlayerBuffering();//start buffering (incase if stop you can restart with this method)
       
    59  * iPlayer->BufferFilled(); //should be called when the buffer given by player is return
       
    60  *                     //this will mark the buffer as filled
       
    61  *
       
    62  * @endcode
       
    63  *
       
    64  */
       
    65 
       
    66 NONSHARABLE_CLASS(CIRAACPlayer) : public CIRMediaEngineInterface,
       
    67 	public MMdaAudioOutputStreamCallback
       
    68 	{
       
    69 public:
       
    70 									//Member Functions
       
    71 	/**
       
    72 	 * Function : NewL
       
    73 	 * function to return an instance of CIRAACPlayer
       
    74 	 * Two phase constructor
       
    75 	 * @return instance of CIRAACPlayer
       
    76 	 */
       
    77 	static CIRAACPlayer* NewL();
       
    78 
       
    79 	/**
       
    80 	 * Function : NewLC
       
    81 	 * function to creates an instance of CIRAACPlayer
       
    82 	 * Two phase constructor
       
    83 	 * @return instance of CIRAACPlayer
       
    84 	 */
       
    85 	static CIRAACPlayer* NewLC();	
       
    86 
       
    87 	/**
       
    88 	 * Function : ~CIRAACPlayer
       
    89 	 * Default Destructor
       
    90 	 */
       
    91 	~CIRAACPlayer();
       
    92 
       
    93 										//Function which control the play
       
    94 
       
    95 	/**
       
    96 	 * Function : Play
       
    97 	 * function to which intiates the playing
       
    98 	 */
       
    99 	void Play();
       
   100 	
       
   101 	/**
       
   102 	 * Function : Stop
       
   103 	 * function to stop the player
       
   104 	 */
       
   105 	void Stop();   	     
       
   106 
       
   107 										 //Function to control the volume
       
   108 	       
       
   109 	/**
       
   110 	 * Function : SetVolume
       
   111 	 * function to set the volume, integer level of volume is the input
       
   112 	 * @param integer level of volume is the input
       
   113 	 */			
       
   114 	void SetVolume(TInt aVolume);
       
   115 			
       
   116 	/**
       
   117 	 * Function : MaxVolume
       
   118 	 * function to returns the maximum volume , integer value is the Output
       
   119 	 * @return integer value is the Output
       
   120 	 */		
       
   121 	TInt MaxVolume() const;
       
   122 	
       
   123 	/**
       
   124 	 * Function : Volume
       
   125 	 * function to returns the volume, integer level of voume is the Output
       
   126 	 * @return integer value is the Output
       
   127 	 */		
       
   128 	TInt Volume() const;
       
   129 	
       
   130 	/**
       
   131 	 * Function: Intialize
       
   132 	 * Set the codec type and sampling rate channel of stream
       
   133 	 * This is set to initial settings which is required to start the player
       
   134 	 * @param configuration infomation
       
   135 	 * @param instance of data buffer, whose size is defined in IRMediaEngineBuffer.h
       
   136 	 * @param instance of the channel through with information is sent to UI
       
   137 	 */			
       
   138 	void Intialize(TConfig& aConfig,TUint8* aInitParams,
       
   139 		CIRCtrlCmdObserver* aChannel);			
       
   140 	
       
   141 	/**
       
   142 	 * Function: StopPlayerBuffering
       
   143 	 * Function is used to freeze bufferring 
       
   144 	 */
       
   145 	void StopPlayerBuffering();
       
   146 	
       
   147 	/**
       
   148 	 * Function: BufferFilled
       
   149 	 * Function which is called when network gets the buffer filled with data
       
   150 	 */
       
   151   	void BufferFilled();
       
   152   	
       
   153   	/**
       
   154 	 * Function: GetAudioPlayer
       
   155 	 * Function which is called To return the Current Audio Player
       
   156 	*/
       
   157 	CMdaAudioOutputStream* GetAudioPlayer();
       
   158 
       
   159 private:	
       
   160 	/**
       
   161 	 * Function: CIRAACPlayer
       
   162 	 * This function is the default constructor
       
   163 	 */
       
   164 	CIRAACPlayer();
       
   165 
       
   166 	/**
       
   167 	 * Function: ConstructL
       
   168 	 * Two phase constructor is used to intialize data members
       
   169 	 */
       
   170 	void ConstructL();	
       
   171 
       
   172 	/**	
       
   173 	 * Function: CreatebufferL 
       
   174 	 * Create the buffers and allocates address for each buffers
       
   175 	 * keeps them in buffer queue
       
   176 	 */       
       
   177 	void CreateBufferL();
       
   178 	
       
   179 	/**
       
   180 	 * Function: ReCreateBufferL
       
   181 	 * Function is used to recreate the buffer
       
   182 	 */	
       
   183 	void ReCreateBufferL();
       
   184 
       
   185 										//Call back functions from MMdaAudioOutputStreamCallback
       
   186 	
       
   187 	/**
       
   188 	 * Function: MaoscBufferCopied
       
   189 	 * call back to implement for using CMdaAudioOutputStream
       
   190 	 * Call as callback from the CMdaAudioOutputStream::WriteL
       
   191 	 * after frame work copies the stream to buffer
       
   192 	 * @param Error
       
   193 	 * @param reference to buffer
       
   194 	 */		
       
   195 	void MaoscBufferCopied(TInt aError, const TDesC8 &aBuffer);
       
   196 		
       
   197 	/**
       
   198 	 * Function: MaoscPlayComplete
       
   199 	 * call back to implement for using CMdaAudioOutputStream
       
   200 	 * Call as callback from the CMdaAudioOutputStream::WriteL
       
   201 	 * after play is completed
       
   202 	 * @param aError
       
   203 	 */	    
       
   204 	void MaoscPlayComplete(TInt aError);
       
   205 	
       
   206 	/**
       
   207 	 * Function: MaoscOpenComplete
       
   208 	 * call back to implement for using CMdaAudioOutputStream
       
   209 	 * Call as callback from the CMdaAudioOutputStream::Open
       
   210 	 * @param aError
       
   211 	 */	    
       
   212 	void MaoscOpenComplete(TInt aError);				
       
   213 		
       
   214 	/**
       
   215 	 * Function: GetAACAudioProperties
       
   216 	 * extract all the information to start the play from the stream
       
   217 	 */
       
   218 	void GetAACAudioProperties();
       
   219 	
       
   220 	/**
       
   221 	 * Function: DoFindnDecodeAACHeader
       
   222 	 * Function return a non modifiable pointer descriptor of data buffer
       
   223 	 */
       
   224 	void DoFindnDecodeAACHeaderL();
       
   225 	
       
   226 	/**
       
   227 	 * Function: ReArrangeBuffer
       
   228 	 * Function rearranges the buffer, and should be called after finding the header
       
   229 	 * from the address of buffers specified, the data buffers are kept in sink queue and 
       
   230 	 * remaining buffers are discarded that is put into source queue.
       
   231 	 * 
       
   232 	 * @param address of starting of header
       
   233 	 */	
       
   234 	void ReArrangeBufferL(TUint8* aInput);
       
   235 
       
   236 
       
   237 										        //data members
       
   238 										        
       
   239 private:	
       
   240 	//Enum for Play State
       
   241 	enum TState
       
   242 		{
       
   243 		ENotReady,    //Not ready to play
       
   244 		EReadyToPlay, //Ready to play
       
   245 		EPlaying      //Playing
       
   246 		};
       
   247 
       
   248 	// Player state	
       
   249 	TState iState; 		
       
   250 
       
   251 	//For implement Player functionalities	
       
   252 	
       
   253 	//player utility 
       
   254 	CMdaAudioOutputStream* iAudioPlayer;
       
   255 	
       
   256 	//Temporary holder for buffer container
       
   257 	CIRBufferContainer* iTempBufferHolder;
       
   258 	
       
   259 	//Holds the address of data buffer which is to be played
       
   260 	TUint8* iTempbuffer;				
       
   261 
       
   262 	//This represents a large input buffer which takes the input
       
   263 	TUint8* iInputBufferPtr;
       
   264 	
       
   265 	//Instance of channel through with data is sent UI
       
   266 	CIRCtrlCmdObserver* iChannel;
       
   267 		
       
   268 	//Setting for sampling rate, channel
       
   269 	TMdaAudioDataSettings iSettings;  
       
   270 				
       
   271 	//FourCC representation of the codec
       
   272 	TFourCC iDataType;				
       
   273 
       
   274 	//hold the configuration information
       
   275 	TConfig iConfig;  				
       
   276 				
       
   277 	//Hold the pointer to the buffer to be filled
       
   278 	TPtr8 iInputBuffer;				 
       
   279 
       
   280 	//Contains Data to be played
       
   281 	TPtr8 iInput;
       
   282 		
       
   283 	//Queue of buffer which is filled
       
   284 	TSglQue<CIRBufferContainer> iSourceBufferQ;
       
   285 		
       
   286 	//Queue of buffer which is empty
       
   287 	TSglQue<CIRBufferContainer> iSinkBufferQ;
       
   288 	
       
   289 	//Holds the audio format data
       
   290 	TAudioFormatData iAudioInfo;
       
   291 	
       
   292 	//Holds the percentage of data in the buffer
       
   293 	TInt iBufferPercentage;
       
   294 	
       
   295 	// For First time play
       
   296 	TBool iFirstTime;
       
   297 	
       
   298 	//checks whether header is found or not
       
   299 	TBool iHeaderFound;
       
   300 	
       
   301 	//this bool indicates buffering is taking place initially or rebuffering
       
   302 	//mainly to intial parameter like volume during rebuffering
       
   303 	TBool iNeedReBuffering;
       
   304 	
       
   305 	//Indicates that it is a new player
       
   306 	TBool iNewPlayer;
       
   307 	
       
   308 	//This is used to StopPlayerBuffering
       
   309 	TBool iStopPlayerBuffering;	
       
   310 	
       
   311 	//This is used to stop buffering if its rebuffering, set if stop function is called
       
   312 	//and  reset when play function is called
       
   313 	TBool iStopState;
       
   314 	
       
   315 	//skips sending the error code during stop if stop internally 
       
   316 	//is during play called
       
   317 	TBool iSkipPlayCompleted;	
       
   318 	};  
       
   319 
       
   320 #endif //IRAACPLAYER_H