vidsurf2.cpp
上传用户:dangjiwu
上传日期:2013-07-19
资源大小:42019k
文件大小:11k
源码类别:

Symbian

开发平台:

Visual C++

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