videofeeds/utils/src/CIptvTerminalVideoSupport.cpp
changeset 0 96612d01cf9f
equal deleted inserted replaced
-1:000000000000 0:96612d01cf9f
       
     1 /*
       
     2 * Copyright (c) 2004-2005 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 the License "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: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include <e32base.h>
       
    23 #include "IptvDebug.h"
       
    24 #include <barsread.h>
       
    25 #include <barsc.h>
       
    26 #include <bautils.h>
       
    27 #include <iptvmimesupport.rsg>
       
    28 #include "CIptvMediaContent.h"
       
    29 #include "CIptvTerminalVideoSupport.h"
       
    30 #include "TIptvMimeType.h"
       
    31 
       
    32 // CONSTANTS
       
    33 _LIT(KIptvMimeResourceFile, "\\Resource\\Apps\\Iptvmimesupport.RSC");
       
    34 _LIT(KIptvMimeRootC, "C:");
       
    35 _LIT(KIptvMimeRootE, "E:");
       
    36 _LIT(KIptvMimeRootF, "F:");
       
    37 _LIT(KIptvMimeRootZ, "Z:");
       
    38 const TInt KIptvMaxDrives = 4;
       
    39 
       
    40 // ============================ MEMBER FUNCTIONS ===============================
       
    41 
       
    42 // ---------------------------------------------------------
       
    43 // CIptvTerminalVideoSupport::ConstructL
       
    44 // Symbian 2nd phase constructor can leave.
       
    45 // ---------------------------------------------------------
       
    46 //
       
    47 void CIptvTerminalVideoSupport::ConstructL()
       
    48     {    
       
    49     IPTVLOGSTRING_LOW_LEVEL("CIptvTerminalVideoSupport::ConstructL");
       
    50 
       
    51     LoadResourceL();    
       
    52     }
       
    53 
       
    54 // ---------------------------------------------------------
       
    55 // CIptvTerminalVideoSupport::LoadResourceL
       
    56 // 
       
    57 // ---------------------------------------------------------
       
    58 //
       
    59 void CIptvTerminalVideoSupport::LoadResourceL()
       
    60     {    
       
    61     IPTVLOGSTRING_LOW_LEVEL("CIptvTerminalVideoSupport::LoadResourceL");
       
    62 
       
    63     RFs fs;
       
    64     User::LeaveIfError(fs.Connect());
       
    65     RResourceFile file;
       
    66     TFileName filename;
       
    67     TBool open = EFalse;
       
    68 
       
    69     for (TInt i = 0; i < KIptvMaxDrives; i++)
       
    70         {
       
    71         switch (i)
       
    72             {
       
    73             case 0:
       
    74                 {
       
    75                 filename.Copy(KIptvMimeRootC);
       
    76                 filename.Append(KIptvMimeResourceFile);
       
    77                 }
       
    78                 break;
       
    79             case 1:
       
    80                 {
       
    81                 filename.Copy(KIptvMimeRootE);
       
    82                 filename.Append(KIptvMimeResourceFile);
       
    83                 }
       
    84                 break;
       
    85             case 2:
       
    86                 {
       
    87                 filename.Copy(KIptvMimeRootF);
       
    88                 filename.Append(KIptvMimeResourceFile);
       
    89                 }
       
    90                 break;
       
    91             case 3:
       
    92                 {
       
    93                 filename.Copy(KIptvMimeRootZ);
       
    94                 filename.Append(KIptvMimeResourceFile);
       
    95                 }
       
    96                 break;
       
    97             default:
       
    98                 {
       
    99                 }
       
   100                 break;
       
   101             } 
       
   102 
       
   103         TRAPD(error, file.OpenL(fs, filename));
       
   104         if (error == KErrNone)
       
   105             {
       
   106             open = ETrue;
       
   107             break;
       
   108             }
       
   109         }
       
   110         
       
   111     if (open)
       
   112         {    
       
   113         CleanupClosePushL(file);    
       
   114         file.ConfirmSignatureL();
       
   115         HBufC8* buffer = file.AllocReadLC(R_SUP_MIME_TYPE_LIST);
       
   116         LoadMimeTypesL(buffer);
       
   117         CleanupStack::PopAndDestroy(); // buffer
       
   118         CleanupStack::PopAndDestroy(); // file     
       
   119         }
       
   120     fs.Close();
       
   121     }
       
   122 
       
   123 // ---------------------------------------------------------
       
   124 // CIptvTerminalVideoSupport::LoadMimeTypesL
       
   125 // 
       
   126 // ---------------------------------------------------------
       
   127 //
       
   128 void CIptvTerminalVideoSupport::LoadMimeTypesL(const HBufC8* aBuffer)
       
   129     {    
       
   130     IPTVLOGSTRING_LOW_LEVEL("CIptvTerminalVideoSupport::LoadMimeTypesL");
       
   131                         
       
   132     if (aBuffer)
       
   133         {                
       
   134         TResourceReader reader;
       
   135         reader.SetBuffer(aBuffer);
       
   136 
       
   137         TUint32 version = reader.ReadUint32();
       
   138         TInt count = reader.ReadInt16();
       
   139                     
       
   140         for (TInt i = 0; i < count; i++)
       
   141             {
       
   142             TIptvMimeType type;
       
   143             HBufC* mimeType = reader.ReadHBufCL();
       
   144             CleanupStack::PushL(mimeType);
       
   145             
       
   146             if (mimeType)
       
   147                 {
       
   148                 TInt length = mimeType->Length();                
       
   149                 TInt dataToCopy = Min(length, KIptvCAMimeTypeLength);                
       
   150                 type.iMimeType.Copy(mimeType->Mid(0, dataToCopy));
       
   151                 }
       
   152 
       
   153             type.iMaxBitrate = reader.ReadUint32();
       
   154             type.iMaxScreensizeH = reader.ReadUint32();
       
   155             type.iMaxScreensizeV = reader.ReadUint32();
       
   156             type.iMaxFramerate = reader.ReadUint32();
       
   157 
       
   158             iMimeTypes.AppendL(type);
       
   159             CleanupStack::PopAndDestroy(mimeType);             
       
   160             }                    
       
   161         }    
       
   162     }
       
   163 
       
   164 // ---------------------------------------------------------
       
   165 // CIptvTerminalVideoSupport::NewL
       
   166 // Two-phased constructor.
       
   167 // ---------------------------------------------------------
       
   168 //
       
   169 EXPORT_C CIptvTerminalVideoSupport* CIptvTerminalVideoSupport::NewL()
       
   170     {
       
   171     CIptvTerminalVideoSupport* self = new(ELeave) CIptvTerminalVideoSupport();
       
   172     CleanupStack::PushL(self);
       
   173 
       
   174     self->ConstructL();
       
   175 
       
   176     CleanupStack::Pop(self);
       
   177     return self;
       
   178     }
       
   179 
       
   180 // ---------------------------------------------------------
       
   181 // CIptvTerminalVideoSupport::~CIptvTerminalVideoSupport
       
   182 // Destructor
       
   183 // -----------------------------------------------------------------------------
       
   184 //
       
   185 CIptvTerminalVideoSupport::~CIptvTerminalVideoSupport()
       
   186     {        
       
   187     iMimeTypes.Close();
       
   188     }
       
   189 
       
   190 // ---------------------------------------------------------
       
   191 // CIptvTerminalVideoSupport::CIptvTerminalVideoSupport
       
   192 // C++ default constructor
       
   193 // ---------------------------------------------------------
       
   194 //
       
   195 CIptvTerminalVideoSupport::CIptvTerminalVideoSupport()     
       
   196     {
       
   197     }
       
   198 
       
   199 // ---------------------------------------------------------
       
   200 // CIptvTerminalVideoSupport::SelectMimeTypeL
       
   201 // 
       
   202 // ---------------------------------------------------------
       
   203 //
       
   204 EXPORT_C TInt CIptvTerminalVideoSupport::SelectMimeTypeL(RPointerArray<CIptvMediaContent>& aMediaContents)
       
   205     {
       
   206     IPTVLOGSTRING_LOW_LEVEL("CIptvTerminalVideoSupport::SelectMimeTypeL");
       
   207         
       
   208     CIptvMediaContent* bestContent = NULL;
       
   209     TInt priority = 0;
       
   210     TInt index = 0;                
       
   211 
       
   212     TInt count = aMediaContents.Count();
       
   213     for (TInt i = 0; i < count; i++)
       
   214         {        
       
   215         TInt mimeTypeCount = iMimeTypes.Count();
       
   216         for (TInt j = 0; j < mimeTypeCount; j++)
       
   217             {
       
   218             // Compare is current media content's mime-type supported.
       
   219             // Mime-types are in priorized order in iMimeTypes array, best is first.
       
   220             if (aMediaContents[i]->iMimeType.Compare(iMimeTypes[j].iMimeType) == 0)
       
   221                 {
       
   222                 // No best content yet. No comparison needed to previous best content.
       
   223                 if (!bestContent)
       
   224                     {
       
   225                     if (aMediaContents[i]->iBitrate <= iMimeTypes[j].iMaxBitrate &&
       
   226                         aMediaContents[i]->iHeight <= iMimeTypes[j].iMaxScreensizeV &&
       
   227                         aMediaContents[i]->iWidth <= iMimeTypes[j].iMaxScreensizeH &&
       
   228                         aMediaContents[i]->iFramerate <= iMimeTypes[j].iMaxFramerate)
       
   229                         {
       
   230                         index = i;
       
   231                         bestContent = aMediaContents[i];
       
   232                         IPTVLOGSTRING_LOW_LEVEL("");
       
   233                         IPTVLOGSTRING_LOW_LEVEL("First best content selected!:");
       
   234                         IPTVLOGSTRING_LOW_LEVEL("");
       
   235                         bestContent->PrintL();
       
   236                         priority = j;
       
   237                         break;
       
   238                         }
       
   239                     }
       
   240                 else
       
   241                     {
       
   242                     // We already have some content as a best content. Let's compare
       
   243                     // is new content better than previous. If is -> we got new best content.
       
   244                     // Notice!! j = 0 is best priority because best mime-type is fist in array!
       
   245                     if (j < priority)
       
   246                         {
       
   247                         if (aMediaContents[i]->iBitrate <= iMimeTypes[j].iMaxBitrate &&
       
   248                             aMediaContents[i]->iHeight <= iMimeTypes[j].iMaxScreensizeV &&
       
   249                             aMediaContents[i]->iWidth <= iMimeTypes[j].iMaxScreensizeH &&
       
   250                             aMediaContents[i]->iFramerate <= iMimeTypes[j].iMaxFramerate)
       
   251                             {
       
   252                             IPTVLOGSTRING_LOW_LEVEL("");
       
   253                             IPTVLOGSTRING_LOW_LEVEL("Best content changed from:");
       
   254                             bestContent->PrintL();                                
       
   255                             priority = j;
       
   256                             index = i;
       
   257                             bestContent = aMediaContents[i];
       
   258                             
       
   259                             IPTVLOGSTRING_LOW_LEVEL("");
       
   260                             IPTVLOGSTRING_LOW_LEVEL("To:");
       
   261                             bestContent->PrintL();
       
   262                             }
       
   263                         }
       
   264                     // Same priority ex. same mime-type. Let's use another parameters.                                                        
       
   265                     else if (j == priority)
       
   266                         {                                                    
       
   267                         // New contents bitrate is better that previous best content's.
       
   268                         if ((aMediaContents[i]->iBitrate > bestContent->iBitrate && aMediaContents[i]->iBitrate <= iMimeTypes[j].iMaxBitrate) &&
       
   269                             aMediaContents[i]->iHeight <= iMimeTypes[j].iMaxScreensizeV &&
       
   270                             aMediaContents[i]->iWidth <= iMimeTypes[j].iMaxScreensizeH &&
       
   271                             aMediaContents[i]->iFramerate <= iMimeTypes[j].iMaxFramerate)                                                        
       
   272                             {
       
   273                             IPTVLOGSTRING_LOW_LEVEL("");
       
   274                             IPTVLOGSTRING_LOW_LEVEL("Best content changed from:");
       
   275                             bestContent->PrintL();      
       
   276 
       
   277                             index = i;
       
   278                             bestContent = aMediaContents[i];
       
   279                 
       
   280                             IPTVLOGSTRING_LOW_LEVEL("");
       
   281                             IPTVLOGSTRING_LOW_LEVEL("To:");
       
   282                             bestContent->PrintL();
       
   283                             }                       
       
   284                         // New contens horizontal screensize is better than previous best content's
       
   285                         else if (aMediaContents[i]->iBitrate <= iMimeTypes[j].iMaxBitrate &&
       
   286                             (aMediaContents[i]->iHeight > bestContent->iHeight && aMediaContents[i]->iHeight <= iMimeTypes[j].iMaxScreensizeH) &&
       
   287                             aMediaContents[i]->iWidth <= iMimeTypes[j].iMaxScreensizeH &&
       
   288                             aMediaContents[i]->iFramerate <= iMimeTypes[j].iMaxFramerate)                                                        
       
   289                             {
       
   290                             IPTVLOGSTRING_LOW_LEVEL("");
       
   291                             IPTVLOGSTRING_LOW_LEVEL("Best content changed from:");
       
   292                             bestContent->PrintL();      
       
   293 
       
   294                             index = i;
       
   295                             bestContent = aMediaContents[i];
       
   296     
       
   297                             IPTVLOGSTRING_LOW_LEVEL("");
       
   298                             IPTVLOGSTRING_LOW_LEVEL("To:");
       
   299                             bestContent->PrintL();
       
   300                             }                    
       
   301                         // New contents vertical screensize is better that previous best content's
       
   302                         else if (aMediaContents[i]->iBitrate <= iMimeTypes[j].iMaxBitrate &&
       
   303                             aMediaContents[i]->iHeight <= iMimeTypes[j].iMaxScreensizeV &&
       
   304                             (aMediaContents[i]->iWidth > bestContent->iWidth && aMediaContents[i]->iWidth <= iMimeTypes[j].iMaxScreensizeV) &&
       
   305                             aMediaContents[i]->iFramerate <= iMimeTypes[j].iMaxFramerate)                                                        
       
   306                             {
       
   307                             IPTVLOGSTRING_LOW_LEVEL("");
       
   308                             IPTVLOGSTRING_LOW_LEVEL("Best content changed from:");
       
   309                             bestContent->PrintL();      
       
   310                             index = i;
       
   311                             bestContent = aMediaContents[i];
       
   312 
       
   313                             IPTVLOGSTRING_LOW_LEVEL("");
       
   314                             IPTVLOGSTRING_LOW_LEVEL("To:");
       
   315                             bestContent->PrintL();
       
   316                             }
       
   317                         // New contents framerate is better than previous best content's
       
   318                         else if (aMediaContents[i]->iBitrate <= iMimeTypes[j].iMaxBitrate &&
       
   319                             aMediaContents[i]->iHeight <= iMimeTypes[j].iMaxScreensizeV &&
       
   320                             aMediaContents[i]->iWidth <= iMimeTypes[j].iMaxScreensizeH &&
       
   321                             (aMediaContents[i]->iFramerate > bestContent->iFramerate && aMediaContents[i]->iFramerate <= iMimeTypes[j].iMaxFramerate))
       
   322                             {
       
   323                             IPTVLOGSTRING_LOW_LEVEL("");
       
   324                             IPTVLOGSTRING_LOW_LEVEL("Best content changed from:");
       
   325                             bestContent->PrintL();      
       
   326                             index = i;
       
   327                             bestContent = aMediaContents[i];
       
   328 
       
   329                             IPTVLOGSTRING_LOW_LEVEL("");
       
   330                             IPTVLOGSTRING_LOW_LEVEL("To:");
       
   331                             bestContent->PrintL();
       
   332                             }                                                  
       
   333                         }
       
   334                     }
       
   335                 }
       
   336             }                                             
       
   337         }
       
   338        
       
   339     if (bestContent)
       
   340         {
       
   341         return index;
       
   342         }
       
   343     else
       
   344         {
       
   345         return KErrNotFound;
       
   346         }
       
   347     }
       
   348 
       
   349 // End of file