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"
40 _p_typeinfo->Release();
43 HRESULT VLCAudio::loadTypeInfo(void)
46 if( NULL == _p_typeinfo )
50 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
53 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCAudio, &_p_typeinfo);
64 STDMETHODIMP VLCAudio::GetTypeInfoCount(UINT* pctInfo)
69 if( SUCCEEDED(loadTypeInfo()) )
77 STDMETHODIMP VLCAudio::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
82 if( SUCCEEDED(loadTypeInfo()) )
84 _p_typeinfo->AddRef();
85 *ppTInfo = _p_typeinfo;
92 STDMETHODIMP VLCAudio::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
93 UINT cNames, LCID lcid, DISPID* rgDispID)
95 if( SUCCEEDED(loadTypeInfo()) )
97 return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
102 STDMETHODIMP VLCAudio::Invoke(DISPID dispIdMember, REFIID riid,
103 LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
104 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
106 if( SUCCEEDED(loadTypeInfo()) )
108 return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
109 pVarResult, pExcepInfo, puArgErr);
114 STDMETHODIMP VLCAudio::get_mute(VARIANT_BOOL* mute)
119 libvlc_instance_t* p_libvlc;
120 HRESULT hr = _p_instance->getVLC(&p_libvlc);
123 libvlc_exception_t ex;
124 libvlc_exception_init(&ex);
126 *mute = libvlc_audio_get_mute(p_libvlc, &ex) ?
127 VARIANT_TRUE : VARIANT_FALSE;
128 if( libvlc_exception_raised(&ex) )
130 _p_instance->setErrorInfo(IID_IVLCAudio,
131 libvlc_exception_get_message(&ex));
132 libvlc_exception_clear(&ex);
140 STDMETHODIMP VLCAudio::put_mute(VARIANT_BOOL mute)
142 libvlc_instance_t* p_libvlc;
143 HRESULT hr = _p_instance->getVLC(&p_libvlc);
146 libvlc_exception_t ex;
147 libvlc_exception_init(&ex);
149 libvlc_audio_set_mute(p_libvlc, VARIANT_FALSE != mute, &ex);
150 if( libvlc_exception_raised(&ex) )
152 _p_instance->setErrorInfo(IID_IVLCAudio,
153 libvlc_exception_get_message(&ex));
154 libvlc_exception_clear(&ex);
162 STDMETHODIMP VLCAudio::get_volume(long* volume)
167 libvlc_instance_t* p_libvlc;
168 HRESULT hr = _p_instance->getVLC(&p_libvlc);
171 libvlc_exception_t ex;
172 libvlc_exception_init(&ex);
174 *volume = libvlc_audio_get_volume(p_libvlc, &ex);
175 if( libvlc_exception_raised(&ex) )
177 _p_instance->setErrorInfo(IID_IVLCAudio,
178 libvlc_exception_get_message(&ex));
179 libvlc_exception_clear(&ex);
187 STDMETHODIMP VLCAudio::put_volume(long volume)
189 libvlc_instance_t* p_libvlc;
190 HRESULT hr = _p_instance->getVLC(&p_libvlc);
193 libvlc_exception_t ex;
194 libvlc_exception_init(&ex);
196 libvlc_audio_set_volume(p_libvlc, volume, &ex);
197 if( libvlc_exception_raised(&ex) )
199 _p_instance->setErrorInfo(IID_IVLCAudio,
200 libvlc_exception_get_message(&ex));
201 libvlc_exception_clear(&ex);
209 STDMETHODIMP VLCAudio::get_track(long* track)
214 libvlc_media_player_t* p_md;
215 HRESULT hr = _p_instance->getMD(&p_md);
218 libvlc_exception_t ex;
219 libvlc_exception_init(&ex);
221 *track = libvlc_audio_get_track(p_md, &ex);
222 if( libvlc_exception_raised(&ex) )
224 _p_instance->setErrorInfo(IID_IVLCAudio,
225 libvlc_exception_get_message(&ex));
226 libvlc_exception_clear(&ex);
234 STDMETHODIMP VLCAudio::put_track(long track)
236 libvlc_media_player_t *p_md;
237 HRESULT hr = _p_instance->getMD(&p_md);
240 libvlc_exception_t ex;
241 libvlc_exception_init(&ex);
243 libvlc_audio_set_track(p_md, track, &ex);
244 if( libvlc_exception_raised(&ex) )
246 _p_instance->setErrorInfo(IID_IVLCAudio,
247 libvlc_exception_get_message(&ex));
248 libvlc_exception_clear(&ex);
256 STDMETHODIMP VLCAudio::get_channel(long *channel)
258 if( NULL == channel )
261 libvlc_instance_t* p_libvlc;
262 HRESULT hr = _p_instance->getVLC(&p_libvlc);
265 libvlc_exception_t ex;
266 libvlc_exception_init(&ex);
268 *channel = libvlc_audio_get_channel(p_libvlc, &ex);
269 if( libvlc_exception_raised(&ex) )
271 _p_instance->setErrorInfo(IID_IVLCAudio,
272 libvlc_exception_get_message(&ex));
273 libvlc_exception_clear(&ex);
281 STDMETHODIMP VLCAudio::put_channel(long channel)
283 libvlc_instance_t* p_libvlc;
284 HRESULT hr = _p_instance->getVLC(&p_libvlc);
287 libvlc_exception_t ex;
288 libvlc_exception_init(&ex);
290 libvlc_audio_set_channel(p_libvlc, channel, &ex);
291 if( libvlc_exception_raised(&ex) )
293 _p_instance->setErrorInfo(IID_IVLCAudio,
294 libvlc_exception_get_message(&ex));
295 libvlc_exception_clear(&ex);
303 STDMETHODIMP VLCAudio::toggleMute()
305 libvlc_instance_t* p_libvlc;
306 HRESULT hr = _p_instance->getVLC(&p_libvlc);
309 libvlc_exception_t ex;
310 libvlc_exception_init(&ex);
312 libvlc_audio_toggle_mute(p_libvlc, &ex);
313 if( libvlc_exception_raised(&ex) )
315 _p_instance->setErrorInfo(IID_IVLCAudio,
316 libvlc_exception_get_message(&ex));
317 libvlc_exception_clear(&ex);
325 /*******************************************************************************/
327 VLCInput::~VLCInput()
330 _p_typeinfo->Release();
333 HRESULT VLCInput::loadTypeInfo(void)
335 HRESULT hr = NOERROR;
336 if( NULL == _p_typeinfo )
340 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
343 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCInput, &_p_typeinfo);
348 p_typelib->Release();
354 STDMETHODIMP VLCInput::GetTypeInfoCount(UINT* pctInfo)
356 if( NULL == pctInfo )
359 if( SUCCEEDED(loadTypeInfo()) )
367 STDMETHODIMP VLCInput::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
369 if( NULL == ppTInfo )
372 if( SUCCEEDED(loadTypeInfo()) )
374 _p_typeinfo->AddRef();
375 *ppTInfo = _p_typeinfo;
382 STDMETHODIMP VLCInput::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
383 UINT cNames, LCID lcid, DISPID* rgDispID)
385 if( SUCCEEDED(loadTypeInfo()) )
387 return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
392 STDMETHODIMP VLCInput::Invoke(DISPID dispIdMember, REFIID riid,
393 LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
394 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
396 if( SUCCEEDED(loadTypeInfo()) )
398 return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
399 pVarResult, pExcepInfo, puArgErr);
404 STDMETHODIMP VLCInput::get_length(double* length)
410 libvlc_media_player_t *p_md;
411 HRESULT hr = _p_instance->getMD(&p_md);
414 libvlc_exception_t ex;
415 libvlc_exception_init(&ex);
417 *length = (double)libvlc_media_player_get_length(p_md, &ex);
418 if( ! libvlc_exception_raised(&ex) )
422 _p_instance->setErrorInfo(IID_IVLCInput,
423 libvlc_exception_get_message(&ex));
424 libvlc_exception_clear(&ex);
430 STDMETHODIMP VLCInput::get_position(double* position)
432 if( NULL == position )
436 libvlc_media_player_t *p_md;
437 HRESULT hr = _p_instance->getMD(&p_md);
440 libvlc_exception_t ex;
441 libvlc_exception_init(&ex);
443 *position = libvlc_media_player_get_position(p_md, &ex);
444 if( ! libvlc_exception_raised(&ex) )
448 _p_instance->setErrorInfo(IID_IVLCInput,
449 libvlc_exception_get_message(&ex));
450 libvlc_exception_clear(&ex);
456 STDMETHODIMP VLCInput::put_position(double position)
458 libvlc_media_player_t *p_md;
459 HRESULT hr = _p_instance->getMD(&p_md);
462 libvlc_exception_t ex;
463 libvlc_exception_init(&ex);
465 libvlc_media_player_set_position(p_md, position, &ex);
466 if( ! libvlc_exception_raised(&ex) )
470 _p_instance->setErrorInfo(IID_IVLCInput,
471 libvlc_exception_get_message(&ex));
472 libvlc_exception_clear(&ex);
478 STDMETHODIMP VLCInput::get_time(double* time)
483 libvlc_media_player_t *p_md;
484 HRESULT hr = _p_instance->getMD(&p_md);
487 libvlc_exception_t ex;
488 libvlc_exception_init(&ex);
490 *time = (double)libvlc_media_player_get_time(p_md, &ex);
491 if( ! libvlc_exception_raised(&ex) )
495 _p_instance->setErrorInfo(IID_IVLCInput,
496 libvlc_exception_get_message(&ex));
497 libvlc_exception_clear(&ex);
503 STDMETHODIMP VLCInput::put_time(double time)
505 libvlc_media_player_t *p_md;
506 HRESULT hr = _p_instance->getMD(&p_md);
509 libvlc_exception_t ex;
510 libvlc_exception_init(&ex);
512 libvlc_media_player_set_time(p_md, (int64_t)time, &ex);
513 if( ! libvlc_exception_raised(&ex) )
517 _p_instance->setErrorInfo(IID_IVLCInput,
518 libvlc_exception_get_message(&ex));
519 libvlc_exception_clear(&ex);
525 STDMETHODIMP VLCInput::get_state(long* state)
530 libvlc_media_player_t *p_md;
531 HRESULT hr = _p_instance->getMD(&p_md);
534 libvlc_exception_t ex;
535 libvlc_exception_init(&ex);
537 *state = libvlc_media_player_get_state(p_md, &ex);
538 if( ! libvlc_exception_raised(&ex) )
542 libvlc_exception_clear(&ex);
543 // don't fail, just return the idle state
550 STDMETHODIMP VLCInput::get_rate(double* rate)
555 libvlc_media_player_t *p_md;
556 HRESULT hr = _p_instance->getMD(&p_md);
559 libvlc_exception_t ex;
560 libvlc_exception_init(&ex);
562 *rate = libvlc_media_player_get_rate(p_md, &ex);
563 if( ! libvlc_exception_raised(&ex) )
567 _p_instance->setErrorInfo(IID_IVLCInput,
568 libvlc_exception_get_message(&ex));
569 libvlc_exception_clear(&ex);
575 STDMETHODIMP VLCInput::put_rate(double rate)
577 libvlc_media_player_t *p_md;
578 HRESULT hr = _p_instance->getMD(&p_md);
581 libvlc_exception_t ex;
582 libvlc_exception_init(&ex);
584 libvlc_media_player_set_rate(p_md, rate, &ex);
585 if( ! libvlc_exception_raised(&ex) )
589 _p_instance->setErrorInfo(IID_IVLCInput,
590 libvlc_exception_get_message(&ex));
591 libvlc_exception_clear(&ex);
597 STDMETHODIMP VLCInput::get_fps(double* fps)
603 libvlc_media_player_t *p_md;
604 HRESULT hr = _p_instance->getMD(&p_md);
607 libvlc_exception_t ex;
608 libvlc_exception_init(&ex);
610 *fps = libvlc_media_player_get_fps(p_md, &ex);
611 if( ! libvlc_exception_raised(&ex) )
615 _p_instance->setErrorInfo(IID_IVLCInput,
616 libvlc_exception_get_message(&ex));
617 libvlc_exception_clear(&ex);
623 STDMETHODIMP VLCInput::get_hasVout(VARIANT_BOOL* hasVout)
625 if( NULL == hasVout )
628 libvlc_media_player_t *p_md;
629 HRESULT hr = _p_instance->getMD(&p_md);
632 libvlc_exception_t ex;
633 libvlc_exception_init(&ex);
635 *hasVout = libvlc_media_player_has_vout(p_md, &ex) ?
636 VARIANT_TRUE : VARIANT_FALSE;
637 if( ! libvlc_exception_raised(&ex) )
641 _p_instance->setErrorInfo(IID_IVLCInput,
642 libvlc_exception_get_message(&ex));
643 libvlc_exception_clear(&ex);
649 /*******************************************************************************/
653 delete _p_vlcmessages;
655 libvlc_log_close(_p_log, NULL);
658 _p_typeinfo->Release();
661 HRESULT VLCLog::loadTypeInfo(void)
663 HRESULT hr = NOERROR;
664 if( NULL == _p_typeinfo )
668 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
671 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCLog, &_p_typeinfo);
676 p_typelib->Release();
682 STDMETHODIMP VLCLog::GetTypeInfoCount(UINT* pctInfo)
684 if( NULL == pctInfo )
687 if( SUCCEEDED(loadTypeInfo()) )
695 STDMETHODIMP VLCLog::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
697 if( NULL == ppTInfo )
700 if( SUCCEEDED(loadTypeInfo()) )
702 _p_typeinfo->AddRef();
703 *ppTInfo = _p_typeinfo;
710 STDMETHODIMP VLCLog::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
711 UINT cNames, LCID lcid, DISPID* rgDispID)
713 if( SUCCEEDED(loadTypeInfo()) )
715 return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
720 STDMETHODIMP VLCLog::Invoke(DISPID dispIdMember, REFIID riid,
721 LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
722 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
724 if( SUCCEEDED(loadTypeInfo()) )
726 return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
727 pVarResult, pExcepInfo, puArgErr);
732 STDMETHODIMP VLCLog::get_messages(IVLCMessages** obj)
737 *obj = _p_vlcmessages;
738 if( NULL != _p_vlcmessages )
740 _p_vlcmessages->AddRef();
743 return E_OUTOFMEMORY;
746 STDMETHODIMP VLCLog::get_verbosity(long* level)
753 libvlc_instance_t* p_libvlc;
754 HRESULT hr = _p_instance->getVLC(&p_libvlc);
757 libvlc_exception_t ex;
758 libvlc_exception_init(&ex);
760 *level = libvlc_get_log_verbosity(p_libvlc, &ex);
761 if( libvlc_exception_raised(&ex) )
763 _p_instance->setErrorInfo(IID_IVLCLog,
764 libvlc_exception_get_message(&ex));
765 libvlc_exception_clear(&ex);
773 /* log is not enabled, return -1 */
779 STDMETHODIMP VLCLog::put_verbosity(long verbosity)
781 libvlc_exception_t ex;
782 libvlc_exception_init(&ex);
784 libvlc_instance_t* p_libvlc;
785 HRESULT hr = _p_instance->getVLC(&p_libvlc);
792 _p_log = libvlc_log_open(p_libvlc, &ex);
793 if( libvlc_exception_raised(&ex) )
795 _p_instance->setErrorInfo(IID_IVLCLog,
796 libvlc_exception_get_message(&ex));
797 libvlc_exception_clear(&ex);
801 libvlc_set_log_verbosity(p_libvlc, (unsigned)verbosity, &ex);
802 if( libvlc_exception_raised(&ex) )
804 _p_instance->setErrorInfo(IID_IVLCLog,
805 libvlc_exception_get_message(&ex));
806 libvlc_exception_clear(&ex);
812 /* close log when verbosity is set to -1 */
813 libvlc_log_close(_p_log, &ex);
815 if( libvlc_exception_raised(&ex) )
817 _p_instance->setErrorInfo(IID_IVLCLog,
818 libvlc_exception_get_message(&ex));
819 libvlc_exception_clear(&ex);
827 /*******************************************************************************/
829 /* STL forward iterator used by VLCEnumIterator class to implement IEnumVARIANT */
831 class VLCMessageSTLIterator
836 VLCMessageSTLIterator(IVLCMessageIterator* iter) : iter(iter), msg(NULL)
842 VLCMessageSTLIterator(const VLCMessageSTLIterator& other)
852 virtual ~VLCMessageSTLIterator()
861 // we only need prefix ++ operator
862 VLCMessageSTLIterator& operator++()
864 VARIANT_BOOL hasNext = VARIANT_FALSE;
867 iter->get_hasNext(&hasNext);
874 if( VARIANT_TRUE == hasNext ) {
881 VARIANT operator*() const
887 if( SUCCEEDED(msg->QueryInterface(IID_IDispatch,
888 (LPVOID*)&V_DISPATCH(&v))) )
890 V_VT(&v) = VT_DISPATCH;
896 bool operator==(const VLCMessageSTLIterator& other) const
898 return msg == other.msg;
901 bool operator!=(const VLCMessageSTLIterator& other) const
903 return msg != other.msg;
907 IVLCMessageIterator* iter;
911 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
913 VLCMessages::~VLCMessages()
916 _p_typeinfo->Release();
919 HRESULT VLCMessages::loadTypeInfo(void)
921 HRESULT hr = NOERROR;
922 if( NULL == _p_typeinfo )
926 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
929 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCMessages, &_p_typeinfo);
934 p_typelib->Release();
940 STDMETHODIMP VLCMessages::GetTypeInfoCount(UINT* pctInfo)
942 if( NULL == pctInfo )
945 if( SUCCEEDED(loadTypeInfo()) )
953 STDMETHODIMP VLCMessages::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
955 if( NULL == ppTInfo )
958 if( SUCCEEDED(loadTypeInfo()) )
960 _p_typeinfo->AddRef();
961 *ppTInfo = _p_typeinfo;
968 STDMETHODIMP VLCMessages::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
969 UINT cNames, LCID lcid, DISPID* rgDispID)
971 if( SUCCEEDED(loadTypeInfo()) )
973 return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
978 STDMETHODIMP VLCMessages::Invoke(DISPID dispIdMember, REFIID riid,
979 LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
980 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
982 if( SUCCEEDED(loadTypeInfo()) )
984 return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
985 pVarResult, pExcepInfo, puArgErr);
990 STDMETHODIMP VLCMessages::get__NewEnum(LPUNKNOWN* _NewEnum)
992 if( NULL == _NewEnum )
995 IVLCMessageIterator* iter = NULL;
998 *_NewEnum= new VLCEnumIterator<IID_IEnumVARIANT,
1001 VLCMessageSTLIterator>
1002 (VLCMessageSTLIterator(iter), VLCMessageSTLIterator(NULL));
1004 return *_NewEnum ? S_OK : E_OUTOFMEMORY;
1007 STDMETHODIMP VLCMessages::clear()
1009 libvlc_log_t *p_log = _p_vlclog->_p_log;
1012 libvlc_exception_t ex;
1013 libvlc_exception_init(&ex);
1015 libvlc_log_clear(p_log, &ex);
1016 if( libvlc_exception_raised(&ex) )
1018 _p_instance->setErrorInfo(IID_IVLCMessages,
1019 libvlc_exception_get_message(&ex));
1020 libvlc_exception_clear(&ex);
1027 STDMETHODIMP VLCMessages::get_count(long* count)
1032 libvlc_log_t *p_log = _p_vlclog->_p_log;
1035 libvlc_exception_t ex;
1036 libvlc_exception_init(&ex);
1038 *count = libvlc_log_count(p_log, &ex);
1039 if( libvlc_exception_raised(&ex) )
1041 _p_instance->setErrorInfo(IID_IVLCMessages,
1042 libvlc_exception_get_message(&ex));
1043 libvlc_exception_clear(&ex);
1052 STDMETHODIMP VLCMessages::iterator(IVLCMessageIterator** iter)
1057 *iter = new VLCMessageIterator(_p_instance, _p_vlclog);
1059 return *iter ? S_OK : E_OUTOFMEMORY;
1062 /*******************************************************************************/
1064 VLCMessageIterator::VLCMessageIterator(VLCPlugin *p_instance, VLCLog* p_vlclog ) :
1065 _p_instance(p_instance),
1070 if( p_vlclog->_p_log )
1072 _p_iter = libvlc_log_get_iterator(p_vlclog->_p_log, NULL);
1078 VLCMessageIterator::~VLCMessageIterator()
1081 libvlc_log_iterator_free(_p_iter, NULL);
1084 _p_typeinfo->Release();
1087 HRESULT VLCMessageIterator::loadTypeInfo(void)
1089 HRESULT hr = NOERROR;
1090 if( NULL == _p_typeinfo )
1092 ITypeLib *p_typelib;
1094 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
1097 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCMessageIterator, &_p_typeinfo);
1102 p_typelib->Release();
1108 STDMETHODIMP VLCMessageIterator::GetTypeInfoCount(UINT* pctInfo)
1110 if( NULL == pctInfo )
1111 return E_INVALIDARG;
1113 if( SUCCEEDED(loadTypeInfo()) )
1121 STDMETHODIMP VLCMessageIterator::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
1123 if( NULL == ppTInfo )
1124 return E_INVALIDARG;
1126 if( SUCCEEDED(loadTypeInfo()) )
1128 _p_typeinfo->AddRef();
1129 *ppTInfo = _p_typeinfo;
1136 STDMETHODIMP VLCMessageIterator::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
1137 UINT cNames, LCID lcid, DISPID* rgDispID)
1139 if( SUCCEEDED(loadTypeInfo()) )
1141 return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
1146 STDMETHODIMP VLCMessageIterator::Invoke(DISPID dispIdMember, REFIID riid,
1147 LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
1148 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
1150 if( SUCCEEDED(loadTypeInfo()) )
1152 return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
1153 pVarResult, pExcepInfo, puArgErr);
1158 STDMETHODIMP VLCMessageIterator::get_hasNext(VARIANT_BOOL* hasNext)
1160 if( NULL == hasNext )
1163 if( _p_iter && _p_vlclog->_p_log )
1165 libvlc_exception_t ex;
1166 libvlc_exception_init(&ex);
1168 *hasNext = libvlc_log_iterator_has_next(_p_iter, &ex) ?
1169 VARIANT_TRUE : VARIANT_FALSE;
1170 if( libvlc_exception_raised(&ex) )
1172 _p_instance->setErrorInfo(IID_IVLCMessageIterator,
1173 libvlc_exception_get_message(&ex));
1174 libvlc_exception_clear(&ex);
1180 *hasNext = VARIANT_FALSE;
1185 STDMETHODIMP VLCMessageIterator::next(IVLCMessage** message)
1187 if( NULL == message )
1190 if( _p_iter && _p_vlclog->_p_log )
1192 struct libvlc_log_message_t buffer;
1194 buffer.sizeof_msg = sizeof(buffer);
1196 libvlc_exception_t ex;
1197 libvlc_exception_init(&ex);
1199 libvlc_log_iterator_next(_p_iter, &buffer, &ex);
1200 if( libvlc_exception_raised(&ex) )
1202 _p_instance->setErrorInfo(IID_IVLCMessageIterator,
1203 libvlc_exception_get_message(&ex));
1204 libvlc_exception_clear(&ex);
1207 *message = new VLCMessage(_p_instance, buffer);
1208 return *message ? NOERROR : E_OUTOFMEMORY;
1213 /*******************************************************************************/
1215 VLCMessage::~VLCMessage()
1218 _p_typeinfo->Release();
1221 HRESULT VLCMessage::loadTypeInfo(void)
1223 HRESULT hr = NOERROR;
1224 if( NULL == _p_typeinfo )
1226 ITypeLib *p_typelib;
1228 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
1231 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCMessage, &_p_typeinfo);
1236 p_typelib->Release();
1242 STDMETHODIMP VLCMessage::GetTypeInfoCount(UINT* pctInfo)
1244 if( NULL == pctInfo )
1245 return E_INVALIDARG;
1247 if( SUCCEEDED(loadTypeInfo()) )
1255 STDMETHODIMP VLCMessage::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
1257 if( NULL == ppTInfo )
1258 return E_INVALIDARG;
1260 if( SUCCEEDED(loadTypeInfo()) )
1262 _p_typeinfo->AddRef();
1263 *ppTInfo = _p_typeinfo;
1270 STDMETHODIMP VLCMessage::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
1271 UINT cNames, LCID lcid, DISPID* rgDispID)
1273 if( SUCCEEDED(loadTypeInfo()) )
1275 return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
1280 STDMETHODIMP VLCMessage::Invoke(DISPID dispIdMember, REFIID riid,
1281 LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
1282 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
1284 if( SUCCEEDED(loadTypeInfo()) )
1286 return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
1287 pVarResult, pExcepInfo, puArgErr);
1292 inline const char *msgSeverity(int sev)
1307 STDMETHODIMP VLCMessage::get__Value(VARIANT* _Value)
1309 if( NULL == _Value )
1314 snprintf(buffer, sizeof(buffer), "%s %s %s: %s",
1315 _msg.psz_type, _msg.psz_name, msgSeverity(_msg.i_severity), _msg.psz_message);
1317 V_VT(_Value) = VT_BSTR;
1318 V_BSTR(_Value) = BSTRFromCStr(CP_UTF8, buffer);
1323 STDMETHODIMP VLCMessage::get_severity(long* level)
1328 *level = _msg.i_severity;
1333 STDMETHODIMP VLCMessage::get_type(BSTR* type)
1338 *type = BSTRFromCStr(CP_UTF8, _msg.psz_type);
1343 STDMETHODIMP VLCMessage::get_name(BSTR* name)
1348 *name = BSTRFromCStr(CP_UTF8, _msg.psz_name);
1353 STDMETHODIMP VLCMessage::get_header(BSTR* header)
1355 if( NULL == header )
1358 *header = BSTRFromCStr(CP_UTF8, _msg.psz_header);
1363 STDMETHODIMP VLCMessage::get_message(BSTR* message)
1365 if( NULL == message )
1368 *message = BSTRFromCStr(CP_UTF8, _msg.psz_message);
1373 /*******************************************************************************/
1375 VLCPlaylistItems::~VLCPlaylistItems()
1378 _p_typeinfo->Release();
1381 HRESULT VLCPlaylistItems::loadTypeInfo(void)
1383 HRESULT hr = NOERROR;
1384 if( NULL == _p_typeinfo )
1386 ITypeLib *p_typelib;
1388 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
1391 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCPlaylistItems, &_p_typeinfo);
1396 p_typelib->Release();
1402 STDMETHODIMP VLCPlaylistItems::GetTypeInfoCount(UINT* pctInfo)
1404 if( NULL == pctInfo )
1405 return E_INVALIDARG;
1407 if( SUCCEEDED(loadTypeInfo()) )
1415 STDMETHODIMP VLCPlaylistItems::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
1417 if( NULL == ppTInfo )
1418 return E_INVALIDARG;
1420 if( SUCCEEDED(loadTypeInfo()) )
1422 _p_typeinfo->AddRef();
1423 *ppTInfo = _p_typeinfo;
1430 STDMETHODIMP VLCPlaylistItems::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
1431 UINT cNames, LCID lcid, DISPID* rgDispID)
1433 if( SUCCEEDED(loadTypeInfo()) )
1435 return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
1440 STDMETHODIMP VLCPlaylistItems::Invoke(DISPID dispIdMember, REFIID riid,
1441 LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
1442 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
1444 if( SUCCEEDED(loadTypeInfo()) )
1446 return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
1447 pVarResult, pExcepInfo, puArgErr);
1452 STDMETHODIMP VLCPlaylistItems::get_count(long* count)
1457 libvlc_exception_t ex;
1458 libvlc_exception_init(&ex);
1460 *count = _p_instance->playlist_count(&ex);
1461 if( libvlc_exception_raised(&ex) )
1463 _p_instance->setErrorInfo(IID_IVLCPlaylistItems,
1464 libvlc_exception_get_message(&ex));
1465 libvlc_exception_clear(&ex);
1471 STDMETHODIMP VLCPlaylistItems::clear()
1473 libvlc_instance_t* p_libvlc;
1474 HRESULT hr = _p_instance->getVLC(&p_libvlc);
1477 libvlc_exception_t ex;
1478 libvlc_exception_init(&ex);
1480 _p_instance->playlist_clear(&ex);
1481 if( libvlc_exception_raised(&ex) )
1483 _p_instance->setErrorInfo(IID_IVLCPlaylistItems,
1484 libvlc_exception_get_message(&ex));
1485 libvlc_exception_clear(&ex);
1493 STDMETHODIMP VLCPlaylistItems::remove(long item)
1495 libvlc_instance_t* p_libvlc;
1496 HRESULT hr = _p_instance->getVLC(&p_libvlc);
1499 libvlc_exception_t ex;
1500 libvlc_exception_init(&ex);
1502 _p_instance->playlist_delete_item(item, &ex);
1503 if( libvlc_exception_raised(&ex) )
1505 _p_instance->setErrorInfo(IID_IVLCPlaylistItems,
1506 libvlc_exception_get_message(&ex));
1507 libvlc_exception_clear(&ex);
1515 /*******************************************************************************/
1517 VLCPlaylist::~VLCPlaylist()
1519 delete _p_vlcplaylistitems;
1521 _p_typeinfo->Release();
1524 HRESULT VLCPlaylist::loadTypeInfo(void)
1526 HRESULT hr = NOERROR;
1527 if( NULL == _p_typeinfo )
1529 ITypeLib *p_typelib;
1531 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
1534 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCPlaylist, &_p_typeinfo);
1539 p_typelib->Release();
1545 STDMETHODIMP VLCPlaylist::GetTypeInfoCount(UINT* pctInfo)
1547 if( NULL == pctInfo )
1548 return E_INVALIDARG;
1550 if( SUCCEEDED(loadTypeInfo()) )
1558 STDMETHODIMP VLCPlaylist::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
1560 if( NULL == ppTInfo )
1561 return E_INVALIDARG;
1563 if( SUCCEEDED(loadTypeInfo()) )
1565 _p_typeinfo->AddRef();
1566 *ppTInfo = _p_typeinfo;
1573 STDMETHODIMP VLCPlaylist::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
1574 UINT cNames, LCID lcid, DISPID* rgDispID)
1576 if( SUCCEEDED(loadTypeInfo()) )
1578 return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
1583 STDMETHODIMP VLCPlaylist::Invoke(DISPID dispIdMember, REFIID riid,
1584 LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
1585 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
1587 if( SUCCEEDED(loadTypeInfo()) )
1589 return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
1590 pVarResult, pExcepInfo, puArgErr);
1595 STDMETHODIMP VLCPlaylist::get_itemCount(long* count)
1601 libvlc_exception_t ex;
1602 libvlc_exception_init(&ex);
1604 *count = _p_instance->playlist_count(&ex);
1605 if( libvlc_exception_raised(&ex) )
1607 _p_instance->setErrorInfo(IID_IVLCPlaylist,
1608 libvlc_exception_get_message(&ex));
1609 libvlc_exception_clear(&ex);
1615 STDMETHODIMP VLCPlaylist::get_isPlaying(VARIANT_BOOL* isPlaying)
1617 if( NULL == isPlaying )
1620 libvlc_media_player_t *p_md;
1621 HRESULT hr = _p_instance->getMD(&p_md);
1624 libvlc_exception_t ex;
1625 libvlc_exception_init(&ex);
1627 *isPlaying = libvlc_media_player_is_playing(p_md, &ex) ?
1628 VARIANT_TRUE: VARIANT_FALSE;
1629 if( libvlc_exception_raised(&ex) )
1631 _p_instance->setErrorInfo(IID_IVLCPlaylist,
1632 libvlc_exception_get_message(&ex));
1633 libvlc_exception_clear(&ex);
1641 STDMETHODIMP VLCPlaylist::add(BSTR uri, VARIANT name, VARIANT options, long* item)
1646 if( 0 == SysStringLen(uri) )
1647 return E_INVALIDARG;
1649 libvlc_instance_t* p_libvlc;
1650 HRESULT hr = _p_instance->getVLC(&p_libvlc);
1653 libvlc_exception_t ex;
1654 libvlc_exception_init(&ex);
1656 char *psz_uri = NULL;
1657 if( SysStringLen(_p_instance->getBaseURL()) > 0 )
1660 ** if the MRL a relative URL, we should end up with an absolute URL
1662 LPWSTR abs_url = CombineURL(_p_instance->getBaseURL(), uri);
1663 if( NULL != abs_url )
1665 psz_uri = CStrFromWSTR(CP_UTF8, abs_url, wcslen(abs_url));
1666 CoTaskMemFree(abs_url);
1670 psz_uri = CStrFromBSTR(CP_UTF8, uri);
1676 ** baseURL is empty, assume MRL is absolute
1678 psz_uri = CStrFromBSTR(CP_UTF8, uri);
1681 if( NULL == psz_uri )
1683 return E_OUTOFMEMORY;
1687 char **ppsz_options;
1689 hr = VLCControl::CreateTargetOptions(CP_UTF8, &options, &ppsz_options, &i_options);
1692 CoTaskMemFree(psz_uri);
1696 char *psz_name = NULL;
1698 VariantInit(&v_name);
1699 if( SUCCEEDED(VariantChangeType(&v_name, &name, 0, VT_BSTR)) )
1701 if( SysStringLen(V_BSTR(&v_name)) > 0 )
1702 psz_name = CStrFromBSTR(CP_UTF8, V_BSTR(&v_name));
1704 VariantClear(&v_name);
1707 *item = _p_instance->playlist_add_extended_untrusted(psz_uri,
1708 i_options, const_cast<const char **>(ppsz_options), &ex);
1710 VLCControl::FreeTargetOptions(ppsz_options, i_options);
1711 CoTaskMemFree(psz_uri);
1713 CoTaskMemFree(psz_name);
1714 if( libvlc_exception_raised(&ex) )
1716 _p_instance->setErrorInfo(IID_IVLCPlaylist,
1717 libvlc_exception_get_message(&ex));
1718 libvlc_exception_clear(&ex);
1726 STDMETHODIMP VLCPlaylist::play()
1728 libvlc_exception_t ex;
1729 libvlc_exception_init(&ex);
1731 _p_instance->playlist_play(&ex);
1732 if( libvlc_exception_raised(&ex) )
1734 libvlc_exception_clear(&ex);
1740 STDMETHODIMP VLCPlaylist::playItem(long item)
1742 libvlc_exception_t ex;
1743 libvlc_exception_init(&ex);
1745 _p_instance->playlist_play_item(item,&ex);
1746 if( libvlc_exception_raised(&ex) )
1748 _p_instance->setErrorInfo(IID_IVLCPlaylist,
1749 libvlc_exception_get_message(&ex));
1750 libvlc_exception_clear(&ex);
1756 STDMETHODIMP VLCPlaylist::togglePause()
1758 libvlc_media_player_t* p_md;
1759 HRESULT hr = _p_instance->getMD(&p_md);
1762 libvlc_exception_t ex;
1763 libvlc_exception_init(&ex);
1765 libvlc_media_player_pause(p_md, &ex);
1766 if( libvlc_exception_raised(&ex) )
1768 _p_instance->setErrorInfo(IID_IVLCPlaylist,
1769 libvlc_exception_get_message(&ex));
1770 libvlc_exception_clear(&ex);
1778 STDMETHODIMP VLCPlaylist::stop()
1780 libvlc_media_player_t *p_md;
1781 HRESULT hr = _p_instance->getMD(&p_md);
1784 libvlc_exception_t ex;
1785 libvlc_exception_init(&ex);
1787 libvlc_media_player_stop(p_md, &ex);
1788 if( libvlc_exception_raised(&ex) )
1790 _p_instance->setErrorInfo(IID_IVLCPlaylist,
1791 libvlc_exception_get_message(&ex));
1792 libvlc_exception_clear(&ex);
1800 STDMETHODIMP VLCPlaylist::next()
1802 libvlc_exception_t ex;
1803 libvlc_exception_init(&ex);
1805 _p_instance->playlist_next(&ex);
1806 if( libvlc_exception_raised(&ex) )
1808 _p_instance->setErrorInfo(IID_IVLCPlaylist,
1809 libvlc_exception_get_message(&ex));
1810 libvlc_exception_clear(&ex);
1816 STDMETHODIMP VLCPlaylist::prev()
1818 libvlc_exception_t ex;
1819 libvlc_exception_init(&ex);
1821 _p_instance->playlist_prev(&ex);
1822 if( libvlc_exception_raised(&ex) )
1824 _p_instance->setErrorInfo(IID_IVLCPlaylist,
1825 libvlc_exception_get_message(&ex));
1826 libvlc_exception_clear(&ex);
1832 STDMETHODIMP VLCPlaylist::clear()
1834 libvlc_exception_t ex;
1835 libvlc_exception_init(&ex);
1837 _p_instance->playlist_clear(&ex);
1838 if( libvlc_exception_raised(&ex) )
1840 _p_instance->setErrorInfo(IID_IVLCPlaylist,
1841 libvlc_exception_get_message(&ex));
1842 libvlc_exception_clear(&ex);
1848 STDMETHODIMP VLCPlaylist::removeItem(long item)
1850 libvlc_instance_t* p_libvlc;
1851 HRESULT hr = _p_instance->getVLC(&p_libvlc);
1854 libvlc_exception_t ex;
1855 libvlc_exception_init(&ex);
1857 _p_instance->playlist_delete_item(item, &ex);
1858 if( libvlc_exception_raised(&ex) )
1860 _p_instance->setErrorInfo(IID_IVLCPlaylist,
1861 libvlc_exception_get_message(&ex));
1862 libvlc_exception_clear(&ex);
1870 STDMETHODIMP VLCPlaylist::get_items(IVLCPlaylistItems** obj)
1875 *obj = _p_vlcplaylistitems;
1876 if( NULL != _p_vlcplaylistitems )
1878 _p_vlcplaylistitems->AddRef();
1881 return E_OUTOFMEMORY;
1884 /*******************************************************************************/
1886 VLCVideo::~VLCVideo()
1889 _p_typeinfo->Release();
1892 HRESULT VLCVideo::loadTypeInfo(void)
1894 HRESULT hr = NOERROR;
1895 if( NULL == _p_typeinfo )
1897 ITypeLib *p_typelib;
1899 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
1902 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCVideo, &_p_typeinfo);
1907 p_typelib->Release();
1913 STDMETHODIMP VLCVideo::GetTypeInfoCount(UINT* pctInfo)
1915 if( NULL == pctInfo )
1916 return E_INVALIDARG;
1918 if( SUCCEEDED(loadTypeInfo()) )
1926 STDMETHODIMP VLCVideo::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
1928 if( NULL == ppTInfo )
1929 return E_INVALIDARG;
1931 if( SUCCEEDED(loadTypeInfo()) )
1933 _p_typeinfo->AddRef();
1934 *ppTInfo = _p_typeinfo;
1941 STDMETHODIMP VLCVideo::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
1942 UINT cNames, LCID lcid, DISPID* rgDispID)
1944 if( SUCCEEDED(loadTypeInfo()) )
1946 return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
1951 STDMETHODIMP VLCVideo::Invoke(DISPID dispIdMember, REFIID riid,
1952 LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
1953 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
1955 if( SUCCEEDED(loadTypeInfo()) )
1957 return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
1958 pVarResult, pExcepInfo, puArgErr);
1963 STDMETHODIMP VLCVideo::get_fullscreen(VARIANT_BOOL* fullscreen)
1965 if( NULL == fullscreen )
1968 libvlc_media_player_t *p_md;
1969 HRESULT hr = _p_instance->getMD(&p_md);
1972 libvlc_exception_t ex;
1973 libvlc_exception_init(&ex);
1975 *fullscreen = libvlc_get_fullscreen(p_md, &ex) ? VARIANT_TRUE : VARIANT_FALSE;
1976 if( ! libvlc_exception_raised(&ex) )
1980 _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
1981 libvlc_exception_clear(&ex);
1987 STDMETHODIMP VLCVideo::put_fullscreen(VARIANT_BOOL fullscreen)
1989 libvlc_media_player_t *p_md;
1990 HRESULT hr = _p_instance->getMD(&p_md);
1993 libvlc_exception_t ex;
1994 libvlc_exception_init(&ex);
1996 libvlc_set_fullscreen(p_md, VARIANT_FALSE != fullscreen, &ex);
1997 if( ! libvlc_exception_raised(&ex) )
2001 _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
2002 libvlc_exception_clear(&ex);
2008 STDMETHODIMP VLCVideo::get_width(long* width)
2013 libvlc_media_player_t *p_md;
2014 HRESULT hr = _p_instance->getMD(&p_md);
2017 libvlc_exception_t ex;
2018 libvlc_exception_init(&ex);
2020 *width = libvlc_video_get_width(p_md, &ex);
2021 if( ! libvlc_exception_raised(&ex) )
2025 _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
2026 libvlc_exception_clear(&ex);
2032 STDMETHODIMP VLCVideo::get_height(long* height)
2034 if( NULL == height )
2037 libvlc_media_player_t *p_md;
2038 HRESULT hr = _p_instance->getMD(&p_md);
2041 libvlc_exception_t ex;
2042 libvlc_exception_init(&ex);
2044 *height = libvlc_video_get_height(p_md, &ex);
2045 if( ! libvlc_exception_raised(&ex) )
2049 _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
2050 libvlc_exception_clear(&ex);
2056 STDMETHODIMP VLCVideo::get_aspectRatio(BSTR* aspect)
2058 if( NULL == aspect )
2061 libvlc_media_player_t *p_md;
2062 HRESULT hr = _p_instance->getMD(&p_md);
2065 libvlc_exception_t ex;
2066 libvlc_exception_init(&ex);
2068 char *psz_aspect = libvlc_video_get_aspect_ratio(p_md, &ex);
2070 if( ! libvlc_exception_raised(&ex) )
2072 if( NULL == psz_aspect )
2073 return E_OUTOFMEMORY;
2075 *aspect = BSTRFromCStr(CP_UTF8, psz_aspect);
2078 return (NULL == *aspect) ? E_OUTOFMEMORY : NOERROR;
2083 _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
2084 libvlc_exception_clear(&ex);
2090 STDMETHODIMP VLCVideo::put_aspectRatio(BSTR aspect)
2092 if( NULL == aspect )
2095 if( 0 == SysStringLen(aspect) )
2096 return E_INVALIDARG;
2098 libvlc_media_player_t *p_md;
2099 HRESULT hr = _p_instance->getMD(&p_md);
2102 libvlc_exception_t ex;
2103 libvlc_exception_init(&ex);
2105 char *psz_aspect = CStrFromBSTR(CP_UTF8, aspect);
2106 if( NULL == psz_aspect )
2108 return E_OUTOFMEMORY;
2111 libvlc_video_set_aspect_ratio(p_md, psz_aspect, &ex);
2113 CoTaskMemFree(psz_aspect);
2114 if( libvlc_exception_raised(&ex) )
2116 _p_instance->setErrorInfo(IID_IVLCVideo,
2117 libvlc_exception_get_message(&ex));
2118 libvlc_exception_clear(&ex);
2126 STDMETHODIMP VLCVideo::get_subtitle(long* spu)
2131 libvlc_media_player_t *p_md;
2132 HRESULT hr = _p_instance->getMD(&p_md);
2135 libvlc_exception_t ex;
2136 libvlc_exception_init(&ex);
2138 *spu = libvlc_video_get_spu(p_md, &ex);
2139 if( ! libvlc_exception_raised(&ex) )
2143 _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
2144 libvlc_exception_clear(&ex);
2150 STDMETHODIMP VLCVideo::put_subtitle(long spu)
2152 libvlc_media_player_t *p_md;
2153 HRESULT hr = _p_instance->getMD(&p_md);
2156 libvlc_exception_t ex;
2157 libvlc_exception_init(&ex);
2159 libvlc_video_set_spu(p_md, spu, &ex);
2160 if( libvlc_exception_raised(&ex) )
2162 _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
2163 libvlc_exception_clear(&ex);
2171 STDMETHODIMP VLCVideo::get_crop(BSTR* geometry)
2173 if( NULL == geometry )
2176 libvlc_media_player_t *p_md;
2177 HRESULT hr = _p_instance->getMD(&p_md);
2180 libvlc_exception_t ex;
2181 libvlc_exception_init(&ex);
2183 char *psz_geometry = libvlc_video_get_crop_geometry(p_md, &ex);
2185 if( ! libvlc_exception_raised(&ex) )
2187 if( NULL == psz_geometry )
2188 return E_OUTOFMEMORY;
2190 *geometry = BSTRFromCStr(CP_UTF8, psz_geometry);
2191 free( psz_geometry );
2192 psz_geometry = NULL;
2193 return (NULL == geometry) ? E_OUTOFMEMORY : NOERROR;
2195 free( psz_geometry );
2196 psz_geometry = NULL;
2197 _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
2198 libvlc_exception_clear(&ex);
2204 STDMETHODIMP VLCVideo::put_crop(BSTR geometry)
2206 if( NULL == geometry )
2209 if( 0 == SysStringLen(geometry) )
2210 return E_INVALIDARG;
2212 libvlc_media_player_t *p_md;
2213 HRESULT hr = _p_instance->getMD(&p_md);
2216 libvlc_exception_t ex;
2217 libvlc_exception_init(&ex);
2219 char *psz_geometry = CStrFromBSTR(CP_UTF8, geometry);
2220 if( NULL == psz_geometry )
2222 return E_OUTOFMEMORY;
2225 libvlc_video_set_crop_geometry(p_md, psz_geometry, &ex);
2227 CoTaskMemFree(psz_geometry);
2228 if( libvlc_exception_raised(&ex) )
2230 _p_instance->setErrorInfo(IID_IVLCVideo,
2231 libvlc_exception_get_message(&ex));
2232 libvlc_exception_clear(&ex);
2240 STDMETHODIMP VLCVideo::get_teletext(long* page)
2245 libvlc_media_player_t *p_md;
2246 HRESULT hr = _p_instance->getMD(&p_md);
2249 libvlc_exception_t ex;
2250 libvlc_exception_init(&ex);
2252 *page = libvlc_video_get_teletext(p_md, &ex);
2253 if( ! libvlc_exception_raised(&ex) )
2257 _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
2258 libvlc_exception_clear(&ex);
2264 STDMETHODIMP VLCVideo::put_teletext(long page)
2266 libvlc_media_player_t *p_md;
2267 HRESULT hr = _p_instance->getMD(&p_md);
2270 libvlc_exception_t ex;
2271 libvlc_exception_init(&ex);
2273 libvlc_video_set_teletext(p_md, page, &ex);
2274 if( libvlc_exception_raised(&ex) )
2276 _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
2277 libvlc_exception_clear(&ex);
2285 STDMETHODIMP VLCVideo::takeSnapshot(LPPICTUREDISP* picture)
2287 if( NULL == picture )
2290 libvlc_media_player_t *p_md;
2291 HRESULT hr = _p_instance->getMD(&p_md);
2294 libvlc_exception_t ex;
2295 libvlc_exception_init(&ex);
2297 static int uniqueId = 0;
2298 TCHAR path[MAX_PATH+1];
2300 int pathlen = GetTempPath(MAX_PATH-24, path);
2301 if( (0 == pathlen) || (pathlen > (MAX_PATH-24)) )
2304 /* check temp directory path by openning it */
2306 HANDLE dirHandle = CreateFile(path, GENERIC_READ,
2307 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
2308 NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
2309 if( INVALID_HANDLE_VALUE == dirHandle )
2311 _p_instance->setErrorInfo(IID_IVLCVideo,
2312 "Invalid temporary directory for snapshot images, check values of TMP, TEMP envars.");
2317 BY_HANDLE_FILE_INFORMATION bhfi;
2318 BOOL res = GetFileInformationByHandle(dirHandle, &bhfi);
2319 CloseHandle(dirHandle);
2320 if( !res || !(bhfi.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) )
2322 _p_instance->setErrorInfo(IID_IVLCVideo,
2323 "Invalid temporary directory for snapshot images, check values of TMP, TEMP envars.");
2329 TCHAR filepath[MAX_PATH+1];
2331 _stprintf(filepath, TEXT("%sAXVLC%lXS%lX.bmp"),
2332 path, GetCurrentProcessId(), ++uniqueId);
2335 /* reuse path storage for UTF8 string */
2336 char *psz_filepath = (char *)path;
2337 WCHAR* wpath = filepath;
2339 char *psz_filepath = path;
2340 /* first convert to unicode using current code page */
2341 WCHAR wpath[MAX_PATH+1];
2342 if( 0 == MultiByteToWideChar(CP_ACP, 0, filepath, -1, wpath, sizeof(wpath)/sizeof(WCHAR)) )
2345 /* convert to UTF8 */
2346 pathlen = WideCharToMultiByte(CP_UTF8, 0, wpath, -1, psz_filepath, sizeof(path), NULL, NULL);
2347 // fail if path is 0 or too short (i.e pathlen is the same as storage size)
2348 if( (0 == pathlen) || (sizeof(path) == pathlen) )
2351 /* take snapshot into file */
2352 libvlc_video_take_snapshot(p_md, psz_filepath, 0, 0, &ex);
2353 if( ! libvlc_exception_raised(&ex) )
2356 /* open snapshot file */
2357 HANDLE snapPic = LoadImage(NULL, filepath, IMAGE_BITMAP,0, 0, LR_CREATEDIBSECTION|LR_LOADFROMFILE);
2362 snapDesc.cbSizeofstruct = sizeof(PICTDESC);
2363 snapDesc.picType = PICTYPE_BITMAP;
2364 snapDesc.bmp.hbitmap = (HBITMAP)snapPic;
2365 snapDesc.bmp.hpal = NULL;
2367 hr = OleCreatePictureIndirect(&snapDesc, IID_IPictureDisp, TRUE, (LPVOID*)picture);
2371 DeleteObject(snapPic);
2374 DeleteFile(filepath);
2377 _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
2378 libvlc_exception_clear(&ex);
2384 STDMETHODIMP VLCVideo::toggleFullscreen()
2386 libvlc_media_player_t *p_md;
2387 HRESULT hr = _p_instance->getMD(&p_md);
2390 libvlc_exception_t ex;
2391 libvlc_exception_init(&ex);
2393 libvlc_toggle_fullscreen(p_md, &ex);
2394 if( ! libvlc_exception_raised(&ex) )
2398 _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
2399 libvlc_exception_clear(&ex);
2405 STDMETHODIMP VLCVideo::toggleTeletext()
2407 libvlc_media_player_t *p_md;
2408 HRESULT hr = _p_instance->getMD(&p_md);
2411 libvlc_exception_t ex;
2412 libvlc_exception_init(&ex);
2414 libvlc_toggle_teletext(p_md, &ex);
2415 if( ! libvlc_exception_raised(&ex) )
2419 _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
2420 libvlc_exception_clear(&ex);
2426 /*******************************************************************************/
2428 VLCControl2::VLCControl2(VLCPlugin *p_instance) :
2429 _p_instance(p_instance),
2433 _p_vlcplaylist(NULL),
2436 _p_vlcaudio = new VLCAudio(p_instance);
2437 _p_vlcinput = new VLCInput(p_instance);
2438 _p_vlclog = new VLCLog(p_instance);
2439 _p_vlcplaylist = new VLCPlaylist(p_instance);
2440 _p_vlcvideo = new VLCVideo(p_instance);
2443 VLCControl2::~VLCControl2()
2446 delete _p_vlcplaylist;
2451 _p_typeinfo->Release();
2454 HRESULT VLCControl2::loadTypeInfo(void)
2456 HRESULT hr = NOERROR;
2457 if( NULL == _p_typeinfo )
2459 ITypeLib *p_typelib;
2461 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
2464 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCControl2, &_p_typeinfo);
2469 p_typelib->Release();
2475 STDMETHODIMP VLCControl2::GetTypeInfoCount(UINT* pctInfo)
2477 if( NULL == pctInfo )
2478 return E_INVALIDARG;
2480 if( SUCCEEDED(loadTypeInfo()) )
2488 STDMETHODIMP VLCControl2::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
2490 if( NULL == ppTInfo )
2491 return E_INVALIDARG;
2493 if( SUCCEEDED(loadTypeInfo()) )
2495 _p_typeinfo->AddRef();
2496 *ppTInfo = _p_typeinfo;
2503 STDMETHODIMP VLCControl2::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
2504 UINT cNames, LCID lcid, DISPID* rgDispID)
2506 if( SUCCEEDED(loadTypeInfo()) )
2508 return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
2513 STDMETHODIMP VLCControl2::Invoke(DISPID dispIdMember, REFIID riid,
2514 LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
2515 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
2517 if( SUCCEEDED(loadTypeInfo()) )
2519 return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
2520 pVarResult, pExcepInfo, puArgErr);
2525 STDMETHODIMP VLCControl2::get_AutoLoop(VARIANT_BOOL *autoloop)
2527 if( NULL == autoloop )
2530 *autoloop = _p_instance->getAutoLoop() ? VARIANT_TRUE: VARIANT_FALSE;
2534 STDMETHODIMP VLCControl2::put_AutoLoop(VARIANT_BOOL autoloop)
2536 _p_instance->setAutoLoop((VARIANT_FALSE != autoloop) ? TRUE: FALSE);
2540 STDMETHODIMP VLCControl2::get_AutoPlay(VARIANT_BOOL *autoplay)
2542 if( NULL == autoplay )
2545 *autoplay = _p_instance->getAutoPlay() ? VARIANT_TRUE: VARIANT_FALSE;
2549 STDMETHODIMP VLCControl2::put_AutoPlay(VARIANT_BOOL autoplay)
2551 _p_instance->setAutoPlay((VARIANT_FALSE != autoplay) ? TRUE: FALSE);
2555 STDMETHODIMP VLCControl2::get_BaseURL(BSTR *url)
2560 *url = SysAllocStringLen(_p_instance->getBaseURL(),
2561 SysStringLen(_p_instance->getBaseURL()));
2565 STDMETHODIMP VLCControl2::put_BaseURL(BSTR mrl)
2567 _p_instance->setBaseURL(mrl);
2572 STDMETHODIMP VLCControl2::get_MRL(BSTR *mrl)
2577 *mrl = SysAllocStringLen(_p_instance->getMRL(),
2578 SysStringLen(_p_instance->getMRL()));
2582 STDMETHODIMP VLCControl2::put_MRL(BSTR mrl)
2584 _p_instance->setMRL(mrl);
2590 STDMETHODIMP VLCControl2::get_Toolbar(VARIANT_BOOL *visible)
2592 if( NULL == visible )
2596 * Note to developpers
2598 * Returning the _b_toolbar is closer to the method specification.
2599 * But returning True when toolbar is not implemented so not displayed
2600 * could be bad for ActiveX users which rely on this value to show their
2601 * own toolbar if not provided by the ActiveX.
2603 * This is the reason why FALSE is returned, until toolbar get implemented.
2606 /* DISABLED for now */
2607 // *visible = _p_instance->getShowToolbar() ? VARIANT_TRUE: VARIANT_FALSE;
2609 *visible = VARIANT_FALSE;
2614 STDMETHODIMP VLCControl2::put_Toolbar(VARIANT_BOOL visible)
2616 _p_instance->setShowToolbar((VARIANT_FALSE != visible) ? TRUE: FALSE);
2621 STDMETHODIMP VLCControl2::get_StartTime(long *seconds)
2623 if( NULL == seconds )
2626 *seconds = _p_instance->getStartTime();
2631 STDMETHODIMP VLCControl2::put_StartTime(long seconds)
2633 _p_instance->setStartTime(seconds);
2638 STDMETHODIMP VLCControl2::get_VersionInfo(BSTR *version)
2640 if( NULL == version )
2643 const char *versionStr = libvlc_get_version();
2644 if( NULL != versionStr )
2646 *version = BSTRFromCStr(CP_UTF8, versionStr);
2648 return (NULL == *version) ? E_OUTOFMEMORY : NOERROR;
2654 STDMETHODIMP VLCControl2::get_Visible(VARIANT_BOOL *isVisible)
2656 if( NULL == isVisible )
2659 *isVisible = _p_instance->getVisible() ? VARIANT_TRUE : VARIANT_FALSE;
2664 STDMETHODIMP VLCControl2::put_Visible(VARIANT_BOOL isVisible)
2666 _p_instance->setVisible(isVisible != VARIANT_FALSE);
2671 STDMETHODIMP VLCControl2::get_Volume(long *volume)
2673 if( NULL == volume )
2676 *volume = _p_instance->getVolume();
2680 STDMETHODIMP VLCControl2::put_Volume(long volume)
2682 _p_instance->setVolume(volume);
2686 STDMETHODIMP VLCControl2::get_BackColor(OLE_COLOR *backcolor)
2688 if( NULL == backcolor )
2691 *backcolor = _p_instance->getBackColor();
2695 STDMETHODIMP VLCControl2::put_BackColor(OLE_COLOR backcolor)
2697 _p_instance->setBackColor(backcolor);
2701 STDMETHODIMP VLCControl2::get_audio(IVLCAudio** obj)
2707 if( NULL != _p_vlcaudio )
2709 _p_vlcaudio->AddRef();
2712 return E_OUTOFMEMORY;
2715 STDMETHODIMP VLCControl2::get_input(IVLCInput** obj)
2721 if( NULL != _p_vlcinput )
2723 _p_vlcinput->AddRef();
2726 return E_OUTOFMEMORY;
2729 STDMETHODIMP VLCControl2::get_log(IVLCLog** obj)
2735 if( NULL != _p_vlclog )
2737 _p_vlclog->AddRef();
2740 return E_OUTOFMEMORY;
2743 STDMETHODIMP VLCControl2::get_playlist(IVLCPlaylist** obj)
2748 *obj = _p_vlcplaylist;
2749 if( NULL != _p_vlcplaylist )
2751 _p_vlcplaylist->AddRef();
2754 return E_OUTOFMEMORY;
2757 STDMETHODIMP VLCControl2::get_video(IVLCVideo** obj)
2763 if( NULL != _p_vlcvideo )
2765 _p_vlcvideo->AddRef();
2768 return E_OUTOFMEMORY;