shithub: openh264

Download patch

ref: 51af10a25b1d800aadd547356e43d541661e372c
parent: b4112bc8866c55340791998352ebeebee7a12fcb
parent: 1b68890e1ea9b182277ced6ba712c2a8b51e0533
author: dongzha <dongzha@cisco.com>
date: Wed Jun 18 09:55:04 EDT 2014

Merge pull request #968 from huili2/render_syureyi

support rendering changing resollution output yuv on windows platform

--- a/codec/console/dec/src/d3d9_utils.cpp
+++ b/codec/console/dec/src/d3d9_utils.cpp
@@ -75,7 +75,8 @@
   m_lpD3D9                = NULL;
   m_lpD3D9Device          = NULL;
   m_lpD3D9RawSurfaceShare = NULL;
-
+  m_nWidth  = 0;
+  m_nHeight = 0;
   // coverity scan uninitial
   ZeroMemory (&m_d3dpp, sizeof (m_d3dpp));
 }
@@ -147,6 +148,16 @@
 HRESULT CD3D9Utils::Render (void* pDst[3], SBufferInfo* pInfo) {
   HRESULT hResult = E_FAIL;
 
+  if (!pInfo)
+    return E_FAIL;
+
+  if (m_nWidth != pInfo->UsrData.sSystemBuffer.iWidth
+      || m_nHeight != pInfo->UsrData.sSystemBuffer.iHeight) {
+    m_nWidth = pInfo->UsrData.sSystemBuffer.iWidth;
+    m_nHeight = pInfo->UsrData.sSystemBuffer.iHeight;
+    SAFE_RELEASE (m_lpD3D9RawSurfaceShare);
+    SAFE_RELEASE (m_lpD3D9Device);
+  }
   hResult = InitResource (NULL, pInfo);
   if (SUCCEEDED (hResult))
     hResult = Dump2Surface (pDst, m_lpD3D9RawSurfaceShare, pInfo->UsrData.sSystemBuffer.iWidth,
@@ -245,6 +256,8 @@
   m_lpD3D9Device          = NULL;
   m_lpD3D9RawSurfaceShare = NULL;
 
+  m_nWidth = 0;
+  m_nHeight = 0;
   // coverity scan uninitial
   ZeroMemory (&m_d3dpp, sizeof (m_d3dpp));
 }
@@ -316,6 +329,16 @@
 HRESULT CD3D9ExUtils::Render (void* pDst[3], SBufferInfo* pInfo) {
   HRESULT hResult = E_FAIL;
 
+  if (!pInfo)
+    return E_FAIL;
+
+  if (m_nWidth != pInfo->UsrData.sSystemBuffer.iWidth
+      || m_nHeight != pInfo->UsrData.sSystemBuffer.iHeight) {
+    m_nWidth = pInfo->UsrData.sSystemBuffer.iWidth;
+    m_nHeight = pInfo->UsrData.sSystemBuffer.iHeight;
+    SAFE_RELEASE (m_lpD3D9RawSurfaceShare);
+    SAFE_RELEASE (m_lpD3D9Device);
+  }
   hResult = InitResource (NULL, pInfo);
   if (SUCCEEDED (hResult))
     hResult = Dump2Surface (pDst, m_lpD3D9RawSurfaceShare, pInfo->UsrData.sSystemBuffer.iWidth,
@@ -386,6 +409,9 @@
     m_d3dpp.hDeviceWindow = m_hWnd;
     m_d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
     hResult = m_lpD3D9->CreateDeviceEx (uiAdapter, D3DDevType, NULL, dwBehaviorFlags, &m_d3dpp, NULL, &m_lpD3D9Device);
+    if (FAILED (hResult)) {
+      return hResult;
+    }
     iWidth = pInfo->UsrData.sSystemBuffer.iWidth;
     iHeight = pInfo->UsrData.sSystemBuffer.iHeight;
     D3Dformat = (D3DFORMAT)NV12_FORMAT;