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 *****************************************************************************/
25 #include "vlccontrol2.h"
26 #include "vlccontrol.h"
39 _p_typeinfo->Release();
42 HRESULT VLCAudio::loadTypeInfo(void)
45 if( NULL == _p_typeinfo )
49 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
52 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCAudio, &_p_typeinfo);
63 STDMETHODIMP VLCAudio::GetTypeInfoCount(UINT* pctInfo)
68 if( SUCCEEDED(loadTypeInfo()) )
76 STDMETHODIMP VLCAudio::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
81 if( SUCCEEDED(loadTypeInfo()) )
83 _p_typeinfo->AddRef();
84 *ppTInfo = _p_typeinfo;
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);
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);
113 STDMETHODIMP VLCAudio::get_mute(VARIANT_BOOL* mute)
118 libvlc_instance_t* p_libvlc;
119 HRESULT hr = _p_instance->getVLC(&p_libvlc);
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);
137 STDMETHODIMP VLCAudio::put_mute(VARIANT_BOOL mute)
139 libvlc_instance_t* p_libvlc;
140 HRESULT hr = _p_instance->getVLC(&p_libvlc);
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);
158 STDMETHODIMP VLCAudio::get_volume(long* volume)
163 libvlc_instance_t* p_libvlc;
164 HRESULT hr = _p_instance->getVLC(&p_libvlc);
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);
182 STDMETHODIMP VLCAudio::put_volume(long volume)
184 libvlc_instance_t* p_libvlc;
185 HRESULT hr = _p_instance->getVLC(&p_libvlc);
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);
204 STDMETHODIMP VLCAudio::get_track(long* track)
209 libvlc_instance_t* p_libvlc;
210 HRESULT hr = _p_instance->getVLC(&p_libvlc);
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);
231 STDMETHODIMP VLCAudio::put_track(long track)
233 libvlc_instance_t* p_libvlc;
234 HRESULT hr = _p_instance->getVLC(&p_libvlc);
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);
255 STDMETHODIMP VLCAudio::get_channel(long *channel)
257 if( NULL == channel )
260 libvlc_instance_t* p_libvlc;
261 HRESULT hr = _p_instance->getVLC(&p_libvlc);
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);
280 STDMETHODIMP VLCAudio::put_channel(long channel)
282 libvlc_instance_t* p_libvlc;
283 HRESULT hr = _p_instance->getVLC(&p_libvlc);
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);
302 STDMETHODIMP VLCAudio::toggleMute()
304 libvlc_instance_t* p_libvlc;
305 HRESULT hr = _p_instance->getVLC(&p_libvlc);
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);
324 /*******************************************************************************/
326 VLCInput::~VLCInput()
329 _p_typeinfo->Release();
332 HRESULT VLCInput::loadTypeInfo(void)
334 HRESULT hr = NOERROR;
335 if( NULL == _p_typeinfo )
339 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
342 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCInput, &_p_typeinfo);
347 p_typelib->Release();
353 STDMETHODIMP VLCInput::GetTypeInfoCount(UINT* pctInfo)
355 if( NULL == pctInfo )
358 if( SUCCEEDED(loadTypeInfo()) )
366 STDMETHODIMP VLCInput::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
368 if( NULL == ppTInfo )
371 if( SUCCEEDED(loadTypeInfo()) )
373 _p_typeinfo->AddRef();
374 *ppTInfo = _p_typeinfo;
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);
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);
403 STDMETHODIMP VLCInput::get_length(double* length)
408 libvlc_instance_t* p_libvlc;
409 HRESULT hr = _p_instance->getVLC(&p_libvlc);
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) )
425 _p_instance->setErrorInfo(IID_IVLCInput, libvlc_exception_get_message(&ex));
426 libvlc_exception_clear(&ex);
432 STDMETHODIMP VLCInput::get_position(double* position)
434 if( NULL == position )
437 libvlc_instance_t* p_libvlc;
438 HRESULT hr = _p_instance->getVLC(&p_libvlc);
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) )
454 _p_instance->setErrorInfo(IID_IVLCInput, libvlc_exception_get_message(&ex));
455 libvlc_exception_clear(&ex);
461 STDMETHODIMP VLCInput::put_position(double position)
463 libvlc_instance_t* p_libvlc;
464 HRESULT hr = _p_instance->getVLC(&p_libvlc);
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) )
480 _p_instance->setErrorInfo(IID_IVLCInput, libvlc_exception_get_message(&ex));
481 libvlc_exception_clear(&ex);
487 STDMETHODIMP VLCInput::get_time(double* time)
492 libvlc_instance_t* p_libvlc;
493 HRESULT hr = _p_instance->getVLC(&p_libvlc);
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) )
509 _p_instance->setErrorInfo(IID_IVLCInput, libvlc_exception_get_message(&ex));
510 libvlc_exception_clear(&ex);
516 STDMETHODIMP VLCInput::put_time(double time)
518 libvlc_instance_t* p_libvlc;
519 HRESULT hr = _p_instance->getVLC(&p_libvlc);
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) )
535 _p_instance->setErrorInfo(IID_IVLCInput, libvlc_exception_get_message(&ex));
536 libvlc_exception_clear(&ex);
542 STDMETHODIMP VLCInput::get_state(long* state)
547 libvlc_instance_t* p_libvlc;
548 HRESULT hr = _p_instance->getVLC(&p_libvlc);
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) )
564 libvlc_exception_clear(&ex);
565 // don't fail, just return the idle state
572 STDMETHODIMP VLCInput::get_rate(double* rate)
577 libvlc_instance_t* p_libvlc;
578 HRESULT hr = _p_instance->getVLC(&p_libvlc);
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) )
594 _p_instance->setErrorInfo(IID_IVLCInput, libvlc_exception_get_message(&ex));
595 libvlc_exception_clear(&ex);
601 STDMETHODIMP VLCInput::put_rate(double rate)
603 libvlc_instance_t* p_libvlc;
604 HRESULT hr = _p_instance->getVLC(&p_libvlc);
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) )
620 _p_instance->setErrorInfo(IID_IVLCInput, libvlc_exception_get_message(&ex));
621 libvlc_exception_clear(&ex);
627 STDMETHODIMP VLCInput::get_fps(double* fps)
633 libvlc_instance_t* p_libvlc;
634 HRESULT hr = _p_instance->getVLC(&p_libvlc);
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) )
650 _p_instance->setErrorInfo(IID_IVLCInput, libvlc_exception_get_message(&ex));
651 libvlc_exception_clear(&ex);
657 STDMETHODIMP VLCInput::get_hasVout(VARIANT_BOOL* hasVout)
659 if( NULL == hasVout )
662 libvlc_instance_t* p_libvlc;
663 HRESULT hr = _p_instance->getVLC(&p_libvlc);
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) )
679 _p_instance->setErrorInfo(IID_IVLCInput, libvlc_exception_get_message(&ex));
680 libvlc_exception_clear(&ex);
686 /*******************************************************************************/
690 delete _p_vlcmessages;
692 libvlc_log_close(_p_log, NULL);
695 _p_typeinfo->Release();
698 HRESULT VLCLog::loadTypeInfo(void)
700 HRESULT hr = NOERROR;
701 if( NULL == _p_typeinfo )
705 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
708 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCLog, &_p_typeinfo);
713 p_typelib->Release();
719 STDMETHODIMP VLCLog::GetTypeInfoCount(UINT* pctInfo)
721 if( NULL == pctInfo )
724 if( SUCCEEDED(loadTypeInfo()) )
732 STDMETHODIMP VLCLog::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
734 if( NULL == ppTInfo )
737 if( SUCCEEDED(loadTypeInfo()) )
739 _p_typeinfo->AddRef();
740 *ppTInfo = _p_typeinfo;
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);
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);
769 STDMETHODIMP VLCLog::get_messages(IVLCMessages** obj)
774 *obj = _p_vlcmessages;
775 if( NULL != _p_vlcmessages )
777 _p_vlcmessages->AddRef();
780 return E_OUTOFMEMORY;
783 STDMETHODIMP VLCLog::get_verbosity(long* level)
790 libvlc_instance_t* p_libvlc;
791 HRESULT hr = _p_instance->getVLC(&p_libvlc);
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);
809 /* log is not enabled, return -1 */
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);
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);
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);
846 /* close log when verbosity is set to -1 */
847 libvlc_log_close(_p_log, &ex);
849 if( libvlc_exception_raised(&ex) )
851 _p_instance->setErrorInfo(IID_IVLCLog, libvlc_exception_get_message(&ex));
852 libvlc_exception_clear(&ex);
860 /*******************************************************************************/
862 /* STL forward iterator used by VLCEnumIterator class to implement IEnumVARIANT */
864 class VLCMessageSTLIterator
869 VLCMessageSTLIterator(IVLCMessageIterator* iter) : iter(iter), msg(NULL)
875 VLCMessageSTLIterator(const VLCMessageSTLIterator& other)
885 virtual ~VLCMessageSTLIterator()
894 // we only need prefix ++ operator
895 VLCMessageSTLIterator& operator++()
897 VARIANT_BOOL hasNext = VARIANT_FALSE;
900 iter->get_hasNext(&hasNext);
907 if( VARIANT_TRUE == hasNext ) {
914 VARIANT operator*() const
920 if( SUCCEEDED(msg->QueryInterface(IID_IDispatch, (LPVOID*)&V_DISPATCH(&v))) )
922 V_VT(&v) = VT_DISPATCH;
928 bool operator==(const VLCMessageSTLIterator& other) const
930 return msg == other.msg;
933 bool operator!=(const VLCMessageSTLIterator& other) const
935 return msg != other.msg;
939 IVLCMessageIterator* iter;
943 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
945 VLCMessages::~VLCMessages()
948 _p_typeinfo->Release();
951 HRESULT VLCMessages::loadTypeInfo(void)
953 HRESULT hr = NOERROR;
954 if( NULL == _p_typeinfo )
958 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
961 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCMessages, &_p_typeinfo);
966 p_typelib->Release();
972 STDMETHODIMP VLCMessages::GetTypeInfoCount(UINT* pctInfo)
974 if( NULL == pctInfo )
977 if( SUCCEEDED(loadTypeInfo()) )
985 STDMETHODIMP VLCMessages::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
987 if( NULL == ppTInfo )
990 if( SUCCEEDED(loadTypeInfo()) )
992 _p_typeinfo->AddRef();
993 *ppTInfo = _p_typeinfo;
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);
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);
1022 STDMETHODIMP VLCMessages::get__NewEnum(LPUNKNOWN* _NewEnum)
1024 if( NULL == _NewEnum )
1027 IVLCMessageIterator* iter = NULL;
1030 *_NewEnum= new VLCEnumIterator<IID_IEnumVARIANT,
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;
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);
1058 STDMETHODIMP VLCMessages::get_count(long* count)
1063 libvlc_log_t *p_log = _p_vlclog->_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);
1082 STDMETHODIMP VLCMessages::iterator(IVLCMessageIterator** iter)
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),
1100 if( p_vlclog->_p_log )
1102 _p_iter = libvlc_log_get_iterator(p_vlclog->_p_log, NULL);
1108 VLCMessageIterator::~VLCMessageIterator()
1111 libvlc_log_iterator_free(_p_iter, NULL);
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);
1127 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCMessageIterator, &_p_typeinfo);
1132 p_typelib->Release();
1138 STDMETHODIMP VLCMessageIterator::GetTypeInfoCount(UINT* pctInfo)
1140 if( NULL == pctInfo )
1141 return E_INVALIDARG;
1143 if( SUCCEEDED(loadTypeInfo()) )
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;
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);
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);
1188 STDMETHODIMP VLCMessageIterator::get_hasNext(VARIANT_BOOL* hasNext)
1190 if( NULL == hasNext )
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);
1208 *hasNext = VARIANT_FALSE;
1213 STDMETHODIMP VLCMessageIterator::next(IVLCMessage** message)
1215 if( NULL == message )
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);
1234 *message = new VLCMessage(_p_instance, buffer);
1235 return *message ? NOERROR : E_OUTOFMEMORY;
1240 /*******************************************************************************/
1242 VLCMessage::~VLCMessage()
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);
1258 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCMessage, &_p_typeinfo);
1263 p_typelib->Release();
1269 STDMETHODIMP VLCMessage::GetTypeInfoCount(UINT* pctInfo)
1271 if( NULL == pctInfo )
1272 return E_INVALIDARG;
1274 if( SUCCEEDED(loadTypeInfo()) )
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;
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);
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);
1319 inline const char *msgSeverity(int sev)
1334 STDMETHODIMP VLCMessage::get__Value(VARIANT* _Value)
1336 if( NULL == _Value )
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);
1350 STDMETHODIMP VLCMessage::get_severity(long* level)
1355 *level = _msg.i_severity;
1360 STDMETHODIMP VLCMessage::get_type(BSTR* type)
1365 *type = BSTRFromCStr(CP_UTF8, _msg.psz_type);
1370 STDMETHODIMP VLCMessage::get_name(BSTR* name)
1375 *name = BSTRFromCStr(CP_UTF8, _msg.psz_name);
1380 STDMETHODIMP VLCMessage::get_header(BSTR* header)
1382 if( NULL == header )
1385 *header = BSTRFromCStr(CP_UTF8, _msg.psz_header);
1390 STDMETHODIMP VLCMessage::get_message(BSTR* message)
1392 if( NULL == message )
1395 *message = BSTRFromCStr(CP_UTF8, _msg.psz_message);
1400 /*******************************************************************************/
1402 VLCPlaylistItems::~VLCPlaylistItems()
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);
1418 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCPlaylistItems, &_p_typeinfo);
1423 p_typelib->Release();
1429 STDMETHODIMP VLCPlaylistItems::GetTypeInfoCount(UINT* pctInfo)
1431 if( NULL == pctInfo )
1432 return E_INVALIDARG;
1434 if( SUCCEEDED(loadTypeInfo()) )
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;
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);
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);
1479 STDMETHODIMP VLCPlaylistItems::get_count(long* count)
1484 libvlc_instance_t* p_libvlc;
1485 HRESULT hr = _p_instance->getVLC(&p_libvlc);
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);
1504 STDMETHODIMP VLCPlaylistItems::clear()
1506 libvlc_instance_t* p_libvlc;
1507 HRESULT hr = _p_instance->getVLC(&p_libvlc);
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);
1526 STDMETHODIMP VLCPlaylistItems::remove(long item)
1528 libvlc_instance_t* p_libvlc;
1529 HRESULT hr = _p_instance->getVLC(&p_libvlc);
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);
1548 /*******************************************************************************/
1550 VLCPlaylist::~VLCPlaylist()
1552 delete _p_vlcplaylistitems;
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);
1567 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCPlaylist, &_p_typeinfo);
1572 p_typelib->Release();
1578 STDMETHODIMP VLCPlaylist::GetTypeInfoCount(UINT* pctInfo)
1580 if( NULL == pctInfo )
1581 return E_INVALIDARG;
1583 if( SUCCEEDED(loadTypeInfo()) )
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;
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);
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);
1628 STDMETHODIMP VLCPlaylist::get_itemCount(long* count)
1633 libvlc_instance_t* p_libvlc;
1634 HRESULT hr = _p_instance->getVLC(&p_libvlc);
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);
1653 STDMETHODIMP VLCPlaylist::get_isPlaying(VARIANT_BOOL* isPlaying)
1655 if( NULL == isPlaying )
1658 libvlc_instance_t* p_libvlc;
1659 HRESULT hr = _p_instance->getVLC(&p_libvlc);
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);
1678 STDMETHODIMP VLCPlaylist::add(BSTR uri, VARIANT name, VARIANT options, long* item)
1683 if( 0 == SysStringLen(uri) )
1684 return E_INVALIDARG;
1686 libvlc_instance_t* p_libvlc;
1687 HRESULT hr = _p_instance->getVLC(&p_libvlc);
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);
1707 psz_uri = CStrFromBSTR(CP_UTF8, uri);
1713 ** baseURL is empty, assume MRL is absolute
1715 psz_uri = CStrFromBSTR(CP_UTF8, uri);
1718 if( NULL == psz_uri )
1720 return E_OUTOFMEMORY;
1724 char **ppsz_options;
1726 hr = VLCControl::CreateTargetOptions(CP_UTF8, &options, &ppsz_options, &i_options);
1729 CoTaskMemFree(psz_uri);
1733 char *psz_name = NULL;
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,
1748 const_cast<const char **>(ppsz_options),
1751 VLCControl::FreeTargetOptions(ppsz_options, i_options);
1752 CoTaskMemFree(psz_uri);
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);
1767 STDMETHODIMP VLCPlaylist::play()
1769 libvlc_instance_t* p_libvlc;
1770 HRESULT hr = _p_instance->getVLC(&p_libvlc);
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);
1787 STDMETHODIMP VLCPlaylist::playItem(long item)
1789 libvlc_instance_t* p_libvlc;
1790 HRESULT hr = _p_instance->getVLC(&p_libvlc);
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);
1809 STDMETHODIMP VLCPlaylist::togglePause()
1811 libvlc_instance_t* p_libvlc;
1812 HRESULT hr = _p_instance->getVLC(&p_libvlc);
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);
1831 STDMETHODIMP VLCPlaylist::stop()
1833 libvlc_instance_t* p_libvlc;
1834 HRESULT hr = _p_instance->getVLC(&p_libvlc);
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);
1853 STDMETHODIMP VLCPlaylist::next()
1855 libvlc_instance_t* p_libvlc;
1856 HRESULT hr = _p_instance->getVLC(&p_libvlc);
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);
1875 STDMETHODIMP VLCPlaylist::prev()
1877 libvlc_instance_t* p_libvlc;
1878 HRESULT hr = _p_instance->getVLC(&p_libvlc);
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);
1897 STDMETHODIMP VLCPlaylist::clear()
1899 libvlc_instance_t* p_libvlc;
1900 HRESULT hr = _p_instance->getVLC(&p_libvlc);
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);
1919 STDMETHODIMP VLCPlaylist::removeItem(long item)
1921 libvlc_instance_t* p_libvlc;
1922 HRESULT hr = _p_instance->getVLC(&p_libvlc);
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);
1941 STDMETHODIMP VLCPlaylist::get_items(IVLCPlaylistItems** obj)
1946 *obj = _p_vlcplaylistitems;
1947 if( NULL != _p_vlcplaylistitems )
1949 _p_vlcplaylistitems->AddRef();
1952 return E_OUTOFMEMORY;
1955 /*******************************************************************************/
1957 VLCVideo::~VLCVideo()
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);
1973 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCVideo, &_p_typeinfo);
1978 p_typelib->Release();
1984 STDMETHODIMP VLCVideo::GetTypeInfoCount(UINT* pctInfo)
1986 if( NULL == pctInfo )
1987 return E_INVALIDARG;
1989 if( SUCCEEDED(loadTypeInfo()) )
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;
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);
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);
2034 STDMETHODIMP VLCVideo::get_fullscreen(VARIANT_BOOL* fullscreen)
2036 if( NULL == fullscreen )
2039 libvlc_instance_t* p_libvlc;
2040 HRESULT hr = _p_instance->getVLC(&p_libvlc);
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) )
2056 _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
2057 libvlc_exception_clear(&ex);
2063 STDMETHODIMP VLCVideo::put_fullscreen(VARIANT_BOOL fullscreen)
2065 libvlc_instance_t* p_libvlc;
2066 HRESULT hr = _p_instance->getVLC(&p_libvlc);
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) )
2082 _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
2083 libvlc_exception_clear(&ex);
2089 STDMETHODIMP VLCVideo::get_width(long* width)
2094 libvlc_instance_t* p_libvlc;
2095 HRESULT hr = _p_instance->getVLC(&p_libvlc);
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) )
2111 _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
2112 libvlc_exception_clear(&ex);
2118 STDMETHODIMP VLCVideo::get_height(long* height)
2120 if( NULL == height )
2123 libvlc_instance_t* p_libvlc;
2124 HRESULT hr = _p_instance->getVLC(&p_libvlc);
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) )
2140 _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
2141 libvlc_exception_clear(&ex);
2147 STDMETHODIMP VLCVideo::get_aspectRatio(BSTR* aspect)
2149 if( NULL == aspect )
2152 libvlc_instance_t* p_libvlc;
2153 HRESULT hr = _p_instance->getVLC(&p_libvlc);
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);
2173 return (NULL == *aspect) ? E_OUTOFMEMORY : NOERROR;
2175 if( psz_aspect ) free( psz_aspect );
2178 _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
2179 libvlc_exception_clear(&ex);
2185 STDMETHODIMP VLCVideo::put_aspectRatio(BSTR aspect)
2187 if( NULL == aspect )
2190 if( 0 == SysStringLen(aspect) )
2191 return E_INVALIDARG;
2193 libvlc_instance_t* p_libvlc;
2194 HRESULT hr = _p_instance->getVLC(&p_libvlc);
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);
2226 STDMETHODIMP VLCVideo::get_subtitle(long* spu)
2231 libvlc_instance_t* p_libvlc;
2232 HRESULT hr = _p_instance->getVLC(&p_libvlc);
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) )
2248 _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
2249 libvlc_exception_clear(&ex);
2255 STDMETHODIMP VLCVideo::put_subtitle(long spu)
2257 libvlc_instance_t* p_libvlc;
2258 HRESULT hr = _p_instance->getVLC(&p_libvlc);
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);
2278 STDMETHODIMP VLCVideo::get_crop(BSTR* geometry)
2280 if( NULL == geometry )
2283 libvlc_instance_t* p_libvlc;
2284 HRESULT hr = _p_instance->getVLC(&p_libvlc);
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);
2316 STDMETHODIMP VLCVideo::put_crop(BSTR geometry)
2318 if( NULL == geometry )
2321 if( 0 == SysStringLen(geometry) )
2322 return E_INVALIDARG;
2324 libvlc_instance_t* p_libvlc;
2325 HRESULT hr = _p_instance->getVLC(&p_libvlc);
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);
2357 STDMETHODIMP VLCVideo::get_teletext(long* page)
2362 libvlc_instance_t* p_libvlc;
2363 HRESULT hr = _p_instance->getVLC(&p_libvlc);
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) )
2379 _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
2380 libvlc_exception_clear(&ex);
2386 STDMETHODIMP VLCVideo::put_teletext(long page)
2388 libvlc_instance_t* p_libvlc;
2389 HRESULT hr = _p_instance->getVLC(&p_libvlc);
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);
2409 STDMETHODIMP VLCVideo::takeSnapshot(LPPICTUREDISP* picture)
2411 if( NULL == picture )
2414 libvlc_instance_t* p_libvlc;
2415 HRESULT hr = _p_instance->getVLC(&p_libvlc);
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)) )
2431 /* check temp directory path by openning it */
2433 HANDLE dirHandle = CreateFile(path,
2435 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
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.");
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.");
2459 TCHAR filepath[MAX_PATH+1];
2461 _stprintf(filepath, TEXT("%sAXVLC%lXS%lX.bmp"),
2462 path, GetCurrentProcessId(), ++uniqueId);
2465 /* reuse path storage for UTF8 string */
2466 char *psz_filepath = (char *)path;
2467 WCHAR* wpath = filepath;
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)) )
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) )
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) )
2487 /* open snapshot file */
2488 HANDLE snapPic = LoadImage(NULL, filepath, IMAGE_BITMAP,0, 0, LR_CREATEDIBSECTION|LR_LOADFROMFILE);
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);
2502 DeleteObject(snapPic);
2505 DeleteFile(filepath);
2509 _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
2510 libvlc_exception_clear(&ex);
2516 STDMETHODIMP VLCVideo::toggleFullscreen()
2518 libvlc_instance_t* p_libvlc;
2519 HRESULT hr = _p_instance->getVLC(&p_libvlc);
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) )
2535 _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
2536 libvlc_exception_clear(&ex);
2542 STDMETHODIMP VLCVideo::toggleTeletext()
2544 libvlc_instance_t* p_libvlc;
2545 HRESULT hr = _p_instance->getVLC(&p_libvlc);
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) )
2561 _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
2562 libvlc_exception_clear(&ex);
2568 /*******************************************************************************/
2570 VLCControl2::VLCControl2(VLCPlugin *p_instance) :
2571 _p_instance(p_instance),
2575 _p_vlcplaylist(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()
2588 delete _p_vlcplaylist;
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);
2606 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCControl2, &_p_typeinfo);
2611 p_typelib->Release();
2617 STDMETHODIMP VLCControl2::GetTypeInfoCount(UINT* pctInfo)
2619 if( NULL == pctInfo )
2620 return E_INVALIDARG;
2622 if( SUCCEEDED(loadTypeInfo()) )
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;
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);
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);
2667 STDMETHODIMP VLCControl2::get_AutoLoop(VARIANT_BOOL *autoloop)
2669 if( NULL == autoloop )
2672 *autoloop = _p_instance->getAutoLoop() ? VARIANT_TRUE: VARIANT_FALSE;
2676 STDMETHODIMP VLCControl2::put_AutoLoop(VARIANT_BOOL autoloop)
2678 _p_instance->setAutoLoop((VARIANT_FALSE != autoloop) ? TRUE: FALSE);
2682 STDMETHODIMP VLCControl2::get_AutoPlay(VARIANT_BOOL *autoplay)
2684 if( NULL == autoplay )
2687 *autoplay = _p_instance->getAutoPlay() ? VARIANT_TRUE: VARIANT_FALSE;
2691 STDMETHODIMP VLCControl2::put_AutoPlay(VARIANT_BOOL autoplay)
2693 _p_instance->setAutoPlay((VARIANT_FALSE != autoplay) ? TRUE: FALSE);
2697 STDMETHODIMP VLCControl2::get_BaseURL(BSTR *url)
2702 *url = SysAllocStringLen(_p_instance->getBaseURL(),
2703 SysStringLen(_p_instance->getBaseURL()));
2707 STDMETHODIMP VLCControl2::put_BaseURL(BSTR mrl)
2709 _p_instance->setBaseURL(mrl);
2714 STDMETHODIMP VLCControl2::get_MRL(BSTR *mrl)
2719 *mrl = SysAllocStringLen(_p_instance->getMRL(),
2720 SysStringLen(_p_instance->getMRL()));
2724 STDMETHODIMP VLCControl2::put_MRL(BSTR mrl)
2726 _p_instance->setMRL(mrl);
2731 STDMETHODIMP VLCControl2::get_StartTime(long *seconds)
2733 if( NULL == seconds )
2736 *seconds = _p_instance->getStartTime();
2741 STDMETHODIMP VLCControl2::put_StartTime(long seconds)
2743 _p_instance->setStartTime(seconds);
2748 STDMETHODIMP VLCControl2::get_VersionInfo(BSTR *version)
2750 if( NULL == version )
2753 const char *versionStr = VLC_Version();
2754 if( NULL != versionStr )
2756 *version = BSTRFromCStr(CP_UTF8, versionStr);
2758 return NULL == *version ? E_OUTOFMEMORY : NOERROR;
2764 STDMETHODIMP VLCControl2::get_Visible(VARIANT_BOOL *isVisible)
2766 if( NULL == isVisible )
2769 *isVisible = _p_instance->getVisible() ? VARIANT_TRUE : VARIANT_FALSE;
2774 STDMETHODIMP VLCControl2::put_Visible(VARIANT_BOOL isVisible)
2776 _p_instance->setVisible(isVisible != VARIANT_FALSE);
2781 STDMETHODIMP VLCControl2::get_Volume(long *volume)
2783 if( NULL == volume )
2786 *volume = _p_instance->getVolume();
2790 STDMETHODIMP VLCControl2::put_Volume(long volume)
2792 _p_instance->setVolume(volume);
2796 STDMETHODIMP VLCControl2::get_BackColor(OLE_COLOR *backcolor)
2798 if( NULL == backcolor )
2801 *backcolor = _p_instance->getBackColor();
2805 STDMETHODIMP VLCControl2::put_BackColor(OLE_COLOR backcolor)
2807 _p_instance->setBackColor(backcolor);
2811 STDMETHODIMP VLCControl2::get_audio(IVLCAudio** obj)
2817 if( NULL != _p_vlcaudio )
2819 _p_vlcaudio->AddRef();
2822 return E_OUTOFMEMORY;
2825 STDMETHODIMP VLCControl2::get_input(IVLCInput** obj)
2831 if( NULL != _p_vlcinput )
2833 _p_vlcinput->AddRef();
2836 return E_OUTOFMEMORY;
2839 STDMETHODIMP VLCControl2::get_log(IVLCLog** obj)
2845 if( NULL != _p_vlclog )
2847 _p_vlclog->AddRef();
2850 return E_OUTOFMEMORY;
2853 STDMETHODIMP VLCControl2::get_playlist(IVLCPlaylist** obj)
2858 *obj = _p_vlcplaylist;
2859 if( NULL != _p_vlcplaylist )
2861 _p_vlcplaylist->AddRef();
2864 return E_OUTOFMEMORY;
2867 STDMETHODIMP VLCControl2::get_video(IVLCVideo** obj)
2873 if( NULL != _p_vlcvideo )
2875 _p_vlcvideo->AddRef();
2878 return E_OUTOFMEMORY;