sl@0: /* sl@0: * Copyright (c) 2005-2006 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: DRM Play Session sl@0: * sl@0: */ sl@0: sl@0: sl@0: #include "DRMPlaySession.h" sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #ifdef RD_TSP_CLIENT_MAPPER sl@0: #include sl@0: #endif // #ifdef RD_TSP_CLIENT_MAPPER sl@0: sl@0: #ifdef _DEBUG sl@0: #define DEP_PRN0(str) RDebug::Print(str) sl@0: #define DEP_PRN1(str, v1) RDebug::Print(str, v1) sl@0: #define DEP_PRN2(str, v1, v2) RDebug::Print(str, v1, v2) sl@0: #else sl@0: #define DEP_PRN0(str) sl@0: #define DEP_PRN1(str, v1) sl@0: #define DEP_PRN2(str, v1, v2) sl@0: #endif // _DEBUG sl@0: sl@0: // This is the UID defined by custom interface builder sl@0: const TUid KUidCustomInterfaceBuilderImpl = {0x10207A8E}; sl@0: sl@0: // panic the client sl@0: void CDRMPlayServerSession::PanicClient(const RMessage2 &aMessage, TInt aPanic) const sl@0: { sl@0: _LIT(KTxtServer,"DRM Play server"); sl@0: aMessage.Panic(KTxtServer,aPanic); sl@0: } sl@0: sl@0: CDRMPlayServerSession::CDRMPlayServerSession(CDRMPlayServer* aServer) sl@0: :iMessage2(NULL) sl@0: { sl@0: iServer=aServer; sl@0: } sl@0: sl@0: CDRMPlayServerSession* CDRMPlayServerSession::NewL(CDRMPlayServer* aServer, const RMessage2& aMessage ) sl@0: { sl@0: DEP_PRN0(_L("CDRMPlayServerSession::NewL")); sl@0: sl@0: CDRMPlayServerSession* self = new(ELeave) CDRMPlayServerSession(aServer); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL( aMessage ); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: #ifdef RD_TSP_CLIENT_MAPPER sl@0: void CDRMPlayServerSession::ConstructL( const RMessage2& aMessage ) sl@0: #else sl@0: void CDRMPlayServerSession::ConstructL( const RMessage2& /*aMessage*/ ) sl@0: #endif //RD_TSP_CLIENT_MAPPER sl@0: { sl@0: #ifdef RD_TSP_CLIENT_MAPPER sl@0: iTSPClientMapper = CTspClientMapper::NewL(); sl@0: // Get client process ID sl@0: RThread clientThread; sl@0: RProcess clientProcess; sl@0: // Open client thread and process handles sl@0: User::LeaveIfError( aMessage.Client(clientThread) ); sl@0: User::LeaveIfError( clientThread.Process(clientProcess) ); sl@0: // Get process id sl@0: iClientProcessId = clientProcess.Id(); sl@0: // Close client thread and client process handles sl@0: clientThread.Close(); sl@0: clientProcess.Close(); sl@0: sl@0: iTSPClientMapper->SetTspTargetClient( sl@0: CTspClientMapper::ERegisteredClients, sl@0: iClientProcessId ); sl@0: #endif // #ifdef RD_TSP_CLIENT_MAPPER sl@0: sl@0: // Increment number of sessions in server sl@0: iServer->iClients++; sl@0: sl@0: DEP_PRN1(_L("CDRMPlayServerSession::iClients = %d"), iServer->iClients); sl@0: } sl@0: sl@0: CDRMPlayServerSession::~CDRMPlayServerSession() sl@0: { sl@0: if(iMetaDataBuffer) sl@0: { sl@0: delete iMetaDataBuffer; sl@0: iMetaDataBuffer = NULL; sl@0: } sl@0: // Delete any pending message objects sl@0: // This will never happen, only happens when sl@0: // Client closes the session in the middle of playback sl@0: // but we cannot complete the message as RSession Handle is invalid sl@0: /* if (iMessage2) sl@0: { sl@0: iMessage2->Complete(KErrCancel); sl@0: } sl@0: */ sl@0: if(iMessage2) sl@0: { sl@0: delete iMessage2; sl@0: iMessage2 = NULL; sl@0: } sl@0: sl@0: // Delete play utility sl@0: if (iPlayUtil) sl@0: { sl@0: delete iPlayUtil; sl@0: iPlayUtil = NULL; sl@0: } sl@0: //delete iAsyncCallback; sl@0: //iAsyncCallback = NULL; sl@0: sl@0: #ifdef RD_TSP_CLIENT_MAPPER sl@0: if (iTSPClientMapper) sl@0: { sl@0: sl@0: TInt status = iTSPClientMapper->RemoveTspTargetClient( sl@0: CTspClientMapper::ERegisteredClients, sl@0: iClientProcessId ); sl@0: DEP_PRN2(_L("CDRMPlayServerSession::~CDRMPlayServerSession:Unreg PID[%x]Status[%d]"), iClientProcessId.Id(), status ); sl@0: delete iTSPClientMapper; sl@0: } sl@0: #endif // #ifdef RD_TSP_CLIENT_MAPPER sl@0: sl@0: // Cancel any pending async messages. sl@0: TInt index(0); sl@0: CDRMCustomCommandAsyncAO* tempAO(NULL); sl@0: for (;index < iActiveAsyncCustomCommands.Count(); index++) sl@0: { sl@0: tempAO = iActiveAsyncCustomCommands[0]; sl@0: if ( iCDRMCustomCommandAsyncAO2Phase == tempAO ) sl@0: { sl@0: iCDRMCustomCommandAsyncAO2Phase = NULL; sl@0: } sl@0: delete tempAO; sl@0: iActiveAsyncCustomCommands.Remove(0); sl@0: } sl@0: iActiveAsyncCustomCommands.Reset(); sl@0: iActiveAsyncCustomCommands.Close(); sl@0: sl@0: delete iCDRMCustomCommandAsyncAO2Phase; sl@0: sl@0: iServer->iClients--; sl@0: sl@0: if(!iServer->iClients) sl@0: { sl@0: CActiveScheduler::Stop(); sl@0: } sl@0: } sl@0: sl@0: void CDRMPlayServerSession::ServiceL(const RMessage2& aMessage) sl@0: { sl@0: TInt ret = KErrNone; sl@0: TRAPD(err,ret = DispatchMessageL(aMessage)); sl@0: if (KErrNone != err) sl@0: { sl@0: ret = err; sl@0: } sl@0: if(iAsyncComplete == EFalse) sl@0: { sl@0: DEP_PRN1(_L("CDRMPlayServerSession::ServiceL - ret = %d"),ret); sl@0: aMessage.Complete(ret); sl@0: } sl@0: } sl@0: sl@0: sl@0: sl@0: // service a client request; test the opcode and then do appropriate servicing sl@0: TInt CDRMPlayServerSession::DispatchMessageL(const RMessage2 &aMessage) sl@0: { sl@0: TInt ret=KErrNone; sl@0: iAsyncComplete= EFalse; sl@0: DEP_PRN1(_L("CDRMPlayServerSession::DispatchMessageL:FnId[%d]"),aMessage.Function()); sl@0: switch (aMessage.Function()) sl@0: { sl@0: case EDRMPlayServCreate: sl@0: break; sl@0: case EDRMPlayServNewFilePlayerL: sl@0: iMessage = aMessage; sl@0: NewFilePlayerL(aMessage); sl@0: iAsyncComplete = ETrue; sl@0: break; sl@0: case EDRMPlayServNewDesPlayerL: sl@0: iMessage = aMessage; sl@0: NewDesPlayerL(aMessage); sl@0: iAsyncComplete = ETrue; sl@0: break; sl@0: case EDRMPlayServNewDesPlayerReadOnlyL: sl@0: iMessage = aMessage; sl@0: NewDesPlayerReadOnlyL(aMessage); sl@0: iAsyncComplete = ETrue; sl@0: break; sl@0: case EDRMPlayServNewPlayerL: sl@0: NewPlayerL(aMessage); sl@0: break; sl@0: case EDRMPlayServOpenFile: sl@0: iMessage = aMessage; sl@0: OpenFileL(aMessage); sl@0: iAsyncComplete = ETrue; sl@0: break; sl@0: case EDRMPlayServOpenFileByHandle: sl@0: iMessage = aMessage; sl@0: OpenFileByHandleL(aMessage); sl@0: iAsyncComplete = ETrue; sl@0: break; sl@0: case EDRMPlayServOpenFileBySource: sl@0: iMessage = aMessage; sl@0: OpenFileBySourceL(aMessage); sl@0: iAsyncComplete = ETrue; sl@0: break; sl@0: case EDRMPlayServOpenDes: sl@0: iMessage = aMessage; sl@0: OpenDesL(aMessage); sl@0: iAsyncComplete = ETrue; sl@0: break; sl@0: case EDRMPlayServOpenUrl: sl@0: iMessage = aMessage; sl@0: OpenUrlL(aMessage); sl@0: iAsyncComplete = ETrue; sl@0: break; sl@0: case EDRMPlayServPlay: sl@0: iMessage = aMessage; sl@0: if(iMessage2) sl@0: { sl@0: iMessage2->Complete(KErrCancel); sl@0: delete iMessage2; sl@0: iMessage2 = NULL; sl@0: } sl@0: iMessage2 = new (ELeave) RMessage2(aMessage); sl@0: Play(); sl@0: iAsyncComplete = ETrue; sl@0: break; sl@0: case EDRMPlayServStop: sl@0: if(iState == EStopped) sl@0: break; sl@0: if(iMessage2) sl@0: { sl@0: iMessage2->Complete(KErrCancel); sl@0: delete iMessage2; sl@0: iMessage2 = NULL; sl@0: } sl@0: Stop(); sl@0: break; sl@0: case EDRMPlayServSetVolume: sl@0: SetVolume(aMessage); sl@0: break; sl@0: case EDRMPlayServSetRepeats: sl@0: SetRepeats(aMessage); sl@0: break; sl@0: case EDRMPlayServSetVolumeRamp: sl@0: SetVolumeRamp(aMessage); sl@0: break; sl@0: case EDRMPlayServDuration: sl@0: Duration(aMessage); sl@0: break; sl@0: case EDRMPlayServMaxVolume: sl@0: ret = MaxVolume(); sl@0: break; sl@0: case EDRMPlayServPause: sl@0: ret = Pause(); sl@0: if(iMessage2) sl@0: { sl@0: iMessage2->Complete(KErrCancel); sl@0: delete iMessage2; sl@0: iMessage2 = NULL; sl@0: } sl@0: iAsyncComplete = EFalse; sl@0: break; sl@0: case EDRMPlayServClose: sl@0: Close(); sl@0: break; sl@0: case EDRMPlayServGetPosition: sl@0: ret = GetPosition(aMessage); sl@0: break; sl@0: case EDRMPlayServSetPosition: sl@0: SetPosition(aMessage); sl@0: break; sl@0: case EDRMPlayServSetPriority: sl@0: ret = SetPriority(aMessage); sl@0: break; sl@0: case EDRMPlayServGetVolume: sl@0: ret = GetVolume(aMessage); sl@0: break; sl@0: case EDRMPlayServGetNumberOfMetaDataEntries: sl@0: ret = GetNumberOfMetaDataEntries(aMessage); sl@0: break; sl@0: case EDRMPlayServGetMetaDataEntry: sl@0: GetMetaDataEntryL(aMessage); sl@0: break; sl@0: case EDRMPlayServClearPlayWindow: sl@0: ret = ClearPlayWindow(); sl@0: break; sl@0: case EDRMPlayServSetBalance: sl@0: ret = SetBalance(aMessage); sl@0: break; sl@0: case EDRMPlayServGetBalance: sl@0: ret = GetBalance(aMessage); sl@0: break; sl@0: case EDRMPlayServGetBitRate: sl@0: ret = GetBitRate(aMessage); sl@0: break; sl@0: case EDRMPlayServRegisterForAudioLoadingNotification: sl@0: iMessage = aMessage; sl@0: RegisterForAudioLoadingNotification(aMessage); sl@0: iAsyncComplete = ETrue; sl@0: break; sl@0: case EDRMPlayServGetAudioLoadingProgress: sl@0: GetAudioLoadingProgressL(aMessage); sl@0: break; sl@0: case EDRMPlayServSetPlayWindow: sl@0: SetPlayWindow(aMessage); sl@0: break; sl@0: case EDRMPlayServControllerImplementationInformation: sl@0: ControllerImplementationInformationL(aMessage); sl@0: break; sl@0: case EDRMPlayServCustomCommandSyncWithReturn: sl@0: case EDRMPlayServCustomCommandSyncWithoutReturn: sl@0: CustomCommandSyncL(aMessage); sl@0: break; sl@0: case EDRMPlayServCustomCommandAsyncWithReturnStep1: sl@0: case EDRMPlayServCustomCommandAsyncWithoutReturnStep1: sl@0: CustomCommandAsyncStep1L(aMessage); sl@0: // Setting this flag does not complete message in ServiceL, sl@0: iAsyncComplete = ETrue; sl@0: break; sl@0: case EDRMPlayServCustomCommandAsyncWithReturnStep2: sl@0: case EDRMPlayServCustomCommandAsyncWithoutReturnStep2: sl@0: CustomCommandAsyncStep2L(aMessage); sl@0: // Setting this flag does not complete message in ServiceL, sl@0: iAsyncComplete = ETrue; sl@0: break; sl@0: case EDRMPlayServSetPriorityPreference: sl@0: SetPriorityPreference(aMessage); sl@0: break; sl@0: sl@0: default: sl@0: PanicClient(aMessage, EBadRequest); sl@0: break; sl@0: } sl@0: return ret; sl@0: } sl@0: sl@0: void CDRMPlayServerSession::NewFilePlayerL(const RMessage2 aMessage) sl@0: { sl@0: TDataStructPckgBuf params; sl@0: sl@0: aMessage.Read(0,iCallbackState); sl@0: aMessage.Read(1,params); sl@0: aMessage.Read(2,iErrDurPckg); sl@0: HBufC16* inputBuf = HBufC16::NewL(aMessage.GetDesLengthL(3)); sl@0: TPtr16 ptr = inputBuf->Des(); sl@0: aMessage.Read(3,ptr); sl@0: const TDataStruct &theStruct = params(); sl@0: delete iPlayUtil; sl@0: iPlayUtil = NULL; sl@0: iPlayUtil = CMdaAudioPlayerUtility::NewFilePlayerL( inputBuf->Des(), sl@0: *this, sl@0: iPriority, sl@0: iPref); sl@0: delete inputBuf; sl@0: } sl@0: sl@0: void CDRMPlayServerSession::NewDesPlayerL(const RMessage2 aMessage) sl@0: { sl@0: TDataStructPckgBuf thePckg; sl@0: aMessage.Read(0,iCallbackState); sl@0: aMessage.Read(1,thePckg); sl@0: aMessage.Read(2,iErrDurPckg); sl@0: sl@0: delete iPlayUtil; sl@0: iPlayUtil = NULL; sl@0: iPlayUtil = CMdaAudioPlayerUtility::NewDesPlayerL(thePckg().iData, sl@0: *this, sl@0: iPriority, sl@0: iPref); sl@0: sl@0: } sl@0: sl@0: void CDRMPlayServerSession::NewDesPlayerReadOnlyL(const RMessage2 aMessage) sl@0: { sl@0: TDataStructPckgBuf thePckg; sl@0: aMessage.Read(0,iCallbackState); sl@0: aMessage.Read(1,thePckg); sl@0: aMessage.Read(2,iErrDurPckg); sl@0: sl@0: delete iPlayUtil; sl@0: iPlayUtil = NULL; sl@0: iPlayUtil = CMdaAudioPlayerUtility::NewDesPlayerReadOnlyL(thePckg().iData, sl@0: *this, sl@0: iPriority, sl@0: iPref); sl@0: } sl@0: sl@0: void CDRMPlayServerSession::NewPlayerL(const RMessage2 aMessage) sl@0: { sl@0: sl@0: TDataStructPckgBuf thePckg; sl@0: aMessage.Read(0,iCallbackState); sl@0: aMessage.Read(1,thePckg); sl@0: aMessage.Read(2,iErrDurPckg); sl@0: sl@0: delete iPlayUtil; sl@0: iPlayUtil = NULL; sl@0: iPlayUtil = CMdaAudioPlayerUtility::NewL(*this, sl@0: iPriority, sl@0: iPref); sl@0: } sl@0: sl@0: void CDRMPlayServerSession::OpenFileL(const RMessage2 &aMessage) sl@0: { sl@0: //call mmfclientaudioplayer open file sl@0: iFileHandleUsed = EFalse; sl@0: sl@0: aMessage.Read(0,iCallbackState); sl@0: // Get the file length sl@0: TInt len = aMessage.GetDesLengthL(1); sl@0: HBufC* fileName = HBufC::NewLC(len); sl@0: TPtr fileNamePtr = fileName->Des(); sl@0: aMessage.Read(1,fileNamePtr); sl@0: aMessage.Read(2,iErrDurPckg); sl@0: if(iPlayUtil) sl@0: { sl@0: iPlayUtil->OpenFileL(fileNamePtr); sl@0: } sl@0: CleanupStack::PopAndDestroy(fileName); sl@0: } sl@0: sl@0: void CDRMPlayServerSession::OpenFileByHandleL(const RMessage2 &aMessage) sl@0: { sl@0: iFileHandleUsed = ETrue; sl@0: TInt err = iFileHandle.AdoptFromClient(aMessage,1,3); sl@0: sl@0: aMessage.Read(0,iCallbackState); sl@0: aMessage.Read(2,iErrDurPckg); sl@0: sl@0: if (err == KErrNone) sl@0: { sl@0: if(iPlayUtil) sl@0: { sl@0: iPlayUtil->OpenFileL(iFileHandle); sl@0: } sl@0: } sl@0: else sl@0: { sl@0: User::Leave(err); sl@0: } sl@0: } sl@0: sl@0: void CDRMPlayServerSession::OpenFileBySourceL(const RMessage2 &/*aMessage*/) sl@0: { sl@0: sl@0: } sl@0: sl@0: void CDRMPlayServerSession::OpenDesL(const RMessage2 &aMessage) sl@0: { sl@0: //call mmfclientaudioplayer OpenDesL sl@0: TBuf8<50> aDes; sl@0: sl@0: aMessage.Read(0,iCallbackState); sl@0: aMessage.Read(1,aDes); sl@0: aMessage.Read(2,iErrDurPckg); sl@0: sl@0: if(iPlayUtil) sl@0: { sl@0: iPlayUtil->OpenDesL(aDes); sl@0: } sl@0: } sl@0: sl@0: void CDRMPlayServerSession::OpenUrlL(const RMessage2 &aMessage) sl@0: { sl@0: //call mmfclientaudioplayer OpenUrlL sl@0: TUrlStructPckgBuf thePckg; sl@0: sl@0: aMessage.Read(0,iCallbackState); sl@0: aMessage.Read(1,thePckg); sl@0: aMessage.Read(2,iErrDurPckg); sl@0: sl@0: if(iPlayUtil) sl@0: { sl@0: iPlayUtil->OpenUrlL(thePckg().iUrl, sl@0: thePckg().iIapId, sl@0: thePckg().iMimeType); sl@0: } sl@0: } sl@0: sl@0: void CDRMPlayServerSession::Play() sl@0: { sl@0: //call mmfclientaudioplayer Play sl@0: iState = EPlaying; sl@0: if(iPlayUtil) sl@0: { sl@0: iPlayUtil->Play(); sl@0: #ifdef RD_TSP_CLIENT_MAPPER sl@0: TInt status = iTSPClientMapper->SetTspTargetClientToOtherType( sl@0: CTspClientMapper::EPlayingClients, sl@0: iClientProcessId ); sl@0: DEP_PRN2(_L("CDRMPlayServerSession::Play:Change PID[%x]Status[%d]"), iClientProcessId.Id(), status ); sl@0: #endif // #ifdef RD_TSP_CLIENT_MAPPER sl@0: } sl@0: } sl@0: sl@0: void CDRMPlayServerSession::Stop() sl@0: { sl@0: //call mmfclientaudioplayer Stop sl@0: if(iPlayUtil) sl@0: { sl@0: iPlayUtil->Stop(); sl@0: #ifdef RD_TSP_CLIENT_MAPPER sl@0: TInt status = iTSPClientMapper->SetTspTargetClientToOtherType( sl@0: CTspClientMapper::EStoppedClients, sl@0: iClientProcessId ); sl@0: DEP_PRN2(_L("CDRMPlayServerSession::Stop:Change PID[%x]Status[%d]"), iClientProcessId.Id(), status ); sl@0: #endif // #ifdef RD_TSP_CLIENT_MAPPER sl@0: } sl@0: iState = EStopped; sl@0: } sl@0: sl@0: void CDRMPlayServerSession::SetVolume(const RMessage2 & aMessage) sl@0: { sl@0: //call mmfclientaudioplayer SetVolume sl@0: TInt theVolume = aMessage.Int0(); sl@0: sl@0: if(iPlayUtil) sl@0: { sl@0: iPlayUtil->SetVolume(theVolume); sl@0: } sl@0: } sl@0: sl@0: void CDRMPlayServerSession::SetRepeats(const RMessage2 &aMessage) sl@0: { sl@0: //call mmfclientaudioplayer SetRepeats sl@0: TInt theRepeatNumberOfTimes = aMessage.Int0(); sl@0: TTimeIntervalMicroSeconds theTrailingSilence; sl@0: sl@0: TPckgTTimeIntervalMicroSeconds theTrailingSilencePckg(theTrailingSilence); sl@0: aMessage.Read(1,theTrailingSilencePckg); sl@0: sl@0: iPlayUtil->SetRepeats(theRepeatNumberOfTimes,theTrailingSilence); sl@0: } sl@0: sl@0: void CDRMPlayServerSession::SetVolumeRamp(const RMessage2 &aMessage) sl@0: { sl@0: //call mmfclientaudioplayer SetVolumeRamp sl@0: TTimeIntervalMicroSeconds theRampDuration; sl@0: TPckgTTimeIntervalMicroSeconds theRampDurationPckg(theRampDuration); sl@0: aMessage.Read(0,theRampDurationPckg); sl@0: sl@0: iPlayUtil->SetVolumeRamp(theRampDuration); sl@0: } sl@0: sl@0: void CDRMPlayServerSession::Duration(const RMessage2& aMessage) sl@0: { sl@0: TTimeIntervalMicroSeconds theDuration; sl@0: theDuration = iPlayUtil->Duration(); sl@0: sl@0: TPckgBufTTimeIntervalMicroSeconds theDurationPckg(theDuration); sl@0: aMessage.Write(0,theDurationPckg); sl@0: } sl@0: sl@0: TInt CDRMPlayServerSession::MaxVolume() sl@0: { sl@0: TInt theMaxVolume; sl@0: theMaxVolume = iPlayUtil->MaxVolume(); sl@0: sl@0: return theMaxVolume; sl@0: } sl@0: sl@0: // API Additions since version 7.0 sl@0: TInt CDRMPlayServerSession::Pause() sl@0: { sl@0: TInt ret = KErrNone; sl@0: if(iPlayUtil) sl@0: { sl@0: ret = iPlayUtil->Pause(); sl@0: } sl@0: sl@0: // This message should not be completed here. It should be completed in ServiceL() sl@0: /* if(iState == EPlaying) sl@0: { sl@0: iMessage.Complete(KErrNone); sl@0: }*/ sl@0: iState = EStopped; sl@0: return ret; sl@0: } sl@0: sl@0: void CDRMPlayServerSession::Close() sl@0: { sl@0: sl@0: if(iFileHandleUsed) sl@0: iFileHandle.Close(); sl@0: sl@0: iPlayUtil->Close(); sl@0: } sl@0: sl@0: TInt CDRMPlayServerSession::GetPosition(const RMessage2 &aMessage) sl@0: { sl@0: TInt ret; sl@0: TTimeIntervalMicroSeconds thePosition; sl@0: sl@0: ret = iPlayUtil->GetPosition(thePosition); sl@0: sl@0: sl@0: TPckgTTimeIntervalMicroSeconds thePositionPckg(thePosition); sl@0: aMessage.Write(0,thePositionPckg); sl@0: sl@0: return ret; sl@0: } sl@0: sl@0: void CDRMPlayServerSession::SetPosition(const RMessage2 &aMessage) sl@0: { sl@0: TTimeIntervalMicroSeconds thePosition; sl@0: TPckgTTimeIntervalMicroSeconds thePositionPckg(thePosition); sl@0: aMessage.Read(0,thePositionPckg); sl@0: iPlayUtil->SetPosition(thePosition); sl@0: } sl@0: sl@0: TInt CDRMPlayServerSession::SetPriority(const RMessage2 &aMessage) sl@0: { sl@0: TInt thePriority = aMessage.Int0(); sl@0: TMdaPriorityPreference thePref = (TMdaPriorityPreference)aMessage.Int1(); sl@0: sl@0: TInt ret = iPlayUtil->SetPriority(thePriority,thePref); sl@0: sl@0: return ret; sl@0: } sl@0: sl@0: TInt CDRMPlayServerSession::GetVolume(const RMessage2 &aMessage) sl@0: { sl@0: TInt theVolume; sl@0: TInt ret = iPlayUtil->GetVolume(theVolume); sl@0: TPckgBufTInt pckg(theVolume); sl@0: aMessage.Write(0,pckg); sl@0: return ret; sl@0: } sl@0: sl@0: TInt CDRMPlayServerSession::GetNumberOfMetaDataEntries(const RMessage2 &aMessage) sl@0: { sl@0: TInt ret; sl@0: TInt theNumOfMetaDataEntries; sl@0: sl@0: ret = iPlayUtil->GetNumberOfMetaDataEntries(theNumOfMetaDataEntries); sl@0: sl@0: TPckgBufTInt pckg(theNumOfMetaDataEntries); sl@0: aMessage.Write(0,pckg); sl@0: sl@0: return ret; sl@0: } sl@0: sl@0: sl@0: void CDRMPlayServerSession::GetMetaDataEntryL(const RMessage2 &aMessage) sl@0: { sl@0: //Get the index of the required entry sl@0: TInt theIndex = aMessage.Int0(); sl@0: CMMFMetaDataEntry* entry = iPlayUtil->GetMetaDataEntryL(theIndex); sl@0: CleanupStack::PushL(entry); sl@0: // Delete any existing buffer sl@0: if (iMetaDataBuffer) sl@0: { sl@0: delete iMetaDataBuffer; sl@0: iMetaDataBuffer = NULL; sl@0: } sl@0: sl@0: // Create a buffer to hold the externalised entry sl@0: iMetaDataBuffer = CBufFlat::NewL(32); sl@0: RBufWriteStream s; sl@0: s.Open(*iMetaDataBuffer); sl@0: CleanupClosePushL(s); sl@0: entry->ExternalizeL(s); sl@0: CleanupStack::PopAndDestroy(2);//s, entry sl@0: sl@0: //Write the externalised data back to the client sl@0: aMessage.Write(1,iMetaDataBuffer->Ptr(0)); sl@0: } sl@0: sl@0: sl@0: TInt CDRMPlayServerSession::SetPlayWindow(const RMessage2 &aMessage) sl@0: { sl@0: TPlayWindowStructBuf buf; sl@0: aMessage.Read(0,buf); sl@0: sl@0: TTimeIntervalMicroSeconds playStart = buf().iPlayStart; sl@0: TTimeIntervalMicroSeconds playEnd = buf().iPlayEnd; sl@0: sl@0: TInt ret = iPlayUtil->SetPlayWindow(playStart,playEnd); sl@0: sl@0: return ret; sl@0: } sl@0: sl@0: TInt CDRMPlayServerSession::ClearPlayWindow() sl@0: { sl@0: return iPlayUtil->ClearPlayWindow(); sl@0: } sl@0: sl@0: TInt CDRMPlayServerSession::SetBalance(const RMessage2 &aMessage) sl@0: { sl@0: TInt theBalance = aMessage.Int0(); sl@0: return iPlayUtil->SetBalance(theBalance); sl@0: } sl@0: sl@0: TInt CDRMPlayServerSession::GetBalance(const RMessage2 &aMessage) sl@0: { sl@0: TInt theBalance; sl@0: TInt ret; sl@0: sl@0: ret = iPlayUtil->GetBalance(theBalance); sl@0: sl@0: TPckgBufTInt pckg(theBalance); sl@0: aMessage.Write(0,pckg); sl@0: sl@0: return ret; sl@0: } sl@0: sl@0: TInt CDRMPlayServerSession::GetBitRate(const RMessage2 &aMessage) sl@0: { sl@0: TUint theBitRate; sl@0: TInt ret; sl@0: sl@0: ret = iPlayUtil->GetBitRate(theBitRate); sl@0: sl@0: TPckgBufTUint pckg(theBitRate); sl@0: aMessage.Write(0,pckg); sl@0: sl@0: return ret; sl@0: } sl@0: sl@0: void CDRMPlayServerSession::RegisterForAudioLoadingNotification(const RMessage2 &aMessage) sl@0: { sl@0: aMessage.Read(0,iCallbackState); sl@0: sl@0: if(iCallbackState()==ELoadingStarted) sl@0: { sl@0: iPlayUtil->RegisterForAudioLoadingNotification(*this); sl@0: } sl@0: } sl@0: sl@0: void CDRMPlayServerSession::GetAudioLoadingProgressL(const RMessage2 &aMessage) sl@0: { sl@0: TInt thePercentProgress; sl@0: sl@0: iPlayUtil->GetAudioLoadingProgressL(thePercentProgress); sl@0: sl@0: TPckgBufTInt pckg(thePercentProgress); sl@0: sl@0: aMessage.Write(0,pckg); sl@0: } sl@0: sl@0: void CDRMPlayServerSession::ControllerImplementationInformationL(const RMessage2 &aMessage) sl@0: { sl@0: const CMMFControllerImplementationInformation& x= iPlayUtil->ControllerImplementationInformationL(); sl@0: sl@0: //for now just write Uid by to client sl@0: typedef TPckg TPckgTUid; sl@0: sl@0: TPckgTUid thePckg(x.Uid()); sl@0: aMessage.Write(0,thePckg); sl@0: } sl@0: sl@0: sl@0: void CDRMPlayServerSession::CustomCommandSyncL(const RMessage2 &aMessage) sl@0: { sl@0: DEP_PRN0(_L("CDRMPlayServerSession::CustomCommandSyncL:Enter")); sl@0: sl@0: TPckgCustomCommand thePckgCustomCommand; sl@0: User::LeaveIfError(aMessage.Read(0,thePckgCustomCommand)); sl@0: sl@0: HBufC8* dataTo1Buf(NULL); sl@0: HBufC8* dataTo2Buf(NULL); sl@0: HBufC8* dataFromBuf(NULL); sl@0: TPtr8 ptr1(NULL, NULL); sl@0: TPtr8 ptr2(NULL, NULL); sl@0: TPtr8 ptr3(NULL, NULL); sl@0: sl@0: // Read data1 sl@0: dataTo1Buf = HBufC8::NewL(aMessage.GetDesLengthL(1)); sl@0: CleanupStack::PushL(dataTo1Buf); sl@0: ptr1.Set(dataTo1Buf->Des()); sl@0: User::LeaveIfError(aMessage.Read(1,ptr1)); sl@0: sl@0: // Check and filter the messages sl@0: // Dont Allow Select Custom Commands sl@0: if( !IsValidCustomCommandDestination(thePckgCustomCommand().iDestination().InterfaceId(), ptr1) ) sl@0: User::Leave(KErrAccessDenied); sl@0: sl@0: // Read data2 sl@0: dataTo2Buf = HBufC8::NewL(aMessage.GetDesLengthL(2)); sl@0: CleanupStack::PushL(dataTo2Buf); sl@0: ptr2.Set(dataTo2Buf->Des()); sl@0: User::LeaveIfError(aMessage.Read(2,ptr2)); sl@0: sl@0: if ( aMessage.Function() == EDRMPlayServCustomCommandSyncWithReturn ) sl@0: { sl@0: // Read data3 sl@0: dataFromBuf = HBufC8::NewL(aMessage.GetDesLengthL(3)); sl@0: CleanupStack::PushL(dataFromBuf); sl@0: ptr3.Set(dataFromBuf->Des()); sl@0: User::LeaveIfError(aMessage.Read(3,ptr3)); sl@0: /* sl@0: RDebug::Print(_L("CDRMPlayServerSession::CustomCommandSync:IFId[%x]DestHndl[%x]Fn[%d]RetDesLen[%d]"), sl@0: thePckgCustomCommand().iDestination().InterfaceId(), sl@0: thePckgCustomCommand().iDestination().DestinationHandle(), sl@0: thePckgCustomCommand().iFunction, sl@0: ptr3.MaxLength()); sl@0: */ sl@0: // Call CustomCommandSync on play util sl@0: User::LeaveIfError(iPlayUtil->CustomCommandSync( sl@0: thePckgCustomCommand().iDestination, sl@0: thePckgCustomCommand().iFunction, sl@0: ptr1, sl@0: ptr2, sl@0: ptr3)); sl@0: User::LeaveIfError(aMessage.Write(3,ptr3)); sl@0: sl@0: // Free heap allocated for data3 sl@0: CleanupStack::PopAndDestroy(dataFromBuf); sl@0: } sl@0: else sl@0: { sl@0: /* sl@0: RDebug::Print(_L("CDRMPlayServerSession::CustomCommandSync:IFId[%x]DestHndl[%x]Fn[%d]"), sl@0: thePckgCustomCommand().iDestination().InterfaceId(), sl@0: thePckgCustomCommand().iDestination().DestinationHandle(), sl@0: thePckgCustomCommand().iFunction ); sl@0: */ sl@0: // Call CustomCommandSync on play util sl@0: User::LeaveIfError(iPlayUtil->CustomCommandSync( sl@0: thePckgCustomCommand().iDestination, sl@0: thePckgCustomCommand().iFunction, sl@0: ptr1, sl@0: ptr2)); sl@0: } sl@0: sl@0: // Free heap allocated for data2 sl@0: CleanupStack::PopAndDestroy(dataTo2Buf); sl@0: // Free heap allocated for data1 sl@0: CleanupStack::PopAndDestroy(dataTo1Buf); sl@0: sl@0: DEP_PRN0(_L("CDRMPlayServerSession::CustomCommandSyncL:Exit")); sl@0: } sl@0: sl@0: void CDRMPlayServerSession::CustomCommandAsyncStep1L( const RMessage2& aMessage ) sl@0: { sl@0: DEP_PRN0(_L("CDRMPlayServerSession::CustomCommandAsyncStep1L:Enter")); sl@0: sl@0: // If there is a pending phase1, then there is something wrong. sl@0: if ( iCDRMCustomCommandAsyncAO2Phase ) sl@0: { sl@0: User::Leave(KErrAlreadyExists); sl@0: } sl@0: sl@0: if ( aMessage.Function() == EDRMPlayServCustomCommandAsyncWithReturnStep1 ) sl@0: { sl@0: iCDRMCustomCommandAsyncAO2Phase = CDRMCustomCommandAsyncAO::NewL( sl@0: aMessage, sl@0: CDRMCustomCommandAsyncAO::ECustomCommandWithResult, sl@0: *this ); sl@0: } sl@0: else /*if ( aMessage.Function() == EDRMPlayServCustomCommandAsyncWithoutReturnStep1 )*/ sl@0: { sl@0: iCDRMCustomCommandAsyncAO2Phase = CDRMCustomCommandAsyncAO::NewL( sl@0: aMessage, sl@0: CDRMCustomCommandAsyncAO::ECustomCommandWithoutResult, sl@0: *this ); sl@0: } sl@0: // Get reference to data1 descriptor sl@0: TPtr8 data1Ptr(iCDRMCustomCommandAsyncAO2Phase->GetData1FromClient()->Des()); sl@0: sl@0: // Check and filter the messages sl@0: // Dont Allow Select Custom Commands sl@0: if( !IsValidCustomCommandDestination((iCDRMCustomCommandAsyncAO2Phase->GetMMFMessageDestinationPckg())().InterfaceId(), data1Ptr) ) sl@0: { sl@0: User::Leave( KErrAccessDenied ); sl@0: } sl@0: sl@0: aMessage.Complete( KErrNone ); sl@0: DEP_PRN0(_L("CDRMPlayServerSession::CustomCommandAsyncStep1L:Exit")); sl@0: } sl@0: sl@0: void CDRMPlayServerSession::CustomCommandAsyncStep2L( const RMessage2& aMessage ) sl@0: { sl@0: DEP_PRN0(_L("CDRMPlayServerSession::CustomCommandAsyncStep2L:Enter")); sl@0: sl@0: // Read info from client session sl@0: TPtr8 data1Ptr(NULL,NULL); sl@0: TPtr8 data2Ptr(NULL,NULL); sl@0: TPtr8 dataToClientPtr(NULL,NULL); sl@0: sl@0: // If there is no pending phase1, then there is something wrong. sl@0: if ( !iCDRMCustomCommandAsyncAO2Phase ) sl@0: { sl@0: User::Leave(KErrNotReady); sl@0: } sl@0: sl@0: // Add custCmdAsyncAO object to array of async custom command objects sl@0: iActiveAsyncCustomCommands.AppendL( iCDRMCustomCommandAsyncAO2Phase ); sl@0: sl@0: // aMessage ownership is transferred to custCmdAsyncAO. sl@0: // After succesful transfer, aMessage should not be completed sl@0: // anywhere outside of this object. sl@0: iCDRMCustomCommandAsyncAO2Phase->TransferOwnershipL(aMessage); sl@0: sl@0: CDRMCustomCommandAsyncAO* drmCCAsyncAO = iCDRMCustomCommandAsyncAO2Phase; sl@0: iCDRMCustomCommandAsyncAO2Phase = NULL; sl@0: sl@0: // Get reference to descriptors sl@0: data1Ptr.Set(drmCCAsyncAO->GetData1FromClient()->Des()); sl@0: data2Ptr.Set(drmCCAsyncAO->GetData2FromClient()->Des()); sl@0: sl@0: // Make call on controller sl@0: drmCCAsyncAO->SetActive(); sl@0: if ( aMessage.Function() == EDRMPlayServCustomCommandAsyncWithReturnStep2 ) sl@0: { sl@0: // If date needs to be returned, get reference to the descriptor sl@0: dataToClientPtr.Set(drmCCAsyncAO->GetDataToClient()->Des()); sl@0: /* sl@0: RDebug::Print(_L("CDRMPlayServerSession::CustomCommandAsyncStep2L:IFId[%x]DestHndl[%x]Fn[%d]Data1[Len:%d:MaxLen:%d]Data2Len[Len:%d:MaxLen:%d]RetDesLen[Len:%d:MaxLen:%d]"), sl@0: (drmCCAsyncAO->GetMMFMessageDestinationPckg())().InterfaceId(), sl@0: (drmCCAsyncAO->GetMMFMessageDestinationPckg())().DestinationHandle(), sl@0: drmCCAsyncAO->GetMMFMessageFunction(), sl@0: data1Ptr.Length(), sl@0: data1Ptr.MaxLength(), sl@0: data2Ptr.Length(), sl@0: data2Ptr.MaxLength(), sl@0: dataToClientPtr.Length(), sl@0: dataToClientPtr.MaxLength() ); sl@0: */ sl@0: // Call CustomCommandAsync on play util sl@0: iPlayUtil->CustomCommandAsync( sl@0: drmCCAsyncAO->GetMMFMessageDestinationPckg(), sl@0: drmCCAsyncAO->GetMMFMessageFunction(), sl@0: data1Ptr, sl@0: data2Ptr, sl@0: dataToClientPtr, sl@0: drmCCAsyncAO->iStatus ); sl@0: } sl@0: else /*if ( aMessage.Function() == EDRMPlayServCustomCommandAsyncWithoutReturnStep2 )*/ sl@0: { sl@0: /* sl@0: RDebug::Print(_L("CDRMPlayServerSession::CustomCommandAsyncStep2L:IFId[%x]DestHndl[%x]Fn[%d]Data1[Len:%d:MaxLen:%d]Data2Len[Len:%d:MaxLen:%d]"), sl@0: (drmCCAsyncAO->GetMMFMessageDestinationPckg())().InterfaceId(), sl@0: (drmCCAsyncAO->GetMMFMessageDestinationPckg())().DestinationHandle(), sl@0: drmCCAsyncAO->GetMMFMessageFunction(), sl@0: data1Ptr.Length(), sl@0: data1Ptr.MaxLength(), sl@0: data2Ptr.Length(), sl@0: data2Ptr.MaxLength() ); sl@0: */ sl@0: // Call CustomCommandAsync on play util sl@0: iPlayUtil->CustomCommandAsync( sl@0: drmCCAsyncAO->GetMMFMessageDestinationPckg(), sl@0: drmCCAsyncAO->GetMMFMessageFunction(), sl@0: data1Ptr, sl@0: data2Ptr, sl@0: drmCCAsyncAO->iStatus ); sl@0: } sl@0: sl@0: DEP_PRN0(_L("CDRMPlayServerSession::CustomCommandAsyncStep2L:Exit")); sl@0: } sl@0: sl@0: void CDRMPlayServerSession::MapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds& aDuration) sl@0: { sl@0: sl@0: DEP_PRN2(_L("CDRMPlayServerSession::MapcInitComplete :-> Status[%d] Duration[%d]"), aError, I64INT(aDuration.Int64())); sl@0: //iMessage.Write aError & aDuration to client sl@0: iCallbackState() = EInitComplete; sl@0: sl@0: iMessage.Write(0,iCallbackState); sl@0: sl@0: iErrDurPckg().iError = aError; sl@0: iErrDurPckg().iDuration = aDuration; sl@0: sl@0: iMessage.Write(2,iErrDurPckg); sl@0: iMessage.Complete(aError); sl@0: iAsyncComplete= EFalse; sl@0: } sl@0: sl@0: void CDRMPlayServerSession::MapcPlayComplete(TInt aError) sl@0: { sl@0: DEP_PRN1(_L("CDRMPlayServerSession::MapcPlayComplete :-> Error[%d]"), aError); sl@0: sl@0: #ifdef RD_TSP_CLIENT_MAPPER sl@0: TInt status = iTSPClientMapper->SetTspTargetClientToOtherType( sl@0: CTspClientMapper::EStoppedClients, sl@0: iClientProcessId ); sl@0: DEP_PRN2(_L("CDRMPlayServerSession::MapcPlayComplete:Change PID[%x]Status[%d]"), iClientProcessId.Id(), status ); sl@0: #endif // #ifdef RD_TSP_CLIENT_MAPPER sl@0: sl@0: sl@0: iState = EStopped; sl@0: sl@0: iCallbackState()= EPlayComplete; sl@0: /* sl@0: iMessage.Write(0,iCallbackState); sl@0: iErrDurPckg().iError = aError; sl@0: iErrDurPckg().iDuration = 0; sl@0: iMessage.Write(2,iErrDurPckg); sl@0: iMessage.Complete(aError); sl@0: */ sl@0: if ( iMessage2 ) sl@0: { sl@0: //iMessage2. Write aError & aDuration to client sl@0: iCallbackState() = EPlayComplete; sl@0: sl@0: iMessage2->Write(0,iCallbackState); sl@0: sl@0: iErrDurPckg().iError = aError; sl@0: iErrDurPckg().iDuration = 0; sl@0: iMessage2->Write(2,iErrDurPckg); sl@0: iMessage2->Complete(aError); sl@0: delete iMessage2; sl@0: iMessage2 = NULL; sl@0: } sl@0: sl@0: iAsyncComplete= EFalse; sl@0: } sl@0: sl@0: sl@0: void CDRMPlayServerSession::MaloLoadingStarted() sl@0: { sl@0: //send event to client sl@0: iCallbackState() = ELoadingStarted; sl@0: iMessage.Write(0,iCallbackState); sl@0: iMessage.Complete(KErrNone); sl@0: iAsyncComplete= EFalse; sl@0: } sl@0: void CDRMPlayServerSession::MaloLoadingComplete() sl@0: { sl@0: //send event to client sl@0: iCallbackState() = ELoadingComplete; sl@0: iMessage.Write(0,iCallbackState); sl@0: iMessage.Complete(KErrNone); sl@0: iAsyncComplete= EFalse; sl@0: } sl@0: sl@0: void CDRMPlayServerSession::AsyncCustomCommandCompleted( CDRMCustomCommandAsyncAO* aObject) sl@0: { sl@0: TInt index = iActiveAsyncCustomCommands.Find( aObject ); sl@0: // This should never happen. Else there is something wrong.... sl@0: if ( index != KErrNotFound ) sl@0: { sl@0: iActiveAsyncCustomCommands.Remove(index); sl@0: } sl@0: delete aObject; sl@0: } sl@0: sl@0: void CDRMPlayServerSession::SetPriorityPreference(const RMessage2 &aMessage) sl@0: { sl@0: iPriority = aMessage.Int0(); sl@0: iPref = (TMdaPriorityPreference)aMessage.Int1(); sl@0: } sl@0: sl@0: TBool CDRMPlayServerSession::IsValidCustomCommandDestination(TUid aDestinationUid, TDesC8& aParam) sl@0: { sl@0: TBool retValue(ETrue); sl@0: if (aDestinationUid == KUidInterfaceMMFDRMControl) sl@0: { sl@0: retValue = EFalse; sl@0: } sl@0: else if ( aDestinationUid == KUidCustomInterfaceBuilderImpl ) sl@0: { sl@0: RDesReadStream stream(aParam); sl@0: CleanupClosePushL(stream); sl@0: TUid paramUid; sl@0: TRAPD(status, paramUid.iUid = stream.ReadInt32L()); sl@0: CleanupStack::PopAndDestroy(&stream); sl@0: if ( (status == KErrNone ) && (paramUid == KUidAudioOutput) ) sl@0: { sl@0: retValue = EFalse; sl@0: } sl@0: } sl@0: return retValue; sl@0: } sl@0: sl@0: // End of File sl@0: