mmfenh/advancedaudiocontroller/audiocontrollerpluginsvariant/3gpDataSourceAdapter/Src/3gpDataSourceAdapter.cpp
changeset 0 71ca22bcf22a
child 5 709f89d8c047
equal deleted inserted replaced
-1:000000000000 0:71ca22bcf22a
       
     1 /*
       
     2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Class definition for the DataSourceAdapter functions.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 //  INCLUDES
       
    20 #include "3gpDataSourceAdapter.h"
       
    21 #include "DebugMacros.h"
       
    22 #include <mmfclip.h>
       
    23 //#include <mmfdatabuffer.h>
       
    24 #include <MultimediaDataSourceFactory.h>
       
    25 #include <mmffile.h>
       
    26 #include <caf/caf.h>
       
    27 #include <mmfcontroller.h>
       
    28 
       
    29 
       
    30 #include <oma2dcf.h> // EPeek
       
    31 const TInt KDataSourceReadBufferSize = 16*1024; // read from source
       
    32 const TInt KParserReadBufferSize = 2000; // read from parser - it only gives 1 frame
       
    33 const TInt KMaxFrameSize = 1536;
       
    34 
       
    35 // ============================ MEMBER FUNCTIONS ===============================
       
    36 
       
    37 // -----------------------------------------------------------------------------
       
    38 // C3gpDataSourceAdapter::C3gpDataSourceAdapter
       
    39 // C++ default constructor can NOT contain any code, that
       
    40 // might leave.
       
    41 // -----------------------------------------------------------------------------
       
    42 //
       
    43 C3gpDataSourceAdapter::C3gpDataSourceAdapter() :
       
    44     	MDataSink(KUidMmfFormatDecode)
       
    45 
       
    46     {
       
    47     }
       
    48 
       
    49 // -----------------------------------------------------------------------------
       
    50 // C3gpDataSourceAdapter::ConstructL
       
    51 // Symbian 2nd phase constructor can leave.
       
    52 // -----------------------------------------------------------------------------
       
    53 //
       
    54 void C3gpDataSourceAdapter::ConstructL()
       
    55     {
       
    56 	// should end up doing this for all sources
       
    57 	iMediaId = KUidMediaTypeAudio;
       
    58 	iParserBuf = CreateSourceBufferOfSizeL(KParserReadBufferSize);
       
    59 	iSrcBuf = CreateSourceBufferOfSizeL(KDataSourceReadBufferSize);
       
    60 	iZeroBuffer = CMMFDataBuffer::NewL(0); // this is just for test to allow source seek
       
    61 	iHdrBuffer = CMMFDataBuffer::NewL(20); // just enough to cover the header lengths create by recorder
       
    62     iAsyncProxyFillBuffer = new(ELeave) CAsyncProxyFillBuffer(*this);
       
    63 
       
    64 	}
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // C3gpDataSourceAdapter::NewL
       
    68 // Two-phased constructor.
       
    69 // -----------------------------------------------------------------------------
       
    70 //
       
    71 EXPORT_C C3gpDataSourceAdapter* C3gpDataSourceAdapter::NewL()
       
    72     {
       
    73     DP0(_L("C3gpDataSourceAdapter::NewL"));
       
    74     C3gpDataSourceAdapter* self = new(ELeave) C3gpDataSourceAdapter();
       
    75     CleanupStack::PushL(self);
       
    76     self->ConstructL();
       
    77     CleanupStack::Pop(self);
       
    78     return self;
       
    79     }
       
    80 
       
    81 // Destructor
       
    82 EXPORT_C C3gpDataSourceAdapter::~C3gpDataSourceAdapter()
       
    83     {
       
    84     DP0(_L("C3gpDataSourceAdapter::~C3gpDataSourceAdapter"));
       
    85 	MP4ParseClose(iMP4Handle);
       
    86 	delete iParserBuf;
       
    87 	delete iSrcBuf;
       
    88     delete iCafHandle;
       
    89     iQueuedAsyncBuffers.Close(); // this is different from one in base class
       
    90 	delete iAsyncProxyFillBuffer; // this is different from one in base class
       
    91     }
       
    92 
       
    93 // -----------------------------------------------------------------------------
       
    94 // From MDataSource
       
    95 // -----------------------------------------------------------------------------
       
    96 //
       
    97 EXPORT_C void C3gpDataSourceAdapter::FillBufferL(CMMFBuffer* aBuffer, MDataSink* aDataSink,TMediaId /*aMediaId*/)
       
    98 	{
       
    99 	TInt status = KErrNone;
       
   100     CMMFDataBuffer* buffer = static_cast<CMMFDataBuffer*>(aBuffer);
       
   101 		
       
   102 	DP1(_L("C3gpDataSourceAdapter::FillBufferL buffer[%x]"), buffer->Data().Ptr());
       
   103 	if (aDataSink != this)
       
   104 	    { // called from the controller
       
   105         iControllerMDataSink = aDataSink;
       
   106         iQueuedAsyncBuffers.Append(aBuffer);
       
   107 	    if (iQueuedAsyncBuffers.Count() > 1)
       
   108 	        {
       
   109 			DP1(_L("C3gpDataSourceAdapter::FillBufferL buffer queued count[%d]"), iQueuedAsyncBuffers.Count());
       
   110     	    return;
       
   111 	        }
       
   112 	    }
       
   113         
       
   114     if (iParserBuf->Data().Length())
       
   115         {
       
   116 		// Audio Frames previously read is appended first
       
   117         buffer->Data().Append(iParserBuf->Data().Ptr(), iParserBuf->Data().Length());
       
   118 		iParserBuf->Data().SetLength(0);
       
   119         iParserBuf->SetPosition(0);
       
   120         }
       
   121         
       
   122     iFillingBuffer = aBuffer;
       
   123     if (iReadMp4LibSync)
       
   124     	{
       
   125 	    iAsyncProxyFillBuffer->ReadSync();
       
   126     	}
       
   127     else
       
   128     	{
       
   129 	    status = ReadAsync();
       
   130     	}	
       
   131 
       
   132     if (status == KErrNone)
       
   133         {
       
   134         // do nothing
       
   135         }
       
   136     else
       
   137         { // define the use case for this...
       
   138         DP1(_L("C3gpDataSourceAdapter::FillSharedBufferL, ReadAsync status[%d] calling frames available"), status);
       
   139         M3GPMP4LibAudioFramesAvailable(status, 0, 0,0,0);
       
   140         }
       
   141 	}
       
   142 
       
   143 EXPORT_C void C3gpDataSourceAdapter::SourcePrimeL()
       
   144 	{
       
   145 	DP0(_L("C3gpDataSourceAdapter::SourcePrimeL"));
       
   146 	iDataSource->SourcePrimeL();
       
   147    	if (!iMP4Handle)
       
   148    		{
       
   149    		PrepareMP4ParserL();
       
   150    		}
       
   151 	}
       
   152 	
       
   153 EXPORT_C void C3gpDataSourceAdapter::SourceStopL()
       
   154 	{
       
   155 	DP0(_L("C3gpDataSourceAdapter::SourceStopL"));
       
   156 	ResetVariables();
       
   157 	MP4ParseClose(iMP4Handle);
       
   158 	iMP4Handle = NULL;
       
   159 	iDataSource->SourceStopL();
       
   160 	// Clear previously read Audio Frames  
       
   161 	iParserBuf->Data().SetLength(0);
       
   162 	iParserBuf->SetPosition(0);	
       
   163 	}
       
   164 
       
   165 // -----------------------------------------------------------------------------
       
   166 // From MMultimediaDataSourceObserver
       
   167 // -----------------------------------------------------------------------------
       
   168 //
       
   169 EXPORT_C void C3gpDataSourceAdapter::BufferFilled(CMMFBuffer* aBuffer)
       
   170 	{
       
   171 	TRAPD(err,BufferFilledL(aBuffer));
       
   172 	if (err != KErrNone)
       
   173 		{//send event to client to notify error in source adapter
       
   174 	//	SendEvent(TMMFEvent(KMMFEventCategoryPlaybackComplete, err));		
       
   175 		}
       
   176 	}
       
   177 
       
   178 EXPORT_C void C3gpDataSourceAdapter::Event(TUid aEvent)
       
   179 	{
       
   180 	iControllerMMultimediaDataSourceObserver->Event(aEvent);
       
   181 	}
       
   182 	
       
   183 EXPORT_C TInt C3gpDataSourceAdapter::GetBitRate(TUint& aBitRate)
       
   184 	{
       
   185 	return iControllerMMultimediaDataSourceObserver->GetBitRate(aBitRate);
       
   186 	}
       
   187 	
       
   188 // -----------------------------------------------------------------------------
       
   189 // From CDataSourceAdapter
       
   190 // -----------------------------------------------------------------------------
       
   191 //
       
   192 EXPORT_C TInt C3gpDataSourceAdapter::SeekToTime(TUint aTimeMs, TUint& aFoundTimeMs)
       
   193 	{
       
   194 	DP0(_L("C3gpDataSourceAdapter::SeekToTime"));
       
   195 	TInt status = KErrNone;
       
   196     mp4_u32 audioTimeStamp, videoTimeStamp;
       
   197 	MP4Err err = MP4ParseSeek(iMP4Handle, aTimeMs, &audioTimeStamp, &videoTimeStamp, EFalse);
       
   198 	
       
   199 	aFoundTimeMs = audioTimeStamp;
       
   200 
       
   201 	DP3(_L("C3gpDataSourceAdapter::SeekToTime stat[%d] timeMs[%d] foundtimeMs[%d]"), err, aTimeMs,aFoundTimeMs);
       
   202 
       
   203 	status = TranslateMP4Err(err);	
       
   204 	return status;
       
   205 	}
       
   206 
       
   207 EXPORT_C void C3gpDataSourceAdapter::SetDataSourceL(MDataSource* aDataSource,
       
   208 								 MMultimediaDataSourceObserver* aMMultimediaDataSourceObserver,
       
   209 								 MAsyncEventHandler* aAsyncEventHandler)
       
   210 	{
       
   211 	DP0(_L("C3gpDataSourceAdapter::SetDataSource"));
       
   212 	iHeaderOnly = EFalse;
       
   213 	iControllerMMultimediaDataSourceObserver = aMMultimediaDataSourceObserver;
       
   214 	iAsyncEventHandler = aAsyncEventHandler;
       
   215 	ResetVariables();
       
   216    	if (iDataSource)
       
   217     	{
       
   218 	    return;
       
   219    		}
       
   220 
       
   221     if (iCafHandle)
       
   222         {
       
   223         delete iCafHandle;
       
   224         iCafHandle = NULL;
       
   225         }
       
   226 
       
   227   	iDataSource = aDataSource;
       
   228     iSourceType = iDataSource->DataSourceType();
       
   229 	DP1(_L("C3gpDataSourceAdapter::SetDataSource DataSourceType[0x%x]"), iSourceType);
       
   230     
       
   231     if ((iSourceType == KMmdsStreamingSourceUid) || (iSourceType == KMmdsProgDLSourceUid) ||
       
   232         (iSourceType == KS60AudioStreamingSourceUid) || (iSourceType == KMmdsDescriptorSourceUid) ||
       
   233         (iSourceType == KUidMmfDescriptorSource) || (iSourceType == KMmdsFileSourceUid))
       
   234 		{ // data is streamed in buffers to parser and we read sync from parser - parser does not support seeking
       
   235 		iReadMp4LibSync = ETrue;
       
   236 		}
       
   237 	else
       
   238 		{ // parser has file handle and we read async from parser - parser supports seeking
       
   239 		iReadMp4LibSync = EFalse;
       
   240     	iTimeSeekable = ETrue;
       
   241 		}	
       
   242 
       
   243     if ((iSourceType == KMmdsStreamingSourceUid) || (iSourceType == KMmdsProgDLSourceUid) ||
       
   244         (iSourceType == KS60AudioStreamingSourceUid) || (iSourceType == KMmdsDescriptorSourceUid) ||
       
   245         (iSourceType == KMmdsFileSourceUid))
       
   246         { // data is written to parser
       
   247         TInt err = CMultimediaDataSourceFactory::CreateDataSource(*iDataSource, iMMDataSource);
       
   248 
       
   249         User::LeaveIfError(err);
       
   250 
       
   251 //        iMMDataSource->SetObserver(*this);
       
   252         User::LeaveIfError(iMMDataSource->SetObserver(*this));
       
   253         User::LeaveIfError(iMMDataSource->Open());
       
   254         }
       
   255 	if ((iSourceType == KUidMmfFileSource) || (iSourceType == KOldProgDLSourceUid))
       
   256     	{ // parser has file handle
       
   257 		// read async from lib when it has a file handle
       
   258 		iClip = static_cast<CMMFClip*>(iDataSource);
       
   259         iDataSource->SourcePrimeL();
       
   260    		iIsProtected = static_cast<CMMFFile*>(iDataSource)->IsProtectedL();
       
   261 		iClip->SourceThreadLogon(*aAsyncEventHandler);
       
   262 		iClip->ReadBufferL(iHdrBuffer,0);
       
   263 		iClip->ReadBufferL(iZeroBuffer, 0); // seek back to 0 position
       
   264 		const TUint8* ptr = iHdrBuffer->Data().Ptr();
       
   265     	if (iClip->Size() == 11)
       
   266     		{ // check for just the header from recorder
       
   267     		TUint32* w1p = (TUint32*)ptr;
       
   268     		TUint32* w2p = (TUint32*)(ptr+4);
       
   269     		TUint32* w3p = (TUint32*)(ptr+8);
       
   270     		if (((*w1p & 0x1C000000)==0x1C000000) && 
       
   271     			((*w2p & 0x70797466)==0x70797466) && 
       
   272     			((*w3p & 0x0034706D)==0x0034706D))
       
   273     			{
       
   274 	    		iClip->SourceStopL();
       
   275     			iHeaderOnly = ETrue;
       
   276     			return;
       
   277     			}
       
   278     		}
       
   279     		
       
   280         if (iSourceType == KUidMmfFileSource)
       
   281             {
       
   282             CMMFFile* File = static_cast<CMMFFile*>(iDataSource);                
       
   283             RFile rFile = File->FileL();
       
   284             iCafHandle = ContentAccess::CData::NewL(rFile, File->UniqueId(), EPeek);                
       
   285             }
       
   286     	}
       
   287 	}
       
   288 
       
   289 // -----------------------------------------------------------------------------
       
   290 // From MDataSink
       
   291 // -----------------------------------------------------------------------------
       
   292 //
       
   293 EXPORT_C void C3gpDataSourceAdapter::BufferFilledL(CMMFBuffer* aBuffer)
       
   294 	{ // only talks to MMDataSource asynchronously using a single iSrcBuf
       
   295 	// aBuffer here is just the one iSrcBuf
       
   296     CMMFDataBuffer* buffer = static_cast<CMMFDataBuffer*>(aBuffer);
       
   297     DP2(_L("C3gpDataSourceAdapter::BufferFilledL[%x], LastBuffer[%d]"), buffer->Data().Ptr(), aBuffer->LastBuffer());
       
   298 
       
   299 	TUint bufferSize = buffer->Data().Length();
       
   300 
       
   301     DP1(_L("C3gpDataSourceAdapter::BufferFilledL, Length[%d]"), bufferSize);
       
   302 
       
   303 	TUint8* bufPtr = const_cast<TUint8*>(buffer->Data().Ptr());
       
   304     TInt err = KErrNone;
       
   305 /*	
       
   306 	if ( bufferSize > 5 )
       
   307 	{
       
   308 	DP5(_L("C3gpDataSourceAdapter::BufferFilledL data[0x%x][0x%x][0x%x][0x%x][0x%x]"), \
       
   309 	*bufPtr,*(bufPtr+1),*(bufPtr+2),*(bufPtr+3),*(bufPtr+4));
       
   310     }
       
   311 */	
       
   312     if (bufferSize > 0)
       
   313    	    {
       
   314    	    err = TranslateMP4Err(MP4ParseWriteData(iMP4Handle, bufPtr, bufferSize));
       
   315 		//mp4_u32 audioLength, audioType, timeScale, averateBitRate;
       
   316 		mp4_u32 audioLength, timeScale, averateBitRate;
       
   317 		mp4_u8 framesPerSample;
       
   318 		if (!iMp4HeaderAvail)
       
   319 			{
       
   320 			if (MP4_OK == MP4ParseRequestAudioDescription(iMP4Handle, &audioLength, &iAudioType,	&framesPerSample, &timeScale, &averateBitRate))
       
   321 				{ // header is required to do anything.
       
   322 				iMp4HeaderAvail = ETrue;
       
   323 				}
       
   324 			}
       
   325 
       
   326         DP3(_L("C3gpDataSourceAdapter::BufferFilledL, MP4ParseWriteData err[%d], bufferSize[%d] d0[%x]"), err, bufferSize, bufPtr[0]);
       
   327         if (err == MP4_OUT_OF_MEMORY)
       
   328         	{
       
   329 	        DP0(_L("C3gpDataSourceAdapter::BufferFilledL, out of memory abort"));
       
   330 	        User::Leave(KErrAbort);
       
   331         	}
       
   332     	if (err == MP4_OK)
       
   333     		{
       
   334 	  	    if (!aBuffer->LastBuffer())
       
   335    		        {
       
   336 	   	        // continue getting next buffer
       
   337 		        DP1(_L("C3gpDataSourceAdapter::BufferFilledL, iMMDataSource->FillBuffer buffer[%x]"), iSrcBuf->Data().Ptr());
       
   338 	       	    buffer->SetPosition(0);
       
   339 			    buffer->Data().SetLength(0);
       
   340 				iMMDataSource->FillBuffer(iSrcBuf);
       
   341 	   	    	}
       
   342 		    else
       
   343 		        {
       
   344 	    	    // do nothing, since the file has reach the end
       
   345             	DP0(_L("C3gpDataSourceAdapter::BufferFilledL, reach EOF"));
       
   346 	            iLastBufferWrittenToMp4Lib = ETrue;
       
   347 		        }
       
   348     		}
       
   349        	} // buffersize > 0
       
   350    	else
       
   351    	    { // buffersize <= 0
       
   352    	    // should never reach here, since no callback should occur if no data available for streaming
       
   353         DP0(_L("C3gpDataSourceAdapter::BufferFilledL, unexpected 0 length buffer"));
       
   354         User::Leave(KErrAbort);
       
   355    	    }
       
   356 	if (iRestartSyncRead)
       
   357 		{
       
   358 		iRestartSyncRead = EFalse;
       
   359         DP0(_L("C3gpDataSourceAdapter::BufferFilledL, restarting parser read ReadSync()"));
       
   360 	    iAsyncProxyFillBuffer->ReadSync();
       
   361 		}
       
   362 	}
       
   363 
       
   364 EXPORT_C void C3gpDataSourceAdapter::EmptyBufferL(
       
   365 	CMMFBuffer* /*aBuffer*/,
       
   366 	MDataSource* /*aSupplier*/,
       
   367 	TMediaId /*aMediaId*/ )
       
   368 	{}
       
   369 
       
   370 EXPORT_C TFourCC C3gpDataSourceAdapter::SinkDataTypeCode(
       
   371 	TMediaId /*aMediaId*/ )
       
   372 	{
       
   373 	return KFourCCNULL;
       
   374 	}
       
   375 
       
   376 EXPORT_C TBool C3gpDataSourceAdapter::CanCreateSinkBuffer()
       
   377 	{
       
   378 	return EFalse;
       
   379 	}
       
   380 
       
   381 EXPORT_C CMMFBuffer* C3gpDataSourceAdapter::CreateSinkBufferL(
       
   382 	TMediaId /*aMediaId*/,
       
   383 	TBool& /*aReference*/ )
       
   384 	{
       
   385 	return NULL;
       
   386 	}
       
   387 
       
   388 EXPORT_C void C3gpDataSourceAdapter::ConstructSinkL(
       
   389 	const TDesC8& /*aInitData*/ )
       
   390 	{}
       
   391 
       
   392 EXPORT_C TBool C3gpDataSourceAdapter::IsPositonSeekable()
       
   393     {
       
   394     DP1(_L("C3gpDataSourceAdapter::IsPositonSeekable DataSourceType[0x%x]"), iSourceType);
       
   395     if ((iSourceType == KMmdsStreamingSourceUid) || (iSourceType == KMmdsProgDLSourceUid) ||
       
   396         (iSourceType == KS60AudioStreamingSourceUid) || (iSourceType == KMmdsDescriptorSourceUid) ||
       
   397         (iSourceType == KUidMmfDescriptorSource) || (iSourceType == KMmdsFileSourceUid) ||
       
   398         (iSourceType == KOldProgDLSourceUid))
       
   399         {
       
   400         return EFalse;
       
   401         }
       
   402     else
       
   403         {
       
   404         return ETrue;
       
   405         }   
       
   406     }
       
   407 // -----------------------------------------------------------------------------
       
   408 // From M3GPMP4LibAsyncObserver
       
   409 // -----------------------------------------------------------------------------
       
   410 //
       
   411 // -----------------------------------------------------------------------------
       
   412 // C3gpDataSourceAdapter::M3GPMP4LibAudioFramesAvailable
       
   413 // -----------------------------------------------------------------------------
       
   414 //
       
   415 void C3gpDataSourceAdapter::M3GPMP4LibAudioFramesAvailable(MP4Err aError,
       
   416                                                                 mp4_u32 aAudioSize,
       
   417                                                                 mp4_u32 /*aTimeStamp*/,
       
   418                                                                 mp4_u32 /*aReturnedFrames*/,
       
   419                                                                 mp4_u32 /*aTimestamp2*/)
       
   420     {
       
   421     DP2(_L("C3gpDataSourceAdapter::M3GPMP4LibAudioFramesAvailable, aError = %d, aAudioSize = %d"), aError, aAudioSize);
       
   422     DP2(_L("C3gpDataSourceAdapter::M3GPMP4LibAudioFramesAvailable, iParserBuf[%x] d0[%x]"), static_cast<CMMFDataBuffer*>(iParserBuf)->Data().Ptr(), static_cast<CMMFDataBuffer*>(iParserBuf)->Data().Ptr()[0]);
       
   423 
       
   424     TInt err = aError;
       
   425     if (err == MP4_OK)
       
   426         {
       
   427         TUint8* bufPtr = const_cast<TUint8*>(iParserBuf->Data().Ptr());
       
   428     	TInt requestSize = static_cast<CMMFDataBuffer*>(iFillingBuffer)->RequestSize();
       
   429     	TInt bufferlength = static_cast<CMMFDataBuffer*>(iFillingBuffer)->Data().Length()+aAudioSize;
       
   430 	
       
   431         if (bufferlength <= requestSize)
       
   432             {
       
   433 /*            TUint32 timePositionInMilliSecs = I64INT(iPlayWindowEndPosition.Int64())/1000;
       
   434             
       
   435             if ((iPlayWindowEndPosition != TTimeIntervalMicroSeconds(0)) && (aTimeStamp >= timePositionInMilliSecs))
       
   436                 {
       
   437                 iFillingBuffer->SetLastBuffer(ETrue);
       
   438                 iFillingBuffer->SetStatus(EFull);
       
   439                 }
       
   440             else // Not reached end of playwindow or no playwindow at all
       
   441 */                {
       
   442                 static_cast<CMMFDataBuffer*>(iFillingBuffer)->Data().Append(iParserBuf->Data().Ptr(), aAudioSize);
       
   443                 iParserBuf->Data().SetLength(0);
       
   444                 iParserBuf->SetPosition(0);
       
   445 
       
   446                 err = ReadAsync();
       
   447                 // this error return value is handled below
       
   448                     
       
   449                 }
       
   450             }
       
   451         else
       
   452             {
       
   453             // Save this read for the next source buffer
       
   454             DP2(_L("C3gpDataSourceAdapter::M3GPMP4LibAudioFramesAvailable, iFillingBuffer[%x] - FULL, Length[%d]"),
       
   455             		static_cast<CMMFDataBuffer*>(iFillingBuffer)->Data().Ptr(), static_cast<CMMFDataBuffer*>(iFillingBuffer)->Data().Length());
       
   456             iParserBuf->Data().SetLength(aAudioSize);
       
   457             iQueValid = ETrue;
       
   458             TRAP(err,iControllerMDataSink->BufferFilledL(iFillingBuffer)); // setpos could come in here and clear the queue here and add another read
       
   459             // this error return value is handled below
       
   460             if (iQueValid)
       
   461                 { // this detects if the que has been cleared and refilled
       
   462                 // we don't want to do this with the new buffers in the queue
       
   463                 iQueuedAsyncBuffers.Remove(0);
       
   464                 if (iQueuedAsyncBuffers.Count() > 0)
       
   465                     {
       
   466                     DP0(_L("C3gpDataSourceAdapter::M3GPMP4LibAudioFramesAvailable calls FillBufferL"));
       
   467                     TRAP(err,FillBufferL(iQueuedAsyncBuffers[0],this,iMediaId));
       
   468                     // this error return value is handled below
       
   469                     }
       
   470                 }
       
   471             }
       
   472         }
       
   473     if (err == MP4_NO_FRAME)
       
   474 	    {
       
   475         DP0(_L("C3gpDataSourceAdapter::M3GPMP4LibAudioFramesAvailable sending last buffer"));
       
   476 	    iFillingBuffer->SetLastBuffer(ETrue);
       
   477         TRAP(err,iControllerMDataSink->BufferFilledL(iFillingBuffer));
       
   478        	if (err != KErrNone)
       
   479            	{
       
   480            	DP1(_L("C3gpDataSourceAdapter::M3GPMP4LibAudioFramesAvailable, BufferFilledL err[%d]"), err);
       
   481 
       
   482 //            	SendEvent(TMMFEvent(KMMFEventCategoryPlaybackComplete, err));
       
   483            	}          
       
   484 	    }
       
   485     else if (err != MP4_OK)
       
   486         {
       
   487         DP1(_L("error %d..."), TranslateMP4Err(err));
       
   488         
       
   489         //send event to client to notify error in source adapter
       
   490         if(iAsyncEventHandler)
       
   491         	{
       
   492          	iAsyncEventHandler->SendEventToClient(TMMFEvent(KMMFEventCategoryPlaybackComplete, KErrSourceAdapter));
       
   493         	}
       
   494         }
       
   495     }
       
   496 
       
   497 // -----------------------------------------------------------------------------
       
   498 // C3gpDataSourceAdapter::M3GPMP4LibVideoFrameAvailable
       
   499 // -----------------------------------------------------------------------------
       
   500 //
       
   501 void C3gpDataSourceAdapter::M3GPMP4LibVideoFrameAvailable(MP4Err /*aError*/,
       
   502                                                           mp4_u32 /*aFrameSize*/,
       
   503                                                           mp4_u32 /*aTimeStamp*/,
       
   504                                                           mp4_bool /*aKeyFrame*/,
       
   505                                                           mp4_u32 /*aTimestamp2*/)
       
   506     {
       
   507     // do nothing, not used
       
   508     }
       
   509 
       
   510 // -----------------------------------------------------------------------------
       
   511 // New
       
   512 // -----------------------------------------------------------------------------
       
   513 //
       
   514 EXPORT_C TInt C3gpDataSourceAdapter::ReadHeader(TUint32& aAudioLength, TUint32& aAudioType, 
       
   515             TUint8& aFramesPerSample, TUint32& aTimeScale, TUint32& aAverateBitRate)
       
   516 	{
       
   517 	TInt err = MP4ParseRequestAudioDescription(iMP4Handle, &aAudioLength, &aAudioType, &aFramesPerSample, &aTimeScale, &aAverateBitRate);
       
   518     DP6(_L("C3gpDataSourceAdapter::ReadHeader stat[%d] aAudioLength[%d], aAudioType[%d], aFramesPerSample[%d], aTimeScale[%d], aAverateBitRate[%d]"), 
       
   519     	err, aAudioLength, aAudioType, aFramesPerSample, aTimeScale, aAverateBitRate);
       
   520 	iAudioType = aAudioType;    	
       
   521 	return(TranslateMP4Err(err));
       
   522 	}
       
   523     
       
   524 EXPORT_C TInt C3gpDataSourceAdapter::ReadAudioSpecificConfig(TUint8* aDecSpecInfo, TUint32 aDecSpecInfoSizeIn, TUint32* aDecSpecInfoSizeOut)
       
   525 	{
       
   526 	TInt err = KErrNone;
       
   527 	MP4Err stat = MP4ParseReadAudioDecoderSpecificInfo(iMP4Handle, aDecSpecInfo, aDecSpecInfoSizeIn, aDecSpecInfoSizeOut);
       
   528 	if ((stat == MP4_BUFFER_TOO_SMALL) && (aDecSpecInfo == NULL)) // This is valid Error as we are just getting the buffersize
       
   529 		{
       
   530 		err = KErrNone;
       
   531 		}
       
   532 	else
       
   533 		{
       
   534 		err = TranslateMP4Err(stat);
       
   535 		}
       
   536     DP2(_L("C3gpDataSourceAdapter::ReadAudioSpecificConfig info[0x%x] err[%d]"), aDecSpecInfo, err);
       
   537 	return err;
       
   538 	}
       
   539     
       
   540 // -----------------------------------------------------------------------------
       
   541 // Local
       
   542 // -----------------------------------------------------------------------------
       
   543 //
       
   544 void C3gpDataSourceAdapter::PrepareMP4ParserL()
       
   545 	{
       
   546     DP0(_L("C3gpDataSourceAdapter::PrepareMP4ParserL"));
       
   547 
       
   548     MP4Err err = MP4_ERROR;
       
   549 	
       
   550     if (iCafHandle)
       
   551         {
       
   552         // SourceStopL might terminate the access to the File, SourcePrimeL to regain access
       
   553         err = MP4ParseOpenCAF(&iMP4Handle, iCafHandle);
       
   554         DP1(_L("C3gpDataSourceAdapter::PrepareMP4ParserL, MP4ParseOpenCAF err = %d"), err);
       
   555         User::LeaveIfError(TranslateMP4Err(err));
       
   556         }
       
   557 	else if (iSourceType == KUidMmfDescriptorSource)	// KUidMmfDescriptorSource
       
   558 		{
       
   559 		err = MP4ParseOpen(&iMP4Handle, NULL);
       
   560 		User::LeaveIfError(TranslateMP4Err(err));
       
   561 
       
   562 		CMMFClip* clip = static_cast<CMMFClip*>(iDataSource);
       
   563 
       
   564 		TBool endOfFile = EFalse;
       
   565 		iSourceReadPosition = 0;
       
   566 		TUint8* buffer = const_cast<TUint8*>(iSrcBuf->Data().Ptr());
       
   567 		while (!endOfFile)
       
   568 			{
       
   569 			clip->ReadBufferL(iSrcBuf, iSourceReadPosition);
       
   570 			TUint buffersize = iSrcBuf->Data().Length();
       
   571 			
       
   572 			if (buffersize > 0)
       
   573 				{
       
   574 				err = MP4ParseWriteData(iMP4Handle, buffer, buffersize);
       
   575 		        DP1(_L("C3gpDataSourceAdapter::PrepareMP4ParserL, write desc buffer to parser stat[%d]"), err);
       
   576 				User::LeaveIfError(TranslateMP4Err(err));
       
   577 				iSourceReadPosition += buffersize;
       
   578 				}
       
   579 			else
       
   580 				{
       
   581 				endOfFile = ETrue;
       
   582 				// This call with empty buffer indicates to the 3GP library that
       
   583 				// this is the last buffer.
       
   584 				iLastBufferWrittenToMp4Lib = ETrue;
       
   585 				err = MP4ParseWriteData(iMP4Handle, buffer, 0);
       
   586 		        DP1(_L("C3gpDataSourceAdapter::PrepareMP4ParserL, write last desc buffer to parser stat[%d]"), err);
       
   587 				User::LeaveIfError(TranslateMP4Err(err));
       
   588 				}
       
   589 			}
       
   590 
       
   591 		clip->SourceStopL();
       
   592 		}
       
   593     else if (iReadMp4LibSync && (iSourceType != KOldProgDLSourceUid))
       
   594 //		    (iSourceType == KMmdsStreamingSourceUid) || (iSourceType == KMmdsProgDLSourceUid) || 
       
   595 //    		 (iSourceType == KS60AudioStreamingSourceUid) || (iSourceType == KMmdsFileSourceUid) || 
       
   596 //    		 (iSourceType == KMmdsDescriptorSourceUid))
       
   597         {
       
   598         err = MP4ParseOpen(&iMP4Handle, NULL);
       
   599         User::LeaveIfError(TranslateMP4Err(err));
       
   600         DP1(_L("C3gpDataSourceAdapter::PrepareMP4ParserL, iMMDataSource->FillBuffer buffer[%x]"), iSrcBuf->Data().Ptr());
       
   601    	    iSrcBuf->SetPosition(0);
       
   602 	    iSrcBuf->Data().SetLength(0);
       
   603 		iMMDataSource->FillBuffer(iSrcBuf);
       
   604         }
       
   605 	else if (iSourceType == KOldProgDLSourceUid)
       
   606 		{
       
   607 		err = MP4ParseOpen(&iMP4Handle, NULL);
       
   608 		User::LeaveIfError(TranslateMP4Err(err));
       
   609 
       
   610 		iSourceReadPosition = 0;
       
   611 		StartReadingSourceL();
       
   612 		}
       
   613 	else
       
   614 		{
       
   615 		User::Leave(KErrNotSupported);
       
   616 		}
       
   617 		
       
   618 	// MP4ParseRequestAudioDescription() is used here to initialize the parser internally
       
   619 	// before other parser functions can be used.
       
   620 	// The data gathered here is not used and the function may return an error in some cases.
       
   621 	// mp4_u32 audioLength, audioType, timeScale, averateBitRate;
       
   622 	mp4_u32 audioLength, timeScale, averateBitRate;	
       
   623 	mp4_u8 framesPerSample;
       
   624 	err = MP4ParseRequestAudioDescription(iMP4Handle, &audioLength, &iAudioType,	&framesPerSample, &timeScale, &averateBitRate);
       
   625 	if (err == MP4_OK)
       
   626 		{ // mmf descriptor source or a short file would put complete content to the parser
       
   627 		// so this needs to be set here.
       
   628 		iMp4HeaderAvail = ETrue;
       
   629 		}
       
   630 	if /*( ((iSourceType == KOldProgDLSourceUid) || (iSourceType == KMmdsFileSourceUid) ||
       
   631     	  (iSourceType == KMmdsStreamingSourceUid) || (iSourceType == KMmdsProgDLSourceUid) ||
       
   632     	  (iSourceType == KS60AudioStreamingSourceUid) || (iSourceType == KMmdsDescriptorSourceUid)) &&*/
       
   633     	 ((err == MP4_NOT_AVAILABLE) || (err == MP4_FILE_ERROR)) //)
       
   634         {
       
   635         // do nothing
       
   636         }
       
   637     else
       
   638         {
       
   639         DP1(_L("C3gpDataSourceAdapter::PrepareMP4ParserL Leave, err = %d"), err);
       
   640         User::LeaveIfError(TranslateMP4Err(err));
       
   641         }
       
   642 	}
       
   643 
       
   644 
       
   645 // -----------------------------------------------------------------------------
       
   646 // C3gpDataSourceAdapter::TranslateMP4Err
       
   647 // -----------------------------------------------------------------------------
       
   648 //
       
   649 TInt C3gpDataSourceAdapter::TranslateMP4Err(
       
   650 	MP4Err aError)
       
   651 	{
       
   652     DP1(_L("C3gpDataSourceAdapter::TranslateMP4Err err = %d"), aError);
       
   653 	TInt err;
       
   654 	switch (aError)
       
   655 		{
       
   656 		case MP4_OK:
       
   657 			err = KErrNone;
       
   658 			break;
       
   659 		case MP4_OUT_OF_MEMORY:
       
   660 			err = KErrNoMemory;
       
   661 			break;
       
   662 		case MP4_NOT_AVAILABLE:     // valid error for progressive download and streaming source
       
   663 			err = KErrNotReady;
       
   664 			break;
       
   665 		case MP4_FILE_ERROR:
       
   666 			err = KErrBadHandle;
       
   667 			break;
       
   668 		case MP4_INVALID_TYPE:
       
   669 			err = KErrNotSupported;
       
   670 			break;
       
   671 		case MP4_TIMESCALE_NOT_SET:
       
   672 			err = KErrNotReady;
       
   673 			break;
       
   674 		case MP4_NOT_STREAMABLE:
       
   675 		case MP4_NO_REQUESTED_FRAME:
       
   676 		case MP4_CANT_SEEK:
       
   677 		case MP4_INVALID_INPUT_STREAM:
       
   678 		case MP4_NO_FRAME:
       
   679 			err = KErrArgument;
       
   680 			break;
       
   681 		case MP4_ERROR:
       
   682 		case MP4_FILE_MODE:
       
   683 		case MP4_BUFFER_TOO_SMALL:
       
   684 		case MP4_END_OF_VIDEO:
       
   685 		case MP4_METADATA_ERROR:
       
   686 		case MP4_NO_VIDEO:
       
   687 		case MP4_NO_AUDIO:
       
   688 			err = KErrGeneral;
       
   689 			break;
       
   690 		default:
       
   691 			if (aError > 0)     //For Any 3GPLib Errors
       
   692                 {
       
   693                 err = KErrGeneral;
       
   694                 }
       
   695             else                // For CAF Errors 
       
   696                 {
       
   697                 err = aError;
       
   698                 }
       
   699 
       
   700 			break;
       
   701 		}
       
   702 
       
   703 	return err;
       
   704 	}
       
   705 
       
   706 
       
   707 CMMFDataBuffer* C3gpDataSourceAdapter::CreateSourceBufferOfSizeL(
       
   708 	TUint aSize )
       
   709     {
       
   710     CMMFDataBuffer* buffer = CMMFDataBuffer::NewL(aSize);
       
   711     CleanupStack::PushL(buffer);
       
   712     buffer->SetRequestSizeL(aSize);
       
   713     buffer->SetPosition(0);
       
   714 	buffer->Data().SetLength(0);
       
   715 	CleanupStack::Pop(buffer);	
       
   716     return buffer;
       
   717     }
       
   718     
       
   719     
       
   720 // -----------------------------------------------------------------------------
       
   721 // C3gpDataSourceAdapter::StartReadingSourceL
       
   722 // -----------------------------------------------------------------------------
       
   723 //
       
   724 void C3gpDataSourceAdapter::StartReadingSourceL()
       
   725 	{
       
   726     DP1(_L("C3gpDataSourceAdapter::StartReadingSourceL, iSourceReadPosition = %d"), iSourceReadPosition);
       
   727 
       
   728 	// kick off the asynchronous read from source
       
   729 //	iClip->SourcePrimeL();
       
   730 //	iClip->SourceThreadLogon(*this);
       
   731 	iSrcBuf->SetPosition(0);
       
   732 	iSrcBuf->Data().SetLength(0);
       
   733 	iClip->ReadBufferL(iSrcBuf, iSourceReadPosition, this);
       
   734 	iContinueReading = ETrue;
       
   735 	}
       
   736 	
       
   737 // -----------------------------------------------------------------------------
       
   738 // C3gpDataSourceAdapter::ReadAsync
       
   739 // -----------------------------------------------------------------------------
       
   740 //
       
   741 TInt C3gpDataSourceAdapter::ReadAsync()
       
   742     {
       
   743     TUint8* bufPtr = const_cast<TUint8*>(iParserBuf->Data().Ptr());
       
   744     mp4_u32 buffersize = iParserBuf->RequestSize();
       
   745     DP2(_L("C3gpDataSourceAdapter::ReadAsync ptr[%x] size[%d]"), bufPtr, buffersize);
       
   746     MP4Err err = MP4_ERROR;
       
   747     
       
   748     if (iMP4Handle)
       
   749         {
       
   750 	    err = MP4ParseReadAudioFramesAsync(iMP4Handle, this, bufPtr, &buffersize);
       
   751         }
       
   752     return err;
       
   753     }
       
   754 
       
   755 // -----------------------------------------------------------------------------
       
   756 // C3gpDataSourceAdapter::ReadSyncL
       
   757 // -----------------------------------------------------------------------------
       
   758 //
       
   759 TInt C3gpDataSourceAdapter::ReadSyncL()
       
   760     {
       
   761     TInt err = MP4_ERROR;
       
   762     CMMFDataBuffer* buffer = static_cast<CMMFDataBuffer*>(iFillingBuffer);
       
   763     TUint8* bufPtr = const_cast<TUint8*>(buffer->Data().Ptr()) + iFillingBuffer->Position();
       
   764 	TInt buffersize = iFillingBuffer->RequestSize() - iFillingBuffer->Position();
       
   765     DP4(_L("C3gpDataSourceAdapter::ReadSyncL, buffer[%x] length[%d] buffersize[%d] position[%d]"),
       
   766 		     buffer->Data().Ptr(), buffer->Data().Length(), buffersize, iFillingBuffer->Position());
       
   767 
       
   768 	TInt bytesAdded = 0;
       
   769 	mp4_u32 framesize;
       
   770 
       
   771 	while (ETrue)
       
   772 		{
       
   773 		if (iMp4HeaderAvail)
       
   774 			{ // know audio type after header read
       
   775 			err = MP4ParseNextFrameSize(iMP4Handle, iAudioType, &framesize);
       
   776 			if (err != MP4_OK)
       
   777 				{ // default in case not enough data
       
   778 				framesize = KMaxFrameSize;
       
   779 				err = MP4_OK;	
       
   780 				}
       
   781 			}	
       
   782 		else
       
   783 			{
       
   784 			framesize = KMaxFrameSize;		
       
   785 			}
       
   786 		if (buffersize >= framesize)
       
   787 	        {
       
   788     	    mp4_u32 audiosize, timestamp, returnedframes, timestamp2;
       
   789         	if (iMp4HeaderAvail)
       
   790 	        	{
       
   791 		  	    err = MP4ParseReadAudioFrames(iMP4Handle, bufPtr, buffersize, &audiosize, &timestamp, &returnedframes, &timestamp2);
       
   792 	   		    DP4(_L("C3gpDataSourceAdapter::ReadSyncL, MP4ParseReadAudioFrames err[%d] timestamp[%d] size[%d] d0[%x]"), 
       
   793 	   		    	err, timestamp, audiosize, bufPtr[0]);
       
   794 				mp4_u32 bytes;	   		    	
       
   795 	   		    TInt s = MP4ParseGetBufferedBytes(iMP4Handle, &bytes);
       
   796 			    DP2(_L("C3gpDataSourceAdapter::ReadSyncL bufferedbytes[%x] stat[%d]"),bytes,s);
       
   797 /*
       
   798 	    TInt block,aNumber =2;
       
   799         RHeap &heap = User::Heap();
       
   800         RDebug::Print(_L("### SB-Cont%d"), aNumber);
       
   801         RDebug::Print(_L("### SB-Cont%d: Heap Base Address: [0x%x]"),aNumber, heap.Base());
       
   802         RDebug::Print(_L("### SB-Cont%d: Available Heap Memory [%6d]"),aNumber, heap.Available(block));
       
   803         RDebug::Print(_L("### SB-Cont%d: Largest block: [%6d]"),aNumber, block);
       
   804         RDebug::Print(_L("### SB-Cont%d: Size: [%8d]"),aNumber, heap.Size());
       
   805         RDebug::Print(_L("### SB-Cont%d: Max length: [%8d]"),aNumber, heap.MaxLength());
       
   806 */
       
   807 
       
   808         		}
       
   809 	        else
       
   810     	    	{
       
   811         		err = MP4_NOT_AVAILABLE;
       
   812 	   	    	DP0(_L("C3gpDataSourceAdapter::ReadSyncL no read - header not available yet"));
       
   813 	        	}	
       
   814 				                            
       
   815 	        if (err == MP4_OK)
       
   816     	        {
       
   817 /*            if (!((iSourceType == KMmfAudioStreamingSourceUid) || (iSourceType == KMmfAudioProgDLSourceUid) 
       
   818                 || (iSourceType == KS60AudioStreamingSourceUid) || (iSourceType == KMmfFileSourceUid) || (iSourceType == KMmfDescriptorSourceUid)))   // pay attention to the ! (not condition)
       
   819                 {
       
   820                 TUint32 timePositionInMilliSecs = I64LOW(iPlayWindowEndPosition.Int64()/1000);
       
   821                     
       
   822                 if ((iPlayWindowEndPosition != TTimeIntervalMicroSeconds(0)) &&
       
   823                     (timestamp >= timePositionInMilliSecs))
       
   824                     {
       
   825                     aBuffer->SetLastBuffer(ETrue);
       
   826                     break;
       
   827                     }
       
   828                 }
       
   829 */                
       
   830 				bufPtr += audiosize;
       
   831 				buffersize -= audiosize;
       
   832 				bytesAdded += audiosize;
       
   833 				}
       
   834 	        else if ((err == MP4_NO_FRAME) ||
       
   835     	   			((err == MP4_NOT_AVAILABLE) && iLastBufferWrittenToMp4Lib))
       
   836   			    { // if the file is cut short, it might return not_available - so check for last buffer
       
   837    		    	iFillingBuffer->SetLastBuffer(ETrue);
       
   838 	            break;
       
   839    			    }
       
   840        		else if (err == MP4_NOT_AVAILABLE)
       
   841 	  		    { // in case parser is totally out of data
       
   842   			    TInt pos = buffer->Data().Length()+bytesAdded;
       
   843   			    buffer->Data().SetLength(pos); // must set length first to accomodate position
       
   844   		    	iFillingBuffer->SetPosition(pos);
       
   845   			    iRestartSyncRead = ETrue;
       
   846 			    DP3(_L("C3gpDataSourceAdapter::ReadSyncL, MP4_NOT_AVAILABLE bytesAdded[%d] pos[%d] length[%d]"), 
       
   847 		    		bytesAdded, iFillingBuffer->Position(), buffer->Data().Length());
       
   848 	            break;
       
   849    			    }
       
   850     		} // if buffer large enough for read
       
   851     	else
       
   852     		{ // if buffer too small for read
       
   853 		    DP3(_L("C3gpDataSourceAdapter::ReadSyncL, buffersize[%d] too small for next frame[%d] err[%d] should be 0"),
       
   854 		    		buffersize, framesize, err); 
       
   855     		break;
       
   856     		}
       
   857 		} // while ETrue keep filling buffer
       
   858 	if ((err == MP4_OK) || (iFillingBuffer->LastBuffer()))
       
   859 		{
       
   860 	    iQueValid = ETrue;
       
   861 	    buffer->Data().SetLength(buffer->Data().Length() + bytesAdded);
       
   862 	    DP2(_L("C3gpDataSourceAdapter::ReadSyncL, sending buffer to controller iFillingBuffer[%x], Length[%d]"),
       
   863 	    		buffer->Data().Ptr(), buffer->Data().Length());
       
   864     	iControllerMDataSink->BufferFilledL(iFillingBuffer); // setpos could come in here and clear the queue here and add another read
       
   865     	if (iQueValid)
       
   866         	{ // this detects if the que has been cleared and refilled
       
   867 		      // we don't want to do this with the new buffers in the queue
       
   868     	    iQueuedAsyncBuffers.Remove(0);
       
   869         	if (iQueuedAsyncBuffers.Count() > 0)
       
   870 	            {
       
   871     	        DP0(_L("C3gpDataSourceAdapter::ReadSyncL calls FillBufferL"));
       
   872         	    FillBufferL(iQueuedAsyncBuffers[0],this,iMediaId);
       
   873 	            }
       
   874     	    }
       
   875 		}
       
   876     TInt status = TranslateMP4Err(err);
       
   877 	return status;
       
   878     }
       
   879 
       
   880 void C3gpDataSourceAdapter::ResetVariables()
       
   881 	{
       
   882 	iRestartSyncRead = EFalse;
       
   883     iLastBufferWrittenToMp4Lib = EFalse;
       
   884     iMp4HeaderAvail = EFalse;
       
   885 	iQueuedAsyncBuffers.Reset();
       
   886 	iQueValid = EFalse;
       
   887 	}
       
   888 	
       
   889 // -----------------------------------------------------------------------------
       
   890 // C3gpDataSourceAdapter::CAsyncProxyFillBuffer
       
   891 // -----------------------------------------------------------------------------
       
   892 
       
   893 // -----------------------------------------------------------------------------
       
   894 // C3gpDataSourceAdapter::CAsyncProxyFillBuffer::CAsyncProxyFillBuffer
       
   895 // -----------------------------------------------------------------------------
       
   896 //
       
   897 C3gpDataSourceAdapter::CAsyncProxyFillBuffer::CAsyncProxyFillBuffer(C3gpDataSourceAdapter& a3gpDataSourceAdapter) :
       
   898     CActive(EPriorityHigh),
       
   899     i3gpDataSourceAdapter(a3gpDataSourceAdapter)
       
   900 	{
       
   901     DP0(_L("C3gpDataSourceAdapter::CAsyncProxyFillBuffer::CAsyncProxyFillBuffer"));
       
   902 	CActiveScheduler::Add(this);
       
   903 	}
       
   904 
       
   905 // -----------------------------------------------------------------------------
       
   906 // C3gpDataSourceAdapter::CAsyncProxyFillBuffer::~CAsyncProxyFillBuffer
       
   907 // -----------------------------------------------------------------------------
       
   908 //
       
   909 C3gpDataSourceAdapter::CAsyncProxyFillBuffer::~CAsyncProxyFillBuffer()
       
   910 	{
       
   911     DP0(_L("C3gpDataSourceAdapter::CAsyncProxyFillBuffer::~CAsyncProxyFillBuffer"));
       
   912 	}
       
   913 
       
   914 // -----------------------------------------------------------------------------
       
   915 // C3gpDataSourceAdapter::CAsyncProxyFillBuffer::GenerateCallback
       
   916 // -----------------------------------------------------------------------------
       
   917 //
       
   918 void C3gpDataSourceAdapter::CAsyncProxyFillBuffer::ReadSync()
       
   919 	{
       
   920     DP0(_L("C3gpDataSourceAdapter::CAsyncProxyFillBuffer::ReadSync"));
       
   921     iStatus = KRequestPending; // service request would be made here and pending set by service provider
       
   922 	SetActive();
       
   923 	iRequestStatus = &iStatus;
       
   924 	User::RequestComplete(iRequestStatus, KErrNone);
       
   925 	}
       
   926     
       
   927 // -----------------------------------------------------------------------------
       
   928 // C3gpDataSourceAdapter::CAsyncProxyFillBuffer::DoCancel
       
   929 // -----------------------------------------------------------------------------
       
   930 //
       
   931 void  C3gpDataSourceAdapter::CAsyncProxyFillBuffer::DoCancel()
       
   932 	{
       
   933     DP0(_L("C3gpDataSourceAdapter::CAsyncProxyFillBuffer::DoCancel"));
       
   934 	}
       
   935 
       
   936 // -----------------------------------------------------------------------------
       
   937 // C3gpDataSourceAdapter::CAsyncProxyFillBuffer::RunL
       
   938 // -----------------------------------------------------------------------------
       
   939 //
       
   940 void C3gpDataSourceAdapter::CAsyncProxyFillBuffer::RunL()
       
   941 	{
       
   942     DP0(_L("C3gpDataSourceAdapter::CAsyncProxyFillBuffer::RunL"));
       
   943     i3gpDataSourceAdapter.ReadSyncL();
       
   944 	}
       
   945 
       
   946 // -----------------------------------------------------------------------------
       
   947 // C3gpDataSourceAdapter::CAsyncProxyFillBuffer::RunError
       
   948 // -----------------------------------------------------------------------------
       
   949 //
       
   950 TInt C3gpDataSourceAdapter::CAsyncProxyFillBuffer::RunError(TInt aError)
       
   951 	{
       
   952 	if (aError)
       
   953 	    {
       
   954 	    DP1(_L("C3gpDataSourceAdapter::CAsyncProxyFillBuffer::RunError, aError = %d"), aError);
       
   955 	    }
       
   956 	return KErrNone;
       
   957 	}
       
   958 
       
   959 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   960 
       
   961 // End of File
       
   962