javauis/mmapi_qt/baseline/src/cmmavideourlplayerfactory.cpp
branchRCL_3
changeset 24 0fd27995241b
equal deleted inserted replaced
20:f9bb0fca356a 24:0fd27995241b
       
     1 /*
       
     2 * Copyright (c) 2002 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 video player.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 //  INCLUDE FILES
       
    20 #include <logger.h>
       
    21 
       
    22 #include "cmmavideourlplayerfactory.h"
       
    23 #include "cmmavideourlplayer.h"
       
    24 #include "cmmavideocontrol.h"
       
    25 #include "cmmaaudiovolumecontrol.h"
       
    26 #include "cmmammfratecontrol.h"
       
    27 
       
    28 //  CONSTANTS
       
    29 const TInt KDefaultGranularity = 8;
       
    30 _LIT(KProtocolRtsp, "rtsp");
       
    31 _LIT(KRtspMimeType, "application/sdp");
       
    32 
       
    33 _LIT(KAudioXPnRmMimeType, "application/x-pn-realmedia");
       
    34 _LIT(KAudioRmMimeType, "application/vnd.rn-realmedia");
       
    35 _LIT(KAudio3gppMimeType, "audio/3gpp");
       
    36 _LIT(KAudio3gpp2MimeType, "audio/3gpp2");
       
    37 _LIT(KAudioAmrMimeType, "audio/amr");
       
    38 _LIT(KAudioMp4MimeType, "audio/mp4");
       
    39 _LIT(KAudioMp4LatmMimeType, "audio/mp4-latm");
       
    40 _LIT(KAudioQcelpMimeType, "audio/qcelp");
       
    41 _LIT(KAudioVndQcelpMimeType, "audio/vnd.qcelp");
       
    42 _LIT(KVideo3GppMimeType, "video/3gpp");
       
    43 _LIT(KVideo3Gpp2MimeType, "video/3gpp2");
       
    44 _LIT(KVideoMp4MimeType, "video/mp4");
       
    45 
       
    46 _LIT(KProtocolSeparator, "://");
       
    47 _LIT(KParameterSeparator, "?");
       
    48 
       
    49 CMMAVideoUrlPlayerFactory::CMMAVideoUrlPlayerFactory()
       
    50 {
       
    51 }
       
    52 
       
    53 
       
    54 CMMAVideoUrlPlayerFactory* CMMAVideoUrlPlayerFactory::NewLC()
       
    55 {
       
    56     CMMAVideoUrlPlayerFactory* pFactory =
       
    57         new(ELeave) CMMAVideoUrlPlayerFactory();
       
    58     CleanupStack::PushL(pFactory);
       
    59     return pFactory;
       
    60 }
       
    61 
       
    62 
       
    63 CMMAVideoUrlPlayerFactory::~CMMAVideoUrlPlayerFactory()
       
    64 {
       
    65     delete iUrl;
       
    66 }
       
    67 
       
    68 
       
    69 CMMAPlayer* CMMAVideoUrlPlayerFactory::CreatePlayerL(const TDesC& /*aContentType*/)
       
    70 {
       
    71     // Only creating with locator is supported
       
    72     return NULL;
       
    73 }
       
    74 CMMAPlayer* CMMAVideoUrlPlayerFactory::CreatePlayerL(const TDesC& aProtocol,
       
    75         const TDesC& aMiddlePart,
       
    76         const TDesC& aParameters)
       
    77 {
       
    78     // Is it rtsp:// protocol
       
    79     if (aProtocol != KProtocolRtsp)
       
    80     {
       
    81         return NULL;
       
    82     }
       
    83     CMMFFormatSelectionParameters* fSelect =
       
    84         CMMFFormatSelectionParameters::NewLC();
       
    85 
       
    86     // combining the locator
       
    87     HBufC* remadeLocator = HBufC::NewLC(aProtocol.Length() +
       
    88                                         KProtocolSeparator().Length() +
       
    89                                         aMiddlePart.Length() +
       
    90                                         KParameterSeparator().Length() +
       
    91                                         aParameters.Length());
       
    92     TPtr loc = remadeLocator->Des();
       
    93     loc.Append(aProtocol);
       
    94     loc.Append(KProtocolSeparator);
       
    95     loc.Append(aMiddlePart);
       
    96     if (aParameters != KNullDesC)
       
    97     {
       
    98         loc.Append(KParameterSeparator);
       
    99         loc.Append(aParameters);
       
   100     }
       
   101     delete iUrl;
       
   102     iUrl = remadeLocator;
       
   103     CleanupStack::Pop(remadeLocator);
       
   104 
       
   105     // RTSP URLs without file extension:
       
   106     // In case of file extensionless RTSP URL a predefined mime type
       
   107     // is used to select controller. It is assumed that this mime
       
   108     // type selects the controller that is capable to play any file
       
   109     // extensionless RTSP URLs.
       
   110     // To determine whether there is a file extension, it is checked whether
       
   111     // there is a dot at all or if there is a slash after last dot in the
       
   112     // URL. If there is a slash after last dot or if there is no dot at all,
       
   113     // then there is no file extension.
       
   114     TInt dotPos = aMiddlePart.LocateReverse('.');
       
   115     TInt slashPos = aMiddlePart.LocateReverse('/');
       
   116     if ((dotPos == KErrNotFound) || (slashPos > dotPos))
       
   117     {
       
   118         HBufC8* mimeBuf = HBufC8::NewLC(KRtspMimeType().Length());
       
   119         TPtr8 mimePtr = mimeBuf->Des();
       
   120         mimePtr.Copy(KRtspMimeType());
       
   121         fSelect->SetMatchToMimeTypeL(mimePtr);
       
   122         CleanupStack::PopAndDestroy(mimeBuf);
       
   123     }
       
   124     else
       
   125     {
       
   126         // Match to file name, using only middle part of the locator
       
   127         fSelect->SetMatchToUriL(loc);
       
   128     }
       
   129 
       
   130     CMMAPlayer* player = CMMAMMFPlayerFactory::CreatePlayerL(fSelect);
       
   131 
       
   132     CleanupStack::PopAndDestroy(fSelect);
       
   133     return player;
       
   134 }
       
   135 
       
   136 CMMAPlayer* CMMAVideoUrlPlayerFactory::CreatePlayerL(
       
   137     const TDesC8& /*aHeaderData*/)
       
   138 {
       
   139     // We do not try to match headerdata
       
   140     return NULL;
       
   141 }
       
   142 
       
   143 
       
   144 void CMMAVideoUrlPlayerFactory::GetSupportedContentTypesL(
       
   145     const TDesC& aProtocol,
       
   146     CDesC16Array& aMimeTypes)
       
   147 {
       
   148     if ((aProtocol == KNullDesC) ||
       
   149             (aProtocol == KProtocolRtsp))
       
   150     {
       
   151         aMimeTypes.AppendL(KAudio3gppMimeType);
       
   152         aMimeTypes.AppendL(KAudio3gpp2MimeType);
       
   153         aMimeTypes.AppendL(KAudioAmrMimeType);
       
   154         aMimeTypes.AppendL(KAudioMp4MimeType);
       
   155         aMimeTypes.AppendL(KAudioMp4LatmMimeType);
       
   156         aMimeTypes.AppendL(KAudioQcelpMimeType);
       
   157         aMimeTypes.AppendL(KAudioVndQcelpMimeType);
       
   158         aMimeTypes.AppendL(KVideo3GppMimeType);
       
   159         aMimeTypes.AppendL(KVideo3Gpp2MimeType);
       
   160         aMimeTypes.AppendL(KVideoMp4MimeType);
       
   161         aMimeTypes.AppendL(KAudioRmMimeType);
       
   162         aMimeTypes.AppendL(KAudioXPnRmMimeType);
       
   163         // plus RTSP content types
       
   164         aMimeTypes.AppendL(KRtspMimeType);
       
   165     }
       
   166 }
       
   167 
       
   168 
       
   169 void CMMAVideoUrlPlayerFactory::GetSupportedProtocolsL(
       
   170     const TDesC& aContentType,
       
   171     CDesC16Array& aProtocolArray)
       
   172 {
       
   173     CDesC16ArraySeg* supportedCTs
       
   174     = new(ELeave) CDesC16ArraySeg(KDefaultGranularity);
       
   175     CleanupStack::PushL(supportedCTs);
       
   176     GetSupportedContentTypesL(KNullDesC, *supportedCTs);
       
   177     TInt ignore(0);
       
   178     if ((supportedCTs->Find(aContentType, ignore) == 0) ||
       
   179             (aContentType == KNullDesC))
       
   180     {
       
   181         aProtocolArray.AppendL(KProtocolRtsp);
       
   182     }
       
   183     CleanupStack::PopAndDestroy(supportedCTs);
       
   184 }
       
   185 
       
   186 CMMAPlayer* CMMAVideoUrlPlayerFactory::CreatePlayerL(
       
   187     CMMAMMFResolver* aResolver)
       
   188 {
       
   189     CMMAVideoUrlPlayer* player = CMMAVideoUrlPlayer::NewLC(aResolver,
       
   190                                  *iUrl);
       
   191 
       
   192     CMMAVideoControl* videoControl = new(ELeave) CMMAVideoControl(player);
       
   193     CleanupStack::PushL(videoControl);
       
   194     player->AddControlL(videoControl);
       
   195     CleanupStack::Pop(videoControl);
       
   196 
       
   197     CMMAAudioVolumeControl* audioVolumeControl = CMMAAudioVolumeControl::NewL(player);
       
   198     CleanupStack::PushL(audioVolumeControl);
       
   199     player->AddControlL(audioVolumeControl);
       
   200     CleanupStack::Pop(audioVolumeControl);
       
   201 
       
   202     CMMAMMFRateControl* rateControl = CMMAMMFRateControl::NewL(player);
       
   203     CleanupStack::PushL(rateControl);
       
   204     player->AddControlL(rateControl);
       
   205     CleanupStack::Pop(rateControl);
       
   206 
       
   207     CleanupStack::Pop(); // player
       
   208     return player;
       
   209 }
       
   210 
       
   211 void CMMAVideoUrlPlayerFactory::MediaIdsL(RArray<TUid>& aMediaIds)
       
   212 {
       
   213     User::LeaveIfError(aMediaIds.Append(KUidMediaTypeVideo));
       
   214 }
       
   215 
       
   216 CMMFPluginSelectionParameters::TMediaIdMatchType
       
   217 CMMAVideoUrlPlayerFactory::MediaIdMatchType()
       
   218 {
       
   219     // We are now getting only Audio Controllers
       
   220     return CMMFPluginSelectionParameters::EAllowOtherMediaIds;
       
   221 }
       
   222 
       
   223 //  END OF FILE