]> git.vomp.tv Git - vompclient.git/blob - dsallocator.cc
Demuxer::scanForVideo()
[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         surfallocnotify=NULL;
26         refcount=1;
27         
28
29
30 }
31
32 DsAllocator::~DsAllocator() {
33         CleanupSurfaces();
34
35 }
36
37 void DsAllocator::CleanupSurfaces() {
38         for (int i=0;i<surfaces.size();i++) {
39                 if (surfaces[i]!=NULL) surfaces[i]->Release();
40                 surfaces[i]=NULL;
41         }
42 }
43
44 HRESULT STDMETHODCALLTYPE DsAllocator::InitializeDevice(DWORD_PTR userid,VMR9AllocationInfo* allocinf,DWORD*numbuf){
45         if (!surfallocnotify) return S_FALSE;
46         Lock();
47         CleanupSurfaces();
48
49         surfaces.resize(*numbuf);
50         HRESULT hres= surfallocnotify->AllocateSurfaceHelper(allocinf,numbuf,&surfaces.at(0));
51         Unlock();
52         return hres;
53 }
54
55 void DsAllocator::LostDevice() {
56         if (!surfallocnotify) return ;
57         Lock();
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         Unlock();
64
65 }
66
67 HRESULT STDMETHODCALLTYPE DsAllocator::TerminateDevice(DWORD_PTR userid){
68         Lock();
69         CleanupSurfaces();
70         Unlock();
71         return S_OK; //Do nothing
72 }
73 HRESULT STDMETHODCALLTYPE DsAllocator::GetSurface(DWORD_PTR userid,DWORD surfindex,DWORD surfflags, IDirect3DSurface9** surf)
74 {
75         if (surfindex>=surfaces.size()) return E_FAIL;
76         if (surf==NULL) return E_POINTER;
77
78         Lock();
79         surfaces[surfindex]->AddRef();
80         *surf=surfaces[surfindex];
81         Unlock();
82         return S_OK;
83 }
84 HRESULT STDMETHODCALLTYPE DsAllocator::AdviseNotify(IVMRSurfaceAllocatorNotify9* allnoty){
85         Lock();
86         surfallocnotify=allnoty;
87         IDirect3DDevice9 *d3ddev;
88         //OK lets set the direct3d object from the osd
89         d3ddev=((OsdWin*)Osd::getInstance())->getD3dDev();
90         HMONITOR hmon=((OsdWin*)Osd::getInstance())->getD3d()->GetAdapterMonitor(D3DADAPTER_DEFAULT);
91         HRESULT hres=surfallocnotify->SetD3DDevice(d3ddev,hmon);
92         Unlock();
93         return hres;
94 }
95
96
97 HRESULT STDMETHODCALLTYPE DsAllocator::StartPresenting(DWORD_PTR userid){
98         ((OsdWin*)Osd::getInstance())->setExternalDriving(this);
99         return S_OK;
100 }
101 HRESULT STDMETHODCALLTYPE DsAllocator::StopPresenting(DWORD_PTR userid){
102         ((OsdWin*)Osd::getInstance())->setExternalDriving(NULL);
103         return S_OK;
104 }
105
106 HRESULT STDMETHODCALLTYPE DsAllocator::PresentImage(DWORD_PTR userid,VMR9PresentationInfo* presinf){
107         ((OsdWin*)Osd::getInstance())->RenderDS(presinf->lpSurf); //render and return
108         return S_OK;
109
110 }
111
112 HRESULT STDMETHODCALLTYPE DsAllocator::QueryInterface(REFIID refiid,void ** obj){\r
113         if (obj==NULL) return E_POINTER;\r
114 \r
115         if (refiid==IID_IVMRSurfaceAllocator9) {\r
116                  *obj=static_cast<IVMRSurfaceAllocator9*>(this);\r
117                  AddRef();\r
118                  return S_OK;\r
119         } else if (refiid==IID_IVMRImagePresenter9) {\r
120                 *obj=static_cast<IVMRImagePresenter9*>(this);\r
121                 AddRef();\r
122                 return S_OK;\r
123         }\r
124         return E_NOINTERFACE;\r
125 }\r
126 \r
127 ULONG STDMETHODCALLTYPE  DsAllocator::AddRef(){\r
128         return InterlockedIncrement(&refcount);\r
129 }
130
131 ULONG STDMETHODCALLTYPE DsAllocator::Release(){
132         ULONG ref=0;
133         ref=InterlockedDecrement(&refcount);
134         if (ref==NULL) {
135                 delete this; //Commit suicide
136         }
137         return ref;
138 }
139
140 \r