javauis/mmapi_qt/baseline/src/tmmaparametervalidator.cpp
branchRCL_3
changeset 25 ae942d28ec0e
equal deleted inserted replaced
24:6c158198356e 25:ae942d28ec0e
       
     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 storing and parsing properties
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 //  INCLUDE FILES
       
    20 #include <mmf/plugin/mmfformatimplementationuids.hrh>
       
    21 #include <mmf/plugin/mmfcontrollerimplementationuids.hrh>
       
    22 #include <mmf/common/mmfcontrollerpluginresolver.h>
       
    23 
       
    24 #include "logger.h"
       
    25 #include "cmmaplayerproperties.h"
       
    26 #include "tmmaparametervalidator.h"
       
    27 
       
    28 // CONSTANTS
       
    29 
       
    30 // AUDIO PARAMETERS
       
    31 _LIT(KPropertyEncoding,     "encoding");
       
    32 _LIT(KPropertyEncodingPcm,  "pcm");     // Wav
       
    33 _LIT(KPropertyEncodingAmr,  "amr");     // Amr
       
    34 _LIT(KPropertyEncodingGsm,  "gsm");
       
    35 _LIT(KPropertyEncodingUlaw, "ulaw");    // Au
       
    36 _LIT(KPropertyEncodingAlaw, "alaw");
       
    37 _LIT(KPropertyEncodingRaw,  "raw");     // Raw pcm
       
    38 _LIT(KPropertyEncodingNone,  "");       // empty string
       
    39 
       
    40 _LIT(KContentTypeWav, "audio/wav");
       
    41 _LIT(KContentTypeAu,  "audio/au");
       
    42 _LIT(KContentTypeAmr, "audio/amr");
       
    43 _LIT(KContentTypeRaw, "audio/raw");
       
    44 
       
    45 // Format used if not specified in locator
       
    46 _LIT(KDefaultAudioRecordContentType, "audio/wav");
       
    47 
       
    48 _LIT(KPropertyRate,         "rate");
       
    49 _LIT(KPropertyBits,         "bits");
       
    50 _LIT(KPropertyChannels,     "channels");
       
    51 
       
    52 _LIT(KPropertyEndian,       "endian");
       
    53 MMA_PARAMETER_STR(KPropertyEndianLittle, "little");
       
    54 MMA_PARAMETER_STR(KPropertyEndianBig,    "big");
       
    55 MMA_PARAMETER_ARRAY(KValidEndianValues)
       
    56 {
       
    57     {
       
    58         &KPropertyEndianLittle
       
    59     }, {&KPropertyEndianBig}
       
    60 };
       
    61 
       
    62 _LIT(KPropertySigned,       "signed");
       
    63 MMA_PARAMETER_STR(KPropertySignedSigned, "signed");
       
    64 MMA_PARAMETER_STR(KPropertySignedUnsigned, "unsigned");
       
    65 MMA_PARAMETER_ARRAY(KValidSignedValues)
       
    66 {
       
    67     {
       
    68         &KPropertySignedSigned
       
    69     }, {&KPropertySignedUnsigned}
       
    70 };
       
    71 
       
    72 // VIDEO PARAMETERS
       
    73 _LIT(KPropertyFps,         "fps");
       
    74 _LIT(KPropertyWidth,       "width");
       
    75 _LIT(KPropertyHeight,      "height");
       
    76 
       
    77 const TInt KSizeNotSet = -1;
       
    78 
       
    79 // Format used if not specified in locator
       
    80 _LIT(KDefaultVideoRecordContentType, "video/3gpp");
       
    81 
       
    82 //IMAGE PARAMETERS
       
    83 _LIT(KPropertyType,             "type");
       
    84 MMA_PARAMETER_STR(KPropertyJfif,  "jfif");
       
    85 MMA_PARAMETER_STR(KPropertyExif,  "exif");
       
    86 MMA_PARAMETER_ARRAY(KValidTypes)
       
    87 {
       
    88     {
       
    89         &KPropertyJfif
       
    90     }, {&KPropertyExif}
       
    91 };
       
    92 
       
    93 _LIT(KFormatPng, "png");
       
    94 _LIT(KFormatJpg, "jpeg");   // not "jpg"
       
    95 _LIT(KFormatGif, "gif");
       
    96 _LIT(KFormatBmp, "bmp");
       
    97 _LIT(KContentTypePng, "image/png");
       
    98 _LIT(KContentTypeJpg, "image/jpeg");
       
    99 _LIT(KContentTypeJpg2,"image/jpg");
       
   100 _LIT(KContentTypeGif, "image/gif");
       
   101 _LIT(KContentTypeBmp, "image/bmp");
       
   102 
       
   103 _LIT(KPropertyColor, "colors");
       
   104 MMA_PARAMETER_STR(KPropertyRGB888,  "rgb888");
       
   105 MMA_PARAMETER_STR(KPropertyRGB444,  "rgb444");
       
   106 MMA_PARAMETER_STR(KPropertyGray16,  "gray16");
       
   107 MMA_PARAMETER_STR(KPropertyGray8,   "gray8");
       
   108 
       
   109 _LIT(KPropertyQuality, "quality");
       
   110 const TInt KDefaultQuality = 75; // digged out from ICL source
       
   111 const TInt KDefaultBpp = 24;
       
   112 const TInt KDefaultBpp444 = 12;
       
   113 const TInt KDefaultBppGray16 = 16;
       
   114 const TInt KDefaultBppGray8 = 8;
       
   115 const TInt KNoUserDefinedQuality = -1;
       
   116 const TReal32 KNoUserDefinedFps = -1;
       
   117 
       
   118 // CMMAImageSettings container destructor
       
   119 CMMAImageSettings::~CMMAImageSettings()
       
   120 {
       
   121     delete iMimeType;
       
   122     delete iType;
       
   123     delete iImageData;
       
   124 }
       
   125 
       
   126 CMMAAudioSettings::~CMMAAudioSettings()
       
   127 {
       
   128     delete iContentType;
       
   129 }
       
   130 
       
   131 CMMAAudioSettings *TMMAParameterValidator::ValidateAudioPropertiesL(const TDesC& aProperties)
       
   132 {
       
   133     CMMAAudioSettings* settings = new(ELeave) CMMAAudioSettings;
       
   134     CleanupStack::PushL(settings);
       
   135 
       
   136     CMMAParameterRuleSet* rules = CMMAParameterRuleSet::NewLC();
       
   137 
       
   138     // "bits" must be between 0 - 24
       
   139     TMMAParameterRuleInt bitsRule(KPropertyBits, 0, 24);
       
   140     rules->AppendRuleL(&bitsRule);
       
   141 
       
   142     // "rate" must be positive
       
   143     TMMAParameterRuleInt rateRule(KPropertyRate, 1);
       
   144     rules->AppendRuleL(&rateRule);
       
   145 
       
   146     // "channels" must be 1 or 2
       
   147     TMMAParameterRuleInt channelsRule(KPropertyChannels, 1, 2);
       
   148     rules->AppendRuleL(&channelsRule);
       
   149 
       
   150     // "signed" must be "signed" or "unsigned"
       
   151     TMMAParameterRuleDes signedRule(KPropertySigned, KValidSignedValues,
       
   152                                     MMA_PARAMETER_ARRAY_SIZE(KValidSignedValues));
       
   153     rules->AppendRuleL(&signedRule);
       
   154 
       
   155     // "endian" must be "little" or "big"
       
   156     TMMAParameterRuleDes endianRule(KPropertyEndian, KValidEndianValues,
       
   157                                     MMA_PARAMETER_ARRAY_SIZE(KValidEndianValues));
       
   158     rules->AppendRuleL(&endianRule);
       
   159 
       
   160     // "encoding" must be one of valid values
       
   161     TMMAParameterRuleDes encodingRule(KPropertyEncoding);
       
   162     rules->AppendRuleL(&encodingRule);
       
   163 
       
   164     CMMAPlayerProperties* properties = CMMAPlayerProperties::NewL(aProperties, *rules);
       
   165     CleanupStack::PushL(properties);
       
   166 
       
   167     // validating properties
       
   168     properties->ValidateL();
       
   169 
       
   170     TInt bits = KDefaultBits;
       
   171     properties->GetProperty(KPropertyBits, bits);
       
   172 
       
   173     settings->iRate = KDefaultRate;
       
   174     properties->GetProperty(KPropertyRate, settings->iRate);
       
   175 
       
   176     settings->iChannels = KDefaultChannels;
       
   177     properties->GetProperty(KPropertyChannels, settings->iChannels);
       
   178 
       
   179 
       
   180     // Normally encoders are not streamable
       
   181     settings->iStreamableFormat = EFalse;
       
   182 
       
   183     // signed=signed/unsigned (default is unsigned for 8bit, signed for 16bit)
       
   184     TBool dataSigned = EFalse;
       
   185     if (properties->Compare(KPropertyBits, 16))
       
   186     {
       
   187         dataSigned = ETrue;
       
   188     }
       
   189 
       
   190     if (properties->Compare(KPropertySigned, KPropertySignedSigned()))
       
   191     {
       
   192         dataSigned = ETrue;
       
   193     }
       
   194     else if (properties->Compare(KPropertySigned, KPropertySignedUnsigned()))
       
   195     {
       
   196         dataSigned = EFalse;
       
   197     }
       
   198 
       
   199     // little by default
       
   200     TBool endianLittle = ETrue;
       
   201     if (properties->Compare(KPropertyEndian, KPropertyEndianBig()))
       
   202     {
       
   203         endianLittle = EFalse;
       
   204     }
       
   205 
       
   206     settings->iDataType = KMMFFourCCCodeNULL;
       
   207 
       
   208     // encoding specific
       
   209 
       
   210     TPtrC encoding(NULL, 0);
       
   211     properties->GetProperty(KPropertyEncoding, encoding);
       
   212 
       
   213     if ((encoding == KPropertyEncodingAmr()) ||
       
   214             (encoding == KPropertyEncodingGsm()))
       
   215     {
       
   216         // AMR format
       
   217         encoding.Set(KContentTypeAmr());
       
   218     }
       
   219 
       
   220     else if (encoding == KPropertyEncodingUlaw())
       
   221     {
       
   222         // AU format, ulaw codec
       
   223         encoding.Set(KContentTypeAu());
       
   224         settings->iDataType = KMMFFourCCCodeMuLAW;
       
   225     }
       
   226 
       
   227     else if (encoding == KPropertyEncodingAlaw())
       
   228     {
       
   229         // AU format, alaw codec
       
   230         encoding.Set(KContentTypeAu());
       
   231         settings->iDataType = KMMFFourCCCodeALAW;
       
   232     }
       
   233 
       
   234     else if (encoding == KPropertyEncodingPcm())
       
   235     {
       
   236         // wav format
       
   237         encoding.Set(KContentTypeWav());
       
   238     }
       
   239 
       
   240     else if (encoding == KPropertyEncodingRaw())
       
   241     {
       
   242         // raw format, default codec
       
   243         encoding.Set(KContentTypeRaw());
       
   244     }
       
   245 
       
   246     else if ((encoding == KPropertyEncodingNone()))     // this is the default case
       
   247     {
       
   248         encoding.Set(KDefaultAudioRecordContentType());
       
   249     }
       
   250 
       
   251     settings->iContentType = encoding.AllocL();
       
   252 
       
   253 
       
   254     // wav specific
       
   255     if (*settings->iContentType == KContentTypeWav())
       
   256     {
       
   257         if (bits == 8)
       
   258         {
       
   259             settings->iDataType = KMMFFourCCCodePCMU8;
       
   260         }
       
   261 
       
   262         else if (bits == 16)
       
   263         {
       
   264             settings->iDataType = KMMFFourCCCodePCM16;
       
   265         }
       
   266 
       
   267         else if (bits != KDefaultBits)
       
   268         {
       
   269             User::Leave(KErrNotSupported);
       
   270         }
       
   271     }
       
   272 
       
   273     // raw specific
       
   274     if (*settings->iContentType == KContentTypeRaw())
       
   275     {
       
   276         if (bits == 8)
       
   277         {
       
   278             if (dataSigned)
       
   279             {
       
   280                 settings->iDataType = KMMFFourCCCodePCM8;
       
   281             }
       
   282             else
       
   283             {
       
   284                 settings->iDataType = KMMFFourCCCodePCMU8;
       
   285             }
       
   286         }
       
   287 
       
   288         else if (bits == 16)
       
   289         {
       
   290             if (endianLittle)
       
   291             {
       
   292                 if (dataSigned)
       
   293                 {
       
   294                     settings->iDataType = KMMFFourCCCodePCM16;
       
   295                 }
       
   296                 else
       
   297                 {
       
   298                     settings->iDataType = KMMFFourCCCodePCMU16;
       
   299                 }
       
   300             }
       
   301             else // Big endian
       
   302             {
       
   303                 if (dataSigned)
       
   304                 {
       
   305                     settings->iDataType = KMMFFourCCCodePCM16B;
       
   306                 }
       
   307                 else
       
   308                 {
       
   309                     settings->iDataType = KMMFFourCCCodePCMU16B;
       
   310                 }
       
   311             }
       
   312         }
       
   313 
       
   314         else if (bits != KDefaultBits) // bits not 8 or 16
       
   315         {
       
   316             User::Leave(KErrNotSupported);
       
   317         }
       
   318 
       
   319         settings->iEncoding = TUid::Uid(KMmfUidFormatRAWWrite);
       
   320         settings->iController = TUid::Uid(KMmfUidControllerAudio);
       
   321     }
       
   322 
       
   323 
       
   324     CleanupStack::PopAndDestroy(2);   // rules, properties
       
   325     CleanupStack::Pop(settings);
       
   326     return settings;
       
   327 }
       
   328 
       
   329 TMMAVideoSettings TMMAParameterValidator::ValidateVideoPropertiesL(const TDesC& aProperties)
       
   330 {
       
   331     CheckEncodingL(aProperties);
       
   332     TMMAVideoSettings settings;
       
   333     CMMAParameterRuleSet* rules = CMMAParameterRuleSet::NewLC();
       
   334 
       
   335     // "fps" is real, taking it as string and validating later
       
   336     TMMAParameterRuleDes fpsRule(KPropertyFps);
       
   337     rules->AppendRuleL(&fpsRule);
       
   338 
       
   339     // "width" must be positive
       
   340     TMMAParameterRuleInt widthRule(KPropertyWidth, 1);
       
   341     rules->AppendRuleL(&widthRule);
       
   342 
       
   343     // "height" must be positive
       
   344     TMMAParameterRuleInt heightRule(KPropertyHeight, 1);
       
   345     rules->AppendRuleL(&heightRule);
       
   346 
       
   347     // "encoding" can be anything in this point (actual validation will be done by MMF)
       
   348     TMMAParameterRuleDes encodingRule(KPropertyEncoding);
       
   349     rules->AppendRuleL(&encodingRule);
       
   350 
       
   351     CMMAPlayerProperties* properties = CMMAPlayerProperties::NewL(aProperties, *rules);
       
   352     CleanupStack::PushL(properties);
       
   353 
       
   354     // validating properties
       
   355     properties->ValidateL();
       
   356 
       
   357     properties->GetProperty(KPropertyWidth, settings.iWidth = KSizeNotSet);
       
   358     properties->GetProperty(KPropertyHeight, settings.iHeight = KSizeNotSet);
       
   359 
       
   360     TPtrC fps;
       
   361     settings.iFps = KNoUserDefinedFps;
       
   362     if (properties->GetProperty(KPropertyFps, fps))
       
   363     {
       
   364         TLex lex(fps);
       
   365         TReal32 fpsReal;
       
   366         // try to get fps value from string
       
   367         TInt err = lex.Val(fpsReal);
       
   368         if (err == KErrNone)
       
   369         {
       
   370             // Check if there other characters after
       
   371             // number ( 34xxx )
       
   372             if (!lex.Eos() ||
       
   373                     (fpsReal <= 0))
       
   374             {
       
   375                 User::Leave(KErrArgument);
       
   376             }
       
   377             else
       
   378             {
       
   379                 settings.iFps = fpsReal;
       
   380             }
       
   381         }
       
   382         else if (err == KErrNoMemory)
       
   383         {
       
   384             User::Leave(KErrNoMemory);
       
   385         }
       
   386         else
       
   387         {
       
   388             // value is not available
       
   389             User::Leave(KErrArgument);
       
   390         }
       
   391     }
       
   392 
       
   393     settings.iEncoding.Set(KDefaultVideoRecordContentType());
       
   394     properties->GetProperty(KPropertyEncoding, settings.iEncoding);
       
   395 
       
   396     CleanupStack::PopAndDestroy(2);   // rules, properties
       
   397     return settings;
       
   398 }
       
   399 
       
   400 CMMAImageSettings* TMMAParameterValidator::ValidateImagePropertiesL(const TDesC& aProperties)
       
   401 {
       
   402     CMMAImageSettings* settings = new(ELeave)CMMAImageSettings;
       
   403     CleanupStack::PushL(settings);
       
   404 
       
   405     CMMAParameterRuleSet* rules = CMMAParameterRuleSet::NewLC();
       
   406 
       
   407     // "width" must be positive
       
   408     TMMAParameterRuleInt widthRule(KPropertyWidth, 1);
       
   409     rules->AppendRuleL(&widthRule);
       
   410 
       
   411     // "height" must be positive
       
   412     TMMAParameterRuleInt heightRule(KPropertyHeight, 1);
       
   413     rules->AppendRuleL(&heightRule);
       
   414 
       
   415     // "encoding" final validation is done with image encoder
       
   416     TMMAParameterRuleDes encodingRule(KPropertyEncoding);
       
   417     rules->AppendRuleL(&encodingRule);
       
   418 
       
   419     // "color" can be anything in this point, it will be validated later
       
   420     TMMAParameterRuleDes colorRule(KPropertyColor);
       
   421     rules->AppendRuleL(&colorRule);
       
   422 
       
   423     // "type" must be "jfif" or "exif"
       
   424     TMMAParameterRuleDes typeRule(KPropertyType, KValidTypes,
       
   425                                   MMA_PARAMETER_ARRAY_SIZE(KValidTypes));
       
   426     rules->AppendRuleL(&typeRule);
       
   427 
       
   428     // "quality" must be between 0 and 100
       
   429     TMMAParameterRuleInt qualityRule(KPropertyQuality, 0, 100);
       
   430     rules->AppendRuleL(&qualityRule);
       
   431 
       
   432     CMMAPlayerProperties* properties = CMMAPlayerProperties::NewL(aProperties, *rules);
       
   433     CleanupStack::PushL(properties);
       
   434 
       
   435     // validating properties
       
   436     properties->ValidateL();
       
   437 
       
   438     properties->GetProperty(KPropertyWidth, settings->iWidth = KSizeNotSet);
       
   439     properties->GetProperty(KPropertyHeight, settings->iHeight = KSizeNotSet);
       
   440 
       
   441     // do not set quality if user has not defined it
       
   442     TInt quality = KNoUserDefinedQuality;
       
   443     properties->GetProperty(KPropertyQuality, quality);
       
   444 
       
   445     TPtrC encoding;
       
   446     if (properties->Compare(KPropertyEncoding, KFormatPng) ||
       
   447             properties->Compare(KPropertyEncoding, KContentTypePng))
       
   448     {
       
   449         //PNG
       
   450         settings->iMimeType = CreateHBufC8FromUnicodeL(KContentTypePng);
       
   451         TPngEncodeData* imageData = new(ELeave)TPngEncodeData();
       
   452         imageData->iBitsPerPixel = KDefaultBpp;
       
   453         imageData->iColor = ETrue;
       
   454         imageData->iPaletted = EFalse;
       
   455         imageData->iLevel = TPngEncodeData::EDefaultCompression;
       
   456 
       
   457         CleanupStack::PushL(imageData);
       
   458         TPtrC color;
       
   459         if (properties->Compare(KPropertyColor, KPropertyRGB888()))
       
   460         {
       
   461             // default
       
   462         }
       
   463         else if (properties->Compare(KPropertyColor, KPropertyRGB444()))
       
   464         {
       
   465             imageData->iBitsPerPixel = KDefaultBpp444;
       
   466         }
       
   467         else if (properties->Compare(KPropertyColor, KPropertyGray16()))
       
   468         {
       
   469             imageData->iBitsPerPixel = KDefaultBppGray16;
       
   470             imageData->iColor = EFalse;
       
   471         }
       
   472         else if (properties->Compare(KPropertyColor, KPropertyGray8()))
       
   473         {
       
   474             imageData->iBitsPerPixel = KDefaultBppGray8;
       
   475             imageData->iColor = EFalse;
       
   476         }
       
   477         else if (properties->GetProperty(KPropertyColor, color))
       
   478         {
       
   479             // not valid color parameter
       
   480             User::Leave(KErrArgument);
       
   481         }
       
   482         settings->iImageData = CFrameImageData::NewL();
       
   483         User::LeaveIfError(settings->iImageData->AppendFrameData(imageData));
       
   484         // CFrameImageData took ownership of imageData
       
   485         CleanupStack::Pop(imageData);
       
   486 
       
   487         // png quality setting not supported, "type" is only for jpeg.
       
   488         TPtrC tmp;
       
   489         if (quality != KNoUserDefinedQuality ||
       
   490                 properties->GetProperty(KPropertyType, tmp)
       
   491            )
       
   492         {
       
   493             User::Leave(KErrArgument);
       
   494         }
       
   495     }
       
   496     else if (properties->Compare(KPropertyEncoding, KFormatJpg) ||
       
   497              properties->Compare(KPropertyEncoding, KContentTypeJpg) ||
       
   498              properties->Compare(KPropertyEncoding, KContentTypeJpg2))
       
   499     {
       
   500         // JPG
       
   501         settings->iMimeType = CreateHBufC8FromUnicodeL(KContentTypeJpg);
       
   502         if (properties->Compare(KPropertyType, KPropertyJfif()))
       
   503         {
       
   504             settings->iType = CreateHBufC8FromUnicodeL(KPropertyJfif());
       
   505         }
       
   506         else if (properties->Compare(KPropertyType, KPropertyExif()))
       
   507         {
       
   508             settings->iType = CreateHBufC8FromUnicodeL(KPropertyExif());
       
   509         }
       
   510         else
       
   511         {
       
   512             settings->iType = CreateHBufC8FromUnicodeL(KPropertyExif());
       
   513         }
       
   514 
       
   515         TJpegImageData* imageData = new(ELeave)TJpegImageData();
       
   516         CleanupStack::PushL(imageData);
       
   517         imageData->iQualityFactor = KDefaultQuality;
       
   518         imageData->iSampleScheme = TJpegImageData::EColor444;
       
   519         if (quality != KNoUserDefinedQuality)
       
   520         {
       
   521             imageData->iQualityFactor = quality;
       
   522         }
       
   523         settings->iImageData = CFrameImageData::NewL();
       
   524         User::LeaveIfError(settings->iImageData->AppendImageData(imageData));
       
   525         // CFrameImageData took ownership of imageData
       
   526         CleanupStack::Pop(imageData);
       
   527 
       
   528         TPtrC tmp;
       
   529         // jpg encoders colors cannot be configured,
       
   530         // notice that if there was "type" defined it must be "jfif"
       
   531         // and encoder will check that anyway.
       
   532         if (properties->GetProperty(KPropertyColor, tmp))
       
   533         {
       
   534             User::Leave(KErrArgument);
       
   535         }
       
   536     }
       
   537     else if (properties->Compare(KPropertyEncoding, KFormatGif) ||
       
   538              properties->Compare(KPropertyEncoding, KContentTypeGif))
       
   539     {
       
   540         //GIF
       
   541         settings->iMimeType = CreateHBufC8FromUnicodeL(KContentTypeGif);
       
   542         TPtrC tmp;
       
   543         // gif encoder is not configurable
       
   544         if (properties->GetProperty(KPropertyColor, tmp) ||
       
   545                 properties->GetProperty(KPropertyType, tmp)  ||
       
   546                 quality != KNoUserDefinedQuality)
       
   547         {
       
   548             User::Leave(KErrArgument);
       
   549         }
       
   550     }
       
   551     else if (properties->Compare(KPropertyEncoding, KFormatBmp) ||
       
   552              properties->Compare(KPropertyEncoding, KContentTypeBmp))
       
   553     {
       
   554         //BMP
       
   555         settings->iMimeType = CreateHBufC8FromUnicodeL(KContentTypeBmp);
       
   556         TBmpImageData* imageData = new(ELeave)TBmpImageData();
       
   557         CleanupStack::PushL(imageData);
       
   558         imageData->iBitsPerPixel = KDefaultBpp;
       
   559         TPtrC color;
       
   560         if (properties->Compare(KPropertyColor, KPropertyRGB888()))
       
   561         {
       
   562             // default
       
   563         }
       
   564         else if (properties->Compare(KPropertyColor, KPropertyRGB444()))
       
   565         {
       
   566             imageData->iBitsPerPixel = KDefaultBpp444;
       
   567         }
       
   568         else if (properties->GetProperty(KPropertyColor, color))
       
   569         {
       
   570             // not valid color parameter
       
   571             User::Leave(KErrArgument);
       
   572         }
       
   573 
       
   574         settings->iImageData = CFrameImageData::NewL();
       
   575         User::LeaveIfError(settings->iImageData->AppendImageData(imageData));
       
   576         // CFrameImageData took ownership of imageData
       
   577         CleanupStack::Pop(imageData);
       
   578 
       
   579         //  quality not supported, "type" is only for jpg
       
   580         TPtrC tmp;
       
   581         if (quality != KNoUserDefinedQuality ||
       
   582                 properties->GetProperty(KPropertyType, tmp))
       
   583         {
       
   584             User::Leave(KErrArgument);
       
   585         }
       
   586     }
       
   587     else if (properties->GetProperty(KPropertyEncoding, encoding))
       
   588     {
       
   589         // OTHER POSSIBLE TYPE
       
   590         // trying to create encoder with only content/mime-type
       
   591         settings->iMimeType = CreateHBufC8FromUnicodeL(encoding);
       
   592 
       
   593         // No extra parameters, only content-type
       
   594         TPtrC tmp;
       
   595         if (properties->GetProperty(KPropertyColor, tmp) ||
       
   596                 properties->GetProperty(KPropertyType, tmp) ||
       
   597                 quality != KNoUserDefinedQuality)
       
   598         {
       
   599             User::Leave(KErrArgument);
       
   600         }
       
   601     }
       
   602     else // default: we had empty properties string
       
   603     {
       
   604         settings->iMimeType = CreateHBufC8FromUnicodeL(KContentTypePng);
       
   605     }
       
   606     CleanupStack::PopAndDestroy(properties);
       
   607     CleanupStack::PopAndDestroy(rules);
       
   608     CleanupStack::Pop(settings);
       
   609     return settings;
       
   610 }
       
   611 
       
   612 void TMMAParameterValidator::CheckEncodingL(const TDesC& aProperties)
       
   613 {
       
   614     TInt encodingPos = aProperties.Find(KPropertyEncoding);
       
   615     // empty properties is valid and
       
   616     // encoding must be first parameter and must exist every time
       
   617     if ((aProperties.Length() > 0) &&
       
   618             ((encodingPos == KErrNotFound) ||
       
   619              (encodingPos != 0)))
       
   620     {
       
   621         User::Leave(KErrArgument);
       
   622     }
       
   623 }
       
   624 
       
   625 HBufC8* TMMAParameterValidator::CreateHBufC8FromUnicodeL(const TDesC& aDes)
       
   626 {
       
   627     HBufC8* tmp = HBufC8::NewL(aDes.Length());
       
   628     tmp->Des().Copy(aDes);
       
   629     return tmp;
       
   630 }
       
   631 
       
   632 //  END OF FILE