mmlibs/mmfw/src/ControllerFramework/mmfvideosubtitlecustomcommands.cpp
changeset 0 40261b775718
equal deleted inserted replaced
-1:000000000000 0:40261b775718
       
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include "mmfvideosubtitlecustomcommands.h"
       
    17 
       
    18 /**
       
    19 @internalComponent
       
    20 */
       
    21 enum TMMFSubtitleSupportMessages
       
    22 	{
       
    23 	EMMFSubtitleSupportAvailable,
       
    24 	EMMFSubtitleSupportEnable,
       
    25 	EMMFSubtitleSupportDisable,
       
    26 	EMMFSubtitleSupportGetLanguageSupportCount,
       
    27 	EMMFSubtitleSupportGetLanguageSupportData,
       
    28 	EMMFSubtitleSupportSetLanguage,
       
    29 	EMMFSubtitleSupportGetLanguage,
       
    30 	EMMFSubtitleSupportUpdateSubtitleConfig,
       
    31 	EMMFSubtitleSupportAddSubtitleConfig,
       
    32 	EMMFSubtitleSupportRemoveSubtitleConfig,
       
    33 	EMMFSubtitleSupportGetCrpParameter
       
    34 	};
       
    35 
       
    36 /**
       
    37 @internalComponent
       
    38 */
       
    39 class TCrpParameters
       
    40 	{
       
    41 public:
       
    42 	TCrpParameters() : iId(TWsGraphicId::EUninitialized) {}
       
    43 	
       
    44 	TWsGraphicId iId;
       
    45 	TRect iCrpRect;
       
    46 	};
       
    47 
       
    48 /**
       
    49  * Constructor.
       
    50  * 
       
    51  * @param aController The client side controller object to be used by this custom 
       
    52  * command interface.
       
    53  */
       
    54 EXPORT_C RMMFVideoPlaySubtitleSupportCustomCommands::RMMFVideoPlaySubtitleSupportCustomCommands(RMMFController& aController)
       
    55 	: RMMFCustomCommandsBase(aController, KUidInterfaceMMFVideoPlaySubtitleSupport)
       
    56 	{
       
    57 	}
       
    58 
       
    59 /**
       
    60  * Adds subtitle configuration data for a window.
       
    61  * 
       
    62  * @param aConfig Subtitle configuration data for a window.
       
    63  * @return KErrNone if completed succesfully, otherwise one of the system wide error codes.
       
    64  */
       
    65 EXPORT_C TInt RMMFVideoPlaySubtitleSupportCustomCommands::AddSubtitleConfig(const TMMFSubtitleWindowConfig& aConfig)
       
    66 	{
       
    67 	TPckgBuf<TMMFSubtitleWindowConfig> configPckg(aConfig);
       
    68 	
       
    69 	return iController.CustomCommandSync(iDestinationPckg,
       
    70 			EMMFSubtitleSupportAddSubtitleConfig, 
       
    71 			configPckg,
       
    72 			KNullDesC8);
       
    73 	}
       
    74 
       
    75 /**
       
    76  * Removes the subtitle configuration data associated with the given window.
       
    77  * 
       
    78  * @param aWindowId Unique identifier of the window associated with the 
       
    79  * configuration data being removed.
       
    80  * @return KErrNone if completed succesfully, otherwise one of the system wide error codes.
       
    81  */
       
    82 EXPORT_C TInt RMMFVideoPlaySubtitleSupportCustomCommands::RemoveSubtitleConfig(TInt aWindowId)
       
    83 	{
       
    84 	TPckgBuf<TInt> windowPckg(aWindowId);
       
    85 	
       
    86 	return iController.CustomCommandSync(iDestinationPckg,
       
    87 			EMMFSubtitleSupportRemoveSubtitleConfig,
       
    88 			windowPckg,
       
    89 			KNullDesC8);
       
    90 	}
       
    91 
       
    92 /** 
       
    93  * Reconfigures subtitle configuration.
       
    94  * 
       
    95  * @param aConfig Subtitle configuration data for a window.
       
    96  * @return KErrNone if completed succesfully, otherwise one of the system wide error codes.
       
    97  */
       
    98 EXPORT_C TInt RMMFVideoPlaySubtitleSupportCustomCommands::UpdateSubtitleConfig(const TMMFSubtitleWindowConfig& aConfig)
       
    99 	{
       
   100 	TPckgBuf<TMMFSubtitleWindowConfig> configPckg(aConfig);
       
   101 	
       
   102 	return iController.CustomCommandSync(iDestinationPckg,
       
   103 			EMMFSubtitleSupportUpdateSubtitleConfig, 
       
   104 			configPckg,
       
   105 			KNullDesC8);
       
   106 	}
       
   107 
       
   108 /** 
       
   109  * Checks if subtitles are available in the current video stream.  
       
   110  * 
       
   111  * @param aAvailable When this function returns, this is set to ETrue if the 
       
   112  * controller supports subtitle extensions and subtitles are available in the 
       
   113  * current video stream.
       
   114  * @return KErrNone if subtitles are supported by the controller; KErrNotSupported 
       
   115  * if the controller does not support subtitles; otherwise other system error code.
       
   116  */
       
   117 EXPORT_C TInt RMMFVideoPlaySubtitleSupportCustomCommands::GetSubtitlesAvailable(TBool& aAvailable)
       
   118 	{
       
   119 	TPckgBuf<TBool> avail;
       
   120 	
       
   121 	TInt err = iController.CustomCommandSync(iDestinationPckg,
       
   122 			EMMFSubtitleSupportAvailable,
       
   123 			KNullDesC8,
       
   124 			KNullDesC8,
       
   125 			avail);
       
   126 	
       
   127 	aAvailable = (KErrNone == err) && avail();
       
   128 	return err;
       
   129 	}
       
   130 
       
   131 /**
       
   132  * Disables subtitles during video playback.
       
   133  * 
       
   134  * @return KErrNone if completed succesfully, otherwise one of the system wide error codes.
       
   135  */
       
   136 EXPORT_C TInt RMMFVideoPlaySubtitleSupportCustomCommands::DisableSubtitles()
       
   137 	{
       
   138 	return iController.CustomCommandSync(iDestinationPckg,
       
   139 			EMMFSubtitleSupportDisable,
       
   140 			KNullDesC8,
       
   141 			KNullDesC8);
       
   142 	}
       
   143 
       
   144 /**
       
   145  * Enables subtitles during video playback.
       
   146  * 
       
   147  * @return KErrNone if subtitles are supported; KErrNotSupported if 
       
   148  * controller does not support subtitles; KErrNotFound if subtitle data 
       
   149  * not found; otherwise other system error code.
       
   150  */
       
   151 EXPORT_C TInt RMMFVideoPlaySubtitleSupportCustomCommands::EnableSubtitles()
       
   152 	{	
       
   153 	return iController.CustomCommandSync(iDestinationPckg,
       
   154 			EMMFSubtitleSupportEnable,
       
   155 			KNullDesC8,
       
   156 			KNullDesC8);
       
   157 	}
       
   158 
       
   159 /**
       
   160  * Gets the CRP parameters associated with a display
       
   161  * 
       
   162  * @param aWindowId The window id used in the query.
       
   163  * @param aId Return the CRP id associated with the given display id
       
   164  * @param aCrpRect Return the subtitle region for drawing the CRP
       
   165  * 
       
   166  * @return KErrNone on success; system wide error code otherwise.
       
   167  */
       
   168 EXPORT_C TInt RMMFVideoPlaySubtitleSupportCustomCommands::GetCrpParameters(TInt aWindowId, TWsGraphicId& aId, TRect& aCrpRect)
       
   169 	{
       
   170 	TPckgBuf<TInt> windowIdPckg(aWindowId);
       
   171 	TPckgBuf<TCrpParameters> parameterPckg;
       
   172 	
       
   173 	TInt err = iController.CustomCommandSync(iDestinationPckg,
       
   174 			EMMFSubtitleSupportGetCrpParameter,
       
   175 			windowIdPckg,
       
   176 			KNullDesC8,
       
   177 			parameterPckg);
       
   178 	
       
   179 	if (KErrNone == err)
       
   180 		{
       
   181 		aId = parameterPckg().iId;
       
   182 		aCrpRect = parameterPckg().iCrpRect;
       
   183 		}
       
   184 	
       
   185 	return err;
       
   186 	}
       
   187 
       
   188 /**
       
   189  * Gets the current subtitle language
       
   190  * 
       
   191  * @param aLanguage On return, set the the current language.
       
   192  * @return KErrNone on success. KErrNotSupported when the enabled subtitle does not 
       
   193  * contain language information.  Otherwise system wide error code.
       
   194  */
       
   195 EXPORT_C TInt RMMFVideoPlaySubtitleSupportCustomCommands::GetSubtitleLanguage(TLanguage& aLanguage)
       
   196 	{
       
   197 	TPckgBuf<TLanguage> languagePckg;
       
   198 	TInt err = iController.CustomCommandSync(iDestinationPckg,
       
   199 			EMMFSubtitleSupportGetLanguage,
       
   200 			KNullDesC8,
       
   201 			KNullDesC8,
       
   202 			languagePckg);
       
   203 	
       
   204 	if (KErrNone == err)
       
   205 		{
       
   206 		aLanguage = languagePckg();
       
   207 		}
       
   208 	
       
   209 	return err;
       
   210 	}
       
   211 
       
   212 /**
       
   213  * Gets a list of all available languages.
       
   214  * 
       
   215  * @param aAvailable Array of available languages
       
   216  * @leave KErrNotSupported If the current controller does not support subtitles.
       
   217  * @leave KErrNotFound If the controller cannot find subtitle data.
       
   218  * @leave Otherwise leaves with any of the system wide error codes.
       
   219  */
       
   220 EXPORT_C void RMMFVideoPlaySubtitleSupportCustomCommands::GetSupportedSubtitleLanguagesL(RArray<TLanguage>& aSubtitleLanguages)
       
   221 	{
       
   222 	aSubtitleLanguages.Reset();
       
   223 	
       
   224 	TPckgBuf<TInt> countPckg;
       
   225 	User::LeaveIfError(iController.CustomCommandSync(iDestinationPckg,
       
   226 			EMMFSubtitleSupportGetLanguageSupportCount,
       
   227 			KNullDesC8,
       
   228 			KNullDesC8,
       
   229 			countPckg));
       
   230 	
       
   231 	TInt count = countPckg();
       
   232 	
       
   233 	if (count > 0)
       
   234 		{	
       
   235 		HBufC8* buf = HBufC8::NewLC(count * sizeof(TLanguage));	
       
   236 		TPtr8 ptr = buf->Des();
       
   237 	
       
   238 		User::LeaveIfError(iController.CustomCommandSync(iDestinationPckg, 
       
   239 				EMMFSubtitleSupportGetLanguageSupportData, 
       
   240 				KNullDesC8,
       
   241 				KNullDesC8,
       
   242 				ptr));
       
   243 		
       
   244 		TPckgBuf<TLanguage> langPckg;
       
   245 		RDesReadStream stream(ptr);
       
   246 		CleanupClosePushL(stream);
       
   247 	
       
   248 		for (TInt i = 0; i < count; i++)
       
   249 			{
       
   250 			stream.ReadL(langPckg);
       
   251 			aSubtitleLanguages.AppendL(langPckg());
       
   252 			}
       
   253 	
       
   254 		CleanupStack::PopAndDestroy(2, buf); //stream, buf
       
   255 		}
       
   256 	}
       
   257 
       
   258 /**
       
   259  * Sets the current subtitle language
       
   260  * 
       
   261  * @param aSubtitleLanguage Language to be used for subtitle stream.
       
   262  * @return KErrNone on success.  KErrNotSupported when the enabled subtitle 
       
   263  * does not contain language information.  Otherwise system wide error code.
       
   264  */
       
   265 EXPORT_C TInt RMMFVideoPlaySubtitleSupportCustomCommands::SetSubtitleLanguage(TLanguage aSubtitleLanguage)
       
   266 	{
       
   267 	TPckgBuf<TLanguage> languagePckg(aSubtitleLanguage);
       
   268 	
       
   269 	return iController.CustomCommandSync(iDestinationPckg,
       
   270 			EMMFSubtitleSupportSetLanguage,
       
   271 			languagePckg,
       
   272 			KNullDesC8);
       
   273 	}
       
   274 
       
   275 /**
       
   276  * Creates a new custom command parser capable of handling subtitle support commands.
       
   277  * 
       
   278  * @param aImplementor A reference to the controller plugin that owns this new 
       
   279  * object.
       
   280  * 
       
   281  * @return A pointer to the object created.
       
   282  */
       
   283 EXPORT_C CMMFVideoPlaySubtitleSupportCustomCommandParser* CMMFVideoPlaySubtitleSupportCustomCommandParser::NewL(
       
   284 		MMMFVideoPlaySubtitleSupportCustomCommandImplementor& aImplementor)
       
   285 	{
       
   286 	return new(ELeave) CMMFVideoPlaySubtitleSupportCustomCommandParser(aImplementor);
       
   287 	}
       
   288 
       
   289 CMMFVideoPlaySubtitleSupportCustomCommandParser::CMMFVideoPlaySubtitleSupportCustomCommandParser(MMMFVideoPlaySubtitleSupportCustomCommandImplementor& aImplementor) :
       
   290 	CMMFCustomCommandParserBase(KUidInterfaceMMFVideoPlaySubtitleSupport),
       
   291 	iImplementor(aImplementor)
       
   292 	{
       
   293 	}
       
   294 
       
   295 /**
       
   296  * Destructor.
       
   297  */
       
   298 EXPORT_C CMMFVideoPlaySubtitleSupportCustomCommandParser::~CMMFVideoPlaySubtitleSupportCustomCommandParser()
       
   299 	{
       
   300 	iAvailableLanguages.Close();
       
   301 	}
       
   302 
       
   303 /**
       
   304  * Handles a request from the client. Called by the controller framework.
       
   305  * 
       
   306  * @param aMessage The message to be handled.
       
   307  */
       
   308 void CMMFVideoPlaySubtitleSupportCustomCommandParser::HandleRequest(TMMFMessage& aMessage)
       
   309 	{
       
   310 	if (aMessage.Destination().InterfaceId() == KUidInterfaceMMFVideoPlaySubtitleSupport)
       
   311 		{
       
   312 		TRAPD(error, DoHandleRequestL(aMessage));
       
   313 		aMessage.Complete(error);
       
   314 		}
       
   315 	else
       
   316 		{
       
   317 		aMessage.Complete(KErrNotSupported);
       
   318 		}
       
   319 	}
       
   320 
       
   321 void CMMFVideoPlaySubtitleSupportCustomCommandParser::DoHandleRequestL(TMMFMessage& aMessage)
       
   322 	{
       
   323 	switch (aMessage.Function())
       
   324 		{
       
   325 	case EMMFSubtitleSupportAvailable:
       
   326 		DoGetSubtitlesAvailableL(aMessage);
       
   327 		break;
       
   328 	case EMMFSubtitleSupportEnable:
       
   329 		DoEnableSubtitlesL(aMessage);
       
   330 		break;
       
   331 	case EMMFSubtitleSupportDisable:
       
   332 		DoDisableSubtitlesL(aMessage);
       
   333 		break;
       
   334 	case EMMFSubtitleSupportGetLanguageSupportCount:
       
   335 		DoGetSupportedLanguagesCountL(aMessage);
       
   336 		break;
       
   337 	case EMMFSubtitleSupportGetLanguageSupportData:
       
   338 		DoGetSupportedLanguagesDataL(aMessage);
       
   339 		break;
       
   340 	case EMMFSubtitleSupportGetLanguage:
       
   341 		DoGetSubtitleLanguageL(aMessage);
       
   342 		break;
       
   343 	case EMMFSubtitleSupportSetLanguage:
       
   344 		DoSetSubtitleLanguageL(aMessage);
       
   345 		break;
       
   346 	case EMMFSubtitleSupportUpdateSubtitleConfig:
       
   347 		DoUpdateSubtitleConfigL(aMessage);
       
   348 		break;
       
   349 	case EMMFSubtitleSupportAddSubtitleConfig:
       
   350 		DoAddSubtitleConfigL(aMessage);
       
   351 		break;
       
   352 	case EMMFSubtitleSupportRemoveSubtitleConfig:
       
   353 		DoRemoveSubtitleConfigL(aMessage);
       
   354 		break;
       
   355 	case EMMFSubtitleSupportGetCrpParameter:
       
   356 		DoGetCrpParametersL(aMessage);
       
   357 		break;
       
   358 	default:
       
   359 		User::Leave(KErrNotSupported);
       
   360 		break;
       
   361 		}
       
   362 	}
       
   363 
       
   364 void CMMFVideoPlaySubtitleSupportCustomCommandParser::DoGetSubtitlesAvailableL(TMMFMessage& aMessage)
       
   365 	{
       
   366 	TBool avail;
       
   367 	iImplementor.MvpsusGetSubtitlesAvailableL(avail);
       
   368 	TPckgBuf<TBool> availPckg(avail);
       
   369 	aMessage.WriteDataToClientL(availPckg);
       
   370 	}
       
   371 
       
   372 void CMMFVideoPlaySubtitleSupportCustomCommandParser::DoUpdateSubtitleConfigL(TMMFMessage& aMessage)
       
   373 	{
       
   374 	TPckgBuf<TMMFSubtitleWindowConfig> configPckg;
       
   375 	aMessage.ReadData1FromClientL(configPckg);
       
   376 	iImplementor.MvpsusUpdateSubtitleConfigL(configPckg());
       
   377 	}
       
   378 
       
   379 void CMMFVideoPlaySubtitleSupportCustomCommandParser::DoAddSubtitleConfigL(TMMFMessage& aMessage)
       
   380 	{
       
   381 	TPckgBuf<TMMFSubtitleWindowConfig> configPckg;
       
   382 	aMessage.ReadData1FromClientL(configPckg);
       
   383 	iImplementor.MvpsusAddSubtitleConfigL(configPckg());
       
   384 	}
       
   385 
       
   386 void CMMFVideoPlaySubtitleSupportCustomCommandParser::DoRemoveSubtitleConfigL(TMMFMessage& aMessage)
       
   387 	{
       
   388 	TPckgBuf<TInt> windowPckg;
       
   389 	aMessage.ReadData1FromClientL(windowPckg);
       
   390 	iImplementor.MvpsusRemoveSubtitleConfigL(windowPckg());
       
   391 	}
       
   392 
       
   393 void CMMFVideoPlaySubtitleSupportCustomCommandParser::DoDisableSubtitlesL(TMMFMessage& /*aMessage*/)
       
   394 	{
       
   395 	iImplementor.MvpsusDisableSubtitlesL();
       
   396 	}
       
   397 
       
   398 void CMMFVideoPlaySubtitleSupportCustomCommandParser::DoEnableSubtitlesL(TMMFMessage& /*aMessage*/)
       
   399 	{
       
   400 	iImplementor.MvpsusEnableSubtitlesL();
       
   401 	}
       
   402 
       
   403 void CMMFVideoPlaySubtitleSupportCustomCommandParser::DoGetSupportedLanguagesDataL(TMMFMessage& aMessage)
       
   404 	{
       
   405 	HBufC8* buf = HBufC8::NewLC(iAvailableLanguages.Count() * sizeof(TLanguage));
       
   406 	TPtr8 ptr = buf->Des();
       
   407 	RDesWriteStream stream(ptr);
       
   408 	CleanupClosePushL(stream);
       
   409 	
       
   410 	for (TInt i = 0; i < iAvailableLanguages.Count(); i++)
       
   411 		{
       
   412 		TPckgBuf<TLanguage> langPckg(iAvailableLanguages[i]);
       
   413 		stream.WriteL(langPckg);
       
   414 		}
       
   415 	
       
   416 	stream.CommitL();
       
   417 	aMessage.WriteDataToClientL(ptr);
       
   418 	CleanupStack::PopAndDestroy(2, buf); // stream, buf
       
   419 	}
       
   420 
       
   421 void CMMFVideoPlaySubtitleSupportCustomCommandParser::DoGetSupportedLanguagesCountL(TMMFMessage& aMessage)
       
   422 	{
       
   423 	iAvailableLanguages.Reset();
       
   424 	iImplementor.MvpsusGetSupportedSubtitleLanguagesL(iAvailableLanguages);
       
   425 	
       
   426 	TPckgBuf<TInt> countPckg(iAvailableLanguages.Count());
       
   427 	aMessage.WriteDataToClientL(countPckg);
       
   428 	}
       
   429 
       
   430 void CMMFVideoPlaySubtitleSupportCustomCommandParser::DoGetSubtitleLanguageL(TMMFMessage& aMessage)
       
   431 	{
       
   432 	TLanguage lang;
       
   433 	iImplementor.MvpsusGetSubtitleLanguageL(lang);
       
   434 	TPckgBuf<TLanguage> langPckg(lang);
       
   435 	aMessage.WriteDataToClientL(langPckg);
       
   436 	}
       
   437 
       
   438 void CMMFVideoPlaySubtitleSupportCustomCommandParser::DoSetSubtitleLanguageL(TMMFMessage& aMessage)
       
   439 	{
       
   440 	TPckgBuf<TLanguage> langPckg;
       
   441 	aMessage.ReadData1FromClientL(langPckg);
       
   442 	iImplementor.MvpsusSetSubtitleLanguageL(langPckg());
       
   443 	}
       
   444 
       
   445 void CMMFVideoPlaySubtitleSupportCustomCommandParser::DoGetCrpParametersL(TMMFMessage& aMessage)
       
   446 	{
       
   447 	TCrpParameters crpParams;
       
   448 	TPckgBuf<TInt> displayPckg;
       
   449 	aMessage.ReadData1FromClientL(displayPckg);
       
   450 	iImplementor.MvpsusGetCrpParametersL(displayPckg(), crpParams.iId, crpParams.iCrpRect);
       
   451 	
       
   452 	TPckgBuf<TCrpParameters> paramPckg(crpParams);
       
   453 	aMessage.WriteDataToClientL(paramPckg);
       
   454 	}