plugin.h 11.5 KB
Newer Older
1 2 3
/*****************************************************************************
 * plugin.h: ActiveX control for VLC
 *****************************************************************************
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 10 11 12 13 14 15 16 17 18 19 20
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
Antoine Cellerier's avatar
Antoine Cellerier committed
21
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 23 24 25 26
 *****************************************************************************/

#ifndef __PLUGIN_H__
#define __PLUGIN_H__

27 28 29
#ifdef HAVE_CONFIG
# include "config.h"
#endif
30

31 32
#include <olectl.h>

33
#include "../common/win32_fullscreen.h"
34

35 36 37 38
extern "C" const GUID CLSID_VLCPlugin;
extern "C" const GUID CLSID_VLCPlugin2;
extern "C" const GUID LIBID_AXVLC;
extern "C" const GUID DIID_DVLCEvents;
39

40 41 42 43 44 45 46
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))

typedef struct {
    const libvlc_event_type_t libvlc_type; /* libvlc event type */
    libvlc_callback_t libvlc_callback;     /* libvlc callback function */
} vlcplugin_event_t;

47 48 49 50 51
class VLCPluginClass : public IClassFactory
{

public:

52
    VLCPluginClass(LONG *p_class_ref, HINSTANCE hInstance, REFCLSID rclsid);
53 54 55 56 57 58 59

    /* IUnknown methods */
    STDMETHODIMP QueryInterface(REFIID riid, void **ppv);
    STDMETHODIMP_(ULONG) AddRef(void);
    STDMETHODIMP_(ULONG) Release(void);

    /* IClassFactory methods */
Damien Fouilleul's avatar
Damien Fouilleul committed
60
    STDMETHODIMP CreateInstance(LPUNKNOWN pUnkOuter, REFIID riid, void **ppv);
61 62
    STDMETHODIMP LockServer(BOOL fLock);

63 64
    REFCLSID getClassID(void) { return (REFCLSID)_classid; };

65
    LPCTSTR getInPlaceWndClassName(void) const { return TEXT("VLC Plugin In-Place"); };
66
    HINSTANCE getHInstance(void) const { return _hinstance; };
Damien Fouilleul's avatar
Damien Fouilleul committed
67 68
    LPPICTURE getInPlacePict(void) const
        { if( NULL != _inplace_picture) _inplace_picture->AddRef(); return _inplace_picture; };
69 70 71 72 73 74 75 76

protected:

    virtual ~VLCPluginClass();

private:

    LPLONG      _p_class_ref;
77
    ULONG       _class_ref;
78
    HINSTANCE   _hinstance;
79
    CLSID       _classid;
80
    ATOM        _inplace_wndclass_atom;
Damien Fouilleul's avatar
Damien Fouilleul committed
81
    LPPICTURE   _inplace_picture;
82 83
};

84
class VLCPlugin
85
    : public IUnknown, private vlc_player_options, private vlc_player
86 87
{
public:
Damien Fouilleul's avatar
Damien Fouilleul committed
88
    VLCPlugin(VLCPluginClass *p_class, LPUNKNOWN pUnkOuter);
89 90 91 92 93 94 95

    /* IUnknown methods */
    STDMETHODIMP QueryInterface(REFIID riid, void **ppv);
    STDMETHODIMP_(ULONG) AddRef(void);
    STDMETHODIMP_(ULONG) Release(void);

    /* custom methods */
96
    HRESULT getTypeLib(LCID lcid, ITypeLib **pTL) { return LoadRegTypeLib(LIBID_AXVLC, 1, 0, lcid, pTL); };
97
    REFCLSID getClassID(void) { return _p_class->getClassID(); };
98 99
    REFIID getDispEventID(void) { return (REFIID)DIID_DVLCEvents; };

100 101 102 103 104 105
    vlc_player& get_player()
    {
        if( !vlc_player::is_open() ) initVLC();
        return *static_cast<vlc_player*>(this);
    }

106 107 108 109 110
    vlc_player_options& get_options()
        { return *static_cast<vlc_player_options*>(this); }
    const vlc_player_options& get_options() const
        { return *static_cast<const vlc_player_options*>(this); }

111 112 113 114 115 116
    /*
    ** persistant properties
    */
    void setMRL(BSTR mrl)
    {
        SysFreeString(_bstr_mrl);
117
        _bstr_mrl = SysAllocStringLen(mrl, SysStringLen(mrl));
118 119
        setDirty(TRUE);
    };
Rafaël Carré's avatar
Rafaël Carré committed
120
    BSTR getMRL(void) { return _bstr_mrl; };
121 122 123

    inline void setAutoPlay(BOOL autoplay)
    {
124
        set_autoplay(autoplay != FALSE);
125 126
        setDirty(TRUE);
    };
127
    inline BOOL getAutoPlay(void) { return get_autoplay()? TRUE : FALSE; };
128

129
    inline void setAutoLoop(BOOL autoloop)
130 131
    {
        _b_autoloop = autoloop;
132 133 134 135
        if( vlc_player::is_open() ){
            vlc_player::set_mode(autoloop ? libvlc_playback_mode_loop :
                                            libvlc_playback_mode_default);
        }
136 137 138
        setDirty(TRUE);
    };
    inline BOOL getAutoLoop(void) { return _b_autoloop;};
139

140 141
    inline void setShowToolbar(BOOL showtoolbar)
    {
142
        set_show_toolbar(showtoolbar != FALSE);
143 144
        setDirty(TRUE);
    };
145
    inline BOOL getShowToolbar(void) { return get_show_toolbar() ? TRUE : FALSE; };
146

147
    void setVolume(int volume);
148
    int getVolume(void) { return _i_volume; };
149

150 151 152
    void setBackColor(OLE_COLOR backcolor);
    OLE_COLOR getBackColor(void) { return _i_backcolor; };

153 154
    void setVisible(BOOL fVisible);
    BOOL getVisible(void) { return _b_visible; };
155
    BOOL isVisible(void) { return _b_visible || (! _b_usermode); };
156

157 158 159 160 161 162 163
    inline void setStartTime(int time)
    {
        _i_time = time;
        setDirty(TRUE);
    };
    inline int getStartTime(void) { return _i_time; };

164 165 166
    void setTime(int time);
    int  getTime(void) { return _i_time; };

167 168 169 170 171 172
    void setBaseURL(BSTR url)
    {
        SysFreeString(_bstr_baseurl);
        _bstr_baseurl = SysAllocStringLen(url, SysStringLen(url));
        setDirty(TRUE);
    };
Rafaël Carré's avatar
Rafaël Carré committed
173
    BSTR getBaseURL(void) { return _bstr_baseurl; };
174

175 176 177 178 179 180 181 182
    // control size in HIMETRIC
    inline void setExtent(const SIZEL& extent)
    {
        _extent = extent;
        setDirty(TRUE);
    };
    const SIZEL& getExtent(void) { return _extent; };

183
    // transient properties
184 185 186 187 188 189 190
    inline void setMute(BOOL mute) { _b_mute = mute; };

    inline void setPicture(LPPICTURE pict)
    {
        if( NULL != _p_pict )
            _p_pict->Release();
        if( NULL != pict )
191
            pict->AddRef();
192 193 194 195 196 197 198 199 200
        _p_pict = pict;
    };

    inline LPPICTURE getPicture(void)
    {
        if( NULL != _p_pict )
            _p_pict->AddRef();
        return _p_pict;
    };
201

202 203 204
    BOOL hasFocus(void);
    void setFocus(BOOL fFocus);

205
    inline UINT getCodePage(void) { return _i_codepage; };
206 207 208 209 210 211 212 213
    inline void setCodePage(UINT cp)
    {
        // accept new codepage only if it works on this system
        size_t mblen = WideCharToMultiByte(cp,
                0, L"test", -1, NULL, 0, NULL, NULL);
        if( mblen > 0 )
            _i_codepage = cp;
    };
214

215 216
    inline BOOL isUserMode(void) { return _b_usermode; };
    inline void setUserMode(BOOL um) { _b_usermode = um; };
217

218 219 220
    inline BOOL isDirty(void) { return _b_dirty; };
    inline void setDirty(BOOL dirty) { _b_dirty = dirty; };

221
    inline BOOL isRunning(void) { return NULL != _p_libvlc; };
JP Dinger's avatar
JP Dinger committed
222 223 224 225 226 227

    HRESULT getVLC(libvlc_instance_t** pp_libvlc)
    {
        if( !isRunning() )
            initVLC();
        *pp_libvlc = _p_libvlc;
228
        return _p_libvlc ? S_OK : E_FAIL;
JP Dinger's avatar
JP Dinger committed
229 230 231
    }
    HRESULT getMD(libvlc_media_player_t **pp_md)
    {
232 233
        *pp_md = get_player().get_mp();
        return *pp_md ? S_OK : E_FAIL;
JP Dinger's avatar
JP Dinger committed
234
    }
235
    void setErrorInfo(REFIID riid, const char *description);
236 237

    // control geometry within container
238
    RECT getPosRect(void) { return _posRect; };
239
    inline HWND getInPlaceWindow(void) const { return _inplacewnd; };
240 241
    void toggleFullscreen();

242 243 244 245 246 247 248 249 250 251 252
    BOOL isInPlaceActive(void);

    /*
    ** container events
    */
    HRESULT onInit(void);
    HRESULT onLoad(void);
    HRESULT onActivateInPlace(LPMSG lpMesg, HWND hwndParent, LPCRECT lprcPosRect, LPCRECT lprcClipRect);
    HRESULT onInPlaceDeactivate(void);
    HRESULT onAmbientChanged(LPUNKNOWN pContainer, DISPID dispID);
    HRESULT onClose(DWORD dwSaveOption);
253
    void onPositionChange(LPCRECT lprcPosRect, LPCRECT lprcClipRect);
Damien Fouilleul's avatar
Damien Fouilleul committed
254 255
    void onDraw(DVTARGETDEVICE * ptd, HDC hicTargetDev,
            HDC hdcDraw, LPCRECTL lprcBounds, LPCRECTL lprcWBounds);
256
    void onPaint(HDC hdc, const RECT &bounds, const RECT &pr);
257

258 259 260
    /*
    ** control events
    */
Damien Fouilleul's avatar
Damien Fouilleul committed
261
    void freezeEvents(BOOL freeze);
262 263 264 265 266
    void firePropChangedEvent(DISPID dispid);
    void fireOnPlayEvent(void);
    void fireOnPauseEvent(void);
    void fireOnStopEvent(void);

267
    // async events;
268 269
    void fireOnMediaPlayerNothingSpecialEvent();
    void fireOnMediaPlayerOpeningEvent();
270
    void fireOnMediaPlayerBufferingEvent(float cache);
271 272 273 274 275 276 277 278
    void fireOnMediaPlayerPlayingEvent();
    void fireOnMediaPlayerPausedEvent();
    void fireOnMediaPlayerForwardEvent();
    void fireOnMediaPlayerBackwardEvent();
    void fireOnMediaPlayerEncounteredErrorEvent();
    void fireOnMediaPlayerEndReachedEvent();
    void fireOnMediaPlayerStoppedEvent();

279 280
    void fireOnMediaPlayerTimeChangedEvent(libvlc_time_t time);
    void fireOnMediaPlayerPositionChangedEvent(float position);
281 282
    void fireOnMediaPlayerSeekableChangedEvent(VARIANT_BOOL seekable);
    void fireOnMediaPlayerPausableChangedEvent(VARIANT_BOOL pausable);
283 284 285
    void fireOnMediaPlayerMediaChangedEvent();
    void fireOnMediaPlayerTitleChangedEvent(int title);
    void fireOnMediaPlayerLengthChangedEvent(long length);
286

Damien Fouilleul's avatar
Damien Fouilleul committed
287 288 289
    // controlling IUnknown interface
    LPUNKNOWN pUnkOuter;

JP Dinger's avatar
JP Dinger committed
290 291 292
    /*
    ** libvlc interface
    */
293
    bool isPlaying()
JP Dinger's avatar
JP Dinger committed
294
    {
295 296 297 298 299 300 301 302 303
        return get_player().is_playing();
    }
    int playlist_get_current_index()
    {
        return get_player().current_item();
    }
    int playlist_add_extended_untrusted(const char *mrl, int optc, const char **optv)
    {
        return get_player().add_item(mrl, optc, optv);
JP Dinger's avatar
JP Dinger committed
304
    }
305
    void playlist_delete_item(int idx)
JP Dinger's avatar
JP Dinger committed
306
    {
307
        get_player().delete_item(idx);
JP Dinger's avatar
JP Dinger committed
308
    }
309
    void playlist_clear()
JP Dinger's avatar
JP Dinger committed
310
    {
311
        get_player().clear_items();
JP Dinger's avatar
JP Dinger committed
312
    }
313
    int  playlist_count()
JP Dinger's avatar
JP Dinger committed
314
    {
315
         return get_player().items_count();
JP Dinger's avatar
JP Dinger committed
316
    }
317
    void playlist_pause()
JP Dinger's avatar
JP Dinger committed
318
    {
319
        get_player().pause();
JP Dinger's avatar
JP Dinger committed
320
    }
321
    void playlist_play()
JP Dinger's avatar
JP Dinger committed
322
    {
323
        get_player().play();
JP Dinger's avatar
JP Dinger committed
324
    }
325
    void playlist_play_item(int idx)
JP Dinger's avatar
JP Dinger committed
326
    {
327
        get_player().play(idx);
JP Dinger's avatar
JP Dinger committed
328
    }
329
    void playlist_stop()
JP Dinger's avatar
JP Dinger committed
330
    {
331
        get_player().stop();
JP Dinger's avatar
JP Dinger committed
332
    }
333
    void playlist_next()
JP Dinger's avatar
JP Dinger committed
334
    {
335
        get_player().next();
JP Dinger's avatar
JP Dinger committed
336
    }
337
    void playlist_prev()
JP Dinger's avatar
JP Dinger committed
338
    {
339
        get_player().prev();
JP Dinger's avatar
JP Dinger committed
340 341
    }

342
protected:
343
    void on_player_action(vlc_player_action_e);
344 345 346 347

    virtual ~VLCPlugin();

private:
JP Dinger's avatar
JP Dinger committed
348
    void initVLC();
349
    void set_player_window();
350 351
    void player_register_events();
    void player_unregister_events();
352 353 354 355 356 357 358 359 360 361 362 363 364

    //implemented interfaces
    class VLCOleObject *vlcOleObject;
    class VLCOleControl *vlcOleControl;
    class VLCOleInPlaceObject *vlcOleInPlaceObject;
    class VLCOleInPlaceActiveObject *vlcOleInPlaceActiveObject;
    class VLCPersistStreamInit *vlcPersistStreamInit;
    class VLCPersistStorage *vlcPersistStorage;
    class VLCPersistPropertyBag *vlcPersistPropertyBag;
    class VLCProvideClassInfo *vlcProvideClassInfo;
    class VLCConnectionPointContainer *vlcConnectionPointContainer;
    class VLCObjectSafety *vlcObjectSafety;
    class VLCControl *vlcControl;
365
    class VLCControl2 *vlcControl2;
366
    class VLCViewObject *vlcViewObject;
Damien Fouilleul's avatar
Damien Fouilleul committed
367
    class VLCDataObject *vlcDataObject;
368
    class VLCSupportErrorInfo *vlcSupportErrorInfo;
369

370
    // in place activated window (Plugin window)
371
    HWND _inplacewnd;
372
    VLCViewResources  _ViewRC;
373
    VLCWindowsManager _WindowsManager;
374

375
    VLCPluginClass* _p_class;
376 377
    ULONG _i_ref;

JP Dinger's avatar
JP Dinger committed
378 379
    libvlc_instance_t     *_p_libvlc;

380 381
    UINT _i_codepage;
    BOOL _b_usermode;
382
    RECT _posRect;
383
    LPPICTURE _p_pict;
384 385

    // persistable properties
386
    BSTR _bstr_baseurl;
387 388
    BSTR _bstr_mrl;
    BOOL _b_autoloop;
389
    BOOL _b_visible;
390
    BOOL _b_mute;
391
    int  _i_volume;
392
    int  _i_time;
Damien Fouilleul's avatar
Damien Fouilleul committed
393
    SIZEL _extent;
394
    OLE_COLOR _i_backcolor;
395 396
    // indicates whether properties needs persisting
    BOOL _b_dirty;
397 398 399
};

#endif