]> git.saurik.com Git - wxWidgets.git/blob - src/msw/mediactrl.cpp
Further steps towards media control support in WinCE (Ryan Norton)
[wxWidgets.git] / src / msw / mediactrl.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/mediactrl.cpp
3 // Purpose: Built-in Media Backends for Windows
4 // Author: Ryan Norton <wxprojects@comcast.net>
5 // Modified by:
6 // Created: 11/07/04
7 // RCS-ID: $Id$
8 // Copyright: (c) Ryan Norton
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // FIXME FIXME FIXME:
13 // extract different backends in different files (better yet, make backends
14 // dynamically loadable...), they have nothing to do with each other and this
15 // file is huge and also separate the standard contents from our code itself
16
17
18 //===========================================================================
19 // DECLARATIONS
20 //===========================================================================
21
22 //---------------------------------------------------------------------------
23 // Pre-compiled header stuff
24 //---------------------------------------------------------------------------
25
26 // For compilers that support precompilation, includes "wx.h".
27 #include "wx/wxprec.h"
28
29 #ifdef __BORLANDC__
30 #pragma hdrstop
31 #endif
32
33 //---------------------------------------------------------------------------
34 // MediaCtrl include
35 //---------------------------------------------------------------------------
36 #include "wx/mediactrl.h"
37
38 //---------------------------------------------------------------------------
39 // Compilation guard
40 //---------------------------------------------------------------------------
41 #if wxUSE_MEDIACTRL
42
43 //---------------------------------------------------------------------------
44 // WX Includes
45 //---------------------------------------------------------------------------
46 #include "wx/log.h" //wxLogDebug
47 #include "wx/math.h" //log10 & pow
48 #include "wx/msw/private.h" //user info and wndproc setting/getting
49 #include "wx/dcclient.h"
50 #include "wx/timer.h"
51 #include "wx/dynlib.h"
52
53 //---------------------------------------------------------------------------
54 // Externals (somewhere in src/msw/app.cpp and src/msw/window.cpp)
55 //---------------------------------------------------------------------------
56 extern "C" WXDLLIMPEXP_BASE HINSTANCE wxGetInstance(void);
57 #ifdef __WXWINCE__
58 extern WXDLLIMPEXP_CORE wxChar *wxCanvasClassName;
59 #else
60 extern WXDLLIMPEXP_CORE const wxChar *wxCanvasClassName;
61 #endif
62
63 LRESULT WXDLLIMPEXP_CORE APIENTRY _EXPORT wxWndProc(HWND hWnd, UINT message,
64 WPARAM wParam, LPARAM lParam);
65
66 //===========================================================================
67 // BACKEND DECLARATIONS
68 //===========================================================================
69
70 //---------------------------------------------------------------------------
71 //
72 // wxAMMediaBackend
73 //
74 //---------------------------------------------------------------------------
75
76 //---------------------------------------------------------------------------
77 // wxActiveXContainer - includes all the COM-specific stuff we need
78 //---------------------------------------------------------------------------
79 #include "wx/msw/ole/activex.h"
80
81 //---------------------------------------------------------------------------
82 // IIDS - used by CoCreateInstance and IUnknown::QueryInterface
83 //
84 // [idl name] [idl decription]
85 // amcompat.idl Microsoft Active Movie Control (Ver 2.0)
86 // nscompat.idl Microsoft NetShow Player (Ver 1.0)
87 // msdxm.idl Windows Media Player (Ver 1.0)
88 // quartz.idl
89 //
90 // First, when I say I "from XXX.idl", I mean I go into the COM Browser
91 // ($Microsoft Visual Studio$/Common/Tools/OLEVIEW.EXE), open
92 // "type libraries", open a specific type library (for quartz for example its
93 // "ActiveMovie control type library (V1.0)"), save it as an .idl, compile the
94 // idl using the midl compiler that comes with visual studio
95 // ($Microsoft Visual Studio$/VC98/bin/midl.exe on VC6) with the /h argument
96 // to make it generate stubs (a .h & .c file), then clean up the generated
97 // interfaces I want with the STDMETHOD wrappers and then put them into
98 // mediactrl.cpp.
99 //
100 // According to the MSDN docs, IMediaPlayer requires Windows 98 SE
101 // or greater. NetShow is available on Windows 3.1 and I'm guessing
102 // IActiveMovie is too. IMediaPlayer is essentially the Windows Media
103 // Player 6.4 SDK.
104 //
105 // Some of these are not used but are kept here for future reference anyway
106 //---------------------------------------------------------------------------
107 const IID IID_IActiveMovie = {0x05589FA2,0xC356,0x11CE,{0xBF,0x01,0x00,0xAA,0x00,0x55,0x59,0x5A}};
108 const IID IID_IActiveMovie2 = {0xB6CD6554,0xE9CB,0x11D0,{0x82,0x1F,0x00,0xA0,0xC9,0x1F,0x9C,0xA0}};
109 const IID IID_IActiveMovie3 = {0x265EC140,0xAE62,0x11D1,{0x85,0x00,0x00,0xA0,0xC9,0x1F,0x9C,0xA0}};
110
111 const IID IID_INSOPlay = {0x2179C5D1,0xEBFF,0x11CF,{0xB6,0xFD,0x00,0xAA,0x00,0xB4,0xE2,0x20}};
112 const IID IID_INSPlay = {0xE7C4BE80,0x7960,0x11D0,{0xB7,0x27,0x00,0xAA,0x00,0xB4,0xE2,0x20}};
113 const IID IID_INSPlay1 = {0x265EC141,0xAE62,0x11D1,{0x85,0x00,0x00,0xA0,0xC9,0x1F,0x9C,0xA0}};
114
115 const IID IID_IMediaPlayer = {0x22D6F311,0xB0F6,0x11D0,{0x94,0xAB,0x00,0x80,0xC7,0x4C,0x7E,0x95}};
116 const IID IID_IMediaPlayer2 = {0x20D4F5E0,0x5475,0x11D2,{0x97,0x74,0x00,0x00,0xF8,0x08,0x55,0xE6}};
117
118 const CLSID CLSID_ActiveMovie = {0x05589FA1,0xC356,0x11CE,{0xBF,0x01,0x00,0xAA,0x00,0x55,0x59,0x5A}};
119 const CLSID CLSID_MediaPlayer = {0x22D6F312,0xB0F6,0x11D0,{0x94,0xAB,0x00,0x80,0xC7,0x4C,0x7E,0x95}};
120 const CLSID CLSID_NSPlay = {0x2179C5D3,0xEBFF,0x11CF,{0xB6,0xFD,0x00,0xAA,0x00,0xB4,0xE2,0x20}};
121
122 const IID IID_IAMOpenProgress = {0x8E1C39A1, 0xDE53, 0x11CF,{0xAA, 0x63, 0x00, 0x80, 0xC7, 0x44, 0x52, 0x8D}};
123
124 // QUARTZ
125 const CLSID CLSID_FilgraphManager = {0xE436EBB3,0x524F,0x11CE,{0x9F,0x53,0x00,0x20,0xAF,0x0B,0xA7,0x70}};
126 const IID IID_IMediaEvent = {0x56A868B6,0x0AD4,0x11CE,{0xB0,0x3A,0x00,0x20,0xAF,0x0B,0xA7,0x70}};
127
128 //?? QUARTZ Also?
129 const CLSID CLSID_VideoMixingRenderer9 ={0x51B4ABF3, 0x748F, 0x4E3B,{0xA2, 0x76, 0xC8, 0x28, 0x33, 0x0E, 0x92, 0x6A}};
130 const IID IID_IVMRWindowlessControl9 = {0x8F537D09, 0xF85E, 0x4414,{0xB2, 0x3B, 0x50, 0x2E, 0x54, 0xC7, 0x99, 0x27}};
131 const IID IID_IFilterGraph = {0x56A8689F, 0x0AD4, 0x11CE,{0xB0, 0x3A, 0x00, 0x20, 0xAF, 0x0B, 0xA7, 0x70}};
132 const IID IID_IGraphBuilder = {0x56A868A9, 0x0AD4, 0x11CE,{0xB0, 0x3A, 0x00, 0x20, 0xAF, 0x0B, 0xA7, 0x70}};
133 const IID IID_IVMRFilterConfig9 = {0x5A804648, 0x4F66, 0x4867,{0x9C, 0x43, 0x4F, 0x5C, 0x82, 0x2C, 0xF1, 0xB8}};
134 const IID IID_IBaseFilter = {0x56A86895, 0x0AD4, 0x11CE,{0xB0, 0x3A, 0x00, 0x20, 0xAF, 0x0B, 0xA7, 0x70}};
135
136 //---------------------------------------------------------------------------
137 // QUARTZ COM INTERFACES (dumped from quartz.idl from MSVC COM Browser)
138 //---------------------------------------------------------------------------
139
140 struct IAMOpenProgress : public IUnknown
141 {
142 STDMETHOD(QueryProgress)(LONGLONG *pllTotal, LONGLONG *pllCurrent) PURE;
143 STDMETHOD(AbortOperation)(void) PURE;
144 };
145
146 struct IMediaEvent : public IDispatch
147 {
148 STDMETHOD(GetEventHandle)(LONG_PTR *) PURE;
149 STDMETHOD(GetEvent)(long *, LONG_PTR *, LONG_PTR *, long) PURE;
150 STDMETHOD(WaitForCompletion)(long, long *) PURE;
151 STDMETHOD(CancelDefaultHandling)(long) PURE;
152 STDMETHOD(RestoreDefaultHandling)(long) PURE;
153 STDMETHOD(FreeEventParams)(long, LONG_PTR, LONG_PTR) PURE;
154 };
155
156 //---------------------------------------------------------------------------
157 // ACTIVEMOVIE COM INTERFACES (dumped from amcompat.idl from MSVC COM Browser)
158 //---------------------------------------------------------------------------
159
160 enum ReadyStateConstants
161 {
162 amvUninitialized = 0,
163 amvLoading = 1,
164 amvInteractive = 3,
165 amvComplete = 4
166 };
167
168 enum StateConstants
169 {
170 amvNotLoaded = -1,
171 amvStopped = 0,
172 amvPaused = 1,
173 amvRunning = 2
174 };
175
176 enum DisplayModeConstants
177 {
178 amvTime = 0,
179 amvFrames = 1
180 };
181
182 enum WindowSizeConstants
183 {
184 amvOriginalSize = 0,
185 amvDoubleOriginalSize = 1,
186 amvOneSixteenthScreen = 2,
187 amvOneFourthScreen = 3,
188 amvOneHalfScreen = 4
189 };
190
191 enum AppearanceConstants
192 {
193 amvFlat = 0,
194 amv3D = 1
195 };
196
197 enum BorderStyleConstants
198 {
199 amvNone = 0,
200 amvFixedSingle = 1
201 };
202
203 struct IActiveMovie : public IDispatch
204 {
205 STDMETHOD(AboutBox)( void) PURE;
206 STDMETHOD(Run)( void) PURE;
207 STDMETHOD(Pause)( void) PURE;
208 STDMETHOD(Stop)( void) PURE;
209 STDMETHOD(get_ImageSourceWidth)(long __RPC_FAR *pWidth) PURE;
210 STDMETHOD(get_ImageSourceHeight)(long __RPC_FAR *pHeight) PURE;
211 STDMETHOD(get_Author)(BSTR __RPC_FAR *pbstrAuthor) PURE;
212 STDMETHOD(get_Title)(BSTR __RPC_FAR *pbstrTitle) PURE;
213 STDMETHOD(get_Copyright)(BSTR __RPC_FAR *pbstrCopyright) PURE;
214 STDMETHOD(get_Description)(BSTR __RPC_FAR *pbstrDescription) PURE;
215 STDMETHOD(get_Rating)(BSTR __RPC_FAR *pbstrRating) PURE;
216 STDMETHOD(get_FileName)(BSTR __RPC_FAR *pbstrFileName) PURE;
217 STDMETHOD(put_FileName)(BSTR pbstrFileName) PURE;
218 STDMETHOD(get_Duration)(double __RPC_FAR *pValue) PURE;
219 STDMETHOD(get_CurrentPosition)(double __RPC_FAR *pValue) PURE;
220 STDMETHOD(put_CurrentPosition)(double pValue) PURE;
221 STDMETHOD(get_PlayCount)(long __RPC_FAR *pPlayCount) PURE;
222 STDMETHOD(put_PlayCount)(long pPlayCount) PURE;
223 STDMETHOD(get_SelectionStart)(double __RPC_FAR *pValue) PURE;
224 STDMETHOD(put_SelectionStart)(double pValue) PURE;
225 STDMETHOD(get_SelectionEnd)(double __RPC_FAR *pValue) PURE;
226 STDMETHOD(put_SelectionEnd)(double pValue) PURE;
227 STDMETHOD(get_CurrentState)(StateConstants __RPC_FAR *pState) PURE;
228 STDMETHOD(get_Rate)(double __RPC_FAR *pValue) PURE;
229 STDMETHOD(put_Rate)(double pValue) PURE;
230 STDMETHOD(get_Volume)(long __RPC_FAR *pValue) PURE;
231 STDMETHOD(put_Volume)(long pValue) PURE;
232 STDMETHOD(get_Balance)(long __RPC_FAR *pValue) PURE;
233 STDMETHOD(put_Balance)(long pValue) PURE;
234 STDMETHOD(get_EnableContextMenu)(VARIANT_BOOL __RPC_FAR *pEnable) PURE;
235 STDMETHOD(put_EnableContextMenu)(VARIANT_BOOL pEnable) PURE;
236 STDMETHOD(get_ShowDisplay)(VARIANT_BOOL __RPC_FAR *Show) PURE;
237 STDMETHOD(put_ShowDisplay)(VARIANT_BOOL Show) PURE;
238 STDMETHOD(get_ShowControls)(VARIANT_BOOL __RPC_FAR *Show) PURE;
239 STDMETHOD(put_ShowControls)(VARIANT_BOOL Show) PURE;
240 STDMETHOD(get_ShowPositionControls)(VARIANT_BOOL __RPC_FAR *Show) PURE;
241 STDMETHOD(put_ShowPositionControls)(VARIANT_BOOL Show) PURE;
242 STDMETHOD(get_ShowSelectionControls)(VARIANT_BOOL __RPC_FAR *Show) PURE;
243 STDMETHOD(put_ShowSelectionControls)(VARIANT_BOOL Show) PURE;
244 STDMETHOD(get_ShowTracker)(VARIANT_BOOL __RPC_FAR *Show) PURE;
245 STDMETHOD(put_ShowTracker)(VARIANT_BOOL Show) PURE;
246 STDMETHOD(get_EnablePositionControls)(VARIANT_BOOL __RPC_FAR *Enable) PURE;
247 STDMETHOD(put_EnablePositionControls)(VARIANT_BOOL Enable) PURE;
248 STDMETHOD(get_EnableSelectionControls)(VARIANT_BOOL __RPC_FAR *Enable) PURE;
249 STDMETHOD(put_EnableSelectionControls)(VARIANT_BOOL Enable) PURE;
250 STDMETHOD(get_EnableTracker)(VARIANT_BOOL __RPC_FAR *Enable) PURE;
251 STDMETHOD(put_EnableTracker)(VARIANT_BOOL Enable) PURE;
252 STDMETHOD(get_AllowHideDisplay)(VARIANT_BOOL __RPC_FAR *Show) PURE;
253 STDMETHOD(put_AllowHideDisplay)(VARIANT_BOOL Show) PURE;
254 STDMETHOD(get_AllowHideControls)(VARIANT_BOOL __RPC_FAR *Show) PURE;
255 STDMETHOD(put_AllowHideControls)(VARIANT_BOOL Show) PURE;
256 STDMETHOD(get_DisplayMode)(DisplayModeConstants __RPC_FAR *pValue) PURE;
257 STDMETHOD(put_DisplayMode)(DisplayModeConstants pValue) PURE;
258 STDMETHOD(get_AllowChangeDisplayMode)(VARIANT_BOOL __RPC_FAR *fAllow) PURE;
259 STDMETHOD(put_AllowChangeDisplayMode)(VARIANT_BOOL fAllow) PURE;
260 STDMETHOD(get_FilterGraph)(IUnknown __RPC_FAR *__RPC_FAR *ppFilterGraph) PURE;
261 STDMETHOD(put_FilterGraph)(IUnknown __RPC_FAR *ppFilterGraph) PURE;
262 STDMETHOD(get_FilterGraphDispatch)(IDispatch __RPC_FAR *__RPC_FAR *pDispatch) PURE;
263 STDMETHOD(get_DisplayForeColor)(unsigned long __RPC_FAR *ForeColor) PURE;
264 STDMETHOD(put_DisplayForeColor)(unsigned long ForeColor) PURE;
265 STDMETHOD(get_DisplayBackColor)(unsigned long __RPC_FAR *BackColor) PURE;
266 STDMETHOD(put_DisplayBackColor)(unsigned long BackColor) PURE;
267 STDMETHOD(get_MovieWindowSize)(WindowSizeConstants __RPC_FAR *WindowSize) PURE;
268 STDMETHOD(put_MovieWindowSize)(WindowSizeConstants WindowSize) PURE;
269 STDMETHOD(get_FullScreenMode)(VARIANT_BOOL __RPC_FAR *pEnable) PURE;
270 STDMETHOD(put_FullScreenMode)(VARIANT_BOOL pEnable) PURE;
271 STDMETHOD(get_AutoStart)(VARIANT_BOOL __RPC_FAR *pEnable) PURE;
272 STDMETHOD(put_AutoStart)(VARIANT_BOOL pEnable) PURE;
273 STDMETHOD(get_AutoRewind)(VARIANT_BOOL __RPC_FAR *pEnable) PURE;
274 STDMETHOD(put_AutoRewind)(VARIANT_BOOL pEnable) PURE;
275 STDMETHOD(get_hWnd)(long __RPC_FAR *hWnd) PURE;
276 STDMETHOD(get_Appearance)(AppearanceConstants __RPC_FAR *pAppearance) PURE;
277 STDMETHOD(put_Appearance)(AppearanceConstants pAppearance) PURE;
278 STDMETHOD(get_BorderStyle)(BorderStyleConstants __RPC_FAR *pBorderStyle) PURE;
279 STDMETHOD(put_BorderStyle)(BorderStyleConstants pBorderStyle) PURE;
280 STDMETHOD(get_Enabled)(VARIANT_BOOL __RPC_FAR *pEnabled) PURE;
281 STDMETHOD(put_Enabled)(VARIANT_BOOL pEnabled) PURE;
282 STDMETHOD(get_Info)(long __RPC_FAR *ppInfo) PURE;
283 };
284
285
286 struct IActiveMovie2 : public IActiveMovie
287 {
288 STDMETHOD(IsSoundCardEnabled)(VARIANT_BOOL __RPC_FAR *pbSoundCard) PURE;
289 STDMETHOD(get_ReadyState)(ReadyStateConstants __RPC_FAR *pValue) PURE;
290 };
291
292 struct IActiveMovie3 : public IActiveMovie2
293 {
294 STDMETHOD(get_MediaPlayer)(IDispatch __RPC_FAR *__RPC_FAR *ppDispatch) PURE;
295 };
296
297
298 //---------------------------------------------------------------------------
299 // MEDIAPLAYER COM INTERFACES (dumped from msdxm.idl from MSVC COM Browser)
300 //---------------------------------------------------------------------------
301
302 enum MPPlayStateConstants
303 {
304 mpStopped = 0,
305 mpPaused = 1,
306 mpPlaying = 2,
307 mpWaiting = 3,
308 mpScanForward = 4,
309 mpScanReverse = 5,
310 mpClosed = 6
311 };
312
313 enum MPDisplaySizeConstants
314 {
315 mpDefaultSize = 0,
316 mpHalfSize = 1,
317 mpDoubleSize = 2,
318 mpFullScreen = 3,
319 mpFitToSize = 4,
320 mpOneSixteenthScreen = 5,
321 mpOneFourthScreen = 6,
322 mpOneHalfScreen = 7
323 };
324
325 enum MPReadyStateConstants
326 {
327 mpReadyStateUninitialized = 0,
328 mpReadyStateLoading = 1,
329 mpReadyStateInteractive = 3,
330 mpReadyStateComplete = 4
331 };
332
333 typedef unsigned long VB_OLE_COLOR;
334
335 enum MPDisplayModeConstants
336 {
337 mpTime = 0,
338 mpFrames = 1
339 };
340
341 enum MPMoreInfoType
342 {
343 mpShowURL = 0,
344 mpClipURL = 1,
345 mpBannerURL = 2
346 };
347
348 enum MPMediaInfoType
349 {
350 mpShowFilename = 0,
351 mpShowTitle = 1,
352 mpShowAuthor = 2,
353 mpShowCopyright = 3,
354 mpShowRating = 4,
355 mpShowDescription = 5,
356 mpShowLogoIcon = 6,
357 mpClipFilename = 7,
358 mpClipTitle = 8,
359 mpClipAuthor = 9,
360 mpClipCopyright = 10,
361 mpClipRating = 11,
362 mpClipDescription = 12,
363 mpClipLogoIcon = 13,
364 mpBannerImage = 14,
365 mpBannerMoreInfo = 15,
366 mpWatermark = 16
367 };
368
369 enum DVDMenuIDConstants
370 {
371 dvdMenu_Title = 2,
372 dvdMenu_Root = 3,
373 dvdMenu_Subpicture = 4,
374 dvdMenu_Audio = 5,
375 dvdMenu_Angle = 6,
376 dvdMenu_Chapter = 7
377 };
378
379 enum MPShowDialogConstants
380 {
381 mpShowDialogHelp = 0,
382 mpShowDialogStatistics = 1,
383 mpShowDialogOptions = 2,
384 mpShowDialogContextMenu = 3
385 };
386
387
388 struct IMediaPlayer : public IDispatch
389 {
390 STDMETHOD(get_CurrentPosition)(double __RPC_FAR *pCurrentPosition) PURE;
391 STDMETHOD(put_CurrentPosition)(double pCurrentPosition) PURE;
392 STDMETHOD(get_Duration)(double __RPC_FAR *pDuration) PURE;
393 STDMETHOD(get_ImageSourceWidth)(long __RPC_FAR *pWidth) PURE;
394 STDMETHOD(get_ImageSourceHeight)(long __RPC_FAR *pHeight) PURE;
395 STDMETHOD(get_MarkerCount)(long __RPC_FAR *pMarkerCount) PURE;
396 STDMETHOD(get_CanScan)(VARIANT_BOOL __RPC_FAR *pCanScan) PURE;
397 STDMETHOD(get_CanSeek)(VARIANT_BOOL __RPC_FAR *pCanSeek) PURE;
398 STDMETHOD(get_CanSeekToMarkers)(VARIANT_BOOL __RPC_FAR *pCanSeekToMarkers) PURE;
399 STDMETHOD(get_CurrentMarker)(long __RPC_FAR *pCurrentMarker) PURE;
400 STDMETHOD(put_CurrentMarker)(long pCurrentMarker) PURE;
401 STDMETHOD(get_FileName)(BSTR __RPC_FAR *pbstrFileName) PURE;
402 STDMETHOD(put_FileName)(BSTR pbstrFileName) PURE;
403 STDMETHOD(get_SourceLink)(BSTR __RPC_FAR *pbstrSourceLink) PURE;
404 STDMETHOD(get_CreationDate)(DATE __RPC_FAR *pCreationDate) PURE;
405 STDMETHOD(get_ErrorCorrection)(BSTR __RPC_FAR *pbstrErrorCorrection) PURE;
406 STDMETHOD(get_Bandwidth)(long __RPC_FAR *pBandwidth) PURE;
407 STDMETHOD(get_SourceProtocol)(long __RPC_FAR *pSourceProtocol) PURE;
408 STDMETHOD(get_ReceivedPackets)(long __RPC_FAR *pReceivedPackets) PURE;
409 STDMETHOD(get_RecoveredPackets)(long __RPC_FAR *pRecoveredPackets) PURE;
410 STDMETHOD(get_LostPackets)(long __RPC_FAR *pLostPackets) PURE;
411 STDMETHOD(get_ReceptionQuality)(long __RPC_FAR *pReceptionQuality) PURE;
412 STDMETHOD(get_BufferingCount)(long __RPC_FAR *pBufferingCount) PURE;
413 STDMETHOD(get_IsBroadcast)(VARIANT_BOOL __RPC_FAR *pIsBroadcast) PURE;
414 STDMETHOD(get_BufferingProgress)(long __RPC_FAR *pBufferingProgress) PURE;
415 STDMETHOD(get_ChannelName)(BSTR __RPC_FAR *pbstrChannelName) PURE;
416 STDMETHOD(get_ChannelDescription)(BSTR __RPC_FAR *pbstrChannelDescription) PURE;
417 STDMETHOD(get_ChannelURL)(BSTR __RPC_FAR *pbstrChannelURL) PURE;
418 STDMETHOD(get_ContactAddress)(BSTR __RPC_FAR *pbstrContactAddress) PURE;
419 STDMETHOD(get_ContactPhone)(BSTR __RPC_FAR *pbstrContactPhone) PURE;
420 STDMETHOD(get_ContactEmail)(BSTR __RPC_FAR *pbstrContactEmail) PURE;
421 STDMETHOD(get_BufferingTime)(double __RPC_FAR *pBufferingTime) PURE;
422 STDMETHOD(put_BufferingTime)(double pBufferingTime) PURE;
423 STDMETHOD(get_AutoStart)(VARIANT_BOOL __RPC_FAR *pAutoStart) PURE;
424 STDMETHOD(put_AutoStart)(VARIANT_BOOL pAutoStart) PURE;
425 STDMETHOD(get_AutoRewind)(VARIANT_BOOL __RPC_FAR *pAutoRewind) PURE;
426 STDMETHOD(put_AutoRewind)(VARIANT_BOOL pAutoRewind) PURE;
427 STDMETHOD(get_Rate)(double __RPC_FAR *pRate) PURE;
428 STDMETHOD(put_Rate)(double pRate) PURE;
429 STDMETHOD(get_SendKeyboardEvents)(VARIANT_BOOL __RPC_FAR *pSendKeyboardEvents) PURE;
430 STDMETHOD(put_SendKeyboardEvents)(VARIANT_BOOL pSendKeyboardEvents) PURE;
431 STDMETHOD(get_SendMouseClickEvents)(VARIANT_BOOL __RPC_FAR *pSendMouseClickEvents) PURE;
432 STDMETHOD(put_SendMouseClickEvents)(VARIANT_BOOL pSendMouseClickEvents) PURE;
433 STDMETHOD(get_SendMouseMoveEvents)(VARIANT_BOOL __RPC_FAR *pSendMouseMoveEvents) PURE;
434 STDMETHOD(put_SendMouseMoveEvents)(VARIANT_BOOL pSendMouseMoveEvents) PURE;
435 STDMETHOD(get_PlayCount)(long __RPC_FAR *pPlayCount) PURE;
436 STDMETHOD(put_PlayCount)(long pPlayCount) PURE;
437 STDMETHOD(get_ClickToPlay)(VARIANT_BOOL __RPC_FAR *pClickToPlay) PURE;
438 STDMETHOD(put_ClickToPlay)(VARIANT_BOOL pClickToPlay) PURE;
439 STDMETHOD(get_AllowScan)(VARIANT_BOOL __RPC_FAR *pAllowScan) PURE;
440 STDMETHOD(put_AllowScan)(VARIANT_BOOL pAllowScan) PURE;
441 STDMETHOD(get_EnableContextMenu)(VARIANT_BOOL __RPC_FAR *pEnableContextMenu) PURE;
442 STDMETHOD(put_EnableContextMenu)(VARIANT_BOOL pEnableContextMenu) PURE;
443 STDMETHOD(get_CursorType)(long __RPC_FAR *pCursorType) PURE;
444 STDMETHOD(put_CursorType)(long pCursorType) PURE;
445 STDMETHOD(get_CodecCount)(long __RPC_FAR *pCodecCount) PURE;
446 STDMETHOD(get_AllowChangeDisplaySize)(VARIANT_BOOL __RPC_FAR *pAllowChangeDisplaySize) PURE;
447 STDMETHOD(put_AllowChangeDisplaySize)( VARIANT_BOOL pAllowChangeDisplaySize) PURE;
448 STDMETHOD(get_IsDurationValid)(VARIANT_BOOL __RPC_FAR *pIsDurationValid) PURE;
449 STDMETHOD(get_OpenState)(long __RPC_FAR *pOpenState) PURE;
450 STDMETHOD(get_SendOpenStateChangeEvents)(VARIANT_BOOL __RPC_FAR *pSendOpenStateChangeEvents) PURE;
451 STDMETHOD(put_SendOpenStateChangeEvents)(VARIANT_BOOL pSendOpenStateChangeEvents) PURE;
452 STDMETHOD(get_SendWarningEvents)( VARIANT_BOOL __RPC_FAR *pSendWarningEvents) PURE;
453 STDMETHOD(put_SendWarningEvents)(VARIANT_BOOL pSendWarningEvents) PURE;
454 STDMETHOD(get_SendErrorEvents)(VARIANT_BOOL __RPC_FAR *pSendErrorEvents) PURE;
455 STDMETHOD(put_SendErrorEvents)(VARIANT_BOOL pSendErrorEvents) PURE;
456 STDMETHOD(get_PlayState)(MPPlayStateConstants __RPC_FAR *pPlayState) PURE;
457 STDMETHOD(get_SendPlayStateChangeEvents)(VARIANT_BOOL __RPC_FAR *pSendPlayStateChangeEvents) PURE;
458 STDMETHOD(put_SendPlayStateChangeEvents)(VARIANT_BOOL pSendPlayStateChangeEvents) PURE;
459 STDMETHOD(get_DisplaySize)(MPDisplaySizeConstants __RPC_FAR *pDisplaySize) PURE;
460 STDMETHOD(put_DisplaySize)(MPDisplaySizeConstants pDisplaySize) PURE;
461 STDMETHOD(get_InvokeURLs)(VARIANT_BOOL __RPC_FAR *pInvokeURLs) PURE;
462 STDMETHOD(put_InvokeURLs)(VARIANT_BOOL pInvokeURLs) PURE;
463 STDMETHOD(get_BaseURL)(BSTR __RPC_FAR *pbstrBaseURL) PURE;
464 STDMETHOD(put_BaseURL)(BSTR pbstrBaseURL) PURE;
465 STDMETHOD(get_DefaultFrame)(BSTR __RPC_FAR *pbstrDefaultFrame) PURE;
466 STDMETHOD(put_DefaultFrame)(BSTR pbstrDefaultFrame) PURE;
467 STDMETHOD(get_HasError)(VARIANT_BOOL __RPC_FAR *pHasError) PURE;
468 STDMETHOD(get_ErrorDescription)(BSTR __RPC_FAR *pbstrErrorDescription) PURE;
469 STDMETHOD(get_ErrorCode)(long __RPC_FAR *pErrorCode) PURE;
470 STDMETHOD(get_AnimationAtStart)(VARIANT_BOOL __RPC_FAR *pAnimationAtStart) PURE;
471 STDMETHOD(put_AnimationAtStart)(VARIANT_BOOL pAnimationAtStart) PURE;
472 STDMETHOD(get_TransparentAtStart)( VARIANT_BOOL __RPC_FAR *pTransparentAtStart) PURE;
473 STDMETHOD(put_TransparentAtStart)(VARIANT_BOOL pTransparentAtStart) PURE;
474 STDMETHOD(get_Volume)(long __RPC_FAR *pVolume) PURE;
475 STDMETHOD(put_Volume)(long pVolume) PURE;
476 STDMETHOD(get_Balance)(long __RPC_FAR *pBalance) PURE;
477 STDMETHOD(put_Balance)(long pBalance) PURE;
478 STDMETHOD(get_ReadyState)(MPReadyStateConstants __RPC_FAR *pValue) PURE;
479 STDMETHOD(get_SelectionStart)(double __RPC_FAR *pValue) PURE;
480 STDMETHOD(put_SelectionStart)(double pValue) PURE;
481 STDMETHOD(get_SelectionEnd)(double __RPC_FAR *pValue) PURE;
482 STDMETHOD(put_SelectionEnd)(double pValue) PURE;
483 STDMETHOD(get_ShowDisplay)(VARIANT_BOOL __RPC_FAR *Show) PURE;
484 STDMETHOD(put_ShowDisplay)(VARIANT_BOOL Show) PURE;
485 STDMETHOD(get_ShowControls)(VARIANT_BOOL __RPC_FAR *Show) PURE;
486 STDMETHOD(put_ShowControls)(VARIANT_BOOL Show) PURE;
487 STDMETHOD(get_ShowPositionControls)(VARIANT_BOOL __RPC_FAR *Show) PURE;
488 STDMETHOD(put_ShowPositionControls)(VARIANT_BOOL Show) PURE;
489 STDMETHOD(get_ShowTracker)(VARIANT_BOOL __RPC_FAR *Show) PURE;
490 STDMETHOD(put_ShowTracker)(VARIANT_BOOL Show) PURE;
491 STDMETHOD(get_EnablePositionControls)(VARIANT_BOOL __RPC_FAR *Enable) PURE;
492 STDMETHOD(put_EnablePositionControls)(VARIANT_BOOL Enable) PURE;
493 STDMETHOD(get_EnableTracker)(VARIANT_BOOL __RPC_FAR *Enable) PURE;
494 STDMETHOD(put_EnableTracker)(VARIANT_BOOL Enable) PURE;
495 STDMETHOD(get_Enabled)(VARIANT_BOOL __RPC_FAR *pEnabled) PURE;
496 STDMETHOD(put_Enabled)(VARIANT_BOOL pEnabled) PURE;
497 STDMETHOD(get_DisplayForeColor)(VB_OLE_COLOR __RPC_FAR *ForeColor) PURE;
498 STDMETHOD(put_DisplayForeColor)(VB_OLE_COLOR ForeColor) PURE;
499 STDMETHOD(get_DisplayBackColor)(VB_OLE_COLOR __RPC_FAR *BackColor) PURE;
500 STDMETHOD(put_DisplayBackColor)(VB_OLE_COLOR BackColor) PURE;
501 STDMETHOD(get_DisplayMode)(MPDisplayModeConstants __RPC_FAR *pValue) PURE;
502 STDMETHOD(put_DisplayMode)(MPDisplayModeConstants pValue) PURE;
503 STDMETHOD(get_VideoBorder3D)(VARIANT_BOOL __RPC_FAR *pVideoBorderWidth) PURE;
504 STDMETHOD(put_VideoBorder3D)(VARIANT_BOOL pVideoBorderWidth) PURE;
505 STDMETHOD(get_VideoBorderWidth)(long __RPC_FAR *pVideoBorderWidth) PURE;
506 STDMETHOD(put_VideoBorderWidth)(long pVideoBorderWidth) PURE;
507 STDMETHOD(get_VideoBorderColor)(VB_OLE_COLOR __RPC_FAR *pVideoBorderWidth) PURE;
508 STDMETHOD(put_VideoBorderColor)(VB_OLE_COLOR pVideoBorderWidth) PURE;
509 STDMETHOD(get_ShowGotoBar)(VARIANT_BOOL __RPC_FAR *pbool) PURE;
510 STDMETHOD(put_ShowGotoBar)(VARIANT_BOOL pbool) PURE;
511 STDMETHOD(get_ShowStatusBar)(VARIANT_BOOL __RPC_FAR *pbool) PURE;
512 STDMETHOD(put_ShowStatusBar)(VARIANT_BOOL pbool) PURE;
513 STDMETHOD(get_ShowCaptioning)(VARIANT_BOOL __RPC_FAR *pbool) PURE;
514 STDMETHOD(put_ShowCaptioning)(VARIANT_BOOL pbool) PURE;
515 STDMETHOD(get_ShowAudioControls)(VARIANT_BOOL __RPC_FAR *pbool) PURE;
516 STDMETHOD(put_ShowAudioControls)(VARIANT_BOOL pbool) PURE;
517 STDMETHOD(get_CaptioningID)( BSTR __RPC_FAR *pstrText) PURE;
518 STDMETHOD(put_CaptioningID)(BSTR pstrText) PURE;
519 STDMETHOD(get_Mute)(VARIANT_BOOL __RPC_FAR *vbool) PURE;
520 STDMETHOD(put_Mute)(VARIANT_BOOL vbool) PURE;
521 STDMETHOD(get_CanPreview)(VARIANT_BOOL __RPC_FAR *pCanPreview) PURE;
522 STDMETHOD(get_PreviewMode)(VARIANT_BOOL __RPC_FAR *pPreviewMode) PURE;
523 STDMETHOD(put_PreviewMode)(VARIANT_BOOL pPreviewMode) PURE;
524 STDMETHOD(get_HasMultipleItems)(VARIANT_BOOL __RPC_FAR *pHasMuliItems) PURE;
525 STDMETHOD(get_Language)(long __RPC_FAR *pLanguage) PURE;
526 STDMETHOD(put_Language)(long pLanguage) PURE;
527 STDMETHOD(get_AudioStream)(long __RPC_FAR *pStream) PURE;
528 STDMETHOD(put_AudioStream)(long pStream) PURE;
529 STDMETHOD(get_SAMIStyle)(BSTR __RPC_FAR *pbstrStyle) PURE;
530 STDMETHOD(put_SAMIStyle)(BSTR pbstrStyle) PURE;
531 STDMETHOD(get_SAMILang)(BSTR __RPC_FAR *pbstrLang) PURE;
532 STDMETHOD(put_SAMILang)(BSTR pbstrLang) PURE;
533 STDMETHOD(get_SAMIFileName)(BSTR __RPC_FAR *pbstrFileName) PURE;
534 STDMETHOD(put_SAMIFileName)(BSTR pbstrFileName) PURE;
535 STDMETHOD(get_StreamCount)( long __RPC_FAR *pStreamCount) PURE;
536 STDMETHOD(get_ClientId)(BSTR __RPC_FAR *pbstrClientId) PURE;
537 STDMETHOD(get_ConnectionSpeed)(long __RPC_FAR *plConnectionSpeed) PURE;
538 STDMETHOD(get_AutoSize)(VARIANT_BOOL __RPC_FAR *pbool) PURE;
539 STDMETHOD(put_AutoSize)(VARIANT_BOOL pbool) PURE;
540 STDMETHOD(get_EnableFullScreenControls)(VARIANT_BOOL __RPC_FAR *pbVal) PURE;
541 STDMETHOD(put_EnableFullScreenControls)(VARIANT_BOOL pbVal) PURE;
542 STDMETHOD(get_ActiveMovie)(IDispatch __RPC_FAR *__RPC_FAR *ppdispatch) PURE;
543 STDMETHOD(get_NSPlay)(IDispatch __RPC_FAR *__RPC_FAR *ppdispatch) PURE;
544 STDMETHOD(get_WindowlessVideo)(VARIANT_BOOL __RPC_FAR *pbool) PURE;
545 STDMETHOD(put_WindowlessVideo)(VARIANT_BOOL pbool) PURE;
546 STDMETHOD(Play)(void) PURE;
547 STDMETHOD(Stop)(void) PURE;
548 STDMETHOD(Pause)(void) PURE;
549 STDMETHOD(GetMarkerTime)(long MarkerNum,
550 double __RPC_FAR *pMarkerTime) PURE;
551 STDMETHOD(GetMarkerName)(long MarkerNum,
552 BSTR __RPC_FAR *pbstrMarkerName) PURE;
553 STDMETHOD(AboutBox)(void) PURE;
554 STDMETHOD(GetCodecInstalled)(long CodecNum,
555 VARIANT_BOOL __RPC_FAR *pCodecInstalled) PURE;
556 STDMETHOD(GetCodecDescription)(long CodecNum,
557 BSTR __RPC_FAR *pbstrCodecDescription) PURE;
558 STDMETHOD(GetCodecURL)(long CodecNum,
559 BSTR __RPC_FAR *pbstrCodecURL) PURE;
560 STDMETHOD(GetMoreInfoURL)(MPMoreInfoType MoreInfoType,
561 BSTR __RPC_FAR *pbstrMoreInfoURL) PURE;
562 STDMETHOD(GetMediaInfoString)(MPMediaInfoType MediaInfoType,
563 BSTR __RPC_FAR *pbstrMediaInfo) PURE;
564 STDMETHOD(Cancel)(void) PURE;
565 STDMETHOD(Open)(BSTR bstrFileName) PURE;
566 STDMETHOD(IsSoundCardEnabled)(VARIANT_BOOL __RPC_FAR *pbSoundCard) PURE;
567 STDMETHOD(Next)(void) PURE;
568 STDMETHOD(Previous)(void) PURE;
569 STDMETHOD(StreamSelect)(long StreamNum) PURE;
570 STDMETHOD(FastForward)(void) PURE;
571 STDMETHOD(FastReverse)(void) PURE;
572 STDMETHOD(GetStreamName)(long StreamNum,
573 BSTR __RPC_FAR *pbstrStreamName) PURE;
574 STDMETHOD(GetStreamGroup)(long StreamNum,
575 long __RPC_FAR *pStreamGroup) PURE;
576 STDMETHOD(GetStreamSelected)(long StreamNum, VARIANT_BOOL __RPC_FAR *pStreamSelected) PURE;
577 };
578
579 struct IMediaPlayer2 : public IMediaPlayer
580 {
581 STDMETHOD(get_DVD)(struct IMediaPlayerDvd __RPC_FAR *__RPC_FAR *ppdispatch) PURE;
582 STDMETHOD(GetMediaParameter)(long EntryNum, BSTR bstrParameterName, BSTR __RPC_FAR *pbstrParameterValue) PURE;
583 STDMETHOD(GetMediaParameterName(long EntryNum, long Index, BSTR __RPC_FAR *pbstrParameterName) PURE;
584 STDMETHOD(get_EntryCount)(long __RPC_FAR *pNumberEntries) PURE;
585 STDMETHOD(GetCurrentEntry)(long __RPC_FAR *pEntryNumber) PURE;
586 STDMETHOD(SetCurrentEntry)(long EntryNumber) PURE;
587 STDMETHOD(ShowDialog)(MPShowDialogConstants mpDialogIndex) PURE;
588 };
589
590 //---------------------------------------------------------------------------
591 // NETSHOW COM INTERFACES (dumped from nscompat.idl from MSVC COM Browser)
592 //---------------------------------------------------------------------------
593
594 struct INSOPlay : public IDispatch
595 {
596 STDMETHOD(get_ImageSourceWidth)(long __RPC_FAR *pWidth) PURE;
597 STDMETHOD(get_ImageSourceHeight)(long __RPC_FAR *pHeight) PURE;
598 STDMETHOD(get_Duration)(double __RPC_FAR *pDuration) PURE;
599 STDMETHOD(get_Author)(BSTR __RPC_FAR *pbstrAuthor) PURE;
600 STDMETHOD(get_Copyright)(BSTR __RPC_FAR *pbstrCopyright) PURE;
601 STDMETHOD(get_Description)(BSTR __RPC_FAR *pbstrDescription) PURE;
602 STDMETHOD(get_Rating)(BSTR __RPC_FAR *pbstrRating) PURE;
603 STDMETHOD(get_Title)(BSTR __RPC_FAR *pbstrTitle) PURE;
604 STDMETHOD(get_SourceLink)(BSTR __RPC_FAR *pbstrSourceLink) PURE;
605 STDMETHOD(get_MarkerCount)(long __RPC_FAR *pMarkerCount) PURE;
606 STDMETHOD(get_CanScan)(VARIANT_BOOL __RPC_FAR *pCanScan) PURE;
607 STDMETHOD(get_CanSeek)(VARIANT_BOOL __RPC_FAR *pCanSeek) PURE;
608 STDMETHOD(get_CanSeekToMarkers)(VARIANT_BOOL __RPC_FAR *pCanSeekToMarkers) PURE;
609 STDMETHOD(get_CreationDate)(DATE __RPC_FAR *pCreationDate) PURE;
610 STDMETHOD(get_Bandwidth)(long __RPC_FAR *pBandwidth) PURE;
611 STDMETHOD(get_ErrorCorrection)(BSTR __RPC_FAR *pbstrErrorCorrection) PURE;
612 STDMETHOD(get_AutoStart)(VARIANT_BOOL __RPC_FAR *pAutoStart) PURE;
613 STDMETHOD(put_AutoStart)(VARIANT_BOOL pAutoStart) PURE;
614 STDMETHOD(get_AutoRewind)(VARIANT_BOOL __RPC_FAR *pAutoRewind) PURE;
615 STDMETHOD(put_AutoRewind)(VARIANT_BOOL pAutoRewind) PURE;
616 STDMETHOD(get_AllowChangeControlType)(VARIANT_BOOL __RPC_FAR *pAllowChangeControlType) PURE;
617 STDMETHOD(put_AllowChangeControlType)(VARIANT_BOOL pAllowChangeControlType) PURE;
618 STDMETHOD(get_InvokeURLs)(VARIANT_BOOL __RPC_FAR *pInvokeURLs) PURE;
619 STDMETHOD(put_InvokeURLs)(VARIANT_BOOL pInvokeURLs) PURE;
620 STDMETHOD(get_EnableContextMenu)(VARIANT_BOOL __RPC_FAR *pEnableContextMenu) PURE;
621 STDMETHOD(put_EnableContextMenu)(VARIANT_BOOL pEnableContextMenu) PURE;
622 STDMETHOD(get_TransparentAtStart)(VARIANT_BOOL __RPC_FAR *pTransparentAtStart) PURE;
623 STDMETHOD(put_TransparentAtStart)(VARIANT_BOOL pTransparentAtStart) PURE;
624 STDMETHOD(get_TransparentOnStop)(VARIANT_BOOL __RPC_FAR *pTransparentOnStop) PURE;
625 STDMETHOD(put_TransparentOnStop)(VARIANT_BOOL pTransparentOnStop) PURE;
626 STDMETHOD(get_ClickToPlay)(VARIANT_BOOL __RPC_FAR *pClickToPlay) PURE;
627 STDMETHOD(put_ClickToPlay)(VARIANT_BOOL pClickToPlay) PURE;
628 STDMETHOD(get_FileName)(BSTR __RPC_FAR *pbstrFileName) PURE;
629 STDMETHOD(put_FileName)(BSTR pbstrFileName) PURE;
630 STDMETHOD(get_CurrentPosition)(double __RPC_FAR *pCurrentPosition) PURE;
631 STDMETHOD(put_CurrentPosition)(double pCurrentPosition) PURE;
632 STDMETHOD(get_Rate)(double __RPC_FAR *pRate) PURE;
633 STDMETHOD(put_Rate)(double pRate) PURE;
634 STDMETHOD(get_CurrentMarker)(long __RPC_FAR *pCurrentMarker) PURE;
635 STDMETHOD(put_CurrentMarker)(long pCurrentMarker) PURE;
636 STDMETHOD(get_PlayCount)(long __RPC_FAR *pPlayCount) PURE;
637 STDMETHOD(put_PlayCount)(long pPlayCount) PURE;
638 STDMETHOD(get_CurrentState)(long __RPC_FAR *pCurrentState) PURE;
639 STDMETHOD(get_DisplaySize)(long __RPC_FAR *pDisplaySize) PURE;
640 STDMETHOD(put_DisplaySize)(long pDisplaySize) PURE;
641 STDMETHOD(get_MainWindow)(long __RPC_FAR *pMainWindow) PURE;
642 STDMETHOD(get_ControlType)(long __RPC_FAR *pControlType) PURE;
643 STDMETHOD(put_ControlType)(long pControlType) PURE;
644 STDMETHOD(get_AllowScan)(VARIANT_BOOL __RPC_FAR *pAllowScan) PURE;
645 STDMETHOD(put_AllowScan)(VARIANT_BOOL pAllowScan) PURE;
646 STDMETHOD(get_SendKeyboardEvents)(VARIANT_BOOL __RPC_FAR *pSendKeyboardEvents) PURE;
647 STDMETHOD(put_SendKeyboardEvents)(VARIANT_BOOL pSendKeyboardEvents) PURE;
648 STDMETHOD(get_SendMouseClickEvents)(VARIANT_BOOL __RPC_FAR *pSendMouseClickEvents) PURE;
649 STDMETHOD(put_SendMouseClickEvents)(VARIANT_BOOL pSendMouseClickEvents) PURE;
650 STDMETHOD(get_SendMouseMoveEvents)(VARIANT_BOOL __RPC_FAR *pSendMouseMoveEvents) PURE;
651 STDMETHOD(put_SendMouseMoveEvents)(VARIANT_BOOL pSendMouseMoveEvents) PURE;
652 STDMETHOD(get_SendStateChangeEvents)(VARIANT_BOOL __RPC_FAR *pSendStateChangeEvents) PURE;
653 STDMETHOD(put_SendStateChangeEvents)(VARIANT_BOOL pSendStateChangeEvents) PURE;
654 STDMETHOD(get_ReceivedPackets)(long __RPC_FAR *pReceivedPackets) PURE;
655 STDMETHOD(get_RecoveredPackets)(long __RPC_FAR *pRecoveredPackets) PURE;
656 STDMETHOD(get_LostPackets)(long __RPC_FAR *pLostPackets) PURE;
657 STDMETHOD(get_ReceptionQuality)(long __RPC_FAR *pReceptionQuality) PURE;
658 STDMETHOD(get_BufferingCount)(long __RPC_FAR *pBufferingCount) PURE;
659 STDMETHOD(get_CursorType)(long __RPC_FAR *pCursorType) PURE;
660 STDMETHOD(put_CursorType)(long pCursorType) PURE;
661 STDMETHOD(get_AnimationAtStart)(VARIANT_BOOL __RPC_FAR *pAnimationAtStart) PURE;
662 STDMETHOD(put_AnimationAtStart)(VARIANT_BOOL pAnimationAtStart) PURE;
663 STDMETHOD(get_AnimationOnStop)(VARIANT_BOOL __RPC_FAR *pAnimationOnStop) PURE;
664 STDMETHOD(put_AnimationOnStop)(VARIANT_BOOL pAnimationOnStop) PURE;
665 STDMETHOD(Play)(void) PURE;
666 STDMETHOD(Pause)(void) PURE;
667 STDMETHOD(Stop)(void) PURE;
668 STDMETHOD(GetMarkerTime)(long MarkerNum, double __RPC_FAR *pMarkerTime) PURE;
669 STDMETHOD(GetMarkerName)(long MarkerNum, BSTR __RPC_FAR *pbstrMarkerName) PURE;
670 };
671
672 struct INSPlay : public INSOPlay
673 {
674 STDMETHOD(get_ChannelName)(BSTR __RPC_FAR *pbstrChannelName) PURE;
675 STDMETHOD(get_ChannelDescription)(BSTR __RPC_FAR *pbstrChannelDescription) PURE;
676 STDMETHOD(get_ChannelURL)(BSTR __RPC_FAR *pbstrChannelURL) PURE;
677 STDMETHOD(get_ContactAddress)(BSTR __RPC_FAR *pbstrContactAddress) PURE;
678 STDMETHOD(get_ContactPhone)(BSTR __RPC_FAR *pbstrContactPhone) PURE;
679 STDMETHOD(get_ContactEmail)(BSTR __RPC_FAR *pbstrContactEmail) PURE;
680 STDMETHOD(get_AllowChangeDisplaySize)(VARIANT_BOOL __RPC_FAR *pAllowChangeDisplaySize) PURE;
681 STDMETHOD(put_AllowChangeDisplaySize)(VARIANT_BOOL pAllowChangeDisplaySize) PURE;
682 STDMETHOD(get_CodecCount)(long __RPC_FAR *pCodecCount) PURE;
683 STDMETHOD(get_IsBroadcast)(VARIANT_BOOL __RPC_FAR *pIsBroadcast) PURE;
684 STDMETHOD(get_IsDurationValid)(VARIANT_BOOL __RPC_FAR *pIsDurationValid) PURE;
685 STDMETHOD(get_SourceProtocol)(long __RPC_FAR *pSourceProtocol) PURE;
686 STDMETHOD(get_OpenState)(long __RPC_FAR *pOpenState) PURE;
687 STDMETHOD(get_SendOpenStateChangeEvents)(VARIANT_BOOL __RPC_FAR *pSendOpenStateChangeEvents) PURE;
688 STDMETHOD(put_SendOpenStateChangeEvents)(VARIANT_BOOL pSendOpenStateChangeEvents) PURE;
689 STDMETHOD(get_SendWarningEvents)(VARIANT_BOOL __RPC_FAR *pSendWarningEvents) PURE;
690 STDMETHOD(put_SendWarningEvents)(VARIANT_BOOL pSendWarningEvents) PURE;
691 STDMETHOD(get_SendErrorEvents)(VARIANT_BOOL __RPC_FAR *pSendErrorEvents) PURE;
692 STDMETHOD(put_SendErrorEvents)(VARIANT_BOOL pSendErrorEvents) PURE;
693 STDMETHOD(get_HasError)(VARIANT_BOOL __RPC_FAR *pHasError) PURE;
694 STDMETHOD(get_ErrorDescription)(BSTR __RPC_FAR *pbstrErrorDescription) PURE;
695 STDMETHOD(get_ErrorCode)(long __RPC_FAR *pErrorCode) PURE;
696 STDMETHOD(get_PlayState)(long __RPC_FAR *pPlayState) PURE;
697 STDMETHOD(get_SendPlayStateChangeEvents)(VARIANT_BOOL __RPC_FAR *pSendPlayStateChangeEvents) PURE;
698 STDMETHOD(put_SendPlayStateChangeEvents)(VARIANT_BOOL pSendPlayStateChangeEvents) PURE;
699 STDMETHOD(get_BufferingTime)(double __RPC_FAR *pBufferingTime) PURE;
700 STDMETHOD(put_BufferingTime)(double pBufferingTime) PURE;
701 STDMETHOD(get_UseFixedUDPPort)(VARIANT_BOOL __RPC_FAR *pUseFixedUDPPort) PURE;
702 STDMETHOD(put_UseFixedUDPPort)(VARIANT_BOOL pUseFixedUDPPort) PURE;
703 STDMETHOD(get_FixedUDPPort)(long __RPC_FAR *pFixedUDPPort) PURE;
704 STDMETHOD(put_FixedUDPPort)(long pFixedUDPPort) PURE;
705 STDMETHOD(get_UseHTTPProxy)(VARIANT_BOOL __RPC_FAR *pUseHTTPProxy) PURE;
706 STDMETHOD(put_UseHTTPProxy)(VARIANT_BOOL pUseHTTPProxy) PURE;
707 STDMETHOD(get_EnableAutoProxy)(VARIANT_BOOL __RPC_FAR *pEnableAutoProxy) PURE;
708 STDMETHOD(put_EnableAutoProxy)(VARIANT_BOOL pEnableAutoProxy) PURE;
709 STDMETHOD(get_HTTPProxyHost)(BSTR __RPC_FAR *pbstrHTTPProxyHost) PURE;
710 STDMETHOD(put_HTTPProxyHost)(BSTR pbstrHTTPProxyHost) PURE;
711 STDMETHOD(get_HTTPProxyPort)(long __RPC_FAR *pHTTPProxyPort) PURE;
712 STDMETHOD(put_HTTPProxyPort)(long pHTTPProxyPort) PURE;
713 STDMETHOD(get_EnableMulticast)(VARIANT_BOOL __RPC_FAR *pEnableMulticast) PURE;
714 STDMETHOD(put_EnableMulticast)(VARIANT_BOOL pEnableMulticast) PURE;
715 STDMETHOD(get_EnableUDP)(VARIANT_BOOL __RPC_FAR *pEnableUDP) PURE;
716 STDMETHOD(put_EnableUDP)(VARIANT_BOOL pEnableUDP) PURE;
717 STDMETHOD(get_EnableTCP)(VARIANT_BOOL __RPC_FAR *pEnableTCP) PURE;
718 STDMETHOD(put_EnableTCP)(VARIANT_BOOL pEnableTCP) PURE;
719 STDMETHOD(get_EnableHTTP)(VARIANT_BOOL __RPC_FAR *pEnableHTTP) PURE;
720 STDMETHOD(put_EnableHTTP)(VARIANT_BOOL pEnableHTTP) PURE;
721 STDMETHOD(get_BufferingProgress)(long __RPC_FAR *pBufferingProgress) PURE;
722 STDMETHOD(get_BaseURL)(BSTR __RPC_FAR *pbstrBaseURL) PURE;
723 STDMETHOD(put_BaseURL)(BSTR pbstrBaseURL) PURE;
724 STDMETHOD(get_DefaultFrame)(BSTR __RPC_FAR *pbstrDefaultFrame) PURE;
725 STDMETHOD(put_DefaultFrame)(BSTR pbstrDefaultFrame) PURE;
726 STDMETHOD(AboutBox))(void) PURE;
727 STDMETHOD(Cancel)(void) PURE;
728 STDMETHOD(GetCodecInstalled)(long CodecNum, VARIANT_BOOL __RPC_FAR *pCodecInstalled) PURE;
729 STDMETHOD(GetCodecDescription)(long CodecNum, BSTR __RPC_FAR *pbstrCodecDescription) PURE;
730 STDMETHOD(GetCodecURL)(long CodecNum, BSTR __RPC_FAR *pbstrCodecURL) PURE;
731 STDMETHOD(Open)(BSTR bstrFileName) PURE;
732 };
733
734
735 struct INSPlay1 : public INSPlay
736 {
737 STDMETHOD(get_MediaPlayer)(IDispatch __RPC_FAR *__RPC_FAR *ppdispatch) PURE;
738 };
739
740 //---------------------------------------------------------------------------
741 // MISC COM INTERFACES
742 //---------------------------------------------------------------------------
743 typedef enum _FilterState
744 {
745 State_Stopped,
746 State_Paused,
747 State_Running
748 }
749 FILTER_STATE;
750
751 typedef enum _PinDirection
752 {
753 PINDIR_INPUT,
754 PINDIR_OUTPUT
755 }
756 PIN_DIRECTION;
757
758 typedef struct _FilterInfo
759 {
760 WCHAR achName[128];
761 struct IFilterGraph *pGraph;
762 }
763 FILTER_INFO;
764
765 typedef struct _PinInfo
766 {
767 struct IBaseFilter *pFilter;
768 PIN_DIRECTION dir;
769 WCHAR achName[128];
770 }
771 PIN_INFO;
772
773 struct IBaseFilter;
774 struct IPin;
775 struct IEnumFilters;
776 typedef struct _MediaType
777 {
778 GUID majortype;
779 GUID subtype;
780 BOOL bFixedSizeSamples;
781 BOOL bTemporalCompression;
782 ULONG lSampleSize;
783 GUID formattype;
784 IUnknown *pUnk;
785 ULONG cbFormat;
786 BYTE *pbFormat;
787 }
788 AM_MEDIA_TYPE;
789
790 struct IFilterGraph : public IUnknown
791 {
792 STDMETHOD(AddFilter)(IBaseFilter *, LPCWSTR) PURE;
793 STDMETHOD(RemoveFilter)(IBaseFilter *) PURE;
794 STDMETHOD(EnumFilters)(IEnumFilters **) PURE;
795 STDMETHOD(FindFilterByName)(LPCWSTR, IBaseFilter **) PURE;
796 STDMETHOD(ConnectDirect)(IPin *, IPin *, const AM_MEDIA_TYPE *) PURE;
797 STDMETHOD(Reconnect)(IPin *) PURE;
798 STDMETHOD(Disconnect)(IPin *) PURE;
799 STDMETHOD(SetDefaultSyncSource)() PURE;
800 };
801
802 struct IGraphBuilder : public IFilterGraph
803 {
804 STDMETHOD(Connect)(IPin *, IPin *) PURE;
805 STDMETHOD(Render)(IPin *) PURE;
806 STDMETHOD(RenderFile)(LPCWSTR, LPCWSTR) PURE;
807 STDMETHOD(AddSourceFilter)(LPCWSTR, LPCWSTR, IBaseFilter **) PURE;
808 STDMETHOD(SetLogFile)(DWORD_PTR) PURE;
809 STDMETHOD(Abort)() PURE;
810 STDMETHOD(ShouldOperationContinue)() PURE;
811 };
812
813 struct IReferenceClock;
814 struct IEnumPins;
815 #define REFERENCE_TIME LONGLONG
816 struct IMediaFilter : public IPersist
817 {
818 STDMETHOD(Stop)( void) PURE;
819 STDMETHOD(Pause)( void) PURE;
820 STDMETHOD(Run)(REFERENCE_TIME tStart) PURE;
821 STDMETHOD(GetState)(DWORD dwMilliSecsTimeout,
822 FILTER_STATE *State) PURE;
823 STDMETHOD(SetSyncSource)(IReferenceClock *pClock) PURE;
824 STDMETHOD(GetSyncSource)(IReferenceClock **pClock) PURE;
825 };
826
827 struct IBaseFilter : public IMediaFilter
828 {
829 STDMETHOD(EnumPins)(IEnumPins **ppEnum) PURE;
830 STDMETHOD(FindPin)(LPCWSTR Id, IPin **ppPin) PURE;
831 STDMETHOD(QueryFilterInfo)(FILTER_INFO *pInfo) PURE;
832 STDMETHOD(JoinFilterGraph)(IFilterGraph *pGraph, LPCWSTR pName) PURE;
833 STDMETHOD(QueryVendorInfo)(LPWSTR *pVendorInfo) PURE;
834 };
835
836
837 //---------------------------------------------------------------------------
838 // wxAMMediaBackend
839 //---------------------------------------------------------------------------
840
841 typedef BOOL (WINAPI* LPAMGETERRORTEXT)(HRESULT, wxChar *, DWORD);
842
843 class WXDLLIMPEXP_MEDIA wxAMMediaBackend : public wxMediaBackendCommonBase
844 {
845 public:
846 wxAMMediaBackend();
847 virtual ~wxAMMediaBackend();
848 void Clear();
849
850 virtual bool CreateControl(wxControl* ctrl, wxWindow* parent,
851 wxWindowID id,
852 const wxPoint& pos,
853 const wxSize& size,
854 long style,
855 const wxValidator& validator,
856 const wxString& name);
857
858 virtual bool Play();
859 virtual bool Pause();
860 virtual bool Stop();
861
862 virtual bool Load(const wxString& fileName);
863 virtual bool Load(const wxURI& location);
864 virtual bool Load(const wxURI& location, const wxURI& proxy);
865
866 bool DoLoad(const wxString& location);
867 void FinishLoad();
868
869 virtual wxMediaState GetState();
870
871 virtual bool SetPosition(wxLongLong where);
872 virtual wxLongLong GetPosition();
873 virtual wxLongLong GetDuration();
874
875 virtual void Move(int x, int y, int w, int h);
876 wxSize GetVideoSize() const;
877
878 virtual double GetPlaybackRate();
879 virtual bool SetPlaybackRate(double);
880
881 virtual double GetVolume();
882 virtual bool SetVolume(double);
883
884 virtual bool ShowPlayerControls(wxMediaCtrlPlayerControls flags);
885 void Cleanup();
886
887 void DoGetDownloadProgress(wxLongLong*, wxLongLong*);
888
889 virtual wxLongLong GetDownloadProgress()
890 {
891 wxLongLong progress, total;
892 DoGetDownloadProgress(&progress, &total);
893 return progress;
894 }
895
896 virtual wxLongLong GetDownloadTotal()
897 {
898 wxLongLong progress, total;
899 DoGetDownloadProgress(&progress, &total);
900 return total;
901 }
902
903 wxActiveXContainer* m_pAX;
904 IActiveMovie* m_pAM;
905 IMediaPlayer* m_pMP;
906 wxTimer* m_pTimer;
907 wxSize m_bestSize;
908
909 #ifdef __WXDEBUG__
910 wxDynamicLibrary m_dllQuartz;
911 LPAMGETERRORTEXT m_lpAMGetErrorText;
912 wxString GetErrorString(HRESULT hrdsv);
913 #endif
914
915 DECLARE_DYNAMIC_CLASS(wxAMMediaBackend)
916 };
917
918 //---------------------------------------------------------------------------
919 //
920 // wxMCIMediaBackend
921 //
922 //---------------------------------------------------------------------------
923
924 //---------------------------------------------------------------------------
925 // MCI Includes
926 //---------------------------------------------------------------------------
927 #ifndef __WXWINCE__
928 #include <mmsystem.h>
929
930 class WXDLLIMPEXP_MEDIA wxMCIMediaBackend : public wxMediaBackendCommonBase
931 {
932 public:
933
934 wxMCIMediaBackend();
935 ~wxMCIMediaBackend();
936
937 virtual bool CreateControl(wxControl* ctrl, wxWindow* parent,
938 wxWindowID id,
939 const wxPoint& pos,
940 const wxSize& size,
941 long style,
942 const wxValidator& validator,
943 const wxString& name);
944
945 virtual bool Play();
946 virtual bool Pause();
947 virtual bool Stop();
948
949 virtual bool Load(const wxURI& location,
950 const wxURI& proxy)
951 { return wxMediaBackend::Load(location, proxy); }
952
953 virtual bool Load(const wxString& fileName);
954 virtual bool Load(const wxURI& location);
955
956 virtual wxMediaState GetState();
957
958 virtual bool SetPosition(wxLongLong where);
959 virtual wxLongLong GetPosition();
960 virtual wxLongLong GetDuration();
961
962 virtual void Move(int x, int y, int w, int h);
963 wxSize GetVideoSize() const;
964
965 virtual double GetPlaybackRate();
966 virtual bool SetPlaybackRate(double dRate);
967
968 virtual double GetVolume();
969 virtual bool SetVolume(double);
970
971 static LRESULT CALLBACK NotifyWndProc(HWND hWnd, UINT nMsg,
972 WPARAM wParam, LPARAM lParam);
973
974 LRESULT CALLBACK OnNotifyWndProc(HWND hWnd, UINT nMsg,
975 WPARAM wParam, LPARAM lParam);
976
977 MCIDEVICEID m_hDev; //Our MCI Device ID/Handler
978 HWND m_hNotifyWnd; //Window to use for MCI events
979 bool m_bVideo; //Whether or not we have video
980
981 DECLARE_DYNAMIC_CLASS(wxMCIMediaBackend)
982 };
983 #endif
984
985 //---------------------------------------------------------------------------
986 //
987 // wxQTMediaBackend
988 //
989 // We don't include Quicktime headers here and define all the types
990 // ourselves because looking for the quicktime libaries etc. would
991 // be tricky to do and making this a dependency for the MSVC projects
992 // would be unrealistic.
993 //
994 // Thanks to Robert Roebling for the wxDL macro/library idea
995 //---------------------------------------------------------------------------
996
997 //---------------------------------------------------------------------------
998 // QT Includes
999 //---------------------------------------------------------------------------
1000 //#include <qtml.h> //Windoze QT include
1001 //#include <QuickTimeComponents.h> //Standard QT stuff
1002 #include "wx/dynlib.h"
1003
1004 //---------------------------------------------------------------------------
1005 // QT Types
1006 //---------------------------------------------------------------------------
1007 typedef struct MovieRecord* Movie;
1008 typedef wxInt16 OSErr;
1009 typedef wxInt32 OSStatus;
1010 #define noErr 0
1011 #define fsRdPerm 1
1012 typedef unsigned char Str255[256];
1013 #define StringPtr unsigned char*
1014 #define newMovieActive 1
1015 #define newMovieAsyncOK (1 << 8)
1016 #define Ptr char*
1017 #define Handle Ptr*
1018 #define Fixed long
1019 #define OSType unsigned long
1020 #define CGrafPtr struct GrafPort *
1021 #define TimeScale long
1022 #define TimeBase struct TimeBaseRecord *
1023 typedef struct ComponentInstanceRecord * ComponentInstance;
1024 #define kMovieLoadStatePlayable 10000
1025 #define Boolean int
1026 #define MovieController ComponentInstance
1027
1028 #ifndef URLDataHandlerSubType
1029 #if defined(__WATCOMC__) || defined(__MINGW32__)
1030 // use magic numbers for compilers which complain about multicharacter integers
1031 const OSType URLDataHandlerSubType = 1970433056;
1032 const OSType VisualMediaCharacteristic = 1702454643;
1033 #else
1034 const OSType URLDataHandlerSubType = 'url ';
1035 const OSType VisualMediaCharacteristic = 'eyes';
1036 #endif
1037 #endif
1038
1039 struct FSSpec
1040 {
1041 short vRefNum;
1042 long parID;
1043 Str255 name; // Str63 on mac, Str255 on msw
1044 };
1045
1046 struct Rect
1047 {
1048 short top;
1049 short left;
1050 short bottom;
1051 short right;
1052 };
1053
1054 struct wide
1055 {
1056 wxInt32 hi;
1057 wxUint32 lo;
1058 };
1059
1060 struct TimeRecord
1061 {
1062 wide value; // units
1063 TimeScale scale; // units per second
1064 TimeBase base;
1065 };
1066
1067 struct Point
1068 {
1069 short v;
1070 short h;
1071 };
1072
1073 struct EventRecord
1074 {
1075 wxUint16 what;
1076 wxUint32 message;
1077 wxUint32 when;
1078 Point where;
1079 wxUint16 modifiers;
1080 };
1081
1082 enum {
1083 mcTopLeftMovie = 1,
1084 mcScaleMovieToFit = 2,
1085 mcWithBadge = 4,
1086 mcNotVisible = 8,
1087 mcWithFrame = 16
1088 };
1089
1090 //---------------------------------------------------------------------------
1091 // QT Library
1092 //---------------------------------------------------------------------------
1093 #define wxDL_METHOD_DEFINE( rettype, name, args, shortargs, defret ) \
1094 typedef rettype (* name ## Type) args ; \
1095 name ## Type pfn_ ## name; \
1096 rettype name args \
1097 { if (m_ok) return pfn_ ## name shortargs ; return defret; }
1098
1099 #define wxDL_VOIDMETHOD_DEFINE( name, args, shortargs ) \
1100 typedef void (* name ## Type) args ; \
1101 name ## Type pfn_ ## name; \
1102 void name args \
1103 { if (m_ok) pfn_ ## name shortargs ; }
1104
1105 #define wxDL_METHOD_LOAD( lib, name, success ) \
1106 pfn_ ## name = (name ## Type) lib.GetSymbol( wxT(#name), &success ); \
1107 if (!success) { wxLog::EnableLogging(bWasLoggingEnabled); return false; }
1108
1109
1110 class WXDLLIMPEXP_MEDIA wxQuickTimeLibrary
1111 {
1112 public:
1113 ~wxQuickTimeLibrary()
1114 {
1115 if (m_dll.IsLoaded())
1116 m_dll.Unload();
1117 }
1118
1119 bool Initialize();
1120 bool IsOk() const {return m_ok;}
1121
1122 protected:
1123 wxDynamicLibrary m_dll;
1124 bool m_ok;
1125
1126 public:
1127 wxDL_VOIDMETHOD_DEFINE( StartMovie, (Movie m), (m) );
1128 wxDL_VOIDMETHOD_DEFINE( StopMovie, (Movie m), (m) );
1129 wxDL_METHOD_DEFINE( bool, IsMovieDone, (Movie m), (m), false);
1130 wxDL_VOIDMETHOD_DEFINE( GoToBeginningOfMovie, (Movie m), (m) );
1131 wxDL_METHOD_DEFINE( OSErr, GetMoviesError, (), (), -1);
1132 wxDL_METHOD_DEFINE( OSErr, EnterMovies, (), (), -1);
1133 wxDL_VOIDMETHOD_DEFINE( ExitMovies, (), () );
1134 wxDL_METHOD_DEFINE( OSErr, InitializeQTML, (long flags), (flags), -1);
1135 wxDL_VOIDMETHOD_DEFINE( TerminateQTML, (), () );
1136
1137 wxDL_METHOD_DEFINE( OSErr, NativePathNameToFSSpec,
1138 (char* inName, FSSpec* outFile, long flags),
1139 (inName, outFile, flags), -1);
1140
1141 wxDL_METHOD_DEFINE( OSErr, OpenMovieFile,
1142 (const FSSpec * fileSpec, short * resRefNum, wxInt8 permission),
1143 (fileSpec, resRefNum, permission), -1 );
1144
1145 wxDL_METHOD_DEFINE( OSErr, CloseMovieFile,
1146 (short resRefNum), (resRefNum), -1);
1147
1148 wxDL_METHOD_DEFINE( OSErr, NewMovieFromFile,
1149 (Movie * theMovie, short resRefNum, short * resId,
1150 StringPtr resName, short newMovieFlags,
1151 bool * dataRefWasChanged),
1152 (theMovie, resRefNum, resId, resName, newMovieFlags,
1153 dataRefWasChanged), -1);
1154
1155 wxDL_VOIDMETHOD_DEFINE( SetMovieRate, (Movie m, Fixed rate), (m, rate) );
1156 wxDL_METHOD_DEFINE( Fixed, GetMovieRate, (Movie m), (m), 0);
1157 wxDL_VOIDMETHOD_DEFINE( MoviesTask, (Movie m, long maxms), (m, maxms) );
1158 wxDL_VOIDMETHOD_DEFINE( BlockMove,
1159 (const char* p1, const char* p2, long s), (p1,p2,s) );
1160 wxDL_METHOD_DEFINE( Handle, NewHandleClear, (long s), (s), NULL );
1161
1162 wxDL_METHOD_DEFINE( OSErr, NewMovieFromDataRef,
1163 (Movie * m, short flags, short * id,
1164 Handle dataRef, OSType dataRefType),
1165 (m,flags,id,dataRef,dataRefType), -1 );
1166
1167 wxDL_VOIDMETHOD_DEFINE( DisposeHandle, (Handle h), (h) );
1168 wxDL_VOIDMETHOD_DEFINE( GetMovieNaturalBoundsRect, (Movie m, Rect* r), (m,r) );
1169 wxDL_METHOD_DEFINE( void*, GetMovieIndTrackType,
1170 (Movie m, long index, OSType type, long flags),
1171 (m,index,type,flags), NULL );
1172 wxDL_VOIDMETHOD_DEFINE( CreatePortAssociation,
1173 (void* hWnd, void* junk, long morejunk), (hWnd, junk, morejunk) );
1174 wxDL_METHOD_DEFINE(void*, GetNativeWindowPort, (void* hWnd), (hWnd), NULL);
1175 wxDL_VOIDMETHOD_DEFINE(SetMovieGWorld, (Movie m, CGrafPtr port, void* whatever),
1176 (m, port, whatever) );
1177 wxDL_VOIDMETHOD_DEFINE(DisposeMovie, (Movie m), (m) );
1178 wxDL_VOIDMETHOD_DEFINE(SetMovieBox, (Movie m, Rect* r), (m,r));
1179 wxDL_VOIDMETHOD_DEFINE(SetMovieTimeScale, (Movie m, long s), (m,s));
1180 wxDL_METHOD_DEFINE(long, GetMovieDuration, (Movie m), (m), 0);
1181 wxDL_METHOD_DEFINE(TimeBase, GetMovieTimeBase, (Movie m), (m), 0);
1182 wxDL_METHOD_DEFINE(TimeScale, GetMovieTimeScale, (Movie m), (m), 0);
1183 wxDL_METHOD_DEFINE(long, GetMovieTime, (Movie m, void* cruft), (m,cruft), 0);
1184 wxDL_VOIDMETHOD_DEFINE(SetMovieTime, (Movie m, TimeRecord* tr), (m,tr) );
1185 wxDL_METHOD_DEFINE(short, GetMovieVolume, (Movie m), (m), 0);
1186 wxDL_VOIDMETHOD_DEFINE(SetMovieVolume, (Movie m, short sVolume), (m,sVolume) );
1187 wxDL_VOIDMETHOD_DEFINE(SetMovieTimeValue, (Movie m, long s), (m,s));
1188 wxDL_METHOD_DEFINE(ComponentInstance, NewMovieController, (Movie m, const Rect* mr, long fl), (m,mr,fl), 0);
1189 wxDL_VOIDMETHOD_DEFINE(DisposeMovieController, (ComponentInstance ci), (ci));
1190 wxDL_METHOD_DEFINE(int, MCSetVisible, (ComponentInstance m, int b), (m, b), 0);
1191
1192
1193 wxDL_VOIDMETHOD_DEFINE(PrePrerollMovie, (Movie m, long t, Fixed r, WXFARPROC p1, void* p2), (m,t,r,p1,p2) );
1194 wxDL_VOIDMETHOD_DEFINE(PrerollMovie, (Movie m, long t, Fixed r), (m,t,r) );
1195 wxDL_METHOD_DEFINE(Fixed, GetMoviePreferredRate, (Movie m), (m), 0);
1196 wxDL_METHOD_DEFINE(long, GetMovieLoadState, (Movie m), (m), 0);
1197 wxDL_METHOD_DEFINE(void*, NewRoutineDescriptor, (WXFARPROC f, int l, void* junk), (f, l, junk), 0);
1198 wxDL_VOIDMETHOD_DEFINE(DisposeRoutineDescriptor, (void* f), (f));
1199 wxDL_METHOD_DEFINE(void*, GetCurrentArchitecture, (), (), 0);
1200 wxDL_METHOD_DEFINE(int, MCDoAction, (ComponentInstance ci, long f, void* p), (ci,f,p), 0);
1201 wxDL_VOIDMETHOD_DEFINE(MCSetControllerBoundsRect, (ComponentInstance ci, Rect* r), (ci,r));
1202 wxDL_VOIDMETHOD_DEFINE(DestroyPortAssociation, (CGrafPtr g), (g));
1203 wxDL_VOIDMETHOD_DEFINE(NativeEventToMacEvent, (MSG* p1, EventRecord* p2), (p1,p2));
1204 wxDL_VOIDMETHOD_DEFINE(MCIsPlayerEvent, (ComponentInstance ci, EventRecord* p2), (ci, p2));
1205 wxDL_METHOD_DEFINE(int, MCSetMovie, (ComponentInstance ci, Movie m, void* p1, Point w),
1206 (ci,m,p1,w),0);
1207 wxDL_VOIDMETHOD_DEFINE(MCPositionController,
1208 (ComponentInstance ci, Rect* r, void* junk, void* morejunk), (ci,r,junk,morejunk));
1209 wxDL_VOIDMETHOD_DEFINE(MCSetActionFilterWithRefCon,
1210 (ComponentInstance ci, WXFARPROC cb, void* ref), (ci,cb,ref));
1211 wxDL_VOIDMETHOD_DEFINE(MCGetControllerInfo, (MovieController mc, long* flags), (mc,flags));
1212 wxDL_VOIDMETHOD_DEFINE(BeginUpdate, (CGrafPtr port), (port));
1213 wxDL_VOIDMETHOD_DEFINE(UpdateMovie, (Movie m), (m));
1214 wxDL_VOIDMETHOD_DEFINE(EndUpdate, (CGrafPtr port), (port));
1215 wxDL_METHOD_DEFINE( OSErr, GetMoviesStickyError, (), (), -1);
1216 };
1217
1218 bool wxQuickTimeLibrary::Initialize()
1219 {
1220 m_ok = false;
1221
1222 // Turn off the wxDynamicLibrary logging
1223 bool bWasLoggingEnabled = wxLog::EnableLogging(false);
1224
1225 if (!m_dll.Load(wxT("qtmlClient.dll")))
1226 {
1227 wxLog::EnableLogging(bWasLoggingEnabled);
1228 return false;
1229 }
1230
1231 wxDL_METHOD_LOAD( m_dll, StartMovie, m_ok );
1232 wxDL_METHOD_LOAD( m_dll, StopMovie, m_ok );
1233 wxDL_METHOD_LOAD( m_dll, IsMovieDone, m_ok );
1234 wxDL_METHOD_LOAD( m_dll, GoToBeginningOfMovie, m_ok );
1235 wxDL_METHOD_LOAD( m_dll, GetMoviesError, m_ok );
1236 wxDL_METHOD_LOAD( m_dll, EnterMovies, m_ok );
1237 wxDL_METHOD_LOAD( m_dll, ExitMovies, m_ok );
1238 wxDL_METHOD_LOAD( m_dll, InitializeQTML, m_ok );
1239 wxDL_METHOD_LOAD( m_dll, TerminateQTML, m_ok );
1240 wxDL_METHOD_LOAD( m_dll, NativePathNameToFSSpec, m_ok );
1241 wxDL_METHOD_LOAD( m_dll, OpenMovieFile, m_ok );
1242 wxDL_METHOD_LOAD( m_dll, CloseMovieFile, m_ok );
1243 wxDL_METHOD_LOAD( m_dll, NewMovieFromFile, m_ok );
1244 wxDL_METHOD_LOAD( m_dll, GetMovieRate, m_ok );
1245 wxDL_METHOD_LOAD( m_dll, SetMovieRate, m_ok );
1246 wxDL_METHOD_LOAD( m_dll, MoviesTask, m_ok );
1247 wxDL_METHOD_LOAD( m_dll, BlockMove, m_ok );
1248 wxDL_METHOD_LOAD( m_dll, NewHandleClear, m_ok );
1249 wxDL_METHOD_LOAD( m_dll, NewMovieFromDataRef, m_ok );
1250 wxDL_METHOD_LOAD( m_dll, DisposeHandle, m_ok );
1251 wxDL_METHOD_LOAD( m_dll, GetMovieNaturalBoundsRect, m_ok );
1252 wxDL_METHOD_LOAD( m_dll, GetMovieIndTrackType, m_ok );
1253 wxDL_METHOD_LOAD( m_dll, CreatePortAssociation, m_ok );
1254 wxDL_METHOD_LOAD( m_dll, DestroyPortAssociation, m_ok );
1255 wxDL_METHOD_LOAD( m_dll, GetNativeWindowPort, m_ok );
1256 wxDL_METHOD_LOAD( m_dll, SetMovieGWorld, m_ok );
1257 wxDL_METHOD_LOAD( m_dll, DisposeMovie, m_ok );
1258 wxDL_METHOD_LOAD( m_dll, SetMovieBox, m_ok );
1259 wxDL_METHOD_LOAD( m_dll, SetMovieTimeScale, m_ok );
1260 wxDL_METHOD_LOAD( m_dll, GetMovieDuration, m_ok );
1261 wxDL_METHOD_LOAD( m_dll, GetMovieTimeBase, m_ok );
1262 wxDL_METHOD_LOAD( m_dll, GetMovieTimeScale, m_ok );
1263 wxDL_METHOD_LOAD( m_dll, GetMovieTime, m_ok );
1264 wxDL_METHOD_LOAD( m_dll, SetMovieTime, m_ok );
1265 wxDL_METHOD_LOAD( m_dll, GetMovieVolume, m_ok );
1266 wxDL_METHOD_LOAD( m_dll, SetMovieVolume, m_ok );
1267 wxDL_METHOD_LOAD( m_dll, SetMovieTimeValue, m_ok );
1268 wxDL_METHOD_LOAD( m_dll, NewMovieController, m_ok );
1269 wxDL_METHOD_LOAD( m_dll, DisposeMovieController, m_ok );
1270 wxDL_METHOD_LOAD( m_dll, MCSetVisible, m_ok );
1271 wxDL_METHOD_LOAD( m_dll, PrePrerollMovie, m_ok );
1272 wxDL_METHOD_LOAD( m_dll, PrerollMovie, m_ok );
1273 wxDL_METHOD_LOAD( m_dll, GetMoviePreferredRate, m_ok );
1274 wxDL_METHOD_LOAD( m_dll, GetMovieLoadState, m_ok );
1275 wxDL_METHOD_LOAD( m_dll, MCDoAction, m_ok );
1276 wxDL_METHOD_LOAD( m_dll, MCSetControllerBoundsRect, m_ok );
1277 wxDL_METHOD_LOAD( m_dll, NativeEventToMacEvent, m_ok );
1278 wxDL_METHOD_LOAD( m_dll, MCIsPlayerEvent, m_ok );
1279 wxDL_METHOD_LOAD( m_dll, MCSetMovie, m_ok );
1280 wxDL_METHOD_LOAD( m_dll, MCSetActionFilterWithRefCon, m_ok );
1281 wxDL_METHOD_LOAD( m_dll, MCGetControllerInfo, m_ok );
1282 wxDL_METHOD_LOAD( m_dll, BeginUpdate, m_ok );
1283 wxDL_METHOD_LOAD( m_dll, UpdateMovie, m_ok );
1284 wxDL_METHOD_LOAD( m_dll, EndUpdate, m_ok );
1285 wxDL_METHOD_LOAD( m_dll, GetMoviesStickyError, m_ok );
1286
1287 wxLog::EnableLogging(bWasLoggingEnabled);
1288 m_ok = true;
1289
1290 return true;
1291 }
1292
1293 class WXDLLIMPEXP_MEDIA wxQTMediaBackend : public wxMediaBackendCommonBase
1294 {
1295 public:
1296 wxQTMediaBackend();
1297 ~wxQTMediaBackend();
1298
1299 virtual bool CreateControl(wxControl* ctrl, wxWindow* parent,
1300 wxWindowID id,
1301 const wxPoint& pos,
1302 const wxSize& size,
1303 long style,
1304 const wxValidator& validator,
1305 const wxString& name);
1306
1307 virtual bool Play();
1308 virtual bool Pause();
1309 virtual bool Stop();
1310
1311 virtual bool Load(const wxURI& location,
1312 const wxURI& proxy)
1313 { return wxMediaBackend::Load(location, proxy); }
1314
1315 virtual bool Load(const wxString& fileName);
1316 virtual bool Load(const wxURI& location);
1317
1318 virtual wxMediaState GetState();
1319
1320 virtual bool SetPosition(wxLongLong where);
1321 virtual wxLongLong GetPosition();
1322 virtual wxLongLong GetDuration();
1323
1324 virtual void Move(int x, int y, int w, int h);
1325 wxSize GetVideoSize() const;
1326
1327 virtual double GetPlaybackRate();
1328 virtual bool SetPlaybackRate(double dRate);
1329
1330 virtual double GetVolume();
1331 virtual bool SetVolume(double);
1332
1333 void Cleanup();
1334 void FinishLoad();
1335
1336 static void PPRMProc (Movie theMovie, OSErr theErr, void* theRefCon);
1337
1338 // TODO: Last param actually long - does this work on 64bit machines?
1339 static Boolean MCFilterProc (MovieController theController,
1340 short action, void *params, LONG_PTR refCon);
1341
1342 static LRESULT CALLBACK QTWndProc(HWND, UINT, WPARAM, LPARAM);
1343
1344 virtual bool ShowPlayerControls(wxMediaCtrlPlayerControls flags);
1345
1346 wxSize m_bestSize; // Original movie size
1347 Movie m_movie; // QT Movie handle/instance
1348 bool m_bVideo; // Whether or not we have video
1349 bool m_bPlaying; // Whether or not movie is playing
1350 wxTimer* m_timer; // Load or Play timer
1351 wxQuickTimeLibrary m_lib; // DLL to load functions from
1352 ComponentInstance m_pMC; // Movie Controller
1353
1354 friend class wxQTMediaEvtHandler;
1355 DECLARE_DYNAMIC_CLASS(wxQTMediaBackend)
1356 };
1357
1358 // helper to hijack background erasing for the QT window
1359 class WXDLLIMPEXP_MEDIA wxQTMediaEvtHandler : public wxEvtHandler
1360 {
1361 public:
1362 wxQTMediaEvtHandler(wxQTMediaBackend *qtb, WXHWND hwnd)
1363 {
1364 m_qtb = qtb;
1365 m_hwnd = hwnd;
1366
1367 m_qtb->m_ctrl->Connect(m_qtb->m_ctrl->GetId(),
1368 wxEVT_ERASE_BACKGROUND,
1369 wxEraseEventHandler(wxQTMediaEvtHandler::OnEraseBackground),
1370 NULL, this);
1371 }
1372
1373 void OnEraseBackground(wxEraseEvent& event);
1374
1375 private:
1376 wxQTMediaBackend *m_qtb;
1377 WXHWND m_hwnd;
1378
1379 DECLARE_NO_COPY_CLASS(wxQTMediaEvtHandler)
1380 };
1381
1382
1383 //===========================================================================
1384 // IMPLEMENTATION
1385 //===========================================================================
1386
1387 //---------------------------------------------------------------------------
1388 // wxAMMediaBackend
1389 //---------------------------------------------------------------------------
1390
1391 IMPLEMENT_DYNAMIC_CLASS(wxAMMediaBackend, wxMediaBackend)
1392
1393 //---------------------------------------------------------------------------
1394 // Usual debugging macros
1395 //---------------------------------------------------------------------------
1396 #ifdef __WXDEBUG__
1397 #define MAX_ERROR_TEXT_LEN 160
1398
1399 // Get the error string for Active Movie
1400 wxString wxAMMediaBackend::GetErrorString(HRESULT hrdsv)
1401 {
1402 wxChar szError[MAX_ERROR_TEXT_LEN];
1403 if ( m_lpAMGetErrorText != NULL &&
1404 (*m_lpAMGetErrorText)(hrdsv, szError, MAX_ERROR_TEXT_LEN) == 0)
1405 {
1406 return wxString::Format(wxT("DirectShow error \"%s\" \n")
1407 wxT("(numeric %X)\n")
1408 wxT("occured"),
1409 szError, (int)hrdsv);
1410 }
1411 else
1412 {
1413 return wxString::Format(wxT("Unknown error \n")
1414 wxT("(numeric %X)\n")
1415 wxT("occured"),
1416 (int)hrdsv);
1417 }
1418 }
1419
1420 #define wxAMFAIL(x) wxFAIL_MSG(GetErrorString(x));
1421 #define wxVERIFY(x) wxASSERT((x))
1422 #define wxAMLOG(x) wxLogDebug(GetErrorString(x))
1423 #else
1424 #define wxAMVERIFY(x) (x)
1425 #define wxVERIFY(x) (x)
1426 #define wxAMLOG(x)
1427 #define wxAMFAIL(x)
1428 #endif
1429
1430 //---------------------------------------------------------------------------
1431 // Standard macros for ease of use
1432 //---------------------------------------------------------------------------
1433 #define SAFE_RELEASE(x) { if (x) x->Release(); x = NULL; }
1434
1435 //---------------------------------------------------------------------------
1436 // wxAMLoadTimer
1437 //
1438 // Queries the control periodically to see if it has reached the point
1439 // in its loading cycle where we can begin playing the media - if so
1440 // then we finish up some things like getting the original size of the video
1441 // and then sending the loaded event to our handler
1442 //---------------------------------------------------------------------------
1443 class wxAMLoadTimer : public wxTimer
1444 {
1445 public:
1446 wxAMLoadTimer(wxAMMediaBackend* parent) :
1447 m_parent(parent) {}
1448
1449 void Notify()
1450 {
1451 if (m_parent->m_pMP)
1452 {
1453 MPReadyStateConstants nState;
1454 m_parent->m_pMP->get_ReadyState(&nState);
1455 if (nState != mpReadyStateLoading)
1456 {
1457 Stop();
1458 m_parent->FinishLoad();
1459 delete this;
1460 }
1461 }
1462 else
1463 {
1464 IActiveMovie2* pAM2 = NULL;
1465 ReadyStateConstants nState;
1466 if (m_parent->m_pAM->QueryInterface(IID_IActiveMovie2, (void**)&pAM2) == 0
1467 && pAM2->get_ReadyState(&nState) == 0)
1468 {
1469 pAM2->Release();
1470 if (nState != amvLoading)
1471 {
1472 Stop();
1473 m_parent->FinishLoad();
1474 delete this;
1475 }
1476 }
1477 else
1478 {
1479 if (pAM2)
1480 pAM2->Release();
1481
1482 Stop();
1483 m_parent->FinishLoad();
1484 delete this;
1485 }
1486 }
1487 }
1488
1489 protected:
1490 wxAMMediaBackend* m_parent; //Backend pointer
1491 };
1492
1493 //---------------------------------------------------------------------------
1494 // wxAMPlayTimer
1495 //
1496 // Sets m_hNotifyWnd to NULL to signify that we haven't loaded anything yet
1497 // Queries the control periodically to see if it has stopped -
1498 // if it has it sends the stop event
1499 //---------------------------------------------------------------------------
1500 class wxAMPlayTimer : public wxTimer
1501 {
1502 public:
1503 wxAMPlayTimer(wxAMMediaBackend* parent) :
1504 m_parent(parent) {}
1505
1506 void Notify()
1507 {
1508 // NB: Stop events could get triggered by the interface
1509 // if ShowPlayerControls is enabled,
1510 // so we need this hack here to make an attempt
1511 // at it not getting sent - but its far from ideal -
1512 // they can still get sent in some cases
1513 if (m_parent->GetState() == wxMEDIASTATE_STOPPED &&
1514 m_parent->GetPosition() == m_parent->GetDuration())
1515 {
1516 if ( m_parent->SendStopEvent() )
1517 {
1518 // seek to beginning of movie
1519 m_parent->wxAMMediaBackend::SetPosition(0);
1520 Stop();
1521
1522 // send the event to our child
1523 m_parent->QueueFinishEvent();
1524 }
1525 }
1526 }
1527
1528 protected:
1529 wxAMMediaBackend* m_parent; //Backend pointer
1530 };
1531
1532
1533 #if 0
1534 // The following is an alternative way - but it doesn't seem
1535 // to work with the IActiveMovie control - it probably processes
1536 // its own events
1537 //---------------------------------------------------------------------------
1538 // wxAMPlayTimer
1539 //
1540 // Query the IMediaEvent interface from the embedded WMP's
1541 // filtergraph, then process the events from it - sending
1542 // EC_COMPLETE events as stop events to the media control.
1543 //---------------------------------------------------------------------------
1544 class wxAMPlayTimer : public wxTimer
1545 {
1546 public:
1547 wxAMPlayTimer(wxAMMediaBackend* pBE) : m_pBE(pBE), m_pME(NULL)
1548 {
1549 HRESULT hr;
1550 IUnknown* pGB;
1551 hr = m_pBE->m_pAM->get_FilterGraph(&pGB);
1552 wxASSERT(SUCCEEDED(hr));
1553 hr = pGB->QueryInterface(IID_IMediaEvent, (void**)&m_pME);
1554 wxASSERT(SUCCEEDED(hr));
1555 pGB->Release();
1556 }
1557
1558 ~wxAMPlayTimer()
1559 {
1560 SAFE_RELEASE(m_pME);
1561 }
1562
1563 void Notify()
1564 {
1565 LONG evCode;
1566 LONG_PTR evParam1, evParam2;
1567
1568 // DirectShow keeps a list of queued events, and we need
1569 // to go through them one by one, stopping at (hopefully only one)
1570 // EC_COMPLETE message
1571 while ( m_pME->GetEvent(&evCode, &evParam1, &evParam2, 0) == 0 )
1572 {
1573 // Cleanup memory that GetEvent allocated
1574 HRESULT hr = m_pME->FreeEventParams(evCode, evParam1, evParam2);
1575 if (hr != 0)
1576 {
1577 // Even though this makes a messagebox, this is Windows,
1578 // where we can do GUI stuff in separate threads :)
1579 wxFAIL_MSG(m_pBE->GetErrorString(hr));
1580 }
1581 // If this is the end of the clip, notify handler
1582 else if (1 == evCode) // EC_COMPLETE
1583 {
1584 if ( m_pBE->SendStopEvent() )
1585 {
1586 Stop();
1587 m_pBE->QueueFinishEvent();
1588 }
1589 }
1590 }
1591 }
1592
1593 protected:
1594 wxAMMediaBackend* m_pBE; // Backend pointer
1595 IMediaEvent* m_pME; // To determine when to send stop event
1596 };
1597 #endif
1598
1599 //---------------------------------------------------------------------------
1600 // wxAMMediaBackend Constructor
1601 //---------------------------------------------------------------------------
1602 wxAMMediaBackend::wxAMMediaBackend()
1603 :m_pAX(NULL),
1604 m_pAM(NULL),
1605 m_pMP(NULL),
1606 m_pTimer(NULL)
1607 {
1608 }
1609
1610 //---------------------------------------------------------------------------
1611 // wxAMMediaBackend Destructor
1612 //---------------------------------------------------------------------------
1613 wxAMMediaBackend::~wxAMMediaBackend()
1614 {
1615 // Free memory from Load()
1616 Clear();
1617
1618 if (m_pAX)
1619 {
1620 m_pAX->DissociateHandle();
1621 delete m_pAX;
1622 m_pAM->Release();
1623
1624 if (m_pMP)
1625 m_pMP->Release();
1626 }
1627 }
1628
1629 //---------------------------------------------------------------------------
1630 // wxAMMediaBackend::Clear
1631 //
1632 // Free up interfaces and memory allocated by LoadXXX
1633 //---------------------------------------------------------------------------
1634 void wxAMMediaBackend::Clear()
1635 {
1636 if (m_pTimer)
1637 {
1638 delete m_pTimer;
1639 m_pTimer = NULL;
1640 }
1641 }
1642
1643 //---------------------------------------------------------------------------
1644 // wxAMMediaBackend::CreateControl
1645 //---------------------------------------------------------------------------
1646 bool wxAMMediaBackend::CreateControl(wxControl* ctrl, wxWindow* parent,
1647 wxWindowID id,
1648 const wxPoint& pos,
1649 const wxSize& size,
1650 long style,
1651 const wxValidator& validator,
1652 const wxString& name)
1653 {
1654 // First get the AMGetErrorText procedure in debug
1655 // mode for more meaningful messages
1656 #ifdef __WXDEBUG__
1657 if ( m_dllQuartz.Load(_T("quartz.dll"), wxDL_VERBATIM) )
1658 {
1659 m_lpAMGetErrorText = (LPAMGETERRORTEXT)
1660 m_dllQuartz.GetSymbolAorW(wxT("AMGetErrorText"));
1661 }
1662 #endif
1663
1664 #ifdef __WXWINCE__
1665 CLSID clsid;
1666 if (CLSIDFromProgID(wxT("WPCEOCX.WMP"), &clsid) != S_OK &&
1667 CLSIDFromProgID(wxT("MediaPlayer.MediaPlayer.1"), &clsid) != S_OK)
1668 return false;
1669
1670 // determine which (if any) media player interface
1671 // is available - IMediaPlayer or IActiveMovie
1672 if ( ::CoCreateInstance(clsid, NULL,
1673 CLSCTX_INPROC_SERVER,
1674 IID_IMediaPlayer, (void**)&m_pMP) != 0 )
1675 {
1676 return false;
1677 }
1678 else
1679 {
1680 m_pMP->QueryInterface(IID_IActiveMovie, (void**)&m_pAM);
1681 }
1682 #else
1683 // determine which (if any) media player interface
1684 // is available - IMediaPlayer or IActiveMovie
1685 if ( ::CoCreateInstance(CLSID_MediaPlayer, NULL,
1686 CLSCTX_INPROC_SERVER,
1687 IID_IMediaPlayer, (void**)&m_pMP) != 0 )
1688 {
1689 if ( ::CoCreateInstance(CLSID_ActiveMovie, NULL,
1690 CLSCTX_INPROC_SERVER,
1691 IID_IActiveMovie, (void**)&m_pAM) != 0 )
1692 {
1693 return false;
1694 }
1695
1696 m_pAM->QueryInterface(IID_IMediaPlayer, (void**)&m_pMP);
1697 }
1698 else
1699 {
1700 m_pMP->QueryInterface(IID_IActiveMovie, (void**)&m_pAM);
1701 }
1702 #endif
1703
1704 // Create window
1705 // By default wxWindow(s) is created with a border -
1706 // so we need to get rid of those
1707 //
1708 // Since we don't have a child window like most other
1709 // backends, we don't need wxCLIP_CHILDREN
1710 if ( !ctrl->wxControl::Create(parent, id, pos, size,
1711 (style & ~wxBORDER_MASK) | wxBORDER_NONE,
1712 validator, name) )
1713 {
1714 return false;
1715 }
1716
1717 // Create the ActiveX container along with the media player
1718 // interface and query them
1719 m_ctrl = wxStaticCast(ctrl, wxMediaCtrl);
1720 m_pAX = new wxActiveXContainer(ctrl,
1721 m_pMP ? IID_IMediaPlayer : IID_IActiveMovie,
1722 m_pAM);
1723
1724 // Set up wx-specific stuff for the default
1725 // settings wxMediaCtrl says it will conform to (???)
1726 if (m_pMP)
1727 {
1728 m_pMP->put_DisplaySize(mpFitToSize);
1729
1730 // TODO: Unsure what actual effect this has
1731 m_pMP->put_WindowlessVideo(VARIANT_TRUE);
1732 }
1733 else
1734 m_pAM->put_MovieWindowSize(amvDoubleOriginalSize);
1735
1736 // by default true
1737 m_pAM->put_AutoStart(VARIANT_FALSE);
1738
1739 // by default enabled
1740 wxAMMediaBackend::ShowPlayerControls(wxMEDIACTRLPLAYERCONTROLS_NONE);
1741
1742 // by default with AM only 0.5
1743 wxAMMediaBackend::SetVolume(1.0);
1744
1745 // don't erase the background of our control window
1746 // so that resizing is a bit smoother
1747 m_ctrl->SetBackgroundStyle(wxBG_STYLE_CUSTOM);
1748
1749 // success
1750 return true;
1751 }
1752
1753 //---------------------------------------------------------------------------
1754 // wxAMMediaBackend::Load (file version)
1755 //---------------------------------------------------------------------------
1756 bool wxAMMediaBackend::Load(const wxString& fileName)
1757 {
1758 return DoLoad(fileName);
1759 }
1760
1761 //---------------------------------------------------------------------------
1762 // wxAMMediaBackend::Load (URL Version)
1763 //---------------------------------------------------------------------------
1764 bool wxAMMediaBackend::Load(const wxURI& location)
1765 {
1766 // Turn off loading from a proxy, as user may have set it previously
1767 INSPlay* pPlay = NULL;
1768 m_pAM->QueryInterface(IID_INSPlay, (void**) &pPlay);
1769 if (pPlay)
1770 {
1771 pPlay->put_UseHTTPProxy(VARIANT_FALSE);
1772 pPlay->Release();
1773 }
1774
1775 return DoLoad(location.BuildURI());
1776 }
1777
1778 //---------------------------------------------------------------------------
1779 // wxAMMediaBackend::Load (URL Version with Proxy)
1780 //---------------------------------------------------------------------------
1781 bool wxAMMediaBackend::Load(const wxURI& location, const wxURI& proxy)
1782 {
1783 // Set the proxy of the NETSHOW interface
1784 INSPlay* pPlay = NULL;
1785 m_pAM->QueryInterface(IID_INSPlay, (void**) &pPlay);
1786
1787 if (pPlay)
1788 {
1789 pPlay->put_UseHTTPProxy(VARIANT_TRUE);
1790 pPlay->put_HTTPProxyHost(wxBasicString(proxy.GetServer()).Get());
1791 pPlay->put_HTTPProxyPort(wxAtoi(proxy.GetPort()));
1792 pPlay->Release();
1793 }
1794
1795 return DoLoad(location.BuildURI());
1796 }
1797
1798 //---------------------------------------------------------------------------
1799 // wxAMMediaBackend::DoLoad
1800 //
1801 // Called by all functions - this actually renders
1802 // the file and sets up the filter graph
1803 //---------------------------------------------------------------------------
1804 bool wxAMMediaBackend::DoLoad(const wxString& location)
1805 {
1806 //Clear up previously allocated memory
1807 Clear();
1808
1809 HRESULT hr;
1810
1811 // Play the movie the normal way through the embedded WMP.
1812 // Supposedly, Open is better in theory because
1813 // the docs say its async and put_FileName is not -
1814 // but in practice they both appear to be async anyway
1815 if (m_pMP)
1816 hr = m_pMP->Open( wxBasicString(location).Get() );
1817 else
1818 hr = m_pAM->put_FileName( wxBasicString(location).Get() );
1819
1820 if (FAILED(hr))
1821 {
1822 wxAMLOG(hr);
1823 return false;
1824 }
1825
1826 // In AM playing will FAIL if
1827 // the user plays before the media is loaded
1828 m_pTimer = new wxAMLoadTimer(this);
1829 m_pTimer->Start(20);
1830
1831 return true;
1832 }
1833
1834 //---------------------------------------------------------------------------
1835 // wxAMMediaBackend::FinishLoad
1836 //
1837 // Called by our wxAMLoadTimer when the
1838 // embedded WMP tells its the media is ready to play.
1839 //
1840 // Here we get the original size of the video and
1841 // send the loaded event to our watcher :).
1842 //---------------------------------------------------------------------------
1843 void wxAMMediaBackend::FinishLoad()
1844 {
1845 //Get the original video size
1846 m_pAM->get_ImageSourceWidth((long*)&m_bestSize.x);
1847 m_pAM->get_ImageSourceHeight((long*)&m_bestSize.y);
1848
1849 // Start the play timer to catch stop events
1850 // Previous load timer cleans up itself
1851 m_pTimer = new wxAMPlayTimer(this);
1852
1853 NotifyMovieLoaded();
1854 }
1855
1856 //---------------------------------------------------------------------------
1857 // wxAMMediaBackend::ShowPlayerControls
1858 //---------------------------------------------------------------------------
1859 bool wxAMMediaBackend::ShowPlayerControls(wxMediaCtrlPlayerControls flags)
1860 {
1861 // Note that IMediaPlayer doesn't have a statusbar by
1862 // default but IActiveMovie does - so lets try to keep
1863 // the interface consistant
1864 if (!flags)
1865 {
1866 m_pAM->put_Enabled(VARIANT_FALSE);
1867 m_pAM->put_ShowControls(VARIANT_FALSE);
1868 if (m_pMP)
1869 m_pMP->put_ShowStatusBar(VARIANT_FALSE);
1870 }
1871 else
1872 {
1873 m_pAM->put_Enabled(VARIANT_TRUE);
1874 m_pAM->put_ShowControls(VARIANT_TRUE);
1875
1876 m_pAM->put_ShowPositionControls(
1877 (flags & wxMEDIACTRLPLAYERCONTROLS_STEP) ?
1878 VARIANT_TRUE : VARIANT_FALSE);
1879
1880 if (m_pMP)
1881 {
1882 m_pMP->put_ShowStatusBar(VARIANT_TRUE);
1883 m_pMP->put_ShowAudioControls(
1884 (flags & wxMEDIACTRLPLAYERCONTROLS_VOLUME) ?
1885 VARIANT_TRUE : VARIANT_FALSE);
1886 }
1887 }
1888
1889 return true;
1890 }
1891
1892 //---------------------------------------------------------------------------
1893 // wxAMMediaBackend::Play
1894 //
1895 // Plays the stream. If it is non-seekable, it will restart it (implicit).
1896 //
1897 // Note that we use SUCCEEDED here because run/pause/stop tend to be overly
1898 // picky and return warnings on pretty much every call
1899 //---------------------------------------------------------------------------
1900 bool wxAMMediaBackend::Play()
1901 {
1902 // Actually try to play the movie, even though it may not be loaded yet.
1903 HRESULT hr = m_pAM->Run();
1904 if (SUCCEEDED(hr))
1905 {
1906 m_pTimer->Start(20);
1907 return true;
1908 }
1909
1910 wxAMLOG(hr);
1911
1912 return false;
1913 }
1914
1915 //---------------------------------------------------------------------------
1916 // wxAMMediaBackend::Pause
1917 //
1918 // Pauses the stream.
1919 //---------------------------------------------------------------------------
1920 bool wxAMMediaBackend::Pause()
1921 {
1922 HRESULT hr = m_pAM->Pause();
1923 if (SUCCEEDED(hr))
1924 return true;
1925
1926 wxAMLOG(hr);
1927
1928 return false;
1929 }
1930
1931 //---------------------------------------------------------------------------
1932 // wxAMMediaBackend::Stop
1933 //
1934 // Stops the stream.
1935 //---------------------------------------------------------------------------
1936 bool wxAMMediaBackend::Stop()
1937 {
1938 HRESULT hr = m_pAM->Stop();
1939 if (SUCCEEDED(hr))
1940 {
1941 // Seek to beginning
1942 wxAMMediaBackend::SetPosition(0);
1943
1944 // Stop stop event timer
1945 m_pTimer->Stop();
1946 return true;
1947 }
1948
1949 wxAMLOG(hr);
1950
1951 return false;
1952 }
1953
1954 //---------------------------------------------------------------------------
1955 // wxAMMediaBackend::SetPosition
1956 //
1957 // 1) Translates the current position's time to directshow time,
1958 // which is in a scale of 1 second (in a double)
1959 // 2) Sets the play position of the IMediaSeeking interface -
1960 // passing NULL as the stop position means to keep the old
1961 // stop position
1962 //---------------------------------------------------------------------------
1963 bool wxAMMediaBackend::SetPosition(wxLongLong where)
1964 {
1965 HRESULT hr = m_pAM->put_CurrentPosition(
1966 ((LONGLONG)where.GetValue()) / 1000.0
1967 );
1968 if (FAILED(hr))
1969 {
1970 wxAMLOG(hr);
1971 return false;
1972 }
1973
1974 return true;
1975 }
1976
1977 //---------------------------------------------------------------------------
1978 // wxAMMediaBackend::GetPosition
1979 //
1980 // 1) Obtains the current play and stop positions from IMediaSeeking
1981 // 2) Returns the play position translated to our time base
1982 //---------------------------------------------------------------------------
1983 wxLongLong wxAMMediaBackend::GetPosition()
1984 {
1985 double outCur;
1986 HRESULT hr = m_pAM->get_CurrentPosition(&outCur);
1987 if (FAILED(hr))
1988 {
1989 wxAMLOG(hr);
1990 return 0;
1991 }
1992
1993 // h,m,s,milli - outdur is in 1 second (double)
1994 outCur *= 1000;
1995 wxLongLong ll;
1996 ll.Assign(outCur);
1997
1998 return ll;
1999 }
2000
2001 //---------------------------------------------------------------------------
2002 // wxAMMediaBackend::GetVolume
2003 //
2004 // Gets the volume through the IBasicAudio interface -
2005 // value ranges from 0 (MAX volume) to -10000 (minimum volume).
2006 // -100 per decibel.
2007 //---------------------------------------------------------------------------
2008 double wxAMMediaBackend::GetVolume()
2009 {
2010 long lVolume;
2011 HRESULT hr = m_pAM->get_Volume(&lVolume);
2012 if (FAILED(hr))
2013 {
2014 wxAMLOG(hr);
2015 return 0.0;
2016 }
2017
2018 return pow(10.0, lVolume / 2000.0);
2019 }
2020
2021 //---------------------------------------------------------------------------
2022 // wxAMMediaBackend::SetVolume
2023 //
2024 // Sets the volume through the IBasicAudio interface -
2025 // value ranges from 0 (MAX volume) to -10000 (minimum volume).
2026 // -100 per decibel.
2027 //---------------------------------------------------------------------------
2028 bool wxAMMediaBackend::SetVolume(double dVolume)
2029 {
2030 // pow(10.0, -80.0) to correct 0 == -INF
2031 long lVolume = (long)(2000.0 * log10( pow( 10.0, -80.0) + dVolume ) );
2032 HRESULT hr = m_pAM->put_Volume( lVolume );
2033 if (FAILED(hr))
2034 {
2035 wxAMLOG(hr);
2036 return false;
2037 }
2038
2039 return true;
2040 }
2041
2042 //---------------------------------------------------------------------------
2043 // wxAMMediaBackend::GetDuration
2044 //
2045 // 1) Obtains the duration of the media from IAMMultiMediaStream
2046 // 2) Converts that value to our time base, and returns it
2047 //
2048 // NB: With VBR MP3 files the default DirectShow MP3 render does not
2049 // read the Xing header correctly, resulting in skewed values for duration
2050 // and seeking
2051 //---------------------------------------------------------------------------
2052 wxLongLong wxAMMediaBackend::GetDuration()
2053 {
2054 double outDuration;
2055 HRESULT hr = m_pAM->get_Duration(&outDuration);
2056 if (FAILED(hr))
2057 {
2058 wxAMLOG(hr);
2059 return 0;
2060 }
2061
2062 // h,m,s,milli - outdur is in 1 second (double)
2063 outDuration *= 1000;
2064 wxLongLong ll;
2065 ll.Assign(outDuration);
2066
2067 return ll;
2068 }
2069
2070 //---------------------------------------------------------------------------
2071 // wxAMMediaBackend::GetState
2072 //
2073 // Returns the cached state
2074 //---------------------------------------------------------------------------
2075 wxMediaState wxAMMediaBackend::GetState()
2076 {
2077 StateConstants nState;
2078 HRESULT hr = m_pAM->get_CurrentState(&nState);
2079 if (FAILED(hr))
2080 {
2081 wxAMLOG(hr);
2082 return wxMEDIASTATE_STOPPED;
2083 }
2084
2085 return (wxMediaState)nState;
2086 }
2087
2088 //---------------------------------------------------------------------------
2089 // wxAMMediaBackend::GetPlaybackRate
2090 //
2091 // Pretty simple way of obtaining the playback rate from
2092 // the IMediaSeeking interface
2093 //---------------------------------------------------------------------------
2094 double wxAMMediaBackend::GetPlaybackRate()
2095 {
2096 double dRate;
2097 HRESULT hr = m_pAM->get_Rate(&dRate);
2098 if (FAILED(hr))
2099 {
2100 wxAMLOG(hr);
2101 return 0.0;
2102 }
2103
2104 return dRate;
2105 }
2106
2107 //---------------------------------------------------------------------------
2108 // wxAMMediaBackend::SetPlaybackRate
2109 //
2110 // Sets the playback rate of the media - DirectShow is pretty good
2111 // about this, actually
2112 //---------------------------------------------------------------------------
2113 bool wxAMMediaBackend::SetPlaybackRate(double dRate)
2114 {
2115 HRESULT hr = m_pAM->put_Rate(dRate);
2116 if (FAILED(hr))
2117 {
2118 wxAMLOG(hr);
2119 return false;
2120 }
2121
2122 return true;
2123 }
2124
2125 //---------------------------------------------------------------------------
2126 // wxAMMediaBackend::GetDownloadXXX
2127 //
2128 // Queries for and gets the total size of the file and the current
2129 // progress in downloading that file from the IAMOpenProgress
2130 // interface from the media player interface's filter graph
2131 //---------------------------------------------------------------------------
2132 void wxAMMediaBackend::DoGetDownloadProgress(wxLongLong* pLoadProgress,
2133 wxLongLong* pLoadTotal)
2134 {
2135 LONGLONG loadTotal = 0, loadProgress = 0;
2136 IUnknown* pFG;
2137 IAMOpenProgress* pOP;
2138 HRESULT hr;
2139 hr = m_pAM->get_FilterGraph(&pFG);
2140 if (SUCCEEDED(hr))
2141 {
2142 hr = pFG->QueryInterface(IID_IAMOpenProgress, (void**)&pOP);
2143 if (SUCCEEDED(hr))
2144 {
2145 hr = pOP->QueryProgress(&loadTotal, &loadProgress);
2146 pOP->Release();
2147 }
2148
2149 pFG->Release();
2150 }
2151
2152 if (SUCCEEDED(hr))
2153 {
2154 *pLoadProgress = loadProgress;
2155 *pLoadTotal = loadTotal;
2156 }
2157 else
2158 {
2159 // When not loading from a URL QueryProgress will return
2160 // E_NOINTERFACE or whatever
2161 // wxAMFAIL(hr);
2162 *pLoadProgress = 0;
2163 *pLoadTotal = 0;
2164 }
2165 }
2166
2167 //---------------------------------------------------------------------------
2168 // wxAMMediaBackend::GetVideoSize
2169 //
2170 // Obtains the cached original video size
2171 //---------------------------------------------------------------------------
2172 wxSize wxAMMediaBackend::GetVideoSize() const
2173 {
2174 return m_bestSize;
2175 }
2176
2177 //---------------------------------------------------------------------------
2178 // wxAMMediaBackend::Move
2179 //
2180 // We take care of this in our redrawing
2181 //---------------------------------------------------------------------------
2182 void wxAMMediaBackend::Move(int WXUNUSED(x), int WXUNUSED(y),
2183 int WXUNUSED(w), int WXUNUSED(h))
2184 {
2185 }
2186
2187 //---------------------------------------------------------------------------
2188 // End of wxAMMediaBackend
2189 //---------------------------------------------------------------------------
2190
2191 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2192 //
2193 // wxMCIMediaBackend
2194 //
2195 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2196
2197 #ifndef __WXWINCE__
2198 IMPLEMENT_DYNAMIC_CLASS(wxMCIMediaBackend, wxMediaBackend)
2199
2200 //---------------------------------------------------------------------------
2201 // Usual debugging macros for MCI returns
2202 //---------------------------------------------------------------------------
2203
2204 #ifdef __WXDEBUG__
2205 #define wxMCIVERIFY(arg) \
2206 { \
2207 DWORD nRet; \
2208 if ( (nRet = (arg)) != 0) \
2209 { \
2210 TCHAR sz[5000]; \
2211 mciGetErrorString(nRet, sz, 5000); \
2212 wxFAIL_MSG(wxString::Format(_T("MCI Error:%s"), sz)); \
2213 } \
2214 }
2215 #else
2216 #define wxMCIVERIFY(arg) (arg);
2217 #endif
2218
2219 //---------------------------------------------------------------------------
2220 // Simulation for <digitalv.h>
2221 //
2222 // Mingw and possibly other compilers don't have the digitalv.h header
2223 // that is needed to have some essential features of mci work with
2224 // windows - so we provide the declarations for the types we use here
2225 //---------------------------------------------------------------------------
2226
2227 typedef struct
2228 {
2229 DWORD_PTR dwCallback;
2230 #ifdef MCI_USE_OFFEXT
2231 POINT ptOffset;
2232 POINT ptExtent;
2233 #else
2234 RECT rc;
2235 #endif
2236 }
2237 MCI_DGV_RECT_PARMS;
2238
2239 typedef struct
2240 {
2241 DWORD_PTR dwCallback;
2242 HWND hWnd;
2243 #ifndef _WIN32
2244 WORD wReserved1;
2245 #endif
2246 UINT nCmdShow;
2247 #ifndef _WIN32
2248 WORD wReserved2;
2249 #endif
2250 wxChar* lpstrText;
2251 }
2252 MCI_DGV_WINDOW_PARMS;
2253
2254 typedef struct
2255 {
2256 DWORD_PTR dwCallback;
2257 DWORD dwTimeFormat;
2258 DWORD dwAudio;
2259 DWORD dwFileFormat;
2260 DWORD dwSpeed;
2261 }
2262 MCI_DGV_SET_PARMS;
2263
2264 typedef struct
2265 {
2266 DWORD_PTR dwCallback;
2267 DWORD dwItem;
2268 DWORD dwValue;
2269 DWORD dwOver;
2270 wxChar* lpstrAlgorithm;
2271 wxChar* lpstrQuality;
2272 }
2273 MCI_DGV_SETAUDIO_PARMS;
2274
2275 //---------------------------------------------------------------------------
2276 // wxMCIMediaBackend Constructor
2277 //
2278 // Here we don't need to do much except say we don't have any video :)
2279 //---------------------------------------------------------------------------
2280 wxMCIMediaBackend::wxMCIMediaBackend() : m_hNotifyWnd(NULL), m_bVideo(false)
2281 {
2282 }
2283
2284 //---------------------------------------------------------------------------
2285 // wxMCIMediaBackend Destructor
2286 //
2287 // We close the mci device - note that there may not be an mci device here,
2288 // or it may fail - but we don't really care, since we're destructing
2289 //---------------------------------------------------------------------------
2290 wxMCIMediaBackend::~wxMCIMediaBackend()
2291 {
2292 if (m_hNotifyWnd)
2293 {
2294 mciSendCommand(m_hDev, MCI_CLOSE, 0, 0);
2295 DestroyWindow(m_hNotifyWnd);
2296 m_hNotifyWnd = NULL;
2297 }
2298 }
2299
2300 //---------------------------------------------------------------------------
2301 // wxMCIMediaBackend::Create
2302 //
2303 // Here we just tell wxMediaCtrl that mci does exist (which it does, on all
2304 // msw systems, at least in some form dating back to win16 days)
2305 //---------------------------------------------------------------------------
2306 bool wxMCIMediaBackend::CreateControl(wxControl* ctrl, wxWindow* parent,
2307 wxWindowID id,
2308 const wxPoint& pos,
2309 const wxSize& size,
2310 long style,
2311 const wxValidator& validator,
2312 const wxString& name)
2313 {
2314 // Create window
2315 // By default wxWindow(s) is created with a border -
2316 // so we need to get rid of those, and create with
2317 // wxCLIP_CHILDREN, so that if the driver/backend
2318 // is a child window, it refereshes properly
2319 if ( !ctrl->wxControl::Create(parent, id, pos, size,
2320 (style & ~wxBORDER_MASK) | wxBORDER_NONE | wxCLIP_CHILDREN,
2321 validator, name) )
2322 return false;
2323
2324 m_ctrl = wxStaticCast(ctrl, wxMediaCtrl);
2325
2326 return true;
2327 }
2328
2329 //---------------------------------------------------------------------------
2330 // wxMCIMediaBackend::Load (file version)
2331 //
2332 // Here we have MCI load a file and device, set the time format to our
2333 // default (milliseconds), and set the video (if any) to play in the control
2334 //---------------------------------------------------------------------------
2335 bool wxMCIMediaBackend::Load(const wxString& fileName)
2336 {
2337 // if the user already called load close the previous MCI device
2338 if (m_hNotifyWnd)
2339 {
2340 mciSendCommand(m_hDev, MCI_CLOSE, 0, 0);
2341 DestroyWindow(m_hNotifyWnd);
2342 m_hNotifyWnd = NULL;
2343 }
2344
2345 // Opens a file and has MCI select a device. Normally you'd put
2346 // MCI_OPEN_TYPE in addition to MCI_OPEN_ELEMENT - however if you
2347 // omit this it tells MCI to select the device instead. This is good
2348 // because we have no reliable way of "enumerating" the devices in MCI
2349 MCI_OPEN_PARMS openParms;
2350 openParms.lpstrElementName = (wxChar*) fileName.c_str();
2351
2352 if ( mciSendCommand(0, MCI_OPEN, MCI_OPEN_ELEMENT,
2353 (DWORD)(LPVOID)&openParms) != 0)
2354 {
2355 return false;
2356 }
2357
2358 m_hDev = openParms.wDeviceID;
2359
2360 // set the time format for the device to milliseconds
2361 MCI_SET_PARMS setParms;
2362 setParms.dwCallback = 0;
2363 setParms.dwTimeFormat = MCI_FORMAT_MILLISECONDS;
2364
2365 if (mciSendCommand(m_hDev, MCI_SET, MCI_SET_TIME_FORMAT,
2366 (DWORD)(LPVOID)&setParms) != 0)
2367 {
2368 return false;
2369 }
2370
2371 // tell the MCI device to display the video in our wxMediaCtrl
2372 MCI_DGV_WINDOW_PARMS windowParms;
2373 windowParms.hWnd = (HWND)m_ctrl->GetHandle();
2374
2375 m_bVideo = (mciSendCommand(m_hDev, MCI_WINDOW,
2376 0x00010000L, // MCI_DGV_WINDOW_HWND
2377 (DWORD)(LPVOID)&windowParms) == 0);
2378
2379 // Create a hidden window and register to handle MCI events
2380 // Note that wxCanvasClassName is already registered
2381 // and used by all wxWindows and normal wxControls
2382 m_hNotifyWnd = ::CreateWindow(
2383 wxCanvasClassName,
2384 NULL,
2385 0, 0, 0, 0,
2386 0,
2387 (HWND) NULL,
2388 (HMENU)NULL,
2389 wxGetInstance(),
2390 (LPVOID)NULL );
2391
2392 if (!m_hNotifyWnd)
2393 {
2394 wxLogSysError( wxT("Could not create hidden needed for ")
2395 wxT("registering for MCI events!") );
2396
2397 return false;
2398 }
2399
2400 wxSetWindowProc(m_hNotifyWnd, wxMCIMediaBackend::NotifyWndProc);
2401 wxSetWindowUserData(m_hNotifyWnd, this);
2402
2403 NotifyMovieLoaded();
2404
2405 return true;
2406 }
2407
2408 //---------------------------------------------------------------------------
2409 // wxMCIMediaBackend::Load (URL version)
2410 //
2411 // MCI doesn't support URLs directly (?)
2412 //
2413 // TODO: Use wxURL/wxFileSystem and mmioInstallProc
2414 //---------------------------------------------------------------------------
2415 bool wxMCIMediaBackend::Load(const wxURI& WXUNUSED(location))
2416 {
2417 return false;
2418 }
2419
2420 //---------------------------------------------------------------------------
2421 // wxMCIMediaBackend::Play
2422 //
2423 // Plays/Resumes the MCI device... a couple notes:
2424 // 1) Certain drivers will crash and burn if we don't pass them an
2425 // MCI_PLAY_PARMS, despite the documentation that says otherwise...
2426 // 2) There is a MCI_RESUME command, but MCI_PLAY does the same thing
2427 // and will resume from a stopped state also, so there's no need to
2428 // call both, for example
2429 //---------------------------------------------------------------------------
2430 bool wxMCIMediaBackend::Play()
2431 {
2432 MCI_PLAY_PARMS playParms;
2433 playParms.dwCallback = (DWORD)m_hNotifyWnd;
2434
2435 bool bOK = ( mciSendCommand(m_hDev, MCI_PLAY, MCI_NOTIFY,
2436 (DWORD)(LPVOID)&playParms) == 0 );
2437
2438 if (bOK)
2439 m_ctrl->Show(m_bVideo);
2440
2441 return bOK;
2442 }
2443
2444 //---------------------------------------------------------------------------
2445 // wxMCIMediaBackend::Pause
2446 //
2447 // Pauses the MCI device - nothing special
2448 //---------------------------------------------------------------------------
2449 bool wxMCIMediaBackend::Pause()
2450 {
2451 return (mciSendCommand(m_hDev, MCI_PAUSE, MCI_WAIT, 0) == 0);
2452 }
2453
2454 //---------------------------------------------------------------------------
2455 // wxMCIMediaBackend::Stop
2456 //
2457 // Stops the MCI device & seeks to the beginning as wxMediaCtrl docs outline
2458 //---------------------------------------------------------------------------
2459 bool wxMCIMediaBackend::Stop()
2460 {
2461 return (mciSendCommand(m_hDev, MCI_STOP, MCI_WAIT, 0) == 0) &&
2462 (mciSendCommand(m_hDev, MCI_SEEK, MCI_SEEK_TO_START, 0) == 0);
2463 }
2464
2465 //---------------------------------------------------------------------------
2466 // wxMCIMediaBackend::GetState
2467 //
2468 // Here we get the state and convert it to a wxMediaState -
2469 // since we use direct comparisons with MCI_MODE_PLAY and
2470 // MCI_MODE_PAUSE, we don't care if the MCI_STATUS call
2471 // fails or not
2472 //---------------------------------------------------------------------------
2473 wxMediaState wxMCIMediaBackend::GetState()
2474 {
2475 MCI_STATUS_PARMS statusParms;
2476 statusParms.dwItem = MCI_STATUS_MODE;
2477
2478 mciSendCommand(m_hDev, MCI_STATUS, MCI_STATUS_ITEM,
2479 (DWORD)(LPVOID)&statusParms);
2480
2481 if (statusParms.dwReturn == MCI_MODE_PAUSE)
2482 return wxMEDIASTATE_PAUSED;
2483 else if (statusParms.dwReturn == MCI_MODE_PLAY)
2484 return wxMEDIASTATE_PLAYING;
2485 else
2486 return wxMEDIASTATE_STOPPED;
2487 }
2488
2489 //---------------------------------------------------------------------------
2490 // wxMCIMediaBackend::SetPosition
2491 //
2492 // Here we set the position of the device in the stream.
2493 // Note that MCI actually stops the device after you seek it if the
2494 // device is playing/paused, so we need to play the file after
2495 // MCI seeks like normal APIs would
2496 //---------------------------------------------------------------------------
2497 bool wxMCIMediaBackend::SetPosition(wxLongLong where)
2498 {
2499 MCI_SEEK_PARMS seekParms;
2500 seekParms.dwCallback = 0;
2501
2502 #if wxUSE_LONGLONG_NATIVE && !wxUSE_LONGLONG_WX
2503 seekParms.dwTo = (DWORD)where.GetValue();
2504 #else // wxUSE_LONGLONG_WX
2505 // no way to return it in one piece
2506 wxASSERT( where.GetHi() == 0 );
2507 seekParms.dwTo = (DWORD)where.GetLo();
2508 #endif
2509
2510 // device was playing?
2511 bool bReplay = GetState() == wxMEDIASTATE_PLAYING;
2512
2513 if ( mciSendCommand(m_hDev, MCI_SEEK, MCI_TO,
2514 (DWORD)(LPVOID)&seekParms) != 0)
2515 {
2516 return false;
2517 }
2518
2519 // If the device was playing, resume it
2520 if (bReplay)
2521 return Play();
2522 else
2523 return true;
2524 }
2525
2526 //---------------------------------------------------------------------------
2527 // wxMCIMediaBackend::GetPosition
2528 //
2529 // Gets the position of the device in the stream using the current
2530 // time format... nothing special here...
2531 //---------------------------------------------------------------------------
2532 wxLongLong wxMCIMediaBackend::GetPosition()
2533 {
2534 MCI_STATUS_PARMS statusParms;
2535 statusParms.dwItem = MCI_STATUS_POSITION;
2536
2537 if (mciSendCommand(m_hDev, MCI_STATUS, MCI_STATUS_ITEM,
2538 (DWORD)(LPSTR)&statusParms) != 0)
2539 {
2540 return 0;
2541 }
2542
2543 return statusParms.dwReturn;
2544 }
2545
2546 //---------------------------------------------------------------------------
2547 // wxMCIMediaBackend::GetVolume
2548 //
2549 // Gets the volume of the current media via the MCI_DGV_STATUS_VOLUME
2550 // message. Value ranges from 0 (minimum) to 1000 (maximum volume).
2551 //---------------------------------------------------------------------------
2552 double wxMCIMediaBackend::GetVolume()
2553 {
2554 MCI_STATUS_PARMS statusParms;
2555 statusParms.dwCallback = 0;
2556 statusParms.dwItem = 0x4019; // MCI_DGV_STATUS_VOLUME
2557
2558 if (mciSendCommand(m_hDev, MCI_STATUS, MCI_STATUS_ITEM,
2559 (DWORD)(LPSTR)&statusParms) != 0)
2560 {
2561 return 0;
2562 }
2563
2564 return ((double)statusParms.dwReturn) / 1000.0;
2565 }
2566
2567 //---------------------------------------------------------------------------
2568 // wxMCIMediaBackend::SetVolume
2569 //
2570 // Sets the volume of the current media via the MCI_DGV_SETAUDIO_VOLUME
2571 // message. Value ranges from 0 (minimum) to 1000 (maximum volume).
2572 //---------------------------------------------------------------------------
2573 bool wxMCIMediaBackend::SetVolume(double dVolume)
2574 {
2575 MCI_DGV_SETAUDIO_PARMS audioParms;
2576 audioParms.dwCallback = 0;
2577 audioParms.dwItem = 0x4002; // MCI_DGV_SETAUDIO_VOLUME
2578 audioParms.dwValue = (DWORD) (dVolume * 1000.0);
2579 audioParms.dwOver = 0;
2580 audioParms.lpstrAlgorithm = NULL;
2581 audioParms.lpstrQuality = NULL;
2582
2583 if (mciSendCommand(m_hDev, 0x0873, // MCI_SETAUDIO
2584 // MCI_DGV_SETAUDIO + (_ITEM | _VALUE)
2585 0x00800000L | 0x01000000L,
2586 (DWORD)(LPSTR)&audioParms) != 0)
2587 {
2588 return false;
2589 }
2590
2591 return true;
2592 }
2593
2594 //---------------------------------------------------------------------------
2595 // wxMCIMediaBackend::GetDuration
2596 //
2597 // Gets the duration of the stream... nothing special
2598 //---------------------------------------------------------------------------
2599 wxLongLong wxMCIMediaBackend::GetDuration()
2600 {
2601 MCI_STATUS_PARMS statusParms;
2602 statusParms.dwItem = MCI_STATUS_LENGTH;
2603
2604 if (mciSendCommand(m_hDev, MCI_STATUS, MCI_STATUS_ITEM,
2605 (DWORD)(LPSTR)&statusParms) != 0)
2606 {
2607 return 0;
2608 }
2609
2610 return statusParms.dwReturn;
2611 }
2612
2613 //---------------------------------------------------------------------------
2614 // wxMCIMediaBackend::Move
2615 //
2616 // Moves the window to a location
2617 //---------------------------------------------------------------------------
2618 void wxMCIMediaBackend::Move(int WXUNUSED(x), int WXUNUSED(y), int w, int h)
2619 {
2620 if (m_hNotifyWnd && m_bVideo)
2621 {
2622 MCI_DGV_RECT_PARMS putParms; // ifdefed MCI_DGV_PUT_PARMS
2623 memset(&putParms, 0, sizeof(MCI_DGV_RECT_PARMS));
2624 putParms.rc.bottom = h;
2625 putParms.rc.right = w;
2626
2627 // wxStackWalker will crash and burn here on assert
2628 // and MCI doesn't like 0 and 0 for some reason (out of range)
2629 // so just don't it in that case
2630 if (w || h)
2631 {
2632 wxMCIVERIFY( mciSendCommand(m_hDev, MCI_PUT,
2633 0x00040000L, // MCI_DGV_PUT_DESTINATION
2634 (DWORD)(LPSTR)&putParms) );
2635 }
2636 }
2637 }
2638
2639 //---------------------------------------------------------------------------
2640 // wxMCIMediaBackend::GetVideoSize
2641 //
2642 // Gets the original size of the movie for sizers
2643 //---------------------------------------------------------------------------
2644 wxSize wxMCIMediaBackend::GetVideoSize() const
2645 {
2646 if (m_bVideo)
2647 {
2648 MCI_DGV_RECT_PARMS whereParms; // ifdefed MCI_DGV_WHERE_PARMS
2649
2650 wxMCIVERIFY( mciSendCommand(m_hDev, MCI_WHERE,
2651 0x00020000L, // MCI_DGV_WHERE_SOURCE
2652 (DWORD)(LPSTR)&whereParms) );
2653
2654 return wxSize(whereParms.rc.right, whereParms.rc.bottom);
2655 }
2656 return wxSize(0, 0);
2657 }
2658
2659 //---------------------------------------------------------------------------
2660 // wxMCIMediaBackend::GetPlaybackRate
2661 //
2662 // TODO
2663 //---------------------------------------------------------------------------
2664 double wxMCIMediaBackend::GetPlaybackRate()
2665 {
2666 return 1.0;
2667 }
2668
2669 //---------------------------------------------------------------------------
2670 // wxMCIMediaBackend::SetPlaybackRate
2671 //
2672 // TODO
2673 //---------------------------------------------------------------------------
2674 bool wxMCIMediaBackend::SetPlaybackRate(double WXUNUSED(dRate))
2675 {
2676 #if 0
2677 MCI_WAVE_SET_SAMPLESPERSEC
2678 MCI_DGV_SET_PARMS setParms;
2679 setParms.dwSpeed = (DWORD) (dRate * 1000.0);
2680
2681 return (mciSendCommand(m_hDev, MCI_SET,
2682 0x00020000L, // MCI_DGV_SET_SPEED
2683 (DWORD)(LPSTR)&setParms) == 0);
2684 #endif
2685
2686 return false;
2687 }
2688
2689 //---------------------------------------------------------------------------
2690 // [static] wxMCIMediaBackend::MSWWindowProc
2691 //
2692 // Here we process a message when MCI reaches the stopping point
2693 // in the stream
2694 //---------------------------------------------------------------------------
2695 LRESULT CALLBACK wxMCIMediaBackend::NotifyWndProc(HWND hWnd, UINT nMsg,
2696 WPARAM wParam,
2697 LPARAM lParam)
2698 {
2699 wxMCIMediaBackend* backend =
2700 (wxMCIMediaBackend*)wxGetWindowUserData(hWnd);
2701
2702 return backend->OnNotifyWndProc(hWnd, nMsg, wParam, lParam);
2703 }
2704
2705 LRESULT CALLBACK wxMCIMediaBackend::OnNotifyWndProc(HWND hWnd, UINT nMsg,
2706 WPARAM wParam,
2707 LPARAM lParam)
2708 {
2709 if (nMsg == MM_MCINOTIFY)
2710 {
2711 wxASSERT(lParam == (LPARAM) m_hDev);
2712 if (wParam == MCI_NOTIFY_SUCCESSFUL && lParam == (LPARAM)m_hDev)
2713 {
2714 if ( SendStopEvent() )
2715 {
2716 wxMCIVERIFY( mciSendCommand(m_hDev, MCI_SEEK, MCI_SEEK_TO_START, 0) );
2717 QueueFinishEvent();
2718 }
2719 }
2720 }
2721 return DefWindowProc(hWnd, nMsg, wParam, lParam);
2722 }
2723 #endif // __WXWINCE__
2724
2725 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2726 //
2727 // wxQTMediaBackend
2728 //
2729 // TODO: Use a less kludgy way to pause/get state/set state
2730 // FIXME: Greg Hazel reports that sometimes files that cannot be played
2731 // with this backend are treated as playable anyway - not verified though.
2732 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2733
2734 IMPLEMENT_DYNAMIC_CLASS(wxQTMediaBackend, wxMediaBackend)
2735
2736 // Time between timer calls - this is the Apple recommendation to the TCL
2737 // team I believe
2738 #define MOVIE_DELAY 20
2739
2740 #include "wx/timer.h"
2741
2742
2743 //---------------------------------------------------------------------------
2744 // wxQTLoadTimer
2745 //
2746 // QT, esp. QT for Windows is very picky about how you go about
2747 // async loading. If you were to go through a Windows message loop
2748 // or a MoviesTask or both and then check the movie load state
2749 // it would still return 1000 (loading)... even (pre)prerolling doesn't
2750 // help. However, making a load timer like this works
2751 //---------------------------------------------------------------------------
2752 class wxQTLoadTimer : public wxTimer
2753 {
2754 public:
2755 wxQTLoadTimer(Movie movie, wxQTMediaBackend* parent, wxQuickTimeLibrary* pLib) :
2756 m_movie(movie), m_parent(parent), m_pLib(pLib) {}
2757
2758 void Notify()
2759 {
2760 m_pLib->MoviesTask(m_movie, 0);
2761 //kMovieLoadStatePlayable
2762 if (m_pLib->GetMovieLoadState(m_movie) >= 10000)
2763 {
2764 m_parent->FinishLoad();
2765 delete this;
2766 }
2767 }
2768
2769 protected:
2770 Movie m_movie; //Our movie instance
2771 wxQTMediaBackend* m_parent; //Backend pointer
2772 wxQuickTimeLibrary* m_pLib; //Interfaces
2773 };
2774
2775
2776 // --------------------------------------------------------------------------
2777 // wxQTPlayTimer - Handle Asyncronous Playing
2778 //
2779 // 1) Checks to see if the movie is done, and if not continues
2780 // streaming the movie
2781 // 2) Sends the wxEVT_MEDIA_STOP event if we have reached the end of
2782 // the movie.
2783 // --------------------------------------------------------------------------
2784 class wxQTPlayTimer : public wxTimer
2785 {
2786 public:
2787 wxQTPlayTimer(Movie movie, wxQTMediaBackend* parent,
2788 wxQuickTimeLibrary* pLib) :
2789 m_movie(movie), m_parent(parent), m_pLib(pLib) {}
2790
2791 void Notify()
2792 {
2793 //
2794 // OK, a little explaining - basically originally
2795 // we only called MoviesTask if the movie was actually
2796 // playing (not paused or stopped)... this was before
2797 // we realized MoviesTask actually handles repainting
2798 // of the current frame - so if you were to resize
2799 // or something it would previously not redraw that
2800 // portion of the movie.
2801 //
2802 // So now we call MoviesTask always so that it repaints
2803 // correctly.
2804 //
2805 m_pLib->MoviesTask(m_movie, 0);
2806
2807 //
2808 // Handle the stop event - if the movie has reached
2809 // the end, notify our handler
2810 //
2811 // m_bPlaying == !(Stopped | Paused)
2812 //
2813 if (m_parent->m_bPlaying)
2814 {
2815 if (m_pLib->IsMovieDone(m_movie))
2816 {
2817 if ( m_parent->SendStopEvent() )
2818 {
2819 m_parent->Stop();
2820 wxASSERT(m_pLib->GetMoviesError() == noErr);
2821
2822 m_parent->QueueFinishEvent();
2823 }
2824 }
2825 }
2826 }
2827
2828 protected:
2829 Movie m_movie; // Our movie instance
2830 wxQTMediaBackend* m_parent; //Backend pointer
2831 wxQuickTimeLibrary* m_pLib; //Interfaces
2832 };
2833
2834
2835 //---------------------------------------------------------------------------
2836 // wxQTMediaBackend::QTWndProc
2837 //
2838 // Forwards events to the Movie Controller so that it can
2839 // redraw itself/process messages etc..
2840 //---------------------------------------------------------------------------
2841 LRESULT CALLBACK wxQTMediaBackend::QTWndProc(HWND hWnd, UINT nMsg,
2842 WPARAM wParam, LPARAM lParam)
2843 {
2844 wxQTMediaBackend* pThis = (wxQTMediaBackend*)wxGetWindowUserData(hWnd);
2845
2846 MSG msg;
2847 msg.hwnd = hWnd;
2848 msg.message = nMsg;
2849 msg.wParam = wParam;
2850 msg.lParam = lParam;
2851 msg.time = 0;
2852 msg.pt.x = 0;
2853 msg.pt.y = 0;
2854 EventRecord theEvent;
2855 pThis->m_lib.NativeEventToMacEvent(&msg, &theEvent);
2856 pThis->m_lib.MCIsPlayerEvent(pThis->m_pMC, &theEvent);
2857
2858 return pThis->m_ctrl->MSWWindowProc(nMsg, wParam, lParam);
2859 }
2860
2861 //---------------------------------------------------------------------------
2862 // wxQTMediaBackend Destructor
2863 //
2864 // Sets m_timer to NULL signifying we havn't loaded anything yet
2865 //---------------------------------------------------------------------------
2866 wxQTMediaBackend::wxQTMediaBackend()
2867 : m_movie(NULL), m_bPlaying(false), m_timer(NULL), m_pMC(NULL)
2868 {
2869 }
2870
2871 //---------------------------------------------------------------------------
2872 // wxQTMediaBackend Destructor
2873 //
2874 // 1) Cleans up the QuickTime movie instance
2875 // 2) Decrements the QuickTime reference counter - if this reaches
2876 // 0, QuickTime shuts down
2877 // 3) Decrements the QuickTime Windows Media Layer reference counter -
2878 // if this reaches 0, QuickTime shuts down the Windows Media Layer
2879 //---------------------------------------------------------------------------
2880 wxQTMediaBackend::~wxQTMediaBackend()
2881 {
2882 if (m_movie)
2883 Cleanup();
2884
2885 if (m_lib.IsOk())
2886 {
2887 if (m_pMC)
2888 {
2889 m_lib.DisposeMovieController(m_pMC);
2890 // m_pMC = NULL;
2891 }
2892
2893 // destroy wxQTMediaEvtHandler we pushed on it
2894 m_ctrl->PopEventHandler(true);
2895
2896 m_lib.DestroyPortAssociation(
2897 (CGrafPtr)m_lib.GetNativeWindowPort(m_ctrl->GetHWND()));
2898
2899 //Note that ExitMovies() is not necessary, but
2900 //the docs are fuzzy on whether or not TerminateQTML is
2901 m_lib.ExitMovies();
2902 m_lib.TerminateQTML();
2903 }
2904 }
2905
2906 //---------------------------------------------------------------------------
2907 // wxQTMediaBackend::CreateControl
2908 //
2909 // 1) Intializes QuickTime
2910 // 2) Creates the control window
2911 //---------------------------------------------------------------------------
2912 bool wxQTMediaBackend::CreateControl(wxControl* ctrl, wxWindow* parent,
2913 wxWindowID id,
2914 const wxPoint& pos,
2915 const wxSize& size,
2916 long style,
2917 const wxValidator& validator,
2918 const wxString& name)
2919 {
2920 if (!m_lib.Initialize())
2921 return false;
2922
2923 int nError = m_lib.InitializeQTML(0);
2924 if (nError != noErr) //-2093 no dll
2925 {
2926 wxFAIL_MSG(wxString::Format(wxT("Couldn't Initialize Quicktime-%i"), nError));
2927 return false;
2928 }
2929
2930 m_lib.EnterMovies();
2931
2932 // Create window
2933 // By default wxWindow(s) is created with a border -
2934 // so we need to get rid of those
2935 //
2936 // Since we don't have a child window like most other
2937 // backends, we don't need wxCLIP_CHILDREN
2938 //
2939 if ( !ctrl->wxControl::Create(parent, id, pos, size,
2940 (style & ~wxBORDER_MASK) | wxBORDER_NONE,
2941 validator, name) )
2942 {
2943 return false;
2944 }
2945
2946 m_ctrl = wxStaticCast(ctrl, wxMediaCtrl);
2947
2948 // Create a port association for our window so we
2949 // can use it as a WindowRef
2950 m_lib.CreatePortAssociation(m_ctrl->GetHWND(), NULL, 0L);
2951
2952 // Part of a suggestion from Greg Hazel
2953 // to repaint movie when idle
2954 m_ctrl->PushEventHandler(new wxQTMediaEvtHandler(this, m_ctrl->GetHWND()));
2955
2956 // done
2957 return true;
2958 }
2959
2960 //---------------------------------------------------------------------------
2961 // wxQTMediaBackend::Load (file version)
2962 //
2963 // 1) Get an FSSpec from the Windows path name
2964 // 2) Open the movie
2965 // 3) Obtain the movie instance from the movie resource
2966 // 4) Close the movie resource
2967 // 5) Finish loading
2968 //---------------------------------------------------------------------------
2969 bool wxQTMediaBackend::Load(const wxString& fileName)
2970 {
2971 if (m_movie)
2972 Cleanup();
2973
2974 bool result = true;
2975 OSErr err = noErr;
2976 short movieResFile = 0; //= 0 because of annoying VC6 warning
2977 FSSpec sfFile;
2978
2979 err = m_lib.NativePathNameToFSSpec(
2980 (char*) (const char*) fileName.mb_str(),
2981 &sfFile, 0);
2982 result = (err == noErr);
2983
2984 if (result)
2985 {
2986 err = m_lib.OpenMovieFile(&sfFile, &movieResFile, fsRdPerm);
2987 result = (err == noErr);
2988 }
2989
2990 if (result)
2991 {
2992 short movieResID = 0;
2993 Str255 movieName;
2994
2995 err = m_lib.NewMovieFromFile(
2996 &m_movie,
2997 movieResFile,
2998 &movieResID,
2999 movieName,
3000 newMovieActive,
3001 NULL ); // wasChanged
3002 result = (err == noErr && m_lib.GetMoviesStickyError() == noErr);
3003
3004 // check m_lib.GetMoviesStickyError() because it may not find the
3005 // proper codec and play black video and other strange effects,
3006 // not to mention mess up the dynamic backend loading scheme
3007 // of wxMediaCtrl - so it just does what the QuickTime player does
3008 if (result)
3009 {
3010 m_lib.CloseMovieFile(movieResFile);
3011 FinishLoad();
3012 }
3013 }
3014
3015 return result;
3016 }
3017
3018 //---------------------------------------------------------------------------
3019 // wxQTMediaBackend::PPRMProc (static)
3020 //
3021 // Called when done PrePrerolling the movie.
3022 // Note that in 99% of the cases this does nothing...
3023 // Anyway we set up the loading timer here to tell us when the movie is done
3024 //---------------------------------------------------------------------------
3025 void wxQTMediaBackend::PPRMProc (Movie theMovie,
3026 OSErr WXUNUSED_UNLESS_DEBUG(theErr),
3027 void* theRefCon)
3028 {
3029 wxASSERT( theMovie );
3030 wxASSERT( theRefCon );
3031 wxASSERT( theErr == noErr );
3032
3033 wxQTMediaBackend* pBE = (wxQTMediaBackend*) theRefCon;
3034
3035 long lTime = pBE->m_lib.GetMovieTime(theMovie,NULL);
3036 Fixed rate = pBE->m_lib.GetMoviePreferredRate(theMovie);
3037 pBE->m_lib.PrerollMovie(theMovie, lTime, rate);
3038 pBE->m_timer = new wxQTLoadTimer(pBE->m_movie, pBE, &pBE->m_lib);
3039 pBE->m_timer->Start(MOVIE_DELAY);
3040 }
3041
3042 //---------------------------------------------------------------------------
3043 // wxQTMediaBackend::Load (URL Version)
3044 //
3045 // 1) Build an escaped URI from location
3046 // 2) Create a handle to store the URI string
3047 // 3) Put the URI string inside the handle
3048 // 4) Make a QuickTime URL data ref from the handle with the URI in it
3049 // 5) Clean up the URI string handle
3050 // 6) Do some prerolling
3051 // 7) Finish Loading
3052 //---------------------------------------------------------------------------
3053 bool wxQTMediaBackend::Load(const wxURI& location)
3054 {
3055 if (m_movie)
3056 Cleanup();
3057
3058 wxString theURI = location.BuildURI();
3059
3060 Handle theHandle = m_lib.NewHandleClear(theURI.length() + 1);
3061 wxASSERT(theHandle);
3062
3063 m_lib.BlockMove(theURI.mb_str(), *theHandle, theURI.length() + 1);
3064
3065 // create the movie from the handle that refers to the URI
3066 OSErr err = m_lib.NewMovieFromDataRef(&m_movie, newMovieActive |
3067 newMovieAsyncOK
3068 /*|newMovieIdleImportOK*/,
3069 NULL, theHandle,
3070 URLDataHandlerSubType);
3071
3072 m_lib.DisposeHandle(theHandle);
3073
3074 if (err == noErr)
3075 {
3076 long timeNow;
3077 Fixed playRate;
3078
3079 timeNow = m_lib.GetMovieTime(m_movie, NULL);
3080 wxASSERT(m_lib.GetMoviesError() == noErr);
3081
3082 playRate = m_lib.GetMoviePreferredRate(m_movie);
3083 wxASSERT(m_lib.GetMoviesError() == noErr);
3084
3085 // Note that the callback here is optional,
3086 // but without it PrePrerollMovie can be buggy
3087 // (see Apple ml). Also, some may wonder
3088 // why we need this at all - this is because
3089 // Apple docs say QuickTime streamed movies
3090 // require it if you don't use a Movie Controller,
3091 // which we don't by default.
3092 //
3093 m_lib.PrePrerollMovie(m_movie, timeNow, playRate,
3094 (WXFARPROC)wxQTMediaBackend::PPRMProc,
3095 (void*)this);
3096
3097 return true;
3098 }
3099 else
3100 return false;
3101 }
3102
3103 //---------------------------------------------------------------------------
3104 // wxQTMediaBackend::FinishLoad
3105 //
3106 // 1) Create the movie timer
3107 // 2) Get real size of movie for GetBestSize/sizers
3108 // 3) Set the movie time scale to something usable so that seeking
3109 // etc. will work correctly
3110 // 4) Set our Movie Controller to display the movie if it exists,
3111 // otherwise set the bounds of the Movie
3112 // 5) Refresh parent window
3113 //---------------------------------------------------------------------------
3114 void wxQTMediaBackend::FinishLoad()
3115 {
3116 // Create the playing/streaming timer
3117 m_timer = new wxQTPlayTimer(m_movie, (wxQTMediaBackend*) this, &m_lib);
3118 wxASSERT(m_timer);
3119
3120 m_timer->Start(MOVIE_DELAY, wxTIMER_CONTINUOUS);
3121
3122 // get the real size of the movie
3123 Rect outRect;
3124 memset(&outRect, 0, sizeof(Rect)); // suppress annoying VC6 warning
3125 m_lib.GetMovieNaturalBoundsRect (m_movie, &outRect);
3126 wxASSERT(m_lib.GetMoviesError() == noErr);
3127
3128 m_bestSize.x = outRect.right - outRect.left;
3129 m_bestSize.y = outRect.bottom - outRect.top;
3130
3131 // Handle the movie GWorld
3132 if (m_pMC)
3133 {
3134 Point thePoint;
3135 thePoint.h = thePoint.v = 0;
3136 m_lib.MCSetMovie(m_pMC, m_movie,
3137 m_lib.GetNativeWindowPort(m_ctrl->GetHandle()),
3138 thePoint);
3139 m_lib.MCSetVisible(m_pMC, true);
3140 m_bestSize.y += 16;
3141 }
3142 else
3143 {
3144 m_lib.SetMovieGWorld(m_movie,
3145 (CGrafPtr) m_lib.GetNativeWindowPort(m_ctrl->GetHWND()),
3146 NULL);
3147 }
3148
3149 // Set the movie to millisecond precision
3150 m_lib.SetMovieTimeScale(m_movie, 1000);
3151 wxASSERT(m_lib.GetMoviesError() == noErr);
3152
3153 NotifyMovieLoaded();
3154 }
3155
3156 //---------------------------------------------------------------------------
3157 // wxQTMediaBackend::Play
3158 //
3159 // 1) Start the QT movie
3160 // 2) Start the movie loading timer
3161 //
3162 // NOTE: This will still return success even when
3163 // the movie is still loading, and as mentioned in wxQTLoadTimer
3164 // I don't know of a way to force this to be sync - so if its
3165 // still loading the function will return true but the movie will
3166 // still be in the stopped state
3167 //---------------------------------------------------------------------------
3168 bool wxQTMediaBackend::Play()
3169 {
3170 m_lib.StartMovie(m_movie);
3171 m_bPlaying = true;
3172
3173 return m_lib.GetMoviesError() == noErr;
3174 }
3175
3176 //---------------------------------------------------------------------------
3177 // wxQTMediaBackend::Pause
3178 //
3179 // 1) Stop the movie
3180 // 2) Stop the movie timer
3181 //---------------------------------------------------------------------------
3182 bool wxQTMediaBackend::Pause()
3183 {
3184 m_bPlaying = false;
3185 m_lib.StopMovie(m_movie);
3186
3187 return m_lib.GetMoviesError() == noErr;
3188 }
3189
3190 //---------------------------------------------------------------------------
3191 // wxQTMediaBackend::Stop
3192 //
3193 // 1) Stop the movie
3194 // 2) Stop the movie timer
3195 // 3) Seek to the beginning of the movie
3196 //---------------------------------------------------------------------------
3197 bool wxQTMediaBackend::Stop()
3198 {
3199 m_bPlaying = false;
3200
3201 m_lib.StopMovie(m_movie);
3202 if (m_lib.GetMoviesError() == noErr)
3203 m_lib.GoToBeginningOfMovie(m_movie);
3204
3205 return m_lib.GetMoviesError() == noErr;
3206 }
3207
3208 //---------------------------------------------------------------------------
3209 // wxQTMediaBackend::GetPlaybackRate
3210 //
3211 // Get the movie playback rate from ::GetMovieRate
3212 //---------------------------------------------------------------------------
3213 double wxQTMediaBackend::GetPlaybackRate()
3214 {
3215 return ( ((double)m_lib.GetMovieRate(m_movie)) / 0x10000);
3216 }
3217
3218 //---------------------------------------------------------------------------
3219 // wxQTMediaBackend::SetPlaybackRate
3220 //
3221 // Convert dRate to Fixed and Set the movie rate through SetMovieRate
3222 //---------------------------------------------------------------------------
3223 bool wxQTMediaBackend::SetPlaybackRate(double dRate)
3224 {
3225 m_lib.SetMovieRate(m_movie, (Fixed) (dRate * 0x10000));
3226
3227 return m_lib.GetMoviesError() == noErr;
3228 }
3229
3230 //---------------------------------------------------------------------------
3231 // wxQTMediaBackend::SetPosition
3232 //
3233 // 1) Create a time record struct (TimeRecord) with appropriate values
3234 // 2) Pass struct to SetMovieTime
3235 //---------------------------------------------------------------------------
3236 bool wxQTMediaBackend::SetPosition(wxLongLong where)
3237 {
3238 // NB: For some reason SetMovieTime does not work
3239 // correctly with the Quicktime Windows SDK (6)
3240 // From Muskelkatermann at the wxForum
3241 // http://www.solidsteel.nl/users/wxwidgets/viewtopic.php?t=2957
3242 // RN - note that I have not verified this but there
3243 // is no harm in calling SetMovieTimeValue instead
3244 #if 0
3245 TimeRecord theTimeRecord;
3246 memset(&theTimeRecord, 0, sizeof(TimeRecord));
3247 theTimeRecord.value.lo = where.GetLo();
3248 theTimeRecord.scale = m_lib.GetMovieTimeScale(m_movie);
3249 theTimeRecord.base = m_lib.GetMovieTimeBase(m_movie);
3250 m_lib.SetMovieTime(m_movie, &theTimeRecord);
3251 #else
3252 m_lib.SetMovieTimeValue(m_movie, where.GetLo());
3253 #endif
3254
3255 return (m_lib.GetMoviesError() == noErr);
3256 }
3257
3258 //---------------------------------------------------------------------------
3259 // wxQTMediaBackend::GetPosition
3260 //
3261 // 1) Calls GetMovieTime to get the position we are in in the movie
3262 // in milliseconds (we called
3263 //---------------------------------------------------------------------------
3264 wxLongLong wxQTMediaBackend::GetPosition()
3265 {
3266 return m_lib.GetMovieTime(m_movie, NULL);
3267 }
3268
3269 //---------------------------------------------------------------------------
3270 // wxQTMediaBackend::GetVolume
3271 //
3272 // Gets the volume through GetMovieVolume - which returns a 16 bit short -
3273 //
3274 // +--------+--------+
3275 // + (1) + (2) +
3276 // +--------+--------+
3277 //
3278 // (1) first 8 bits are value before decimal
3279 // (2) second 8 bits are value after decimal
3280 //
3281 // Volume ranges from -1.0 (gain but no sound), 0 (no sound and no gain) to
3282 // 1 (full gain and sound)
3283 //---------------------------------------------------------------------------
3284 double wxQTMediaBackend::GetVolume()
3285 {
3286 short sVolume = m_lib.GetMovieVolume(m_movie);
3287 wxASSERT(m_lib.GetMoviesError() == noErr);
3288
3289 if (sVolume & (128 << 8)) //negative - no sound
3290 return 0.0;
3291
3292 return sVolume / 256.0;
3293 }
3294
3295 //---------------------------------------------------------------------------
3296 // wxQTMediaBackend::SetVolume
3297 //
3298 // Sets the volume through SetMovieVolume - which takes a 16 bit short -
3299 //
3300 // +--------+--------+
3301 // + (1) + (2) +
3302 // +--------+--------+
3303 //
3304 // (1) first 8 bits are value before decimal
3305 // (2) second 8 bits are value after decimal
3306 //
3307 // Volume ranges from -1.0 (gain but no sound), 0 (no sound and no gain) to
3308 // 1 (full gain and sound)
3309 //---------------------------------------------------------------------------
3310 bool wxQTMediaBackend::SetVolume(double dVolume)
3311 {
3312 m_lib.SetMovieVolume(m_movie, (short) (dVolume * 256));
3313 return m_lib.GetMoviesError() == noErr;
3314 }
3315
3316 //---------------------------------------------------------------------------
3317 // wxQTMediaBackend::GetDuration
3318 //
3319 // Calls GetMovieDuration
3320 //---------------------------------------------------------------------------
3321 wxLongLong wxQTMediaBackend::GetDuration()
3322 {
3323 return m_lib.GetMovieDuration(m_movie);
3324 }
3325
3326 //---------------------------------------------------------------------------
3327 // wxQTMediaBackend::GetState
3328 //
3329 // Determines the current state:
3330 // if we are at the beginning, then we are stopped
3331 //---------------------------------------------------------------------------
3332 wxMediaState wxQTMediaBackend::GetState()
3333 {
3334 if (m_bPlaying)
3335 return wxMEDIASTATE_PLAYING;
3336 else if ( !m_movie || wxQTMediaBackend::GetPosition() == 0 )
3337 return wxMEDIASTATE_STOPPED;
3338 else
3339 return wxMEDIASTATE_PAUSED;
3340 }
3341
3342 //---------------------------------------------------------------------------
3343 // wxQTMediaBackend::Cleanup
3344 //
3345 // Diposes of the movie timer, Disassociates the Movie Controller with
3346 // movie and hides it if it exists, and stops and disposes
3347 // of the QT movie
3348 //---------------------------------------------------------------------------
3349 void wxQTMediaBackend::Cleanup()
3350 {
3351 m_bPlaying = false;
3352
3353 if (m_timer)
3354 {
3355 delete m_timer;
3356 m_timer = NULL;
3357 }
3358
3359 m_lib.StopMovie(m_movie);
3360
3361 if (m_pMC)
3362 {
3363 Point thePoint;
3364 thePoint.h = thePoint.v = 0;
3365 m_lib.MCSetVisible(m_pMC, false);
3366 m_lib.MCSetMovie(m_pMC, NULL, NULL, thePoint);
3367 }
3368
3369 m_lib.DisposeMovie(m_movie);
3370 m_movie = NULL;
3371 }
3372
3373 //---------------------------------------------------------------------------
3374 // wxQTMediaBackend::ShowPlayerControls
3375 //
3376 // Creates a movie controller for the Movie if the user wants it
3377 //---------------------------------------------------------------------------
3378 bool wxQTMediaBackend::ShowPlayerControls(wxMediaCtrlPlayerControls flags)
3379 {
3380 if (m_pMC)
3381 {
3382 // restore old wndproc
3383 wxSetWindowProc((HWND)m_ctrl->GetHWND(), wxWndProc);
3384 m_lib.DisposeMovieController(m_pMC);
3385 m_pMC = NULL;
3386
3387 // movie controller height
3388 m_bestSize.y -= 16;
3389 }
3390
3391 if (flags && m_movie)
3392 {
3393 Rect rect;
3394 wxRect wxrect = m_ctrl->GetClientRect();
3395
3396 // make room for controller
3397 if (wxrect.width < 320)
3398 wxrect.width = 320;
3399
3400 rect.top = (short)wxrect.y;
3401 rect.left = (short)wxrect.x;
3402 rect.right = (short)(rect.left + wxrect.width);
3403 rect.bottom = (short)(rect.top + wxrect.height);
3404
3405 if (!m_pMC)
3406 {
3407 m_pMC = m_lib.NewMovieController(m_movie, &rect, mcTopLeftMovie |
3408 // mcScaleMovieToFit |
3409 // mcWithBadge |
3410 mcWithFrame);
3411 m_lib.MCDoAction(m_pMC, 32, (void*)true); //mcActionSetKeysEnabled
3412 m_lib.MCSetActionFilterWithRefCon(m_pMC,
3413 (WXFARPROC)wxQTMediaBackend::MCFilterProc, (void*)this);
3414 m_bestSize.y += 16; // movie controller height
3415
3416 // By default the movie controller uses its own colour palette
3417 // for the movie which can be bad on some files, so turn it off.
3418 // Also turn off its frame/border for the movie
3419 // Also take care of a couple of the interface flags here
3420 long mcFlags = 0;
3421 m_lib.MCDoAction(m_pMC, 39/*mcActionGetFlags*/, (void*)&mcFlags);
3422
3423 mcFlags |=
3424 // (1<< 0) /*mcFlagSuppressMovieFrame*/ |
3425 (1<< 3) /*mcFlagsUseWindowPalette*/
3426 | ((flags & wxMEDIACTRLPLAYERCONTROLS_STEP)
3427 ? 0 : (1<< 1) /*mcFlagSuppressStepButtons*/)
3428 | ((flags & wxMEDIACTRLPLAYERCONTROLS_VOLUME)
3429 ? 0 : (1<< 2) /*mcFlagSuppressSpeakerButton*/)
3430 // | (1<< 4) /*mcFlagDontInvalidate*/ // if we take care of repainting ourselves
3431 ;
3432
3433 m_lib.MCDoAction(m_pMC, 38/*mcActionSetFlags*/, (void*)mcFlags);
3434
3435 // intercept the wndproc of our control window
3436 wxSetWindowProc((HWND)m_ctrl->GetHWND(), wxQTMediaBackend::QTWndProc);
3437
3438 // set the user data of our window
3439 wxSetWindowUserData((HWND)m_ctrl->GetHWND(), this);
3440 }
3441 }
3442
3443 NotifyMovieSizeChanged();
3444
3445 return m_lib.GetMoviesError() == noErr;
3446 }
3447
3448 //---------------------------------------------------------------------------
3449 // wxQTMediaBackend::MCFilterProc (static)
3450 //
3451 // Callback for when the movie controller recieves a message
3452 //---------------------------------------------------------------------------
3453 Boolean wxQTMediaBackend::MCFilterProc(MovieController WXUNUSED(theController),
3454 short action,
3455 void * WXUNUSED(params),
3456 LONG_PTR refCon)
3457 {
3458 wxQTMediaBackend* pThis = (wxQTMediaBackend*)refCon;
3459
3460 switch (action)
3461 {
3462 case 8:
3463 // play button triggered - MC will set movie to opposite state
3464 // of current - playing ? paused : playing
3465 if (pThis)
3466 pThis->m_bPlaying = !(pThis->m_bPlaying);
3467
3468 // NB: Sometimes it doesn't redraw properly -
3469 // if you click on the button but don't move the mouse
3470 // the button will not change its state until you move
3471 // mcActionDraw and Refresh/Update combo do nothing
3472 // to help this unfortunately
3473 break;
3474
3475 case 1:
3476 // don't process idle events
3477 break;
3478
3479 default:
3480 break;
3481 }
3482
3483 return 0;
3484 }
3485
3486 //---------------------------------------------------------------------------
3487 // wxQTMediaBackend::GetVideoSize
3488 //
3489 // Returns the actual size of the QT movie
3490 //---------------------------------------------------------------------------
3491 wxSize wxQTMediaBackend::GetVideoSize() const
3492 {
3493 return m_bestSize;
3494 }
3495
3496 //---------------------------------------------------------------------------
3497 // wxQTMediaBackend::Move
3498 //
3499 // Sets the bounds of either the Movie or Movie Controller
3500 //---------------------------------------------------------------------------
3501 void wxQTMediaBackend::Move(int WXUNUSED(x), int WXUNUSED(y), int w, int h)
3502 {
3503 if (m_movie)
3504 {
3505 // make room for controller
3506 if (m_pMC)
3507 {
3508 if (w < 320)
3509 w = 320;
3510
3511 Rect theRect = {0, 0, (short)h, (short)w};
3512 m_lib.MCSetControllerBoundsRect(m_pMC, &theRect);
3513 }
3514 else
3515 {
3516 Rect theRect = {0, 0, (short)h, (short)w};
3517 m_lib.SetMovieBox(m_movie, &theRect);
3518 }
3519
3520 wxASSERT(m_lib.GetMoviesError() == noErr);
3521 }
3522 }
3523
3524 //---------------------------------------------------------------------------
3525 // wxQTMediaBackend::OnEraseBackground
3526 //
3527 // Suggestion from Greg Hazel to repaint the movie when idle
3528 // (on pause also)
3529 //
3530 // TODO: We may be repainting too much here - under what exact circumstances
3531 // do we need this? I think Move also repaints correctly for the Movie
3532 // Controller, so in that instance we don't need this either
3533 //---------------------------------------------------------------------------
3534 void wxQTMediaEvtHandler::OnEraseBackground(wxEraseEvent& evt)
3535 {
3536 wxQuickTimeLibrary& m_pLib = m_qtb->m_lib;
3537
3538 if ( m_qtb->m_pMC )
3539 {
3540 // repaint movie controller
3541 m_pLib.MCDoAction(m_qtb->m_pMC, 2 /*mcActionDraw*/,
3542 m_pLib.GetNativeWindowPort(m_hwnd));
3543 }
3544 else if ( m_qtb->m_movie )
3545 {
3546 // no movie controller
3547 CGrafPtr port = (CGrafPtr)m_pLib.GetNativeWindowPort(m_hwnd);
3548
3549 m_pLib.BeginUpdate(port);
3550 m_pLib.UpdateMovie(m_qtb->m_movie);
3551 wxASSERT(m_pLib.GetMoviesError() == noErr);
3552 m_pLib.EndUpdate(port);
3553 }
3554 else
3555 {
3556 // no movie
3557 // let the system repaint the window
3558 evt.Skip();
3559 }
3560 }
3561
3562 //---------------------------------------------------------------------------
3563 // End QT Backend
3564 //---------------------------------------------------------------------------
3565
3566 //in source file that contains stuff you don't directly use
3567 #include "wx/html/forcelnk.h"
3568 FORCE_LINK_ME(basewxmediabackends)
3569
3570 //---------------------------------------------------------------------------
3571 // End wxMediaCtrl Compilation Guard and this file
3572 //---------------------------------------------------------------------------
3573 #endif //wxUSE_MEDIACTRL