os/mm/mmlibs/mmfw/src/Client/Video/mmfsubtitleutility.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
/**
sl@0
    17
 @file
sl@0
    18
 @internalComponent
sl@0
    19
*/
sl@0
    20
sl@0
    21
#include "mmfsubtitleutility.h"
sl@0
    22
sl@0
    23
sl@0
    24
CMMFSubtitleUtility* CMMFSubtitleUtility::NewL(RMMFController& aController, RWsSession &aWs)
sl@0
    25
	{
sl@0
    26
	CMMFSubtitleUtility* self = new(ELeave) CMMFSubtitleUtility(aController);
sl@0
    27
	CleanupStack::PushL(self);
sl@0
    28
	self->ConstructL(aWs);
sl@0
    29
	CleanupStack::Pop();
sl@0
    30
	return self;	
sl@0
    31
	}
sl@0
    32
sl@0
    33
CMMFSubtitleUtility::CMMFSubtitleUtility(RMMFController& aController): iSubtitleSupportCustomCommands(aController)
sl@0
    34
	{
sl@0
    35
	}
sl@0
    36
sl@0
    37
void CMMFSubtitleUtility::ConstructL(RWsSession &aWs)
sl@0
    38
	{
sl@0
    39
	iDevice = new (ELeave) CWsScreenDevice(aWs);
sl@0
    40
	User::LeaveIfError(iDevice->Construct());
sl@0
    41
	iSubtitleGc = new (ELeave) CWindowGc(iDevice);
sl@0
    42
	User::LeaveIfError(iSubtitleGc->Construct());
sl@0
    43
	}
sl@0
    44
sl@0
    45
CMMFSubtitleUtility::~CMMFSubtitleUtility()
sl@0
    46
	{
sl@0
    47
	delete iSubtitleGc;
sl@0
    48
	delete iDevice;
sl@0
    49
	iSubtitleLanguages.Close();
sl@0
    50
	iCrpDataArray.Close();
sl@0
    51
	}
sl@0
    52
sl@0
    53
// Add subtitle related config to controller
sl@0
    54
TInt CMMFSubtitleUtility::AddSubtitleConfig(const TMMFSubtitleWindowConfig& aConfig)
sl@0
    55
	{
sl@0
    56
	TCrpData crpData(aConfig.iWindowId);
sl@0
    57
	// Add the crp data before calling custom commands in case append fails
sl@0
    58
	TInt err = iCrpDataArray.Append(crpData);
sl@0
    59
	if (KErrNone == err)
sl@0
    60
		{
sl@0
    61
		err = iSubtitleSupportCustomCommands.AddSubtitleConfig(aConfig);
sl@0
    62
	
sl@0
    63
		if (KErrNone != err)
sl@0
    64
			{
sl@0
    65
			// removed the added crp data on error
sl@0
    66
			iCrpDataArray.Remove(iCrpDataArray.Count()-1);
sl@0
    67
			}
sl@0
    68
		}
sl@0
    69
	
sl@0
    70
	return err;
sl@0
    71
	}
sl@0
    72
sl@0
    73
// Found the index of the subtitle data in iCrpDataArray given aWindowId
sl@0
    74
TInt CMMFSubtitleUtility::FindCrpArrayIndex(TInt aWindowId)
sl@0
    75
	{
sl@0
    76
	TInt ret = KErrNotFound;
sl@0
    77
	for (TInt i = iCrpDataArray.Count(); --i >= 0; )
sl@0
    78
		{
sl@0
    79
		if (iCrpDataArray[i].iWindowId == aWindowId)
sl@0
    80
			{
sl@0
    81
			ret = i;
sl@0
    82
			break;
sl@0
    83
			}
sl@0
    84
		}
sl@0
    85
	return ret;
sl@0
    86
	}
sl@0
    87
sl@0
    88
// Remove subtitle related config from controller
sl@0
    89
TInt CMMFSubtitleUtility::RemoveSubtitleConfig(TInt aWindowId)
sl@0
    90
	{
sl@0
    91
	TInt ret = FindCrpArrayIndex(aWindowId);
sl@0
    92
	if (ret >= 0)
sl@0
    93
		{		
sl@0
    94
		iCrpDataArray.Remove(ret);
sl@0
    95
		ret = iSubtitleSupportCustomCommands.RemoveSubtitleConfig(aWindowId);
sl@0
    96
		}
sl@0
    97
	return ret;
sl@0
    98
	}
sl@0
    99
sl@0
   100
// Update subtitle related config from controller and clear the subtitle region
sl@0
   101
TInt CMMFSubtitleUtility::UpdateSubtitleConfig(const TMMFSubtitleWindowConfig& aConfig)
sl@0
   102
	{
sl@0
   103
	TInt ret = FindCrpArrayIndex(aConfig.iWindowId);
sl@0
   104
	if (ret >= 0)
sl@0
   105
		{
sl@0
   106
		// clear the CRP id
sl@0
   107
		iCrpDataArray[ret].iCrpId.Set(0);
sl@0
   108
sl@0
   109
		ret = iSubtitleSupportCustomCommands.UpdateSubtitleConfig(aConfig);
sl@0
   110
		}
sl@0
   111
	return ret;
sl@0
   112
	}
sl@0
   113
sl@0
   114
// Return if subtitle is available
sl@0
   115
TBool CMMFSubtitleUtility::SubtitlesAvailable(RMMFController& aController)
sl@0
   116
	{
sl@0
   117
	TBool available = EFalse;
sl@0
   118
	RMMFVideoPlaySubtitleSupportCustomCommands subtitleSupportCustomCommands(aController);
sl@0
   119
	subtitleSupportCustomCommands.GetSubtitlesAvailable(available);
sl@0
   120
	return available;
sl@0
   121
	}
sl@0
   122
sl@0
   123
TInt CMMFSubtitleUtility::EnableSubtitles()
sl@0
   124
	{
sl@0
   125
	return iSubtitleSupportCustomCommands.EnableSubtitles();
sl@0
   126
	}
sl@0
   127
sl@0
   128
void CMMFSubtitleUtility::DisableSubtitles()
sl@0
   129
	{
sl@0
   130
	for (TInt i = iCrpDataArray.Count(); --i >= 0; )
sl@0
   131
		{
sl@0
   132
		iSubtitleSupportCustomCommands.RemoveSubtitleConfig(iCrpDataArray[i].iWindowId);
sl@0
   133
		}
sl@0
   134
sl@0
   135
	iCrpDataArray.Reset();
sl@0
   136
	
sl@0
   137
	// still need to send disable command to controller event if array count was 0
sl@0
   138
	// because window may have been removed after subtitle is enabled
sl@0
   139
	iSubtitleSupportCustomCommands.DisableSubtitles();
sl@0
   140
	}
sl@0
   141
sl@0
   142
// Helper function to draw CRP
sl@0
   143
void CMMFSubtitleUtility::DrawCrp(RWindow& aWindow, TInt aCrpIdx, TBool aCallBeginRedraw)
sl@0
   144
	{
sl@0
   145
	TCrpData& crpData = iCrpDataArray[aCrpIdx];
sl@0
   146
sl@0
   147
	if (crpData.iCrpId.Id() != 0)
sl@0
   148
		{
sl@0
   149
sl@0
   150
		if (aCallBeginRedraw)
sl@0
   151
			{
sl@0
   152
			// CRP is ready to be drawn
sl@0
   153
			aWindow.Invalidate(crpData.iCrpRect);
sl@0
   154
			aWindow.BeginRedraw(crpData.iCrpRect);
sl@0
   155
			}
sl@0
   156
		
sl@0
   157
		iSubtitleGc->Activate(aWindow);
sl@0
   158
		iSubtitleGc->DrawWsGraphic(crpData.iCrpId, crpData.iCrpRect);
sl@0
   159
		iSubtitleGc->Deactivate();
sl@0
   160
		
sl@0
   161
		if (aCallBeginRedraw)
sl@0
   162
			{
sl@0
   163
			aWindow.EndRedraw();
sl@0
   164
			}
sl@0
   165
		}
sl@0
   166
	}
sl@0
   167
sl@0
   168
// Handle CRP ready event from controller and draw the CRP
sl@0
   169
void CMMFSubtitleUtility::HandleCrpReady(RWindow& aWindow)
sl@0
   170
	{
sl@0
   171
	TInt index = FindCrpArrayIndex(aWindow.WsHandle());
sl@0
   172
	if (index >= 0)
sl@0
   173
		{
sl@0
   174
		TCrpData& crpData = iCrpDataArray[index];
sl@0
   175
		TInt err = iSubtitleSupportCustomCommands.GetCrpParameters(aWindow.WsHandle(), 
sl@0
   176
																	crpData.iCrpId, 
sl@0
   177
																	crpData.iCrpRect);
sl@0
   178
sl@0
   179
		if (KErrNone == err)
sl@0
   180
			{
sl@0
   181
			DrawCrp(aWindow, index, ETrue);
sl@0
   182
			}
sl@0
   183
		else
sl@0
   184
			{
sl@0
   185
			// Window may have been removed before the event was received, ignore event
sl@0
   186
			RDebug::Print(_L("CMMFSubtitleUtility::HandleCrpReady aWindowId=%d, err==%d"), aWindow.WsHandle(), err);
sl@0
   187
			}
sl@0
   188
		}
sl@0
   189
	}
sl@0
   190
sl@0
   191
// Redraw subtitle CRP if redraw rect intersect with subtitle region
sl@0
   192
void CMMFSubtitleUtility::RedrawSubtitle(RWindow& aWindow, const TRect& aRedrawRect)
sl@0
   193
	{
sl@0
   194
	TInt index = FindCrpArrayIndex(aWindow.WsHandle());
sl@0
   195
	if (index >= 0 && aRedrawRect.Intersects(iCrpDataArray[index].iCrpRect))
sl@0
   196
		{
sl@0
   197
		DrawCrp(aWindow, index, EFalse);
sl@0
   198
		}
sl@0
   199
	}
sl@0
   200
sl@0
   201
TInt CMMFSubtitleUtility::SetSubtitleLanguage(TLanguage aSubtitleLanguage)
sl@0
   202
	{
sl@0
   203
	return iSubtitleSupportCustomCommands.SetSubtitleLanguage(aSubtitleLanguage);
sl@0
   204
	}
sl@0
   205
sl@0
   206
TArray<TLanguage> CMMFSubtitleUtility::SupportedSubtitleLanguagesL()
sl@0
   207
	{
sl@0
   208
	TRAPD(err, iSubtitleSupportCustomCommands.GetSupportedSubtitleLanguagesL(iSubtitleLanguages));
sl@0
   209
	
sl@0
   210
	// Do not propagate KErrNotSupported; return empty list of languages.
sl@0
   211
	if (KErrNone != err && KErrNotSupported != err)
sl@0
   212
		{
sl@0
   213
		User::Leave(err);
sl@0
   214
		}
sl@0
   215
	return iSubtitleLanguages.Array();
sl@0
   216
	}
sl@0
   217
sl@0
   218
TLanguage CMMFSubtitleUtility::SubtitleLanguage()
sl@0
   219
	{
sl@0
   220
	TLanguage language = ELangNone;
sl@0
   221
	
sl@0
   222
	// ignore returned value, language parameter is unchanged on error
sl@0
   223
	iSubtitleSupportCustomCommands.GetSubtitleLanguage(language);
sl@0
   224
sl@0
   225
	return language;
sl@0
   226
	}