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_errmsg());
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( VLCMarquee )
55 EMIT_EXCEPTION_BRIDGE( VLCMessageIterator )
56 EMIT_EXCEPTION_BRIDGE( VLCMessages )
57 EMIT_EXCEPTION_BRIDGE( VLCLog )
58 EMIT_EXCEPTION_BRIDGE( VLCPlaylistItems )
59 EMIT_EXCEPTION_BRIDGE( VLCPlaylist )
60 EMIT_EXCEPTION_BRIDGE( VLCVideo )
61 EMIT_EXCEPTION_BRIDGE( VLCSubtitle )
63 #undef EMIT_EXCEPTION_BRIDGE
69 _p_typeinfo->Release();
72 HRESULT VLCAudio::loadTypeInfo(void)
75 if( NULL == _p_typeinfo )
79 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
82 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCAudio, &_p_typeinfo);
93 STDMETHODIMP VLCAudio::GetTypeInfoCount(UINT* pctInfo)
98 if( SUCCEEDED(loadTypeInfo()) )
106 STDMETHODIMP VLCAudio::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
108 if( NULL == ppTInfo )
111 if( SUCCEEDED(loadTypeInfo()) )
113 _p_typeinfo->AddRef();
114 *ppTInfo = _p_typeinfo;
121 STDMETHODIMP VLCAudio::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
122 UINT cNames, LCID lcid, DISPID* rgDispID)
124 if( SUCCEEDED(loadTypeInfo()) )
126 return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
131 STDMETHODIMP VLCAudio::Invoke(DISPID dispIdMember, REFIID riid,
132 LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
133 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
135 if( SUCCEEDED(loadTypeInfo()) )
137 return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
138 pVarResult, pExcepInfo, puArgErr);
143 STDMETHODIMP VLCAudio::get_mute(VARIANT_BOOL* mute)
148 libvlc_instance_t* p_libvlc;
149 HRESULT hr = _p_instance->getVLC(&p_libvlc);
151 *mute = libvlc_audio_get_mute(p_libvlc) ?
152 VARIANT_TRUE : VARIANT_FALSE;
156 STDMETHODIMP VLCAudio::put_mute(VARIANT_BOOL mute)
158 libvlc_instance_t* p_libvlc;
159 HRESULT hr = _p_instance->getVLC(&p_libvlc);
161 libvlc_audio_set_mute(p_libvlc, VARIANT_FALSE != mute);
165 STDMETHODIMP VLCAudio::get_volume(long* volume)
170 libvlc_instance_t* p_libvlc;
171 HRESULT hr = _p_instance->getVLC(&p_libvlc);
173 *volume = libvlc_audio_get_volume(p_libvlc);
177 STDMETHODIMP VLCAudio::put_volume(long volume)
179 libvlc_instance_t* p_libvlc;
180 HRESULT hr = _p_instance->getVLC(&p_libvlc);
183 libvlc_exception_t ex;
184 libvlc_exception_init(&ex);
186 libvlc_audio_set_volume(p_libvlc, volume, &ex);
187 hr = exception_bridge(&ex);
192 STDMETHODIMP VLCAudio::get_track(long* track)
197 libvlc_media_player_t* p_md;
198 HRESULT hr = _p_instance->getMD(&p_md);
201 libvlc_exception_t ex;
202 libvlc_exception_init(&ex);
204 *track = libvlc_audio_get_track(p_md, &ex);
205 hr = exception_bridge(&ex);
210 STDMETHODIMP VLCAudio::put_track(long track)
212 libvlc_media_player_t *p_md;
213 HRESULT hr = _p_instance->getMD(&p_md);
216 libvlc_exception_t ex;
217 libvlc_exception_init(&ex);
219 libvlc_audio_set_track(p_md, track, &ex);
220 hr = exception_bridge(&ex);
225 STDMETHODIMP VLCAudio::get_count(long* trackNumber)
227 if( NULL == trackNumber )
230 libvlc_media_player_t* p_md;
231 HRESULT hr = _p_instance->getMD(&p_md);
234 libvlc_exception_t ex;
235 libvlc_exception_init(&ex);
236 // get the number of audio track available and return it
237 *trackNumber = libvlc_audio_get_track_count(p_md, &ex);
238 hr = exception_bridge(&ex);
244 STDMETHODIMP VLCAudio::description(long trackID, BSTR* name)
249 libvlc_media_player_t* p_md;
250 libvlc_exception_t ex;
251 libvlc_exception_init(&ex);
253 HRESULT hr = _p_instance->getMD(&p_md);
257 const char *psz_name;
258 libvlc_track_description_t *p_trackDesc;
260 // get tracks description
261 p_trackDesc = libvlc_audio_get_track_description(p_md, &ex);
262 hr = exception_bridge(&ex);
266 //get the number of available track
267 i_limit = libvlc_audio_get_track_count(p_md, &ex);
268 hr = exception_bridge(&ex);
272 // check if the number given is a good one
273 if ( ( trackID > ( i_limit -1 ) ) || ( trackID < 0 ) )
276 // get the good trackDesc
277 for( i = 0 ; i < trackID ; i++ )
279 p_trackDesc = p_trackDesc->p_next;
281 // get the track name
282 psz_name = p_trackDesc->psz_name;
285 if( psz_name != NULL )
287 *name = BSTRFromCStr(CP_UTF8, psz_name);
288 return (NULL == *name) ? E_OUTOFMEMORY : NOERROR;
296 STDMETHODIMP VLCAudio::get_channel(long *channel)
298 if( NULL == channel )
301 libvlc_instance_t* p_libvlc;
302 HRESULT hr = _p_instance->getVLC(&p_libvlc);
305 libvlc_exception_t ex;
306 libvlc_exception_init(&ex);
308 *channel = libvlc_audio_get_channel(p_libvlc, &ex);
309 hr = exception_bridge(&ex);
314 STDMETHODIMP VLCAudio::put_channel(long channel)
316 libvlc_instance_t* p_libvlc;
317 HRESULT hr = _p_instance->getVLC(&p_libvlc);
320 libvlc_exception_t ex;
321 libvlc_exception_init(&ex);
323 libvlc_audio_set_channel(p_libvlc, channel, &ex);
324 hr = exception_bridge(&ex);
329 STDMETHODIMP VLCAudio::toggleMute()
331 libvlc_instance_t* p_libvlc;
332 HRESULT hr = _p_instance->getVLC(&p_libvlc);
334 libvlc_audio_toggle_mute(p_libvlc);
338 /*******************************************************************************/
340 VLCInput::~VLCInput()
343 _p_typeinfo->Release();
346 HRESULT VLCInput::loadTypeInfo(void)
348 HRESULT hr = NOERROR;
349 if( NULL == _p_typeinfo )
353 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
356 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCInput, &_p_typeinfo);
361 p_typelib->Release();
367 STDMETHODIMP VLCInput::GetTypeInfoCount(UINT* pctInfo)
369 if( NULL == pctInfo )
372 if( SUCCEEDED(loadTypeInfo()) )
380 STDMETHODIMP VLCInput::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
382 if( NULL == ppTInfo )
385 if( SUCCEEDED(loadTypeInfo()) )
387 _p_typeinfo->AddRef();
388 *ppTInfo = _p_typeinfo;
395 STDMETHODIMP VLCInput::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
396 UINT cNames, LCID lcid, DISPID* rgDispID)
398 if( SUCCEEDED(loadTypeInfo()) )
400 return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
405 STDMETHODIMP VLCInput::Invoke(DISPID dispIdMember, REFIID riid,
406 LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
407 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
409 if( SUCCEEDED(loadTypeInfo()) )
411 return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
412 pVarResult, pExcepInfo, puArgErr);
417 STDMETHODIMP VLCInput::get_length(double* length)
423 libvlc_media_player_t *p_md;
424 HRESULT hr = _p_instance->getMD(&p_md);
427 libvlc_exception_t ex;
428 libvlc_exception_init(&ex);
430 *length = (double)libvlc_media_player_get_length(p_md, &ex);
431 hr = exception_bridge(&ex);
436 STDMETHODIMP VLCInput::get_position(double* position)
438 if( NULL == position )
442 libvlc_media_player_t *p_md;
443 HRESULT hr = _p_instance->getMD(&p_md);
446 libvlc_exception_t ex;
447 libvlc_exception_init(&ex);
449 *position = libvlc_media_player_get_position(p_md, &ex);
450 hr = exception_bridge(&ex);
455 STDMETHODIMP VLCInput::put_position(double position)
457 libvlc_media_player_t *p_md;
458 HRESULT hr = _p_instance->getMD(&p_md);
461 libvlc_exception_t ex;
462 libvlc_exception_init(&ex);
464 libvlc_media_player_set_position(p_md, position, &ex);
465 hr = exception_bridge(&ex);
470 STDMETHODIMP VLCInput::get_time(double* time)
475 libvlc_media_player_t *p_md;
476 HRESULT hr = _p_instance->getMD(&p_md);
479 libvlc_exception_t ex;
480 libvlc_exception_init(&ex);
482 *time = (double)libvlc_media_player_get_time(p_md, &ex);
483 hr = exception_bridge(&ex);
488 STDMETHODIMP VLCInput::put_time(double time)
490 libvlc_media_player_t *p_md;
491 HRESULT hr = _p_instance->getMD(&p_md);
494 libvlc_exception_t ex;
495 libvlc_exception_init(&ex);
497 libvlc_media_player_set_time(p_md, (int64_t)time, &ex);
498 hr = exception_bridge(&ex);
503 STDMETHODIMP VLCInput::get_state(long* state)
508 libvlc_media_player_t *p_md;
509 HRESULT hr = _p_instance->getMD(&p_md);
512 libvlc_exception_t ex;
513 libvlc_exception_init(&ex);
515 *state = libvlc_media_player_get_state(p_md, &ex);
516 if( libvlc_exception_raised(&ex) )
518 // don't fail, just return the idle state
520 libvlc_exception_clear(&ex);
526 STDMETHODIMP VLCInput::get_rate(double* rate)
531 libvlc_media_player_t *p_md;
532 HRESULT hr = _p_instance->getMD(&p_md);
535 libvlc_exception_t ex;
536 libvlc_exception_init(&ex);
538 *rate = libvlc_media_player_get_rate(p_md, &ex);
539 hr = exception_bridge(&ex);
544 STDMETHODIMP VLCInput::put_rate(double rate)
546 libvlc_media_player_t *p_md;
547 HRESULT hr = _p_instance->getMD(&p_md);
550 libvlc_exception_t ex;
551 libvlc_exception_init(&ex);
553 libvlc_media_player_set_rate(p_md, rate, &ex);
554 hr = exception_bridge(&ex);
559 STDMETHODIMP VLCInput::get_fps(double* fps)
565 libvlc_media_player_t *p_md;
566 HRESULT hr = _p_instance->getMD(&p_md);
569 libvlc_exception_t ex;
570 libvlc_exception_init(&ex);
572 *fps = libvlc_media_player_get_fps(p_md, &ex);
573 hr = exception_bridge(&ex);
578 STDMETHODIMP VLCInput::get_hasVout(VARIANT_BOOL* hasVout)
580 if( NULL == hasVout )
583 libvlc_media_player_t *p_md;
584 HRESULT hr = _p_instance->getMD(&p_md);
587 libvlc_exception_t ex;
588 libvlc_exception_init(&ex);
590 *hasVout = libvlc_media_player_has_vout(p_md, &ex) ?
591 VARIANT_TRUE : VARIANT_FALSE;
592 hr = exception_bridge(&ex);
597 /*******************************************************************************/
601 delete _p_vlcmessages;
603 libvlc_log_close(_p_log);
606 _p_typeinfo->Release();
609 HRESULT VLCLog::loadTypeInfo(void)
611 HRESULT hr = NOERROR;
612 if( NULL == _p_typeinfo )
616 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
619 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCLog, &_p_typeinfo);
624 p_typelib->Release();
630 STDMETHODIMP VLCLog::GetTypeInfoCount(UINT* pctInfo)
632 if( NULL == pctInfo )
635 if( SUCCEEDED(loadTypeInfo()) )
643 STDMETHODIMP VLCLog::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
645 if( NULL == ppTInfo )
648 if( SUCCEEDED(loadTypeInfo()) )
650 _p_typeinfo->AddRef();
651 *ppTInfo = _p_typeinfo;
658 STDMETHODIMP VLCLog::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
659 UINT cNames, LCID lcid, DISPID* rgDispID)
661 if( SUCCEEDED(loadTypeInfo()) )
663 return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
668 STDMETHODIMP VLCLog::Invoke(DISPID dispIdMember, REFIID riid,
669 LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
670 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
672 if( SUCCEEDED(loadTypeInfo()) )
674 return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
675 pVarResult, pExcepInfo, puArgErr);
680 STDMETHODIMP VLCLog::get_messages(IVLCMessages** obj)
685 *obj = _p_vlcmessages;
686 if( NULL != _p_vlcmessages )
688 _p_vlcmessages->AddRef();
691 return E_OUTOFMEMORY;
694 STDMETHODIMP VLCLog::get_verbosity(long* level)
701 libvlc_instance_t* p_libvlc;
702 HRESULT hr = _p_instance->getVLC(&p_libvlc);
704 *level = libvlc_get_log_verbosity(p_libvlc);
709 /* log is not enabled, return -1 */
715 STDMETHODIMP VLCLog::put_verbosity(long verbosity)
717 libvlc_instance_t* p_libvlc;
718 HRESULT hr = _p_instance->getVLC(&p_libvlc);
721 libvlc_exception_t ex;
722 libvlc_exception_init(&ex);
728 _p_log = libvlc_log_open(p_libvlc, &ex);
729 hr = exception_bridge(&ex);
732 libvlc_set_log_verbosity(p_libvlc, (unsigned)verbosity);
736 /* close log when verbosity is set to -1 */
737 libvlc_log_close(_p_log);
740 hr = exception_bridge(&ex);
745 /*******************************************************************************/
747 VLCMarquee::~VLCMarquee()
750 _p_typeinfo->Release();
753 HRESULT VLCMarquee::loadTypeInfo(void)
755 HRESULT hr = NOERROR;
756 if( NULL == _p_typeinfo )
760 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
763 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCMarquee, &_p_typeinfo);
768 p_typelib->Release();
774 STDMETHODIMP VLCMarquee::GetTypeInfoCount(UINT* pctInfo)
776 if( NULL == pctInfo )
779 if( SUCCEEDED(loadTypeInfo()) )
787 STDMETHODIMP VLCMarquee::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
789 if( NULL == ppTInfo )
792 if( SUCCEEDED(loadTypeInfo()) )
794 _p_typeinfo->AddRef();
795 *ppTInfo = _p_typeinfo;
802 STDMETHODIMP VLCMarquee::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
803 UINT cNames, LCID lcid, DISPID* rgDispID)
805 if( SUCCEEDED(loadTypeInfo()) )
807 return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
812 STDMETHODIMP VLCMarquee::Invoke(DISPID dispIdMember, REFIID riid,
813 LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
814 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
816 if( SUCCEEDED(loadTypeInfo()) )
818 return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
819 pVarResult, pExcepInfo, puArgErr);
824 STDMETHODIMP VLCMarquee::enable()
826 libvlc_media_player_t *p_md;
827 HRESULT hr = _p_instance->getMD(&p_md);
830 libvlc_exception_t ex;
831 libvlc_exception_init(&ex);
833 libvlc_video_set_marquee_option_as_int(p_md, libvlc_marquee_Enabled, true, &ex);
834 hr = exception_bridge(&ex);
839 STDMETHODIMP VLCMarquee::disable()
841 libvlc_media_player_t *p_md;
842 HRESULT hr = _p_instance->getMD(&p_md);
845 libvlc_exception_t ex;
846 libvlc_exception_init(&ex);
848 libvlc_video_set_marquee_option_as_int(p_md, libvlc_marquee_Enabled, false, &ex);
849 hr = exception_bridge(&ex);
854 STDMETHODIMP VLCMarquee::color(long val)
856 libvlc_media_player_t *p_md;
857 HRESULT hr = _p_instance->getMD(&p_md);
860 libvlc_exception_t ex;
861 libvlc_exception_init(&ex);
863 libvlc_video_set_marquee_option_as_int(p_md, libvlc_marquee_Color, val, &ex);
864 hr = exception_bridge(&ex);
869 STDMETHODIMP VLCMarquee::opacity(long val)
871 libvlc_media_player_t *p_md;
872 HRESULT hr = _p_instance->getMD(&p_md);
875 libvlc_exception_t ex;
876 libvlc_exception_init(&ex);
878 libvlc_video_set_marquee_option_as_int(p_md, libvlc_marquee_Opacity, val, &ex);
879 hr = exception_bridge(&ex);
884 STDMETHODIMP VLCMarquee::position(long val)
886 libvlc_media_player_t *p_md;
887 HRESULT hr = _p_instance->getMD(&p_md);
890 libvlc_exception_t ex;
891 libvlc_exception_init(&ex);
893 libvlc_video_set_marquee_option_as_int(p_md, libvlc_marquee_Position, val, &ex);
894 hr = exception_bridge(&ex);
899 STDMETHODIMP VLCMarquee::refresh(long val)
901 libvlc_media_player_t *p_md;
902 HRESULT hr = _p_instance->getMD(&p_md);
905 libvlc_exception_t ex;
906 libvlc_exception_init(&ex);
908 libvlc_video_set_marquee_option_as_int(p_md, libvlc_marquee_Refresh, val, &ex);
909 hr = exception_bridge(&ex);
914 STDMETHODIMP VLCMarquee::size(long val)
916 libvlc_media_player_t *p_md;
917 HRESULT hr = _p_instance->getMD(&p_md);
920 libvlc_exception_t ex;
921 libvlc_exception_init(&ex);
923 libvlc_video_set_marquee_option_as_int(p_md, libvlc_marquee_Size, val, &ex);
924 hr = exception_bridge(&ex);
929 STDMETHODIMP VLCMarquee::text(BSTR text)
931 libvlc_media_player_t *p_md;
932 HRESULT hr = _p_instance->getMD(&p_md);
935 libvlc_exception_t ex;
936 libvlc_exception_init(&ex);
938 char *psz_text = CStrFromBSTR(CP_UTF8, text);
939 libvlc_video_set_marquee_option_as_string(p_md, libvlc_marquee_Text, psz_text, &ex);
940 hr = exception_bridge(&ex);
941 CoTaskMemFree(psz_text);
946 STDMETHODIMP VLCMarquee::timeout(long val)
948 libvlc_media_player_t *p_md;
949 HRESULT hr = _p_instance->getMD(&p_md);
952 libvlc_exception_t ex;
953 libvlc_exception_init(&ex);
955 libvlc_video_set_marquee_option_as_int(p_md, libvlc_marquee_Timeout, val, &ex);
956 hr = exception_bridge(&ex);
961 STDMETHODIMP VLCMarquee::x(long val)
963 libvlc_media_player_t *p_md;
964 HRESULT hr = _p_instance->getMD(&p_md);
967 libvlc_exception_t ex;
968 libvlc_exception_init(&ex);
970 libvlc_video_set_marquee_option_as_int(p_md, libvlc_marquee_X, val, &ex);
971 hr = exception_bridge(&ex);
976 STDMETHODIMP VLCMarquee::y(long val)
978 libvlc_media_player_t *p_md;
979 HRESULT hr = _p_instance->getMD(&p_md);
982 libvlc_exception_t ex;
983 libvlc_exception_init(&ex);
985 libvlc_video_set_marquee_option_as_int(p_md, libvlc_marquee_Y, val, &ex);
986 hr = exception_bridge(&ex);
991 /*******************************************************************************/
993 /* STL forward iterator used by VLCEnumIterator class to implement IEnumVARIANT */
995 class VLCMessageSTLIterator
1000 VLCMessageSTLIterator(IVLCMessageIterator* iter) : iter(iter), msg(NULL)
1002 // get first message
1006 VLCMessageSTLIterator(const VLCMessageSTLIterator& other)
1016 virtual ~VLCMessageSTLIterator()
1025 // we only need prefix ++ operator
1026 VLCMessageSTLIterator& operator++()
1028 VARIANT_BOOL hasNext = VARIANT_FALSE;
1031 iter->get_hasNext(&hasNext);
1038 if( VARIANT_TRUE == hasNext ) {
1045 VARIANT operator*() const
1051 if( SUCCEEDED(msg->QueryInterface(IID_IDispatch,
1052 (LPVOID*)&V_DISPATCH(&v))) )
1054 V_VT(&v) = VT_DISPATCH;
1060 bool operator==(const VLCMessageSTLIterator& other) const
1062 return msg == other.msg;
1065 bool operator!=(const VLCMessageSTLIterator& other) const
1067 return msg != other.msg;
1071 IVLCMessageIterator* iter;
1075 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
1077 VLCMessages::~VLCMessages()
1080 _p_typeinfo->Release();
1083 HRESULT VLCMessages::loadTypeInfo(void)
1085 HRESULT hr = NOERROR;
1086 if( NULL == _p_typeinfo )
1088 ITypeLib *p_typelib;
1090 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
1093 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCMessages, &_p_typeinfo);
1098 p_typelib->Release();
1104 STDMETHODIMP VLCMessages::GetTypeInfoCount(UINT* pctInfo)
1106 if( NULL == pctInfo )
1107 return E_INVALIDARG;
1109 if( SUCCEEDED(loadTypeInfo()) )
1117 STDMETHODIMP VLCMessages::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
1119 if( NULL == ppTInfo )
1120 return E_INVALIDARG;
1122 if( SUCCEEDED(loadTypeInfo()) )
1124 _p_typeinfo->AddRef();
1125 *ppTInfo = _p_typeinfo;
1132 STDMETHODIMP VLCMessages::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
1133 UINT cNames, LCID lcid, DISPID* rgDispID)
1135 if( SUCCEEDED(loadTypeInfo()) )
1137 return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
1142 STDMETHODIMP VLCMessages::Invoke(DISPID dispIdMember, REFIID riid,
1143 LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
1144 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
1146 if( SUCCEEDED(loadTypeInfo()) )
1148 return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
1149 pVarResult, pExcepInfo, puArgErr);
1154 STDMETHODIMP VLCMessages::get__NewEnum(LPUNKNOWN* _NewEnum)
1156 if( NULL == _NewEnum )
1159 IVLCMessageIterator* iter = NULL;
1162 *_NewEnum= new VLCEnumIterator<IID_IEnumVARIANT,
1165 VLCMessageSTLIterator>
1166 (VLCMessageSTLIterator(iter), VLCMessageSTLIterator(NULL));
1168 return *_NewEnum ? S_OK : E_OUTOFMEMORY;
1171 STDMETHODIMP VLCMessages::clear()
1173 libvlc_log_t *p_log = _p_vlclog->_p_log;
1175 libvlc_log_clear(p_log);
1179 STDMETHODIMP VLCMessages::get_count(long* count)
1184 libvlc_log_t *p_log = _p_vlclog->_p_log;
1185 *count = libvlc_log_count(p_log);
1189 STDMETHODIMP VLCMessages::iterator(IVLCMessageIterator** iter)
1194 *iter = new VLCMessageIterator(_p_instance, _p_vlclog);
1196 return *iter ? S_OK : E_OUTOFMEMORY;
1199 /*******************************************************************************/
1201 VLCMessageIterator::VLCMessageIterator(VLCPlugin *p_instance, VLCLog* p_vlclog ) :
1202 _p_instance(p_instance),
1207 if( p_vlclog->_p_log )
1209 _p_iter = libvlc_log_get_iterator(p_vlclog->_p_log, NULL);
1215 VLCMessageIterator::~VLCMessageIterator()
1218 libvlc_log_iterator_free(_p_iter);
1221 _p_typeinfo->Release();
1224 HRESULT VLCMessageIterator::loadTypeInfo(void)
1226 HRESULT hr = NOERROR;
1227 if( NULL == _p_typeinfo )
1229 ITypeLib *p_typelib;
1231 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
1234 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCMessageIterator, &_p_typeinfo);
1239 p_typelib->Release();
1245 STDMETHODIMP VLCMessageIterator::GetTypeInfoCount(UINT* pctInfo)
1247 if( NULL == pctInfo )
1248 return E_INVALIDARG;
1250 if( SUCCEEDED(loadTypeInfo()) )
1258 STDMETHODIMP VLCMessageIterator::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
1260 if( NULL == ppTInfo )
1261 return E_INVALIDARG;
1263 if( SUCCEEDED(loadTypeInfo()) )
1265 _p_typeinfo->AddRef();
1266 *ppTInfo = _p_typeinfo;
1273 STDMETHODIMP VLCMessageIterator::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
1274 UINT cNames, LCID lcid, DISPID* rgDispID)
1276 if( SUCCEEDED(loadTypeInfo()) )
1278 return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
1283 STDMETHODIMP VLCMessageIterator::Invoke(DISPID dispIdMember, REFIID riid,
1284 LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
1285 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
1287 if( SUCCEEDED(loadTypeInfo()) )
1289 return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
1290 pVarResult, pExcepInfo, puArgErr);
1295 STDMETHODIMP VLCMessageIterator::get_hasNext(VARIANT_BOOL* hasNext)
1297 if( NULL == hasNext )
1300 if( _p_iter && _p_vlclog->_p_log )
1302 *hasNext = libvlc_log_iterator_has_next(_p_iter) ?
1303 VARIANT_TRUE : VARIANT_FALSE;
1307 *hasNext = VARIANT_FALSE;
1312 STDMETHODIMP VLCMessageIterator::next(IVLCMessage** message)
1316 if( NULL == message )
1319 if( _p_iter && _p_vlclog->_p_log )
1321 struct libvlc_log_message_t buffer;
1323 buffer.sizeof_msg = sizeof(buffer);
1325 libvlc_exception_t ex;
1326 libvlc_exception_init(&ex);
1328 libvlc_log_iterator_next(_p_iter, &buffer, &ex);
1329 *message = new VLCMessage(_p_instance, buffer);
1336 /*******************************************************************************/
1338 VLCMessage::~VLCMessage()
1341 _p_typeinfo->Release();
1344 HRESULT VLCMessage::loadTypeInfo(void)
1346 HRESULT hr = NOERROR;
1347 if( NULL == _p_typeinfo )
1349 ITypeLib *p_typelib;
1351 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
1354 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCMessage, &_p_typeinfo);
1359 p_typelib->Release();
1365 STDMETHODIMP VLCMessage::GetTypeInfoCount(UINT* pctInfo)
1367 if( NULL == pctInfo )
1368 return E_INVALIDARG;
1370 if( SUCCEEDED(loadTypeInfo()) )
1378 STDMETHODIMP VLCMessage::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
1380 if( NULL == ppTInfo )
1381 return E_INVALIDARG;
1383 if( SUCCEEDED(loadTypeInfo()) )
1385 _p_typeinfo->AddRef();
1386 *ppTInfo = _p_typeinfo;
1393 STDMETHODIMP VLCMessage::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
1394 UINT cNames, LCID lcid, DISPID* rgDispID)
1396 if( SUCCEEDED(loadTypeInfo()) )
1398 return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
1403 STDMETHODIMP VLCMessage::Invoke(DISPID dispIdMember, REFIID riid,
1404 LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
1405 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
1407 if( SUCCEEDED(loadTypeInfo()) )
1409 return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
1410 pVarResult, pExcepInfo, puArgErr);
1415 inline const char *msgSeverity(int sev)
1430 STDMETHODIMP VLCMessage::get__Value(VARIANT* _Value)
1432 if( NULL == _Value )
1437 snprintf(buffer, sizeof(buffer), "%s %s %s: %s",
1438 _msg.psz_type, _msg.psz_name, msgSeverity(_msg.i_severity), _msg.psz_message);
1440 V_VT(_Value) = VT_BSTR;
1441 V_BSTR(_Value) = BSTRFromCStr(CP_UTF8, buffer);
1446 STDMETHODIMP VLCMessage::get_severity(long* level)
1451 *level = _msg.i_severity;
1456 STDMETHODIMP VLCMessage::get_type(BSTR* type)
1461 *type = BSTRFromCStr(CP_UTF8, _msg.psz_type);
1466 STDMETHODIMP VLCMessage::get_name(BSTR* name)
1471 *name = BSTRFromCStr(CP_UTF8, _msg.psz_name);
1476 STDMETHODIMP VLCMessage::get_header(BSTR* header)
1478 if( NULL == header )
1481 *header = BSTRFromCStr(CP_UTF8, _msg.psz_header);
1486 STDMETHODIMP VLCMessage::get_message(BSTR* message)
1488 if( NULL == message )
1491 *message = BSTRFromCStr(CP_UTF8, _msg.psz_message);
1496 /*******************************************************************************/
1498 VLCPlaylistItems::~VLCPlaylistItems()
1501 _p_typeinfo->Release();
1504 HRESULT VLCPlaylistItems::loadTypeInfo(void)
1506 HRESULT hr = NOERROR;
1507 if( NULL == _p_typeinfo )
1509 ITypeLib *p_typelib;
1511 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
1514 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCPlaylistItems, &_p_typeinfo);
1519 p_typelib->Release();
1525 STDMETHODIMP VLCPlaylistItems::GetTypeInfoCount(UINT* pctInfo)
1527 if( NULL == pctInfo )
1528 return E_INVALIDARG;
1530 if( SUCCEEDED(loadTypeInfo()) )
1538 STDMETHODIMP VLCPlaylistItems::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
1540 if( NULL == ppTInfo )
1541 return E_INVALIDARG;
1543 if( SUCCEEDED(loadTypeInfo()) )
1545 _p_typeinfo->AddRef();
1546 *ppTInfo = _p_typeinfo;
1553 STDMETHODIMP VLCPlaylistItems::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
1554 UINT cNames, LCID lcid, DISPID* rgDispID)
1556 if( SUCCEEDED(loadTypeInfo()) )
1558 return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
1563 STDMETHODIMP VLCPlaylistItems::Invoke(DISPID dispIdMember, REFIID riid,
1564 LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
1565 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
1567 if( SUCCEEDED(loadTypeInfo()) )
1569 return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
1570 pVarResult, pExcepInfo, puArgErr);
1575 STDMETHODIMP VLCPlaylistItems::get_count(long* count)
1580 libvlc_exception_t ex;
1581 libvlc_exception_init(&ex);
1583 *count = _p_instance->playlist_count(&ex);
1584 return exception_bridge(&ex);
1587 STDMETHODIMP VLCPlaylistItems::clear()
1589 libvlc_exception_t ex;
1590 libvlc_exception_init(&ex);
1592 _p_instance->playlist_clear(&ex);
1593 return exception_bridge(&ex);
1596 STDMETHODIMP VLCPlaylistItems::remove(long item)
1598 libvlc_instance_t* p_libvlc;
1599 HRESULT hr = _p_instance->getVLC(&p_libvlc);
1602 libvlc_exception_t ex;
1603 libvlc_exception_init(&ex);
1605 _p_instance->playlist_delete_item(item, &ex);
1606 hr = exception_bridge(&ex);
1611 /*******************************************************************************/
1613 VLCPlaylist::~VLCPlaylist()
1615 delete _p_vlcplaylistitems;
1617 _p_typeinfo->Release();
1620 HRESULT VLCPlaylist::loadTypeInfo(void)
1622 HRESULT hr = NOERROR;
1623 if( NULL == _p_typeinfo )
1625 ITypeLib *p_typelib;
1627 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
1630 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCPlaylist, &_p_typeinfo);
1635 p_typelib->Release();
1641 STDMETHODIMP VLCPlaylist::GetTypeInfoCount(UINT* pctInfo)
1643 if( NULL == pctInfo )
1644 return E_INVALIDARG;
1646 if( SUCCEEDED(loadTypeInfo()) )
1654 STDMETHODIMP VLCPlaylist::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
1656 if( NULL == ppTInfo )
1657 return E_INVALIDARG;
1659 if( SUCCEEDED(loadTypeInfo()) )
1661 _p_typeinfo->AddRef();
1662 *ppTInfo = _p_typeinfo;
1669 STDMETHODIMP VLCPlaylist::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
1670 UINT cNames, LCID lcid, DISPID* rgDispID)
1672 if( SUCCEEDED(loadTypeInfo()) )
1674 return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
1679 STDMETHODIMP VLCPlaylist::Invoke(DISPID dispIdMember, REFIID riid,
1680 LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
1681 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
1683 if( SUCCEEDED(loadTypeInfo()) )
1685 return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
1686 pVarResult, pExcepInfo, puArgErr);
1691 STDMETHODIMP VLCPlaylist::get_itemCount(long* count)
1697 libvlc_exception_t ex;
1698 libvlc_exception_init(&ex);
1700 *count = _p_instance->playlist_count(&ex);
1701 return exception_bridge(&ex);
1704 STDMETHODIMP VLCPlaylist::get_isPlaying(VARIANT_BOOL* isPlaying)
1706 if( NULL == isPlaying )
1709 libvlc_media_player_t *p_md;
1710 HRESULT hr = _p_instance->getMD(&p_md);
1713 libvlc_exception_t ex;
1714 libvlc_exception_init(&ex);
1716 *isPlaying = libvlc_media_player_is_playing(p_md, &ex) ?
1717 VARIANT_TRUE: VARIANT_FALSE;
1718 libvlc_exception_clear(&ex);
1723 STDMETHODIMP VLCPlaylist::add(BSTR uri, VARIANT name, VARIANT options, long* item)
1728 if( 0 == SysStringLen(uri) )
1729 return E_INVALIDARG;
1731 libvlc_instance_t* p_libvlc;
1732 HRESULT hr = _p_instance->getVLC(&p_libvlc);
1735 libvlc_exception_t ex;
1736 libvlc_exception_init(&ex);
1738 char *psz_uri = NULL;
1739 if( SysStringLen(_p_instance->getBaseURL()) > 0 )
1742 ** if the MRL a relative URL, we should end up with an absolute URL
1744 LPWSTR abs_url = CombineURL(_p_instance->getBaseURL(), uri);
1745 if( NULL != abs_url )
1747 psz_uri = CStrFromWSTR(CP_UTF8, abs_url, wcslen(abs_url));
1748 CoTaskMemFree(abs_url);
1752 psz_uri = CStrFromBSTR(CP_UTF8, uri);
1758 ** baseURL is empty, assume MRL is absolute
1760 psz_uri = CStrFromBSTR(CP_UTF8, uri);
1763 if( NULL == psz_uri )
1765 return E_OUTOFMEMORY;
1769 char **ppsz_options;
1771 hr = VLCControl::CreateTargetOptions(CP_UTF8, &options, &ppsz_options, &i_options);
1774 CoTaskMemFree(psz_uri);
1778 char *psz_name = NULL;
1780 VariantInit(&v_name);
1781 if( SUCCEEDED(VariantChangeType(&v_name, &name, 0, VT_BSTR)) )
1783 if( SysStringLen(V_BSTR(&v_name)) > 0 )
1784 psz_name = CStrFromBSTR(CP_UTF8, V_BSTR(&v_name));
1786 VariantClear(&v_name);
1789 *item = _p_instance->playlist_add_extended_untrusted(psz_uri,
1790 i_options, const_cast<const char **>(ppsz_options), &ex);
1792 VLCControl::FreeTargetOptions(ppsz_options, i_options);
1793 CoTaskMemFree(psz_uri);
1794 if( psz_name ) /* XXX Do we even need to check? */
1795 CoTaskMemFree(psz_name);
1796 hr = exception_bridge(&ex);
1801 STDMETHODIMP VLCPlaylist::play()
1803 libvlc_exception_t ex;
1804 libvlc_exception_init(&ex);
1806 _p_instance->playlist_play(&ex);
1807 return exception_bridge(&ex);
1810 STDMETHODIMP VLCPlaylist::playItem(long item)
1812 libvlc_exception_t ex;
1813 libvlc_exception_init(&ex);
1815 _p_instance->playlist_play_item(item,&ex);
1816 return exception_bridge(&ex);;
1819 STDMETHODIMP VLCPlaylist::togglePause()
1821 libvlc_media_player_t* p_md;
1822 HRESULT hr = _p_instance->getMD(&p_md);
1825 libvlc_exception_t ex;
1826 libvlc_exception_init(&ex);
1828 libvlc_media_player_pause(p_md, &ex);
1829 hr = exception_bridge(&ex);;
1834 STDMETHODIMP VLCPlaylist::stop()
1836 libvlc_media_player_t *p_md;
1837 HRESULT hr = _p_instance->getMD(&p_md);
1840 libvlc_exception_t ex;
1841 libvlc_exception_init(&ex);
1843 libvlc_media_player_stop(p_md, &ex);
1844 hr = exception_bridge(&ex);;
1849 STDMETHODIMP VLCPlaylist::next()
1851 libvlc_exception_t ex;
1852 libvlc_exception_init(&ex);
1854 _p_instance->playlist_next(&ex);
1855 return exception_bridge(&ex);;
1858 STDMETHODIMP VLCPlaylist::prev()
1860 libvlc_exception_t ex;
1861 libvlc_exception_init(&ex);
1863 _p_instance->playlist_prev(&ex);
1864 return exception_bridge(&ex);;
1867 STDMETHODIMP VLCPlaylist::clear()
1869 libvlc_exception_t ex;
1870 libvlc_exception_init(&ex);
1872 _p_instance->playlist_clear(&ex);
1873 return exception_bridge(&ex);;
1876 STDMETHODIMP VLCPlaylist::removeItem(long item)
1878 libvlc_instance_t* p_libvlc;
1879 HRESULT hr = _p_instance->getVLC(&p_libvlc);
1882 libvlc_exception_t ex;
1883 libvlc_exception_init(&ex);
1885 _p_instance->playlist_delete_item(item, &ex);
1886 hr = exception_bridge(&ex);;
1891 STDMETHODIMP VLCPlaylist::get_items(IVLCPlaylistItems** obj)
1896 *obj = _p_vlcplaylistitems;
1897 if( NULL != _p_vlcplaylistitems )
1899 _p_vlcplaylistitems->AddRef();
1902 return E_OUTOFMEMORY;
1905 /*******************************************************************************/
1907 VLCSubtitle::~VLCSubtitle()
1910 _p_typeinfo->Release();
1913 HRESULT VLCSubtitle::loadTypeInfo(void)
1915 HRESULT hr = NOERROR;
1916 if( NULL == _p_typeinfo )
1918 ITypeLib *p_typelib;
1920 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
1923 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCSubtitle, &_p_typeinfo);
1928 p_typelib->Release();
1934 STDMETHODIMP VLCSubtitle::GetTypeInfoCount(UINT* pctInfo)
1936 if( NULL == pctInfo )
1937 return E_INVALIDARG;
1939 if( SUCCEEDED(loadTypeInfo()) )
1947 STDMETHODIMP VLCSubtitle::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
1949 if( NULL == ppTInfo )
1950 return E_INVALIDARG;
1952 if( SUCCEEDED(loadTypeInfo()) )
1954 _p_typeinfo->AddRef();
1955 *ppTInfo = _p_typeinfo;
1962 STDMETHODIMP VLCSubtitle::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
1963 UINT cNames, LCID lcid, DISPID* rgDispID)
1965 if( SUCCEEDED(loadTypeInfo()) )
1967 return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
1972 STDMETHODIMP VLCSubtitle::Invoke(DISPID dispIdMember, REFIID riid,
1973 LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
1974 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
1976 if( SUCCEEDED(loadTypeInfo()) )
1978 return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
1979 pVarResult, pExcepInfo, puArgErr);
1984 STDMETHODIMP VLCSubtitle::get_track(long* spu)
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 *spu = libvlc_video_get_spu(p_md, &ex);
1997 hr = exception_bridge(&ex);
2002 STDMETHODIMP VLCSubtitle::put_track(long spu)
2004 libvlc_media_player_t *p_md;
2005 HRESULT hr = _p_instance->getMD(&p_md);
2008 libvlc_exception_t ex;
2009 libvlc_exception_init(&ex);
2011 libvlc_video_set_spu(p_md, spu, &ex);
2012 hr = exception_bridge(&ex);
2017 STDMETHODIMP VLCSubtitle::get_count(long* spuNumber)
2019 if( NULL == spuNumber )
2022 libvlc_media_player_t *p_md;
2023 HRESULT hr = _p_instance->getMD(&p_md);
2026 libvlc_exception_t ex;
2027 libvlc_exception_init(&ex);
2028 // get the number of video subtitle available and return it
2029 *spuNumber = libvlc_video_get_spu_count(p_md, &ex);
2030 hr = exception_bridge(&ex);
2036 STDMETHODIMP VLCSubtitle::description(long nameID, BSTR* name)
2041 libvlc_media_player_t* p_md;
2042 libvlc_exception_t ex;
2043 libvlc_exception_init(&ex);
2045 HRESULT hr = _p_instance->getMD(&p_md);
2049 const char *psz_name;
2050 libvlc_track_description_t *p_spuDesc;
2052 // get subtitles description
2053 p_spuDesc = libvlc_video_get_spu_description(p_md, &ex);
2054 hr = exception_bridge(&ex);
2058 // get the number of available subtitle
2059 i_limit = libvlc_video_get_spu_count(p_md, &ex);
2060 hr = exception_bridge(&ex);
2064 // check if the number given is a good one
2065 if ( ( nameID > ( i_limit -1 ) ) || ( nameID < 0 ) )
2068 // get the good spuDesc
2069 for( i = 0 ; i < nameID ; i++ )
2071 p_spuDesc = p_spuDesc->p_next;
2073 // get the subtitle name
2074 psz_name = p_spuDesc->psz_name;
2077 if( psz_name != NULL )
2079 *name = BSTRFromCStr(CP_UTF8, psz_name);
2080 return (NULL == *name) ? E_OUTOFMEMORY : NOERROR;
2088 /*******************************************************************************/
2090 VLCVideo::~VLCVideo()
2092 delete _p_vlcmarquee;
2094 _p_typeinfo->Release();
2097 HRESULT VLCVideo::loadTypeInfo(void)
2099 HRESULT hr = NOERROR;
2100 if( NULL == _p_typeinfo )
2102 ITypeLib *p_typelib;
2104 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
2107 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCVideo, &_p_typeinfo);
2112 p_typelib->Release();
2118 STDMETHODIMP VLCVideo::GetTypeInfoCount(UINT* pctInfo)
2120 if( NULL == pctInfo )
2121 return E_INVALIDARG;
2123 if( SUCCEEDED(loadTypeInfo()) )
2131 STDMETHODIMP VLCVideo::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
2133 if( NULL == ppTInfo )
2134 return E_INVALIDARG;
2136 if( SUCCEEDED(loadTypeInfo()) )
2138 _p_typeinfo->AddRef();
2139 *ppTInfo = _p_typeinfo;
2146 STDMETHODIMP VLCVideo::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
2147 UINT cNames, LCID lcid, DISPID* rgDispID)
2149 if( SUCCEEDED(loadTypeInfo()) )
2151 return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
2156 STDMETHODIMP VLCVideo::Invoke(DISPID dispIdMember, REFIID riid,
2157 LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
2158 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
2160 if( SUCCEEDED(loadTypeInfo()) )
2162 return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
2163 pVarResult, pExcepInfo, puArgErr);
2168 STDMETHODIMP VLCVideo::get_fullscreen(VARIANT_BOOL* fullscreen)
2170 if( NULL == fullscreen )
2173 libvlc_media_player_t *p_md;
2174 HRESULT hr = _p_instance->getMD(&p_md);
2177 libvlc_exception_t ex;
2178 libvlc_exception_init(&ex);
2180 *fullscreen = libvlc_get_fullscreen(p_md, &ex) ?
2181 VARIANT_TRUE : VARIANT_FALSE;
2182 hr = exception_bridge(&ex);
2187 STDMETHODIMP VLCVideo::put_fullscreen(VARIANT_BOOL fullscreen)
2189 libvlc_media_player_t *p_md;
2190 HRESULT hr = _p_instance->getMD(&p_md);
2193 libvlc_exception_t ex;
2194 libvlc_exception_init(&ex);
2196 libvlc_set_fullscreen(p_md, VARIANT_FALSE != fullscreen, &ex);
2197 hr = exception_bridge(&ex);
2202 STDMETHODIMP VLCVideo::get_width(long* width)
2207 libvlc_media_player_t *p_md;
2208 HRESULT hr = _p_instance->getMD(&p_md);
2211 libvlc_exception_t ex;
2212 libvlc_exception_init(&ex);
2214 *width = libvlc_video_get_width(p_md, &ex);
2215 hr = exception_bridge(&ex);
2220 STDMETHODIMP VLCVideo::get_height(long* height)
2222 if( NULL == height )
2225 libvlc_media_player_t *p_md;
2226 HRESULT hr = _p_instance->getMD(&p_md);
2229 libvlc_exception_t ex;
2230 libvlc_exception_init(&ex);
2232 *height = libvlc_video_get_height(p_md, &ex);
2233 hr = exception_bridge(&ex);
2238 STDMETHODIMP VLCVideo::get_aspectRatio(BSTR* aspect)
2240 if( NULL == aspect )
2243 libvlc_media_player_t *p_md;
2244 HRESULT hr = _p_instance->getMD(&p_md);
2247 libvlc_exception_t ex;
2248 libvlc_exception_init(&ex);
2250 char *psz_aspect = libvlc_video_get_aspect_ratio(p_md, &ex);
2252 hr = exception_bridge(&ex);
2253 if( SUCCEEDED(hr) && NULL != psz_aspect )
2255 *aspect = BSTRFromCStr(CP_UTF8, psz_aspect);
2256 if( NULL == *aspect )
2258 } else if( NULL == psz_aspect) hr = E_OUTOFMEMORY; // strdup("") failed
2264 STDMETHODIMP VLCVideo::put_aspectRatio(BSTR aspect)
2266 if( NULL == aspect )
2269 libvlc_media_player_t *p_md;
2270 HRESULT hr = _p_instance->getMD(&p_md);
2273 libvlc_exception_t ex;
2274 libvlc_exception_init(&ex);
2276 char *psz_aspect = CStrFromBSTR(CP_UTF8, aspect);
2277 if( NULL == psz_aspect )
2279 return E_OUTOFMEMORY;
2282 libvlc_video_set_aspect_ratio(p_md, psz_aspect, &ex);
2284 CoTaskMemFree(psz_aspect);
2285 hr = exception_bridge(&ex);
2290 STDMETHODIMP VLCVideo::get_subtitle(long* spu)
2295 libvlc_media_player_t *p_md;
2296 HRESULT hr = _p_instance->getMD(&p_md);
2299 libvlc_exception_t ex;
2300 libvlc_exception_init(&ex);
2302 *spu = libvlc_video_get_spu(p_md, &ex);
2303 hr = exception_bridge(&ex);
2308 STDMETHODIMP VLCVideo::put_subtitle(long spu)
2310 libvlc_media_player_t *p_md;
2311 HRESULT hr = _p_instance->getMD(&p_md);
2314 libvlc_exception_t ex;
2315 libvlc_exception_init(&ex);
2317 libvlc_video_set_spu(p_md, spu, &ex);
2318 hr = exception_bridge(&ex);
2323 STDMETHODIMP VLCVideo::get_crop(BSTR* geometry)
2325 if( NULL == geometry )
2328 libvlc_media_player_t *p_md;
2329 HRESULT hr = _p_instance->getMD(&p_md);
2332 libvlc_exception_t ex;
2333 libvlc_exception_init(&ex);
2335 char *psz_geometry = libvlc_video_get_crop_geometry(p_md, &ex);
2337 hr = exception_bridge(&ex);
2338 if( SUCCEEDED(&ex) && NULL != psz_geometry )
2340 *geometry = BSTRFromCStr(CP_UTF8, psz_geometry);
2341 if( NULL == geometry ) hr = E_OUTOFMEMORY;
2342 } else if( NULL == psz_geometry ) hr = E_OUTOFMEMORY;
2343 free( psz_geometry );
2348 STDMETHODIMP VLCVideo::put_crop(BSTR geometry)
2350 if( NULL == geometry )
2353 if( 0 == SysStringLen(geometry) )
2354 return E_INVALIDARG;
2356 libvlc_media_player_t *p_md;
2357 HRESULT hr = _p_instance->getMD(&p_md);
2360 libvlc_exception_t ex;
2361 libvlc_exception_init(&ex);
2363 char *psz_geometry = CStrFromBSTR(CP_UTF8, geometry);
2364 if( NULL == psz_geometry )
2366 return E_OUTOFMEMORY;
2369 libvlc_video_set_crop_geometry(p_md, psz_geometry, &ex);
2371 CoTaskMemFree(psz_geometry);
2372 hr = exception_bridge(&ex);
2377 STDMETHODIMP VLCVideo::get_teletext(long* page)
2382 libvlc_media_player_t *p_md;
2383 HRESULT hr = _p_instance->getMD(&p_md);
2386 libvlc_exception_t ex;
2387 libvlc_exception_init(&ex);
2389 *page = libvlc_video_get_teletext(p_md, &ex);
2390 hr = exception_bridge(&ex);
2395 STDMETHODIMP VLCVideo::put_teletext(long page)
2397 libvlc_media_player_t *p_md;
2398 HRESULT hr = _p_instance->getMD(&p_md);
2401 libvlc_exception_t ex;
2402 libvlc_exception_init(&ex);
2404 libvlc_video_set_teletext(p_md, page, &ex);
2405 hr = exception_bridge(&ex);
2410 STDMETHODIMP VLCVideo::deinterlaceDisable()
2412 libvlc_media_player_t *p_md;
2413 HRESULT hr = _p_instance->getMD(&p_md);
2416 libvlc_exception_t ex;
2417 libvlc_exception_init(&ex);
2419 libvlc_video_set_deinterlace(p_md, 0, "", &ex);
2420 hr = exception_bridge(&ex);
2425 STDMETHODIMP VLCVideo::deinterlaceEnable(BSTR mode)
2427 libvlc_media_player_t *p_md;
2428 HRESULT hr = _p_instance->getMD(&p_md);
2431 libvlc_exception_t ex;
2432 libvlc_exception_init(&ex);
2433 /* get deinterlace mode from the user */
2434 char *psz_mode = CStrFromBSTR(CP_UTF8, mode);
2435 /* enable deinterlace filter if possible */
2436 libvlc_video_set_deinterlace(p_md, 1, psz_mode, &ex);
2437 hr = exception_bridge(&ex);
2438 CoTaskMemFree(psz_mode);
2443 STDMETHODIMP VLCVideo::takeSnapshot(LPPICTUREDISP* picture)
2445 if( NULL == picture )
2448 libvlc_media_player_t *p_md;
2449 HRESULT hr = _p_instance->getMD(&p_md);
2452 libvlc_exception_t ex;
2453 libvlc_exception_init(&ex);
2455 static int uniqueId = 0;
2456 TCHAR path[MAX_PATH+1];
2458 int pathlen = GetTempPath(MAX_PATH-24, path);
2459 if( (0 == pathlen) || (pathlen > (MAX_PATH-24)) )
2462 /* check temp directory path by openning it */
2464 HANDLE dirHandle = CreateFile(path, GENERIC_READ,
2465 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
2466 NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
2467 if( INVALID_HANDLE_VALUE == dirHandle )
2469 _p_instance->setErrorInfo(IID_IVLCVideo,
2470 "Invalid temporary directory for snapshot images, check values of TMP, TEMP envars.");
2475 BY_HANDLE_FILE_INFORMATION bhfi;
2476 BOOL res = GetFileInformationByHandle(dirHandle, &bhfi);
2477 CloseHandle(dirHandle);
2478 if( !res || !(bhfi.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) )
2480 _p_instance->setErrorInfo(IID_IVLCVideo,
2481 "Invalid temporary directory for snapshot images, check values of TMP, TEMP envars.");
2487 TCHAR filepath[MAX_PATH+1];
2489 _stprintf(filepath, TEXT("%sAXVLC%lXS%lX.bmp"),
2490 path, GetCurrentProcessId(), ++uniqueId);
2493 /* reuse path storage for UTF8 string */
2494 char *psz_filepath = (char *)path;
2495 WCHAR* wpath = filepath;
2497 char *psz_filepath = path;
2498 /* first convert to unicode using current code page */
2499 WCHAR wpath[MAX_PATH+1];
2500 if( 0 == MultiByteToWideChar(CP_ACP, 0, filepath, -1,
2501 wpath, sizeof(wpath)/sizeof(WCHAR)) )
2504 /* convert to UTF8 */
2505 pathlen = WideCharToMultiByte(CP_UTF8, 0, wpath, -1,
2506 psz_filepath, sizeof(path), NULL, NULL);
2507 // fail if path is 0 or too short (i.e pathlen is the same as
2510 if( (0 == pathlen) || (sizeof(path) == pathlen) )
2513 /* take snapshot into file */
2514 libvlc_video_take_snapshot(p_md, psz_filepath, 0, 0, &ex);
2515 hr = exception_bridge(&ex);
2518 /* open snapshot file */
2519 HANDLE snapPic = LoadImage(NULL, filepath, IMAGE_BITMAP, 0, 0,
2520 LR_CREATEDIBSECTION|LR_LOADFROMFILE);
2525 snapDesc.cbSizeofstruct = sizeof(PICTDESC);
2526 snapDesc.picType = PICTYPE_BITMAP;
2527 snapDesc.bmp.hbitmap = (HBITMAP)snapPic;
2528 snapDesc.bmp.hpal = NULL;
2530 hr = OleCreatePictureIndirect(&snapDesc, IID_IPictureDisp,
2531 TRUE, (LPVOID*)picture);
2535 DeleteObject(snapPic);
2538 DeleteFile(filepath);
2544 STDMETHODIMP VLCVideo::toggleFullscreen()
2546 libvlc_media_player_t *p_md;
2547 HRESULT hr = _p_instance->getMD(&p_md);
2550 libvlc_exception_t ex;
2551 libvlc_exception_init(&ex);
2553 libvlc_toggle_fullscreen(p_md, &ex);
2554 hr = exception_bridge(&ex);
2559 STDMETHODIMP VLCVideo::toggleTeletext()
2561 libvlc_media_player_t *p_md;
2562 HRESULT hr = _p_instance->getMD(&p_md);
2565 libvlc_exception_t ex;
2566 libvlc_exception_init(&ex);
2568 libvlc_toggle_teletext(p_md, &ex);
2569 hr = exception_bridge(&ex);
2574 STDMETHODIMP VLCVideo::get_marquee(IVLCMarquee** obj)
2579 *obj = _p_vlcmarquee;
2580 if( NULL != _p_vlcmarquee )
2582 _p_vlcmarquee->AddRef();
2585 return E_OUTOFMEMORY;
2588 /*******************************************************************************/
2590 VLCControl2::VLCControl2(VLCPlugin *p_instance) :
2591 _p_instance(p_instance),
2595 _p_vlcplaylist(NULL),
2596 _p_vlcsubtitle(NULL),
2599 _p_vlcaudio = new VLCAudio(p_instance);
2600 _p_vlcinput = new VLCInput(p_instance);
2601 _p_vlclog = new VLCLog(p_instance);
2602 _p_vlcplaylist = new VLCPlaylist(p_instance);
2603 _p_vlcsubtitle = new VLCSubtitle(p_instance);
2604 _p_vlcvideo = new VLCVideo(p_instance);
2607 VLCControl2::~VLCControl2()
2610 delete _p_vlcsubtitle;
2611 delete _p_vlcplaylist;
2616 _p_typeinfo->Release();
2619 HRESULT VLCControl2::loadTypeInfo(void)
2621 HRESULT hr = NOERROR;
2622 if( NULL == _p_typeinfo )
2624 ITypeLib *p_typelib;
2626 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
2629 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCControl2, &_p_typeinfo);
2634 p_typelib->Release();
2640 STDMETHODIMP VLCControl2::GetTypeInfoCount(UINT* pctInfo)
2642 if( NULL == pctInfo )
2643 return E_INVALIDARG;
2645 if( SUCCEEDED(loadTypeInfo()) )
2653 STDMETHODIMP VLCControl2::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
2655 if( NULL == ppTInfo )
2656 return E_INVALIDARG;
2658 if( SUCCEEDED(loadTypeInfo()) )
2660 _p_typeinfo->AddRef();
2661 *ppTInfo = _p_typeinfo;
2668 STDMETHODIMP VLCControl2::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
2669 UINT cNames, LCID lcid, DISPID* rgDispID)
2671 if( SUCCEEDED(loadTypeInfo()) )
2673 return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
2678 STDMETHODIMP VLCControl2::Invoke(DISPID dispIdMember, REFIID riid,
2679 LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
2680 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
2682 if( SUCCEEDED(loadTypeInfo()) )
2684 return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
2685 pVarResult, pExcepInfo, puArgErr);
2690 STDMETHODIMP VLCControl2::get_AutoLoop(VARIANT_BOOL *autoloop)
2692 if( NULL == autoloop )
2695 *autoloop = _p_instance->getAutoLoop() ? VARIANT_TRUE: VARIANT_FALSE;
2699 STDMETHODIMP VLCControl2::put_AutoLoop(VARIANT_BOOL autoloop)
2701 _p_instance->setAutoLoop((VARIANT_FALSE != autoloop) ? TRUE: FALSE);
2705 STDMETHODIMP VLCControl2::get_AutoPlay(VARIANT_BOOL *autoplay)
2707 if( NULL == autoplay )
2710 *autoplay = _p_instance->getAutoPlay() ? VARIANT_TRUE: VARIANT_FALSE;
2714 STDMETHODIMP VLCControl2::put_AutoPlay(VARIANT_BOOL autoplay)
2716 _p_instance->setAutoPlay((VARIANT_FALSE != autoplay) ? TRUE: FALSE);
2720 STDMETHODIMP VLCControl2::get_BaseURL(BSTR *url)
2725 *url = SysAllocStringLen(_p_instance->getBaseURL(),
2726 SysStringLen(_p_instance->getBaseURL()));
2730 STDMETHODIMP VLCControl2::put_BaseURL(BSTR mrl)
2732 _p_instance->setBaseURL(mrl);
2737 STDMETHODIMP VLCControl2::get_MRL(BSTR *mrl)
2742 *mrl = SysAllocStringLen(_p_instance->getMRL(),
2743 SysStringLen(_p_instance->getMRL()));
2747 STDMETHODIMP VLCControl2::put_MRL(BSTR mrl)
2749 _p_instance->setMRL(mrl);
2755 STDMETHODIMP VLCControl2::get_Toolbar(VARIANT_BOOL *visible)
2757 if( NULL == visible )
2761 * Note to developers
2763 * Returning the _b_toolbar is closer to the method specification.
2764 * But returning True when toolbar is not implemented so not displayed
2765 * could be bad for ActiveX users which rely on this value to show their
2766 * own toolbar if not provided by the ActiveX.
2768 * This is the reason why FALSE is returned, until toolbar get implemented.
2771 /* DISABLED for now */
2772 // *visible = _p_instance->getShowToolbar() ? VARIANT_TRUE: VARIANT_FALSE;
2774 *visible = VARIANT_FALSE;
2779 STDMETHODIMP VLCControl2::put_Toolbar(VARIANT_BOOL visible)
2781 _p_instance->setShowToolbar((VARIANT_FALSE != visible) ? TRUE: FALSE);
2786 STDMETHODIMP VLCControl2::get_StartTime(long *seconds)
2788 if( NULL == seconds )
2791 *seconds = _p_instance->getStartTime();
2796 STDMETHODIMP VLCControl2::put_StartTime(long seconds)
2798 _p_instance->setStartTime(seconds);
2803 STDMETHODIMP VLCControl2::get_VersionInfo(BSTR *version)
2805 if( NULL == version )
2808 const char *versionStr = libvlc_get_version();
2809 if( NULL != versionStr )
2811 *version = BSTRFromCStr(CP_UTF8, versionStr);
2813 return (NULL == *version) ? E_OUTOFMEMORY : NOERROR;
2819 STDMETHODIMP VLCControl2::get_Visible(VARIANT_BOOL *isVisible)
2821 if( NULL == isVisible )
2824 *isVisible = _p_instance->getVisible() ? VARIANT_TRUE : VARIANT_FALSE;
2829 STDMETHODIMP VLCControl2::put_Visible(VARIANT_BOOL isVisible)
2831 _p_instance->setVisible(isVisible != VARIANT_FALSE);
2836 STDMETHODIMP VLCControl2::get_Volume(long *volume)
2838 if( NULL == volume )
2841 *volume = _p_instance->getVolume();
2845 STDMETHODIMP VLCControl2::put_Volume(long volume)
2847 _p_instance->setVolume(volume);
2851 STDMETHODIMP VLCControl2::get_BackColor(OLE_COLOR *backcolor)
2853 if( NULL == backcolor )
2856 *backcolor = _p_instance->getBackColor();
2860 STDMETHODIMP VLCControl2::put_BackColor(OLE_COLOR backcolor)
2862 _p_instance->setBackColor(backcolor);
2866 STDMETHODIMP VLCControl2::get_audio(IVLCAudio** obj)
2872 if( NULL != _p_vlcaudio )
2874 _p_vlcaudio->AddRef();
2877 return E_OUTOFMEMORY;
2880 STDMETHODIMP VLCControl2::get_input(IVLCInput** obj)
2886 if( NULL != _p_vlcinput )
2888 _p_vlcinput->AddRef();
2891 return E_OUTOFMEMORY;
2894 STDMETHODIMP VLCControl2::get_log(IVLCLog** obj)
2900 if( NULL != _p_vlclog )
2902 _p_vlclog->AddRef();
2905 return E_OUTOFMEMORY;
2908 STDMETHODIMP VLCControl2::get_playlist(IVLCPlaylist** obj)
2913 *obj = _p_vlcplaylist;
2914 if( NULL != _p_vlcplaylist )
2916 _p_vlcplaylist->AddRef();
2919 return E_OUTOFMEMORY;
2922 STDMETHODIMP VLCControl2::get_subtitle(IVLCSubtitle** obj)
2927 *obj = _p_vlcsubtitle;
2928 if( NULL != _p_vlcsubtitle )
2930 _p_vlcsubtitle->AddRef();
2933 return E_OUTOFMEMORY;
2936 STDMETHODIMP VLCControl2::get_video(IVLCVideo** obj)
2942 if( NULL != _p_vlcvideo )
2944 _p_vlcvideo->AddRef();
2947 return E_OUTOFMEMORY;