Some files have moved
[vlc/vlc-skelet.git] / activex / vlccontrol2.cpp
blob8d45973db4e3b45c9cb6ce31078b1cba42e4f003
1 /*****************************************************************************
2 * vlccontrol2.cpp: ActiveX control for VLC
3 *****************************************************************************
4 * Copyright (C) 2006 the VideoLAN team
6 * Authors: Damien Fouilleul <Damien.Fouilleul@laposte.net>
7 * Jean-Paul Saman <jpsaman _at_ m2x _dot_ nl>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 #include "plugin.h"
25 #include "vlccontrol2.h"
26 #include "vlccontrol.h"
28 #include "utils.h"
30 #include <shlwapi.h>
31 #include <wininet.h>
32 #include <tchar.h>
34 using namespace std;
36 VLCAudio::~VLCAudio()
38 if( _p_typeinfo )
39 _p_typeinfo->Release();
42 HRESULT VLCAudio::loadTypeInfo(void)
44 HRESULT hr = NOERROR;
45 if( NULL == _p_typeinfo )
47 ITypeLib *p_typelib;
49 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
50 if( SUCCEEDED(hr) )
52 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCAudio, &_p_typeinfo);
53 if( FAILED(hr) )
55 _p_typeinfo = NULL;
57 p_typelib->Release();
60 return hr;
63 STDMETHODIMP VLCAudio::GetTypeInfoCount(UINT* pctInfo)
65 if( NULL == pctInfo )
66 return E_INVALIDARG;
68 if( SUCCEEDED(loadTypeInfo()) )
69 *pctInfo = 1;
70 else
71 *pctInfo = 0;
73 return NOERROR;
76 STDMETHODIMP VLCAudio::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
78 if( NULL == ppTInfo )
79 return E_INVALIDARG;
81 if( SUCCEEDED(loadTypeInfo()) )
83 _p_typeinfo->AddRef();
84 *ppTInfo = _p_typeinfo;
85 return NOERROR;
87 *ppTInfo = NULL;
88 return E_NOTIMPL;
91 STDMETHODIMP VLCAudio::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
92 UINT cNames, LCID lcid, DISPID* rgDispID)
94 if( SUCCEEDED(loadTypeInfo()) )
96 return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
98 return E_NOTIMPL;
101 STDMETHODIMP VLCAudio::Invoke(DISPID dispIdMember, REFIID riid,
102 LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
103 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
105 if( SUCCEEDED(loadTypeInfo()) )
107 return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
108 pVarResult, pExcepInfo, puArgErr);
110 return E_NOTIMPL;
113 STDMETHODIMP VLCAudio::get_mute(VARIANT_BOOL* mute)
115 if( NULL == mute )
116 return E_POINTER;
118 libvlc_instance_t* p_libvlc;
119 HRESULT hr = _p_instance->getVLC(&p_libvlc);
120 if( SUCCEEDED(hr) )
122 libvlc_exception_t ex;
123 libvlc_exception_init(&ex);
125 *mute = libvlc_audio_get_mute(p_libvlc, &ex) ? VARIANT_TRUE : VARIANT_FALSE;
126 if( libvlc_exception_raised(&ex) )
128 _p_instance->setErrorInfo(IID_IVLCAudio, libvlc_exception_get_message(&ex));
129 libvlc_exception_clear(&ex);
130 return E_FAIL;
132 return NOERROR;
134 return hr;
137 STDMETHODIMP VLCAudio::put_mute(VARIANT_BOOL mute)
139 libvlc_instance_t* p_libvlc;
140 HRESULT hr = _p_instance->getVLC(&p_libvlc);
141 if( SUCCEEDED(hr) )
143 libvlc_exception_t ex;
144 libvlc_exception_init(&ex);
146 libvlc_audio_set_mute(p_libvlc, VARIANT_FALSE != mute, &ex);
147 if( libvlc_exception_raised(&ex) )
149 _p_instance->setErrorInfo(IID_IVLCAudio, libvlc_exception_get_message(&ex));
150 libvlc_exception_clear(&ex);
151 return E_FAIL;
153 return NOERROR;
155 return hr;
158 STDMETHODIMP VLCAudio::get_volume(long* volume)
160 if( NULL == volume )
161 return E_POINTER;
163 libvlc_instance_t* p_libvlc;
164 HRESULT hr = _p_instance->getVLC(&p_libvlc);
165 if( SUCCEEDED(hr) )
167 libvlc_exception_t ex;
168 libvlc_exception_init(&ex);
170 *volume = libvlc_audio_get_volume(p_libvlc, &ex);
171 if( libvlc_exception_raised(&ex) )
173 _p_instance->setErrorInfo(IID_IVLCAudio, libvlc_exception_get_message(&ex));
174 libvlc_exception_clear(&ex);
175 return E_FAIL;
177 return NOERROR;
179 return hr;
182 STDMETHODIMP VLCAudio::put_volume(long volume)
184 libvlc_instance_t* p_libvlc;
185 HRESULT hr = _p_instance->getVLC(&p_libvlc);
186 if( SUCCEEDED(hr) )
188 libvlc_exception_t ex;
189 libvlc_exception_init(&ex);
191 libvlc_audio_set_volume(p_libvlc, volume, &ex);
192 if( libvlc_exception_raised(&ex) )
194 _p_instance->setErrorInfo(IID_IVLCAudio,
195 libvlc_exception_get_message(&ex));
196 libvlc_exception_clear(&ex);
197 return E_FAIL;
199 return NOERROR;
201 return hr;
204 STDMETHODIMP VLCAudio::get_track(long* track)
206 if( NULL == track )
207 return E_POINTER;
209 libvlc_instance_t* p_libvlc;
210 HRESULT hr = _p_instance->getVLC(&p_libvlc);
211 if( SUCCEEDED(hr) )
213 libvlc_exception_t ex;
214 libvlc_exception_init(&ex);
216 libvlc_media_instance_t *p_md = libvlc_playlist_get_media_instance(p_libvlc, &ex);
217 *track = libvlc_audio_get_track(p_md, &ex);
218 libvlc_media_instance_release(p_md);
219 if( libvlc_exception_raised(&ex) )
221 _p_instance->setErrorInfo(IID_IVLCAudio,
222 libvlc_exception_get_message(&ex));
223 libvlc_exception_clear(&ex);
224 return E_FAIL;
226 return NOERROR;
228 return hr;
231 STDMETHODIMP VLCAudio::put_track(long track)
233 libvlc_instance_t* p_libvlc;
234 HRESULT hr = _p_instance->getVLC(&p_libvlc);
235 if( SUCCEEDED(hr) )
237 libvlc_exception_t ex;
238 libvlc_exception_init(&ex);
240 libvlc_media_instance_t *p_md = libvlc_playlist_get_media_instance(p_libvlc, &ex);
241 libvlc_audio_set_track(p_md, track, &ex);
242 libvlc_media_instance_release(p_md);
243 if( libvlc_exception_raised(&ex) )
245 _p_instance->setErrorInfo(IID_IVLCAudio,
246 libvlc_exception_get_message(&ex));
247 libvlc_exception_clear(&ex);
248 return E_FAIL;
250 return NOERROR;
252 return hr;
255 STDMETHODIMP VLCAudio::get_channel(long *channel)
257 if( NULL == channel )
258 return E_POINTER;
260 libvlc_instance_t* p_libvlc;
261 HRESULT hr = _p_instance->getVLC(&p_libvlc);
262 if( SUCCEEDED(hr) )
264 libvlc_exception_t ex;
265 libvlc_exception_init(&ex);
267 *channel = libvlc_audio_get_channel(p_libvlc, &ex);
268 if( libvlc_exception_raised(&ex) )
270 _p_instance->setErrorInfo(IID_IVLCAudio,
271 libvlc_exception_get_message(&ex));
272 libvlc_exception_clear(&ex);
273 return E_FAIL;
275 return NOERROR;
277 return hr;
280 STDMETHODIMP VLCAudio::put_channel(long channel)
282 libvlc_instance_t* p_libvlc;
283 HRESULT hr = _p_instance->getVLC(&p_libvlc);
284 if( SUCCEEDED(hr) )
286 libvlc_exception_t ex;
287 libvlc_exception_init(&ex);
289 libvlc_audio_set_channel(p_libvlc, channel, &ex);
290 if( libvlc_exception_raised(&ex) )
292 _p_instance->setErrorInfo(IID_IVLCAudio,
293 libvlc_exception_get_message(&ex));
294 libvlc_exception_clear(&ex);
295 return E_FAIL;
297 return NOERROR;
299 return hr;
302 STDMETHODIMP VLCAudio::toggleMute()
304 libvlc_instance_t* p_libvlc;
305 HRESULT hr = _p_instance->getVLC(&p_libvlc);
306 if( SUCCEEDED(hr) )
308 libvlc_exception_t ex;
309 libvlc_exception_init(&ex);
311 libvlc_audio_toggle_mute(p_libvlc, &ex);
312 if( libvlc_exception_raised(&ex) )
314 _p_instance->setErrorInfo(IID_IVLCAudio,
315 libvlc_exception_get_message(&ex));
316 libvlc_exception_clear(&ex);
317 return E_FAIL;
319 return NOERROR;
321 return hr;
324 /*******************************************************************************/
326 VLCInput::~VLCInput()
328 if( _p_typeinfo )
329 _p_typeinfo->Release();
332 HRESULT VLCInput::loadTypeInfo(void)
334 HRESULT hr = NOERROR;
335 if( NULL == _p_typeinfo )
337 ITypeLib *p_typelib;
339 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
340 if( SUCCEEDED(hr) )
342 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCInput, &_p_typeinfo);
343 if( FAILED(hr) )
345 _p_typeinfo = NULL;
347 p_typelib->Release();
350 return hr;
353 STDMETHODIMP VLCInput::GetTypeInfoCount(UINT* pctInfo)
355 if( NULL == pctInfo )
356 return E_INVALIDARG;
358 if( SUCCEEDED(loadTypeInfo()) )
359 *pctInfo = 1;
360 else
361 *pctInfo = 0;
363 return NOERROR;
366 STDMETHODIMP VLCInput::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
368 if( NULL == ppTInfo )
369 return E_INVALIDARG;
371 if( SUCCEEDED(loadTypeInfo()) )
373 _p_typeinfo->AddRef();
374 *ppTInfo = _p_typeinfo;
375 return NOERROR;
377 *ppTInfo = NULL;
378 return E_NOTIMPL;
381 STDMETHODIMP VLCInput::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
382 UINT cNames, LCID lcid, DISPID* rgDispID)
384 if( SUCCEEDED(loadTypeInfo()) )
386 return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
388 return E_NOTIMPL;
391 STDMETHODIMP VLCInput::Invoke(DISPID dispIdMember, REFIID riid,
392 LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
393 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
395 if( SUCCEEDED(loadTypeInfo()) )
397 return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
398 pVarResult, pExcepInfo, puArgErr);
400 return E_NOTIMPL;
403 STDMETHODIMP VLCInput::get_length(double* length)
405 if( NULL == length )
406 return E_POINTER;
408 libvlc_instance_t* p_libvlc;
409 HRESULT hr = _p_instance->getVLC(&p_libvlc);
410 if( SUCCEEDED(hr) )
412 libvlc_exception_t ex;
413 libvlc_exception_init(&ex);
415 libvlc_media_instance_t *p_md = libvlc_playlist_get_media_instance(p_libvlc, &ex);
416 if( ! libvlc_exception_raised(&ex) )
418 *length = (double)libvlc_media_instance_get_length(p_md, &ex);
419 libvlc_media_instance_release(p_md);
420 if( ! libvlc_exception_raised(&ex) )
422 return NOERROR;
425 _p_instance->setErrorInfo(IID_IVLCInput, libvlc_exception_get_message(&ex));
426 libvlc_exception_clear(&ex);
427 return E_FAIL;
429 return hr;
432 STDMETHODIMP VLCInput::get_position(double* position)
434 if( NULL == position )
435 return E_POINTER;
437 libvlc_instance_t* p_libvlc;
438 HRESULT hr = _p_instance->getVLC(&p_libvlc);
439 if( SUCCEEDED(hr) )
441 libvlc_exception_t ex;
442 libvlc_exception_init(&ex);
444 libvlc_media_instance_t *p_md = libvlc_playlist_get_media_instance(p_libvlc, &ex);
445 if( ! libvlc_exception_raised(&ex) )
447 *position = libvlc_media_instance_get_position(p_md, &ex);
448 libvlc_media_instance_release(p_md);
449 if( ! libvlc_exception_raised(&ex) )
451 return NOERROR;
454 _p_instance->setErrorInfo(IID_IVLCInput, libvlc_exception_get_message(&ex));
455 libvlc_exception_clear(&ex);
456 return E_FAIL;
458 return hr;
461 STDMETHODIMP VLCInput::put_position(double position)
463 libvlc_instance_t* p_libvlc;
464 HRESULT hr = _p_instance->getVLC(&p_libvlc);
465 if( SUCCEEDED(hr) )
467 libvlc_exception_t ex;
468 libvlc_exception_init(&ex);
470 libvlc_media_instance_t *p_md = libvlc_playlist_get_media_instance(p_libvlc, &ex);
471 if( ! libvlc_exception_raised(&ex) )
473 libvlc_media_instance_set_position(p_md, position, &ex);
474 libvlc_media_instance_release(p_md);
475 if( ! libvlc_exception_raised(&ex) )
477 return NOERROR;
480 _p_instance->setErrorInfo(IID_IVLCInput, libvlc_exception_get_message(&ex));
481 libvlc_exception_clear(&ex);
482 return E_FAIL;
484 return hr;
487 STDMETHODIMP VLCInput::get_time(double* time)
489 if( NULL == time )
490 return E_POINTER;
492 libvlc_instance_t* p_libvlc;
493 HRESULT hr = _p_instance->getVLC(&p_libvlc);
494 if( SUCCEEDED(hr) )
496 libvlc_exception_t ex;
497 libvlc_exception_init(&ex);
499 libvlc_media_instance_t *p_md = libvlc_playlist_get_media_instance(p_libvlc, &ex);
500 if( ! libvlc_exception_raised(&ex) )
502 *time = (double)libvlc_media_instance_get_time(p_md, &ex);
503 libvlc_media_instance_release(p_md);
504 if( ! libvlc_exception_raised(&ex) )
506 return NOERROR;
509 _p_instance->setErrorInfo(IID_IVLCInput, libvlc_exception_get_message(&ex));
510 libvlc_exception_clear(&ex);
511 return E_FAIL;
513 return hr;
516 STDMETHODIMP VLCInput::put_time(double time)
518 libvlc_instance_t* p_libvlc;
519 HRESULT hr = _p_instance->getVLC(&p_libvlc);
520 if( SUCCEEDED(hr) )
522 libvlc_exception_t ex;
523 libvlc_exception_init(&ex);
525 libvlc_media_instance_t *p_md = libvlc_playlist_get_media_instance(p_libvlc, &ex);
526 if( ! libvlc_exception_raised(&ex) )
528 libvlc_media_instance_set_time(p_md, (vlc_int64_t)time, &ex);
529 libvlc_media_instance_release(p_md);
530 if( ! libvlc_exception_raised(&ex) )
532 return NOERROR;
535 _p_instance->setErrorInfo(IID_IVLCInput, libvlc_exception_get_message(&ex));
536 libvlc_exception_clear(&ex);
537 return E_FAIL;
539 return hr;
542 STDMETHODIMP VLCInput::get_state(long* state)
544 if( NULL == state )
545 return E_POINTER;
547 libvlc_instance_t* p_libvlc;
548 HRESULT hr = _p_instance->getVLC(&p_libvlc);
549 if( SUCCEEDED(hr) )
551 libvlc_exception_t ex;
552 libvlc_exception_init(&ex);
554 libvlc_media_instance_t *p_md = libvlc_playlist_get_media_instance(p_libvlc, &ex);
555 if( ! libvlc_exception_raised(&ex) )
557 *state = libvlc_media_instance_get_state(p_md, &ex);
558 libvlc_media_instance_release(p_md);
559 if( ! libvlc_exception_raised(&ex) )
561 return NOERROR;
564 libvlc_exception_clear(&ex);
565 // don't fail, just return the idle state
566 *state = 0;
567 return NOERROR;
569 return hr;
572 STDMETHODIMP VLCInput::get_rate(double* rate)
574 if( NULL == rate )
575 return E_POINTER;
577 libvlc_instance_t* p_libvlc;
578 HRESULT hr = _p_instance->getVLC(&p_libvlc);
579 if( SUCCEEDED(hr) )
581 libvlc_exception_t ex;
582 libvlc_exception_init(&ex);
584 libvlc_media_instance_t *p_md = libvlc_playlist_get_media_instance(p_libvlc, &ex);
585 if( ! libvlc_exception_raised(&ex) )
587 *rate = libvlc_media_instance_get_rate(p_md, &ex);
588 libvlc_media_instance_release(p_md);
589 if( ! libvlc_exception_raised(&ex) )
591 return NOERROR;
594 _p_instance->setErrorInfo(IID_IVLCInput, libvlc_exception_get_message(&ex));
595 libvlc_exception_clear(&ex);
596 return E_FAIL;
598 return hr;
601 STDMETHODIMP VLCInput::put_rate(double rate)
603 libvlc_instance_t* p_libvlc;
604 HRESULT hr = _p_instance->getVLC(&p_libvlc);
605 if( SUCCEEDED(hr) )
607 libvlc_exception_t ex;
608 libvlc_exception_init(&ex);
610 libvlc_media_instance_t *p_md = libvlc_playlist_get_media_instance(p_libvlc, &ex);
611 if( ! libvlc_exception_raised(&ex) )
613 libvlc_media_instance_set_rate(p_md, rate, &ex);
614 libvlc_media_instance_release(p_md);
615 if( ! libvlc_exception_raised(&ex) )
617 return NOERROR;
620 _p_instance->setErrorInfo(IID_IVLCInput, libvlc_exception_get_message(&ex));
621 libvlc_exception_clear(&ex);
622 return E_FAIL;
624 return hr;
627 STDMETHODIMP VLCInput::get_fps(double* fps)
629 if( NULL == fps )
630 return E_POINTER;
632 *fps = 0.0;
633 libvlc_instance_t* p_libvlc;
634 HRESULT hr = _p_instance->getVLC(&p_libvlc);
635 if( SUCCEEDED(hr) )
637 libvlc_exception_t ex;
638 libvlc_exception_init(&ex);
640 libvlc_media_instance_t *p_md = libvlc_playlist_get_media_instance(p_libvlc, &ex);
641 if( ! libvlc_exception_raised(&ex) )
643 *fps = libvlc_media_instance_get_fps(p_md, &ex);
644 libvlc_media_instance_release(p_md);
645 if( ! libvlc_exception_raised(&ex) )
647 return NOERROR;
650 _p_instance->setErrorInfo(IID_IVLCInput, libvlc_exception_get_message(&ex));
651 libvlc_exception_clear(&ex);
652 return E_FAIL;
654 return hr;
657 STDMETHODIMP VLCInput::get_hasVout(VARIANT_BOOL* hasVout)
659 if( NULL == hasVout )
660 return E_POINTER;
662 libvlc_instance_t* p_libvlc;
663 HRESULT hr = _p_instance->getVLC(&p_libvlc);
664 if( SUCCEEDED(hr) )
666 libvlc_exception_t ex;
667 libvlc_exception_init(&ex);
669 libvlc_media_instance_t *p_md = libvlc_playlist_get_media_instance(p_libvlc, &ex);
670 if( ! libvlc_exception_raised(&ex) )
672 *hasVout = libvlc_media_instance_has_vout(p_md, &ex) ? VARIANT_TRUE : VARIANT_FALSE;
673 libvlc_media_instance_release(p_md);
674 if( ! libvlc_exception_raised(&ex) )
676 return NOERROR;
679 _p_instance->setErrorInfo(IID_IVLCInput, libvlc_exception_get_message(&ex));
680 libvlc_exception_clear(&ex);
681 return E_FAIL;
683 return hr;
686 /*******************************************************************************/
688 VLCLog::~VLCLog()
690 delete _p_vlcmessages;
691 if( _p_log )
692 libvlc_log_close(_p_log, NULL);
694 if( _p_typeinfo )
695 _p_typeinfo->Release();
698 HRESULT VLCLog::loadTypeInfo(void)
700 HRESULT hr = NOERROR;
701 if( NULL == _p_typeinfo )
703 ITypeLib *p_typelib;
705 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
706 if( SUCCEEDED(hr) )
708 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCLog, &_p_typeinfo);
709 if( FAILED(hr) )
711 _p_typeinfo = NULL;
713 p_typelib->Release();
716 return hr;
719 STDMETHODIMP VLCLog::GetTypeInfoCount(UINT* pctInfo)
721 if( NULL == pctInfo )
722 return E_INVALIDARG;
724 if( SUCCEEDED(loadTypeInfo()) )
725 *pctInfo = 1;
726 else
727 *pctInfo = 0;
729 return NOERROR;
732 STDMETHODIMP VLCLog::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
734 if( NULL == ppTInfo )
735 return E_INVALIDARG;
737 if( SUCCEEDED(loadTypeInfo()) )
739 _p_typeinfo->AddRef();
740 *ppTInfo = _p_typeinfo;
741 return NOERROR;
743 *ppTInfo = NULL;
744 return E_NOTIMPL;
747 STDMETHODIMP VLCLog::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
748 UINT cNames, LCID lcid, DISPID* rgDispID)
750 if( SUCCEEDED(loadTypeInfo()) )
752 return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
754 return E_NOTIMPL;
757 STDMETHODIMP VLCLog::Invoke(DISPID dispIdMember, REFIID riid,
758 LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
759 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
761 if( SUCCEEDED(loadTypeInfo()) )
763 return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
764 pVarResult, pExcepInfo, puArgErr);
766 return E_NOTIMPL;
769 STDMETHODIMP VLCLog::get_messages(IVLCMessages** obj)
771 if( NULL == obj )
772 return E_POINTER;
774 *obj = _p_vlcmessages;
775 if( NULL != _p_vlcmessages )
777 _p_vlcmessages->AddRef();
778 return NOERROR;
780 return E_OUTOFMEMORY;
783 STDMETHODIMP VLCLog::get_verbosity(long* level)
785 if( NULL == level )
786 return E_POINTER;
788 if( _p_log )
790 libvlc_instance_t* p_libvlc;
791 HRESULT hr = _p_instance->getVLC(&p_libvlc);
792 if( SUCCEEDED(hr) )
794 libvlc_exception_t ex;
795 libvlc_exception_init(&ex);
797 *level = libvlc_get_log_verbosity(p_libvlc, &ex);
798 if( libvlc_exception_raised(&ex) )
800 _p_instance->setErrorInfo(IID_IVLCLog, libvlc_exception_get_message(&ex));
801 libvlc_exception_clear(&ex);
802 return E_FAIL;
805 return hr;
807 else
809 /* log is not enabled, return -1 */
810 *level = -1;
811 return NOERROR;
815 STDMETHODIMP VLCLog::put_verbosity(long verbosity)
817 libvlc_exception_t ex;
818 libvlc_exception_init(&ex);
820 libvlc_instance_t* p_libvlc;
821 HRESULT hr = _p_instance->getVLC(&p_libvlc);
822 if( SUCCEEDED(hr) )
824 if( verbosity >= 0 )
826 if( ! _p_log )
828 _p_log = libvlc_log_open(p_libvlc, &ex);
829 if( libvlc_exception_raised(&ex) )
831 _p_instance->setErrorInfo(IID_IVLCLog, libvlc_exception_get_message(&ex));
832 libvlc_exception_clear(&ex);
833 return E_FAIL;
836 libvlc_set_log_verbosity(p_libvlc, (unsigned)verbosity, &ex);
837 if( libvlc_exception_raised(&ex) )
839 _p_instance->setErrorInfo(IID_IVLCLog, libvlc_exception_get_message(&ex));
840 libvlc_exception_clear(&ex);
841 return E_FAIL;
844 else if( _p_log )
846 /* close log when verbosity is set to -1 */
847 libvlc_log_close(_p_log, &ex);
848 _p_log = NULL;
849 if( libvlc_exception_raised(&ex) )
851 _p_instance->setErrorInfo(IID_IVLCLog, libvlc_exception_get_message(&ex));
852 libvlc_exception_clear(&ex);
853 return E_FAIL;
857 return hr;
860 /*******************************************************************************/
862 /* STL forward iterator used by VLCEnumIterator class to implement IEnumVARIANT */
864 class VLCMessageSTLIterator
867 public:
869 VLCMessageSTLIterator(IVLCMessageIterator* iter) : iter(iter), msg(NULL)
871 // get first message
872 operator++();
875 VLCMessageSTLIterator(const VLCMessageSTLIterator& other)
877 iter = other.iter;
878 if( iter )
879 iter->AddRef();
880 msg = other.msg;
881 if( msg )
882 msg->AddRef();
885 virtual ~VLCMessageSTLIterator()
887 if( msg )
888 msg->Release();
890 if( iter )
891 iter->Release();
894 // we only need prefix ++ operator
895 VLCMessageSTLIterator& operator++()
897 VARIANT_BOOL hasNext = VARIANT_FALSE;
898 if( iter )
900 iter->get_hasNext(&hasNext);
902 if( msg )
904 msg->Release();
905 msg = NULL;
907 if( VARIANT_TRUE == hasNext ) {
908 iter->next(&msg);
911 return *this;
914 VARIANT operator*() const
916 VARIANT v;
917 VariantInit(&v);
918 if( msg )
920 if( SUCCEEDED(msg->QueryInterface(IID_IDispatch, (LPVOID*)&V_DISPATCH(&v))) )
922 V_VT(&v) = VT_DISPATCH;
925 return v;
928 bool operator==(const VLCMessageSTLIterator& other) const
930 return msg == other.msg;
933 bool operator!=(const VLCMessageSTLIterator& other) const
935 return msg != other.msg;
938 private:
939 IVLCMessageIterator* iter;
940 IVLCMessage* msg;
943 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
945 VLCMessages::~VLCMessages()
947 if( _p_typeinfo )
948 _p_typeinfo->Release();
951 HRESULT VLCMessages::loadTypeInfo(void)
953 HRESULT hr = NOERROR;
954 if( NULL == _p_typeinfo )
956 ITypeLib *p_typelib;
958 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
959 if( SUCCEEDED(hr) )
961 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCMessages, &_p_typeinfo);
962 if( FAILED(hr) )
964 _p_typeinfo = NULL;
966 p_typelib->Release();
969 return hr;
972 STDMETHODIMP VLCMessages::GetTypeInfoCount(UINT* pctInfo)
974 if( NULL == pctInfo )
975 return E_INVALIDARG;
977 if( SUCCEEDED(loadTypeInfo()) )
978 *pctInfo = 1;
979 else
980 *pctInfo = 0;
982 return NOERROR;
985 STDMETHODIMP VLCMessages::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
987 if( NULL == ppTInfo )
988 return E_INVALIDARG;
990 if( SUCCEEDED(loadTypeInfo()) )
992 _p_typeinfo->AddRef();
993 *ppTInfo = _p_typeinfo;
994 return NOERROR;
996 *ppTInfo = NULL;
997 return E_NOTIMPL;
1000 STDMETHODIMP VLCMessages::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
1001 UINT cNames, LCID lcid, DISPID* rgDispID)
1003 if( SUCCEEDED(loadTypeInfo()) )
1005 return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
1007 return E_NOTIMPL;
1010 STDMETHODIMP VLCMessages::Invoke(DISPID dispIdMember, REFIID riid,
1011 LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
1012 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
1014 if( SUCCEEDED(loadTypeInfo()) )
1016 return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
1017 pVarResult, pExcepInfo, puArgErr);
1019 return E_NOTIMPL;
1022 STDMETHODIMP VLCMessages::get__NewEnum(LPUNKNOWN* _NewEnum)
1024 if( NULL == _NewEnum )
1025 return E_POINTER;
1027 IVLCMessageIterator* iter = NULL;
1028 iterator(&iter);
1030 *_NewEnum= new VLCEnumIterator<IID_IEnumVARIANT,
1031 IEnumVARIANT,
1032 VARIANT,
1033 VLCMessageSTLIterator>
1034 (VLCMessageSTLIterator(iter), VLCMessageSTLIterator(NULL));
1036 return *_NewEnum ? S_OK : E_OUTOFMEMORY;
1039 STDMETHODIMP VLCMessages::clear()
1041 libvlc_log_t *p_log = _p_vlclog->_p_log;
1042 if( p_log )
1044 libvlc_exception_t ex;
1045 libvlc_exception_init(&ex);
1047 libvlc_log_clear(p_log, &ex);
1048 if( libvlc_exception_raised(&ex) )
1050 _p_instance->setErrorInfo(IID_IVLCMessages, libvlc_exception_get_message(&ex));
1051 libvlc_exception_clear(&ex);
1052 return E_FAIL;
1055 return NOERROR;
1058 STDMETHODIMP VLCMessages::get_count(long* count)
1060 if( NULL == count )
1061 return E_POINTER;
1063 libvlc_log_t *p_log = _p_vlclog->_p_log;
1064 if( p_log )
1066 libvlc_exception_t ex;
1067 libvlc_exception_init(&ex);
1069 *count = libvlc_log_count(p_log, &ex);
1070 if( libvlc_exception_raised(&ex) )
1072 _p_instance->setErrorInfo(IID_IVLCMessages, libvlc_exception_get_message(&ex));
1073 libvlc_exception_clear(&ex);
1074 return E_FAIL;
1077 else
1078 *count = 0;
1079 return S_OK;
1082 STDMETHODIMP VLCMessages::iterator(IVLCMessageIterator** iter)
1084 if( NULL == iter )
1085 return E_POINTER;
1087 *iter = new VLCMessageIterator(_p_instance, _p_vlclog);
1089 return *iter ? S_OK : E_OUTOFMEMORY;
1092 /*******************************************************************************/
1094 VLCMessageIterator::VLCMessageIterator(VLCPlugin *p_instance, VLCLog* p_vlclog ) :
1095 _p_instance(p_instance),
1096 _p_typeinfo(NULL),
1097 _refcount(1),
1098 _p_vlclog(p_vlclog)
1100 if( p_vlclog->_p_log )
1102 _p_iter = libvlc_log_get_iterator(p_vlclog->_p_log, NULL);
1104 else
1105 _p_iter = NULL;
1108 VLCMessageIterator::~VLCMessageIterator()
1110 if( _p_iter )
1111 libvlc_log_iterator_free(_p_iter, NULL);
1113 if( _p_typeinfo )
1114 _p_typeinfo->Release();
1117 HRESULT VLCMessageIterator::loadTypeInfo(void)
1119 HRESULT hr = NOERROR;
1120 if( NULL == _p_typeinfo )
1122 ITypeLib *p_typelib;
1124 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
1125 if( SUCCEEDED(hr) )
1127 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCMessageIterator, &_p_typeinfo);
1128 if( FAILED(hr) )
1130 _p_typeinfo = NULL;
1132 p_typelib->Release();
1135 return hr;
1138 STDMETHODIMP VLCMessageIterator::GetTypeInfoCount(UINT* pctInfo)
1140 if( NULL == pctInfo )
1141 return E_INVALIDARG;
1143 if( SUCCEEDED(loadTypeInfo()) )
1144 *pctInfo = 1;
1145 else
1146 *pctInfo = 0;
1148 return NOERROR;
1151 STDMETHODIMP VLCMessageIterator::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
1153 if( NULL == ppTInfo )
1154 return E_INVALIDARG;
1156 if( SUCCEEDED(loadTypeInfo()) )
1158 _p_typeinfo->AddRef();
1159 *ppTInfo = _p_typeinfo;
1160 return NOERROR;
1162 *ppTInfo = NULL;
1163 return E_NOTIMPL;
1166 STDMETHODIMP VLCMessageIterator::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
1167 UINT cNames, LCID lcid, DISPID* rgDispID)
1169 if( SUCCEEDED(loadTypeInfo()) )
1171 return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
1173 return E_NOTIMPL;
1176 STDMETHODIMP VLCMessageIterator::Invoke(DISPID dispIdMember, REFIID riid,
1177 LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
1178 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
1180 if( SUCCEEDED(loadTypeInfo()) )
1182 return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
1183 pVarResult, pExcepInfo, puArgErr);
1185 return E_NOTIMPL;
1188 STDMETHODIMP VLCMessageIterator::get_hasNext(VARIANT_BOOL* hasNext)
1190 if( NULL == hasNext )
1191 return E_POINTER;
1193 if( _p_iter && _p_vlclog->_p_log )
1195 libvlc_exception_t ex;
1196 libvlc_exception_init(&ex);
1198 *hasNext = libvlc_log_iterator_has_next(_p_iter, &ex) ? VARIANT_TRUE : VARIANT_FALSE;
1199 if( libvlc_exception_raised(&ex) )
1201 _p_instance->setErrorInfo(IID_IVLCMessageIterator, libvlc_exception_get_message(&ex));
1202 libvlc_exception_clear(&ex);
1203 return E_FAIL;
1206 else
1208 *hasNext = VARIANT_FALSE;
1210 return S_OK;
1213 STDMETHODIMP VLCMessageIterator::next(IVLCMessage** message)
1215 if( NULL == message )
1216 return E_POINTER;
1218 if( _p_iter && _p_vlclog->_p_log )
1220 struct libvlc_log_message_t buffer;
1222 buffer.sizeof_msg = sizeof(buffer);
1224 libvlc_exception_t ex;
1225 libvlc_exception_init(&ex);
1227 libvlc_log_iterator_next(_p_iter, &buffer, &ex);
1228 if( libvlc_exception_raised(&ex) )
1230 _p_instance->setErrorInfo(IID_IVLCMessageIterator, libvlc_exception_get_message(&ex));
1231 libvlc_exception_clear(&ex);
1232 return E_FAIL;
1234 *message = new VLCMessage(_p_instance, buffer);
1235 return *message ? NOERROR : E_OUTOFMEMORY;
1237 return E_FAIL;
1240 /*******************************************************************************/
1242 VLCMessage::~VLCMessage()
1244 if( _p_typeinfo )
1245 _p_typeinfo->Release();
1248 HRESULT VLCMessage::loadTypeInfo(void)
1250 HRESULT hr = NOERROR;
1251 if( NULL == _p_typeinfo )
1253 ITypeLib *p_typelib;
1255 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
1256 if( SUCCEEDED(hr) )
1258 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCMessage, &_p_typeinfo);
1259 if( FAILED(hr) )
1261 _p_typeinfo = NULL;
1263 p_typelib->Release();
1266 return hr;
1269 STDMETHODIMP VLCMessage::GetTypeInfoCount(UINT* pctInfo)
1271 if( NULL == pctInfo )
1272 return E_INVALIDARG;
1274 if( SUCCEEDED(loadTypeInfo()) )
1275 *pctInfo = 1;
1276 else
1277 *pctInfo = 0;
1279 return NOERROR;
1282 STDMETHODIMP VLCMessage::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
1284 if( NULL == ppTInfo )
1285 return E_INVALIDARG;
1287 if( SUCCEEDED(loadTypeInfo()) )
1289 _p_typeinfo->AddRef();
1290 *ppTInfo = _p_typeinfo;
1291 return NOERROR;
1293 *ppTInfo = NULL;
1294 return E_NOTIMPL;
1297 STDMETHODIMP VLCMessage::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
1298 UINT cNames, LCID lcid, DISPID* rgDispID)
1300 if( SUCCEEDED(loadTypeInfo()) )
1302 return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
1304 return E_NOTIMPL;
1307 STDMETHODIMP VLCMessage::Invoke(DISPID dispIdMember, REFIID riid,
1308 LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
1309 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
1311 if( SUCCEEDED(loadTypeInfo()) )
1313 return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
1314 pVarResult, pExcepInfo, puArgErr);
1316 return E_NOTIMPL;
1319 inline const char *msgSeverity(int sev)
1321 switch( sev )
1323 case 0:
1324 return "info";
1325 case 1:
1326 return "error";
1327 case 2:
1328 return "warning";
1329 default:
1330 return "debug";
1334 STDMETHODIMP VLCMessage::get__Value(VARIANT* _Value)
1336 if( NULL == _Value )
1337 return E_POINTER;
1339 char buffer[256];
1341 snprintf(buffer, sizeof(buffer), "%s %s %s: %s",
1342 _msg.psz_type, _msg.psz_name, msgSeverity(_msg.i_severity), _msg.psz_message);
1344 V_VT(_Value) = VT_BSTR;
1345 V_BSTR(_Value) = BSTRFromCStr(CP_UTF8, buffer);
1347 return S_OK;
1350 STDMETHODIMP VLCMessage::get_severity(long* level)
1352 if( NULL == level )
1353 return E_POINTER;
1355 *level = _msg.i_severity;
1357 return S_OK;
1360 STDMETHODIMP VLCMessage::get_type(BSTR* type)
1362 if( NULL == type )
1363 return E_POINTER;
1365 *type = BSTRFromCStr(CP_UTF8, _msg.psz_type);
1367 return NOERROR;
1370 STDMETHODIMP VLCMessage::get_name(BSTR* name)
1372 if( NULL == name )
1373 return E_POINTER;
1375 *name = BSTRFromCStr(CP_UTF8, _msg.psz_name);
1377 return NOERROR;
1380 STDMETHODIMP VLCMessage::get_header(BSTR* header)
1382 if( NULL == header )
1383 return E_POINTER;
1385 *header = BSTRFromCStr(CP_UTF8, _msg.psz_header);
1387 return NOERROR;
1390 STDMETHODIMP VLCMessage::get_message(BSTR* message)
1392 if( NULL == message )
1393 return E_POINTER;
1395 *message = BSTRFromCStr(CP_UTF8, _msg.psz_message);
1397 return NOERROR;
1400 /*******************************************************************************/
1402 VLCPlaylistItems::~VLCPlaylistItems()
1404 if( _p_typeinfo )
1405 _p_typeinfo->Release();
1408 HRESULT VLCPlaylistItems::loadTypeInfo(void)
1410 HRESULT hr = NOERROR;
1411 if( NULL == _p_typeinfo )
1413 ITypeLib *p_typelib;
1415 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
1416 if( SUCCEEDED(hr) )
1418 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCPlaylistItems, &_p_typeinfo);
1419 if( FAILED(hr) )
1421 _p_typeinfo = NULL;
1423 p_typelib->Release();
1426 return hr;
1429 STDMETHODIMP VLCPlaylistItems::GetTypeInfoCount(UINT* pctInfo)
1431 if( NULL == pctInfo )
1432 return E_INVALIDARG;
1434 if( SUCCEEDED(loadTypeInfo()) )
1435 *pctInfo = 1;
1436 else
1437 *pctInfo = 0;
1439 return NOERROR;
1442 STDMETHODIMP VLCPlaylistItems::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
1444 if( NULL == ppTInfo )
1445 return E_INVALIDARG;
1447 if( SUCCEEDED(loadTypeInfo()) )
1449 _p_typeinfo->AddRef();
1450 *ppTInfo = _p_typeinfo;
1451 return NOERROR;
1453 *ppTInfo = NULL;
1454 return E_NOTIMPL;
1457 STDMETHODIMP VLCPlaylistItems::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
1458 UINT cNames, LCID lcid, DISPID* rgDispID)
1460 if( SUCCEEDED(loadTypeInfo()) )
1462 return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
1464 return E_NOTIMPL;
1467 STDMETHODIMP VLCPlaylistItems::Invoke(DISPID dispIdMember, REFIID riid,
1468 LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
1469 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
1471 if( SUCCEEDED(loadTypeInfo()) )
1473 return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
1474 pVarResult, pExcepInfo, puArgErr);
1476 return E_NOTIMPL;
1479 STDMETHODIMP VLCPlaylistItems::get_count(long* count)
1481 if( NULL == count )
1482 return E_POINTER;
1484 libvlc_instance_t* p_libvlc;
1485 HRESULT hr = _p_instance->getVLC(&p_libvlc);
1486 if( SUCCEEDED(hr) )
1488 libvlc_exception_t ex;
1489 libvlc_exception_init(&ex);
1491 *count = libvlc_playlist_items_count(p_libvlc, &ex);
1492 if( libvlc_exception_raised(&ex) )
1494 _p_instance->setErrorInfo(IID_IVLCPlaylistItems,
1495 libvlc_exception_get_message(&ex));
1496 libvlc_exception_clear(&ex);
1497 return E_FAIL;
1499 return NOERROR;
1501 return hr;
1504 STDMETHODIMP VLCPlaylistItems::clear()
1506 libvlc_instance_t* p_libvlc;
1507 HRESULT hr = _p_instance->getVLC(&p_libvlc);
1508 if( SUCCEEDED(hr) )
1510 libvlc_exception_t ex;
1511 libvlc_exception_init(&ex);
1513 libvlc_playlist_clear(p_libvlc, &ex);
1514 if( libvlc_exception_raised(&ex) )
1516 _p_instance->setErrorInfo(IID_IVLCPlaylistItems,
1517 libvlc_exception_get_message(&ex));
1518 libvlc_exception_clear(&ex);
1519 return E_FAIL;
1521 return NOERROR;
1523 return hr;
1526 STDMETHODIMP VLCPlaylistItems::remove(long item)
1528 libvlc_instance_t* p_libvlc;
1529 HRESULT hr = _p_instance->getVLC(&p_libvlc);
1530 if( SUCCEEDED(hr) )
1532 libvlc_exception_t ex;
1533 libvlc_exception_init(&ex);
1535 libvlc_playlist_delete_item(p_libvlc, item, &ex);
1536 if( libvlc_exception_raised(&ex) )
1538 _p_instance->setErrorInfo(IID_IVLCPlaylistItems,
1539 libvlc_exception_get_message(&ex));
1540 libvlc_exception_clear(&ex);
1541 return E_FAIL;
1543 return NOERROR;
1545 return hr;
1548 /*******************************************************************************/
1550 VLCPlaylist::~VLCPlaylist()
1552 delete _p_vlcplaylistitems;
1553 if( _p_typeinfo )
1554 _p_typeinfo->Release();
1557 HRESULT VLCPlaylist::loadTypeInfo(void)
1559 HRESULT hr = NOERROR;
1560 if( NULL == _p_typeinfo )
1562 ITypeLib *p_typelib;
1564 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
1565 if( SUCCEEDED(hr) )
1567 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCPlaylist, &_p_typeinfo);
1568 if( FAILED(hr) )
1570 _p_typeinfo = NULL;
1572 p_typelib->Release();
1575 return hr;
1578 STDMETHODIMP VLCPlaylist::GetTypeInfoCount(UINT* pctInfo)
1580 if( NULL == pctInfo )
1581 return E_INVALIDARG;
1583 if( SUCCEEDED(loadTypeInfo()) )
1584 *pctInfo = 1;
1585 else
1586 *pctInfo = 0;
1588 return NOERROR;
1591 STDMETHODIMP VLCPlaylist::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
1593 if( NULL == ppTInfo )
1594 return E_INVALIDARG;
1596 if( SUCCEEDED(loadTypeInfo()) )
1598 _p_typeinfo->AddRef();
1599 *ppTInfo = _p_typeinfo;
1600 return NOERROR;
1602 *ppTInfo = NULL;
1603 return E_NOTIMPL;
1606 STDMETHODIMP VLCPlaylist::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
1607 UINT cNames, LCID lcid, DISPID* rgDispID)
1609 if( SUCCEEDED(loadTypeInfo()) )
1611 return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
1613 return E_NOTIMPL;
1616 STDMETHODIMP VLCPlaylist::Invoke(DISPID dispIdMember, REFIID riid,
1617 LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
1618 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
1620 if( SUCCEEDED(loadTypeInfo()) )
1622 return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
1623 pVarResult, pExcepInfo, puArgErr);
1625 return E_NOTIMPL;
1628 STDMETHODIMP VLCPlaylist::get_itemCount(long* count)
1630 if( NULL == count )
1631 return E_POINTER;
1633 libvlc_instance_t* p_libvlc;
1634 HRESULT hr = _p_instance->getVLC(&p_libvlc);
1635 if( SUCCEEDED(hr) )
1637 libvlc_exception_t ex;
1638 libvlc_exception_init(&ex);
1640 *count = libvlc_playlist_items_count(p_libvlc, &ex);
1641 if( libvlc_exception_raised(&ex) )
1643 _p_instance->setErrorInfo(IID_IVLCPlaylist,
1644 libvlc_exception_get_message(&ex));
1645 libvlc_exception_clear(&ex);
1646 return E_FAIL;
1648 return NOERROR;
1650 return hr;
1653 STDMETHODIMP VLCPlaylist::get_isPlaying(VARIANT_BOOL* isPlaying)
1655 if( NULL == isPlaying )
1656 return E_POINTER;
1658 libvlc_instance_t* p_libvlc;
1659 HRESULT hr = _p_instance->getVLC(&p_libvlc);
1660 if( SUCCEEDED(hr) )
1662 libvlc_exception_t ex;
1663 libvlc_exception_init(&ex);
1665 *isPlaying = libvlc_playlist_isplaying(p_libvlc, &ex) ? VARIANT_TRUE: VARIANT_FALSE;
1666 if( libvlc_exception_raised(&ex) )
1668 _p_instance->setErrorInfo(IID_IVLCPlaylist,
1669 libvlc_exception_get_message(&ex));
1670 libvlc_exception_clear(&ex);
1671 return E_FAIL;
1673 return NOERROR;
1675 return hr;
1678 STDMETHODIMP VLCPlaylist::add(BSTR uri, VARIANT name, VARIANT options, long* item)
1680 if( NULL == item )
1681 return E_POINTER;
1683 if( 0 == SysStringLen(uri) )
1684 return E_INVALIDARG;
1686 libvlc_instance_t* p_libvlc;
1687 HRESULT hr = _p_instance->getVLC(&p_libvlc);
1688 if( SUCCEEDED(hr) )
1690 libvlc_exception_t ex;
1691 libvlc_exception_init(&ex);
1693 char *psz_uri = NULL;
1694 if( SysStringLen(_p_instance->getBaseURL()) > 0 )
1697 ** if the MRL a relative URL, we should end up with an absolute URL
1699 LPWSTR abs_url = CombineURL(_p_instance->getBaseURL(), uri);
1700 if( NULL != abs_url )
1702 psz_uri = CStrFromWSTR(CP_UTF8, abs_url, wcslen(abs_url));
1703 CoTaskMemFree(abs_url);
1705 else
1707 psz_uri = CStrFromBSTR(CP_UTF8, uri);
1710 else
1713 ** baseURL is empty, assume MRL is absolute
1715 psz_uri = CStrFromBSTR(CP_UTF8, uri);
1718 if( NULL == psz_uri )
1720 return E_OUTOFMEMORY;
1723 int i_options;
1724 char **ppsz_options;
1726 hr = VLCControl::CreateTargetOptions(CP_UTF8, &options, &ppsz_options, &i_options);
1727 if( FAILED(hr) )
1729 CoTaskMemFree(psz_uri);
1730 return hr;
1733 char *psz_name = NULL;
1734 VARIANT v_name;
1735 VariantInit(&v_name);
1736 if( SUCCEEDED(VariantChangeType(&v_name, &name, 0, VT_BSTR)) )
1738 if( SysStringLen(V_BSTR(&v_name)) > 0 )
1739 psz_name = CStrFromBSTR(CP_UTF8, V_BSTR(&v_name));
1741 VariantClear(&v_name);
1744 *item = libvlc_playlist_add_extended(p_libvlc,
1745 psz_uri,
1746 psz_name,
1747 i_options,
1748 const_cast<const char **>(ppsz_options),
1749 &ex);
1751 VLCControl::FreeTargetOptions(ppsz_options, i_options);
1752 CoTaskMemFree(psz_uri);
1753 if( psz_name )
1754 CoTaskMemFree(psz_name);
1755 if( libvlc_exception_raised(&ex) )
1757 _p_instance->setErrorInfo(IID_IVLCPlaylist,
1758 libvlc_exception_get_message(&ex));
1759 libvlc_exception_clear(&ex);
1760 return E_FAIL;
1762 return NOERROR;
1764 return hr;
1767 STDMETHODIMP VLCPlaylist::play()
1769 libvlc_instance_t* p_libvlc;
1770 HRESULT hr = _p_instance->getVLC(&p_libvlc);
1771 if( SUCCEEDED(hr) )
1773 libvlc_exception_t ex;
1774 libvlc_exception_init(&ex);
1776 libvlc_playlist_play(p_libvlc, -1, 0, NULL, &ex);
1777 if( libvlc_exception_raised(&ex) )
1779 libvlc_exception_clear(&ex);
1780 return E_FAIL;
1782 return NOERROR;
1784 return hr;
1787 STDMETHODIMP VLCPlaylist::playItem(long item)
1789 libvlc_instance_t* p_libvlc;
1790 HRESULT hr = _p_instance->getVLC(&p_libvlc);
1791 if( SUCCEEDED(hr) )
1793 libvlc_exception_t ex;
1794 libvlc_exception_init(&ex);
1796 libvlc_playlist_play(p_libvlc, item, 0, NULL, &ex);
1797 if( libvlc_exception_raised(&ex) )
1799 _p_instance->setErrorInfo(IID_IVLCPlaylist,
1800 libvlc_exception_get_message(&ex));
1801 libvlc_exception_clear(&ex);
1802 return E_FAIL;
1804 return NOERROR;
1806 return hr;
1809 STDMETHODIMP VLCPlaylist::togglePause()
1811 libvlc_instance_t* p_libvlc;
1812 HRESULT hr = _p_instance->getVLC(&p_libvlc);
1813 if( SUCCEEDED(hr) )
1815 libvlc_exception_t ex;
1816 libvlc_exception_init(&ex);
1818 libvlc_playlist_pause(p_libvlc, &ex);
1819 if( libvlc_exception_raised(&ex) )
1821 _p_instance->setErrorInfo(IID_IVLCPlaylist,
1822 libvlc_exception_get_message(&ex));
1823 libvlc_exception_clear(&ex);
1824 return E_FAIL;
1826 return NOERROR;
1828 return hr;
1831 STDMETHODIMP VLCPlaylist::stop()
1833 libvlc_instance_t* p_libvlc;
1834 HRESULT hr = _p_instance->getVLC(&p_libvlc);
1835 if( SUCCEEDED(hr) )
1837 libvlc_exception_t ex;
1838 libvlc_exception_init(&ex);
1840 libvlc_playlist_stop(p_libvlc, &ex);
1841 if( libvlc_exception_raised(&ex) )
1843 _p_instance->setErrorInfo(IID_IVLCPlaylist,
1844 libvlc_exception_get_message(&ex));
1845 libvlc_exception_clear(&ex);
1846 return E_FAIL;
1848 return NOERROR;
1850 return hr;
1853 STDMETHODIMP VLCPlaylist::next()
1855 libvlc_instance_t* p_libvlc;
1856 HRESULT hr = _p_instance->getVLC(&p_libvlc);
1857 if( SUCCEEDED(hr) )
1859 libvlc_exception_t ex;
1860 libvlc_exception_init(&ex);
1862 libvlc_playlist_next(p_libvlc, &ex);
1863 if( libvlc_exception_raised(&ex) )
1865 _p_instance->setErrorInfo(IID_IVLCPlaylist,
1866 libvlc_exception_get_message(&ex));
1867 libvlc_exception_clear(&ex);
1868 return E_FAIL;
1870 return NOERROR;
1872 return hr;
1875 STDMETHODIMP VLCPlaylist::prev()
1877 libvlc_instance_t* p_libvlc;
1878 HRESULT hr = _p_instance->getVLC(&p_libvlc);
1879 if( SUCCEEDED(hr) )
1881 libvlc_exception_t ex;
1882 libvlc_exception_init(&ex);
1884 libvlc_playlist_prev(p_libvlc, &ex);
1885 if( libvlc_exception_raised(&ex) )
1887 _p_instance->setErrorInfo(IID_IVLCPlaylist,
1888 libvlc_exception_get_message(&ex));
1889 libvlc_exception_clear(&ex);
1890 return E_FAIL;
1892 return NOERROR;
1894 return hr;
1897 STDMETHODIMP VLCPlaylist::clear()
1899 libvlc_instance_t* p_libvlc;
1900 HRESULT hr = _p_instance->getVLC(&p_libvlc);
1901 if( SUCCEEDED(hr) )
1903 libvlc_exception_t ex;
1904 libvlc_exception_init(&ex);
1906 libvlc_playlist_clear(p_libvlc, &ex);
1907 if( libvlc_exception_raised(&ex) )
1909 _p_instance->setErrorInfo(IID_IVLCPlaylist,
1910 libvlc_exception_get_message(&ex));
1911 libvlc_exception_clear(&ex);
1912 return E_FAIL;
1914 return NOERROR;
1916 return hr;
1919 STDMETHODIMP VLCPlaylist::removeItem(long item)
1921 libvlc_instance_t* p_libvlc;
1922 HRESULT hr = _p_instance->getVLC(&p_libvlc);
1923 if( SUCCEEDED(hr) )
1925 libvlc_exception_t ex;
1926 libvlc_exception_init(&ex);
1928 libvlc_playlist_delete_item(p_libvlc, item, &ex);
1929 if( libvlc_exception_raised(&ex) )
1931 _p_instance->setErrorInfo(IID_IVLCPlaylist,
1932 libvlc_exception_get_message(&ex));
1933 libvlc_exception_clear(&ex);
1934 return E_FAIL;
1936 return NOERROR;
1938 return hr;
1941 STDMETHODIMP VLCPlaylist::get_items(IVLCPlaylistItems** obj)
1943 if( NULL == obj )
1944 return E_POINTER;
1946 *obj = _p_vlcplaylistitems;
1947 if( NULL != _p_vlcplaylistitems )
1949 _p_vlcplaylistitems->AddRef();
1950 return NOERROR;
1952 return E_OUTOFMEMORY;
1955 /*******************************************************************************/
1957 VLCVideo::~VLCVideo()
1959 if( _p_typeinfo )
1960 _p_typeinfo->Release();
1963 HRESULT VLCVideo::loadTypeInfo(void)
1965 HRESULT hr = NOERROR;
1966 if( NULL == _p_typeinfo )
1968 ITypeLib *p_typelib;
1970 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
1971 if( SUCCEEDED(hr) )
1973 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCVideo, &_p_typeinfo);
1974 if( FAILED(hr) )
1976 _p_typeinfo = NULL;
1978 p_typelib->Release();
1981 return hr;
1984 STDMETHODIMP VLCVideo::GetTypeInfoCount(UINT* pctInfo)
1986 if( NULL == pctInfo )
1987 return E_INVALIDARG;
1989 if( SUCCEEDED(loadTypeInfo()) )
1990 *pctInfo = 1;
1991 else
1992 *pctInfo = 0;
1994 return NOERROR;
1997 STDMETHODIMP VLCVideo::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
1999 if( NULL == ppTInfo )
2000 return E_INVALIDARG;
2002 if( SUCCEEDED(loadTypeInfo()) )
2004 _p_typeinfo->AddRef();
2005 *ppTInfo = _p_typeinfo;
2006 return NOERROR;
2008 *ppTInfo = NULL;
2009 return E_NOTIMPL;
2012 STDMETHODIMP VLCVideo::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
2013 UINT cNames, LCID lcid, DISPID* rgDispID)
2015 if( SUCCEEDED(loadTypeInfo()) )
2017 return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
2019 return E_NOTIMPL;
2022 STDMETHODIMP VLCVideo::Invoke(DISPID dispIdMember, REFIID riid,
2023 LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
2024 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
2026 if( SUCCEEDED(loadTypeInfo()) )
2028 return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
2029 pVarResult, pExcepInfo, puArgErr);
2031 return E_NOTIMPL;
2034 STDMETHODIMP VLCVideo::get_fullscreen(VARIANT_BOOL* fullscreen)
2036 if( NULL == fullscreen )
2037 return E_POINTER;
2039 libvlc_instance_t* p_libvlc;
2040 HRESULT hr = _p_instance->getVLC(&p_libvlc);
2041 if( SUCCEEDED(hr) )
2043 libvlc_exception_t ex;
2044 libvlc_exception_init(&ex);
2046 libvlc_media_instance_t *p_md = libvlc_playlist_get_media_instance(p_libvlc, &ex);
2047 if( ! libvlc_exception_raised(&ex) )
2049 *fullscreen = libvlc_get_fullscreen(p_md, &ex) ? VARIANT_TRUE : VARIANT_FALSE;
2050 libvlc_media_instance_release(p_md);
2051 if( ! libvlc_exception_raised(&ex) )
2053 return NOERROR;
2056 _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
2057 libvlc_exception_clear(&ex);
2058 return E_FAIL;
2060 return hr;
2063 STDMETHODIMP VLCVideo::put_fullscreen(VARIANT_BOOL fullscreen)
2065 libvlc_instance_t* p_libvlc;
2066 HRESULT hr = _p_instance->getVLC(&p_libvlc);
2067 if( SUCCEEDED(hr) )
2069 libvlc_exception_t ex;
2070 libvlc_exception_init(&ex);
2072 libvlc_media_instance_t *p_md = libvlc_playlist_get_media_instance(p_libvlc, &ex);
2073 if( ! libvlc_exception_raised(&ex) )
2075 libvlc_set_fullscreen(p_md, VARIANT_FALSE != fullscreen, &ex);
2076 libvlc_media_instance_release(p_md);
2077 if( ! libvlc_exception_raised(&ex) )
2079 return NOERROR;
2082 _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
2083 libvlc_exception_clear(&ex);
2084 return E_FAIL;
2086 return hr;
2089 STDMETHODIMP VLCVideo::get_width(long* width)
2091 if( NULL == width )
2092 return E_POINTER;
2094 libvlc_instance_t* p_libvlc;
2095 HRESULT hr = _p_instance->getVLC(&p_libvlc);
2096 if( SUCCEEDED(hr) )
2098 libvlc_exception_t ex;
2099 libvlc_exception_init(&ex);
2101 libvlc_media_instance_t *p_md = libvlc_playlist_get_media_instance(p_libvlc, &ex);
2102 if( ! libvlc_exception_raised(&ex) )
2104 *width = libvlc_video_get_width(p_md, &ex);
2105 libvlc_media_instance_release(p_md);
2106 if( ! libvlc_exception_raised(&ex) )
2108 return NOERROR;
2111 _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
2112 libvlc_exception_clear(&ex);
2113 return E_FAIL;
2115 return hr;
2118 STDMETHODIMP VLCVideo::get_height(long* height)
2120 if( NULL == height )
2121 return E_POINTER;
2123 libvlc_instance_t* p_libvlc;
2124 HRESULT hr = _p_instance->getVLC(&p_libvlc);
2125 if( SUCCEEDED(hr) )
2127 libvlc_exception_t ex;
2128 libvlc_exception_init(&ex);
2130 libvlc_media_instance_t *p_md = libvlc_playlist_get_media_instance(p_libvlc, &ex);
2131 if( ! libvlc_exception_raised(&ex) )
2133 *height = libvlc_video_get_height(p_md, &ex);
2134 libvlc_media_instance_release(p_md);
2135 if( ! libvlc_exception_raised(&ex) )
2137 return NOERROR;
2140 _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
2141 libvlc_exception_clear(&ex);
2142 return E_FAIL;
2144 return hr;
2147 STDMETHODIMP VLCVideo::get_aspectRatio(BSTR* aspect)
2149 if( NULL == aspect )
2150 return E_POINTER;
2152 libvlc_instance_t* p_libvlc;
2153 HRESULT hr = _p_instance->getVLC(&p_libvlc);
2154 if( SUCCEEDED(hr) )
2156 libvlc_exception_t ex;
2157 libvlc_exception_init(&ex);
2159 libvlc_media_instance_t *p_md = libvlc_playlist_get_media_instance(p_libvlc, &ex);
2160 if( ! libvlc_exception_raised(&ex) )
2162 char *psz_aspect = libvlc_video_get_aspect_ratio(p_md, &ex);
2164 libvlc_media_instance_release(p_md);
2165 if( ! libvlc_exception_raised(&ex) )
2167 if( NULL == psz_aspect )
2168 return E_OUTOFMEMORY;
2170 *aspect = BSTRFromCStr(CP_UTF8, psz_aspect);
2171 free( psz_aspect );
2172 psz_aspect = NULL;
2173 return (NULL == *aspect) ? E_OUTOFMEMORY : NOERROR;
2175 if( psz_aspect ) free( psz_aspect );
2176 psz_aspect = NULL;
2178 _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
2179 libvlc_exception_clear(&ex);
2180 return E_FAIL;
2182 return hr;
2185 STDMETHODIMP VLCVideo::put_aspectRatio(BSTR aspect)
2187 if( NULL == aspect )
2188 return E_POINTER;
2190 if( 0 == SysStringLen(aspect) )
2191 return E_INVALIDARG;
2193 libvlc_instance_t* p_libvlc;
2194 HRESULT hr = _p_instance->getVLC(&p_libvlc);
2195 if( SUCCEEDED(hr) )
2197 libvlc_exception_t ex;
2198 libvlc_exception_init(&ex);
2200 libvlc_media_instance_t *p_md = libvlc_playlist_get_media_instance(p_libvlc, &ex);
2201 if( ! libvlc_exception_raised(&ex) )
2203 char *psz_aspect = CStrFromBSTR(CP_UTF8, aspect);
2204 if( NULL == psz_aspect )
2206 return E_OUTOFMEMORY;
2209 libvlc_video_set_aspect_ratio(p_md, psz_aspect, &ex);
2211 CoTaskMemFree(psz_aspect);
2212 libvlc_media_instance_release(p_md);
2213 if( libvlc_exception_raised(&ex) )
2215 _p_instance->setErrorInfo(IID_IVLCVideo,
2216 libvlc_exception_get_message(&ex));
2217 libvlc_exception_clear(&ex);
2218 return E_FAIL;
2221 return NOERROR;
2223 return hr;
2226 STDMETHODIMP VLCVideo::get_subtitle(long* spu)
2228 if( NULL == spu )
2229 return E_POINTER;
2231 libvlc_instance_t* p_libvlc;
2232 HRESULT hr = _p_instance->getVLC(&p_libvlc);
2233 if( SUCCEEDED(hr) )
2235 libvlc_exception_t ex;
2236 libvlc_exception_init(&ex);
2238 libvlc_media_instance_t *p_md = libvlc_playlist_get_media_instance(p_libvlc, &ex);
2239 if( ! libvlc_exception_raised(&ex) )
2241 *spu = libvlc_video_get_spu(p_md, &ex);
2242 libvlc_media_instance_release(p_md);
2243 if( ! libvlc_exception_raised(&ex) )
2245 return NOERROR;
2248 _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
2249 libvlc_exception_clear(&ex);
2250 return E_FAIL;
2252 return hr;
2255 STDMETHODIMP VLCVideo::put_subtitle(long spu)
2257 libvlc_instance_t* p_libvlc;
2258 HRESULT hr = _p_instance->getVLC(&p_libvlc);
2259 if( SUCCEEDED(hr) )
2261 libvlc_exception_t ex;
2262 libvlc_exception_init(&ex);
2264 libvlc_media_instance_t *p_md = libvlc_playlist_get_media_instance(p_libvlc, &ex);
2265 libvlc_video_set_spu(p_md, spu, &ex);
2266 libvlc_media_instance_release(p_md);
2267 if( libvlc_exception_raised(&ex) )
2269 _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
2270 libvlc_exception_clear(&ex);
2271 return E_FAIL;
2273 return NOERROR;
2275 return hr;
2278 STDMETHODIMP VLCVideo::get_crop(BSTR* geometry)
2280 if( NULL == geometry )
2281 return E_POINTER;
2283 libvlc_instance_t* p_libvlc;
2284 HRESULT hr = _p_instance->getVLC(&p_libvlc);
2285 if( SUCCEEDED(hr) )
2287 libvlc_exception_t ex;
2288 libvlc_exception_init(&ex);
2290 libvlc_media_instance_t *p_md = libvlc_playlist_get_media_instance(p_libvlc, &ex);
2291 if( ! libvlc_exception_raised(&ex) )
2293 char *psz_geometry = libvlc_video_get_crop_geometry(p_md, &ex);
2295 libvlc_media_instance_release(p_md);
2296 if( ! libvlc_exception_raised(&ex) )
2298 if( NULL == psz_geometry )
2299 return E_OUTOFMEMORY;
2301 *geometry = BSTRFromCStr(CP_UTF8, psz_geometry);
2302 free( psz_geometry );
2303 psz_geometry = NULL;
2304 return (NULL == geometry) ? E_OUTOFMEMORY : NOERROR;
2306 if( psz_geometry ) free( psz_geometry );
2307 psz_geometry = NULL;
2309 _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
2310 libvlc_exception_clear(&ex);
2311 return E_FAIL;
2313 return hr;
2316 STDMETHODIMP VLCVideo::put_crop(BSTR geometry)
2318 if( NULL == geometry )
2319 return E_POINTER;
2321 if( 0 == SysStringLen(geometry) )
2322 return E_INVALIDARG;
2324 libvlc_instance_t* p_libvlc;
2325 HRESULT hr = _p_instance->getVLC(&p_libvlc);
2326 if( SUCCEEDED(hr) )
2328 libvlc_exception_t ex;
2329 libvlc_exception_init(&ex);
2331 libvlc_media_instance_t *p_md = libvlc_playlist_get_media_instance(p_libvlc, &ex);
2332 if( ! libvlc_exception_raised(&ex) )
2334 char *psz_geometry = CStrFromBSTR(CP_UTF8, geometry);
2335 if( NULL == psz_geometry )
2337 return E_OUTOFMEMORY;
2340 libvlc_video_set_crop_geometry(p_md, psz_geometry, &ex);
2342 CoTaskMemFree(psz_geometry);
2343 libvlc_media_instance_release(p_md);
2344 if( libvlc_exception_raised(&ex) )
2346 _p_instance->setErrorInfo(IID_IVLCVideo,
2347 libvlc_exception_get_message(&ex));
2348 libvlc_exception_clear(&ex);
2349 return E_FAIL;
2352 return NOERROR;
2354 return hr;
2357 STDMETHODIMP VLCVideo::get_teletext(long* page)
2359 if( NULL == page )
2360 return E_POINTER;
2362 libvlc_instance_t* p_libvlc;
2363 HRESULT hr = _p_instance->getVLC(&p_libvlc);
2364 if( SUCCEEDED(hr) )
2366 libvlc_exception_t ex;
2367 libvlc_exception_init(&ex);
2369 libvlc_media_instance_t *p_md = libvlc_playlist_get_media_instance(p_libvlc, &ex);
2370 if( ! libvlc_exception_raised(&ex) )
2372 *page = libvlc_video_get_teletext(p_md, &ex);
2373 libvlc_media_instance_release(p_md);
2374 if( ! libvlc_exception_raised(&ex) )
2376 return NOERROR;
2379 _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
2380 libvlc_exception_clear(&ex);
2381 return E_FAIL;
2383 return hr;
2386 STDMETHODIMP VLCVideo::put_teletext(long page)
2388 libvlc_instance_t* p_libvlc;
2389 HRESULT hr = _p_instance->getVLC(&p_libvlc);
2390 if( SUCCEEDED(hr) )
2392 libvlc_exception_t ex;
2393 libvlc_exception_init(&ex);
2395 libvlc_media_instance_t *p_md = libvlc_playlist_get_media_instance(p_libvlc, &ex);
2396 libvlc_video_set_teletext(p_md, page, &ex);
2397 libvlc_media_instance_release(p_md);
2398 if( libvlc_exception_raised(&ex) )
2400 _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
2401 libvlc_exception_clear(&ex);
2402 return E_FAIL;
2404 return NOERROR;
2406 return hr;
2409 STDMETHODIMP VLCVideo::takeSnapshot(LPPICTUREDISP* picture)
2411 if( NULL == picture )
2412 return E_POINTER;
2414 libvlc_instance_t* p_libvlc;
2415 HRESULT hr = _p_instance->getVLC(&p_libvlc);
2416 if( SUCCEEDED(hr) )
2418 libvlc_exception_t ex;
2419 libvlc_exception_init(&ex);
2421 libvlc_media_instance_t *p_md = libvlc_playlist_get_media_instance(p_libvlc, &ex);
2422 if( ! libvlc_exception_raised(&ex) )
2424 static int uniqueId = 0;
2425 TCHAR path[MAX_PATH+1];
2427 int pathlen = GetTempPath(MAX_PATH-24, path);
2428 if( (0 == pathlen) || (pathlen > (MAX_PATH-24)) )
2429 return E_FAIL;
2431 /* check temp directory path by openning it */
2433 HANDLE dirHandle = CreateFile(path,
2434 GENERIC_READ,
2435 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
2436 NULL,
2437 OPEN_EXISTING,
2438 FILE_FLAG_BACKUP_SEMANTICS, NULL);
2439 if( INVALID_HANDLE_VALUE == dirHandle )
2441 _p_instance->setErrorInfo(IID_IVLCVideo,
2442 "Invalid temporary directory for snapshot images, check values of TMP, TEMP envars.");
2443 return E_FAIL;
2445 else
2447 BY_HANDLE_FILE_INFORMATION bhfi;
2448 BOOL res = GetFileInformationByHandle(dirHandle, &bhfi);
2449 CloseHandle(dirHandle);
2450 if( !res || !(bhfi.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) )
2452 _p_instance->setErrorInfo(IID_IVLCVideo,
2453 "Invalid temporary directory for snapshot images, check values of TMP, TEMP envars.");
2454 return E_FAIL;
2459 TCHAR filepath[MAX_PATH+1];
2461 _stprintf(filepath, TEXT("%sAXVLC%lXS%lX.bmp"),
2462 path, GetCurrentProcessId(), ++uniqueId);
2464 #ifdef _UNICODE
2465 /* reuse path storage for UTF8 string */
2466 char *psz_filepath = (char *)path;
2467 WCHAR* wpath = filepath;
2468 #else
2469 char *psz_filepath = path;
2470 /* first convert to unicode using current code page */
2471 WCHAR wpath[MAX_PATH+1];
2472 if( 0 == MultiByteToWideChar(CP_ACP, 0, filepath, -1, wpath, sizeof(wpath)/sizeof(WCHAR)) )
2473 return E_FAIL;
2474 #endif
2475 /* convert to UTF8 */
2476 pathlen = WideCharToMultiByte(CP_UTF8, 0, wpath, -1, psz_filepath, sizeof(path), NULL, NULL);
2477 // fail if path is 0 or too short (i.e pathlen is the same as storage size)
2478 if( (0 == pathlen) || (sizeof(path) == pathlen) )
2479 return E_FAIL;
2481 /* take snapshot into file */
2482 libvlc_video_take_snapshot(p_md, psz_filepath, 0, 0, &ex);
2483 libvlc_media_instance_release(p_md);
2484 if( ! libvlc_exception_raised(&ex) )
2486 hr = E_FAIL;
2487 /* open snapshot file */
2488 HANDLE snapPic = LoadImage(NULL, filepath, IMAGE_BITMAP,0, 0, LR_CREATEDIBSECTION|LR_LOADFROMFILE);
2489 if( snapPic )
2491 PICTDESC snapDesc;
2493 snapDesc.cbSizeofstruct = sizeof(PICTDESC);
2494 snapDesc.picType = PICTYPE_BITMAP;
2495 snapDesc.bmp.hbitmap = (HBITMAP)snapPic;
2496 snapDesc.bmp.hpal = NULL;
2498 hr = OleCreatePictureIndirect(&snapDesc, IID_IPictureDisp, TRUE, (LPVOID*)picture);
2499 if( FAILED(hr) )
2501 *picture = NULL;
2502 DeleteObject(snapPic);
2505 DeleteFile(filepath);
2506 return hr;
2509 _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
2510 libvlc_exception_clear(&ex);
2511 return E_FAIL;
2513 return hr;
2516 STDMETHODIMP VLCVideo::toggleFullscreen()
2518 libvlc_instance_t* p_libvlc;
2519 HRESULT hr = _p_instance->getVLC(&p_libvlc);
2520 if( SUCCEEDED(hr) )
2522 libvlc_exception_t ex;
2523 libvlc_exception_init(&ex);
2525 libvlc_media_instance_t *p_md = libvlc_playlist_get_media_instance(p_libvlc, &ex);
2526 if( ! libvlc_exception_raised(&ex) )
2528 libvlc_toggle_fullscreen(p_md, &ex);
2529 libvlc_media_instance_release(p_md);
2530 if( ! libvlc_exception_raised(&ex) )
2532 return NOERROR;
2535 _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
2536 libvlc_exception_clear(&ex);
2537 return E_FAIL;
2539 return hr;
2542 STDMETHODIMP VLCVideo::toggleTeletext()
2544 libvlc_instance_t* p_libvlc;
2545 HRESULT hr = _p_instance->getVLC(&p_libvlc);
2546 if( SUCCEEDED(hr) )
2548 libvlc_exception_t ex;
2549 libvlc_exception_init(&ex);
2551 libvlc_media_instance_t *p_md = libvlc_playlist_get_media_instance(p_libvlc, &ex);
2552 if( ! libvlc_exception_raised(&ex) )
2554 libvlc_toggle_teletext(p_md, &ex);
2555 libvlc_media_instance_release(p_md);
2556 if( ! libvlc_exception_raised(&ex) )
2558 return NOERROR;
2561 _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
2562 libvlc_exception_clear(&ex);
2563 return E_FAIL;
2565 return hr;
2568 /*******************************************************************************/
2570 VLCControl2::VLCControl2(VLCPlugin *p_instance) :
2571 _p_instance(p_instance),
2572 _p_typeinfo(NULL),
2573 _p_vlcaudio(NULL),
2574 _p_vlcinput(NULL),
2575 _p_vlcplaylist(NULL),
2576 _p_vlcvideo(NULL)
2578 _p_vlcaudio = new VLCAudio(p_instance);
2579 _p_vlcinput = new VLCInput(p_instance);
2580 _p_vlclog = new VLCLog(p_instance);
2581 _p_vlcplaylist = new VLCPlaylist(p_instance);
2582 _p_vlcvideo = new VLCVideo(p_instance);
2585 VLCControl2::~VLCControl2()
2587 delete _p_vlcvideo;
2588 delete _p_vlcplaylist;
2589 delete _p_vlclog;
2590 delete _p_vlcinput;
2591 delete _p_vlcaudio;
2592 if( _p_typeinfo )
2593 _p_typeinfo->Release();
2596 HRESULT VLCControl2::loadTypeInfo(void)
2598 HRESULT hr = NOERROR;
2599 if( NULL == _p_typeinfo )
2601 ITypeLib *p_typelib;
2603 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
2604 if( SUCCEEDED(hr) )
2606 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCControl2, &_p_typeinfo);
2607 if( FAILED(hr) )
2609 _p_typeinfo = NULL;
2611 p_typelib->Release();
2614 return hr;
2617 STDMETHODIMP VLCControl2::GetTypeInfoCount(UINT* pctInfo)
2619 if( NULL == pctInfo )
2620 return E_INVALIDARG;
2622 if( SUCCEEDED(loadTypeInfo()) )
2623 *pctInfo = 1;
2624 else
2625 *pctInfo = 0;
2627 return NOERROR;
2630 STDMETHODIMP VLCControl2::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
2632 if( NULL == ppTInfo )
2633 return E_INVALIDARG;
2635 if( SUCCEEDED(loadTypeInfo()) )
2637 _p_typeinfo->AddRef();
2638 *ppTInfo = _p_typeinfo;
2639 return NOERROR;
2641 *ppTInfo = NULL;
2642 return E_NOTIMPL;
2645 STDMETHODIMP VLCControl2::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
2646 UINT cNames, LCID lcid, DISPID* rgDispID)
2648 if( SUCCEEDED(loadTypeInfo()) )
2650 return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
2652 return E_NOTIMPL;
2655 STDMETHODIMP VLCControl2::Invoke(DISPID dispIdMember, REFIID riid,
2656 LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
2657 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
2659 if( SUCCEEDED(loadTypeInfo()) )
2661 return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
2662 pVarResult, pExcepInfo, puArgErr);
2664 return E_NOTIMPL;
2667 STDMETHODIMP VLCControl2::get_AutoLoop(VARIANT_BOOL *autoloop)
2669 if( NULL == autoloop )
2670 return E_POINTER;
2672 *autoloop = _p_instance->getAutoLoop() ? VARIANT_TRUE: VARIANT_FALSE;
2673 return S_OK;
2676 STDMETHODIMP VLCControl2::put_AutoLoop(VARIANT_BOOL autoloop)
2678 _p_instance->setAutoLoop((VARIANT_FALSE != autoloop) ? TRUE: FALSE);
2679 return S_OK;
2682 STDMETHODIMP VLCControl2::get_AutoPlay(VARIANT_BOOL *autoplay)
2684 if( NULL == autoplay )
2685 return E_POINTER;
2687 *autoplay = _p_instance->getAutoPlay() ? VARIANT_TRUE: VARIANT_FALSE;
2688 return S_OK;
2691 STDMETHODIMP VLCControl2::put_AutoPlay(VARIANT_BOOL autoplay)
2693 _p_instance->setAutoPlay((VARIANT_FALSE != autoplay) ? TRUE: FALSE);
2694 return S_OK;
2697 STDMETHODIMP VLCControl2::get_BaseURL(BSTR *url)
2699 if( NULL == url )
2700 return E_POINTER;
2702 *url = SysAllocStringLen(_p_instance->getBaseURL(),
2703 SysStringLen(_p_instance->getBaseURL()));
2704 return NOERROR;
2707 STDMETHODIMP VLCControl2::put_BaseURL(BSTR mrl)
2709 _p_instance->setBaseURL(mrl);
2711 return S_OK;
2714 STDMETHODIMP VLCControl2::get_MRL(BSTR *mrl)
2716 if( NULL == mrl )
2717 return E_POINTER;
2719 *mrl = SysAllocStringLen(_p_instance->getMRL(),
2720 SysStringLen(_p_instance->getMRL()));
2721 return NOERROR;
2724 STDMETHODIMP VLCControl2::put_MRL(BSTR mrl)
2726 _p_instance->setMRL(mrl);
2728 return S_OK;
2731 STDMETHODIMP VLCControl2::get_StartTime(long *seconds)
2733 if( NULL == seconds )
2734 return E_POINTER;
2736 *seconds = _p_instance->getStartTime();
2738 return S_OK;
2741 STDMETHODIMP VLCControl2::put_StartTime(long seconds)
2743 _p_instance->setStartTime(seconds);
2745 return NOERROR;
2748 STDMETHODIMP VLCControl2::get_VersionInfo(BSTR *version)
2750 if( NULL == version )
2751 return E_POINTER;
2753 const char *versionStr = VLC_Version();
2754 if( NULL != versionStr )
2756 *version = BSTRFromCStr(CP_UTF8, versionStr);
2758 return NULL == *version ? E_OUTOFMEMORY : NOERROR;
2760 *version = NULL;
2761 return E_FAIL;
2764 STDMETHODIMP VLCControl2::get_Visible(VARIANT_BOOL *isVisible)
2766 if( NULL == isVisible )
2767 return E_POINTER;
2769 *isVisible = _p_instance->getVisible() ? VARIANT_TRUE : VARIANT_FALSE;
2771 return NOERROR;
2774 STDMETHODIMP VLCControl2::put_Visible(VARIANT_BOOL isVisible)
2776 _p_instance->setVisible(isVisible != VARIANT_FALSE);
2778 return NOERROR;
2781 STDMETHODIMP VLCControl2::get_Volume(long *volume)
2783 if( NULL == volume )
2784 return E_POINTER;
2786 *volume = _p_instance->getVolume();
2787 return NOERROR;
2790 STDMETHODIMP VLCControl2::put_Volume(long volume)
2792 _p_instance->setVolume(volume);
2793 return NOERROR;
2796 STDMETHODIMP VLCControl2::get_BackColor(OLE_COLOR *backcolor)
2798 if( NULL == backcolor )
2799 return E_POINTER;
2801 *backcolor = _p_instance->getBackColor();
2802 return NOERROR;
2805 STDMETHODIMP VLCControl2::put_BackColor(OLE_COLOR backcolor)
2807 _p_instance->setBackColor(backcolor);
2808 return NOERROR;
2811 STDMETHODIMP VLCControl2::get_audio(IVLCAudio** obj)
2813 if( NULL == obj )
2814 return E_POINTER;
2816 *obj = _p_vlcaudio;
2817 if( NULL != _p_vlcaudio )
2819 _p_vlcaudio->AddRef();
2820 return NOERROR;
2822 return E_OUTOFMEMORY;
2825 STDMETHODIMP VLCControl2::get_input(IVLCInput** obj)
2827 if( NULL == obj )
2828 return E_POINTER;
2830 *obj = _p_vlcinput;
2831 if( NULL != _p_vlcinput )
2833 _p_vlcinput->AddRef();
2834 return NOERROR;
2836 return E_OUTOFMEMORY;
2839 STDMETHODIMP VLCControl2::get_log(IVLCLog** obj)
2841 if( NULL == obj )
2842 return E_POINTER;
2844 *obj = _p_vlclog;
2845 if( NULL != _p_vlclog )
2847 _p_vlclog->AddRef();
2848 return NOERROR;
2850 return E_OUTOFMEMORY;
2853 STDMETHODIMP VLCControl2::get_playlist(IVLCPlaylist** obj)
2855 if( NULL == obj )
2856 return E_POINTER;
2858 *obj = _p_vlcplaylist;
2859 if( NULL != _p_vlcplaylist )
2861 _p_vlcplaylist->AddRef();
2862 return NOERROR;
2864 return E_OUTOFMEMORY;
2867 STDMETHODIMP VLCControl2::get_video(IVLCVideo** obj)
2869 if( NULL == obj )
2870 return E_POINTER;
2872 *obj = _p_vlcvideo;
2873 if( NULL != _p_vlcvideo )
2875 _p_vlcvideo->AddRef();
2876 return NOERROR;
2878 return E_OUTOFMEMORY;