videoeditorengine/vedengine/src/vedqualitysettingsapi.cpp
changeset 0 951a5db380a0
equal deleted inserted replaced
-1:000000000000 0:951a5db380a0
       
     1 /*
       
     2 * Copyright (c) 2010 Ixonos Plc.
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the "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 * Ixonos Plc
       
    14 *
       
    15 * Description:  
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include "vedqualitysettingsapi.h"
       
    21 
       
    22 const TUint KCameraDisplayID = 2;
       
    23 
       
    24 // ---------------------------------------------------------------------------
       
    25 // Constructor of CVideoQualitySelector
       
    26 // ---------------------------------------------------------------------------
       
    27 //
       
    28 CVideoQualitySelector::CVideoQualitySelector()
       
    29     {
       
    30     }
       
    31     
       
    32 // ---------------------------------------------------------------------------
       
    33 // Destructor of CVideoQualitySelector
       
    34 // ---------------------------------------------------------------------------
       
    35 //
       
    36 CVideoQualitySelector::~CVideoQualitySelector()
       
    37     {
       
    38     if( iConfigManager )
       
    39         {
       
    40         delete iConfigManager;
       
    41         iConfigManager = 0;
       
    42         }
       
    43         
       
    44     if( iQualityLevels )
       
    45         {
       
    46         delete iQualityLevels;
       
    47         iQualityLevels = 0;
       
    48         }
       
    49     }
       
    50     
       
    51 // ---------------------------------------------------------------------------
       
    52 // ConstructL() of CVideoQualitySelector
       
    53 // ---------------------------------------------------------------------------
       
    54 //
       
    55 void CVideoQualitySelector::ConstructL()
       
    56     {
       
    57     iConfigManager = CImagingConfigManager::NewL();
       
    58     
       
    59     iQualityLevels = new (ELeave) CArrayFixFlat<TUint>(16);
       
    60     
       
    61     iConfigManager->GetVideoQualityLevelsL( *iQualityLevels, KCameraDisplayID );
       
    62     }
       
    63     
       
    64 // ---------------------------------------------------------------------------
       
    65 // NewL() of CVideoQualitySelector
       
    66 // ---------------------------------------------------------------------------
       
    67 //
       
    68 CVideoQualitySelector* CVideoQualitySelector::NewL()
       
    69     {
       
    70     CVideoQualitySelector* self = CVideoQualitySelector::NewLC();
       
    71     CleanupStack::Pop( self );
       
    72     return self;
       
    73     }
       
    74 
       
    75 // ---------------------------------------------------------------------------
       
    76 // NewLC() of CVideoQualitySelector
       
    77 // ---------------------------------------------------------------------------
       
    78 //
       
    79 CVideoQualitySelector* CVideoQualitySelector::NewLC()
       
    80     {
       
    81     CVideoQualitySelector* self = new( ELeave ) CVideoQualitySelector;
       
    82     CleanupStack::PushL( self );
       
    83     self->ConstructL();
       
    84     return self;
       
    85     }
       
    86 
       
    87 // ---------------------------------------------------------------------------
       
    88 // Get number of defined quality levels.
       
    89 // ---------------------------------------------------------------------------
       
    90 //
       
    91 TInt CVideoQualitySelector::NumberOfQualityLevels()
       
    92     {
       
    93     return iQualityLevels->Count();
       
    94     }
       
    95 
       
    96 // ---------------------------------------------------------------------------
       
    97 // Get quality set associated with the given level.
       
    98 // ---------------------------------------------------------------------------
       
    99 //
       
   100 void CVideoQualitySelector::GetVideoQualitySetL( SVideoQualitySet& aSet, TInt aLevel, TBool aAspectRatioWide )
       
   101     {
       
   102     if ( !aAspectRatioWide )
       
   103         {
       
   104         GetVideoQualitySetL( aSet, aLevel );
       
   105         }
       
   106     else
       
   107         {
       
   108         // NOT READY
       
   109         User::Leave( KErrNotSupported );     
       
   110         }
       
   111     }
       
   112 
       
   113 // ---------------------------------------------------------------------------
       
   114 // Get quality set associated with the given level.
       
   115 // ---------------------------------------------------------------------------
       
   116 //
       
   117 void CVideoQualitySelector::GetVideoQualitySetL( SVideoQualitySet& aSet, TInt aLevel )
       
   118     {
       
   119     TVideoQualitySet currentSet;
       
   120     
       
   121     switch ( aLevel )
       
   122         {
       
   123         case EVideoQualityMMS :
       
   124             {
       
   125             iConfigManager->GetVideoQualitySet( currentSet, CImagingConfigManager::EQualityLow, KCameraDisplayID );
       
   126             MapQualitySet( aSet, currentSet );
       
   127             }
       
   128             break;
       
   129             
       
   130         case EVideoQualityNormal :
       
   131             {
       
   132             iConfigManager->GetVideoQualitySet( currentSet, CImagingConfigManager::EQualityNormal, KCameraDisplayID );
       
   133             MapQualitySet( aSet, currentSet );
       
   134             }
       
   135             break;
       
   136             
       
   137         case EVideoQualityHigh :
       
   138             {
       
   139             iConfigManager->GetVideoQualitySet( currentSet, CImagingConfigManager::EQualityHigh, KCameraDisplayID );
       
   140             MapQualitySet( aSet, currentSet );
       
   141             }
       
   142             break;
       
   143             
       
   144         default:
       
   145             {
       
   146             if ( aLevel < EVideoQualityMin )
       
   147                 {
       
   148                 User::Leave( KErrArgument );
       
   149                 }
       
   150             
       
   151             // Map our quality level to config manager's quality level   
       
   152             TInt configManagerLevel = aLevel * (CImagingConfigManager::EQualityHigh - CImagingConfigManager::EQualityMin);
       
   153             configManagerLevel /= (EVideoQualityHigh - EVideoQualityMin);
       
   154             
       
   155             iConfigManager->GetVideoQualitySet( currentSet, configManagerLevel, KCameraDisplayID );
       
   156             MapQualitySet( aSet, currentSet );
       
   157             }
       
   158             break;
       
   159         }
       
   160     }
       
   161 
       
   162 // ---------------------------------------------------------------------------
       
   163 // Get quality set associated with the given video resolution.
       
   164 // ---------------------------------------------------------------------------
       
   165 //
       
   166 void CVideoQualitySelector::GetVideoQualitySetL( SVideoQualitySet& aSet, const TSize& aVideoResolution )
       
   167     {
       
   168     TVideoQualitySet currentSet;
       
   169     TInt candidate = -1;
       
   170     TInt i;
       
   171     
       
   172     // Go through the qualities until a match is found. If several matches, pick the 1st one
       
   173     for ( i = iQualityLevels->Count() - 1; i >= 0; i-- ) // Searches from up to down to find higher quality first
       
   174         {
       
   175         iConfigManager->GetVideoQualitySet( currentSet, iQualityLevels->At( i ), KCameraDisplayID );
       
   176         
       
   177         if ( (currentSet.iVideoWidth == aVideoResolution.iWidth) && (currentSet.iVideoHeight == aVideoResolution.iHeight) )
       
   178             {
       
   179             // We've found a set which matches with the requested size
       
   180             
       
   181             if ( candidate == -1 )  // Don't set to worse if already found
       
   182                 {
       
   183                 candidate = i;
       
   184                 }
       
   185             
       
   186             if ( (currentSet.iVideoQualitySetLevel == CImagingConfigManager::EQualityLow) ||
       
   187                  (currentSet.iVideoQualitySetLevel == CImagingConfigManager::EQualityNormal) ||
       
   188                  (currentSet.iVideoQualitySetLevel == CImagingConfigManager::EQualityHigh) )
       
   189                 {
       
   190                 // We've found a set which matches also with preferred qualities
       
   191                 MapQualitySet( aSet, currentSet );
       
   192                 return;
       
   193                 }
       
   194             }
       
   195         }
       
   196     
       
   197     if ( candidate >= 0 ) 
       
   198         {
       
   199         iConfigManager->GetVideoQualitySet( currentSet, iQualityLevels->At( candidate ), KCameraDisplayID );
       
   200         MapQualitySet( aSet, currentSet );
       
   201         }
       
   202     else
       
   203         {
       
   204         User::Leave( KErrNotSupported );
       
   205         }
       
   206     }
       
   207 
       
   208 // ---------------------------------------------------------------------------
       
   209 // Get quality set associated with the given video codec MIME-type.
       
   210 // ---------------------------------------------------------------------------
       
   211 //
       
   212 void CVideoQualitySelector::GetVideoQualitySetL( SVideoQualitySet& aSet, const TPtrC8& aVideoCodecMimeType )
       
   213     {
       
   214     TVideoQualitySet currentSet;
       
   215     TPtrC8 settingsMimeType;
       
   216     TInt i;
       
   217     
       
   218     for ( i = iQualityLevels->Count() - 1; i >= 0; i-- ) // searches from up to down to find higher quality first
       
   219         {
       
   220         iConfigManager->GetVideoQualitySet( currentSet, iQualityLevels->At( i ), KCameraDisplayID );
       
   221         
       
   222         settingsMimeType.Set(TPtrC8(currentSet.iVideoCodecMimeType));
       
   223         if ( settingsMimeType.MatchF( (const TDesC8& )aVideoCodecMimeType ) != KErrNotFound ) 
       
   224             {
       
   225             // Found a match
       
   226             MapQualitySet( aSet, currentSet );
       
   227             return;
       
   228             }
       
   229         }
       
   230         
       
   231     User::Leave( KErrNotSupported );
       
   232     }
       
   233     
       
   234 // ---------------------------------------------------------------------------
       
   235 // Copies the values from the source set to the target set.
       
   236 // ---------------------------------------------------------------------------
       
   237 //
       
   238 void CVideoQualitySelector::MapQualitySet( SVideoQualitySet& aTargetSet, TVideoQualitySet& aSourceSet )
       
   239     {
       
   240     TInt i = 0;
       
   241     
       
   242     // Video aspect ratio
       
   243     // We don't have wide screen quality sets yet so this is always true
       
   244     aTargetSet.iVideoAspectRatioNormal = ETrue;
       
   245     
       
   246     // Video file format mime type    
       
   247     for ( i = 0; (i < KQSMaxShortStringLength - 1) && (i < KMaxStringLength); i++ )
       
   248         {
       
   249         aTargetSet.iVideoFileMimeType[i] = aSourceSet.iVideoFileMimeType[i];
       
   250         }
       
   251     aTargetSet.iVideoFileMimeType[i] = '\0';    // Add null termination
       
   252     
       
   253     // Video codec mime type    
       
   254     for ( i = 0; (i < KQSMaxLongStringLength - 1) && (i < KMaxStringLength); i++ )
       
   255         {
       
   256         aTargetSet.iVideoCodecMimeType[i] = aSourceSet.iVideoCodecMimeType[i];
       
   257         }
       
   258     aTargetSet.iVideoCodecMimeType[i] = '\0';   // Add null termination
       
   259     
       
   260     // Video picture width in pixels (luminance)
       
   261     aTargetSet.iVideoWidth = aSourceSet.iVideoWidth;
       
   262     
       
   263     // Video picture height in pixels (luminance)
       
   264     aTargetSet.iVideoHeight = aSourceSet.iVideoHeight;
       
   265     
       
   266     // Video framerate in fps
       
   267     aTargetSet.iVideoFrameRate = aSourceSet.iVideoFrameRate;
       
   268     
       
   269     // Video bitrate in bps
       
   270     aTargetSet.iVideoBitRate = aSourceSet.iVideoBitRate;
       
   271     
       
   272     // Random access point rate, in pictures per second
       
   273     aTargetSet.iRandomAccessRate = aSourceSet.iRandomAccessRate;
       
   274     
       
   275     // Audio codec FourCC
       
   276     if ( aSourceSet.iAudioFourCCType == TFourCC(' ', 'A', 'M', 'R') )
       
   277     {
       
   278         // AMR
       
   279         aTargetSet.iAudioFourCCType[0] = ' ';
       
   280         aTargetSet.iAudioFourCCType[1] = 'A';
       
   281         aTargetSet.iAudioFourCCType[2] = 'M';
       
   282         aTargetSet.iAudioFourCCType[3] = 'R';
       
   283         aTargetSet.iAudioFourCCType[4] = '\0';
       
   284     } 
       
   285     
       
   286     else if (aSourceSet.iAudioFourCCType == TFourCC(' ', 'A', 'A', 'C') )
       
   287     {
       
   288         // AAC
       
   289         aTargetSet.iAudioFourCCType[0] = ' ';
       
   290         aTargetSet.iAudioFourCCType[1] = 'A';
       
   291         aTargetSet.iAudioFourCCType[2] = 'A';
       
   292         aTargetSet.iAudioFourCCType[3] = 'C';
       
   293         aTargetSet.iAudioFourCCType[4] = '\0';
       
   294     } 
       
   295     else 
       
   296         aTargetSet.iAudioFourCCType[0] = '\0';
       
   297 
       
   298     // Audio bitrate in bps
       
   299     aTargetSet.iAudioBitRate = aSourceSet.iAudioBitRate;
       
   300     
       
   301     // Audio sampling rate in Hz
       
   302     aTargetSet.iAudioSamplingRate = aSourceSet.iAudioSamplingRate;
       
   303     
       
   304     // Number of audio channels
       
   305     aTargetSet.iAudioChannels = aSourceSet.iAudioChannels;
       
   306     }
       
   307