vtprotocolplugins/DisplaySink/src/CDisplaySinkNGA.cpp
changeset 0 ed9695c8bcbe
equal deleted inserted replaced
-1:000000000000 0:ed9695c8bcbe
       
     1 /*
       
     2 * Copyright (c) 2004-2006 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:  Class for CDisplaySinkNGA.
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 
       
    20 #include "CDisplaySinkNGA.h"
       
    21 
       
    22 // MACROS
       
    23 
       
    24 #ifdef _DEBUG
       
    25     #include <e32debug.h>
       
    26     #define PRINT RDebug::Print
       
    27     #define _IFDBG(a) a
       
    28 #else
       
    29     #define PRINT
       
    30     #define _IFDBG(a)
       
    31 #endif
       
    32 
       
    33  static const TUint8 NGA_COFF_TBL_64K[ 220 ]=
       
    34     {
       
    35     0xe9,0x66,0x01,0x00,    // KRedCrFactor
       
    36     0x1a,0x58,0x00,0x00,    // KGreenCbFactor
       
    37     0xd2,0xb6,0x00,0x00,    // KGreenCrFactor
       
    38     0xa2,0xc5,0x01,0x00,    // KBlueCbFactor
       
    39 
       
    40     0x00,0x00,0x00,0x00,    // 5-bit
       
    41     0x00,0x00,0x00,0x00,
       
    42     0x00,0x00,0x00,0x00,
       
    43     0x00,0x00,0x00,0x00,
       
    44     0x00,0x00,0x00,0x00,
       
    45     0x00,0x00,0x00,0x00,
       
    46     0x00,0x01,0x02,0x03,
       
    47     0x04,0x05,0x06,0x07,
       
    48     0x08,0x09,0x0a,0x0b,
       
    49     0x0c,0x0d,0x0e,0x0f,
       
    50     0x10,0x11,0x12,0x13,
       
    51     0x14,0x15,0x16,0x17,
       
    52     0x18,0x19,0x1a,0x1b,
       
    53     0x1c,0x1d,0x1e,0x1f,
       
    54     0x1f,0x1f,0x1f,0x1f,
       
    55     0x1f,0x1f,0x1f,0x1f,
       
    56     0x1f,0x1f,0x1f,0x1f,
       
    57     0x1f,0x1f,0x1f,0x1f,
       
    58     0x1f,0x1f,0x1f,0x1f,
       
    59 
       
    60     0x00,0x00,0x00,0x00,    // 6-bit
       
    61     0x00,0x00,0x00,0x00,
       
    62     0x00,0x00,0x00,0x00,
       
    63     0x00,0x00,0x00,0x00,
       
    64     0x00,0x00,0x00,0x00,
       
    65     0x00,0x01,0x02,0x03,
       
    66     0x04,0x05,0x06,0x07,
       
    67     0x08,0x09,0x0a,0x0b,
       
    68     0x0c,0x0d,0x0e,0x0f,
       
    69     0x10,0x11,0x12,0x13,
       
    70     0x14,0x15,0x16,0x17,
       
    71     0x18,0x19,0x1a,0x1b,
       
    72     0x1c,0x1d,0x1e,0x1f,
       
    73     0x20,0x21,0x22,0x23,
       
    74     0x24,0x25,0x26,0x27,
       
    75     0x28,0x29,0x2a,0x2b,
       
    76     0x2c,0x2d,0x2e,0x2f,
       
    77     0x30,0x31,0x32,0x33,
       
    78     0x34,0x35,0x36,0x37,
       
    79     0x38,0x39,0x3a,0x3b,
       
    80     0x3c,0x3d,0x3e,0x3f,
       
    81     0x3f,0x3f,0x3f,0x3f,
       
    82     0x3f,0x3f,0x3f,0x3f,
       
    83     0x3f,0x3f,0x3f,0x3f,
       
    84     0x3f,0x3f,0x3f,0x3f,
       
    85     0x3f,0x3f,0x3f,0x3f,
       
    86     0x3f,0x3f,0x3f,0x3f,
       
    87     0x3f,0x3f,0x3f,0x3f,
       
    88     0x3f,0x3f,0x3f,0x3f,
       
    89     0x3f,0x3f,0x3f,0x3f,
       
    90     0x3f,0x3f,0x3f,0x3f,
       
    91     0x3f,0x3f,0x3f,0x3f
       
    92     };
       
    93 
       
    94  
       
    95  const TUint8 NGA_COFF_TBL_16M[ 528 ] =
       
    96      {
       
    97      0xe9,0x66,0x01,0x00,    // KRedCrFactor
       
    98      0x1a,0x58,0x00,0x00,    // KGreenCbFactor
       
    99      0xd2,0xb6,0x00,0x00,    // KGreenCrFactor
       
   100      0xa2,0xc5,0x01,0x00,    // KBlueCbFactor
       
   101 
       
   102      0x00,0x00,0x00,0x00,
       
   103      0x00,0x00,0x00,0x00,
       
   104      0x00,0x00,0x00,0x00,
       
   105      0x00,0x00,0x00,0x00,
       
   106 
       
   107      0x00,0x00,0x00,0x00,
       
   108      0x00,0x00,0x00,0x00,
       
   109      0x00,0x00,0x00,0x00,
       
   110      0x00,0x00,0x00,0x00,
       
   111 
       
   112      0x00,0x00,0x00,0x00,
       
   113      0x00,0x00,0x00,0x00,
       
   114      0x00,0x00,0x00,0x00,
       
   115      0x00,0x00,0x00,0x00,
       
   116 
       
   117      0x00,0x00,0x00,0x00,
       
   118      0x00,0x00,0x00,0x00,
       
   119      0x00,0x00,0x00,0x00,
       
   120      0x00,0x00,0x00,0x00,
       
   121 
       
   122      0x00,0x00,0x00,0x00,
       
   123      0x00,0x00,0x00,0x00,
       
   124      0x00,0x00,0x00,0x00,
       
   125      0x00,0x00,0x00,0x00,
       
   126 
       
   127      0x00,0x00,0x00,0x00,
       
   128      0x00,0x00,0x00,0x00,
       
   129      0x00,0x00,0x00,0x00,
       
   130      0x00,0x00,0x00,0x00,
       
   131 
       
   132      0x00,0x00,0x00,0x00,
       
   133      0x00,0x00,0x00,0x00,
       
   134      0x00,0x00,0x00,0x00,
       
   135      0x00,0x00,0x00,0x00,
       
   136 
       
   137      0x00,0x00,0x00,0x00,
       
   138      0x00,0x00,0x00,0x00,
       
   139      0x00,0x00,0x00,0x00,
       
   140      0x00,0x00,0x00,0x00,
       
   141 
       
   142      0x00,0x01,0x02,0x03,    // 8-bit
       
   143      0x04,0x05,0x06,0x07,
       
   144      0x08,0x09,0x0a,0x0b,
       
   145      0x0c,0x0d,0x0e,0x0f,
       
   146 
       
   147      0x10,0x11,0x12,0x13,
       
   148      0x14,0x15,0x16,0x17,
       
   149      0x18,0x19,0x1a,0x1b,
       
   150      0x1c,0x1d,0x1e,0x1f,
       
   151 
       
   152      0x20,0x21,0x22,0x23,
       
   153      0x24,0x25,0x26,0x27,
       
   154      0x28,0x29,0x2a,0x2b,
       
   155      0x2c,0x2d,0x2e,0x2f,
       
   156 
       
   157      0x30,0x31,0x32,0x33,
       
   158      0x34,0x35,0x36,0x37,
       
   159      0x38,0x39,0x3a,0x3b,
       
   160      0x3c,0x3d,0x3e,0x3f,
       
   161 
       
   162      0x40,0x41,0x42,0x43,
       
   163      0x44,0x45,0x46,0x47,
       
   164      0x48,0x49,0x4a,0x4b,
       
   165      0x4c,0x4d,0x4e,0x4f,
       
   166 
       
   167      0x50,0x51,0x52,0x53,
       
   168      0x54,0x55,0x56,0x57,
       
   169      0x58,0x59,0x5a,0x5b,
       
   170      0x5c,0x5d,0x5e,0x5f,
       
   171 
       
   172      0x60,0x61,0x62,0x63,
       
   173      0x64,0x65,0x66,0x67,
       
   174      0x68,0x69,0x6a,0x6b,
       
   175      0x6c,0x6d,0x6e,0x6f,
       
   176 
       
   177      0x70,0x71,0x72,0x73,
       
   178      0x74,0x75,0x76,0x77,
       
   179      0x78,0x79,0x7a,0x7b,
       
   180      0x7c,0x7d,0x7e,0x7f,
       
   181 
       
   182      0x80,0x81,0x82,0x83,
       
   183      0x84,0x85,0x86,0x87,
       
   184      0x88,0x89,0x8a,0x8b,
       
   185      0x8c,0x8d,0x8e,0x8f,
       
   186 
       
   187      0x90,0x91,0x92,0x93,
       
   188      0x94,0x95,0x96,0x97,
       
   189      0x98,0x99,0x9a,0x9b,
       
   190      0x9c,0x9d,0x9e,0x9f,
       
   191 
       
   192      0xa0,0xa1,0xa2,0xa3,
       
   193      0xa4,0xa5,0xa6,0xa7,
       
   194      0xa8,0xa9,0xaa,0xab,
       
   195      0xac,0xad,0xae,0xaf,
       
   196 
       
   197      0xb0,0xb1,0xb2,0xb3,
       
   198      0xb4,0xb5,0xb6,0xb7,
       
   199      0xb8,0xb9,0xba,0xbb,
       
   200      0xbc,0xbd,0xbe,0xbf,
       
   201 
       
   202      0xc0,0xc1,0xc2,0xc3,
       
   203      0xc4,0xc5,0xc6,0xc7,
       
   204      0xc8,0xc9,0xca,0xcb,
       
   205      0xcc,0xcd,0xce,0xcf,
       
   206 
       
   207      0xd0,0xd1,0xd2,0xd3,
       
   208      0xd4,0xd5,0xd6,0xd7,
       
   209      0xd8,0xd9,0xda,0xdb,
       
   210      0xdc,0xdd,0xde,0xdf,
       
   211 
       
   212      0xe0,0xe1,0xe2,0xe3,
       
   213      0xe4,0xe5,0xe6,0xe7,
       
   214      0xe8,0xe9,0xea,0xeb,
       
   215      0xec,0xed,0xee,0xef,
       
   216 
       
   217      0xf0,0xf1,0xf2,0xf3,
       
   218      0xf4,0xf5,0xf6,0xf7,
       
   219      0xf8,0xf9,0xfa,0xfb,
       
   220      0xfc,0xfd,0xfe,0xff,
       
   221 
       
   222      0xff,0xff,0xff,0xff,
       
   223      0xff,0xff,0xff,0xff,
       
   224      0xff,0xff,0xff,0xff,
       
   225      0xff,0xff,0xff,0xff,
       
   226 
       
   227      0xff,0xff,0xff,0xff,
       
   228      0xff,0xff,0xff,0xff,
       
   229      0xff,0xff,0xff,0xff,
       
   230      0xff,0xff,0xff,0xff,
       
   231 
       
   232      0xff,0xff,0xff,0xff,
       
   233      0xff,0xff,0xff,0xff,
       
   234      0xff,0xff,0xff,0xff,
       
   235      0xff,0xff,0xff,0xff,
       
   236 
       
   237      0xff,0xff,0xff,0xff,
       
   238      0xff,0xff,0xff,0xff,
       
   239      0xff,0xff,0xff,0xff,
       
   240      0xff,0xff,0xff,0xff,
       
   241 
       
   242      0xff,0xff,0xff,0xff,
       
   243      0xff,0xff,0xff,0xff,
       
   244      0xff,0xff,0xff,0xff,
       
   245      0xff,0xff,0xff,0xff,
       
   246 
       
   247      0xff,0xff,0xff,0xff,
       
   248      0xff,0xff,0xff,0xff,
       
   249      0xff,0xff,0xff,0xff,
       
   250      0xff,0xff,0xff,0xff,
       
   251 
       
   252      0xff,0xff,0xff,0xff,
       
   253      0xff,0xff,0xff,0xff,
       
   254      0xff,0xff,0xff,0xff,
       
   255      0xff,0xff,0xff,0xff
       
   256      };
       
   257 
       
   258 
       
   259  void ConvertFrom420PlanarToRGB_565(
       
   260          const TDesC8& aSource,
       
   261          const TSize& aSize,
       
   262          TDes8& aTarget,
       
   263          TInt aStride )
       
   264      {
       
   265      TInt height( aSize.iHeight >> 1 );
       
   266      TInt width( aSize.iWidth );
       
   267 
       
   268      TInt ySize = aSize.iWidth * aSize.iHeight;
       
   269      TInt ySizeDiv4 = ( ySize >> 2 );
       
   270 
       
   271      const TUint32* y1 = reinterpret_cast< const TUint32* >( aSource.Mid( 0, ySize ).Ptr() );
       
   272      const TUint32* u = reinterpret_cast< const TUint32* >( aSource.Mid( ySize, ySizeDiv4 ).Ptr() );
       
   273      const TUint32* v = reinterpret_cast< const TUint32* >( aSource.Mid( ySize + ySizeDiv4, ySizeDiv4 ).Ptr() );    
       
   274      
       
   275      TUint32 uintsPerDestRow = aStride >> 2;
       
   276      
       
   277      const TUint32* TargetPtr =  reinterpret_cast< const TUint32* >( aTarget.Ptr() );
       
   278      
       
   279      TUint32* d1 = const_cast< TUint32* >( TargetPtr );    
       
   280      
       
   281      TUint32 ywidth = width >> 2;
       
   282 
       
   283      width >>= 3;
       
   284 
       
   285      TInt32 cb;
       
   286      TInt32 cr;
       
   287      TInt32 greenCbCr;
       
   288      TInt32 yy;
       
   289      TInt32 red;
       
   290      TInt32 green;
       
   291      TInt32 blue;
       
   292      TUint32 r1;
       
   293      const TUint8* clip = NGA_COFF_TBL_64K + 40;
       
   294 
       
   295      for( TInt y = 0; y < height; y++ )
       
   296          {
       
   297          for( TInt x = 0; x < width; x++ )
       
   298              {
       
   299              TUint32 u1 = *u++;
       
   300              TUint32 v1 = *v++;
       
   301 
       
   302              for( TInt c2 = 0; c2 < 2; c2++ )
       
   303                  {
       
   304                  TUint32 yy2 = y1[ ywidth ];
       
   305                  TUint32 yy1 = *y1++;
       
   306 
       
   307                  for( TInt c = 0; c < 2; c++ )
       
   308                      {
       
   309                      cb = TInt32( u1 & 0xff ) - 128;
       
   310                      u1 >>= 8;
       
   311                      cr = TInt32( v1 & 0xff ) - 128;
       
   312                      v1 >>= 8;
       
   313 
       
   314                      greenCbCr =
       
   315                          (
       
   316                          cr * *reinterpret_cast< const TInt32* >( clip - 32 ) +
       
   317                          cb * *reinterpret_cast< const TInt32* >( clip - 36 )
       
   318                          ) >> 16;
       
   319                      cr =
       
   320                          (
       
   321                          cr * *reinterpret_cast< const TInt32* >( clip - 40 )
       
   322                          ) >> 16;
       
   323                      cb =
       
   324                          (
       
   325                          cb * *reinterpret_cast< const TInt32* >( clip - 28 )
       
   326                          ) >> 16;
       
   327 
       
   328                      // lower left
       
   329                      yy = ( yy2 & 0xff );
       
   330                      yy2 >>= 8;
       
   331 
       
   332                      red = yy + cr;
       
   333                      green = yy - greenCbCr;
       
   334                      blue = yy + cb;
       
   335 
       
   336                      red = clip[ red >> 4 ];
       
   337                      green = clip[ green >> 4 ];
       
   338                      blue = clip[ blue >> 4 ];
       
   339 
       
   340                      // RGB_444
       
   341                      r1 = green | ( red << 4 );
       
   342                      r1 = blue | ( r1 << 4 );
       
   343 
       
   344                      // lower right
       
   345                      yy = ( yy2 & 0xff );
       
   346                      yy2 >>= 8;
       
   347 
       
   348                      red = yy + cr;
       
   349                      green = yy - greenCbCr;
       
   350                      blue = yy + cb;
       
   351 
       
   352                      red = clip[ red >> 4 ];
       
   353                      green = clip[ green >> 4 ];
       
   354                      blue = clip[ blue >> 4 ];
       
   355 
       
   356                      // RGB_444
       
   357                      r1 |= ( ( green | ( red << 4 ) ) << 4 | blue ) << 16;
       
   358 
       
   359                      d1[ uintsPerDestRow ] = r1;
       
   360 
       
   361                      // upper left
       
   362                      yy = ( yy1 & 0xff );
       
   363                      yy1 >>= 8;
       
   364 
       
   365                      red = yy + cr;
       
   366                      green = yy - greenCbCr;
       
   367                      blue = yy + cb;
       
   368 
       
   369                      red = clip[ red >> 4 ];
       
   370                      green = clip[ green >> 4 ];
       
   371                      blue = clip[ blue >> 4 ];
       
   372 
       
   373                      // RGB_444
       
   374                      r1 = green | ( red << 4 );
       
   375                      r1 = blue | ( r1 << 4 );
       
   376 
       
   377                      // upper right
       
   378                      yy = ( yy1 & 0xff );
       
   379                      yy1 >>= 8;
       
   380 
       
   381                      red = yy + cr;
       
   382                      green = yy - greenCbCr;
       
   383                      blue = yy + cb;
       
   384 
       
   385                      red = clip[ red >> 4 ];
       
   386                      green = clip[ green >> 4 ];
       
   387                      blue = clip[ blue >> 4 ];
       
   388 
       
   389                      // RGB_444
       
   390                      r1 |= ( ( green | ( red << 4 ) ) << 4 | blue ) << 16;
       
   391 
       
   392                      *d1++ = r1;
       
   393                      }
       
   394                  }
       
   395              }
       
   396 
       
   397          y1 += ( width << 1 );
       
   398          d1 += uintsPerDestRow;
       
   399          }     
       
   400      }
       
   401  
       
   402  
       
   403  void ConvertFrom420PlanarToXRGB_8888(
       
   404           const TDesC8& aSource,
       
   405           const TSize& aSize,
       
   406           TDes8& aTarget,
       
   407           TInt aStride )
       
   408      {
       
   409      
       
   410      TInt height( aSize.iHeight >> 1 );
       
   411      TInt width( aSize.iWidth );
       
   412      
       
   413      TInt ySize = aSize.iWidth * aSize.iHeight;
       
   414      TInt ySizeDiv4 = ( ySize >> 2 );
       
   415 
       
   416      const TUint32* y1 = reinterpret_cast< const TUint32* >( aSource.Mid( 0, ySize ).Ptr() );
       
   417      const TUint32* u = reinterpret_cast< const TUint32* >( aSource.Mid( ySize, ySizeDiv4 ).Ptr() );
       
   418      const TUint32* v = reinterpret_cast< const TUint32* >( aSource.Mid( ySize + ySizeDiv4, ySizeDiv4 ).Ptr() );
       
   419      
       
   420      TUint32 uintsPerDestRow = aStride >> 2;
       
   421 
       
   422      const TUint32* TargetPtr =  reinterpret_cast< const TUint32* >( aTarget.Ptr() );
       
   423      
       
   424      TUint32* d1 = const_cast< TUint32* >( TargetPtr );    
       
   425 
       
   426 
       
   427      TUint32 ywidth = width >> 2;
       
   428 
       
   429      width >>= 3;
       
   430 
       
   431      TInt32 cb;
       
   432      TInt32 cr;
       
   433      TInt32 greenCbCr;
       
   434      TInt32 yy;
       
   435      TUint32 p;
       
   436      const TUint8* clip = NGA_COFF_TBL_16M + 144;
       
   437 
       
   438      for( TInt y = 0; y < height; y++ )
       
   439          {
       
   440          for( TInt x = 0; x < width; x++ )
       
   441              {
       
   442              TUint32 u1 = *u++;
       
   443              TUint32 v1 = *v++;
       
   444 
       
   445              for( TInt c2 = 0; c2 < 2; c2++ )
       
   446                  {
       
   447                  TUint32 yy2 = y1[ ywidth ];
       
   448                  TUint32 yy1 = *y1++;
       
   449 
       
   450                  for( TInt c = 0; c < 2; c++ )
       
   451                      {
       
   452                      cb = TInt32( u1 & 0xff ) - 128;
       
   453                      u1 >>= 8;
       
   454                      cr = TInt32( v1 & 0xff ) - 128;
       
   455                      v1 >>= 8;
       
   456 
       
   457                      greenCbCr =
       
   458                          (
       
   459                          cr * *reinterpret_cast< const TInt32* >( clip - 136 ) +
       
   460                          cb * *reinterpret_cast< const TInt32* >( clip - 140 )
       
   461                          ) >> 16;
       
   462                      cr =
       
   463                          (
       
   464                          cr * *reinterpret_cast< const TInt32* >( clip - 144 )
       
   465                          ) >> 16;
       
   466                      cb =
       
   467                          (
       
   468                          cb * *reinterpret_cast< const TInt32* >( clip - 132 )
       
   469                          ) >> 16;
       
   470 
       
   471                      // lower left
       
   472                      yy = ( yy2 & 0xff );
       
   473                      yy2 >>= 8;
       
   474 
       
   475                      // 0xffBBGG
       
   476                      p = 0xff0000 |
       
   477                          ( clip[ yy + cr ] << 8 ) | clip[ yy - greenCbCr ];
       
   478                      // 0xffBBGGRR
       
   479                      d1[ uintsPerDestRow ] = clip[ yy + cb ] | ( p << 8 );
       
   480 
       
   481                      // lower right
       
   482                      yy = ( yy2 & 0xff );
       
   483                      yy2 >>= 8;
       
   484 
       
   485                      // 0xffBBGG
       
   486                      p = 0xff0000 |
       
   487                          ( clip[ yy + cr ] << 8 ) | clip[ yy - greenCbCr ];
       
   488                      // 0xffBBGGRR
       
   489                      d1[ uintsPerDestRow + 1 ] = clip[ yy + cb ] | ( p << 8 );
       
   490 
       
   491                      // upper left
       
   492                      yy = ( yy1 & 0xff );
       
   493                      yy1 >>= 8;
       
   494 
       
   495                      // 0xffBBGG
       
   496                      p = 0xff0000 |
       
   497                          ( clip[ yy + cr ] << 8 ) | clip[ yy - greenCbCr ];
       
   498                      // 0xffBBGGRR
       
   499                      *d1++ = clip[ yy + cb ] | ( p << 8 );
       
   500 
       
   501                      // upper right
       
   502                      yy = ( yy1 & 0xff );
       
   503                      yy1 >>= 8;
       
   504 
       
   505                      // 0xffBBGG
       
   506                      p = 0xff0000 |
       
   507                          ( clip[ yy + cr ] << 8 ) | clip[ yy - greenCbCr ];
       
   508                      // 0xffBBGGRR
       
   509                      *d1++ = clip[ yy + cb ] | ( p << 8 );
       
   510                      }
       
   511                  }
       
   512              }
       
   513 
       
   514          y1 += ( width << 1 );
       
   515          d1 += uintsPerDestRow;
       
   516          }  
       
   517      
       
   518      }
       
   519   
       
   520 
       
   521 // -----------------------------------------------------------------------------
       
   522 // CDisplaySinkNGA::NewL
       
   523 // -----------------------------------------------------------------------------
       
   524 //
       
   525 CDisplaySinkNGA* CDisplaySinkNGA::NewL( TDisplaySinkParams& aParams,
       
   526         const TDesC8& aInitData )
       
   527     {
       
   528     _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkNGA::NewL()<"), RThread().Id().operator TUint()));
       
   529     CDisplaySinkNGA* self = new ( ELeave ) CDisplaySinkNGA();
       
   530     CleanupStack::PushL( self );
       
   531     self->ConstructL( aParams, aInitData );
       
   532     CleanupStack::Pop(); // self
       
   533     _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkNGA::NewL()>"), RThread().Id().operator TUint()));
       
   534     return self;
       
   535     }
       
   536 
       
   537 // -----------------------------------------------------------------------------
       
   538 // CDisplaySinkNGA::CDisplaySinkNGA
       
   539 // -----------------------------------------------------------------------------
       
   540 //
       
   541 CDisplaySinkNGA::CDisplaySinkNGA()
       
   542     {
       
   543     _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkNGA::Ctor<"), RThread().Id().operator TUint()));
       
   544     _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkNGA::Ctor>"), RThread().Id().operator TUint()));
       
   545     }
       
   546 
       
   547 // -----------------------------------------------------------------------------
       
   548 // CDisplaySinkNGA::~CDisplaySinkNGA
       
   549 // -----------------------------------------------------------------------------
       
   550 //
       
   551 CDisplaySinkNGA::~CDisplaySinkNGA()
       
   552     {
       
   553     _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkNGA::~<"), RThread().Id().operator TUint()));
       
   554     _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkNGA::~>"), RThread().Id().operator TUint()));
       
   555     }
       
   556 
       
   557 // -----------------------------------------------------------------------------
       
   558 // CDisplaySinkNGA::BaseConstructL
       
   559 // -----------------------------------------------------------------------------
       
   560 //
       
   561 void CDisplaySinkNGA::BaseConstructL( TDisplaySinkParams& aParams,
       
   562     const TDesC8& )
       
   563     {
       
   564     _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkNGA::BaseConstructL()<"), RThread().Id().operator TUint()));
       
   565     iNewParams = static_cast< const TDisplaySinkParamsNGA& >( aParams );
       
   566     if ( !iNewParams.iSurfaceBuffer1 || !iNewParams.iSurfaceBuffer2 )
       
   567         {
       
   568         _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkNGA::BaseConstructL() surface buffer is NULL!")));
       
   569         User::Leave( KErrArgument );
       
   570         }
       
   571     iBitmapTable[EFirstBitmap].iBuffer = iNewParams.iSurfaceBuffer1;
       
   572     iBitmapTable[ESecondBitmap].iBuffer = iNewParams.iSurfaceBuffer2;    
       
   573     _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkNGA::BaseConstructL()>"), RThread().Id().operator TUint()));
       
   574     }
       
   575 
       
   576 // -----------------------------------------------------------------------------
       
   577 // CDisplaySinkNGA::BaseConvert
       
   578 // -----------------------------------------------------------------------------
       
   579 //
       
   580 TBool CDisplaySinkNGA::BaseConvert( const TVtMMFDataBuffer& aBuffer )
       
   581     {
       
   582     _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkNGA::BaseConvert()<"), RThread().Id().operator TUint()));
       
   583     
       
   584     TBool consumed( ETrue );
       
   585     TBitmapNo bitmapNo( iBitmapTable[ EFirstBitmap ].iIsFree ? EFirstBitmap : ESecondBitmap );
       
   586     if ( iBitmapTable[ bitmapNo ].iIsFree &&
       
   587          !iReleased &&
       
   588          ( *iRequestStatusPtr == KRequestPending ) )
       
   589         {
       
   590 #if 1        
       
   591         TInt bufferLength(
       
   592              //iNewParams.iFrameSize.iHeight * ( iNewParams.iFrameSize.iWidth * 2 ) );
       
   593              iNewParams.iFrameSize.iHeight * ( iNewParams.iFrameSize.iWidth * 3/2 ) );
       
   594 #else
       
   595         TInt bufferLength(
       
   596              iNewParams.iFrameSize.iHeight * ( iNewParams.iFrameSize.iWidth * 4 ) );
       
   597 #endif             
       
   598 
       
   599         TPtr8 ptrBuffer(
       
   600                 *iBitmapTable[ bitmapNo ].iBuffer,
       
   601             bufferLength,
       
   602             bufferLength
       
   603             );
       
   604 
       
   605         _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkNGA::BaseConvert(): buffer %d: $%x %d bytes"), RThread().Id().operator TUint(), bitmapNo, *iBitmapTable[ bitmapNo ].iBuffer, bufferLength));
       
   606 
       
   607         // Determine wether to convert or copy (420 will be just copied)
       
   608         //if ( iNewParams.iSurfaceFormat ==  EUidPixelFormatRGB_565 )
       
   609         if ( iNewParams.iSurfaceFormat ==  EUidPixelFormatXRGB_8888 )
       
   610             {
       
   611             _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkNGA::BaseConvert(): converting to RGB565"), RThread().Id().operator TUint()));
       
   612 
       
   613             /*
       
   614             ConvertFrom420PlanarToRGB_565(
       
   615                     aBuffer.Data(),
       
   616                     aBuffer.GetFrameSize(),
       
   617                     ptrBuffer,
       
   618                     iNewParams.iFrameSize.iWidth * 2 );
       
   619                     */
       
   620             
       
   621             ConvertFrom420PlanarToXRGB_8888(
       
   622                     aBuffer.Data(),
       
   623                     aBuffer.GetFrameSize(),
       
   624                     ptrBuffer,
       
   625                     iNewParams.iFrameSize.iWidth * 4 );
       
   626             
       
   627             }
       
   628         else
       
   629             {
       
   630             _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkNGA::BaseConvert(): copying as 420"), RThread().Id().operator TUint()));
       
   631             ptrBuffer = aBuffer.Data();
       
   632             }
       
   633 
       
   634         iBitmapTable[ bitmapNo ].iIsFree = EFalse;
       
   635         TRequestStatus* statusP = iRequestStatusPtr;
       
   636         iThread.RequestComplete( statusP, bitmapNo );
       
   637         }
       
   638     else
       
   639         {
       
   640         consumed = EFalse;
       
   641         _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkNGA::BaseConvert(): could not find free buffer"), RThread().Id().operator TUint()));
       
   642         }
       
   643     _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkNGA::BaseConvert()>"), RThread().Id().operator TUint()));
       
   644     return consumed;
       
   645 
       
   646     }
       
   647 
       
   648 // -----------------------------------------------------------------------------
       
   649 // CDisplaySinkNGA::BaseSinkThreadLogonL
       
   650 // -----------------------------------------------------------------------------
       
   651 //
       
   652 void CDisplaySinkNGA::BaseSinkThreadLogonL()
       
   653     {
       
   654     _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkNGA::BaseSinkThreadLogonL()<"), RThread().Id().operator TUint()));
       
   655     UpdateExpectedFrameSizeL();
       
   656     _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkNGA::BaseSinkThreadLogonL()>"), RThread().Id().operator TUint()));
       
   657     }
       
   658 
       
   659 // -----------------------------------------------------------------------------
       
   660 // CDisplaySinkNGA::BaseSinkThreadLogoff
       
   661 // -----------------------------------------------------------------------------
       
   662 //
       
   663 void CDisplaySinkNGA::BaseSinkThreadLogoff()
       
   664     {
       
   665     _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkNGA::BaseSinkThreadLogoff()<"), RThread().Id().operator TUint()));
       
   666     _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkNGA::BaseSinkThreadLogoff()>"), RThread().Id().operator TUint()));
       
   667     }
       
   668 
       
   669 // -----------------------------------------------------------------------------
       
   670 // CDisplaySinkNGA::BaseUpdateSinkParamsL
       
   671 // -----------------------------------------------------------------------------
       
   672 //
       
   673 void CDisplaySinkNGA::BaseUpdateSinkParamsL( const TDisplaySinkParams& aParams )
       
   674     {
       
   675     _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkNGA::BaseUpdateSinkParamsL()<"), RThread().Id().operator TUint()));
       
   676     iNewParams = static_cast< const TDisplaySinkParamsNGA& >( aParams );
       
   677     _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkNGA::BaseUpdateSinkParamsL()>"), RThread().Id().operator TUint()));
       
   678     }
       
   679 
       
   680 // -----------------------------------------------------------------------------
       
   681 // CDisplaySinkNGA::BaseDoUpdateParamsL
       
   682 // -----------------------------------------------------------------------------
       
   683 //
       
   684 void CDisplaySinkNGA::BaseDoUpdateParamsL()
       
   685     {
       
   686     _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkNGA::BaseDoUpdateParamsL()<"), RThread().Id().operator TUint()));
       
   687     iBitmapTable[ EFirstBitmap ].iBuffer = iNewParams.iSurfaceBuffer1;
       
   688     iBitmapTable[ ESecondBitmap ].iBuffer = iNewParams.iSurfaceBuffer2;
       
   689     UpdateExpectedFrameSizeL();
       
   690     if( iNewParams.iFrameRateLimit != iFrameRateInterval )
       
   691         {
       
   692         SetFrameRateLimit( iNewParams.iFrameRateLimit );
       
   693         ResetFrameRateLimitter();
       
   694         }    
       
   695     _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkNGA::BaseDoUpdateParamsL()>"), RThread().Id().operator TUint()));
       
   696     }
       
   697 
       
   698 // -----------------------------------------------------------------------------
       
   699 // CDisplaySinkNGA::BaseSetVideoFrameSizeL
       
   700 // -----------------------------------------------------------------------------
       
   701 //
       
   702 void CDisplaySinkNGA::BaseSetVideoFrameSizeL( const TSize& )
       
   703     {
       
   704     _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkNGA::BaseSetVideoFrameSizeL()<"), RThread().Id().operator TUint()));
       
   705     _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkNGA::BaseSetVideoFrameSizeL()>"), RThread().Id().operator TUint()));
       
   706     }
       
   707 
       
   708 // -----------------------------------------------------------------------------
       
   709 // CDisplaySinkNGA::BaseSizesMatch
       
   710 // -----------------------------------------------------------------------------
       
   711 //
       
   712 TBool CDisplaySinkNGA::BaseSizesMatch( const TSize& aSize)
       
   713     {
       
   714     _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkNGA::BaseSizesMatch()<"), RThread().Id().operator TUint()));
       
   715     TBool sizesMatch( iExpectedFrameSize == aSize );
       
   716     _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkNGA::BaseSizesMatch()>"), RThread().Id().operator TUint()));
       
   717     return sizesMatch;
       
   718     }
       
   719 
       
   720 // -----------------------------------------------------------------------------
       
   721 // CDisplaySinkNGA::BitmapEntry
       
   722 // -----------------------------------------------------------------------------
       
   723 //
       
   724 CDisplaySink::TBitmapEntry& CDisplaySinkNGA::BitmapEntry( TInt aIndex )
       
   725     {
       
   726     _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkNGA::BitmapEntry(%d)<"), RThread().Id().operator TUint(), aIndex));
       
   727     _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkNGA::BitmapEntry()>"), RThread().Id().operator TUint()));
       
   728     return iBitmapTable[ aIndex ];
       
   729     }
       
   730 
       
   731 // -----------------------------------------------------------------------------
       
   732 // CDisplaySinkNGA::BaseEmptyBufferL
       
   733 // -----------------------------------------------------------------------------
       
   734 //
       
   735 void CDisplaySinkNGA::BaseEmptyBufferL( TVtMMFDataBuffer& aVTMMFBuffer )
       
   736     {
       
   737     _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkNGA::BaseEmptyBufferL()<"), RThread().Id().operator TUint()));
       
   738     if ( BaseConvert( aVTMMFBuffer ) )
       
   739         {
       
   740         CleanupStack::PopAndDestroy(); // iBitmapCS.Signal();
       
   741         iSupplier->BufferEmptiedL( iBuffer );
       
   742         }
       
   743     else
       
   744         {
       
   745         if ( iVideoFrameQueue->IsStored() || !IsOkToSendFrame() )
       
   746             {
       
   747             CleanupStack::PopAndDestroy(); // iBitmapCS.Signal();
       
   748             iSupplier->BufferEmptiedL( iBuffer );
       
   749             }
       
   750         else
       
   751             {
       
   752             iVideoFrameQueue->Store( *iSupplier, static_cast<CMMFDataBuffer*>(aVTMMFBuffer.GetMMFBuffer()),  aVTMMFBuffer.GetFrameSize(), aVTMMFBuffer.Data());
       
   753             CleanupStack::PopAndDestroy(); // iBitmapCS.Signal();
       
   754             }
       
   755         }    
       
   756     _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkNGA::BaseEmptyBufferL()>"), RThread().Id().operator TUint()));
       
   757     }
       
   758 
       
   759 // -----------------------------------------------------------------------------
       
   760 // CDisplaySinkNGA::BaseSetBitmapAvailable( TBitmapNo aBitmapNo )
       
   761 // -----------------------------------------------------------------------------
       
   762 //
       
   763 void CDisplaySinkNGA::BaseSetBitmapAvailable( TBitmapNo )
       
   764     {
       
   765     _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkNGA::BaseSetBitmapAvailable()<"), RThread().Id().operator TUint()));
       
   766     if ( iVideoFrameQueue->IsStored() )
       
   767         {
       
   768         if ( IsOkToSendFrame() )
       
   769             {
       
   770             BaseConvert( iVideoFrameQueue->Buffer() );
       
   771             }
       
   772         iVideoFrameQueue->Release();
       
   773         }       
       
   774     _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkNGA::BaseSetBitmapAvailable()>"), RThread().Id().operator TUint()));
       
   775     }
       
   776 
       
   777 // -----------------------------------------------------------------------------
       
   778 // CDisplaySinkNGA::BaseVideoFrameSizeChangedL( const TSize& )
       
   779 // -----------------------------------------------------------------------------
       
   780 //
       
   781 void CDisplaySinkNGA::BaseVideoFrameSizeChangedL( const TSize& )
       
   782     {
       
   783     _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkNGA::BaseVideoFrameSizeChangedL()<"), RThread().Id().operator TUint()));
       
   784     _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkNGA::BaseVideoFrameSizeChangedL()>"), RThread().Id().operator TUint()));
       
   785     }
       
   786 
       
   787 // -----------------------------------------------------------------------------
       
   788 // CDisplaySinkNGA::NextFrame
       
   789 // -----------------------------------------------------------------------------
       
   790 //
       
   791 void CDisplaySinkNGA::NextFrame()
       
   792     {
       
   793     _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkNGA::NextFrame()<"), RThread().Id().operator TUint()));
       
   794     iBitmapCS.Wait();
       
   795     if ( iVideoFrameQueue->IsStored() )
       
   796         {
       
   797         if ( IsOkToSendFrame() )
       
   798             {
       
   799             BaseConvert( iVideoFrameQueue->Buffer() );
       
   800             }
       
   801         iVideoFrameQueue->Release();
       
   802         }    
       
   803     iBitmapCS.Signal();
       
   804     _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkNGA::NextFrame()>"), RThread().Id().operator TUint()));
       
   805     }
       
   806 
       
   807 // -----------------------------------------------------------------------------
       
   808 // CDisplaySinkDP::UpdateExpectedFrameSizeL()
       
   809 // -----------------------------------------------------------------------------
       
   810 //
       
   811 void CDisplaySinkNGA::UpdateExpectedFrameSizeL()
       
   812     {
       
   813     _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkNGA::UpdateExpectedFrameSizeL()<"), RThread().Id().operator TUint()));
       
   814     iExpectedFrameSize = iNewParams.iFrameSize;
       
   815     _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkNGA::UpdateExpectedFrameSizeL()>"), RThread().Id().operator TUint()));
       
   816     }
       
   817 
       
   818 // End of File