plugin.cpp 43.6 KB
Newer Older
1 2 3
/*****************************************************************************
 * plugin.cpp: ActiveX control for VLC
 *****************************************************************************
4
 * Copyright (C) 2006-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
#include "config.h"

26 27 28 29 30 31 32 33 34 35 36 37 38
#include "plugin.h"

#include "oleobject.h"
#include "olecontrol.h"
#include "oleinplaceobject.h"
#include "oleinplaceactiveobject.h"
#include "persistpropbag.h"
#include "persiststreaminit.h"
#include "persiststorage.h"
#include "provideclassinfo.h"
#include "connectioncontainer.h"
#include "objectsafety.h"
#include "vlccontrol.h"
39
#include "vlccontrol2.h"
40
#include "viewobject.h"
Damien Fouilleul's avatar
Damien Fouilleul committed
41
#include "dataobject.h"
42
#include "supporterrorinfo.h"
43 44 45

#include "utils.h"

46
#include <stdio.h>
47 48
#include <string.h>
#include <winreg.h>
49 50 51 52
#include <winuser.h>
#include <servprov.h>
#include <shlwapi.h>
#include <wininet.h>
53
#include <assert.h>
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72

using namespace std;

////////////////////////////////////////////////////////////////////////
//class factory

static LRESULT CALLBACK VLCInPlaceClassWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
    VLCPlugin *p_instance = reinterpret_cast<VLCPlugin *>(GetWindowLongPtr(hWnd, GWLP_USERDATA));

    switch( uMsg )
    {
        case WM_ERASEBKGND:
            return 1L;

        case WM_PAINT:
            PAINTSTRUCT ps;
            RECT pr;
            if( GetUpdateRect(hWnd, &pr, FALSE) )
            {
73 74
                RECT bounds;
                GetClientRect(hWnd, &bounds);
75
                BeginPaint(hWnd, &ps);
76
                p_instance->onPaint(ps.hdc, bounds, pr);
77 78 79
                EndPaint(hWnd, &ps);
            }
            return 0L;
80 81 82 83 84 85 86 87 88 89
        case WM_SIZE:{
            int new_client_width = LOWORD(lParam);
            int new_client_height = HIWORD(lParam);
            //first child will be resized to client area
            HWND hChildWnd = GetWindow(hWnd, GW_CHILD);
            if(hChildWnd){
                MoveWindow(hChildWnd, 0, 0, new_client_width, new_client_height, FALSE);
            }
            return 0L;
        }
90 91 92 93 94
        default:
            return DefWindowProc(hWnd, uMsg, wParam, lParam);
    }
};

95
VLCPluginClass::VLCPluginClass(LONG *p_class_ref, HINSTANCE hInstance, REFCLSID rclsid) :
96
    _p_class_ref(p_class_ref),
Damien Fouilleul's avatar
Damien Fouilleul committed
97
    _hinstance(hInstance),
98
    _classid(rclsid),
Damien Fouilleul's avatar
Damien Fouilleul committed
99
    _inplace_picture(NULL)
100 101 102 103 104
{
    WNDCLASS wClass;

    if( ! GetClassInfo(hInstance, getInPlaceWndClassName(), &wClass) )
    {
105
        wClass.style          = CS_NOCLOSE|CS_DBLCLKS;
106 107 108 109 110 111 112 113 114
        wClass.lpfnWndProc    = VLCInPlaceClassWndProc;
        wClass.cbClsExtra     = 0;
        wClass.cbWndExtra     = 0;
        wClass.hInstance      = hInstance;
        wClass.hIcon          = NULL;
        wClass.hCursor        = LoadCursor(NULL, IDC_ARROW);
        wClass.hbrBackground  = NULL;
        wClass.lpszMenuName   = NULL;
        wClass.lpszClassName  = getInPlaceWndClassName();
115

116 117 118 119 120 121 122
        _inplace_wndclass_atom = RegisterClass(&wClass);
    }
    else
    {
        _inplace_wndclass_atom = 0;
    }

123
    HBITMAP hbitmap = (HBITMAP)LoadImage(getHInstance(), MAKEINTRESOURCE(2), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR);
Damien Fouilleul's avatar
Damien Fouilleul committed
124 125 126 127 128 129 130 131
    if( NULL != hbitmap )
    {
        PICTDESC pictDesc;

        pictDesc.cbSizeofstruct = sizeof(PICTDESC);
        pictDesc.picType        = PICTYPE_BITMAP;
        pictDesc.bmp.hbitmap    = hbitmap;
        pictDesc.bmp.hpal       = NULL;
132

Damien Fouilleul's avatar
Damien Fouilleul committed
133 134 135
        if( FAILED(OleCreatePictureIndirect(&pictDesc, IID_IPicture, TRUE, reinterpret_cast<LPVOID*>(&_inplace_picture))) )
            _inplace_picture = NULL;
    }
136 137 138 139 140 141 142 143
    AddRef();
};

VLCPluginClass::~VLCPluginClass()
{
    if( 0 != _inplace_wndclass_atom )
        UnregisterClass(MAKEINTATOM(_inplace_wndclass_atom), _hinstance);

Damien Fouilleul's avatar
Damien Fouilleul committed
144 145
    if( NULL != _inplace_picture )
        _inplace_picture->Release();
146 147 148 149 150 151 152
};

STDMETHODIMP VLCPluginClass::QueryInterface(REFIID riid, void **ppv)
{
    if( NULL == ppv )
        return E_INVALIDARG;

153 154
    if( (IID_IUnknown == riid)
     || (IID_IClassFactory == riid) )
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
    {
        AddRef();
        *ppv = reinterpret_cast<LPVOID>(this);

        return NOERROR;
    }

    *ppv = NULL;

    return E_NOINTERFACE;
};

STDMETHODIMP_(ULONG) VLCPluginClass::AddRef(void)
{
    return InterlockedIncrement(_p_class_ref);
};

STDMETHODIMP_(ULONG) VLCPluginClass::Release(void)
{
    ULONG refcount = InterlockedDecrement(_p_class_ref);
    if( 0 == refcount )
    {
        delete this;
        return 0;
    }
    return refcount;
};

Damien Fouilleul's avatar
Damien Fouilleul committed
183
STDMETHODIMP VLCPluginClass::CreateInstance(LPUNKNOWN pUnkOuter, REFIID riid, void **ppv)
184 185 186 187 188 189
{
    if( NULL == ppv )
        return E_POINTER;

    *ppv = NULL;

Damien Fouilleul's avatar
Damien Fouilleul committed
190
    if( (NULL != pUnkOuter) && (IID_IUnknown != riid) ) {
191
        return CLASS_E_NOAGGREGATION;
Damien Fouilleul's avatar
Damien Fouilleul committed
192
    }
193

Damien Fouilleul's avatar
Damien Fouilleul committed
194
    VLCPlugin *plugin = new VLCPlugin(this, pUnkOuter);
195 196 197
    if( NULL != plugin )
    {
        HRESULT hr = plugin->QueryInterface(riid, ppv);
198
        // the following will destroy the object if QueryInterface() failed
199 200 201 202 203 204 205 206 207 208
        plugin->Release();
        return hr;
    }
    return E_OUTOFMEMORY;
};

STDMETHODIMP VLCPluginClass::LockServer(BOOL fLock)
{
    if( fLock )
        AddRef();
209
    else
210 211 212 213 214 215
        Release();

    return S_OK;
};

////////////////////////////////////////////////////////////////////////
216
extern HMODULE DllGetModule();
217

Damien Fouilleul's avatar
Damien Fouilleul committed
218
VLCPlugin::VLCPlugin(VLCPluginClass *p_class, LPUNKNOWN pUnkOuter) :
219
    _inplacewnd(NULL),
220
    _WindowsManager(DllGetModule(), _ViewRC, this),
221 222
    _p_class(p_class),
    _i_ref(1UL),
223
    _p_libvlc(NULL),
JP Dinger's avatar
JP Dinger committed
224 225 226
    _p_mlist(NULL),
    _p_mplayer(NULL),
    _i_midx(-1),
227
    _i_codepage(CP_ACP),
Rafaël Carré's avatar
Rafaël Carré committed
228
    _b_usermode(TRUE)
229
{
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
    _ViewRC.hDeFullscreenBitmap =
        LoadImage(DllGetModule(), MAKEINTRESOURCE(3),
                  IMAGE_BITMAP, 0, 0, LR_LOADMAP3DCOLORS);

    _ViewRC.hPlayBitmap =
        LoadImage(DllGetModule(), MAKEINTRESOURCE(4),
                  IMAGE_BITMAP, 0, 0, LR_LOADMAP3DCOLORS);

    _ViewRC.hPauseBitmap =
        LoadImage(DllGetModule(), MAKEINTRESOURCE(5),
                  IMAGE_BITMAP, 0, 0, LR_LOADMAP3DCOLORS);

    _ViewRC.hVolumeBitmap =
        LoadImage(DllGetModule(), MAKEINTRESOURCE(6),
                  IMAGE_BITMAP, 0, 0, LR_LOADMAP3DCOLORS);

    _ViewRC.hVolumeMutedBitmap =
        LoadImage(DllGetModule(), MAKEINTRESOURCE(7),
                  IMAGE_BITMAP, 0, 0, LR_LOADMAP3DCOLORS);

    _ViewRC.hBackgroundIcon =
        (HICON) LoadImage(DllGetModule(), MAKEINTRESOURCE(8),
                          IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);

    _ViewRC.hFullscreenBitmap =
        LoadImage(DllGetModule(), MAKEINTRESOURCE(9),
                  IMAGE_BITMAP, 0, 0, LR_LOADMAP3DCOLORS);

258 259 260 261 262 263 264 265 266 267 268 269
    p_class->AddRef();

    vlcOleControl = new VLCOleControl(this);
    vlcOleInPlaceObject = new VLCOleInPlaceObject(this);
    vlcOleInPlaceActiveObject = new VLCOleInPlaceActiveObject(this);
    vlcPersistStorage = new VLCPersistStorage(this);
    vlcPersistStreamInit = new VLCPersistStreamInit(this);
    vlcPersistPropertyBag = new VLCPersistPropertyBag(this);
    vlcProvideClassInfo = new VLCProvideClassInfo(this);
    vlcConnectionPointContainer = new VLCConnectionPointContainer(this);
    vlcObjectSafety = new VLCObjectSafety(this);
    vlcControl = new VLCControl(this);
270
    vlcControl2 = new VLCControl2(this);
271
    vlcViewObject = new VLCViewObject(this);
Damien Fouilleul's avatar
Damien Fouilleul committed
272
    vlcDataObject = new VLCDataObject(this);
273
    vlcOleObject = new VLCOleObject(this);
274
    vlcSupportErrorInfo = new VLCSupportErrorInfo(this);
Damien Fouilleul's avatar
Damien Fouilleul committed
275 276 277 278 279

    // configure controlling IUnknown interface for implemented interfaces
    this->pUnkOuter = (NULL != pUnkOuter) ? pUnkOuter : dynamic_cast<LPUNKNOWN>(this);

    // default picure
280
    _p_pict = p_class->getInPlacePict();
Damien Fouilleul's avatar
Damien Fouilleul committed
281

282 283
    // make sure that persistable properties are initialized
    onInit();
284 285 286 287
};

VLCPlugin::~VLCPlugin()
{
288
    delete vlcSupportErrorInfo;
289
    delete vlcOleObject;
Damien Fouilleul's avatar
Damien Fouilleul committed
290
    delete vlcDataObject;
291
    delete vlcViewObject;
292
    delete vlcControl2;
293 294 295 296 297 298 299 300
    delete vlcControl;
    delete vlcConnectionPointContainer;
    delete vlcProvideClassInfo;
    delete vlcPersistPropertyBag;
    delete vlcPersistStreamInit;
    delete vlcPersistStorage;
    delete vlcOleInPlaceActiveObject;
    delete vlcOleInPlaceObject;
301
    delete vlcObjectSafety;
302

303 304 305
    delete vlcOleControl;
    if( _p_pict )
        _p_pict->Release();
Damien Fouilleul's avatar
Damien Fouilleul committed
306

Damien Fouilleul's avatar
Damien Fouilleul committed
307
    SysFreeString(_bstr_mrl);
308
    SysFreeString(_bstr_baseurl);
309

310 311
    if( _p_mplayer )
    {
312 313 314
        if( isPlaying() )
            playlist_stop();

315 316 317 318
        player_unregister_events();
        libvlc_media_player_release(_p_mplayer);
        _p_mplayer=NULL;
    }
JP Dinger's avatar
JP Dinger committed
319 320 321
    if( _p_mlist )   { libvlc_media_list_release(_p_mlist); _p_mlist=NULL; }
    if( _p_libvlc )  { libvlc_release(_p_libvlc); _p_libvlc=NULL; }

322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342
    _p_class->Release();
};

STDMETHODIMP VLCPlugin::QueryInterface(REFIID riid, void **ppv)
{
    if( NULL == ppv )
        return E_INVALIDARG;

    if( IID_IUnknown == riid )
        *ppv = reinterpret_cast<LPVOID>(this);
    else if( IID_IOleObject == riid )
        *ppv = reinterpret_cast<LPVOID>(vlcOleObject);
    else if( IID_IOleControl == riid )
        *ppv = reinterpret_cast<LPVOID>(vlcOleControl);
    else if( IID_IOleWindow == riid )
        *ppv = reinterpret_cast<LPVOID>(vlcOleInPlaceObject);
    else if( IID_IOleInPlaceObject == riid )
        *ppv = reinterpret_cast<LPVOID>(vlcOleInPlaceObject);
    else if( IID_IOleInPlaceActiveObject == riid )
        *ppv = reinterpret_cast<LPVOID>(vlcOleInPlaceActiveObject);
    else if( IID_IPersist == riid )
343
        *ppv = reinterpret_cast<LPVOID>(vlcPersistStreamInit);
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358
    else if( IID_IPersistStreamInit == riid )
        *ppv = reinterpret_cast<LPVOID>(vlcPersistStreamInit);
    else if( IID_IPersistStorage == riid )
        *ppv = reinterpret_cast<LPVOID>(vlcPersistStorage);
    else if( IID_IPersistPropertyBag == riid )
        *ppv = reinterpret_cast<LPVOID>(vlcPersistPropertyBag);
    else if( IID_IProvideClassInfo == riid )
        *ppv = reinterpret_cast<LPVOID>(vlcProvideClassInfo);
    else if( IID_IProvideClassInfo2 == riid )
        *ppv = reinterpret_cast<LPVOID>(vlcProvideClassInfo);
    else if( IID_IConnectionPointContainer == riid )
        *ppv = reinterpret_cast<LPVOID>(vlcConnectionPointContainer);
    else if( IID_IObjectSafety == riid )
        *ppv = reinterpret_cast<LPVOID>(vlcObjectSafety);
    else if( IID_IDispatch == riid )
359 360 361
        *ppv = (CLSID_VLCPlugin2 == getClassID()) ?
                reinterpret_cast<LPVOID>(vlcControl2) :
                reinterpret_cast<LPVOID>(vlcControl);
362 363
    else if( IID_IVLCControl == riid )
        *ppv = reinterpret_cast<LPVOID>(vlcControl);
364 365
    else if( IID_IVLCControl2 == riid )
        *ppv = reinterpret_cast<LPVOID>(vlcControl2);
366 367
    else if( IID_IViewObject == riid )
        *ppv = reinterpret_cast<LPVOID>(vlcViewObject);
Damien Fouilleul's avatar
Damien Fouilleul committed
368 369
    else if( IID_IViewObject2 == riid )
        *ppv = reinterpret_cast<LPVOID>(vlcViewObject);
Damien Fouilleul's avatar
Damien Fouilleul committed
370 371
    else if( IID_IDataObject == riid )
        *ppv = reinterpret_cast<LPVOID>(vlcDataObject);
372 373
    else if( IID_ISupportErrorInfo == riid )
        *ppv = reinterpret_cast<LPVOID>(vlcSupportErrorInfo);
Damien Fouilleul's avatar
Damien Fouilleul committed
374 375 376 377
    else
    {
        *ppv = NULL;
        return E_NOINTERFACE;
Damien Fouilleul's avatar
Damien Fouilleul committed
378
    }
Damien Fouilleul's avatar
Damien Fouilleul committed
379 380
    ((LPUNKNOWN)*ppv)->AddRef();
    return NOERROR;
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399
};

STDMETHODIMP_(ULONG) VLCPlugin::AddRef(void)
{
    return InterlockedIncrement((LONG *)&_i_ref);
};

STDMETHODIMP_(ULONG) VLCPlugin::Release(void)
{
    if( ! InterlockedDecrement((LONG *)&_i_ref) )
    {
        delete this;
        return 0;
    }
    return _i_ref;
};

//////////////////////////////////////

400
HRESULT VLCPlugin::onInit(void)
401
{
402
    if( NULL == _p_libvlc )
403
    {
404
        // initialize persistable properties
405
        set_autoplay(true);
406
        _b_autoloop   = FALSE;
407
        set_show_toolbar(false);
408
        _bstr_baseurl = NULL;
409 410 411 412 413 414
        _bstr_mrl     = NULL;
        _b_visible    = TRUE;
        _b_mute       = FALSE;
        _i_volume     = 50;
        _i_time       = 0;
        _i_backcolor  = 0;
415 416 417 418 419 420
        // set default/preferred size (320x240) pixels in HIMETRIC
        HDC hDC = CreateDevDC(NULL);
        _extent.cx = 320;
        _extent.cy = 240;
        HimetricFromDP(hDC, (LPPOINT)&_extent, 1);
        DeleteDC(hDC);
421 422 423

        return S_OK;
    }
Damien Fouilleul's avatar
Damien Fouilleul committed
424
    return CO_E_ALREADYINITIALIZED;
425
};
426 427 428

HRESULT VLCPlugin::onLoad(void)
{
429
    if( SysStringLen(_bstr_baseurl) == 0 )
430
    {
431
        /*
432
        ** try to retreive the base URL using the client site moniker, which for Internet Explorer
433
        ** is the URL of the page the plugin is embedded into.
434
        */
435
        LPOLECLIENTSITE pClientSite;
Damien Fouilleul's avatar
Damien Fouilleul committed
436
        if( SUCCEEDED(vlcOleObject->GetClientSite(&pClientSite)) && (NULL != pClientSite) )
437 438 439 440 441 442 443 444
        {
            IBindCtx *pBC = 0;
            if( SUCCEEDED(CreateBindCtx(0, &pBC)) )
            {
                LPMONIKER pContMoniker = NULL;
                if( SUCCEEDED(pClientSite->GetMoniker(OLEGETMONIKER_ONLYIFTHERE,
                                OLEWHICHMK_CONTAINER, &pContMoniker)) )
                {
445 446
                    LPOLESTR base_url;
                    if( SUCCEEDED(pContMoniker->GetDisplayName(pBC, NULL, &base_url)) )
447
                    {
448 449 450
                        /*
                        ** check that the moniker name is a URL
                        */
451
                        if( UrlIsW(base_url, URLIS_URL) )
452
                        {
453
                            /* copy base URL */
454
                            _bstr_baseurl = SysAllocString(base_url);
455
                        }
456
                        CoTaskMemFree(base_url);
457 458 459 460
                    }
                }
            }
        }
461 462 463 464 465
    }
    setDirty(FALSE);
    return S_OK;
};

JP Dinger's avatar
JP Dinger committed
466
void VLCPlugin::initVLC()
467
{
468 469
    extern HMODULE DllGetModule();

JP Dinger's avatar
JP Dinger committed
470 471 472 473 474
    /*
    ** default initialization options
    */
    const char *ppsz_argv[32] = { };
    int   ppsz_argc = 0;
475

JP Dinger's avatar
JP Dinger committed
476 477 478 479
    char p_progpath[MAX_PATH];
    {
        TCHAR w_progpath[MAX_PATH];
        DWORD len = GetModuleFileName(DllGetModule(), w_progpath, MAX_PATH);
480
        w_progpath[MAX_PATH-1] = '\0';
JP Dinger's avatar
JP Dinger committed
481
        if( len > 0 )
Damien Fouilleul's avatar
Damien Fouilleul committed
482
        {
JP Dinger's avatar
JP Dinger committed
483 484
            len = WideCharToMultiByte(CP_UTF8, 0, w_progpath, len, p_progpath,
                       sizeof(p_progpath)-1, NULL, NULL);
Damien Fouilleul's avatar
Damien Fouilleul committed
485 486
            if( len > 0 )
            {
JP Dinger's avatar
JP Dinger committed
487 488
                p_progpath[len] = '\0';
                ppsz_argv[0] = p_progpath;
Damien Fouilleul's avatar
Damien Fouilleul committed
489 490
            }
        }
JP Dinger's avatar
JP Dinger committed
491
    }
Damien Fouilleul's avatar
Damien Fouilleul committed
492

JP Dinger's avatar
JP Dinger committed
493
    ppsz_argv[ppsz_argc++] = "-vv";
Damien Fouilleul's avatar
Damien Fouilleul committed
494

JP Dinger's avatar
JP Dinger committed
495 496 497 498 499 500 501 502 503
    HKEY h_key;
    char p_pluginpath[MAX_PATH];
    if( RegOpenKeyEx( HKEY_LOCAL_MACHINE, TEXT("Software\\VideoLAN\\VLC"),
                      0, KEY_READ, &h_key ) == ERROR_SUCCESS )
    {
        DWORD i_type, i_data = MAX_PATH;
        TCHAR w_pluginpath[MAX_PATH];
        if( RegQueryValueEx( h_key, TEXT("InstallDir"), 0, &i_type,
                             (LPBYTE)w_pluginpath, &i_data ) == ERROR_SUCCESS )
504
        {
505
            w_pluginpath[MAX_PATH-1] = '\0';
JP Dinger's avatar
JP Dinger committed
506
            if( i_type == REG_SZ )
507
            {
JP Dinger's avatar
JP Dinger committed
508 509
                if( WideCharToMultiByte(CP_UTF8, 0, w_pluginpath, -1, p_pluginpath,
                         sizeof(p_pluginpath)-sizeof("\\plugins")+1, NULL, NULL) )
510
                {
JP Dinger's avatar
JP Dinger committed
511 512 513
                    strcat( p_pluginpath, "\\plugins" );
                    ppsz_argv[ppsz_argc++] = "--plugin-path";
                    ppsz_argv[ppsz_argc++] = p_pluginpath;
514 515
                }
            }
516
        }
JP Dinger's avatar
JP Dinger committed
517 518
        RegCloseKey( h_key );
    }
519

JP Dinger's avatar
JP Dinger committed
520 521
    // make sure plugin isn't affected with VLC single instance mode
    ppsz_argv[ppsz_argc++] = "--no-one-instance";
522

JP Dinger's avatar
JP Dinger committed
523
    /* common settings */
524
    ppsz_argv[ppsz_argc++] = "-vv";
JP Dinger's avatar
JP Dinger committed
525 526 527
    ppsz_argv[ppsz_argc++] = "--no-stats";
    ppsz_argv[ppsz_argc++] = "--no-media-library";
    ppsz_argv[ppsz_argc++] = "--intf=dummy";
528 529
    ppsz_argv[ppsz_argc++] = "--no-video-title-show";

530

JP Dinger's avatar
JP Dinger committed
531 532 533
    // loop mode is a configuration option only
    if( _b_autoloop )
        ppsz_argv[ppsz_argc++] = "--loop";
534

535 536
    _p_libvlc = libvlc_new(ppsz_argc, ppsz_argv);
    if( !_p_libvlc )
JP Dinger's avatar
JP Dinger committed
537
        return;
538

539
    _p_mlist = libvlc_media_list_new(_p_libvlc);
540

JP Dinger's avatar
JP Dinger committed
541 542 543 544 545 546 547 548 549 550 551 552
    // initial playlist item
    if( SysStringLen(_bstr_mrl) > 0 )
    {
        char *psz_mrl = NULL;

        if( SysStringLen(_bstr_baseurl) > 0 )
        {
            /*
            ** if the MRL a relative URL, we should end up with an absolute URL
            */
            LPWSTR abs_url = CombineURL(_bstr_baseurl, _bstr_mrl);
            if( NULL != abs_url )
553
            {
JP Dinger's avatar
JP Dinger committed
554 555
                psz_mrl = CStrFromWSTR(CP_UTF8, abs_url, wcslen(abs_url));
                CoTaskMemFree(abs_url);
556 557 558 559
            }
            else
            {
                psz_mrl = CStrFromBSTR(CP_UTF8, _bstr_mrl);
560
            }
JP Dinger's avatar
JP Dinger committed
561 562 563 564 565 566 567 568 569 570 571 572
        }
        else
        {
            /*
            ** baseURL is empty, assume MRL is absolute
            */
            psz_mrl = CStrFromBSTR(CP_UTF8, _bstr_mrl);
        }
        if( NULL != psz_mrl )
        {
            const char *options[1];
            int i_options = 0;
573

JP Dinger's avatar
JP Dinger committed
574 575 576 577 578
            char timeBuffer[32];
            if( _i_time )
            {
                snprintf(timeBuffer, sizeof(timeBuffer), ":start-time=%d", _i_time);
                options[i_options++] = timeBuffer;
579
            }
JP Dinger's avatar
JP Dinger committed
580
            // add default target to playlist
581
            playlist_add_extended_untrusted(psz_mrl, i_options, options);
JP Dinger's avatar
JP Dinger committed
582
            CoTaskMemFree(psz_mrl);
583
        }
584 585 586
    }
};

587 588 589 590 591 592 593
void VLCPlugin::setErrorInfo(REFIID riid, const char *description)
{
    vlcSupportErrorInfo->setErrorInfo( getClassID() == CLSID_VLCPlugin2 ?
        OLESTR("VideoLAN.VLCPlugin.2") : OLESTR("VideoLAN.VLCPlugin.1"),
        riid, description );
};

594
HRESULT VLCPlugin::onAmbientChanged(LPUNKNOWN pContainer, DISPID dispID)
595
{
596 597
    VARIANT v;
    switch( dispID )
598
    {
599
        case DISPID_AMBIENT_BACKCOLOR:
600 601 602 603 604 605
            VariantInit(&v);
            V_VT(&v) = VT_I4;
            if( SUCCEEDED(GetObjectProperty(pContainer, dispID, v)) )
            {
                setBackColor(V_I4(&v));
            }
606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659
            break;
        case DISPID_AMBIENT_DISPLAYNAME:
            break;
        case DISPID_AMBIENT_FONT:
            break;
        case DISPID_AMBIENT_FORECOLOR:
            break;
        case DISPID_AMBIENT_LOCALEID:
            break;
        case DISPID_AMBIENT_MESSAGEREFLECT:
            break;
        case DISPID_AMBIENT_SCALEUNITS:
            break;
        case DISPID_AMBIENT_TEXTALIGN:
            break;
        case DISPID_AMBIENT_USERMODE:
            VariantInit(&v);
            V_VT(&v) = VT_BOOL;
            if( SUCCEEDED(GetObjectProperty(pContainer, dispID, v)) )
            {
                setUserMode(V_BOOL(&v) != VARIANT_FALSE);
            }
            break;
        case DISPID_AMBIENT_UIDEAD:
            break;
        case DISPID_AMBIENT_SHOWGRABHANDLES:
            break;
        case DISPID_AMBIENT_SHOWHATCHING:
            break;
        case DISPID_AMBIENT_DISPLAYASDEFAULT:
            break;
        case DISPID_AMBIENT_SUPPORTSMNEMONICS:
            break;
        case DISPID_AMBIENT_AUTOCLIP:
            break;
        case DISPID_AMBIENT_APPEARANCE:
            break;
        case DISPID_AMBIENT_CODEPAGE:
            VariantInit(&v);
            V_VT(&v) = VT_I4;
            if( SUCCEEDED(GetObjectProperty(pContainer, dispID, v)) )
            {
                setCodePage(V_I4(&v));
            }
            break;
        case DISPID_AMBIENT_PALETTE:
            break;
        case DISPID_AMBIENT_CHARSET:
            break;
        case DISPID_AMBIENT_RIGHTTOLEFT:
            break;
        case DISPID_AMBIENT_TOPTOBOTTOM:
            break;
        case DISPID_UNKNOWN:
660 661 662
            /*
            ** multiple property change, look up the ones we are interested in
            */
663 664 665 666 667 668 669 670
            VariantInit(&v);
            V_VT(&v) = VT_BOOL;
            if( SUCCEEDED(GetObjectProperty(pContainer, DISPID_AMBIENT_USERMODE, v)) )
            {
                setUserMode(V_BOOL(&v) != VARIANT_FALSE);
            }
            VariantInit(&v);
            V_VT(&v) = VT_I4;
671
            if( SUCCEEDED(GetObjectProperty(pContainer, DISPID_AMBIENT_CODEPAGE, v)) )
672 673 674 675
            {
                setCodePage(V_I4(&v));
            }
            break;
676 677 678 679
    }
    return S_OK;
};

680 681
HRESULT VLCPlugin::onClose(DWORD dwSaveOption)
{
682 683 684 685 686
    if( isInPlaceActive() )
    {
        onInPlaceDeactivate();
    }
    if( isRunning() )
687
    {
688
        libvlc_instance_t* p_libvlc = _p_libvlc;
Damien Fouilleul's avatar
Damien Fouilleul committed
689

690
        _p_libvlc = NULL;
Damien Fouilleul's avatar
Damien Fouilleul committed
691
        vlcDataObject->onClose();
692

693 694
        if( p_libvlc )
            libvlc_release(p_libvlc);
695 696 697 698 699 700 701 702 703 704 705
    }
    return S_OK;
};

BOOL VLCPlugin::isInPlaceActive(void)
{
    return (NULL != _inplacewnd);
};

HRESULT VLCPlugin::onActivateInPlace(LPMSG lpMesg, HWND hwndParent, LPCRECT lprcPosRect, LPCRECT lprcClipRect)
{
Damien Fouilleul's avatar
Damien Fouilleul committed
706
    RECT clipRect = *lprcClipRect;
707

Damien Fouilleul's avatar
Damien Fouilleul committed
708 709
    /*
    ** record keeping of control geometry within container
710
    */
711
    _posRect = *lprcPosRect;
712

Damien Fouilleul's avatar
Damien Fouilleul committed
713 714
    /*
    ** Create a window for in place activated control.
715 716
    ** the window geometry matches the control viewport
    ** within container so that embedded video is always
717
    ** properly displayed.
Damien Fouilleul's avatar
Damien Fouilleul committed
718
    */
719
    _inplacewnd = CreateWindow(_p_class->getInPlaceWndClassName(),
720
            TEXT("VLC Plugin In-Place Window"),
721
            WS_CHILD|WS_CLIPCHILDREN|WS_CLIPSIBLINGS,
722 723 724 725
            lprcPosRect->left,
            lprcPosRect->top,
            lprcPosRect->right-lprcPosRect->left,
            lprcPosRect->bottom-lprcPosRect->top,
726 727 728 729 730 731 732 733 734 735 736
            hwndParent,
            0,
            _p_class->getHInstance(),
            NULL
           );

    if( NULL == _inplacewnd )
        return E_FAIL;

    SetWindowLongPtr(_inplacewnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this));

737 738
    /* change cliprect coordinates system relative to window bounding rect */
    OffsetRect(&clipRect, -lprcPosRect->left, -lprcPosRect->top);
739

740 741
    HRGN clipRgn = CreateRectRgnIndirect(&clipRect);
    SetWindowRgn(_inplacewnd, clipRgn, TRUE);
742

743 744
    _WindowsManager.CreateWindows(this->getInPlaceWindow());

745
    if( _b_usermode )
746
    {
747
        /* will run vlc if not done already */
748 749
        libvlc_instance_t* p_libvlc;
        HRESULT result = getVLC(&p_libvlc);
750 751 752
        if( FAILED(result) )
            return result;

753
        if( get_autoplay() && playlist_select(0) )
754
        {
755
            libvlc_media_player_play(_p_mplayer);
JP Dinger's avatar
JP Dinger committed
756
            fireOnPlayEvent();
757
        }
758
    }
759 760 761 762

    if( isVisible() )
        ShowWindow(_inplacewnd, SW_SHOW);

763 764 765
    return S_OK;
};

766 767 768 769 770
void VLCPlugin::toggleFullscreen()
{
    _WindowsManager.ToggleFullScreen();
}

771 772
HRESULT VLCPlugin::onInPlaceDeactivate(void)
{
773
    if( isPlaying() )
774
    {
775
        playlist_stop();
776 777
        fireOnStopEvent();
    }
778

779 780
    _WindowsManager.DestroyWindows();

781 782
    DestroyWindow(_inplacewnd);
    _inplacewnd = NULL;
783

784 785 786 787 788
    return S_OK;
};

void VLCPlugin::setVisible(BOOL fVisible)
{
789 790 791 792 793 794
    if( fVisible != _b_visible )
    {
        _b_visible = fVisible;
        if( isInPlaceActive() )
        {
            ShowWindow(_inplacewnd, fVisible ? SW_SHOW : SW_HIDE);
795
            if( fVisible )
796
                InvalidateRect(_inplacewnd, NULL, TRUE);
797
        }
798
        setDirty(TRUE);
799 800
        firePropChangedEvent(DISPID_Visible);
    }
801 802
};

803 804 805 806 807 808 809 810 811 812 813 814
void VLCPlugin::setVolume(int volume)
{
    if( volume < 0 )
        volume = 0;
    else if( volume > 200 )
        volume = 200;

    if( volume != _i_volume )
    {
        _i_volume = volume;
        if( isRunning() )
        {
815 816 817 818
            libvlc_media_player_t *p_md;
            HRESULT hr = getMD(&p_md);
            if( SUCCEEDED(hr) )
                libvlc_audio_set_volume(p_md, _i_volume);
819 820 821 822 823
        }
        setDirty(TRUE);
    }
};

824 825 826 827 828 829 830 831 832 833 834 835 836
void VLCPlugin::setBackColor(OLE_COLOR backcolor)
{
    if( _i_backcolor != backcolor )
    {
        _i_backcolor = backcolor;
        if( isInPlaceActive() )
        {

        }
        setDirty(TRUE);
    }
};

837 838 839 840 841 842 843
void VLCPlugin::setTime(int seconds)
{
    if( seconds < 0 )
        seconds = 0;

    if( seconds != _i_time )
    {
844
        setStartTime(_i_time);
JP Dinger's avatar
JP Dinger committed
845
        if( NULL != _p_mplayer )
846
        {
847
            libvlc_media_player_set_time(_p_mplayer, _i_time);
848 849 850 851
        }
    }
};

852 853 854 855 856 857 858 859 860 861 862
void VLCPlugin::setFocus(BOOL fFocus)
{
    if( fFocus )
        SetActiveWindow(_inplacewnd);
};

BOOL VLCPlugin::hasFocus(void)
{
    return GetActiveWindow() == _inplacewnd;
};

Damien Fouilleul's avatar
Damien Fouilleul committed
863 864
void VLCPlugin::onDraw(DVTARGETDEVICE * ptd, HDC hicTargetDev,
        HDC hdcDraw, LPCRECTL lprcBounds, LPCRECTL lprcWBounds)
865
{
866
    if( isVisible() )
867
    {
Damien Fouilleul's avatar
Damien Fouilleul committed
868 869 870 871
        long width = lprcBounds->right-lprcBounds->left;
        long height = lprcBounds->bottom-lprcBounds->top;

        RECT bounds = { lprcBounds->left, lprcBounds->top, lprcBounds->right, lprcBounds->bottom };
872

873
        if( isUserMode() )
874
        {
875 876 877 878
            /* VLC is in user mode, just draw background color */
            COLORREF colorref = RGB(0, 0, 0);
            OleTranslateColor(_i_backcolor, (HPALETTE)GetStockObject(DEFAULT_PALETTE), &colorref);
            if( colorref != RGB(0, 0, 0) )
879
            {
880 881 882 883
                /* custom background */
                HBRUSH colorbrush = CreateSolidBrush(colorref);
                FillRect(hdcDraw, &bounds, colorbrush);
                DeleteObject((HANDLE)colorbrush);
884
            }
885
            else
886
            {
887 888
                /* black background */
                FillRect(hdcDraw, &bounds, (HBRUSH)GetStockObject(BLACK_BRUSH));
889
            }
890 891 892 893 894
        }
        else
        {
            /* VLC is in design mode, draw the VLC logo */
            FillRect(hdcDraw, &bounds, (HBRUSH)GetStockObject(WHITE_BRUSH));
895

896 897 898 899 900
            LPPICTURE pict = getPicture();
            if( NULL != pict )
            {
                OLE_XSIZE_HIMETRIC picWidth;
                OLE_YSIZE_HIMETRIC picHeight;
Damien Fouilleul's avatar
Damien Fouilleul committed
901

902 903
                pict->get_Width(&picWidth);
                pict->get_Height(&picHeight);
Damien Fouilleul's avatar
Damien Fouilleul committed
904

905
                SIZEL picSize = { picWidth, picHeight };
Damien Fouilleul's avatar
Damien Fouilleul committed
906

907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923
                if( NULL != hicTargetDev )
                {
                    DPFromHimetric(hicTargetDev, (LPPOINT)&picSize, 1);
                }
                else if( NULL != (hicTargetDev = CreateDevDC(ptd)) )
                {
                    DPFromHimetric(hicTargetDev, (LPPOINT)&picSize, 1);
                    DeleteDC(hicTargetDev);
                }

                if( picSize.cx > width-4 )
                    picSize.cx = width-4;
                if( picSize.cy > height-4 )
                    picSize.cy = height-4;

                LONG dstX = lprcBounds->left+(width-picSize.cx)/2;
                LONG dstY = lprcBounds->top+(height-picSize.cy)/2;
924

925 926 927 928 929 930
                if( NULL != lprcWBounds )
                {
                    RECT wBounds = { lprcWBounds->left, lprcWBounds->top, lprcWBounds->right, lprcWBounds->bottom };
                    pict->Render(hdcDraw, dstX, dstY, picSize.cx, picSize.cy,
                            0L, picHeight, picWidth, -picHeight, &wBounds);
                }
931
                else
932 933
                    pict->Render(hdcDraw, dstX, dstY, picSize.cx, picSize.cy,
                            0L, picHeight, picWidth, -picHeight, NULL);
934

935 936 937 938 939 940 941 942 943 944 945
                pict->Release();
            }

            SelectObject(hdcDraw, GetStockObject(BLACK_BRUSH));

            MoveToEx(hdcDraw, bounds.left, bounds.top, NULL);
            LineTo(hdcDraw, bounds.left+width-1, bounds.top);
            LineTo(hdcDraw, bounds.left+width-1, bounds.top+height-1);
            LineTo(hdcDraw, bounds.left, bounds.top+height-1);
            LineTo(hdcDraw, bounds.left, bounds.top);
        }
Damien Fouilleul's avatar
Damien Fouilleul committed
946 947 948 949 950
    }
};

void VLCPlugin::onPaint(HDC hdc, const RECT &bounds, const RECT &clipRect)
{
951
    if( isVisible() )
Damien Fouilleul's avatar
Damien Fouilleul committed
952
    {
953
        /* if VLC is in design mode, draw control logo */
954 955
        HDC hdcDraw = CreateCompatibleDC(hdc);
        if( NULL != hdcDraw )
Damien Fouilleul's avatar
Damien Fouilleul committed
956
        {
957 958 959 960
            SIZEL size = getExtent();
            DPFromHimetric(hdc, (LPPOINT)&size, 1);
            RECTL posRect = { 0, 0, size.cx, size.cy };

Damien Fouilleul's avatar
Damien Fouilleul committed
961 962
            int width = bounds.right-bounds.left;
            int height = bounds.bottom-bounds.top;
963

Damien Fouilleul's avatar
Damien Fouilleul committed
964 965 966
            HBITMAP hBitmap = CreateCompatibleBitmap(hdc, width, height);
            if( NULL != hBitmap )
            {
967
                HBITMAP oldBmp = (HBITMAP)SelectObject(hdcDraw, hBitmap);
Damien Fouilleul's avatar
Damien Fouilleul committed
968

969
                if( (size.cx != width) || (size.cy != height) )
970 971 972 973 974 975
                {
                    // needs to scale canvas
                    SetMapMode(hdcDraw, MM_ANISOTROPIC);
                    SetWindowExtEx(hdcDraw, size.cx, size.cy, NULL);
                    SetViewportExtEx(hdcDraw, width, height, NULL);
                }
Damien Fouilleul's avatar
Damien Fouilleul committed
976

977
                onDraw(NULL, hdc, hdcDraw, &posRect, NULL);
Damien Fouilleul's avatar
Damien Fouilleul committed
978

979 980 981 982 983
                SetMapMode(hdcDraw, MM_TEXT);
                BitBlt(hdc, bounds.left, bounds.top,
                        width, height,
                        hdcDraw, 0, 0,
                        SRCCOPY);
Damien Fouilleul's avatar
Damien Fouilleul committed
984

985
                SelectObject(hdcDraw, oldBmp);
Damien Fouilleul's avatar
Damien Fouilleul committed
986 987
                DeleteObject(hBitmap);
            }
988
            DeleteDC(hdcDraw);
Damien Fouilleul's avatar
Damien Fouilleul committed
989
        }
990
    }
991 992 993 994
};

void VLCPlugin::onPositionChange(LPCRECT lprcPosRect, LPCRECT lprcClipRect)
{
Damien Fouilleul's avatar
Damien Fouilleul committed
995 996
    RECT clipRect = *lprcClipRect;

997
    //RedrawWindow(GetParent(_inplacewnd), &_posRect, NULL, RDW_INVALIDATE|RDW_ERASE|RDW_ALLCHILDREN);
998

Damien Fouilleul's avatar
Damien Fouilleul committed
999 1000
    /*
    ** record keeping of control geometry within container
1001
    */
1002
    _posRect = *lprcPosRect;
1003 1004 1005 1006

    /*
    ** change in-place window geometry to match clipping region
    */
1007
    SetWindowPos(_inplacewnd, NULL,
1008 1009 1010 1011
            lprcPosRect->left,
            lprcPosRect->top,
            lprcPosRect->right-lprcPosRect->left,
            lprcPosRect->bottom-lprcPosRect->top,
1012 1013 1014 1015
            SWP_NOACTIVATE|
            SWP_NOCOPYBITS|
            SWP_NOZORDER|
            SWP_NOOWNERZORDER );
1016

1017 1018 1019
    /* change cliprect coordinates system relative to window bounding rect */
    OffsetRect(&clipRect, -lprcPosRect->left, -lprcPosRect->top);
    HRGN clipRgn = CreateRectRgnIndirect(&clipRect);
1020
    SetWindowRgn(_inplacewnd, clipRgn, FALSE);
1021

1022
    //RedrawWindow(_videownd, &posRect, NULL, RDW_INVALIDATE|RDW_ERASE|RDW_ALLCHILDREN);
1023 1024
};

Damien Fouilleul's avatar
Damien Fouilleul committed
1025 1026 1027 1028 1029
void VLCPlugin::freezeEvents(BOOL freeze)
{
    vlcConnectionPointContainer->freezeEvents(freeze);
};

1030 1031
void VLCPlugin::firePropChangedEvent(DISPID dispid)
{
1032
    vlcConnectionPointContainer->firePropChangedEvent(dispid);
1033 1034 1035 1036
};

void VLCPlugin::fireOnPlayEvent(void)
{
Damien Fouilleul's avatar
Damien Fouilleul committed
1037
    DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
1038
    vlcConnectionPointContainer->fireEvent(DISPID_PlayEvent, &dispparamsNoArgs);
1039 1040 1041 1042
};

void VLCPlugin::fireOnPauseEvent(void)
{
Damien Fouilleul's avatar
Damien Fouilleul committed
1043
    DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
1044
    vlcConnectionPointContainer->fireEvent(DISPID_PauseEvent, &dispparamsNoArgs);
1045 1046 1047 1048
};

void VLCPlugin::fireOnStopEvent(void)
{
Damien Fouilleul's avatar
Damien Fouilleul committed
1049
    DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
1050
    vlcConnectionPointContainer->fireEvent(DISPID_StopEvent, &dispparamsNoArgs);
1051
};
JP Dinger's avatar
JP Dinger committed
1052

1053 1054 1055
/*
 * Async events
 */
1056
void VLCPlugin::fireOnMediaPlayerNothingSpecialEvent()
1057 1058
{
    DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
1059
    vlcConnectionPointContainer->fireEvent(DISPID_MediaPlayerNothingSpecialEvent, &dispparamsNoArgs);
1060 1061
};

1062
void VLCPlugin::fireOnMediaPlayerOpeningEvent()
1063 1064
{
    DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
1065
    vlcConnectionPointContainer->fireEvent(DISPID_MediaPlayerOpeningEvent, &dispparamsNoArgs);
1066 1067
};

1068
void VLCPlugin::fireOnMediaPlayerBufferingEvent(float cache)
1069
{
1070 1071 1072 1073 1074
    DISPPARAMS params;
    params.cArgs = 1;
    params.rgvarg = (VARIANTARG *) CoTaskMemAlloc(sizeof(VARIANTARG) * params.cArgs) ;
    memset(params.rgvarg, 0, sizeof(VARIANTARG) * params.cArgs);
    params.rgvarg[0].vt = VT_I4;
1075
    params.rgvarg[0].lVal = static_cast<LONG>(cache);
1076 1077 1078
    params.rgdispidNamedArgs = NULL;
    params.cNamedArgs = 0;
    vlcConnectionPointContainer->fireEvent(DISPID_MediaPlayerBufferingEvent, &params);
1079 1080
};

1081
void VLCPlugin::fireOnMediaPlayerPlayingEvent()
1082 1083
{
    DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
1084
    vlcConnectionPointContainer->fireEvent(DISPID_MediaPlayerPlayingEvent, &dispparamsNoArgs);
1085 1086
};

1087
void VLCPlugin::fireOnMediaPlayerPausedEvent()
1088 1089
{
    DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
1090
    vlcConnectionPointContainer->fireEvent(DISPID_MediaPlayerPausedEvent, &dispparamsNoArgs);
1091 1092
};

1093
void VLCPlugin::fireOnMediaPlayerEncounteredErrorEvent()
1094 1095
{
    DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
1096
    vlcConnectionPointContainer->fireEvent(DISPID_MediaPlayerEncounteredErrorEvent, &dispparamsNoArgs);
1097 1098
};

1099
void VLCPlugin::fireOnMediaPlayerEndReachedEvent()
1100 1101
{
    DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
1102
    vlcConnectionPointContainer->fireEvent(DISPID_MediaPlayerEndReachedEvent, &dispparamsNoArgs);
1103 1104
};

1105
void VLCPlugin::fireOnMediaPlayerStoppedEvent()
1106 1107
{
    DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
1108
    vlcConnectionPointContainer->fireEvent(DISPID_MediaPlayerStoppedEvent, &dispparamsNoArgs);
1109 1110
};

1111
void VLCPlugin::fireOnMediaPlayerForwardEvent()
1112 1113
{
    DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
1114
    vlcConnectionPointContainer->fireEvent(DISPID_MediaPlayerForwardEvent, &dispparamsNoArgs);
1115 1116
};

1117
void VLCPlugin::fireOnMediaPlayerBackwardEvent()
1118 1119
{
    DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
1120
    vlcConnectionPointContainer->fireEvent(DISPID_MediaPlayerBackwardEvent, &dispparamsNoArgs);
1121 1122 1123 1124 1125 1126 1127 1128
};

static void handle_input_state_event(const libvlc_event_t* event, void *param)
{
    VLCPlugin *plugin = (VLCPlugin*)param;
    switch( event->type )
    {
        case libvlc_MediaPlayerNothingSpecial:
1129
            plugin->fireOnMediaPlayerNothingSpecialEvent();
1130 1131
            break;
        case libvlc_MediaPlayerOpening:
1132
            plugin->fireOnMediaPlayerOpeningEvent();
1133 1134
            break;
        case libvlc_MediaPlayerBuffering:
1135
            plugin->fireOnMediaPlayerBufferingEvent(event->u.media_player_buffering.new_cache);
1136 1137
            break;
        case libvlc_MediaPlayerPlaying:
1138
            plugin->fireOnMediaPlayerPlayingEvent();
1139 1140
            break;
        case libvlc_MediaPlayerPaused:
1141
            plugin->fireOnMediaPlayerPausedEvent();
1142 1143
            break;
        case libvlc_MediaPlayerStopped:
1144
            plugin->fireOnMediaPlayerStoppedEvent();
1145 1146
            break;
        case libvlc_MediaPlayerForward:
1147
            plugin->fireOnMediaPlayerForwardEvent();
1148 1149
            break;
        case libvlc_MediaPlayerBackward:
1150
            plugin->fireOnMediaPlayerBackwardEvent();
1151 1152
            break;
        case libvlc_MediaPlayerEndReached:
1153
            plugin->fireOnMediaPlayerEndReachedEvent();
1154 1155
            break;
        case libvlc_MediaPlayerEncounteredError:
1156
            plugin->fireOnMediaPlayerEncounteredErrorEvent();
1157 1158 1159 1160
            break;
    }
}

1161
void VLCPlugin::fireOnMediaPlayerTimeChangedEvent(libvlc_time_t  time)
1162
{