]> git.vomp.tv Git - vompclient.git/blob - dsallocator.h
Convert PlayerRadioRec to std::thread
[vompclient.git] / dsallocator.h
1 /*
2     Copyright 2004-2005 Chris Tallon, Marten Richter
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, see <https://www.gnu.org/licenses/>.
18 */
19 #ifndef DSALLOCATOR_H
20 #define DSALLOCATOR_H
21
22 #include <queue>
23 #include <vector>
24 #include <mutex>
25
26 #include <winsock2.h>
27
28 #include <d3d9.h>
29 #include <dshow.h> 
30 #include <vmr9.h>
31 #include <evr.h>
32
33
34 //The Allocator and Presenter for VMR9 is also a Presnter for EVR
35
36 class DsAllocator: public IVMRSurfaceAllocator9, IVMRImagePresenter9, IMFVideoDeviceID,
37     IMFTopologyServiceLookupClient,public IMFVideoPresenter,IMFGetService, IQualProp {
38   public:
39     DsAllocator();
40     virtual ~DsAllocator();
41
42     virtual HRESULT STDMETHODCALLTYPE StartPresenting(DWORD_PTR userid);
43     virtual HRESULT STDMETHODCALLTYPE StopPresenting(DWORD_PTR userid);
44     virtual HRESULT STDMETHODCALLTYPE PresentImage(DWORD_PTR userid,VMR9PresentationInfo* presinf);
45
46     virtual HRESULT STDMETHODCALLTYPE InitializeDevice(DWORD_PTR userid, VMR9AllocationInfo* allocinf,DWORD* numbuf);
47     virtual HRESULT STDMETHODCALLTYPE TerminateDevice(DWORD_PTR userid);
48     virtual HRESULT STDMETHODCALLTYPE GetSurface(DWORD_PTR userid,DWORD surfindex,DWORD surfflags, IDirect3DSurface9** surf);
49     virtual HRESULT STDMETHODCALLTYPE AdviseNotify(IVMRSurfaceAllocatorNotify9* allnoty);
50
51     virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID refiid,void ** obj);
52     virtual ULONG STDMETHODCALLTYPE AddRef();
53     virtual ULONG STDMETHODCALLTYPE Release();
54
55     void LostDevice(IDirect3DDevice9 *d3ddev, IDirect3D9* d3d);
56
57     /* EVR members */
58     virtual HRESULT STDMETHODCALLTYPE GetDeviceID(IID *pDid);
59
60     virtual HRESULT STDMETHODCALLTYPE InitServicePointers(IMFTopologyServiceLookup *plooky);
61     virtual HRESULT STDMETHODCALLTYPE ReleaseServicePointers();
62
63     virtual HRESULT STDMETHODCALLTYPE ProcessMessage(MFVP_MESSAGE_TYPE mess,ULONG_PTR mess_para);
64
65     virtual HRESULT STDMETHODCALLTYPE OnClockStart(MFTIME systime,LONGLONG startoffset);
66     virtual HRESULT STDMETHODCALLTYPE OnClockStop(MFTIME systime);
67     virtual HRESULT STDMETHODCALLTYPE OnClockPause(MFTIME systime);
68     virtual HRESULT STDMETHODCALLTYPE OnClockRestart(MFTIME systime);
69     virtual HRESULT STDMETHODCALLTYPE OnClockSetRate(MFTIME systime,float rate);
70     virtual HRESULT STDMETHODCALLTYPE GetCurrentMediaType(IMFVideoMediaType **mtype);
71
72     virtual HRESULT STDMETHODCALLTYPE GetService(const GUID &guid,const IID &iid,LPVOID *obj);
73
74     virtual HRESULT STDMETHODCALLTYPE get_FramesDrawn(int *val);
75     virtual HRESULT STDMETHODCALLTYPE get_AvgFrameRate(int *val);
76     virtual HRESULT STDMETHODCALLTYPE get_Jitter(int *val);
77     virtual HRESULT STDMETHODCALLTYPE get_AvgSyncOffset(int *val);
78     virtual HRESULT STDMETHODCALLTYPE get_DevSyncOffset(int *val);
79     virtual HRESULT STDMETHODCALLTYPE get_FramesDroppedInRenderer(int *val);
80
81     void GetNextSurface(LPDIRECT3DSURFACE9 *surf,DWORD *waittime);
82     void DiscardSurfaceandgetWait(DWORD *waittime);
83
84 protected:
85
86     void RenegotiateEVRMediaType();
87     void AllocateEVRSurfaces();
88     void FlushEVRSamples();
89     void GetEVRSamples();
90
91     void ResetSyncOffsets();
92     void CalcSyncOffsets(int sync);
93     void CalcJitter(int jitter);
94
95     std::vector<IDirect3DSurface9*> surfaces;
96     std::queue<IMFSample*> emptyevrsamples;
97     std::queue<IMFSample*> fullevrsamples;
98     //CCritSec objCritSec;
99     IVMRSurfaceAllocatorNotify9* surfallocnotify;
100     void CleanupSurfaces();
101     LONG refcount;
102     DWORD vheight;
103     DWORD vwidth;
104     bool inevrmode;
105     bool endofstream;
106     bool start_get_evr_samples;
107
108     IMFTransform* mftransform;
109     IMediaEventSink* mediasink;
110     IMFClock* mfclock;
111     IMFMediaType *mfmediatype;
112
113     static const int n_stats=126;
114     int sync_offset[n_stats];
115     int jitter_offset[n_stats];
116     unsigned int sync_pos;
117     unsigned int jitter_pos;
118     int framesdrawn;
119     int framesdropped;
120     int avg_sync_offset;
121     int dev_sync_offset;
122     int jitter;
123     int avgfps;
124     LONGLONG lastdelframe;
125
126     std::mutex dsaLock;
127 };
128
129 #endif