mmlibs/mmfw/src/Client/Audio/mmfclientaudioconverter.cpp
changeset 0 40261b775718
equal deleted inserted replaced
-1:000000000000 0:40261b775718
       
     1 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <e32std.h>
       
    17 #include <mmf/common/mmffourcc.h>
       
    18 #include <mmf/common/mmfpaniccodes.h>
       
    19 #include <mmfformatimplementationuids.hrh>
       
    20 
       
    21 #include "mmfclientaudioconverter.h"
       
    22 
       
    23 // declared in the recorder module
       
    24 void Panic(TInt aPanicCode);
       
    25 
       
    26 //CMdaAudioConvertUtility
       
    27 
       
    28 
       
    29 /**
       
    30 Returns the current utility state.
       
    31 
       
    32 @return The state of the audio sample data. See CMdaAudioClipUtility::TState.
       
    33 
       
    34 @since  5.0
       
    35 */
       
    36 CMdaAudioClipUtility::TState CMdaAudioConvertUtility::State()
       
    37 	{
       
    38 	ASSERT(iProperties);
       
    39 	return iProperties->State();
       
    40 	}
       
    41 
       
    42 /**
       
    43 Closes the current audio clip.
       
    44 
       
    45 @since  5.0
       
    46 */
       
    47 void CMdaAudioConvertUtility::Close()
       
    48 	{
       
    49 	ASSERT(iProperties);
       
    50 	iProperties->Close();
       
    51 	}
       
    52 
       
    53 /**
       
    54 This function is mapped to ConvertL(). ConvertL() should be used instead.
       
    55 
       
    56 @see ConvertL()
       
    57 
       
    58 @since  5.0
       
    59 */
       
    60 void CMdaAudioConvertUtility::PlayL()
       
    61 	{
       
    62 	ASSERT(iProperties);
       
    63 	iProperties->PlayL();
       
    64 	}
       
    65 
       
    66 /**
       
    67 This function is mapped to ConvertL. ConvertL() should be used instead.
       
    68 
       
    69 @since  5.0
       
    70 */
       
    71 void CMdaAudioConvertUtility::RecordL()
       
    72 	{
       
    73 	ASSERT(iProperties);
       
    74 	iProperties->RecordL();
       
    75 	}
       
    76 
       
    77 /**
       
    78 Stops the current operation (playback/recording/conversion).
       
    79 
       
    80 When conversion has been stopped, successfully or otherwise, the client is notified by 
       
    81 MMdaObjectStateChangeObserver::MoscoStateChangeEvent(). The callback is initiated by this function 
       
    82 providing it with state change information and error codes.
       
    83 
       
    84 @since  5.0
       
    85 */
       
    86 void CMdaAudioConvertUtility::Stop()
       
    87 	{
       
    88 	ASSERT(iProperties);
       
    89 	iProperties->Stop();
       
    90 	}
       
    91 
       
    92 /**
       
    93 Crops the current clip from the current position. The remainder of the clip is discarded.
       
    94 
       
    95 The effects of the function cannot be undone. The function is synchronous and can leave if there is 
       
    96 a problem. The leave code depends on the configuration.
       
    97 
       
    98 @since  5.0
       
    99 */
       
   100 void CMdaAudioConvertUtility::CropL()
       
   101 	{
       
   102 	ASSERT(iProperties);
       
   103 	iProperties->CropL(ETrue);
       
   104 	}
       
   105 
       
   106 /**
       
   107 Sets the current position in the audio clip.
       
   108 
       
   109 A subsequent call to ConvertL() starts conversion from this new position.
       
   110 
       
   111 @param  aPosition
       
   112         The position in the audio clip, in microseconds.
       
   113 
       
   114 @since  5.0
       
   115 */
       
   116 void CMdaAudioConvertUtility::SetPosition(const TTimeIntervalMicroSeconds& aPosition)
       
   117 	{
       
   118 	ASSERT(iProperties);
       
   119 	iProperties->SetPosition(aPosition);
       
   120 	}
       
   121 
       
   122 /**
       
   123 Returns the current position in the audio clip. The position is defined in terms of a time interval
       
   124 measured from the beginning of the audio sample data.
       
   125 
       
   126 @return The current position in the audio clip, in microseconds.
       
   127 
       
   128 @since  5.0
       
   129 */
       
   130 const TTimeIntervalMicroSeconds& CMdaAudioConvertUtility::Position()
       
   131 	{
       
   132 	ASSERT(iProperties);
       
   133 	return iProperties->Position();
       
   134 	}
       
   135 
       
   136 /**
       
   137 Returns the amount of recording time available to the current clip.
       
   138 
       
   139 @return The recording time available measured in microseconds.
       
   140 
       
   141 @since  5.0
       
   142 */
       
   143 const TTimeIntervalMicroSeconds& CMdaAudioConvertUtility::RecordTimeAvailable()
       
   144 	{
       
   145 	ASSERT(iProperties);
       
   146 	return iProperties->RecordTimeAvailable();
       
   147 	}
       
   148 
       
   149 /**
       
   150 Returns the duration of the audio clip.
       
   151 
       
   152 @return The duration in microseconds.
       
   153 
       
   154 @since  5.0
       
   155 */
       
   156 const TTimeIntervalMicroSeconds& CMdaAudioConvertUtility::Duration()
       
   157 	{
       
   158 	ASSERT(iProperties);
       
   159 	return iProperties->Duration();
       
   160 	}
       
   161 
       
   162 /**
       
   163 Sets a window for playback.
       
   164 
       
   165 The window is defined in terms of a start and end time. A subsequent call to ConvertL() results 
       
   166 in just the data within the window being converted.
       
   167 
       
   168 @param  aStart
       
   169         The position in the clip to start playback, in microseconds. This must be any value from zero
       
   170         to aEnd. If this value is less than zero or greater than aEnd, this function raises 
       
   171         EMMFMediaClientPanicServerCommunicationProblem panic in debug version.
       
   172 @param  aEnd
       
   173         The position in the clip to end playback, in microseconds. This must be any value from aStart 
       
   174         to the value returned by Duration(). If this value is greater than the value returned by 
       
   175         Duration() or less than aStart, this function raises EMMFMediaClientPanicServerCommunicationProblem panic in debug version.
       
   176 
       
   177 @since  5.0
       
   178 */
       
   179 void CMdaAudioConvertUtility::SetPlayWindow(const TTimeIntervalMicroSeconds& aStart, const TTimeIntervalMicroSeconds& aEnd)
       
   180 	{
       
   181 	ASSERT(iProperties);
       
   182 	iProperties->SetPlayWindow(aStart, aEnd);
       
   183 	}
       
   184 
       
   185 /**
       
   186 Clears the playback window. 
       
   187 
       
   188 Playback returns to playing the entire clip. A subsequent call to ConvertL() results in the entire 
       
   189 source audio being converted.
       
   190 
       
   191 @since  5.0
       
   192 */
       
   193 void CMdaAudioConvertUtility::ClearPlayWindow()
       
   194 	{
       
   195 	ASSERT(iProperties);
       
   196 	iProperties->ClearPlayWindow();
       
   197 	}
       
   198 
       
   199 /**
       
   200 Sets the number of repetitions for playback. This is unsupported for CMdaConvertUtility as there is
       
   201 no playback facility. It is provided only for binary compatibility.
       
   202 
       
   203 @param  aRepeatNumberOfTimes
       
   204         The number of times to repeat the audio clip, after the first playback. If this is set to 
       
   205         KMdaRepeatForever, then the audio sample, together with the trailing silence, is repeated 
       
   206         indefinitely. If this is set to zero, then the audio sample is not repeated.
       
   207 @param  aTrailingSilence
       
   208         A delay to wait before each repetition.
       
   209 
       
   210 @since  5.0
       
   211 */
       
   212 void CMdaAudioConvertUtility::SetRepeats(TInt aRepeatNumberOfTimes, const TTimeIntervalMicroSeconds& aTrailingSilence)
       
   213 	{
       
   214 	ASSERT(iProperties);
       
   215 	iProperties->SetRepeats(aRepeatNumberOfTimes, aTrailingSilence);
       
   216 	}
       
   217 
       
   218 /**
       
   219 Sets the maximum size of an audio clip.
       
   220 
       
   221 This function is provided so that applications such as recorders and converters can limit the amount 
       
   222 of file storage/memory that should be allocated.
       
   223 
       
   224 @param  aMaxWriteLength
       
   225         The maximum size of the audio clip, in bytes. If the default value is used, there is no 
       
   226         maximum file size.
       
   227 
       
   228 @since 7.0
       
   229 */
       
   230 void CMdaAudioConvertUtility::SetMaxWriteLength(TInt aMaxWriteLength /* = KMdaClipLocationMaxWriteLengthNone*/)
       
   231 	{
       
   232 	ASSERT(iProperties);
       
   233 	iProperties->SetMaxWriteLength(aMaxWriteLength);
       
   234 	}
       
   235 
       
   236 /**
       
   237 Crops the audio clip from the start of the file to the current position. The audio data
       
   238 prior to the current position is discarded.
       
   239 
       
   240 The effects of the function cannot be undone.
       
   241 
       
   242 The function is synchronous and can leave if there is a problem. The leave code depends on the
       
   243 configuration.
       
   244 
       
   245 @since 7.0s
       
   246 */
       
   247 void CMdaAudioConvertUtility::CropFromBeginningL()
       
   248 	{
       
   249 	ASSERT(iProperties);
       
   250 	iProperties->CropL(EFalse);
       
   251 	}
       
   252 
       
   253 /**
       
   254 Constructs and initialises a new instance of the audio converter for converting audio sample data 
       
   255 from one format to another.
       
   256 
       
   257 The function leaves if the audio converter object cannot be created.
       
   258 
       
   259 @param  aObserver
       
   260         The class to receive state change events from converter.
       
   261 @param  aServer
       
   262         No longer used, should be NULL.
       
   263 @param  aPriority
       
   264         The Priority Value - this client's relative priority. This is a value between EMdaPriorityMin and 
       
   265         EMdaPriorityMax and represents a relative priority. A higher value indicates a more important request.
       
   266 @param  aPref
       
   267         The Priority Preference - an additional audio policy parameter. The suggested default is 
       
   268         EMdaPriorityPreferenceNone. Further values are given by TMdaPriorityPreference, and additional 
       
   269         values may be supported by given phones and/or platforms, but should not be depended upon by 
       
   270         portable code.
       
   271 
       
   272 @return A pointer to a new instance of CMdaAudioConvertUtility.
       
   273 
       
   274 @since  5.0
       
   275 
       
   276 Note: The Priority Value and Priority Preference are used primarily when deciding what to do when
       
   277 several audio clients attempt to play or record simultaneously. In addition to the Priority Value and Preference, 
       
   278 the adaptation may consider other parameters such as the SecureId and Capabilities of the client process. 
       
   279 Whatever, the decision  as to what to do in such situations is up to the audio adaptation, and may
       
   280 vary between different phones. Portable applications are advised not to assume any specific behaviour. 
       
   281 */
       
   282 EXPORT_C CMdaAudioConvertUtility* CMdaAudioConvertUtility::NewL(MMdaObjectStateChangeObserver& aObserver,
       
   283 																CMdaServer* /*aServer*/,
       
   284 																TInt aPriority,
       
   285 																TInt aPref)
       
   286 	{
       
   287 	CMdaAudioConvertUtility* self = new(ELeave) CMdaAudioConvertUtility();
       
   288 	CleanupStack::PushL(self);
       
   289 	self->iProperties = new(ELeave) CMMFMdaAudioConvertUtility(self, aObserver);
       
   290 	self->iProperties->ConstructL(aPriority, aPref);
       
   291 	CleanupStack::Pop(self);
       
   292 	return self;
       
   293 	}
       
   294 
       
   295 /**
       
   296 Destructor. 
       
   297 
       
   298 Closes the audio clip and frees resources.
       
   299 
       
   300 @since  5.0
       
   301 */
       
   302 CMdaAudioConvertUtility::~CMdaAudioConvertUtility()
       
   303 	{
       
   304 	delete iProperties;
       
   305 	}
       
   306 
       
   307 /**
       
   308 Ensures that any subsequent calls to OpenXYZ() will create controllers that
       
   309 share a heap.
       
   310 
       
   311 The default behaviour is that for each converter utility a controller with its own heap
       
   312 is created. Each heap uses a chunk, so using this function avoids situations where 
       
   313 the number of chunks per process is limited.
       
   314 The default behaviour is generally to be preferred, and should give lower overall
       
   315 memory usage. However, if many controllers are to be created for a particular thread,
       
   316 then this function should be used to prevent running out of heaps or chunks.
       
   317 
       
   318 @since	9.2
       
   319 */
       
   320 EXPORT_C void CMdaAudioConvertUtility::UseSharedHeap()
       
   321 	{
       
   322 	ASSERT(iProperties);
       
   323 	iProperties->UseSharedHeap();
       
   324 	}
       
   325 	
       
   326 /**
       
   327 Opens source and target files (both of which must already exist) so that audio sample data can be 
       
   328 extracted from the source file, converted and appended to the target file.
       
   329 
       
   330 When opening is complete, successfully or otherwise, the client is notified by 
       
   331 MMdaObjectStateChangeObserver::MoscoStateChangeEvent(). The callback is initiated by this function 
       
   332 providing it with state change information and error codes.
       
   333 
       
   334 @param  aPrimaryFile
       
   335         The full path and filename of a file containing audio sample data to be converted.
       
   336 @param  aSecondaryFile
       
   337         The full path and filename of a file to which converted data is appended.
       
   338 
       
   339 @since  5.0
       
   340 */
       
   341 void CMdaAudioConvertUtility::OpenL(const TDesC& aPrimaryFile, const TDesC& aSecondaryFile)
       
   342 	{
       
   343 	ASSERT(iProperties);
       
   344 	iProperties->OpenL(aPrimaryFile, aSecondaryFile);
       
   345 	}
       
   346 
       
   347 /**
       
   348 Opens an existing audio file so that audio sample data can be extracted from it, converted and 
       
   349 placed into the target audio object.
       
   350 
       
   351 When opening is complete, successfully or otherwise, the client is notified by 
       
   352 MMdaObjectStateChangeObserver::MoscoStateChangeEvent(). The callback is initiated by this function 
       
   353 providing it with state change information and error codes.
       
   354 
       
   355 @param  aPrimaryFile
       
   356         The full path and filename of a file containing audio sample data to be converted.
       
   357 @param  aLocation
       
   358         The target location for the audio data. This is normally a file (TMdaFileClipLocation) or a 
       
   359         descriptor (TMdaDesClipLocation).
       
   360 @param  aFormat
       
   361         The audio format for the target audio object.
       
   362 @param  aArg1
       
   363         The codec to use for the target audio object.
       
   364 @param  aArg2
       
   365         The audio settings for the target audio object.
       
   366 
       
   367 @since  5.0
       
   368 */
       
   369 void CMdaAudioConvertUtility::OpenL(const TDesC& aPrimaryFile, TMdaClipLocation* aLocation, TMdaClipFormat* aFormat,
       
   370 									TMdaPackage* aArg1 /*= NULL*/, TMdaPackage* aArg2 /*= NULL*/)
       
   371 	{
       
   372 	ASSERT(iProperties);
       
   373 	iProperties->OpenL(aPrimaryFile, aLocation, aFormat, aArg1, aArg2);
       
   374 	}
       
   375 
       
   376 /**
       
   377 Opens an audio clip for conversion.
       
   378 
       
   379 @param  aPriLocation
       
   380         The source location for audio data. This is normally a file (TMdaFileClipLocation) or a 
       
   381         descriptor (TMdaDesClipLocation).
       
   382 @param  aSecLocation
       
   383         The target location for audio data. This is normally a file (TMdaFileClipLocation) or a 
       
   384         descriptor (TMdaDesClipLocation).
       
   385 @param  aPriFormat
       
   386         The audio format of the source audio object.
       
   387 @param  aSecFormat
       
   388         The audio format for the target audio object.
       
   389 @param  aPriArg1
       
   390         The codec used by the source audio object.
       
   391 @param  aPriArg2
       
   392         The audio settings of the source audio object.
       
   393 @param  aSecArg1
       
   394         The codec to be used for the target audio object.
       
   395 @param  aSecArg2
       
   396         The audio settings for the target audio object.
       
   397 
       
   398 @since  5.0
       
   399 */
       
   400 void CMdaAudioConvertUtility::OpenL(TMdaClipLocation* aPriLocation, TMdaClipLocation* aSecLocation,
       
   401 									TMdaClipFormat* aPriFormat,  TMdaClipFormat* aSecFormat,
       
   402 									TMdaPackage* aPriArg1 /*= NULL*/, TMdaPackage* aPriArg2 /*= NULL*/,
       
   403 									TMdaPackage* aSecArg1 /*= NULL*/, TMdaPackage* aSecArg2 /*= NULL*/)
       
   404 	{
       
   405 	ASSERT(iProperties);
       
   406 	iProperties->OpenL(aPriLocation, aSecLocation, aPriFormat, aSecFormat, aPriArg1, aPriArg2, aSecArg1, aSecArg2);
       
   407 	}
       
   408 
       
   409 // New functions for 7.0s
       
   410 /**
       
   411 Opens source and target audio objects and specifies controller and audio format and codec 
       
   412 information.
       
   413 
       
   414 When opening is complete, successfully or otherwise, the client is notified by 
       
   415 MMdaObjectStateChangeObserver::MoscoStateChangeEvent(). The callback is initiated by this function
       
   416 providing it with state change information and error codes.
       
   417 
       
   418 @param  aPriLocation
       
   419         The source location for audio data. This is normally a file (TMdaFileClipLocation) or a 
       
   420         descriptor (TMdaDesClipLocation).
       
   421 @param  aSecLocation
       
   422         The destination location for the converted audio data. This is normally a file 
       
   423         (TMdaFileClipLocation) or a descriptor (TMdaDesClipLocation).
       
   424 @param  aControllerUid
       
   425         The UID of the controller to used for conversion.
       
   426 @param  aDestFormatUid
       
   427         The UID of the destination format.
       
   428 @param  aDestDataType
       
   429         The audio codec to use for the destination data sink.
       
   430 
       
   431 @since  7.0s
       
   432 */
       
   433 EXPORT_C void CMdaAudioConvertUtility::OpenL(TMdaClipLocation* aPriLocation, TMdaClipLocation* aSecLocation, TUid aControllerUid,
       
   434 											  TUid aDestFormatUid, TFourCC aDestDataType)
       
   435 	{
       
   436 	ASSERT(iProperties);
       
   437 	iProperties->OpenL(aPriLocation, aSecLocation, aControllerUid, aDestFormatUid, aDestDataType);
       
   438 	}
       
   439 
       
   440 /**
       
   441 Returns a list of the supported data types for the conversion destination.
       
   442 
       
   443 @param  aSupportedDestinationDataTypes
       
   444         A list of four character codes, representing the supported data
       
   445         encodings for the conversion destination.
       
   446 
       
   447 @since  7.0s
       
   448 */
       
   449 EXPORT_C void CMdaAudioConvertUtility::GetSupportedDestinationDataTypesL(RArray<TFourCC>& aSupportedDestinationDataTypes)
       
   450 	{
       
   451 	ASSERT(iProperties);
       
   452 	iProperties->GetSupportedDestinationDataTypesL(aSupportedDestinationDataTypes);
       
   453 	}
       
   454 
       
   455 /**
       
   456 Sets the data type of the destination audio clip.
       
   457 
       
   458 @param  aCodec
       
   459         The four character code, representing the encoding of the destination audio clip
       
   460 
       
   461 @since  7.0s
       
   462 */
       
   463 EXPORT_C void CMdaAudioConvertUtility::SetDestinationDataTypeL(TFourCC aCodec)
       
   464 	{
       
   465 	ASSERT(iProperties);
       
   466 	iProperties->SetDestinationDataTypeL(aCodec);
       
   467 	}
       
   468 
       
   469 /**
       
   470 Returns the data type of the destination audio clip.
       
   471 
       
   472 @return The four character code, representing the encoding of the destination audio clip.
       
   473 
       
   474 @since  7.0s
       
   475 */
       
   476 EXPORT_C TFourCC CMdaAudioConvertUtility::DestinationDataTypeL()
       
   477 	{
       
   478 	ASSERT(iProperties);
       
   479 	return iProperties->DestinationDataTypeL();
       
   480 	}
       
   481 
       
   482 /**
       
   483 Returns the data type of the source audio clip.
       
   484 
       
   485 @return The four character code, representing the encoding of the source audio clip.
       
   486 
       
   487 @since  7.0s
       
   488 */
       
   489 EXPORT_C TFourCC CMdaAudioConvertUtility::SourceDataTypeL()
       
   490 	{
       
   491 	ASSERT(iProperties);
       
   492 	return iProperties->SourceDataTypeL();
       
   493 	}
       
   494 
       
   495 /**
       
   496 Sets the bit rate of the destination audio clip.
       
   497 
       
   498 The bit rate must be one of the supported bit rates of the audio target. Use
       
   499 GetSupportedConversionBitRatesL() to retrieve a list of supported bit rates.
       
   500 
       
   501 @param  aBitRate
       
   502         The destination bit rate in bits/second.
       
   503 
       
   504 @since  7.0s
       
   505 */
       
   506 EXPORT_C void CMdaAudioConvertUtility::SetDestinationBitRateL(TUint aBitRate)
       
   507 	{
       
   508 	ASSERT(iProperties);
       
   509 	iProperties->SetDestinationBitRateL(aBitRate);
       
   510 	}
       
   511 
       
   512 /**
       
   513 Returns the bit rate of the destination audio clip.
       
   514 
       
   515 @return The destination bit rate in bits/second.
       
   516 
       
   517 @since  7.0s
       
   518 */
       
   519 EXPORT_C TUint CMdaAudioConvertUtility::DestinationBitRateL()
       
   520 	{
       
   521 	ASSERT(iProperties);
       
   522 	return iProperties->DestinationBitRateL();
       
   523 	}
       
   524 
       
   525 /**
       
   526 Gets a list of the supported bit rates for the conversion destination.
       
   527 
       
   528 @param  aSupportedBitRates
       
   529         The list of bit rates supported for the conversion destination.
       
   530 
       
   531 @since  7.0s
       
   532 */
       
   533 EXPORT_C void CMdaAudioConvertUtility::GetSupportedConversionBitRatesL(RArray<TUint>& aSupportedBitRates)
       
   534 	{
       
   535 	ASSERT(iProperties);
       
   536 	iProperties->GetSupportedConversionBitRatesL(aSupportedBitRates);
       
   537 	}
       
   538 
       
   539 /**
       
   540 Returns the bit rate of the source audio clip.
       
   541 
       
   542 @return The source bit rate in bits/second.
       
   543 
       
   544 @since  7.0s
       
   545 */
       
   546 EXPORT_C TInt CMdaAudioConvertUtility::SourceBitRateL()
       
   547 	{
       
   548 	ASSERT(iProperties);
       
   549 	return iProperties->SourceBitRateL();
       
   550 	}
       
   551 
       
   552 /**
       
   553 Sets the sample rate for the conversion destination.
       
   554 
       
   555 The sample rate must be one of the supported sample rates of the audio target. Use 
       
   556 GetSupportedConversionSampleRatesL() to retrieve a list of supported sample rates.
       
   557 This function should not be used if the audio clip already exists; that is, in the
       
   558 "Open and Append" scenario, when the function's behaviour is undefined.
       
   559 
       
   560 @param  aSampleRate
       
   561         The sample rate of the conversion destination in samples per second.
       
   562 
       
   563 @since  7.0s
       
   564 */
       
   565 EXPORT_C void CMdaAudioConvertUtility::SetDestinationSampleRateL(TUint aSampleRate)
       
   566 	{
       
   567 	ASSERT(iProperties);
       
   568 	iProperties->SetDestinationSampleRateL(aSampleRate);
       
   569 	}
       
   570 
       
   571 /**
       
   572 Returns the sample rate of the conversion destination.
       
   573 
       
   574 @return The sample rate of the conversion destination in samples per second.
       
   575 
       
   576 @since  7.0s
       
   577 */
       
   578 EXPORT_C TUint CMdaAudioConvertUtility::DestinationSampleRateL()
       
   579 	{
       
   580 	ASSERT(iProperties);
       
   581 	return iProperties->DestinationSampleRateL();
       
   582 	}
       
   583 
       
   584 /**
       
   585 Gets a list of supported conversion sample rates. This is a list of the sample rates that
       
   586 the conversion destination can take.
       
   587 
       
   588 @param  aSupportedSampleRates
       
   589         A list of the sample rates that are supported for the conversion.
       
   590 
       
   591 @since  7.0s
       
   592 */
       
   593 EXPORT_C void CMdaAudioConvertUtility::GetSupportedConversionSampleRatesL(RArray<TUint>& aSupportedSampleRates)
       
   594 	{
       
   595 	ASSERT(iProperties);
       
   596 	iProperties->GetSupportedConversionSampleRatesL(aSupportedSampleRates);
       
   597 	}
       
   598 
       
   599 /**
       
   600 Returns the sample rate of the source audio clip.
       
   601 
       
   602 @return The source sample rate in samples/second.
       
   603 
       
   604 @since  7.0s
       
   605 */
       
   606 EXPORT_C TUint CMdaAudioConvertUtility::SourceSampleRateL()
       
   607 	{
       
   608 	ASSERT(iProperties);
       
   609 	return iProperties->SourceSampleRateL();
       
   610 	}
       
   611 
       
   612 /**
       
   613 Sets the format of the destination audio clip.
       
   614 
       
   615 The UID (aFormatUid) corresponds to the UID of the destination format to use.
       
   616 
       
   617 @param  aFormatUid
       
   618         The UID of the destination format.
       
   619 
       
   620 @since  7.0s
       
   621 */
       
   622 EXPORT_C void CMdaAudioConvertUtility::SetDestinationFormatL(TUid aFormatUid)
       
   623 	{
       
   624 	ASSERT(iProperties);
       
   625 	iProperties->SetDestinationFormatL(aFormatUid);
       
   626 	}
       
   627 
       
   628 /**
       
   629 Returns the format of the destination audio clip.
       
   630 
       
   631 @return The UID of the destination format.
       
   632 
       
   633 @since  7.0s
       
   634 */
       
   635 EXPORT_C TUid CMdaAudioConvertUtility::DestinationFormatL()
       
   636 	{
       
   637 	ASSERT(iProperties);
       
   638 	return iProperties->DestinationFormatL();
       
   639 	}
       
   640 
       
   641 /**
       
   642 Returns the format of the source audio clip.
       
   643 
       
   644 @return The UID of the source format.
       
   645 
       
   646 @since  7.0s
       
   647 */
       
   648 EXPORT_C TUid CMdaAudioConvertUtility::SourceFormatL()
       
   649 	{
       
   650 	ASSERT(iProperties);
       
   651 	return iProperties->SourceFormatL();
       
   652 	}
       
   653 
       
   654 /**
       
   655 Sets the number of channels the destination audio clip contains.
       
   656 
       
   657 The number of channels must be one of the values returned by 
       
   658 GetSupportedConversionNumberOfChannelsL().
       
   659 
       
   660 @param  aNumberOfChannels
       
   661         The number of channels.
       
   662 
       
   663 @since  7.0s
       
   664 */
       
   665 EXPORT_C void CMdaAudioConvertUtility::SetDestinationNumberOfChannelsL(TUint aNumberOfChannels)
       
   666 	{
       
   667 	ASSERT(iProperties);
       
   668 	iProperties->SetDestinationNumberOfChannelsL(aNumberOfChannels);
       
   669 	}
       
   670 
       
   671 /**
       
   672 Returns the number of channels the destination audio clip contains.
       
   673 
       
   674 @return The number of channels.
       
   675 
       
   676 @since  7.0s
       
   677 */
       
   678 EXPORT_C TUint CMdaAudioConvertUtility::DestinationNumberOfChannelsL()
       
   679 	{
       
   680 	ASSERT(iProperties);
       
   681 	return iProperties->DestinationNumberOfChannelsL();
       
   682 	}
       
   683 
       
   684 /**
       
   685 Returns a list of the supported number of channels for conversion.
       
   686 
       
   687 For example, 1 for mono, 2 for stereo and so on.
       
   688 
       
   689 @param  aSupportedNumChannels
       
   690         A list of the number of channels supported for the conversion destination.
       
   691 
       
   692 @since  7.0s
       
   693 */
       
   694 EXPORT_C void CMdaAudioConvertUtility::GetSupportedConversionNumberOfChannelsL(RArray<TUint>& aSupportedNumChannels)
       
   695 	{
       
   696 	ASSERT(iProperties);
       
   697 	iProperties->GetSupportedConversionNumberOfChannelsL(aSupportedNumChannels);
       
   698 	}
       
   699 
       
   700 /**
       
   701 Returns the number of channels used by the conversion source.
       
   702 
       
   703 @return The number of channels.
       
   704 
       
   705 @since  7.0s
       
   706 */
       
   707 EXPORT_C TUint CMdaAudioConvertUtility::SourceNumberOfChannelsL()
       
   708 	{
       
   709 	ASSERT(iProperties);
       
   710 	return iProperties->SourceNumberOfChannelsL();
       
   711 	}
       
   712 /**
       
   713 Performs the conversion from the source audio format to the destination.
       
   714 
       
   715 When conversion is complete, successfully or otherwise, the client is notified by 
       
   716 MMdaObjectStateChangeObserver::MoscoStateChangeEvent(). The callback is initiated by this function 
       
   717 providing it with state change information and error codes.
       
   718 
       
   719 @since  7.0s
       
   720 */
       
   721 EXPORT_C void CMdaAudioConvertUtility::ConvertL()
       
   722 	{
       
   723 	ASSERT(iProperties);
       
   724 	iProperties->ConvertL();
       
   725 	}
       
   726 
       
   727 /**
       
   728 Returns the controller implementation information associated with the current controller.
       
   729 
       
   730 @return The controller implementation structure associated with the controller
       
   731 
       
   732 @since  7.0s
       
   733 */
       
   734 EXPORT_C const CMMFControllerImplementationInformation& CMdaAudioConvertUtility::ControllerImplementationInformationL()
       
   735 	{
       
   736 	ASSERT(iProperties);
       
   737 	return iProperties->ControllerImplementationInformationL();
       
   738 	}
       
   739 
       
   740 /**
       
   741 Sends a synchronous custom command to the controller.
       
   742 
       
   743 @param  aDestination
       
   744         The destination of the message, consisting of the UID of the interface of this message.
       
   745 @param  aFunction
       
   746         The function number to indicate which function is to be called
       
   747         on the interface defined in the aDestination parameter.
       
   748 @param  aDataTo1
       
   749         A reference to the first chunk of data to be copied to the controller
       
   750         framework. The exact contents of the data are dependent on the
       
   751         interface being called. Can be KNullDesC8.
       
   752 @param  aDataTo2
       
   753         A reference to the second chunk of data to be copied to the controller
       
   754         framework. The exact contents of the data are dependent on the
       
   755         interface being called. Can be KNullDesC8.
       
   756 @param  aDataFrom
       
   757         A reference to an area of memory to which the controller framework will
       
   758         write any data to be passed back to the client. Can't be KNullDesC8.
       
   759 
       
   760 @return The result of the request. Exact range of values is dependent on the interface.
       
   761 
       
   762 @since  7.0s
       
   763 */
       
   764 EXPORT_C TInt CMdaAudioConvertUtility::CustomCommandSync(const TMMFMessageDestinationPckg& aDestination, TInt aFunction, const TDesC8& aDataTo1, const TDesC8& aDataTo2, TDes8& aDataFrom)
       
   765 	{
       
   766 	ASSERT(iProperties);
       
   767 	return iProperties->CustomCommandSync(aDestination, aFunction, aDataTo1, aDataTo2, aDataFrom);
       
   768 	}
       
   769 
       
   770 /**
       
   771 Sends a synchronous custom command to the controller.
       
   772 
       
   773 @param  aDestination
       
   774         The destination of the message, consisting of the UID of the interface of this message.
       
   775 @param  aFunction
       
   776         The function number to indicate which function is to be called on the interface defined in 
       
   777         the aDestination parameter.
       
   778 @param  aDataTo1
       
   779         A reference to the first chunk of data to be copied to the controllert framework. The exact
       
   780         contents of the data are dependent on the interface being called. Can be KNullDesC8.
       
   781 @param  aDataTo2
       
   782         A reference to the second chunk of data to be copied to the controller framework. The exact
       
   783         contents of the data are dependent on the interface being called. Can be KNullDesC8.
       
   784 
       
   785 @return The result of the request. The exact range of values is dependent on the interface.
       
   786 
       
   787 @since  7.0s
       
   788 */
       
   789 EXPORT_C TInt CMdaAudioConvertUtility::CustomCommandSync(const TMMFMessageDestinationPckg& aDestination, TInt aFunction, const TDesC8& aDataTo1, const TDesC8& aDataTo2)
       
   790 	{
       
   791 	ASSERT(iProperties);
       
   792 	return iProperties->CustomCommandSync(aDestination, aFunction, aDataTo1, aDataTo2);
       
   793 	}
       
   794 
       
   795 /**
       
   796 Send a asynchronous custom command to the controller.
       
   797 
       
   798 Note: This method will return immediately.  The RunL of the active object owning the
       
   799 aStatus parameter will be called when the command is completed by the controller framework.
       
   800 
       
   801 @param  aDestination
       
   802         The destination of the message, consisting of the UID of the interface of this message.
       
   803 @param  aFunction
       
   804         The function number to indicate which function is to be called on the interface defined in
       
   805         the aDestination parameter.
       
   806 @param  aDataTo1
       
   807         A reference to the first chunk of data to be copied to the controller framework. The exact
       
   808         contents of the data are dependent on the interface being called. Can be KNullDesC8.
       
   809 @param  aDataTo2
       
   810         A reference to the second chunk of data to be copied to the controller framework. The exact
       
   811         contents of the data are dependent on the interface being called. Can be KNullDesC8.
       
   812 @param  aDataFrom
       
   813         A reference to an area of memory to which the controller framework will write any data to be
       
   814         passed back to the client. Can't be KNullDesC8.
       
   815 @param  aStatus
       
   816         The TRequestStatus of an active object.  This will contain the result of the request on
       
   817         completion. The exact range of result values is dependent on the interface.
       
   818 @since  7.0s
       
   819 */
       
   820 EXPORT_C void CMdaAudioConvertUtility::CustomCommandAsync(const TMMFMessageDestinationPckg& aDestination, TInt aFunction, const TDesC8& aDataTo1, const TDesC8& aDataTo2, TDes8& aDataFrom, TRequestStatus& aStatus)
       
   821 	{
       
   822 	ASSERT(iProperties);
       
   823 	iProperties->CustomCommandAsync(aDestination, aFunction, aDataTo1, aDataTo2, aDataFrom, aStatus);
       
   824 	}
       
   825 
       
   826 /**
       
   827 Send a asynchronous custom command to the controller.
       
   828 
       
   829 Note: This method will return immediately.  The RunL of the active object owning the
       
   830 aStatus parameter will be called when the command is completed by the controller framework.
       
   831 
       
   832 @param  aDestination
       
   833         The destination of the message, consisting of the UID of the interface of this message.
       
   834 @param  aFunction
       
   835         The function number to indicate which function is to be called on the interface defined in 
       
   836         the aDestination parameter.
       
   837 @param  aDataTo1
       
   838         A reference to the first chunk of data to be copied to the controller framework. The exact 
       
   839         contents of the data are dependent on the interface being called. Can be KNullDesC8.
       
   840 @param  aDataTo2
       
   841         A reference to the second chunk of data to be copied to the controller framework. The exact 
       
   842         contents of the data are dependent on the interface being called. Can be KNullDesC8.
       
   843 @param  aStatus
       
   844         The TRequestStatus of an active object. This will contain the result of the request on
       
   845         completion. The exact range of result values is dependent on the interface.
       
   846 
       
   847 @since  7.0s
       
   848 */
       
   849 EXPORT_C void CMdaAudioConvertUtility::CustomCommandAsync(const TMMFMessageDestinationPckg& aDestination, TInt aFunction, const TDesC8& aDataTo1, const TDesC8& aDataTo2, TRequestStatus& aStatus)
       
   850 	{
       
   851 	ASSERT(iProperties);
       
   852 	iProperties->CustomCommandAsync(aDestination, aFunction, aDataTo1, aDataTo2, aStatus);
       
   853 	}
       
   854 
       
   855 /**
       
   856 Set the priority of the controller's sub thread.
       
   857 
       
   858 This can be used to increase the responsiveness of the audio plugin to minimise
       
   859 any lag in processing. This function should be used with care as it may have knock-on
       
   860 effects elsewhere in the system.
       
   861 
       
   862 @param	aPriority
       
   863 		The TThreadPriority that the thread should run under.  The default is EPriorityNormal.
       
   864 @return	TInt
       
   865 		A standard error code: KErrNone if successful, KErrNotReady if the thread does not have a
       
   866 		valid handle.
       
   867 */
       
   868 EXPORT_C TInt CMdaAudioConvertUtility::SetThreadPriority(const TThreadPriority& aThreadPriority) const
       
   869 	{
       
   870 	ASSERT(iProperties);
       
   871 	return iProperties->SetThreadPriority(aThreadPriority);
       
   872 	}
       
   873 
       
   874 
       
   875 /******************************************************************************/
       
   876 
       
   877 
       
   878 CMMFMdaAudioConvertUtility::CMMFMdaAudioConvertUtility(CMdaAudioConvertUtility* aParent,
       
   879 													   MMdaObjectStateChangeObserver& aCallback) :
       
   880 	iCallback(aCallback),
       
   881 	iAudioControllerCustomCommands(iController),
       
   882 	iAudioPlayControllerCustomCommands(iController),
       
   883 	iAudioRecordControllerCustomCommands(iController),
       
   884 	iParent(aParent),
       
   885 	iHasCropped(EFalse),
       
   886 	iCroppedDuration(0)
       
   887 	{
       
   888 	iConvertStart = TTimeIntervalMicroSeconds(0);
       
   889 	iConvertEnd = TTimeIntervalMicroSeconds(0);
       
   890 	iConvertWindowSet = EFalse;
       
   891 	}
       
   892 
       
   893 void CMMFMdaAudioConvertUtility::ConstructL(TInt /*aPriority*/, TInt /*aPref*/)
       
   894 	{
       
   895 	iControllerEventMonitor = CMMFControllerEventMonitor::NewL(*this, iController);
       
   896 	iAsyncCallback = CMMFMdaObjectStateChangeObserverCallback::NewL(iCallback);
       
   897 	User::LeaveIfError(iMediaIds.Append(KUidMediaTypeAudio));
       
   898 	iFindAndOpenController = CMMFFindAndOpenController::NewL(*this);
       
   899 	iFindAndOpenController->Configure(iMediaIds[0], iPrioritySettings);
       
   900 	iFindAndOpenController->ConfigureController(iController, *iControllerEventMonitor, CMMFFindAndOpenController::EConvert);
       
   901 	}
       
   902 
       
   903 CMMFMdaAudioConvertUtility::~CMMFMdaAudioConvertUtility()
       
   904 	{
       
   905 	delete iControllerImplementationInformation;
       
   906 	delete iAsyncCallback;
       
   907 	delete iFindAndOpenController;
       
   908 	delete iControllerEventMonitor;
       
   909 	iMediaIds.Close();
       
   910 	iController.Close();
       
   911 	}
       
   912 
       
   913 void CMMFMdaAudioConvertUtility::UseSharedHeap()
       
   914 	{
       
   915 	iFindAndOpenController->UseSharedHeap();
       
   916 	}
       
   917 	
       
   918 void CMMFMdaAudioConvertUtility::MfaocComplete(		
       
   919 		TInt& aError, 
       
   920 		RMMFController* /*aController*/,
       
   921 		TUid aControllerUid, 
       
   922 		TMMFMessageDestination* /*aSourceHandle*/, 
       
   923 		TMMFMessageDestination* /*aSinkHandle*/)
       
   924 	{
       
   925 	TInt oldState = iState;
       
   926 
       
   927 	if (aError == KErrNone)
       
   928 		{
       
   929 		iControllerUid = aControllerUid;
       
   930 		aError = ControllerOpen();
       
   931 		if (iFindAndOpenController)	
       
   932 			{
       
   933 			iFindAndOpenController->Close();
       
   934 			}
       
   935 		}
       
   936 
       
   937 	iAsyncCallback->CallBack(iParent, oldState, iState, aError);
       
   938 	}
       
   939 
       
   940 void CMMFMdaAudioConvertUtility::OpenL(TMdaClipLocation* aPriLocation, 
       
   941 									   TMdaClipLocation* aSecLocation, 
       
   942 									   TMdaClipFormat* aPriFormat, 
       
   943 									   TMdaClipFormat* aSecFormat, 
       
   944 									   TMdaPackage* aPriArg1 /*= NULL*/, 
       
   945 									   TMdaPackage* aPriArg2 /*= NULL*/, 
       
   946 									   TMdaPackage* aSecArg1 /*= NULL*/, 
       
   947 									   TMdaPackage* aSecArg2 /*= NULL*/)
       
   948 	{
       
   949 	__ASSERT_ALWAYS((aPriLocation && aSecLocation && aPriFormat && aSecFormat), User::Leave(KErrArgument));
       
   950 
       
   951 	__ASSERT_ALWAYS((((aPriLocation->Uid() == KUidMdaFileResLoc) || (aPriLocation->Uid() == KUidMdaDesResLoc) || (aPriLocation->Uid() == KUidMdaUrlResLoc)) &&
       
   952 	   ((aSecLocation->Uid() == KUidMdaFileResLoc) || (aSecLocation->Uid() == KUidMdaDesResLoc) || (aSecLocation->Uid() == KUidMdaUrlResLoc))),
       
   953 		User::Leave(KErrNotSupported));
       
   954 
       
   955 	__ASSERT_ALWAYS(((aPriFormat->Uid() != KNullUid) && (aSecFormat->Uid() != KNullUid)), User::Leave(KErrNotSupported));
       
   956 
       
   957 	Reset();
       
   958 	
       
   959 	//Do aPriArg2 & aSecArg2 contain the correct package type
       
   960 	if(aPriArg2)
       
   961 		{
       
   962 		TMdaPackage* pckg = aPriArg2;
       
   963 		if(pckg->Uid() != KUidMdaMediaTypeAudio)
       
   964 			User::Leave(KErrNotSupported);
       
   965 
       
   966 		TMdaAudioDataSettings audioSettings = *(TMdaAudioDataSettings*)aPriArg2;
       
   967 		iSourceSampleRate = audioSettings.iSampleRate;
       
   968 		iSourceChannels = audioSettings.iChannels;
       
   969 		}
       
   970 
       
   971 	if(aSecArg2)
       
   972 		{
       
   973 		TMdaPackage* pckg = aSecArg2;
       
   974 		if(pckg->Uid() != KUidMdaMediaTypeAudio)
       
   975 			User::Leave(KErrNotSupported);
       
   976 		TMdaAudioDataSettings audioSettings = *(TMdaAudioDataSettings*)aSecArg2;
       
   977 		iSinkSampleRate = audioSettings.iSampleRate;
       
   978 		iSinkChannels = audioSettings.iChannels;
       
   979 		}
       
   980 
       
   981 
       
   982 	//Do aPriArg1 & aSecArg1 contain supported FourCC types
       
   983 	iSourceDataType = KMMFFourCCCodeNULL;
       
   984 	if (aPriArg1)
       
   985 		{
       
   986 		iSourceDataType = CMMFClientUtility::ConvertMdaCodecToFourCC(*aPriArg1);
       
   987 		if(iSourceDataType == KMMFFourCCCodeNULL)
       
   988 			User::Leave(KErrNotSupported);
       
   989 		}
       
   990 
       
   991 	iSinkDataType = KMMFFourCCCodeNULL;
       
   992 	if (aSecArg1)
       
   993 		{
       
   994 		iSinkDataType = CMMFClientUtility::ConvertMdaCodecToFourCC(*aSecArg1);
       
   995 		if(iSinkDataType == KMMFFourCCCodeNULL)
       
   996 			User::Leave(KErrNotSupported);
       
   997 		}
       
   998 
       
   999 
       
  1000 
       
  1001 	TInt err = KErrNone;
       
  1002 
       
  1003 	iSourceFormatUid = CMMFClientUtility::ConvertMdaFormatUidToECOMRead(aPriFormat->Uid());
       
  1004 	//If a new formatter plugin has been added, use the supplied read format implementation ID
       
  1005 	if (iSourceFormatUid == KNullUid)
       
  1006 		iSourceFormatUid = aPriFormat->Uid();
       
  1007 
       
  1008 	iSinkFormatUid = CMMFClientUtility::ConvertMdaFormatUidToECOMWrite(aSecFormat->Uid());
       
  1009 	//If a new formatter plugin has been added, use the supplied write format implementation ID
       
  1010 	if (iSinkFormatUid == KNullUid)
       
  1011 		iSinkFormatUid = aSecFormat->Uid();
       
  1012 
       
  1013 	TRAP(err, ConfigureSourceSinkL(aPriLocation, aSecLocation));
       
  1014 
       
  1015 	if (!err)
       
  1016 		iFindAndOpenController->OpenByFormatUid(iSourceFormatUid, iSinkFormatUid);
       
  1017 
       
  1018 	if (err)
       
  1019 		{
       
  1020 		TInt oldState = State();
       
  1021 		iAsyncCallback->CallBack(iParent, oldState, oldState, err);
       
  1022 		return;
       
  1023 		}
       
  1024 	}
       
  1025 
       
  1026 
       
  1027 
       
  1028 
       
  1029 void CMMFMdaAudioConvertUtility::OpenL(const TDesC& aPrimaryFile, const TDesC& aSecondaryFile)
       
  1030 	{
       
  1031 	Reset();
       
  1032 	
       
  1033 	iFindAndOpenController->ConfigureSourceSink(
       
  1034 		CMMFFindAndOpenController::TSourceSink(KUidMmfFileSource, CMMFFindAndOpenController::GetConfigFile(aPrimaryFile)), 
       
  1035 		CMMFFindAndOpenController::TSourceSink(KUidMmfFileSink, CMMFFindAndOpenController::GetConfigFile(aSecondaryFile)));
       
  1036 
       
  1037 	TMMFileSource tfs(aPrimaryFile);
       
  1038 	iFindAndOpenController->OpenByFileSource(tfs, aSecondaryFile);
       
  1039 	}
       
  1040 
       
  1041 void CMMFMdaAudioConvertUtility::OpenL(const TDesC& aPrimaryFile,
       
  1042 						TMdaClipLocation* aLocation,	// Normally file or descriptor
       
  1043 						TMdaClipFormat* aFormat,		// Data format
       
  1044 						TMdaPackage* aArg1,		// Normally codec to use
       
  1045 						TMdaPackage* aArg2)		// Normally audio settings
       
  1046 	{
       
  1047 	__ASSERT_ALWAYS(aLocation && aFormat, User::Leave(KErrArgument)); 
       
  1048 
       
  1049 	Reset();
       
  1050 
       
  1051 	// convert from the old parameters
       
  1052 	if (aFormat)
       
  1053 		{
       
  1054 		iSinkFormatUid = CMMFClientUtility::ConvertMdaFormatUidToECOMWrite(aFormat->Uid());
       
  1055 	
       
  1056 		//If a new formatter plugin has been added, use the supplied format ID
       
  1057 		if (iSinkFormatUid == KNullUid)
       
  1058 			iSinkFormatUid = aFormat->Uid();
       
  1059 		}
       
  1060 
       
  1061 	if (aArg1)
       
  1062 		iSinkDataType = CMMFClientUtility::ConvertMdaCodecToFourCC(*aArg1);
       
  1063 
       
  1064 	if (aArg2)
       
  1065 		{//have audio settings
       
  1066 		TMdaAudioDataSettings audioSettings = *(TMdaAudioDataSettings*)aArg2; //shoud check arg2 are data settings
       
  1067 		iSinkSampleRate = audioSettings.iSampleRate;
       
  1068 		iSinkChannels = audioSettings.iChannels;
       
  1069 		}
       
  1070 
       
  1071 
       
  1072 	
       
  1073 	TMMFFileConfig sourceCfg;
       
  1074 	sourceCfg().iPath = aPrimaryFile;
       
  1075 
       
  1076 	TMMFDescriptorConfig dstDesCfg;
       
  1077 	TMMFFileConfig dstFileCfg;
       
  1078 	CBufFlat* dstCfgBuffer = NULL;
       
  1079 	CMMFUrlParams* dstURLCfg = NULL;
       
  1080 	TUid dstUid = KNullUid;
       
  1081 	TPtrC8 dstCfg(NULL, 0);
       
  1082 
       
  1083 	TInt err = KErrNone;
       
  1084 
       
  1085 	if (aLocation->Uid() == KUidMdaFileResLoc)
       
  1086 		{//sink clip location is a file
       
  1087 		TDesC& fileName = ((TMdaFileClipLocation*)aLocation)->iName;
       
  1088 		dstFileCfg().iPath = fileName;
       
  1089 		dstCfg.Set(dstFileCfg);
       
  1090 		dstUid = KUidMmfFileSink;
       
  1091 		}
       
  1092 	else if (aLocation->Uid() == KUidMdaDesResLoc)
       
  1093 		{//sink clip is a descriptor - pass down descriptor & thread id
       
  1094 		TMdaDesClipLocation* desLoc = (TMdaDesClipLocation*)aLocation;
       
  1095 		dstDesCfg().iDes = desLoc->iDes;
       
  1096 		dstDesCfg().iDesThreadId = desLoc->iThreadId;
       
  1097 		dstCfg.Set(dstDesCfg);
       
  1098 		dstUid = KUidMmfDescriptorSink;
       
  1099 		}
       
  1100 	else if (aLocation->Uid() == KUidMdaUrlResLoc)
       
  1101 		{
       
  1102 		TMdaUrlClipLocation* desLoc = (TMdaUrlClipLocation*)aLocation;
       
  1103 		dstURLCfg = CMMFUrlParams::NewLC(desLoc->iUrl, desLoc->iIapId);
       
  1104 		dstCfgBuffer = dstURLCfg->ExternalizeToCBufFlatLC();
       
  1105 		dstCfg.Set(dstCfgBuffer->Ptr(0));
       
  1106 		dstUid = KUidMmfUrlSink;
       
  1107 		}
       
  1108 	else
       
  1109 		err = KErrNotSupported;
       
  1110 
       
  1111 	if (!err)
       
  1112 		{
       
  1113 		iFindAndOpenController->ConfigureSourceSink(
       
  1114 			CMMFFindAndOpenController::TSourceSink(KUidMmfFileSource,	sourceCfg), 
       
  1115 			CMMFFindAndOpenController::TSourceSink(dstUid, dstCfg));
       
  1116 			
       
  1117 		TMMFileSource tfs(aPrimaryFile);
       
  1118 		iFindAndOpenController->OpenByFileSource(tfs);
       
  1119 		}
       
  1120 
       
  1121 
       
  1122 
       
  1123 	if (dstCfgBuffer)
       
  1124 		CleanupStack::PopAndDestroy(dstCfgBuffer);
       
  1125 	if (dstURLCfg)
       
  1126 		CleanupStack::PopAndDestroy(dstURLCfg);
       
  1127 
       
  1128 
       
  1129 	if (err)
       
  1130 		{	
       
  1131 		TInt oldState = State();
       
  1132 		iAsyncCallback->CallBack(iParent, oldState, oldState, err);
       
  1133 		return;
       
  1134 		}
       
  1135 	}
       
  1136 
       
  1137 void CMMFMdaAudioConvertUtility::OpenL(TMdaClipLocation* aPriLocation, 
       
  1138 						TMdaClipLocation* aSecLocation, 
       
  1139 						TUid aControllerUid, // the controller to use
       
  1140 						TUid aDestFormatUid,
       
  1141 						TFourCC aDestDataType)
       
  1142 	{
       
  1143 	__ASSERT_ALWAYS(aPriLocation && aSecLocation, User::Leave(KErrArgument)); 
       
  1144 
       
  1145 	Reset();
       
  1146 
       
  1147 
       
  1148 	// Configure the destination format and data type
       
  1149 	if (aDestFormatUid != KNullUid)
       
  1150 		iSinkFormatUid = aDestFormatUid;
       
  1151 
       
  1152 	if (aDestDataType != KMMFFourCCCodeNULL)
       
  1153 		iSinkDataType = aDestDataType;
       
  1154 
       
  1155 	TRAPD(err, ConfigureSourceSinkL(aPriLocation, aSecLocation));
       
  1156 	if (!err)
       
  1157 		iFindAndOpenController->OpenByControllerUid(aControllerUid);
       
  1158 
       
  1159 
       
  1160 	if (err)
       
  1161 		{
       
  1162 		TInt oldState = State();
       
  1163 		iAsyncCallback->CallBack(iParent, oldState, oldState, err);
       
  1164 		return;
       
  1165 		}
       
  1166 	}
       
  1167 
       
  1168 
       
  1169 void CMMFMdaAudioConvertUtility::HandleEvent(const TMMFEvent& aEvent)
       
  1170 	{
       
  1171 	//When converting, state is EPlaying, ERecording is never used
       
  1172 	if (aEvent.iEventType==KMMFEventCategoryPlaybackComplete || aEvent.iEventType==KMMFErrorCategoryControllerGeneralError)
       
  1173 		{
       
  1174 		TInt oldState = iState;
       
  1175 		iState = CMdaAudioClipUtility::EOpen;
       
  1176 
       
  1177 		//if we weren't converting, don't advise Client.
       
  1178 		if(oldState == CMdaAudioClipUtility::EPlaying)
       
  1179 			iCallback.MoscoStateChangeEvent(iParent, CMdaAudioClipUtility::EPlaying, iState, aEvent.iErrorCode);
       
  1180 		}
       
  1181 	}
       
  1182 
       
  1183 void CMMFMdaAudioConvertUtility::PlayL()
       
  1184 	{
       
  1185 	// N.B. ConvertL should be used in preference to PlayL
       
  1186 	ConvertL();
       
  1187 	}
       
  1188 
       
  1189 void CMMFMdaAudioConvertUtility::RecordL()
       
  1190 	{
       
  1191 	// N.B. ConvertL should be used in preference to RecordL
       
  1192 	ConvertL();
       
  1193 	}
       
  1194 
       
  1195 void CMMFMdaAudioConvertUtility::ConvertL()
       
  1196 	{
       
  1197 	if (iState == CMdaAudioClipUtility::EOpen) 
       
  1198 		{
       
  1199 		TInt err;
       
  1200 		err = iController.Prime();
       
  1201 		if (err==KErrNone)
       
  1202 			{
       
  1203 			err=iController.SetPosition(iPosition);
       
  1204 			if (!err && iConvertWindowSet)
       
  1205 				err = iAudioPlayControllerCustomCommands.SetPlaybackWindow(iConvertStart, iConvertEnd);
       
  1206 			if (err==KErrNone)
       
  1207 				err = iController.Play();
       
  1208 			}
       
  1209 
       
  1210 			TInt oldState = iState;
       
  1211 			if (!err)
       
  1212 				iState = CMdaAudioClipUtility::EPlaying;
       
  1213 
       
  1214 			iAsyncCallback->CallBack(iParent, oldState, iState, err);
       
  1215 		}
       
  1216 	else
       
  1217 		iAsyncCallback->CallBack(iParent, iState, iState, KErrNotReady);
       
  1218 	}
       
  1219 
       
  1220 void CMMFMdaAudioConvertUtility::Stop()
       
  1221 	{ 
       
  1222 	TInt err = iController.Pause();
       
  1223 	TInt oldState = iState;
       
  1224 	if (!err)
       
  1225 		iState = CMdaAudioClipUtility::EOpen;
       
  1226 	iAsyncCallback->CallBack(iParent, oldState, iState, err);	
       
  1227 	}
       
  1228 
       
  1229 void CMMFMdaAudioConvertUtility::CropL(TBool aCropToEnd)
       
  1230 	{
       
  1231 	// if we are busy converting, or we have not opened the file, return KErrNotReady
       
  1232 	if (iState!=CMdaAudioClipUtility::EOpen)
       
  1233 		User::Leave(KErrNotReady);
       
  1234 
       
  1235 	// check that cropping position is valid if clip has been cropped before
       
  1236 	if (iHasCropped && iPosition > iCroppedDuration)
       
  1237 		{
       
  1238 		User::Leave(KErrArgument);
       
  1239 		}
       
  1240 
       
  1241 	TInt err = iController.Prime();
       
  1242 	if (!err)
       
  1243 		{
       
  1244 
       
  1245 		if (!err)
       
  1246 			err = iController.SetPosition(iPosition);
       
  1247 		
       
  1248 		err = iAudioRecordControllerCustomCommands.Crop(aCropToEnd);
       
  1249 		// try to stop controller regardless of whether any of the above commands failed
       
  1250 		iController.Stop();
       
  1251 		// save the duration of the cropped clip because
       
  1252 		// Duration() returns length of the original clip only
       
  1253 		// this is used to prevent a subsequent crop, beyond the end of the
       
  1254 		// already cropped clip.
       
  1255 		if (err == KErrNone)
       
  1256 			{
       
  1257 			iHasCropped = ETrue;
       
  1258 			if (aCropToEnd)
       
  1259 				iCroppedDuration = iPosition;
       
  1260 			else
       
  1261 				iCroppedDuration = TTimeIntervalMicroSeconds(iDuration.Int64() - iPosition.Int64());
       
  1262 			}
       
  1263 		}
       
  1264 	User::LeaveIfError(err);
       
  1265 	}
       
  1266 
       
  1267 void CMMFMdaAudioConvertUtility::SetPosition(const TTimeIntervalMicroSeconds& aPosition)
       
  1268 	{
       
  1269 	iPosition = aPosition;
       
  1270 
       
  1271 	// Clip the position if aPosition is greater than the duration, or less then 0
       
  1272 	const TTimeIntervalMicroSeconds duration = Duration();
       
  1273 	if (iPosition > duration)
       
  1274 		iPosition = duration;
       
  1275 	else if (iPosition < TTimeIntervalMicroSeconds(0))
       
  1276 		iPosition = 0;
       
  1277 
       
  1278 	if (iState==CMdaAudioClipUtility::EPlaying)
       
  1279 		iController.SetPosition(iPosition);
       
  1280 	}
       
  1281 
       
  1282 const TTimeIntervalMicroSeconds& CMMFMdaAudioConvertUtility::Position()
       
  1283 	{
       
  1284 	if (iState==CMdaAudioClipUtility::EPlaying)
       
  1285 		{
       
  1286 		TInt err = iController.GetPosition(iPositionTemp);
       
  1287 		if (err==KErrNone)
       
  1288 			return iPositionTemp;
       
  1289 		}
       
  1290 	return iPosition;
       
  1291 	}
       
  1292 
       
  1293 const TTimeIntervalMicroSeconds& CMMFMdaAudioConvertUtility::RecordTimeAvailable()
       
  1294 	{
       
  1295 #ifdef _DEBUG
       
  1296 	TInt error = 
       
  1297 #endif
       
  1298 		iAudioRecordControllerCustomCommands.GetRecordTimeAvailable(iRecordTimeAvailable);
       
  1299 	__ASSERT_DEBUG(error==KErrNone, Panic(EMMFMediaClientPanicServerCommunicationProblem)); 
       
  1300 	return iRecordTimeAvailable;
       
  1301 	}
       
  1302 
       
  1303 const TTimeIntervalMicroSeconds& CMMFMdaAudioConvertUtility::Duration()
       
  1304 	{
       
  1305 	TInt err = iController.GetDuration(iDuration);
       
  1306 	if (err)
       
  1307 		iDuration = 0;
       
  1308 	return iDuration;
       
  1309 	}
       
  1310 
       
  1311 void CMMFMdaAudioConvertUtility::SetMaxWriteLength(TInt aMaxWriteLength)
       
  1312 	{
       
  1313 	iAudioRecordControllerCustomCommands.SetMaxFileSize(aMaxWriteLength);
       
  1314 	}
       
  1315 
       
  1316 
       
  1317 void CMMFMdaAudioConvertUtility::SetPlayWindow(const TTimeIntervalMicroSeconds& aStart, const TTimeIntervalMicroSeconds& aEnd)
       
  1318 	{
       
  1319 	if (aStart >= TTimeIntervalMicroSeconds(0) &&
       
  1320 		aStart < iDuration &&
       
  1321 			aStart <= aEnd &&
       
  1322 			aEnd <= iDuration )
       
  1323 		{
       
  1324 		iConvertStart = aStart;
       
  1325 		iConvertEnd = aEnd;
       
  1326 		iConvertWindowSet = ETrue;
       
  1327 
       
  1328 		if (iState==CMdaAudioClipUtility::EPlaying)
       
  1329 			{
       
  1330 #ifdef _DEBUG
       
  1331 			TInt error = 
       
  1332 #endif
       
  1333 				iAudioPlayControllerCustomCommands.SetPlaybackWindow(aStart, aEnd);
       
  1334 			__ASSERT_DEBUG(error==KErrNone, Panic(EMMFMediaClientPanicServerCommunicationProblem)); 
       
  1335 			}
       
  1336 		}
       
  1337 	else
       
  1338 		{
       
  1339 		__ASSERT_DEBUG(EFalse, Panic(EMMFMediaClientPanicServerCommunicationProblem)); 
       
  1340 		}
       
  1341 	}
       
  1342 
       
  1343 void CMMFMdaAudioConvertUtility::ClearPlayWindow()
       
  1344 	{
       
  1345 	iConvertWindowSet = EFalse;
       
  1346 #ifdef _DEBUG
       
  1347 	TInt err = 
       
  1348 #endif //_DEBUG
       
  1349 	iAudioPlayControllerCustomCommands.DeletePlaybackWindow();
       
  1350 	__ASSERT_DEBUG(err==KErrNone, Panic(EMMFMediaClientPanicServerCommunicationProblem)); 
       
  1351 	}
       
  1352 
       
  1353 void CMMFMdaAudioConvertUtility::SetRepeats(TInt /*aRepeatNumberOfTimes*/, const TTimeIntervalMicroSeconds& /*aTrailingSilence*/)
       
  1354 	{
       
  1355 	// This doesn't really make sense for the converter.
       
  1356 	}
       
  1357 
       
  1358 void CMMFMdaAudioConvertUtility::SetPriority(TInt aPriority, TInt aPref)
       
  1359 	{
       
  1360 	iPrioritySettings.iPref = aPref;
       
  1361 	iPrioritySettings.iPriority = aPriority;
       
  1362 	iFindAndOpenController->Configure(iMediaIds[0], iPrioritySettings);
       
  1363 	iController.SetPrioritySettings(iPrioritySettings);
       
  1364 	}
       
  1365 
       
  1366 
       
  1367 void CMMFMdaAudioConvertUtility::Close()
       
  1368 	{
       
  1369 	iControllerEventMonitor->Cancel();
       
  1370 	iController.Close();
       
  1371 
       
  1372 	if (iFindAndOpenController)
       
  1373 		iFindAndOpenController->Close();
       
  1374 
       
  1375 	iHasCropped = EFalse;
       
  1376 	iCroppedDuration = 0;
       
  1377 	iState = CMdaAudioClipUtility::ENotReady;
       
  1378 	if(iControllerImplementationInformation)
       
  1379 		{
       
  1380 		delete iControllerImplementationInformation;
       
  1381 		iControllerImplementationInformation = NULL;
       
  1382 		}
       
  1383 	iControllerUid = KNullUid;
       
  1384 	}
       
  1385 
       
  1386 void CMMFMdaAudioConvertUtility::CropL(const TTimeIntervalMicroSeconds &aCropBegin,
       
  1387 									   const TTimeIntervalMicroSeconds &aCropEnd)
       
  1388 	{
       
  1389 	// if we are busy converting, or we have not opened the file, return KErrNotReady
       
  1390 	if (iState!=CMdaAudioClipUtility::EOpen)
       
  1391 		User::Leave(KErrNotReady);
       
  1392 
       
  1393 	// check that cropping positions are valid if clip has been cropped before
       
  1394 	if (iHasCropped && aCropEnd > iCroppedDuration)
       
  1395 		{
       
  1396 		User::Leave(KErrArgument);
       
  1397 		}
       
  1398 
       
  1399 	TInt err = iController.Prime();
       
  1400 	if (!err)
       
  1401 		{
       
  1402 		err =iController.SetPosition(aCropEnd);
       
  1403 		if (!err)
       
  1404 			err = iAudioRecordControllerCustomCommands.Crop(ETrue);
       
  1405 		if (!err)
       
  1406 			{
       
  1407 			//remember the cropping, store the cropped length
       
  1408 			iHasCropped = ETrue;
       
  1409 			iCroppedDuration = aCropEnd;
       
  1410 			err = iController.SetPosition(aCropBegin);
       
  1411 			}
       
  1412 		if (!err)
       
  1413 			err = iAudioRecordControllerCustomCommands.Crop(EFalse);
       
  1414 		if (!err) // store the new cropped length
       
  1415 			iCroppedDuration = TTimeIntervalMicroSeconds(aCropEnd.Int64() - aCropBegin.Int64());
       
  1416 			
       
  1417 		// try to stop controller regardless of whether any of the above commands failed
       
  1418 		iController.Stop();
       
  1419 		}
       
  1420 	User::LeaveIfError(err);
       
  1421 	}
       
  1422 
       
  1423 CMdaAudioClipUtility::TState CMMFMdaAudioConvertUtility::State()
       
  1424 	{
       
  1425 	return iState;
       
  1426 	}
       
  1427 
       
  1428 void CMMFMdaAudioConvertUtility::GetSupportedDestinationDataTypesL(RArray<TFourCC>& aSupportedDataTypes)
       
  1429 	{
       
  1430 	iAudioControllerCustomCommands.GetSupportedSinkDataTypesL(aSupportedDataTypes);
       
  1431 	}
       
  1432 
       
  1433 void CMMFMdaAudioConvertUtility::SetSourceDataTypeL(TFourCC aDataType)
       
  1434 	{
       
  1435 	User::LeaveIfError(iAudioControllerCustomCommands.SetSourceDataType(aDataType));
       
  1436 	}
       
  1437 
       
  1438 void CMMFMdaAudioConvertUtility::SetDestinationDataTypeL(TFourCC aDataType)
       
  1439 	{
       
  1440 	User::LeaveIfError(iAudioControllerCustomCommands.SetSinkDataType(aDataType));
       
  1441 	}
       
  1442 
       
  1443 TFourCC CMMFMdaAudioConvertUtility::DestinationDataTypeL()
       
  1444 	{
       
  1445 	TFourCC dataType;
       
  1446 	User::LeaveIfError(iAudioControllerCustomCommands.GetSinkDataType(dataType));
       
  1447 	return dataType;
       
  1448 	}
       
  1449 
       
  1450 TFourCC CMMFMdaAudioConvertUtility::SourceDataTypeL()
       
  1451 	{
       
  1452 	TFourCC dataType;
       
  1453 	User::LeaveIfError(iAudioControllerCustomCommands.GetSourceDataType(dataType));
       
  1454 	return dataType;
       
  1455 	}
       
  1456 
       
  1457 
       
  1458 void CMMFMdaAudioConvertUtility::SetDestinationBitRateL(TUint aBitRate)
       
  1459 	{
       
  1460 	User::LeaveIfError(iAudioControllerCustomCommands.SetSinkBitRate(aBitRate));
       
  1461 	}
       
  1462 
       
  1463 void CMMFMdaAudioConvertUtility::SetSourceSampleRateL(TUint aSampleRate)
       
  1464 	{
       
  1465 	User::LeaveIfError(iController.Stop());
       
  1466 	User::LeaveIfError(iAudioControllerCustomCommands.SetSourceSampleRate(aSampleRate));
       
  1467 	}
       
  1468 
       
  1469 void CMMFMdaAudioConvertUtility::SetDestinationSampleRateL(TUint aSampleRate)
       
  1470 	{
       
  1471 	User::LeaveIfError(iController.Stop());
       
  1472 	User::LeaveIfError(iAudioControllerCustomCommands.SetSinkSampleRate(aSampleRate));
       
  1473 	}
       
  1474 
       
  1475 void CMMFMdaAudioConvertUtility::SetSourceFormatL(TUid aRecordFormat)
       
  1476 	{
       
  1477 	User::LeaveIfError(iAudioControllerCustomCommands.SetSourceFormat(aRecordFormat));
       
  1478 	}
       
  1479 
       
  1480 void CMMFMdaAudioConvertUtility::SetDestinationFormatL(TUid aRecordFormat)
       
  1481 	{
       
  1482 	User::LeaveIfError(iAudioControllerCustomCommands.SetSinkFormat(aRecordFormat));
       
  1483 	}
       
  1484 
       
  1485 void CMMFMdaAudioConvertUtility::SetSourceNumberOfChannelsL(TUint aNumberOfChannels)
       
  1486 	{
       
  1487 	User::LeaveIfError(iAudioControllerCustomCommands.SetSourceNumChannels(aNumberOfChannels));
       
  1488 	}
       
  1489 
       
  1490 void CMMFMdaAudioConvertUtility::SetDestinationNumberOfChannelsL(TUint aNumberOfChannels)
       
  1491 	{
       
  1492 	User::LeaveIfError(iAudioControllerCustomCommands.SetSinkNumChannels(aNumberOfChannels));
       
  1493 	}
       
  1494 
       
  1495 TUint CMMFMdaAudioConvertUtility::DestinationBitRateL()
       
  1496 	{
       
  1497 	TUint bitRate;
       
  1498 	User::LeaveIfError(iAudioControllerCustomCommands.GetSinkBitRate(bitRate));
       
  1499 	return bitRate;
       
  1500 	}
       
  1501 
       
  1502 TUint CMMFMdaAudioConvertUtility::DestinationSampleRateL()
       
  1503 	{
       
  1504 	TUint sampleRate;
       
  1505 	User::LeaveIfError(iAudioControllerCustomCommands.GetSinkSampleRate(sampleRate));
       
  1506 	return sampleRate;
       
  1507 	}
       
  1508 
       
  1509 TUid CMMFMdaAudioConvertUtility::DestinationFormatL()
       
  1510 	{
       
  1511 	TUid format;
       
  1512 	User::LeaveIfError(iAudioControllerCustomCommands.GetSinkFormat(format));
       
  1513 	return format;
       
  1514 	}
       
  1515 
       
  1516 TUint CMMFMdaAudioConvertUtility::DestinationNumberOfChannelsL()
       
  1517 	{
       
  1518 	TUint numChannels;
       
  1519 	User::LeaveIfError(iAudioControllerCustomCommands.GetSinkNumChannels(numChannels));
       
  1520 	return numChannels;
       
  1521 	}
       
  1522 
       
  1523 TUint CMMFMdaAudioConvertUtility::SourceBitRateL()
       
  1524 	{
       
  1525 	TUint bitRate;
       
  1526 	User::LeaveIfError(iAudioControllerCustomCommands.GetSourceBitRate(bitRate));
       
  1527 	return bitRate;
       
  1528 	}
       
  1529 
       
  1530 TUint CMMFMdaAudioConvertUtility::SourceSampleRateL()
       
  1531 	{
       
  1532 	TUint sampleRate;
       
  1533 	User::LeaveIfError(iAudioControllerCustomCommands.GetSourceSampleRate(sampleRate));
       
  1534 	return sampleRate;
       
  1535 	}
       
  1536 
       
  1537 TUid CMMFMdaAudioConvertUtility::SourceFormatL()
       
  1538 	{
       
  1539 	TUid format;
       
  1540 	User::LeaveIfError(iAudioControllerCustomCommands.GetSourceFormat(format));
       
  1541 	return format;
       
  1542 	}
       
  1543 
       
  1544 TUint CMMFMdaAudioConvertUtility::SourceNumberOfChannelsL()
       
  1545 	{
       
  1546 	TUint numChannels;
       
  1547 	User::LeaveIfError(iAudioControllerCustomCommands.GetSourceNumChannels(numChannels));
       
  1548 	return numChannels;
       
  1549 	}
       
  1550 
       
  1551 
       
  1552 void CMMFMdaAudioConvertUtility::GetSupportedConversionBitRatesL(RArray<TUint>& aSupportedBitRates)
       
  1553 	{
       
  1554 	iAudioControllerCustomCommands.GetSupportedSinkBitRatesL(aSupportedBitRates);
       
  1555 	}
       
  1556 
       
  1557 void CMMFMdaAudioConvertUtility::GetSupportedConversionSampleRatesL(RArray<TUint>& aSupportedSampleRates)
       
  1558 	{
       
  1559 	User::LeaveIfError(iController.Prime());
       
  1560 	iAudioControllerCustomCommands.GetSupportedSinkSampleRatesL(aSupportedSampleRates);
       
  1561 	User::LeaveIfError(iController.Stop());
       
  1562 	}
       
  1563 
       
  1564 void CMMFMdaAudioConvertUtility::GetSupportedConversionNumberOfChannelsL(RArray<TUint>& aSupportedNumChannels)
       
  1565 	{
       
  1566 	iAudioControllerCustomCommands.GetSupportedSinkNumChannelsL(aSupportedNumChannels);
       
  1567 	}
       
  1568 
       
  1569 CMdaAudioConvertUtility* CMMFMdaAudioConvertUtility::Parent() const
       
  1570 	{
       
  1571 	ASSERT(iParent);
       
  1572 	return static_cast<CMdaAudioConvertUtility*>(iParent);
       
  1573 	}
       
  1574 
       
  1575 TInt CMMFMdaAudioConvertUtility::CustomCommandSync(const TMMFMessageDestinationPckg& aDestination, TInt aFunction, const TDesC8& aDataTo1, const TDesC8& aDataTo2, TDes8& aDataFrom)
       
  1576 	{
       
  1577 	return iController.CustomCommandSync(aDestination, aFunction, aDataTo1, aDataTo2, aDataFrom);
       
  1578 	}
       
  1579 	
       
  1580 TInt CMMFMdaAudioConvertUtility::CustomCommandSync(const TMMFMessageDestinationPckg& aDestination, TInt aFunction, const TDesC8& aDataTo1, const TDesC8& aDataTo2)
       
  1581 	{
       
  1582 	return iController.CustomCommandSync(aDestination, aFunction, aDataTo1, aDataTo2);
       
  1583 	}
       
  1584 	
       
  1585 void CMMFMdaAudioConvertUtility::CustomCommandAsync(const TMMFMessageDestinationPckg& aDestination, TInt aFunction, const TDesC8& aDataTo1, const TDesC8& aDataTo2, TDes8& aDataFrom, TRequestStatus& aStatus)
       
  1586 	{
       
  1587 	iController.CustomCommandAsync(aDestination, aFunction, aDataTo1, aDataTo2, aDataFrom, aStatus);
       
  1588 	}
       
  1589 	
       
  1590 void CMMFMdaAudioConvertUtility::CustomCommandAsync(const TMMFMessageDestinationPckg& aDestination, TInt aFunction, const TDesC8& aDataTo1, const TDesC8& aDataTo2, TRequestStatus& aStatus)
       
  1591 	{
       
  1592 	iController.CustomCommandAsync(aDestination, aFunction, aDataTo1, aDataTo2, aStatus);
       
  1593 	}
       
  1594 
       
  1595 const CMMFControllerImplementationInformation& CMMFMdaAudioConvertUtility::ControllerImplementationInformationL()
       
  1596 	{
       
  1597 	if (!iControllerImplementationInformation)
       
  1598 		{
       
  1599 		if (iControllerUid==KNullUid)
       
  1600 			User::Leave(KErrNotReady);
       
  1601 		iControllerImplementationInformation = CMMFControllerImplementationInformation::NewL(iControllerUid);
       
  1602 		}
       
  1603 	return *iControllerImplementationInformation;
       
  1604 	}
       
  1605 
       
  1606 
       
  1607 void CMMFMdaAudioConvertUtility::Reset()
       
  1608 	{
       
  1609 	// Make sure any existing controller is closed.
       
  1610 	Close();
       
  1611 
       
  1612 	iSourceFormatUid = KNullUid;
       
  1613 	iSinkFormatUid = KNullUid;
       
  1614 	iSourceDataType = KMMFFourCCCodeNULL;
       
  1615 	iSinkDataType = KMMFFourCCCodeNULL;
       
  1616 	iSourceSampleRate = 0;
       
  1617 	iSinkSampleRate = 0;
       
  1618 	iSourceChannels = 0;
       
  1619 	iSinkChannels = 0;
       
  1620 	}
       
  1621 
       
  1622 
       
  1623 TInt CMMFMdaAudioConvertUtility::ControllerOpen()
       
  1624 	{
       
  1625 	TInt err = KErrNone;
       
  1626 
       
  1627 	if(iSourceFormatUid != KNullUid)
       
  1628 		TRAP(err, SetSourceFormatL(iSourceFormatUid));
       
  1629 
       
  1630 	if(!err && iSinkFormatUid != KNullUid)
       
  1631 		TRAP(err, SetDestinationFormatL(iSinkFormatUid));
       
  1632 
       
  1633 	if(!err && iSourceDataType != KMMFFourCCCodeNULL)
       
  1634 		{
       
  1635 		TRAP(err, SetSourceDataTypeL(iSourceDataType));
       
  1636 		}
       
  1637 
       
  1638 	if(!err && iSinkDataType != KMMFFourCCCodeNULL)
       
  1639 		{
       
  1640 		TRAP(err, SetDestinationDataTypeL(iSinkDataType));
       
  1641 		}
       
  1642 
       
  1643 	// set the audio data settings ie sample rate & channels
       
  1644 	if (!err && iSourceSampleRate != 0)
       
  1645 		{
       
  1646 		TRAP(err, SetSourceSampleRateL(iSourceSampleRate));
       
  1647 		}
       
  1648 
       
  1649 	if (!err && iSourceChannels != 0)
       
  1650 		{
       
  1651 		TRAP(err, SetSourceNumberOfChannelsL(iSourceChannels));
       
  1652 		}
       
  1653 
       
  1654 	if (!err && iSinkSampleRate != 0)
       
  1655 		{
       
  1656 		TRAP(err, SetDestinationSampleRateL(iSinkSampleRate));
       
  1657 		}
       
  1658 
       
  1659 	if (!err && iSinkChannels != 0)
       
  1660 		{
       
  1661 		TRAP(err, SetDestinationNumberOfChannelsL(iSinkChannels));
       
  1662 		}
       
  1663 
       
  1664 	//get the clip duration
       
  1665 	if (!err)
       
  1666 		{
       
  1667 		iDuration = TTimeIntervalMicroSeconds(0);
       
  1668 		err = iController.GetDuration(iDuration);
       
  1669 		}
       
  1670 
       
  1671 	if (err)
       
  1672 		Close();
       
  1673 	else
       
  1674 		iState = CMdaAudioClipUtility::EOpen;
       
  1675 	
       
  1676 	return err;
       
  1677 	}
       
  1678 
       
  1679 
       
  1680 void CMMFMdaAudioConvertUtility::ConfigureSourceSinkL(TMdaClipLocation* aPriLocation, TMdaClipLocation* aSecLocation)
       
  1681 	{
       
  1682 	TMMFDescriptorConfig srcDesCfg;
       
  1683 	TMMFFileConfig srcFileCfg;
       
  1684 	CBufFlat* srcCfgBuffer = NULL;
       
  1685 	CMMFUrlParams* srcURLCfg = NULL;
       
  1686 	TPtrC8 sourceCfg;
       
  1687 	TUid sourceUid = KNullUid;
       
  1688 
       
  1689 	TMMFDescriptorConfig dstDesCfg;
       
  1690 	TMMFFileConfig dstFileCfg;
       
  1691 	CBufFlat* dstCfgBuffer = NULL;
       
  1692 	CMMFUrlParams* dstURLCfg = NULL;
       
  1693 	TPtrC8 dstCfg;
       
  1694 	TUid dstUid = KNullUid;
       
  1695 
       
  1696 	TInt err = KErrNone;
       
  1697 
       
  1698 	// setup the source config info
       
  1699 	if (aPriLocation->Uid() == KUidMdaFileResLoc)
       
  1700 		{//sink clip location is a file
       
  1701 		TDesC& fileName = ((TMdaFileClipLocation*)aPriLocation)->iName;		
       
  1702 		srcFileCfg().iPath = fileName;
       
  1703 		sourceCfg.Set(srcFileCfg);
       
  1704 		sourceUid = KUidMmfFileSource;
       
  1705 		}
       
  1706 	else if (aPriLocation->Uid() == KUidMdaDesResLoc)
       
  1707 		{//sink clip is a descriptor - pass down descriptor & thread id
       
  1708 		TMdaDesClipLocation* srcLoc = (TMdaDesClipLocation*)aPriLocation;
       
  1709 		srcDesCfg().iDes = srcLoc->iDes;
       
  1710 		srcDesCfg().iDesThreadId = srcLoc->iThreadId;
       
  1711 		sourceCfg.Set(srcDesCfg);
       
  1712 		sourceUid = KUidMmfDescriptorSource;
       
  1713 		}
       
  1714 	else if (aPriLocation->Uid() == KUidMdaUrlResLoc)
       
  1715 		{
       
  1716 		TMdaUrlClipLocation* srcLoc = (TMdaUrlClipLocation*)aPriLocation;
       
  1717 		srcURLCfg = CMMFUrlParams::NewLC(srcLoc->iUrl, srcLoc->iIapId);
       
  1718 		srcCfgBuffer = srcURLCfg->ExternalizeToCBufFlatLC();
       
  1719 		sourceCfg.Set(srcCfgBuffer->Ptr(0));
       
  1720 		sourceUid = KUidMmfUrlSource;
       
  1721 		}
       
  1722 	else
       
  1723 		{
       
  1724 		err = KErrNotSupported;
       
  1725 		}
       
  1726 
       
  1727 	if (!err)
       
  1728 		{
       
  1729 		if (aSecLocation->Uid() == KUidMdaFileResLoc)
       
  1730 			{//sink clip location is a file
       
  1731 			TDesC& fileName = ((TMdaFileClipLocation*)aSecLocation)->iName;
       
  1732 			dstFileCfg().iPath = fileName;
       
  1733 			dstCfg.Set(dstFileCfg);
       
  1734 			dstUid = KUidMmfFileSink;
       
  1735 			}
       
  1736 		else if (aSecLocation->Uid() == KUidMdaDesResLoc)
       
  1737 			{//sink clip is a descriptor - pass down descriptor & thread id
       
  1738 			TMdaDesClipLocation* desLoc = (TMdaDesClipLocation*)aSecLocation;
       
  1739 			dstDesCfg().iDes = desLoc->iDes;
       
  1740 			dstDesCfg().iDesThreadId = desLoc->iThreadId;
       
  1741 			dstCfg.Set(dstDesCfg);
       
  1742 			dstUid = KUidMmfDescriptorSink;
       
  1743 			}
       
  1744 		else if (aSecLocation->Uid() == KUidMdaUrlResLoc)
       
  1745 			{
       
  1746 			TMdaUrlClipLocation* desLoc = (TMdaUrlClipLocation*)aSecLocation;
       
  1747 			dstURLCfg = CMMFUrlParams::NewLC(desLoc->iUrl, desLoc->iIapId);
       
  1748 			dstCfgBuffer = dstURLCfg->ExternalizeToCBufFlatLC();
       
  1749 			dstCfg.Set(dstCfgBuffer->Ptr(0));
       
  1750 			dstUid = KUidMmfUrlSink;
       
  1751 			}
       
  1752 		else
       
  1753 			{
       
  1754 			err = KErrNotSupported;
       
  1755 			}
       
  1756 		}
       
  1757 
       
  1758 	if (!err)
       
  1759 		{
       
  1760 		iFindAndOpenController->ConfigureSourceSink(
       
  1761 			CMMFFindAndOpenController::TSourceSink(sourceUid, sourceCfg), 
       
  1762 			CMMFFindAndOpenController::TSourceSink(dstUid, dstCfg));
       
  1763 		}
       
  1764 
       
  1765 	if (dstCfgBuffer)
       
  1766 		CleanupStack::PopAndDestroy(2);	//dstCfgBuffer, dstURLCfg
       
  1767 	if (srcCfgBuffer)
       
  1768 		CleanupStack::PopAndDestroy(2); //srcCfgBuffer, srcURLCfg
       
  1769 
       
  1770 	User::LeaveIfError(err);
       
  1771 	}
       
  1772 
       
  1773 
       
  1774 TInt CMMFMdaAudioConvertUtility::SetThreadPriority(const TThreadPriority& aThreadPriority) const
       
  1775 	{
       
  1776 	return iController.SetThreadPriority(aThreadPriority);
       
  1777 	}
       
  1778 
       
  1779 
       
  1780 
       
  1781 
       
  1782