--- /dev/null
+/*
+ Copyright 2004-2005 Chris Tallon
+
+ This file is part of VOMP.
+
+ VOMP is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ VOMP is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with VOMP; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+#include "osdwin.h"
+#include "dsallocator.h"
+
+
+DsAllocator::DsAllocator() {
+ CAutoLock locked(&objCritSec);
+ surfallocnotify=NULL;
+ refcount=1;
+
+
+
+}
+
+DsAllocator::~DsAllocator() {
+ CAutoLock locked(&objCritSec);
+ CleanupSurfaces();
+
+}
+
+void DsAllocator::CleanupSurfaces() {
+ for (int i=0;i<surfaces.size();i++) {
+ if (surfaces[i]!=NULL) surfaces[i]->Release();
+ surfaces[i]=NULL;
+ }
+}
+
+HRESULT STDMETHODCALLTYPE DsAllocator::InitializeDevice(DWORD_PTR userid,VMR9AllocationInfo* allocinf,DWORD*numbuf){
+ CAutoLock locked(&objCritSec);
+ if (!surfallocnotify) return S_FALSE;
+ CleanupSurfaces();
+
+ surfaces.resize(*numbuf);
+ return surfallocnotify->AllocateSurfaceHelper(allocinf,numbuf,&surfaces.at(0));
+}
+
+void DsAllocator::LostDevice() {
+ CAutoLock locked(&objCritSec);
+ if (!surfallocnotify) return ;
+ CleanupSurfaces();
+ IDirect3DDevice9 *d3ddev;
+ d3ddev=((OsdWin*)Osd::getInstance())->getD3dDev();
+ HMONITOR hmon=((OsdWin*)Osd::getInstance())->getD3d()->GetAdapterMonitor(D3DADAPTER_DEFAULT);
+ surfallocnotify->ChangeD3DDevice(d3ddev,hmon);
+
+}
+
+HRESULT STDMETHODCALLTYPE DsAllocator::TerminateDevice(DWORD_PTR userid){
+ CAutoLock locked(&objCritSec);
+ CleanupSurfaces();
+ return S_OK; //Do nothing
+}
+HRESULT STDMETHODCALLTYPE DsAllocator::GetSurface(DWORD_PTR userid,DWORD surfindex,DWORD surfflags, IDirect3DSurface9** surf)
+{
+ if (surfindex>=surfaces.size()) return E_FAIL;
+ if (surf==NULL) return E_POINTER;
+
+ CAutoLock locked(&objCritSec);
+ surfaces[surfindex]->AddRef();
+ *surf=surfaces[surfindex];
+ return S_OK;
+}
+HRESULT STDMETHODCALLTYPE DsAllocator::AdviseNotify(IVMRSurfaceAllocatorNotify9* allnoty){
+ CAutoLock locked(&objCritSec);
+ surfallocnotify=allnoty;
+ IDirect3DDevice9 *d3ddev;
+ //OK lets set the direct3d object from the osd
+ d3ddev=((OsdWin*)Osd::getInstance())->getD3dDev();
+ HMONITOR hmon=((OsdWin*)Osd::getInstance())->getD3d()->GetAdapterMonitor(D3DADAPTER_DEFAULT);
+ return surfallocnotify->SetD3DDevice(d3ddev,hmon);
+}
+
+
+HRESULT STDMETHODCALLTYPE DsAllocator::StartPresenting(DWORD_PTR userid){
+ ((OsdWin*)Osd::getInstance())->setExternalDriving(this);
+ return S_OK;
+}
+HRESULT STDMETHODCALLTYPE DsAllocator::StopPresenting(DWORD_PTR userid){
+ ((OsdWin*)Osd::getInstance())->setExternalDriving(NULL);
+ return S_OK;
+}
+
+HRESULT STDMETHODCALLTYPE DsAllocator::PresentImage(DWORD_PTR userid,VMR9PresentationInfo* presinf){
+ ((OsdWin*)Osd::getInstance())->RenderDS(presinf->lpSurf); //render and return
+ return S_OK;
+
+}
+
+HRESULT STDMETHODCALLTYPE DsAllocator::QueryInterface(REFIID refiid,void ** obj){\r
+ if (obj==NULL) return E_POINTER;\r
+\r
+ if (refiid==IID_IVMRSurfaceAllocator9) {\r
+ *obj=static_cast<IVMRSurfaceAllocator9*>(this);\r
+ AddRef();\r
+ return S_OK;\r
+ } else if (refiid==IID_IVMRImagePresenter9) {\r
+ *obj=static_cast<IVMRImagePresenter9*>(this);\r
+ AddRef();\r
+ return S_OK;\r
+ }\r
+ return E_NOINTERFACE;\r
+}\r
+\r
+ULONG STDMETHODCALLTYPE DsAllocator::AddRef(){\r
+ return InterlockedIncrement(&refcount);\r
+}
+
+ULONG STDMETHODCALLTYPE DsAllocator::Release(){
+ ULONG ref=0;
+ ref=InterlockedDecrement(&refcount);
+ if (ref==NULL) {
+ delete this; //Commit suicide
+ }
+ return ref;
+}
+
+\r
--- /dev/null
+/*
+ Copyright 2004-2005 Chris Tallon
+
+ This file is part of VOMP.
+
+ VOMP is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ VOMP is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with VOMP; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+#ifndef DSALLOCATOR_H
+#define DSALLOCATOR_H
+
+#include <vector>
+using namespace std;
+#include <winsock2.h>
+#include <streams.h>
+#include <d3d9.h>
+#include <vmr9.h>
+
+
+
+
+class DsAllocator: public IVMRSurfaceAllocator9, IVMRImagePresenter9 {
+public:
+ DsAllocator();
+ virtual ~DsAllocator();
+
+ virtual HRESULT STDMETHODCALLTYPE StartPresenting(DWORD_PTR userid);
+ virtual HRESULT STDMETHODCALLTYPE StopPresenting(DWORD_PTR userid);
+ virtual HRESULT STDMETHODCALLTYPE PresentImage(DWORD_PTR userid,VMR9PresentationInfo* presinf);
+
+ virtual HRESULT STDMETHODCALLTYPE InitializeDevice(DWORD_PTR userid,
+ VMR9AllocationInfo* allocinf,DWORD* numbuf);
+ virtual HRESULT STDMETHODCALLTYPE TerminateDevice(DWORD_PTR userid);
+ virtual HRESULT STDMETHODCALLTYPE GetSurface(DWORD_PTR userid,DWORD surfindex,DWORD surfflags, IDirect3DSurface9** surf);
+ virtual HRESULT STDMETHODCALLTYPE AdviseNotify(IVMRSurfaceAllocatorNotify9* allnoty);
+ \r
+\r
+ virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID refiid,void ** obj);\r
+ virtual ULONG STDMETHODCALLTYPE AddRef();\r
+ virtual ULONG STDMETHODCALLTYPE Release();\r
+\r
+ void LostDevice();
+
+protected:
+
+ vector<IDirect3DSurface9* > surfaces;
+ CCritSec objCritSec;
+ IVMRSurfaceAllocatorNotify9* surfallocnotify;
+ void CleanupSurfaces();
+ LONG refcount;
+
+
+};
+
+
+
+
+
+
+
+#endif\r