vlccontrol2.h 13.5 KB
Newer Older
1 2 3
/*****************************************************************************
 * vlccontrol.h: ActiveX control for VLC
 *****************************************************************************
4
 * Copyright (C) 2006 the VideoLAN team
5
 * Copyright (C) 2010 M2X BV
6 7
 *
 * Authors: Damien Fouilleul <Damien.Fouilleul@laposte.net>
8
 *          Jean-Paul Saman <jpsaman _at_ m2x _dot_ nl>
9 10 11 12 13 14 15 16 17 18 19
 *
 * 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.
 *
20 21 22
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 24 25 26 27 28 29
 *****************************************************************************/

#ifndef _VLCCONTROL2_H_
#define _VLCCONTROL2_H_

#include "axvlc_idl.h"

30
#include <ole2.h>
31

32 33 34 35 36 37 38 39 40 41 42
class VLCInterfaceBase {
public:
    VLCInterfaceBase(VLCPlugin *p): _plug(p), _ti(NULL) { }
    virtual ~VLCInterfaceBase() { if( _ti ) _ti->Release(); }

protected:
    HRESULT loadTypeInfo(REFIID riid);
    ITypeInfo *TypeInfo() const { return _ti; }

    STDMETHODIMP_(ULONG) AddRef(void) { return _plug->pUnkOuter->AddRef(); };
    STDMETHODIMP_(ULONG) Release(void) { return _plug->pUnkOuter->Release(); };
43

44
    VLCPlugin *_plug;
45
private:
46 47 48 49
    ITypeInfo *_ti;
};

template<class T,class I>
50
class VLCInterface: public I, protected VLCInterfaceBase
51
{
52 53 54 55 56 57 58 59 60 61
private:
    typedef VLCInterfaceBase Base;
          T *This()       { return static_cast<      T *>(this); }
    const T *This() const { return static_cast<const T *>(this); }

    HRESULT loadTypeInfo()
    {
        return TypeInfo() ? NOERROR : Base::loadTypeInfo(_riid);
    }

62
public:
63 64
    VLCInterface(VLCPlugin *p): Base(p) { }

65 66
    STDMETHODIMP QueryInterface(REFIID riid, void **ppv)
    {
67 68
        if( NULL == ppv ) return E_POINTER;

69 70
        if( (IID_IUnknown == riid)
         || (IID_IDispatch == riid)
71
         || (_riid == riid) )
72
        {
73 74
            This()->AddRef();
            *ppv = reinterpret_cast<LPVOID>(This());
75 76 77 78
            return NOERROR;
        }
        // behaves as a standalone object
        return E_NOINTERFACE;
79
    }
80

81 82 83 84 85 86 87
    STDMETHODIMP GetTypeInfoCount(UINT* pctInfo)
    {
        if( NULL == pctInfo )
            return E_INVALIDARG;
        *pctInfo = SUCCEEDED(loadTypeInfo()) ? 1 : 0;
        return NOERROR;
    }
88
    STDMETHODIMP GetTypeInfo(UINT , LCID , LPTYPEINFO* ppTInfo)
89 90 91 92 93 94 95 96 97 98 99 100 101
    {
        if( NULL == ppTInfo )
            return E_INVALIDARG;

        if( SUCCEEDED(loadTypeInfo()) )
        {
            (*ppTInfo = TypeInfo())->AddRef();
            return NOERROR;
        }
        *ppTInfo = NULL;
        return E_NOTIMPL;
    }

102 103
    STDMETHODIMP GetIDsOfNames(REFIID , LPOLESTR* rgszNames,
            UINT cNames, LCID , DISPID* rgDispID)
104 105 106 107 108
    {
        return FAILED(loadTypeInfo()) ? E_NOTIMPL :
            DispGetIDsOfNames(TypeInfo(), rgszNames, cNames, rgDispID);
    }

109 110
    STDMETHODIMP Invoke(DISPID dispIdMember, REFIID ,
        LCID , WORD wFlags, DISPPARAMS* pDispParams,
111 112 113 114 115 116 117 118 119 120 121 122
        VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
    {
        return FAILED(loadTypeInfo()) ? E_NOTIMPL :
            DispInvoke(This(), TypeInfo(), dispIdMember, wFlags,
                       pDispParams, pVarResult, pExcepInfo, puArgErr);
    }

    STDMETHODIMP_(ULONG) AddRef(void)  { return Base::AddRef(); };
    STDMETHODIMP_(ULONG) Release(void) { return Base::Release(); };
private:
    static REFIID _riid;
};
123

124 125 126 127
class VLCAudio : public VLCInterface<VLCAudio,IVLCAudio>
{
public:
    VLCAudio(VLCPlugin *p): VLCInterface<VLCAudio,IVLCAudio>(p) { }
128 129 130 131

    // IVLCAudio methods
    STDMETHODIMP get_mute(VARIANT_BOOL*);
    STDMETHODIMP put_mute(VARIANT_BOOL);
132 133
    STDMETHODIMP get_volume(long*);
    STDMETHODIMP put_volume(long);
134 135
    STDMETHODIMP get_track(long*);
    STDMETHODIMP put_track(long);
136
    STDMETHODIMP get_count(long*);
137 138
    STDMETHODIMP get_channel(long*);
    STDMETHODIMP put_channel(long);
139
    STDMETHODIMP toggleMute();
140
    STDMETHODIMP description(long trackId, BSTR*);
141
};
142

143
class VLCInput: public VLCInterface<VLCInput,IVLCInput>
144 145
{
public:
146
    VLCInput(VLCPlugin *p): VLCInterface<VLCInput,IVLCInput>(p) { }
147 148

    // IVLCInput methods
149
    STDMETHODIMP get_length(double*);
150 151
    STDMETHODIMP get_position(double*);
    STDMETHODIMP put_position(double);
152 153
    STDMETHODIMP get_time(double*);
    STDMETHODIMP put_time(double);
154 155 156 157
    STDMETHODIMP get_state(long*);
    STDMETHODIMP get_rate(double*);
    STDMETHODIMP put_rate(double);
    STDMETHODIMP get_fps(double*);
158 159
    STDMETHODIMP get_hasVout(VARIANT_BOOL*);
};
160

161
class VLCMarquee: public VLCInterface<VLCMarquee,IVLCMarquee>
162 163
{
public:
164
    VLCMarquee(VLCPlugin *p): VLCInterface<VLCMarquee,IVLCMarquee>(p) { }
Ludovic Fauvet's avatar
Ludovic Fauvet committed
165
    virtual ~VLCMarquee() { }
166 167

    // IVLCMarquee methods
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
    STDMETHODIMP enable()  { return do_put_int(libvlc_marquee_Enable, true); }
    STDMETHODIMP disable() { return do_put_int(libvlc_marquee_Enable, false); }

    STDMETHODIMP get_text(BSTR *);
    STDMETHODIMP put_text(BSTR);
    STDMETHODIMP get_position(BSTR *);
    STDMETHODIMP put_position(BSTR);

#define PROP_INT( a, b ) \
        STDMETHODIMP get_##a(LONG *val) { return do_get_int(b,val); } \
        STDMETHODIMP put_##a(LONG val)  { return do_put_int(b,val); }

    PROP_INT( color,    libvlc_marquee_Color )
    PROP_INT( opacity,  libvlc_marquee_Opacity )
    PROP_INT( refresh,  libvlc_marquee_Refresh )
    PROP_INT( size,     libvlc_marquee_Size )
    PROP_INT( timeout,  libvlc_marquee_Timeout )
    PROP_INT( x,        libvlc_marquee_X )
    PROP_INT( y,        libvlc_marquee_Y )

#undef  PROP_INT
189 190

private:
191 192
    HRESULT do_put_int(unsigned idx, LONG val);
    HRESULT do_get_int(unsigned idx, LONG *val);
193 194
};

195
class VLCLogo: public VLCInterface<VLCLogo,IVLCLogo>
196 197
{
public:
198
    VLCLogo(VLCPlugin *p): VLCInterface<VLCLogo,IVLCLogo>(p) { }
Ludovic Fauvet's avatar
Ludovic Fauvet committed
199
    virtual ~VLCLogo() { }
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227

    STDMETHODIMP enable()  { return do_put_int(libvlc_logo_enable, true); }
    STDMETHODIMP disable() { return do_put_int(libvlc_logo_enable, false); }

    STDMETHODIMP file(BSTR fname);

#define PROP_INT( a ) \
        STDMETHODIMP get_##a(LONG *val) \
            { return do_get_int(libvlc_logo_##a,val); } \
        STDMETHODIMP put_##a(LONG val) \
            { return do_put_int(libvlc_logo_##a,val); }

    PROP_INT( delay )
    PROP_INT( repeat )
    PROP_INT( opacity )
    PROP_INT( x )
    PROP_INT( y )

#undef  PROP_INT

    STDMETHODIMP get_position(BSTR* val);
    STDMETHODIMP put_position(BSTR val);

private:
    HRESULT do_put_int(unsigned idx, LONG val);
    HRESULT do_get_int(unsigned idx, LONG *val);
};

228 229 230 231 232
class VLCDeinterlace: public VLCInterface<VLCDeinterlace,IVLCDeinterlace>
{
public:
    VLCDeinterlace(VLCPlugin *p):
        VLCInterface<VLCDeinterlace,IVLCDeinterlace>(p) { }
Ludovic Fauvet's avatar
Ludovic Fauvet committed
233
    virtual ~VLCDeinterlace() { }
234 235 236 237 238

    STDMETHODIMP enable(BSTR val);
    STDMETHODIMP disable();
};

239
class VLCPlaylistItems: public VLCInterface<VLCPlaylistItems,IVLCPlaylistItems>
240 241
{
public:
242 243
    VLCPlaylistItems(VLCPlugin *p):
        VLCInterface<VLCPlaylistItems,IVLCPlaylistItems>(p) { }
244 245 246 247 248 249

    // IVLCPlaylistItems methods
    STDMETHODIMP get_count(long*);
    STDMETHODIMP clear();
    STDMETHODIMP remove(long);
};
250

251
class VLCPlaylist: public VLCInterface<VLCPlaylist,IVLCPlaylist>
252 253
{
public:
254 255 256 257
    VLCPlaylist(VLCPlugin *p):
        VLCInterface<VLCPlaylist,IVLCPlaylist>(p),
        _p_vlcplaylistitems(new VLCPlaylistItems(p)) { }
    virtual ~VLCPlaylist() { delete _p_vlcplaylistitems; }
258 259

    // IVLCPlaylist methods
260
    STDMETHODIMP get_itemCount(long*);
261
    STDMETHODIMP get_isPlaying(VARIANT_BOOL*);
262
    STDMETHODIMP get_currentItem(long*);
263
    STDMETHODIMP add(BSTR, VARIANT, VARIANT, long*);
264
    STDMETHODIMP play();
265
    STDMETHODIMP playItem(long);
266
    STDMETHODIMP pause();
267 268 269 270 271
    STDMETHODIMP togglePause();
    STDMETHODIMP stop();
    STDMETHODIMP next();
    STDMETHODIMP prev();
    STDMETHODIMP clear();
272
    STDMETHODIMP removeItem(long);
273
    STDMETHODIMP get_items(IVLCPlaylistItems**);
274

275
private:
276
    VLCPlaylistItems*    _p_vlcplaylistitems;
277
};
278

279
class VLCSubtitle: public VLCInterface<VLCSubtitle,IVLCSubtitle>
280 281
{
public:
282
    VLCSubtitle(VLCPlugin *p): VLCInterface<VLCSubtitle,IVLCSubtitle>(p) { }
283 284 285 286 287 288 289 290

    // IVLCSubtitle methods
    STDMETHODIMP get_track(long*);
    STDMETHODIMP put_track(long);
    STDMETHODIMP get_count(long*);
    STDMETHODIMP description(long, BSTR*);
};

291
class VLCVideo: public VLCInterface<VLCVideo,IVLCVideo>
292 293
{
public:
294
    VLCVideo(VLCPlugin *p): VLCInterface<VLCVideo,IVLCVideo>(p),
295 296 297
        _p_vlcmarquee(new VLCMarquee(p)), _p_vlclogo(new VLCLogo(p)),
        _p_vlcdeint(new VLCDeinterlace(p)) { }
    virtual ~VLCVideo() {
298 299 300
        _p_vlcmarquee->Release();
        _p_vlclogo->Release();
        _p_vlcdeint->Release();
301
    }
302 303 304 305

    // IVLCVideo methods
    STDMETHODIMP get_fullscreen(VARIANT_BOOL*);
    STDMETHODIMP put_fullscreen(VARIANT_BOOL);
306 307
    STDMETHODIMP get_width(long*);
    STDMETHODIMP get_height(long*);
308
    STDMETHODIMP get_aspectRatio(BSTR*);
309
    STDMETHODIMP put_aspectRatio(BSTR);
310 311
    STDMETHODIMP get_subtitle(long*);
    STDMETHODIMP put_subtitle(long);
312 313
    STDMETHODIMP get_crop(BSTR*);
    STDMETHODIMP put_crop(BSTR);
314 315
    STDMETHODIMP get_teletext(long*);
    STDMETHODIMP put_teletext(long);
316
    STDMETHODIMP get_marquee(IVLCMarquee**);
317
    STDMETHODIMP get_logo(IVLCLogo**);
318
    STDMETHODIMP get_deinterlace(IVLCDeinterlace**);
319
    STDMETHODIMP takeSnapshot(LPPICTUREDISP*);
320
    STDMETHODIMP toggleFullscreen();
321
    STDMETHODIMP toggleTeletext();
322

323
private:
324 325 326
    IVLCMarquee     *_p_vlcmarquee;
    IVLCLogo        *_p_vlclogo;
    IVLCDeinterlace *_p_vlcdeint;
327
};
328

329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358
class VLCMediaDescription:
    public VLCInterface<VLCMediaDescription, IVLCMediaDescription>
{
public:
    VLCMediaDescription(VLCPlugin *p)
        : VLCInterface<VLCMediaDescription, IVLCMediaDescription>(p) { }

    // IVLCMediaDescription methods
    STDMETHODIMP get_title(BSTR*);
    STDMETHODIMP get_artist(BSTR*);
    STDMETHODIMP get_genre(BSTR*);
    STDMETHODIMP get_copyright(BSTR*);
    STDMETHODIMP get_album(BSTR*);
    STDMETHODIMP get_trackNumber(BSTR*);
    STDMETHODIMP get_description(BSTR*);
    STDMETHODIMP get_rating(BSTR*);
    STDMETHODIMP get_date(BSTR*);
    STDMETHODIMP get_setting(BSTR*);
    STDMETHODIMP get_URL(BSTR*);
    STDMETHODIMP get_language(BSTR*);
    STDMETHODIMP get_nowPlaying(BSTR*);
    STDMETHODIMP get_publisher(BSTR*);
    STDMETHODIMP get_encodedBy(BSTR*);
    STDMETHODIMP get_artworkURL(BSTR*);
    STDMETHODIMP get_trackID(BSTR*);

private:
    STDMETHODIMP get_meta(BSTR*, libvlc_meta_t);
};

359
class VLCControl2 : public IVLCControl2
360 361 362 363 364 365 366
{
public:

    VLCControl2(VLCPlugin *p_instance);
    virtual ~VLCControl2();

    // IUnknown methods
367
    STDMETHODIMP QueryInterface(REFIID riid, void **ppv) override
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391
    {
        if( NULL == ppv )
          return E_POINTER;
        if( (IID_IUnknown == riid)
         || (IID_IDispatch == riid)
         || (IID_IVLCControl2 == riid) )
        {
            AddRef();
            *ppv = reinterpret_cast<LPVOID>(this);
            return NOERROR;
        }
        return _p_instance->pUnkOuter->QueryInterface(riid, ppv);
    };

    STDMETHODIMP_(ULONG) AddRef(void) { return _p_instance->pUnkOuter->AddRef(); };
    STDMETHODIMP_(ULONG) Release(void) { return _p_instance->pUnkOuter->Release(); };

    // IDispatch methods
    STDMETHODIMP GetTypeInfoCount(UINT*);
    STDMETHODIMP GetTypeInfo(UINT, LCID, LPTYPEINFO*);
    STDMETHODIMP GetIDsOfNames(REFIID,LPOLESTR*,UINT,LCID,DISPID*);
    STDMETHODIMP Invoke(DISPID,REFIID,LCID,WORD,DISPPARAMS*,VARIANT*,EXCEPINFO*,UINT*);

    // IVLCControl2 methods
392 393 394 395 396 397 398 399
    STDMETHODIMP get_AutoLoop(VARIANT_BOOL *autoloop);
    STDMETHODIMP put_AutoLoop(VARIANT_BOOL autoloop);
    STDMETHODIMP get_AutoPlay(VARIANT_BOOL *autoplay);
    STDMETHODIMP put_AutoPlay(VARIANT_BOOL autoplay);
    STDMETHODIMP get_BaseURL(BSTR *url);
    STDMETHODIMP put_BaseURL(BSTR url);
    STDMETHODIMP get_MRL(BSTR *mrl);
    STDMETHODIMP put_MRL(BSTR mrl);
400 401
    STDMETHODIMP get_Toolbar(VARIANT_BOOL *visible);
    STDMETHODIMP put_Toolbar(VARIANT_BOOL visible);
402 403
    STDMETHODIMP get_StartTime(long *seconds);
    STDMETHODIMP put_StartTime(long seconds);
404
    STDMETHODIMP get_VersionInfo(BSTR *version);
405
    STDMETHODIMP getVersionInfo(BSTR *version);
406 407
    STDMETHODIMP get_Visible(VARIANT_BOOL *visible);
    STDMETHODIMP put_Visible(VARIANT_BOOL visible);
408 409
    STDMETHODIMP get_Volume(long *volume);
    STDMETHODIMP put_Volume(long volume);
410 411
    STDMETHODIMP get_BackColor(OLE_COLOR *backcolor);
    STDMETHODIMP put_BackColor(OLE_COLOR backcolor);
412 413
    STDMETHODIMP get_FullscreenEnabled(VARIANT_BOOL* enabled);
    STDMETHODIMP put_FullscreenEnabled(VARIANT_BOOL enabled);
414

415 416 417
    STDMETHODIMP get_audio(IVLCAudio**);
    STDMETHODIMP get_input(IVLCInput**);
    STDMETHODIMP get_playlist(IVLCPlaylist**);
418
    STDMETHODIMP get_subtitle(IVLCSubtitle**);
419
    STDMETHODIMP get_video(IVLCVideo**);
420
    STDMETHODIMP get_mediaDescription(IVLCMediaDescription**);
421

422
protected:
423
    HRESULT loadTypeInfo();
424

425
private:
426 427 428 429 430 431 432 433
    VLCPlugin    *_p_instance;
    ITypeInfo    *_p_typeinfo;

    IVLCAudio    *_p_vlcaudio;
    IVLCInput    *_p_vlcinput;
    IVLCPlaylist *_p_vlcplaylist;
    IVLCSubtitle *_p_vlcsubtitle;
    IVLCVideo    *_p_vlcvideo;
434 435

    VLCMediaDescription    _p_vlcmedia_desc;
436 437
};

438
#endif