diff -r 000000000000 -r 96612d01cf9f videofeeds/vcnsuiengine/src/vcxnsstreaminghandler.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/videofeeds/vcnsuiengine/src/vcxnsstreaminghandler.cpp Mon Jan 18 20:21:12 2010 +0200 @@ -0,0 +1,374 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: Streaming handler* +*/ + + +// Version : %version: 8 % + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "IptvDebug.h" +#include "vcxnsstreaminghandler.h" +#include "vcxnscontent.h" +#include "vcxnsuiengine.h" +#include "vcxnscontentprovider.h" + +// Get spec for this. +const TInt KMinIntervalFromBegin = 1000; // 1 sec +const TInt KMinIntervalFromEnd = 5000; // 5 sec + +// ----------------------------------------------------------------------------- +// CVcxNsStreamingHandler::CVcxNsStreamingHandler +// ----------------------------------------------------------------------------- +// +CVcxNsStreamingHandler::CVcxNsStreamingHandler( CVcxNsUiEngine& aUiEngine ) : + iUiEngine ( aUiEngine ) + { + } + +// ----------------------------------------------------------------------------- +// CVcxNsStreamingHandler::NewL +// ----------------------------------------------------------------------------- +// +CVcxNsStreamingHandler* CVcxNsStreamingHandler::NewL( CVcxNsUiEngine& aUiEngine ) + { + CVcxNsStreamingHandler* self = new( ELeave) CVcxNsStreamingHandler( aUiEngine ); + CleanupStack::PushL(self); + self->ConstructL(); + CleanupStack::Pop(self); + return self; + } + +// ----------------------------------------------------------------------------- +// CVcxNsStreamingHandler::ConstructL +// ----------------------------------------------------------------------------- +// +void CVcxNsStreamingHandler::ConstructL() + { + IPTVLOGSTRING_LOW_LEVEL(">>>CVcxNsStreamingHandler::ConstructL"); + + IPTVLOGSTRING_LOW_LEVEL("<<RemoveObserverL( *this ) ); + iPlaybackUtility->Close(); + } + } + +// --------------------------------------------------------------------------- +// From MMPXPlaybackObserver +// Handle playback message. +// --------------------------------------------------------------------------- +// +void CVcxNsStreamingHandler::HandlePlaybackMessage( CMPXMessage* aMessage, TInt aError ) + { + IPTVLOGSTRING_LOW_LEVEL(">>>CVcxNsStreamingHandler::HandlePlaybackMessage"); + + if ( aError == KErrNone && aMessage ) + { + TRAP_IGNORE( DoHandlePlaybackMessageL( *aMessage ) ); + } + + IPTVLOGSTRING_LOW_LEVEL("<<>>CVcxNsStreamingHandler::DoHandlePlaybackMessageL"); + + TMPXMessageId id( *aMessage.Value< TMPXMessageId >( KMPXMessageGeneralId ) ); + + IPTVLOGSTRING2_LOW_LEVEL("CVcxNsStreamingHandler::DoHandlePlaybackMessageL TMPXMessageId = 0x%08x", id ); + + if ( KMPXMessageGeneral == id ) + { + TInt event = *aMessage.Value( KMPXMessageGeneralEvent ); + + IPTVLOGSTRING2_LOW_LEVEL("CVcxNsStreamingHandler::DoHandlePlaybackMessageL: event = %d", event ); + + switch ( event ) + { + case TMPXPlaybackMessage::EPropertyChanged: + { + HandlePropertyChangedL( aMessage ); + } + break; + case TMPXPlaybackMessage::EStateChanged: + { + HandleStateChangedL( aMessage ); + } + break; + default: + break; + } + } + + IPTVLOGSTRING_LOW_LEVEL("<<>>CVcxNsStreamingHandler::HandleStateChangedL"); + + if ( iContent && + aMessage.IsSupported( KMPXMessageGeneralType ) ) + { + iCurrentState = *aMessage.Value( KMPXMessageGeneralType ); + + IPTVLOGSTRING2_LOW_LEVEL("CVcxNsStreamingHandler::HandleStateChangedL: state = %d", iCurrentState ); + + switch ( iCurrentState ) + { + case EPbStateInitialised: + { + if ( iLastPosPending ) + { + SeekToLastPosL(); + } + } + break; + case EPbStateStopped: + case EPbStateShuttingDown: + { + HandleCloseStream(); + } + break; + case EPbStatePlaying: + { + GetDurationL(); + } + break; + default: + break; + } + } + + IPTVLOGSTRING_LOW_LEVEL("<<>>CVcxNsStreamingHandler::HandlePropertyChangedL"); + + if( iContent && + aMessage.IsSupported( KMPXMessageGeneralType ) && + aMessage.IsSupported( KMPXMessageGeneralData ) ) + { + TInt property = *aMessage.Value( KMPXMessageGeneralType ); + TInt data = *aMessage.Value( KMPXMessageGeneralData ); + + if( property == EPbPropertyPosition ) + { + IPTVLOGSTRING2_LOW_LEVEL("CVcxNsStreamingHandler::HandlePropertyChangedL(): pos = %d", data ); + + iContent->SetLastPlaybackPosition( TReal32 ( data ), + CVcxNsContent::EVcxContentTypeStream ); + } + } + + IPTVLOGSTRING_LOW_LEVEL("<<>>CVcxNsStreamingHandler::HandleOpenStreamL"); + + HandleCloseStream(); + + if ( !iPlaybackUtility ) + { + iPlaybackUtility = MMPXPlaybackUtility::UtilityL( EMPXCategoryVideo, KPbModeDefault ); + iPlaybackUtility->AddObserverL( *this ); + } + + iContent = CVcxNsContent::NewL( *aContent ); + + TInt prevPos = iContent->GetLastPlaybackPosition( CVcxNsContent::EVcxContentTypeStream ); + + if ( prevPos > KMinIntervalFromBegin ) + { + iLastPosPending = ETrue; + iResumePos = prevPos; + } + else + { + iLastPosPending = EFalse; + iResumePos = 0; + } + + IPTVLOGSTRING_LOW_LEVEL("<<>>CVcxNsStreamingHandler::HandleCloseStream"); + + TRAP_IGNORE( StoreLastPosL() ); + + delete iContent; + iContent = NULL; + + iLastPosPending = EFalse; + iResumePos = 0; + iDuration = 0; + iCurrentState = EPbStateNotInitialised; + + IPTVLOGSTRING_LOW_LEVEL("<<>>CVcxNsStreamingHandler::SeekToLastPosL"); + + iLastPosPending = EFalse; + + if ( iResumePos != 0 ) + { + iPlaybackUtility->SetL( EPbPropertyPosition, iResumePos ); + iResumePos = 0; + } + + IPTVLOGSTRING_LOW_LEVEL("<<>>CVcxNsStreamingHandler::StoreLastPosL"); + + if( iContent && iUiEngine.ContentProvider() ) + { + TInt pos = iContent->GetLastPlaybackPosition( CVcxNsContent::EVcxContentTypeStream ); + + if ( pos <= iDuration - KMinIntervalFromEnd && pos >= KMinIntervalFromBegin ) + { + iUiEngine.ContentProvider()->StoreLastPlayPosL( iContent, + CVcxNsContent::EVcxContentTypeStream, + TReal32( pos ) ); + } + else + { + iUiEngine.ContentProvider()->StoreLastPlayPosL( iContent, + CVcxNsContent::EVcxContentTypeStream, + TReal32 ( 0 ) ); + } + } + + IPTVLOGSTRING_LOW_LEVEL("<<>>CVcxNsStreamingHandler::GetDurationL"); + + iPlaybackUtility->PropertyL( *this, EPbPropertyDuration ); + + IPTVLOGSTRING_LOW_LEVEL("<<>>CVcxNsStreamingHandler::HandlePropertyL"); + + if ( aError == KErrNone && + aProperty == EPbPropertyDuration ) + { + iDuration = aValue; + } + + IPTVLOGSTRING_LOW_LEVEL("<<