]>
Commit | Line | Data |
---|---|---|
1a680109 RN |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: msw/mediactrl.cpp | |
ff4aedc5 | 3 | // Purpose: Built-in Media Backends for Windows |
1a680109 | 4 | // Author: Ryan Norton <wxprojects@comcast.net> |
72259e00 | 5 | // Modified by: |
1a680109 RN |
6 | // Created: 11/07/04 |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Ryan Norton | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
ff4aedc5 RN |
12 | //=========================================================================== |
13 | // DECLARATIONS | |
14 | //=========================================================================== | |
15 | ||
1a680109 | 16 | //--------------------------------------------------------------------------- |
ff4aedc5 | 17 | // Pre-compiled header stuff |
1a680109 RN |
18 | //--------------------------------------------------------------------------- |
19 | ||
ff4aedc5 RN |
20 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
21 | #pragma implementation "mediactrl.h" | |
22 | #endif | |
1a680109 RN |
23 | |
24 | // For compilers that support precompilation, includes "wx.h". | |
25 | #include "wx/wxprec.h" | |
26 | ||
27 | #ifdef __BORLANDC__ | |
28 | #pragma hdrstop | |
29 | #endif | |
30 | ||
ff4aedc5 RN |
31 | //--------------------------------------------------------------------------- |
32 | // Includes | |
33 | //--------------------------------------------------------------------------- | |
1a680109 RN |
34 | #include "wx/mediactrl.h" |
35 | ||
ff4aedc5 RN |
36 | //--------------------------------------------------------------------------- |
37 | // Compilation guard | |
38 | //--------------------------------------------------------------------------- | |
1a680109 RN |
39 | #if wxUSE_MEDIACTRL |
40 | ||
1a680109 | 41 | //--------------------------------------------------------------------------- |
ff4aedc5 | 42 | // Externals (somewhere in src/msw/app.cpp) |
1a680109 | 43 | //--------------------------------------------------------------------------- |
ff4aedc5 RN |
44 | extern "C" WXDLLIMPEXP_BASE HINSTANCE wxGetInstance(void); |
45 | #ifdef __WXWINCE__ | |
7a4d2469 | 46 | extern WXDLLIMPEXP_CORE wxChar *wxCanvasClassName; |
ff4aedc5 | 47 | #else |
316d19ac | 48 | extern WXDLLIMPEXP_CORE const wxChar *wxCanvasClassName; |
ff4aedc5 | 49 | #endif |
1a680109 | 50 | |
ff4aedc5 RN |
51 | //=========================================================================== |
52 | // BACKEND DECLARATIONS | |
53 | //=========================================================================== | |
1a680109 RN |
54 | |
55 | //--------------------------------------------------------------------------- | |
ff4aedc5 RN |
56 | // |
57 | // wxAMMediaBackend | |
58 | // | |
1a680109 | 59 | //--------------------------------------------------------------------------- |
920a7c15 JS |
60 | // |
61 | //####################THE BIG DIRECTSHOW OVERVIEW############################ | |
62 | // | |
63 | // | |
64 | // OK... this deserves its own little tutorial. Knowledge of COM and class | |
65 | // factories is assumed throughout this code. | |
66 | // | |
67 | // Basically, the way directshow works is that you tell it to render | |
68 | // a file, and it builds and connects a bunch of filters together. | |
69 | // | |
70 | // There are many, many ways to do this. | |
71 | // | |
72 | // WAYS TO RENDER A FILE (URLS WORK IN DS ALSO) | |
73 | // | |
74 | // 1) Create an instance of IGraphBuilder and call RenderFile on it | |
75 | // 2) Create an instance of IMediaControl and call RenderFile on it | |
76 | // 3) Create an instance of IAMMultiMediaStream, call | |
77 | // IAMMultiMediaStream::AddStream and pass an IDirectDraw instance for | |
78 | // the video, and pass an IDirectSound(Buffer?) instance or use the | |
79 | // default sound renderer, then call RenderFile or RenderMoniker | |
80 | // 4) Create a Moniker instance for the file and create and build | |
81 | // all of the filtergraph manually | |
82 | // | |
83 | // Our issue here is that we can't use the default representation of 1 and 2 | |
84 | // because the IVideoWindow instance hogs a lot of the useful window | |
85 | // messages such as WM_SETCURSOR. | |
86 | // | |
87 | // Solution #1 was to use #3 by creating a seperate IDirectDraw instance | |
88 | // for our window and blitting to that through a thread... unfortunately | |
89 | // the blitting resizing is very low quality and its quite slow. | |
90 | // | |
91 | // The current way is to use windowless rendering and have directshow | |
92 | // do all the DirectDraw-style clipping to our window | |
93 | // | |
94 | // ~~~~~~~~~~~~~~AFTER RENDERING THE FILE~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
95 | // | |
96 | // When done rendering the file, we need to get several interfaces from | |
97 | // either a IMediaControl or IGraphBuilder instance - | |
98 | // | |
99 | // IMediaPosition - we can set the rate with this... we can also get | |
100 | // positions and set positions through this with REFTIME (double) instead | |
101 | // of the normal LONGLONG that IAMMultiMediaStream and IMediaControl use | |
102 | // | |
103 | // IBasicAudio - we need this for setting/getting the volume | |
104 | // | |
105 | // Interfaces that we don't use but might be useful one day - | |
106 | // | |
107 | // IDirectDrawVideo - you can get this through the IFilter returned | |
108 | // from L"Video Renderer" filter from FindFilter on the IGraphBuilder. | |
109 | // Through this we can set the IDirectDraw instance DrawShow uses. | |
110 | // | |
111 | // ~~~~~~~~~~~~~~STOPPING~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
112 | // | |
113 | // There are two ways we can do this - | |
114 | // 1) Have a thread compare the current position to the end position | |
115 | // about every 10 milliseconds | |
116 | // 2) Have IMediaSeekingEx send a message to a windowproc or signal a | |
117 | // windows event | |
118 | // | |
119 | // Note that we can do these both, I.E. if an IMediaSeekingEx interface | |
120 | // is unavailable we can check the position instead of an event | |
121 | // | |
122 | //--------------------------------------------------------------------------- | |
1a680109 | 123 | |
ff4aedc5 | 124 | //--------------------------------------------------------------------------- |
a2a444e3 RN |
125 | // COM includes |
126 | //--------------------------------------------------------------------------- | |
127 | #include "wx/msw/ole/oleutils.h" //wxBasicString, IID etc. | |
128 | #include "wx/msw/ole/uuid.h" //IID etc.. | |
129 | ||
920a7c15 JS |
130 | //--------------------------------------------------------------------------- |
131 | // COM compatability definitions | |
132 | //--------------------------------------------------------------------------- | |
133 | #ifndef STDMETHODCALLTYPE | |
134 | #define STDMETHODCALLTYPE __stdcall | |
135 | #endif | |
136 | #ifndef STDMETHOD | |
137 | #define STDMETHOD(funcname) virtual HRESULT STDMETHODCALLTYPE funcname | |
138 | #endif | |
139 | #ifndef PURE | |
140 | #define PURE = 0 | |
141 | #endif | |
a2a444e3 RN |
142 | //--------------------------------------------------------------------------- |
143 | // IIDS - used by CoCreateInstance and IUnknown::QueryInterface | |
920a7c15 JS |
144 | // Dumped from amstream.idl, quartz.idl, direct draw and with some |
145 | // confirmation from WINE | |
146 | // | |
147 | // Some of these are not used but are kept here for future reference anyway | |
a2a444e3 | 148 | //--------------------------------------------------------------------------- |
920a7c15 JS |
149 | |
150 | //QUARTZ | |
a2a444e3 RN |
151 | const IID LIBID_QuartzTypeLib = {0x56A868B0,0x0AD4,0x11CE,{0xB0,0x3A,0x00,0x20,0xAF,0x0B,0xA7,0x70}}; |
152 | const IID IID_IAMCollection = {0x56A868B9,0x0AD4,0x11CE,{0xB0,0x3A,0x00,0x20,0xAF,0x0B,0xA7,0x70}}; | |
153 | const IID IID_IMediaControl = {0x56A868B1,0x0AD4,0x11CE,{0xB0,0x3A,0x00,0x20,0xAF,0x0B,0xA7,0x70}}; | |
154 | const IID IID_IMediaEvent = {0x56A868B6,0x0AD4,0x11CE,{0xB0,0x3A,0x00,0x20,0xAF,0x0B,0xA7,0x70}}; | |
155 | const IID IID_IMediaEventEx = {0x56A868C0,0x0AD4,0x11CE,{0xB0,0x3A,0x00,0x20,0xAF,0x0B,0xA7,0x70}}; | |
156 | const IID IID_IMediaPosition = {0x56A868B2,0x0AD4,0x11CE,{0xB0,0x3A,0x00,0x20,0xAF,0x0B,0xA7,0x70}}; | |
157 | const IID IID_IBasicAudio = {0x56A868B3,0x0AD4,0x11CE,{0xB0,0x3A,0x00,0x20,0xAF,0x0B,0xA7,0x70}}; | |
158 | const IID IID_IVideoWindow = {0x56A868B4,0x0AD4,0x11CE,{0xB0,0x3A,0x00,0x20,0xAF,0x0B,0xA7,0x70}}; | |
159 | const IID IID_IBasicVideo = {0x56A868B5,0x0AD4,0x11CE,{0xB0,0x3A,0x00,0x20,0xAF,0x0B,0xA7,0x70}}; | |
160 | const IID IID_IBasicVideo2 = {0x329BB360,0xF6EA,0x11D1,{0x90,0x38,0x00,0xA0,0xC9,0x69,0x72,0x98}}; | |
161 | const IID IID_IDeferredCommand = {0x56A868B8,0x0AD4,0x11CE,{0xB0,0x3A,0x00,0x20,0xAF,0x0B,0xA7,0x70}}; | |
162 | const IID IID_IQueueCommand = {0x56A868B7,0x0AD4,0x11CE,{0xB0,0x3A,0x00,0x20,0xAF,0x0B,0xA7,0x70}}; | |
163 | const IID IID_IFilterInfo = {0x56A868BA,0x0AD4,0x11CE,{0xB0,0x3A,0x00,0x20,0xAF,0x0B,0xA7,0x70}}; | |
164 | const IID IID_IRegFilterInfo = {0x56A868BB,0x0AD4,0x11CE,{0xB0,0x3A,0x00,0x20,0xAF,0x0B,0xA7,0x70}}; | |
165 | const IID IID_IMediaTypeInfo = {0x56A868BC,0x0AD4,0x11CE,{0xB0,0x3A,0x00,0x20,0xAF,0x0B,0xA7,0x70}}; | |
166 | const IID IID_IPinInfo = {0x56A868BD,0x0AD4,0x11CE,{0xB0,0x3A,0x00,0x20,0xAF,0x0B,0xA7,0x70}}; | |
167 | const IID IID_IAMStats = {0xBC9BCF80,0xDCD2,0x11D2,{0xAB,0xF6,0x00,0xA0,0xC9,0x05,0xF3,0x75}}; | |
a2a444e3 RN |
168 | const CLSID CLSID_FilgraphManager = {0xE436EBB3,0x524F,0x11CE,{0x9F,0x53,0x00,0x20,0xAF,0x0B,0xA7,0x70}}; |
169 | ||
920a7c15 JS |
170 | //AMSTREAM |
171 | const CLSID CLSID_AMMultiMediaStream = {0x49C47CE5, 0x9BA4, 0x11D0,{0x82, 0x12, 0x00, 0xC0, 0x4F, 0xC3, 0x2C, 0x45}}; | |
172 | const IID IID_IAMMultiMediaStream = {0xBEBE595C, 0x9A6F, 0x11D0,{0x8F, 0xDE, 0x00, 0xC0, 0x4F, 0xD9, 0x18, 0x9D}}; | |
173 | const IID IID_IDirectDrawMediaStream = {0xF4104FCE, 0x9A70, 0x11D0,{0x8F, 0xDE, 0x00, 0xC0, 0x4F, 0xD9, 0x18, 0x9D}}; | |
174 | const GUID MSPID_PrimaryVideo = {0xa35FF56A, 0x9FDA, 0x11D0,{0x8F, 0xDF, 0x00, 0xC0, 0x4F, 0xD9, 0x18, 0x9D}}; | |
175 | const GUID MSPID_PrimaryAudio = {0xa35FF56B, 0x9FDA, 0x11D0,{0x8F, 0xDF, 0x00, 0xC0, 0x4F, 0xD9, 0x18, 0x9D}}; | |
176 | ||
177 | //DDRAW | |
178 | const IID IID_IDirectDraw = {0x6C14DB80,0xA733,0x11CE,{0xA5,0x21,0x00,0x20,0xAF,0x0B,0xE5,0x60}}; | |
179 | const CLSID CLSID_DirectDraw = {0xD7B70EE0,0x4340,0x11CF,{0xB0,0x63,0x00,0x20,0xAF,0xC2,0xCD,0x35}}; | |
180 | ||
181 | //?? QUARTZ Also? | |
182 | const CLSID CLSID_VideoMixingRenderer = {0xB87BEB7B, 0x8D29, 0x423F,{0xAE, 0x4D, 0x65, 0x82, 0xC1, 0x01, 0x75, 0xAC}}; | |
183 | const IID IID_IVMRWindowlessControl = {0x0EB1088C, 0x4DCD, 0x46F0,{0x87, 0x8F, 0x39, 0xDA, 0xE8, 0x6A, 0x51, 0xB7}}; | |
184 | const IID IID_IFilterGraph = {0x56A8689F, 0x0AD4, 0x11CE,{0xB0, 0x3A, 0x00, 0x20, 0xAF, 0x0B, 0xA7, 0x70}}; | |
185 | const IID IID_IGraphBuilder = {0x56A868A9, 0x0AD4, 0x11CE,{0xB0, 0x3A, 0x00, 0x20, 0xAF, 0x0B, 0xA7, 0x70}}; | |
186 | const IID IID_IVMRFilterConfig = {0x9E5530C5, 0x7034, 0x48B4,{0xBB, 0x46, 0x0B, 0x8A, 0x6E, 0xFC, 0x8E, 0x36}}; | |
187 | const IID IID_IBaseFilter = {0x56A86895, 0x0AD4, 0x11CE,{0xB0, 0x3A, 0x00, 0x20, 0xAF, 0x0B, 0xA7, 0x70}}; | |
188 | ||
189 | //--------------------------------------------------------------------------- | |
190 | // DIRECTDRAW COM INTERFACES | |
191 | //--------------------------------------------------------------------------- | |
192 | //DDSURFACESDESC - we don't need most of the stuff here, esp. DDPIXELFORMAT, | |
193 | //so just put stubs in | |
194 | struct DDPIXELFORMAT {DWORD dw1,dw2,dw3,dw4,dw5,dw6,dw7,dw8;}; | |
195 | struct DDCOLORKEY {DWORD dwLow, dwHigh;}; | |
196 | ||
197 | typedef struct IDirectDrawClipper* LPDIRECTDRAWCLIPPER; | |
198 | typedef struct IDirectDraw* LPDIRECTDRAW; | |
199 | typedef struct IDirectDrawSurface* LPDIRECTDRAWSURFACE; | |
200 | typedef struct DDSURFACEDESC* LPDDSURFACEDESC; | |
201 | typedef struct IDirectDrawPalette* LPDIRECTDRAWPALETTE; | |
202 | typedef struct DDSCAPS* LPDDSCAPS; | |
203 | typedef DDCOLORKEY* LPDDCOLORKEY; | |
204 | typedef DDPIXELFORMAT* LPDDPIXELFORMAT; | |
205 | typedef struct DDCAPS* LPDDCAPS; | |
206 | ||
207 | struct DDSURFACEDESC | |
208 | { | |
209 | DWORD dwSize; | |
210 | DWORD dwFlags; | |
211 | DWORD dwHeight; | |
212 | DWORD dwWidth; | |
213 | union | |
214 | { | |
215 | LONG lPitch; | |
216 | DWORD dwLinearSize; | |
217 | }; | |
218 | DWORD dwBackBufferCount; | |
219 | union | |
220 | { | |
221 | DWORD dwMipMapCount; | |
222 | DWORD dwZBufferBitDepth; | |
223 | DWORD dwRefreshRate; | |
224 | }; | |
225 | DWORD dwAlphaBitDepth; | |
226 | DWORD dwReserved; | |
227 | LPVOID lpSurface; | |
228 | DDCOLORKEY ddckCKDestOverlay; | |
229 | DDCOLORKEY ddckCKDestBlt; | |
230 | DDCOLORKEY ddckCKSrcOverlay; | |
231 | DDCOLORKEY ddckCKSrcBlt; | |
232 | DDPIXELFORMAT ddpfPixelFormat; | |
233 | struct DDSCAPS {DWORD dwCaps;} ddsCaps; | |
a2a444e3 RN |
234 | }; |
235 | ||
920a7c15 | 236 | struct IDirectDrawClipper : public IUnknown |
a2a444e3 | 237 | { |
920a7c15 JS |
238 | STDMETHOD(GetClipList)(LPRECT, LPRGNDATA, LPDWORD) PURE; |
239 | STDMETHOD(GetHWnd)(HWND*) PURE; | |
240 | STDMETHOD(Initialize)(LPDIRECTDRAW, DWORD) PURE; | |
241 | STDMETHOD(IsClipListChanged)(BOOL*) PURE; | |
242 | STDMETHOD(SetClipList)(LPRGNDATA,DWORD) PURE; | |
243 | STDMETHOD(SetHWnd)(DWORD, HWND) PURE; | |
a2a444e3 RN |
244 | }; |
245 | ||
920a7c15 JS |
246 | struct IDirectDrawSurface : public IUnknown |
247 | { | |
248 | STDMETHOD(AddAttachedSurface)(LPDIRECTDRAWSURFACE) PURE; | |
249 | STDMETHOD(AddOverlayDirtyRect)(LPRECT) PURE; | |
250 | STDMETHOD(Blt)(LPRECT,LPDIRECTDRAWSURFACE, LPRECT,DWORD, struct DDBLTFX*) PURE; | |
251 | STDMETHOD(BltBatch)(struct DDBLTBATCH*, DWORD, DWORD ) PURE; | |
252 | STDMETHOD(BltFast)(DWORD,DWORD,LPDIRECTDRAWSURFACE, LPRECT,DWORD) PURE; | |
253 | STDMETHOD(DeleteAttachedSurface)(DWORD,LPDIRECTDRAWSURFACE) PURE; | |
254 | STDMETHOD(EnumAttachedSurfaces)(LPVOID, LPVOID/*LPDDENUMSURFACESCALLBACK*/) PURE; | |
255 | STDMETHOD(EnumOverlayZOrders)(DWORD,LPVOID,LPVOID/*LPDDENUMSURFACESCALLBACK*/) PURE; | |
256 | STDMETHOD(Flip)(LPDIRECTDRAWSURFACE, DWORD) PURE; | |
257 | STDMETHOD(GetAttachedSurface)(LPDDSCAPS, LPDIRECTDRAWSURFACE*) PURE; | |
258 | STDMETHOD(GetBltStatus)(DWORD) PURE; | |
259 | STDMETHOD(GetCaps)(LPDDSCAPS) PURE; | |
260 | STDMETHOD(GetClipper)(LPDIRECTDRAWCLIPPER*) PURE; | |
261 | STDMETHOD(GetColorKey)(DWORD, LPDDCOLORKEY) PURE; | |
262 | STDMETHOD(GetDC)(HDC *) PURE; | |
263 | STDMETHOD(GetFlipStatus)(DWORD) PURE; | |
264 | STDMETHOD(GetOverlayPosition)(LPLONG, LPLONG ) PURE; | |
265 | STDMETHOD(GetPalette)(LPDIRECTDRAWPALETTE FAR*) PURE; | |
266 | STDMETHOD(GetPixelFormat)(LPDDPIXELFORMAT) PURE; | |
267 | STDMETHOD(GetSurfaceDesc)(LPDDSURFACEDESC) PURE; | |
268 | STDMETHOD(Initialize)(LPDIRECTDRAW, LPDDSURFACEDESC) PURE; | |
269 | STDMETHOD(IsLost)(THIS) PURE; | |
270 | STDMETHOD(Lock)(LPRECT,LPDDSURFACEDESC,DWORD,HANDLE) PURE; | |
271 | STDMETHOD(ReleaseDC)(HDC) PURE; | |
272 | STDMETHOD(Restore)(THIS) PURE; | |
273 | STDMETHOD(SetClipper)(LPDIRECTDRAWCLIPPER) PURE; | |
274 | STDMETHOD(SetColorKey)(DWORD, LPDDCOLORKEY) PURE; | |
275 | STDMETHOD(SetOverlayPosition)(LONG, LONG ) PURE; | |
276 | STDMETHOD(SetPalette)(IUnknown*) PURE; | |
277 | STDMETHOD(Unlock)(LPVOID) PURE; | |
278 | STDMETHOD(UpdateOverlay)(LPRECT, LPDIRECTDRAWSURFACE,LPRECT, | |
279 | DWORD, struct DDOVERLAYFX*) PURE; | |
280 | STDMETHOD(UpdateOverlayDisplay)(DWORD) PURE; | |
281 | STDMETHOD(UpdateOverlayZOrder)(DWORD, LPDIRECTDRAWSURFACE) PURE; | |
a2a444e3 RN |
282 | }; |
283 | ||
920a7c15 JS |
284 | struct IDirectDraw : public IUnknown |
285 | { | |
286 | STDMETHOD(Compact)() PURE; | |
287 | STDMETHOD(CreateClipper)(DWORD, LPDIRECTDRAWCLIPPER*, IUnknown * ) PURE; | |
288 | STDMETHOD(CreatePalette)(DWORD, LPPALETTEENTRY, LPDIRECTDRAWPALETTE *, IUnknown * ) PURE; | |
289 | STDMETHOD(CreateSurface)(LPDDSURFACEDESC, LPDIRECTDRAWSURFACE *, IUnknown *) PURE; | |
290 | STDMETHOD(DuplicateSurface)(LPDIRECTDRAWSURFACE, LPDIRECTDRAWSURFACE * ) PURE; | |
291 | STDMETHOD(EnumDisplayModes)(DWORD, LPDDSURFACEDESC, LPVOID, LPVOID ) PURE; | |
292 | STDMETHOD(EnumSurfaces)(DWORD, LPDDSURFACEDESC, LPVOID,LPVOID ) PURE; | |
293 | STDMETHOD(FlipToGDISurface)() PURE; | |
294 | STDMETHOD(GetCaps)(LPDDCAPS, LPDDCAPS) PURE; | |
295 | STDMETHOD(GetDisplayMode)(LPDDSURFACEDESC) PURE; | |
296 | STDMETHOD(GetFourCCCodes)(LPDWORD, LPDWORD ) PURE; | |
297 | STDMETHOD(GetGDISurface)(LPDIRECTDRAWSURFACE *) PURE; | |
298 | STDMETHOD(GetMonitorFrequency)(LPDWORD) PURE; | |
299 | STDMETHOD(GetScanLine)(LPDWORD) PURE; | |
300 | STDMETHOD(GetVerticalBlankStatus)(LPBOOL ) PURE; | |
301 | STDMETHOD(Initialize)(GUID *) PURE; | |
302 | STDMETHOD(RestoreDisplayMode)() PURE; | |
303 | STDMETHOD(SetCooperativeLevel)(HWND, DWORD) PURE; | |
304 | STDMETHOD(SetDisplayMode)(DWORD, DWORD,DWORD, DWORD, DWORD) PURE; | |
305 | STDMETHOD(WaitForVerticalBlank)(DWORD, HANDLE ) PURE; | |
306 | }; | |
307 | ||
308 | //--------------------------------------------------------------------------- | |
309 | // AMMEDIA COM INTERFACES | |
310 | //--------------------------------------------------------------------------- | |
311 | struct IMediaStream; | |
312 | struct IMultiMediaStream; | |
313 | struct IStreamSample : public IUnknown | |
a2a444e3 RN |
314 | { |
315 | public: | |
920a7c15 JS |
316 | STDMETHOD(GetMediaStream)(IMediaStream **) PURE; |
317 | STDMETHOD(GetSampleTimes)(LONGLONG *, LONGLONG *, LONGLONG *) PURE; | |
318 | STDMETHOD(SetSampleTimes)(const LONGLONG *, const LONGLONG *) PURE; | |
319 | STDMETHOD(Update)(DWORD, HANDLE, LPVOID, DWORD_PTR) PURE; | |
320 | STDMETHOD(CompletionStatus)(DWORD, DWORD) PURE; | |
a2a444e3 | 321 | }; |
b11eba7e | 322 | |
920a7c15 | 323 | struct IDirectDrawStreamSample : public IStreamSample |
a2a444e3 RN |
324 | { |
325 | public: | |
920a7c15 JS |
326 | STDMETHOD(GetSurface)(IDirectDrawSurface **, RECT *) PURE; |
327 | STDMETHOD(SetRect)(const RECT *) PURE; | |
a2a444e3 RN |
328 | }; |
329 | ||
920a7c15 | 330 | struct IMediaStream : public IUnknown |
a2a444e3 | 331 | { |
920a7c15 JS |
332 | STDMETHOD(GetMultiMediaStream)(IMultiMediaStream **) PURE; |
333 | STDMETHOD(GetInformation)(GUID *, int *) PURE; | |
334 | STDMETHOD(SetSameFormat)(IMediaStream *, DWORD) PURE; | |
335 | STDMETHOD(AllocateSample)(DWORD, IStreamSample **) PURE; | |
336 | STDMETHOD(CreateSharedSample)(IStreamSample *, DWORD, | |
337 | IStreamSample **) PURE; | |
338 | STDMETHOD(SendEndOfStream)(DWORD dwFlags) PURE; | |
a2a444e3 | 339 | }; |
b11eba7e | 340 | |
920a7c15 | 341 | struct IDirectDrawMediaStream : public IMediaStream |
a2a444e3 | 342 | { |
920a7c15 JS |
343 | STDMETHOD(GetFormat)(DDSURFACEDESC *, IDirectDrawPalette **, |
344 | DDSURFACEDESC *, DWORD *) PURE; | |
345 | STDMETHOD(SetFormat)(const DDSURFACEDESC *, IDirectDrawPalette *) PURE; | |
346 | STDMETHOD(GetDirectDraw)(IDirectDraw **) PURE; | |
347 | STDMETHOD(SetDirectDraw)(IDirectDraw *) PURE; | |
348 | STDMETHOD(CreateSample)(IDirectDrawSurface *, const RECT *, | |
349 | DWORD, IDirectDrawStreamSample **) PURE; | |
350 | STDMETHOD(GetTimePerFrame)(LONGLONG *) PURE; | |
351 | }; | |
b11eba7e | 352 | |
920a7c15 JS |
353 | struct IMultiMediaStream : public IUnknown |
354 | { | |
355 | STDMETHOD(GetInformation)(DWORD *, int *) PURE; | |
356 | STDMETHOD(GetMediaStream)(REFGUID, IMediaStream **) PURE; | |
357 | STDMETHOD(EnumMediaStreams)(long, IMediaStream **) PURE; | |
358 | STDMETHOD(GetState)(int *pCurrentState) PURE; | |
359 | STDMETHOD(SetState)(int NewState) PURE; | |
360 | STDMETHOD(GetTime)(LONGLONG *pCurrentTime) PURE; | |
361 | STDMETHOD(GetDuration)(LONGLONG *pDuration) PURE; | |
362 | STDMETHOD(Seek)(LONGLONG SeekTime) PURE; | |
363 | STDMETHOD(GetEndOfStreamEventHandle)(HANDLE *phEOS) PURE; | |
a2a444e3 | 364 | }; |
1a680109 | 365 | |
920a7c15 | 366 | struct IAMMultiMediaStream : public IMultiMediaStream |
a2a444e3 | 367 | { |
920a7c15 JS |
368 | STDMETHOD(Initialize)(int, DWORD, IUnknown *) PURE; |
369 | STDMETHOD(GetFilterGraph)(IUnknown **) PURE; | |
370 | STDMETHOD(GetFilter)(IUnknown **) PURE; | |
371 | STDMETHOD(AddMediaStream)(IUnknown *, const GUID*, DWORD, | |
372 | IMediaStream **) PURE; | |
373 | STDMETHOD(OpenFile)(LPCWSTR, DWORD) PURE; | |
374 | STDMETHOD(OpenMoniker)(IBindCtx *, IMoniker *, DWORD) PURE; | |
375 | STDMETHOD(Render)(DWORD) PURE; | |
a2a444e3 | 376 | }; |
b11eba7e | 377 | |
920a7c15 JS |
378 | //--------------------------------------------------------------------------- |
379 | // QUARTZ COM INTERFACES (dumped from quartz.idl from MSVC COM Browser) | |
380 | //--------------------------------------------------------------------------- | |
381 | struct IAMCollection : public IDispatch | |
a2a444e3 | 382 | { |
920a7c15 JS |
383 | STDMETHOD(get_Count)(long *) PURE; |
384 | STDMETHOD(Item)(long, IUnknown **) PURE; | |
385 | STDMETHOD(get__NewEnum)(IUnknown **) PURE; | |
386 | }; | |
b11eba7e | 387 | |
920a7c15 JS |
388 | struct IMediaControl : public IDispatch |
389 | { | |
390 | STDMETHOD(Run)() PURE; | |
391 | STDMETHOD(Pause)() PURE; | |
392 | STDMETHOD(Stop)() PURE; | |
393 | STDMETHOD(GetState)(long, long*) PURE; | |
394 | STDMETHOD(RenderFile)(BSTR) PURE; | |
395 | STDMETHOD(AddSourceFilter)(BSTR, IDispatch **) PURE; | |
396 | STDMETHOD(get_FilterCollection)(IDispatch **) PURE; | |
397 | STDMETHOD(get_RegFilterCollection)(IDispatch **) PURE; | |
398 | STDMETHOD(StopWhenReady)() PURE; | |
a2a444e3 | 399 | }; |
b11eba7e | 400 | |
920a7c15 | 401 | struct IMediaEvent : public IDispatch |
a2a444e3 | 402 | { |
920a7c15 JS |
403 | STDMETHOD(GetEventHandle)(LONG_PTR *) PURE; |
404 | STDMETHOD(GetEvent)(long *, LONG_PTR *, LONG_PTR *, long) PURE; | |
405 | STDMETHOD(WaitForCompletion)(long, long *) PURE; | |
406 | STDMETHOD(CancelDefaultHandling)(long) PURE; | |
407 | STDMETHOD(RestoreDefaultHandling)(long) PURE; | |
408 | STDMETHOD(FreeEventParams)(long, LONG_PTR, LONG_PTR) PURE; | |
a2a444e3 RN |
409 | }; |
410 | ||
920a7c15 | 411 | struct IMediaEventEx : public IMediaEvent |
a2a444e3 | 412 | { |
920a7c15 JS |
413 | STDMETHOD(SetNotifyWindow)(LONG_PTR, long, LONG_PTR) PURE; |
414 | STDMETHOD(SetNotifyFlags)(long) PURE; | |
415 | STDMETHOD(GetNotifyFlags)(long *) PURE; | |
416 | }; | |
b11eba7e | 417 | |
920a7c15 JS |
418 | struct IMediaPosition : public IDispatch |
419 | { | |
420 | STDMETHOD(get_Duration)(double *) PURE; | |
421 | STDMETHOD(put_CurrentPosition)(double) PURE; | |
422 | STDMETHOD(get_CurrentPosition)(double *) PURE; | |
423 | STDMETHOD(get_StopTime)(double *) PURE; | |
424 | STDMETHOD(put_StopTime)(double) PURE; | |
425 | STDMETHOD(get_PrerollTime)(double *) PURE; | |
426 | STDMETHOD(put_PrerollTime)(double) PURE; | |
427 | STDMETHOD(put_Rate)(double) PURE; | |
428 | STDMETHOD(get_Rate)(double *) PURE; | |
429 | STDMETHOD(CanSeekForward)(long *) PURE; | |
430 | STDMETHOD(CanSeekBackward)(long *) PURE; | |
a2a444e3 | 431 | }; |
b11eba7e | 432 | |
920a7c15 | 433 | struct IBasicAudio : public IDispatch |
a2a444e3 | 434 | { |
920a7c15 JS |
435 | STDMETHOD(put_Volume)(long) PURE; |
436 | STDMETHOD(get_Volume)(long *) PURE; | |
437 | STDMETHOD(put_Balance)(long) PURE; | |
438 | STDMETHOD(get_Balance)(long *) PURE; | |
a2a444e3 | 439 | }; |
b11eba7e | 440 | |
920a7c15 JS |
441 | //--------------------------------------------------------------------------- |
442 | // MISC COM INTERFACES | |
443 | //--------------------------------------------------------------------------- | |
444 | struct IVMRWindowlessControl : public IUnknown | |
445 | { | |
446 | STDMETHOD(GetNativeVideoSize)(LONG *, LONG *, LONG *, LONG *) PURE; | |
447 | STDMETHOD(GetMinIdealVideoSize)(LONG *, LONG *) PURE; | |
448 | STDMETHOD(GetMaxIdealVideoSize)(LONG *, LONG *) PURE; | |
449 | STDMETHOD(SetVideoPosition)(const LPRECT,const LPRECT) PURE; | |
450 | STDMETHOD(GetVideoPosition)(LPRECT, LPRECT) PURE; | |
451 | STDMETHOD(GetAspectRatioMode)(DWORD *) PURE; | |
452 | STDMETHOD(SetAspectRatioMode)(DWORD) PURE; | |
453 | STDMETHOD(SetVideoClippingWindow)(HWND) PURE; | |
454 | STDMETHOD(RepaintVideo)(HWND, HDC) PURE; | |
455 | STDMETHOD(DisplayModeChanged)() PURE; | |
456 | STDMETHOD(GetCurrentImage)(BYTE **) PURE; | |
457 | STDMETHOD(SetBorderColor)(COLORREF) PURE; | |
458 | STDMETHOD(GetBorderColor)(COLORREF *) PURE; | |
459 | STDMETHOD(SetColorKey)(COLORREF) PURE; | |
460 | STDMETHOD(GetColorKey)(COLORREF *) PURE; | |
461 | }; | |
b11eba7e | 462 | |
920a7c15 | 463 | typedef IUnknown IVMRImageCompositor; |
b11eba7e | 464 | |
920a7c15 JS |
465 | struct IVMRFilterConfig : public IUnknown |
466 | { | |
467 | STDMETHOD(SetImageCompositor)(IVMRImageCompositor *) PURE; | |
468 | STDMETHOD(SetNumberOfStreams)(DWORD) PURE; | |
469 | STDMETHOD(GetNumberOfStreams)(DWORD *) PURE; | |
470 | STDMETHOD(SetRenderingPrefs)(DWORD) PURE; | |
471 | STDMETHOD(GetRenderingPrefs)(DWORD *) PURE; | |
472 | STDMETHOD(SetRenderingMode)(DWORD) PURE; | |
473 | STDMETHOD(GetRenderingMode)(DWORD *) PURE; | |
474 | }; | |
475 | ||
476 | typedef IUnknown IBaseFilter; | |
477 | typedef IUnknown IPin; | |
478 | typedef IUnknown IEnumFilters; | |
479 | typedef int AM_MEDIA_TYPE; | |
480 | ||
481 | struct IFilterGraph : public IUnknown | |
482 | { | |
483 | STDMETHOD(AddFilter)(IBaseFilter *, LPCWSTR) PURE; | |
484 | STDMETHOD(RemoveFilter)(IBaseFilter *) PURE; | |
485 | STDMETHOD(EnumFilters)(IEnumFilters **) PURE; | |
486 | STDMETHOD(FindFilterByName)(LPCWSTR, IBaseFilter **) PURE; | |
487 | STDMETHOD(ConnectDirect)(IPin *, IPin *, const AM_MEDIA_TYPE *) PURE; | |
488 | STDMETHOD(Reconnect)(IPin *) PURE; | |
489 | STDMETHOD(Disconnect)(IPin *) PURE; | |
490 | STDMETHOD(SetDefaultSyncSource)() PURE; | |
a2a444e3 | 491 | }; |
b11eba7e | 492 | |
920a7c15 | 493 | struct IGraphBuilder : public IFilterGraph |
a2a444e3 RN |
494 | { |
495 | public: | |
920a7c15 JS |
496 | STDMETHOD(Connect)(IPin *, IPin *) PURE; |
497 | STDMETHOD(Render)(IPin *) PURE; | |
498 | STDMETHOD(RenderFile)(LPCWSTR, LPCWSTR) PURE; | |
499 | STDMETHOD(AddSourceFilter)(LPCWSTR, LPCWSTR, IBaseFilter **) PURE; | |
500 | STDMETHOD(SetLogFile)(DWORD_PTR) PURE; | |
501 | STDMETHOD(Abort)() PURE; | |
502 | STDMETHOD(ShouldOperationContinue)() PURE; | |
a2a444e3 | 503 | }; |
b11eba7e | 504 | |
920a7c15 JS |
505 | //------------------------------------------------------------------ |
506 | // wxAMMediaBackend (Active Movie) | |
507 | //------------------------------------------------------------------ | |
508 | class WXDLLIMPEXP_MEDIA wxAMMediaThread : public wxThread | |
a2a444e3 RN |
509 | { |
510 | public: | |
920a7c15 | 511 | virtual ExitCode Entry(); |
b11eba7e | 512 | |
920a7c15 | 513 | class wxAMMediaBackend* pThis; |
a2a444e3 RN |
514 | }; |
515 | ||
920a7c15 JS |
516 | //cludgy workaround for wx events. slots would be nice :) |
517 | class WXDLLIMPEXP_MEDIA wxAMMediaEvtHandler : public wxEvtHandler | |
a2a444e3 RN |
518 | { |
519 | public: | |
920a7c15 JS |
520 | void OnPaint(wxPaintEvent&); |
521 | void OnMove(wxMoveEvent&); | |
522 | void OnSize(wxSizeEvent&); | |
523 | void OnEraseBackground(wxEraseEvent&); | |
a2a444e3 RN |
524 | }; |
525 | ||
920a7c15 JS |
526 | typedef BOOL (WINAPI* LPAMGETERRORTEXT)(HRESULT, wxChar *, DWORD); |
527 | ||
ff2b312f | 528 | class WXDLLIMPEXP_MEDIA wxAMMediaBackend : public wxMediaBackend |
1a680109 RN |
529 | { |
530 | public: | |
ff4aedc5 | 531 | wxAMMediaBackend(); |
1a680109 | 532 | |
ff4aedc5 | 533 | virtual ~wxAMMediaBackend(); |
1a680109 | 534 | |
226ec5a7 | 535 | virtual bool CreateControl(wxControl* ctrl, wxWindow* parent, |
ff4aedc5 | 536 | wxWindowID id, |
226ec5a7 | 537 | const wxPoint& pos, |
ff4aedc5 | 538 | const wxSize& size, |
226ec5a7 | 539 | long style, |
ff4aedc5 RN |
540 | const wxValidator& validator, |
541 | const wxString& name); | |
1a680109 RN |
542 | |
543 | virtual bool Play(); | |
544 | virtual bool Pause(); | |
545 | virtual bool Stop(); | |
546 | ||
547 | virtual bool Load(const wxString& fileName); | |
548 | virtual bool Load(const wxURI& location); | |
549 | ||
550 | virtual wxMediaState GetState(); | |
551 | ||
ff4aedc5 RN |
552 | virtual bool SetPosition(wxLongLong where); |
553 | virtual wxLongLong GetPosition(); | |
554 | virtual wxLongLong GetDuration(); | |
1a680109 | 555 | |
ff4aedc5 RN |
556 | virtual void Move(int x, int y, int w, int h); |
557 | wxSize GetVideoSize() const; | |
1a680109 RN |
558 | |
559 | virtual double GetPlaybackRate(); | |
560 | virtual bool SetPlaybackRate(double); | |
561 | ||
6f8c67e7 JS |
562 | virtual double GetVolume(); |
563 | virtual bool SetVolume(double); | |
564 | ||
1a680109 | 565 | void Cleanup(); |
920a7c15 JS |
566 | void OnStop(); |
567 | bool SetWindowlessMode(IGraphBuilder* pGB, | |
568 | IVMRWindowlessControl** ppVMC = NULL); | |
1a680109 | 569 | |
ff4aedc5 | 570 | wxControl* m_ctrl; |
1a680109 | 571 | |
920a7c15 JS |
572 | wxMediaState m_state; |
573 | wxCriticalSection m_rendercs; | |
574 | ||
575 | IVMRWindowlessControl* m_pVMC; | |
576 | IGraphBuilder* m_pGB; | |
a2a444e3 | 577 | IBasicAudio* m_pBA; |
1a680109 | 578 | IMediaControl* m_pMC; |
920a7c15 | 579 | IMediaEvent* m_pME; |
a2a444e3 | 580 | IMediaPosition* m_pMS; |
920a7c15 JS |
581 | |
582 | wxAMMediaThread* m_pThread; | |
1a680109 RN |
583 | |
584 | wxSize m_bestSize; | |
ff4aedc5 | 585 | |
920a7c15 JS |
586 | #ifdef __WXDEBUG__ |
587 | HMODULE m_hQuartzDll; | |
588 | LPAMGETERRORTEXT m_lpAMGetErrorText; | |
589 | #endif | |
590 | ||
591 | friend class wxAMMediaThread; | |
592 | friend class wxAMMediaEvtHandler; | |
593 | ||
19b6f122 | 594 | DECLARE_DYNAMIC_CLASS(wxAMMediaBackend) |
1a680109 RN |
595 | }; |
596 | ||
1a680109 | 597 | //--------------------------------------------------------------------------- |
ff4aedc5 RN |
598 | // |
599 | // wxMCIMediaBackend | |
600 | // | |
1a680109 RN |
601 | //--------------------------------------------------------------------------- |
602 | ||
ff4aedc5 RN |
603 | //--------------------------------------------------------------------------- |
604 | // MCI Includes | |
605 | //--------------------------------------------------------------------------- | |
1a680109 | 606 | #include <mmsystem.h> |
1a680109 | 607 | |
ff2b312f | 608 | class WXDLLIMPEXP_MEDIA wxMCIMediaBackend : public wxMediaBackend |
1a680109 RN |
609 | { |
610 | public: | |
3f9a3bf9 | 611 | |
ff4aedc5 RN |
612 | wxMCIMediaBackend(); |
613 | ~wxMCIMediaBackend(); | |
1a680109 | 614 | |
226ec5a7 | 615 | virtual bool CreateControl(wxControl* ctrl, wxWindow* parent, |
ff4aedc5 | 616 | wxWindowID id, |
226ec5a7 | 617 | const wxPoint& pos, |
ff4aedc5 | 618 | const wxSize& size, |
226ec5a7 | 619 | long style, |
ff4aedc5 RN |
620 | const wxValidator& validator, |
621 | const wxString& name); | |
1a680109 RN |
622 | |
623 | virtual bool Play(); | |
624 | virtual bool Pause(); | |
625 | virtual bool Stop(); | |
626 | ||
627 | virtual bool Load(const wxString& fileName); | |
628 | virtual bool Load(const wxURI& location); | |
629 | ||
630 | virtual wxMediaState GetState(); | |
631 | ||
ff4aedc5 RN |
632 | virtual bool SetPosition(wxLongLong where); |
633 | virtual wxLongLong GetPosition(); | |
634 | virtual wxLongLong GetDuration(); | |
1a680109 | 635 | |
ff4aedc5 RN |
636 | virtual void Move(int x, int y, int w, int h); |
637 | wxSize GetVideoSize() const; | |
1a680109 RN |
638 | |
639 | virtual double GetPlaybackRate(); | |
ff4aedc5 | 640 | virtual bool SetPlaybackRate(double dRate); |
3f9a3bf9 | 641 | |
6f8c67e7 JS |
642 | virtual double GetVolume(); |
643 | virtual bool SetVolume(double); | |
644 | ||
226ec5a7 | 645 | static LRESULT CALLBACK NotifyWndProc(HWND hWnd, UINT nMsg, |
ff4aedc5 | 646 | WPARAM wParam, LPARAM lParam); |
5987f174 | 647 | |
226ec5a7 | 648 | LRESULT CALLBACK OnNotifyWndProc(HWND hWnd, UINT nMsg, |
ff4aedc5 | 649 | WPARAM wParam, LPARAM lParam); |
1a680109 | 650 | |
ff4aedc5 RN |
651 | MCIDEVICEID m_hDev; //Our MCI Device ID/Handler |
652 | wxControl* m_ctrl; //Parent control | |
653 | HWND m_hNotifyWnd; //Window to use for MCI events | |
654 | bool m_bVideo; //Whether or not we have video | |
655 | ||
3839f37e | 656 | DECLARE_DYNAMIC_CLASS(wxMCIMediaBackend) |
ff4aedc5 | 657 | }; |
1a680109 RN |
658 | |
659 | //--------------------------------------------------------------------------- | |
660 | // | |
ff4aedc5 | 661 | // wxQTMediaBackend |
1a680109 RN |
662 | // |
663 | //--------------------------------------------------------------------------- | |
664 | ||
ff4aedc5 RN |
665 | //--------------------------------------------------------------------------- |
666 | // QT Includes | |
667 | //--------------------------------------------------------------------------- | |
d7a9c895 RN |
668 | //#include <qtml.h> //Windoze QT include |
669 | //#include <QuickTimeComponents.h> //Standard QT stuff | |
670 | #include "wx/dynlib.h" | |
671 | ||
672 | //--------------------------------------------------------------------------- | |
673 | // QT Types | |
674 | //--------------------------------------------------------------------------- | |
675 | typedef struct MovieRecord* Movie; | |
676 | typedef wxInt16 OSErr; | |
677 | typedef wxInt32 OSStatus; | |
678 | #define noErr 0 | |
679 | #define fsRdPerm 1 | |
680 | typedef unsigned char Str255[256]; | |
681 | #define StringPtr unsigned char* | |
682 | #define newMovieActive 1 | |
b11eba7e | 683 | #define Ptr char* |
d7a9c895 RN |
684 | #define Handle Ptr* |
685 | #define Fixed long | |
686 | #define OSType unsigned long | |
b11eba7e | 687 | #define CGrafPtr struct GrafPort * |
d7a9c895 | 688 | #define TimeScale long |
b11eba7e | 689 | #define TimeBase struct TimeBaseRecord * |
d7a9c895 | 690 | |
19b6f122 WS |
691 | #ifndef URLDataHandlerSubType |
692 | #if defined(__WATCOMC__) || defined(__MINGW32__) | |
693 | // use magic numbers for compilers which complain about multicharacter integers | |
694 | const OSType URLDataHandlerSubType = 1970433056; | |
695 | const OSType VisualMediaCharacteristic = 1702454643; | |
696 | #else | |
697 | const OSType URLDataHandlerSubType = 'url '; | |
698 | const OSType VisualMediaCharacteristic = 'eyes'; | |
699 | #endif | |
700 | #endif | |
701 | ||
d7a9c895 | 702 | struct FSSpec { |
600ffb32 WS |
703 | short vRefNum; |
704 | long parID; | |
705 | Str255 name; /*Str63 on mac, Str255 on msw */ | |
d7a9c895 RN |
706 | }; |
707 | ||
708 | struct Rect { | |
600ffb32 WS |
709 | short top; |
710 | short left; | |
711 | short bottom; | |
712 | short right; | |
d7a9c895 RN |
713 | }; |
714 | ||
715 | struct wide { | |
600ffb32 WS |
716 | wxInt32 hi; |
717 | wxUint32 lo; | |
d7a9c895 RN |
718 | }; |
719 | ||
720 | struct TimeRecord { | |
600ffb32 WS |
721 | wide value; /* units */ |
722 | TimeScale scale; /* units per second */ | |
723 | TimeBase base; | |
d7a9c895 RN |
724 | }; |
725 | ||
726 | //--------------------------------------------------------------------------- | |
727 | // QT Library | |
728 | //--------------------------------------------------------------------------- | |
729 | #define wxDL_METHOD_DEFINE( rettype, name, args, shortargs, defret ) \ | |
730 | typedef rettype (* name ## Type) args ; \ | |
731 | name ## Type pfn_ ## name; \ | |
732 | rettype name args \ | |
733 | { if (m_ok) return pfn_ ## name shortargs ; return defret; } | |
b11eba7e | 734 | |
d7a9c895 RN |
735 | #define wxDL_VOIDMETHOD_DEFINE( name, args, shortargs ) \ |
736 | typedef void (* name ## Type) args ; \ | |
737 | name ## Type pfn_ ## name; \ | |
738 | void name args \ | |
739 | { if (m_ok) pfn_ ## name shortargs ; } | |
740 | ||
741 | #define wxDL_METHOD_LOAD( lib, name, success ) \ | |
742 | pfn_ ## name = (name ## Type) lib.GetSymbol( wxT(#name), &success ); \ | |
743 | if (!success) return false; | |
744 | ||
745 | //Class that utilizes Robert Roeblings Dynamic Library Macros | |
b11eba7e | 746 | class WXDLLIMPEXP_MEDIA wxQuickTimeLibrary |
d7a9c895 RN |
747 | { |
748 | public: | |
749 | ~wxQuickTimeLibrary() | |
b11eba7e | 750 | { |
d7a9c895 RN |
751 | if(m_dll.IsLoaded()) |
752 | m_dll.Unload(); | |
753 | } | |
754 | ||
755 | bool Initialize(); | |
756 | bool IsOk() const {return m_ok;} | |
757 | ||
758 | protected: | |
759 | wxDynamicLibrary m_dll; | |
760 | bool m_ok; | |
761 | ||
762 | public: | |
763 | wxDL_VOIDMETHOD_DEFINE( StartMovie, (Movie m), (m) ); | |
764 | wxDL_VOIDMETHOD_DEFINE( StopMovie, (Movie m), (m) ); | |
765 | wxDL_METHOD_DEFINE( bool, IsMovieDone, (Movie m), (m), false); | |
766 | wxDL_VOIDMETHOD_DEFINE( GoToBeginningOfMovie, (Movie m), (m) ); | |
767 | wxDL_METHOD_DEFINE( OSErr, GetMoviesError, (), (), -1); | |
768 | wxDL_METHOD_DEFINE( OSErr, EnterMovies, (), (), -1); | |
769 | wxDL_VOIDMETHOD_DEFINE( ExitMovies, (), () ); | |
770 | wxDL_METHOD_DEFINE( OSErr, InitializeQTML, (long flags), (flags), -1); | |
771 | wxDL_VOIDMETHOD_DEFINE( TerminateQTML, (), () ); | |
772 | ||
b11eba7e WS |
773 | wxDL_METHOD_DEFINE( OSErr, NativePathNameToFSSpec, |
774 | (char* inName, FSSpec* outFile, long flags), | |
d7a9c895 RN |
775 | (inName, outFile, flags), -1); |
776 | ||
b11eba7e | 777 | wxDL_METHOD_DEFINE( OSErr, OpenMovieFile, |
d7a9c895 RN |
778 | (const FSSpec * fileSpec, short * resRefNum, wxInt8 permission), |
779 | (fileSpec, resRefNum, permission), -1 ); | |
780 | ||
781 | wxDL_METHOD_DEFINE( OSErr, CloseMovieFile, | |
782 | (short resRefNum), (resRefNum), -1); | |
783 | ||
784 | wxDL_METHOD_DEFINE( OSErr, NewMovieFromFile, | |
785 | (Movie * theMovie, short resRefNum, short * resId, | |
786 | StringPtr resName, short newMovieFlags, | |
b11eba7e | 787 | bool * dataRefWasChanged), |
d7a9c895 RN |
788 | (theMovie, resRefNum, resId, resName, newMovieFlags, |
789 | dataRefWasChanged), -1); | |
790 | ||
791 | wxDL_VOIDMETHOD_DEFINE( SetMovieRate, (Movie m, Fixed rate), (m, rate) ); | |
792 | wxDL_METHOD_DEFINE( Fixed, GetMovieRate, (Movie m), (m), 0); | |
793 | wxDL_VOIDMETHOD_DEFINE( MoviesTask, (Movie m, long maxms), (m, maxms) ); | |
b11eba7e | 794 | wxDL_VOIDMETHOD_DEFINE( BlockMove, |
d7a9c895 RN |
795 | (const char* p1, const char* p2, long s), (p1,p2,s) ); |
796 | wxDL_METHOD_DEFINE( Handle, NewHandleClear, (long s), (s), NULL ); | |
797 | ||
b11eba7e | 798 | wxDL_METHOD_DEFINE( OSErr, NewMovieFromDataRef, |
d7a9c895 RN |
799 | (Movie * m, short flags, short * id, |
800 | Handle dataRef, OSType dataRefType), | |
801 | (m,flags,id,dataRef,dataRefType), -1 ); | |
802 | ||
803 | wxDL_VOIDMETHOD_DEFINE( DisposeHandle, (Handle h), (h) ); | |
804 | wxDL_VOIDMETHOD_DEFINE( GetMovieNaturalBoundsRect, (Movie m, Rect* r), (m,r) ); | |
b11eba7e WS |
805 | wxDL_METHOD_DEFINE( void*, GetMovieIndTrackType, |
806 | (Movie m, long index, OSType type, long flags), | |
d7a9c895 | 807 | (m,index,type,flags), NULL ); |
b11eba7e | 808 | wxDL_VOIDMETHOD_DEFINE( CreatePortAssociation, |
d7a9c895 RN |
809 | (void* hWnd, void* junk, long morejunk), (hWnd, junk, morejunk) ); |
810 | wxDL_METHOD_DEFINE(void*, GetNativeWindowPort, (void* hWnd), (hWnd), NULL); | |
811 | wxDL_VOIDMETHOD_DEFINE(SetMovieGWorld, (Movie m, CGrafPtr port, void* whatever), | |
812 | (m, port, whatever) ); | |
813 | wxDL_VOIDMETHOD_DEFINE(DisposeMovie, (Movie m), (m) ); | |
814 | wxDL_VOIDMETHOD_DEFINE(SetMovieBox, (Movie m, Rect* r), (m,r)); | |
815 | wxDL_VOIDMETHOD_DEFINE(SetMovieTimeScale, (Movie m, long s), (m,s)); | |
816 | wxDL_METHOD_DEFINE(long, GetMovieDuration, (Movie m), (m), 0); | |
817 | wxDL_METHOD_DEFINE(TimeBase, GetMovieTimeBase, (Movie m), (m), 0); | |
818 | wxDL_METHOD_DEFINE(TimeScale, GetMovieTimeScale, (Movie m), (m), 0); | |
819 | wxDL_METHOD_DEFINE(long, GetMovieTime, (Movie m, void* cruft), (m,cruft), 0); | |
820 | wxDL_VOIDMETHOD_DEFINE(SetMovieTime, (Movie m, TimeRecord* tr), (m,tr) ); | |
6f8c67e7 JS |
821 | wxDL_METHOD_DEFINE(short, GetMovieVolume, (Movie m), (m), 0); |
822 | wxDL_VOIDMETHOD_DEFINE(SetMovieVolume, (Movie m, short sVolume), (m,sVolume) ); | |
d7a9c895 RN |
823 | }; |
824 | ||
825 | bool wxQuickTimeLibrary::Initialize() | |
826 | { | |
827 | m_ok = false; | |
828 | ||
829 | if(!m_dll.Load(wxT("qtmlClient.dll"))) | |
830 | return false; | |
831 | ||
832 | bool bOk; | |
833 | ||
834 | wxDL_METHOD_LOAD( m_dll, StartMovie, bOk ); | |
835 | wxDL_METHOD_LOAD( m_dll, StopMovie, bOk ); | |
836 | wxDL_METHOD_LOAD( m_dll, IsMovieDone, bOk ); | |
837 | wxDL_METHOD_LOAD( m_dll, GoToBeginningOfMovie, bOk ); | |
838 | wxDL_METHOD_LOAD( m_dll, GetMoviesError, bOk ); | |
839 | wxDL_METHOD_LOAD( m_dll, EnterMovies, bOk ); | |
840 | wxDL_METHOD_LOAD( m_dll, ExitMovies, bOk ); | |
841 | wxDL_METHOD_LOAD( m_dll, InitializeQTML, bOk ); | |
842 | wxDL_METHOD_LOAD( m_dll, TerminateQTML, bOk ); | |
843 | wxDL_METHOD_LOAD( m_dll, NativePathNameToFSSpec, bOk ); | |
844 | wxDL_METHOD_LOAD( m_dll, OpenMovieFile, bOk ); | |
845 | wxDL_METHOD_LOAD( m_dll, CloseMovieFile, bOk ); | |
846 | wxDL_METHOD_LOAD( m_dll, NewMovieFromFile, bOk ); | |
847 | wxDL_METHOD_LOAD( m_dll, GetMovieRate, bOk ); | |
848 | wxDL_METHOD_LOAD( m_dll, SetMovieRate, bOk ); | |
849 | wxDL_METHOD_LOAD( m_dll, MoviesTask, bOk ); | |
850 | wxDL_METHOD_LOAD( m_dll, BlockMove, bOk ); | |
851 | wxDL_METHOD_LOAD( m_dll, NewHandleClear, bOk ); | |
852 | wxDL_METHOD_LOAD( m_dll, NewMovieFromDataRef, bOk ); | |
853 | wxDL_METHOD_LOAD( m_dll, DisposeHandle, bOk ); | |
854 | wxDL_METHOD_LOAD( m_dll, GetMovieNaturalBoundsRect, bOk ); | |
855 | wxDL_METHOD_LOAD( m_dll, GetMovieIndTrackType, bOk ); | |
856 | wxDL_METHOD_LOAD( m_dll, CreatePortAssociation, bOk ); | |
857 | wxDL_METHOD_LOAD( m_dll, GetNativeWindowPort, bOk ); | |
858 | wxDL_METHOD_LOAD( m_dll, SetMovieGWorld, bOk ); | |
859 | wxDL_METHOD_LOAD( m_dll, DisposeMovie, bOk ); | |
860 | wxDL_METHOD_LOAD( m_dll, SetMovieBox, bOk ); | |
861 | wxDL_METHOD_LOAD( m_dll, SetMovieTimeScale, bOk ); | |
862 | wxDL_METHOD_LOAD( m_dll, GetMovieDuration, bOk ); | |
863 | wxDL_METHOD_LOAD( m_dll, GetMovieTimeBase, bOk ); | |
864 | wxDL_METHOD_LOAD( m_dll, GetMovieTimeScale, bOk ); | |
865 | wxDL_METHOD_LOAD( m_dll, GetMovieTime, bOk ); | |
866 | wxDL_METHOD_LOAD( m_dll, SetMovieTime, bOk ); | |
6f8c67e7 JS |
867 | wxDL_METHOD_LOAD( m_dll, GetMovieVolume, bOk ); |
868 | wxDL_METHOD_LOAD( m_dll, SetMovieVolume, bOk ); | |
b11eba7e | 869 | |
d7a9c895 RN |
870 | m_ok = true; |
871 | ||
872 | return true; | |
873 | } | |
1a680109 | 874 | |
ff2b312f | 875 | class WXDLLIMPEXP_MEDIA wxQTMediaBackend : public wxMediaBackend |
ff4aedc5 RN |
876 | { |
877 | public: | |
ff4aedc5 RN |
878 | wxQTMediaBackend(); |
879 | ~wxQTMediaBackend(); | |
1a680109 | 880 | |
226ec5a7 | 881 | virtual bool CreateControl(wxControl* ctrl, wxWindow* parent, |
ff4aedc5 | 882 | wxWindowID id, |
226ec5a7 | 883 | const wxPoint& pos, |
ff4aedc5 | 884 | const wxSize& size, |
226ec5a7 | 885 | long style, |
ff4aedc5 RN |
886 | const wxValidator& validator, |
887 | const wxString& name); | |
1a680109 | 888 | |
ff4aedc5 RN |
889 | virtual bool Play(); |
890 | virtual bool Pause(); | |
891 | virtual bool Stop(); | |
1a680109 | 892 | |
ff4aedc5 RN |
893 | virtual bool Load(const wxString& fileName); |
894 | virtual bool Load(const wxURI& location); | |
1a680109 | 895 | |
ff4aedc5 | 896 | virtual wxMediaState GetState(); |
1a680109 | 897 | |
ff4aedc5 RN |
898 | virtual bool SetPosition(wxLongLong where); |
899 | virtual wxLongLong GetPosition(); | |
900 | virtual wxLongLong GetDuration(); | |
1a680109 | 901 | |
ff4aedc5 RN |
902 | virtual void Move(int x, int y, int w, int h); |
903 | wxSize GetVideoSize() const; | |
1a680109 | 904 | |
ff4aedc5 RN |
905 | virtual double GetPlaybackRate(); |
906 | virtual bool SetPlaybackRate(double dRate); | |
1a680109 | 907 | |
6f8c67e7 JS |
908 | virtual double GetVolume(); |
909 | virtual bool SetVolume(double); | |
910 | ||
ff4aedc5 RN |
911 | void Cleanup(); |
912 | void FinishLoad(); | |
1a680109 | 913 | |
ff4aedc5 | 914 | wxSize m_bestSize; //Original movie size |
d7a9c895 | 915 | Movie m_movie; //QT Movie handle/instance |
ff4aedc5 RN |
916 | wxControl* m_ctrl; //Parent control |
917 | bool m_bVideo; //Whether or not we have video | |
918 | class _wxQTTimer* m_timer; //Timer for streaming the movie | |
d7a9c895 RN |
919 | wxQuickTimeLibrary m_lib; |
920 | ||
19b6f122 | 921 | DECLARE_DYNAMIC_CLASS(wxQTMediaBackend) |
ff4aedc5 | 922 | }; |
1a680109 | 923 | |
1a680109 | 924 | |
ff4aedc5 RN |
925 | //=========================================================================== |
926 | // IMPLEMENTATION | |
927 | //=========================================================================== | |
1a680109 | 928 | |
ff4aedc5 RN |
929 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
930 | // | |
931 | // wxAMMediaBackend | |
932 | // | |
933 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | |
1a680109 | 934 | |
ff4aedc5 | 935 | IMPLEMENT_DYNAMIC_CLASS(wxAMMediaBackend, wxMediaBackend); |
1a680109 | 936 | |
ff4aedc5 RN |
937 | //--------------------------------------------------------------------------- |
938 | // Usual debugging macros | |
939 | //--------------------------------------------------------------------------- | |
940 | #ifdef __WXDEBUG__ | |
920a7c15 JS |
941 | #include "wx/msgdlg.h" |
942 | #define MAX_ERROR_TEXT_LEN 160 | |
943 | // | |
944 | // FIXME : Just use wxASSERT_MSG here instead of msgdlg - but | |
945 | // stackwalker still crashes win2k, so do msgdlg for now... | |
946 | // | |
ff4aedc5 RN |
947 | #define wxAMVERIFY(x) \ |
948 | { \ | |
949 | HRESULT hrdsv = (x); \ | |
950 | if ( FAILED(hrdsv) ) \ | |
951 | { \ | |
920a7c15 JS |
952 | wxChar szError[MAX_ERROR_TEXT_LEN]; \ |
953 | if( m_lpAMGetErrorText != NULL && \ | |
954 | (*m_lpAMGetErrorText)(hrdsv, szError, MAX_ERROR_TEXT_LEN) == 0) \ | |
955 | { \ | |
956 | wxMessageBox( wxString::Format(wxT("DirectShow error \"%s\" \n")\ | |
957 | wxT("(numeric %i)\n")\ | |
958 | wxT("occured at line %i in ") \ | |
959 | wxT("mediactrl.cpp"), \ | |
960 | (int)hrdsv, szError, __LINE__) ); \ | |
961 | wxASSERT(false);\ | |
962 | } \ | |
963 | else \ | |
964 | { \ | |
965 | wxMessageBox( wxString::Format(wxT("Unknown error (%i) ") \ | |
3103e8a9 | 966 | wxT("occurred at") \ |
ff4aedc5 RN |
967 | wxT(" line %i in mediactrl.cpp."), \ |
968 | (int)hrdsv, __LINE__) ); \ | |
920a7c15 JS |
969 | wxASSERT(false);\ |
970 | } \ | |
ff4aedc5 | 971 | } \ |
1a680109 | 972 | } |
ff4aedc5 RN |
973 | #define wxVERIFY(x) wxASSERT((x)) |
974 | #else | |
975 | #define wxAMVERIFY(x) (x) | |
976 | #define wxVERIFY(x) (x) | |
977 | #endif | |
1a680109 | 978 | |
ff4aedc5 RN |
979 | //--------------------------------------------------------------------------- |
980 | // Standard macros for ease of use | |
981 | //--------------------------------------------------------------------------- | |
982 | #define SAFE_RELEASE(x) { if (x) x->Release(); x = NULL; } | |
1a680109 | 983 | |
ff4aedc5 RN |
984 | //--------------------------------------------------------------------------- |
985 | // wxAMMediaBackend Constructor | |
986 | // | |
987 | // Sets m_hNotifyWnd to NULL to signify that we haven't loaded anything yet | |
226ec5a7 | 988 | //--------------------------------------------------------------------------- |
920a7c15 JS |
989 | wxAMMediaBackend::wxAMMediaBackend() : m_state(wxMEDIASTATE_STOPPED), |
990 | m_pVMC(NULL) | |
991 | #ifdef __WXDEBUG__ | |
992 | , m_hQuartzDll(NULL) | |
993 | #endif | |
1a680109 | 994 | { |
1a680109 RN |
995 | } |
996 | ||
ff4aedc5 RN |
997 | //--------------------------------------------------------------------------- |
998 | // wxAMMediaBackend Destructor | |
999 | // | |
226ec5a7 WS |
1000 | // Cleans up everything |
1001 | //--------------------------------------------------------------------------- | |
ff4aedc5 | 1002 | wxAMMediaBackend::~wxAMMediaBackend() |
1a680109 | 1003 | { |
920a7c15 | 1004 | if (m_pVMC) |
ff4aedc5 | 1005 | Cleanup(); |
920a7c15 JS |
1006 | #ifdef __WXDEBUG__ |
1007 | if(m_hQuartzDll) | |
1008 | ::FreeLibrary(m_hQuartzDll); | |
1009 | #endif | |
1a680109 RN |
1010 | } |
1011 | ||
1a680109 | 1012 | //--------------------------------------------------------------------------- |
ff4aedc5 | 1013 | // wxAMMediaBackend::CreateControl |
1a680109 | 1014 | // |
920a7c15 JS |
1015 | // 1) Check to see if Active Movie supports windowless controls |
1016 | // 2) Connect events to the media control and its TLW | |
226ec5a7 WS |
1017 | //--------------------------------------------------------------------------- |
1018 | bool wxAMMediaBackend::CreateControl(wxControl* ctrl, wxWindow* parent, | |
ff4aedc5 | 1019 | wxWindowID id, |
226ec5a7 | 1020 | const wxPoint& pos, |
ff4aedc5 | 1021 | const wxSize& size, |
226ec5a7 | 1022 | long style, |
ff4aedc5 RN |
1023 | const wxValidator& validator, |
1024 | const wxString& name) | |
226ec5a7 | 1025 | { |
920a7c15 JS |
1026 | #ifdef __WXDEBUG__ |
1027 | m_hQuartzDll = ::LoadLibrary(wxT("quartz.dll")); | |
1028 | if(m_hQuartzDll) | |
1029 | { | |
1030 | m_lpAMGetErrorText = (LPAMGETERRORTEXT) ::GetProcAddress( | |
1031 | m_hQuartzDll, | |
1032 | wxString::Format(wxT("AMGetErrorText%s"), | |
1a680109 | 1033 | |
920a7c15 JS |
1034 | #ifdef __WXUNICODE__ |
1035 | wxT("W") | |
1036 | #else | |
1037 | wxT("A") | |
1038 | #endif | |
1039 | #ifdef __WXWINCE__ | |
1040 | ) | |
1041 | #else | |
1042 | ).mb_str(wxConvLocal) | |
1043 | #endif | |
1044 | ); | |
1045 | } | |
1046 | #endif | |
1047 | ||
1048 | //Make sure a valid windowless video mixing interface exists | |
1049 | IGraphBuilder* pGB; | |
1050 | if( CoCreateInstance(CLSID_FilgraphManager, NULL, | |
1051 | CLSCTX_INPROC_SERVER, | |
1052 | IID_IGraphBuilder, (void**)&pGB) != 0 ) | |
1053 | return false; | |
1054 | ||
1055 | if( !SetWindowlessMode(pGB) ) | |
1a680109 RN |
1056 | return false; |
1057 | ||
920a7c15 JS |
1058 | //clean up |
1059 | pGB->Release(); | |
ff4aedc5 RN |
1060 | |
1061 | // | |
1062 | // Create window | |
1063 | // By default wxWindow(s) is created with a border - | |
1064 | // so we need to get rid of those, and create with | |
1065 | // wxCLIP_CHILDREN, so that if the driver/backend | |
3103e8a9 | 1066 | // is a child window, it refreshes properly |
ff4aedc5 RN |
1067 | // |
1068 | if ( !ctrl->wxControl::Create(parent, id, pos, size, | |
11085e4b | 1069 | (style & ~wxBORDER_MASK) | wxBORDER_NONE | wxCLIP_CHILDREN, |
ff4aedc5 RN |
1070 | validator, name) ) |
1071 | return false; | |
1a680109 | 1072 | |
ff4aedc5 | 1073 | m_ctrl = ctrl; |
920a7c15 JS |
1074 | |
1075 | // | |
1076 | // Connect Events | |
1077 | // | |
1078 | //TODO: Greg Hazel reports problems with this... but win2k seems fine on mine... | |
1079 | // m_ctrl->Connect(m_ctrl->GetId(), wxEVT_ERASE_BACKGROUND, | |
1080 | // wxEraseEventHandler(wxAMMediaEvtHandler::OnEraseBackground), | |
1081 | // NULL, (wxEvtHandler*) this); | |
1082 | m_ctrl->Connect(m_ctrl->GetId(), wxEVT_PAINT, | |
1083 | wxPaintEventHandler(wxAMMediaEvtHandler::OnPaint), | |
1084 | NULL, (wxEvtHandler*) this); | |
1085 | ||
1086 | // | |
1087 | // As noted below, we need to catch the Top Level Window's | |
1088 | // move events because they are not sent to us if the media control | |
1089 | // size remains the same but it actually moves in window coordinates | |
1090 | // | |
1091 | wxWindow* pTheTLW = m_ctrl->GetParent(); | |
1092 | while( pTheTLW->GetParent() ) | |
1093 | pTheTLW = pTheTLW->GetParent(); | |
1094 | ||
1095 | // | |
1096 | // FIXMEHACKFIXMEHACKFIXME | |
1097 | // This is really nasty... basically the deal is not only above | |
1098 | // but the repainting is messed up when the parent is maximized | |
1099 | // too, so we've got to catch all 4 events! | |
1100 | // | |
1101 | m_ctrl->Connect(m_ctrl->GetId(), wxEVT_MOVE, | |
1102 | wxMoveEventHandler(wxAMMediaEvtHandler::OnMove), | |
1103 | NULL, (wxEvtHandler*) this); | |
1104 | m_ctrl->Connect(m_ctrl->GetId(), wxEVT_SIZE, | |
1105 | wxSizeEventHandler(wxAMMediaEvtHandler::OnSize), | |
1106 | NULL, (wxEvtHandler*) this); | |
1107 | ||
1108 | pTheTLW->Connect(pTheTLW->GetId(), wxEVT_MOVE, | |
1109 | wxMoveEventHandler(wxAMMediaEvtHandler::OnMove), | |
1110 | NULL, (wxEvtHandler*) this); | |
1111 | pTheTLW->Connect(pTheTLW->GetId(), wxEVT_SIZE, | |
1112 | wxSizeEventHandler(wxAMMediaEvtHandler::OnSize), | |
1113 | NULL, (wxEvtHandler*) this); | |
1114 | ||
1115 | // | |
1116 | // done... | |
1117 | // | |
1a680109 RN |
1118 | return true; |
1119 | } | |
1120 | ||
ff4aedc5 | 1121 | //--------------------------------------------------------------------------- |
920a7c15 | 1122 | // wxAMMediaBackend::SetWindowlessMode |
ff4aedc5 | 1123 | // |
920a7c15 JS |
1124 | // Adds a Video Mixing Renderer to a Filter Graph and obtains the |
1125 | // windowless control from it | |
226ec5a7 | 1126 | //--------------------------------------------------------------------------- |
920a7c15 JS |
1127 | bool wxAMMediaBackend::SetWindowlessMode(IGraphBuilder* pGB, |
1128 | IVMRWindowlessControl** ppVMC) | |
1a680109 | 1129 | { |
920a7c15 JS |
1130 | // |
1131 | // Create and add a custom Video Mixing Render to the graph | |
1132 | // | |
1133 | IBaseFilter* pVMR; | |
1134 | if( CoCreateInstance(CLSID_VideoMixingRenderer, NULL, CLSCTX_INPROC_SERVER, | |
1135 | IID_IBaseFilter, (void**)&pVMR) != 0 ) | |
1a680109 RN |
1136 | return false; |
1137 | ||
920a7c15 JS |
1138 | if ( pGB->AddFilter(pVMR, L"Video Mixing Renderer") != 0) |
1139 | { | |
1140 | pVMR->Release(); | |
1141 | return false; | |
1142 | } | |
ff4aedc5 RN |
1143 | |
1144 | // | |
920a7c15 | 1145 | // Set the graph to windowless mode |
ff4aedc5 | 1146 | // |
920a7c15 JS |
1147 | IVMRFilterConfig* pConfig; |
1148 | if( pVMR->QueryInterface(IID_IVMRFilterConfig, (void**)&pConfig) != 0 ) | |
1149 | { | |
1150 | pVMR->Release(); | |
1151 | return false; | |
1152 | } | |
ff4aedc5 | 1153 | |
920a7c15 JS |
1154 | if( pConfig->SetRenderingMode(2) != 0) //2 == VMRMode_Windowless |
1155 | { | |
1156 | pConfig->Release(); | |
1157 | pVMR->Release(); | |
1158 | return false; | |
1159 | } | |
ff4aedc5 | 1160 | |
920a7c15 | 1161 | pConfig->Release(); |
ff4aedc5 RN |
1162 | |
1163 | // | |
920a7c15 | 1164 | // Obtain the windowless control |
ff4aedc5 | 1165 | // |
920a7c15 JS |
1166 | IVMRWindowlessControl* pVMC; |
1167 | if( pVMR->QueryInterface(IID_IVMRWindowlessControl, (void**)&pVMC) != 0 ) | |
1a680109 | 1168 | { |
920a7c15 JS |
1169 | pVMR->Release(); |
1170 | return false; | |
1a680109 RN |
1171 | } |
1172 | ||
ff4aedc5 | 1173 | // |
920a7c15 | 1174 | // Success |
226ec5a7 | 1175 | // |
920a7c15 JS |
1176 | if(ppVMC) |
1177 | *ppVMC = pVMC; | |
1178 | else | |
1179 | pVMC->Release(); | |
ff4aedc5 | 1180 | |
920a7c15 JS |
1181 | pVMR->Release(); |
1182 | return true; | |
1183 | } | |
1a680109 | 1184 | |
920a7c15 JS |
1185 | //--------------------------------------------------------------------------- |
1186 | // wxAMMediaBackend::Load (file version) | |
1187 | // | |
1188 | // 1) Cleans up previously loaded data | |
1189 | // 2) Creates a filter graph | |
1190 | // 3) Add a video mixer, set the graph to windowless mode and clip | |
1191 | // output to our media control | |
1192 | // 4) Query interfaces to use later | |
1193 | // 5) Get native video size (which becomes our best size) | |
1194 | // 6) Refresh parent's sizers | |
1195 | // 7) Start event/rendering thread | |
1196 | //--------------------------------------------------------------------------- | |
1197 | bool wxAMMediaBackend::Load(const wxString& fileName) | |
1198 | { | |
1199 | //if previously loaded cleanup | |
1200 | if(m_pVMC) | |
1201 | Cleanup(); | |
1202 | ||
1203 | //Create interfaces - we already checked for success in CreateControl | |
1204 | CoCreateInstance(CLSID_FilgraphManager, NULL, CLSCTX_INPROC_SERVER, | |
1205 | IID_IGraphBuilder, (void**)&m_pGB); | |
1206 | ||
1207 | ||
1208 | // Set and clip output | |
1209 | SetWindowlessMode(m_pGB, &m_pVMC); | |
1210 | if( m_pVMC->SetVideoClippingWindow((HWND)m_ctrl->GetHandle()) != 0 ) | |
1211 | { | |
1212 | m_bestSize.x = m_bestSize.y = 0; | |
1213 | wxASSERT(false); | |
ff4aedc5 | 1214 | } |
226ec5a7 | 1215 | |
920a7c15 JS |
1216 | //load the graph & render |
1217 | if( m_pGB->RenderFile(fileName.wc_str(wxConvLocal), NULL) != 0 ) | |
1218 | return false; | |
1a680109 | 1219 | |
920a7c15 JS |
1220 | //Get the interfaces, all of them |
1221 | wxAMVERIFY( m_pGB->QueryInterface(IID_IMediaEvent, (void**)&m_pME) ); | |
1222 | wxAMVERIFY( m_pGB->QueryInterface(IID_IMediaControl, (void**)&m_pMC) ); | |
1223 | wxAMVERIFY( m_pGB->QueryInterface(IID_IMediaPosition, (void**)&m_pMS) ); | |
1224 | wxAMVERIFY( m_pGB->QueryInterface(IID_IBasicAudio, (void**)&m_pBA) ); | |
1a680109 | 1225 | |
920a7c15 JS |
1226 | // Get original video size |
1227 | if( m_pVMC->GetNativeVideoSize((LONG*)&m_bestSize.x, (LONG*)&m_bestSize.y, | |
1228 | NULL, NULL) != 0 ) | |
1229 | { | |
1230 | m_bestSize.x = m_bestSize.y = 0; | |
1231 | wxASSERT(false); | |
1232 | } | |
3f9a3bf9 | 1233 | |
ff4aedc5 RN |
1234 | // |
1235 | // Force the parent window of this control to recalculate | |
1236 | // the size of this if sizers are being used | |
1237 | // and render the results immediately | |
1238 | // | |
3f9a3bf9 RN |
1239 | m_ctrl->InvalidateBestSize(); |
1240 | m_ctrl->GetParent()->Layout(); | |
1a680109 RN |
1241 | m_ctrl->GetParent()->Refresh(); |
1242 | m_ctrl->GetParent()->Update(); | |
b11eba7e | 1243 | m_ctrl->SetSize(m_ctrl->GetSize()); |
1a680109 | 1244 | |
920a7c15 JS |
1245 | m_pThread = new wxAMMediaThread; |
1246 | m_pThread->pThis = this; | |
1247 | m_pThread->Create(); | |
1248 | m_pThread->Run(); | |
1249 | ||
1a680109 RN |
1250 | return true; |
1251 | } | |
1252 | ||
ff4aedc5 RN |
1253 | //--------------------------------------------------------------------------- |
1254 | // wxAMMediaBackend::Load (URL Version) | |
1255 | // | |
1256 | // Loads media from a URL. Interestingly enough DirectShow | |
1257 | // appears (?) to escape the URL for us, at least on normal | |
1258 | // files | |
226ec5a7 | 1259 | //--------------------------------------------------------------------------- |
ff4aedc5 | 1260 | bool wxAMMediaBackend::Load(const wxURI& location) |
1a680109 RN |
1261 | { |
1262 | return Load(location.BuildUnescapedURI()); | |
1263 | } | |
1264 | ||
ff4aedc5 RN |
1265 | //--------------------------------------------------------------------------- |
1266 | // wxAMMediaBackend::Play | |
1267 | // | |
920a7c15 JS |
1268 | // Plays the stream. If it is non-seekable, it will restart it (implicit). |
1269 | // | |
1270 | // Note that we use SUCCEEDED here because run/pause/stop tend to be overly | |
1271 | // picky and return warnings on pretty much every call | |
226ec5a7 | 1272 | //--------------------------------------------------------------------------- |
ff4aedc5 | 1273 | bool wxAMMediaBackend::Play() |
1a680109 | 1274 | { |
920a7c15 JS |
1275 | wxCriticalSectionLocker lock(m_rendercs); |
1276 | ||
1277 | if( SUCCEEDED(m_pMC->Run()) ) | |
1278 | { | |
1279 | m_state = wxMEDIASTATE_PLAYING; | |
1280 | m_ctrl->Refresh(); //videoless control finicky about refreshing | |
1281 | return true; | |
1282 | } | |
1283 | ||
1284 | return false; | |
1a680109 RN |
1285 | } |
1286 | ||
ff4aedc5 RN |
1287 | //--------------------------------------------------------------------------- |
1288 | // wxAMMediaBackend::Pause | |
1289 | // | |
1290 | // Pauses the stream. | |
226ec5a7 | 1291 | //--------------------------------------------------------------------------- |
ff4aedc5 | 1292 | bool wxAMMediaBackend::Pause() |
1a680109 | 1293 | { |
920a7c15 JS |
1294 | wxCriticalSectionLocker lock(m_rendercs); |
1295 | ||
1296 | if( SUCCEEDED(m_pMC->Pause()) ) | |
1297 | { | |
1298 | m_state = wxMEDIASTATE_PAUSED; | |
1299 | return true; | |
1300 | } | |
1301 | ||
1302 | return false; | |
1a680109 RN |
1303 | } |
1304 | ||
ff4aedc5 RN |
1305 | //--------------------------------------------------------------------------- |
1306 | // wxAMMediaBackend::Stop | |
1307 | // | |
1308 | // Stops the stream. | |
226ec5a7 | 1309 | //--------------------------------------------------------------------------- |
ff4aedc5 | 1310 | bool wxAMMediaBackend::Stop() |
1a680109 | 1311 | { |
920a7c15 | 1312 | wxCriticalSectionLocker lock(m_rendercs); |
e4b12a53 | 1313 | |
920a7c15 JS |
1314 | if( SUCCEEDED(m_pMC->Stop()) ) |
1315 | { | |
e4b12a53 RN |
1316 | //We don't care if it can't get to the beginning in directshow - |
1317 | //it could be a non-seeking filter (wince midi) in which case playing | |
1318 | //starts all over again | |
920a7c15 JS |
1319 | wxAMMediaBackend::SetPosition(0); |
1320 | ||
1321 | m_state = wxMEDIASTATE_STOPPED; | |
1322 | return true; | |
1323 | } | |
1324 | ||
1325 | return false; | |
1a680109 RN |
1326 | } |
1327 | ||
ff4aedc5 RN |
1328 | //--------------------------------------------------------------------------- |
1329 | // wxAMMediaBackend::SetPosition | |
1330 | // | |
226ec5a7 | 1331 | // 1) Translates the current position's time to directshow time, |
a2a444e3 | 1332 | // which is in a scale of 1 second (in a double) |
ff4aedc5 RN |
1333 | // 2) Sets the play position of the IMediaSeeking interface - |
1334 | // passing NULL as the stop position means to keep the old | |
1335 | // stop position | |
226ec5a7 | 1336 | //--------------------------------------------------------------------------- |
ff4aedc5 | 1337 | bool wxAMMediaBackend::SetPosition(wxLongLong where) |
1a680109 | 1338 | { |
a2a444e3 | 1339 | return SUCCEEDED( m_pMS->put_CurrentPosition( |
920a7c15 JS |
1340 | ((LONGLONG)where.GetValue()) / 1000.0 |
1341 | ) ); | |
1a680109 RN |
1342 | } |
1343 | ||
ff4aedc5 RN |
1344 | //--------------------------------------------------------------------------- |
1345 | // wxAMMediaBackend::GetPosition | |
1346 | // | |
1347 | // 1) Obtains the current play and stop positions from IMediaSeeking | |
1348 | // 2) Returns the play position translated to our time base | |
226ec5a7 | 1349 | //--------------------------------------------------------------------------- |
ff4aedc5 | 1350 | wxLongLong wxAMMediaBackend::GetPosition() |
1a680109 | 1351 | { |
a2a444e3 RN |
1352 | double outCur; |
1353 | wxAMVERIFY( m_pMS->get_CurrentPosition(&outCur) ); | |
1a680109 | 1354 | |
a2a444e3 | 1355 | //h,m,s,milli - outdur is in 1 second (double) |
600ffb32 WS |
1356 | outCur *= 1000; |
1357 | wxLongLong ll; | |
1358 | ll.Assign(outCur); | |
1359 | ||
1360 | return ll; | |
1a680109 RN |
1361 | } |
1362 | ||
6f8c67e7 JS |
1363 | //--------------------------------------------------------------------------- |
1364 | // wxAMMediaBackend::SetVolume | |
1365 | // | |
1366 | // Sets the volume through the IBasicAudio interface - | |
1367 | // value ranges from 0 (MAX volume) to -10000 (minimum volume). | |
1368 | // -100 per decibel. | |
1369 | //--------------------------------------------------------------------------- | |
b11eba7e WS |
1370 | bool wxAMMediaBackend::SetVolume(double dVolume) |
1371 | { | |
920a7c15 | 1372 | return SUCCEEDED(m_pBA->put_Volume( (long) ((dVolume-1.0) * 10000.0) ) ); |
b11eba7e | 1373 | } |
6f8c67e7 JS |
1374 | |
1375 | //--------------------------------------------------------------------------- | |
1376 | // wxAMMediaBackend::GetVolume | |
1377 | // | |
1378 | // Gets the volume through the IBasicAudio interface - | |
1379 | // value ranges from 0 (MAX volume) to -10000 (minimum volume). | |
1380 | // -100 per decibel. | |
1381 | //--------------------------------------------------------------------------- | |
1382 | double wxAMMediaBackend::GetVolume() | |
1383 | { | |
1384 | long lVolume; | |
920a7c15 | 1385 | if ( SUCCEEDED( m_pBA->get_Volume(&lVolume) ) ) |
6f8c67e7 JS |
1386 | return (((double)(lVolume + 10000)) / 10000.0); |
1387 | return 0.0; | |
1388 | } | |
b11eba7e | 1389 | |
ff4aedc5 RN |
1390 | //--------------------------------------------------------------------------- |
1391 | // wxAMMediaBackend::GetDuration | |
1392 | // | |
920a7c15 | 1393 | // 1) Obtains the duration of the media from IAMMultiMediaStream |
ff4aedc5 | 1394 | // 2) Converts that value to our time base, and returns it |
920a7c15 JS |
1395 | // |
1396 | // NB: With VBR MP3 files the default DirectShow MP3 render does not | |
1397 | // read the Xing header correctly, resulting in skewed values for duration | |
1398 | // and seeking | |
226ec5a7 | 1399 | //--------------------------------------------------------------------------- |
ff4aedc5 | 1400 | wxLongLong wxAMMediaBackend::GetDuration() |
1a680109 | 1401 | { |
a2a444e3 RN |
1402 | double outDuration; |
1403 | wxAMVERIFY( m_pMS->get_Duration(&outDuration) ); | |
1a680109 | 1404 | |
a2a444e3 | 1405 | //h,m,s,milli - outdur is in 1 second (double) |
600ffb32 WS |
1406 | outDuration *= 1000; |
1407 | wxLongLong ll; | |
1408 | ll.Assign(outDuration); | |
1409 | ||
1410 | return ll; | |
1a680109 RN |
1411 | } |
1412 | ||
ff4aedc5 RN |
1413 | //--------------------------------------------------------------------------- |
1414 | // wxAMMediaBackend::GetState | |
1415 | // | |
920a7c15 | 1416 | // Returns the cached state |
226ec5a7 | 1417 | //--------------------------------------------------------------------------- |
ff4aedc5 | 1418 | wxMediaState wxAMMediaBackend::GetState() |
1a680109 | 1419 | { |
920a7c15 | 1420 | return m_state; |
1a680109 RN |
1421 | } |
1422 | ||
ff4aedc5 RN |
1423 | //--------------------------------------------------------------------------- |
1424 | // wxAMMediaBackend::GetPlaybackRate | |
1425 | // | |
1426 | // Pretty simple way of obtaining the playback rate from | |
1427 | // the IMediaSeeking interface | |
226ec5a7 | 1428 | //--------------------------------------------------------------------------- |
ff4aedc5 | 1429 | double wxAMMediaBackend::GetPlaybackRate() |
1a680109 RN |
1430 | { |
1431 | double dRate; | |
a2a444e3 | 1432 | wxAMVERIFY( m_pMS->get_Rate(&dRate) ); |
1a680109 RN |
1433 | return dRate; |
1434 | } | |
1435 | ||
ff4aedc5 RN |
1436 | //--------------------------------------------------------------------------- |
1437 | // wxAMMediaBackend::SetPlaybackRate | |
1438 | // | |
1439 | // Sets the playback rate of the media - DirectShow is pretty good | |
1440 | // about this, actually | |
226ec5a7 | 1441 | //--------------------------------------------------------------------------- |
ff4aedc5 | 1442 | bool wxAMMediaBackend::SetPlaybackRate(double dRate) |
1a680109 | 1443 | { |
920a7c15 | 1444 | return m_pMS->put_Rate(dRate) == 0; |
1a680109 RN |
1445 | } |
1446 | ||
ff4aedc5 | 1447 | //--------------------------------------------------------------------------- |
920a7c15 | 1448 | // wxAMMediaBackend::Cleanup |
ff4aedc5 | 1449 | // |
920a7c15 JS |
1450 | // Releases all the directshow interfaces we use |
1451 | // TODO: Maybe only create one instance of IAMMultiMediaStream and reuse it | |
1452 | // rather than recreating it each time? | |
226ec5a7 | 1453 | //--------------------------------------------------------------------------- |
920a7c15 | 1454 | void wxAMMediaBackend::Cleanup() |
ff4aedc5 | 1455 | { |
920a7c15 JS |
1456 | m_pThread->Delete(); |
1457 | m_pThread = NULL; | |
ff4aedc5 | 1458 | |
920a7c15 JS |
1459 | // Release and zero DirectShow interfaces |
1460 | SAFE_RELEASE(m_pMC); | |
1461 | SAFE_RELEASE(m_pME); | |
1462 | SAFE_RELEASE(m_pMS); | |
1463 | SAFE_RELEASE(m_pBA); | |
1464 | SAFE_RELEASE(m_pGB); | |
1465 | SAFE_RELEASE(m_pVMC); | |
1466 | } | |
1467 | ||
1468 | ||
1469 | //--------------------------------------------------------------------------- | |
1470 | // wxAMMediaBackend::GetVideoSize | |
1471 | // | |
1472 | // Obtains the cached original video size | |
1473 | //--------------------------------------------------------------------------- | |
1474 | wxSize wxAMMediaBackend::GetVideoSize() const | |
1475 | { | |
1476 | return m_bestSize; | |
1477 | } | |
1478 | ||
1479 | //--------------------------------------------------------------------------- | |
1480 | // wxAMMediaBackend::Move | |
1481 | // | |
1482 | // We take care of this in our redrawing | |
1483 | //--------------------------------------------------------------------------- | |
1484 | void wxAMMediaBackend::Move(int WXUNUSED(x), int WXUNUSED(y), | |
1485 | int w, int h) | |
1486 | { | |
1487 | if(m_pVMC) | |
1488 | { | |
1489 | RECT srcRect, destRect; | |
1490 | ||
1491 | //portion of video to display in window | |
1492 | srcRect.top = 0; srcRect.left = 0; | |
1493 | srcRect.bottom = m_bestSize.y; srcRect.right = m_bestSize.x; | |
1494 | ||
1495 | //position in window client coordinates to display and stretch to | |
1496 | destRect.top = 0; destRect.left = 0; | |
1497 | destRect.bottom = h; destRect.right = w; | |
1498 | ||
1499 | //set the windowless control positions | |
1500 | if( m_pVMC->SetVideoPosition(&srcRect, &destRect) != 0 ) | |
1501 | { | |
1502 | wxASSERT_MSG(false, wxT("Could not set video position!")); | |
1503 | } | |
1504 | ||
1505 | /* | |
1506 | //oddly enough, it doesn't redraw the frame after moving... | |
1507 | //TODO: Use wxClientDC? | |
1508 | HDC hdc = ::GetDC((HWND)m_ctrl->GetHandle()); | |
1509 | if( m_pVMC->RepaintVideo((HWND)m_ctrl->GetHandle(), | |
1510 | hdc) != 0 ) | |
1511 | { | |
1512 | wxASSERT(false); | |
1513 | } | |
1514 | ::ReleaseDC((HWND)m_ctrl->GetHandle(), hdc); | |
1515 | */ | |
1516 | } | |
1517 | } | |
1518 | ||
1519 | //--------------------------------------------------------------------------- | |
1520 | // wxAMMediaEvtHandler::OnMove | |
1521 | // | |
1522 | // Oddly enough Move isn't called on MSW when the parent moves | |
1523 | // and the child (us) doesn't, so we have to do it twice I guess :( | |
1524 | //--------------------------------------------------------------------------- | |
1525 | void wxAMMediaEvtHandler::OnMove(wxMoveEvent& evt) | |
1526 | { | |
1527 | wxAMMediaBackend* pThis = (wxAMMediaBackend*) this; | |
1528 | pThis->Move(pThis->m_ctrl->GetPosition().x, | |
1529 | pThis->m_ctrl->GetPosition().y, | |
1530 | pThis->m_ctrl->GetSize().x, | |
1531 | pThis->m_ctrl->GetSize().y ); | |
1532 | evt.Skip(); | |
1533 | } | |
1534 | void wxAMMediaEvtHandler::OnSize(wxSizeEvent& evt) | |
1535 | { | |
1536 | wxAMMediaBackend* pThis = (wxAMMediaBackend*) this; | |
1537 | pThis->Move(pThis->m_ctrl->GetPosition().x, | |
1538 | pThis->m_ctrl->GetPosition().y, | |
1539 | pThis->m_ctrl->GetSize().x, | |
1540 | pThis->m_ctrl->GetSize().y ); | |
1541 | evt.Skip(); | |
ff4aedc5 RN |
1542 | } |
1543 | ||
920a7c15 JS |
1544 | //--------------------------------------------------------------------------- |
1545 | // wxAMMediaThread::Entry | |
1546 | // | |
1547 | // Render the current movie frame | |
1548 | //--------------------------------------------------------------------------- | |
1549 | wxThread::ExitCode wxAMMediaThread::Entry() | |
1a680109 | 1550 | { |
920a7c15 | 1551 | while(!TestDestroy()) |
1a680109 | 1552 | { |
226ec5a7 WS |
1553 | LONG evCode, |
1554 | evParam1, | |
ff4aedc5 RN |
1555 | evParam2; |
1556 | ||
1557 | // | |
1558 | // DirectShow keeps a list of queued events, and we need | |
1559 | // to go through them one by one, stopping at (Hopefully only one) | |
1560 | // EC_COMPLETE message | |
1561 | // | |
920a7c15 JS |
1562 | while( pThis->m_pME->GetEvent(&evCode, (LONG_PTR *) &evParam1, |
1563 | (LONG_PTR *) &evParam2, 0) == 0 ) | |
1a680109 | 1564 | { |
ff4aedc5 | 1565 | // Cleanup memory that GetEvent allocated |
920a7c15 JS |
1566 | if( pThis->m_pME->FreeEventParams(evCode, evParam1, evParam2) != 0 ) |
1567 | { | |
1568 | wxASSERT(false); | |
1569 | } | |
1a680109 RN |
1570 | |
1571 | // If this is the end of the clip, notify handler | |
a2a444e3 | 1572 | if(1 == evCode) //EC_COMPLETE |
1a680109 | 1573 | { |
920a7c15 JS |
1574 | pThis->OnStop(); |
1575 | } | |
1576 | } | |
1577 | ||
1578 | Sleep(10); | |
1579 | } | |
1580 | ||
1581 | return NULL; | |
1582 | } | |
1583 | ||
1584 | ||
1585 | //--------------------------------------------------------------------------- | |
1586 | // wxAMMediaBackend::OnStop | |
1587 | // | |
1588 | // Handle stopping when the stream ends | |
1589 | //--------------------------------------------------------------------------- | |
1590 | void wxAMMediaBackend::OnStop() | |
1591 | { | |
ff4aedc5 RN |
1592 | //send the event to our child |
1593 | wxMediaEvent theEvent(wxEVT_MEDIA_STOP, m_ctrl->GetId()); | |
1594 | m_ctrl->ProcessEvent(theEvent); | |
1595 | ||
1596 | //if the user didn't veto it, stop the stream | |
1597 | if (theEvent.IsAllowed()) | |
1598 | { | |
1599 | //Interestingly enough, DirectShow does not actually stop | |
1600 | //the filters - even when it reaches the end! | |
1601 | wxVERIFY( Stop() ); | |
226ec5a7 | 1602 | |
ff4aedc5 | 1603 | //send the event to our child |
226ec5a7 | 1604 | wxMediaEvent theEvent(wxEVT_MEDIA_FINISHED, |
ff4aedc5 RN |
1605 | m_ctrl->GetId()); |
1606 | m_ctrl->ProcessEvent(theEvent); | |
1607 | } | |
1a680109 RN |
1608 | } |
1609 | ||
ff4aedc5 | 1610 | //--------------------------------------------------------------------------- |
920a7c15 | 1611 | // wxAMMediaEvtHandler::OnEraseBackground |
ff4aedc5 | 1612 | // |
920a7c15 | 1613 | // Tell WX not to erase the background of our control window |
226ec5a7 | 1614 | //--------------------------------------------------------------------------- |
920a7c15 | 1615 | void wxAMMediaEvtHandler::OnEraseBackground(wxEraseEvent& evt) |
1a680109 | 1616 | { |
920a7c15 JS |
1617 | wxAMMediaBackend* pThis = (wxAMMediaBackend*) this; |
1618 | if(pThis->m_pVMC) | |
1a680109 | 1619 | { |
920a7c15 JS |
1620 | //TODO: Use wxClientDC? |
1621 | HDC hdc = ::GetDC((HWND)pThis->m_ctrl->GetHandle()); | |
1622 | if( pThis->m_pVMC->RepaintVideo((HWND)pThis->m_ctrl->GetHandle(), | |
1623 | hdc) != 0 ) | |
1624 | { | |
1625 | wxASSERT(false); | |
1a680109 | 1626 | } |
920a7c15 JS |
1627 | ::ReleaseDC((HWND)pThis->m_ctrl->GetHandle(), hdc); |
1628 | } | |
1629 | else | |
1630 | evt.Skip(); | |
1a680109 RN |
1631 | } |
1632 | ||
ff4aedc5 | 1633 | //--------------------------------------------------------------------------- |
920a7c15 | 1634 | // wxAMMediaEvtHandler::OnPaint |
ff4aedc5 | 1635 | // |
920a7c15 | 1636 | // Handle redrawing |
226ec5a7 | 1637 | //--------------------------------------------------------------------------- |
920a7c15 | 1638 | void wxAMMediaEvtHandler::OnPaint(wxPaintEvent& WXUNUSED(evt)) |
1a680109 | 1639 | { |
920a7c15 JS |
1640 | wxAMMediaBackend* pThis = (wxAMMediaBackend*) this; |
1641 | wxPaintDC dc(pThis->m_ctrl); | |
19c1b67d | 1642 | if( pThis->m_pVMC ) |
1a680109 | 1643 | { |
19c1b67d JS |
1644 | if( pThis->m_pVMC->RepaintVideo((HWND)pThis->m_ctrl->GetHandle(), |
1645 | (HDC)dc.GetHDC()) != 0 ) | |
1646 | { | |
1647 | wxASSERT(false); | |
1648 | } | |
1a680109 RN |
1649 | } |
1650 | } | |
1651 | ||
ff4aedc5 RN |
1652 | //--------------------------------------------------------------------------- |
1653 | // End of wxAMMediaBackend | |
1654 | //--------------------------------------------------------------------------- | |
1a680109 | 1655 | |
ff4aedc5 | 1656 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1a680109 | 1657 | // |
ff4aedc5 | 1658 | // wxMCIMediaBackend |
226ec5a7 | 1659 | // |
ff4aedc5 RN |
1660 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1661 | ||
ff4aedc5 RN |
1662 | IMPLEMENT_DYNAMIC_CLASS(wxMCIMediaBackend, wxMediaBackend); |
1663 | ||
1664 | //--------------------------------------------------------------------------- | |
1665 | // Usual debugging macros for MCI returns | |
1a680109 RN |
1666 | //--------------------------------------------------------------------------- |
1667 | ||
ff4aedc5 RN |
1668 | #ifdef __WXDEBUG__ |
1669 | #define wxMCIVERIFY(arg) \ | |
1670 | { \ | |
1671 | DWORD nRet; \ | |
1672 | if ( (nRet = (arg)) != 0) \ | |
1673 | { \ | |
1674 | TCHAR sz[5000]; \ | |
1675 | mciGetErrorString(nRet, sz, 5000); \ | |
1676 | wxFAIL_MSG(wxString::Format(_T("MCI Error:%s"), sz)); \ | |
1677 | } \ | |
1678 | } | |
1679 | #else | |
1680 | #define wxMCIVERIFY(arg) (arg); | |
1681 | #endif | |
1682 | ||
1683 | //--------------------------------------------------------------------------- | |
1684 | // Simulation for <digitalv.h> | |
33d8e2fc | 1685 | // |
ff4aedc5 | 1686 | // Mingw and possibly other compilers don't have the digitalv.h header |
226ec5a7 | 1687 | // that is needed to have some essential features of mci work with |
ff4aedc5 RN |
1688 | // windows - so we provide the declarations for the types we use here |
1689 | //--------------------------------------------------------------------------- | |
33d8e2fc RN |
1690 | |
1691 | typedef struct { | |
1692 | DWORD_PTR dwCallback; | |
1693 | #ifdef MCI_USE_OFFEXT | |
1694 | POINT ptOffset; | |
1695 | POINT ptExtent; | |
226ec5a7 | 1696 | #else |
33d8e2fc RN |
1697 | RECT rc; |
1698 | #endif | |
1699 | } MCI_DGV_RECT_PARMS; | |
1700 | ||
1701 | typedef struct { | |
1702 | DWORD_PTR dwCallback; | |
1703 | HWND hWnd; | |
1704 | #ifndef _WIN32 | |
1705 | WORD wReserved1; | |
1706 | #endif | |
1707 | UINT nCmdShow; | |
1708 | #ifndef _WIN32 | |
1709 | WORD wReserved2; | |
1710 | #endif | |
ff4aedc5 RN |
1711 | wxChar* lpstrText; |
1712 | } MCI_DGV_WINDOW_PARMS; | |
33d8e2fc RN |
1713 | |
1714 | typedef struct { | |
226ec5a7 WS |
1715 | DWORD_PTR dwCallback; |
1716 | DWORD dwTimeFormat; | |
1717 | DWORD dwAudio; | |
1718 | DWORD dwFileFormat; | |
1719 | DWORD dwSpeed; | |
1720 | } MCI_DGV_SET_PARMS; | |
33d8e2fc | 1721 | |
6f8c67e7 JS |
1722 | typedef struct { |
1723 | DWORD_PTR dwCallback; | |
1724 | DWORD dwItem; | |
1725 | DWORD dwValue; | |
1726 | DWORD dwOver; | |
1727 | wxChar* lpstrAlgorithm; | |
1728 | wxChar* lpstrQuality; | |
1729 | } MCI_DGV_SETAUDIO_PARMS; | |
1730 | ||
ff4aedc5 RN |
1731 | //--------------------------------------------------------------------------- |
1732 | // wxMCIMediaBackend Constructor | |
1733 | // | |
1734 | // Here we don't need to do much except say we don't have any video :) | |
1735 | //--------------------------------------------------------------------------- | |
1736 | wxMCIMediaBackend::wxMCIMediaBackend() : m_hNotifyWnd(NULL), m_bVideo(false) | |
1737 | { | |
3f9a3bf9 RN |
1738 | } |
1739 | ||
ff4aedc5 RN |
1740 | //--------------------------------------------------------------------------- |
1741 | // wxMCIMediaBackend Destructor | |
1742 | // | |
1743 | // We close the mci device - note that there may not be an mci device here, | |
1744 | // or it may fail - but we don't really care, since we're destructing | |
1745 | //--------------------------------------------------------------------------- | |
1746 | wxMCIMediaBackend::~wxMCIMediaBackend() | |
3f9a3bf9 | 1747 | { |
ff4aedc5 RN |
1748 | if(m_hNotifyWnd) |
1749 | { | |
1750 | mciSendCommand(m_hDev, MCI_CLOSE, 0, 0); | |
1751 | DestroyWindow(m_hNotifyWnd); | |
1752 | m_hNotifyWnd = NULL; | |
1753 | } | |
3f9a3bf9 RN |
1754 | } |
1755 | ||
ff4aedc5 RN |
1756 | //--------------------------------------------------------------------------- |
1757 | // wxMCIMediaBackend::Create | |
1758 | // | |
1759 | // Here we just tell wxMediaCtrl that mci does exist (which it does, on all | |
1760 | // msw systems, at least in some form dating back to win16 days) | |
1761 | //--------------------------------------------------------------------------- | |
226ec5a7 | 1762 | bool wxMCIMediaBackend::CreateControl(wxControl* ctrl, wxWindow* parent, |
ff4aedc5 | 1763 | wxWindowID id, |
226ec5a7 | 1764 | const wxPoint& pos, |
ff4aedc5 | 1765 | const wxSize& size, |
226ec5a7 | 1766 | long style, |
ff4aedc5 RN |
1767 | const wxValidator& validator, |
1768 | const wxString& name) | |
72259e00 | 1769 | { |
ff4aedc5 RN |
1770 | // |
1771 | // Create window | |
1772 | // By default wxWindow(s) is created with a border - | |
1773 | // so we need to get rid of those, and create with | |
1774 | // wxCLIP_CHILDREN, so that if the driver/backend | |
1775 | // is a child window, it refereshes properly | |
1776 | // | |
1777 | if ( !ctrl->wxControl::Create(parent, id, pos, size, | |
11085e4b | 1778 | (style & ~wxBORDER_MASK) | wxBORDER_NONE | wxCLIP_CHILDREN, |
ff4aedc5 RN |
1779 | validator, name) ) |
1780 | return false; | |
1781 | ||
3f9a3bf9 RN |
1782 | m_ctrl = ctrl; |
1783 | return true; | |
1784 | } | |
1785 | ||
ff4aedc5 RN |
1786 | //--------------------------------------------------------------------------- |
1787 | // wxMCIMediaBackend::Load (file version) | |
1788 | // | |
1789 | // Here we have MCI load a file and device, set the time format to our | |
1790 | // default (milliseconds), and set the video (if any) to play in the control | |
1791 | //--------------------------------------------------------------------------- | |
1792 | bool wxMCIMediaBackend::Load(const wxString& fileName) | |
3f9a3bf9 | 1793 | { |
ff4aedc5 RN |
1794 | // |
1795 | //if the user already called load close the previous MCI device | |
1796 | // | |
1797 | if(m_hNotifyWnd) | |
1798 | { | |
3f9a3bf9 | 1799 | mciSendCommand(m_hDev, MCI_CLOSE, 0, 0); |
ff4aedc5 RN |
1800 | DestroyWindow(m_hNotifyWnd); |
1801 | m_hNotifyWnd = NULL; | |
1802 | } | |
3f9a3bf9 | 1803 | |
ff4aedc5 RN |
1804 | // |
1805 | //Opens a file and has MCI select a device. Normally you'd put | |
1806 | //MCI_OPEN_TYPE in addition to MCI_OPEN_ELEMENT - however if you | |
226ec5a7 | 1807 | //omit this it tells MCI to select the device instead. This is |
ff4aedc5 RN |
1808 | //good because we have no reliable way of "enumerating" the devices |
1809 | //in MCI | |
1810 | // | |
3f9a3bf9 | 1811 | MCI_OPEN_PARMS openParms; |
3f9a3bf9 RN |
1812 | openParms.lpstrElementName = (wxChar*) fileName.c_str(); |
1813 | ||
226ec5a7 | 1814 | if ( mciSendCommand(0, MCI_OPEN, MCI_OPEN_ELEMENT, |
ff4aedc5 RN |
1815 | (DWORD)(LPVOID)&openParms) != 0) |
1816 | return false; | |
3f9a3bf9 RN |
1817 | |
1818 | m_hDev = openParms.wDeviceID; | |
1819 | ||
ff4aedc5 RN |
1820 | // |
1821 | //Now set the time format for the device to milliseconds | |
1822 | // | |
1823 | MCI_SET_PARMS setParms; | |
3f9a3bf9 RN |
1824 | setParms.dwCallback = 0; |
1825 | setParms.dwTimeFormat = MCI_FORMAT_MILLISECONDS; | |
1826 | ||
1827 | if (mciSendCommand(m_hDev, MCI_SET, MCI_SET_TIME_FORMAT, | |
1828 | (DWORD)(LPVOID)&setParms) != 0) | |
1829 | return false; | |
1830 | ||
ff4aedc5 RN |
1831 | // |
1832 | //Now tell the MCI device to display the video in our wxMediaCtrl | |
1833 | // | |
3f9a3bf9 | 1834 | MCI_DGV_WINDOW_PARMS windowParms; |
5987f174 | 1835 | windowParms.hWnd = (HWND)m_ctrl->GetHandle(); |
3f9a3bf9 | 1836 | |
226ec5a7 | 1837 | m_bVideo = (mciSendCommand(m_hDev, MCI_WINDOW, |
ff4aedc5 RN |
1838 | 0x00010000L, //MCI_DGV_WINDOW_HWND |
1839 | (DWORD)(LPVOID)&windowParms) == 0); | |
1840 | ||
1841 | // | |
1842 | // Create a hidden window and register to handle | |
1843 | // MCI events | |
226ec5a7 | 1844 | // Note that wxCanvasClassName is already registered |
ff4aedc5 | 1845 | // and used by all wxWindows and normal wxControls |
226ec5a7 | 1846 | // |
ff4aedc5 RN |
1847 | m_hNotifyWnd = ::CreateWindow |
1848 | ( | |
1849 | wxCanvasClassName, | |
1850 | NULL, | |
1851 | 0, 0, 0, 0, | |
1852 | 0, | |
1853 | (HWND) NULL, | |
1854 | (HMENU)NULL, | |
1855 | wxGetInstance(), | |
1856 | (LPVOID) NULL | |
1857 | ); | |
1858 | ||
1859 | if(!m_hNotifyWnd) | |
1860 | { | |
1861 | wxLogSysError( wxT("Could not create hidden needed for ") | |
1862 | wxT("registering for DirectShow events!") ); | |
1863 | ||
1864 | return false; | |
1865 | } | |
226ec5a7 | 1866 | |
1146983c | 1867 | wxSetWindowProc(m_hNotifyWnd, wxMCIMediaBackend::NotifyWndProc); |
ff4aedc5 RN |
1868 | |
1869 | ::SetWindowLong(m_hNotifyWnd, GWL_USERDATA, | |
1870 | (LONG) this); | |
1871 | ||
1872 | // | |
1873 | //Here, if the parent of the control has a sizer - we | |
1874 | //tell it to recalculate the size of this control since | |
3103e8a9 | 1875 | //the user opened a separate media file |
ff4aedc5 | 1876 | // |
5987f174 RN |
1877 | m_ctrl->InvalidateBestSize(); |
1878 | m_ctrl->GetParent()->Layout(); | |
1879 | m_ctrl->GetParent()->Refresh(); | |
1880 | m_ctrl->GetParent()->Update(); | |
b11eba7e | 1881 | m_ctrl->SetSize(m_ctrl->GetSize()); |
72259e00 | 1882 | |
3f9a3bf9 RN |
1883 | return true; |
1884 | } | |
1885 | ||
ff4aedc5 RN |
1886 | //--------------------------------------------------------------------------- |
1887 | // wxMCIMediaBackend::Load (URL version) | |
1888 | // | |
1889 | // MCI doesn't support URLs directly (?) | |
1890 | // | |
1891 | // TODO: Use wxURL/wxFileSystem and mmioInstallProc | |
1892 | //--------------------------------------------------------------------------- | |
1893 | bool wxMCIMediaBackend::Load(const wxURI& WXUNUSED(location)) | |
3f9a3bf9 RN |
1894 | { |
1895 | return false; | |
1896 | } | |
1897 | ||
ff4aedc5 RN |
1898 | //--------------------------------------------------------------------------- |
1899 | // wxMCIMediaBackend::Play | |
1900 | // | |
1901 | // Plays/Resumes the MCI device... a couple notes: | |
1902 | // 1) Certain drivers will crash and burn if we don't pass them an | |
1903 | // MCI_PLAY_PARMS, despite the documentation that says otherwise... | |
1904 | // 2) There is a MCI_RESUME command, but MCI_PLAY does the same thing | |
226ec5a7 | 1905 | // and will resume from a stopped state also, so there's no need to |
ff4aedc5 RN |
1906 | // call both, for example |
1907 | //--------------------------------------------------------------------------- | |
1908 | bool wxMCIMediaBackend::Play() | |
5987f174 | 1909 | { |
5987f174 | 1910 | MCI_PLAY_PARMS playParms; |
ff4aedc5 RN |
1911 | playParms.dwCallback = (DWORD)m_hNotifyWnd; |
1912 | ||
11219c9e | 1913 | bool bOK = ( mciSendCommand(m_hDev, MCI_PLAY, MCI_NOTIFY, |
ff4aedc5 | 1914 | (DWORD)(LPVOID)&playParms) == 0 ); |
11219c9e RN |
1915 | |
1916 | if(bOK) | |
1917 | m_ctrl->Show(m_bVideo); | |
1918 | ||
1919 | return bOK; | |
5987f174 RN |
1920 | } |
1921 | ||
ff4aedc5 RN |
1922 | //--------------------------------------------------------------------------- |
1923 | // wxMCIMediaBackend::Pause | |
1924 | // | |
1925 | // Pauses the MCI device - nothing special | |
226ec5a7 | 1926 | //--------------------------------------------------------------------------- |
ff4aedc5 | 1927 | bool wxMCIMediaBackend::Pause() |
5987f174 RN |
1928 | { |
1929 | return (mciSendCommand(m_hDev, MCI_PAUSE, MCI_WAIT, 0) == 0); | |
1930 | } | |
1931 | ||
ff4aedc5 RN |
1932 | //--------------------------------------------------------------------------- |
1933 | // wxMCIMediaBackend::Stop | |
1934 | // | |
1935 | // Stops the MCI device & seeks to the beginning as wxMediaCtrl docs outline | |
226ec5a7 | 1936 | //--------------------------------------------------------------------------- |
ff4aedc5 | 1937 | bool wxMCIMediaBackend::Stop() |
5987f174 RN |
1938 | { |
1939 | return (mciSendCommand(m_hDev, MCI_STOP, MCI_WAIT, 0) == 0) && | |
1940 | (mciSendCommand(m_hDev, MCI_SEEK, MCI_SEEK_TO_START, 0) == 0); | |
1941 | } | |
1942 | ||
ff4aedc5 RN |
1943 | //--------------------------------------------------------------------------- |
1944 | // wxMCIMediaBackend::GetState | |
1945 | // | |
1946 | // Here we get the state and convert it to a wxMediaState - | |
1947 | // since we use direct comparisons with MCI_MODE_PLAY and | |
1948 | // MCI_MODE_PAUSE, we don't care if the MCI_STATUS call | |
1949 | // fails or not | |
226ec5a7 | 1950 | //--------------------------------------------------------------------------- |
ff4aedc5 | 1951 | wxMediaState wxMCIMediaBackend::GetState() |
3f9a3bf9 RN |
1952 | { |
1953 | MCI_STATUS_PARMS statusParms; | |
1954 | statusParms.dwItem = MCI_STATUS_MODE; | |
ff4aedc5 | 1955 | |
3f9a3bf9 RN |
1956 | mciSendCommand(m_hDev, MCI_STATUS, MCI_STATUS_ITEM, |
1957 | (DWORD)(LPVOID)&statusParms); | |
1958 | ||
1959 | if(statusParms.dwReturn == MCI_MODE_PAUSE) | |
1960 | return wxMEDIASTATE_PAUSED; | |
1961 | else if(statusParms.dwReturn == MCI_MODE_PLAY) | |
1962 | return wxMEDIASTATE_PLAYING; | |
1963 | else | |
1964 | return wxMEDIASTATE_STOPPED; | |
1965 | } | |
1966 | ||
ff4aedc5 RN |
1967 | //--------------------------------------------------------------------------- |
1968 | // wxMCIMediaBackend::SetPosition | |
1969 | // | |
1970 | // Here we set the position of the device in the stream. | |
226ec5a7 | 1971 | // Note that MCI actually stops the device after you seek it if the |
ff4aedc5 | 1972 | // device is playing/paused, so we need to play the file after |
226ec5a7 WS |
1973 | // MCI seeks like normal APIs would |
1974 | //--------------------------------------------------------------------------- | |
ff4aedc5 | 1975 | bool wxMCIMediaBackend::SetPosition(wxLongLong where) |
3f9a3bf9 RN |
1976 | { |
1977 | MCI_SEEK_PARMS seekParms; | |
1978 | seekParms.dwCallback = 0; | |
e70fda0e | 1979 | #if wxUSE_LONGLONG_NATIVE && !wxUSE_LONGLONG_WX |
226ec5a7 | 1980 | seekParms.dwTo = (DWORD)where.GetValue(); |
e70fda0e WS |
1981 | #else /* wxUSE_LONGLONG_WX */ |
1982 | /* no way to return it in one piece */ | |
1983 | wxASSERT( where.GetHi()==0 ); | |
1984 | seekParms.dwTo = (DWORD)where.GetLo(); | |
1985 | #endif /* wxUSE_LONGLONG_* */ | |
3f9a3bf9 | 1986 | |
ff4aedc5 | 1987 | //device was playing? |
3f9a3bf9 RN |
1988 | bool bReplay = GetState() == wxMEDIASTATE_PLAYING; |
1989 | ||
226ec5a7 | 1990 | if( mciSendCommand(m_hDev, MCI_SEEK, MCI_TO, |
ff4aedc5 | 1991 | (DWORD)(LPVOID)&seekParms) != 0) |
3f9a3bf9 | 1992 | return false; |
3f9a3bf9 | 1993 | |
ff4aedc5 | 1994 | //If the device was playing, resume it |
3f9a3bf9 RN |
1995 | if (bReplay) |
1996 | return Play(); | |
1997 | else | |
1998 | return true; | |
1999 | } | |
2000 | ||
ff4aedc5 RN |
2001 | //--------------------------------------------------------------------------- |
2002 | // wxMCIMediaBackend::GetPosition | |
2003 | // | |
2004 | // Gets the position of the device in the stream using the current | |
2005 | // time format... nothing special here... | |
226ec5a7 | 2006 | //--------------------------------------------------------------------------- |
ff4aedc5 | 2007 | wxLongLong wxMCIMediaBackend::GetPosition() |
3f9a3bf9 RN |
2008 | { |
2009 | MCI_STATUS_PARMS statusParms; | |
72259e00 | 2010 | statusParms.dwItem = MCI_STATUS_POSITION; |
ff4aedc5 | 2011 | |
72259e00 | 2012 | if (mciSendCommand(m_hDev, MCI_STATUS, MCI_STATUS_ITEM, |
ff4aedc5 | 2013 | (DWORD)(LPSTR)&statusParms) != 0) |
3f9a3bf9 RN |
2014 | return 0; |
2015 | ||
2016 | return statusParms.dwReturn; | |
2017 | } | |
2018 | ||
6f8c67e7 JS |
2019 | //--------------------------------------------------------------------------- |
2020 | // wxMCIMediaBackend::GetVolume | |
2021 | // | |
2022 | // Gets the volume of the current media via the MCI_DGV_STATUS_VOLUME | |
2023 | // message. Value ranges from 0 (minimum) to 1000 (maximum volume). | |
2024 | //--------------------------------------------------------------------------- | |
2025 | double wxMCIMediaBackend::GetVolume() | |
2026 | { | |
2027 | MCI_STATUS_PARMS statusParms; | |
600ffb32 | 2028 | statusParms.dwCallback = 0; |
6f8c67e7 JS |
2029 | statusParms.dwItem = 0x4019; //MCI_DGV_STATUS_VOLUME |
2030 | ||
2031 | if (mciSendCommand(m_hDev, MCI_STATUS, MCI_STATUS_ITEM, | |
2032 | (DWORD)(LPSTR)&statusParms) != 0) | |
2033 | return 0; | |
2034 | ||
2035 | return ((double)statusParms.dwReturn) / 1000.0; | |
2036 | } | |
2037 | ||
2038 | //--------------------------------------------------------------------------- | |
2039 | // wxMCIMediaBackend::SetVolume | |
2040 | // | |
2041 | // Sets the volume of the current media via the MCI_DGV_SETAUDIO_VOLUME | |
2042 | // message. Value ranges from 0 (minimum) to 1000 (maximum volume). | |
2043 | //--------------------------------------------------------------------------- | |
2044 | bool wxMCIMediaBackend::SetVolume(double dVolume) | |
2045 | { | |
2046 | MCI_DGV_SETAUDIO_PARMS audioParms; | |
600ffb32 | 2047 | audioParms.dwCallback = 0; |
6f8c67e7 JS |
2048 | audioParms.dwItem = 0x4002; //MCI_DGV_SETAUDIO_VOLUME |
2049 | audioParms.dwValue = (DWORD) (dVolume * 1000.0); | |
2050 | audioParms.dwOver = 0; | |
2051 | audioParms.lpstrAlgorithm = NULL; | |
2052 | audioParms.lpstrQuality = NULL; | |
2053 | ||
b11eba7e | 2054 | if (mciSendCommand(m_hDev, 0x0873, //MCI_SETAUDIO |
6f8c67e7 JS |
2055 | 0x00800000L | 0x01000000L, //MCI_DGV_SETAUDIO+(_ITEM | _VALUE) |
2056 | (DWORD)(LPSTR)&audioParms) != 0) | |
2057 | return false; | |
2058 | return true; | |
2059 | } | |
2060 | ||
ff4aedc5 RN |
2061 | //--------------------------------------------------------------------------- |
2062 | // wxMCIMediaBackend::GetDuration | |
2063 | // | |
2064 | // Gets the duration of the stream... nothing special | |
226ec5a7 | 2065 | //--------------------------------------------------------------------------- |
ff4aedc5 | 2066 | wxLongLong wxMCIMediaBackend::GetDuration() |
3f9a3bf9 RN |
2067 | { |
2068 | MCI_STATUS_PARMS statusParms; | |
72259e00 | 2069 | statusParms.dwItem = MCI_STATUS_LENGTH; |
ff4aedc5 | 2070 | |
72259e00 | 2071 | if (mciSendCommand(m_hDev, MCI_STATUS, MCI_STATUS_ITEM, |
ff4aedc5 | 2072 | (DWORD)(LPSTR)&statusParms) != 0) |
3f9a3bf9 RN |
2073 | return 0; |
2074 | ||
2075 | return statusParms.dwReturn; | |
2076 | } | |
2077 | ||
ff4aedc5 RN |
2078 | //--------------------------------------------------------------------------- |
2079 | // wxMCIMediaBackend::Move | |
2080 | // | |
2081 | // Moves the window to a location | |
226ec5a7 WS |
2082 | //--------------------------------------------------------------------------- |
2083 | void wxMCIMediaBackend::Move(int WXUNUSED(x), int WXUNUSED(y), | |
ff4aedc5 | 2084 | int w, int h) |
3f9a3bf9 | 2085 | { |
ff4aedc5 RN |
2086 | if (m_hNotifyWnd && m_bVideo) |
2087 | { | |
2088 | MCI_DGV_RECT_PARMS putParms; //ifdefed MCI_DGV_PUT_PARMS | |
b11eba7e | 2089 | memset(&putParms, 0, sizeof(MCI_DGV_RECT_PARMS)); |
ff4aedc5 | 2090 | putParms.rc.bottom = h; |
b11eba7e | 2091 | putParms.rc.right = w; |
7c4a4505 | 2092 | |
b11eba7e WS |
2093 | //wxStackWalker will crash and burn here on assert |
2094 | //and mci doesn't like 0 and 0 for some reason (out of range ) | |
2095 | //so just don't it in that case | |
2096 | if(w || h) | |
2097 | { | |
7c4a4505 | 2098 | wxMCIVERIFY( mciSendCommand(m_hDev, MCI_PUT, |
ff4aedc5 RN |
2099 | 0x00040000L, //MCI_DGV_PUT_DESTINATION |
2100 | (DWORD)(LPSTR)&putParms) ); | |
7c4a4505 | 2101 | } |
ff4aedc5 | 2102 | } |
3f9a3bf9 RN |
2103 | } |
2104 | ||
ff4aedc5 RN |
2105 | //--------------------------------------------------------------------------- |
2106 | // wxMCIMediaBackend::GetVideoSize | |
2107 | // | |
2108 | // Gets the original size of the movie for sizers | |
226ec5a7 | 2109 | //--------------------------------------------------------------------------- |
ff4aedc5 | 2110 | wxSize wxMCIMediaBackend::GetVideoSize() const |
3f9a3bf9 RN |
2111 | { |
2112 | if(m_bVideo) | |
2113 | { | |
ff4aedc5 | 2114 | MCI_DGV_RECT_PARMS whereParms; //ifdefed MCI_DGV_WHERE_PARMS |
3f9a3bf9 | 2115 | |
226ec5a7 | 2116 | wxMCIVERIFY( mciSendCommand(m_hDev, MCI_WHERE, |
ff4aedc5 RN |
2117 | 0x00020000L, //MCI_DGV_WHERE_SOURCE |
2118 | (DWORD)(LPSTR)&whereParms) ); | |
226ec5a7 | 2119 | |
ff4aedc5 | 2120 | return wxSize(whereParms.rc.right, whereParms.rc.bottom); |
3f9a3bf9 | 2121 | } |
c47addef | 2122 | return wxSize(0,0); |
3f9a3bf9 RN |
2123 | } |
2124 | ||
ff4aedc5 RN |
2125 | //--------------------------------------------------------------------------- |
2126 | // wxMCIMediaBackend::GetPlaybackRate | |
2127 | // | |
2128 | // TODO | |
226ec5a7 | 2129 | //--------------------------------------------------------------------------- |
ff4aedc5 | 2130 | double wxMCIMediaBackend::GetPlaybackRate() |
3f9a3bf9 RN |
2131 | { |
2132 | return 1.0; | |
2133 | } | |
2134 | ||
ff4aedc5 RN |
2135 | //--------------------------------------------------------------------------- |
2136 | // wxMCIMediaBackend::SetPlaybackRate | |
2137 | // | |
2138 | // TODO | |
226ec5a7 | 2139 | //--------------------------------------------------------------------------- |
ff4aedc5 | 2140 | bool wxMCIMediaBackend::SetPlaybackRate(double WXUNUSED(dRate)) |
3f9a3bf9 | 2141 | { |
ff4aedc5 RN |
2142 | /* |
2143 | MCI_WAVE_SET_SAMPLESPERSEC | |
2144 | MCI_DGV_SET_PARMS setParms; | |
2145 | setParms.dwSpeed = (DWORD) (dRate * 1000.0); | |
2146 | ||
226ec5a7 | 2147 | return (mciSendCommand(m_hDev, MCI_SET, |
ff4aedc5 RN |
2148 | 0x00020000L, //MCI_DGV_SET_SPEED |
2149 | (DWORD)(LPSTR)&setParms) == 0); | |
2150 | */ | |
3f9a3bf9 RN |
2151 | return false; |
2152 | } | |
2153 | ||
ff4aedc5 RN |
2154 | //--------------------------------------------------------------------------- |
2155 | // [static] wxMCIMediaBackend::MSWWindowProc | |
2156 | // | |
226ec5a7 | 2157 | // Here we process a message when MCI reaches the stopping point |
ff4aedc5 | 2158 | // in the stream |
226ec5a7 WS |
2159 | //--------------------------------------------------------------------------- |
2160 | LRESULT CALLBACK wxMCIMediaBackend::NotifyWndProc(HWND hWnd, UINT nMsg, | |
2161 | WPARAM wParam, | |
ff4aedc5 RN |
2162 | LPARAM lParam) |
2163 | { | |
2164 | wxMCIMediaBackend* backend = (wxMCIMediaBackend*) | |
106d80ad | 2165 | #ifdef _WIN32 |
ff4aedc5 | 2166 | ::GetWindowLong(hWnd, GWL_USERDATA); |
106d80ad JS |
2167 | #else |
2168 | ::GetWindowLongPtr(hWnd, GWLP_USERDATA); | |
b11eba7e | 2169 | #endif |
ff4aedc5 RN |
2170 | wxASSERT(backend); |
2171 | ||
2172 | return backend->OnNotifyWndProc(hWnd, nMsg, wParam, lParam); | |
2173 | } | |
2174 | ||
226ec5a7 WS |
2175 | LRESULT CALLBACK wxMCIMediaBackend::OnNotifyWndProc(HWND hWnd, UINT nMsg, |
2176 | WPARAM wParam, | |
ff4aedc5 | 2177 | LPARAM lParam) |
3f9a3bf9 | 2178 | { |
5987f174 RN |
2179 | if(nMsg == MM_MCINOTIFY) |
2180 | { | |
ff4aedc5 RN |
2181 | wxASSERT(lParam == (LPARAM) m_hDev); |
2182 | if(wParam == MCI_NOTIFY_SUCCESSFUL && lParam == (LPARAM)m_hDev) | |
5987f174 | 2183 | { |
ff4aedc5 RN |
2184 | wxMediaEvent theEvent(wxEVT_MEDIA_STOP, m_ctrl->GetId()); |
2185 | m_ctrl->ProcessEvent(theEvent); | |
2186 | ||
2187 | if(theEvent.IsAllowed()) | |
2188 | { | |
226ec5a7 | 2189 | wxMCIVERIFY( mciSendCommand(m_hDev, MCI_SEEK, |
ff4aedc5 | 2190 | MCI_SEEK_TO_START, 0) ); |
3f9a3bf9 | 2191 | |
ff4aedc5 | 2192 | //send the event to our child |
226ec5a7 | 2193 | wxMediaEvent theEvent(wxEVT_MEDIA_FINISHED, |
ff4aedc5 RN |
2194 | m_ctrl->GetId()); |
2195 | m_ctrl->ProcessEvent(theEvent); | |
2196 | } | |
5987f174 | 2197 | } |
5987f174 | 2198 | } |
ff4aedc5 | 2199 | return DefWindowProc(hWnd, nMsg, wParam, lParam); |
3f9a3bf9 | 2200 | } |
ff4aedc5 RN |
2201 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2202 | // | |
2203 | // wxQTMediaBackend | |
226ec5a7 | 2204 | // |
ff4aedc5 RN |
2205 | // TODO: Use a less cludgy way to pause/get state/set state |
2206 | // TODO: Dynamically load from qtml.dll | |
2207 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | |
2208 | ||
ff4aedc5 RN |
2209 | IMPLEMENT_DYNAMIC_CLASS(wxQTMediaBackend, wxMediaBackend); |
2210 | ||
2211 | //Time between timer calls | |
2212 | #define MOVIE_DELAY 100 | |
2213 | ||
2214 | #include "wx/timer.h" | |
2215 | ||
2216 | // -------------------------------------------------------------------------- | |
2217 | // wxQTTimer - Handle Asyncronous Playing | |
2218 | // -------------------------------------------------------------------------- | |
2219 | class _wxQTTimer : public wxTimer | |
2220 | { | |
2221 | public: | |
d7a9c895 RN |
2222 | _wxQTTimer(Movie movie, wxQTMediaBackend* parent, wxQuickTimeLibrary* pLib) : |
2223 | m_movie(movie), m_bPaused(false), m_parent(parent), m_pLib(pLib) | |
ff4aedc5 RN |
2224 | { |
2225 | } | |
2226 | ||
2227 | ~_wxQTTimer() | |
2228 | { | |
2229 | } | |
2230 | ||
2231 | bool GetPaused() {return m_bPaused;} | |
2232 | void SetPaused(bool bPaused) {m_bPaused = bPaused;} | |
2233 | ||
2234 | //----------------------------------------------------------------------- | |
2235 | // _wxQTTimer::Notify | |
2236 | // | |
2237 | // 1) Checks to see if the movie is done, and if not continues | |
2238 | // streaming the movie | |
2239 | // 2) Sends the wxEVT_MEDIA_STOP event if we have reached the end of | |
2240 | // the movie. | |
2241 | //----------------------------------------------------------------------- | |
2242 | void Notify() | |
2243 | { | |
2244 | if (!m_bPaused) | |
2245 | { | |
d7a9c895 RN |
2246 | if(!m_pLib->IsMovieDone(m_movie)) |
2247 | m_pLib->MoviesTask(m_movie, MOVIE_DELAY); | |
ff4aedc5 RN |
2248 | else |
2249 | { | |
226ec5a7 | 2250 | wxMediaEvent theEvent(wxEVT_MEDIA_STOP, |
ff4aedc5 RN |
2251 | m_parent->m_ctrl->GetId()); |
2252 | m_parent->m_ctrl->ProcessEvent(theEvent); | |
2253 | ||
2254 | if(theEvent.IsAllowed()) | |
2255 | { | |
2256 | Stop(); | |
2257 | m_parent->Stop(); | |
d7a9c895 | 2258 | wxASSERT(m_pLib->GetMoviesError() == noErr); |
ff4aedc5 RN |
2259 | |
2260 | //send the event to our child | |
226ec5a7 | 2261 | wxMediaEvent theEvent(wxEVT_MEDIA_FINISHED, |
ff4aedc5 RN |
2262 | m_parent->m_ctrl->GetId()); |
2263 | m_parent->m_ctrl->ProcessEvent(theEvent); | |
2264 | } | |
2265 | } | |
2266 | } | |
2267 | } | |
2268 | ||
2269 | protected: | |
2270 | Movie m_movie; //Our movie instance | |
2271 | bool m_bPaused; //Whether we are paused or not | |
2272 | wxQTMediaBackend* m_parent; //Backend pointer | |
d7a9c895 | 2273 | wxQuickTimeLibrary* m_pLib; //Interfaces |
ff4aedc5 RN |
2274 | }; |
2275 | ||
2276 | //--------------------------------------------------------------------------- | |
2277 | // wxQTMediaBackend Destructor | |
2278 | // | |
2279 | // Sets m_timer to NULL signifying we havn't loaded anything yet | |
2280 | //--------------------------------------------------------------------------- | |
2281 | wxQTMediaBackend::wxQTMediaBackend() : m_timer(NULL) | |
2282 | { | |
2283 | } | |
2284 | ||
2285 | //--------------------------------------------------------------------------- | |
2286 | // wxQTMediaBackend Destructor | |
2287 | // | |
2288 | // 1) Cleans up the QuickTime movie instance | |
2289 | // 2) Decrements the QuickTime reference counter - if this reaches | |
2290 | // 0, QuickTime shuts down | |
2291 | // 3) Decrements the QuickTime Windows Media Layer reference counter - | |
2292 | // if this reaches 0, QuickTime shuts down the Windows Media Layer | |
2293 | //--------------------------------------------------------------------------- | |
2294 | wxQTMediaBackend::~wxQTMediaBackend() | |
2295 | { | |
2296 | if(m_timer) | |
2297 | Cleanup(); | |
2298 | ||
d7a9c895 RN |
2299 | if(m_lib.IsOk()) |
2300 | { | |
3103e8a9 | 2301 | //Note that ExitMovies() is not necessary, but |
d7a9c895 RN |
2302 | //the docs are fuzzy on whether or not TerminateQTML is |
2303 | m_lib.ExitMovies(); | |
2304 | m_lib.TerminateQTML(); | |
2305 | } | |
ff4aedc5 RN |
2306 | } |
2307 | ||
2308 | //--------------------------------------------------------------------------- | |
2309 | // wxQTMediaBackend::CreateControl | |
2310 | // | |
2311 | // 1) Intializes QuickTime | |
2312 | // 2) Creates the control window | |
2313 | //--------------------------------------------------------------------------- | |
226ec5a7 | 2314 | bool wxQTMediaBackend::CreateControl(wxControl* ctrl, wxWindow* parent, |
ff4aedc5 | 2315 | wxWindowID id, |
226ec5a7 | 2316 | const wxPoint& pos, |
ff4aedc5 | 2317 | const wxSize& size, |
226ec5a7 | 2318 | long style, |
ff4aedc5 RN |
2319 | const wxValidator& validator, |
2320 | const wxString& name) | |
2321 | { | |
d7a9c895 RN |
2322 | if(!m_lib.Initialize()) |
2323 | return false; | |
b11eba7e | 2324 | |
600ffb32 WS |
2325 | int nError = m_lib.InitializeQTML(0); |
2326 | if (nError != noErr) //-2093 no dll | |
ff4aedc5 RN |
2327 | { |
2328 | wxFAIL_MSG(wxString::Format(wxT("Couldn't Initialize Quicktime-%i"), nError)); | |
2329 | return false; | |
2330 | } | |
d7a9c895 | 2331 | m_lib.EnterMovies(); |
ff4aedc5 RN |
2332 | |
2333 | // | |
2334 | // Create window | |
2335 | // By default wxWindow(s) is created with a border - | |
2336 | // so we need to get rid of those | |
2337 | // | |
2338 | // Since we don't have a child window like most other | |
2339 | // backends, we don't need wxCLIP_CHILDREN | |
2340 | // | |
2341 | if ( !ctrl->wxControl::Create(parent, id, pos, size, | |
11085e4b | 2342 | (style & ~wxBORDER_MASK) | wxBORDER_NONE, |
ff4aedc5 RN |
2343 | validator, name) ) |
2344 | return false; | |
2345 | ||
ff4aedc5 RN |
2346 | m_ctrl = ctrl; |
2347 | return true; | |
2348 | } | |
2349 | ||
2350 | //--------------------------------------------------------------------------- | |
2351 | // wxQTMediaBackend::Load (file version) | |
2352 | // | |
2353 | // 1) Get an FSSpec from the Windows path name | |
2354 | // 2) Open the movie | |
2355 | // 3) Obtain the movie instance from the movie resource | |
226ec5a7 | 2356 | // 4) |
ff4aedc5 RN |
2357 | //--------------------------------------------------------------------------- |
2358 | bool wxQTMediaBackend::Load(const wxString& fileName) | |
2359 | { | |
2360 | if(m_timer) | |
2361 | Cleanup(); | |
3f9a3bf9 | 2362 | |
920a7c15 | 2363 | short movieResFile = 0; //= 0 because of annoying VC6 warning |
ff4aedc5 RN |
2364 | FSSpec sfFile; |
2365 | ||
d7a9c895 | 2366 | if (m_lib.NativePathNameToFSSpec ((char*) (const char*) fileName.mb_str(), |
78450975 | 2367 | &sfFile, 0) != noErr) |
ff4aedc5 | 2368 | return false; |
226ec5a7 | 2369 | |
d7a9c895 | 2370 | if (m_lib.OpenMovieFile (&sfFile, &movieResFile, fsRdPerm) != noErr) |
ff4aedc5 RN |
2371 | return false; |
2372 | ||
2373 | short movieResID = 0; | |
2374 | Str255 movieName; | |
2375 | ||
600ffb32 WS |
2376 | OSErr err = m_lib.NewMovieFromFile ( |
2377 | &m_movie, | |
2378 | movieResFile, | |
2379 | &movieResID, | |
2380 | movieName, | |
2381 | newMovieActive, | |
2382 | NULL | |
2383 | ); //wasChanged | |
ff4aedc5 | 2384 | |
d7a9c895 | 2385 | m_lib.CloseMovieFile (movieResFile); |
ff4aedc5 RN |
2386 | |
2387 | if (err != noErr) | |
2388 | return false; | |
2389 | ||
2390 | FinishLoad(); | |
2391 | ||
d7a9c895 | 2392 | return m_lib.GetMoviesError() == noErr; |
ff4aedc5 RN |
2393 | } |
2394 | ||
2395 | //--------------------------------------------------------------------------- | |
2396 | // wxQTMediaBackend::Move | |
2397 | // | |
2398 | // TODO | |
2399 | //--------------------------------------------------------------------------- | |
2400 | bool wxQTMediaBackend::Load(const wxURI& location) | |
2401 | { | |
2402 | if(m_timer) | |
2403 | Cleanup(); | |
2404 | ||
2405 | wxString theURI = location.BuildURI(); | |
2406 | ||
d7a9c895 | 2407 | Handle theHandle = m_lib.NewHandleClear(theURI.length() + 1); |
ff4aedc5 RN |
2408 | wxASSERT(theHandle); |
2409 | ||
d7a9c895 | 2410 | m_lib.BlockMove(theURI.mb_str(), *theHandle, theURI.length() + 1); |
ff4aedc5 RN |
2411 | |
2412 | //create the movie from the handle that refers to the URI | |
600ffb32 | 2413 | OSErr err = m_lib.NewMovieFromDataRef(&m_movie, newMovieActive, |
226ec5a7 | 2414 | NULL, theHandle, |
19b6f122 | 2415 | URLDataHandlerSubType); |
ff4aedc5 | 2416 | |
d7a9c895 | 2417 | m_lib.DisposeHandle(theHandle); |
ff4aedc5 RN |
2418 | |
2419 | if (err != noErr) | |
2420 | return false; | |
2421 | ||
2422 | //preroll movie for streaming | |
2423 | //TODO:Async this? | |
d7a9c895 RN |
2424 | /* |
2425 | TimeValue timeNow; | |
ff4aedc5 RN |
2426 | Fixed playRate; |
2427 | timeNow = GetMovieTime(m_movie, NULL); | |
2428 | playRate = GetMoviePreferredRate(m_movie); | |
2429 | PrePrerollMovie(m_movie, timeNow, playRate, NULL, NULL); | |
b11eba7e | 2430 | PrerollMovie(m_movie, timeNow, playRate); |
d7a9c895 RN |
2431 | m_lib.SetMovieRate(m_movie, playRate); |
2432 | */ | |
ff4aedc5 RN |
2433 | |
2434 | FinishLoad(); | |
2435 | ||
d7a9c895 | 2436 | return m_lib.GetMoviesError() == noErr; |
ff4aedc5 RN |
2437 | } |
2438 | ||
2439 | //--------------------------------------------------------------------------- | |
2440 | // wxQTMediaBackend::Move | |
2441 | // | |
2442 | // TODO | |
2443 | //--------------------------------------------------------------------------- | |
2444 | void wxQTMediaBackend::FinishLoad() | |
2445 | { | |
d7a9c895 | 2446 | m_timer = new _wxQTTimer(m_movie, (wxQTMediaBackend*) this, &m_lib); |
ff4aedc5 RN |
2447 | wxASSERT(m_timer); |
2448 | ||
2449 | //get the real size of the movie | |
2450 | Rect outRect; | |
920a7c15 | 2451 | memset(&outRect, 0, sizeof(Rect)); //for annoying VC6 warning |
d7a9c895 RN |
2452 | m_lib.GetMovieNaturalBoundsRect (m_movie, &outRect); |
2453 | wxASSERT(m_lib.GetMoviesError() == noErr); | |
ff4aedc5 RN |
2454 | |
2455 | m_bestSize.x = outRect.right - outRect.left; | |
2456 | m_bestSize.y = outRect.bottom - outRect.top; | |
226ec5a7 | 2457 | |
ff4aedc5 | 2458 | //reparent movie/*AudioMediaCharacteristic*/ |
d7a9c895 | 2459 | if(m_lib.GetMovieIndTrackType(m_movie, 1, |
19b6f122 | 2460 | VisualMediaCharacteristic, |
b11eba7e | 2461 | (1 << 1) //movieTrackCharacteristic |
d7a9c895 RN |
2462 | | (1 << 2) //movieTrackEnabledOnly |
2463 | ) != NULL) | |
ff4aedc5 | 2464 | { |
d7a9c895 | 2465 | m_lib.CreatePortAssociation(m_ctrl->GetHWND(), NULL, 0L); |
226ec5a7 | 2466 | |
d7a9c895 RN |
2467 | m_lib.SetMovieGWorld(m_movie, |
2468 | (CGrafPtr) m_lib.GetNativeWindowPort(m_ctrl->GetHWND()), | |
2469 | NULL); | |
ff4aedc5 RN |
2470 | } |
2471 | ||
2472 | //we want millisecond precision | |
d7a9c895 RN |
2473 | m_lib.SetMovieTimeScale(m_movie, 1000); |
2474 | wxASSERT(m_lib.GetMoviesError() == noErr); | |
ff4aedc5 RN |
2475 | |
2476 | // | |
2477 | //Here, if the parent of the control has a sizer - we | |
2478 | //tell it to recalculate the size of this control since | |
3103e8a9 | 2479 | //the user opened a separate media file |
ff4aedc5 RN |
2480 | // |
2481 | m_ctrl->InvalidateBestSize(); | |
2482 | m_ctrl->GetParent()->Layout(); | |
2483 | m_ctrl->GetParent()->Refresh(); | |
2484 | m_ctrl->GetParent()->Update(); | |
2485 | } | |
2486 | ||
2487 | //--------------------------------------------------------------------------- | |
2488 | // wxQTMediaBackend::Move | |
2489 | // | |
2490 | // TODO | |
2491 | //--------------------------------------------------------------------------- | |
2492 | bool wxQTMediaBackend::Play() | |
2493 | { | |
d7a9c895 | 2494 | m_lib.StartMovie(m_movie); |
ff4aedc5 RN |
2495 | m_timer->SetPaused(false); |
2496 | m_timer->Start(MOVIE_DELAY, wxTIMER_CONTINUOUS); | |
d7a9c895 | 2497 | return m_lib.GetMoviesError() == noErr; |
ff4aedc5 RN |
2498 | } |
2499 | ||
2500 | //--------------------------------------------------------------------------- | |
2501 | // wxQTMediaBackend::Move | |
2502 | // | |
2503 | // TODO | |
2504 | //--------------------------------------------------------------------------- | |
2505 | bool wxQTMediaBackend::Pause() | |
2506 | { | |
d7a9c895 | 2507 | m_lib.StopMovie(m_movie); |
ff4aedc5 RN |
2508 | m_timer->SetPaused(true); |
2509 | m_timer->Stop(); | |
d7a9c895 | 2510 | return m_lib.GetMoviesError() == noErr; |
ff4aedc5 RN |
2511 | } |
2512 | ||
2513 | //--------------------------------------------------------------------------- | |
2514 | // wxQTMediaBackend::Move | |
2515 | // | |
2516 | // TODO | |
2517 | //--------------------------------------------------------------------------- | |
2518 | bool wxQTMediaBackend::Stop() | |
2519 | { | |
2520 | m_timer->SetPaused(false); | |
2521 | m_timer->Stop(); | |
2522 | ||
d7a9c895 RN |
2523 | m_lib.StopMovie(m_movie); |
2524 | if(m_lib.GetMoviesError() != noErr) | |
ff4aedc5 | 2525 | return false; |
226ec5a7 | 2526 | |
d7a9c895 RN |
2527 | m_lib.GoToBeginningOfMovie(m_movie); |
2528 | return m_lib.GetMoviesError() == noErr; | |
ff4aedc5 RN |
2529 | } |
2530 | ||
2531 | //--------------------------------------------------------------------------- | |
2532 | // wxQTMediaBackend::Move | |
2533 | // | |
2534 | // TODO | |
2535 | //--------------------------------------------------------------------------- | |
2536 | double wxQTMediaBackend::GetPlaybackRate() | |
2537 | { | |
d7a9c895 | 2538 | return ( ((double)m_lib.GetMovieRate(m_movie)) / 0x10000); |
ff4aedc5 RN |
2539 | } |
2540 | ||
2541 | //--------------------------------------------------------------------------- | |
2542 | // wxQTMediaBackend::Move | |
2543 | // | |
2544 | // TODO | |
2545 | //--------------------------------------------------------------------------- | |
2546 | bool wxQTMediaBackend::SetPlaybackRate(double dRate) | |
2547 | { | |
d7a9c895 RN |
2548 | m_lib.SetMovieRate(m_movie, (Fixed) (dRate * 0x10000)); |
2549 | return m_lib.GetMoviesError() == noErr; | |
ff4aedc5 RN |
2550 | } |
2551 | ||
2552 | //--------------------------------------------------------------------------- | |
2553 | // wxQTMediaBackend::Move | |
2554 | // | |
2555 | // TODO | |
2556 | //--------------------------------------------------------------------------- | |
2557 | bool wxQTMediaBackend::SetPosition(wxLongLong where) | |
2558 | { | |
2559 | TimeRecord theTimeRecord; | |
2560 | memset(&theTimeRecord, 0, sizeof(TimeRecord)); | |
600ffb32 | 2561 | theTimeRecord.value.lo = where.GetLo(); |
d7a9c895 RN |
2562 | theTimeRecord.scale = m_lib.GetMovieTimeScale(m_movie); |
2563 | theTimeRecord.base = m_lib.GetMovieTimeBase(m_movie); | |
2564 | m_lib.SetMovieTime(m_movie, &theTimeRecord); | |
ff4aedc5 | 2565 | |
d7a9c895 | 2566 | if (m_lib.GetMoviesError() != noErr) |
ff4aedc5 RN |
2567 | return false; |
2568 | ||
2569 | return true; | |
2570 | } | |
2571 | ||
2572 | //--------------------------------------------------------------------------- | |
e163773d | 2573 | // wxQTMediaBackend::GetPosition |
ff4aedc5 | 2574 | // |
e163773d | 2575 | // 1) Calls GetMovieTime to get the position we are in in the movie |
8b5d5223 | 2576 | // in milliseconds (we called |
ff4aedc5 RN |
2577 | //--------------------------------------------------------------------------- |
2578 | wxLongLong wxQTMediaBackend::GetPosition() | |
2579 | { | |
d7a9c895 | 2580 | return m_lib.GetMovieTime(m_movie, NULL); |
ff4aedc5 RN |
2581 | } |
2582 | ||
6f8c67e7 JS |
2583 | //--------------------------------------------------------------------------- |
2584 | // wxQTMediaBackend::GetVolume | |
2585 | // | |
2586 | // Gets the volume through GetMovieVolume - which returns a 16 bit short - | |
2587 | // | |
2588 | // +--------+--------+ | |
2589 | // + (1) + (2) + | |
2590 | // +--------+--------+ | |
2591 | // | |
2592 | // (1) first 8 bits are value before decimal | |
2593 | // (2) second 8 bits are value after decimal | |
2594 | // | |
2595 | // Volume ranges from -1.0 (gain but no sound), 0 (no sound and no gain) to | |
2596 | // 1 (full gain and sound) | |
2597 | //--------------------------------------------------------------------------- | |
2598 | double wxQTMediaBackend::GetVolume() | |
2599 | { | |
2600 | short sVolume = m_lib.GetMovieVolume(m_movie); | |
b11eba7e | 2601 | |
6f8c67e7 JS |
2602 | if(sVolume & (128 << 8)) //negative - no sound |
2603 | return 0.0; | |
2604 | ||
2605 | return (sVolume & (127 << 8)) ? 1.0 : ((double)(sVolume & 255)) / 255.0; | |
2606 | } | |
2607 | ||
2608 | //--------------------------------------------------------------------------- | |
2609 | // wxQTMediaBackend::SetVolume | |
2610 | // | |
2611 | // Sets the volume through SetMovieVolume - which takes a 16 bit short - | |
2612 | // | |
2613 | // +--------+--------+ | |
2614 | // + (1) + (2) + | |
2615 | // +--------+--------+ | |
2616 | // | |
2617 | // (1) first 8 bits are value before decimal | |
2618 | // (2) second 8 bits are value after decimal | |
2619 | // | |
2620 | // Volume ranges from -1.0 (gain but no sound), 0 (no sound and no gain) to | |
2621 | // 1 (full gain and sound) | |
2622 | //--------------------------------------------------------------------------- | |
2623 | bool wxQTMediaBackend::SetVolume(double dVolume) | |
2624 | { | |
600ffb32 | 2625 | short sVolume = (short) (dVolume >= .9999 ? 1 << 8 : (dVolume * 255) ); |
6f8c67e7 JS |
2626 | m_lib.SetMovieVolume(m_movie, sVolume); |
2627 | return true; | |
2628 | } | |
2629 | ||
ff4aedc5 RN |
2630 | //--------------------------------------------------------------------------- |
2631 | // wxQTMediaBackend::Move | |
2632 | // | |
2633 | // TODO | |
2634 | //--------------------------------------------------------------------------- | |
2635 | wxLongLong wxQTMediaBackend::GetDuration() | |
2636 | { | |
d7a9c895 | 2637 | return m_lib.GetMovieDuration(m_movie); |
ff4aedc5 RN |
2638 | } |
2639 | ||
2640 | //--------------------------------------------------------------------------- | |
2641 | // wxQTMediaBackend::Move | |
2642 | // | |
2643 | // TODO | |
2644 | //--------------------------------------------------------------------------- | |
2645 | wxMediaState wxQTMediaBackend::GetState() | |
2646 | { | |
226ec5a7 | 2647 | if ( !m_timer || (m_timer->IsRunning() == false && |
ff4aedc5 RN |
2648 | m_timer->GetPaused() == false) ) |
2649 | return wxMEDIASTATE_STOPPED; | |
2650 | ||
2651 | if( m_timer->IsRunning() == true ) | |
2652 | return wxMEDIASTATE_PLAYING; | |
2653 | else | |
2654 | return wxMEDIASTATE_PAUSED; | |
2655 | } | |
2656 | ||
2657 | //--------------------------------------------------------------------------- | |
2658 | // wxQTMediaBackend::Move | |
2659 | // | |
2660 | // TODO | |
2661 | //--------------------------------------------------------------------------- | |
2662 | void wxQTMediaBackend::Cleanup() | |
2663 | { | |
2664 | delete m_timer; | |
2665 | m_timer = NULL; | |
2666 | ||
d7a9c895 RN |
2667 | m_lib.StopMovie(m_movie); |
2668 | m_lib.DisposeMovie(m_movie); | |
ff4aedc5 RN |
2669 | } |
2670 | ||
2671 | //--------------------------------------------------------------------------- | |
2672 | // wxQTMediaBackend::Move | |
2673 | // | |
2674 | // TODO | |
2675 | //--------------------------------------------------------------------------- | |
2676 | wxSize wxQTMediaBackend::GetVideoSize() const | |
2677 | { | |
2678 | return m_bestSize; | |
2679 | } | |
2680 | ||
2681 | //--------------------------------------------------------------------------- | |
2682 | // wxQTMediaBackend::Move | |
2683 | // | |
2684 | // TODO | |
2685 | //--------------------------------------------------------------------------- | |
d7a9c895 | 2686 | void wxQTMediaBackend::Move(int WXUNUSED(x), int WXUNUSED(y), int w, int h) |
ff4aedc5 RN |
2687 | { |
2688 | if(m_timer) | |
2689 | { | |
600ffb32 | 2690 | Rect theRect = {0, 0, (short)h, (short)w}; |
ff4aedc5 | 2691 | |
d7a9c895 RN |
2692 | m_lib.SetMovieBox(m_movie, &theRect); |
2693 | wxASSERT(m_lib.GetMoviesError() == noErr); | |
ff4aedc5 RN |
2694 | } |
2695 | } | |
2696 | ||
2697 | //--------------------------------------------------------------------------- | |
1146983c | 2698 | // End QT Backend |
ff4aedc5 | 2699 | //--------------------------------------------------------------------------- |
ff4aedc5 RN |
2700 | |
2701 | //in source file that contains stuff you don't directly use | |
2702 | #include <wx/html/forcelnk.h> | |
2703 | FORCE_LINK_ME(basewxmediabackends); | |
2704 | ||
2705 | //--------------------------------------------------------------------------- | |
2706 | // End wxMediaCtrl Compilation Guard and this file | |
2707 | //--------------------------------------------------------------------------- | |
72259e00 RL |
2708 | #endif //wxUSE_MEDIACTRL |
2709 | ||
ff4aedc5 | 2710 |