[xiph-commits] r16960 - trunk/oggdsf/src/lib/plugin/AxPlayer

cristianadam at svn.xiph.org cristianadam at svn.xiph.org
Wed Mar 10 15:04:34 PST 2010


Author: cristianadam
Date: 2010-03-10 15:04:34 -0800 (Wed, 10 Mar 2010)
New Revision: 16960

Added:
   trunk/oggdsf/src/lib/plugin/AxPlayer/CustomVMR9Allocator.cpp
   trunk/oggdsf/src/lib/plugin/AxPlayer/CustomVMR9Allocator.h
Removed:
   trunk/oggdsf/src/lib/plugin/AxPlayer/CustomVMR7Allocator.cpp
   trunk/oggdsf/src/lib/plugin/AxPlayer/CustomVMR7Allocator.h
Modified:
   trunk/oggdsf/src/lib/plugin/AxPlayer/AxPlayer-2005.vcproj
   trunk/oggdsf/src/lib/plugin/AxPlayer/DShowVideoPlayer.cpp
   trunk/oggdsf/src/lib/plugin/AxPlayer/DShowVideoPlayer.h
   trunk/oggdsf/src/lib/plugin/AxPlayer/FilterGraph.cpp
   trunk/oggdsf/src/lib/plugin/AxPlayer/FilterGraph.h
Log:
Updated custom renderer from VMR7 to VMR9.

Modified: trunk/oggdsf/src/lib/plugin/AxPlayer/AxPlayer-2005.vcproj
===================================================================
--- trunk/oggdsf/src/lib/plugin/AxPlayer/AxPlayer-2005.vcproj	2010-03-10 16:03:11 UTC (rev 16959)
+++ trunk/oggdsf/src/lib/plugin/AxPlayer/AxPlayer-2005.vcproj	2010-03-10 23:04:34 UTC (rev 16960)
@@ -56,7 +56,7 @@
 				Name="VCCLCompilerTool"
 				Optimization="0"
 				AdditionalIncludeDirectories=""Generated Files";res;..\..\helper\;..\uriparser\include"
-				PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_BIND_TO_CURRENT_CRT_VERSION;WIN32;_WINDOWS;_DEBUG;_USRDLL;_MERGE_PROXYSTUB"
+				PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_BIND_TO_CURRENT_CRT_VERSION;WIN32;_WINDOWS;_DEBUG;_USRDLL;_MERGE_PROXYSTUB;"
 				MinimalRebuild="true"
 				BasicRuntimeChecks="3"
 				RuntimeLibrary="3"
@@ -81,7 +81,7 @@
 				Name="VCLinkerTool"
 				RegisterOutput="true"
 				IgnoreImportLibrary="true"
-				AdditionalDependencies="ddraw.lib"
+				AdditionalDependencies="ddraw.lib d3d9.lib "
 				LinkIncremental="2"
 				ModuleDefinitionFile=".\AxPlayer.def"
 				GenerateDebugInformation="true"
@@ -174,7 +174,7 @@
 			<Tool
 				Name="VCLinkerTool"
 				IgnoreImportLibrary="true"
-				AdditionalDependencies="ddraw.lib"
+				AdditionalDependencies="ddraw.lib d3d9.lib"
 				LinkIncremental="2"
 				ModuleDefinitionFile=".\AxPlayer.def"
 				GenerateDebugInformation="true"
@@ -270,7 +270,7 @@
 				Name="VCLinkerTool"
 				RegisterOutput="true"
 				IgnoreImportLibrary="true"
-				AdditionalDependencies="ddraw.lib"
+				AdditionalDependencies="ddraw.lib d3d9.lib"
 				LinkIncremental="1"
 				ModuleDefinitionFile=".\AxPlayer.def"
 				GenerateDebugInformation="true"
@@ -366,7 +366,7 @@
 			<Tool
 				Name="VCLinkerTool"
 				IgnoreImportLibrary="true"
-				AdditionalDependencies="ddraw.lib"
+				AdditionalDependencies="ddraw.lib d3d9.lib"
 				LinkIncremental="1"
 				ModuleDefinitionFile=".\AxPlayer.def"
 				GenerateDebugInformation="true"
@@ -422,7 +422,7 @@
 				>
 			</File>
 			<File
-				RelativePath=".\CustomVMR7Allocator.cpp"
+				RelativePath=".\CustomVMR9Allocator.cpp"
 				>
 			</File>
 			<File
@@ -572,7 +572,7 @@
 				>
 			</File>
 			<File
-				RelativePath=".\CustomVMR7Allocator.h"
+				RelativePath=".\CustomVMR9Allocator.h"
 				>
 			</File>
 			<File
@@ -626,11 +626,11 @@
 				>
 			</File>
 			<File
-				RelativePath=".\Res\VideoTagBehavior.rgs"
+				RelativePath=".\VideoTagBehavior.rgs"
 				>
 			</File>
 			<File
-				RelativePath=".\VideoTagBehavior.rgs"
+				RelativePath=".\Res\VideoTagBehavior.rgs"
 				>
 			</File>
 		</Filter>

Deleted: trunk/oggdsf/src/lib/plugin/AxPlayer/CustomVMR7Allocator.cpp
===================================================================
--- trunk/oggdsf/src/lib/plugin/AxPlayer/CustomVMR7Allocator.cpp	2010-03-10 16:03:11 UTC (rev 16959)
+++ trunk/oggdsf/src/lib/plugin/AxPlayer/CustomVMR7Allocator.cpp	2010-03-10 23:04:34 UTC (rev 16960)
@@ -1,117 +0,0 @@
-//===========================================================================
-// Copyright (C) 2010 Cristian Adam
-//
-//Redistribution and use in source and binary forms, with or without
-//modification, are permitted provided that the following conditions
-//are met:
-//
-//- Redistributions of source code must retain the above copyright
-//  notice, this list of conditions and the following disclaimer.
-//
-//- Redistributions in binary form must reproduce the above copyright
-//  notice, this list of conditions and the following disclaimer in the
-//  documentation and/or other materials provided with the distribution.
-//
-//- Neither the name of Cristian Adam nor the names of contributors
-//  may be used to endorse or promote products derived from this software
-//  without specific prior written permission.
-//
-//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-//``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
-//PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE ORGANISATION OR
-//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-//EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-//PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-//PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
-//LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
-//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-//SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-//==============================================================
-
-#include "StdAfx.h"
-#include "CustomVMR7Allocator.h"
-#include <uuids.h>
-
-CustomVMR7Allocator::CustomVMR7Allocator():
-m_notifyWindow(0),
-m_presentImageMessage(0)
-{
-}
-
-CustomVMR7Allocator::~CustomVMR7Allocator()
-{
-}
-
-
-HRESULT CustomVMR7Allocator::CreateDefaultSurfaceAllocator()
-{
-    return m_defaultAllocator.CoCreateInstance(CLSID_AllocPresenter, 0, CLSCTX_INPROC_SERVER);
-}
-
-// IVMRSurfaceAllocator Methods
-HRESULT __stdcall CustomVMR7Allocator::AllocateSurface(DWORD_PTR dwUserID, VMRALLOCATIONINFO *lpAllocInfo, 
-                                                       DWORD *lpdwActualBuffers, LPDIRECTDRAWSURFACE7 *lplpSurface)
-{
-    ATLASSERT(m_defaultAllocator && "Missing default allocator");
-    return m_defaultAllocator->AllocateSurface(dwUserID, lpAllocInfo, lpdwActualBuffers, lplpSurface);
-}
-
-HRESULT __stdcall CustomVMR7Allocator::FreeSurface(DWORD_PTR dwID)
-{
-    ATLASSERT(m_defaultAllocator && "Missing default allocator");
-    return m_defaultAllocator->FreeSurface(dwID);
-}
-
-HRESULT __stdcall CustomVMR7Allocator::PrepareSurface(DWORD_PTR dwUserID,LPDIRECTDRAWSURFACE7 lpSurface, 
-                                                      DWORD dwSurfaceFlags)
-{
-    ATLASSERT(m_defaultAllocator && "Missing default allocator");
-    return m_defaultAllocator->PrepareSurface(dwUserID, lpSurface, dwSurfaceFlags);
-}
-
-HRESULT __stdcall CustomVMR7Allocator::AdviseNotify(IVMRSurfaceAllocatorNotify *lpIVMRSurfAllocNotify)
-{
-   ATLASSERT(m_defaultAllocator && "Missing default allocator");
-   return m_defaultAllocator->AdviseNotify(lpIVMRSurfAllocNotify);
-}
-
-// IVMRImagePresenter Methods
-HRESULT __stdcall CustomVMR7Allocator::StartPresenting(DWORD_PTR /*dwUserID*/)
-{
-    return S_OK;
-}
-
-HRESULT __stdcall CustomVMR7Allocator::StopPresenting(DWORD_PTR /*dwUserID*/)
-{
-    return S_OK;
-}
-
-HRESULT __stdcall CustomVMR7Allocator::PresentImage(DWORD_PTR dwUserID, VMRPRESENTATIONINFO *lpPresInfo)
-{
-    ATLASSERT(m_notifyWindow && "SetNotifyWindow must be called first!");
-    ATLASSERT(m_presentImageMessage && "SetPresentImageMessage must be called first!");
-
-    ::SendMessage(m_notifyWindow, m_presentImageMessage, dwUserID, reinterpret_cast<LPARAM>(lpPresInfo));
-    return S_OK;
-}
-
-int CustomVMR7Allocator::GetPresentImageMessage() const
-{
-    return m_presentImageMessage;
-}
-
-void CustomVMR7Allocator::SetPresentImageMessage( int val )
-{
-    m_presentImageMessage = val;
-}
-
-HWND CustomVMR7Allocator::GetNotifyWindow() const
-{
-    return m_notifyWindow;
-}
-
-void CustomVMR7Allocator::SetNotifyWindow( HWND val )
-{
-    m_notifyWindow = val;
-}

Deleted: trunk/oggdsf/src/lib/plugin/AxPlayer/CustomVMR7Allocator.h
===================================================================
--- trunk/oggdsf/src/lib/plugin/AxPlayer/CustomVMR7Allocator.h	2010-03-10 16:03:11 UTC (rev 16959)
+++ trunk/oggdsf/src/lib/plugin/AxPlayer/CustomVMR7Allocator.h	2010-03-10 23:04:34 UTC (rev 16960)
@@ -1,83 +0,0 @@
-//===========================================================================
-// Copyright (C) 2010 Cristian Adam
-//
-//Redistribution and use in source and binary forms, with or without
-//modification, are permitted provided that the following conditions
-//are met:
-//
-//- Redistributions of source code must retain the above copyright
-//  notice, this list of conditions and the following disclaimer.
-//
-//- Redistributions in binary form must reproduce the above copyright
-//  notice, this list of conditions and the following disclaimer in the
-//  documentation and/or other materials provided with the distribution.
-//
-//- Neither the name of Cristian Adam nor the names of contributors
-//  may be used to endorse or promote products derived from this software
-//  without specific prior written permission.
-//
-//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-//``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
-//PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE ORGANISATION OR
-//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-//EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-//PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-//PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
-//LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
-//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-//SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-//==============================================================
-
-#ifndef CUSTOMVMR7ALLOCATOR_H
-#define CUSTOMVMR7ALLOCATOR_H
-
-#pragma once
-
-#include <ddraw.h>
-#include <strmif.h>
-
-class CustomVMR7Allocator: 
-    public CComObjectRootEx<CComSingleThreadModel>,
-    public IVMRSurfaceAllocator, 
-    public IVMRImagePresenter
-{
-public:
-    
-    BEGIN_COM_MAP(CustomVMR7Allocator)
-        COM_INTERFACE_ENTRY(IVMRSurfaceAllocator)
-        COM_INTERFACE_ENTRY(IVMRImagePresenter)
-    END_COM_MAP()
-
-    CustomVMR7Allocator();
-    virtual ~CustomVMR7Allocator();
-
-    int GetPresentImageMessage() const;
-    void SetPresentImageMessage(int val);
-
-    HWND GetNotifyWindow() const;
-    void SetNotifyWindow(HWND val);
-
-    HRESULT CreateDefaultSurfaceAllocator();
-
-    // IVMRSurfaceAllocator Methods
-    virtual HRESULT __stdcall AllocateSurface(DWORD_PTR dwUserID, VMRALLOCATIONINFO *lpAllocInfo,
-                                      DWORD *lpdwActualBuffers, LPDIRECTDRAWSURFACE7 *lplpSurface);
-    virtual HRESULT __stdcall FreeSurface(DWORD_PTR dwID);
-    virtual HRESULT __stdcall PrepareSurface(DWORD_PTR dwUserID, LPDIRECTDRAWSURFACE7 lpSurface,
-                                     DWORD dwSurfaceFlags);
-    virtual HRESULT __stdcall AdviseNotify(IVMRSurfaceAllocatorNotify *lpIVMRSurfAllocNotify);
-
-    // IVMRImagePresenter Methods
-    virtual HRESULT __stdcall StartPresenting(DWORD_PTR dwUserID);
-    virtual HRESULT __stdcall StopPresenting(DWORD_PTR dwUserID);
-    virtual HRESULT __stdcall PresentImage(DWORD_PTR dwUserID, VMRPRESENTATIONINFO *lpPresInfo);
-
-protected:
-    
-    CComPtr<IVMRSurfaceAllocator> m_defaultAllocator;
-    HWND m_notifyWindow;
-    int m_presentImageMessage;
-};
-
-#endif // CUSTOMVMR7ALLOCATOR_H

Copied: trunk/oggdsf/src/lib/plugin/AxPlayer/CustomVMR9Allocator.cpp (from rev 16904, trunk/oggdsf/src/lib/plugin/AxPlayer/CustomVMR7Allocator.cpp)
===================================================================
--- trunk/oggdsf/src/lib/plugin/AxPlayer/CustomVMR9Allocator.cpp	                        (rev 0)
+++ trunk/oggdsf/src/lib/plugin/AxPlayer/CustomVMR9Allocator.cpp	2010-03-10 23:04:34 UTC (rev 16960)
@@ -0,0 +1,189 @@
+//===========================================================================
+// Copyright (C) 2010 Cristian Adam
+//
+//Redistribution and use in source and binary forms, with or without
+//modification, are permitted provided that the following conditions
+//are met:
+//
+//- Redistributions of source code must retain the above copyright
+//  notice, this list of conditions and the following disclaimer.
+//
+//- Redistributions in binary form must reproduce the above copyright
+//  notice, this list of conditions and the following disclaimer in the
+//  documentation and/or other materials provided with the distribution.
+//
+//- Neither the name of Cristian Adam nor the names of contributors
+//  may be used to endorse or promote products derived from this software
+//  without specific prior written permission.
+//
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+//``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+//PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE ORGANISATION OR
+//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+//EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+//PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+//PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+//LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+//SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//==============================================================
+
+#include "StdAfx.h"
+#include "CustomVMR9Allocator.h"
+#include <uuids.h>
+#include <algorithm>
+
+namespace {
+    struct ReleaseObject
+    {
+        template <typename T>
+        void operator () (T* arg)
+        {
+            arg->Release();
+        }
+    };
+}
+
+CustomVMR9Allocator::CustomVMR9Allocator():
+m_notifyWindow(0),
+m_presentImageMessage(0)
+{
+}
+
+CustomVMR9Allocator::~CustomVMR9Allocator()
+{
+    std::for_each(m_surfacesList.begin(), m_surfacesList.end(), ReleaseObject());
+    m_surfacesList.clear();
+}
+
+// IVMRSurfaceAllocator9 Methods
+HRESULT CustomVMR9Allocator::InitializeDevice(DWORD_PTR /*dwUserID*/, 
+                                              VMR9AllocationInfo *lpAllocInfo, DWORD *lpNumBuffers)
+{
+    if (!lpNumBuffers)
+    {
+        return E_POINTER;
+    }
+
+    HRESULT hr = S_OK;
+    try
+    {
+        std::for_each(m_surfacesList.begin(), m_surfacesList.end(), ReleaseObject());
+        m_surfacesList.resize(*lpNumBuffers);
+
+        CHECK_HR(m_surfaceAllocatorNotify->AllocateSurfaceHelper(lpAllocInfo, lpNumBuffers, &*m_surfacesList.begin()));
+    }
+    catch (const CAtlException& except)
+    {
+        hr = except.m_hr;
+    }
+
+    return hr;
+}
+
+HRESULT CustomVMR9Allocator::TerminateDevice(DWORD_PTR /*dwID*/)
+{
+    AutoLock lock(m_lockObject);
+    std::for_each(m_surfacesList.begin(), m_surfacesList.end(), ReleaseObject());
+    m_surfacesList.clear();
+    
+    return S_OK;
+}
+
+HRESULT CustomVMR9Allocator::GetSurface(DWORD_PTR /*dwUserID*/, DWORD surfaceIndex, DWORD /*surfaceFlags*/, 
+                                        IDirect3DSurface9 **lplpSurface)
+{
+    if (!lplpSurface)
+    {
+        return E_POINTER;
+    }
+
+    AutoLock lock(m_lockObject);
+    *lplpSurface = m_surfacesList[surfaceIndex];
+    (*lplpSurface)->AddRef();
+
+    return S_OK;
+}
+
+HRESULT CustomVMR9Allocator::AdviseNotify(IVMRSurfaceAllocatorNotify9 *lpIVMRSurfAllocNotify)
+{
+    AutoLock locker(m_lockObject);
+
+    HRESULT hr = S_OK;
+    try
+    {
+        m_surfaceAllocatorNotify = lpIVMRSurfAllocNotify;
+        
+        HMONITOR defaultMonitor = GetD3D()->GetAdapterMonitor(D3DADAPTER_DEFAULT);
+        CHECK_HR(m_surfaceAllocatorNotify->SetD3DDevice(GetD3DDevice(), defaultMonitor));
+    }
+    catch (const CAtlException& except)
+    {
+        hr = except.m_hr;
+    }
+    
+    return hr;
+}
+
+// IVMRImagePresenter Methods
+HRESULT __stdcall CustomVMR9Allocator::StartPresenting(DWORD_PTR /*dwUserID*/)
+{
+    return S_OK;
+}
+
+HRESULT __stdcall CustomVMR9Allocator::StopPresenting(DWORD_PTR /*dwUserID*/)
+{
+    return S_OK;
+}
+
+HRESULT __stdcall CustomVMR9Allocator::PresentImage(DWORD_PTR dwUserID, VMR9PresentationInfo *lpPresInfo)
+{
+    ATLASSERT(m_notifyWindow && "SetNotifyWindow must be called first!");
+    ATLASSERT(m_presentImageMessage && "SetPresentImageMessage must be called first!");
+
+    ::SendMessage(m_notifyWindow, m_presentImageMessage, dwUserID, reinterpret_cast<LPARAM>(lpPresInfo));
+    return S_OK;
+}
+
+int CustomVMR9Allocator::GetPresentImageMessage() const
+{
+    return m_presentImageMessage;
+}
+
+void CustomVMR9Allocator::SetPresentImageMessage( int val )
+{
+    m_presentImageMessage = val;
+}
+
+HWND CustomVMR9Allocator::GetNotifyWindow() const
+{
+    return m_notifyWindow;
+}
+
+void CustomVMR9Allocator::SetNotifyWindow(HWND val)
+{
+    m_notifyWindow = val;
+}
+
+CComPtr<IDirect3DDevice9> CustomVMR9Allocator::GetD3DDevice() const
+{
+    ATLASSERT(m_d3dDevice && L"SetD3DDevice should have been called before");
+    return m_d3dDevice;
+}
+
+void CustomVMR9Allocator::SetD3DDevice(const CComPtr<IDirect3DDevice9>& val)
+{
+    m_d3dDevice = val;
+}
+
+CComPtr<IDirect3D9> CustomVMR9Allocator::GetD3D() const
+{
+    ATLASSERT(m_d3d && L"SetD3D should have been called before");
+    return m_d3d;
+}
+
+void CustomVMR9Allocator::SetD3D(const CComPtr<IDirect3D9>& val)
+{
+    m_d3d = val;
+}

Copied: trunk/oggdsf/src/lib/plugin/AxPlayer/CustomVMR9Allocator.h (from rev 16904, trunk/oggdsf/src/lib/plugin/AxPlayer/CustomVMR7Allocator.h)
===================================================================
--- trunk/oggdsf/src/lib/plugin/AxPlayer/CustomVMR9Allocator.h	                        (rev 0)
+++ trunk/oggdsf/src/lib/plugin/AxPlayer/CustomVMR9Allocator.h	2010-03-10 23:04:34 UTC (rev 16960)
@@ -0,0 +1,117 @@
+//===========================================================================
+// Copyright (C) 2010 Cristian Adam
+//
+//Redistribution and use in source and binary forms, with or without
+//modification, are permitted provided that the following conditions
+//are met:
+//
+//- Redistributions of source code must retain the above copyright
+//  notice, this list of conditions and the following disclaimer.
+//
+//- Redistributions in binary form must reproduce the above copyright
+//  notice, this list of conditions and the following disclaimer in the
+//  documentation and/or other materials provided with the distribution.
+//
+//- Neither the name of Cristian Adam nor the names of contributors
+//  may be used to endorse or promote products derived from this software
+//  without specific prior written permission.
+//
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+//``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+//PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE ORGANISATION OR
+//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+//EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+//PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+//PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+//LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+//SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//==============================================================
+
+#ifndef CUSTOMVMR9ALLOCATOR_H
+#define CUSTOMVMR9ALLOCATOR_H
+
+#pragma once
+
+#include <strmif.h>
+#include <d3d9.h>
+#include <vmr9.h>
+
+class CustomVMR9Allocator: 
+    public CComObjectRootEx<CComSingleThreadModel>,
+    public IVMRSurfaceAllocator9, 
+    public IVMRImagePresenter9
+{
+public:
+    
+    BEGIN_COM_MAP(CustomVMR9Allocator)
+        COM_INTERFACE_ENTRY(IVMRSurfaceAllocator9)
+        COM_INTERFACE_ENTRY(IVMRImagePresenter9)
+    END_COM_MAP()
+
+    CustomVMR9Allocator();
+    virtual ~CustomVMR9Allocator();
+
+    int GetPresentImageMessage() const;
+    void SetPresentImageMessage(int val);
+
+    HWND GetNotifyWindow() const;
+    void SetNotifyWindow(HWND val);
+
+    CComPtr<IDirect3DDevice9> GetD3DDevice() const;
+    void SetD3DDevice(const CComPtr<IDirect3DDevice9>& val);
+
+    CComPtr<IDirect3D9> GetD3D() const;
+    void SetD3D(const CComPtr<IDirect3D9>& val);
+
+    // IVMRSurfaceAllocator9 Methods
+    virtual HRESULT __stdcall InitializeDevice(DWORD_PTR dwUserID, 
+        VMR9AllocationInfo *lpAllocInfo, DWORD *lpNumBuffers);
+
+    virtual HRESULT __stdcall TerminateDevice(DWORD_PTR dwID);
+
+    virtual HRESULT __stdcall GetSurface(DWORD_PTR dwUserID,
+        DWORD SurfaceIndex, DWORD SurfaceFlags, IDirect3DSurface9 **lplpSurface);
+
+    virtual HRESULT __stdcall AdviseNotify(IVMRSurfaceAllocatorNotify9 *lpIVMRSurfAllocNotify);
+
+    // IVMRImagePresenter9  Methods
+    virtual HRESULT __stdcall StartPresenting(DWORD_PTR dwUserID);
+    virtual HRESULT __stdcall StopPresenting(DWORD_PTR dwUserID);
+    virtual HRESULT __stdcall PresentImage(DWORD_PTR dwUserID, VMR9PresentationInfo *lpPresInfo);
+
+private:
+    
+    CComPtr<IVMRSurfaceAllocator9> m_defaultAllocator;
+    CComPtr<IVMRSurfaceAllocatorNotify9> m_surfaceAllocatorNotify;
+
+    CComPtr<IDirect3DDevice9> m_d3dDevice;
+    CComPtr<IDirect3D9> m_d3d;
+    typedef std::vector<IDirect3DSurface9*> SurfaceList;
+    SurfaceList m_surfacesList;
+
+    HWND m_notifyWindow;
+    int m_presentImageMessage;
+
+    struct AutoLock
+    {
+        CComAutoCriticalSection& m_lockObject;
+
+        AutoLock(CComAutoCriticalSection& lockObject) : 
+        m_lockObject(lockObject)
+        {
+            m_lockObject.Lock();
+        }
+
+        ~AutoLock()
+        {
+            m_lockObject.Unlock();
+        }
+    };
+
+    CComAutoCriticalSection m_lockObject;
+
+};
+
+#endif // CUSTOMVMR7ALLOCATOR_H

Modified: trunk/oggdsf/src/lib/plugin/AxPlayer/DShowVideoPlayer.cpp
===================================================================
--- trunk/oggdsf/src/lib/plugin/AxPlayer/DShowVideoPlayer.cpp	2010-03-10 16:03:11 UTC (rev 16959)
+++ trunk/oggdsf/src/lib/plugin/AxPlayer/DShowVideoPlayer.cpp	2010-03-10 23:04:34 UTC (rev 16960)
@@ -39,10 +39,13 @@
 m_isFirstFrame(false),
 m_executeFunctionOnThread(0),
 m_playerCallback(0),
-m_state(NotOpened)
+m_state(NotOpened),
+m_textureFilterType(D3DTEXF_NONE)
 {
     m_stopPlaybackEvent = ::CreateEvent(0, FALSE, FALSE, 0);
     m_executeFunctionEvent = ::CreateEvent(0 , FALSE, FALSE, 0);
+
+    m_d3d.Attach(Direct3DCreate9(D3D_SDK_VERSION));
 }
 
 DShowVideoPlayer::~DShowVideoPlayer()
@@ -55,58 +58,66 @@
 {
     try
     {
-        CHECK_HR(DirectDrawCreateEx(0, (void**)&m_directDraw7, IID_IDirectDraw7, 0));
-        CHECK_HR(m_directDraw7->SetCooperativeLevel(m_hWnd, DDSCL_NORMAL + DDSCL_MULTITHREADED));
-     
-        // Create back buffer for conversion to RGB.
-        // Buffer will by default be in a format compatible to the primary surface.
-        LPDIRECTDRAWSURFACE7 surface = NULL;
-        DDSURFACEDESC2 descriptor = {0};
-        ZeroMemory(&descriptor, sizeof(DDSURFACEDESC2));
-
-        descriptor.dwSize = sizeof(DDSURFACEDESC2);
-        descriptor.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
-        descriptor.dwWidth = videoSize.cx;
-        descriptor.dwHeight = videoSize.cy;
-
-        descriptor.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
-
-        CHECK_HR(m_directDraw7->CreateSurface(&descriptor, &surface, 0));
-        m_backBuffer = surface;
+        CHECK_HR(GetDevice()->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &m_backBuffer));
+ 
+        D3DSURFACE_DESC backBufferDesc;
+        CHECK_HR(m_backBuffer->GetDesc(&backBufferDesc));
     }
     catch (const CAtlException& /*except*/)
     {
     }
 }
 
-
-CComPtr<IDirectDrawSurface7> DShowVideoPlayer::GetScalingSurface(const CSize &aSize)
+void DShowVideoPlayer::CreateDevice()
 {
-    if (m_scalingBuffer && aSize != m_scalingSize) 
+    ATLASSERT(m_d3d && "Direct3D should be created!");
+    if (!m_d3d)
     {
-        LOG(logDEBUG3) << __FUNCTIONW__ << " Releasing old scaling surface";
-
-        m_scalingBuffer = 0;
+        return;
     }
 
-    if (!m_scalingBuffer) 
+    try
     {
-        LOG(logDEBUG3) << __FUNCTIONW__ << " Creating new scaling surface";
+        D3DDISPLAYMODE displayMode = {};
+        CHECK_HR(m_d3d->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &displayMode));
 
-        // Create a new back buffer surface
-        DDSURFACEDESC2 descriptor = {0};
-        descriptor.dwSize = sizeof(DDSURFACEDESC2);
-        descriptor.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
-        descriptor.dwWidth = aSize.cx;
-        descriptor.dwHeight = aSize.cy;
-        descriptor.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
+        // CreateDevice fails on 0x0 windows;
+        MoveWindow(0, 0, displayMode.Width, displayMode.Height, false);
 
-        CHECK_HR(m_directDraw7->CreateSurface(&descriptor, &m_scalingBuffer, 0));
+        D3DPRESENT_PARAMETERS presentParameters = {};
+        presentParameters.Windowed = TRUE;
+        presentParameters.hDeviceWindow = m_hWnd;
+        presentParameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
+        presentParameters.BackBufferFormat = displayMode.Format;
+        presentParameters.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;
 
-        m_scalingSize = aSize;
+        CHECK_HR(m_d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, m_hWnd, 
+            D3DCREATE_MULTITHREADED | D3DCREATE_SOFTWARE_VERTEXPROCESSING, &presentParameters, &m_direct3dDevice));
+
+        D3DCAPS9 d3dCaps = {};
+        CHECK_HR(m_d3d->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &d3dCaps));
+        if (d3dCaps.StretchRectFilterCaps & D3DPTFILTERCAPS_MAGFPOINT)
+        {
+            m_textureFilterType = D3DTEXF_POINT;
+        }
+        if (d3dCaps.StretchRectFilterCaps & D3DPTFILTERCAPS_MAGFLINEAR)
+        {
+            m_textureFilterType = D3DTEXF_LINEAR;
+        }
     }
+    catch (const CAtlException& /*except*/)
+    {
+    }
+}
 
-    return m_scalingBuffer;
+CComPtr<IDirect3DDevice9>& DShowVideoPlayer::GetDevice()
+{
+    if (!m_direct3dDevice)
+    {
+        CreateDevice();
+    }
+
+    return m_direct3dDevice;
 }
 
 HRESULT DShowVideoPlayer::Draw(RECT rcBounds, RECT rcUpdate, LONG lDrawFlags, HDC hdc, LPVOID pvDrawObject)
@@ -118,41 +129,41 @@
     {
         if (m_backBuffer)
         {
-            // Use a third buffer to scale the picture
-            CComPtr<IDirectDrawSurface7> scaledSurface = GetScalingSurface(CSize(rect.Width(), rect.Height()));
-            CHECK_HR(scaledSurface->Blt(NULL, m_backBuffer, NULL, DDBLT_WAIT, NULL));
+            HDC backBufferDC;
+            CHECK_HR(m_backBuffer->GetDC(&backBufferDC));
 
-            HDC scaledDC;
-            CHECK_HR(scaledSurface->GetDC(&scaledDC));
-
             // Do not paint when the current displayed line is passing
             // our rect, when it does and we draw we get tearing.
             for(; ;)
             {
-                DWORD scanLine;
-                hr = m_directDraw7->GetScanLine(&scanLine);
+                D3DRASTER_STATUS rasterStatus;
+                hr = GetDevice()->GetRasterStatus(0, &rasterStatus);
 
-                if (hr ==  DDERR_VERTICALBLANKINPROGRESS)
+                if (FAILED(hr))
                 {
                     break;
                 }
 
-                if (FAILED(hr))
+                if (rasterStatus.InVBlank)
                 {
                     break;
                 }
 
-                if (scanLine >= (DWORD)rect.top && scanLine <= (DWORD)rect.bottom)
+                if (rasterStatus.ScanLine >= (DWORD)rect.top && rasterStatus.ScanLine <= (DWORD)rect.bottom)
                 {
+                    Sleep(1);
                     continue;
                 }
 
                 break;
             }
 
-            ::BitBlt(hdc, rect.left, rect.top, rect.Width(), rect.Height(), scaledDC, 0, 0, SRCCOPY);
+            ::BitBlt(hdc, rect.left, rect.top, rect.Width(), rect.Height(), backBufferDC, 0, 0, SRCCOPY);
 
-            CHECK_HR(scaledSurface->ReleaseDC(scaledDC));
+            CHECK_HR(m_backBuffer->ReleaseDC(backBufferDC));
+
+            m_width = rect.Width();
+            m_height = rect.Height();
         }
     }
     catch (const CAtlException& except)
@@ -237,6 +248,8 @@
 {
     m_filterGraph.SetNotifyWindow(m_hWnd);
     m_filterGraph.SetPresentImageMessage(WM_PRESENT_IMAGE);
+    m_filterGraph.SetD3D(m_d3d);
+    m_filterGraph.SetD3DDevice(GetDevice());
 
     m_isFirstFrame = true;
     m_filterGraph.BuildGraph(GetSrc());
@@ -307,19 +320,17 @@
     return 0;
 }
 
-CSize DShowVideoPlayer::GetSurfaceSize(const CComPtr<IDirectDrawSurface7>& surface)
+CSize DShowVideoPlayer::GetSurfaceSize(const CComPtr<IDirect3DSurface9>& surface)
 {
-    DDSURFACEDESC2 descriptor;
-    ZeroMemory(&descriptor, sizeof(DDSURFACEDESC2));
-    descriptor.dwSize = sizeof(DDSURFACEDESC2);
-    
-    surface->GetSurfaceDesc(&descriptor);
-    return CSize(descriptor.dwWidth, descriptor.dwHeight);
+    D3DSURFACE_DESC descriptor;
+    surface->GetDesc(&descriptor);
+
+    return CSize(descriptor.Width, descriptor.Height);
 }
 
 LRESULT DShowVideoPlayer::OnPresentImage(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
 {
-    VMRPRESENTATIONINFO* frame = reinterpret_cast<VMRPRESENTATIONINFO*>(lParam);
+    VMR9PresentationInfo* frame = reinterpret_cast<VMR9PresentationInfo*>(lParam);
 
     if (m_isFirstFrame)
     {
@@ -338,10 +349,11 @@
         return 0;
     }
 
-    HRESULT hr = m_backBuffer->BltFast(0, 0, frame->lpSurf, NULL, DDBLTFAST_DONOTWAIT);
+    CRect displayRect(0, 0, m_width, m_height);
+    HRESULT hr = GetDevice()->StretchRect(frame->lpSurf, 0, m_backBuffer, &displayRect, m_textureFilterType);
 
     LOG(logDEBUG2) << __FUNCTIONW__ << " Start: " << ReferenceTime(frame->rtStart) 
-        << " End: " << ReferenceTime(frame->rtEnd) << " result: 0x" << std::hex << hr;
+        << " End: " << ReferenceTime(frame->rtEnd) << " StretchRect result: 0x" << std::hex << hr;
 
     if (m_playerCallback)
     {

Modified: trunk/oggdsf/src/lib/plugin/AxPlayer/DShowVideoPlayer.h
===================================================================
--- trunk/oggdsf/src/lib/plugin/AxPlayer/DShowVideoPlayer.h	2010-03-10 16:03:11 UTC (rev 16959)
+++ trunk/oggdsf/src/lib/plugin/AxPlayer/DShowVideoPlayer.h	2010-03-10 23:04:34 UTC (rev 16960)
@@ -99,16 +99,18 @@
     void Thread_ExecuteFunction();
     
     void CreateBackBufferSurface(const CSize& videoSize);
-    CSize GetSurfaceSize(const CComPtr<IDirectDrawSurface7>& surface);
-    CComPtr<IDirectDrawSurface7> GetScalingSurface(const CSize &aSize);
+    CSize GetSurfaceSize(const CComPtr<IDirect3DSurface9>& surface);
+    CComPtr<IDirect3DSurface9>& GetScalingSurface(const CSize &aSize);
 
+    void CreateDevice();
+    CComPtr<IDirect3DDevice9>& GetDevice();
+
 private:
     FilterGraph m_filterGraph;
 
-    CComPtr<IDirectDraw7> m_directDraw7;
-    CComPtr<IDirectDrawSurface7> m_backBuffer;
-    CComPtr<IDirectDrawSurface7> m_scalingBuffer;
-    CSize m_scalingSize;
+    CComPtr<IDirect3D9> m_d3d;
+    CComPtr<IDirect3DDevice9> m_direct3dDevice;
+    CComPtr<IDirect3DSurface9> m_backBuffer;
 
     int m_width;
     int m_height;
@@ -126,6 +128,8 @@
 
     bool m_isFirstFrame;
     PlayerState m_state;
+
+    D3DTEXTUREFILTERTYPE m_textureFilterType;
 };
 
 #endif // DSHOWVIDEOPLAYER_H

Modified: trunk/oggdsf/src/lib/plugin/AxPlayer/FilterGraph.cpp
===================================================================
--- trunk/oggdsf/src/lib/plugin/AxPlayer/FilterGraph.cpp	2010-03-10 16:03:11 UTC (rev 16959)
+++ trunk/oggdsf/src/lib/plugin/AxPlayer/FilterGraph.cpp	2010-03-10 23:04:34 UTC (rev 16960)
@@ -36,7 +36,7 @@
 #include <uuids.h>
 
 #include "DShowUtil.h"
-#include "CustomVMR7Allocator.h"
+#include "CustomVMR9Allocator.h"
 
 namespace {
     const GUID CLSID_OggDemuxPacketSourceFilter =
@@ -152,8 +152,8 @@
                                                     L"DirectSound Renderer");
     
     // Add video renderer
-    m_videoRenderer = DShowUtil::AddFilterFromCLSID(m_graphBuilder, CLSID_VideoMixingRenderer,
-                                                    L"Video Renderer");
+    m_videoRenderer = DShowUtil::AddFilterFromCLSID(m_graphBuilder, CLSID_VideoMixingRenderer9,
+                                                    L"Video Mixing Renderer 9");
 }
 
 void FilterGraph::ConnnectRenderers()
@@ -179,39 +179,37 @@
 
 void FilterGraph::ConfigureVideoRenderer()
 {
-    CComQIPtr<IVMRFilterConfig> config = m_videoRenderer;
+    CComQIPtr<IVMRFilterConfig9> config = m_videoRenderer;
 
     if (!config)
     {
         return;
     }
 
-    CHECK_HR(config->SetRenderingMode(VMRMode_Renderless));
-
+    CHECK_HR(config->SetRenderingMode(VMR9Mode_Renderless));
     CHECK_HR(m_videoRenderer.QueryInterface(&m_surfaceNotify));
 
-    // Connect our custom VMR7 allocator
-    CComObject<CustomVMR7Allocator>::CreateInstance(&m_customVmrAllocator);
+    // Connect our custom VMR9 allocator
+    CComObject<CustomVMR9Allocator>::CreateInstance(&m_customVmrAllocator);
     m_customVmrAllocator->AddRef();
 
-    ATLASSERT(GetNotifyWindow() && "SetNotifyWindow should be called first!");
-    ATLASSERT(GetPresentImageMessage() && "SetPresentImageMessage should be called first!");
     m_customVmrAllocator->SetNotifyWindow(GetNotifyWindow());
     m_customVmrAllocator->SetPresentImageMessage(GetPresentImageMessage());
+    m_customVmrAllocator->SetD3D(GetD3D());
+    m_customVmrAllocator->SetD3DDevice(GetD3DDevice());
 
     CHECK_HR(m_surfaceNotify->AdviseSurfaceAllocator(ALLOCATOR_ID, m_customVmrAllocator));
-    CHECK_HR(m_customVmrAllocator->CreateDefaultSurfaceAllocator());
     CHECK_HR(m_customVmrAllocator->AdviseNotify(m_surfaceNotify));
 
     CHECK_HR(config->SetNumberOfStreams(1));
 
-    CComQIPtr<IVMRMixerControl> mixerControl = m_videoRenderer;
+    CComQIPtr<IVMRMixerControl9> mixerControl = m_videoRenderer;
 
     DWORD mixingPrefs;
     CHECK_HR(mixerControl->GetMixingPrefs(&mixingPrefs));
 
-    mixingPrefs &= ~MixerPref_RenderTargetMask;
-    mixingPrefs |= MixerPref_RenderTargetRGB;
+    mixingPrefs &= ~MixerPref9_RenderTargetMask;
+    mixingPrefs |= MixerPref9_RenderTargetRGB;
 
     CHECK_HR(mixerControl->SetMixingPrefs(mixingPrefs));
 }
@@ -272,6 +270,7 @@
 
 HWND FilterGraph::GetNotifyWindow() const
 {
+    ATLASSERT(m_notifyWindow && "SetNotifyWindow should be called first!");
     return m_notifyWindow;
 }
 
@@ -282,6 +281,7 @@
 
 int FilterGraph::GetPresentImageMessage() const
 {
+    ATLASSERT(m_presentImageMessage && "SetPresentImageMessage should be called first!");
     return m_presentImageMessage;
 }
 
@@ -331,3 +331,25 @@
 
     return eventCode;
 }
+
+CComPtr<IDirect3DDevice9> FilterGraph::GetD3DDevice() const
+{
+    ATLASSERT(m_d3dDevice && L"SetD3DDevice should have been called before");
+    return m_d3dDevice;
+}
+
+void FilterGraph::SetD3DDevice(const CComPtr<IDirect3DDevice9>& val)
+{
+    m_d3dDevice = val;
+}
+
+CComPtr<IDirect3D9> FilterGraph::GetD3D() const
+{
+    ATLASSERT(m_d3d && L"SetD3D should have been called before");
+    return m_d3d;
+}
+
+void FilterGraph::SetD3D(const CComPtr<IDirect3D9>& val)
+{
+    m_d3d = val;
+}
\ No newline at end of file

Modified: trunk/oggdsf/src/lib/plugin/AxPlayer/FilterGraph.h
===================================================================
--- trunk/oggdsf/src/lib/plugin/AxPlayer/FilterGraph.h	2010-03-10 16:03:11 UTC (rev 16959)
+++ trunk/oggdsf/src/lib/plugin/AxPlayer/FilterGraph.h	2010-03-10 23:04:34 UTC (rev 16960)
@@ -36,8 +36,10 @@
 
 #include <dshow.h>
 #include <strmif.h>
+#include <d3d9.h>
+#include <vmr9.h>
 
-class CustomVMR7Allocator;
+class CustomVMR9Allocator;
 
 class FilterGraph
 {
@@ -57,6 +59,12 @@
     int GetPresentImageMessage() const;
     void SetPresentImageMessage(int val);
 
+    CComPtr<IDirect3DDevice9> GetD3DDevice() const;
+    void SetD3DDevice(const CComPtr<IDirect3DDevice9>& val);
+
+    CComPtr<IDirect3D9> GetD3D() const;
+    void SetD3D(const CComPtr<IDirect3D9>& val);
+
     HANDLE GetMovieEventHandle();
     long GetMovieEventCode();
 
@@ -80,14 +88,16 @@
     CComPtr<IBaseFilter> m_audioRenderer;
     CComPtr<IBaseFilter> m_videoRenderer;
 
-    CComPtr<IVMRSurfaceAllocatorNotify> m_surfaceNotify;
-    CComObject<CustomVMR7Allocator>* m_customVmrAllocator;
+    CComPtr<IVMRSurfaceAllocatorNotify9> m_surfaceNotify;
+    CComObject<CustomVMR9Allocator>* m_customVmrAllocator;
 
     CComPtr<IMediaControl> m_mediaControl;
     CComPtr<IMediaEvent> m_mediaEvent;
     
     HWND m_notifyWindow;
     int m_presentImageMessage;
+    CComPtr<IDirect3D9> m_d3d;
+    CComPtr<IDirect3DDevice9> m_d3dDevice;
 
     bool m_haveAudio;
     bool m_haveVideo;



More information about the commits mailing list