camerauis/cameraxui/cxengine/src/cxequalitypresetssymbian.cpp
changeset 43 0e652f8f1fbd
parent 28 3075d9b614e6
child 45 24fd82631616
equal deleted inserted replaced
28:3075d9b614e6 43:0e652f8f1fbd
    15 * Description:
    15 * Description:
    16 * Implementation file for CxeQualityPresetsSymbian class
    16 * Implementation file for CxeQualityPresetsSymbian class
    17 *
    17 *
    18 */
    18 */
    19 
    19 
       
    20 #include <algorithm>
    20 #include <e32std.h> // For Symbian types used in mmsenginedomaincrkeys.h
    21 #include <e32std.h> // For Symbian types used in mmsenginedomaincrkeys.h
    21 #include <MmsEngineDomainCRKeys.h>
    22 #include <MmsEngineDomainCRKeys.h>
    22 
    23 
    23 #include "cxutils.h"
    24 #include "cxutils.h"
    24 #include "cxenamespace.h"
    25 #include "cxenamespace.h"
    33 
    34 
    34 // constants
    35 // constants
    35 namespace
    36 namespace
    36 {
    37 {
    37     // Display IDs for cameras, used when requesting data from ICM
    38     // Display IDs for cameras, used when requesting data from ICM
    38     const int   PRIMARY_CAMERA_DISPLAY_ID   = 2;
    39     const int    PRIMARY_CAMERA_DISPLAY_ID   = 2;
    39     const int   SECONDARY_CAMERA_DISPLAY_ID = 3;
    40     const int    SECONDARY_CAMERA_DISPLAY_ID = 3;
    40 
    41 
    41     const int   ONE_MILLION    = 1000000;
    42     const int    ONE_MILLION    = 1000000;
    42     const qreal ASPECT_16_BY_9 = (16/9.0);
    43 
    43     const qreal DELTA_ERROR    = 0.20;
    44     const QSize ASPECT_RATIO_SIZE_4BY3  = QSize(4,3);
       
    45     const QSize ASPECT_RATIO_SIZE_16BY9 = QSize(16, 9);
       
    46     const QSize ASPECT_RATIO_SIZE_11BY9 = QSize(11, 9);
    44 
    47 
    45     // ICM "camcorderVisible" parameter value below this means sharing aka mms quality.
    48     // ICM "camcorderVisible" parameter value below this means sharing aka mms quality.
    46     const int   MMS_QUALITY_CAMCORDERVISIBLE_LIMIT = 200;
    49     const int    MMS_QUALITY_CAMCORDERVISIBLE_LIMIT = 200;
       
    50 
       
    51     // Average video bit rate scaler
       
    52     const qreal  VIDEO_AVG_BITRATE_SCALER = 0.9;
       
    53     // Coefficient to estimate video metadata amount
       
    54     const qreal  VIDEO_METADATA_COEFF = 1.03;
       
    55     // Maximum video clip duration in seconds for all qualities
       
    56     const qint64 VIDEO_MAX_DURATION = 5400;
    47 }
    57 }
    48 
    58 
    49 
    59 
    50 /* !
    60 /* !
    51 * Intializes ImagingConfigManager
    61 * Intializes ImagingConfigManager
    52 */
    62 */
    53 CxeQualityPresetsSymbian::CxeQualityPresetsSymbian(CxeSettings &settings)
    63 CxeQualityPresetsSymbian::CxeQualityPresetsSymbian(CxeSettings &settings)
    54     : mSettings(settings)
    64     : mSettings(settings)
    55 {
    65 {
    56     CX_DEBUG_ENTER_FUNCTION();
    66     CX_DEBUG_ENTER_FUNCTION();
       
    67     OstTrace0(camerax_performance, CXEQUALITYPRESETSSYMBIAN_1, "msg: e_CX_QUALITYPRESETS_NEW 1");
    57 
    68 
    58     TRAPD(err,  mIcm = CImagingConfigManager::NewL());
    69     TRAPD(err,  mIcm = CImagingConfigManager::NewL());
    59 
    70 
    60     if (err) {
    71     if (err) {
    61         CX_DEBUG(("Error during ICM initialization error code = %d", err));
    72         CX_DEBUG(("Error during ICM initialization error code = %d", err));
    62         mIcm = NULL;
    73         mIcm = NULL;
    63     }
    74     }
    64 
    75 
    65     CX_DEBUG_EXIT_FUNCTION();
    76     OstTrace0(camerax_performance, CXEQUALITYPRESETSSYMBIAN_2, "msg: e_CX_QUALITYPRESETS_NEW 0");
    66 
    77     CX_DEBUG_EXIT_FUNCTION();
    67 }
    78 }
    68 
    79 
    69 /* !
    80 /* !
    70 * CxeQualityPresetsSymbian::~CxeQualityPresetsSymbian()
    81 * CxeQualityPresetsSymbian::~CxeQualityPresetsSymbian()
    71 */
    82 */
    96         return presetList;
   107         return presetList;
    97     }
   108     }
    98     int totalLevels = mIcm->NumberOfImageQualityLevels();
   109     int totalLevels = mIcm->NumberOfImageQualityLevels();
    99 
   110 
   100     CX_DEBUG(("Total image quality levels = %d", totalLevels));
   111     CX_DEBUG(("Total image quality levels = %d", totalLevels));
   101     CArrayFixFlat<TUint>* levels= new CArrayFixFlat<TUint>(totalLevels);
   112     CArrayFixFlat<TUint>* levels = new CArrayFixFlat<TUint>(totalLevels);
   102 
   113 
   103     // Get camera display id based on camera index
   114     // Get camera display id based on camera index
   104     int displayId = cameraId == Cxe::SecondaryCameraIndex
   115     int displayId = cameraId == Cxe::SecondaryCameraIndex
   105                   ? SECONDARY_CAMERA_DISPLAY_ID : PRIMARY_CAMERA_DISPLAY_ID;
   116                   ? SECONDARY_CAMERA_DISPLAY_ID : PRIMARY_CAMERA_DISPLAY_ID;
   106 
   117 
   233 /*!
   244 /*!
   234 * Creates a new video preset based on TVideoQualitySet values from ICM.
   245 * Creates a new video preset based on TVideoQualitySet values from ICM.
   235 */
   246 */
   236 CxeVideoDetails CxeQualityPresetsSymbian::createVideoPreset(TVideoQualitySet set)
   247 CxeVideoDetails CxeQualityPresetsSymbian::createVideoPreset(TVideoQualitySet set)
   237 {
   248 {
       
   249     CX_DEBUG_ENTER_FUNCTION();
   238     CxeVideoDetails newPreset;
   250     CxeVideoDetails newPreset;
   239     // set setting values from quality set
   251     // set setting values from quality set
   240     newPreset.mWidth = set.iVideoWidth;
   252     newPreset.mWidth = set.iVideoWidth;
   241     newPreset.mHeight = set.iVideoHeight;
   253     newPreset.mHeight = set.iVideoHeight;
   242 
   254 
   270     fourCC.Append('\0');
   282     fourCC.Append('\0');
   271 
   283 
   272     // set audiotype
   284     // set audiotype
   273     newPreset.mAudioType = toString(fourCCBuf);
   285     newPreset.mAudioType = toString(fourCCBuf);
   274 
   286 
       
   287     CX_DEBUG_EXIT_FUNCTION();
   275     return newPreset;
   288     return newPreset;
   276 }
   289 }
   277 
   290 
   278 
   291 
   279 /*!
   292 /*!
   293 */
   306 */
   294 Cxe::AspectRatio CxeQualityPresetsSymbian::calculateAspectRatio(int width, int height) const
   307 Cxe::AspectRatio CxeQualityPresetsSymbian::calculateAspectRatio(int width, int height) const
   295 {
   308 {
   296     Cxe::AspectRatio aspectRatio = Cxe::AspectRatio4to3;
   309     Cxe::AspectRatio aspectRatio = Cxe::AspectRatio4to3;
   297 
   310 
   298     qreal ratio = 0;
   311     // calculate delta error for the resolution against supported aspect ratio's
   299     if (height != 0) {
   312     int delta16by9 = abs((width * ASPECT_RATIO_SIZE_16BY9.height()) - (height * ASPECT_RATIO_SIZE_16BY9.width()));
   300         ratio = (1.0 * width) / height;
   313     int delta11by9 = abs((width * ASPECT_RATIO_SIZE_11BY9.height()) - (height * ASPECT_RATIO_SIZE_11BY9.width()));
   301 
   314     int delta4by3  = abs((width * ASPECT_RATIO_SIZE_4BY3.height()) - (height * ASPECT_RATIO_SIZE_4BY3.width()));
   302         qreal delta16by9 = ratio - ASPECT_16_BY_9;
   315 
   303         if (abs(delta16by9) < DELTA_ERROR) {
   316     // get the closest aspect ratio
   304             aspectRatio = Cxe::AspectRatio16to9;
   317     int minValue = qMin(qMin(delta16by9, delta11by9), delta4by3);
   305         }
   318 
       
   319     if (minValue == delta16by9) {
       
   320         aspectRatio = Cxe::AspectRatio16to9;
       
   321     } else if (minValue == delta11by9) {
       
   322         aspectRatio = Cxe::AspectRatio11to9;
       
   323     } else if (minValue == delta4by3) {
       
   324         aspectRatio = Cxe::AspectRatio4to3;
   306     }
   325     }
   307 
   326 
   308     return aspectRatio;
   327     return aspectRatio;
   309 }
   328 }
   310 
   329 
   337     }
   356     }
   338 
   357 
   339     return mpxCountString;
   358     return mpxCountString;
   340 
   359 
   341 
   360 
       
   361 }
       
   362 
       
   363 /*!
       
   364 * Get the available recording time with given video quality details and disk space.
       
   365 * @param details Video quality details to use in calculation.
       
   366 * @param space Available disk space to use in calculation.
       
   367 * @return Available recording time estimate in seconds.
       
   368 */
       
   369 int CxeQualityPresetsSymbian::recordingTimeAvailable(const CxeVideoDetails& details, qint64 space)
       
   370 {
       
   371     CX_DEBUG_ENTER_FUNCTION();
       
   372     int time(0);
       
   373 
       
   374     // Maximum clip size may be limited for mms quality.
       
   375     // If mMaximumSizeInBytes == 0, no limit is specified.
       
   376     if (details.mMaximumSizeInBytes > 0 && details.mMaximumSizeInBytes < space) {
       
   377         space = details.mMaximumSizeInBytes;
       
   378     }
       
   379 
       
   380     // Use average audio/video bitrates to estimate remaining time
       
   381     qreal scaler(avgVideoBitRateScaler());
       
   382     if (scaler == 0) {
       
   383         // video bit rate scaler is 0, use the constant value
       
   384         scaler = VIDEO_AVG_BITRATE_SCALER;
       
   385     }
       
   386 
       
   387     int muteSetting = 0; // audio enabled
       
   388     mSettings.get(CxeSettingIds::VIDEO_MUTE_SETTING, muteSetting);
       
   389 
       
   390     int avgVideoBitRate = (details.mVideoBitRate * scaler);
       
   391     int avgAudioBitRate = (muteSetting == 1) ? 0 : details.mAudioBitRate;
       
   392 
       
   393     quint32 averageBitRate = (quint32)((avgVideoBitRate + avgAudioBitRate) * VIDEO_METADATA_COEFF);
       
   394     quint32 averageByteRate = averageBitRate / 8;
       
   395 
       
   396     // 0 <= Remaining time <= KCamCMaxClipDurationInSecs
       
   397     qint64 remaining = std::max(qint64(0), space/averageByteRate);
       
   398     time = std::min(remaining, VIDEO_MAX_DURATION);
       
   399 
       
   400     CX_DEBUG(( "remaining time from algorithm: %d", time ));
       
   401     CX_DEBUG_EXIT_FUNCTION();
       
   402     return time;
   342 }
   403 }
   343 
   404 
   344 
   405 
   345 /*!
   406 /*!
   346 Operator to sort values in ascending order.
   407 Operator to sort values in ascending order.