]> git.vomp.tv Git - vompclient.git/blob - dsallocator.cc
Fixes (1) for new frame number navigation
[vompclient.git] / dsallocator.cc
1 /*
2     Copyright 2004-2005 Chris Tallon
3
4     This file is part of VOMP.
5
6     VOMP is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     VOMP is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with VOMP; if not, write to the Free Software
18     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 */
20 #include "osdwin.h"
21 #include "dsallocator.h"
22
23
24 DsAllocator::DsAllocator() {
25         CAutoLock locked(&objCritSec);
26         surfallocnotify=NULL;
27         refcount=1;
28         
29
30
31 }
32
33 DsAllocator::~DsAllocator() {
34         CAutoLock locked(&objCritSec);
35         CleanupSurfaces();
36
37 }
38
39 void DsAllocator::CleanupSurfaces() {
40         for (int i=0;i<surfaces.size();i++) {
41                 if (surfaces[i]!=NULL) surfaces[i]->Release();
42                 surfaces[i]=NULL;
43         }
44 }
45
46 HRESULT STDMETHODCALLTYPE DsAllocator::InitializeDevice(DWORD_PTR userid,VMR9AllocationInfo* allocinf,DWORD*numbuf){
47         CAutoLock locked(&objCritSec);
48         if (!surfallocnotify) return S_FALSE;
49         CleanupSurfaces();
50
51         surfaces.resize(*numbuf);
52         return surfallocnotify->AllocateSurfaceHelper(allocinf,numbuf,&surfaces.at(0));
53 }
54
55 void DsAllocator::LostDevice() {
56         CAutoLock locked(&objCritSec);
57         if (!surfallocnotify) return ;
58         CleanupSurfaces();
59         IDirect3DDevice9 *d3ddev;
60         d3ddev=((OsdWin*)Osd::getInstance())->getD3dDev();
61         HMONITOR hmon=((OsdWin*)Osd::getInstance())->getD3d()->GetAdapterMonitor(D3DADAPTER_DEFAULT);
62         surfallocnotify->ChangeD3DDevice(d3ddev,hmon);
63
64 }
65
66 HRESULT STDMETHODCALLTYPE DsAllocator::TerminateDevice(DWORD_PTR userid){
67         CAutoLock locked(&objCritSec);
68         CleanupSurfaces();
69         return S_OK; //Do nothing
70 }
71 HRESULT STDMETHODCALLTYPE DsAllocator::GetSurface(DWORD_PTR userid,DWORD surfindex,DWORD surfflags, IDirect3DSurface9** surf)
72 {
73         if (surfindex>=surfaces.size()) return E_FAIL;
74         if (surf==NULL) return E_POINTER;
75
76         CAutoLock locked(&objCritSec);
77         surfaces[surfindex]->AddRef();
78         *surf=surfaces[surfindex];
79         return S_OK;
80 }
81 HRESULT STDMETHODCALLTYPE DsAllocator::AdviseNotify(IVMRSurfaceAllocatorNotify9* allnoty){
82         CAutoLock locked(&objCritSec);
83         surfallocnotify=allnoty;
84         IDirect3DDevice9 *d3ddev;
85         //OK lets set the direct3d object from the osd
86         d3ddev=((OsdWin*)Osd::getInstance())->getD3dDev();
87         HMONITOR hmon=((OsdWin*)Osd::getInstance())->getD3d()->GetAdapterMonitor(D3DADAPTER_DEFAULT);
88         return surfallocnotify->SetD3DDevice(d3ddev,hmon);
89 }
90
91
92 HRESULT STDMETHODCALLTYPE DsAllocator::StartPresenting(DWORD_PTR userid){
93         ((OsdWin*)Osd::getInstance())->setExternalDriving(this);
94         return S_OK;
95 }
96 HRESULT STDMETHODCALLTYPE DsAllocator::StopPresenting(DWORD_PTR userid){
97         ((OsdWin*)Osd::getInstance())->setExternalDriving(NULL);
98         return S_OK;
99 }
100
101 HRESULT STDMETHODCALLTYPE DsAllocator::PresentImage(DWORD_PTR userid,VMR9PresentationInfo* presinf){
102         ((OsdWin*)Osd::getInstance())->RenderDS(presinf->lpSurf); //render and return
103         return S_OK;
104
105 }
106
107 HRESULT STDMETHODCALLTYPE DsAllocator::QueryInterface(REFIID refiid,void ** obj){\r
108         if (obj==NULL) return E_POINTER;\r
109 \r
110         if (refiid==IID_IVMRSurfaceAllocator9) {\r
111                  *obj=static_cast<IVMRSurfaceAllocator9*>(this);\r
112                  AddRef();\r
113                  return S_OK;\r
114         } else if (refiid==IID_IVMRImagePresenter9) {\r
115                 *obj=static_cast<IVMRImagePresenter9*>(this);\r
116                 AddRef();\r
117                 return S_OK;\r
118         }\r
119         return E_NOINTERFACE;\r
120 }\r
121 \r
122 ULONG STDMETHODCALLTYPE  DsAllocator::AddRef(){\r
123         return InterlockedIncrement(&refcount);\r
124 }
125
126 ULONG STDMETHODCALLTYPE DsAllocator::Release(){
127         ULONG ref=0;
128         ref=InterlockedDecrement(&refcount);
129         if (ref==NULL) {
130                 delete this; //Commit suicide
131         }
132         return ref;
133 }
134
135 \r