javauis/mmapi_akn/src_drmv2/src/cmmadrmplayerfactory.cpp
branchRCL_3
changeset 14 04becd199f91
child 24 6c158198356e
equal deleted inserted replaced
13:f5050f1da672 14:04becd199f91
       
     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 DRM v2 player.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 //  INCLUDE FILES
       
    20 #include <jdebug.h>
       
    21 
       
    22 #include <DRMCommon.h>
       
    23 #include <DRMHelper.h>
       
    24 #include <caf/stringattributeset.h>
       
    25 
       
    26 #include "cmmadrmplayerfactory.h"
       
    27 #include "cmmadrmaudioplayer.h"
       
    28 #include "cmmadrmvolumecontrol.h"
       
    29 #include "cmmastoptimecontrol.h"
       
    30 #include "cmmadrmmetadatacontrol.h"
       
    31 #include "cmmadrmratecontrol.h"
       
    32 #include "cmmavideoplayer.h"
       
    33 
       
    34 _LIT(KMMAAudio, "audio");
       
    35 // this (get from caf) cannot be recognized is it audio or video
       
    36 _LIT(KMMARMCafMimeType, "application/vnd.rn-realmedia");
       
    37 // drm v2 file suffix
       
    38 _LIT(KMMADRMv2SuffixODF, "odf");
       
    39 
       
    40 // ---------------------------------------------------------------------------
       
    41 // CMMADRMPlayerFactory::NewLC
       
    42 // ---------------------------------------------------------------------------
       
    43 //
       
    44 CMMADRMPlayerFactory* CMMADRMPlayerFactory::NewLC(CMMAVideoPlayerFactory* aVideoPlayerFactory)
       
    45 {
       
    46     CMMADRMPlayerFactory* pFactory =
       
    47         new(ELeave) CMMADRMPlayerFactory(aVideoPlayerFactory);
       
    48     CleanupStack::PushL(pFactory);
       
    49     return pFactory;
       
    50 }
       
    51 
       
    52 // ---------------------------------------------------------------------------
       
    53 // CMMADRMPlayerFactory::CMMADRMPlayerFactory
       
    54 // ---------------------------------------------------------------------------
       
    55 //
       
    56 CMMADRMPlayerFactory::CMMADRMPlayerFactory(CMMAVideoPlayerFactory* aVideoPlayerFactory)
       
    57         :iVideoPlayerFactory(aVideoPlayerFactory)
       
    58 {
       
    59 }
       
    60 
       
    61 // ---------------------------------------------------------------------------
       
    62 // CMMADRMPlayerFactory::~CMMADRMPlayerFactory
       
    63 // ---------------------------------------------------------------------------
       
    64 //
       
    65 CMMADRMPlayerFactory::~CMMADRMPlayerFactory()
       
    66 {
       
    67 }
       
    68 
       
    69 // ---------------------------------------------------------------------------
       
    70 // CMMADRMPlayerFactory::CreatePlayerL
       
    71 // ---------------------------------------------------------------------------
       
    72 //
       
    73 CMMAPlayer* CMMADRMPlayerFactory::CreatePlayerL(const TDesC& /*aContentType*/)
       
    74 {
       
    75     // only file is supported
       
    76     return NULL;
       
    77 }
       
    78 
       
    79 // ---------------------------------------------------------------------------
       
    80 // CMMADRMPlayerFactory::CreatePlayerL
       
    81 // ---------------------------------------------------------------------------
       
    82 //
       
    83 CMMAPlayer* CMMADRMPlayerFactory::CreatePlayerL(
       
    84     const TDesC& aProtocol,
       
    85     const TDesC& aMiddlePart,
       
    86     const TDesC& /*aProperties*/)
       
    87 {
       
    88     DEBUG("MMA::CMMADRMPlayerFactory::CreatePlayerL +");
       
    89     CMMAPlayer* player = NULL;
       
    90     if (aProtocol == KMMAFileProtocol)
       
    91     {
       
    92         // we are most likely going to play this file
       
    93         ContentAccess::TIntent intent = ContentAccess::EPlay;
       
    94 
       
    95         ContentAccess::CContent* contentObj = ContentAccess::CContent::NewL(aMiddlePart);
       
    96         CleanupStack::PushL(contentObj);
       
    97 
       
    98         ContentAccess::CData* dataObj = NULL;
       
    99         TRAPD(openContentErr, dataObj = contentObj->OpenContentL(intent));
       
   100         CleanupStack::PushL(dataObj);
       
   101 
       
   102         DEBUG_INT("MMA::CMMADRMPlayerFactory::CreatePlayerL openContentErr: %d", openContentErr);
       
   103         if (KErrCA_LowerLimit <= openContentErr && openContentErr <= KErrCA_UpperLimit)
       
   104         {
       
   105             // handle error, possible update rights
       
   106             UpdateRightsL(openContentErr, aMiddlePart);
       
   107             User::Leave(openContentErr);
       
   108         }
       
   109         else
       
   110         {
       
   111             User::LeaveIfError(openContentErr);
       
   112         }
       
   113 
       
   114         ContentAccess::RStringAttributeSet stringAttributeSet;
       
   115         CleanupClosePushL(stringAttributeSet);
       
   116         stringAttributeSet.AddL(ContentAccess::EMimeType);
       
   117 
       
   118         User::LeaveIfError(dataObj->GetStringAttributeSet(stringAttributeSet));
       
   119 
       
   120         TBuf<KMaxName> mimeType;
       
   121         TInt err = stringAttributeSet.GetValue(ContentAccess::EMimeType, mimeType);
       
   122         if (err == KErrNone)
       
   123         {
       
   124             DEBUG_STR("MMA::CMMADRMPlayerFactory::CreatePlayerL, no err, mime type = %S", mimeType);
       
   125             // we use 16bit mimeType
       
   126             HBufC* mimeTypeBuf = HBufC::NewLC(mimeType.Length());
       
   127             mimeTypeBuf->Des().Copy(mimeType);
       
   128 
       
   129             if (((mimeTypeBuf->Length() >= KMMAAudio().Length()) &&
       
   130                     (mimeTypeBuf->Left(KMMAAudio().Length()) == KMMAAudio)) ||
       
   131                     ((KErrNone == mimeTypeBuf->Compare(KMMARMCafMimeType)) &&
       
   132                      (aMiddlePart.Right(KMMADRMv2SuffixODF().Length()) ==
       
   133                       KMMADRMv2SuffixODF())))
       
   134             {
       
   135                 // if content-type starts with "audio" or
       
   136                 // if it's KMMARMCafMimeType and file suffix is ODF
       
   137                 // then create audio player
       
   138                 player = CreateAudioPlayerL(*mimeTypeBuf, aMiddlePart);
       
   139             }
       
   140             else
       
   141             {
       
   142                 // otherwise try video player
       
   143                 player = CreateVideoPlayerL(*mimeTypeBuf, aMiddlePart);
       
   144             }
       
   145             CleanupStack::PopAndDestroy(mimeTypeBuf);
       
   146         }
       
   147         else
       
   148         {
       
   149             DEBUG_INT("MMA::CMMADRMPlayerFactory::CreatePlayerL get mime err: %d", err);
       
   150             DEBUG_STR("MMA::CMMADRMPlayerFactory::CreatePlayerL mime type = %S", mimeType);
       
   151             User::Leave(err);
       
   152         }
       
   153         CleanupStack::PopAndDestroy(3); //dataObj, contentObj, stringAttributeSet
       
   154     }
       
   155     DEBUG("MMA::CMMADRMPlayerFactory::CreatePlayerL -");
       
   156     return player;
       
   157 }
       
   158 
       
   159 // ---------------------------------------------------------------------------
       
   160 // CMMADRMPlayerFactory::CreatePlayerL
       
   161 // ---------------------------------------------------------------------------
       
   162 //
       
   163 CMMAPlayer* CMMADRMPlayerFactory::CreatePlayerL(const TDesC8& /*aHeaderData*/)
       
   164 {
       
   165     // only file is supported
       
   166     return NULL;
       
   167 }
       
   168 
       
   169 // ---------------------------------------------------------------------------
       
   170 // CMMADRMPlayerFactory::GetSupportedContentTypesL
       
   171 // ---------------------------------------------------------------------------
       
   172 //
       
   173 void CMMADRMPlayerFactory::GetSupportedContentTypesL(const TDesC& /*aProtocol*/,
       
   174         CDesC16Array& /*aMimeTypeArray*/)
       
   175 {
       
   176     // DRM Supports same content-types as others, no need to add
       
   177 }
       
   178 
       
   179 // ---------------------------------------------------------------------------
       
   180 // CMMADRMPlayerFactory::GetSupportedProtocolsL
       
   181 // ---------------------------------------------------------------------------
       
   182 //
       
   183 void CMMADRMPlayerFactory::GetSupportedProtocolsL(
       
   184     const TDesC& /*aContentType*/,
       
   185     CDesC16Array& /*aProtocolArray*/)
       
   186 {
       
   187     // DRM Supports same protocols as others, no need to add
       
   188 }
       
   189 
       
   190 // ---------------------------------------------------------------------------
       
   191 // CMMADRMPlayerFactory::UpdateRightsL
       
   192 // ---------------------------------------------------------------------------
       
   193 //
       
   194 void CMMADRMPlayerFactory::UpdateRightsL(TInt aError,
       
   195         const TDesC& aFileName)
       
   196 {
       
   197     DEBUG("MMA::CMMADRMPlayerFactory::UpdateRightsL +");
       
   198     CDRMHelper* helper = CDRMHelper::NewLC();
       
   199     TInt code = helper->HandleErrorL(aError, aFileName);
       
   200     if (code == 0)
       
   201     {
       
   202         User::Leave(aError);
       
   203     }
       
   204     CleanupStack::PopAndDestroy(helper);
       
   205 }
       
   206 
       
   207 // ---------------------------------------------------------------------------
       
   208 // CMMADRMPlayerFactory::CreateAudioPlayerL
       
   209 // ---------------------------------------------------------------------------
       
   210 //
       
   211 CMMAPlayer* CMMADRMPlayerFactory::CreateAudioPlayerL(const TDesC& aContentType,
       
   212         const TDesC& aFileName)
       
   213 {
       
   214     DEBUG("MMA::CMMADRMPlayerFactory::CreateAudioPlayerL +");
       
   215     CMMADRMAudioPlayer* player = CMMADRMAudioPlayer::NewLC(aContentType,
       
   216                                  aFileName);
       
   217 
       
   218     CMMADRMVolumeControl* volumeControl = CMMADRMVolumeControl::NewL(player);
       
   219     CleanupStack::PushL(volumeControl);
       
   220     player->AddControlL(volumeControl);
       
   221     CleanupStack::Pop(volumeControl);
       
   222 
       
   223     CMMAStopTimeControl* stopTimeControl = CMMAStopTimeControl::NewL(player);
       
   224     CleanupStack::PushL(stopTimeControl);
       
   225     player->AddControlL(stopTimeControl);
       
   226     CleanupStack::Pop(stopTimeControl);
       
   227 
       
   228     CMMADRMMetaDataControl* metaDataControl =
       
   229         new(ELeave)CMMADRMMetaDataControl(player);
       
   230     CleanupStack::PushL(metaDataControl);
       
   231     player->AddControlL(metaDataControl);
       
   232     CleanupStack::Pop(metaDataControl);
       
   233 
       
   234     CMMADRMRateControl* drmRateControl = CMMADRMRateControl::NewL(player);
       
   235     CleanupStack::PushL(drmRateControl);
       
   236     player->AddControlL(drmRateControl);
       
   237     CleanupStack::Pop(drmRateControl);
       
   238 
       
   239     CleanupStack::Pop(player);
       
   240     return player;
       
   241 }
       
   242 
       
   243 // ---------------------------------------------------------------------------
       
   244 // CMMADRMPlayerFactory::CreateVideoPlayerL
       
   245 // ---------------------------------------------------------------------------
       
   246 //
       
   247 CMMAPlayer* CMMADRMPlayerFactory::CreateVideoPlayerL(const TDesC& aContentType,
       
   248         const TDesC& aFileName)
       
   249 {
       
   250     DEBUG("MMA::CMMADRMPlayerFactory::CreateVideoPlayerL +");
       
   251     CMMAPlayer* player =
       
   252         iVideoPlayerFactory->CreatePlayerWithFileL(aContentType, &aFileName);
       
   253 
       
   254     return player;
       
   255 }
       
   256 
       
   257 //  END OF FILE