javauis/mmapi_qt/baseline/src/cmmammfplayerfactory.cpp
changeset 23 98ccebc37403
child 26 dc7c549001d5
equal deleted inserted replaced
21:2a9601315dfc 23:98ccebc37403
       
     1 /*
       
     2 * Copyright (c) 2002-2007 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  This class is used for creating MMF-based players.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 //  INCLUDE FILES
       
    20 #include <badesca.h>
       
    21 #include <logger.h>
       
    22 
       
    23 #ifndef RD_JAVA_OMA_DRM_V2
       
    24 #include <DRMCommon.h>
       
    25 #endif // RD_JAVA_OMA_DRM_V2
       
    26 
       
    27 #include "cmmammfplayerfactory.h"
       
    28 #include "cmmammfresolver.h"
       
    29 
       
    30 // CONSTANTS
       
    31 // Granularity used to create initial arrays.
       
    32 const TInt KGranularity = 8;
       
    33 _LIT(KContentTypePacketSrcNotIncluded, "application/x-ext-packetsrc");
       
    34 
       
    35 EXPORT_C CMMAMMFPlayerFactory::CMMAMMFPlayerFactory()
       
    36 {
       
    37 }
       
    38 
       
    39 EXPORT_C CMMAMMFPlayerFactory::~CMMAMMFPlayerFactory()
       
    40 {
       
    41 }
       
    42 
       
    43 CMMAPlayer* CMMAMMFPlayerFactory::CreatePlayerL(const TDesC& aContentType)
       
    44 {
       
    45     return CreatePlayerL(aContentType, NULL);
       
    46 }
       
    47 
       
    48 CMMAPlayer* CMMAMMFPlayerFactory::CreatePlayerL(const TDesC& aContentType,
       
    49         const TDesC* aFileName)
       
    50 {
       
    51     LOG1( EJavaMMAPI, EInfo, "MMA::CMMAMMFPlayerFactory::CreatePlayerL content type = %S",
       
    52               aContentType.Ptr());
       
    53     CMMFFormatSelectionParameters* fSelect =
       
    54         CMMFFormatSelectionParameters::NewLC();
       
    55 
       
    56     // MMF needs 8bit data
       
    57     HBufC8* contentType = HBufC8::NewLC(aContentType.Length());
       
    58     contentType->Des().Copy(aContentType);
       
    59 
       
    60     // Match to mime/content type
       
    61     fSelect->SetMatchToMimeTypeL(*contentType);
       
    62 
       
    63     CMMAPlayer* player = CreatePlayerL(fSelect, aFileName);
       
    64 
       
    65     CleanupStack::PopAndDestroy(contentType);
       
    66     CleanupStack::PopAndDestroy(fSelect);
       
    67     LOG( EJavaMMAPI, EInfo, "MMA::CMMAMMFPlayerFactory::CreatePlayerL content type ok");
       
    68     return player;
       
    69 }
       
    70 
       
    71 CMMAPlayer* CMMAMMFPlayerFactory::CreatePlayerL(const TDesC& aProtocol,
       
    72         const TDesC& aMiddlePart,
       
    73         const TDesC&)
       
    74 {
       
    75     LOG1( EJavaMMAPI, EInfo, "MMA::CMMAMMFPlayerFactory::CreatePlayerL aMiddlePart = %S",
       
    76               aMiddlePart.Ptr());
       
    77     CMMFFormatSelectionParameters* fSelect =
       
    78         CMMFFormatSelectionParameters::NewLC();
       
    79 
       
    80     // Match to file name, using only middle part of the locator
       
    81     fSelect->SetMatchToFileNameL(aMiddlePart);
       
    82 
       
    83     CMMAPlayer* player = NULL;
       
    84     if (aProtocol == KMMAFileProtocol)
       
    85     {
       
    86         LOG( EJavaMMAPI, EInfo, "MMA:CMMAMMFPlayerFactory::CreatePlayerL creating file player");
       
    87         player = CreatePlayerL(fSelect, &aMiddlePart);
       
    88 
       
    89 #ifndef RD_JAVA_OMA_DRM_V2
       
    90         // if opening is failed, it might be DRM file, trying it
       
    91         if (!player)
       
    92         {
       
    93             player = TryOpenDRMFileL(aMiddlePart);
       
    94         }
       
    95 #endif // RD_JAVA_OMA_DRM_V2
       
    96 
       
    97     }
       
    98     else
       
    99     {
       
   100         player = CreatePlayerL(fSelect, NULL);
       
   101     }
       
   102 
       
   103     CleanupStack::PopAndDestroy(fSelect);
       
   104     LOG( EJavaMMAPI, EInfo, "MMA::CMMAMMFPlayerFactory::CreatePlayerL aMiddlePart ok");
       
   105     return player;
       
   106 }
       
   107 
       
   108 #ifndef RD_JAVA_OMA_DRM_V2
       
   109 CMMAPlayer* CMMAMMFPlayerFactory::TryOpenDRMFileL(const TDesC& aFileName)
       
   110 {
       
   111     // we are most likely going to play this file
       
   112     ContentAccess::TIntent intent = ContentAccess::EPlay;
       
   113 
       
   114     CContent* contentObj = CContent::NewL(aFileName);
       
   115     CleanupStack::PushL(contentObj);
       
   116     CData* dataObj = contentObj->OpenContentL(intent);
       
   117     CleanupStack::PushL(dataObj);
       
   118     User::LeaveIfError(dataObj->EvaluateIntent(intent));
       
   119     TBuf8<KMaxName> mimeType;
       
   120     CMMAPlayer* player = NULL;
       
   121     if (dataObj->GetMimeTypeL(mimeType))
       
   122     {
       
   123         // we use 16bit mimeType
       
   124         HBufC* mimeTypeBuf = HBufC::NewLC(mimeType.Length());
       
   125         mimeTypeBuf->Des().Copy(mimeType);
       
   126         player = CreatePlayerL(*mimeTypeBuf, &aFileName);
       
   127         CleanupStack::PopAndDestroy(mimeTypeBuf);
       
   128     }
       
   129     CleanupStack::PopAndDestroy(2); //dataObj, contentObj
       
   130     return player;
       
   131 }
       
   132 #endif // RD_JAVA_OMA_DRM_V2
       
   133 
       
   134 CMMAPlayer* CMMAMMFPlayerFactory::CreatePlayerL(const TDesC8& aHeaderData)
       
   135 {
       
   136     LOG( EJavaMMAPI, EInfo, "MMA::CMMAMMFPlayerFactory::CreatePlayerL header data +");
       
   137     CMMFFormatSelectionParameters* fSelect =
       
   138         CMMFFormatSelectionParameters::NewLC();
       
   139 
       
   140     // Match to header data
       
   141     fSelect->SetMatchToHeaderDataL(aHeaderData);
       
   142 
       
   143     CMMAPlayer* player = CreatePlayerL(fSelect);
       
   144 
       
   145     CleanupStack::PopAndDestroy(fSelect);
       
   146     LOG( EJavaMMAPI, EInfo, "MMA::CMMAMMFPlayerFactory::CreatePlayerL header data -");
       
   147     return player;
       
   148 }
       
   149 
       
   150 void CMMAMMFPlayerFactory::GetSupportedContentTypesL(const TDesC& aProtocol,
       
   151         CDesC16Array& aMimeTypeArray)
       
   152 {
       
   153     // check that this is supported protocol
       
   154     if (!IsSupportedProtocolL(aProtocol))
       
   155     {
       
   156         return;
       
   157     }
       
   158 
       
   159     CMMFFormatSelectionParameters* fSelect =
       
   160         CMMFFormatSelectionParameters::NewLC();
       
   161 
       
   162     CMMAMMFResolver* cSelect =
       
   163         CMMAMMFResolver::NewLC();
       
   164 
       
   165     PreparePluginSelectionParametersL(cSelect, fSelect);
       
   166 
       
   167     // Set the media ids
       
   168     RArray<TUid> mediaIds;
       
   169     CleanupClosePushL(mediaIds);
       
   170     MediaIdsL(mediaIds);
       
   171     cSelect->SelectionParameters()->SetMediaIdsL(mediaIds, MediaIdMatchType());
       
   172 
       
   173     cSelect->GetSupportedContentTypesL(aMimeTypeArray);
       
   174 
       
   175     // Content type application/x-ext-packetsrc must not be supported,
       
   176     // thus it is removed from the list of supported content types
       
   177     TInt position(0);
       
   178     TInt err = aMimeTypeArray.Find(KContentTypePacketSrcNotIncluded, position);
       
   179     if (err == KErrNone)
       
   180     {
       
   181         aMimeTypeArray.Delete(position);
       
   182         aMimeTypeArray.Compress();
       
   183     }
       
   184 
       
   185     CleanupStack::PopAndDestroy(); // mediaIds
       
   186     CleanupStack::PopAndDestroy(cSelect);
       
   187     CleanupStack::PopAndDestroy(fSelect);
       
   188 }
       
   189 
       
   190 EXPORT_C CMMAPlayer* CMMAMMFPlayerFactory::CreatePlayerL(CMMFFormatSelectionParameters* aFormatSelect,
       
   191         const TDesC* aFileName)
       
   192 {
       
   193     CMMAMMFResolver* cSelect =
       
   194         CMMAMMFResolver::NewLC();
       
   195     cSelect->SetFileNameL(aFileName);
       
   196 
       
   197     PreparePluginSelectionParametersL(cSelect,
       
   198                                       aFormatSelect);
       
   199 
       
   200     // Set the media ids
       
   201     RArray<TUid> mediaIds;
       
   202     CleanupClosePushL(mediaIds);
       
   203     MediaIdsL(mediaIds);
       
   204     cSelect->SelectionParameters()->SetMediaIdsL(
       
   205         mediaIds, MediaIdMatchType());
       
   206 
       
   207     cSelect->ListImplementationsL();
       
   208     CMMAPlayer* player = NULL;
       
   209 
       
   210     // check that did we get any hits
       
   211     if (cSelect->Implementations()->Count() > 0)
       
   212     {
       
   213         // Call actual factory to create player
       
   214         player = CreatePlayerL(cSelect);
       
   215     }
       
   216 
       
   217     CleanupStack::PopAndDestroy(); // mediaIds
       
   218     CleanupStack::PopAndDestroy(cSelect);
       
   219     return player;
       
   220 }
       
   221 
       
   222 void CMMAMMFPlayerFactory::GetSupportedProtocolsL(const TDesC& aContentType,
       
   223         CDesC16Array& aProtocolArray)
       
   224 {
       
   225     // Check that this is supported content type
       
   226     if (!IsSupportedContentTypeL(aContentType))
       
   227     {
       
   228         return;
       
   229     }
       
   230     aProtocolArray.AppendL(KMMAHttpProtocol);
       
   231     aProtocolArray.AppendL(KMMAHttpsProtocol);
       
   232     aProtocolArray.AppendL(KMMAFileProtocol);
       
   233 }
       
   234 
       
   235 TBool CMMAMMFPlayerFactory::IsSupportedProtocolL(const TDesC& aProtocol)
       
   236 {
       
   237     // With null desc we are getting all
       
   238     if (aProtocol == KNullDesC)
       
   239     {
       
   240         return ETrue;
       
   241     }
       
   242     CDesC16ArraySeg* protocols = new(ELeave) CDesC16ArraySeg(KGranularity);
       
   243     CleanupStack::PushL(protocols);
       
   244     GetSupportedProtocolsL(KNullDesC, *protocols);
       
   245     TInt pos = KErrNotFound;
       
   246     // Find returns 0 if there contentType is found
       
   247     TBool retValue = (protocols->Find(aProtocol, pos) == 0);
       
   248     CleanupStack::PopAndDestroy(protocols);
       
   249     return retValue;
       
   250 }
       
   251 
       
   252 TBool CMMAMMFPlayerFactory::IsSupportedContentTypeL(const TDesC& aContentType)
       
   253 {
       
   254     // With null desc we are getting all
       
   255     if (aContentType == KNullDesC)
       
   256     {
       
   257         return ETrue;
       
   258     }
       
   259 
       
   260     // Content type application/x-ext-packetsrc
       
   261     // must not be supported at the moment.
       
   262     if (aContentType == KContentTypePacketSrcNotIncluded)
       
   263     {
       
   264         return EFalse;
       
   265     }
       
   266 
       
   267     CDesC16ArraySeg* contentTypes = new(ELeave) CDesC16ArraySeg(KGranularity);
       
   268     CleanupStack::PushL(contentTypes);
       
   269     GetSupportedContentTypesL(KNullDesC, *contentTypes);
       
   270     TInt pos = KErrNotFound;
       
   271     // Find returns 0 if there contentType is found
       
   272     TBool retValue = (contentTypes->Find(aContentType, pos) == 0);
       
   273     CleanupStack::PopAndDestroy(contentTypes);
       
   274     return retValue;
       
   275 }
       
   276 
       
   277 EXPORT_C void CMMAMMFPlayerFactory::PreparePluginSelectionParametersL(
       
   278     CMMAMMFResolver* aResolver,
       
   279     CMMFFormatSelectionParameters* aFormatSelection)
       
   280 {
       
   281     // Play type is default
       
   282     aResolver->SetRequiredPlayFormatSupportL(*aFormatSelection);
       
   283 }
       
   284 
       
   285 
       
   286 CMMFPluginSelectionParameters::TMediaIdMatchType
       
   287 CMMAMMFPlayerFactory::MediaIdMatchType()
       
   288 {
       
   289     // We are now getting only Audio Controllers
       
   290     return CMMFPluginSelectionParameters::EAllowOnlySuppliedMediaIds;
       
   291 }
       
   292 //  END OF FILE