sl@0: // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include "mmfvideosubtitlecustomcommands.h" sl@0: sl@0: /** sl@0: @internalComponent sl@0: */ sl@0: enum TMMFSubtitleSupportMessages sl@0: { sl@0: EMMFSubtitleSupportAvailable, sl@0: EMMFSubtitleSupportEnable, sl@0: EMMFSubtitleSupportDisable, sl@0: EMMFSubtitleSupportGetLanguageSupportCount, sl@0: EMMFSubtitleSupportGetLanguageSupportData, sl@0: EMMFSubtitleSupportSetLanguage, sl@0: EMMFSubtitleSupportGetLanguage, sl@0: EMMFSubtitleSupportUpdateSubtitleConfig, sl@0: EMMFSubtitleSupportAddSubtitleConfig, sl@0: EMMFSubtitleSupportRemoveSubtitleConfig, sl@0: EMMFSubtitleSupportGetCrpParameter sl@0: }; sl@0: sl@0: /** sl@0: @internalComponent sl@0: */ sl@0: class TCrpParameters sl@0: { sl@0: public: sl@0: TCrpParameters() : iId(TWsGraphicId::EUninitialized) {} sl@0: sl@0: TWsGraphicId iId; sl@0: TRect iCrpRect; sl@0: }; sl@0: sl@0: /** sl@0: * Constructor. sl@0: * sl@0: * @param aController The client side controller object to be used by this custom sl@0: * command interface. sl@0: */ sl@0: EXPORT_C RMMFVideoPlaySubtitleSupportCustomCommands::RMMFVideoPlaySubtitleSupportCustomCommands(RMMFController& aController) sl@0: : RMMFCustomCommandsBase(aController, KUidInterfaceMMFVideoPlaySubtitleSupport) sl@0: { sl@0: } sl@0: sl@0: /** sl@0: * Adds subtitle configuration data for a window. sl@0: * sl@0: * @param aConfig Subtitle configuration data for a window. sl@0: * @return KErrNone if completed succesfully, otherwise one of the system wide error codes. sl@0: */ sl@0: EXPORT_C TInt RMMFVideoPlaySubtitleSupportCustomCommands::AddSubtitleConfig(const TMMFSubtitleWindowConfig& aConfig) sl@0: { sl@0: TPckgBuf configPckg(aConfig); sl@0: sl@0: return iController.CustomCommandSync(iDestinationPckg, sl@0: EMMFSubtitleSupportAddSubtitleConfig, sl@0: configPckg, sl@0: KNullDesC8); sl@0: } sl@0: sl@0: /** sl@0: * Removes the subtitle configuration data associated with the given window. sl@0: * sl@0: * @param aWindowId Unique identifier of the window associated with the sl@0: * configuration data being removed. sl@0: * @return KErrNone if completed succesfully, otherwise one of the system wide error codes. sl@0: */ sl@0: EXPORT_C TInt RMMFVideoPlaySubtitleSupportCustomCommands::RemoveSubtitleConfig(TInt aWindowId) sl@0: { sl@0: TPckgBuf windowPckg(aWindowId); sl@0: sl@0: return iController.CustomCommandSync(iDestinationPckg, sl@0: EMMFSubtitleSupportRemoveSubtitleConfig, sl@0: windowPckg, sl@0: KNullDesC8); sl@0: } sl@0: sl@0: /** sl@0: * Reconfigures subtitle configuration. sl@0: * sl@0: * @param aConfig Subtitle configuration data for a window. sl@0: * @return KErrNone if completed succesfully, otherwise one of the system wide error codes. sl@0: */ sl@0: EXPORT_C TInt RMMFVideoPlaySubtitleSupportCustomCommands::UpdateSubtitleConfig(const TMMFSubtitleWindowConfig& aConfig) sl@0: { sl@0: TPckgBuf configPckg(aConfig); sl@0: sl@0: return iController.CustomCommandSync(iDestinationPckg, sl@0: EMMFSubtitleSupportUpdateSubtitleConfig, sl@0: configPckg, sl@0: KNullDesC8); sl@0: } sl@0: sl@0: /** sl@0: * Checks if subtitles are available in the current video stream. sl@0: * sl@0: * @param aAvailable When this function returns, this is set to ETrue if the sl@0: * controller supports subtitle extensions and subtitles are available in the sl@0: * current video stream. sl@0: * @return KErrNone if subtitles are supported by the controller; KErrNotSupported sl@0: * if the controller does not support subtitles; otherwise other system error code. sl@0: */ sl@0: EXPORT_C TInt RMMFVideoPlaySubtitleSupportCustomCommands::GetSubtitlesAvailable(TBool& aAvailable) sl@0: { sl@0: TPckgBuf avail; sl@0: sl@0: TInt err = iController.CustomCommandSync(iDestinationPckg, sl@0: EMMFSubtitleSupportAvailable, sl@0: KNullDesC8, sl@0: KNullDesC8, sl@0: avail); sl@0: sl@0: aAvailable = (KErrNone == err) && avail(); sl@0: return err; sl@0: } sl@0: sl@0: /** sl@0: * Disables subtitles during video playback. sl@0: * sl@0: * @return KErrNone if completed succesfully, otherwise one of the system wide error codes. sl@0: */ sl@0: EXPORT_C TInt RMMFVideoPlaySubtitleSupportCustomCommands::DisableSubtitles() sl@0: { sl@0: return iController.CustomCommandSync(iDestinationPckg, sl@0: EMMFSubtitleSupportDisable, sl@0: KNullDesC8, sl@0: KNullDesC8); sl@0: } sl@0: sl@0: /** sl@0: * Enables subtitles during video playback. sl@0: * sl@0: * @return KErrNone if subtitles are supported; KErrNotSupported if sl@0: * controller does not support subtitles; KErrNotFound if subtitle data sl@0: * not found; otherwise other system error code. sl@0: */ sl@0: EXPORT_C TInt RMMFVideoPlaySubtitleSupportCustomCommands::EnableSubtitles() sl@0: { sl@0: return iController.CustomCommandSync(iDestinationPckg, sl@0: EMMFSubtitleSupportEnable, sl@0: KNullDesC8, sl@0: KNullDesC8); sl@0: } sl@0: sl@0: /** sl@0: * Gets the CRP parameters associated with a display sl@0: * sl@0: * @param aWindowId The window id used in the query. sl@0: * @param aId Return the CRP id associated with the given display id sl@0: * @param aCrpRect Return the subtitle region for drawing the CRP sl@0: * sl@0: * @return KErrNone on success; system wide error code otherwise. sl@0: */ sl@0: EXPORT_C TInt RMMFVideoPlaySubtitleSupportCustomCommands::GetCrpParameters(TInt aWindowId, TWsGraphicId& aId, TRect& aCrpRect) sl@0: { sl@0: TPckgBuf windowIdPckg(aWindowId); sl@0: TPckgBuf parameterPckg; sl@0: sl@0: TInt err = iController.CustomCommandSync(iDestinationPckg, sl@0: EMMFSubtitleSupportGetCrpParameter, sl@0: windowIdPckg, sl@0: KNullDesC8, sl@0: parameterPckg); sl@0: sl@0: if (KErrNone == err) sl@0: { sl@0: aId = parameterPckg().iId; sl@0: aCrpRect = parameterPckg().iCrpRect; sl@0: } sl@0: sl@0: return err; sl@0: } sl@0: sl@0: /** sl@0: * Gets the current subtitle language sl@0: * sl@0: * @param aLanguage On return, set the the current language. sl@0: * @return KErrNone on success. KErrNotSupported when the enabled subtitle does not sl@0: * contain language information. Otherwise system wide error code. sl@0: */ sl@0: EXPORT_C TInt RMMFVideoPlaySubtitleSupportCustomCommands::GetSubtitleLanguage(TLanguage& aLanguage) sl@0: { sl@0: TPckgBuf languagePckg; sl@0: TInt err = iController.CustomCommandSync(iDestinationPckg, sl@0: EMMFSubtitleSupportGetLanguage, sl@0: KNullDesC8, sl@0: KNullDesC8, sl@0: languagePckg); sl@0: sl@0: if (KErrNone == err) sl@0: { sl@0: aLanguage = languagePckg(); sl@0: } sl@0: sl@0: return err; sl@0: } sl@0: sl@0: /** sl@0: * Gets a list of all available languages. sl@0: * sl@0: * @param aAvailable Array of available languages sl@0: * @leave KErrNotSupported If the current controller does not support subtitles. sl@0: * @leave KErrNotFound If the controller cannot find subtitle data. sl@0: * @leave Otherwise leaves with any of the system wide error codes. sl@0: */ sl@0: EXPORT_C void RMMFVideoPlaySubtitleSupportCustomCommands::GetSupportedSubtitleLanguagesL(RArray& aSubtitleLanguages) sl@0: { sl@0: aSubtitleLanguages.Reset(); sl@0: sl@0: TPckgBuf countPckg; sl@0: User::LeaveIfError(iController.CustomCommandSync(iDestinationPckg, sl@0: EMMFSubtitleSupportGetLanguageSupportCount, sl@0: KNullDesC8, sl@0: KNullDesC8, sl@0: countPckg)); sl@0: sl@0: TInt count = countPckg(); sl@0: sl@0: if (count > 0) sl@0: { sl@0: HBufC8* buf = HBufC8::NewLC(count * sizeof(TLanguage)); sl@0: TPtr8 ptr = buf->Des(); sl@0: sl@0: User::LeaveIfError(iController.CustomCommandSync(iDestinationPckg, sl@0: EMMFSubtitleSupportGetLanguageSupportData, sl@0: KNullDesC8, sl@0: KNullDesC8, sl@0: ptr)); sl@0: sl@0: TPckgBuf langPckg; sl@0: RDesReadStream stream(ptr); sl@0: CleanupClosePushL(stream); sl@0: sl@0: for (TInt i = 0; i < count; i++) sl@0: { sl@0: stream.ReadL(langPckg); sl@0: aSubtitleLanguages.AppendL(langPckg()); sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(2, buf); //stream, buf sl@0: } sl@0: } sl@0: sl@0: /** sl@0: * Sets the current subtitle language sl@0: * sl@0: * @param aSubtitleLanguage Language to be used for subtitle stream. sl@0: * @return KErrNone on success. KErrNotSupported when the enabled subtitle sl@0: * does not contain language information. Otherwise system wide error code. sl@0: */ sl@0: EXPORT_C TInt RMMFVideoPlaySubtitleSupportCustomCommands::SetSubtitleLanguage(TLanguage aSubtitleLanguage) sl@0: { sl@0: TPckgBuf languagePckg(aSubtitleLanguage); sl@0: sl@0: return iController.CustomCommandSync(iDestinationPckg, sl@0: EMMFSubtitleSupportSetLanguage, sl@0: languagePckg, sl@0: KNullDesC8); sl@0: } sl@0: sl@0: /** sl@0: * Creates a new custom command parser capable of handling subtitle support commands. sl@0: * sl@0: * @param aImplementor A reference to the controller plugin that owns this new sl@0: * object. sl@0: * sl@0: * @return A pointer to the object created. sl@0: */ sl@0: EXPORT_C CMMFVideoPlaySubtitleSupportCustomCommandParser* CMMFVideoPlaySubtitleSupportCustomCommandParser::NewL( sl@0: MMMFVideoPlaySubtitleSupportCustomCommandImplementor& aImplementor) sl@0: { sl@0: return new(ELeave) CMMFVideoPlaySubtitleSupportCustomCommandParser(aImplementor); sl@0: } sl@0: sl@0: CMMFVideoPlaySubtitleSupportCustomCommandParser::CMMFVideoPlaySubtitleSupportCustomCommandParser(MMMFVideoPlaySubtitleSupportCustomCommandImplementor& aImplementor) : sl@0: CMMFCustomCommandParserBase(KUidInterfaceMMFVideoPlaySubtitleSupport), sl@0: iImplementor(aImplementor) sl@0: { sl@0: } sl@0: sl@0: /** sl@0: * Destructor. sl@0: */ sl@0: EXPORT_C CMMFVideoPlaySubtitleSupportCustomCommandParser::~CMMFVideoPlaySubtitleSupportCustomCommandParser() sl@0: { sl@0: iAvailableLanguages.Close(); sl@0: } sl@0: sl@0: /** sl@0: * Handles a request from the client. Called by the controller framework. sl@0: * sl@0: * @param aMessage The message to be handled. sl@0: */ sl@0: void CMMFVideoPlaySubtitleSupportCustomCommandParser::HandleRequest(TMMFMessage& aMessage) sl@0: { sl@0: if (aMessage.Destination().InterfaceId() == KUidInterfaceMMFVideoPlaySubtitleSupport) sl@0: { sl@0: TRAPD(error, DoHandleRequestL(aMessage)); sl@0: aMessage.Complete(error); sl@0: } sl@0: else sl@0: { sl@0: aMessage.Complete(KErrNotSupported); sl@0: } sl@0: } sl@0: sl@0: void CMMFVideoPlaySubtitleSupportCustomCommandParser::DoHandleRequestL(TMMFMessage& aMessage) sl@0: { sl@0: switch (aMessage.Function()) sl@0: { sl@0: case EMMFSubtitleSupportAvailable: sl@0: DoGetSubtitlesAvailableL(aMessage); sl@0: break; sl@0: case EMMFSubtitleSupportEnable: sl@0: DoEnableSubtitlesL(aMessage); sl@0: break; sl@0: case EMMFSubtitleSupportDisable: sl@0: DoDisableSubtitlesL(aMessage); sl@0: break; sl@0: case EMMFSubtitleSupportGetLanguageSupportCount: sl@0: DoGetSupportedLanguagesCountL(aMessage); sl@0: break; sl@0: case EMMFSubtitleSupportGetLanguageSupportData: sl@0: DoGetSupportedLanguagesDataL(aMessage); sl@0: break; sl@0: case EMMFSubtitleSupportGetLanguage: sl@0: DoGetSubtitleLanguageL(aMessage); sl@0: break; sl@0: case EMMFSubtitleSupportSetLanguage: sl@0: DoSetSubtitleLanguageL(aMessage); sl@0: break; sl@0: case EMMFSubtitleSupportUpdateSubtitleConfig: sl@0: DoUpdateSubtitleConfigL(aMessage); sl@0: break; sl@0: case EMMFSubtitleSupportAddSubtitleConfig: sl@0: DoAddSubtitleConfigL(aMessage); sl@0: break; sl@0: case EMMFSubtitleSupportRemoveSubtitleConfig: sl@0: DoRemoveSubtitleConfigL(aMessage); sl@0: break; sl@0: case EMMFSubtitleSupportGetCrpParameter: sl@0: DoGetCrpParametersL(aMessage); sl@0: break; sl@0: default: sl@0: User::Leave(KErrNotSupported); sl@0: break; sl@0: } sl@0: } sl@0: sl@0: void CMMFVideoPlaySubtitleSupportCustomCommandParser::DoGetSubtitlesAvailableL(TMMFMessage& aMessage) sl@0: { sl@0: TBool avail; sl@0: iImplementor.MvpsusGetSubtitlesAvailableL(avail); sl@0: TPckgBuf availPckg(avail); sl@0: aMessage.WriteDataToClientL(availPckg); sl@0: } sl@0: sl@0: void CMMFVideoPlaySubtitleSupportCustomCommandParser::DoUpdateSubtitleConfigL(TMMFMessage& aMessage) sl@0: { sl@0: TPckgBuf configPckg; sl@0: aMessage.ReadData1FromClientL(configPckg); sl@0: iImplementor.MvpsusUpdateSubtitleConfigL(configPckg()); sl@0: } sl@0: sl@0: void CMMFVideoPlaySubtitleSupportCustomCommandParser::DoAddSubtitleConfigL(TMMFMessage& aMessage) sl@0: { sl@0: TPckgBuf configPckg; sl@0: aMessage.ReadData1FromClientL(configPckg); sl@0: iImplementor.MvpsusAddSubtitleConfigL(configPckg()); sl@0: } sl@0: sl@0: void CMMFVideoPlaySubtitleSupportCustomCommandParser::DoRemoveSubtitleConfigL(TMMFMessage& aMessage) sl@0: { sl@0: TPckgBuf windowPckg; sl@0: aMessage.ReadData1FromClientL(windowPckg); sl@0: iImplementor.MvpsusRemoveSubtitleConfigL(windowPckg()); sl@0: } sl@0: sl@0: void CMMFVideoPlaySubtitleSupportCustomCommandParser::DoDisableSubtitlesL(TMMFMessage& /*aMessage*/) sl@0: { sl@0: iImplementor.MvpsusDisableSubtitlesL(); sl@0: } sl@0: sl@0: void CMMFVideoPlaySubtitleSupportCustomCommandParser::DoEnableSubtitlesL(TMMFMessage& /*aMessage*/) sl@0: { sl@0: iImplementor.MvpsusEnableSubtitlesL(); sl@0: } sl@0: sl@0: void CMMFVideoPlaySubtitleSupportCustomCommandParser::DoGetSupportedLanguagesDataL(TMMFMessage& aMessage) sl@0: { sl@0: HBufC8* buf = HBufC8::NewLC(iAvailableLanguages.Count() * sizeof(TLanguage)); sl@0: TPtr8 ptr = buf->Des(); sl@0: RDesWriteStream stream(ptr); sl@0: CleanupClosePushL(stream); sl@0: sl@0: for (TInt i = 0; i < iAvailableLanguages.Count(); i++) sl@0: { sl@0: TPckgBuf langPckg(iAvailableLanguages[i]); sl@0: stream.WriteL(langPckg); sl@0: } sl@0: sl@0: stream.CommitL(); sl@0: aMessage.WriteDataToClientL(ptr); sl@0: CleanupStack::PopAndDestroy(2, buf); // stream, buf sl@0: } sl@0: sl@0: void CMMFVideoPlaySubtitleSupportCustomCommandParser::DoGetSupportedLanguagesCountL(TMMFMessage& aMessage) sl@0: { sl@0: iAvailableLanguages.Reset(); sl@0: iImplementor.MvpsusGetSupportedSubtitleLanguagesL(iAvailableLanguages); sl@0: sl@0: TPckgBuf countPckg(iAvailableLanguages.Count()); sl@0: aMessage.WriteDataToClientL(countPckg); sl@0: } sl@0: sl@0: void CMMFVideoPlaySubtitleSupportCustomCommandParser::DoGetSubtitleLanguageL(TMMFMessage& aMessage) sl@0: { sl@0: TLanguage lang; sl@0: iImplementor.MvpsusGetSubtitleLanguageL(lang); sl@0: TPckgBuf langPckg(lang); sl@0: aMessage.WriteDataToClientL(langPckg); sl@0: } sl@0: sl@0: void CMMFVideoPlaySubtitleSupportCustomCommandParser::DoSetSubtitleLanguageL(TMMFMessage& aMessage) sl@0: { sl@0: TPckgBuf langPckg; sl@0: aMessage.ReadData1FromClientL(langPckg); sl@0: iImplementor.MvpsusSetSubtitleLanguageL(langPckg()); sl@0: } sl@0: sl@0: void CMMFVideoPlaySubtitleSupportCustomCommandParser::DoGetCrpParametersL(TMMFMessage& aMessage) sl@0: { sl@0: TCrpParameters crpParams; sl@0: TPckgBuf displayPckg; sl@0: aMessage.ReadData1FromClientL(displayPckg); sl@0: iImplementor.MvpsusGetCrpParametersL(displayPckg(), crpParams.iId, crpParams.iCrpRect); sl@0: sl@0: TPckgBuf paramPckg(crpParams); sl@0: aMessage.WriteDataToClientL(paramPckg); sl@0: }