00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include <mmffile.h>
00033 #include <ecom.h>
00034 #include <mmfformatimplementationuids.hrh>
00035 #include <mmffourcc.h>
00036
00037 #include "mmfrawformat.h"
00038 #include "UIDs.hrh"
00039
00040 const TUint KFormatDefaultFrameSize(0x1000);
00041 const TUint KDefineIOBufferSize(0x0200);
00042 const TUint KOneSecondInMicroSeconds(1000000);
00043 const TUint KMono(1);
00044 const TUint KStereo(2);
00045
00046 const TUint KRawSampleRates[] = { 8000, 11025, 22050, 44100 };
00047
00048
00049
00050
00051
00052
00053
00054 CMMFFormatDecode* CMMFRawFormatRead::NewL(MDataSource* aSource)
00055 {
00056 if ((aSource->DataSourceType()==KUidMmfDescriptorSource)||
00057 (aSource->DataSourceType()==KUidMmfFileSource))
00058 {
00059 CMMFRawFormatRead* self = new(ELeave)CMMFRawFormatRead;
00060 CleanupStack::PushL(self);
00061 self->ConstructL(aSource);
00062 CleanupStack::Pop();
00063 return self;
00064 }
00065 else return NULL;
00066 }
00067
00068
00069 CMMFRawFormatRead::~CMMFRawFormatRead()
00070 {
00071 delete iBuffer;
00072 }
00073
00074
00075 void CMMFRawFormatRead::ConstructL(MDataSource* aSource)
00076 {
00077
00078 iClip = aSource;
00079 User::LeaveIfError(iClip->SourceThreadLogon(*this));
00080 iClip->SourcePrimeL();
00081 iFrameSize = KFormatDefaultFrameSize;
00082 iClipLength = (static_cast<CMMFClip*>(iClip))->Size();
00083 }
00084
00085
00086
00087
00088 void CMMFRawFormatRead::FillBufferL(CMMFBuffer* aBuffer, MDataSink* aConsumer, TMediaId aMediaId )
00089 {
00090
00091 if (aMediaId.iMediaType != KUidMediaTypeAudio) User::Leave(KErrNotSupported);
00092 iDataPath = aConsumer;
00093
00094 TUint position = ((aBuffer->FrameNumber()-1)*iFrameSize)+iStartPosition;
00095 (static_cast<CMMFClip*>(iClip))->ReadBufferL(aBuffer, position, this);
00096
00097 }
00098
00099
00100
00101 CMMFBuffer* CMMFRawFormatRead::CreateSourceBufferL(TMediaId aMediaId, CMMFBuffer& aSinkBuffer, TBool &aReference)
00102 {
00103 if (aMediaId.iMediaType == KUidMediaTypeAudio)
00104 {
00105 NegotiateSourceBufferL(aSinkBuffer);
00106 return CreateSourceBufferL(aMediaId, aReference);
00107 }
00108 else User::Leave(KErrNotSupported);
00109 return NULL;
00110 }
00111
00112
00113 CMMFBuffer* CMMFRawFormatRead::CreateSourceBufferL(TMediaId aMediaId, TBool &aReference)
00114 {
00115 if (aMediaId.iMediaType == KUidMediaTypeAudio)
00116 {
00117
00118 if (!iFrameSize) iFrameSize = KFormatDefaultFrameSize;
00119
00120 aReference = EFalse;
00121 return CreateSourceBufferOfSizeL(iFrameSize);
00122 }
00123 else User::Leave(KErrNotSupported);
00124 return NULL;
00125 }
00126
00127
00128 CMMFDataBuffer* CMMFRawFormatRead::CreateSourceBufferOfSizeL(TUint aSize)
00129 {
00130
00131 CMMFDataBuffer* buffer = CMMFDataBuffer::NewL(aSize);
00132 buffer->Data().FillZ(aSize);
00133 return buffer;
00134 }
00135
00136
00137 void CMMFRawFormatRead::NegotiateSourceBufferL(CMMFBuffer& aSinkBuffer)
00138 {
00139
00140 if (aSinkBuffer.Type() == KUidMmfDataBuffer)
00141 {
00142
00143 TUint sinkBufferLength = (static_cast<CMMFDataBuffer&>(aSinkBuffer)).Data().MaxLength();
00144 if (sinkBufferLength == 0) sinkBufferLength = KFormatDefaultFrameSize;
00145 iFrameSize = sinkBufferLength;
00146 CalculateFrameTimeInterval();
00147 }
00148 else
00149 User::Leave(KErrNotSupported);
00150 }
00151
00152
00153 TFourCC CMMFRawFormatRead::SourceDataTypeCode(TMediaId aMediaId)
00154 {
00155 if (aMediaId.iMediaType == KUidMediaTypeAudio) return iFourCC;
00156 else return TFourCC();
00157 }
00158
00159
00160 TInt CMMFRawFormatRead::SetSourceDataTypeCode(TFourCC aSinkFourCC, TMediaId aMediaId)
00161 {
00162 if (aMediaId.iMediaType != KUidMediaTypeAudio) return KErrNotSupported;
00163 else iFourCC = aSinkFourCC;
00164
00165 if ((iFourCC == KMMFFourCCCodePCM16) ||
00166 (iFourCC == KMMFFourCCCodePCM16B) ||
00167 (iFourCC == KMMFFourCCCodePCMU16))
00168 iBitsPerSample = 16;
00169 else if ((iFourCC == KMMFFourCCCodeIMAD) ||
00170 (iFourCC == KMMFFourCCCodeIMAS))
00171 iBitsPerSample = 4;
00172 else
00173 iBitsPerSample = 8;
00174 return KErrNone;
00175 }
00176
00177
00178 TInt CMMFRawFormatRead::SourceThreadLogon(MAsyncEventHandler& aEventHandler)
00179 {
00180 return(iClip->SourceThreadLogon(aEventHandler));
00181 }
00182
00183
00184 void CMMFRawFormatRead::SourcePrimeL()
00185 {
00186 iClip->SourcePrimeL();
00187 CalculateFrameTimeInterval();
00188 }
00189
00190
00191 void CMMFRawFormatRead::SourcePlayL()
00192 {
00193 iClip->SourcePlayL();
00194 }
00195
00196
00197 void CMMFRawFormatRead::SourcePauseL()
00198 {
00199 iClip->SourcePauseL();
00200 }
00201
00202
00203 void CMMFRawFormatRead::SourceStopL()
00204 {
00205 iClip->SourceStopL();
00206 }
00207
00208
00209 void CMMFRawFormatRead::SourceThreadLogoff()
00210 {
00211 iClip->SourceThreadLogoff();
00212 }
00213
00214
00215
00216
00217 void CMMFRawFormatRead::BufferFilledL(CMMFBuffer* aBuffer)
00218 {
00219
00220 TTimeIntervalMicroSeconds position =
00221 TTimeIntervalMicroSeconds(TInt64(aBuffer->FrameNumber()-1)*iFrameTimeInterval.Int64());
00222 aBuffer->SetTimeToPlay(position);
00223 iDataPath->BufferFilledL(aBuffer);
00224 }
00225
00226
00227
00228
00229
00230 TUint CMMFRawFormatRead::Streams(TUid aMediaType) const
00231 {
00232
00233 if (aMediaType == KUidMediaTypeAudio) return 1;
00234 else return 0;
00235 }
00236
00237
00238 TTimeIntervalMicroSeconds CMMFRawFormatRead::FrameTimeInterval(TMediaId aMediaId) const
00239 {
00240 if (aMediaId.iMediaType == KUidMediaTypeAudio) return iFrameTimeInterval;
00241 else return TTimeIntervalMicroSeconds(0);
00242 }
00243
00244
00245 TTimeIntervalMicroSeconds CMMFRawFormatRead::Duration(TMediaId aMediaId) const
00246 {
00247 if ((aMediaId.iMediaType == KUidMediaTypeAudio) &&
00248 (iClipLength) && (iSampleRate) && (iBitsPerSample) && (iChannels))
00249 {
00250 TInt64 clipLength(iClipLength);
00251 clipLength*=KOneSecondInMicroSeconds;
00252 TTimeIntervalMicroSeconds duration = TTimeIntervalMicroSeconds(clipLength/iSampleRate);
00253 duration = TTimeIntervalMicroSeconds(duration.Int64()/(iBitsPerSample*iChannels));
00254 duration = TTimeIntervalMicroSeconds(duration.Int64()*8);
00255 return duration;
00256 }
00257 else return TTimeIntervalMicroSeconds(0);
00258 }
00259
00260
00261 void CMMFRawFormatRead::CalculateFrameTimeInterval()
00262 {
00263 if ((iFrameSize) && (iSampleRate) && (iBitsPerSample) && (iChannels))
00264 {
00265 iFrameTimeInterval = TTimeIntervalMicroSeconds((iFrameSize*KOneSecondInMicroSeconds)/iSampleRate);
00266 iFrameTimeInterval =
00267 TTimeIntervalMicroSeconds(iFrameTimeInterval.Int64()/(iBitsPerSample*iChannels));
00268 iFrameTimeInterval = TTimeIntervalMicroSeconds(iFrameTimeInterval.Int64()*8);
00269 }
00270 }
00271
00272
00273 void CMMFRawFormatRead::SuggestSourceBufferSize(TUint aSuggestedBufferSize)
00274 {
00275 iFrameSize = aSuggestedBufferSize;
00276 CalculateFrameTimeInterval();
00277 }
00278
00279
00280 TInt CMMFRawFormatRead::SetNumChannels(TUint aChannels)
00281 {
00282 TInt error = KErrNone;
00283 if ((aChannels == KMono)||(aChannels == KStereo)) iChannels = aChannels;
00284 else error = KErrNotSupported;
00285 return error;
00286 }
00287
00288
00289 TInt CMMFRawFormatRead::SetSampleRate(TUint aSampleRate)
00290 {
00291 TInt status = KErrNotSupported;
00292
00293 TInt i = sizeof(KRawSampleRates) / sizeof(TUint);
00294
00295 while ((i--) && (status != KErrNone))
00296 {
00297 if (aSampleRate == KRawSampleRates[i])
00298 {
00299 iSampleRate = aSampleRate;
00300 status = KErrNone;
00301 }
00302 }
00303 return status;
00304 }
00305
00306
00307 void CMMFRawFormatRead::DoReadL(TInt aReadPosition)
00308 {
00309 STATIC_CAST(CMMFClip*,iClip)->ReadBufferL(iBuffer,aReadPosition);
00310 }
00311
00312
00313 void CMMFRawFormatRead::GetSupportedSampleRatesL(RArray<TUint>& aSampleRates)
00314 {
00315 aSampleRates.Reset();
00316
00317
00318 TInt i = sizeof(KRawSampleRates) / sizeof(TUint);
00319
00320 while (i--)
00321 {
00322 User::LeaveIfError(aSampleRates.Append(KRawSampleRates[i]));
00323 }
00324 }
00325
00326
00327 void CMMFRawFormatRead::GetSupportedNumChannelsL(RArray<TUint>& aNumChannels)
00328 {
00329 aNumChannels.Reset();
00330 User::LeaveIfError(aNumChannels.Append(KMono));
00331 User::LeaveIfError(aNumChannels.Append(KStereo));
00332 }
00333
00334
00335 void CMMFRawFormatRead::GetSupportedDataTypesL(TMediaId aMediaId, RArray<TFourCC>& aDataTypes)
00336 {
00337 if (aMediaId.iMediaType != KUidMediaTypeAudio)
00338 User::Leave(KErrNotSupported);
00339 aDataTypes.Reset();
00340 User::LeaveIfError(aDataTypes.Append(KMMFFourCCCodePCM16));
00341 User::LeaveIfError(aDataTypes.Append(KMMFFourCCCodePCM16B));
00342 User::LeaveIfError(aDataTypes.Append(KMMFFourCCCodePCMU16));
00343 User::LeaveIfError(aDataTypes.Append(KMMFFourCCCodeIMAD));
00344 User::LeaveIfError(aDataTypes.Append(KMMFFourCCCodeIMAS));
00345 }
00346
00347
00348
00349
00350
00351
00352
00353 CMMFFormatEncode* CMMFRawFormatWrite::NewL(MDataSink* aSink)
00354 {
00355 if ((aSink->DataSinkType()==KUidMmfDescriptorSink)||
00356 (aSink->DataSinkType()==KUidMmfFileSink))
00357 {
00358 CMMFRawFormatWrite* self = new(ELeave)CMMFRawFormatWrite;
00359 CleanupStack::PushL(self);
00360 self->ConstructL(aSink);
00361 CleanupStack::Pop();
00362 return STATIC_CAST(CMMFFormatEncode*, self);
00363 }
00364 else return NULL;
00365 }
00366
00367
00368 CMMFRawFormatWrite::~CMMFRawFormatWrite()
00369 {
00370 delete iBuffer;
00371 delete iConvertBuffer;
00372 delete iChannelAndSampleRateConverterFactory;
00373 }
00374
00375
00376 void CMMFRawFormatWrite::ConstructL(MDataSink* aSink)
00377 {
00378 iClip = aSink;
00379
00380 User::LeaveIfError(iClip->SinkThreadLogon(*this));
00381 iClip->SinkPrimeL();
00382 iBuffer = CreateSinkBufferOfSizeL(KDefineIOBufferSize);
00383 DoReadL(0);
00384 if (iBuffer->Data().Size()> 0)
00385 {
00386 iClipAlreadyExists = ETrue;
00387
00388 iDataSize = iClipLength = STATIC_CAST(CMMFClip*,iClip)->Size();
00389 }
00390 iFrameSize = KFormatDefaultFrameSize;
00391 }
00392
00393
00394
00395
00396 TInt CMMFRawFormatWrite::SinkThreadLogon(MAsyncEventHandler& aEventHandler)
00397 {
00398 return(iClip->SinkThreadLogon(aEventHandler));
00399 }
00400
00401
00402 void CMMFRawFormatWrite::CalculateFrameTimeInterval()
00403 {
00404 if ((iFrameSize) && (iSampleRate) && (iBitsPerSample) && (iChannels))
00405 {
00406 iFrameTimeInterval = TTimeIntervalMicroSeconds((iFrameSize*KOneSecondInMicroSeconds)/iSampleRate);
00407 iFrameTimeInterval =
00408 TTimeIntervalMicroSeconds((iFrameTimeInterval.Int64())/(iBitsPerSample*iChannels));
00409 iFrameTimeInterval = TTimeIntervalMicroSeconds(iFrameTimeInterval.Int64()*8);
00410 }
00411 }
00412
00413
00414 void CMMFRawFormatWrite::Negotiate(MDataSource& aSource)
00415 {
00416 if (aSource.DataSourceType() == KUidMmfAudioInput)
00417 {
00418
00419 iSourceSampleRate = 8000;
00420 iSourceChannels = 1;
00421 iSourceFourCC.Set(KMMFFourCCCodePCM16);
00422 }
00423 else if (aSource.DataSourceType() == KUidMmfFormatDecode)
00424 {
00425 iSourceSampleRate = ((CMMFFormatDecode&)aSource).SampleRate();
00426 iSourceChannels = ((CMMFFormatDecode&)aSource).NumChannels();
00427 iSourceFourCC.Set(aSource.SourceDataTypeCode(TMediaId(KUidMediaTypeAudio)));
00428 iSourceWillSampleConvert = STATIC_CAST(CMMFFormatDecode&, aSource).SourceSampleConvert();
00429 ((CMMFFormatDecode&)aSource).SuggestSourceBufferSize(iFrameSize);
00430
00431 }
00432 else return;
00433
00434 if (iClipAlreadyExists) iStartPosition = iClipLength;
00435 if (!iSampleRate) iSampleRate = iSourceSampleRate;
00436 if (!iChannels) iChannels = iSourceChannels;
00437 if (!iBitsPerSample)
00438 {
00439 iFourCC.Set(iSourceFourCC);
00440 if ((iFourCC == KMMFFourCCCodePCM16) ||
00441 (iFourCC == KMMFFourCCCodePCM16B) ||
00442 (iFourCC == KMMFFourCCCodePCMU16))
00443 iBitsPerSample = 16;
00444 else if ((iFourCC == KMMFFourCCCodeIMAD) ||
00445 (iFourCC == KMMFFourCCCodeIMAS))
00446 iBitsPerSample = 4;
00447 else
00448 iBitsPerSample = 8;
00449 }
00450 CalculateFrameTimeInterval();
00451 }
00452
00453
00454 void CMMFRawFormatWrite::SinkPrimeL()
00455 {
00456 iClip->SinkPrimeL();
00457 CalculateFrameTimeInterval();
00458 }
00459
00460
00461 void CMMFRawFormatWrite::SinkPlayL()
00462 {
00463 iClip->SinkPlayL();
00464 if ((iChannels != iSourceChannels) || (iSampleRate != iSourceSampleRate) && (!iSourceWillSampleConvert))
00465 {
00466
00467 if (iFourCC != KMMFFourCCCodePCM16) User::Leave(KErrNotSupported);
00468 iChannelAndSampleRateConverterFactory
00469 = new(ELeave)CMMFChannelAndSampleRateConverterFactory;
00470 iChannelAndSampleRateConverter =
00471 iChannelAndSampleRateConverterFactory->CreateConverterL( iSourceSampleRate, iSourceChannels,
00472 iSampleRate, iChannels);
00473
00474 TUint convertedBufferFrameSize = (iFrameSize*iChannels)/iSourceChannels;
00475 iConvertBuffer = CreateSinkBufferOfSizeL(convertedBufferFrameSize);
00476 }
00477 iFileHasChanged = ETrue;
00478 }
00479
00480
00481 void CMMFRawFormatWrite::SinkPauseL()
00482 {
00483 iClip->SinkPauseL();
00484 }
00485
00486
00487 void CMMFRawFormatWrite::SinkStopL()
00488 {
00489 iClip->SinkStopL();
00490 }
00491
00492
00493 void CMMFRawFormatWrite::SinkThreadLogoff()
00494 {
00495 iClip->SinkThreadLogoff();
00496 }
00497
00498
00499 void CMMFRawFormatWrite::EmptyBufferL(CMMFBuffer* aBuffer, MDataSource* aSupplier, TMediaId aMediaId)
00500 {
00501
00502
00503
00504 if (aMediaId.iMediaType!=KUidMediaTypeAudio) User::Leave(KErrNotSupported);
00505 iDataPath = aSupplier;
00506
00507
00508 if (iMaximumClipSize > 0)
00509 {
00510
00511 TInt currentClipLength = STATIC_CAST(CMMFClip*, iClip)->Size();
00512 TInt bufferSize = aBuffer->BufferSize();
00513 if ((currentClipLength + bufferSize) >= iMaximumClipSize)
00514 User::Leave(KErrEof);
00515 }
00516
00517
00518 iBufferToEmpty = aBuffer;
00519 TInt position = ((aBuffer->FrameNumber()-1)*iFrameSize)+iStartPosition;
00520 if (position < (TInt)iStartPosition) position = iStartPosition;
00521 if ((iChannelAndSampleRateConverter) && (!iSourceWillSampleConvert))
00522 {
00523 iFrameSize = iChannelAndSampleRateConverter->Convert(*(CMMFDataBuffer*)aBuffer,*iConvertBuffer);
00524 STATIC_CAST(CMMFClip*,iClip)->WriteBufferL(iConvertBuffer, position, this);
00525 }
00526 else
00527 {
00528 STATIC_CAST(CMMFClip*,iClip)->WriteBufferL(aBuffer, position, this);
00529 }
00530 iPos = position;
00531 }
00532
00533
00534 CMMFDataBuffer* CMMFRawFormatWrite::CreateSinkBufferOfSizeL(TUint aSize)
00535 {
00536
00537 CMMFDataBuffer* buffer = CMMFDataBuffer::NewL(aSize);
00538 buffer->Data().FillZ(aSize);
00539 iBufferCreated = ETrue;
00540 return buffer;
00541 }
00542
00543
00544 CMMFBuffer* CMMFRawFormatWrite::CreateSinkBufferL(TMediaId aMediaId, TBool &aReference)
00545 {
00546 if (aMediaId.iMediaType == KUidMediaTypeAudio)
00547 {
00548 if (!iFrameSize) iFrameSize = KFormatDefaultFrameSize;
00549 aReference = EFalse;
00550 return CreateSinkBufferOfSizeL(iFrameSize);
00551 }
00552 else User::Leave(KErrNotSupported);
00553 return NULL;
00554 }
00555
00556
00557 TFourCC CMMFRawFormatWrite::SinkDataTypeCode(TMediaId aMediaId)
00558 {
00559 if (aMediaId.iMediaType == KUidMediaTypeAudio) return iFourCC;
00560 else return TFourCC();
00561 }
00562
00563
00564 TInt CMMFRawFormatWrite::SetSinkDataTypeCode(TFourCC aSinkFourCC, TMediaId aMediaId)
00565 {
00566 if (aMediaId.iMediaType != KUidMediaTypeAudio) return KErrNotSupported;
00567 else iFourCC = aSinkFourCC;
00568
00569 if ((iFourCC == KMMFFourCCCodePCM16) ||
00570 (iFourCC == KMMFFourCCCodePCM16B) ||
00571 (iFourCC == KMMFFourCCCodePCMU16))
00572 iBitsPerSample = 16;
00573 else if ((iFourCC == KMMFFourCCCodeIMAD) ||
00574 (iFourCC == KMMFFourCCCodeIMAS))
00575 iBitsPerSample = 4;
00576 else
00577 iBitsPerSample = 8;
00578
00579 return KErrNone;
00580 }
00581
00582
00583 void CMMFRawFormatWrite::DoReadL(TInt aReadPosition)
00584 {
00585 STATIC_CAST(CMMFClip*,iClip)->ReadBufferL(iBuffer,aReadPosition);
00586 }
00587
00588
00589 void CMMFRawFormatWrite::DoWriteL(TInt aWritePosition)
00590 {
00591 STATIC_CAST(CMMFClip*,iClip)->WriteBufferL(iBuffer,aWritePosition);
00592 }
00593
00594
00595
00596
00597
00598 void CMMFRawFormatWrite::BufferEmptiedL(CMMFBuffer* aBuffer)
00599 {
00600 iDataSize+=aBuffer->BufferSize();
00601 iPos += aBuffer->BufferSize();
00602 if (iMaxPos < iPos) iMaxPos = iPos;
00603 if (iBufferToEmpty != aBuffer) iDataPath->BufferEmptiedL(iBufferToEmpty);
00604 else iDataPath->BufferEmptiedL(aBuffer);
00605 }
00606
00607
00608
00609
00610
00611 TInt CMMFRawFormatWrite::SetNumChannels(TUint aChannels)
00612 {
00613 TInt error = KErrNone;
00614 if ((aChannels == KMono)||(aChannels == KStereo)) iChannels = aChannels;
00615 else error = KErrNotSupported;
00616 return error;
00617 }
00618
00619
00620 TInt CMMFRawFormatWrite::SetSampleRate(TUint aSampleRate)
00621 {
00622 TInt status = KErrNotSupported;
00623
00624 TInt i = sizeof(KRawSampleRates) / sizeof(TUint);
00625
00626 while ((i--) && (status != KErrNone))
00627 {
00628 if (aSampleRate == KRawSampleRates[i])
00629 {
00630 iSampleRate = aSampleRate;
00631 status = KErrNone;
00632 }
00633 }
00634 return status;
00635 }
00636
00637
00638 TTimeIntervalMicroSeconds CMMFRawFormatWrite::FrameTimeInterval(TMediaId aMediaId) const
00639 {
00640 if (aMediaId.iMediaType == KUidMediaTypeAudio) return iFrameTimeInterval;
00641 else return TTimeIntervalMicroSeconds(0);
00642 }
00643
00644
00645 TTimeIntervalMicroSeconds CMMFRawFormatWrite::Duration(TMediaId aMediaId) const
00646 {
00647 if ((aMediaId.iMediaType == KUidMediaTypeAudio)
00648 && (iDataSize) && (iSampleRate) && (iBitsPerSample) && (iChannels))
00649 {
00650 TInt64 clipLength(iDataSize);
00651 clipLength*=KOneSecondInMicroSeconds;
00652 TTimeIntervalMicroSeconds duration = TTimeIntervalMicroSeconds(clipLength/iSampleRate);
00653 duration =
00654 TTimeIntervalMicroSeconds(duration.Int64()/(iBitsPerSample*iChannels));
00655 duration = TTimeIntervalMicroSeconds(duration.Int64()*8);
00656 return duration;
00657 }
00658 else return TTimeIntervalMicroSeconds(0);
00659 }
00660
00661
00662 TInt64 CMMFRawFormatWrite::BytesPerSecond()
00663 {
00664 TInt64 bitsPerSecond = iSampleRate * iBitsPerSample * iChannels ;
00665 TInt64 bytesPerSecond = bitsPerSecond/8;
00666 return bytesPerSecond ;
00667 }
00668
00669
00670 void CMMFRawFormatWrite::CropL(TTimeIntervalMicroSeconds aPosition, TBool aToEnd )
00671 {
00672
00673 if (!(STATIC_CAST(CMMFClip*,iClip)->Size())) User::Leave(KErrNotFound);
00674
00675
00676
00677 if ( ( aPosition < TTimeIntervalMicroSeconds(0) ) || ( aPosition >= Duration( KUidMediaTypeAudio) ) )
00678 User::Leave( KErrArgument ) ;
00679
00680
00681
00682 TInt64 cropPosition64 =
00683 TInt64( ( aPosition.Int64() * iSampleRate * (iBitsPerSample/8) * iChannels ) /KOneSecondInMicroSeconds);
00684 TUint cropPosition = I64INT(cropPosition64);
00685
00686
00687
00688 TUint dataSize ;
00689
00690 if ( !aToEnd )
00691 {
00692
00693
00694
00695 dataSize = iMaxPos - cropPosition ;
00696 if (( dataSize > 0 ) && (aPosition != TTimeIntervalMicroSeconds(0)))
00697 {
00698 TUint bufSize = ( dataSize < KDefineIOBufferSize ? dataSize : KDefineIOBufferSize ) ;
00699 CMMFDataBuffer* buffer = CMMFDataBuffer::NewL(bufSize) ;
00700 CleanupStack::PushL( buffer ) ;
00701
00702 TUint rPos = cropPosition ;
00703 TUint wPos = 0;
00704 TInt dataToShift = ETrue ;
00705 while ( dataToShift )
00706 {
00707 STATIC_CAST( CMMFClip*, iClip )->ReadBufferL( buffer, rPos ) ;
00708 STATIC_CAST( CMMFClip*, iClip )->WriteBufferL( buffer, wPos ) ;
00709 if ( rPos > iMaxPos )
00710 dataToShift = EFalse ;
00711 else
00712 {
00713 rPos += bufSize ;
00714 wPos += bufSize ;
00715 }
00716 }
00717 CleanupStack::PopAndDestroy( ) ;
00718 }
00719 }
00720 else
00721 dataSize = cropPosition ;
00722
00723 iDataSize = dataSize ;
00724 iMaxPos = dataSize ;
00725
00726
00727 if ( iClip->DataSinkType() == KUidMmfFileSink )
00728 {
00729 STATIC_CAST( CMMFFile*, iClip )->FileL().SetSize( iMaxPos ) ;
00730 iClipLength = iMaxPos;
00731 }
00732 }
00733
00734
00735 void CMMFRawFormatWrite::GetSupportedSampleRatesL(RArray<TUint>& aSampleRates)
00736 {
00737 aSampleRates.Reset();
00738
00739
00740 TInt i = sizeof(KRawSampleRates) / sizeof(TUint);
00741
00742 while (i--)
00743 {
00744 User::LeaveIfError(aSampleRates.Append(KRawSampleRates[i]));
00745 }
00746 }
00747
00748
00749 void CMMFRawFormatWrite::GetSupportedNumChannelsL(RArray<TUint>& aNumChannels)
00750 {
00751 aNumChannels.Reset();
00752 User::LeaveIfError(aNumChannels.Append(KMono));
00753 User::LeaveIfError(aNumChannels.Append(KStereo));
00754 }
00755
00756
00757 void CMMFRawFormatWrite::SetMaximumClipSize(TInt aBytes)
00758 {
00759 iMaximumClipSize = aBytes;
00760 }
00761
00762
00763 void CMMFRawFormatWrite::GetSupportedDataTypesL(TMediaId aMediaId, RArray<TFourCC>& aDataTypes)
00764 {
00765 if (aMediaId.iMediaType != KUidMediaTypeAudio)
00766 User::Leave(KErrNotSupported);
00767 aDataTypes.Reset();
00768 User::LeaveIfError(aDataTypes.Append(KMMFFourCCCodePCM16));
00769 User::LeaveIfError(aDataTypes.Append(KMMFFourCCCodePCM16B));
00770 User::LeaveIfError(aDataTypes.Append(KMMFFourCCCodePCMU16));
00771 User::LeaveIfError(aDataTypes.Append(KMMFFourCCCodeIMAD));
00772 User::LeaveIfError(aDataTypes.Append(KMMFFourCCCodeIMAS));
00773 }
00774
00775
00776
00777
00778
00779
00780 const TImplementationProxy ImplementationTable[] =
00781 {
00782 IMPLEMENTATION_PROXY_ENTRY(KRawDecoder, CMMFRawFormatRead::NewL),
00783 IMPLEMENTATION_PROXY_ENTRY(KRawEncoder, CMMFRawFormatWrite::NewL)
00784 };
00785
00786 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
00787 {
00788 aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
00789
00790 return ImplementationTable;
00791 }