First public contribution.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #include "mmfvideosubtitlecustomcommands.h"
21 enum TMMFSubtitleSupportMessages
23 EMMFSubtitleSupportAvailable,
24 EMMFSubtitleSupportEnable,
25 EMMFSubtitleSupportDisable,
26 EMMFSubtitleSupportGetLanguageSupportCount,
27 EMMFSubtitleSupportGetLanguageSupportData,
28 EMMFSubtitleSupportSetLanguage,
29 EMMFSubtitleSupportGetLanguage,
30 EMMFSubtitleSupportUpdateSubtitleConfig,
31 EMMFSubtitleSupportAddSubtitleConfig,
32 EMMFSubtitleSupportRemoveSubtitleConfig,
33 EMMFSubtitleSupportGetCrpParameter
42 TCrpParameters() : iId(TWsGraphicId::EUninitialized) {}
51 * @param aController The client side controller object to be used by this custom
54 EXPORT_C RMMFVideoPlaySubtitleSupportCustomCommands::RMMFVideoPlaySubtitleSupportCustomCommands(RMMFController& aController)
55 : RMMFCustomCommandsBase(aController, KUidInterfaceMMFVideoPlaySubtitleSupport)
60 * Adds subtitle configuration data for a window.
62 * @param aConfig Subtitle configuration data for a window.
63 * @return KErrNone if completed succesfully, otherwise one of the system wide error codes.
65 EXPORT_C TInt RMMFVideoPlaySubtitleSupportCustomCommands::AddSubtitleConfig(const TMMFSubtitleWindowConfig& aConfig)
67 TPckgBuf<TMMFSubtitleWindowConfig> configPckg(aConfig);
69 return iController.CustomCommandSync(iDestinationPckg,
70 EMMFSubtitleSupportAddSubtitleConfig,
76 * Removes the subtitle configuration data associated with the given window.
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.
82 EXPORT_C TInt RMMFVideoPlaySubtitleSupportCustomCommands::RemoveSubtitleConfig(TInt aWindowId)
84 TPckgBuf<TInt> windowPckg(aWindowId);
86 return iController.CustomCommandSync(iDestinationPckg,
87 EMMFSubtitleSupportRemoveSubtitleConfig,
93 * Reconfigures subtitle configuration.
95 * @param aConfig Subtitle configuration data for a window.
96 * @return KErrNone if completed succesfully, otherwise one of the system wide error codes.
98 EXPORT_C TInt RMMFVideoPlaySubtitleSupportCustomCommands::UpdateSubtitleConfig(const TMMFSubtitleWindowConfig& aConfig)
100 TPckgBuf<TMMFSubtitleWindowConfig> configPckg(aConfig);
102 return iController.CustomCommandSync(iDestinationPckg,
103 EMMFSubtitleSupportUpdateSubtitleConfig,
109 * Checks if subtitles are available in the current video stream.
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.
117 EXPORT_C TInt RMMFVideoPlaySubtitleSupportCustomCommands::GetSubtitlesAvailable(TBool& aAvailable)
119 TPckgBuf<TBool> avail;
121 TInt err = iController.CustomCommandSync(iDestinationPckg,
122 EMMFSubtitleSupportAvailable,
127 aAvailable = (KErrNone == err) && avail();
132 * Disables subtitles during video playback.
134 * @return KErrNone if completed succesfully, otherwise one of the system wide error codes.
136 EXPORT_C TInt RMMFVideoPlaySubtitleSupportCustomCommands::DisableSubtitles()
138 return iController.CustomCommandSync(iDestinationPckg,
139 EMMFSubtitleSupportDisable,
145 * Enables subtitles during video playback.
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.
151 EXPORT_C TInt RMMFVideoPlaySubtitleSupportCustomCommands::EnableSubtitles()
153 return iController.CustomCommandSync(iDestinationPckg,
154 EMMFSubtitleSupportEnable,
160 * Gets the CRP parameters associated with a display
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
166 * @return KErrNone on success; system wide error code otherwise.
168 EXPORT_C TInt RMMFVideoPlaySubtitleSupportCustomCommands::GetCrpParameters(TInt aWindowId, TWsGraphicId& aId, TRect& aCrpRect)
170 TPckgBuf<TInt> windowIdPckg(aWindowId);
171 TPckgBuf<TCrpParameters> parameterPckg;
173 TInt err = iController.CustomCommandSync(iDestinationPckg,
174 EMMFSubtitleSupportGetCrpParameter,
181 aId = parameterPckg().iId;
182 aCrpRect = parameterPckg().iCrpRect;
189 * Gets the current subtitle language
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.
195 EXPORT_C TInt RMMFVideoPlaySubtitleSupportCustomCommands::GetSubtitleLanguage(TLanguage& aLanguage)
197 TPckgBuf<TLanguage> languagePckg;
198 TInt err = iController.CustomCommandSync(iDestinationPckg,
199 EMMFSubtitleSupportGetLanguage,
206 aLanguage = languagePckg();
213 * Gets a list of all available languages.
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.
220 EXPORT_C void RMMFVideoPlaySubtitleSupportCustomCommands::GetSupportedSubtitleLanguagesL(RArray<TLanguage>& aSubtitleLanguages)
222 aSubtitleLanguages.Reset();
224 TPckgBuf<TInt> countPckg;
225 User::LeaveIfError(iController.CustomCommandSync(iDestinationPckg,
226 EMMFSubtitleSupportGetLanguageSupportCount,
231 TInt count = countPckg();
235 HBufC8* buf = HBufC8::NewLC(count * sizeof(TLanguage));
236 TPtr8 ptr = buf->Des();
238 User::LeaveIfError(iController.CustomCommandSync(iDestinationPckg,
239 EMMFSubtitleSupportGetLanguageSupportData,
244 TPckgBuf<TLanguage> langPckg;
245 RDesReadStream stream(ptr);
246 CleanupClosePushL(stream);
248 for (TInt i = 0; i < count; i++)
250 stream.ReadL(langPckg);
251 aSubtitleLanguages.AppendL(langPckg());
254 CleanupStack::PopAndDestroy(2, buf); //stream, buf
259 * Sets the current subtitle language
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.
265 EXPORT_C TInt RMMFVideoPlaySubtitleSupportCustomCommands::SetSubtitleLanguage(TLanguage aSubtitleLanguage)
267 TPckgBuf<TLanguage> languagePckg(aSubtitleLanguage);
269 return iController.CustomCommandSync(iDestinationPckg,
270 EMMFSubtitleSupportSetLanguage,
276 * Creates a new custom command parser capable of handling subtitle support commands.
278 * @param aImplementor A reference to the controller plugin that owns this new
281 * @return A pointer to the object created.
283 EXPORT_C CMMFVideoPlaySubtitleSupportCustomCommandParser* CMMFVideoPlaySubtitleSupportCustomCommandParser::NewL(
284 MMMFVideoPlaySubtitleSupportCustomCommandImplementor& aImplementor)
286 return new(ELeave) CMMFVideoPlaySubtitleSupportCustomCommandParser(aImplementor);
289 CMMFVideoPlaySubtitleSupportCustomCommandParser::CMMFVideoPlaySubtitleSupportCustomCommandParser(MMMFVideoPlaySubtitleSupportCustomCommandImplementor& aImplementor) :
290 CMMFCustomCommandParserBase(KUidInterfaceMMFVideoPlaySubtitleSupport),
291 iImplementor(aImplementor)
298 EXPORT_C CMMFVideoPlaySubtitleSupportCustomCommandParser::~CMMFVideoPlaySubtitleSupportCustomCommandParser()
300 iAvailableLanguages.Close();
304 * Handles a request from the client. Called by the controller framework.
306 * @param aMessage The message to be handled.
308 void CMMFVideoPlaySubtitleSupportCustomCommandParser::HandleRequest(TMMFMessage& aMessage)
310 if (aMessage.Destination().InterfaceId() == KUidInterfaceMMFVideoPlaySubtitleSupport)
312 TRAPD(error, DoHandleRequestL(aMessage));
313 aMessage.Complete(error);
317 aMessage.Complete(KErrNotSupported);
321 void CMMFVideoPlaySubtitleSupportCustomCommandParser::DoHandleRequestL(TMMFMessage& aMessage)
323 switch (aMessage.Function())
325 case EMMFSubtitleSupportAvailable:
326 DoGetSubtitlesAvailableL(aMessage);
328 case EMMFSubtitleSupportEnable:
329 DoEnableSubtitlesL(aMessage);
331 case EMMFSubtitleSupportDisable:
332 DoDisableSubtitlesL(aMessage);
334 case EMMFSubtitleSupportGetLanguageSupportCount:
335 DoGetSupportedLanguagesCountL(aMessage);
337 case EMMFSubtitleSupportGetLanguageSupportData:
338 DoGetSupportedLanguagesDataL(aMessage);
340 case EMMFSubtitleSupportGetLanguage:
341 DoGetSubtitleLanguageL(aMessage);
343 case EMMFSubtitleSupportSetLanguage:
344 DoSetSubtitleLanguageL(aMessage);
346 case EMMFSubtitleSupportUpdateSubtitleConfig:
347 DoUpdateSubtitleConfigL(aMessage);
349 case EMMFSubtitleSupportAddSubtitleConfig:
350 DoAddSubtitleConfigL(aMessage);
352 case EMMFSubtitleSupportRemoveSubtitleConfig:
353 DoRemoveSubtitleConfigL(aMessage);
355 case EMMFSubtitleSupportGetCrpParameter:
356 DoGetCrpParametersL(aMessage);
359 User::Leave(KErrNotSupported);
364 void CMMFVideoPlaySubtitleSupportCustomCommandParser::DoGetSubtitlesAvailableL(TMMFMessage& aMessage)
367 iImplementor.MvpsusGetSubtitlesAvailableL(avail);
368 TPckgBuf<TBool> availPckg(avail);
369 aMessage.WriteDataToClientL(availPckg);
372 void CMMFVideoPlaySubtitleSupportCustomCommandParser::DoUpdateSubtitleConfigL(TMMFMessage& aMessage)
374 TPckgBuf<TMMFSubtitleWindowConfig> configPckg;
375 aMessage.ReadData1FromClientL(configPckg);
376 iImplementor.MvpsusUpdateSubtitleConfigL(configPckg());
379 void CMMFVideoPlaySubtitleSupportCustomCommandParser::DoAddSubtitleConfigL(TMMFMessage& aMessage)
381 TPckgBuf<TMMFSubtitleWindowConfig> configPckg;
382 aMessage.ReadData1FromClientL(configPckg);
383 iImplementor.MvpsusAddSubtitleConfigL(configPckg());
386 void CMMFVideoPlaySubtitleSupportCustomCommandParser::DoRemoveSubtitleConfigL(TMMFMessage& aMessage)
388 TPckgBuf<TInt> windowPckg;
389 aMessage.ReadData1FromClientL(windowPckg);
390 iImplementor.MvpsusRemoveSubtitleConfigL(windowPckg());
393 void CMMFVideoPlaySubtitleSupportCustomCommandParser::DoDisableSubtitlesL(TMMFMessage& /*aMessage*/)
395 iImplementor.MvpsusDisableSubtitlesL();
398 void CMMFVideoPlaySubtitleSupportCustomCommandParser::DoEnableSubtitlesL(TMMFMessage& /*aMessage*/)
400 iImplementor.MvpsusEnableSubtitlesL();
403 void CMMFVideoPlaySubtitleSupportCustomCommandParser::DoGetSupportedLanguagesDataL(TMMFMessage& aMessage)
405 HBufC8* buf = HBufC8::NewLC(iAvailableLanguages.Count() * sizeof(TLanguage));
406 TPtr8 ptr = buf->Des();
407 RDesWriteStream stream(ptr);
408 CleanupClosePushL(stream);
410 for (TInt i = 0; i < iAvailableLanguages.Count(); i++)
412 TPckgBuf<TLanguage> langPckg(iAvailableLanguages[i]);
413 stream.WriteL(langPckg);
417 aMessage.WriteDataToClientL(ptr);
418 CleanupStack::PopAndDestroy(2, buf); // stream, buf
421 void CMMFVideoPlaySubtitleSupportCustomCommandParser::DoGetSupportedLanguagesCountL(TMMFMessage& aMessage)
423 iAvailableLanguages.Reset();
424 iImplementor.MvpsusGetSupportedSubtitleLanguagesL(iAvailableLanguages);
426 TPckgBuf<TInt> countPckg(iAvailableLanguages.Count());
427 aMessage.WriteDataToClientL(countPckg);
430 void CMMFVideoPlaySubtitleSupportCustomCommandParser::DoGetSubtitleLanguageL(TMMFMessage& aMessage)
433 iImplementor.MvpsusGetSubtitleLanguageL(lang);
434 TPckgBuf<TLanguage> langPckg(lang);
435 aMessage.WriteDataToClientL(langPckg);
438 void CMMFVideoPlaySubtitleSupportCustomCommandParser::DoSetSubtitleLanguageL(TMMFMessage& aMessage)
440 TPckgBuf<TLanguage> langPckg;
441 aMessage.ReadData1FromClientL(langPckg);
442 iImplementor.MvpsusSetSubtitleLanguageL(langPckg());
445 void CMMFVideoPlaySubtitleSupportCustomCommandParser::DoGetCrpParametersL(TMMFMessage& aMessage)
447 TCrpParameters crpParams;
448 TPckgBuf<TInt> displayPckg;
449 aMessage.ReadData1FromClientL(displayPckg);
450 iImplementor.MvpsusGetCrpParametersL(displayPckg(), crpParams.iId, crpParams.iCrpRect);
452 TPckgBuf<TCrpParameters> paramPckg(crpParams);
453 aMessage.WriteDataToClientL(paramPckg);