[prev in list] [next in list] [prev in thread] [next in thread] 

List:       helix-video-cvs
Subject:    [Video-cvs] sitelib basesite.cpp,1.32,1.33 basesurf.cpp,1.23,1.24
From:       cdunn () helixcommunity ! org
Date:       2006-04-11 22:30:56
[Download RAW message or body]

Update of /cvsroot/video/sitelib
In directory cvs02.internal.helixcommunity.org:/tmp/cvs-serv31417

Modified Files:
	basesite.cpp basesurf.cpp 
Log Message:
Add IHXSiteCapture

Index: basesurf.cpp
===================================================================
RCS file: /cvsroot/video/sitelib/basesurf.cpp,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- basesurf.cpp	17 Jan 2006 19:37:24 -0000	1.23
+++ basesurf.cpp	11 Apr 2006 22:30:54 -0000	1.24
@@ -2389,7 +2389,126 @@
     return ret;
 }
 
+void
+CBaseSurface::CaptureImage(UCHAR* pImageData, HXBitmapInfoHeader* pBitmapInfo)
+{
+    if (m_pSite && m_pSite->m_pCaptureResponse != NULL &&
+	pImageData != NULL && pBitmapInfo != NULL)
+    {
+	// Capture this frame and send it via IHXCaptureResponse
+	HX_RESULT res=HXR_OK;
+	HXBitmapInfoHeader bmiCaptureFormat;
+	INT32 dWidth, dHeight;
+	INT32 nSrcCID = GETBITMAPCOLOR(pBitmapInfo);
+	INT32 nDestCID;
+	HXBOOL bConvert=FALSE;
+
+	memset( &bmiCaptureFormat, 0, sizeof(bmiCaptureFormat) );
+
+	// Set the size
+	if (m_pSite->m_captureSize.cx == 0 || m_pSite->m_captureSize.cy == 0)
+	{
+	    dWidth = pBitmapInfo->biWidth;
+	    dHeight = pBitmapInfo->biHeight;
+	}
+	else
+	{
+	    dWidth = m_pSite->m_captureSize.cx;
+	    dHeight = m_pSite->m_captureSize.cy;
+	}
+
+	// Set the CID
+	if (m_pSite->m_dCaptureCID != CID_UNKNOWN)
+	{
+	    nDestCID = m_pSite->m_dCaptureCID;
+	}
+	else
+	{
+	    nDestCID = nSrcCID;
+	}
+
+	// Set the capture format
+	int nResult     = 0;
+#ifdef _WIN32
+	nResult = MakeBitmap( (LPBITMAPINFO)&bmiCaptureFormat,
+	    sizeof(bmiCaptureFormat),
+	    nDestCID,
+	    dWidth,
+	    dHeight,
+	    NULL,
+	    0);
+#else
+	nResult = MakeBitmap( (HXBitmapInfo*)&bmiCaptureFormat,
+	    sizeof(bmiCaptureFormat),
+	    nDestCID,
+	    dWidth,
+	    dHeight,
+	    NULL,
+	    0);
+#endif
+	bmiCaptureFormat.biSize = nResult;
+
+	if (m_pSite->m_pCaptureBuffer && nResult != 0)
+	{
+	    bConvert = zm_pColorAcc->CheckColorConverter(nSrcCID, nDestCID);
+	    m_pSite->ColorConverterRequest(nSrcCID, nDestCID, bConvert);
+	    if (bConvert)
+	    {
+		HXxRect rSrcRect = {0, 0, pBitmapInfo->biWidth, pBitmapInfo->biHeight};
+		HXxRect rDestRect = {0, 0, bmiCaptureFormat.biWidth, bmiCaptureFormat.biHeight};
+
+		//Well krap(tm). We just can't win with odd number of lines
+		//and YUV formats. This sucks. I guess just fake it.
+		AlignRect(&rSrcRect, pBitmapInfo->biWidth, pBitmapInfo->biHeight);
+		AlignRect(&rDestRect, bmiCaptureFormat.biWidth, bmiCaptureFormat.biHeight);
+
+		int dxDst = rDestRect.right  - rDestRect.left;
+		int dyDst = rDestRect.bottom - rDestRect.top;
+		int dxSrc = rSrcRect.right   - rSrcRect.left;
+		int dySrc = rSrcRect.bottom  - rSrcRect.top;
 
+		res = m_pSite->m_pCaptureBuffer->SetSize( bmiCaptureFormat.biSizeImage );
+
+		if (res == HXR_OK)
+		{
+		  res = zm_pColorAcc->ColorConvert(
+		    nDestCID, 					// cidOut
+		    m_pSite->m_pCaptureBuffer->GetBuffer(),	// dest_ptr
+		    bmiCaptureFormat.biWidth,			// dest_width
+		    bmiCaptureFormat.biHeight,			// dest_height
+		    GETBITMAPPITCH(&(bmiCaptureFormat)),	// dest_pitch
+		    rDestRect.left, rDestRect.top,		// dest_x, dest_y
+		    HXxRECT_WIDTH(rDestRect), HXxRECT_HEIGHT(rDestRect), // dest_dx, dest_dy
+		    nSrcCID,					// cidIn
+		    pImageData,					// src_ptr
+		    pBitmapInfo->biWidth,			// src_width
+		    pBitmapInfo->biHeight,			// src_height
+		    GETBITMAPPITCH(pBitmapInfo),		// src_pitch
+		    rSrcRect.left, rSrcRect.top,		// src_x, src_y
+		    HXxRECT_WIDTH(rSrcRect), HXxRECT_HEIGHT(rSrcRect) // src_dx, src_dy
+		    );
+		}
+		bConvert = (res == HXR_OK);
+	    }
+	}
+	if (!bConvert)
+	{
+	    // Buffer has not been converted & copied, so copy in source image
+	    memcpy( &bmiCaptureFormat, pBitmapInfo, sizeof( HXBitmapInfoHeader ) );
+	    if (m_pSite->m_pCaptureBuffer)
+	    {
+		if (m_pSite->m_pCaptureBuffer->SetSize( pBitmapInfo->biSizeImage ) == HXR_OK)
+		{
+		    memcpy( m_pSite->m_pCaptureBuffer->GetBuffer(), pImageData, \
pBitmapInfo->biSizeImage); +		}
+	    }
+	}
+
+	// Send the response
+	m_pSite->m_pCaptureResponse->CaptureDone(res, bmiCaptureFormat, \
m_pSite->m_pCaptureBuffer); +	HX_RELEASE(m_pSite->m_pCaptureResponse);
+    }
+}
 
 STDMETHODIMP CBaseSurface::Blt( UCHAR*               pImageData,
                                 HXBitmapInfoHeader* pBitmapInfo,
@@ -2451,6 +2570,12 @@
     INT32 nCID = GETBITMAPCOLOR(pBitmapInfo);
     INT32 nCIDOld = GETBITMAPCOLOR(&m_bmiLastBlt);
 
+    //// Capture image
+    if (m_pSite && m_pSite->m_pCaptureResponse != NULL)
+    {
+	CaptureImage(pImageData, pBitmapInfo);
+    }
+
     if( m_pSite->IsCompositionLocked() && !IsYUV(nCID) )
     {
         m_pSite->_TLSUnlock();
@@ -2760,7 +2885,6 @@
         goto cleanup;
     }
 
-
     for( j=0 ; j<nNumRects ; j++ )
     {
         switch (m_nBltMode)

Index: basesite.cpp
===================================================================
RCS file: /cvsroot/video/sitelib/basesite.cpp,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -d -r1.32 -r1.33
--- basesite.cpp	23 Feb 2006 22:34:07 -0000	1.32
+++ basesite.cpp	11 Apr 2006 22:30:54 -0000	1.33
@@ -269,6 +269,9 @@
     , m_bScrollingSite(FALSE)
     , m_pMutex(NULL)
     , m_pDummyThread(NULL)
+    , m_pCaptureResponse(NULL)
+    , m_pCaptureBuffer(NULL)
+    , m_dCaptureCID(CID_UNKNOWN)
 {
     m_fpTransitionEffect = z_TransitionTable[0].m_pSubTypes[0].m_fpTranFunction;
 
@@ -441,6 +444,9 @@
     HX_RELEASE(m_pVideoSurface);
     HX_RELEASE(m_pRootSurface);
 
+    HX_RELEASE(m_pCaptureResponse);
+    HX_RELEASE(m_pCaptureBuffer);
+
     if(m_pTopLevelSite != this)
         HX_RELEASE(m_pTopLevelSite);
 
@@ -517,104 +523,33 @@
  */
 STDMETHODIMP CHXBaseSite::SiteNonDelegatingQueryInterface(REFIID riid, void** \
ppvObj)  {
-    if (IsEqualIID(riid, IID_IUnknown))
-    {
-        AddRef();
-        *ppvObj = (IUnknown*)(IHXSite*)this;
-        return HXR_OK;
-    }
-    else if (IsEqualIID(riid, IID_IHXSite))
-    {
-        AddRef();
-        *ppvObj = (IHXSite*)this;
-        return HXR_OK;
-    }
-    else if (IsEqualIID(riid, IID_IHXSite2))
-    {
-        AddRef();
-        *ppvObj = (IHXSite2*)this;
-        return HXR_OK;
-    }
-    else if (IsEqualIID(riid, IID_IHXSiteTreeNavigation))
-    {
-        AddRef();
-        *ppvObj = (IHXSiteTreeNavigation*)this;
-        return HXR_OK;
-    }
-    else if (IsEqualIID(riid, IID_IHXInterruptSafe))
-    {
-        AddRef();
-        *ppvObj = (IHXInterruptSafe*)this;
-        return HXR_OK;
-    }
-    else if (IsEqualIID(riid, IID_IHXSiteWindowless))
-    {
-        AddRef();
-        *ppvObj = (IHXSiteWindowless*)this;
-        return HXR_OK;
-    }
-    else if (IsEqualIID(riid, IID_IHXSiteWindowed))
-    {
-        AddRef();
-        *ppvObj = (IHXSiteWindowed*)this;
-        return HXR_OK;
-    }
-    else if (IsEqualIID(riid, IID_IHXStatusMessage))
-    {
-        AddRef();
-        *ppvObj = (IHXStatusMessage*)this;
-        return HXR_OK;
-    }
-    else if (IsEqualIID(riid, IID_IHXSiteFullScreen))
-    {
-        AddRef();
-        *ppvObj = (IHXSiteFullScreen*)this;
-        return HXR_OK;
-    }
-    else if (IsEqualIID(riid, IID_IHXVideoControl))
-    {
-        AddRef();
-        *ppvObj = (IHXVideoControl*)this;
-        return HXR_OK;
-    }
-    else if (IsEqualIID(riid, IID_IHXSiteTransition))
-    {
-        AddRef();
-        *ppvObj = (IHXSiteTransition*)this;
-        return HXR_OK;
-    }
-    else if (IsEqualIID(riid, IID_IHXSiteComposition))
-    {
-        AddRef();
-        *ppvObj = (IHXSiteComposition*)this;
-        return HXR_OK;
-    }
-    else if (m_pValues &&
+    if (m_pValues &&
              m_pValues->QueryInterface(riid, ppvObj) == HXR_OK)
     {
         return HXR_OK;
     }
-    else if (IsEqualIID(riid, IID_IHXKeyBoardFocus))
-    {
-        AddRef();
-        *ppvObj = (IHXKeyBoardFocus*)this;
-        return HXR_OK;
-    }
-    else if (IsEqualIID(riid, IID_IHXDrawFocus))
-    {
-        AddRef();
-        *ppvObj = (IHXDrawFocus*)this;
-        return HXR_OK;
-    }
-    else if (IsEqualIID(riid, IID_IHXSubRectSite))
+
+    QInterfaceList qiList[] =
     {
-        AddRef();
-        *ppvObj = (IHXSubRectSite*)this;
-        return HXR_OK;
-    }
+	{ GET_IIDHANDLE(IID_IUnknown),		(IUnknown*)(IHXSite*)this },
+	{ GET_IIDHANDLE(IID_IHXSite),		(IHXSite*)this },
+	{ GET_IIDHANDLE(IID_IHXSite2),		(IHXSite2*)this },
+	{ GET_IIDHANDLE(IID_IHXSiteCapture),	(IHXSiteCapture*)this },
+	{ GET_IIDHANDLE(IID_IHXSiteTreeNavigation), (IHXSiteTreeNavigation*)this },
+	{ GET_IIDHANDLE(IID_IHXInterruptSafe),	(IHXInterruptSafe*)this },
+	{ GET_IIDHANDLE(IID_IHXSiteWindowless),	(IHXSiteWindowless*)this },
+	{ GET_IIDHANDLE(IID_IHXSiteWindowed),	(IHXSiteWindowed*)this },
+	{ GET_IIDHANDLE(IID_IHXStatusMessage),	(IHXStatusMessage*)this },
+	{ GET_IIDHANDLE(IID_IHXSiteFullScreen),	(IHXSiteFullScreen*)this },
+	{ GET_IIDHANDLE(IID_IHXVideoControl),	(IHXVideoControl*)this },
+	{ GET_IIDHANDLE(IID_IHXSiteTransition),	(IHXSiteTransition*)this },
+	{ GET_IIDHANDLE(IID_IHXSiteComposition),(IHXSiteComposition*)this },
+	{ GET_IIDHANDLE(IID_IHXKeyBoardFocus),	(IHXKeyBoardFocus*)this },
+	{ GET_IIDHANDLE(IID_IHXDrawFocus),	(IHXDrawFocus*)this },
+	{ GET_IIDHANDLE(IID_IHXSubRectSite),	(IHXSubRectSite*)this }
+    };
 
-    *ppvObj = NULL;
-    return HXR_NOINTERFACE;
+    return ::QIFind(qiList, QILISTSIZE(qiList), riid, ppvObj);
 }
 
 /************************************************************************
@@ -2466,6 +2401,93 @@
     return hr;
 }
 
+/************************************************************************
+ *  IHXSiteCapture Methods
+ */
+// IHXSiteCapture::CanCapture
+//
+// Can Capture be called on this site/surf?
+// May return:
+//    HXR_FAIL  -- bCanCapture is *not* valid. General Error.
+//    HXR_OK    -- bCanCapture is valid.
+STDMETHODIMP
+CHXBaseSite::CanCapture(HXBOOL&  bCanCapture)
+{
+    bCanCapture = (m_pCaptureResponse == NULL &&
+		   !m_bSiteNeverBlts &&
+		   m_pUser != NULL &&
+		   (m_pVideoSurface &&
+		    GETBITMAPCOLOR(&(m_pVideoSurface->m_bmiLastBlt)) != CID_UNKNOWN &&
+                    m_pVideoSurface->m_nSrcCID != CID_UNKNOWN));
+
+    HX_RESULT res=HXR_OK;
+
+    if (m_pCaptureResponse != NULL ||
+	m_pVideoSurface->m_nSrcCID == CID_UNKNOWN)
+    {
+	res = HXR_RETRY;
+    }
+    else if (m_bSiteNeverBlts)
+    {
+	res = HXR_FAIL;
+    }
+
+    return res;
+}
+
+//
+// IHXSiteCapture::Capture
+//
+// asynchronous call. pCaptureResponse->CaptureDone() will be called
+// with result.   pCaptureBuffer will hold the
+// output data. If NULL, CaptureDone() will not supply image data
+// but will supply HXBitmapInfoHeader.
+//
+// Returns:
+//   HXR_FAIL  -- No capture will be done. General Error.
+//   HXR_OK    -- Capture will be done if pCaptureBuffer is not NULL.
+//   HXR_UNEXPECTED -- You can not capture this site.
+//
+STDMETHODIMP
+CHXBaseSite::Capture(IHXSiteCaptureResponse* pCaptureResponse, IHXBuffer* \
pCaptureBuffer, HXxSize* pOutputSize, INT32 dOutputCID) +{
+    HX_RESULT res=HXR_OK;
+    HXBOOL bCanCapture=FALSE;
+
+    _TLSLock();
+
+    res = CanCapture(bCanCapture);
+
+    if (res == HXR_OK && bCanCapture && pCaptureResponse != NULL)
+    {
+	m_pCaptureResponse = pCaptureResponse;
+	m_pCaptureResponse->AddRef();
+	m_pCaptureBuffer = pCaptureBuffer;
+	if (pOutputSize)
+	{
+	    m_captureSize = *pOutputSize;
+	}
+	else
+	{
+	    m_captureSize.cx = 0;
+	    m_captureSize.cy = 0;
+	}
+	   
+	m_dCaptureCID = dOutputCID;
+	
+	// Drop out of VS2 to VS1 so that Blt() gets called and the frame can be captured
+	HXxEvent event = {HX_SURFACE_MODE_CHANGE, NULL, NULL,
+                              (void*)HX_VIDEOSURFACE1_RECOMMENDED, 0, 0};
+        if (m_pUser)
+        {
+            m_pUser->HandleEvent(&event);
+        }
+    }
+
+    _TLSUnlock();
+
+    return res;
+}
 
 
 void CHXBaseSite::_HandleMouseEvent(HXxEvent* pEvent)


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic