javauis/mmapi_qt/baseline/src.emc/cmmaemcplayerfactory.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 EMC-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 "cmmaemcplayerfactory.h"
       
    28 #include "cmmaemcresolver.h"
       
    29 #include "MimeTypes.h"
       
    30 
       
    31 // CONSTANTS
       
    32 // Granularity used to create initial arrays.
       
    33 const TInt KGranularity = 8;
       
    34 _LIT(KContentTypePacketSrcNotIncluded, "application/x-ext-packetsrc");
       
    35 
       
    36 CMMAEMCPlayerFactory::CMMAEMCPlayerFactory()
       
    37 {
       
    38 }
       
    39 
       
    40 CMMAEMCPlayerFactory::~CMMAEMCPlayerFactory()
       
    41 {
       
    42 }
       
    43 
       
    44 CMMAPlayer* CMMAEMCPlayerFactory::CreatePlayerL(const TDesC& aContentType)
       
    45 {
       
    46     return CreatePlayerL(aContentType, NULL);
       
    47 }
       
    48 
       
    49 CMMAPlayer* CMMAEMCPlayerFactory::CreatePlayerL(const TDesC& /*aContentType*/,
       
    50         const TDesC* /*aFileName*/)
       
    51 {
       
    52     return (CMMAPlayer*)NULL;
       
    53 }
       
    54 
       
    55 CMMAPlayer* CMMAEMCPlayerFactory::CreatePlayerL(const TDesC& aProtocol,
       
    56         const TDesC& aMiddlePart,
       
    57         const TDesC&)
       
    58 {
       
    59     LOG1( EJavaMMAPI, EInfo, "MMA::CMMAEMCPlayerFactory::CreatePlayerL aMiddlePart = %S",
       
    60               aMiddlePart.Ptr());
       
    61     CMMAEMCResolver* emcresolver =
       
    62         CMMAEMCResolver::NewLC();
       
    63 
       
    64     emcresolver ->SetFileNameL(&aMiddlePart);
       
    65 
       
    66     CMMAPlayer* player = NULL;
       
    67     if (aProtocol == KMMAFileProtocol)
       
    68     {
       
    69 
       
    70         //player = CreatePlayerL( emcresolver, &aMiddlePart );
       
    71 
       
    72 #ifndef RD_JAVA_OMA_DRM_V2
       
    73         // if opening is failed, it might be DRM file, trying it
       
    74         if (!player)
       
    75         {
       
    76             player = TryOpenDRMFileL(aMiddlePart);
       
    77         }
       
    78 #endif // RD_JAVA_OMA_DRM_V2
       
    79 
       
    80     }
       
    81     else
       
    82     {
       
    83         player = CreatePlayerL(emcresolver);
       
    84     }
       
    85 
       
    86     CleanupStack::PopAndDestroy(emcresolver);
       
    87     LOG( EJavaMMAPI, EInfo, "MMA::CMMAEMCPlayerFactory::CreatePlayerL aMiddlePart ok");
       
    88     return player;
       
    89 }
       
    90 
       
    91 #ifndef RD_JAVA_OMA_DRM_V2
       
    92 CMMAPlayer* CMMAEMCPlayerFactory::TryOpenDRMFileL(const TDesC& aFileName)
       
    93 {
       
    94     // we are most likely going to play this file
       
    95     ContentAccess::TIntent intent = ContentAccess::EPlay;
       
    96 
       
    97     CContent* contentObj = CContent::NewL(aFileName);
       
    98     CleanupStack::PushL(contentObj);
       
    99     CData* dataObj = contentObj->OpenContentL(intent);
       
   100     CleanupStack::PushL(dataObj);
       
   101     User::LeaveIfError(dataObj->EvaluateIntent(intent));
       
   102     TBuf8<KMaxName> mimeType;
       
   103     CMMAPlayer* player = NULL;
       
   104     if (dataObj->GetMimeTypeL(mimeType))
       
   105     {
       
   106         // we use 16bit mimeType
       
   107         HBufC* mimeTypeBuf = HBufC::NewLC(mimeType.Length());
       
   108         mimeTypeBuf->Des().Copy(mimeType);
       
   109         player = CreatePlayerL(*mimeTypeBuf, &aFileName);
       
   110         CleanupStack::PopAndDestroy(mimeTypeBuf);
       
   111     }
       
   112     CleanupStack::PopAndDestroy(2); //dataObj, contentObj
       
   113     return player;
       
   114 }
       
   115 #endif // RD_JAVA_OMA_DRM_V2
       
   116 
       
   117 CMMAPlayer* CMMAEMCPlayerFactory::CreatePlayerL(const TDesC8& /*aHeaderData*/)
       
   118 {
       
   119     LOG( EJavaMMAPI, EInfo, "MMA::CMMAEMCPlayerFactory::CreatePlayerL header data +");
       
   120 
       
   121     return (CMMAPlayer*)NULL;
       
   122 }
       
   123 
       
   124 void CMMAEMCPlayerFactory::GetSupportedContentTypesL(const TDesC& aProtocol,
       
   125         CDesC16Array& aMimeTypeArray)
       
   126 {
       
   127     //CMMAEMCResolver class should contain the constant array of all supported mimetype defined in EMC api MimeTypes.h
       
   128     if (!IsSupportedProtocolL(aProtocol))
       
   129     {
       
   130         return;
       
   131     }
       
   132     CMMAEMCResolver* emcresolver = CMMAEMCResolver::NewLC();
       
   133     emcresolver->GetSupportedContentTypesL(aMimeTypeArray);
       
   134 
       
   135     CleanupStack::PopAndDestroy(emcresolver);
       
   136 }
       
   137 
       
   138 void CMMAEMCPlayerFactory::GetSupportedProtocolsL(const TDesC& aContentType,
       
   139         CDesC16Array& aProtocolArray)
       
   140 {
       
   141     // Check that this is supported content type
       
   142     if (!IsSupportedContentTypeL(aContentType))
       
   143     {
       
   144         return;
       
   145     }
       
   146     aProtocolArray.AppendL(KMMAHttpProtocol);
       
   147     aProtocolArray.AppendL(KMMAHttpsProtocol);
       
   148 }
       
   149 
       
   150 TBool CMMAEMCPlayerFactory::IsSupportedProtocolL(const TDesC& aProtocol)
       
   151 {
       
   152     // With null desc we are getting all
       
   153     if (aProtocol == KNullDesC)
       
   154     {
       
   155         return ETrue;
       
   156     }
       
   157     CDesC16ArraySeg* protocols = new(ELeave) CDesC16ArraySeg(KGranularity);
       
   158     CleanupStack::PushL(protocols);
       
   159     GetSupportedProtocolsL(KNullDesC, *protocols);
       
   160     TInt pos = KErrNotFound;
       
   161     // Find returns 0 if there contentType is found
       
   162     TBool retValue = (protocols->Find(aProtocol, pos) == 0);
       
   163     CleanupStack::PopAndDestroy(protocols);
       
   164     return retValue;
       
   165 }
       
   166 
       
   167 TBool CMMAEMCPlayerFactory::IsSupportedContentTypeL(const TDesC& aContentType)
       
   168 {
       
   169     // With null desc we are getting all
       
   170     if (aContentType == KNullDesC)
       
   171     {
       
   172         return ETrue;
       
   173     }
       
   174 
       
   175     // Content type application/x-ext-packetsrc
       
   176     // must not be supported at the moment.
       
   177     if (aContentType == KContentTypePacketSrcNotIncluded)
       
   178     {
       
   179         return EFalse;
       
   180     }
       
   181 
       
   182     CDesC16ArraySeg* contentTypes = new(ELeave) CDesC16ArraySeg(KGranularity);
       
   183     CleanupStack::PushL(contentTypes);
       
   184     GetSupportedContentTypesL(KNullDesC, *contentTypes);
       
   185     TInt pos = KErrNotFound;
       
   186     // Find returns 0 if there contentType is found
       
   187     TBool retValue = (contentTypes->Find(aContentType, pos) == 0);
       
   188     CleanupStack::PopAndDestroy(contentTypes);
       
   189     return retValue;
       
   190 }
       
   191 
       
   192 //  END OF FILE