os/mm/mmlibs/mmfw/src/Client/Video/mmfsubtitleutility.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/mm/mmlibs/mmfw/src/Client/Video/mmfsubtitleutility.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,226 @@
     1.4 +// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +/**
    1.20 + @file
    1.21 + @internalComponent
    1.22 +*/
    1.23 +
    1.24 +#include "mmfsubtitleutility.h"
    1.25 +
    1.26 +
    1.27 +CMMFSubtitleUtility* CMMFSubtitleUtility::NewL(RMMFController& aController, RWsSession &aWs)
    1.28 +	{
    1.29 +	CMMFSubtitleUtility* self = new(ELeave) CMMFSubtitleUtility(aController);
    1.30 +	CleanupStack::PushL(self);
    1.31 +	self->ConstructL(aWs);
    1.32 +	CleanupStack::Pop();
    1.33 +	return self;	
    1.34 +	}
    1.35 +
    1.36 +CMMFSubtitleUtility::CMMFSubtitleUtility(RMMFController& aController): iSubtitleSupportCustomCommands(aController)
    1.37 +	{
    1.38 +	}
    1.39 +
    1.40 +void CMMFSubtitleUtility::ConstructL(RWsSession &aWs)
    1.41 +	{
    1.42 +	iDevice = new (ELeave) CWsScreenDevice(aWs);
    1.43 +	User::LeaveIfError(iDevice->Construct());
    1.44 +	iSubtitleGc = new (ELeave) CWindowGc(iDevice);
    1.45 +	User::LeaveIfError(iSubtitleGc->Construct());
    1.46 +	}
    1.47 +
    1.48 +CMMFSubtitleUtility::~CMMFSubtitleUtility()
    1.49 +	{
    1.50 +	delete iSubtitleGc;
    1.51 +	delete iDevice;
    1.52 +	iSubtitleLanguages.Close();
    1.53 +	iCrpDataArray.Close();
    1.54 +	}
    1.55 +
    1.56 +// Add subtitle related config to controller
    1.57 +TInt CMMFSubtitleUtility::AddSubtitleConfig(const TMMFSubtitleWindowConfig& aConfig)
    1.58 +	{
    1.59 +	TCrpData crpData(aConfig.iWindowId);
    1.60 +	// Add the crp data before calling custom commands in case append fails
    1.61 +	TInt err = iCrpDataArray.Append(crpData);
    1.62 +	if (KErrNone == err)
    1.63 +		{
    1.64 +		err = iSubtitleSupportCustomCommands.AddSubtitleConfig(aConfig);
    1.65 +	
    1.66 +		if (KErrNone != err)
    1.67 +			{
    1.68 +			// removed the added crp data on error
    1.69 +			iCrpDataArray.Remove(iCrpDataArray.Count()-1);
    1.70 +			}
    1.71 +		}
    1.72 +	
    1.73 +	return err;
    1.74 +	}
    1.75 +
    1.76 +// Found the index of the subtitle data in iCrpDataArray given aWindowId
    1.77 +TInt CMMFSubtitleUtility::FindCrpArrayIndex(TInt aWindowId)
    1.78 +	{
    1.79 +	TInt ret = KErrNotFound;
    1.80 +	for (TInt i = iCrpDataArray.Count(); --i >= 0; )
    1.81 +		{
    1.82 +		if (iCrpDataArray[i].iWindowId == aWindowId)
    1.83 +			{
    1.84 +			ret = i;
    1.85 +			break;
    1.86 +			}
    1.87 +		}
    1.88 +	return ret;
    1.89 +	}
    1.90 +
    1.91 +// Remove subtitle related config from controller
    1.92 +TInt CMMFSubtitleUtility::RemoveSubtitleConfig(TInt aWindowId)
    1.93 +	{
    1.94 +	TInt ret = FindCrpArrayIndex(aWindowId);
    1.95 +	if (ret >= 0)
    1.96 +		{		
    1.97 +		iCrpDataArray.Remove(ret);
    1.98 +		ret = iSubtitleSupportCustomCommands.RemoveSubtitleConfig(aWindowId);
    1.99 +		}
   1.100 +	return ret;
   1.101 +	}
   1.102 +
   1.103 +// Update subtitle related config from controller and clear the subtitle region
   1.104 +TInt CMMFSubtitleUtility::UpdateSubtitleConfig(const TMMFSubtitleWindowConfig& aConfig)
   1.105 +	{
   1.106 +	TInt ret = FindCrpArrayIndex(aConfig.iWindowId);
   1.107 +	if (ret >= 0)
   1.108 +		{
   1.109 +		// clear the CRP id
   1.110 +		iCrpDataArray[ret].iCrpId.Set(0);
   1.111 +
   1.112 +		ret = iSubtitleSupportCustomCommands.UpdateSubtitleConfig(aConfig);
   1.113 +		}
   1.114 +	return ret;
   1.115 +	}
   1.116 +
   1.117 +// Return if subtitle is available
   1.118 +TBool CMMFSubtitleUtility::SubtitlesAvailable(RMMFController& aController)
   1.119 +	{
   1.120 +	TBool available = EFalse;
   1.121 +	RMMFVideoPlaySubtitleSupportCustomCommands subtitleSupportCustomCommands(aController);
   1.122 +	subtitleSupportCustomCommands.GetSubtitlesAvailable(available);
   1.123 +	return available;
   1.124 +	}
   1.125 +
   1.126 +TInt CMMFSubtitleUtility::EnableSubtitles()
   1.127 +	{
   1.128 +	return iSubtitleSupportCustomCommands.EnableSubtitles();
   1.129 +	}
   1.130 +
   1.131 +void CMMFSubtitleUtility::DisableSubtitles()
   1.132 +	{
   1.133 +	for (TInt i = iCrpDataArray.Count(); --i >= 0; )
   1.134 +		{
   1.135 +		iSubtitleSupportCustomCommands.RemoveSubtitleConfig(iCrpDataArray[i].iWindowId);
   1.136 +		}
   1.137 +
   1.138 +	iCrpDataArray.Reset();
   1.139 +	
   1.140 +	// still need to send disable command to controller event if array count was 0
   1.141 +	// because window may have been removed after subtitle is enabled
   1.142 +	iSubtitleSupportCustomCommands.DisableSubtitles();
   1.143 +	}
   1.144 +
   1.145 +// Helper function to draw CRP
   1.146 +void CMMFSubtitleUtility::DrawCrp(RWindow& aWindow, TInt aCrpIdx, TBool aCallBeginRedraw)
   1.147 +	{
   1.148 +	TCrpData& crpData = iCrpDataArray[aCrpIdx];
   1.149 +
   1.150 +	if (crpData.iCrpId.Id() != 0)
   1.151 +		{
   1.152 +
   1.153 +		if (aCallBeginRedraw)
   1.154 +			{
   1.155 +			// CRP is ready to be drawn
   1.156 +			aWindow.Invalidate(crpData.iCrpRect);
   1.157 +			aWindow.BeginRedraw(crpData.iCrpRect);
   1.158 +			}
   1.159 +		
   1.160 +		iSubtitleGc->Activate(aWindow);
   1.161 +		iSubtitleGc->DrawWsGraphic(crpData.iCrpId, crpData.iCrpRect);
   1.162 +		iSubtitleGc->Deactivate();
   1.163 +		
   1.164 +		if (aCallBeginRedraw)
   1.165 +			{
   1.166 +			aWindow.EndRedraw();
   1.167 +			}
   1.168 +		}
   1.169 +	}
   1.170 +
   1.171 +// Handle CRP ready event from controller and draw the CRP
   1.172 +void CMMFSubtitleUtility::HandleCrpReady(RWindow& aWindow)
   1.173 +	{
   1.174 +	TInt index = FindCrpArrayIndex(aWindow.WsHandle());
   1.175 +	if (index >= 0)
   1.176 +		{
   1.177 +		TCrpData& crpData = iCrpDataArray[index];
   1.178 +		TInt err = iSubtitleSupportCustomCommands.GetCrpParameters(aWindow.WsHandle(), 
   1.179 +																	crpData.iCrpId, 
   1.180 +																	crpData.iCrpRect);
   1.181 +
   1.182 +		if (KErrNone == err)
   1.183 +			{
   1.184 +			DrawCrp(aWindow, index, ETrue);
   1.185 +			}
   1.186 +		else
   1.187 +			{
   1.188 +			// Window may have been removed before the event was received, ignore event
   1.189 +			RDebug::Print(_L("CMMFSubtitleUtility::HandleCrpReady aWindowId=%d, err==%d"), aWindow.WsHandle(), err);
   1.190 +			}
   1.191 +		}
   1.192 +	}
   1.193 +
   1.194 +// Redraw subtitle CRP if redraw rect intersect with subtitle region
   1.195 +void CMMFSubtitleUtility::RedrawSubtitle(RWindow& aWindow, const TRect& aRedrawRect)
   1.196 +	{
   1.197 +	TInt index = FindCrpArrayIndex(aWindow.WsHandle());
   1.198 +	if (index >= 0 && aRedrawRect.Intersects(iCrpDataArray[index].iCrpRect))
   1.199 +		{
   1.200 +		DrawCrp(aWindow, index, EFalse);
   1.201 +		}
   1.202 +	}
   1.203 +
   1.204 +TInt CMMFSubtitleUtility::SetSubtitleLanguage(TLanguage aSubtitleLanguage)
   1.205 +	{
   1.206 +	return iSubtitleSupportCustomCommands.SetSubtitleLanguage(aSubtitleLanguage);
   1.207 +	}
   1.208 +
   1.209 +TArray<TLanguage> CMMFSubtitleUtility::SupportedSubtitleLanguagesL()
   1.210 +	{
   1.211 +	TRAPD(err, iSubtitleSupportCustomCommands.GetSupportedSubtitleLanguagesL(iSubtitleLanguages));
   1.212 +	
   1.213 +	// Do not propagate KErrNotSupported; return empty list of languages.
   1.214 +	if (KErrNone != err && KErrNotSupported != err)
   1.215 +		{
   1.216 +		User::Leave(err);
   1.217 +		}
   1.218 +	return iSubtitleLanguages.Array();
   1.219 +	}
   1.220 +
   1.221 +TLanguage CMMFSubtitleUtility::SubtitleLanguage()
   1.222 +	{
   1.223 +	TLanguage language = ELangNone;
   1.224 +	
   1.225 +	// ignore returned value, language parameter is unchanged on error
   1.226 +	iSubtitleSupportCustomCommands.GetSubtitleLanguage(language);
   1.227 +
   1.228 +	return language;
   1.229 +	}