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 along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
25 #include "vlccontrol2.h"
26 #include "vlccontrol.h"
37 HRESULT _exception_bridge(VLCPlugin *p,REFIID riid, libvlc_exception_t *ex)
39 if( libvlc_exception_raised(ex) )
41 p->setErrorInfo(riid,libvlc_exception_get_message(ex));
42 libvlc_exception_clear(ex);
48 #define EMIT_EXCEPTION_BRIDGE( classname ) \
49 HRESULT classname::exception_bridge( libvlc_exception_t *ex ) \
50 { return _exception_bridge( _p_instance, IID_I##classname, ex ); }
52 EMIT_EXCEPTION_BRIDGE( VLCAudio )
53 EMIT_EXCEPTION_BRIDGE( VLCInput )
54 EMIT_EXCEPTION_BRIDGE( VLCMessageIterator )
55 EMIT_EXCEPTION_BRIDGE( VLCMessages )
56 EMIT_EXCEPTION_BRIDGE( VLCLog )
57 EMIT_EXCEPTION_BRIDGE( VLCPlaylistItems )
58 EMIT_EXCEPTION_BRIDGE( VLCPlaylist )
59 EMIT_EXCEPTION_BRIDGE( VLCVideo )
61 #undef EMIT_EXCEPTION_BRIDGE
67 _p_typeinfo->Release();
70 HRESULT VLCAudio::loadTypeInfo(void)
73 if( NULL == _p_typeinfo )
77 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
80 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCAudio, &_p_typeinfo);
91 STDMETHODIMP VLCAudio::GetTypeInfoCount(UINT* pctInfo)
96 if( SUCCEEDED(loadTypeInfo()) )
104 STDMETHODIMP VLCAudio::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
106 if( NULL == ppTInfo )
109 if( SUCCEEDED(loadTypeInfo()) )
111 _p_typeinfo->AddRef();
112 *ppTInfo = _p_typeinfo;
119 STDMETHODIMP VLCAudio::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
120 UINT cNames, LCID lcid, DISPID* rgDispID)
122 if( SUCCEEDED(loadTypeInfo()) )
124 return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
129 STDMETHODIMP VLCAudio::Invoke(DISPID dispIdMember, REFIID riid,
130 LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
131 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
133 if( SUCCEEDED(loadTypeInfo()) )
135 return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
136 pVarResult, pExcepInfo, puArgErr);
141 STDMETHODIMP VLCAudio::get_mute(VARIANT_BOOL* mute)
146 libvlc_instance_t* p_libvlc;
147 HRESULT hr = _p_instance->getVLC(&p_libvlc);
150 libvlc_exception_t ex;
151 libvlc_exception_init(&ex);
153 *mute = libvlc_audio_get_mute(p_libvlc, &ex) ?
154 VARIANT_TRUE : VARIANT_FALSE;
155 hr = exception_bridge(&ex);
160 STDMETHODIMP VLCAudio::put_mute(VARIANT_BOOL mute)
162 libvlc_instance_t* p_libvlc;
163 HRESULT hr = _p_instance->getVLC(&p_libvlc);
166 libvlc_exception_t ex;
167 libvlc_exception_init(&ex);
169 libvlc_audio_set_mute(p_libvlc, VARIANT_FALSE != mute, &ex);
170 hr = exception_bridge(&ex);
175 STDMETHODIMP VLCAudio::get_volume(long* volume)
180 libvlc_instance_t* p_libvlc;
181 HRESULT hr = _p_instance->getVLC(&p_libvlc);
184 libvlc_exception_t ex;
185 libvlc_exception_init(&ex);
187 *volume = libvlc_audio_get_volume(p_libvlc, &ex);
188 hr = exception_bridge(&ex);
193 STDMETHODIMP VLCAudio::put_volume(long volume)
195 libvlc_instance_t* p_libvlc;
196 HRESULT hr = _p_instance->getVLC(&p_libvlc);
199 libvlc_exception_t ex;
200 libvlc_exception_init(&ex);
202 libvlc_audio_set_volume(p_libvlc, volume, &ex);
203 hr = exception_bridge(&ex);
208 STDMETHODIMP VLCAudio::get_track(long* track)
213 libvlc_media_player_t* p_md;
214 HRESULT hr = _p_instance->getMD(&p_md);
217 libvlc_exception_t ex;
218 libvlc_exception_init(&ex);
220 *track = libvlc_audio_get_track(p_md, &ex);
221 hr = exception_bridge(&ex);
226 STDMETHODIMP VLCAudio::put_track(long track)
228 libvlc_media_player_t *p_md;
229 HRESULT hr = _p_instance->getMD(&p_md);
232 libvlc_exception_t ex;
233 libvlc_exception_init(&ex);
235 libvlc_audio_set_track(p_md, track, &ex);
236 hr = exception_bridge(&ex);
241 STDMETHODIMP VLCAudio::get_channel(long *channel)
243 if( NULL == channel )
246 libvlc_instance_t* p_libvlc;
247 HRESULT hr = _p_instance->getVLC(&p_libvlc);
250 libvlc_exception_t ex;
251 libvlc_exception_init(&ex);
253 *channel = libvlc_audio_get_channel(p_libvlc, &ex);
254 hr = exception_bridge(&ex);
259 STDMETHODIMP VLCAudio::put_channel(long 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 libvlc_audio_set_channel(p_libvlc, channel, &ex);
269 hr = exception_bridge(&ex);
274 STDMETHODIMP VLCAudio::toggleMute()
276 libvlc_instance_t* p_libvlc;
277 HRESULT hr = _p_instance->getVLC(&p_libvlc);
280 libvlc_exception_t ex;
281 libvlc_exception_init(&ex);
283 libvlc_audio_toggle_mute(p_libvlc, &ex);
284 hr = exception_bridge(&ex);
289 /*******************************************************************************/
291 VLCInput::~VLCInput()
294 _p_typeinfo->Release();
297 HRESULT VLCInput::loadTypeInfo(void)
299 HRESULT hr = NOERROR;
300 if( NULL == _p_typeinfo )
304 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
307 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCInput, &_p_typeinfo);
312 p_typelib->Release();
318 STDMETHODIMP VLCInput::GetTypeInfoCount(UINT* pctInfo)
320 if( NULL == pctInfo )
323 if( SUCCEEDED(loadTypeInfo()) )
331 STDMETHODIMP VLCInput::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
333 if( NULL == ppTInfo )
336 if( SUCCEEDED(loadTypeInfo()) )
338 _p_typeinfo->AddRef();
339 *ppTInfo = _p_typeinfo;
346 STDMETHODIMP VLCInput::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
347 UINT cNames, LCID lcid, DISPID* rgDispID)
349 if( SUCCEEDED(loadTypeInfo()) )
351 return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
356 STDMETHODIMP VLCInput::Invoke(DISPID dispIdMember, REFIID riid,
357 LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
358 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
360 if( SUCCEEDED(loadTypeInfo()) )
362 return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
363 pVarResult, pExcepInfo, puArgErr);
368 STDMETHODIMP VLCInput::get_length(double* length)
374 libvlc_media_player_t *p_md;
375 HRESULT hr = _p_instance->getMD(&p_md);
378 libvlc_exception_t ex;
379 libvlc_exception_init(&ex);
381 *length = (double)libvlc_media_player_get_length(p_md, &ex);
382 hr = exception_bridge(&ex);
387 STDMETHODIMP VLCInput::get_position(double* position)
389 if( NULL == position )
393 libvlc_media_player_t *p_md;
394 HRESULT hr = _p_instance->getMD(&p_md);
397 libvlc_exception_t ex;
398 libvlc_exception_init(&ex);
400 *position = libvlc_media_player_get_position(p_md, &ex);
401 hr = exception_bridge(&ex);
406 STDMETHODIMP VLCInput::put_position(double position)
408 libvlc_media_player_t *p_md;
409 HRESULT hr = _p_instance->getMD(&p_md);
412 libvlc_exception_t ex;
413 libvlc_exception_init(&ex);
415 libvlc_media_player_set_position(p_md, position, &ex);
416 hr = exception_bridge(&ex);
421 STDMETHODIMP VLCInput::get_time(double* time)
426 libvlc_media_player_t *p_md;
427 HRESULT hr = _p_instance->getMD(&p_md);
430 libvlc_exception_t ex;
431 libvlc_exception_init(&ex);
433 *time = (double)libvlc_media_player_get_time(p_md, &ex);
434 hr = exception_bridge(&ex);
439 STDMETHODIMP VLCInput::put_time(double time)
441 libvlc_media_player_t *p_md;
442 HRESULT hr = _p_instance->getMD(&p_md);
445 libvlc_exception_t ex;
446 libvlc_exception_init(&ex);
448 libvlc_media_player_set_time(p_md, (int64_t)time, &ex);
449 hr = exception_bridge(&ex);
454 STDMETHODIMP VLCInput::get_state(long* state)
459 libvlc_media_player_t *p_md;
460 HRESULT hr = _p_instance->getMD(&p_md);
463 libvlc_exception_t ex;
464 libvlc_exception_init(&ex);
466 *state = libvlc_media_player_get_state(p_md, &ex);
467 if( ! libvlc_exception_raised(&ex) )
471 libvlc_exception_clear(&ex);
472 // don't fail, just return the idle state
479 STDMETHODIMP VLCInput::get_rate(double* rate)
484 libvlc_media_player_t *p_md;
485 HRESULT hr = _p_instance->getMD(&p_md);
488 libvlc_exception_t ex;
489 libvlc_exception_init(&ex);
491 *rate = libvlc_media_player_get_rate(p_md, &ex);
492 hr = exception_bridge(&ex);
497 STDMETHODIMP VLCInput::put_rate(double rate)
499 libvlc_media_player_t *p_md;
500 HRESULT hr = _p_instance->getMD(&p_md);
503 libvlc_exception_t ex;
504 libvlc_exception_init(&ex);
506 libvlc_media_player_set_rate(p_md, rate, &ex);
507 hr = exception_bridge(&ex);
512 STDMETHODIMP VLCInput::get_fps(double* fps)
518 libvlc_media_player_t *p_md;
519 HRESULT hr = _p_instance->getMD(&p_md);
522 libvlc_exception_t ex;
523 libvlc_exception_init(&ex);
525 *fps = libvlc_media_player_get_fps(p_md, &ex);
526 hr = exception_bridge(&ex);
531 STDMETHODIMP VLCInput::get_hasVout(VARIANT_BOOL* hasVout)
533 if( NULL == hasVout )
536 libvlc_media_player_t *p_md;
537 HRESULT hr = _p_instance->getMD(&p_md);
540 libvlc_exception_t ex;
541 libvlc_exception_init(&ex);
543 *hasVout = libvlc_media_player_has_vout(p_md, &ex) ?
544 VARIANT_TRUE : VARIANT_FALSE;
545 hr = exception_bridge(&ex);
550 /*******************************************************************************/
554 delete _p_vlcmessages;
556 libvlc_log_close(_p_log, NULL);
559 _p_typeinfo->Release();
562 HRESULT VLCLog::loadTypeInfo(void)
564 HRESULT hr = NOERROR;
565 if( NULL == _p_typeinfo )
569 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
572 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCLog, &_p_typeinfo);
577 p_typelib->Release();
583 STDMETHODIMP VLCLog::GetTypeInfoCount(UINT* pctInfo)
585 if( NULL == pctInfo )
588 if( SUCCEEDED(loadTypeInfo()) )
596 STDMETHODIMP VLCLog::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
598 if( NULL == ppTInfo )
601 if( SUCCEEDED(loadTypeInfo()) )
603 _p_typeinfo->AddRef();
604 *ppTInfo = _p_typeinfo;
611 STDMETHODIMP VLCLog::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
612 UINT cNames, LCID lcid, DISPID* rgDispID)
614 if( SUCCEEDED(loadTypeInfo()) )
616 return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
621 STDMETHODIMP VLCLog::Invoke(DISPID dispIdMember, REFIID riid,
622 LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
623 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
625 if( SUCCEEDED(loadTypeInfo()) )
627 return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
628 pVarResult, pExcepInfo, puArgErr);
633 STDMETHODIMP VLCLog::get_messages(IVLCMessages** obj)
638 *obj = _p_vlcmessages;
639 if( NULL != _p_vlcmessages )
641 _p_vlcmessages->AddRef();
644 return E_OUTOFMEMORY;
647 STDMETHODIMP VLCLog::get_verbosity(long* level)
654 libvlc_instance_t* p_libvlc;
655 HRESULT hr = _p_instance->getVLC(&p_libvlc);
658 libvlc_exception_t ex;
659 libvlc_exception_init(&ex);
661 *level = libvlc_get_log_verbosity(p_libvlc, &ex);
662 hr = exception_bridge(&ex);
668 /* log is not enabled, return -1 */
674 STDMETHODIMP VLCLog::put_verbosity(long verbosity)
676 libvlc_instance_t* p_libvlc;
677 HRESULT hr = _p_instance->getVLC(&p_libvlc);
680 libvlc_exception_t ex;
681 libvlc_exception_init(&ex);
687 _p_log = libvlc_log_open(p_libvlc, &ex);
688 hr = exception_bridge(&ex);
691 libvlc_set_log_verbosity(p_libvlc, (unsigned)verbosity, &ex);
695 /* close log when verbosity is set to -1 */
696 libvlc_log_close(_p_log, &ex);
699 hr = exception_bridge(&ex);
704 /*******************************************************************************/
706 /* STL forward iterator used by VLCEnumIterator class to implement IEnumVARIANT */
708 class VLCMessageSTLIterator
713 VLCMessageSTLIterator(IVLCMessageIterator* iter) : iter(iter), msg(NULL)
719 VLCMessageSTLIterator(const VLCMessageSTLIterator& other)
729 virtual ~VLCMessageSTLIterator()
738 // we only need prefix ++ operator
739 VLCMessageSTLIterator& operator++()
741 VARIANT_BOOL hasNext = VARIANT_FALSE;
744 iter->get_hasNext(&hasNext);
751 if( VARIANT_TRUE == hasNext ) {
758 VARIANT operator*() const
764 if( SUCCEEDED(msg->QueryInterface(IID_IDispatch,
765 (LPVOID*)&V_DISPATCH(&v))) )
767 V_VT(&v) = VT_DISPATCH;
773 bool operator==(const VLCMessageSTLIterator& other) const
775 return msg == other.msg;
778 bool operator!=(const VLCMessageSTLIterator& other) const
780 return msg != other.msg;
784 IVLCMessageIterator* iter;
788 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
790 VLCMessages::~VLCMessages()
793 _p_typeinfo->Release();
796 HRESULT VLCMessages::loadTypeInfo(void)
798 HRESULT hr = NOERROR;
799 if( NULL == _p_typeinfo )
803 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
806 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCMessages, &_p_typeinfo);
811 p_typelib->Release();
817 STDMETHODIMP VLCMessages::GetTypeInfoCount(UINT* pctInfo)
819 if( NULL == pctInfo )
822 if( SUCCEEDED(loadTypeInfo()) )
830 STDMETHODIMP VLCMessages::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
832 if( NULL == ppTInfo )
835 if( SUCCEEDED(loadTypeInfo()) )
837 _p_typeinfo->AddRef();
838 *ppTInfo = _p_typeinfo;
845 STDMETHODIMP VLCMessages::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
846 UINT cNames, LCID lcid, DISPID* rgDispID)
848 if( SUCCEEDED(loadTypeInfo()) )
850 return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
855 STDMETHODIMP VLCMessages::Invoke(DISPID dispIdMember, REFIID riid,
856 LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
857 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
859 if( SUCCEEDED(loadTypeInfo()) )
861 return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
862 pVarResult, pExcepInfo, puArgErr);
867 STDMETHODIMP VLCMessages::get__NewEnum(LPUNKNOWN* _NewEnum)
869 if( NULL == _NewEnum )
872 IVLCMessageIterator* iter = NULL;
875 *_NewEnum= new VLCEnumIterator<IID_IEnumVARIANT,
878 VLCMessageSTLIterator>
879 (VLCMessageSTLIterator(iter), VLCMessageSTLIterator(NULL));
881 return *_NewEnum ? S_OK : E_OUTOFMEMORY;
884 STDMETHODIMP VLCMessages::clear()
886 HRESULT hr = NOERROR;
887 libvlc_log_t *p_log = _p_vlclog->_p_log;
890 libvlc_exception_t ex;
891 libvlc_exception_init(&ex);
893 libvlc_log_clear(p_log, &ex);
894 hr = exception_bridge(&ex);
899 STDMETHODIMP VLCMessages::get_count(long* count)
906 libvlc_log_t *p_log = _p_vlclog->_p_log;
909 libvlc_exception_t ex;
910 libvlc_exception_init(&ex);
912 *count = libvlc_log_count(p_log, &ex);
913 hr = exception_bridge(&ex);
920 STDMETHODIMP VLCMessages::iterator(IVLCMessageIterator** iter)
925 *iter = new VLCMessageIterator(_p_instance, _p_vlclog);
927 return *iter ? S_OK : E_OUTOFMEMORY;
930 /*******************************************************************************/
932 VLCMessageIterator::VLCMessageIterator(VLCPlugin *p_instance, VLCLog* p_vlclog ) :
933 _p_instance(p_instance),
938 if( p_vlclog->_p_log )
940 _p_iter = libvlc_log_get_iterator(p_vlclog->_p_log, NULL);
946 VLCMessageIterator::~VLCMessageIterator()
949 libvlc_log_iterator_free(_p_iter, NULL);
952 _p_typeinfo->Release();
955 HRESULT VLCMessageIterator::loadTypeInfo(void)
957 HRESULT hr = NOERROR;
958 if( NULL == _p_typeinfo )
962 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
965 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCMessageIterator, &_p_typeinfo);
970 p_typelib->Release();
976 STDMETHODIMP VLCMessageIterator::GetTypeInfoCount(UINT* pctInfo)
978 if( NULL == pctInfo )
981 if( SUCCEEDED(loadTypeInfo()) )
989 STDMETHODIMP VLCMessageIterator::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
991 if( NULL == ppTInfo )
994 if( SUCCEEDED(loadTypeInfo()) )
996 _p_typeinfo->AddRef();
997 *ppTInfo = _p_typeinfo;
1004 STDMETHODIMP VLCMessageIterator::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
1005 UINT cNames, LCID lcid, DISPID* rgDispID)
1007 if( SUCCEEDED(loadTypeInfo()) )
1009 return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
1014 STDMETHODIMP VLCMessageIterator::Invoke(DISPID dispIdMember, REFIID riid,
1015 LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
1016 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
1018 if( SUCCEEDED(loadTypeInfo()) )
1020 return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
1021 pVarResult, pExcepInfo, puArgErr);
1026 STDMETHODIMP VLCMessageIterator::get_hasNext(VARIANT_BOOL* hasNext)
1030 if( NULL == hasNext )
1033 if( _p_iter && _p_vlclog->_p_log )
1035 libvlc_exception_t ex;
1036 libvlc_exception_init(&ex);
1038 *hasNext = libvlc_log_iterator_has_next(_p_iter, &ex) ?
1039 VARIANT_TRUE : VARIANT_FALSE;
1040 hr = exception_bridge(&ex);
1044 *hasNext = VARIANT_FALSE;
1049 STDMETHODIMP VLCMessageIterator::next(IVLCMessage** message)
1053 if( NULL == message )
1056 if( _p_iter && _p_vlclog->_p_log )
1058 struct libvlc_log_message_t buffer;
1060 buffer.sizeof_msg = sizeof(buffer);
1062 libvlc_exception_t ex;
1063 libvlc_exception_init(&ex);
1065 libvlc_log_iterator_next(_p_iter, &buffer, &ex);
1066 hr = exception_bridge(&ex);
1069 *message = new VLCMessage(_p_instance, buffer);
1077 /*******************************************************************************/
1079 VLCMessage::~VLCMessage()
1082 _p_typeinfo->Release();
1085 HRESULT VLCMessage::loadTypeInfo(void)
1087 HRESULT hr = NOERROR;
1088 if( NULL == _p_typeinfo )
1090 ITypeLib *p_typelib;
1092 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
1095 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCMessage, &_p_typeinfo);
1100 p_typelib->Release();
1106 STDMETHODIMP VLCMessage::GetTypeInfoCount(UINT* pctInfo)
1108 if( NULL == pctInfo )
1109 return E_INVALIDARG;
1111 if( SUCCEEDED(loadTypeInfo()) )
1119 STDMETHODIMP VLCMessage::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
1121 if( NULL == ppTInfo )
1122 return E_INVALIDARG;
1124 if( SUCCEEDED(loadTypeInfo()) )
1126 _p_typeinfo->AddRef();
1127 *ppTInfo = _p_typeinfo;
1134 STDMETHODIMP VLCMessage::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
1135 UINT cNames, LCID lcid, DISPID* rgDispID)
1137 if( SUCCEEDED(loadTypeInfo()) )
1139 return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
1144 STDMETHODIMP VLCMessage::Invoke(DISPID dispIdMember, REFIID riid,
1145 LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
1146 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
1148 if( SUCCEEDED(loadTypeInfo()) )
1150 return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
1151 pVarResult, pExcepInfo, puArgErr);
1156 inline const char *msgSeverity(int sev)
1171 STDMETHODIMP VLCMessage::get__Value(VARIANT* _Value)
1173 if( NULL == _Value )
1178 snprintf(buffer, sizeof(buffer), "%s %s %s: %s",
1179 _msg.psz_type, _msg.psz_name, msgSeverity(_msg.i_severity), _msg.psz_message);
1181 V_VT(_Value) = VT_BSTR;
1182 V_BSTR(_Value) = BSTRFromCStr(CP_UTF8, buffer);
1187 STDMETHODIMP VLCMessage::get_severity(long* level)
1192 *level = _msg.i_severity;
1197 STDMETHODIMP VLCMessage::get_type(BSTR* type)
1202 *type = BSTRFromCStr(CP_UTF8, _msg.psz_type);
1207 STDMETHODIMP VLCMessage::get_name(BSTR* name)
1212 *name = BSTRFromCStr(CP_UTF8, _msg.psz_name);
1217 STDMETHODIMP VLCMessage::get_header(BSTR* header)
1219 if( NULL == header )
1222 *header = BSTRFromCStr(CP_UTF8, _msg.psz_header);
1227 STDMETHODIMP VLCMessage::get_message(BSTR* message)
1229 if( NULL == message )
1232 *message = BSTRFromCStr(CP_UTF8, _msg.psz_message);
1237 /*******************************************************************************/
1239 VLCPlaylistItems::~VLCPlaylistItems()
1242 _p_typeinfo->Release();
1245 HRESULT VLCPlaylistItems::loadTypeInfo(void)
1247 HRESULT hr = NOERROR;
1248 if( NULL == _p_typeinfo )
1250 ITypeLib *p_typelib;
1252 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
1255 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCPlaylistItems, &_p_typeinfo);
1260 p_typelib->Release();
1266 STDMETHODIMP VLCPlaylistItems::GetTypeInfoCount(UINT* pctInfo)
1268 if( NULL == pctInfo )
1269 return E_INVALIDARG;
1271 if( SUCCEEDED(loadTypeInfo()) )
1279 STDMETHODIMP VLCPlaylistItems::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
1281 if( NULL == ppTInfo )
1282 return E_INVALIDARG;
1284 if( SUCCEEDED(loadTypeInfo()) )
1286 _p_typeinfo->AddRef();
1287 *ppTInfo = _p_typeinfo;
1294 STDMETHODIMP VLCPlaylistItems::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
1295 UINT cNames, LCID lcid, DISPID* rgDispID)
1297 if( SUCCEEDED(loadTypeInfo()) )
1299 return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
1304 STDMETHODIMP VLCPlaylistItems::Invoke(DISPID dispIdMember, REFIID riid,
1305 LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
1306 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
1308 if( SUCCEEDED(loadTypeInfo()) )
1310 return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
1311 pVarResult, pExcepInfo, puArgErr);
1316 STDMETHODIMP VLCPlaylistItems::get_count(long* count)
1321 libvlc_exception_t ex;
1322 libvlc_exception_init(&ex);
1324 *count = _p_instance->playlist_count(&ex);
1325 return exception_bridge(&ex);
1328 STDMETHODIMP VLCPlaylistItems::clear()
1330 libvlc_exception_t ex;
1331 libvlc_exception_init(&ex);
1333 _p_instance->playlist_clear(&ex);
1334 return exception_bridge(&ex);
1337 STDMETHODIMP VLCPlaylistItems::remove(long item)
1339 libvlc_instance_t* p_libvlc;
1340 HRESULT hr = _p_instance->getVLC(&p_libvlc);
1343 libvlc_exception_t ex;
1344 libvlc_exception_init(&ex);
1346 _p_instance->playlist_delete_item(item, &ex);
1347 hr = exception_bridge(&ex);
1352 /*******************************************************************************/
1354 VLCPlaylist::~VLCPlaylist()
1356 delete _p_vlcplaylistitems;
1358 _p_typeinfo->Release();
1361 HRESULT VLCPlaylist::loadTypeInfo(void)
1363 HRESULT hr = NOERROR;
1364 if( NULL == _p_typeinfo )
1366 ITypeLib *p_typelib;
1368 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
1371 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCPlaylist, &_p_typeinfo);
1376 p_typelib->Release();
1382 STDMETHODIMP VLCPlaylist::GetTypeInfoCount(UINT* pctInfo)
1384 if( NULL == pctInfo )
1385 return E_INVALIDARG;
1387 if( SUCCEEDED(loadTypeInfo()) )
1395 STDMETHODIMP VLCPlaylist::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
1397 if( NULL == ppTInfo )
1398 return E_INVALIDARG;
1400 if( SUCCEEDED(loadTypeInfo()) )
1402 _p_typeinfo->AddRef();
1403 *ppTInfo = _p_typeinfo;
1410 STDMETHODIMP VLCPlaylist::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
1411 UINT cNames, LCID lcid, DISPID* rgDispID)
1413 if( SUCCEEDED(loadTypeInfo()) )
1415 return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
1420 STDMETHODIMP VLCPlaylist::Invoke(DISPID dispIdMember, REFIID riid,
1421 LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
1422 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
1424 if( SUCCEEDED(loadTypeInfo()) )
1426 return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
1427 pVarResult, pExcepInfo, puArgErr);
1432 STDMETHODIMP VLCPlaylist::get_itemCount(long* count)
1438 libvlc_exception_t ex;
1439 libvlc_exception_init(&ex);
1441 *count = _p_instance->playlist_count(&ex);
1442 return exception_bridge(&ex);
1445 STDMETHODIMP VLCPlaylist::get_isPlaying(VARIANT_BOOL* isPlaying)
1447 if( NULL == isPlaying )
1450 libvlc_media_player_t *p_md;
1451 HRESULT hr = _p_instance->getMD(&p_md);
1454 libvlc_exception_t ex;
1455 libvlc_exception_init(&ex);
1457 *isPlaying = libvlc_media_player_is_playing(p_md, &ex) ?
1458 VARIANT_TRUE: VARIANT_FALSE;
1459 libvlc_exception_clear(&ex);
1464 STDMETHODIMP VLCPlaylist::add(BSTR uri, VARIANT name, VARIANT options, long* item)
1469 if( 0 == SysStringLen(uri) )
1470 return E_INVALIDARG;
1472 libvlc_instance_t* p_libvlc;
1473 HRESULT hr = _p_instance->getVLC(&p_libvlc);
1476 libvlc_exception_t ex;
1477 libvlc_exception_init(&ex);
1479 char *psz_uri = NULL;
1480 if( SysStringLen(_p_instance->getBaseURL()) > 0 )
1483 ** if the MRL a relative URL, we should end up with an absolute URL
1485 LPWSTR abs_url = CombineURL(_p_instance->getBaseURL(), uri);
1486 if( NULL != abs_url )
1488 psz_uri = CStrFromWSTR(CP_UTF8, abs_url, wcslen(abs_url));
1489 CoTaskMemFree(abs_url);
1493 psz_uri = CStrFromBSTR(CP_UTF8, uri);
1499 ** baseURL is empty, assume MRL is absolute
1501 psz_uri = CStrFromBSTR(CP_UTF8, uri);
1504 if( NULL == psz_uri )
1506 return E_OUTOFMEMORY;
1510 char **ppsz_options;
1512 hr = VLCControl::CreateTargetOptions(CP_UTF8, &options, &ppsz_options, &i_options);
1515 CoTaskMemFree(psz_uri);
1519 char *psz_name = NULL;
1521 VariantInit(&v_name);
1522 if( SUCCEEDED(VariantChangeType(&v_name, &name, 0, VT_BSTR)) )
1524 if( SysStringLen(V_BSTR(&v_name)) > 0 )
1525 psz_name = CStrFromBSTR(CP_UTF8, V_BSTR(&v_name));
1527 VariantClear(&v_name);
1530 *item = _p_instance->playlist_add_extended_untrusted(psz_uri,
1531 i_options, const_cast<const char **>(ppsz_options), &ex);
1533 VLCControl::FreeTargetOptions(ppsz_options, i_options);
1534 CoTaskMemFree(psz_uri);
1535 if( psz_name ) /* XXX Do we even need to check? */
1536 CoTaskMemFree(psz_name);
1537 hr = exception_bridge(&ex);
1542 STDMETHODIMP VLCPlaylist::play()
1544 libvlc_exception_t ex;
1545 libvlc_exception_init(&ex);
1547 _p_instance->playlist_play(&ex);
1548 return exception_bridge(&ex);
1551 STDMETHODIMP VLCPlaylist::playItem(long item)
1553 libvlc_exception_t ex;
1554 libvlc_exception_init(&ex);
1556 _p_instance->playlist_play_item(item,&ex);
1557 return exception_bridge(&ex);;
1560 STDMETHODIMP VLCPlaylist::togglePause()
1562 libvlc_media_player_t* p_md;
1563 HRESULT hr = _p_instance->getMD(&p_md);
1566 libvlc_exception_t ex;
1567 libvlc_exception_init(&ex);
1569 libvlc_media_player_pause(p_md, &ex);
1570 hr = exception_bridge(&ex);;
1575 STDMETHODIMP VLCPlaylist::stop()
1577 libvlc_media_player_t *p_md;
1578 HRESULT hr = _p_instance->getMD(&p_md);
1581 libvlc_exception_t ex;
1582 libvlc_exception_init(&ex);
1584 libvlc_media_player_stop(p_md, &ex);
1585 hr = exception_bridge(&ex);;
1590 STDMETHODIMP VLCPlaylist::next()
1592 libvlc_exception_t ex;
1593 libvlc_exception_init(&ex);
1595 _p_instance->playlist_next(&ex);
1596 return exception_bridge(&ex);;
1599 STDMETHODIMP VLCPlaylist::prev()
1601 libvlc_exception_t ex;
1602 libvlc_exception_init(&ex);
1604 _p_instance->playlist_prev(&ex);
1605 return exception_bridge(&ex);;
1608 STDMETHODIMP VLCPlaylist::clear()
1610 libvlc_exception_t ex;
1611 libvlc_exception_init(&ex);
1613 _p_instance->playlist_clear(&ex);
1614 return exception_bridge(&ex);;
1617 STDMETHODIMP VLCPlaylist::removeItem(long item)
1619 libvlc_instance_t* p_libvlc;
1620 HRESULT hr = _p_instance->getVLC(&p_libvlc);
1623 libvlc_exception_t ex;
1624 libvlc_exception_init(&ex);
1626 _p_instance->playlist_delete_item(item, &ex);
1627 hr = exception_bridge(&ex);;
1632 STDMETHODIMP VLCPlaylist::get_items(IVLCPlaylistItems** obj)
1637 *obj = _p_vlcplaylistitems;
1638 if( NULL != _p_vlcplaylistitems )
1640 _p_vlcplaylistitems->AddRef();
1643 return E_OUTOFMEMORY;
1646 /*******************************************************************************/
1648 VLCVideo::~VLCVideo()
1651 _p_typeinfo->Release();
1654 HRESULT VLCVideo::loadTypeInfo(void)
1656 HRESULT hr = NOERROR;
1657 if( NULL == _p_typeinfo )
1659 ITypeLib *p_typelib;
1661 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
1664 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCVideo, &_p_typeinfo);
1669 p_typelib->Release();
1675 STDMETHODIMP VLCVideo::GetTypeInfoCount(UINT* pctInfo)
1677 if( NULL == pctInfo )
1678 return E_INVALIDARG;
1680 if( SUCCEEDED(loadTypeInfo()) )
1688 STDMETHODIMP VLCVideo::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
1690 if( NULL == ppTInfo )
1691 return E_INVALIDARG;
1693 if( SUCCEEDED(loadTypeInfo()) )
1695 _p_typeinfo->AddRef();
1696 *ppTInfo = _p_typeinfo;
1703 STDMETHODIMP VLCVideo::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
1704 UINT cNames, LCID lcid, DISPID* rgDispID)
1706 if( SUCCEEDED(loadTypeInfo()) )
1708 return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
1713 STDMETHODIMP VLCVideo::Invoke(DISPID dispIdMember, REFIID riid,
1714 LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
1715 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
1717 if( SUCCEEDED(loadTypeInfo()) )
1719 return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
1720 pVarResult, pExcepInfo, puArgErr);
1725 STDMETHODIMP VLCVideo::get_fullscreen(VARIANT_BOOL* fullscreen)
1727 if( NULL == fullscreen )
1730 libvlc_media_player_t *p_md;
1731 HRESULT hr = _p_instance->getMD(&p_md);
1734 libvlc_exception_t ex;
1735 libvlc_exception_init(&ex);
1737 *fullscreen = libvlc_get_fullscreen(p_md, &ex) ?
1738 VARIANT_TRUE : VARIANT_FALSE;
1739 hr = exception_bridge(&ex);
1744 STDMETHODIMP VLCVideo::put_fullscreen(VARIANT_BOOL fullscreen)
1746 libvlc_media_player_t *p_md;
1747 HRESULT hr = _p_instance->getMD(&p_md);
1750 libvlc_exception_t ex;
1751 libvlc_exception_init(&ex);
1753 libvlc_set_fullscreen(p_md, VARIANT_FALSE != fullscreen, &ex);
1754 hr = exception_bridge(&ex);
1759 STDMETHODIMP VLCVideo::get_width(long* width)
1764 libvlc_media_player_t *p_md;
1765 HRESULT hr = _p_instance->getMD(&p_md);
1768 libvlc_exception_t ex;
1769 libvlc_exception_init(&ex);
1771 *width = libvlc_video_get_width(p_md, &ex);
1772 hr = exception_bridge(&ex);
1777 STDMETHODIMP VLCVideo::get_height(long* height)
1779 if( NULL == height )
1782 libvlc_media_player_t *p_md;
1783 HRESULT hr = _p_instance->getMD(&p_md);
1786 libvlc_exception_t ex;
1787 libvlc_exception_init(&ex);
1789 *height = libvlc_video_get_height(p_md, &ex);
1790 hr = exception_bridge(&ex);
1795 STDMETHODIMP VLCVideo::get_aspectRatio(BSTR* aspect)
1797 if( NULL == aspect )
1800 libvlc_media_player_t *p_md;
1801 HRESULT hr = _p_instance->getMD(&p_md);
1804 libvlc_exception_t ex;
1805 libvlc_exception_init(&ex);
1807 char *psz_aspect = libvlc_video_get_aspect_ratio(p_md, &ex);
1809 hr = exception_bridge(&ex);
1810 if( SUCCEEDED(hr) && NULL != psz_aspect )
1812 *aspect = BSTRFromCStr(CP_UTF8, psz_aspect);
1813 if( NULL == *aspect )
1815 } else if( NULL == psz_aspect) hr = E_OUTOFMEMORY; // strdup("") failed
1821 STDMETHODIMP VLCVideo::put_aspectRatio(BSTR aspect)
1823 if( NULL == aspect )
1826 if( 0 == SysStringLen(aspect) )
1827 return E_INVALIDARG;
1829 libvlc_media_player_t *p_md;
1830 HRESULT hr = _p_instance->getMD(&p_md);
1833 libvlc_exception_t ex;
1834 libvlc_exception_init(&ex);
1836 char *psz_aspect = CStrFromBSTR(CP_UTF8, aspect);
1837 if( NULL == psz_aspect )
1839 return E_OUTOFMEMORY;
1842 libvlc_video_set_aspect_ratio(p_md, psz_aspect, &ex);
1844 CoTaskMemFree(psz_aspect);
1845 hr = exception_bridge(&ex);
1850 STDMETHODIMP VLCVideo::get_subtitle(long* spu)
1855 libvlc_media_player_t *p_md;
1856 HRESULT hr = _p_instance->getMD(&p_md);
1859 libvlc_exception_t ex;
1860 libvlc_exception_init(&ex);
1862 *spu = libvlc_video_get_spu(p_md, &ex);
1863 hr = exception_bridge(&ex);
1868 STDMETHODIMP VLCVideo::put_subtitle(long spu)
1870 libvlc_media_player_t *p_md;
1871 HRESULT hr = _p_instance->getMD(&p_md);
1874 libvlc_exception_t ex;
1875 libvlc_exception_init(&ex);
1877 libvlc_video_set_spu(p_md, spu, &ex);
1878 hr = exception_bridge(&ex);
1883 STDMETHODIMP VLCVideo::get_crop(BSTR* geometry)
1885 if( NULL == geometry )
1888 libvlc_media_player_t *p_md;
1889 HRESULT hr = _p_instance->getMD(&p_md);
1892 libvlc_exception_t ex;
1893 libvlc_exception_init(&ex);
1895 char *psz_geometry = libvlc_video_get_crop_geometry(p_md, &ex);
1897 hr = exception_bridge(&ex);
1898 if( SUCCEEDED(&ex) && NULL != psz_geometry )
1900 *geometry = BSTRFromCStr(CP_UTF8, psz_geometry);
1901 if( NULL == geometry ) hr = E_OUTOFMEMORY;
1902 } else if( NULL == psz_geometry ) hr = E_OUTOFMEMORY;
1903 free( psz_geometry );
1908 STDMETHODIMP VLCVideo::put_crop(BSTR geometry)
1910 if( NULL == geometry )
1913 if( 0 == SysStringLen(geometry) )
1914 return E_INVALIDARG;
1916 libvlc_media_player_t *p_md;
1917 HRESULT hr = _p_instance->getMD(&p_md);
1920 libvlc_exception_t ex;
1921 libvlc_exception_init(&ex);
1923 char *psz_geometry = CStrFromBSTR(CP_UTF8, geometry);
1924 if( NULL == psz_geometry )
1926 return E_OUTOFMEMORY;
1929 libvlc_video_set_crop_geometry(p_md, psz_geometry, &ex);
1931 CoTaskMemFree(psz_geometry);
1932 hr = exception_bridge(&ex);
1937 STDMETHODIMP VLCVideo::get_teletext(long* page)
1942 libvlc_media_player_t *p_md;
1943 HRESULT hr = _p_instance->getMD(&p_md);
1946 libvlc_exception_t ex;
1947 libvlc_exception_init(&ex);
1949 *page = libvlc_video_get_teletext(p_md, &ex);
1950 hr = exception_bridge(&ex);
1955 STDMETHODIMP VLCVideo::put_teletext(long page)
1957 libvlc_media_player_t *p_md;
1958 HRESULT hr = _p_instance->getMD(&p_md);
1961 libvlc_exception_t ex;
1962 libvlc_exception_init(&ex);
1964 libvlc_video_set_teletext(p_md, page, &ex);
1965 hr = exception_bridge(&ex);
1970 STDMETHODIMP VLCVideo::takeSnapshot(LPPICTUREDISP* picture)
1972 if( NULL == picture )
1975 libvlc_media_player_t *p_md;
1976 HRESULT hr = _p_instance->getMD(&p_md);
1979 libvlc_exception_t ex;
1980 libvlc_exception_init(&ex);
1982 static int uniqueId = 0;
1983 TCHAR path[MAX_PATH+1];
1985 int pathlen = GetTempPath(MAX_PATH-24, path);
1986 if( (0 == pathlen) || (pathlen > (MAX_PATH-24)) )
1989 /* check temp directory path by openning it */
1991 HANDLE dirHandle = CreateFile(path, GENERIC_READ,
1992 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
1993 NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
1994 if( INVALID_HANDLE_VALUE == dirHandle )
1996 _p_instance->setErrorInfo(IID_IVLCVideo,
1997 "Invalid temporary directory for snapshot images, check values of TMP, TEMP envars.");
2002 BY_HANDLE_FILE_INFORMATION bhfi;
2003 BOOL res = GetFileInformationByHandle(dirHandle, &bhfi);
2004 CloseHandle(dirHandle);
2005 if( !res || !(bhfi.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) )
2007 _p_instance->setErrorInfo(IID_IVLCVideo,
2008 "Invalid temporary directory for snapshot images, check values of TMP, TEMP envars.");
2014 TCHAR filepath[MAX_PATH+1];
2016 _stprintf(filepath, TEXT("%sAXVLC%lXS%lX.bmp"),
2017 path, GetCurrentProcessId(), ++uniqueId);
2020 /* reuse path storage for UTF8 string */
2021 char *psz_filepath = (char *)path;
2022 WCHAR* wpath = filepath;
2024 char *psz_filepath = path;
2025 /* first convert to unicode using current code page */
2026 WCHAR wpath[MAX_PATH+1];
2027 if( 0 == MultiByteToWideChar(CP_ACP, 0, filepath, -1, wpath, sizeof(wpath)/sizeof(WCHAR)) )
2030 /* convert to UTF8 */
2031 pathlen = WideCharToMultiByte(CP_UTF8, 0, wpath, -1, psz_filepath, sizeof(path), NULL, NULL);
2032 // fail if path is 0 or too short (i.e pathlen is the same as storage size)
2033 if( (0 == pathlen) || (sizeof(path) == pathlen) )
2036 /* take snapshot into file */
2037 libvlc_video_take_snapshot(p_md, psz_filepath, 0, 0, &ex);
2038 if( ! libvlc_exception_raised(&ex) )
2041 /* open snapshot file */
2042 HANDLE snapPic = LoadImage(NULL, filepath, IMAGE_BITMAP,0, 0, LR_CREATEDIBSECTION|LR_LOADFROMFILE);
2047 snapDesc.cbSizeofstruct = sizeof(PICTDESC);
2048 snapDesc.picType = PICTYPE_BITMAP;
2049 snapDesc.bmp.hbitmap = (HBITMAP)snapPic;
2050 snapDesc.bmp.hpal = NULL;
2052 hr = OleCreatePictureIndirect(&snapDesc, IID_IPictureDisp, TRUE, (LPVOID*)picture);
2056 DeleteObject(snapPic);
2059 DeleteFile(filepath);
2062 _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
2063 libvlc_exception_clear(&ex);
2069 STDMETHODIMP VLCVideo::toggleFullscreen()
2071 libvlc_media_player_t *p_md;
2072 HRESULT hr = _p_instance->getMD(&p_md);
2075 libvlc_exception_t ex;
2076 libvlc_exception_init(&ex);
2078 libvlc_toggle_fullscreen(p_md, &ex);
2079 hr = exception_bridge(&ex);
2084 STDMETHODIMP VLCVideo::toggleTeletext()
2086 libvlc_media_player_t *p_md;
2087 HRESULT hr = _p_instance->getMD(&p_md);
2090 libvlc_exception_t ex;
2091 libvlc_exception_init(&ex);
2093 libvlc_toggle_teletext(p_md, &ex);
2094 hr = exception_bridge(&ex);
2099 /*******************************************************************************/
2101 VLCControl2::VLCControl2(VLCPlugin *p_instance) :
2102 _p_instance(p_instance),
2106 _p_vlcplaylist(NULL),
2109 _p_vlcaudio = new VLCAudio(p_instance);
2110 _p_vlcinput = new VLCInput(p_instance);
2111 _p_vlclog = new VLCLog(p_instance);
2112 _p_vlcplaylist = new VLCPlaylist(p_instance);
2113 _p_vlcvideo = new VLCVideo(p_instance);
2116 VLCControl2::~VLCControl2()
2119 delete _p_vlcplaylist;
2124 _p_typeinfo->Release();
2127 HRESULT VLCControl2::loadTypeInfo(void)
2129 HRESULT hr = NOERROR;
2130 if( NULL == _p_typeinfo )
2132 ITypeLib *p_typelib;
2134 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
2137 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCControl2, &_p_typeinfo);
2142 p_typelib->Release();
2148 STDMETHODIMP VLCControl2::GetTypeInfoCount(UINT* pctInfo)
2150 if( NULL == pctInfo )
2151 return E_INVALIDARG;
2153 if( SUCCEEDED(loadTypeInfo()) )
2161 STDMETHODIMP VLCControl2::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
2163 if( NULL == ppTInfo )
2164 return E_INVALIDARG;
2166 if( SUCCEEDED(loadTypeInfo()) )
2168 _p_typeinfo->AddRef();
2169 *ppTInfo = _p_typeinfo;
2176 STDMETHODIMP VLCControl2::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
2177 UINT cNames, LCID lcid, DISPID* rgDispID)
2179 if( SUCCEEDED(loadTypeInfo()) )
2181 return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
2186 STDMETHODIMP VLCControl2::Invoke(DISPID dispIdMember, REFIID riid,
2187 LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
2188 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
2190 if( SUCCEEDED(loadTypeInfo()) )
2192 return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
2193 pVarResult, pExcepInfo, puArgErr);
2198 STDMETHODIMP VLCControl2::get_AutoLoop(VARIANT_BOOL *autoloop)
2200 if( NULL == autoloop )
2203 *autoloop = _p_instance->getAutoLoop() ? VARIANT_TRUE: VARIANT_FALSE;
2207 STDMETHODIMP VLCControl2::put_AutoLoop(VARIANT_BOOL autoloop)
2209 _p_instance->setAutoLoop((VARIANT_FALSE != autoloop) ? TRUE: FALSE);
2213 STDMETHODIMP VLCControl2::get_AutoPlay(VARIANT_BOOL *autoplay)
2215 if( NULL == autoplay )
2218 *autoplay = _p_instance->getAutoPlay() ? VARIANT_TRUE: VARIANT_FALSE;
2222 STDMETHODIMP VLCControl2::put_AutoPlay(VARIANT_BOOL autoplay)
2224 _p_instance->setAutoPlay((VARIANT_FALSE != autoplay) ? TRUE: FALSE);
2228 STDMETHODIMP VLCControl2::get_BaseURL(BSTR *url)
2233 *url = SysAllocStringLen(_p_instance->getBaseURL(),
2234 SysStringLen(_p_instance->getBaseURL()));
2238 STDMETHODIMP VLCControl2::put_BaseURL(BSTR mrl)
2240 _p_instance->setBaseURL(mrl);
2245 STDMETHODIMP VLCControl2::get_MRL(BSTR *mrl)
2250 *mrl = SysAllocStringLen(_p_instance->getMRL(),
2251 SysStringLen(_p_instance->getMRL()));
2255 STDMETHODIMP VLCControl2::put_MRL(BSTR mrl)
2257 _p_instance->setMRL(mrl);
2263 STDMETHODIMP VLCControl2::get_Toolbar(VARIANT_BOOL *visible)
2265 if( NULL == visible )
2269 * Note to developpers
2271 * Returning the _b_toolbar is closer to the method specification.
2272 * But returning True when toolbar is not implemented so not displayed
2273 * could be bad for ActiveX users which rely on this value to show their
2274 * own toolbar if not provided by the ActiveX.
2276 * This is the reason why FALSE is returned, until toolbar get implemented.
2279 /* DISABLED for now */
2280 // *visible = _p_instance->getShowToolbar() ? VARIANT_TRUE: VARIANT_FALSE;
2282 *visible = VARIANT_FALSE;
2287 STDMETHODIMP VLCControl2::put_Toolbar(VARIANT_BOOL visible)
2289 _p_instance->setShowToolbar((VARIANT_FALSE != visible) ? TRUE: FALSE);
2294 STDMETHODIMP VLCControl2::get_StartTime(long *seconds)
2296 if( NULL == seconds )
2299 *seconds = _p_instance->getStartTime();
2304 STDMETHODIMP VLCControl2::put_StartTime(long seconds)
2306 _p_instance->setStartTime(seconds);
2311 STDMETHODIMP VLCControl2::get_VersionInfo(BSTR *version)
2313 if( NULL == version )
2316 const char *versionStr = libvlc_get_version();
2317 if( NULL != versionStr )
2319 *version = BSTRFromCStr(CP_UTF8, versionStr);
2321 return (NULL == *version) ? E_OUTOFMEMORY : NOERROR;
2327 STDMETHODIMP VLCControl2::get_Visible(VARIANT_BOOL *isVisible)
2329 if( NULL == isVisible )
2332 *isVisible = _p_instance->getVisible() ? VARIANT_TRUE : VARIANT_FALSE;
2337 STDMETHODIMP VLCControl2::put_Visible(VARIANT_BOOL isVisible)
2339 _p_instance->setVisible(isVisible != VARIANT_FALSE);
2344 STDMETHODIMP VLCControl2::get_Volume(long *volume)
2346 if( NULL == volume )
2349 *volume = _p_instance->getVolume();
2353 STDMETHODIMP VLCControl2::put_Volume(long volume)
2355 _p_instance->setVolume(volume);
2359 STDMETHODIMP VLCControl2::get_BackColor(OLE_COLOR *backcolor)
2361 if( NULL == backcolor )
2364 *backcolor = _p_instance->getBackColor();
2368 STDMETHODIMP VLCControl2::put_BackColor(OLE_COLOR backcolor)
2370 _p_instance->setBackColor(backcolor);
2374 STDMETHODIMP VLCControl2::get_audio(IVLCAudio** obj)
2380 if( NULL != _p_vlcaudio )
2382 _p_vlcaudio->AddRef();
2385 return E_OUTOFMEMORY;
2388 STDMETHODIMP VLCControl2::get_input(IVLCInput** obj)
2394 if( NULL != _p_vlcinput )
2396 _p_vlcinput->AddRef();
2399 return E_OUTOFMEMORY;
2402 STDMETHODIMP VLCControl2::get_log(IVLCLog** obj)
2408 if( NULL != _p_vlclog )
2410 _p_vlclog->AddRef();
2413 return E_OUTOFMEMORY;
2416 STDMETHODIMP VLCControl2::get_playlist(IVLCPlaylist** obj)
2421 *obj = _p_vlcplaylist;
2422 if( NULL != _p_vlcplaylist )
2424 _p_vlcplaylist->AddRef();
2427 return E_OUTOFMEMORY;
2430 STDMETHODIMP VLCControl2::get_video(IVLCVideo** obj)
2436 if( NULL != _p_vlcvideo )
2438 _p_vlcvideo->AddRef();
2441 return E_OUTOFMEMORY;