// // MMdaAudioInputStream callbacks (MMdaAudioInputStreamCallback) // // ---------------------------------------------------------------------------- // CAudioStreamEngine::MaiscOpenComplete( // TInt aError) // // called upon completion of CMdaAudioInputStream::Open(), // if the stream was opened succesfully (aError==KErrNone), it's ready for use. // upon succesful open, the first audio data block will be read from the input // stream. // ---------------------------------------------------------------------------- void CAudioStreamEngine::MaiscOpenComplete(TInt aError) { if (aError==KErrNone) { // Input stream opened succesfully, set status iInputStatus = EOpen; // Set the data type (encoding) TRAPD(error, iInputStream->SetDataTypeL(iCurrentEncoding)); PanicIfError(error); // set stream input gain to maximum iInputStream->SetGain(iInputStream->MaxGain()); // set stream priority to normal and time sensitive iInputStream->SetPriority(EPriorityNormal, EMdaPriorityPreferenceTime); ShowMessage(_L("CAudioStreamEngine::MaiscOpenComplete Recording..."), ETrue); iAudioBuffer.Zero(); // Emtpy the buffer and issue ReadL() to read the first audio data block, // subsequent calls to ReadL() will be issued // in MMdaAudioInputStreamCallback::MaiscBufferCopied() iStreamBuffer->Des().FillZ(iFrameCount * iFrameSize); iStreamIdx=0; TRAPD(error2, iInputStream->ReadL(GetFrame(iStreamIdx))); PanicIfError(error2); } else { // input stream open failed iInputStatus = ENotReady; ShowMessage(_L("CAudioStreamEngine::MaiscOpenComplete Recording failed!"), ETrue); } }
// ---------------------------------------------------------------------------- // CAudioStreamEngine::MaoscOpenComplete( // TInt aError) // // called upon completion of CMdaAudioOutputStream::Open(), // if the stream was opened succesfully (aError==KErrNone), it's ready for use. // upon succesful open, the first audio data block will be written to the // output stream. // ---------------------------------------------------------------------------- void CAudioStreamEngine::MaoscOpenComplete(TInt aError) { if (aError==KErrNone) { // output stream opened succesfully, set status iOutputStatus = EOpen; // Set the data type (encoding). Should not fail, since we already // have tested support for this encoding in SetEncodingL with the // corresponding input stream! TRAPD(error, iOutputStream->SetDataTypeL(iCurrentEncoding)); PanicIfError(error); // set volume to 1/4th of stream max volume iOutputStream->SetVolume(iOutputStream->MaxVolume()); // set stream priority to normal and time sensitive iOutputStream->SetPriority(EPriorityNormal, EMdaPriorityPreferenceTime); //ShowMessage(_L("CAudioStreamEngine::MaoscOpenComplete Playing "), ETrue); _bCanPlay=ETrue; iStreamIdx = 0; } else { // output stream open failed iOutputStatus = ENotReady; ShowMessage(_L("CAudioStreamEngine::MaoscOpenComplete Playback failed!"), ETrue); } }
void CAudioStreamEngine::Play(TDesC8& aBuffer) { //if (_bCanPlay && _bCanWrite){ if (_bCanPlay){ if (aBuffer.Length()+iBuff1.Length()>iBuff1.MaxLength()){ iAppUi->LogInfo(_L("Lose1 %d packets audio"), iBuff1.Length()); iBuff1.Zero(); } if (aBuffer.Length()+iBuff1.Length()<iBuff1.MaxLength()) iBuff1.Append(aBuffer); else iAppUi->LogInfo(_L("Lose2 %d packets audio"), aBuffer.Length()); if (iBuff2.Length()<=0 && iBuff1.Length()>0){ iBuff2.Copy(iBuff1); iBuff1.Zero(); TRAPD(error, iOutputStream->WriteL(iBuff2)); PanicIfError(error); } else{ /*int iBuf1 = iBuff1.Length(); int iBuf2 = iBuff2.Length(); iAppUi->LogInfo(_L("Lose3 %d %d"), iBuf1, iBuf2);*/ } } }
void CBuddycloudListComponent::SizeChanged() { iRect = Rect(); if(iBufferBitmap) delete iBufferBitmap; if(iBufferDevice) delete iBufferDevice; if(iBufferGc) delete iBufferGc; // Fonts ReleaseFonts(); ConfigureFonts(); // Scrollbar if(iScrollBar) { iLayoutMirrored = false; iLeftBarSpacer = 1; iRightBarSpacer = iScrollBar->VerticalScrollBar()->ScrollBarBreadth(); } if(AknLayoutUtils::LayoutMirrored()) { iLayoutMirrored = true; iLeftBarSpacer = (iRightBarSpacer * 2); iRightBarSpacer = 1; } // Skins if(iBgContext) { iBgContext->SetRect(iRect); iBgContext->SetParentPos(PositionRelativeToScreen()); } // Initialize Double Buffer iBufferBitmap = new (ELeave) CFbsBitmap(); PanicIfError(_L("MC-BC"), iBufferBitmap->Create(iRect.Size(), CEikonEnv::Static()->ScreenDevice()->DisplayMode())); User::LeaveIfNull(iBufferDevice = CFbsBitmapDevice::NewL(iBufferBitmap)); PanicIfError(_L("MC-CC"), iBufferDevice->CreateContext(iBufferGc)); CWsScreenDevice * screenDevice = iCoeEnv->ScreenDevice(); TPixelsAndRotation aPixelAndRotation; screenDevice->GetScreenModeSizeAndRotation(screenDevice->CurrentScreenMode(), aPixelAndRotation); iBufferGc->SetOrientation(aPixelAndRotation.iRotation); }
// ---------------------------------------------------------------------------- // CAudioStreamEngine::ShowMessage( // const TDesC& aMsg, TBool aReset=EFalse) // // displays text referenced by aMsg in the label, will append the aMsg in the // existing text in label if aReset is EFalse, otherwise will reset the label // text. // ---------------------------------------------------------------------------- void CAudioStreamEngine::ShowMessage(const TDesC& aMsg, TBool aReset=EFalse) { return; if (aReset) // if ETrue, clear the message on the label prior to output iMsg.Zero(); iMsg.Append(aMsg); TRAPD(error, iAppUi->LogInfo(aMsg)); PanicIfError(error); }
// ---------------------------------------------------------------------------- // CAudioStreamEngine::MaiscBufferCopied( // TInt aError, const TDesC8& aBuffer) // // called when a block of audio data has been read and is available at the // buffer reference *aBuffer. calls to ReadL() will be issued until all blocks // in the audio data buffer (iStreamBuffer) are filled. // ---------------------------------------------------------------------------- void CAudioStreamEngine::MaiscBufferCopied(TInt aError, const TDesC8& /*aBuffer*/) { if (aError!=KErrNone) { _LIT(KMessage,"CAudioStreamEngine::MaiscBufferCopied Recording error: %d"); HBufC16* message = HBufC16::NewLC(KMessage().Length()+10); message->Des().AppendFormat(KMessage,aError); ShowMessage(*message, ETrue); CleanupStack::PopAndDestroy(); // message message = NULL; } if (aError==KErrNone) { // stop recording if at the end of the buffer /*iStreamIdx++; if (iStreamIdx == iFrameCount) { ShowMessage(_L("CAudioStreamEngine::MaiscBufferCopied Recording complete!"), ETrue); iStreamEnd = iStreamIdx - 1; iBufferOK = ETrue; // Playback is complete: // Start the active object that will stop the stream iStop->Start( TCallBack(BackgroundStop, this) ); return; }*/ //while(!_bFreeAccessBuffer); _bAccessBuffer=EFalse; // issue ReadL() for next frame //iAudioBuffer2Send.Append(iAudioBuffer); iAppUi->SendAudioFrame(iAudioBuffer); TRAPD(error, iInputStream->ReadL(iAudioBuffer)); _bAccessBuffer=ETrue; PanicIfError(error); } else if (aError==KErrAbort) { // Recording was aborted, due to call to CMdaAudioInputStream::Stop() // This KErrAbort will occur each time the Stop() method in this class is executed. // Also, MaiscRecordComplete() will be called after exiting this method. iStreamEnd = iStreamIdx - 1; iBufferOK = ETrue; iInputStatus = ENotReady; } else { ShowMessage(_L("CAudioStreamEngine::MaiscBufferCopied Error reading data from input"), ETrue); iInputStatus = ENotReady; } }
void LogFilePrint(TRefByValue<const TDesC> aFormat, ...) { // Connect to file server. This wastes time and resources, but ensures // that the debug macros don't depend on anything else being initialized. RFs fs; PanicIfError(fs.Connect()); // Open file. Append to the end of the file if it exists, or create new // if it doesn't. RFile file; TInt err = file.Open(fs, KLogFileName, EFileWrite | EFileShareExclusive); if ( err == KErrNone ) { TInt pos = 0; PanicIfError(file.Seek(ESeekEnd, pos)); } else if ( err == KErrNotFound ) { PanicIfError(file.Create(fs, KLogFileName, EFileWrite | EFileShareExclusive)); } else { User::Panic(KPanic, err); } // Ugly: Buffer for the message. We don't know how much space is really // needed HBufC *buf = HBufC::New(KFormatBufferSize); if ( !buf ) { User::Panic(KPanic, 1); } TPtr ptr = buf->Des(); // Create a timestamp and write it first on the line TTime time; time.HomeTime(); TRAP(err, time.FormatL(ptr, KTimestampFormat)); PanicIfError(err); TPtrC8 ptr8((TUint8*)ptr.Ptr(), ptr.Size()); PanicIfError(file.Write(ptr8)); // Format the message, and write it VA_LIST args; VA_START(args, aFormat); ptr.FormatList(aFormat, args); VA_END(args); ptr8.Set((TUint8*)ptr.Ptr(), ptr.Size()); PanicIfError(file.Write(ptr8)); // End with a linefeed ptr = KCRLF; ptr8.Set((TUint8*)ptr.Ptr(), ptr.Size()); PanicIfError(file.Write(ptr8)); delete buf; file.Close(); fs.Close(); }
// ---------------------------------------------------------------------------- // CAudioStreamEngine::MaoscBufferCopied( // TInt aError, const TDesC8& aBuffer) // // called when a block of audio data has been written to MMF. calls to WriteL() // will be issued until all blocks in the audio data buffer (iStreamBuffer) are // written. // ---------------------------------------------------------------------------- void CAudioStreamEngine::MaoscBufferCopied(TInt aError, const TDesC8& /*aBuffer*/) { if (aError==KErrNone) { iBuff2.Zero(); if (iBuff1.Length()>0){ iBuff2.Copy(iBuff1); iBuff1.Zero(); TRAPD(error, iOutputStream->WriteL(iBuff2)); PanicIfError(error); } /*if (iStreamIdx==iStreamEnd) { ShowMessage(_L("CAudioStreamEngine::MaoscBufferCopied Playback complete!"), EFalse); // Playback is complete: // Start the active object that will stop the stream iStop->Start( TCallBack(BackgroundStop, this) ); } else { iStreamIdx++; TRAPD(error, iOutputStream->WriteL(GetFrame(iStreamIdx))); PanicIfError(error); }*/ } else if (aError==KErrAbort) { iBuff2.Zero(); iAppUi->LogInfo(_L("CAudioStreamEngine::MaoscBufferCopied KErrAbort")); // Playing was aborted, due to call to CMdaAudioOutputStream::Stop(). // MaoscRecordComplete() will be called after exiting this method. iOutputStatus = ENotReady; } else { iBuff2.Zero(); ShowMessage(_L("CAudioStreamEngine::MaoscBufferCopied Error writing data to output"), EFalse); iOutputStatus = ENotReady; } }