Esempio n. 1
0
GLDEF_C void ExternalizeL(const CDbKey& aKey,RWriteStream& aStream)
	{
	TInt cc=aKey.Count();
	aStream.WriteInt32L(cc);
	for (TInt ii=0;ii<cc;++ii)
		{
		const TDbKeyCol& col=aKey[ii];
		aStream<<col.iName<<TUint8(col.iOrder)<<TInt32(col.iLength);
		}
	aStream<<TUint8(aKey.Comparison())<<TUint8(aKey.IsUnique());
	}
Esempio n. 2
0
LOCAL_C TInt WavRecord()
	{
	// Parse the commandline and get a filename to use
	TLex l(CommandLine);
	TParse destinationName;
	if (destinationName.SetNoWild(l.NextToken(),0,0)!=KErrNone)
		{
		Test.Printf(_L("No arg, skipping\r\n"));
		return(KErrArgument);
		}
	Test.Next(_L("Record Wav file"));

	// Open the file for writing
	TInt r;
	RFile destination;
	r = destination.Replace(Fs,destinationName.FullName(),EFileWrite);
	if (r!=KErrNone)
		{
		Test.Printf(_L("Open file for write failed(%d)\n"), r);
		return(r);
		}		
	Test.Printf(_L("File opened for write\r\n"));
	
	Test.Next(_L("Preparing to record"));
	
	// Get the rate
	TLex cl(l.NextToken());
	TUint32 tmpRate;
	TSoundRate rate;
	r = cl.Val(tmpRate,EDecimal);
	if (r == KErrNone && (r=SamplesPerSecondToRate(tmpRate,rate))==KErrNone)
		{
		Test.Printf(_L("Parsed rate: %d\r\n"), tmpRate);
		RecordFormatBuf().iRate = rate;
		}
	else
		{
		Test.Printf(_L("Parse rate failed(%d)\r\n"),r);
		RecordFormatBuf().iRate = ESoundRate32000Hz;
		}

	// Get number of channels
	TLex cl_chan(l.NextToken());
	TUint32 tmpChannels;
	r = cl_chan.Val(tmpChannels,EDecimal);
	if (r == KErrNone)
		{
		Test.Printf(_L("Parsed %d channels\r\n"),tmpChannels);
		RecordFormatBuf().iChannels = tmpChannels;
		}
	else
		{
		Test.Printf(_L("Parse channels failed(%d)\r\n"), r);
		RecordFormatBuf().iChannels = 2;
		}

	RecordFormatBuf().iEncoding = ESoundEncoding16BitPCM;
	
	// Set the record buffer configuration.
	RChunk chunk;
	TTestSharedChunkBufConfig bufferConfig;
	bufferConfig.iNumBuffers=4;
	bufferConfig.iBufferSizeInBytes=RecordBufferSizeInBytes(RecordFormatBuf());
	if (RecordCapsBuf().iRequestMinSize)
		bufferConfig.iBufferSizeInBytes&=~(RecordCapsBuf().iRequestMinSize-1); 	// Keep the buffer length valid for the driver.
	bufferConfig.iFlags=0;	
	PrintBufferConf(bufferConfig,Test);
	TPckg<TTestSharedChunkBufConfig> bufferConfigBuf(bufferConfig);
	r=RxSoundDevice.SetBufferChunkCreate(bufferConfigBuf,chunk);
	if (r!=KErrNone)
		{
		Test.Printf(_L("Buffer configuration not supported(%d)\r\n"),r);
		return(r);
		}
	
	// Set the audio record configuration.
	RxSoundDevice.SetVolume(KSoundMaxVolume);
	PrintConfig(RecordFormatBuf(),Test);
	r=RxSoundDevice.SetAudioFormat(RecordFormatBuf);
	if (r!=KErrNone)
		{
		Test.Printf(_L("Format not supported\r\n"));
		return(r);
		}

	// Get length in seconds
	TLex cl_seconds(l.NextToken());
	TUint32 tmpSeconds;
	r = cl_seconds.Val(tmpSeconds,EDecimal);
	if (r == KErrNone)
		{
		Test.Printf(_L("Parsed %d seconds\r\n"),tmpSeconds);
		}
	else
		{
		Test.Printf(_L("Parse seconds failed(%d)\r\n"),r);
		tmpSeconds=10;
		}
	TInt bytesToRecord = BytesPerSecond(RecordFormatBuf())*tmpSeconds;	
		
	Test.Next(_L("Recording..."));
	
	// Lay down a file header
	WAVEheader header;
	TPtr8 headerDes((TUint8 *)&header, sizeof(struct WAVEheader), sizeof(struct WAVEheader));

	// "RIFF"
	header.ckID[0] = 'R'; header.ckID[1] = 'I';
	header.ckID[2] = 'F'; header.ckID[3] = 'F';
	// "WAVE"
	header.wave_ckID[0] = 'W'; header.wave_ckID[1] = 'A';
	header.wave_ckID[2] = 'V'; header.wave_ckID[3] = 'E';
	// "fmt "
	header.fmt_ckID[0] = 'f'; header.fmt_ckID[1] = 'm';
	header.fmt_ckID[2] = 't'; header.fmt_ckID[3] = ' ';
	// "data"
	header.data_ckID[0] = 'd'; header.data_ckID[1] = 'a';
	header.data_ckID[2] = 't'; header.data_ckID[3] = 'a';

	header.nChannels		= (TUint16)RecordFormatBuf().iChannels;
	header.nSamplesPerSec	= RateInSamplesPerSecond(RecordFormatBuf().iRate);
	header.nBitsPerSample	= 16;
	header.nBlockAlign		= TUint16((RecordFormatBuf().iChannels == 2) ? 4 : 2);
	header.formatTag		= 1;	// type 1 is PCM
	header.fmt_ckSize		= 16;
	header.nAvgBytesPerSec	= BytesPerSecond(RecordFormatBuf());
	header.data_ckSize		= bytesToRecord;
	header.ckSize			= bytesToRecord + sizeof(struct WAVEheader) - 8;

	Test.Printf(_L("Header rate:%d channels:%d tag:%d bits:%d (%d bytes/s) align %d datalen:%d fmt_ckSize:%d ckSize:%d\r\n"),
			header.nSamplesPerSec, header.nChannels, header.formatTag, header.nBitsPerSample,
			header.nAvgBytesPerSec, header.nBlockAlign, header.data_ckSize, header.fmt_ckSize, header.ckSize, sizeof(struct WAVEheader));

	r = destination.Write(headerDes);

	TRequestStatus stat;
	TInt length;
	TPtrC8 buf;

	TTime startTime;
	startTime.HomeTime();
	
	// Start off by issuing a record request.
	TTime starttime;
	starttime.HomeTime();
	TInt bytesRecorded = 0;
	RxSoundDevice.RecordData(stat,length);

	TInt pausesToDo = 10;
	pausesToDo = 0;
	FOREVER
		{
		// Wait for the outstanding record request to complete.
        User::After(6000);

		User::WaitForAnyRequest();
		if (stat==KRequestPending)
			return(KErrGeneral);

		TTime currentTime;
		currentTime.HomeTime();
		TInt64 elapsedTime = currentTime.Int64()-startTime.Int64();	// us
		TTimeIntervalMicroSecondsBuf timeRecordedBuf;
		if(RxSoundDevice.TimeRecorded(timeRecordedBuf) == KErrNone)
			{
			// Compare TimeRecorded with the actual elapsed time. They should be different, but not drift apart too badly...
			TInt32 offset = TInt32(elapsedTime - timeRecordedBuf().Int64());
			Test.Printf(_L("\telapsedTime - TimeRecorded = %d ms\n"), offset/1000);
			}		
			
		// Check whether the record request was succesful.
		TInt retOffset=stat.Int();
		if (retOffset<0)
			{
			Test.Printf(_L("Record failed(%d)\r\n"),retOffset);
			return(retOffset);
			}
		
		// Successfully recorded another buffer so write the recorded data to the record file and release the buffer.
		buf.Set((const TUint8*)(chunk.Base()+retOffset),length);
		r=destination.Write(buf);
		if (r!=KErrNone)
			{
			Test.Printf(_L("File write failed(%d)\r\n"),r);
			return(r);
			}
		r=RxSoundDevice.ReleaseBuffer(retOffset);
		if (r!=KErrNone)
			{
			Test.Printf(_L("Release buffer failed(%d)\r\n"),r);
			return(r);
			}
		
		Test.Printf(_L("Recorded %d more bytes - %d\r\n"),length,retOffset);

		if((pausesToDo > 0) && (bytesRecorded > bytesToRecord/2))
			{
			--pausesToDo;
			Test.Printf(_L("Pause\r\n"));
			RxSoundDevice.Pause();
			Test.Printf(_L("Paused, sleeping for 0.5 seconds\r\n"));
			User::After(500*1000);
            Test.Printf(_L("Resume\r\n"));
			RxSoundDevice.Resume();
			}
		
		// Check whether we have now recorded all the data. If more to record then queue a further request
		bytesRecorded+=length;
		if (bytesRecorded<bytesToRecord)
		    {
            Test.Printf(_L("RecordData\r\n"));
			RxSoundDevice.RecordData(stat,length);
		    }
		else
			break;
		}
	
	RxSoundDevice.CancelRecordData();	// Stop the driver from recording.
	
	TTime endtime;
	endtime.HomeTime();

	TInt64 elapsedTime = endtime.Int64()-starttime.Int64();	// us
	Test.Printf(_L("Delta time = %d\r\n"),I64LOW(elapsedTime));
	Test.Printf(_L("Seconds in buffer: %d (%d)\r\n"), bytesRecorded / header.nAvgBytesPerSec, (bytesRecorded / header.nAvgBytesPerSec)*1000000);

	if (I64LOW(elapsedTime) <= (bytesRecorded / header.nAvgBytesPerSec)*1000000)
		{
		Test.Printf(_L("Time travelling; record took less time than it should have done\r\n"));
		return(KErrGeneral);
		}
	
	chunk.Close();
	destination.Close();

	Test.Printf(_L("Record finished\r\n"));
	return(KErrNone);
	}
Esempio n. 3
0
LOCAL_C TInt WavPlay()
	{
	RChunk chunk;
	
	// Parse the commandline and get a filename to use
	TLex l(CommandLine);
	TFileName thisfile=RProcess().FileName();
	TPtrC token=l.NextToken();
	if (token.MatchF(thisfile)==0)
		token.Set(l.NextToken());

	if (token.Length()==0)
		{
		// No args, skip to end
		Test.Printf(_L("Invalid configuration\r\n"));
		return(KErrArgument);
		}
		
	Test.Next(_L("Play Wav file"));

	// Assume that the argument is a WAV filename
	TFileName wavFilename=token;
	TInt r;
	RFile source;
	r = source.Open(Fs,wavFilename,EFileRead);
	if (r!=KErrNone)
		{
		Test.Printf(_L("Open failed(%d)\r\n"), r);
		return(r);
		}

	// Read the pcm header
	WAVEheader header;
	TPtr8 headerDes((TUint8 *)&header,sizeof(struct WAVEheader),sizeof(struct WAVEheader));
	r = source.Read(headerDes);
	if (r!=KErrNone)
		{
		source.Close();
		return(r);
		}
	Test.Printf(_L("Header Read %d bytes\r\n"),headerDes.Size());

	if (headerDes.Size() != sizeof(struct WAVEheader)) // EOF
		{
		Test.Printf(_L("Couldn't read a header(%d bytes)\r\n"),headerDes.Size());
		source.Close();
		return(KErrCorrupt);
		}

	Test.Printf(_L("Header rate:%d channels:%d tag:%d bits:%d (%d bytes/s) align %d datalen:%d fmt_ckSize:%d ckSize:%d\n"),
			header.nSamplesPerSec, header.nChannels, header.formatTag, header.nBitsPerSample,
			header.nAvgBytesPerSec, header.nBlockAlign, header.data_ckSize, header.fmt_ckSize, header.ckSize);

	if (header.formatTag != 1) // not pcm
		{
		Test.Printf(_L("Format not PCM(%d)\r\n"),header.formatTag);
		source.Close();
		return(KErrNotSupported);
		}

	if (header.nBitsPerSample != 16) // not 16 bit
		{
		Test.Printf(_L("Format not 16 bit PCM(%d bits)\r\n"),header.nBitsPerSample);
		source.Close();
		return(KErrNotSupported);
		}
		
	TSoundRate rate;	
	if (SamplesPerSecondToRate(header.nSamplesPerSec,rate)!=KErrNone)	
		{
		Test.Printf(_L("Format specifies a rate not supported(%d)\r\n"),header.nSamplesPerSec);
		source.Close();
		return(KErrNotSupported);
		}

	TxSoundDevice.AudioFormat(PlayFormatBuf);	// Read back the current setting which must be valid.
	PlayFormatBuf().iChannels = header.nChannels;
	PlayFormatBuf().iRate = rate;
	PlayFormatBuf().iEncoding = ESoundEncoding16BitPCM;
	
	// Set the play buffer configuration.
	TInt bufSize=BytesPerSecond(PlayFormatBuf())/8; 	// Large enough to hold 1/8th second of data.
	bufSize&=~(header.nBlockAlign-1);					// Keep the buffer length a multiple of the bytes per sample (assumes 16bitPCM, 1 or 2 chans).
	if (PlayCapsBuf().iRequestMinSize)
		bufSize&=~(PlayCapsBuf().iRequestMinSize-1); 	// Keep the buffer length valid for the driver.
	TTestSharedChunkBufConfig bufferConfig;
	bufferConfig.iNumBuffers=3;
	bufferConfig.iBufferSizeInBytes=bufSize;
	bufferConfig.iFlags=0;	
	PrintBufferConf(bufferConfig,Test);
	TPckg<TTestSharedChunkBufConfig> bufferConfigBuf(bufferConfig);
	r=TxSoundDevice.SetBufferChunkCreate(bufferConfigBuf,chunk);
	if (r!=KErrNone)
		{
		Test.Printf(_L("Buffer configuration not supported(%d)\r\n"),r);
		source.Close();
		return(r);
		}
	TxSoundDevice.GetBufferConfig(bufferConfigBuf);			// Read back the configuration - to get the buffer offsets
	CHECK(bufferConfig.iBufferSizeInBytes==bufSize);

	// Set the audio play configuration.
	TxSoundDevice.SetVolume(KSoundMaxVolume - (KSoundMaxVolume / 4)); // set volume to 75%
	PrintConfig(PlayFormatBuf(),Test);
	r=TxSoundDevice.SetAudioFormat(PlayFormatBuf);
	if (r!=KErrNone)
		{
		Test.Printf(_L("Format not supported\r\n"));
		source.Close();
		chunk.Close();
		return(r);
		}
	TxSoundDevice.ResetBytesTransferred();

	TInt32 bytesToPlay = header.data_ckSize;
	TTime starttime;
	starttime.HomeTime();

	TRequestStatus stat[3];
	TPtr8* tPtr[3];
	TInt i;
	for (i=0;i<3;i++)
		tPtr[i]=new TPtr8(NULL,0); 

	TTime startTime;
	startTime.HomeTime();
	
	// Start off by issuing a play request for each buffer (assuming that the file is long enough). Use the full size
	// of each buffer.
	TInt stillToRead=bytesToPlay;
	TInt stillNotPlayed=bytesToPlay;
	TUint flags;
	for (i=0 ; i<3 ; i++)
		{
		// Setup the descriptor for reading in the data from the file.
		tPtr[i]->Set(chunk.Base()+bufferConfig.iBufferOffsetList[i],0,bufSize); 
		
		// If there is still data to read to play then read this into the descriptor
		// and then write it to the driver.
		if (stillToRead)
			{
			r=source.Read(*tPtr[i],Min(stillToRead,bufSize));
			if (r!=KErrNone)
				{
				Test.Printf(_L("Initial file read error(%d)\r\n"),r);
				source.Close();
				chunk.Close();
				return(r);
				}
			stillToRead-=tPtr[i]->Length();
			flags=(stillToRead>0)?0:KSndFlagLastSample;
			TxSoundDevice.PlayData(stat[i],bufferConfig.iBufferOffsetList[i],tPtr[i]->Length(),flags);
			}
		else
			stat[i]=KRequestPending;	
		}	
		
	FOREVER
		{
		// Wait for any one of the outstanding play requests to complete.
		User::WaitForAnyRequest();

		TTime currentTime;
		currentTime.HomeTime();
		TInt64 elapsedTime = currentTime.Int64()-startTime.Int64();	// us
		TTimeIntervalMicroSecondsBuf timePlayedBuf;
		if(TxSoundDevice.TimePlayed(timePlayedBuf) == KErrNone)
			{
			// Compare TimePlayed with the actual elapsed time. They should be different, but not drift apart too badly...
			TInt32 offset = TInt32(elapsedTime - timePlayedBuf().Int64());
			Test.Printf(_L("\telapsedTime - TimePlayed = %d ms\n"), offset/1000);
			}		
	
		// Work out which buffer this applies to
		for (i=0 ; i<3 ; i++)
			{
			if (stat[i]!=KRequestPending)
				break;
			}
		if (i>=3)
			{
			Test.Printf(_L("I/O error\r\n"));
			source.Close();
			chunk.Close();
			return(KErrGeneral);
			}
	
		// Check that the transfer was succesful and whether we have now played all the file.
		if (stat[i]!=KErrNone)
			{
			Test.Printf(_L("Play error(%d)\r\n"),stat[i].Int());
			source.Close();
			chunk.Close();
			return(stat[i].Int());
			}
		Test.Printf(_L("Played %d bytes(%d) - %d\r\n"),tPtr[i]->Length(),i,stat[i].Int());
		stillNotPlayed-=tPtr[i]->Length();
		CHECK(stillNotPlayed>=0);
		if (!stillNotPlayed)
			break;
	
		// Still more to be played so read the next part of the file into the descriptor for this
		// buffer and then write it to the driver.
		if (stillToRead)
			{
			TInt len=Min(stillToRead,bufSize);
		
			// If we've got to the end of the file and the driver is particular about the request length then 
			// zero fill the entire buffer so we can play extra zeros after the last sample from the file.
			if (len<bufSize && PlayCapsBuf().iRequestMinSize)
				tPtr[i]->FillZ(bufSize);
		
			// Read the next part of the file 
			r=source.Read(*tPtr[i],len);			// This will alter the length of the descriptor
			if (r!=KErrNone)
				{
				Test.Printf(_L("File read error(%d)\r\n"),r);
				source.Close();
				chunk.Close();
				return(r);
				}
			stillToRead-=tPtr[i]->Length();
		
			// If we've got to the end of the file and the driver is particular about the request length then
			// round up the length to the next valid boundary. This is OK since we zero filled.
			if (tPtr[i]->Length() < bufSize && PlayCapsBuf().iRequestMinSize)
				{
				TUint m=PlayCapsBuf().iRequestMinSize-1;
				len=(tPtr[i]->Length() + m) & ~m;
				}
		
			// Write it to the driver.
			flags=(stillToRead>0)?0:KSndFlagLastSample;
			TxSoundDevice.PlayData(stat[i],bufferConfig.iBufferOffsetList[i],len,flags);
			}
		else
			stat[i]=KRequestPending;		
		}
	
	// Delete all the variables again.	
	for (i=0 ; i<3 ; i++)
		delete tPtr[i];
	
	TTime endtime;
	endtime.HomeTime();

	Test.Printf(_L("Done playing\r\n"));
	Test.Printf(_L("Bytes played = %d\r\n"),TxSoundDevice.BytesTransferred());
	Test.Printf(_L("Delta time = %d\r\n"),endtime.Int64()-starttime.Int64());

	chunk.Close();
	source.Close();
	return(KErrNone);
	}
Esempio n. 4
0
LOCAL_C TInt testAsyncAccess(TAny* aData)
//
/// Test read file handling.
///
/// @param aData pointer to the thread data area
    {
	TThreadData& data = *(TThreadData*)aData;
	TFileName fileName = data.iFile;
	TBool     dowrite  = (data.iData != NULL);
	TBuf8<KBufLen>* buffer = gBufferArr[data.iNum];
	TRequestStatus* status = gStatusArr[data.iNum];

	RFs   myFs;
	TInt r = myFs.Connect();
	TEST(r==KErrNone);

	r = myFs.SetSessionPath(gSessionPath);
	if (r != KErrNone)
		TTest::Fail(HERE, _L("SetSessionPath returned %d"), r);

	TVolumeInfo vol;
	TInt        drv;
	r = myFs.CharToDrive(fileName[0], drv);
	if (r != KErrNone)
		TTest::Fail(HERE, _L("CharToDrive(%c) returned %d"), fileName[0], r);
	r = myFs.Volume(vol, drv);
	if (r != KErrNone)
		TTest::Fail(HERE, _L("Volume() returned %d"), r);

	TInt64 maxwrite = vol.iFree / 2 - KBufLen;
	if (maxwrite < KBufLen*2)
		TTest::Fail(HERE, _L("Not enough space to do test, only %d KB available"),
					 TInt(vol.iFree/1024));

    RFile f;
	RTimer timer;
	TRequestStatus tstat;
	TTime startTime;
	TTime endTime;
	TTimeIntervalMicroSeconds timeTaken;

	TInt wrnum = 0;
	TInt rdnum = 0;
	TInt opnum = 0;
	TInt opfin = 0;
	TInt i;

	timer.CreateLocal();

	if (dowrite)
		{
		r = f.Replace(myFs, fileName, EFileStreamText | EFileWrite);
		TEST(r==KErrNone);

		// wait for both tasks to have a chance to complete opening the files
		User::After(1000);

		for (i = 0; i < KNumBuf; i++)
			buffer[i].Fill('_', KBufLen);

		timer.After(tstat, KTimeBM * KSecond);

		startTime.HomeTime();

		while (tstat == KRequestPending)
			{
			TInt pos = TInt((wrnum * KBufLen) % maxwrite);
			TInt bnum = opnum++ % KNumBuf;
			f.Write(pos, buffer[bnum], status[bnum]);
			if (opnum - opfin > KMaxLag)
				{
				while (status[opfin % KNumBuf] == KRequestPending)
					User::WaitForRequest(status[opfin % KNumBuf]);
				opfin++;
				}
			++wrnum;
			}

		while (opfin < opnum)
			{
			while (status[opfin % KNumBuf] == KRequestPending)
				User::WaitForRequest(status[opfin % KNumBuf]);
			opfin++;
			}

		endTime.HomeTime();
		TTimeIntervalMicroSeconds timeTaken=endTime.MicroSecondsFrom(startTime);

		TInt64 dtime = timeTaken.Int64();
		TInt64 dsize = wrnum * KBufLen * TInt64(KSecond);
		TInt32 speed = TInt32((dsize + dtime/2) / dtime);
		AddStats(gWrStats, dsize, dtime);

		TTest::Printf(_L("%8d writes in %6d mS = %8d bytes per second\n"),
					  wrnum, TInt32(dtime)/1000, speed);
		}
	else
		{
		r = f.Open(myFs, fileName, EFileStreamText);
		TEST(r==KErrNone);

		timer.After(tstat, KTimeBM * KSecond);

		startTime.HomeTime();

		while (tstat == KRequestPending)
			{
			TInt pos = TInt((rdnum * KBufLen) % maxwrite);
			TInt bnum = opnum++ % KNumBuf;
			f.Read(pos, buffer[bnum], status[bnum]);
			if (opnum - opfin > KMaxLag)
				{
				User::WaitForRequest(status[opfin++ % KNumBuf]);
				}
			++rdnum;
			}

		while (opfin < opnum)
			{
			if (status[opfin % KNumBuf] == KRequestPending)
				User::WaitForRequest(status[opfin % KNumBuf]);
			opfin++;
			}

		endTime.HomeTime();
		timeTaken=endTime.MicroSecondsFrom(startTime);
		TInt64 dtime = timeTaken.Int64();
		TInt64 dsize = rdnum * KBufLen * TInt64(KSecond);
		TInt32 speed = TInt32((dsize + dtime/2) / dtime);
		AddStats(gRdStats, dsize, dtime);

		// wait to allow the dust to settle
		User::After(KSecond);

		TTest::Printf(_L("%8d reads  in %6d mS = %8d bytes per second\n"),
					  rdnum, TInt32(dtime)/1000, speed);

		myFs.Delete(fileName);
		}

	timer.Cancel();
	timer.Close();
	f.Close();
	myFs.Close();
	return r;
    }
Esempio n. 5
0
GLDEF_C void ExternalizeL(const TDbCol& aCol,RWriteStream& aStream)
	{
	aStream<<aCol.iName<<TUint8(aCol.iType)<<TInt32(aCol.iMaxLength)<<TUint8(aCol.iAttributes);
	}
Esempio n. 6
0
bool CCpu::SingleStep()
{
    ServiceInterruptRequest();
    
    //Save incoming PC to compare with the outgoing one. If they are identical
    //this indicates a "halt" instruction.
    TUint16 incommingPc = iRegMap.iPC;
    
    //Read the instruction, and decode the op code.
    TUint16 inst = iMemMap[iRegMap.iPC++];
    TUint op = Decode::BasicOpCode(inst);
    
    //All opcodes need to read and/or write operand A.
    TUint16& a = Decode::OperandA(iRegMap, iMemMap, Decode::A(inst));
    
    if(op != Decode::EOpCodeSPECIAL)
    {
        //All basic instructions need to read A and read and/or write B.
        TUint16& b = Decode::OperandB(iRegMap, iMemMap, Decode::B(inst));
        
        switch(op)
        {
            case Decode::EOpCodeSET:
            {
                b = a;
                AddCycles(1);
                break;
            }
                
            case Decode::EOpCodeADD:
            {
                TUint32 u32 = TUint32(b) + TUint32(a);
                b = TUint16(u32 & 0xffff);
                iRegMap.iEX = TUint16(u32 >> 16);
                AddCycles(2);
                break;
            }
                
            case Decode::EOpCodeSUB:
            {
                TUint32 u32 = TUint32(b) - TUint32(a);
                b = TUint16(u32 & 0xffff);
                iRegMap.iEX = TUint16(u32 >> 16);
                AddCycles(2);
                break;
            }
                
            case Decode::EOpCodeMUL:
            {
                TUint32 u32 = TUint32(b) * TUint32(a);
                b = TUint16(u32 & 0xffff);
                iRegMap.iEX = TUint16(u32 >> 16);
                AddCycles(2);
                break;
            }
                
            case Decode::EOpCodeMLI:
            {
                TInt32 i32 = TInt32(b) * TInt32(a);
                b = TUint16(i32 & 0x7fff);
                iRegMap.iEX = TUint16(i32 >> 16);
                AddCycles(2);
                break;
            }
                
            case Decode::EOpCodeDIV:
            {
                if(a == 0)
                {
                    b = 0;
                    iRegMap.iEX = 0;
                }
                else
                {
                    b /= a;
                    iRegMap.iEX = TUint16(((TUint32(b) << 16) / TUint32(a)));
                }
                AddCycles(3);
                break;
            }
                
            case Decode::EOpCodeDVI:
            {
                if(a == 0)
                {
                    b = 0;
                    iRegMap.iEX = 0;
                }
                else
                {
                    TInt32 sa = TInt32(a);
                    TInt32 sb = TInt32(b);
                    b = TUint16(sb / sa);
                    iRegMap.iEX = TUint16((sb << 16) / sa);
                }
                AddCycles(3);
                break;
            }
                
            case Decode::EOpCodeMOD:
            {
                if(a == 0)
                {
                    b = 0;
                } 
                else 
                {
                    b = TUint16(TInt32(b) % TInt32(a));
                }
                AddCycles(3);
                break;
            }
                
            case Decode::EOpCodeMDI:
            {
                if(a == 0)
                {
                    b = 0;
                }
                else
                {
                    b = TUint16(TInt32(b) % TInt32(a));
                }
                AddCycles(3);
                break;
            }
                
            case Decode::EOpCodeAND:
            {
                b &= a;
                AddCycles(1);
                break;
            }
                
            case Decode::EOpCodeBOR:
            {
                b |= a;
                AddCycles(1);
                break;
            }
                
            case Decode::EOpCodeXOR:
            {
                b ^= a;
                AddCycles(1);
                break;
            }
                
            case Decode::EOpCodeSHR:
            {
                b >>= a;
                iRegMap.iEX = TUint16(((TUint32(b) << 16) >> TUint32(a)));
                AddCycles(1);
                break;
            }
                
            case Decode::EOpCodeASR:
            {
                TInt32 sb = TInt32(b);
                b = TUint16(sb >> a);
                iRegMap.iEX = TUint16((TInt32(sb) << 16) >> TUint32(a));
                AddCycles(1);
                break;
            }
                
            case Decode::EOpCodeSHL:
            {
                TUint32 u32 = TUint32(b) << TUint32(a);
                b = TUint16(u32 & 0xffff);
                iRegMap.iEX = TUint16(u32 >> 16);
                AddCycles(1);
                break;
            }

            case Decode::EOpCodeIFB:
            {
                if((b & a) == 0)
                {
                    SkipInstructions();
                }
                AddCycles(2);
                break;
            }
                
            case Decode::EOpCodeIFC:
            {
                if((b & a) != 0)
                {
                    SkipInstructions();
                }
                AddCycles(2);
                break;
            }
                
            case Decode::EOpCodeIFE:
            {
                if(b != a)
                {
                    SkipInstructions();
                }
                AddCycles(2);
                break;
            }
                
            case Decode::EOpCodeIFN:
            {
                if(b == a)
                {
                    SkipInstructions();
                }
                AddCycles(2);
                break;
            }
                
            case Decode::EOpCodeIFG:
            {
                if(b <= a)
                {
                    SkipInstructions();
                }
                AddCycles(2);
                break;
            }
                
            case Decode::EOpCodeIFA:
            {
                if(TInt32(b) <= TInt32(a))
                {
                    SkipInstructions();
                }
                AddCycles(2);
                break;
            }
                
            case Decode::EOpCodeIFL:
            {
                if(b >= a)
                {
                    SkipInstructions();
                }
                AddCycles(2);
                break;
            }
                
            case Decode::EOpCodeIFU:
            {
                if(TInt32(b) >= TInt32(a))
                {
                    SkipInstructions();
                }
                AddCycles(2);
                break;
            }
                
            case Decode::EOpCodeADX:
            {
                TUint32 u32 = TUint32(b) + TUint32(a) + TUint32(iRegMap.iEX);
                b = TUint16(u32 & 0xffff);
                iRegMap.iEX = TUint16(u32 >> 16);
                AddCycles(3);
                break;
            }
                
            case Decode::EOpCodeSBX:
            {
                TUint32 u32 = TUint32(b) - TUint32(a) + TUint32(iRegMap.iEX);
                b = TUint16(u32 & 0xffff);
                iRegMap.iEX = TUint16(u32 >> 16);
                AddCycles(3);
                break;
            }
                
            case Decode::EOpCodeSTI:
            {
                b = a;
                iRegMap.iI++;
                iRegMap.iJ++;
                AddCycles(2);
                break;
            }
                
            case Decode::EOpCodeSTD:
            {
                b = a;
                iRegMap.iI--;
                iRegMap.iJ--;
                AddCycles(2);
                break;
            }
                
            default: assert("Unknown basic op code" && false);
        }
    }
void CCamcTestClient_9::RunLContinuedL()
// This function exist to skip a MS VC6 bug/feature
// Without this, VC6 would complains about stack abuse. 
    {
        if ( iPaused ) //resume
        {
        switch ( iAction )
            {
            case K_TC9_NewFileNameWhenPaused : 
                {
                    
                AddDriveLetterToPath(_L("NewFileName.3gp"), iFileName );
                    
                iAction=K_Tc9_none;     
                
                TMMFFileParams params;
                params.iPath = iFileName;
                TPckgC<TMMFFileParams> pckg(params);
                
                TUid controllerUid = {0x101F8503};	// controller implementation interface uid
                TInt err = iCamc->CustomCommandSync( TMMFMessageDestination( controllerUid, KMMFObjectHandleController ), ECamCControllerCCNewFilename, pckg, KNullDesC8);
                if (err)
                    {
                    User::Leave(err);
                    }
                break;
                }
            default:   
                iPaused = EFalse;
                iCamc->Record();
            }
        }
    
    else //timer
        {
        switch ( iAction )
            {
            case K_TC9_NewFileNameWhenRecording : 
                {
                AddDriveLetterToPath(_L("NewFileName.3gp"), iFileName );
                
                TMMFFileParams params;
                params.iPath = iFileName;
                TPckgC<TMMFFileParams> pckg(params);
                
                TUid controllerUid = {0x101F8503};	// controller implementation interface uid
                TInt err = iCamc->CustomCommandSync( TMMFMessageDestination( controllerUid, KMMFObjectHandleController ), ECamCControllerCCNewFilename, pckg, KNullDesC8);
                if (err)
                    {
                    User::Leave(err);
                    }
                break;
                }            
            case K_TC9_NewFileNameWhenPaused:
                {
                iCamc->PauseL();
                CTimer::After(2 * TInt32 ( 1E6 ) ); // Pause for 2 seconds.
                iPaused=ETrue;
                break;
                }
            default:
                iCamc->Stop();        // Simulates that iRecording has been completed through the 
                // MvruoRecordComplete callback
                iRecordingReady=ETrue;				
                CTimer::After( 1000 );
            }       
        }
    
    
    }
    void CCamcTestClient_visualcheck::RunLTrappedL()
        {
#ifdef _DEBUG
        RDebug::Print(_L("CamCTestClient VisualCheck:RunL"));
#endif
        if ( iOpenReady ) 
            {
            iOpenReady = EFalse;
            
            switch(iAction)
                {  
                case K_VC_test_case_101:
                    {
                    break; 
                    }
                case K_VC_test_case_102:
                    {
                    iCamc->SetVideoFrameSizeL(TSize(128,96));
                    iCamc->SetVideoFrameRateL(TReal32(3));
                    iCamc->SetVideoBitRateL(TInt(28000));
                    iCamc->SetAudioEnabledL(ETrue); 
                    iCamc->SetAudioBitRateL(12200); 
                    iCamc->SetMaxClipSizeL(95000);
                    break; 
                    }
                case K_VC_test_case_103:
                    {
                    iCamc->SetVideoFrameSizeL(TSize(128,96));
                    iCamc->SetVideoFrameRateL(TReal32(5));
                    iCamc->SetVideoBitRateL(TInt(28000));
                    iCamc->SetAudioEnabledL(ETrue); 
                    iCamc->SetAudioBitRateL(6700); 
                    iCamc->SetMaxClipSizeL(95000);
                    break; 
                    }
                case K_VC_test_case_104:
                    {
                    iCamc->SetVideoFrameSizeL(TSize(128,96));
                    iCamc->SetVideoFrameRateL(TReal32(10));
                    iCamc->SetVideoBitRateL(TInt(28000));
                    iCamc->SetAudioEnabledL(ETrue); 
                    iCamc->SetAudioBitRateL(5150); 
                    iCamc->SetMaxClipSizeL(250000);
                    break; 
                    }
                case K_VC_test_case_105:
                    {
                    iCamc->SetVideoFrameSizeL(TSize(176,144));
                    iCamc->SetVideoFrameRateL(TReal32(1));
                    iCamc->SetVideoBitRateL(TInt(42000));
                    iCamc->SetAudioEnabledL(ETrue); 
                    iCamc->SetAudioBitRateL(7400); 
                    iCamc->SetMaxClipSizeL(95000);
                    break;
                    }
                case K_VC_test_case_106:
                    {
                    iCamc->SetVideoFrameSizeL(TSize(176,144));
                    iCamc->SetVideoFrameRateL(TReal32(3));
                    iCamc->SetVideoBitRateL(TInt(42000));
                    iCamc->SetAudioEnabledL(ETrue); 
                    iCamc->SetAudioBitRateL(4750); 
                    iCamc->SetMaxClipSizeL(95000);
                    break;
                    }
                case K_VC_test_case_107:
                    {
                    iCamc->SetVideoFrameSizeL(TSize(176,144));
                    iCamc->SetVideoFrameRateL(TReal32(5));
                    iCamc->SetVideoBitRateL(TInt(42000));
                    iCamc->SetAudioEnabledL(ETrue); 
                    iCamc->SetAudioBitRateL(12200); 
                    break;
                    }
                case K_VC_test_case_108_a:
                    {
                    iCamc->SetVideoFrameSizeL(TSize(176,144));
                    iCamc->SetVideoFrameRateL(TReal32(8));
                    iCamc->SetVideoBitRateL(TInt(128000));
                    iCamc->SetAudioEnabledL(ETrue); 
                    iCamc->SetAudioBitRateL(12200); 
                    iCamc->SetMaxClipSizeL(250000);
                    break;              
                    }
                case K_VC_test_case_108_b:
                    {
                    iCamc->SetVideoFrameSizeL(TSize(176,144));
                    iCamc->SetVideoFrameRateL(TReal32(1));
                    iCamc->SetVideoBitRateL(TInt(64000));
                    iCamc->SetAudioEnabledL(ETrue); 
                    iCamc->SetAudioBitRateL(12200); 
                    iCamc->SetMaxClipSizeL(250000);
                    break;              
                    }
                case K_VC_test_case_109:
                    {
                    iCamc->SetVideoFrameSizeL(TSize(176,144));
                    iCamc->SetVideoFrameRateL(TReal32(3));
                    iCamc->SetVideoBitRateL(TInt(64000));
                    iCamc->SetAudioEnabledL(ETrue); 
                    iCamc->SetAudioBitRateL(12200); 
                    break;
                    }
                case K_VC_test_case_110:
                    {
                    iCamc->SetVideoFrameSizeL(TSize(176,144));
                    iCamc->SetVideoFrameRateL(TReal32(5));
                    iCamc->SetVideoBitRateL(TInt(42000));    
                    iCamc->SetAudioEnabledL(EFalse); 
                    iCamc->SetMaxClipSizeL(95000);
                    break;
                    }
                case K_VC_test_case_111:
                    {
                    iCamc->SetVideoFrameSizeL(TSize(176,144));
                    iCamc->SetVideoFrameRateL(TReal32(5));
                    iCamc->SetVideoBitRateL(TInt(64000));
                    iCamc->SetAudioEnabledL(EFalse); 
                    iCamc->SetMaxClipSizeL(500000);
                    break;
                    }
                case K_VC_test_case_112:
                    {
                    iCamc->SetVideoFrameSizeL(TSize(128,96));
                    iCamc->SetVideoFrameRateL(TReal32(5));
                    iCamc->SetVideoBitRateL(KMMFVariableVideoBitRate);
                    iCamc->SetMaxClipSizeL(95000);
                    break;
                    }
                case K_VC_test_case_113:
                    {
                    iCamc->SetMaxClipSizeL(50);
                    break; 
                    }
                case K_VC_test_case_114:
                    {
                    break; 
                    }
                case K_VC_test_case_115:
                    {
                    iCamc->SetVideoFrameSizeL(TSize(176,144));
                    iCamc->SetVideoFrameRateL(TReal32(5));
                    iCamc->SetVideoBitRateL(KMMFVariableVideoBitRate);
                    break;
                    }    
                case K_VC_test_case_116:
                    {
                    iCamc->SetVideoFrameSizeL(TSize(176,144));
                    iCamc->SetVideoFrameRateL(TReal32(5));
                    iCamc->SetVideoBitRateL(TInt(64000));
                    iCamc->SetAudioEnabledL(ETrue); 
                    iCamc->SetAudioBitRateL(12200); 
                    break;
                    }    
                case K_VC_test_case_117:
                    {
                    iCamc->SetVideoFrameSizeL(TSize(176,144));
                    iCamc->SetVideoFrameRateL(TReal32(5));
                    iCamc->SetVideoBitRateL(TInt(64000));
                    iCamc->SetMaxClipSizeL(95000);
                    break;
                    }    
                case K_VC_test_case_118:
                    {
                    iCamc->SetVideoFrameSizeL(TSize(176,144));
                    iCamc->SetVideoFrameRateL(TReal32(5));
                    iCamc->SetVideoBitRateL(TInt(64000));
                    iCamc->SetAudioEnabledL(ETrue); 
                    iCamc->SetAudioBitRateL(12200); 
                    break;
                    }    
                case K_VC_test_case_119:
                    {
                    iCamc->SetVideoFrameSizeL(TSize(176,144));
                    iCamc->SetVideoFrameRateL(TReal32(7));
                    iCamc->SetVideoBitRateL(TInt(64000));
                    iCamc->SetMaxClipSizeL(95000);
                    iCamc->SetAudioEnabledL(ETrue); 
                    iCamc->SetAudioBitRateL(5150); 
                    break;
                    }    
                 case K_VC_test_case_120:
                    {
                    iCamc->SetVideoFrameSizeL(TSize(128,96));
                    iCamc->SetVideoFrameRateL(TReal32(10));
                    iCamc->SetVideoBitRateL(TInt(64000));
                    iCamc->SetMaxClipSizeL(500000);
                    break;
                    }    
                case K_VC_test_case_121:
                    {
                    iCamc->SetVideoFrameSizeL(TSize(352,288));
                    iCamc->SetVideoFrameRateL(TReal32(15));
                    iCamc->SetVideoBitRateL(TInt(384000));
                    iCamc->SetAudioEnabledL(ETrue); 
                    break;
                    }
               default:
                    break;
            }
            
            
            
            iCamc->Prepare();
        }
        else if ( iPrepareReady ) 
            {
            iPrepareReady = EFalse;    
            iCamc->Record();
            switch(iAction)
                {
                case K_VC_test_case_101:
                    {
                    CTimer::After( 30 * TInt32 ( 1E6 ) );  // Records for 30 sec
                    break;
                    }
                case K_VC_test_case_102:
                case K_VC_test_case_103:
                case K_VC_test_case_104:
                case K_VC_test_case_105:
                case K_VC_test_case_106:
                case K_VC_test_case_108_a:
                case K_VC_test_case_117:
                case K_VC_test_case_119:
                case K_VC_test_case_113:
                    {
                    // The timeout will be generated by the SetMaxClipSize.
                    break;
                    }
                case K_VC_test_case_114:
                    {
                    CTimer::After( 1 * TInt32 ( 1E6 ) );  // Records for 1 sec
                    break;
                    }
                case K_VC_test_case_116:
                    {
                    CTimer::After( 10 * TInt32 ( 1E6 ) );  // Records for 10 sec
                    iStartRecording2ndTime = EFalse;
                    break;
                    }
                default:
                    {
                    CTimer::After( 10 * TInt32 ( 1E6 ) );
                    break;          
                    }
                }
            }
        else if ( iRecordingReady )
            {
            
            iRecordingReady = EFalse;
            iCamc->Close();
            iClosed = ETrue;
            CTimer::After(1000);
            }
        else if (iClosed)
            {
            CActiveScheduler::Stop();
            }
        else if ( iPaused ) //resume
            {
            switch(iAction)
                {
                case K_VC_test_case_107:
                    {
                    iCamc->Record();
                    CTimer::After( 50 * TInt32 ( 1E6 ) ); // Records for 50 sec.
                    iPaused = EFalse;
                    iAction = K_VC_none;         
                    break;
                    }
                case K_VC_test_case_109: 
                case K_VC_test_case_118: 
                    {
                    if ( iDoublePause )
                        {             
                        iCamc->Record();
                        CTimer::After( 2*60 * TInt32 ( 1E6 ) ); // Record 2 minutes
                        iPaused = EFalse;
                        iAction = K_VC_none;
                        }
                    else 
                        {
                        iCamc->Record();
                        CTimer::After(  2*60 * TInt32 ( 1E6 ) ); // Record 2 minutes
                        iPaused = EFalse;
                        iDoublePause = ETrue;
                        }
                    break;
                    }
                case K_VC_test_case_112:
                    {
                    iCamc->Record();
                    iPaused = EFalse;  
                    break;
                    }
                case K_VC_test_case_115:
                    {
                    if ( iDoublePause )
                        {             
                        iCamc->Record();
                        iAction = K_VC_none;
                        // Record until disk full
                        }
                    else 
                        {
                        iCamc->Record();
                        CTimer::After(   2*60 * TInt32 ( 1E6 ) ); // Record 2 minutes
                        iPaused = EFalse;
                        iDoublePause = ETrue;
                        }
                    break;
                    }
                case K_VC_test_case_121:
                    {
                    iCamc->Record();
                    CTimer::After( 50 * TInt32 ( 1E6 ) ); // Records for 50 sec.
                    iPaused = EFalse;
                    iAction = K_VC_none;         
                    break;
                    }
                default:
                    break;
                }
            }
        else //timer
            {
            switch(iAction)
                {     
                case K_VC_test_case_107:
                    {
                    iCamc->PauseL();
                    iPaused = ETrue;
                    CTimer::After( 5 * TInt32 ( 1E6 ) ); // Pause 5 sec
                    break;
                    }
                case K_VC_test_case_108_a: 
                    {
                    if ( i2ndTime )
                        {
                        // Volume down
                        iCamc->SetGainL( 1 );
                        iAction = K_VC_none;
                        }
                    else 
                        {                
                        // Volume Up
                        TInt aSetGain;
                        aSetGain = iCamc->MaxGainL();
                        iCamc->SetGainL( aSetGain );
                        CTimer::After( 15 * TInt32 ( 1E6 ) );
                        i2ndTime = ETrue;            
                        }
                    break;
                    }
                case K_VC_test_case_108_b: 
                    {
                    if ( i2ndTime )
                        {
                        // Volume down
                        iCamc->SetGainL( 1 );
                        iAction = K_VC_none;
                        }
                    else 
                        {                
                        // Volume Up
                        TInt aSetGain;
                        aSetGain = iCamc->MaxGainL();
                        iCamc->SetGainL( aSetGain );
                        CTimer::After( 15 * TInt32 ( 1E6 ) );
                        i2ndTime = ETrue;            
                        }
                    break;
                    }
                case K_VC_test_case_109:      
                case K_VC_test_case_115:
                case K_VC_test_case_118:
                    {
                    iCamc->PauseL();
                    iPaused = ETrue;          
                    
                    if ( i2ndTime )
                        {
                        CTimer::After( 30 * TInt32 ( 1E6 ) ); // Pauses for 30s
                        }
                    else 
                        {                
                        CTimer::After( 10 * TInt32 ( 1E6 ) ); // Pauses for 10s
                        i2ndTime = ETrue;            
                        }
                    break;
                    }
                case K_VC_test_case_110:
                    {
                    iCamc->SetVideoBitRateL( TCVC_VIDEO_BIT_RATE_10  );
                    break;
                    }
                case K_VC_test_case_111:
                    {
                    iCamc->SetVideoBitRateL( TCVC_VIDEO_BIT_RATE_11  );
                    iAction = K_VC_none;
                    break;
                    }
                case K_VC_test_case_112:
                    {
                    iCamc->PauseL();
                    iPaused = ETrue;
                    CTimer::After( 10 * TInt32 ( 1E6 ) );
                    break;
                    }
                case K_VC_test_case_116:
                    {
                    if(iStartRecording2ndTime)
                        {
                        iPrepareReady = ETrue;    
                        CTimer::After( 10 * TInt32 ( 1E6 ) );
                        iAction = K_VC_none;    
                        }
                    else
                        {
                        iCamc->Stop();
                        CTimer::After( 3 * TInt32 ( 1E6 ) );
                        iStartRecording2ndTime = ETrue;
                        }
                    break;
                    }
                case K_VC_test_case_120:
                    {
                    iCamc->SetVideoBitRateL( TCVC_VIDEO_BIT_RATE_20  );
                    iAction = K_VC_none;
                    break;
                    }
                case K_VC_test_case_121:
                    {
                    iCamc->PauseL();
                    iPaused = ETrue;
                    CTimer::After( 5 * TInt32 ( 1E6 ) ); // Pause 5 sec
                    break;
                    }
                default:
                    iCamc->Stop();
                    // Simulates that iRecording has been completed through the 
                    // MvruoRecordComplete callback
                    iRecordingReady=ETrue;				
                    CTimer::After( 1 * TInt32 ( 1E6 ) );
                    
                }
            }
        
}