]> git.sesse.net Git - vlc/blob - projects/activex/plugin.h
mozilla: activex: add cache filling level to event MediaPlayerBuffering
[vlc] / projects / activex / plugin.h
1 /*****************************************************************************
2  * plugin.h: ActiveX control for VLC
3  *****************************************************************************
4  * Copyright (C) 2005-2010 the VideoLAN team
5  *
6  * Authors: Damien Fouilleul <Damien.Fouilleul@laposte.net>
7  *          Jean-Paul Saman <jpsaman@videolan.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 #ifndef __PLUGIN_H__
25 #define __PLUGIN_H__
26
27 #include <ole2.h>
28 #include <olectl.h>
29
30 #include <vlc/vlc.h>
31
32 extern "C" const GUID CLSID_VLCPlugin;
33 extern "C" const GUID CLSID_VLCPlugin2;
34 extern "C" const GUID LIBID_AXVLC;
35 extern "C" const GUID DIID_DVLCEvents;
36
37 class VLCPluginClass : public IClassFactory
38 {
39
40 public:
41
42     VLCPluginClass(LONG *p_class_ref, HINSTANCE hInstance, REFCLSID rclsid);
43
44     /* IUnknown methods */
45     STDMETHODIMP QueryInterface(REFIID riid, void **ppv);
46     STDMETHODIMP_(ULONG) AddRef(void);
47     STDMETHODIMP_(ULONG) Release(void);
48
49     /* IClassFactory methods */
50     STDMETHODIMP CreateInstance(LPUNKNOWN pUnkOuter, REFIID riid, void **ppv);
51     STDMETHODIMP LockServer(BOOL fLock);
52
53     REFCLSID getClassID(void) { return (REFCLSID)_classid; };
54
55     LPCTSTR getInPlaceWndClassName(void) const { return TEXT("VLC Plugin In-Place"); };
56     HINSTANCE getHInstance(void) const { return _hinstance; };
57     LPPICTURE getInPlacePict(void) const
58         { if( NULL != _inplace_picture) _inplace_picture->AddRef(); return _inplace_picture; };
59
60 protected:
61
62     virtual ~VLCPluginClass();
63
64 private:
65
66     LPLONG      _p_class_ref;
67     HINSTANCE   _hinstance;
68     CLSID       _classid;
69     ATOM        _inplace_wndclass_atom;
70     LPPICTURE   _inplace_picture;
71 };
72
73 class VLCPlugin : public IUnknown
74 {
75
76 public:
77
78     VLCPlugin(VLCPluginClass *p_class, LPUNKNOWN pUnkOuter);
79
80     /* IUnknown methods */
81     STDMETHODIMP QueryInterface(REFIID riid, void **ppv);
82     STDMETHODIMP_(ULONG) AddRef(void);
83     STDMETHODIMP_(ULONG) Release(void);
84
85     /* custom methods */
86     HRESULT getTypeLib(LCID lcid, ITypeLib **pTL) { return LoadRegTypeLib(LIBID_AXVLC, 1, 0, lcid, pTL); };
87     REFCLSID getClassID(void) { return _p_class->getClassID(); };
88     REFIID getDispEventID(void) { return (REFIID)DIID_DVLCEvents; };
89
90     /*
91     ** persistant properties
92     */
93     void setMRL(BSTR mrl)
94     {
95         SysFreeString(_bstr_mrl);
96         _bstr_mrl = SysAllocStringLen(mrl, SysStringLen(mrl));
97         setDirty(TRUE);
98     };
99     const BSTR getMRL(void) { return _bstr_mrl; };
100
101     inline void setAutoPlay(BOOL autoplay)
102     {
103         _b_autoplay = autoplay;
104         setDirty(TRUE);
105     };
106     inline BOOL getAutoPlay(void) { return _b_autoplay; };
107
108     inline void setAutoLoop(BOOL autoloop)
109     {
110         _b_autoloop = autoloop;
111         setDirty(TRUE);
112     };
113     inline BOOL getAutoLoop(void) { return _b_autoloop;};
114
115     inline void setShowToolbar(BOOL showtoolbar)
116     {
117         _b_toolbar = showtoolbar;
118         setDirty(TRUE);
119     };
120     inline BOOL getShowToolbar(void) { return _b_toolbar;};
121
122     void setVolume(int volume);
123     int getVolume(void) { return _i_volume; };
124
125     void setBackColor(OLE_COLOR backcolor);
126     OLE_COLOR getBackColor(void) { return _i_backcolor; };
127
128     void setVisible(BOOL fVisible);
129     BOOL getVisible(void) { return _b_visible; };
130     BOOL isVisible(void) { return _b_visible || (! _b_usermode); };
131
132     inline void setStartTime(int time)
133     {
134         _i_time = time;
135         setDirty(TRUE);
136     };
137     inline int getStartTime(void) { return _i_time; };
138
139     void setTime(int time);
140     int  getTime(void) { return _i_time; };
141
142     void setBaseURL(BSTR url)
143     {
144         SysFreeString(_bstr_baseurl);
145         _bstr_baseurl = SysAllocStringLen(url, SysStringLen(url));
146         setDirty(TRUE);
147     };
148     const BSTR getBaseURL(void) { return _bstr_baseurl; };
149
150     // control size in HIMETRIC
151     inline void setExtent(const SIZEL& extent)
152     {
153         _extent = extent;
154         setDirty(TRUE);
155     };
156     const SIZEL& getExtent(void) { return _extent; };
157
158     // transient properties
159     inline void setMute(BOOL mute) { _b_mute = mute; };
160
161     inline void setPicture(LPPICTURE pict)
162     {
163         if( NULL != _p_pict )
164             _p_pict->Release();
165         if( NULL != pict )
166             pict->AddRef();
167         _p_pict = pict;
168     };
169
170     inline LPPICTURE getPicture(void)
171     {
172         if( NULL != _p_pict )
173             _p_pict->AddRef();
174         return _p_pict;
175     };
176
177     BOOL hasFocus(void);
178     void setFocus(BOOL fFocus);
179
180     inline UINT getCodePage(void) { return _i_codepage; };
181     inline void setCodePage(UINT cp)
182     {
183         // accept new codepage only if it works on this system
184         size_t mblen = WideCharToMultiByte(cp,
185                 0, L"test", -1, NULL, 0, NULL, NULL);
186         if( mblen > 0 )
187             _i_codepage = cp;
188     };
189
190     inline BOOL isUserMode(void) { return _b_usermode; };
191     inline void setUserMode(BOOL um) { _b_usermode = um; };
192
193     inline BOOL isDirty(void) { return _b_dirty; };
194     inline void setDirty(BOOL dirty) { _b_dirty = dirty; };
195
196     inline BOOL isRunning(void) { return NULL != _p_libvlc; };
197
198     HRESULT getVLC(libvlc_instance_t** pp_libvlc)
199     {
200         if( !isRunning() )
201             initVLC();
202         *pp_libvlc = _p_libvlc;
203         return _p_libvlc ? S_OK : E_FAIL;
204     }
205     HRESULT getMD(libvlc_media_player_t **pp_md)
206     {
207         *pp_md = _p_mplayer;
208         return _p_mplayer ? S_OK : E_FAIL;
209     }
210
211     void setErrorInfo(REFIID riid, const char *description);
212
213     // control geometry within container
214     RECT getPosRect(void) { return _posRect; };
215     inline HWND getInPlaceWindow(void) const { return _inplacewnd; };
216     BOOL isInPlaceActive(void);
217
218     /*
219     ** container events
220     */
221     HRESULT onInit(void);
222     HRESULT onLoad(void);
223     HRESULT onActivateInPlace(LPMSG lpMesg, HWND hwndParent, LPCRECT lprcPosRect, LPCRECT lprcClipRect);
224     HRESULT onInPlaceDeactivate(void);
225     HRESULT onAmbientChanged(LPUNKNOWN pContainer, DISPID dispID);
226     HRESULT onClose(DWORD dwSaveOption);
227     void onPositionChange(LPCRECT lprcPosRect, LPCRECT lprcClipRect);
228     void onDraw(DVTARGETDEVICE * ptd, HDC hicTargetDev,
229             HDC hdcDraw, LPCRECTL lprcBounds, LPCRECTL lprcWBounds);
230     void onPaint(HDC hdc, const RECT &bounds, const RECT &pr);
231
232     /*
233     ** control events
234     */
235     void freezeEvents(BOOL freeze);
236     void firePropChangedEvent(DISPID dispid);
237     void fireOnPlayEvent(void);
238     void fireOnPauseEvent(void);
239     void fireOnStopEvent(void);
240
241     // async events;
242     void fireOnMediaPlayerNothingSpecialEvent();
243     void fireOnMediaPlayerOpeningEvent();
244     void fireOnMediaPlayerBufferingEvent(long cache);
245     void fireOnMediaPlayerPlayingEvent();
246     void fireOnMediaPlayerPausedEvent();
247     void fireOnMediaPlayerForwardEvent();
248     void fireOnMediaPlayerBackwardEvent();
249     void fireOnMediaPlayerEncounteredErrorEvent();
250     void fireOnMediaPlayerEndReachedEvent();
251     void fireOnMediaPlayerStoppedEvent();
252
253     void fireOnMediaPlayerTimeChangedEvent(long time);
254     void fireOnMediaPlayerPositionChangedEvent(long position);
255     void fireOnMediaPlayerSeekableChangedEvent(VARIANT_BOOL seekable);
256     void fireOnMediaPlayerPausableChangedEvent(VARIANT_BOOL pausable);
257
258     // controlling IUnknown interface
259     LPUNKNOWN pUnkOuter;
260
261     /*
262     ** libvlc interface
263     */
264     bool isPlaying()
265     {
266         return _p_mplayer && libvlc_media_player_is_playing(_p_mplayer);
267     }
268     int  playlist_get_current_index() { return _i_midx; }
269     int  playlist_add_extended_untrusted(const char *, int, const char **);
270     void playlist_delete_item(int idx)
271     {
272         if( _p_mlist )
273         {
274             libvlc_media_list_lock(_p_mlist);
275             libvlc_media_list_remove_index(_p_mlist,idx);
276             libvlc_media_list_unlock(_p_mlist);
277         }
278     }
279     void playlist_clear()
280     {
281         if( !_p_libvlc )
282             return;
283         if( _p_mlist )
284             libvlc_media_list_release(_p_mlist);
285         _p_mlist = libvlc_media_list_new(_p_libvlc);
286     }
287     int  playlist_count()
288     {
289          int r = 0;
290          if( !_p_mlist )
291              return 0;
292          libvlc_media_list_lock(_p_mlist);
293          r = libvlc_media_list_count(_p_mlist);
294          libvlc_media_list_unlock(_p_mlist);
295          return r;
296     }
297     void playlist_pause()
298     {
299         if( isPlaying() )
300             libvlc_media_player_pause(_p_mplayer);
301     }
302     void playlist_play()
303     {
304         if( _p_mplayer || playlist_select(0) )
305             libvlc_media_player_play(_p_mplayer);
306     }
307     void playlist_play_item(int idx)
308     {
309         if( playlist_select(idx) )
310             libvlc_media_player_play(_p_mplayer);
311     }
312     void playlist_stop()
313     {
314         if( _p_mplayer )
315             libvlc_media_player_stop(_p_mplayer);
316     }
317     void playlist_next()
318     {
319         if( playlist_select( _i_midx+1 ) )
320             libvlc_media_player_play(_p_mplayer);
321     }
322     void playlist_prev()
323     {
324         if( playlist_select( _i_midx-1 ) )
325             libvlc_media_player_play(_p_mplayer);
326     }
327
328 protected:
329
330     virtual ~VLCPlugin();
331
332 private:
333     void initVLC();
334     bool playlist_select(int i);
335     void set_player_window();
336     void player_register_events();
337     void player_unregister_events();
338
339     //implemented interfaces
340     class VLCOleObject *vlcOleObject;
341     class VLCOleControl *vlcOleControl;
342     class VLCOleInPlaceObject *vlcOleInPlaceObject;
343     class VLCOleInPlaceActiveObject *vlcOleInPlaceActiveObject;
344     class VLCPersistStreamInit *vlcPersistStreamInit;
345     class VLCPersistStorage *vlcPersistStorage;
346     class VLCPersistPropertyBag *vlcPersistPropertyBag;
347     class VLCProvideClassInfo *vlcProvideClassInfo;
348     class VLCConnectionPointContainer *vlcConnectionPointContainer;
349     class VLCObjectSafety *vlcObjectSafety;
350     class VLCControl *vlcControl;
351     class VLCControl2 *vlcControl2;
352     class VLCViewObject *vlcViewObject;
353     class VLCDataObject *vlcDataObject;
354     class VLCSupportErrorInfo *vlcSupportErrorInfo;
355
356     // in place activated window (Plugin window)
357     HWND _inplacewnd;
358
359     VLCPluginClass* _p_class;
360     ULONG _i_ref;
361
362     libvlc_instance_t     *_p_libvlc;
363     libvlc_media_list_t   *_p_mlist;
364     libvlc_media_player_t *_p_mplayer;
365     int  _i_midx;
366
367     UINT _i_codepage;
368     BOOL _b_usermode;
369     RECT _posRect;
370     LPPICTURE _p_pict;
371
372     // persistable properties
373     BSTR _bstr_baseurl;
374     BSTR _bstr_mrl;
375     BOOL _b_autoplay;
376     BOOL _b_autoloop;
377     BOOL _b_toolbar;
378     BOOL _b_visible;
379     BOOL _b_mute;
380     int  _i_volume;
381     int  _i_time;
382     SIZEL _extent;
383     OLE_COLOR _i_backcolor;
384     // indicates whether properties needs persisting
385     BOOL _b_dirty;
386 };
387
388 #endif