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
00033 #include <f32file.h>
00034 #include <e32std.h>
00035 #include <mmfdatabuffer.h>
00036
00037 #include "mmfexdes.h"
00038 #include "MmfExSinkSourceUIDs.hrh"
00039
00040
00041 void Panic(TMMFExDescriptorPanicCode aPanicCode)
00042 {
00043 _LIT(KMMFExDescriptorPanicCategory, "MMFExDescriptor");
00044 User::Panic(KMMFExDescriptorPanicCategory, aPanicCode);
00045 }
00046
00047
00048
00049
00050
00051
00052 const TUid KDescriptorSourceUIDObject = {KDescriptorSourceUID};
00053 const TUid KDescriptorSinkUIDObject = {KDescriptorSinkUID};
00054
00055
00056 CMMFExDescriptor::CMMFExDescriptor( ) : CMMFClip( TUid(KDescriptorSourceUIDObject), TUid(KDescriptorSinkUIDObject ))
00057 {
00058 iOffset = 0 ;
00059 }
00060
00061
00062 CMMFExDescriptor::~CMMFExDescriptor()
00063 {
00064 iDesThread.Close() ;
00065 }
00066
00067
00068 MDataSource* CMMFExDescriptor::NewSourceL( )
00069 {
00070 CMMFExDescriptor* self = new (ELeave) CMMFExDescriptor( ) ;
00071 return STATIC_CAST( MDataSource*, self ) ;
00072 }
00073
00074
00075 MDataSink* CMMFExDescriptor::NewSinkL( )
00076 {
00077 CMMFExDescriptor* self = new (ELeave) CMMFExDescriptor( ) ;
00078 return STATIC_CAST( MDataSink*, self ) ;
00079 }
00080
00081
00082
00083 void CMMFExDescriptor::ConstructSourceL( const TDesC8& aInitData )
00084 {
00085 ConstructL( aInitData ) ;
00086 }
00087
00088
00089
00090 void CMMFExDescriptor::ConstructSinkL( const TDesC8& aInitData )
00091 {
00092 ConstructL( aInitData ) ;
00093 }
00094
00095
00096
00097 void CMMFExDescriptor::ConstructL( const TDesC8& aInitData )
00098 {
00099
00100
00101 TMMFExDescriptorParams params;
00102 TPckgC<TMMFExDescriptorParams> config(params);
00103 config.Set(aInitData);
00104 iDes = STATIC_CAST( TDes8*, config().iDes);
00105 User::LeaveIfError( iDesThread.Open( config().iDesThreadId ) );
00106 }
00107
00108
00109
00110
00111 TFourCC CMMFExDescriptor::SourceDataTypeCode(TMediaId )
00112 {
00113 return iSourceFourCC ;
00114 }
00115
00116
00117 void CMMFExDescriptor::FillBufferL( CMMFBuffer* aBuffer, MDataSink* aConsumer, TMediaId )
00118 {
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128 if ( aBuffer->Type() == KUidMmfDataBuffer )
00129 {
00130 TDes8& bufferDes = STATIC_CAST(CMMFDataBuffer*, aBuffer)->Data();
00131 TInt targetMaxLength = bufferDes.MaxLength();
00132 TInt sourceLength = iDes->Length();
00133
00134 if ( ( sourceLength - iOffset - targetMaxLength ) > 0 )
00135 {
00136 bufferDes = iDes->Mid(iOffset,targetMaxLength);
00137 iOffset += targetMaxLength;
00138 }
00139 else
00140 bufferDes.SetLength(0);
00141
00142
00143 TInt requestSize = aBuffer->RequestSize();
00144 if (requestSize)
00145 {
00146 if (bufferDes.Length() < requestSize)
00147 aBuffer->SetLastBuffer(ETrue);
00148 }
00149 else
00150 {
00151 if (bufferDes.Length() < bufferDes.MaxLength())
00152 aBuffer->SetLastBuffer(ETrue);
00153 }
00154
00155 aConsumer->BufferFilledL( aBuffer ) ;
00156 }
00157 else
00158 User::Leave(KErrNotSupported);
00159 }
00160
00161
00162 void CMMFExDescriptor::BufferEmptiedL( CMMFBuffer* )
00163 {
00164
00165 __ASSERT_DEBUG(EFalse, Panic(EMMFDescriptorPanicBufferEmptiedLNotSupported));
00166 }
00167
00168
00169 TBool CMMFExDescriptor::CanCreateSourceBuffer()
00170 {
00171
00172 return EFalse ;
00173 }
00174
00175
00176 CMMFBuffer* CMMFExDescriptor::CreateSourceBufferL( TMediaId , TBool& )
00177 {
00178
00179 User::Leave(KErrNotSupported);
00180 return NULL;
00181 }
00182
00183
00184
00185
00186
00187 TFourCC CMMFExDescriptor::SinkDataTypeCode(TMediaId )
00188 {
00189 return iSinkFourCC ;
00190 }
00191
00192
00193 void CMMFExDescriptor::EmptyBufferL( CMMFBuffer* aBuffer, MDataSource* aSupplier, TMediaId )
00194 {
00195
00196
00197
00198
00199
00200
00201
00202
00203 if ( aBuffer->Type() == KUidMmfDataBuffer )
00204 {
00205 TDes8& bufferDes = STATIC_CAST(CMMFDataBuffer*, aBuffer)->Data();
00206
00207 TInt sourceLength = bufferDes.Length() ;
00208 TInt targetLength = iDes->MaxLength() - iOffset;
00209 if ( targetLength>0 )
00210 {
00211 if (sourceLength>targetLength)
00212 {
00213 sourceLength = targetLength;
00214 bufferDes.SetLength(targetLength);
00215 }
00216
00217 iDes->Append(bufferDes) ;
00218
00219 iOffset += sourceLength ;
00220 }
00221 else
00222 bufferDes.SetLength(0);
00223
00224 aSupplier->BufferEmptiedL( aBuffer ) ;
00225 }
00226 }
00227
00228
00229 void CMMFExDescriptor::BufferFilledL( CMMFBuffer* )
00230 {
00231
00232 __ASSERT_DEBUG(EFalse, Panic(EMMFDescriptorPanicBufferFilledLNotSupported));
00233 }
00234
00235
00236 TBool CMMFExDescriptor::CanCreateSinkBuffer()
00237 {
00238
00239 return EFalse ;
00240 }
00241
00242
00243 CMMFBuffer* CMMFExDescriptor::CreateSinkBufferL( TMediaId , TBool& )
00244 {
00245
00246 User::Leave(KErrNotSupported);
00247 return NULL;
00248 }
00249
00250
00251
00252
00253 void CMMFExDescriptor::ReadBufferL(TInt aLength, CMMFBuffer* aBuffer, TInt aPosition, MDataSink* aConsumer)
00254 {
00255 if (aBuffer->Type() == KUidMmfDataBuffer)
00256 {
00257 TDes8& bufferDes = STATIC_CAST(CMMFDataBuffer*, aBuffer)->Data();
00258
00259 if (aLength>bufferDes.MaxLength())
00260 User::Leave(KErrOverflow);
00261
00262 if ((aLength<0) || (aPosition<0))
00263 User::Leave(KErrArgument);
00264
00265 ReadBufferL(aBuffer, aPosition, aConsumer);
00266 }
00267 else
00268 User::Leave(KErrNotSupported);
00269 }
00270
00271
00272 void CMMFExDescriptor::ReadBufferL(CMMFBuffer* aBuffer, TInt aPosition, MDataSink* aConsumer)
00273 {
00274 if (aBuffer->Type() == KUidMmfDataBuffer)
00275 {
00276 TDes8& bufferDes = STATIC_CAST(CMMFDataBuffer*, aBuffer)->Data();
00277
00278 TInt sourceLength = iDes->Length() ;
00279 TInt destinationMaxLength = bufferDes.MaxLength();
00280 TInt len = sourceLength - aPosition;
00281 if (len > destinationMaxLength)
00282 len = destinationMaxLength;
00283
00284 if (len>0)
00285 {
00286 TPtrC8 srcPtr(iDes->Mid(aPosition,len));
00287 bufferDes.Copy(srcPtr);
00288 }
00289 else
00290 bufferDes.SetLength(0);
00291
00292
00293 TInt requestSize = aBuffer->RequestSize();
00294 if (requestSize)
00295 {
00296 if (bufferDes.Length() < requestSize)
00297 aBuffer->SetLastBuffer(ETrue);
00298 }
00299 else
00300 {
00301 if (bufferDes.Length() < bufferDes.MaxLength())
00302 aBuffer->SetLastBuffer(ETrue);
00303 }
00304
00305 if (aConsumer)
00306 aConsumer->BufferFilledL(aBuffer);
00307 }
00308 else
00309 User::Leave(KErrNotSupported);
00310 }
00311
00312
00313
00314 void CMMFExDescriptor::ReadBufferL(CMMFBuffer* aBuffer, TInt aPosition)
00315 {
00316 ReadBufferL(aBuffer, aPosition, NULL);
00317 }
00318
00319
00320 void CMMFExDescriptor::WriteBufferL(CMMFBuffer* aBuffer, TInt aPosition, MDataSource* aSupplier)
00321 {
00322 if (aBuffer->Type() == KUidMmfDataBuffer)
00323 {
00324 TDes8& bufferDes = STATIC_CAST(CMMFDataBuffer*, aBuffer)->Data();
00325
00326 WriteBufferL(bufferDes.Length(), aBuffer, aPosition, aSupplier);
00327 }
00328 else
00329 User::Leave(KErrNotSupported);
00330 }
00331
00332
00333 void CMMFExDescriptor::WriteBufferL(TInt aLength, CMMFBuffer* aBuffer, TInt aPosition, MDataSource* aSupplier)
00334 {
00335 if (aBuffer->Type() == KUidMmfDataBuffer)
00336 {
00337 TDes8& bufferDes = STATIC_CAST(CMMFDataBuffer*, aBuffer)->Data();
00338
00339 if (aLength>bufferDes.Length() || (aLength<0) || (aPosition<0))
00340 User::Leave(KErrArgument);
00341
00342 TInt sourceLength = aLength;
00343 TPtr8 bufferPtr(((sourceLength) ? &bufferDes[0] : NULL), sourceLength, sourceLength);
00344 TInt targetLength = iDes->MaxLength() - aPosition;
00345 if (targetLength>0 && sourceLength > 0)
00346 {
00347 if (sourceLength>targetLength)
00348 User::Leave(KErrOverflow);
00349
00350 if ((iDes->Length() - aPosition) > 0)
00351 {
00352 TInt bytesToReplace = iDes->Length() - aPosition;
00353 if (sourceLength > bytesToReplace)
00354 {
00355 TPtrC8 replaceBuf = bufferPtr.Left(bytesToReplace);
00356 TPtrC8 appendBuf = bufferPtr.Right(sourceLength-bytesToReplace);
00357 iDes->Replace(aPosition, bytesToReplace, replaceBuf);
00358 iDes->Append(appendBuf);
00359 }
00360 else
00361 iDes->Replace(aPosition, sourceLength, bufferPtr);
00362
00363 }
00364 else if (aPosition == iDes->Length())
00365 iDes->Append(bufferPtr.Ptr(),sourceLength);
00366 else
00367 {
00368 iDes->AppendFill(0,aPosition - iDes->Length());
00369 iDes->Append(bufferPtr.Ptr(),sourceLength);
00370 }
00371 }
00372 else if (targetLength<0)
00373 User::Leave(KErrArgument);
00374 else if (aLength != 0)
00375 User::Leave(KErrOverflow);
00376
00377 if (aSupplier)
00378 aSupplier->BufferEmptiedL(aBuffer);
00379 }
00380 else
00381 User::Leave(KErrNotSupported);
00382 }
00383
00384
00385 void CMMFExDescriptor::WriteBufferL( CMMFBuffer* aBuffer, TInt aPosition)
00386 {
00387 WriteBufferL( aBuffer, aPosition, NULL );
00388 }
00389
00390
00391 TInt64 CMMFExDescriptor::BytesFree()
00392 {
00393
00394 TInt64 length = iDes->Length() ;
00395 TInt64 maxLength = iDes->MaxLength() ;
00396 return( maxLength - length ) ;
00397 }
00398
00399
00400 TInt CMMFExDescriptor::Size()
00401 {
00402
00403 TInt length = iDes->Length();
00404 return(length);
00405 }