javauis/mmapi_akn/baseline/src/cmmammfresolver.cpp
branchRCL_3
changeset 19 04becd199f91
equal deleted inserted replaced
16:f5050f1da672 19:04becd199f91
       
     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 playing sounds
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 //  INCLUDE FILES
       
    20 #include <jdebug.h>
       
    21 
       
    22 
       
    23 #include "cmmammfresolver.h"
       
    24 #include "apgcli.h"
       
    25 #include "apmrec.h"
       
    26 
       
    27 
       
    28 #include "hxmetadatautil.h"
       
    29 _LIT8(KMimetypeRM, "audio/x-pn-realaudio");
       
    30 _LIT(KRVMimeType1, "video/x-pn-realvideo");
       
    31 _LIT(KRVMimeType2, "video/x-realvideo");
       
    32 _LIT(KRVMimeType3, "video/vnd.rn-realvideo");
       
    33 
       
    34 
       
    35 // CONSTANTS
       
    36 
       
    37 CMMAMMFResolver* CMMAMMFResolver::NewLC()
       
    38 {
       
    39     CMMAMMFResolver* self = new(ELeave)CMMAMMFResolver();
       
    40     CleanupStack::PushL(self);
       
    41     self->ConstructL();
       
    42     return self;
       
    43 }
       
    44 
       
    45 void CMMAMMFResolver::ListImplementationsL()
       
    46 {
       
    47     iControllerSelection->ListImplementationsL(*iImplementations);
       
    48     if (iImplementations->Count() > 0)
       
    49     {
       
    50         ResolveContentTypeL();
       
    51     }
       
    52 }
       
    53 
       
    54 RMMFControllerImplInfoArray* CMMAMMFResolver::Implementations()
       
    55 {
       
    56     // ImplementationsOwnership method must not be called before this
       
    57     __ASSERT_DEBUG(iImplementations, User::Invariant());
       
    58     return iImplementations;
       
    59 }
       
    60 
       
    61 RMMFControllerImplInfoArray* CMMAMMFResolver::ImplementationsOwnership()
       
    62 {
       
    63     // ImplementationsOwnership method must not be called many times
       
    64     __ASSERT_DEBUG(iImplementations, User::Invariant());
       
    65 
       
    66     RMMFControllerImplInfoArray* implementations = iImplementations;
       
    67     iImplementations = NULL; // ownership is transferred
       
    68     return implementations;
       
    69 }
       
    70 
       
    71 HBufC* CMMAMMFResolver::ContentTypeOwnership()
       
    72 {
       
    73     HBufC* ct = iContentType;
       
    74     iContentType = NULL;
       
    75     return ct;
       
    76 }
       
    77 
       
    78 HBufC* CMMAMMFResolver::ContentType()
       
    79 {
       
    80     return iContentType;
       
    81 }
       
    82 
       
    83 void CMMAMMFResolver::SetFileNameL(const TDesC* aFileName)
       
    84 {
       
    85     HBufC* fn = NULL;
       
    86     if (aFileName)
       
    87     {
       
    88         fn = aFileName->AllocL();
       
    89     }
       
    90     delete iFileName;
       
    91     iFileName = fn;
       
    92 }
       
    93 
       
    94 HBufC* CMMAMMFResolver::FileNameOwnership()
       
    95 {
       
    96     HBufC* fn = iFileName;
       
    97     iFileName = NULL;
       
    98     return fn;
       
    99 }
       
   100 
       
   101 void CMMAMMFResolver::ResolveContentTypeL()
       
   102 {
       
   103     DEBUG("+ CMMAMMFResolver::ResolveContentTypeL()");
       
   104     CMMFFormatSelectionParameters* fSelect = iRequiredPlayFormatSupport;
       
   105     if (!fSelect)
       
   106     {
       
   107         fSelect = iRequiredRecordFormatSupport;
       
   108     }
       
   109     // if there is no play or record formats this object is not
       
   110     // initialized correctly.
       
   111     __ASSERT_DEBUG(fSelect, User::Invariant());
       
   112 
       
   113     CMMFFormatSelectionParameters::TMatchDataType type =
       
   114         fSelect->MatchDataType();
       
   115 
       
   116     // if there is no implementation this method must not be called.
       
   117     __ASSERT_DEBUG(iImplementations->Count() > 0, User::Invariant());
       
   118     const RMMFFormatImplInfoArray* formats =
       
   119         Formats((*iImplementations)[ 0 ]);
       
   120 
       
   121     HBufC8* contentType = NULL;
       
   122     TInt formatsCount = formats->Count();
       
   123 
       
   124     if (type == CMMFFormatSelectionParameters::EMatchMimeType)
       
   125     {
       
   126         DEBUG("CMMAMMFResolver::ResolveContentTypeL - EMatchMimeType");
       
   127         // The match was based on a mime type.
       
   128         contentType = fSelect->MatchData().AllocLC();
       
   129     }
       
   130     else if (type == CMMFFormatSelectionParameters::EMatchFileExtension)
       
   131     {
       
   132         DEBUG("CMMAMMFResolver::ResolveContentTypeL - EMatchFileExtension");
       
   133         // The match was based on a file extension.
       
   134         RApaLsSession ls;
       
   135         TInt error;
       
   136         error = ls.Connect();
       
   137         TDataRecognitionResult result;
       
   138         error = ls.RecognizeData(*iFileName, KNullDesC8, result);
       
   139         ls.Close();
       
   140 
       
   141         if (iFileName && (iFileName->Right(3).Compare(KRaFileExtension()) == 0))
       
   142         {
       
   143             contentType = KMimetypeRM().AllocLC();
       
   144         }
       
   145         else if (iFileName && (iFileName->Right(3).Compare(KRmFileExtension()) == 0) &&
       
   146                  !(IsRealVideoTypeL(*iFileName)))
       
   147         {
       
   148             contentType = KMimetypeRM().AllocLC();
       
   149         }
       
   150         else if (!error && (result.iConfidence >= CApaDataRecognizerType::EProbable))
       
   151         {
       
   152             DEBUG_INT("CMMAMMFResolver::ResolveContentTypeL - Confidence : %d", result.iConfidence);
       
   153             contentType = result.iDataType.Des8().AllocLC();
       
   154         }
       
   155 
       
   156 
       
   157         else
       
   158         {
       
   159             // The probability is less, hence matching is done based on legacy style
       
   160             for (TInt format = 0; (format < formatsCount) &&
       
   161                     !contentType; format++)
       
   162             {
       
   163                 const CMMFFormatImplementationInformation* info = (*formats)[ format ];
       
   164                 if (info->SupportsFileExtension(fSelect->MatchData()))
       
   165                 {
       
   166                     if (info->SupportedMimeTypes().Count() > 0)
       
   167                     {
       
   168                         contentType = info->SupportedMimeTypes()[ 0 ].AllocLC();
       
   169                     }
       
   170                 }
       
   171             }
       
   172         }
       
   173     }
       
   174     else if (type == CMMFFormatSelectionParameters::EMatchHeaderData)
       
   175     {
       
   176         DEBUG("CMMAMMFResolver::ResolveContentTypeL - EMatchHeaderData");
       
   177         // The match was on a header data.
       
   178         RApaLsSession ls;
       
   179         TInt error;
       
   180         error = ls.Connect();
       
   181         TDataRecognitionResult result;
       
   182         error = ls.RecognizeData(KNullDesC, fSelect->MatchData() , result);
       
   183         ls.Close();
       
   184         if (!error && (result.iConfidence >= CApaDataRecognizerType::EProbable))
       
   185         {
       
   186             contentType = result.iDataType.Des8().AllocLC();
       
   187         }
       
   188         else
       
   189         {
       
   190             // The probability is less, hence matching is done based on legacy style
       
   191             for (TInt format = 0; (format < formatsCount) &&
       
   192                     !contentType; format++)
       
   193             {
       
   194                 CMMFFormatImplementationInformation* info = (*formats)[ format ];
       
   195                 if (info->SupportsHeaderDataL(fSelect->MatchData()))
       
   196                 {
       
   197                     if (info->SupportedMimeTypes().Count() > 0)
       
   198                     {
       
   199                         contentType = info->SupportedMimeTypes()[ 0 ].AllocLC();
       
   200                     }
       
   201                 }
       
   202             }
       
   203         }
       
   204     }
       
   205     else
       
   206     {
       
   207         DEBUG("CMMAMMFResolver::ResolveContentTypeL - KErrNotSupported");
       
   208         // EMatchAny is not supported
       
   209         User::Leave(KErrNotSupported);
       
   210     }
       
   211 
       
   212     // iContentType remains NULL if content type was not found.
       
   213     if (contentType)
       
   214     {
       
   215         DEBUG_STR8("CMMAMMFResolver::ResolveContentTypeL - contentType : %s", (*contentType).Des());
       
   216 
       
   217         HBufC* ct = HBufC::NewL(contentType->Length());
       
   218         (ct->Des()).Copy(*contentType);
       
   219         CleanupStack::PopAndDestroy(contentType);
       
   220         delete iContentType;
       
   221         iContentType = ct;
       
   222     }
       
   223     else
       
   224     {
       
   225         //This situation should never occur
       
   226         DEBUG("CMMAMMFResolver::ResolveContentTypeL - contentType = NULL");
       
   227         User::Leave(KErrUnknown);
       
   228     }
       
   229     DEBUG("- CMMAMMFResolver::ResolveContentTypeL()");
       
   230 }
       
   231 
       
   232 
       
   233 TBool CMMAMMFResolver::IsRealVideoTypeL(const TDesC& aFileName)
       
   234 {
       
   235     TBool result = EFalse;
       
   236 
       
   237     CHXMetaDataUtility *putil;
       
   238     putil = CHXMetaDataUtility::NewL();
       
   239     CleanupStack::PushL(putil);
       
   240     TRAPD(err, putil->OpenFileL(aFileName));
       
   241     DEBUG_INT("MMA:CMMAMMFResolver::IsRealVideoTypeL, err = %d", err);
       
   242 
       
   243     if (err != KErrNone)
       
   244     {
       
   245         CleanupStack::Pop(putil);
       
   246         putil->ResetL();
       
   247         delete putil;
       
   248         return EFalse;
       
   249     }
       
   250 
       
   251     TUint count = 0;
       
   252     putil->GetMetaDataCount(count);
       
   253 
       
   254     TUint i;
       
   255     HXMetaDataKeys::EHXMetaDataId  id;
       
   256 
       
   257     for (i = 0; i < count; i++)
       
   258     {
       
   259         HBufC* pDes = NULL;
       
   260 
       
   261         putil->GetMetaDataAt(i, id, pDes);
       
   262 
       
   263         if (id == HXMetaDataKeys::EHXMimeType)
       
   264         {
       
   265             if (IsRealMimeTypeSupported(*pDes))
       
   266             {
       
   267                 result = ETrue;
       
   268             }
       
   269         }
       
   270     }
       
   271 
       
   272     CleanupStack::Pop(putil);
       
   273 
       
   274     putil->ResetL();
       
   275     delete putil;
       
   276 
       
   277     return result;
       
   278 }
       
   279 
       
   280 
       
   281 TBool CMMAMMFResolver::IsRealMimeTypeSupported(const TDesC& aMimeType)
       
   282 {
       
   283     TBool match = EFalse;
       
   284 
       
   285     if (!aMimeType.Compare(KRVMimeType1()))
       
   286     {
       
   287         match = ETrue;
       
   288         return match;
       
   289     }
       
   290     if (!aMimeType.Compare(KRVMimeType2()))
       
   291     {
       
   292         match = ETrue;
       
   293         return match;
       
   294     }
       
   295     if (!aMimeType.Compare(KRVMimeType3()))
       
   296     {
       
   297         match = ETrue;
       
   298         return match;
       
   299     }
       
   300 
       
   301     return match;
       
   302 }
       
   303 
       
   304 
       
   305 void CMMAMMFResolver::GetSupportedContentTypesL(CDesC16Array& aMimeTypeArray)
       
   306 {
       
   307     iControllerSelection->ListImplementationsL(*iImplementations);
       
   308 
       
   309     TInt impCount = iImplementations->Count();
       
   310     for (TInt i = 0; i < impCount; i++)
       
   311     {
       
   312         const RMMFFormatImplInfoArray* formats = Formats((*iImplementations)[ i ]);
       
   313         TInt formatsCount(formats->Count());
       
   314         for (TInt format = 0; format < formatsCount; format++)
       
   315         {
       
   316             const CMMFFormatImplementationInformation* info = (*formats)[ format ];
       
   317             const CDesC8Array& supportedMimes = info->SupportedMimeTypes();
       
   318             TInt mimeCount = supportedMimes.Count();
       
   319             for (TInt mime = 0; mime < mimeCount; mime++)
       
   320             {
       
   321                 // must convert from 8 bits to 16 bits
       
   322                 HBufC* tmpBuf = HBufC::NewLC(supportedMimes[ mime ].Length());
       
   323                 tmpBuf->Des().Copy(supportedMimes[ mime ]);
       
   324                 aMimeTypeArray.AppendL(*tmpBuf);
       
   325                 CleanupStack::PopAndDestroy(tmpBuf);
       
   326             }
       
   327         }
       
   328     }
       
   329 }
       
   330 
       
   331 
       
   332 void CMMAMMFResolver::SetRequiredPlayFormatSupportL(
       
   333     CMMFFormatSelectionParameters& aRequiredSupport)
       
   334 {
       
   335     iControllerSelection->SetRequiredPlayFormatSupportL(aRequiredSupport);
       
   336     iRequiredPlayFormatSupport = &aRequiredSupport;
       
   337 }
       
   338 
       
   339 void CMMAMMFResolver::SetRequiredRecordFormatSupportL(
       
   340     CMMFFormatSelectionParameters& aRequiredSupport)
       
   341 {
       
   342     iControllerSelection->SetRequiredRecordFormatSupportL(aRequiredSupport);
       
   343     iRequiredRecordFormatSupport = &aRequiredSupport;
       
   344 }
       
   345 
       
   346 const RMMFFormatImplInfoArray* CMMAMMFResolver::Formats(CMMFControllerImplementationInformation* aImplementation)
       
   347 {
       
   348     const RMMFFormatImplInfoArray* formats = NULL;
       
   349     if (iRequiredPlayFormatSupport)
       
   350     {
       
   351         formats = &(aImplementation->PlayFormats());
       
   352     }
       
   353     else
       
   354     {
       
   355         // if there is no play or record formats this object is not
       
   356         // initialized correctly.
       
   357         __ASSERT_DEBUG(iRequiredRecordFormatSupport, User::Invariant());
       
   358 
       
   359         formats = &(aImplementation->RecordFormats());
       
   360     }
       
   361     return formats;
       
   362 }
       
   363 
       
   364 CMMFControllerPluginSelectionParameters*
       
   365 CMMAMMFResolver::SelectionParameters()
       
   366 {
       
   367     return iControllerSelection;
       
   368 }
       
   369 
       
   370 CMMAMMFResolver::~CMMAMMFResolver()
       
   371 {
       
   372     if (iImplementations)
       
   373     {
       
   374         iImplementations->ResetAndDestroy();
       
   375     }
       
   376     delete iImplementations;
       
   377     delete iContentType;
       
   378     delete iControllerSelection;
       
   379     delete iFileName;
       
   380 }
       
   381 
       
   382 
       
   383 CMMAMMFResolver::CMMAMMFResolver()
       
   384 {
       
   385 }
       
   386 
       
   387 
       
   388 void CMMAMMFResolver::ConstructL()
       
   389 {
       
   390     iImplementations = new(ELeave)RMMFControllerImplInfoArray();
       
   391     iControllerSelection = CMMFControllerPluginSelectionParameters::NewL();
       
   392 }
       
   393 
       
   394 
       
   395 //  END OF FILE