sl@0: // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include "omxcomponentbody.h" sl@0: #include "omxcomponentimpl.h" sl@0: sl@0: const TInt KMaxMsgQueueEntries = 10; sl@0: const TInt KMaxComponentNameLength = 256; sl@0: sl@0: const TInt KSymbianErrors[] = sl@0: { sl@0: KErrNoMemory, /*OMX_ErrorInsufficientResources*/ sl@0: KErrUnknown, sl@0: KErrBadName, sl@0: KErrNotFound, sl@0: KErrGeneral, /*OMX_ErrorInvalidComponent*/ sl@0: KErrArgument, /*OMX_ErrorBadParameter*/ sl@0: KErrNotSupported, /*OMX_ErrorNotImplemented*/ sl@0: KErrUnderflow, /*OMX_ErrorUnderflow*/ sl@0: KErrOverflow, /*OMX_ErrorOverflow*/ sl@0: KErrHardwareNotAvailable, /* OMX_ErrorHardware*/ sl@0: KErrGeneral, /*OMX_ErrorInvalidState*/ sl@0: KErrCorrupt, /*OMX_ErrorStreamCorrupt*/ sl@0: KErrArgument, /*OMX_ErrorPortsNotCompatible*/ sl@0: KErrHardwareNotAvailable, /*OMX_ErrorResourcesLost*/ sl@0: KErrCompletion, /*OMX_ErrorNoMore*/ sl@0: KErrGeneral, /*OMX_ErrorVersionMismatch*/ sl@0: KErrNotReady, /*OMX_ErrorNotReady*/ sl@0: KErrTimedOut, /*OMX_ErrorTimeout*/ sl@0: KErrNone /*OMX_ErrorSameState*/ sl@0: }; sl@0: sl@0: /** sl@0: Converts an OpenMAX error code to a Symbian error code. sl@0: @param aErrorType The OpenMAX error code. sl@0: @return The Symbian error code. sl@0: */ sl@0: TInt ConvertOmxErrorType(OMX_ERRORTYPE aErrorType) sl@0: { sl@0: if (aErrorType == OMX_ErrorNone) sl@0: { sl@0: return KErrNone; sl@0: } sl@0: else if (aErrorType >= OMX_ErrorInsufficientResources && sl@0: aErrorType <= OMX_ErrorSameState) sl@0: { sl@0: return KSymbianErrors[aErrorType - OMX_ErrorInsufficientResources]; sl@0: } sl@0: else sl@0: { sl@0: return KErrGeneral; sl@0: } sl@0: } sl@0: sl@0: /** sl@0: Converts a Symbian error code to an OpenMAX error code. sl@0: @param aError The Symbian error code. sl@0: @return The OpenMAX error code. sl@0: */ sl@0: OMX_ERRORTYPE ConvertSymbianErrorType(TInt aError) sl@0: { sl@0: OMX_ERRORTYPE err = OMX_ErrorNone; sl@0: switch (aError) sl@0: { sl@0: case KErrNone: sl@0: err = OMX_ErrorNone; sl@0: break; sl@0: case KErrNoMemory: sl@0: err = OMX_ErrorInsufficientResources; sl@0: break; sl@0: case KErrGeneral: sl@0: break; sl@0: default: sl@0: err = OMX_ErrorUndefined; sl@0: } sl@0: return err; sl@0: } sl@0: sl@0: sl@0: COmxBufferManager::COmxBufferManager(OMX_COMPONENTTYPE* aHandle) sl@0: : iHandle(aHandle) sl@0: { sl@0: } sl@0: sl@0: COmxBufferManager::COmxBuffer::COmxBuffer() sl@0: { sl@0: } sl@0: sl@0: sl@0: COmxBufferManager::COmxBuffer* COmxBufferManager::COmxBuffer::NewL(OMX_BUFFERHEADERTYPE* aBufferHeader, CMMFBuffer* aBuffer) sl@0: { sl@0: COmxBuffer* self = new (ELeave) COmxBuffer; sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aBufferHeader, aBuffer); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: COmxBufferManager::COmxBuffer::~COmxBuffer() sl@0: { sl@0: if (iOwnsMmfBuffer) sl@0: { sl@0: delete iMmfBuffer; sl@0: } sl@0: } sl@0: sl@0: sl@0: CMMFBuffer* COmxBufferManager::COmxBuffer::MmfBuffer() const sl@0: { sl@0: return iMmfBuffer; sl@0: } sl@0: sl@0: OMX_BUFFERHEADERTYPE* COmxBufferManager::COmxBuffer::BufferHeader() const sl@0: { sl@0: return iBufferHeader; sl@0: } sl@0: sl@0: sl@0: MOmxInputPortCallbacks* COmxBufferManager::COmxBuffer::InputPortCallbacks() const sl@0: { sl@0: return iInputPortCallbacks; sl@0: } sl@0: sl@0: MOmxOutputPortCallbacks* COmxBufferManager::COmxBuffer::OutputPortCallbacks() const sl@0: { sl@0: return iOutputPortCallbacks; sl@0: } sl@0: sl@0: void COmxBufferManager::COmxBuffer::SetInputPortCallbacks(MOmxInputPortCallbacks* aCallbacks) sl@0: { sl@0: iInputPortCallbacks = aCallbacks; sl@0: } sl@0: sl@0: void COmxBufferManager::COmxBuffer::SetOutputPortCallbacks(MOmxOutputPortCallbacks* aCallbacks) sl@0: { sl@0: iOutputPortCallbacks = aCallbacks; sl@0: } sl@0: sl@0: // look up the corresponding buffer sl@0: COmxBufferManager::COmxBuffer* COmxBufferManager::FindBuffer(const CMMFBuffer* aBuffer) const sl@0: { sl@0: COmxBuffer* buffer = NULL; sl@0: for (TInt i=0;iMmfBuffer() == aBuffer) sl@0: { sl@0: buffer = iBuffers[i]; sl@0: } sl@0: } sl@0: return buffer; sl@0: } sl@0: sl@0: COmxBufferManager::COmxBuffer* COmxBufferManager::FindBuffer(OMX_BUFFERHEADERTYPE* aBuffer) const sl@0: { sl@0: return reinterpret_cast(aBuffer->pAppPrivate); sl@0: } sl@0: sl@0: sl@0: sl@0: TInt COmxBufferManager::UseBuffer(CMMFBuffer& aBuffer, TUint aPortIndex) sl@0: { sl@0: if (CMMFBuffer::IsSupportedDataBuffer(aBuffer.Type())) sl@0: { sl@0: OMX_BUFFERHEADERTYPE* buffer; sl@0: CMMFDataBuffer& dataBuffer = static_cast(aBuffer); sl@0: sl@0: TDes8& aBufferDes = dataBuffer.Data(); sl@0: OMX_ERRORTYPE error = iHandle->UseBuffer(static_cast(iHandle), &buffer, aPortIndex, (void*)&aBuffer, aBufferDes.MaxLength(), const_cast(aBufferDes.Ptr())); sl@0: if (error != OMX_ErrorNone) sl@0: { sl@0: return ConvertOmxErrorType(error); sl@0: } sl@0: TRAPD(err, StoreBufferL(buffer, &aBuffer)); sl@0: return err; sl@0: } sl@0: else sl@0: { sl@0: return KErrNotSupported; sl@0: } sl@0: } sl@0: sl@0: sl@0: CMMFBuffer* COmxBufferManager::AllocateBufferL(TUint aPortIndex, TUint aSizeBytes) sl@0: { sl@0: OMX_BUFFERHEADERTYPE* buffer; sl@0: OMX_ERRORTYPE error = iHandle->AllocateBuffer(static_cast(iHandle), &buffer, aPortIndex, NULL, aSizeBytes); sl@0: User::LeaveIfError(ConvertOmxErrorType(error)); sl@0: sl@0: StoreBufferL(buffer,NULL); // transfers ownership sl@0: sl@0: // return the newly created buffer sl@0: return FindBuffer(buffer)->MmfBuffer(); sl@0: } sl@0: sl@0: sl@0: TInt COmxBufferManager::FreeBuffer(CMMFBuffer* aBuffer) sl@0: { sl@0: COmxBuffer* buffer; sl@0: for (TInt i=0;iMmfBuffer() == aBuffer) sl@0: { sl@0: iBuffers.Remove(i); sl@0: OMX_ERRORTYPE err = iHandle->FreeBuffer(static_cast(iHandle), 0, buffer->BufferHeader()); sl@0: delete buffer; sl@0: return err; sl@0: } sl@0: } sl@0: return KErrNotFound; sl@0: } sl@0: sl@0: void COmxBufferManager::COmxBuffer::ConstructL(OMX_BUFFERHEADERTYPE* aBufferHeader, CMMFBuffer* aBuffer) sl@0: { sl@0: sl@0: // Now if CMMFBuffer is NULL, this is been called from allocate buffer, and we need to sl@0: // Allocate a ptr buffer to correspond to the buffer created by OMX sl@0: ASSERT(aBufferHeader); sl@0: iBufferHeader = aBufferHeader; sl@0: if (aBuffer == NULL) sl@0: { sl@0: TPtr8 ptr(iBufferHeader->pBuffer, iBufferHeader->nFilledLen, iBufferHeader->nAllocLen); sl@0: CMMFBuffer* mmfBuffer = CMMFPtrBuffer::NewL(ptr); sl@0: iMmfBuffer = mmfBuffer; sl@0: iOwnsMmfBuffer = ETrue; sl@0: } sl@0: else sl@0: { sl@0: iMmfBuffer = aBuffer; sl@0: } sl@0: sl@0: // store pointer to element in array sl@0: iBufferHeader->pAppPrivate = this; sl@0: } sl@0: sl@0: sl@0: sl@0: // Store OMX buffer pointer sl@0: void COmxBufferManager::StoreBufferL(OMX_BUFFERHEADERTYPE* aBufferHeader, CMMFBuffer* aBuffer) sl@0: { sl@0: COmxBuffer* buf = COmxBuffer::NewL(aBufferHeader, aBuffer); sl@0: CleanupStack::PushL(buf); sl@0: iBuffers.AppendL(buf); sl@0: CleanupStack::Pop(buf); sl@0: } sl@0: sl@0: sl@0: TInt COmxBufferManager::EmptyThisBuffer(const CMMFBuffer* aBuffer, MOmxInputPortCallbacks* aObserver) sl@0: { sl@0: if (CMMFBuffer::IsSupportedDataBuffer(aBuffer->Type())) sl@0: { sl@0: COmxBuffer* omxBuffer = FindBuffer(aBuffer); sl@0: if (!omxBuffer) sl@0: { sl@0: return KErrNotFound; sl@0: } sl@0: sl@0: omxBuffer->SetInputPortCallbacks(aObserver); sl@0: OMX_BUFFERHEADERTYPE* bufferHeader = omxBuffer->BufferHeader(); sl@0: const CMMFDataBuffer* buf = static_cast(aBuffer); sl@0: const TDesC8& des = buf->Data(); sl@0: bufferHeader->nFilledLen = des.Length(); sl@0: bufferHeader->nFlags = 0; sl@0: if (aBuffer->LastBuffer()) sl@0: { sl@0: bufferHeader->nFlags |= OMX_BUFFERFLAG_EOS; sl@0: } sl@0: else sl@0: { sl@0: bufferHeader->nFlags &= ~OMX_BUFFERFLAG_EOS; sl@0: } sl@0: return ConvertOmxErrorType(iHandle->EmptyThisBuffer(static_cast(iHandle), bufferHeader)); sl@0: } sl@0: else sl@0: { sl@0: return KErrNotSupported; sl@0: } sl@0: } sl@0: sl@0: sl@0: TInt COmxBufferManager::FillThisBuffer(CMMFBuffer* aBuffer, MOmxOutputPortCallbacks* aObserver) sl@0: { sl@0: if (CMMFBuffer::IsSupportedDataBuffer(aBuffer->Type())) sl@0: { sl@0: COmxBuffer* omxBuffer = FindBuffer(aBuffer); sl@0: if (!omxBuffer) sl@0: { sl@0: return KErrNotFound; sl@0: } sl@0: omxBuffer->SetOutputPortCallbacks(aObserver); sl@0: OMX_BUFFERHEADERTYPE* bufferHeader = omxBuffer->BufferHeader(); sl@0: sl@0: bufferHeader->nFilledLen = 0; sl@0: // clear last buffer flag sl@0: bufferHeader->nFlags &= ~OMX_BUFFERFLAG_EOS; sl@0: return ConvertOmxErrorType(iHandle->FillThisBuffer(static_cast(iHandle), bufferHeader)); sl@0: } sl@0: else sl@0: { sl@0: return KErrNotSupported; sl@0: } sl@0: } sl@0: sl@0: sl@0: sl@0: COmxBufferManager::~COmxBufferManager() sl@0: { sl@0: for (TInt i=0;iFreeBuffer(static_cast(iHandle), 0, omxBuffer->BufferHeader()); sl@0: delete omxBuffer; sl@0: } sl@0: iBuffers.Close(); sl@0: } sl@0: sl@0: // Implementation of the Class COmxComponent sl@0: sl@0: sl@0: sl@0: COmxCallbacks* COmxCallbacks::NewL(MOmxPuCallbacks& aPuCallbacks) sl@0: { sl@0: COmxCallbacks* self = new (ELeave) COmxCallbacks(aPuCallbacks); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: sl@0: void COmxCallbacks::ConstructL() sl@0: { sl@0: OMX_CALLBACKTYPE h = sl@0: { sl@0: &::EventHandler, sl@0: &::EmptyBufferDone, sl@0: &::FillBufferDone sl@0: }; sl@0: sl@0: iHandle = h; sl@0: CActiveScheduler::Add(this); sl@0: sl@0: User::LeaveIfError(iMsgQueue.CreateLocal(KMaxMsgQueueEntries)); sl@0: iMsgQueue.NotifyDataAvailable(iStatus); sl@0: SetActive(); sl@0: } sl@0: sl@0: COmxCallbacks::COmxCallbacks(MOmxPuCallbacks& aPuCallbacks) sl@0: : CActive(EPriorityNormal), sl@0: iPuCallbacks(&aPuCallbacks) sl@0: { sl@0: } sl@0: sl@0: sl@0: COmxCallbacks::operator OMX_CALLBACKTYPE*() sl@0: { sl@0: return &iHandle; sl@0: } sl@0: sl@0: sl@0: void COmxCallbacks::RunL() sl@0: { sl@0: TOmxMessage msg; sl@0: while (iMsgQueue.Receive(msg)==KErrNone) sl@0: { sl@0: switch (msg.iType) sl@0: { sl@0: case EEmptyBufferCallback: sl@0: { sl@0: MOmxInputPortCallbacks* callback = msg.iBuffer->InputPortCallbacks(); sl@0: const CMMFBuffer* buffer = msg.iBuffer->MmfBuffer(); sl@0: callback->EmptyBufferDone(msg.iComponent, buffer); sl@0: break; sl@0: } sl@0: sl@0: case EFillBufferCallback: sl@0: { sl@0: CMMFBuffer* mmfBuffer = msg.iBuffer->MmfBuffer(); sl@0: OMX_BUFFERHEADERTYPE* bufferHeader = msg.iBuffer->BufferHeader(); sl@0: sl@0: if (CMMFBuffer::IsSupportedDataBuffer(mmfBuffer->Type())) sl@0: { sl@0: CMMFDataBuffer* dataBuffer = static_cast(mmfBuffer); sl@0: TDes8& aBufferDes = dataBuffer->Data(); sl@0: aBufferDes.SetLength(bufferHeader->nFilledLen); sl@0: mmfBuffer->SetLastBuffer(bufferHeader->nFlags & OMX_BUFFERFLAG_EOS); sl@0: } sl@0: else sl@0: { sl@0: ASSERT(EFalse); sl@0: } sl@0: MOmxOutputPortCallbacks* callback = msg.iBuffer->OutputPortCallbacks(); sl@0: callback->FillBufferDone(msg.iComponent, mmfBuffer); sl@0: break; sl@0: } sl@0: case EEventCallback: sl@0: { sl@0: iPuCallbacks->MopcEventHandler(msg.iComponent, sl@0: msg.iEventParams.iEvent, sl@0: msg.iEventParams.iData1, sl@0: msg.iEventParams.iData2, sl@0: msg.iEventParams.iExtra); sl@0: break; sl@0: } sl@0: default: sl@0: { sl@0: // This is an invalid state sl@0: ASSERT(EFalse); sl@0: } sl@0: }; sl@0: } sl@0: sl@0: // setup for next callbacks sl@0: iStatus = KRequestPending; sl@0: iMsgQueue.NotifyDataAvailable(iStatus); sl@0: SetActive(); sl@0: } sl@0: sl@0: COmxCallbacks::~COmxCallbacks() sl@0: { sl@0: Cancel(); sl@0: iMsgQueue.Close(); sl@0: } sl@0: sl@0: sl@0: void COmxCallbacks::DoCancel() sl@0: { sl@0: if (iMsgQueue.Handle()!=NULL) sl@0: { sl@0: iMsgQueue.CancelDataAvailable(); sl@0: } sl@0: } sl@0: sl@0: TInt COmxCallbacks::FillBufferDone(OMX_HANDLETYPE aComponent, COmxBufferManager::COmxBuffer* aBuffer) sl@0: { sl@0: TOmxMessage message; sl@0: message.iType = EFillBufferCallback; sl@0: message.iComponent = aComponent; sl@0: message.iBuffer = aBuffer; sl@0: return iMsgQueue.Send(message); sl@0: } sl@0: sl@0: TInt COmxCallbacks::EmptyBufferDone(OMX_HANDLETYPE aComponent, COmxBufferManager::COmxBuffer* aBuffer) sl@0: { sl@0: TOmxMessage message; sl@0: message.iType = EEmptyBufferCallback; sl@0: message.iComponent = aComponent; sl@0: message.iBuffer = aBuffer; sl@0: return iMsgQueue.Send(message); sl@0: } sl@0: sl@0: TInt COmxCallbacks::EventHandler(OMX_HANDLETYPE aComponent, TEventParams aEventParams) sl@0: { sl@0: TOmxMessage message; sl@0: message.iType = EEventCallback; sl@0: message.iComponent = aComponent; sl@0: message.iEventParams = aEventParams; sl@0: return iMsgQueue.Send(message); sl@0: } sl@0: sl@0: sl@0: COmxProcessingUnit::CBody::CBody() sl@0: { sl@0: iPuState = EProcessingUnitInvalid; sl@0: } sl@0: sl@0: sl@0: COmxProcessingUnit::CBody::~CBody() sl@0: { sl@0: delete iBufferManager; sl@0: delete iCallbacks; sl@0: sl@0: iInputPorts.Close(); sl@0: iOutputPorts.Close(); sl@0: sl@0: ::OMX_FreeHandle((OMX_HANDLETYPE)iHandle); sl@0: } sl@0: sl@0: COmxProcessingUnit::CBody* COmxProcessingUnit::CBody::NewL(const TDesC8& aComponentName, sl@0: MOmxPuCallbacks& aPuCallbacks, sl@0: COmxProcessingUnit* aParent, sl@0: const MMdfProcessingUnitObserver& aObserver) sl@0: { sl@0: CBody* self = new (ELeave) CBody; sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aComponentName, aPuCallbacks, aParent, aObserver); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: sl@0: void COmxProcessingUnit::CBody::ConstructL(const TDesC8& aComponentName, sl@0: MOmxPuCallbacks& aPuCallbacks, sl@0: COmxProcessingUnit* aParent, sl@0: const MMdfProcessingUnitObserver& aObserver) sl@0: { sl@0: iCallbacks = COmxCallbacks::NewL(aPuCallbacks); sl@0: sl@0: iParent = aParent; sl@0: iObserver = const_cast(&aObserver); sl@0: sl@0: OMX_ERRORTYPE errorType; sl@0: OMX_CALLBACKTYPE* omxCallbacks = *iCallbacks; sl@0: TBuf8 buf; sl@0: buf.Copy(aComponentName); sl@0: const char* name = reinterpret_cast(buf.PtrZ()); sl@0: errorType = ::OMX_GetHandle((OMX_HANDLETYPE*)&iHandle, const_cast(name), iCallbacks, omxCallbacks); sl@0: sl@0: User::LeaveIfError(ConvertOmxErrorType(errorType)); sl@0: // Create the BufferManager class to look after the buffering sl@0: iBufferManager = new (ELeave) COmxBufferManager(iHandle); sl@0: SetPuState(EProcessingUnitLoaded); sl@0: } sl@0: sl@0: sl@0: sl@0: TInt COmxProcessingUnit::CBody::GetInputPorts(RPointerArray& aComponentInputPorts) sl@0: { sl@0: TInt err = KErrNone; sl@0: for (TInt i=0; i < iInputPorts.Count() && err == KErrNone; i++ ) sl@0: { sl@0: err = aComponentInputPorts.Append(iInputPorts[i]); sl@0: } sl@0: return err; sl@0: } sl@0: sl@0: sl@0: TInt COmxProcessingUnit::CBody::GetOutputPorts(RPointerArray& aComponentOutputPorts) sl@0: { sl@0: TInt err = KErrNone; sl@0: for (TInt i=0; i < iOutputPorts.Count() && err == KErrNone; i++ ) sl@0: { sl@0: err = aComponentOutputPorts.Append(iOutputPorts[i]); sl@0: } sl@0: return err; sl@0: } sl@0: sl@0: sl@0: void COmxProcessingUnit::CBody::Initialize() sl@0: { sl@0: // if the state is not Loaded, we should not accept this call sl@0: if (State() != EProcessingUnitLoaded) sl@0: { sl@0: Observer()->InitializeComplete(iParent, KErrNotReady); sl@0: } sl@0: else sl@0: { sl@0: // initialize each of the ports in turn sl@0: for (TInt i=0; i < iInputPorts.Count(); i++ ) sl@0: { sl@0: iInputPorts[i]->MipInitialize(); sl@0: } sl@0: sl@0: for (TInt i=0; i < iOutputPorts.Count(); i++ ) sl@0: { sl@0: iOutputPorts[i]->MopInitialize(); sl@0: } sl@0: sl@0: // instruct the OMX component to go into the Idle state sl@0: SendCommand(OMX_CommandStateSet, OMX_StateIdle, NULL); sl@0: SetPuState(EProcessingUnitInitializing); sl@0: } sl@0: } sl@0: sl@0: void COmxProcessingUnit::CBody::Execute() sl@0: { sl@0: sl@0: SendCommand(OMX_CommandStateSet, OMX_StateExecuting, NULL); sl@0: iPuState = EProcessingUnitExecuting; sl@0: } sl@0: sl@0: TProcessingUnitState COmxProcessingUnit::CBody::State() sl@0: { sl@0: return iPuState; sl@0: } sl@0: sl@0: TInt COmxProcessingUnit::CBody::EventHandler(OMX_HANDLETYPE /*aComponent*/, OMX_EVENTTYPE aEvent, TUint32 /*aData1*/, sl@0: TUint32 aData2, TAny* /*aExtraInfo*/) sl@0: { sl@0: switch (aEvent) sl@0: { sl@0: sl@0: case OMX_EventCmdComplete: sl@0: { sl@0: sl@0: switch (aData2) sl@0: { sl@0: case OMX_StateIdle: sl@0: if (iPuState == EProcessingUnitInitializing) sl@0: { sl@0: Observer()->InitializeComplete(iParent, KErrNone); sl@0: } sl@0: else sl@0: { sl@0: Observer()->ExecuteComplete(iParent, KErrNone); sl@0: } sl@0: SetPuState(EProcessingUnitIdle); sl@0: sl@0: break; sl@0: }; sl@0: break; sl@0: } sl@0: case OMX_EventBufferFlag: sl@0: { sl@0: SendCommand(OMX_CommandStateSet, OMX_StateIdle, NULL); sl@0: } sl@0: } sl@0: return KErrNone; sl@0: } sl@0: sl@0: // Base Versions are not supported sl@0: TInt COmxProcessingUnit::CBody::Configure(const TPuConfig& /*aConfig*/) sl@0: { sl@0: return KErrNotSupported; sl@0: } sl@0: sl@0: sl@0: // Base Versions are not supported sl@0: TInt COmxProcessingUnit::CBody::GetConfig(TPuConfig& /*aConfig*/) sl@0: { sl@0: return KErrNotSupported; sl@0: } sl@0: sl@0: sl@0: TInt COmxProcessingUnit::CBody::Pause () sl@0: { sl@0: return KErrNone; sl@0: } sl@0: sl@0: void COmxProcessingUnit::CBody::Stop() sl@0: { sl@0: SendCommand(OMX_CommandStateSet, OMX_StateIdle, NULL); sl@0: sl@0: TInt err = KErrNone; sl@0: for (TInt i=0; i < iInputPorts.Count() && err == KErrNone; i++ ) sl@0: { sl@0: iInputPorts[i]->MipDisconnectTunnel(); sl@0: } sl@0: sl@0: for (TInt i=0; i < iOutputPorts.Count() && err == KErrNone; i++ ) sl@0: { sl@0: iOutputPorts[i]->MopDisconnectTunnel(); sl@0: } sl@0: sl@0: SetPuState(EProcessingUnitIdle); sl@0: } sl@0: sl@0: TInt COmxProcessingUnit::CBody::CreateCustomInterface(TUid /*aUid*/) sl@0: { sl@0: return KErrNotSupported; sl@0: } sl@0: sl@0: sl@0: TAny* COmxProcessingUnit::CBody::CustomInterface(TUid /*aUid*/) sl@0: { sl@0: return NULL; sl@0: } sl@0: sl@0: TInt COmxProcessingUnit::CBody::AddInputPort(MMdfInputPort* aInputPort) sl@0: { sl@0: if (iInputPorts.Find(aInputPort)>=0) sl@0: return KErrAlreadyExists; sl@0: return iInputPorts.Append(aInputPort); sl@0: } sl@0: sl@0: TInt COmxProcessingUnit::CBody::AddOutputPort(MMdfOutputPort* aOutputPort) sl@0: { sl@0: if (iOutputPorts.Find(aOutputPort)>=0) sl@0: return KErrAlreadyExists; sl@0: return iOutputPorts.Append(aOutputPort); sl@0: } sl@0: sl@0: MMdfProcessingUnitObserver* COmxProcessingUnit::CBody::Observer() sl@0: { sl@0: return iObserver; sl@0: } sl@0: sl@0: void COmxProcessingUnit::CBody::SetPuState(TProcessingUnitState aPuState) sl@0: { sl@0: iPuState = aPuState; sl@0: } sl@0: sl@0: TInt COmxProcessingUnit::CBody::GetComponentVersion(const TDesC8& /*aComponentName*/, OMX_VERSIONTYPE* /*aComponentVersion*/, OMX_VERSIONTYPE* /*aSpecVersion*/, OMX_UUIDTYPE* /*aComponentUUID*/) sl@0: { sl@0: return KErrNotSupported; sl@0: } sl@0: sl@0: TInt COmxProcessingUnit::CBody::SendCommand(OMX_COMMANDTYPE aCmd, TUint aParam, TAny* aCmdData) sl@0: { sl@0: OMX_ERRORTYPE error = iHandle->SendCommand(static_cast(iHandle), aCmd, aParam, aCmdData); sl@0: return ConvertOmxErrorType(error); sl@0: } sl@0: sl@0: sl@0: TInt COmxProcessingUnit::CBody::GetParameter(OMX_INDEXTYPE aParamIndex, TAny* aComponentParameterStructure) sl@0: { sl@0: OMX_ERRORTYPE error = iHandle->GetParameter(static_cast(iHandle), aParamIndex, aComponentParameterStructure); sl@0: return ConvertOmxErrorType(error); sl@0: } sl@0: sl@0: sl@0: TInt COmxProcessingUnit::CBody::SetParameter(OMX_INDEXTYPE aIndex, TAny* aComponentParameterStructure) sl@0: { sl@0: OMX_ERRORTYPE error = iHandle->SetParameter(static_cast(iHandle), aIndex, aComponentParameterStructure); sl@0: return ConvertOmxErrorType(error); sl@0: } sl@0: sl@0: TInt COmxProcessingUnit::CBody::GetConfig(OMX_INDEXTYPE aIndex, TAny* aValue) sl@0: { sl@0: OMX_ERRORTYPE error = iHandle->GetConfig(static_cast(iHandle), aIndex, aValue); sl@0: return ConvertOmxErrorType(error); sl@0: } sl@0: sl@0: TInt COmxProcessingUnit::CBody::SetConfig(OMX_INDEXTYPE aIndex, TAny* aValue) sl@0: { sl@0: OMX_ERRORTYPE error = iHandle->SetConfig(static_cast(iHandle), aIndex, aValue); sl@0: return ConvertOmxErrorType(error); sl@0: } sl@0: sl@0: TInt COmxProcessingUnit::CBody::GetExtensionIndex(const TDesC8& aParameterName, OMX_INDEXTYPE* aIndexType) sl@0: { sl@0: HBufC8* buf = HBufC8::New(aParameterName.Length()+1); sl@0: if (buf == NULL) sl@0: { sl@0: return KErrNoMemory; sl@0: } sl@0: else sl@0: { sl@0: // Create a zero terminated version of the paramter name sl@0: *buf = aParameterName; sl@0: TPtr8 ptr = buf->Des(); sl@0: TUint8* cstring = const_cast(ptr.PtrZ()); sl@0: OMX_ERRORTYPE error = iHandle->GetExtensionIndex(static_cast(iHandle), reinterpret_cast(cstring), aIndexType); sl@0: // delete the created memory - note no leaving functions so CleanupStack not used sl@0: delete buf; sl@0: return ConvertOmxErrorType(error); sl@0: } sl@0: } sl@0: sl@0: sl@0: TInt COmxProcessingUnit::CBody::GetState(OMX_STATETYPE* aState) sl@0: { sl@0: OMX_ERRORTYPE error = iHandle->GetState(static_cast(iHandle), aState); sl@0: return ConvertOmxErrorType(error); sl@0: } sl@0: sl@0: sl@0: TInt COmxProcessingUnit::CBody::ComponentTunnelRequest(TUint aPortInput, OMX_HANDLETYPE aOutput, TUint aPortOutput, OMX_TUNNELSETUPTYPE* aTunnelSetup) sl@0: { sl@0: OMX_ERRORTYPE error = iHandle->ComponentTunnelRequest(static_cast(iHandle), aPortInput, aOutput, aPortOutput, aTunnelSetup); sl@0: return ConvertOmxErrorType(error); sl@0: } sl@0: sl@0: TInt COmxProcessingUnit::CBody::UseBuffer(CMMFBuffer* aBuffer, TUint aPortIndex) sl@0: { sl@0: return iBufferManager->UseBuffer(*aBuffer, aPortIndex); sl@0: } sl@0: sl@0: sl@0: CMMFBuffer* COmxProcessingUnit::CBody::AllocateBufferL(TUint aPortIndex, TUint aSizeBytes) sl@0: { sl@0: return iBufferManager->AllocateBufferL(aPortIndex, aSizeBytes); sl@0: } sl@0: sl@0: sl@0: TInt COmxProcessingUnit::CBody::FreeBuffer(CMMFBuffer* aBuffer) sl@0: { sl@0: return iBufferManager->FreeBuffer(aBuffer); sl@0: } sl@0: sl@0: TInt COmxProcessingUnit::CBody::EmptyThisBuffer(const CMMFBuffer* aBuffer, MOmxInputPortCallbacks* aObserver) sl@0: { sl@0: return iBufferManager->EmptyThisBuffer(aBuffer, aObserver); sl@0: } sl@0: sl@0: sl@0: TInt COmxProcessingUnit::CBody::FillThisBuffer(CMMFBuffer* aBuffer, MOmxOutputPortCallbacks* aObserver) sl@0: { sl@0: return iBufferManager->FillThisBuffer(aBuffer, aObserver); sl@0: } sl@0: sl@0: sl@0: TInt COmxProcessingUnit::CBody::SetCallbacks(MOmxPuCallbacks& /*aPuCallbacks*/) sl@0: { sl@0: return KErrNotSupported; sl@0: } sl@0: sl@0: // Callbacks implementation - calls back to COMxCallbacks class, which manages a queue sl@0: OMX_ERRORTYPE EventHandler(OMX_OUT OMX_HANDLETYPE aComponent, sl@0: OMX_OUT TAny* aAppData, sl@0: OMX_OUT OMX_EVENTTYPE aEvent, sl@0: OMX_OUT TUint32 aData1, sl@0: OMX_OUT TUint32 aData2, sl@0: OMX_OUT TAny* aExtra) sl@0: { sl@0: COmxCallbacks::TEventParams eventParams; sl@0: eventParams.iEvent = aEvent; sl@0: eventParams.iData1 = aData1; sl@0: eventParams.iData2 = aData2; sl@0: eventParams.iExtra = aExtra; sl@0: TInt error = static_cast(aAppData)->EventHandler(aComponent, eventParams); sl@0: return ConvertSymbianErrorType(error); sl@0: } sl@0: sl@0: OMX_ERRORTYPE EmptyBufferDone( sl@0: OMX_HANDLETYPE aComponent, sl@0: TAny* aAppData, sl@0: OMX_BUFFERHEADERTYPE* aBuffer) sl@0: { sl@0: COmxBufferManager::COmxBuffer* buffer = static_cast(aBuffer->pAppPrivate); sl@0: TInt error = static_cast(aAppData)->EmptyBufferDone(aComponent, buffer); sl@0: return ConvertSymbianErrorType(error); sl@0: } sl@0: sl@0: OMX_ERRORTYPE FillBufferDone( sl@0: OMX_HANDLETYPE aComponent, sl@0: TAny* aAppData, sl@0: OMX_BUFFERHEADERTYPE* aBuffer) sl@0: { sl@0: COmxBufferManager::COmxBuffer* buffer = static_cast(aBuffer->pAppPrivate); sl@0: TInt error = static_cast(aAppData)->FillBufferDone(aComponent, buffer); sl@0: return ConvertSymbianErrorType(error); sl@0: } sl@0: