vlccontrol2.cpp 75 KB
Newer Older
1 2 3 4 5 6
/*****************************************************************************
 * vlccontrol2.cpp: ActiveX control for VLC
 *****************************************************************************
 * Copyright (C) 2006 the VideoLAN team
 *
 * Authors: Damien Fouilleul <Damien.Fouilleul@laposte.net>
7
 *          Jean-Paul Saman <jpsaman _at_ m2x _dot_ nl>
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
 *
 * 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
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

#include "plugin.h"
#include "vlccontrol2.h"
#include "vlccontrol.h"

#include "utils.h"

30 31
#include <shlwapi.h>
#include <wininet.h>
32
#include <tchar.h>
33

34 35 36 37 38 39 40 41
using namespace std;

VLCAudio::~VLCAudio()
{
    if( _p_typeinfo )
        _p_typeinfo->Release();
};

42
HRESULT VLCAudio::loadTypeInfo(void)
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
{
    HRESULT hr = NOERROR;
    if( NULL == _p_typeinfo )
    {
        ITypeLib *p_typelib;

        hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
        if( SUCCEEDED(hr) )
        {
            hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCAudio, &_p_typeinfo);
            if( FAILED(hr) )
            {
                _p_typeinfo = NULL;
            }
            p_typelib->Release();
        }
    }
    return hr;
};

STDMETHODIMP VLCAudio::GetTypeInfoCount(UINT* pctInfo)
{
    if( NULL == pctInfo )
        return E_INVALIDARG;

68
    if( SUCCEEDED(loadTypeInfo()) )
69 70 71 72 73 74 75 76 77 78 79 80
        *pctInfo = 1;
    else
        *pctInfo = 0;

    return NOERROR;
};

STDMETHODIMP VLCAudio::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
{
    if( NULL == ppTInfo )
        return E_INVALIDARG;

81
    if( SUCCEEDED(loadTypeInfo()) )
82 83 84 85 86 87 88 89 90
    {
        _p_typeinfo->AddRef();
        *ppTInfo = _p_typeinfo;
        return NOERROR;
    }
    *ppTInfo = NULL;
    return E_NOTIMPL;
};

91
STDMETHODIMP VLCAudio::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
92 93
        UINT cNames, LCID lcid, DISPID* rgDispID)
{
94
    if( SUCCEEDED(loadTypeInfo()) )
95 96 97 98 99 100 101 102 103 104
    {
        return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
    }
    return E_NOTIMPL;
};

STDMETHODIMP VLCAudio::Invoke(DISPID dispIdMember, REFIID riid,
        LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
        VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
{
105
    if( SUCCEEDED(loadTypeInfo()) )
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
    {
        return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
                pVarResult, pExcepInfo, puArgErr);
    }
    return E_NOTIMPL;
};

STDMETHODIMP VLCAudio::get_mute(VARIANT_BOOL* mute)
{
    if( NULL == mute )
        return E_POINTER;

    libvlc_instance_t* p_libvlc;
    HRESULT hr = _p_instance->getVLC(&p_libvlc);
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

125 126
        *mute = libvlc_audio_get_mute(p_libvlc, &ex) ?
                        VARIANT_TRUE : VARIANT_FALSE;
127 128
        if( libvlc_exception_raised(&ex) )
        {
129 130
            _p_instance->setErrorInfo(IID_IVLCAudio,
                         libvlc_exception_get_message(&ex));
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
            libvlc_exception_clear(&ex);
            return E_FAIL;
        }
        return NOERROR;
    }
    return hr;
};

STDMETHODIMP VLCAudio::put_mute(VARIANT_BOOL mute)
{
    libvlc_instance_t* p_libvlc;
    HRESULT hr = _p_instance->getVLC(&p_libvlc);
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

        libvlc_audio_set_mute(p_libvlc, VARIANT_FALSE != mute, &ex);
        if( libvlc_exception_raised(&ex) )
        {
151 152
            _p_instance->setErrorInfo(IID_IVLCAudio,
                         libvlc_exception_get_message(&ex));
153 154 155 156 157 158 159 160
            libvlc_exception_clear(&ex);
            return E_FAIL;
        }
        return NOERROR;
    }
    return hr;
};

161
STDMETHODIMP VLCAudio::get_volume(long* volume)
162 163 164 165 166 167 168 169 170 171 172 173 174 175
{
    if( NULL == volume )
        return E_POINTER;

    libvlc_instance_t* p_libvlc;
    HRESULT hr = _p_instance->getVLC(&p_libvlc);
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

        *volume = libvlc_audio_get_volume(p_libvlc, &ex);
        if( libvlc_exception_raised(&ex) )
        {
176 177
            _p_instance->setErrorInfo(IID_IVLCAudio,
                         libvlc_exception_get_message(&ex));
178 179 180 181 182 183 184 185
            libvlc_exception_clear(&ex);
            return E_FAIL;
        }
        return NOERROR;
    }
    return hr;
};

186
STDMETHODIMP VLCAudio::put_volume(long volume)
187 188 189 190 191 192 193 194 195 196 197
{
    libvlc_instance_t* p_libvlc;
    HRESULT hr = _p_instance->getVLC(&p_libvlc);
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

        libvlc_audio_set_volume(p_libvlc, volume, &ex);
        if( libvlc_exception_raised(&ex) )
        {
198 199
            _p_instance->setErrorInfo(IID_IVLCAudio,
                         libvlc_exception_get_message(&ex));
200 201 202 203 204 205 206 207
            libvlc_exception_clear(&ex);
            return E_FAIL;
        }
        return NOERROR;
    }
    return hr;
};

208 209 210 211 212 213 214 215 216 217 218 219
STDMETHODIMP VLCAudio::get_track(long* track)
{
    if( NULL == track )
        return E_POINTER;

    libvlc_instance_t* p_libvlc;
    HRESULT hr = _p_instance->getVLC(&p_libvlc);
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

220 221
        libvlc_media_player_t *p_md;
        p_md = libvlc_playlist_get_media_player(p_libvlc, &ex);
222
        *track = libvlc_audio_get_track(p_md, &ex);
223
        libvlc_media_player_release(p_md);
224 225
        if( libvlc_exception_raised(&ex) )
        {
226 227
            _p_instance->setErrorInfo(IID_IVLCAudio,
                         libvlc_exception_get_message(&ex));
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
            libvlc_exception_clear(&ex);
            return E_FAIL;
        }
        return NOERROR;
    }
    return hr;
};

STDMETHODIMP VLCAudio::put_track(long track)
{
    libvlc_instance_t* p_libvlc;
    HRESULT hr = _p_instance->getVLC(&p_libvlc);
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

245 246
        libvlc_media_player_t *p_md;
        p_md = libvlc_playlist_get_media_player(p_libvlc, &ex);
247
        libvlc_audio_set_track(p_md, track, &ex);
248
        libvlc_media_player_release(p_md);
249 250
        if( libvlc_exception_raised(&ex) )
        {
251 252
            _p_instance->setErrorInfo(IID_IVLCAudio,
                         libvlc_exception_get_message(&ex));
253 254 255 256 257 258 259 260
            libvlc_exception_clear(&ex);
            return E_FAIL;
        }
        return NOERROR;
    }
    return hr;
};

261
STDMETHODIMP VLCAudio::get_channel(long *channel)
262 263 264 265 266 267 268 269 270 271 272
{
    if( NULL == channel )
        return E_POINTER;

    libvlc_instance_t* p_libvlc;
    HRESULT hr = _p_instance->getVLC(&p_libvlc);
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

273 274
        *channel = libvlc_audio_get_channel(p_libvlc, &ex);
        if( libvlc_exception_raised(&ex) )
275
        {
276 277 278 279
            _p_instance->setErrorInfo(IID_IVLCAudio,
                        libvlc_exception_get_message(&ex));
            libvlc_exception_clear(&ex);
            return E_FAIL;
280
        }
281
        return NOERROR;
282 283 284 285
    }
    return hr;
};

286
STDMETHODIMP VLCAudio::put_channel(long channel)
287 288 289 290 291 292 293 294
{
    libvlc_instance_t* p_libvlc;
    HRESULT hr = _p_instance->getVLC(&p_libvlc);
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

295
        libvlc_audio_set_channel(p_libvlc, channel, &ex);
296 297 298 299 300 301 302 303 304 305 306 307
        if( libvlc_exception_raised(&ex) )
        {
            _p_instance->setErrorInfo(IID_IVLCAudio,
                         libvlc_exception_get_message(&ex));
            libvlc_exception_clear(&ex);
            return E_FAIL;
        }
        return NOERROR;
    }
    return hr;
};

308 309 310 311 312 313 314 315 316 317 318 319
STDMETHODIMP VLCAudio::toggleMute()
{
    libvlc_instance_t* p_libvlc;
    HRESULT hr = _p_instance->getVLC(&p_libvlc);
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

        libvlc_audio_toggle_mute(p_libvlc, &ex);
        if( libvlc_exception_raised(&ex) )
        {
320 321
            _p_instance->setErrorInfo(IID_IVLCAudio,
                         libvlc_exception_get_message(&ex));
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337
            libvlc_exception_clear(&ex);
            return E_FAIL;
        }
        return NOERROR;
    }
    return hr;
};

/*******************************************************************************/

VLCInput::~VLCInput()
{
    if( _p_typeinfo )
        _p_typeinfo->Release();
};

338
HRESULT VLCInput::loadTypeInfo(void)
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363
{
    HRESULT hr = NOERROR;
    if( NULL == _p_typeinfo )
    {
        ITypeLib *p_typelib;

        hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
        if( SUCCEEDED(hr) )
        {
            hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCInput, &_p_typeinfo);
            if( FAILED(hr) )
            {
                _p_typeinfo = NULL;
            }
            p_typelib->Release();
        }
    }
    return hr;
};

STDMETHODIMP VLCInput::GetTypeInfoCount(UINT* pctInfo)
{
    if( NULL == pctInfo )
        return E_INVALIDARG;

364
    if( SUCCEEDED(loadTypeInfo()) )
365 366 367 368 369 370 371 372 373 374 375 376
        *pctInfo = 1;
    else
        *pctInfo = 0;

    return NOERROR;
};

STDMETHODIMP VLCInput::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
{
    if( NULL == ppTInfo )
        return E_INVALIDARG;

377
    if( SUCCEEDED(loadTypeInfo()) )
378 379 380 381 382 383 384 385 386
    {
        _p_typeinfo->AddRef();
        *ppTInfo = _p_typeinfo;
        return NOERROR;
    }
    *ppTInfo = NULL;
    return E_NOTIMPL;
};

387
STDMETHODIMP VLCInput::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
388 389
        UINT cNames, LCID lcid, DISPID* rgDispID)
{
390
    if( SUCCEEDED(loadTypeInfo()) )
391 392 393 394 395 396 397 398 399 400
    {
        return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
    }
    return E_NOTIMPL;
};

STDMETHODIMP VLCInput::Invoke(DISPID dispIdMember, REFIID riid,
        LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
        VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
{
401
    if( SUCCEEDED(loadTypeInfo()) )
402 403 404 405 406 407 408
    {
        return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
                pVarResult, pExcepInfo, puArgErr);
    }
    return E_NOTIMPL;
};

409
STDMETHODIMP VLCInput::get_length(double* length)
410 411 412
{
    if( NULL == length )
        return E_POINTER;
413
    *length = 0;
414 415 416 417 418 419 420 421

    libvlc_instance_t* p_libvlc;
    HRESULT hr = _p_instance->getVLC(&p_libvlc);
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

422 423
        libvlc_media_player_t *p_md;
        p_md = libvlc_playlist_get_media_player(p_libvlc, &ex);
424 425
        if( ! libvlc_exception_raised(&ex) )
        {
426 427
            *length = (double)libvlc_media_player_get_length(p_md, &ex);
            libvlc_media_player_release(p_md);
428 429 430 431 432
            if( ! libvlc_exception_raised(&ex) )
            {
                return NOERROR;
            }
        }
433 434
        _p_instance->setErrorInfo(IID_IVLCInput,
                     libvlc_exception_get_message(&ex));
435 436 437 438 439 440
        libvlc_exception_clear(&ex);
        return E_FAIL;
    }
    return hr;
};

441
STDMETHODIMP VLCInput::get_position(double* position)
442 443 444 445
{
    if( NULL == position )
        return E_POINTER;

446
    *position = 0.0f;
447 448 449 450 451 452 453
    libvlc_instance_t* p_libvlc;
    HRESULT hr = _p_instance->getVLC(&p_libvlc);
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

454 455
        libvlc_media_player_t *p_md;
        p_md = libvlc_playlist_get_media_player(p_libvlc, &ex);
456 457
        if( ! libvlc_exception_raised(&ex) )
        {
458 459
            *position = libvlc_media_player_get_position(p_md, &ex);
            libvlc_media_player_release(p_md);
460 461 462 463 464
            if( ! libvlc_exception_raised(&ex) )
            {
                return NOERROR;
            }
        }
465 466
        _p_instance->setErrorInfo(IID_IVLCInput,
                     libvlc_exception_get_message(&ex));
467 468 469 470 471 472
        libvlc_exception_clear(&ex);
        return E_FAIL;
    }
    return hr;
};

473
STDMETHODIMP VLCInput::put_position(double position)
474 475 476 477 478 479 480 481
{
    libvlc_instance_t* p_libvlc;
    HRESULT hr = _p_instance->getVLC(&p_libvlc);
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

482 483
        libvlc_media_player_t *p_md;
        p_md = libvlc_playlist_get_media_player(p_libvlc, &ex);
484 485
        if( ! libvlc_exception_raised(&ex) )
        {
486 487
            libvlc_media_player_set_position(p_md, position, &ex);
            libvlc_media_player_release(p_md);
488 489 490 491 492
            if( ! libvlc_exception_raised(&ex) )
            {
                return NOERROR;
            }
        }
493 494
        _p_instance->setErrorInfo(IID_IVLCInput,
                     libvlc_exception_get_message(&ex));
495 496 497 498 499 500
        libvlc_exception_clear(&ex);
        return E_FAIL;
    }
    return hr;
};

501
STDMETHODIMP VLCInput::get_time(double* time)
502 503 504 505 506 507 508 509 510 511 512
{
    if( NULL == time )
        return E_POINTER;

    libvlc_instance_t* p_libvlc;
    HRESULT hr = _p_instance->getVLC(&p_libvlc);
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

513 514
        libvlc_media_player_t *p_md;
        p_md = libvlc_playlist_get_media_player(p_libvlc, &ex);
515 516
        if( ! libvlc_exception_raised(&ex) )
        {
517 518
            *time = (double)libvlc_media_player_get_time(p_md, &ex);
            libvlc_media_player_release(p_md);
519 520 521 522 523
            if( ! libvlc_exception_raised(&ex) )
            {
                return NOERROR;
            }
        }
524 525
        _p_instance->setErrorInfo(IID_IVLCInput,
                     libvlc_exception_get_message(&ex));
526 527 528 529 530 531
        libvlc_exception_clear(&ex);
        return E_FAIL;
    }
    return hr;
};

532
STDMETHODIMP VLCInput::put_time(double time)
533 534 535 536 537 538 539 540
{
    libvlc_instance_t* p_libvlc;
    HRESULT hr = _p_instance->getVLC(&p_libvlc);
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

541 542
        libvlc_media_player_t *p_md;
        p_md = libvlc_playlist_get_media_player(p_libvlc, &ex);
543 544
        if( ! libvlc_exception_raised(&ex) )
        {
Jean-Paul Saman's avatar
Jean-Paul Saman committed
545
            libvlc_media_player_set_time(p_md, (int64_t)time, &ex);
546
            libvlc_media_player_release(p_md);
547 548 549 550 551
            if( ! libvlc_exception_raised(&ex) )
            {
                return NOERROR;
            }
        }
552 553
        _p_instance->setErrorInfo(IID_IVLCInput,
                     libvlc_exception_get_message(&ex));
554 555 556 557 558 559
        libvlc_exception_clear(&ex);
        return E_FAIL;
    }
    return hr;
};

560
STDMETHODIMP VLCInput::get_state(long* state)
561 562 563 564 565 566 567 568 569 570 571
{
    if( NULL == state )
        return E_POINTER;

    libvlc_instance_t* p_libvlc;
    HRESULT hr = _p_instance->getVLC(&p_libvlc);
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

572 573
        libvlc_media_player_t *p_md;
        p_md = libvlc_playlist_get_media_player(p_libvlc, &ex);
574 575
        if( ! libvlc_exception_raised(&ex) )
        {
576 577
            *state = libvlc_media_player_get_state(p_md, &ex);
            libvlc_media_player_release(p_md);
578 579 580 581 582 583 584 585 586 587 588 589 590
            if( ! libvlc_exception_raised(&ex) )
            {
                return NOERROR;
            }
        }
        libvlc_exception_clear(&ex);
        // don't fail, just return the idle state
        *state = 0;
        return NOERROR;
    }
    return hr;
};

591
STDMETHODIMP VLCInput::get_rate(double* rate)
592 593 594 595 596 597 598 599 600 601 602
{
    if( NULL == rate )
        return E_POINTER;

    libvlc_instance_t* p_libvlc;
    HRESULT hr = _p_instance->getVLC(&p_libvlc);
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

603 604
        libvlc_media_player_t *p_md;
        p_md = libvlc_playlist_get_media_player(p_libvlc, &ex);
605 606
        if( ! libvlc_exception_raised(&ex) )
        {
607 608
            *rate = libvlc_media_player_get_rate(p_md, &ex);
            libvlc_media_player_release(p_md);
609 610 611 612 613
            if( ! libvlc_exception_raised(&ex) )
            {
                return NOERROR;
            }
        }
614 615
        _p_instance->setErrorInfo(IID_IVLCInput,
                     libvlc_exception_get_message(&ex));
616 617 618 619 620 621
        libvlc_exception_clear(&ex);
        return E_FAIL;
    }
    return hr;
};

622
STDMETHODIMP VLCInput::put_rate(double rate)
623 624 625 626 627 628 629 630
{
    libvlc_instance_t* p_libvlc;
    HRESULT hr = _p_instance->getVLC(&p_libvlc);
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

631 632
        libvlc_media_player_t *p_md;
        p_md = libvlc_playlist_get_media_player(p_libvlc, &ex);
633 634
        if( ! libvlc_exception_raised(&ex) )
        {
635 636
            libvlc_media_player_set_rate(p_md, rate, &ex);
            libvlc_media_player_release(p_md);
637 638 639 640 641
            if( ! libvlc_exception_raised(&ex) )
            {
                return NOERROR;
            }
        }
642 643
        _p_instance->setErrorInfo(IID_IVLCInput,
                     libvlc_exception_get_message(&ex));
644 645 646 647 648 649
        libvlc_exception_clear(&ex);
        return E_FAIL;
    }
    return hr;
};

650
STDMETHODIMP VLCInput::get_fps(double* fps)
651 652 653 654
{
    if( NULL == fps )
        return E_POINTER;

655
    *fps = 0.0;
656 657 658 659 660 661 662
    libvlc_instance_t* p_libvlc;
    HRESULT hr = _p_instance->getVLC(&p_libvlc);
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

663 664
        libvlc_media_player_t *p_md;
        p_md = libvlc_playlist_get_media_player(p_libvlc, &ex);
665 666
        if( ! libvlc_exception_raised(&ex) )
        {
667 668
            *fps = libvlc_media_player_get_fps(p_md, &ex);
            libvlc_media_player_release(p_md);
669 670 671 672 673
            if( ! libvlc_exception_raised(&ex) )
            {
                return NOERROR;
            }
        }
674 675
        _p_instance->setErrorInfo(IID_IVLCInput,
                     libvlc_exception_get_message(&ex));
676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693
        libvlc_exception_clear(&ex);
        return E_FAIL;
    }
    return hr;
};

STDMETHODIMP VLCInput::get_hasVout(VARIANT_BOOL* hasVout)
{
    if( NULL == hasVout )
        return E_POINTER;

    libvlc_instance_t* p_libvlc;
    HRESULT hr = _p_instance->getVLC(&p_libvlc);
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

694 695
        libvlc_media_player_t *p_md;
        p_md = libvlc_playlist_get_media_player(p_libvlc, &ex);
696 697
        if( ! libvlc_exception_raised(&ex) )
        {
698 699
            *hasVout = libvlc_media_player_has_vout(p_md, &ex) ?
                                    VARIANT_TRUE : VARIANT_FALSE;
700
            libvlc_media_player_release(p_md);
701 702 703 704 705
            if( ! libvlc_exception_raised(&ex) )
            {
                return NOERROR;
            }
        }
706 707
        _p_instance->setErrorInfo(IID_IVLCInput,
                     libvlc_exception_get_message(&ex));
708 709 710 711 712 713 714 715
        libvlc_exception_clear(&ex);
        return E_FAIL;
    }
    return hr;
};

/*******************************************************************************/

716 717
VLCLog::~VLCLog()
{
718
    delete _p_vlcmessages;
719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774
    if( _p_log )
        libvlc_log_close(_p_log, NULL);

    if( _p_typeinfo )
        _p_typeinfo->Release();
};

HRESULT VLCLog::loadTypeInfo(void)
{
    HRESULT hr = NOERROR;
    if( NULL == _p_typeinfo )
    {
        ITypeLib *p_typelib;

        hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
        if( SUCCEEDED(hr) )
        {
            hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCLog, &_p_typeinfo);
            if( FAILED(hr) )
            {
                _p_typeinfo = NULL;
            }
            p_typelib->Release();
        }
    }
    return hr;
};

STDMETHODIMP VLCLog::GetTypeInfoCount(UINT* pctInfo)
{
    if( NULL == pctInfo )
        return E_INVALIDARG;

    if( SUCCEEDED(loadTypeInfo()) )
        *pctInfo = 1;
    else
        *pctInfo = 0;

    return NOERROR;
};

STDMETHODIMP VLCLog::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
{
    if( NULL == ppTInfo )
        return E_INVALIDARG;

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

775
STDMETHODIMP VLCLog::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827
        UINT cNames, LCID lcid, DISPID* rgDispID)
{
    if( SUCCEEDED(loadTypeInfo()) )
    {
        return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
    }
    return E_NOTIMPL;
};

STDMETHODIMP VLCLog::Invoke(DISPID dispIdMember, REFIID riid,
        LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
        VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
{
    if( SUCCEEDED(loadTypeInfo()) )
    {
        return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
                pVarResult, pExcepInfo, puArgErr);
    }
    return E_NOTIMPL;
};

STDMETHODIMP VLCLog::get_messages(IVLCMessages** obj)
{
    if( NULL == obj )
        return E_POINTER;

    *obj = _p_vlcmessages;
    if( NULL != _p_vlcmessages )
    {
        _p_vlcmessages->AddRef();
        return NOERROR;
    }
    return E_OUTOFMEMORY;
};

STDMETHODIMP VLCLog::get_verbosity(long* level)
{
    if( NULL == level )
        return E_POINTER;

    if( _p_log )
    {
        libvlc_instance_t* p_libvlc;
        HRESULT hr = _p_instance->getVLC(&p_libvlc);
        if( SUCCEEDED(hr) )
        {
            libvlc_exception_t ex;
            libvlc_exception_init(&ex);

            *level = libvlc_get_log_verbosity(p_libvlc, &ex);
            if( libvlc_exception_raised(&ex) )
            {
828 829
                _p_instance->setErrorInfo(IID_IVLCLog,
                             libvlc_exception_get_message(&ex));
830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859
                libvlc_exception_clear(&ex);
                return E_FAIL;
            }
        }
        return hr;
    }
    else
    {
        /* log is not enabled, return -1 */
        *level = -1;
        return NOERROR;
    }
};

STDMETHODIMP VLCLog::put_verbosity(long verbosity)
{
    libvlc_exception_t ex;
    libvlc_exception_init(&ex);

    libvlc_instance_t* p_libvlc;
    HRESULT hr = _p_instance->getVLC(&p_libvlc);
    if( SUCCEEDED(hr) )
    {
        if( verbosity >= 0 )
        {
            if( ! _p_log )
            {
                _p_log = libvlc_log_open(p_libvlc, &ex);
                if( libvlc_exception_raised(&ex) )
                {
860 861
                    _p_instance->setErrorInfo(IID_IVLCLog,
                                 libvlc_exception_get_message(&ex));
862 863 864 865 866 867 868
                    libvlc_exception_clear(&ex);
                    return E_FAIL;
                }
            }
            libvlc_set_log_verbosity(p_libvlc, (unsigned)verbosity, &ex);
            if( libvlc_exception_raised(&ex) )
            {
869 870
                _p_instance->setErrorInfo(IID_IVLCLog,
                             libvlc_exception_get_message(&ex));
871 872 873 874 875 876 877 878 879 880 881
                libvlc_exception_clear(&ex);
                return E_FAIL;
            }
        }
        else if( _p_log )
        {
            /* close log  when verbosity is set to -1 */
            libvlc_log_close(_p_log, &ex);
            _p_log = NULL;
            if( libvlc_exception_raised(&ex) )
            {
882 883
                _p_instance->setErrorInfo(IID_IVLCLog,
                             libvlc_exception_get_message(&ex));
884 885 886 887 888 889 890 891 892 893
                libvlc_exception_clear(&ex);
                return E_FAIL;
            }
        }
    }
    return hr;
};

/*******************************************************************************/

894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951
/* STL forward iterator used by VLCEnumIterator class to implement IEnumVARIANT */

class VLCMessageSTLIterator
{

public:

    VLCMessageSTLIterator(IVLCMessageIterator* iter) : iter(iter), msg(NULL)
    {
        // get first message
        operator++();
    };

    VLCMessageSTLIterator(const VLCMessageSTLIterator& other)
    {
        iter = other.iter;
        if( iter )
            iter->AddRef();
        msg = other.msg;
        if( msg )
            msg->AddRef();
    };

    virtual ~VLCMessageSTLIterator()
    {
        if( msg )
            msg->Release();

        if( iter )
            iter->Release();
    };

    // we only need prefix ++ operator
    VLCMessageSTLIterator& operator++()
    {
        VARIANT_BOOL hasNext = VARIANT_FALSE;
        if( iter )
        {
            iter->get_hasNext(&hasNext);

            if( msg )
            {
                msg->Release();
                msg = NULL;
            }
            if( VARIANT_TRUE == hasNext ) {
                iter->next(&msg);
            }
        }
        return *this;
    };

    VARIANT operator*() const
    {
        VARIANT v;
        VariantInit(&v);
        if( msg )
        {
952 953
            if( SUCCEEDED(msg->QueryInterface(IID_IDispatch,
                          (LPVOID*)&V_DISPATCH(&v))) )
954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977
            {
                V_VT(&v) = VT_DISPATCH;
            }
        }
        return v;
    };

    bool operator==(const VLCMessageSTLIterator& other) const
    {
        return msg == other.msg;
    };

    bool operator!=(const VLCMessageSTLIterator& other) const
    {
        return msg != other.msg;
    };

private:
    IVLCMessageIterator* iter;
    IVLCMessage*         msg;
};

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

978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032
VLCMessages::~VLCMessages()
{
    if( _p_typeinfo )
        _p_typeinfo->Release();
};

HRESULT VLCMessages::loadTypeInfo(void)
{
    HRESULT hr = NOERROR;
    if( NULL == _p_typeinfo )
    {
        ITypeLib *p_typelib;

        hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
        if( SUCCEEDED(hr) )
        {
            hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCMessages, &_p_typeinfo);
            if( FAILED(hr) )
            {
                _p_typeinfo = NULL;
            }
            p_typelib->Release();
        }
    }
    return hr;
};

STDMETHODIMP VLCMessages::GetTypeInfoCount(UINT* pctInfo)
{
    if( NULL == pctInfo )
        return E_INVALIDARG;

    if( SUCCEEDED(loadTypeInfo()) )
        *pctInfo = 1;
    else
        *pctInfo = 0;

    return NOERROR;
};

STDMETHODIMP VLCMessages::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
{
    if( NULL == ppTInfo )
        return E_INVALIDARG;

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

1033
STDMETHODIMP VLCMessages::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059
        UINT cNames, LCID lcid, DISPID* rgDispID)
{
    if( SUCCEEDED(loadTypeInfo()) )
    {
        return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
    }
    return E_NOTIMPL;
};

STDMETHODIMP VLCMessages::Invoke(DISPID dispIdMember, REFIID riid,
        LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
        VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
{
    if( SUCCEEDED(loadTypeInfo()) )
    {
        return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
                pVarResult, pExcepInfo, puArgErr);
    }
    return E_NOTIMPL;
};

STDMETHODIMP VLCMessages::get__NewEnum(LPUNKNOWN* _NewEnum)
{
    if( NULL == _NewEnum )
        return E_POINTER;

1060 1061 1062 1063 1064 1065 1066 1067 1068 1069
    IVLCMessageIterator* iter = NULL;
    iterator(&iter);

    *_NewEnum= new VLCEnumIterator<IID_IEnumVARIANT,
                       IEnumVARIANT,
                       VARIANT,
                       VLCMessageSTLIterator>
                       (VLCMessageSTLIterator(iter), VLCMessageSTLIterator(NULL));

    return *_NewEnum ? S_OK : E_OUTOFMEMORY;
1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082
};

STDMETHODIMP VLCMessages::clear()
{
    libvlc_log_t *p_log = _p_vlclog->_p_log;
    if( p_log )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

        libvlc_log_clear(p_log, &ex);
        if( libvlc_exception_raised(&ex) )
        {
1083 1084
            _p_instance->setErrorInfo(IID_IVLCMessages,
                         libvlc_exception_get_message(&ex));
1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105
            libvlc_exception_clear(&ex);
            return E_FAIL;
        }
    }
    return NOERROR;
};

STDMETHODIMP VLCMessages::get_count(long* count)
{
    if( NULL == count )
        return E_POINTER;

    libvlc_log_t *p_log = _p_vlclog->_p_log;
    if( p_log )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

        *count = libvlc_log_count(p_log, &ex);
        if( libvlc_exception_raised(&ex) )
        {
1106 1107
            _p_instance->setErrorInfo(IID_IVLCMessages,
                         libvlc_exception_get_message(&ex));
1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200
            libvlc_exception_clear(&ex);
            return E_FAIL;
        }
    }
    else
        *count = 0;
    return S_OK;
};

STDMETHODIMP VLCMessages::iterator(IVLCMessageIterator** iter)
{
    if( NULL == iter )
        return E_POINTER;

    *iter = new VLCMessageIterator(_p_instance, _p_vlclog);

    return *iter ? S_OK : E_OUTOFMEMORY;
};

/*******************************************************************************/

VLCMessageIterator::VLCMessageIterator(VLCPlugin *p_instance, VLCLog* p_vlclog ) :
    _p_instance(p_instance),
    _p_typeinfo(NULL),
    _refcount(1),
    _p_vlclog(p_vlclog)
{
    if( p_vlclog->_p_log )
    {
        _p_iter = libvlc_log_get_iterator(p_vlclog->_p_log, NULL);
    }
    else
        _p_iter = NULL;
};

VLCMessageIterator::~VLCMessageIterator()
{
    if( _p_iter )
        libvlc_log_iterator_free(_p_iter, NULL);

    if( _p_typeinfo )
        _p_typeinfo->Release();
};

HRESULT VLCMessageIterator::loadTypeInfo(void)
{
    HRESULT hr = NOERROR;
    if( NULL == _p_typeinfo )
    {
        ITypeLib *p_typelib;

        hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
        if( SUCCEEDED(hr) )
        {
            hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCMessageIterator, &_p_typeinfo);
            if( FAILED(hr) )
            {
                _p_typeinfo = NULL;
            }
            p_typelib->Release();
        }
    }
    return hr;
};

STDMETHODIMP VLCMessageIterator::GetTypeInfoCount(UINT* pctInfo)
{
    if( NULL == pctInfo )
        return E_INVALIDARG;

    if( SUCCEEDED(loadTypeInfo()) )
        *pctInfo = 1;
    else
        *pctInfo = 0;

    return NOERROR;
};

STDMETHODIMP VLCMessageIterator::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
{
    if( NULL == ppTInfo )
        return E_INVALIDARG;

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

1201
STDMETHODIMP VLCMessageIterator::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232
        UINT cNames, LCID lcid, DISPID* rgDispID)
{
    if( SUCCEEDED(loadTypeInfo()) )
    {
        return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
    }
    return E_NOTIMPL;
};

STDMETHODIMP VLCMessageIterator::Invoke(DISPID dispIdMember, REFIID riid,
        LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
        VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
{
    if( SUCCEEDED(loadTypeInfo()) )
    {
        return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
                pVarResult, pExcepInfo, puArgErr);
    }
    return E_NOTIMPL;
};

STDMETHODIMP VLCMessageIterator::get_hasNext(VARIANT_BOOL* hasNext)
{
    if( NULL == hasNext )
        return E_POINTER;

    if( _p_iter &&  _p_vlclog->_p_log )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

1233 1234
        *hasNext = libvlc_log_iterator_has_next(_p_iter, &ex) ?
                                     VARIANT_TRUE : VARIANT_FALSE;
1235 1236
        if( libvlc_exception_raised(&ex) )
        {
1237 1238
            _p_instance->setErrorInfo(IID_IVLCMessageIterator,
                         libvlc_exception_get_message(&ex));
1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266
            libvlc_exception_clear(&ex);
            return E_FAIL;
        }
    }
    else
    {
        *hasNext = VARIANT_FALSE;
    }
    return S_OK;
};

STDMETHODIMP VLCMessageIterator::next(IVLCMessage** message)
{
    if( NULL == message )
        return E_POINTER;

    if( _p_iter &&  _p_vlclog->_p_log )
    {
        struct libvlc_log_message_t buffer;

        buffer.sizeof_msg = sizeof(buffer);

        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

        libvlc_log_iterator_next(_p_iter, &buffer, &ex);
        if( libvlc_exception_raised(&ex) )
        {
1267 1268
            _p_instance->setErrorInfo(IID_IVLCMessageIterator,
                         libvlc_exception_get_message(&ex));
1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334
            libvlc_exception_clear(&ex);
            return E_FAIL;
        }
        *message = new VLCMessage(_p_instance, buffer);
        return *message ? NOERROR : E_OUTOFMEMORY;
    }
    return E_FAIL;
};

/*******************************************************************************/

VLCMessage::~VLCMessage()
{
    if( _p_typeinfo )
        _p_typeinfo->Release();
};

HRESULT VLCMessage::loadTypeInfo(void)
{
    HRESULT hr = NOERROR;
    if( NULL == _p_typeinfo )
    {
        ITypeLib *p_typelib;

        hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
        if( SUCCEEDED(hr) )
        {
            hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCMessage, &_p_typeinfo);
            if( FAILED(hr) )
            {
                _p_typeinfo = NULL;
            }
            p_typelib->Release();
        }
    }
    return hr;
};

STDMETHODIMP VLCMessage::GetTypeInfoCount(UINT* pctInfo)
{
    if( NULL == pctInfo )
        return E_INVALIDARG;

    if( SUCCEEDED(loadTypeInfo()) )
        *pctInfo = 1;
    else
        *pctInfo = 0;

    return NOERROR;
};

STDMETHODIMP VLCMessage::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
{
    if( NULL == ppTInfo )
        return E_INVALIDARG;

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

1335
STDMETHODIMP VLCMessage::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439
        UINT cNames, LCID lcid, DISPID* rgDispID)
{
    if( SUCCEEDED(loadTypeInfo()) )
    {
        return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
    }
    return E_NOTIMPL;
};

STDMETHODIMP VLCMessage::Invoke(DISPID dispIdMember, REFIID riid,
        LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
        VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
{
    if( SUCCEEDED(loadTypeInfo()) )
    {
        return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
                pVarResult, pExcepInfo, puArgErr);
    }
    return E_NOTIMPL;
};

inline const char *msgSeverity(int sev)
{
    switch( sev )
    {
        case 0:
            return "info";
        case 1:
            return "error";
        case 2:
            return "warning";
        default:
            return "debug";
    }
};

STDMETHODIMP VLCMessage::get__Value(VARIANT* _Value)
{
    if( NULL == _Value )
        return E_POINTER;

    char buffer[256];

    snprintf(buffer, sizeof(buffer), "%s %s %s: %s",
        _msg.psz_type, _msg.psz_name, msgSeverity(_msg.i_severity), _msg.psz_message);

    V_VT(_Value) = VT_BSTR;
    V_BSTR(_Value) = BSTRFromCStr(CP_UTF8, buffer);

    return S_OK;
};

STDMETHODIMP VLCMessage::get_severity(long* level)
{
    if( NULL == level )
        return E_POINTER;

    *level = _msg.i_severity;

    return S_OK;
};

STDMETHODIMP VLCMessage::get_type(BSTR* type)
{
    if( NULL == type )
        return E_POINTER;

    *type = BSTRFromCStr(CP_UTF8, _msg.psz_type);

    return NOERROR;
};

STDMETHODIMP VLCMessage::get_name(BSTR* name)
{
    if( NULL == name )
        return E_POINTER;

    *name = BSTRFromCStr(CP_UTF8, _msg.psz_name);

    return NOERROR;
};

STDMETHODIMP VLCMessage::get_header(BSTR* header)
{
    if( NULL == header )
        return E_POINTER;

    *header = BSTRFromCStr(CP_UTF8, _msg.psz_header);

    return NOERROR;
};

STDMETHODIMP VLCMessage::get_message(BSTR* message)
{
    if( NULL == message )
        return E_POINTER;

    *message = BSTRFromCStr(CP_UTF8, _msg.psz_message);

    return NOERROR;
};

/*******************************************************************************/

1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494
VLCPlaylistItems::~VLCPlaylistItems()
{
    if( _p_typeinfo )
        _p_typeinfo->Release();
};

HRESULT VLCPlaylistItems::loadTypeInfo(void)
{
    HRESULT hr = NOERROR;
    if( NULL == _p_typeinfo )
    {
        ITypeLib *p_typelib;

        hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
        if( SUCCEEDED(hr) )
        {
            hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCPlaylistItems, &_p_typeinfo);
            if( FAILED(hr) )
            {
                _p_typeinfo = NULL;
            }
            p_typelib->Release();
        }
    }
    return hr;
};

STDMETHODIMP VLCPlaylistItems::GetTypeInfoCount(UINT* pctInfo)
{
    if( NULL == pctInfo )
        return E_INVALIDARG;

    if( SUCCEEDED(loadTypeInfo()) )
        *pctInfo = 1;
    else
        *pctInfo = 0;

    return NOERROR;
};

STDMETHODIMP VLCPlaylistItems::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
{
    if( NULL == ppTInfo )
        return E_INVALIDARG;

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

1495
STDMETHODIMP VLCPlaylistItems::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528
        UINT cNames, LCID lcid, DISPID* rgDispID)
{
    if( SUCCEEDED(loadTypeInfo()) )
    {
        return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
    }
    return E_NOTIMPL;
};

STDMETHODIMP VLCPlaylistItems::Invoke(DISPID dispIdMember, REFIID riid,
        LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
        VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
{
    if( SUCCEEDED(loadTypeInfo()) )
    {
        return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
                pVarResult, pExcepInfo, puArgErr);
    }
    return E_NOTIMPL;
};

STDMETHODIMP VLCPlaylistItems::get_count(long* count)
{
    if( NULL == count )
        return E_POINTER;

    libvlc_instance_t* p_libvlc;
    HRESULT hr = _p_instance->getVLC(&p_libvlc);
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

1529
        libvlc_playlist_lock(p_libvlc);
1530
        *count = libvlc_playlist_items_count(p_libvlc, &ex);
1531
        libvlc_playlist_unlock(p_libvlc);
1532 1533 1534
        if( libvlc_exception_raised(&ex) )
        {
            _p_instance->setErrorInfo(IID_IVLCPlaylistItems,
1535
                         libvlc_exception_get_message(&ex));
1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556
            libvlc_exception_clear(&ex);
            return E_FAIL;
        }
        return NOERROR;
    }
    return hr;
};

STDMETHODIMP VLCPlaylistItems::clear()
{
    libvlc_instance_t* p_libvlc;
    HRESULT hr = _p_instance->getVLC(&p_libvlc);
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

        libvlc_playlist_clear(p_libvlc, &ex);
        if( libvlc_exception_raised(&ex) )
        {
            _p_instance->setErrorInfo(IID_IVLCPlaylistItems,
1557
                         libvlc_exception_get_message(&ex));
1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578
            libvlc_exception_clear(&ex);
            return E_FAIL;
        }
        return NOERROR;
    }
    return hr;
};

STDMETHODIMP VLCPlaylistItems::remove(long item)
{
    libvlc_instance_t* p_libvlc;
    HRESULT hr = _p_instance->getVLC(&p_libvlc);
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

        libvlc_playlist_delete_item(p_libvlc, item, &ex);
        if( libvlc_exception_raised(&ex) )
        {
            _p_instance->setErrorInfo(IID_IVLCPlaylistItems,
1579
                         libvlc_exception_get_message(&ex));
1580 1581 1582 1583 1584 1585 1586 1587 1588 1589
            libvlc_exception_clear(&ex);
            return E_FAIL;
        }
        return NOERROR;
    }
    return hr;
};

/*******************************************************************************/

1590 1591
VLCPlaylist::~VLCPlaylist()
{
1592
    delete _p_vlcplaylistitems;
1593 1594 1595 1596
    if( _p_typeinfo )
        _p_typeinfo->Release();
};

1597
HRESULT VLCPlaylist::loadTypeInfo(void)
1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622
{
    HRESULT hr = NOERROR;
    if( NULL == _p_typeinfo )
    {
        ITypeLib *p_typelib;

        hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
        if( SUCCEEDED(hr) )
        {
            hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCPlaylist, &_p_typeinfo);
            if( FAILED(hr) )
            {
                _p_typeinfo = NULL;
            }
            p_typelib->Release();
        }
    }
    return hr;
};

STDMETHODIMP VLCPlaylist::GetTypeInfoCount(UINT* pctInfo)
{
    if( NULL == pctInfo )
        return E_INVALIDARG;

1623
    if( SUCCEEDED(loadTypeInfo()) )
1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635
        *pctInfo = 1;
    else
        *pctInfo = 0;

    return NOERROR;
};

STDMETHODIMP VLCPlaylist::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
{
    if( NULL == ppTInfo )
        return E_INVALIDARG;

1636
    if( SUCCEEDED(loadTypeInfo()) )
1637 1638 1639 1640 1641 1642 1643 1644 1645
    {
        _p_typeinfo->AddRef();
        *ppTInfo = _p_typeinfo;
        return NOERROR;
    }
    *ppTInfo = NULL;
    return E_NOTIMPL;
};

1646
STDMETHODIMP VLCPlaylist::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
1647 1648
        UINT cNames, LCID lcid, DISPID* rgDispID)
{
1649
    if( SUCCEEDED(loadTypeInfo()) )
1650 1651 1652 1653 1654 1655 1656 1657 1658 1659
    {
        return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
    }
    return E_NOTIMPL;
};

STDMETHODIMP VLCPlaylist::Invoke(DISPID dispIdMember, REFIID riid,
        LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
        VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
{
1660
    if( SUCCEEDED(loadTypeInfo()) )
1661 1662 1663 1664 1665 1666 1667
    {
        return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
                pVarResult, pExcepInfo, puArgErr);
    }
    return E_NOTIMPL;
};

1668
STDMETHODIMP VLCPlaylist::get_itemCount(long* count)
1669 1670 1671 1672
{
    if( NULL == count )
        return E_POINTER;

1673
    *count = 0;
1674 1675 1676 1677 1678 1679 1680
    libvlc_instance_t* p_libvlc;
    HRESULT hr = _p_instance->getVLC(&p_libvlc);
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

1681
        libvlc_playlist_lock(p_libvlc);
1682
        *count = libvlc_playlist_items_count(p_libvlc, &ex);
1683
        libvlc_playlist_unlock(p_libvlc);
1684 1685
        if( libvlc_exception_raised(&ex) )
        {
1686
            _p_instance->setErrorInfo(IID_IVLCPlaylist,
1687
                         libvlc_exception_get_message(&ex));
1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707
            libvlc_exception_clear(&ex);
            return E_FAIL;
        }
        return NOERROR;
    }
    return hr;
};

STDMETHODIMP VLCPlaylist::get_isPlaying(VARIANT_BOOL* isPlaying)
{
    if( NULL == isPlaying )
        return E_POINTER;

    libvlc_instance_t* p_libvlc;
    HRESULT hr = _p_instance->getVLC(&p_libvlc);
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

1708 1709
        *isPlaying = libvlc_playlist_isplaying(p_libvlc, &ex) ?
                                    VARIANT_TRUE: VARIANT_FALSE;
1710 1711
        if( libvlc_exception_raised(&ex) )
        {
1712
            _p_instance->setErrorInfo(IID_IVLCPlaylist,
1713
                         libvlc_exception_get_message(&ex));
1714 1715 1716 1717 1718 1719 1720 1721
            libvlc_exception_clear(&ex);
            return E_FAIL;
        }
        return NOERROR;
    }
    return hr;
};

1722
STDMETHODIMP VLCPlaylist::add(BSTR uri, VARIANT name, VARIANT options, long* item)
1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736
{
    if( NULL == item )
        return E_POINTER;

    if( 0 == SysStringLen(uri) )
        return E_INVALIDARG;

    libvlc_instance_t* p_libvlc;
    HRESULT hr = _p_instance->getVLC(&p_libvlc);
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766
        char *psz_uri = NULL;
        if( SysStringLen(_p_instance->getBaseURL()) > 0 )
        {
            /*
            ** if the MRL a relative URL, we should end up with an absolute URL
            */
            LPWSTR abs_url = CombineURL(_p_instance->getBaseURL(), uri);
            if( NULL != abs_url )
            {
                psz_uri = CStrFromWSTR(CP_UTF8, abs_url, wcslen(abs_url));
                CoTaskMemFree(abs_url);
            }
            else
            {
                psz_uri = CStrFromBSTR(CP_UTF8, uri);
            }
        }
        else
        {
            /*
            ** baseURL is empty, assume MRL is absolute
            */
            psz_uri = CStrFromBSTR(CP_UTF8, uri);
        }

        if( NULL == psz_uri )
        {
            return E_OUTOFMEMORY;
        }

1767 1768 1769 1770 1771 1772
        int i_options;
        char **ppsz_options;

        hr = VLCControl::CreateTargetOptions(CP_UTF8, &options, &ppsz_options, &i_options);
        if( FAILED(hr) )
        {
1773 1774
            CoTaskMemFree(psz_uri);
            return hr;
1775 1776 1777
        }

        char *psz_name = NULL;
1778 1779 1780
        VARIANT v_name;
        VariantInit(&v_name);
        if( SUCCEEDED(VariantChangeType(&v_name, &name, 0, VT_BSTR)) )
1781
        {
1782 1783 1784 1785
            if( SysStringLen(V_BSTR(&v_name)) > 0 )
                psz_name = CStrFromBSTR(CP_UTF8, V_BSTR(&v_name));

            VariantClear(&v_name);
1786 1787 1788
        }

        *item = libvlc_playlist_add_extended(p_libvlc,
1789 1790 1791 1792 1793
                    psz_uri,
                    psz_name,
                    i_options,
                    const_cast<const char **>(ppsz_options),
                    &ex);
1794 1795 1796 1797 1798 1799 1800

        VLCControl::FreeTargetOptions(ppsz_options, i_options);
        CoTaskMemFree(psz_uri);
        if( psz_name )
            CoTaskMemFree(psz_name);
        if( libvlc_exception_raised(&ex) )
        {
1801 1802
            _p_instance->setErrorInfo(IID_IVLCPlaylist,
                libvlc_exception_get_message(&ex));
1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830
            libvlc_exception_clear(&ex);
            return E_FAIL;
        }
        return NOERROR;
    }
    return hr;
};

STDMETHODIMP VLCPlaylist::play()
{
    libvlc_instance_t* p_libvlc;
    HRESULT hr = _p_instance->getVLC(&p_libvlc);
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

        libvlc_playlist_play(p_libvlc, -1, 0, NULL, &ex);
        if( libvlc_exception_raised(&ex) )
        {
            libvlc_exception_clear(&ex);
            return E_FAIL;
        }
        return NOERROR;
    }
    return hr;
};

1831
STDMETHODIMP VLCPlaylist::playItem(long item)
1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842
{
    libvlc_instance_t* p_libvlc;
    HRESULT hr = _p_instance->getVLC(&p_libvlc);
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

        libvlc_playlist_play(p_libvlc, item, 0, NULL, &ex);
        if( libvlc_exception_raised(&ex) )
        {
1843 1844
            _p_instance->setErrorInfo(IID_IVLCPlaylist,
                libvlc_exception_get_message(&ex));
1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864
            libvlc_exception_clear(&ex);
            return E_FAIL;
        }
        return NOERROR;
    }
    return hr;
};

STDMETHODIMP VLCPlaylist::togglePause()
{
    libvlc_instance_t* p_libvlc;
    HRESULT hr = _p_instance->getVLC(&p_libvlc);
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

        libvlc_playlist_pause(p_libvlc, &ex);
        if( libvlc_exception_raised(&ex) )
        {
1865 1866
            _p_instance->setErrorInfo(IID_IVLCPlaylist,
                libvlc_exception_get_message(&ex));
1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886
            libvlc_exception_clear(&ex);
            return E_FAIL;
        }
        return NOERROR;
    }
    return hr;
};

STDMETHODIMP VLCPlaylist::stop()
{
    libvlc_instance_t* p_libvlc;
    HRESULT hr = _p_instance->getVLC(&p_libvlc);
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

        libvlc_playlist_stop(p_libvlc, &ex);
        if( libvlc_exception_raised(&ex) )
        {
1887 1888
            _p_instance->setErrorInfo(IID_IVLCPlaylist,
                libvlc_exception_get_message(&ex));
1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908
            libvlc_exception_clear(&ex);
            return E_FAIL;
        }
        return NOERROR;
    }
    return hr;
};

STDMETHODIMP VLCPlaylist::next()
{
    libvlc_instance_t* p_libvlc;
    HRESULT hr = _p_instance->getVLC(&p_libvlc);
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

        libvlc_playlist_next(p_libvlc, &ex);
        if( libvlc_exception_raised(&ex) )
        {
1909 1910
            _p_instance->setErrorInfo(IID_IVLCPlaylist,
                libvlc_exception_get_message(&ex));
1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930
            libvlc_exception_clear(&ex);
            return E_FAIL;
        }
        return NOERROR;
    }
    return hr;
};

STDMETHODIMP VLCPlaylist::prev()
{
    libvlc_instance_t* p_libvlc;
    HRESULT hr = _p_instance->getVLC(&p_libvlc);
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

        libvlc_playlist_prev(p_libvlc, &ex);
        if( libvlc_exception_raised(&ex) )
        {
1931 1932
            _p_instance->setErrorInfo(IID_IVLCPlaylist,
                libvlc_exception_get_message(&ex));
1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952
            libvlc_exception_clear(&ex);
            return E_FAIL;
        }
        return NOERROR;
    }
    return hr;
};

STDMETHODIMP VLCPlaylist::clear()
{
    libvlc_instance_t* p_libvlc;
    HRESULT hr = _p_instance->getVLC(&p_libvlc);
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

        libvlc_playlist_clear(p_libvlc, &ex);
        if( libvlc_exception_raised(&ex) )
        {
1953 1954
            _p_instance->setErrorInfo(IID_IVLCPlaylist,
                libvlc_exception_get_message(&ex));
1955 1956 1957 1958 1959 1960 1961 1962
            libvlc_exception_clear(&ex);
            return E_FAIL;
        }
        return NOERROR;
    }
    return hr;
};

1963
STDMETHODIMP VLCPlaylist::removeItem(long item)
1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974
{
    libvlc_instance_t* p_libvlc;
    HRESULT hr = _p_instance->getVLC(&p_libvlc);
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

        libvlc_playlist_delete_item(p_libvlc, item, &ex);
        if( libvlc_exception_raised(&ex) )
        {
1975 1976
            _p_instance->setErrorInfo(IID_IVLCPlaylist,
                libvlc_exception_get_message(&ex));
1977 1978 1979 1980 1981 1982 1983 1984
            libvlc_exception_clear(&ex);
            return E_FAIL;
        }
        return NOERROR;
    }
    return hr;
};

1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998
STDMETHODIMP VLCPlaylist::get_items(IVLCPlaylistItems** obj)
{
    if( NULL == obj )
        return E_POINTER;

    *obj = _p_vlcplaylistitems;
    if( NULL != _p_vlcplaylistitems )
    {
        _p_vlcplaylistitems->AddRef();
        return NOERROR;
    }
    return E_OUTOFMEMORY;
};

1999 2000 2001 2002 2003 2004 2005 2006
/*******************************************************************************/

VLCVideo::~VLCVideo()
{
    if( _p_typeinfo )
        _p_typeinfo->Release();
};

2007
HRESULT VLCVideo::loadTypeInfo(void)
2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032
{
    HRESULT hr = NOERROR;
    if( NULL == _p_typeinfo )
    {
        ITypeLib *p_typelib;

        hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
        if( SUCCEEDED(hr) )
        {
            hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCVideo, &_p_typeinfo);
            if( FAILED(hr) )
            {
                _p_typeinfo = NULL;
            }
            p_typelib->Release();
        }
    }
    return hr;
};

STDMETHODIMP VLCVideo::GetTypeInfoCount(UINT* pctInfo)
{
    if( NULL == pctInfo )
        return E_INVALIDARG;

2033
    if( SUCCEEDED(loadTypeInfo()) )
2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045
        *pctInfo = 1;
    else
        *pctInfo = 0;

    return NOERROR;
};

STDMETHODIMP VLCVideo::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
{
    if( NULL == ppTInfo )
        return E_INVALIDARG;

2046
    if( SUCCEEDED(loadTypeInfo()) )
2047 2048 2049 2050 2051 2052 2053 2054 2055
    {
        _p_typeinfo->AddRef();
        *ppTInfo = _p_typeinfo;
        return NOERROR;
    }
    *ppTInfo = NULL;
    return E_NOTIMPL;
};

2056
STDMETHODIMP VLCVideo::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
2057 2058
        UINT cNames, LCID lcid, DISPID* rgDispID)
{
2059
    if( SUCCEEDED(loadTypeInfo()) )
2060 2061 2062 2063 2064 2065 2066 2067 2068 2069
    {
        return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
    }
    return E_NOTIMPL;
};

STDMETHODIMP VLCVideo::Invoke(DISPID dispIdMember, REFIID riid,
        LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
        VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
{
2070
    if( SUCCEEDED(loadTypeInfo()) )
2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089
    {
        return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
                pVarResult, pExcepInfo, puArgErr);
    }
    return E_NOTIMPL;
};

STDMETHODIMP VLCVideo::get_fullscreen(VARIANT_BOOL* fullscreen)
{
    if( NULL == fullscreen )
        return E_POINTER;

    libvlc_instance_t* p_libvlc;
    HRESULT hr = _p_instance->getVLC(&p_libvlc);
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

2090
        libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_libvlc, &ex);
2091 2092
        if( ! libvlc_exception_raised(&ex) )
        {
2093
            *fullscreen = libvlc_get_fullscreen(p_md, &ex) ? VARIANT_TRUE : VARIANT_FALSE;
2094
            libvlc_media_player_release(p_md);
2095 2096 2097 2098 2099
            if( ! libvlc_exception_raised(&ex) )
            {
                return NOERROR;
            }
        }
2100
        _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115
        libvlc_exception_clear(&ex);
        return E_FAIL;
    }
    return hr;
};

STDMETHODIMP VLCVideo::put_fullscreen(VARIANT_BOOL fullscreen)
{
    libvlc_instance_t* p_libvlc;
    HRESULT hr = _p_instance->getVLC(&p_libvlc);
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

2116
        libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_libvlc, &ex);
2117 2118
        if( ! libvlc_exception_raised(&ex) )
        {
2119
            libvlc_set_fullscreen(p_md, VARIANT_FALSE != fullscreen, &ex);
2120
            libvlc_media_player_release(p_md);
2121 2122 2123 2124 2125
            if( ! libvlc_exception_raised(&ex) )
            {
                return NOERROR;
            }
        }
2126
        _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
2127 2128 2129 2130 2131 2132
        libvlc_exception_clear(&ex);
        return E_FAIL;
    }
    return hr;
};

2133
STDMETHODIMP VLCVideo::get_width(long* width)
2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144
{
    if( NULL == width )
        return E_POINTER;

    libvlc_instance_t* p_libvlc;
    HRESULT hr = _p_instance->getVLC(&p_libvlc);
    if( SUCCEEDED(hr) )
    {