mmfenh/advancedaudiocontroller/audiocontrollerpluginsvariant/AdvancedAudioController/Inc/AdvancedAudioUtility.h
changeset 0 71ca22bcf22a
equal deleted inserted replaced
-1:000000000000 0:71ca22bcf22a
       
     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:  This class provides utility functions such as parsing of header
       
    15 *				 information for VBR type clips.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #ifndef CADVANCEDAUDIOUTILITY_H
       
    21 #define CADVANCEDAUDIOUTILITY_H
       
    22 
       
    23 //  INCLUDES
       
    24 #include "AdvancedAudioHelper.h"        // for MAdvancedAudioDecoderUtilityObserver
       
    25 #include <e32base.h>
       
    26 #include <mmfdatabuffer.h>
       
    27 #include <f32file.h>
       
    28 
       
    29 // FORWARD DECARATION
       
    30 class CAdvancedAudioDecoder;
       
    31 class CMMFClip;
       
    32 // CLASS DECLARATION
       
    33 
       
    34 /**
       
    35 *  The TTimePos class is used to record the byte position and the corresponding
       
    36 *  time position in an audio clip and the length of the frame which starts
       
    37 *  from the byte position.
       
    38 *
       
    39 *  @lib AdvancedAudioController.lib
       
    40 *  @since 3.0
       
    41 */
       
    42 class TTimePos
       
    43     {
       
    44 	public:
       
    45 		TTimePos() : iTimePos(0), iBytePos(0), iFrameLen(0)
       
    46 			{}
       
    47 		TTimePos(TInt64 aTimePos, TInt aBytePos, TInt aFrameLen)
       
    48 			: iTimePos(aTimePos), iBytePos(aBytePos), iFrameLen((TInt16)aFrameLen)
       
    49 			{}
       
    50 	public:
       
    51 		TInt64 iTimePos;    // time position (microseconds)
       
    52 		TInt iBytePos;     // byte position
       
    53 		TInt16 iFrameLen;  // frame length
       
    54     };
       
    55 
       
    56 /**
       
    57 *  Frame info struct.
       
    58 *
       
    59 *  @lib AdvancedAudioController.lib
       
    60 *  @since 3.0
       
    61 */
       
    62 class TAudioFrameInfo
       
    63     {
       
    64 	public:
       
    65 		TInt iMode;            // encoding mode
       
    66 		TInt iBitRate;         // bitrate (bit/s)
       
    67 		TInt iSamplingRate;    // sampling frequency (Hz)
       
    68 		TInt iChannels;        // number of channels
       
    69 		TInt iFrameSize;       // encoded size (bytes)
       
    70 		TInt iFrameSamples;    // samples per frame
       
    71 		TInt iSamplingRateOut; // sampling frequency after conversion (Hz)
       
    72 		TInt iChannelsOut;     // number of audio channels after conversion (1 or 2)
       
    73 		TInt iFrameSamplesOut; // decoded size after conversion (samples per frame)
       
    74 		TInt iPadding;         // padding flag (TRUE or FALSE, TRUE if p slot exists)
       
    75 		TInt iId;              // id of algorithm (1 MPEG-1, 0 MPEG-2)
       
    76     };
       
    77     
       
    78 class MAdvancedAudioUtilityObserver
       
    79     {
       
    80     public:
       
    81 
       
    82         /**
       
    83         * Callback function from CAdvancedAudioUtility when bitrate changed situation occurs
       
    84         * @param   aFilledBuffer  data buffer filled with converted data
       
    85         * @return  void
       
    86         */
       
    87         virtual void BitRateChanged() = 0;
       
    88         virtual void SeekPositionReached(TUint aTimeMs) = 0;
       
    89 		virtual void PlayWindowEndPositionReached() = 0;
       
    90     };
       
    91 
       
    92 /**
       
    93 *  Utility class for Advanced Audio Controller Plugins.
       
    94 *
       
    95 *  @lib AdvancedAudioController.lib
       
    96 *  @since 3.0
       
    97 */
       
    98 class CAdvancedAudioUtility : public CBase,
       
    99                               public MAdvancedAudioDecoderUtilityObserver
       
   100     {
       
   101 	public:  // Constructors and destructor
       
   102 
       
   103 		/**
       
   104 		* Destructor.
       
   105 		*/
       
   106 		IMPORT_C virtual ~CAdvancedAudioUtility();
       
   107 
       
   108         /**
       
   109         * C++ default constructor.
       
   110         */
       
   111 		IMPORT_C CAdvancedAudioUtility();
       
   112 
       
   113     public: // New functions
       
   114 
       
   115 		/**
       
   116 		* Scans source buffer, frame by frame to update the frame count,
       
   117 		* byte count and duration.
       
   118 		* @param aClip the source clip, must be primed before calling this function
       
   119 		* @param aBuf buffer containing the header data
       
   120 		* @param aScanThisBufferOnly indication to scan only the contents in aBuf
       
   121 		* @return TInt bytes scannes
       
   122 		*/
       
   123 		IMPORT_C virtual TInt ScanFramesL(CMMFClip* aClip, CMMFDataBuffer* aBuf,
       
   124 			TBool aScanThisBufferOnly = EFalse, TInt aSourceReadPosition = 0);
       
   125 
       
   126 		/**
       
   127         * Scans header information
       
   128 		* @param aDataBuf
       
   129 		* @return void
       
   130 		*/
       
   131 		IMPORT_C virtual void ScanHeaderL(CMMFDataBuffer* aDataBuf);
       
   132 
       
   133 		/**
       
   134 		* Scans source buffer, frame by frame to update the frame count,
       
   135 		* byte count and duration.
       
   136 		* @param aBuf buffer containing the header data
       
   137 		* @param aScanThisBufferOnly indication to scan only the contents in aBuf
       
   138 		* @return TInt bytes scannes
       
   139 		*/
       
   140 		IMPORT_C virtual TInt ScanFramesL(CMMFDataBuffer* aBuf,
       
   141 			TBool aScanThisBufferOnly = EFalse, TInt aSourceReadPosition = 0);
       
   142 
       
   143 		/**
       
   144 		* Finds the byte position of the frame at given time position.
       
   145 		* NOTE: This routine works accurately for time positions smaller than
       
   146 		* 2^32 microseconds (~71min 34seconds) only, since the time stamps
       
   147 		* use 32 bit unsigned integers. If the given time position is greater
       
   148 		* than this, then this routine returns the position of the frame at
       
   149 		* 2^32 microseconds.
       
   150 		* @param aTimePos time position to find (microseconds)
       
   151 		* @param aClip pointer to data clip
       
   152 		* @return position of the frame header; KErrNotFound if not found
       
   153 		*/
       
   154 		IMPORT_C virtual TInt FindFramePos(const TInt64& aTimePos, CMMFClip* aClip = NULL);
       
   155 
       
   156 		/**
       
   157 		* Returns the byte position of the first frame.
       
   158 		* @param aBuf Pointer to the data
       
   159 		* @param aBufLen Length of the data
       
   160 		* @return byte position of the first frame
       
   161 		*/
       
   162 		IMPORT_C virtual TInt SeekSync(CMMFDataBuffer* aBuf, TInt aBufLen) = 0;
       
   163 
       
   164 		/**
       
   165 		* Returns frame info.
       
   166 		* @param aBuf Pointer to the data
       
   167 		* @param aBufLen Length of the data
       
   168 		* @param aInfo Contains the frame info on return
       
   169 		* @return frame length
       
   170 		*/
       
   171 		IMPORT_C virtual TInt FrameInfo(const TUint8* aBuf, TInt aBufLen, TAudioFrameInfo& aInfo);
       
   172 
       
   173 		/**
       
   174 		* Returns the sample rate.
       
   175 		* @param none
       
   176 		* @return sample rate
       
   177 		*/
       
   178 		IMPORT_C TInt SampleRate();
       
   179 
       
   180 		/**
       
   181 		* Returns the bit rate in bits/sec.
       
   182 		* @param none
       
   183 		* @return bit rate
       
   184 		*/
       
   185 		IMPORT_C virtual TInt BitRate();
       
   186 
       
   187 		/**
       
   188 		* Returns the number of channels.
       
   189 		* @param none
       
   190 		* @return number of channels
       
   191 		*/
       
   192 		IMPORT_C TInt Channels();
       
   193 
       
   194 		/**
       
   195 		* Returns the number of channels out of decoder.
       
   196 		* @param none
       
   197 		* @return number of channels
       
   198 		*/
       
   199 		IMPORT_C TInt ChannelsOut();
       
   200 
       
   201 		/**
       
   202 		* Returns the scanned duration.
       
   203 		* @param none
       
   204 		* @return scanned duration
       
   205 		*/
       
   206 		IMPORT_C TInt64 ScanDuration();
       
   207 
       
   208 		/**
       
   209 		* Returns the duration.
       
   210 		* @param none
       
   211 		* @return duration
       
   212 		*/
       
   213 		IMPORT_C virtual TInt64 Duration();
       
   214 
       
   215 		/**
       
   216 		* Returns the header offset.
       
   217 		* @param none
       
   218 		* @return header offset
       
   219 		*/
       
   220 		IMPORT_C TInt HeaderOffset();
       
   221 
       
   222 		/**
       
   223 		* Returns the Sync offset e.g. ID3 header length
       
   224 		*
       
   225 		* @return  TInt
       
   226 		*/
       
   227 		IMPORT_C TInt SyncOffset();
       
   228 		
       
   229 		/**
       
   230 		* Sets the codec config sample rate.
       
   231 		* @param aCodecConfig codec's configuration data
       
   232 		* @return void
       
   233 		*/
       
   234 		IMPORT_C virtual void SetCodecConfigData(RArray<TInt>& aCodecConfig);
       
   235 		
       
   236         /**
       
   237 		* Set the Observer for Callback
       
   238 		* @param CAdvancedAudioPlayController& reference to MAdvancedAudioUtilityObserver object for callback
       
   239 		* @return void
       
   240 		*/
       
   241 		IMPORT_C void SetObserver(MAdvancedAudioUtilityObserver& aObserver);
       
   242 		
       
   243 		/**
       
   244 		* Set the Decoder Object
       
   245         * @param none
       
   246 		* @return void
       
   247 		*/
       
   248 		IMPORT_C void SetDecoder(CAdvancedAudioDecoder& aDecoder);
       
   249 		
       
   250 		/**
       
   251 		* De-reference decoder object from SetDecoderL, should always be called for safety before CAdvancedAudioOutput is deleted
       
   252         * @param none
       
   253 		* @return void
       
   254 		*/
       
   255 		IMPORT_C void DeReferenceDecoder();
       
   256 
       
   257 		/**
       
   258 		* Returns frame header size.
       
   259 		* @param none
       
   260 		* @return frame header size
       
   261 		*/
       
   262 		IMPORT_C virtual TInt FrameHeaderSize();
       
   263 
       
   264         /**
       
   265         * Gets the drive number from drivename
       
   266         * @since 3.0
       
   267         * @param aDriveName
       
   268         * @return TDriveNumber
       
   269         */
       
   270         IMPORT_C TDriveNumber GetDriveNumber(const TDesC& aDriveName);
       
   271 
       
   272         /**
       
   273 		* Set/Update the iClipSize varilable
       
   274 		* @param TUint the new ClipSize
       
   275 		* @return void
       
   276 		*/
       
   277 		IMPORT_C virtual void SetClipSizeL(TUint aSize);
       
   278 		
       
   279         /**
       
   280 		* Enable bitrate change callback, would trigger a BitRateChanged callback when bitrate changes occurs
       
   281 		* @param TInt interval in Milliseconds of callback to happen, 0 means callback on any changes, -1 means no callback
       
   282 		* @return void
       
   283 		*/
       
   284 		IMPORT_C virtual void EnableBitRateChangedEventL(TInt aIntervalInMilliSeconds = -1);
       
   285 		
       
   286         /**
       
   287         * Sets the Source Position based on Time
       
   288         * @since 3.0
       
   289         * @param aTime
       
   290         * @param aPos
       
   291         * @return TDriveNumber
       
   292         */
       
   293         IMPORT_C virtual TInt SetSourceReference(TUint aTimeMs, TUint aPos);
       
   294         
       
   295         /**
       
   296         * Find the closest Frame's position from a given time (millisec) in frametable
       
   297         * added to support AAC optimization
       
   298         * @since 3.2
       
   299         * @param aTimeMs    Time to search from in millisec
       
   300         * @param aPos       Bytes Position found in frametable if return is KErrNone
       
   301         * return TInt       standard system error
       
   302         */
       
   303 		IMPORT_C virtual TInt FindFramePosFromTime(TUint& aTimeMs, TUint& aPos);
       
   304 		
       
   305 		IMPORT_C virtual TInt FindFrameTimeFromPos(TUint& aTimeMs, TUint& aPos);
       
   306 		
       
   307 		/**
       
   308         * Find the last record Frame's position in frametable
       
   309         * added to support AAC optimization
       
   310         * @since 3.2
       
   311         * @param aPos       Bytes Position found in frametable if return is KErrNone
       
   312         * return TInt       standard system error
       
   313         */
       
   314 		IMPORT_C virtual TInt LastFramePos(TUint& aPos);
       
   315 		
       
   316 		/*
       
   317         * Find the last Frame's position relative time (millisec) in frametable
       
   318         * added to support AAC optimization
       
   319         * @since 3.2
       
   320         * @param aTimeMs    Time of the last Frame in millisec if return is KErrNone
       
   321         * return TInt       standard system error
       
   322         */
       
   323 		IMPORT_C virtual TInt LastFrameTime(TUint& aTimeMs);
       
   324 		
       
   325 		/*
       
   326         * Reset the frame table
       
   327         * added to support AAC optimization
       
   328         * @since 3.2
       
   329         * return TInt       standard system error
       
   330         */
       
   331 		IMPORT_C virtual TInt ResetTable();
       
   332 		
       
   333 		/**
       
   334         * Cause FrameTable to generate an event when the desire Position is recorded in FrameTable
       
   335         * added to support AAC optimization
       
   336         * @since 3.2
       
   337         * @param aTimeMs    Time to be Seek to when callback occurs in millisec
       
   338         * return TInt       standard system error
       
   339         */
       
   340 		IMPORT_C virtual TInt SeekToTimeMs(TUint aTimeMs);
       
   341 		IMPORT_C virtual TInt SetPlayWindowEndTimeMs(TUint aTimeMs);
       
   342 
       
   343 	protected:      // new functions
       
   344 
       
   345 		/**
       
   346 		* Records the timestamp into iPosArr.
       
   347 		* @param aFrameLength frame length of the next frame in clip
       
   348 		* @return void
       
   349 		*/
       
   350 		IMPORT_C virtual void RecordTimeStampL(TInt aFrameLength);
       
   351 
       
   352 		/**
       
   353 		* Finds the length of the ID3 header
       
   354 		* @param aBuf
       
   355 		* @return TInt
       
   356 		*/
       
   357         IMPORT_C TInt ID3HeaderLength(const CMMFDataBuffer* aBuf);
       
   358 
       
   359 		/**
       
   360 		* Creates a buffer
       
   361 		* @param aSize
       
   362 		* @return Pointer to the buffer
       
   363 		*/
       
   364         IMPORT_C CMMFDataBuffer* CreateBufferOfSizeLC(TUint aSize);
       
   365         
       
   366     public:         // from MAdvancedAudioDecoderUtilityObserver
       
   367 		IMPORT_C virtual void DecodeIntervalEvent();
       
   368         IMPORT_C virtual void SeekPositionReached(TUint aTimeMs);
       
   369 		IMPORT_C virtual TInt GetOffsets(TInt& aOffsets);
       
   370 		IMPORT_C virtual void PlayWindowEndPositionReached();
       
   371 
       
   372 	protected:      // Data
       
   373 
       
   374 		// Frame byte position, time position, and length
       
   375 		CArrayFixSeg<TTimePos>* iPosArr;
       
   376 		// Sampling rate found in header
       
   377 		TInt iSamplingRate;
       
   378 		// Bit rate (bps) found in header
       
   379 		TInt iBitRate;
       
   380 		// Number of channels found in header
       
   381 		TInt iChannels;
       
   382 		// Number of channels after decoding
       
   383 		TInt iChannelsOut;
       
   384 		// Samples per frame
       
   385 		TInt iSamplesPerFrame;
       
   386 		// Scanned Duration of the clip
       
   387 		TInt64 iScanDuration;
       
   388 		// Duration of the clip
       
   389 		TInt64 iDurationUs;
       
   390 		// Bytes scanned
       
   391 		TInt iScanByteCount;
       
   392 		// Bytes since last frame
       
   393 		TInt iScanInvByteCount;
       
   394 		// Saved length
       
   395 		TInt iSavedLength;
       
   396 		
       
   397 		// clip size
       
   398 		TUint iClipSize;
       
   399 		
       
   400 		// Header offset position
       
   401 		TInt iHeaderOffset;
       
   402 		// Header 2 offset position
       
   403         TInt iSyncOffset;
       
   404         // Indicates the header is read - is to be used to process buffers for calculating bitrate without corrupting the offset calculations
       
   405         TBool iHdrIsRead;
       
   406 		// For Average Bitrate Calculation
       
   407 		TInt 	iNumFrames;
       
   408 		TInt64 	iSumBitRate;
       
   409 		
       
   410 		// Length of MetaData found in file
       
   411 		TInt iLenMetaData;
       
   412 		
       
   413 		MAdvancedAudioUtilityObserver* iObserver;   // new for Streaming/PDL, call back to controller when average bitrate changes
       
   414 		TInt iFrameTimeMs;                          // remember how many millisec per frame contains
       
   415 		TUint iReferenceBitRate;                    // new for Streaming/PDL, remember the last return/callback bitrate
       
   416         TBool iScannedOnce;                         // new for Streaming/PDL, remember whether the first frame has already been scanned
       
   417         
       
   418         CAdvancedAudioDecoder* iDecoder;            // pointer to decoder object own the play controller, does not have ownership
       
   419         TBool iBitRateFrozen;
       
   420         TInt iTotalFrameBytes;
       
   421         TInt iTotalFrames;
       
   422     };
       
   423 
       
   424 #endif 		// CADVANCEDAUDIOUTILITY_H