vidsurf2.cpp
上传用户:zhongxx05
上传日期:2007-06-06
资源大小:33641k
文件大小:11k
源码类别:

Symbian

开发平台:

C/C++

  1. /* ***** BEGIN LICENSE BLOCK ***** 
  2.  * Version: RCSL 1.0/RPSL 1.0 
  3.  *  
  4.  * Portions Copyright (c) 1995-2002 RealNetworks, Inc. All Rights Reserved. 
  5.  *      
  6.  * The contents of this file, and the files included with this file, are 
  7.  * subject to the current version of the RealNetworks Public Source License 
  8.  * Version 1.0 (the "RPSL") available at 
  9.  * http://www.helixcommunity.org/content/rpsl unless you have licensed 
  10.  * the file under the RealNetworks Community Source License Version 1.0 
  11.  * (the "RCSL") available at http://www.helixcommunity.org/content/rcsl, 
  12.  * in which case the RCSL will apply. You may also obtain the license terms 
  13.  * directly from RealNetworks.  You may not use this file except in 
  14.  * compliance with the RPSL or, if you have a valid RCSL with RealNetworks 
  15.  * applicable to this file, the RCSL.  Please see the applicable RPSL or 
  16.  * RCSL for the rights, obligations and limitations governing use of the 
  17.  * contents of the file.  
  18.  *  
  19.  * This file is part of the Helix DNA Technology. RealNetworks is the 
  20.  * developer of the Original Code and owns the copyrights in the portions 
  21.  * it created. 
  22.  *  
  23.  * This file, and the files included with this file, is distributed and made 
  24.  * available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 
  25.  * EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS ALL SUCH WARRANTIES, 
  26.  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS 
  27.  * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 
  28.  * 
  29.  * Technology Compatibility Kit Test Suite(s) Location: 
  30.  *    http://www.helixcommunity.org/content/tck 
  31.  * 
  32.  * Contributor(s): 
  33.  *  
  34.  * ***** END LICENSE BLOCK ***** */ 
  35. #include "hxcom.h"
  36. #include "hxtypes.h"
  37. #include "hxwintyp.h"
  38. #include "hxthread.h"
  39. #include "basesite.h"
  40. #if defined(_WINDOWS)
  41. #include "winsurf.h"
  42. #if defined (HELIX_FEATURE_VS2)
  43. #include "winsurf2.h"
  44. #endif
  45. #include "winroot.h" // must be included before colormap.h
  46. #endif
  47. #include "vidsurf2.h"
  48. #include "colormap.h"
  49. CVideoSurface2::CVideoSurface2(IUnknown* pIUnkOuter)
  50.  :  m_pIUnknown(pIUnkOuter)
  51. {
  52. }
  53. CVideoSurface2::~CVideoSurface2()
  54. {
  55. }
  56. STDMETHODIMP CVideoSurface2::QueryInterface(REFIID riid, void** ppvObj)
  57. {
  58.     if (IsEqualIID(riid, IID_IHXVideoSurface2))
  59.     {
  60.         m_pIUnknown->AddRef();
  61.         *ppvObj = (IUnknown*)(IHXVideoSurface2*)this;
  62.         return HXR_OK;
  63.     }
  64.    
  65.     *ppvObj = NULL;
  66.     return HXR_NOINTERFACE;
  67. }
  68. STDMETHODIMP_(ULONG32) CVideoSurface2::AddRef()
  69. {
  70.     return m_pIUnknown->AddRef();
  71. }
  72. STDMETHODIMP_(ULONG32) CVideoSurface2::Release()
  73. {
  74.     return m_pIUnknown->Release();
  75. }
  76. STDMETHODIMP CVideoSurface2::SetProperties(HXBitmapInfoHeader* pRequest,
  77.                                           REF(UINT32) ulNumBuffers,
  78.                                           IHXRenderTimeLine* pTimeLine)
  79. {
  80.     return HXR_NOTIMPL;
  81. }
  82. STDMETHODIMP CVideoSurface2::GetVideoMem(VideoMemStruct* pVidMem,
  83.                                         UINT32 ulFlags)
  84. {
  85.     return HXR_NOTIMPL;
  86. }
  87. STDMETHODIMP CVideoSurface2::ReleaseVideoMem(VideoMemStruct* pVidMem)
  88. {
  89.     return HXR_NOTIMPL;
  90. }
  91. STDMETHODIMP CVideoSurface2::Present(VideoMemStruct* pVidMem,
  92.                                     INT32 lTime,
  93.                                     UINT32 ulFlags,
  94.                                     HXxRect* prDestRect,
  95.                                     HXxRect* prSrcRect)
  96.                                    
  97. {
  98.     return HXR_NOTIMPL;
  99. }
  100. STDMETHODIMP CVideoSurface2::ColorConvert(INT32    fourCCIn, 
  101.                                          HXxSize *pSrcSize,
  102.                                          HXxRect *prSrcRect,
  103.                                          SourceInputStruct *pInput,
  104.                                          INT32    fourCCOut,
  105.                                          UCHAR   *pDestBuffer, 
  106.                                          HXxSize *pDestSize, 
  107.                                          HXxRect *prDestRect, 
  108.                                          int      nDestPitch)
  109. {
  110.     BOOL bConverter = FALSE;
  111.     BOOL bConverter2 = FALSE;
  112.     HXBitmapInfoHeader bmiFrame;
  113.     UCHAR* pucBuff   = NULL;
  114.     UCHAR* pucYFrame = NULL;
  115.     UCHAR* pucUFrame = NULL;
  116.     UCHAR* pucVFrame = NULL;
  117.     UINT32 nYFramePitch = 0;
  118.     UINT32 nUFramePitch = 0;
  119.     UINT32 nVFramePitch = 0;
  120.     UINT32 nFrameWidth  = 0;
  121.     UINT32 nFrameHeight = 0;
  122.     
  123.     HX_ASSERT( pDestBuffer );
  124.     if (!pInput || pInput->nNumInputs < 1 || !pDestBuffer)
  125.         return HXR_INVALID_PARAMETER;
  126.     int nRet   = -1;
  127.     int cIdIn  = MapFourCCtoCID(fourCCIn);
  128.     int cIdOut = MapFourCCtoCID(fourCCOut);
  129.     CHXBaseSite* pSite = GetSite();
  130.     //Set up input frame pointers for padded and non-padded data
  131.     pucYFrame    = pInput->aSrcInput[0];
  132.     nYFramePitch = pInput->aSrcPitch[0];
  133.     if( pInput->nNumInputs > 1)
  134.     {
  135.         pucUFrame    = pInput->aSrcInput[1];
  136.         nUFramePitch = pInput->aSrcPitch[1];
  137.         pucVFrame    = pInput->aSrcInput[2];
  138.         nVFramePitch = pInput->aSrcPitch[2];
  139.     }
  140.     nFrameWidth  = pSrcSize->cx;
  141.     nFrameHeight = pSrcSize->cy;
  142.     // RGB values are CIDs not FourCCs
  143.     if (CID_UNKNOWN == cIdIn)
  144.         cIdIn = fourCCIn;
  145.     if (CID_UNKNOWN == cIdOut)
  146.         cIdOut = fourCCOut;
  147.     //Grab the converters....
  148.     if( pInput->nNumInputs > 1 )
  149.     {
  150.         //grab the padded converters...
  151.         bConverter2 = GetColorConverter2(cIdIn, cIdOut);
  152.     }
  153.     else
  154.     {
  155.         //grab the non padded converters...
  156.         bConverter = GetColorConverter(cIdIn, cIdOut);
  157.     }
  158.     
  159.     //If we don't have a color converter then we need to do a 2 step process.
  160.     //we will do cIdIn-->I420-->cIdOut.
  161.     if( !bConverter && !bConverter2 )
  162.     {
  163.         // If we don't have a converter to match the source, do an AU
  164.         // otherwise, continue with the 2 step.
  165.         bConverter = GetColorConverter(cIdIn, cIdOut);
  166.         if (!bConverter)
  167.         {
  168.             pSite->ColorConverterRequest(cIdIn, cIdOut, bConverter);
  169.             return HXR_FAILED;
  170.         }
  171.         
  172.         int nResult     = 0;
  173.         int nFramePitch = 0;
  174.         
  175. #ifdef _WIN32
  176.         nResult = MakeBitmap( (LPBITMAPINFO)&bmiFrame,
  177.                               sizeof(bmiFrame),
  178.                               CID_I420,
  179.                               prDestRect->right - prDestRect->left,
  180.                               prDestRect->bottom - prDestRect->top,
  181.                               NULL,
  182.                               0);
  183. #else
  184.         nResult = MakeBitmap( (HXBitmapInfo*)&bmiFrame,
  185.                               sizeof(bmiFrame),
  186.                               CID_I420,
  187.                               prDestRect->right - prDestRect->left,
  188.                               prDestRect->bottom - prDestRect->top,
  189.                               NULL,
  190.                               0);
  191. #endif
  192.         HX_ASSERT( nResult != 0 );
  193.         pucBuff      = (UCHAR*)new char[bmiFrame.biSizeImage*sizeof(UCHAR)];
  194.         nFramePitch  = GETBITMAPPITCH( &bmiFrame );
  195.         nFrameWidth  = bmiFrame.biWidth;
  196.         nFrameHeight = bmiFrame.biHeight;
  197.         HXxSize size   = { nFrameWidth, nFrameHeight };
  198.         HXxRect destRc = { prDestRect->left,
  199.                            prDestRect->top,
  200.                            prDestRect->right-prDestRect->left,
  201.                            prDestRect->bottom-prDestRect->top };
  202.         
  203.         nResult = ColorConvert( fourCCIn,
  204.                                 pSrcSize,
  205.                                 prSrcRect,
  206.                                 pInput,
  207.                                 MAKEFOURCC('I','4','2','0'),
  208.                                 pucBuff,
  209.                                 &size,
  210.                                 &destRc,
  211.                                 GETBITMAPPITCH( &bmiFrame )
  212.                                 );
  213.         if( nResult < 0 )
  214.         {
  215.             HX_VECTOR_DELETE( pucBuff );
  216.             return HXR_FAILED;
  217.         }
  218.         //change pointers for 2nd stage below.....
  219.         if( pInput->nNumInputs > 1 )
  220.         {
  221.             bConverter2 = GetColorConverter2(CID_I420, cIdOut);
  222.             cIdIn        = CID_I420;
  223.             pucYFrame    = pucBuff;
  224.             nYFramePitch = nFramePitch;
  225.         }
  226.         else
  227.         {
  228.             bConverter = GetColorConverter(CID_I420, cIdOut);
  229.             cIdIn        = CID_I420;
  230.             pucYFrame    = pucBuff;
  231.             nYFramePitch = nFramePitch;
  232.         }
  233.     }
  234.     //
  235.     // Normal 1-stage converts....
  236.     //
  237.     if (bConverter2 )
  238.     {
  239.         nRet = ColorConvert2( cIdOut, 
  240.                               pDestBuffer,
  241.                               pDestSize->cx, pDestSize->cy,
  242.                               nDestPitch,
  243.                               prDestRect->left, prDestRect->top, 
  244.                               prDestRect->right-prDestRect->left,
  245.                               prDestRect->bottom-prDestRect->top,
  246.                               cIdIn,
  247.                               pucYFrame,
  248.                               pucUFrame,
  249.                               pucVFrame,
  250.                               nFrameWidth, nFrameHeight,
  251.                               nYFramePitch,
  252.                               nUFramePitch,
  253.                               nVFramePitch,
  254.                               prSrcRect->left, prSrcRect->top, 
  255.                               prSrcRect->right-prSrcRect->left,
  256.                               prSrcRect->bottom-prSrcRect->top
  257.                             );
  258.     }
  259.     else if( bConverter )
  260.     {
  261.         nRet = ColorConvert( cIdOut,
  262.                              pDestBuffer,
  263.                              pDestSize->cx, pDestSize->cy,
  264.                              nDestPitch,
  265.                              prDestRect->left, prDestRect->top,
  266.                              prDestRect->right-prDestRect->left, 
  267.                              prDestRect->bottom-prDestRect->top,
  268.                              cIdIn,
  269.                              pucYFrame,
  270.                              nFrameWidth, nFrameHeight,
  271.                              nYFramePitch,
  272.                              prSrcRect->left, prSrcRect->top,
  273.                              prSrcRect->right-prSrcRect->left, 
  274.                              prSrcRect->bottom-prSrcRect->top
  275.                            );
  276.     }
  277.     HX_VECTOR_DELETE( pucBuff );
  278.     if (nRet == -1)
  279.         return HXR_FAILED;
  280.     
  281.     return HXR_OK;
  282. }
  283. STDMETHODIMP_(void) CVideoSurface2::Flush()
  284. {
  285. }
  286. STDMETHODIMP CVideoSurface2::PresentIfReady()
  287. {
  288.     return HXR_NOTIMPL;
  289. }