vlccontrol2.cpp 70 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
 *
 * 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.
 *
19 20 21
 * 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.
22 23 24 25 26 27 28 29
 *****************************************************************************/

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

#include "utils.h"

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

35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53

static inline
HRESULT _exception_bridge(VLCPlugin *p,REFIID riid, libvlc_exception_t *ex)
{
    if( libvlc_exception_raised(ex) )
    {
        p->setErrorInfo(riid,libvlc_exception_get_message(ex));
        libvlc_exception_clear(ex);
        return E_FAIL;
    }
    return NOERROR;
}

#define EMIT_EXCEPTION_BRIDGE( classname ) \
    HRESULT classname::exception_bridge( libvlc_exception_t *ex ) \
    { return _exception_bridge( _p_instance, IID_I##classname, ex ); }

EMIT_EXCEPTION_BRIDGE( VLCAudio )
EMIT_EXCEPTION_BRIDGE( VLCInput )
54
EMIT_EXCEPTION_BRIDGE( VLCMarquee )
55 56 57 58 59 60
EMIT_EXCEPTION_BRIDGE( VLCMessageIterator )
EMIT_EXCEPTION_BRIDGE( VLCMessages )
EMIT_EXCEPTION_BRIDGE( VLCLog )
EMIT_EXCEPTION_BRIDGE( VLCPlaylistItems )
EMIT_EXCEPTION_BRIDGE( VLCPlaylist )
EMIT_EXCEPTION_BRIDGE( VLCVideo )
61
EMIT_EXCEPTION_BRIDGE( VLCSubtitle )
62 63 64

#undef  EMIT_EXCEPTION_BRIDGE

65 66 67 68 69 70 71

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

72
HRESULT VLCAudio::loadTypeInfo(void)
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
{
    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;

98
    if( SUCCEEDED(loadTypeInfo()) )
99 100 101 102 103 104 105 106 107 108 109 110
        *pctInfo = 1;
    else
        *pctInfo = 0;

    return NOERROR;
};

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

111
    if( SUCCEEDED(loadTypeInfo()) )
112 113 114 115 116 117 118 119 120
    {
        _p_typeinfo->AddRef();
        *ppTInfo = _p_typeinfo;
        return NOERROR;
    }
    *ppTInfo = NULL;
    return E_NOTIMPL;
};

121
STDMETHODIMP VLCAudio::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
122 123
        UINT cNames, LCID lcid, DISPID* rgDispID)
{
124
    if( SUCCEEDED(loadTypeInfo()) )
125 126 127 128 129 130 131 132 133 134
    {
        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)
{
135
    if( SUCCEEDED(loadTypeInfo()) )
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
    {
        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);

155 156
        *mute = libvlc_audio_get_mute(p_libvlc, &ex) ?
                        VARIANT_TRUE : VARIANT_FALSE;
157
        hr = exception_bridge(&ex);
158 159 160 161 162 163 164 165 166 167 168 169 170 171
    }
    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);
172
        hr = exception_bridge(&ex);
173 174 175 176
    }
    return hr;
};

177
STDMETHODIMP VLCAudio::get_volume(long* volume)
178 179 180 181 182 183 184 185 186 187 188 189
{
    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);
190
        hr = exception_bridge(&ex);
191 192 193 194
    }
    return hr;
};

195
STDMETHODIMP VLCAudio::put_volume(long volume)
196 197 198 199 200 201 202 203 204
{
    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);
205
        hr = exception_bridge(&ex);
206 207 208 209
    }
    return hr;
};

210 211 212 213 214
STDMETHODIMP VLCAudio::get_track(long* track)
{
    if( NULL == track )
        return E_POINTER;

JP Dinger's avatar
JP Dinger committed
215 216
    libvlc_media_player_t* p_md;
    HRESULT hr = _p_instance->getMD(&p_md);
217 218 219 220 221
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

222
        *track = libvlc_audio_get_track(p_md, &ex);
223
        hr = exception_bridge(&ex);
224 225 226 227 228 229
    }
    return hr;
};

STDMETHODIMP VLCAudio::put_track(long track)
{
JP Dinger's avatar
JP Dinger committed
230 231
    libvlc_media_player_t *p_md;
    HRESULT hr = _p_instance->getMD(&p_md);
232 233 234 235 236
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

237
        libvlc_audio_set_track(p_md, track, &ex);
238
        hr = exception_bridge(&ex);
239 240 241 242
    }
    return hr;
};

243 244 245 246 247 248 249 250 251 252 253 254 255
STDMETHODIMP VLCAudio::get_count(long* trackNumber)
{
    if( NULL == trackNumber )
        return E_POINTER;

    libvlc_media_player_t* p_md;
    HRESULT hr = _p_instance->getMD(&p_md);
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);
        // get the number of audio track available and return it
        *trackNumber = libvlc_audio_get_track_count(p_md, &ex);
256
        hr = exception_bridge(&ex);
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
    }
    return hr;
};


STDMETHODIMP VLCAudio::description(long trackID, BSTR* name)
{
    if( NULL == name )
        return E_POINTER;

    libvlc_media_player_t* p_md;
    libvlc_exception_t ex;
    libvlc_exception_init(&ex);

    HRESULT hr = _p_instance->getMD(&p_md);
    if( SUCCEEDED(hr) )
    {
        int i, i_limit;
        const char *psz_name;
        libvlc_track_description_t *p_trackDesc;

        // get tracks description
        p_trackDesc = libvlc_audio_get_track_description(p_md, &ex);
280 281 282
        hr = exception_bridge(&ex);
        if( FAILED(hr) )
            return hr;
283 284 285

        //get the number of available track
        i_limit = libvlc_audio_get_track_count(p_md, &ex);
286 287 288
        hr = exception_bridge(&ex);
        if( FAILED(hr) )
            return hr;
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313

        // check if the number given is a good one
        if ( ( trackID > ( i_limit -1 ) ) || ( trackID < 0 ) )
                return E_FAIL;

        // get the good trackDesc
        for( i = 0 ; i < trackID ; i++ )
        {
            p_trackDesc = p_trackDesc->p_next;
        }
        // get the track name
        psz_name = p_trackDesc->psz_name;

        // return it
        if( psz_name != NULL )
        {
            *name = BSTRFromCStr(CP_UTF8, psz_name);
            return (NULL == *name) ? E_OUTOFMEMORY : NOERROR;
        }
        *name = NULL;
        return E_FAIL;
    }
    return hr;
};

314
STDMETHODIMP VLCAudio::get_channel(long *channel)
315 316 317 318 319 320 321 322 323 324 325
{
    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);

326
        *channel = libvlc_audio_get_channel(p_libvlc, &ex);
327
        hr = exception_bridge(&ex);
328 329 330 331
    }
    return hr;
};

332
STDMETHODIMP VLCAudio::put_channel(long channel)
333 334 335 336 337 338 339 340
{
    libvlc_instance_t* p_libvlc;
    HRESULT hr = _p_instance->getVLC(&p_libvlc);
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

341
        libvlc_audio_set_channel(p_libvlc, channel, &ex);
342
        hr = exception_bridge(&ex);
343 344 345 346
    }
    return hr;
};

347 348 349 350 351 352 353 354 355 356
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);
357
        hr = exception_bridge(&ex);
358 359 360 361 362 363 364 365 366 367 368 369
    }
    return hr;
};

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

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

370
HRESULT VLCInput::loadTypeInfo(void)
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395
{
    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;

396
    if( SUCCEEDED(loadTypeInfo()) )
397 398 399 400 401 402 403 404 405 406 407 408
        *pctInfo = 1;
    else
        *pctInfo = 0;

    return NOERROR;
};

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

409
    if( SUCCEEDED(loadTypeInfo()) )
410 411 412 413 414 415 416 417 418
    {
        _p_typeinfo->AddRef();
        *ppTInfo = _p_typeinfo;
        return NOERROR;
    }
    *ppTInfo = NULL;
    return E_NOTIMPL;
};

419
STDMETHODIMP VLCInput::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
420 421
        UINT cNames, LCID lcid, DISPID* rgDispID)
{
422
    if( SUCCEEDED(loadTypeInfo()) )
423 424 425 426 427 428 429 430 431 432
    {
        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)
{
433
    if( SUCCEEDED(loadTypeInfo()) )
434 435 436 437 438 439 440
    {
        return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
                pVarResult, pExcepInfo, puArgErr);
    }
    return E_NOTIMPL;
};

441
STDMETHODIMP VLCInput::get_length(double* length)
442 443 444
{
    if( NULL == length )
        return E_POINTER;
445
    *length = 0;
446

JP Dinger's avatar
JP Dinger committed
447 448
    libvlc_media_player_t *p_md;
    HRESULT hr = _p_instance->getMD(&p_md);
449 450 451 452 453
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

JP Dinger's avatar
JP Dinger committed
454
        *length = (double)libvlc_media_player_get_length(p_md, &ex);
455
        hr = exception_bridge(&ex);
456 457 458 459
    }
    return hr;
};

460
STDMETHODIMP VLCInput::get_position(double* position)
461 462 463 464
{
    if( NULL == position )
        return E_POINTER;

465
    *position = 0.0f;
JP Dinger's avatar
JP Dinger committed
466 467
    libvlc_media_player_t *p_md;
    HRESULT hr = _p_instance->getMD(&p_md);
468 469 470 471 472
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

JP Dinger's avatar
JP Dinger committed
473
        *position = libvlc_media_player_get_position(p_md, &ex);
474
        hr = exception_bridge(&ex);
475 476 477 478
    }
    return hr;
};

479
STDMETHODIMP VLCInput::put_position(double position)
480
{
JP Dinger's avatar
JP Dinger committed
481 482
    libvlc_media_player_t *p_md;
    HRESULT hr = _p_instance->getMD(&p_md);
483 484 485 486 487
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

JP Dinger's avatar
JP Dinger committed
488
        libvlc_media_player_set_position(p_md, position, &ex);
489
        hr = exception_bridge(&ex);
490 491 492 493
    }
    return hr;
};

494
STDMETHODIMP VLCInput::get_time(double* time)
495 496 497 498
{
    if( NULL == time )
        return E_POINTER;

JP Dinger's avatar
JP Dinger committed
499 500
    libvlc_media_player_t *p_md;
    HRESULT hr = _p_instance->getMD(&p_md);
501 502 503 504 505
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

JP Dinger's avatar
JP Dinger committed
506
        *time = (double)libvlc_media_player_get_time(p_md, &ex);
507
        hr = exception_bridge(&ex);
508 509 510 511
    }
    return hr;
};

512
STDMETHODIMP VLCInput::put_time(double time)
513
{
JP Dinger's avatar
JP Dinger committed
514 515
    libvlc_media_player_t *p_md;
    HRESULT hr = _p_instance->getMD(&p_md);
516 517 518 519 520
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

JP Dinger's avatar
JP Dinger committed
521
        libvlc_media_player_set_time(p_md, (int64_t)time, &ex);
522
        hr = exception_bridge(&ex);
523 524 525 526
    }
    return hr;
};

527
STDMETHODIMP VLCInput::get_state(long* state)
528 529 530 531
{
    if( NULL == state )
        return E_POINTER;

JP Dinger's avatar
JP Dinger committed
532 533
    libvlc_media_player_t *p_md;
    HRESULT hr = _p_instance->getMD(&p_md);
534 535 536 537 538
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

JP Dinger's avatar
JP Dinger committed
539
        *state = libvlc_media_player_get_state(p_md, &ex);
540
        if( libvlc_exception_raised(&ex) )
541
        {
542 543 544
            // don't fail, just return the idle state
            *state = 0;
            libvlc_exception_clear(&ex);
545 546 547 548 549
        }
    }
    return hr;
};

550
STDMETHODIMP VLCInput::get_rate(double* rate)
551 552 553 554
{
    if( NULL == rate )
        return E_POINTER;

JP Dinger's avatar
JP Dinger committed
555 556
    libvlc_media_player_t *p_md;
    HRESULT hr = _p_instance->getMD(&p_md);
557 558 559 560 561
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

JP Dinger's avatar
JP Dinger committed
562
        *rate = libvlc_media_player_get_rate(p_md, &ex);
563
        hr = exception_bridge(&ex);
564 565 566 567
    }
    return hr;
};

568
STDMETHODIMP VLCInput::put_rate(double rate)
569
{
JP Dinger's avatar
JP Dinger committed
570 571
    libvlc_media_player_t *p_md;
    HRESULT hr = _p_instance->getMD(&p_md);
572 573 574 575 576
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

JP Dinger's avatar
JP Dinger committed
577
        libvlc_media_player_set_rate(p_md, rate, &ex);
578
        hr = exception_bridge(&ex);
579 580 581 582
    }
    return hr;
};

583
STDMETHODIMP VLCInput::get_fps(double* fps)
584 585 586 587
{
    if( NULL == fps )
        return E_POINTER;

588
    *fps = 0.0;
JP Dinger's avatar
JP Dinger committed
589 590
    libvlc_media_player_t *p_md;
    HRESULT hr = _p_instance->getMD(&p_md);
591 592 593 594 595
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

JP Dinger's avatar
JP Dinger committed
596
        *fps = libvlc_media_player_get_fps(p_md, &ex);
597
        hr = exception_bridge(&ex);
598 599 600 601 602 603 604 605 606
    }
    return hr;
};

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

JP Dinger's avatar
JP Dinger committed
607 608
    libvlc_media_player_t *p_md;
    HRESULT hr = _p_instance->getMD(&p_md);
609 610 611 612 613
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

JP Dinger's avatar
JP Dinger committed
614 615
        *hasVout = libvlc_media_player_has_vout(p_md, &ex) ?
                                VARIANT_TRUE : VARIANT_FALSE;
616
        hr = exception_bridge(&ex);
617 618 619 620 621 622
    }
    return hr;
};

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

623 624
VLCLog::~VLCLog()
{
625
    delete _p_vlcmessages;
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 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681
    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;
};

682
STDMETHODIMP VLCLog::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732
        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);
733
            hr = exception_bridge(&ex);
734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750
        }
        return hr;
    }
    else
    {
        /* log is not enabled, return -1 */
        *level = -1;
        return NOERROR;
    }
};

STDMETHODIMP VLCLog::put_verbosity(long verbosity)
{
    libvlc_instance_t* p_libvlc;
    HRESULT hr = _p_instance->getVLC(&p_libvlc);
    if( SUCCEEDED(hr) )
    {
751 752 753
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

754 755 756 757 758
        if( verbosity >= 0 )
        {
            if( ! _p_log )
            {
                _p_log = libvlc_log_open(p_libvlc, &ex);
759
                hr = exception_bridge(&ex);
760
            }
761 762
            if( SUCCEEDED(hr) )
                libvlc_set_log_verbosity(p_libvlc, (unsigned)verbosity, &ex);
763 764 765 766 767 768 769
        }
        else if( _p_log )
        {
            /* close log  when verbosity is set to -1 */
            libvlc_log_close(_p_log, &ex);
            _p_log = NULL;
        }
770
        hr = exception_bridge(&ex);
771 772 773 774 775 776
    }
    return hr;
};

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

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 828 829 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 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 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 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 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
VLCMarquee::~VLCMarquee()
{
    if( _p_typeinfo )
        _p_typeinfo->Release();
};

HRESULT VLCMarquee::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_IVLCMarquee, &_p_typeinfo);
            if( FAILED(hr) )
            {
                _p_typeinfo = NULL;
            }
            p_typelib->Release();
        }
    }
    return hr;
};

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

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

    return NOERROR;
};

STDMETHODIMP VLCMarquee::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;
};

STDMETHODIMP VLCMarquee::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
        UINT cNames, LCID lcid, DISPID* rgDispID)
{
    if( SUCCEEDED(loadTypeInfo()) )
    {
        return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
    }
    return E_NOTIMPL;
};

STDMETHODIMP VLCMarquee::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 VLCMarquee::enable()
{
    libvlc_media_player_t *p_md;
    HRESULT hr = _p_instance->getMD(&p_md);
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

        libvlc_video_set_marquee_option_as_int(p_md, libvlc_marquee_Enabled, true, &ex);
        hr = exception_bridge(&ex);
    }
    return hr;
};

STDMETHODIMP VLCMarquee::disable()
{
    libvlc_media_player_t *p_md;
    HRESULT hr = _p_instance->getMD(&p_md);
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

        libvlc_video_set_marquee_option_as_int(p_md, libvlc_marquee_Enabled, false, &ex);
        hr = exception_bridge(&ex);
    }
    return hr;
};

STDMETHODIMP VLCMarquee::color(long val)
{
    libvlc_media_player_t *p_md;
    HRESULT hr = _p_instance->getMD(&p_md);
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

        libvlc_video_set_marquee_option_as_int(p_md, libvlc_marquee_Color, val, &ex);
        hr = exception_bridge(&ex);
    }
    return hr;
};

STDMETHODIMP VLCMarquee::opacity(long val)
{
    libvlc_media_player_t *p_md;
    HRESULT hr = _p_instance->getMD(&p_md);
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

        libvlc_video_set_marquee_option_as_int(p_md, libvlc_marquee_Opacity, val, &ex);
        hr = exception_bridge(&ex);
    }
    return hr;
};

STDMETHODIMP VLCMarquee::position(long val)
{
    libvlc_media_player_t *p_md;
    HRESULT hr = _p_instance->getMD(&p_md);
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

        libvlc_video_set_marquee_option_as_int(p_md, libvlc_marquee_Position, val, &ex);
        hr = exception_bridge(&ex);
    }
    return hr;
};

STDMETHODIMP VLCMarquee::refresh(long val)
{
    libvlc_media_player_t *p_md;
    HRESULT hr = _p_instance->getMD(&p_md);
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

        libvlc_video_set_marquee_option_as_int(p_md, libvlc_marquee_Refresh, val, &ex);
        hr = exception_bridge(&ex);
    }
    return hr;
};

STDMETHODIMP VLCMarquee::size(long val)
{
    libvlc_media_player_t *p_md;
    HRESULT hr = _p_instance->getMD(&p_md);
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

        libvlc_video_set_marquee_option_as_int(p_md, libvlc_marquee_Size, val, &ex);
        hr = exception_bridge(&ex);
    }
    return hr;
};

STDMETHODIMP VLCMarquee::text(BSTR text)
{
    libvlc_media_player_t *p_md;
    HRESULT hr = _p_instance->getMD(&p_md);
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

        char *psz_text = CStrFromBSTR(CP_UTF8, text);
        libvlc_video_set_marquee_option_as_string(p_md, libvlc_marquee_Text, psz_text, &ex);
        hr = exception_bridge(&ex);
        CoTaskMemFree(psz_text);
    }
    return hr;
};

STDMETHODIMP VLCMarquee::timeout(long val)
{
    libvlc_media_player_t *p_md;
    HRESULT hr = _p_instance->getMD(&p_md);
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

        libvlc_video_set_marquee_option_as_int(p_md, libvlc_marquee_Timeout, val, &ex);
        hr = exception_bridge(&ex);
    }
    return hr;
};

STDMETHODIMP VLCMarquee::x(long val)
{
    libvlc_media_player_t *p_md;
    HRESULT hr = _p_instance->getMD(&p_md);
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

        libvlc_video_set_marquee_option_as_int(p_md, libvlc_marquee_X, val, &ex);
        hr = exception_bridge(&ex);
    }
    return hr;
};

STDMETHODIMP VLCMarquee::y(long val)
{
    libvlc_media_player_t *p_md;
    HRESULT hr = _p_instance->getMD(&p_md);
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

        libvlc_video_set_marquee_option_as_int(p_md, libvlc_marquee_Y, val, &ex);
        hr = exception_bridge(&ex);
    }
    return hr;
};

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

1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 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 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080
/* 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 )
        {
1081 1082
            if( SUCCEEDED(msg->QueryInterface(IID_IDispatch,
                          (LPVOID*)&V_DISPATCH(&v))) )
1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106
            {
                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;
};

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

1107 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
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;
};

1162
STDMETHODIMP VLCMessages::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
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
        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;

1189 1190 1191 1192 1193 1194 1195 1196 1197 1198
    IVLCMessageIterator* iter = NULL;
    iterator(&iter);

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

    return *_NewEnum ? S_OK : E_OUTOFMEMORY;
1199 1200 1201 1202
};

STDMETHODIMP VLCMessages::clear()
{
1203
    HRESULT hr = NOERROR;
1204 1205 1206 1207 1208 1209 1210
    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);
1211
        hr = exception_bridge(&ex);
1212
    }
1213
    return hr;
1214 1215 1216 1217
};

STDMETHODIMP VLCMessages::get_count(long* count)
{
1218 1219
    HRESULT hr = S_OK;

1220 1221 1222 1223 1224 1225 1226 1227 1228 1229
    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);
1230
        hr = exception_bridge(&ex);
1231 1232 1233
    }
    else
        *count = 0;
1234
    return hr;
1235 1236 1237 1238 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 1267 1268 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
};

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;
};

1321
STDMETHODIMP VLCMessageIterator::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344
        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)
{
1345 1346
    HRESULT hr = S_OK;

1347 1348 1349 1350 1351 1352 1353 1354
    if( NULL == hasNext )
        return E_POINTER;

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

1355
        *hasNext = libvlc_log_iterator_has_next(_p_iter, &ex) ?
1356 1357
                   VARIANT_TRUE : VARIANT_FALSE;
        hr = exception_bridge(&ex);
1358 1359 1360 1361 1362
    }
    else
    {
        *hasNext = VARIANT_FALSE;
    }
1363
    return hr;
1364 1365 1366 1367
};

STDMETHODIMP VLCMessageIterator::next(IVLCMessage** message)
{
1368 1369
    HRESULT hr = S_OK;

1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382
    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);
1383 1384
        hr = exception_bridge(&ex);
        if( SUCCEEDED(hr) )
1385
        {
1386 1387 1388
            *message = new VLCMessage(_p_instance, buffer);
            if( !message )
                hr = E_OUTOFMEMORY;
1389 1390
        }
    }
1391
    return hr;
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 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450
};

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

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;
};

1451
STDMETHODIMP VLCMessage::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
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 1495 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 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555
        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;
};

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

1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610
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;
};

1611
STDMETHODIMP VLCPlaylistItems::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637
        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;

JP Dinger's avatar
JP Dinger committed
1638 1639
    libvlc_exception_t ex;
    libvlc_exception_init(&ex);
1640

JP Dinger's avatar
JP Dinger committed
1641
    *count = _p_instance->playlist_count(&ex);
1642
    return exception_bridge(&ex);
1643 1644 1645 1646
};

STDMETHODIMP VLCPlaylistItems::clear()
{
1647 1648
    libvlc_exception_t ex;
    libvlc_exception_init(&ex);
1649

1650 1651
    _p_instance->playlist_clear(&ex);
    return exception_bridge(&ex);
1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662
};

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);

JP Dinger's avatar
JP Dinger committed
1663
        _p_instance->playlist_delete_item(item, &ex);
1664
        hr = exception_bridge(&ex);
1665 1666 1667 1668 1669 1670
    }
    return hr;
};

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

1671 1672
VLCPlaylist::~VLCPlaylist()
{
1673
    delete _p_vlcplaylistitems;
1674 1675 1676 1677
    if( _p_typeinfo )
        _p_typeinfo->Release();
};

1678
HRESULT VLCPlaylist::loadTypeInfo(void)
1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703
{
    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;

1704
    if( SUCCEEDED(loadTypeInfo()) )
1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716
        *pctInfo = 1;
    else
        *pctInfo = 0;

    return NOERROR;
};

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

1717
    if( SUCCEEDED(loadTypeInfo()) )
1718 1719 1720 1721 1722 1723 1724 1725 1726
    {
        _p_typeinfo->AddRef();
        *ppTInfo = _p_typeinfo;
        return NOERROR;
    }
    *ppTInfo = NULL;
    return E_NOTIMPL;
};

1727
STDMETHODIMP VLCPlaylist::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
1728 1729
        UINT cNames, LCID lcid, DISPID* rgDispID)
{
1730
    if( SUCCEEDED(loadTypeInfo()) )
1731 1732 1733 1734 1735 1736 1737 1738 1739 1740
    {
        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)
{
1741
    if( SUCCEEDED(loadTypeInfo()) )
1742 1743 1744 1745 1746 1747 1748
    {
        return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
                pVarResult, pExcepInfo, puArgErr);
    }
    return E_NOTIMPL;
};

1749
STDMETHODIMP VLCPlaylist::get_itemCount(long* count)
1750 1751 1752 1753
{
    if( NULL == count )
        return E_POINTER;

1754
    *count = 0;
JP Dinger's avatar
JP Dinger committed
1755 1756
    libvlc_exception_t ex;
    libvlc_exception_init(&ex);
1757

JP Dinger's avatar
JP Dinger committed
1758
    *count = _p_instance->playlist_count(&ex);
1759
    return exception_bridge(&ex);
1760 1761 1762 1763 1764 1765 1766
};

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

JP Dinger's avatar
JP Dinger committed
1767 1768
    libvlc_media_player_t *p_md;
    HRESULT hr = _p_instance->getMD(&p_md);
1769 1770 1771 1772 1773
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

JP Dinger's avatar
JP Dinger committed
1774
        *isPlaying = libvlc_media_player_is_playing(p_md, &ex) ?
1775 1776
                     VARIANT_TRUE: VARIANT_FALSE;
        libvlc_exception_clear(&ex);
1777 1778 1779 1780
    }
    return hr;
};

1781
STDMETHODIMP VLCPlaylist::add(BSTR uri, VARIANT name, VARIANT options, long* item)
1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795
{
    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);

1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825
        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;
        }

1826 1827 1828 1829 1830 1831
        int i_options;
        char **ppsz_options;

        hr = VLCControl::CreateTargetOptions(CP_UTF8, &options, &ppsz_options, &i_options);
        if( FAILED(hr) )
        {
1832 1833
            CoTaskMemFree(psz_uri);
            return hr;
1834 1835 1836
        }

        char *psz_name = NULL;
1837 1838 1839
        VARIANT v_name;
        VariantInit(&v_name);
        if( SUCCEEDED(VariantChangeType(&v_name, &name, 0, VT_BSTR)) )
1840
        {
1841 1842 1843 1844
            if( SysStringLen(V_BSTR(&v_name)) > 0 )
                psz_name = CStrFromBSTR(CP_UTF8, V_BSTR(&v_name));

            VariantClear(&v_name);
1845 1846
        }

JP Dinger's avatar
JP Dinger committed
1847 1848
        *item = _p_instance->playlist_add_extended_untrusted(psz_uri,
                    i_options, const_cast<const char **>(ppsz_options), &ex);
1849 1850 1851

        VLCControl::FreeTargetOptions(ppsz_options, i_options);
        CoTaskMemFree(psz_uri);
1852
        if( psz_name ) /* XXX Do we even need to check? */
1853
            CoTaskMemFree(psz_name);
1854
        hr = exception_bridge(&ex);
1855 1856 1857 1858 1859 1860
    }
    return hr;
};

STDMETHODIMP VLCPlaylist::play()
{
JP Dinger's avatar
JP Dinger committed
1861 1862
    libvlc_exception_t ex;
    libvlc_exception_init(&ex);
1863

JP Dinger's avatar
JP Dinger committed
1864
    _p_instance->playlist_play(&ex);
1865
    return exception_bridge(&ex);
1866 1867
};

1868
STDMETHODIMP VLCPlaylist::playItem(long item)
1869
{
JP Dinger's avatar
JP Dinger committed
1870 1871
    libvlc_exception_t ex;
    libvlc_exception_init(&ex);
1872

JP Dinger's avatar
JP Dinger committed
1873
    _p_instance->playlist_play_item(item,&ex);
1874
    return exception_bridge(&ex);;
1875 1876 1877 1878
};

STDMETHODIMP VLCPlaylist::togglePause()
{
JP Dinger's avatar
JP Dinger committed
1879 1880
    libvlc_media_player_t* p_md;
    HRESULT hr = _p_instance->getMD(&p_md);
1881 1882 1883 1884 1885
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

JP Dinger's avatar
JP Dinger committed
1886
        libvlc_media_player_pause(p_md, &ex);
1887
        hr = exception_bridge(&ex);;
1888 1889 1890 1891 1892 1893
    }
    return hr;
};

STDMETHODIMP VLCPlaylist::stop()
{
JP Dinger's avatar
JP Dinger committed
1894 1895
    libvlc_media_player_t *p_md;
    HRESULT hr = _p_instance->getMD(&p_md);
1896 1897 1898 1899 1900
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

JP Dinger's avatar
JP Dinger committed
1901
        libvlc_media_player_stop(p_md, &ex);
1902
        hr = exception_bridge(&ex);;
1903 1904 1905 1906 1907 1908
    }
    return hr;
};

STDMETHODIMP VLCPlaylist::next()
{
JP Dinger's avatar
JP Dinger committed
1909 1910
    libvlc_exception_t ex;
    libvlc_exception_init(&ex);
1911

JP Dinger's avatar
JP Dinger committed
1912
    _p_instance->playlist_next(&ex);
1913
    return exception_bridge(&ex);;
1914 1915 1916 1917
};

STDMETHODIMP VLCPlaylist::prev()
{
JP Dinger's avatar
JP Dinger committed
1918 1919
    libvlc_exception_t ex;
    libvlc_exception_init(&ex);
1920

JP Dinger's avatar
JP Dinger committed
1921
    _p_instance->playlist_prev(&ex);
1922
    return exception_bridge(&ex);;
1923 1924 1925 1926
};

STDMETHODIMP VLCPlaylist::clear()
{
JP Dinger's avatar
JP Dinger committed
1927 1928
    libvlc_exception_t ex;
    libvlc_exception_init(&ex);
1929

JP Dinger's avatar
JP Dinger committed
1930
    _p_instance->playlist_clear(&ex);
1931
    return exception_bridge(&ex);;
1932 1933
};

1934
STDMETHODIMP VLCPlaylist::removeItem(long item)
1935 1936 1937 1938 1939 1940 1941 1942
{
    libvlc_instance_t* p_libvlc;
    HRESULT hr = _p_instance->getVLC(&p_libvlc);
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

JP Dinger's avatar
JP Dinger committed
1943
        _p_instance->playlist_delete_item(item, &ex);
1944
        hr = exception_bridge(&ex);;
1945 1946 1947 1948
    }
    return hr;
};

1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962
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;
};

1963 1964
/*******************************************************************************/

1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 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 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054
VLCSubtitle::~VLCSubtitle()
{
    if( _p_typeinfo )
        _p_typeinfo->Release();
};

HRESULT VLCSubtitle::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_IVLCSubtitle, &_p_typeinfo);
            if( FAILED(hr) )
            {
                _p_typeinfo = NULL;
            }
            p_typelib->Release();
        }
    }
    return hr;
};

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

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

    return NOERROR;
};

STDMETHODIMP VLCSubtitle::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;
};

STDMETHODIMP VLCSubtitle::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
        UINT cNames, LCID lcid, DISPID* rgDispID)
{
    if( SUCCEEDED(loadTypeInfo()) )
    {
        return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
    }
    return E_NOTIMPL;
};

STDMETHODIMP VLCSubtitle::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 VLCSubtitle::get_track(long* spu)
{
    if( NULL == spu )
        return E_POINTER;

    libvlc_media_player_t *p_md;
    HRESULT hr = _p_instance->getMD(&p_md);
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

        *spu = libvlc_video_get_spu(p_md, &ex);
2055
        hr = exception_bridge(&ex);
2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069
    }
    return hr;
};

STDMETHODIMP VLCSubtitle::put_track(long spu)
{
    libvlc_media_player_t *p_md;
    HRESULT hr = _p_instance->getMD(&p_md);
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

        libvlc_video_set_spu(p_md, spu, &ex);
2070
        hr = exception_bridge(&ex);
2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087
    }
    return hr;
};

STDMETHODIMP VLCSubtitle::get_count(long* spuNumber)
{
    if( NULL == spuNumber )
        return E_POINTER;

    libvlc_media_player_t *p_md;
    HRESULT hr = _p_instance->getMD(&p_md);
    if( SUCCEEDED(hr) )
    {
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);
        // get the number of video subtitle available and return it
        *spuNumber = libvlc_video_get_spu_count(p_md, &ex);
2088
        hr = exception_bridge(&ex);