1 /////////////////////////////////////////////////////////////////////////////
2 // Name: msw/mediactrl.cpp
3 // Purpose: Built-in Media Backends for Windows
4 // Author: Ryan Norton <wxprojects@comcast.net>
8 // Copyright: (c) Ryan Norton
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 //===========================================================================
14 //===========================================================================
16 //---------------------------------------------------------------------------
17 // Pre-compiled header stuff
18 //---------------------------------------------------------------------------
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "mediactrl.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
31 //---------------------------------------------------------------------------
33 //---------------------------------------------------------------------------
34 #include "wx/mediactrl.h"
36 //---------------------------------------------------------------------------
38 //---------------------------------------------------------------------------
41 //---------------------------------------------------------------------------
42 // Externals (somewhere in src/msw/app.cpp)
43 //---------------------------------------------------------------------------
44 extern "C" WXDLLIMPEXP_BASE HINSTANCE
wxGetInstance(void);
46 extern WXDLLIMPEXP_CORE wxChar
*wxCanvasClassName
;
48 extern WXDLLIMPEXP_CORE
const wxChar
*wxCanvasClassName
;
51 //===========================================================================
52 // BACKEND DECLARATIONS
53 //===========================================================================
55 //---------------------------------------------------------------------------
59 //---------------------------------------------------------------------------
61 //####################THE BIG DIRECTSHOW OVERVIEW############################
64 // OK... this deserves its own little tutorial. Knowledge of COM and class
65 // factories is assumed throughout this code.
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.
70 // There are many, many ways to do this.
72 // WAYS TO RENDER A FILE (URLS WORK IN DS ALSO)
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
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.
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.
91 // The current way is to use windowless rendering and have directshow
92 // do all the DirectDraw-style clipping to our window
94 // ~~~~~~~~~~~~~~AFTER RENDERING THE FILE~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
96 // When done rendering the file, we need to get several interfaces from
97 // either a IMediaControl or IGraphBuilder instance -
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
103 // IBasicAudio - we need this for setting/getting the volume
105 // Interfaces that we don't use but might be useful one day -
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.
111 // ~~~~~~~~~~~~~~STOPPING~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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
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
122 //---------------------------------------------------------------------------
124 //---------------------------------------------------------------------------
126 //---------------------------------------------------------------------------
127 #include "wx/msw/ole/oleutils.h" //wxBasicString, IID etc.
128 #include "wx/msw/ole/uuid.h" //IID etc..
130 //---------------------------------------------------------------------------
131 // COM compatability definitions
132 //---------------------------------------------------------------------------
133 #ifndef STDMETHODCALLTYPE
134 #define STDMETHODCALLTYPE __stdcall
137 #define STDMETHOD(funcname) virtual HRESULT STDMETHODCALLTYPE funcname
142 //---------------------------------------------------------------------------
143 // IIDS - used by CoCreateInstance and IUnknown::QueryInterface
144 // Dumped from amstream.idl, quartz.idl, direct draw and with some
145 // confirmation from WINE
147 // Some of these are not used but are kept here for future reference anyway
148 //---------------------------------------------------------------------------
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}};
168 const CLSID CLSID_FilgraphManager
= {0xE436EBB3,0x524F,0x11CE,{0x9F,0x53,0x00,0x20,0xAF,0x0B,0xA7,0x70}};
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}};
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}};
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}};
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
;};
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
;
218 DWORD dwBackBufferCount
;
222 DWORD dwZBufferBitDepth
;
225 DWORD dwAlphaBitDepth
;
228 DDCOLORKEY ddckCKDestOverlay
;
229 DDCOLORKEY ddckCKDestBlt
;
230 DDCOLORKEY ddckCKSrcOverlay
;
231 DDCOLORKEY ddckCKSrcBlt
;
232 DDPIXELFORMAT ddpfPixelFormat
;
233 struct DDSCAPS
{DWORD dwCaps
;} ddsCaps
;
236 struct IDirectDrawClipper
: public IUnknown
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
;
246 struct IDirectDrawSurface
: public IUnknown
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
;
284 struct IDirectDraw
: public IUnknown
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
;
308 //---------------------------------------------------------------------------
309 // AMMEDIA COM INTERFACES
310 //---------------------------------------------------------------------------
312 struct IMultiMediaStream
;
313 struct IStreamSample
: public IUnknown
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
;
323 struct IDirectDrawStreamSample
: public IStreamSample
326 STDMETHOD(GetSurface
)(IDirectDrawSurface
**, RECT
*) PURE
;
327 STDMETHOD(SetRect
)(const RECT
*) PURE
;
330 struct IMediaStream
: public IUnknown
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
;
341 struct IDirectDrawMediaStream
: public IMediaStream
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
;
353 struct IMultiMediaStream
: public IUnknown
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
;
366 struct IAMMultiMediaStream
: public IMultiMediaStream
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
;
378 //---------------------------------------------------------------------------
379 // QUARTZ COM INTERFACES (dumped from quartz.idl from MSVC COM Browser)
380 //---------------------------------------------------------------------------
381 struct IAMCollection
: public IDispatch
383 STDMETHOD(get_Count
)(long *) PURE
;
384 STDMETHOD(Item
)(long, IUnknown
**) PURE
;
385 STDMETHOD(get__NewEnum
)(IUnknown
**) PURE
;
388 struct IMediaControl
: public IDispatch
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
;
401 struct IMediaEvent
: public IDispatch
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
;
411 struct IMediaEventEx
: public IMediaEvent
413 STDMETHOD(SetNotifyWindow
)(LONG_PTR
, long, LONG_PTR
) PURE
;
414 STDMETHOD(SetNotifyFlags
)(long) PURE
;
415 STDMETHOD(GetNotifyFlags
)(long *) PURE
;
418 struct IMediaPosition
: public IDispatch
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
;
433 struct IBasicAudio
: public IDispatch
435 STDMETHOD(put_Volume
)(long) PURE
;
436 STDMETHOD(get_Volume
)(long *) PURE
;
437 STDMETHOD(put_Balance
)(long) PURE
;
438 STDMETHOD(get_Balance
)(long *) PURE
;
441 //---------------------------------------------------------------------------
442 // MISC COM INTERFACES
443 //---------------------------------------------------------------------------
444 struct IVMRWindowlessControl
: public IUnknown
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
;
463 typedef IUnknown IVMRImageCompositor
;
465 struct IVMRFilterConfig
: public IUnknown
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
;
476 typedef IUnknown IBaseFilter
;
477 typedef IUnknown IPin
;
478 typedef IUnknown IEnumFilters
;
479 typedef int AM_MEDIA_TYPE
;
481 struct IFilterGraph
: public IUnknown
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
;
493 struct IGraphBuilder
: public IFilterGraph
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
;
505 //------------------------------------------------------------------
506 // wxAMMediaBackend (Active Movie)
507 //------------------------------------------------------------------
508 class WXDLLIMPEXP_MEDIA wxAMMediaThread
: public wxThread
511 virtual ExitCode
Entry();
513 class wxAMMediaBackend
* pThis
;
516 //cludgy workaround for wx events. slots would be nice :)
517 class WXDLLIMPEXP_MEDIA wxAMMediaEvtHandler
: public wxEvtHandler
520 void OnPaint(wxPaintEvent
&);
521 void OnMove(wxMoveEvent
&);
522 void OnSize(wxSizeEvent
&);
523 void OnEraseBackground(wxEraseEvent
&);
526 typedef BOOL (WINAPI
* LPAMGETERRORTEXT
)(HRESULT
, wxChar
*, DWORD
);
528 class WXDLLIMPEXP_MEDIA wxAMMediaBackend
: public wxMediaBackend
533 virtual ~wxAMMediaBackend();
535 virtual bool CreateControl(wxControl
* ctrl
, wxWindow
* parent
,
540 const wxValidator
& validator
,
541 const wxString
& name
);
544 virtual bool Pause();
547 virtual bool Load(const wxString
& fileName
);
548 virtual bool Load(const wxURI
& location
);
550 virtual wxMediaState
GetState();
552 virtual bool SetPosition(wxLongLong where
);
553 virtual wxLongLong
GetPosition();
554 virtual wxLongLong
GetDuration();
556 virtual void Move(int x
, int y
, int w
, int h
);
557 wxSize
GetVideoSize() const;
559 virtual double GetPlaybackRate();
560 virtual bool SetPlaybackRate(double);
562 virtual double GetVolume();
563 virtual bool SetVolume(double);
567 bool SetWindowlessMode(IGraphBuilder
* pGB
,
568 IVMRWindowlessControl
** ppVMC
= NULL
);
572 wxMediaState m_state
;
573 wxCriticalSection m_rendercs
;
575 IVMRWindowlessControl
* m_pVMC
;
576 IGraphBuilder
* m_pGB
;
578 IMediaControl
* m_pMC
;
580 IMediaPosition
* m_pMS
;
582 wxAMMediaThread
* m_pThread
;
587 HMODULE m_hQuartzDll
;
588 LPAMGETERRORTEXT m_lpAMGetErrorText
;
591 friend class wxAMMediaThread
;
592 friend class wxAMMediaEvtHandler
;
594 DECLARE_DYNAMIC_CLASS(wxAMMediaBackend
)
597 //---------------------------------------------------------------------------
601 //---------------------------------------------------------------------------
603 //---------------------------------------------------------------------------
605 //---------------------------------------------------------------------------
606 #include <mmsystem.h>
608 class WXDLLIMPEXP_MEDIA wxMCIMediaBackend
: public wxMediaBackend
613 ~wxMCIMediaBackend();
615 virtual bool CreateControl(wxControl
* ctrl
, wxWindow
* parent
,
620 const wxValidator
& validator
,
621 const wxString
& name
);
624 virtual bool Pause();
627 virtual bool Load(const wxString
& fileName
);
628 virtual bool Load(const wxURI
& location
);
630 virtual wxMediaState
GetState();
632 virtual bool SetPosition(wxLongLong where
);
633 virtual wxLongLong
GetPosition();
634 virtual wxLongLong
GetDuration();
636 virtual void Move(int x
, int y
, int w
, int h
);
637 wxSize
GetVideoSize() const;
639 virtual double GetPlaybackRate();
640 virtual bool SetPlaybackRate(double dRate
);
642 virtual double GetVolume();
643 virtual bool SetVolume(double);
645 static LRESULT CALLBACK
NotifyWndProc(HWND hWnd
, UINT nMsg
,
646 WPARAM wParam
, LPARAM lParam
);
648 LRESULT CALLBACK
OnNotifyWndProc(HWND hWnd
, UINT nMsg
,
649 WPARAM wParam
, LPARAM lParam
);
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
656 DECLARE_DYNAMIC_CLASS(wxMCIMediaBackend
)
659 //---------------------------------------------------------------------------
663 //---------------------------------------------------------------------------
665 //---------------------------------------------------------------------------
667 //---------------------------------------------------------------------------
668 //#include <qtml.h> //Windoze QT include
669 //#include <QuickTimeComponents.h> //Standard QT stuff
670 #include "wx/dynlib.h"
672 //---------------------------------------------------------------------------
674 //---------------------------------------------------------------------------
675 typedef struct MovieRecord
* Movie
;
676 typedef wxInt16 OSErr
;
677 typedef wxInt32 OSStatus
;
680 typedef unsigned char Str255
[256];
681 #define StringPtr unsigned char*
682 #define newMovieActive 1
686 #define OSType unsigned long
687 #define CGrafPtr struct GrafPort *
688 #define TimeScale long
689 #define TimeBase struct TimeBaseRecord *
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;
697 const OSType URLDataHandlerSubType
= 'url ';
698 const OSType VisualMediaCharacteristic
= 'eyes';
705 Str255 name
; /*Str63 on mac, Str255 on msw */
721 wide value
; /* units */
722 TimeScale scale
; /* units per second */
726 //---------------------------------------------------------------------------
728 //---------------------------------------------------------------------------
729 #define wxDL_METHOD_DEFINE( rettype, name, args, shortargs, defret ) \
730 typedef rettype (* name ## Type) args ; \
731 name ## Type pfn_ ## name; \
733 { if (m_ok) return pfn_ ## name shortargs ; return defret; }
735 #define wxDL_VOIDMETHOD_DEFINE( name, args, shortargs ) \
736 typedef void (* name ## Type) args ; \
737 name ## Type pfn_ ## name; \
739 { if (m_ok) pfn_ ## name shortargs ; }
741 #define wxDL_METHOD_LOAD( lib, name, success ) \
742 pfn_ ## name = (name ## Type) lib.GetSymbol( wxT(#name), &success ); \
743 if (!success) return false;
745 //Class that utilizes Robert Roeblings Dynamic Library Macros
746 class WXDLLIMPEXP_MEDIA wxQuickTimeLibrary
749 ~wxQuickTimeLibrary()
756 bool IsOk() const {return m_ok
;}
759 wxDynamicLibrary m_dll
;
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
, (), () );
773 wxDL_METHOD_DEFINE( OSErr
, NativePathNameToFSSpec
,
774 (char* inName
, FSSpec
* outFile
, long flags
),
775 (inName
, outFile
, flags
), -1);
777 wxDL_METHOD_DEFINE( OSErr
, OpenMovieFile
,
778 (const FSSpec
* fileSpec
, short * resRefNum
, wxInt8 permission
),
779 (fileSpec
, resRefNum
, permission
), -1 );
781 wxDL_METHOD_DEFINE( OSErr
, CloseMovieFile
,
782 (short resRefNum
), (resRefNum
), -1);
784 wxDL_METHOD_DEFINE( OSErr
, NewMovieFromFile
,
785 (Movie
* theMovie
, short resRefNum
, short * resId
,
786 StringPtr resName
, short newMovieFlags
,
787 bool * dataRefWasChanged
),
788 (theMovie
, resRefNum
, resId
, resName
, newMovieFlags
,
789 dataRefWasChanged
), -1);
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
) );
794 wxDL_VOIDMETHOD_DEFINE( BlockMove
,
795 (const char* p1
, const char* p2
, long s
), (p1
,p2
,s
) );
796 wxDL_METHOD_DEFINE( Handle
, NewHandleClear
, (long s
), (s
), NULL
);
798 wxDL_METHOD_DEFINE( OSErr
, NewMovieFromDataRef
,
799 (Movie
* m
, short flags
, short * id
,
800 Handle dataRef
, OSType dataRefType
),
801 (m
,flags
,id
,dataRef
,dataRefType
), -1 );
803 wxDL_VOIDMETHOD_DEFINE( DisposeHandle
, (Handle h
), (h
) );
804 wxDL_VOIDMETHOD_DEFINE( GetMovieNaturalBoundsRect
, (Movie m
, Rect
* r
), (m
,r
) );
805 wxDL_METHOD_DEFINE( void*, GetMovieIndTrackType
,
806 (Movie m
, long index
, OSType type
, long flags
),
807 (m
,index
,type
,flags
), NULL
);
808 wxDL_VOIDMETHOD_DEFINE( CreatePortAssociation
,
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
) );
821 wxDL_METHOD_DEFINE(short, GetMovieVolume
, (Movie m
), (m
), 0);
822 wxDL_VOIDMETHOD_DEFINE(SetMovieVolume
, (Movie m
, short sVolume
), (m
,sVolume
) );
825 bool wxQuickTimeLibrary::Initialize()
829 if(!m_dll
.Load(wxT("qtmlClient.dll")))
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
);
867 wxDL_METHOD_LOAD( m_dll
, GetMovieVolume
, bOk
);
868 wxDL_METHOD_LOAD( m_dll
, SetMovieVolume
, bOk
);
875 class WXDLLIMPEXP_MEDIA wxQTMediaBackend
: public wxMediaBackend
881 virtual bool CreateControl(wxControl
* ctrl
, wxWindow
* parent
,
886 const wxValidator
& validator
,
887 const wxString
& name
);
890 virtual bool Pause();
893 virtual bool Load(const wxString
& fileName
);
894 virtual bool Load(const wxURI
& location
);
896 virtual wxMediaState
GetState();
898 virtual bool SetPosition(wxLongLong where
);
899 virtual wxLongLong
GetPosition();
900 virtual wxLongLong
GetDuration();
902 virtual void Move(int x
, int y
, int w
, int h
);
903 wxSize
GetVideoSize() const;
905 virtual double GetPlaybackRate();
906 virtual bool SetPlaybackRate(double dRate
);
908 virtual double GetVolume();
909 virtual bool SetVolume(double);
914 wxSize m_bestSize
; //Original movie size
915 Movie m_movie
; //QT Movie handle/instance
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
919 wxQuickTimeLibrary m_lib
;
921 DECLARE_DYNAMIC_CLASS(wxQTMediaBackend
)
925 //===========================================================================
927 //===========================================================================
929 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
933 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
935 IMPLEMENT_DYNAMIC_CLASS(wxAMMediaBackend
, wxMediaBackend
);
937 //---------------------------------------------------------------------------
938 // Usual debugging macros
939 //---------------------------------------------------------------------------
941 #include "wx/msgdlg.h"
942 #define MAX_ERROR_TEXT_LEN 160
944 // FIXME : Just use wxASSERT_MSG here instead of msgdlg - but
945 // stackwalker still crashes win2k, so do msgdlg for now...
947 #define wxAMVERIFY(x) \
949 HRESULT hrdsv = (x); \
950 if ( FAILED(hrdsv) ) \
952 wxChar szError[MAX_ERROR_TEXT_LEN]; \
953 if( m_lpAMGetErrorText != NULL && \
954 (*m_lpAMGetErrorText)(hrdsv, szError, MAX_ERROR_TEXT_LEN) == 0) \
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__) ); \
965 wxMessageBox( wxString::Format(wxT("Unknown error (%i) ") \
967 wxT(" line %i in mediactrl.cpp."), \
968 (int)hrdsv, __LINE__) ); \
973 #define wxVERIFY(x) wxASSERT((x))
975 #define wxAMVERIFY(x) (x)
976 #define wxVERIFY(x) (x)
979 //---------------------------------------------------------------------------
980 // Standard macros for ease of use
981 //---------------------------------------------------------------------------
982 #define SAFE_RELEASE(x) { if (x) x->Release(); x = NULL; }
984 //---------------------------------------------------------------------------
985 // wxAMMediaBackend Constructor
987 // Sets m_hNotifyWnd to NULL to signify that we haven't loaded anything yet
988 //---------------------------------------------------------------------------
989 wxAMMediaBackend::wxAMMediaBackend() : m_state(wxMEDIASTATE_STOPPED
),
997 //---------------------------------------------------------------------------
998 // wxAMMediaBackend Destructor
1000 // Cleans up everything
1001 //---------------------------------------------------------------------------
1002 wxAMMediaBackend::~wxAMMediaBackend()
1008 ::FreeLibrary(m_hQuartzDll
);
1012 //---------------------------------------------------------------------------
1013 // wxAMMediaBackend::CreateControl
1015 // 1) Check to see if Active Movie supports windowless controls
1016 // 2) Connect events to the media control and its TLW
1017 //---------------------------------------------------------------------------
1018 bool wxAMMediaBackend::CreateControl(wxControl
* ctrl
, wxWindow
* parent
,
1023 const wxValidator
& validator
,
1024 const wxString
& name
)
1027 m_hQuartzDll
= ::LoadLibrary(wxT("quartz.dll"));
1030 m_lpAMGetErrorText
= (LPAMGETERRORTEXT
) ::GetProcAddress(
1032 wxString::Format(wxT("AMGetErrorText%s"),
1034 #ifdef __WXUNICODE__
1042 ).mb_str(wxConvLocal
)
1048 //Make sure a valid windowless video mixing interface exists
1050 if( CoCreateInstance(CLSID_FilgraphManager
, NULL
,
1051 CLSCTX_INPROC_SERVER
,
1052 IID_IGraphBuilder
, (void**)&pGB
) != 0 )
1055 if( !SetWindowlessMode(pGB
) )
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
1066 // is a child window, it refreshes properly
1068 if ( !ctrl
->wxControl::Create(parent
, id
, pos
, size
,
1069 (style
& ~wxBORDER_MASK
) | wxBORDER_NONE
| wxCLIP_CHILDREN
,
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);
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
1091 wxWindow
* pTheTLW
= m_ctrl
->GetParent();
1092 while( pTheTLW
->GetParent() )
1093 pTheTLW
= pTheTLW
->GetParent();
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!
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);
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);
1121 //---------------------------------------------------------------------------
1122 // wxAMMediaBackend::SetWindowlessMode
1124 // Adds a Video Mixing Renderer to a Filter Graph and obtains the
1125 // windowless control from it
1126 //---------------------------------------------------------------------------
1127 bool wxAMMediaBackend::SetWindowlessMode(IGraphBuilder
* pGB
,
1128 IVMRWindowlessControl
** ppVMC
)
1131 // Create and add a custom Video Mixing Render to the graph
1134 if( CoCreateInstance(CLSID_VideoMixingRenderer
, NULL
, CLSCTX_INPROC_SERVER
,
1135 IID_IBaseFilter
, (void**)&pVMR
) != 0 )
1138 if ( pGB
->AddFilter(pVMR
, L
"Video Mixing Renderer") != 0)
1145 // Set the graph to windowless mode
1147 IVMRFilterConfig
* pConfig
;
1148 if( pVMR
->QueryInterface(IID_IVMRFilterConfig
, (void**)&pConfig
) != 0 )
1154 if( pConfig
->SetRenderingMode(2) != 0) //2 == VMRMode_Windowless
1164 // Obtain the windowless control
1166 IVMRWindowlessControl
* pVMC
;
1167 if( pVMR
->QueryInterface(IID_IVMRWindowlessControl
, (void**)&pVMC
) != 0 )
1185 //---------------------------------------------------------------------------
1186 // wxAMMediaBackend::Load (file version)
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
)
1199 //if previously loaded cleanup
1203 //Create interfaces - we already checked for success in CreateControl
1204 CoCreateInstance(CLSID_FilgraphManager
, NULL
, CLSCTX_INPROC_SERVER
,
1205 IID_IGraphBuilder
, (void**)&m_pGB
);
1208 // Set and clip output
1209 SetWindowlessMode(m_pGB
, &m_pVMC
);
1210 if( m_pVMC
->SetVideoClippingWindow((HWND
)m_ctrl
->GetHandle()) != 0 )
1212 m_bestSize
.x
= m_bestSize
.y
= 0;
1216 //load the graph & render
1217 if( m_pGB
->RenderFile(fileName
.wc_str(wxConvLocal
), NULL
) != 0 )
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
) );
1226 // Get original video size
1227 if( m_pVMC
->GetNativeVideoSize((LONG
*)&m_bestSize
.x
, (LONG
*)&m_bestSize
.y
,
1230 m_bestSize
.x
= m_bestSize
.y
= 0;
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
1239 m_ctrl
->InvalidateBestSize();
1240 m_ctrl
->GetParent()->Layout();
1241 m_ctrl
->GetParent()->Refresh();
1242 m_ctrl
->GetParent()->Update();
1243 m_ctrl
->SetSize(m_ctrl
->GetSize());
1245 m_pThread
= new wxAMMediaThread
;
1246 m_pThread
->pThis
= this;
1247 m_pThread
->Create();
1253 //---------------------------------------------------------------------------
1254 // wxAMMediaBackend::Load (URL Version)
1256 // Loads media from a URL. Interestingly enough DirectShow
1257 // appears (?) to escape the URL for us, at least on normal
1259 //---------------------------------------------------------------------------
1260 bool wxAMMediaBackend::Load(const wxURI
& location
)
1262 return Load(location
.BuildUnescapedURI());
1265 //---------------------------------------------------------------------------
1266 // wxAMMediaBackend::Play
1268 // Plays the stream. If it is non-seekable, it will restart it (implicit).
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
1272 //---------------------------------------------------------------------------
1273 bool wxAMMediaBackend::Play()
1275 wxCriticalSectionLocker
lock(m_rendercs
);
1277 if( SUCCEEDED(m_pMC
->Run()) )
1279 m_state
= wxMEDIASTATE_PLAYING
;
1280 m_ctrl
->Refresh(); //videoless control finicky about refreshing
1287 //---------------------------------------------------------------------------
1288 // wxAMMediaBackend::Pause
1290 // Pauses the stream.
1291 //---------------------------------------------------------------------------
1292 bool wxAMMediaBackend::Pause()
1294 wxCriticalSectionLocker
lock(m_rendercs
);
1296 if( SUCCEEDED(m_pMC
->Pause()) )
1298 m_state
= wxMEDIASTATE_PAUSED
;
1305 //---------------------------------------------------------------------------
1306 // wxAMMediaBackend::Stop
1308 // Stops the stream.
1309 //---------------------------------------------------------------------------
1310 bool wxAMMediaBackend::Stop()
1312 wxCriticalSectionLocker
lock(m_rendercs
);
1314 if( SUCCEEDED(m_pMC
->Stop()) )
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
1319 wxAMMediaBackend::SetPosition(0);
1321 m_state
= wxMEDIASTATE_STOPPED
;
1328 //---------------------------------------------------------------------------
1329 // wxAMMediaBackend::SetPosition
1331 // 1) Translates the current position's time to directshow time,
1332 // which is in a scale of 1 second (in a double)
1333 // 2) Sets the play position of the IMediaSeeking interface -
1334 // passing NULL as the stop position means to keep the old
1336 //---------------------------------------------------------------------------
1337 bool wxAMMediaBackend::SetPosition(wxLongLong where
)
1339 return SUCCEEDED( m_pMS
->put_CurrentPosition(
1340 ((LONGLONG
)where
.GetValue()) / 1000.0
1344 //---------------------------------------------------------------------------
1345 // wxAMMediaBackend::GetPosition
1347 // 1) Obtains the current play and stop positions from IMediaSeeking
1348 // 2) Returns the play position translated to our time base
1349 //---------------------------------------------------------------------------
1350 wxLongLong
wxAMMediaBackend::GetPosition()
1353 wxAMVERIFY( m_pMS
->get_CurrentPosition(&outCur
) );
1355 //h,m,s,milli - outdur is in 1 second (double)
1363 //---------------------------------------------------------------------------
1364 // wxAMMediaBackend::SetVolume
1366 // Sets the volume through the IBasicAudio interface -
1367 // value ranges from 0 (MAX volume) to -10000 (minimum volume).
1368 // -100 per decibel.
1369 //---------------------------------------------------------------------------
1370 bool wxAMMediaBackend::SetVolume(double dVolume
)
1372 return SUCCEEDED(m_pBA
->put_Volume( (long) ((dVolume
-1.0) * 10000.0) ) );
1375 //---------------------------------------------------------------------------
1376 // wxAMMediaBackend::GetVolume
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()
1385 if ( SUCCEEDED( m_pBA
->get_Volume(&lVolume
) ) )
1386 return (((double)(lVolume
+ 10000)) / 10000.0);
1390 //---------------------------------------------------------------------------
1391 // wxAMMediaBackend::GetDuration
1393 // 1) Obtains the duration of the media from IAMMultiMediaStream
1394 // 2) Converts that value to our time base, and returns it
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
1399 //---------------------------------------------------------------------------
1400 wxLongLong
wxAMMediaBackend::GetDuration()
1403 wxAMVERIFY( m_pMS
->get_Duration(&outDuration
) );
1405 //h,m,s,milli - outdur is in 1 second (double)
1406 outDuration
*= 1000;
1408 ll
.Assign(outDuration
);
1413 //---------------------------------------------------------------------------
1414 // wxAMMediaBackend::GetState
1416 // Returns the cached state
1417 //---------------------------------------------------------------------------
1418 wxMediaState
wxAMMediaBackend::GetState()
1423 //---------------------------------------------------------------------------
1424 // wxAMMediaBackend::GetPlaybackRate
1426 // Pretty simple way of obtaining the playback rate from
1427 // the IMediaSeeking interface
1428 //---------------------------------------------------------------------------
1429 double wxAMMediaBackend::GetPlaybackRate()
1432 wxAMVERIFY( m_pMS
->get_Rate(&dRate
) );
1436 //---------------------------------------------------------------------------
1437 // wxAMMediaBackend::SetPlaybackRate
1439 // Sets the playback rate of the media - DirectShow is pretty good
1440 // about this, actually
1441 //---------------------------------------------------------------------------
1442 bool wxAMMediaBackend::SetPlaybackRate(double dRate
)
1444 return m_pMS
->put_Rate(dRate
) == 0;
1447 //---------------------------------------------------------------------------
1448 // wxAMMediaBackend::Cleanup
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?
1453 //---------------------------------------------------------------------------
1454 void wxAMMediaBackend::Cleanup()
1456 m_pThread
->Delete();
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
);
1469 //---------------------------------------------------------------------------
1470 // wxAMMediaBackend::GetVideoSize
1472 // Obtains the cached original video size
1473 //---------------------------------------------------------------------------
1474 wxSize
wxAMMediaBackend::GetVideoSize() const
1479 //---------------------------------------------------------------------------
1480 // wxAMMediaBackend::Move
1482 // We take care of this in our redrawing
1483 //---------------------------------------------------------------------------
1484 void wxAMMediaBackend::Move(int WXUNUSED(x
), int WXUNUSED(y
),
1489 RECT srcRect
, destRect
;
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
;
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
;
1499 //set the windowless control positions
1500 if( m_pVMC
->SetVideoPosition(&srcRect
, &destRect
) != 0 )
1502 wxASSERT_MSG(false, wxT("Could not set video position!"));
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(),
1514 ::ReleaseDC((HWND)m_ctrl->GetHandle(), hdc);
1519 //---------------------------------------------------------------------------
1520 // wxAMMediaEvtHandler::OnMove
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
)
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
);
1534 void wxAMMediaEvtHandler::OnSize(wxSizeEvent
& evt
)
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
);
1544 //---------------------------------------------------------------------------
1545 // wxAMMediaThread::Entry
1547 // Render the current movie frame
1548 //---------------------------------------------------------------------------
1549 wxThread::ExitCode
wxAMMediaThread::Entry()
1551 while(!TestDestroy())
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
1562 while( pThis
->m_pME
->GetEvent(&evCode
, (LONG_PTR
*) &evParam1
,
1563 (LONG_PTR
*) &evParam2
, 0) == 0 )
1565 // Cleanup memory that GetEvent allocated
1566 if( pThis
->m_pME
->FreeEventParams(evCode
, evParam1
, evParam2
) != 0 )
1571 // If this is the end of the clip, notify handler
1572 if(1 == evCode
) //EC_COMPLETE
1585 //---------------------------------------------------------------------------
1586 // wxAMMediaBackend::OnStop
1588 // Handle stopping when the stream ends
1589 //---------------------------------------------------------------------------
1590 void wxAMMediaBackend::OnStop()
1592 //send the event to our child
1593 wxMediaEvent
theEvent(wxEVT_MEDIA_STOP
, m_ctrl
->GetId());
1594 m_ctrl
->ProcessEvent(theEvent
);
1596 //if the user didn't veto it, stop the stream
1597 if (theEvent
.IsAllowed())
1599 //Interestingly enough, DirectShow does not actually stop
1600 //the filters - even when it reaches the end!
1603 //send the event to our child
1604 wxMediaEvent
theEvent(wxEVT_MEDIA_FINISHED
,
1606 m_ctrl
->ProcessEvent(theEvent
);
1610 //---------------------------------------------------------------------------
1611 // wxAMMediaEvtHandler::OnEraseBackground
1613 // Tell WX not to erase the background of our control window
1614 //---------------------------------------------------------------------------
1615 void wxAMMediaEvtHandler::OnEraseBackground(wxEraseEvent
& evt
)
1617 wxAMMediaBackend
* pThis
= (wxAMMediaBackend
*) this;
1620 //TODO: Use wxClientDC?
1621 HDC hdc
= ::GetDC((HWND
)pThis
->m_ctrl
->GetHandle());
1622 if( pThis
->m_pVMC
->RepaintVideo((HWND
)pThis
->m_ctrl
->GetHandle(),
1627 ::ReleaseDC((HWND
)pThis
->m_ctrl
->GetHandle(), hdc
);
1633 //---------------------------------------------------------------------------
1634 // wxAMMediaEvtHandler::OnPaint
1637 //---------------------------------------------------------------------------
1638 void wxAMMediaEvtHandler::OnPaint(wxPaintEvent
& WXUNUSED(evt
))
1640 wxAMMediaBackend
* pThis
= (wxAMMediaBackend
*) this;
1641 wxPaintDC
dc(pThis
->m_ctrl
);
1642 if( pThis
->m_pVMC
->RepaintVideo((HWND
)pThis
->m_ctrl
->GetHandle(),
1643 (HDC
)dc
.GetHDC()) != 0 )
1649 //---------------------------------------------------------------------------
1650 // End of wxAMMediaBackend
1651 //---------------------------------------------------------------------------
1653 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1655 // wxMCIMediaBackend
1657 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1659 IMPLEMENT_DYNAMIC_CLASS(wxMCIMediaBackend
, wxMediaBackend
);
1661 //---------------------------------------------------------------------------
1662 // Usual debugging macros for MCI returns
1663 //---------------------------------------------------------------------------
1666 #define wxMCIVERIFY(arg) \
1669 if ( (nRet = (arg)) != 0) \
1672 mciGetErrorString(nRet, sz, 5000); \
1673 wxFAIL_MSG(wxString::Format(_T("MCI Error:%s"), sz)); \
1677 #define wxMCIVERIFY(arg) (arg);
1680 //---------------------------------------------------------------------------
1681 // Simulation for <digitalv.h>
1683 // Mingw and possibly other compilers don't have the digitalv.h header
1684 // that is needed to have some essential features of mci work with
1685 // windows - so we provide the declarations for the types we use here
1686 //---------------------------------------------------------------------------
1689 DWORD_PTR dwCallback
;
1690 #ifdef MCI_USE_OFFEXT
1696 } MCI_DGV_RECT_PARMS
;
1699 DWORD_PTR dwCallback
;
1709 } MCI_DGV_WINDOW_PARMS
;
1712 DWORD_PTR dwCallback
;
1717 } MCI_DGV_SET_PARMS
;
1720 DWORD_PTR dwCallback
;
1724 wxChar
* lpstrAlgorithm
;
1725 wxChar
* lpstrQuality
;
1726 } MCI_DGV_SETAUDIO_PARMS
;
1728 //---------------------------------------------------------------------------
1729 // wxMCIMediaBackend Constructor
1731 // Here we don't need to do much except say we don't have any video :)
1732 //---------------------------------------------------------------------------
1733 wxMCIMediaBackend::wxMCIMediaBackend() : m_hNotifyWnd(NULL
), m_bVideo(false)
1737 //---------------------------------------------------------------------------
1738 // wxMCIMediaBackend Destructor
1740 // We close the mci device - note that there may not be an mci device here,
1741 // or it may fail - but we don't really care, since we're destructing
1742 //---------------------------------------------------------------------------
1743 wxMCIMediaBackend::~wxMCIMediaBackend()
1747 mciSendCommand(m_hDev
, MCI_CLOSE
, 0, 0);
1748 DestroyWindow(m_hNotifyWnd
);
1749 m_hNotifyWnd
= NULL
;
1753 //---------------------------------------------------------------------------
1754 // wxMCIMediaBackend::Create
1756 // Here we just tell wxMediaCtrl that mci does exist (which it does, on all
1757 // msw systems, at least in some form dating back to win16 days)
1758 //---------------------------------------------------------------------------
1759 bool wxMCIMediaBackend::CreateControl(wxControl
* ctrl
, wxWindow
* parent
,
1764 const wxValidator
& validator
,
1765 const wxString
& name
)
1769 // By default wxWindow(s) is created with a border -
1770 // so we need to get rid of those, and create with
1771 // wxCLIP_CHILDREN, so that if the driver/backend
1772 // is a child window, it refereshes properly
1774 if ( !ctrl
->wxControl::Create(parent
, id
, pos
, size
,
1775 (style
& ~wxBORDER_MASK
) | wxBORDER_NONE
| wxCLIP_CHILDREN
,
1783 //---------------------------------------------------------------------------
1784 // wxMCIMediaBackend::Load (file version)
1786 // Here we have MCI load a file and device, set the time format to our
1787 // default (milliseconds), and set the video (if any) to play in the control
1788 //---------------------------------------------------------------------------
1789 bool wxMCIMediaBackend::Load(const wxString
& fileName
)
1792 //if the user already called load close the previous MCI device
1796 mciSendCommand(m_hDev
, MCI_CLOSE
, 0, 0);
1797 DestroyWindow(m_hNotifyWnd
);
1798 m_hNotifyWnd
= NULL
;
1802 //Opens a file and has MCI select a device. Normally you'd put
1803 //MCI_OPEN_TYPE in addition to MCI_OPEN_ELEMENT - however if you
1804 //omit this it tells MCI to select the device instead. This is
1805 //good because we have no reliable way of "enumerating" the devices
1808 MCI_OPEN_PARMS openParms
;
1809 openParms
.lpstrElementName
= (wxChar
*) fileName
.c_str();
1811 if ( mciSendCommand(0, MCI_OPEN
, MCI_OPEN_ELEMENT
,
1812 (DWORD
)(LPVOID
)&openParms
) != 0)
1815 m_hDev
= openParms
.wDeviceID
;
1818 //Now set the time format for the device to milliseconds
1820 MCI_SET_PARMS setParms
;
1821 setParms
.dwCallback
= 0;
1822 setParms
.dwTimeFormat
= MCI_FORMAT_MILLISECONDS
;
1824 if (mciSendCommand(m_hDev
, MCI_SET
, MCI_SET_TIME_FORMAT
,
1825 (DWORD
)(LPVOID
)&setParms
) != 0)
1829 //Now tell the MCI device to display the video in our wxMediaCtrl
1831 MCI_DGV_WINDOW_PARMS windowParms
;
1832 windowParms
.hWnd
= (HWND
)m_ctrl
->GetHandle();
1834 m_bVideo
= (mciSendCommand(m_hDev
, MCI_WINDOW
,
1835 0x00010000L
, //MCI_DGV_WINDOW_HWND
1836 (DWORD
)(LPVOID
)&windowParms
) == 0);
1839 // Create a hidden window and register to handle
1841 // Note that wxCanvasClassName is already registered
1842 // and used by all wxWindows and normal wxControls
1844 m_hNotifyWnd
= ::CreateWindow
1858 wxLogSysError( wxT("Could not create hidden needed for ")
1859 wxT("registering for DirectShow events!") );
1864 wxSetWindowProc(m_hNotifyWnd
, wxMCIMediaBackend::NotifyWndProc
);
1866 ::SetWindowLong(m_hNotifyWnd
, GWL_USERDATA
,
1870 //Here, if the parent of the control has a sizer - we
1871 //tell it to recalculate the size of this control since
1872 //the user opened a separate media file
1874 m_ctrl
->InvalidateBestSize();
1875 m_ctrl
->GetParent()->Layout();
1876 m_ctrl
->GetParent()->Refresh();
1877 m_ctrl
->GetParent()->Update();
1878 m_ctrl
->SetSize(m_ctrl
->GetSize());
1883 //---------------------------------------------------------------------------
1884 // wxMCIMediaBackend::Load (URL version)
1886 // MCI doesn't support URLs directly (?)
1888 // TODO: Use wxURL/wxFileSystem and mmioInstallProc
1889 //---------------------------------------------------------------------------
1890 bool wxMCIMediaBackend::Load(const wxURI
& WXUNUSED(location
))
1895 //---------------------------------------------------------------------------
1896 // wxMCIMediaBackend::Play
1898 // Plays/Resumes the MCI device... a couple notes:
1899 // 1) Certain drivers will crash and burn if we don't pass them an
1900 // MCI_PLAY_PARMS, despite the documentation that says otherwise...
1901 // 2) There is a MCI_RESUME command, but MCI_PLAY does the same thing
1902 // and will resume from a stopped state also, so there's no need to
1903 // call both, for example
1904 //---------------------------------------------------------------------------
1905 bool wxMCIMediaBackend::Play()
1907 MCI_PLAY_PARMS playParms
;
1908 playParms
.dwCallback
= (DWORD
)m_hNotifyWnd
;
1910 bool bOK
= ( mciSendCommand(m_hDev
, MCI_PLAY
, MCI_NOTIFY
,
1911 (DWORD
)(LPVOID
)&playParms
) == 0 );
1914 m_ctrl
->Show(m_bVideo
);
1919 //---------------------------------------------------------------------------
1920 // wxMCIMediaBackend::Pause
1922 // Pauses the MCI device - nothing special
1923 //---------------------------------------------------------------------------
1924 bool wxMCIMediaBackend::Pause()
1926 return (mciSendCommand(m_hDev
, MCI_PAUSE
, MCI_WAIT
, 0) == 0);
1929 //---------------------------------------------------------------------------
1930 // wxMCIMediaBackend::Stop
1932 // Stops the MCI device & seeks to the beginning as wxMediaCtrl docs outline
1933 //---------------------------------------------------------------------------
1934 bool wxMCIMediaBackend::Stop()
1936 return (mciSendCommand(m_hDev
, MCI_STOP
, MCI_WAIT
, 0) == 0) &&
1937 (mciSendCommand(m_hDev
, MCI_SEEK
, MCI_SEEK_TO_START
, 0) == 0);
1940 //---------------------------------------------------------------------------
1941 // wxMCIMediaBackend::GetState
1943 // Here we get the state and convert it to a wxMediaState -
1944 // since we use direct comparisons with MCI_MODE_PLAY and
1945 // MCI_MODE_PAUSE, we don't care if the MCI_STATUS call
1947 //---------------------------------------------------------------------------
1948 wxMediaState
wxMCIMediaBackend::GetState()
1950 MCI_STATUS_PARMS statusParms
;
1951 statusParms
.dwItem
= MCI_STATUS_MODE
;
1953 mciSendCommand(m_hDev
, MCI_STATUS
, MCI_STATUS_ITEM
,
1954 (DWORD
)(LPVOID
)&statusParms
);
1956 if(statusParms
.dwReturn
== MCI_MODE_PAUSE
)
1957 return wxMEDIASTATE_PAUSED
;
1958 else if(statusParms
.dwReturn
== MCI_MODE_PLAY
)
1959 return wxMEDIASTATE_PLAYING
;
1961 return wxMEDIASTATE_STOPPED
;
1964 //---------------------------------------------------------------------------
1965 // wxMCIMediaBackend::SetPosition
1967 // Here we set the position of the device in the stream.
1968 // Note that MCI actually stops the device after you seek it if the
1969 // device is playing/paused, so we need to play the file after
1970 // MCI seeks like normal APIs would
1971 //---------------------------------------------------------------------------
1972 bool wxMCIMediaBackend::SetPosition(wxLongLong where
)
1974 MCI_SEEK_PARMS seekParms
;
1975 seekParms
.dwCallback
= 0;
1976 #if wxUSE_LONGLONG_NATIVE && !wxUSE_LONGLONG_WX
1977 seekParms
.dwTo
= (DWORD
)where
.GetValue();
1978 #else /* wxUSE_LONGLONG_WX */
1979 /* no way to return it in one piece */
1980 wxASSERT( where
.GetHi()==0 );
1981 seekParms
.dwTo
= (DWORD
)where
.GetLo();
1982 #endif /* wxUSE_LONGLONG_* */
1984 //device was playing?
1985 bool bReplay
= GetState() == wxMEDIASTATE_PLAYING
;
1987 if( mciSendCommand(m_hDev
, MCI_SEEK
, MCI_TO
,
1988 (DWORD
)(LPVOID
)&seekParms
) != 0)
1991 //If the device was playing, resume it
1998 //---------------------------------------------------------------------------
1999 // wxMCIMediaBackend::GetPosition
2001 // Gets the position of the device in the stream using the current
2002 // time format... nothing special here...
2003 //---------------------------------------------------------------------------
2004 wxLongLong
wxMCIMediaBackend::GetPosition()
2006 MCI_STATUS_PARMS statusParms
;
2007 statusParms
.dwItem
= MCI_STATUS_POSITION
;
2009 if (mciSendCommand(m_hDev
, MCI_STATUS
, MCI_STATUS_ITEM
,
2010 (DWORD
)(LPSTR
)&statusParms
) != 0)
2013 return statusParms
.dwReturn
;
2016 //---------------------------------------------------------------------------
2017 // wxMCIMediaBackend::GetVolume
2019 // Gets the volume of the current media via the MCI_DGV_STATUS_VOLUME
2020 // message. Value ranges from 0 (minimum) to 1000 (maximum volume).
2021 //---------------------------------------------------------------------------
2022 double wxMCIMediaBackend::GetVolume()
2024 MCI_STATUS_PARMS statusParms
;
2025 statusParms
.dwCallback
= 0;
2026 statusParms
.dwItem
= 0x4019; //MCI_DGV_STATUS_VOLUME
2028 if (mciSendCommand(m_hDev
, MCI_STATUS
, MCI_STATUS_ITEM
,
2029 (DWORD
)(LPSTR
)&statusParms
) != 0)
2032 return ((double)statusParms
.dwReturn
) / 1000.0;
2035 //---------------------------------------------------------------------------
2036 // wxMCIMediaBackend::SetVolume
2038 // Sets the volume of the current media via the MCI_DGV_SETAUDIO_VOLUME
2039 // message. Value ranges from 0 (minimum) to 1000 (maximum volume).
2040 //---------------------------------------------------------------------------
2041 bool wxMCIMediaBackend::SetVolume(double dVolume
)
2043 MCI_DGV_SETAUDIO_PARMS audioParms
;
2044 audioParms
.dwCallback
= 0;
2045 audioParms
.dwItem
= 0x4002; //MCI_DGV_SETAUDIO_VOLUME
2046 audioParms
.dwValue
= (DWORD
) (dVolume
* 1000.0);
2047 audioParms
.dwOver
= 0;
2048 audioParms
.lpstrAlgorithm
= NULL
;
2049 audioParms
.lpstrQuality
= NULL
;
2051 if (mciSendCommand(m_hDev
, 0x0873, //MCI_SETAUDIO
2052 0x00800000L
| 0x01000000L
, //MCI_DGV_SETAUDIO+(_ITEM | _VALUE)
2053 (DWORD
)(LPSTR
)&audioParms
) != 0)
2058 //---------------------------------------------------------------------------
2059 // wxMCIMediaBackend::GetDuration
2061 // Gets the duration of the stream... nothing special
2062 //---------------------------------------------------------------------------
2063 wxLongLong
wxMCIMediaBackend::GetDuration()
2065 MCI_STATUS_PARMS statusParms
;
2066 statusParms
.dwItem
= MCI_STATUS_LENGTH
;
2068 if (mciSendCommand(m_hDev
, MCI_STATUS
, MCI_STATUS_ITEM
,
2069 (DWORD
)(LPSTR
)&statusParms
) != 0)
2072 return statusParms
.dwReturn
;
2075 //---------------------------------------------------------------------------
2076 // wxMCIMediaBackend::Move
2078 // Moves the window to a location
2079 //---------------------------------------------------------------------------
2080 void wxMCIMediaBackend::Move(int WXUNUSED(x
), int WXUNUSED(y
),
2083 if (m_hNotifyWnd
&& m_bVideo
)
2085 MCI_DGV_RECT_PARMS putParms
; //ifdefed MCI_DGV_PUT_PARMS
2086 memset(&putParms
, 0, sizeof(MCI_DGV_RECT_PARMS
));
2087 putParms
.rc
.bottom
= h
;
2088 putParms
.rc
.right
= w
;
2090 //wxStackWalker will crash and burn here on assert
2091 //and mci doesn't like 0 and 0 for some reason (out of range )
2092 //so just don't it in that case
2095 wxMCIVERIFY( mciSendCommand(m_hDev
, MCI_PUT
,
2096 0x00040000L
, //MCI_DGV_PUT_DESTINATION
2097 (DWORD
)(LPSTR
)&putParms
) );
2102 //---------------------------------------------------------------------------
2103 // wxMCIMediaBackend::GetVideoSize
2105 // Gets the original size of the movie for sizers
2106 //---------------------------------------------------------------------------
2107 wxSize
wxMCIMediaBackend::GetVideoSize() const
2111 MCI_DGV_RECT_PARMS whereParms
; //ifdefed MCI_DGV_WHERE_PARMS
2113 wxMCIVERIFY( mciSendCommand(m_hDev
, MCI_WHERE
,
2114 0x00020000L
, //MCI_DGV_WHERE_SOURCE
2115 (DWORD
)(LPSTR
)&whereParms
) );
2117 return wxSize(whereParms
.rc
.right
, whereParms
.rc
.bottom
);
2122 //---------------------------------------------------------------------------
2123 // wxMCIMediaBackend::GetPlaybackRate
2126 //---------------------------------------------------------------------------
2127 double wxMCIMediaBackend::GetPlaybackRate()
2132 //---------------------------------------------------------------------------
2133 // wxMCIMediaBackend::SetPlaybackRate
2136 //---------------------------------------------------------------------------
2137 bool wxMCIMediaBackend::SetPlaybackRate(double WXUNUSED(dRate
))
2140 MCI_WAVE_SET_SAMPLESPERSEC
2141 MCI_DGV_SET_PARMS setParms;
2142 setParms.dwSpeed = (DWORD) (dRate * 1000.0);
2144 return (mciSendCommand(m_hDev, MCI_SET,
2145 0x00020000L, //MCI_DGV_SET_SPEED
2146 (DWORD)(LPSTR)&setParms) == 0);
2151 //---------------------------------------------------------------------------
2152 // [static] wxMCIMediaBackend::MSWWindowProc
2154 // Here we process a message when MCI reaches the stopping point
2156 //---------------------------------------------------------------------------
2157 LRESULT CALLBACK
wxMCIMediaBackend::NotifyWndProc(HWND hWnd
, UINT nMsg
,
2161 wxMCIMediaBackend
* backend
= (wxMCIMediaBackend
*)
2163 ::GetWindowLong(hWnd
, GWL_USERDATA
);
2165 ::GetWindowLongPtr(hWnd
, GWLP_USERDATA
);
2169 return backend
->OnNotifyWndProc(hWnd
, nMsg
, wParam
, lParam
);
2172 LRESULT CALLBACK
wxMCIMediaBackend::OnNotifyWndProc(HWND hWnd
, UINT nMsg
,
2176 if(nMsg
== MM_MCINOTIFY
)
2178 wxASSERT(lParam
== (LPARAM
) m_hDev
);
2179 if(wParam
== MCI_NOTIFY_SUCCESSFUL
&& lParam
== (LPARAM
)m_hDev
)
2181 wxMediaEvent
theEvent(wxEVT_MEDIA_STOP
, m_ctrl
->GetId());
2182 m_ctrl
->ProcessEvent(theEvent
);
2184 if(theEvent
.IsAllowed())
2186 wxMCIVERIFY( mciSendCommand(m_hDev
, MCI_SEEK
,
2187 MCI_SEEK_TO_START
, 0) );
2189 //send the event to our child
2190 wxMediaEvent
theEvent(wxEVT_MEDIA_FINISHED
,
2192 m_ctrl
->ProcessEvent(theEvent
);
2196 return DefWindowProc(hWnd
, nMsg
, wParam
, lParam
);
2198 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2202 // TODO: Use a less cludgy way to pause/get state/set state
2203 // TODO: Dynamically load from qtml.dll
2204 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2206 IMPLEMENT_DYNAMIC_CLASS(wxQTMediaBackend
, wxMediaBackend
);
2208 //Time between timer calls
2209 #define MOVIE_DELAY 100
2211 #include "wx/timer.h"
2213 // --------------------------------------------------------------------------
2214 // wxQTTimer - Handle Asyncronous Playing
2215 // --------------------------------------------------------------------------
2216 class _wxQTTimer
: public wxTimer
2219 _wxQTTimer(Movie movie
, wxQTMediaBackend
* parent
, wxQuickTimeLibrary
* pLib
) :
2220 m_movie(movie
), m_bPaused(false), m_parent(parent
), m_pLib(pLib
)
2228 bool GetPaused() {return m_bPaused
;}
2229 void SetPaused(bool bPaused
) {m_bPaused
= bPaused
;}
2231 //-----------------------------------------------------------------------
2232 // _wxQTTimer::Notify
2234 // 1) Checks to see if the movie is done, and if not continues
2235 // streaming the movie
2236 // 2) Sends the wxEVT_MEDIA_STOP event if we have reached the end of
2238 //-----------------------------------------------------------------------
2243 if(!m_pLib
->IsMovieDone(m_movie
))
2244 m_pLib
->MoviesTask(m_movie
, MOVIE_DELAY
);
2247 wxMediaEvent
theEvent(wxEVT_MEDIA_STOP
,
2248 m_parent
->m_ctrl
->GetId());
2249 m_parent
->m_ctrl
->ProcessEvent(theEvent
);
2251 if(theEvent
.IsAllowed())
2255 wxASSERT(m_pLib
->GetMoviesError() == noErr
);
2257 //send the event to our child
2258 wxMediaEvent
theEvent(wxEVT_MEDIA_FINISHED
,
2259 m_parent
->m_ctrl
->GetId());
2260 m_parent
->m_ctrl
->ProcessEvent(theEvent
);
2267 Movie m_movie
; //Our movie instance
2268 bool m_bPaused
; //Whether we are paused or not
2269 wxQTMediaBackend
* m_parent
; //Backend pointer
2270 wxQuickTimeLibrary
* m_pLib
; //Interfaces
2273 //---------------------------------------------------------------------------
2274 // wxQTMediaBackend Destructor
2276 // Sets m_timer to NULL signifying we havn't loaded anything yet
2277 //---------------------------------------------------------------------------
2278 wxQTMediaBackend::wxQTMediaBackend() : m_timer(NULL
)
2282 //---------------------------------------------------------------------------
2283 // wxQTMediaBackend Destructor
2285 // 1) Cleans up the QuickTime movie instance
2286 // 2) Decrements the QuickTime reference counter - if this reaches
2287 // 0, QuickTime shuts down
2288 // 3) Decrements the QuickTime Windows Media Layer reference counter -
2289 // if this reaches 0, QuickTime shuts down the Windows Media Layer
2290 //---------------------------------------------------------------------------
2291 wxQTMediaBackend::~wxQTMediaBackend()
2298 //Note that ExitMovies() is not necessary, but
2299 //the docs are fuzzy on whether or not TerminateQTML is
2301 m_lib
.TerminateQTML();
2305 //---------------------------------------------------------------------------
2306 // wxQTMediaBackend::CreateControl
2308 // 1) Intializes QuickTime
2309 // 2) Creates the control window
2310 //---------------------------------------------------------------------------
2311 bool wxQTMediaBackend::CreateControl(wxControl
* ctrl
, wxWindow
* parent
,
2316 const wxValidator
& validator
,
2317 const wxString
& name
)
2319 if(!m_lib
.Initialize())
2322 int nError
= m_lib
.InitializeQTML(0);
2323 if (nError
!= noErr
) //-2093 no dll
2325 wxFAIL_MSG(wxString::Format(wxT("Couldn't Initialize Quicktime-%i"), nError
));
2328 m_lib
.EnterMovies();
2332 // By default wxWindow(s) is created with a border -
2333 // so we need to get rid of those
2335 // Since we don't have a child window like most other
2336 // backends, we don't need wxCLIP_CHILDREN
2338 if ( !ctrl
->wxControl::Create(parent
, id
, pos
, size
,
2339 (style
& ~wxBORDER_MASK
) | wxBORDER_NONE
,
2347 //---------------------------------------------------------------------------
2348 // wxQTMediaBackend::Load (file version)
2350 // 1) Get an FSSpec from the Windows path name
2351 // 2) Open the movie
2352 // 3) Obtain the movie instance from the movie resource
2354 //---------------------------------------------------------------------------
2355 bool wxQTMediaBackend::Load(const wxString
& fileName
)
2360 short movieResFile
= 0; //= 0 because of annoying VC6 warning
2363 if (m_lib
.NativePathNameToFSSpec ((char*) (const char*) fileName
.mb_str(),
2364 &sfFile
, 0) != noErr
)
2367 if (m_lib
.OpenMovieFile (&sfFile
, &movieResFile
, fsRdPerm
) != noErr
)
2370 short movieResID
= 0;
2373 OSErr err
= m_lib
.NewMovieFromFile (
2382 m_lib
.CloseMovieFile (movieResFile
);
2389 return m_lib
.GetMoviesError() == noErr
;
2392 //---------------------------------------------------------------------------
2393 // wxQTMediaBackend::Move
2396 //---------------------------------------------------------------------------
2397 bool wxQTMediaBackend::Load(const wxURI
& location
)
2402 wxString theURI
= location
.BuildURI();
2404 Handle theHandle
= m_lib
.NewHandleClear(theURI
.length() + 1);
2405 wxASSERT(theHandle
);
2407 m_lib
.BlockMove(theURI
.mb_str(), *theHandle
, theURI
.length() + 1);
2409 //create the movie from the handle that refers to the URI
2410 OSErr err
= m_lib
.NewMovieFromDataRef(&m_movie
, newMovieActive
,
2412 URLDataHandlerSubType
);
2414 m_lib
.DisposeHandle(theHandle
);
2419 //preroll movie for streaming
2424 timeNow = GetMovieTime(m_movie, NULL);
2425 playRate = GetMoviePreferredRate(m_movie);
2426 PrePrerollMovie(m_movie, timeNow, playRate, NULL, NULL);
2427 PrerollMovie(m_movie, timeNow, playRate);
2428 m_lib.SetMovieRate(m_movie, playRate);
2433 return m_lib
.GetMoviesError() == noErr
;
2436 //---------------------------------------------------------------------------
2437 // wxQTMediaBackend::Move
2440 //---------------------------------------------------------------------------
2441 void wxQTMediaBackend::FinishLoad()
2443 m_timer
= new _wxQTTimer(m_movie
, (wxQTMediaBackend
*) this, &m_lib
);
2446 //get the real size of the movie
2448 memset(&outRect
, 0, sizeof(Rect
)); //for annoying VC6 warning
2449 m_lib
.GetMovieNaturalBoundsRect (m_movie
, &outRect
);
2450 wxASSERT(m_lib
.GetMoviesError() == noErr
);
2452 m_bestSize
.x
= outRect
.right
- outRect
.left
;
2453 m_bestSize
.y
= outRect
.bottom
- outRect
.top
;
2455 //reparent movie/*AudioMediaCharacteristic*/
2456 if(m_lib
.GetMovieIndTrackType(m_movie
, 1,
2457 VisualMediaCharacteristic
,
2458 (1 << 1) //movieTrackCharacteristic
2459 | (1 << 2) //movieTrackEnabledOnly
2462 m_lib
.CreatePortAssociation(m_ctrl
->GetHWND(), NULL
, 0L);
2464 m_lib
.SetMovieGWorld(m_movie
,
2465 (CGrafPtr
) m_lib
.GetNativeWindowPort(m_ctrl
->GetHWND()),
2469 //we want millisecond precision
2470 m_lib
.SetMovieTimeScale(m_movie
, 1000);
2471 wxASSERT(m_lib
.GetMoviesError() == noErr
);
2474 //Here, if the parent of the control has a sizer - we
2475 //tell it to recalculate the size of this control since
2476 //the user opened a separate media file
2478 m_ctrl
->InvalidateBestSize();
2479 m_ctrl
->GetParent()->Layout();
2480 m_ctrl
->GetParent()->Refresh();
2481 m_ctrl
->GetParent()->Update();
2484 //---------------------------------------------------------------------------
2485 // wxQTMediaBackend::Move
2488 //---------------------------------------------------------------------------
2489 bool wxQTMediaBackend::Play()
2491 m_lib
.StartMovie(m_movie
);
2492 m_timer
->SetPaused(false);
2493 m_timer
->Start(MOVIE_DELAY
, wxTIMER_CONTINUOUS
);
2494 return m_lib
.GetMoviesError() == noErr
;
2497 //---------------------------------------------------------------------------
2498 // wxQTMediaBackend::Move
2501 //---------------------------------------------------------------------------
2502 bool wxQTMediaBackend::Pause()
2504 m_lib
.StopMovie(m_movie
);
2505 m_timer
->SetPaused(true);
2507 return m_lib
.GetMoviesError() == noErr
;
2510 //---------------------------------------------------------------------------
2511 // wxQTMediaBackend::Move
2514 //---------------------------------------------------------------------------
2515 bool wxQTMediaBackend::Stop()
2517 m_timer
->SetPaused(false);
2520 m_lib
.StopMovie(m_movie
);
2521 if(m_lib
.GetMoviesError() != noErr
)
2524 m_lib
.GoToBeginningOfMovie(m_movie
);
2525 return m_lib
.GetMoviesError() == noErr
;
2528 //---------------------------------------------------------------------------
2529 // wxQTMediaBackend::Move
2532 //---------------------------------------------------------------------------
2533 double wxQTMediaBackend::GetPlaybackRate()
2535 return ( ((double)m_lib
.GetMovieRate(m_movie
)) / 0x10000);
2538 //---------------------------------------------------------------------------
2539 // wxQTMediaBackend::Move
2542 //---------------------------------------------------------------------------
2543 bool wxQTMediaBackend::SetPlaybackRate(double dRate
)
2545 m_lib
.SetMovieRate(m_movie
, (Fixed
) (dRate
* 0x10000));
2546 return m_lib
.GetMoviesError() == noErr
;
2549 //---------------------------------------------------------------------------
2550 // wxQTMediaBackend::Move
2553 //---------------------------------------------------------------------------
2554 bool wxQTMediaBackend::SetPosition(wxLongLong where
)
2556 TimeRecord theTimeRecord
;
2557 memset(&theTimeRecord
, 0, sizeof(TimeRecord
));
2558 theTimeRecord
.value
.lo
= where
.GetLo();
2559 theTimeRecord
.scale
= m_lib
.GetMovieTimeScale(m_movie
);
2560 theTimeRecord
.base
= m_lib
.GetMovieTimeBase(m_movie
);
2561 m_lib
.SetMovieTime(m_movie
, &theTimeRecord
);
2563 if (m_lib
.GetMoviesError() != noErr
)
2569 //---------------------------------------------------------------------------
2570 // wxQTMediaBackend::GetPosition
2572 // 1) Calls GetMovieTime to get the position we are in in the movie
2573 // in milliseconds (we called
2574 //---------------------------------------------------------------------------
2575 wxLongLong
wxQTMediaBackend::GetPosition()
2577 return m_lib
.GetMovieTime(m_movie
, NULL
);
2580 //---------------------------------------------------------------------------
2581 // wxQTMediaBackend::GetVolume
2583 // Gets the volume through GetMovieVolume - which returns a 16 bit short -
2585 // +--------+--------+
2587 // +--------+--------+
2589 // (1) first 8 bits are value before decimal
2590 // (2) second 8 bits are value after decimal
2592 // Volume ranges from -1.0 (gain but no sound), 0 (no sound and no gain) to
2593 // 1 (full gain and sound)
2594 //---------------------------------------------------------------------------
2595 double wxQTMediaBackend::GetVolume()
2597 short sVolume
= m_lib
.GetMovieVolume(m_movie
);
2599 if(sVolume
& (128 << 8)) //negative - no sound
2602 return (sVolume
& (127 << 8)) ? 1.0 : ((double)(sVolume
& 255)) / 255.0;
2605 //---------------------------------------------------------------------------
2606 // wxQTMediaBackend::SetVolume
2608 // Sets the volume through SetMovieVolume - which takes a 16 bit short -
2610 // +--------+--------+
2612 // +--------+--------+
2614 // (1) first 8 bits are value before decimal
2615 // (2) second 8 bits are value after decimal
2617 // Volume ranges from -1.0 (gain but no sound), 0 (no sound and no gain) to
2618 // 1 (full gain and sound)
2619 //---------------------------------------------------------------------------
2620 bool wxQTMediaBackend::SetVolume(double dVolume
)
2622 short sVolume
= (short) (dVolume
>= .9999 ? 1 << 8 : (dVolume
* 255) );
2623 m_lib
.SetMovieVolume(m_movie
, sVolume
);
2627 //---------------------------------------------------------------------------
2628 // wxQTMediaBackend::Move
2631 //---------------------------------------------------------------------------
2632 wxLongLong
wxQTMediaBackend::GetDuration()
2634 return m_lib
.GetMovieDuration(m_movie
);
2637 //---------------------------------------------------------------------------
2638 // wxQTMediaBackend::Move
2641 //---------------------------------------------------------------------------
2642 wxMediaState
wxQTMediaBackend::GetState()
2644 if ( !m_timer
|| (m_timer
->IsRunning() == false &&
2645 m_timer
->GetPaused() == false) )
2646 return wxMEDIASTATE_STOPPED
;
2648 if( m_timer
->IsRunning() == true )
2649 return wxMEDIASTATE_PLAYING
;
2651 return wxMEDIASTATE_PAUSED
;
2654 //---------------------------------------------------------------------------
2655 // wxQTMediaBackend::Move
2658 //---------------------------------------------------------------------------
2659 void wxQTMediaBackend::Cleanup()
2664 m_lib
.StopMovie(m_movie
);
2665 m_lib
.DisposeMovie(m_movie
);
2668 //---------------------------------------------------------------------------
2669 // wxQTMediaBackend::Move
2672 //---------------------------------------------------------------------------
2673 wxSize
wxQTMediaBackend::GetVideoSize() const
2678 //---------------------------------------------------------------------------
2679 // wxQTMediaBackend::Move
2682 //---------------------------------------------------------------------------
2683 void wxQTMediaBackend::Move(int WXUNUSED(x
), int WXUNUSED(y
), int w
, int h
)
2687 Rect theRect
= {0, 0, (short)h
, (short)w
};
2689 m_lib
.SetMovieBox(m_movie
, &theRect
);
2690 wxASSERT(m_lib
.GetMoviesError() == noErr
);
2694 //---------------------------------------------------------------------------
2696 //---------------------------------------------------------------------------
2698 //in source file that contains stuff you don't directly use
2699 #include <wx/html/forcelnk.h>
2700 FORCE_LINK_ME(basewxmediabackends
);
2702 //---------------------------------------------------------------------------
2703 // End wxMediaCtrl Compilation Guard and this file
2704 //---------------------------------------------------------------------------
2705 #endif //wxUSE_MEDIACTRL