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( 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);
152 libvlc_exception_t ex;
153 libvlc_exception_init(&ex);
155 *mute = libvlc_audio_get_mute(p_libvlc, &ex) ?
156 VARIANT_TRUE : VARIANT_FALSE;
157 hr = exception_bridge(&ex);
162 STDMETHODIMP VLCAudio::put_mute(VARIANT_BOOL mute)
164 libvlc_instance_t* p_libvlc;
165 HRESULT hr = _p_instance->getVLC(&p_libvlc);
168 libvlc_exception_t ex;
169 libvlc_exception_init(&ex);
171 libvlc_audio_set_mute(p_libvlc, VARIANT_FALSE != mute, &ex);
172 hr = exception_bridge(&ex);
177 STDMETHODIMP VLCAudio::get_volume(long* volume)
182 libvlc_instance_t* p_libvlc;
183 HRESULT hr = _p_instance->getVLC(&p_libvlc);
186 libvlc_exception_t ex;
187 libvlc_exception_init(&ex);
189 *volume = libvlc_audio_get_volume(p_libvlc, &ex);
190 hr = exception_bridge(&ex);
195 STDMETHODIMP VLCAudio::put_volume(long volume)
197 libvlc_instance_t* p_libvlc;
198 HRESULT hr = _p_instance->getVLC(&p_libvlc);
201 libvlc_exception_t ex;
202 libvlc_exception_init(&ex);
204 libvlc_audio_set_volume(p_libvlc, volume, &ex);
205 hr = exception_bridge(&ex);
210 STDMETHODIMP VLCAudio::get_track(long* track)
215 libvlc_media_player_t* p_md;
216 HRESULT hr = _p_instance->getMD(&p_md);
219 libvlc_exception_t ex;
220 libvlc_exception_init(&ex);
222 *track = libvlc_audio_get_track(p_md, &ex);
223 hr = exception_bridge(&ex);
228 STDMETHODIMP VLCAudio::put_track(long track)
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);
237 libvlc_audio_set_track(p_md, track, &ex);
238 hr = exception_bridge(&ex);
243 STDMETHODIMP VLCAudio::get_count(long* trackNumber)
245 if( NULL == trackNumber )
248 libvlc_media_player_t* p_md;
249 HRESULT hr = _p_instance->getMD(&p_md);
252 libvlc_exception_t ex;
253 libvlc_exception_init(&ex);
254 // get the number of audio track available and return it
255 *trackNumber = libvlc_audio_get_track_count(p_md, &ex);
256 hr = exception_bridge(&ex);
262 STDMETHODIMP VLCAudio::description(long trackID, BSTR* name)
267 libvlc_media_player_t* p_md;
268 libvlc_exception_t ex;
269 libvlc_exception_init(&ex);
271 HRESULT hr = _p_instance->getMD(&p_md);
275 const char *psz_name;
276 libvlc_track_description_t *p_trackDesc;
278 // get tracks description
279 p_trackDesc = libvlc_audio_get_track_description(p_md, &ex);
280 hr = exception_bridge(&ex);
284 //get the number of available track
285 i_limit = libvlc_audio_get_track_count(p_md, &ex);
286 hr = exception_bridge(&ex);
290 // check if the number given is a good one
291 if ( ( trackID > ( i_limit -1 ) ) || ( trackID < 0 ) )
294 // get the good trackDesc
295 for( i = 0 ; i < trackID ; i++ )
297 p_trackDesc = p_trackDesc->p_next;
299 // get the track name
300 psz_name = p_trackDesc->psz_name;
303 if( psz_name != NULL )
305 *name = BSTRFromCStr(CP_UTF8, psz_name);
306 return (NULL == *name) ? E_OUTOFMEMORY : NOERROR;
314 STDMETHODIMP VLCAudio::get_channel(long *channel)
316 if( NULL == channel )
319 libvlc_instance_t* p_libvlc;
320 HRESULT hr = _p_instance->getVLC(&p_libvlc);
323 libvlc_exception_t ex;
324 libvlc_exception_init(&ex);
326 *channel = libvlc_audio_get_channel(p_libvlc, &ex);
327 hr = exception_bridge(&ex);
332 STDMETHODIMP VLCAudio::put_channel(long channel)
334 libvlc_instance_t* p_libvlc;
335 HRESULT hr = _p_instance->getVLC(&p_libvlc);
338 libvlc_exception_t ex;
339 libvlc_exception_init(&ex);
341 libvlc_audio_set_channel(p_libvlc, channel, &ex);
342 hr = exception_bridge(&ex);
347 STDMETHODIMP VLCAudio::toggleMute()
349 libvlc_instance_t* p_libvlc;
350 HRESULT hr = _p_instance->getVLC(&p_libvlc);
353 libvlc_exception_t ex;
354 libvlc_exception_init(&ex);
356 libvlc_audio_toggle_mute(p_libvlc, &ex);
357 hr = exception_bridge(&ex);
362 /*******************************************************************************/
364 VLCInput::~VLCInput()
367 _p_typeinfo->Release();
370 HRESULT VLCInput::loadTypeInfo(void)
372 HRESULT hr = NOERROR;
373 if( NULL == _p_typeinfo )
377 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
380 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCInput, &_p_typeinfo);
385 p_typelib->Release();
391 STDMETHODIMP VLCInput::GetTypeInfoCount(UINT* pctInfo)
393 if( NULL == pctInfo )
396 if( SUCCEEDED(loadTypeInfo()) )
404 STDMETHODIMP VLCInput::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
406 if( NULL == ppTInfo )
409 if( SUCCEEDED(loadTypeInfo()) )
411 _p_typeinfo->AddRef();
412 *ppTInfo = _p_typeinfo;
419 STDMETHODIMP VLCInput::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
420 UINT cNames, LCID lcid, DISPID* rgDispID)
422 if( SUCCEEDED(loadTypeInfo()) )
424 return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
429 STDMETHODIMP VLCInput::Invoke(DISPID dispIdMember, REFIID riid,
430 LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
431 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
433 if( SUCCEEDED(loadTypeInfo()) )
435 return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
436 pVarResult, pExcepInfo, puArgErr);
441 STDMETHODIMP VLCInput::get_length(double* length)
447 libvlc_media_player_t *p_md;
448 HRESULT hr = _p_instance->getMD(&p_md);
451 libvlc_exception_t ex;
452 libvlc_exception_init(&ex);
454 *length = (double)libvlc_media_player_get_length(p_md, &ex);
455 hr = exception_bridge(&ex);
460 STDMETHODIMP VLCInput::get_position(double* position)
462 if( NULL == position )
466 libvlc_media_player_t *p_md;
467 HRESULT hr = _p_instance->getMD(&p_md);
470 libvlc_exception_t ex;
471 libvlc_exception_init(&ex);
473 *position = libvlc_media_player_get_position(p_md, &ex);
474 hr = exception_bridge(&ex);
479 STDMETHODIMP VLCInput::put_position(double position)
481 libvlc_media_player_t *p_md;
482 HRESULT hr = _p_instance->getMD(&p_md);
485 libvlc_exception_t ex;
486 libvlc_exception_init(&ex);
488 libvlc_media_player_set_position(p_md, position, &ex);
489 hr = exception_bridge(&ex);
494 STDMETHODIMP VLCInput::get_time(double* time)
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 *time = (double)libvlc_media_player_get_time(p_md, &ex);
507 hr = exception_bridge(&ex);
512 STDMETHODIMP VLCInput::put_time(double time)
514 libvlc_media_player_t *p_md;
515 HRESULT hr = _p_instance->getMD(&p_md);
518 libvlc_exception_t ex;
519 libvlc_exception_init(&ex);
521 libvlc_media_player_set_time(p_md, (int64_t)time, &ex);
522 hr = exception_bridge(&ex);
527 STDMETHODIMP VLCInput::get_state(long* state)
532 libvlc_media_player_t *p_md;
533 HRESULT hr = _p_instance->getMD(&p_md);
536 libvlc_exception_t ex;
537 libvlc_exception_init(&ex);
539 *state = libvlc_media_player_get_state(p_md, &ex);
540 if( libvlc_exception_raised(&ex) )
542 // don't fail, just return the idle state
544 libvlc_exception_clear(&ex);
550 STDMETHODIMP VLCInput::get_rate(double* rate)
555 libvlc_media_player_t *p_md;
556 HRESULT hr = _p_instance->getMD(&p_md);
559 libvlc_exception_t ex;
560 libvlc_exception_init(&ex);
562 *rate = libvlc_media_player_get_rate(p_md, &ex);
563 hr = exception_bridge(&ex);
568 STDMETHODIMP VLCInput::put_rate(double rate)
570 libvlc_media_player_t *p_md;
571 HRESULT hr = _p_instance->getMD(&p_md);
574 libvlc_exception_t ex;
575 libvlc_exception_init(&ex);
577 libvlc_media_player_set_rate(p_md, rate, &ex);
578 hr = exception_bridge(&ex);
583 STDMETHODIMP VLCInput::get_fps(double* fps)
589 libvlc_media_player_t *p_md;
590 HRESULT hr = _p_instance->getMD(&p_md);
593 libvlc_exception_t ex;
594 libvlc_exception_init(&ex);
596 *fps = libvlc_media_player_get_fps(p_md, &ex);
597 hr = exception_bridge(&ex);
602 STDMETHODIMP VLCInput::get_hasVout(VARIANT_BOOL* hasVout)
604 if( NULL == hasVout )
607 libvlc_media_player_t *p_md;
608 HRESULT hr = _p_instance->getMD(&p_md);
611 libvlc_exception_t ex;
612 libvlc_exception_init(&ex);
614 *hasVout = libvlc_media_player_has_vout(p_md, &ex) ?
615 VARIANT_TRUE : VARIANT_FALSE;
616 hr = exception_bridge(&ex);
621 /*******************************************************************************/
625 delete _p_vlcmessages;
627 libvlc_log_close(_p_log);
630 _p_typeinfo->Release();
633 HRESULT VLCLog::loadTypeInfo(void)
635 HRESULT hr = NOERROR;
636 if( NULL == _p_typeinfo )
640 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
643 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCLog, &_p_typeinfo);
648 p_typelib->Release();
654 STDMETHODIMP VLCLog::GetTypeInfoCount(UINT* pctInfo)
656 if( NULL == pctInfo )
659 if( SUCCEEDED(loadTypeInfo()) )
667 STDMETHODIMP VLCLog::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
669 if( NULL == ppTInfo )
672 if( SUCCEEDED(loadTypeInfo()) )
674 _p_typeinfo->AddRef();
675 *ppTInfo = _p_typeinfo;
682 STDMETHODIMP VLCLog::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
683 UINT cNames, LCID lcid, DISPID* rgDispID)
685 if( SUCCEEDED(loadTypeInfo()) )
687 return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
692 STDMETHODIMP VLCLog::Invoke(DISPID dispIdMember, REFIID riid,
693 LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
694 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
696 if( SUCCEEDED(loadTypeInfo()) )
698 return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
699 pVarResult, pExcepInfo, puArgErr);
704 STDMETHODIMP VLCLog::get_messages(IVLCMessages** obj)
709 *obj = _p_vlcmessages;
710 if( NULL != _p_vlcmessages )
712 _p_vlcmessages->AddRef();
715 return E_OUTOFMEMORY;
718 STDMETHODIMP VLCLog::get_verbosity(long* level)
725 libvlc_instance_t* p_libvlc;
726 HRESULT hr = _p_instance->getVLC(&p_libvlc);
728 *level = libvlc_get_log_verbosity(p_libvlc);
733 /* log is not enabled, return -1 */
739 STDMETHODIMP VLCLog::put_verbosity(long verbosity)
741 libvlc_instance_t* p_libvlc;
742 HRESULT hr = _p_instance->getVLC(&p_libvlc);
745 libvlc_exception_t ex;
746 libvlc_exception_init(&ex);
752 _p_log = libvlc_log_open(p_libvlc, &ex);
753 hr = exception_bridge(&ex);
756 libvlc_set_log_verbosity(p_libvlc, (unsigned)verbosity);
760 /* close log when verbosity is set to -1 */
761 libvlc_log_close(_p_log);
764 hr = exception_bridge(&ex);
769 /*******************************************************************************/
771 VLCMarquee::~VLCMarquee()
774 _p_typeinfo->Release();
777 HRESULT VLCMarquee::loadTypeInfo(void)
779 HRESULT hr = NOERROR;
780 if( NULL == _p_typeinfo )
784 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
787 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCMarquee, &_p_typeinfo);
792 p_typelib->Release();
798 STDMETHODIMP VLCMarquee::GetTypeInfoCount(UINT* pctInfo)
800 if( NULL == pctInfo )
803 if( SUCCEEDED(loadTypeInfo()) )
811 STDMETHODIMP VLCMarquee::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
813 if( NULL == ppTInfo )
816 if( SUCCEEDED(loadTypeInfo()) )
818 _p_typeinfo->AddRef();
819 *ppTInfo = _p_typeinfo;
826 STDMETHODIMP VLCMarquee::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
827 UINT cNames, LCID lcid, DISPID* rgDispID)
829 if( SUCCEEDED(loadTypeInfo()) )
831 return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
836 STDMETHODIMP VLCMarquee::Invoke(DISPID dispIdMember, REFIID riid,
837 LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
838 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
840 if( SUCCEEDED(loadTypeInfo()) )
842 return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
843 pVarResult, pExcepInfo, puArgErr);
848 STDMETHODIMP VLCMarquee::enable()
850 libvlc_media_player_t *p_md;
851 HRESULT hr = _p_instance->getMD(&p_md);
854 libvlc_exception_t ex;
855 libvlc_exception_init(&ex);
857 libvlc_video_set_marquee_option_as_int(p_md, libvlc_marquee_Enabled, true, &ex);
858 hr = exception_bridge(&ex);
863 STDMETHODIMP VLCMarquee::disable()
865 libvlc_media_player_t *p_md;
866 HRESULT hr = _p_instance->getMD(&p_md);
869 libvlc_exception_t ex;
870 libvlc_exception_init(&ex);
872 libvlc_video_set_marquee_option_as_int(p_md, libvlc_marquee_Enabled, false, &ex);
873 hr = exception_bridge(&ex);
878 STDMETHODIMP VLCMarquee::color(long val)
880 libvlc_media_player_t *p_md;
881 HRESULT hr = _p_instance->getMD(&p_md);
884 libvlc_exception_t ex;
885 libvlc_exception_init(&ex);
887 libvlc_video_set_marquee_option_as_int(p_md, libvlc_marquee_Color, val, &ex);
888 hr = exception_bridge(&ex);
893 STDMETHODIMP VLCMarquee::opacity(long val)
895 libvlc_media_player_t *p_md;
896 HRESULT hr = _p_instance->getMD(&p_md);
899 libvlc_exception_t ex;
900 libvlc_exception_init(&ex);
902 libvlc_video_set_marquee_option_as_int(p_md, libvlc_marquee_Opacity, val, &ex);
903 hr = exception_bridge(&ex);
908 STDMETHODIMP VLCMarquee::position(long val)
910 libvlc_media_player_t *p_md;
911 HRESULT hr = _p_instance->getMD(&p_md);
914 libvlc_exception_t ex;
915 libvlc_exception_init(&ex);
917 libvlc_video_set_marquee_option_as_int(p_md, libvlc_marquee_Position, val, &ex);
918 hr = exception_bridge(&ex);
923 STDMETHODIMP VLCMarquee::refresh(long val)
925 libvlc_media_player_t *p_md;
926 HRESULT hr = _p_instance->getMD(&p_md);
929 libvlc_exception_t ex;
930 libvlc_exception_init(&ex);
932 libvlc_video_set_marquee_option_as_int(p_md, libvlc_marquee_Refresh, val, &ex);
933 hr = exception_bridge(&ex);
938 STDMETHODIMP VLCMarquee::size(long val)
940 libvlc_media_player_t *p_md;
941 HRESULT hr = _p_instance->getMD(&p_md);
944 libvlc_exception_t ex;
945 libvlc_exception_init(&ex);
947 libvlc_video_set_marquee_option_as_int(p_md, libvlc_marquee_Size, val, &ex);
948 hr = exception_bridge(&ex);
953 STDMETHODIMP VLCMarquee::text(BSTR text)
955 libvlc_media_player_t *p_md;
956 HRESULT hr = _p_instance->getMD(&p_md);
959 libvlc_exception_t ex;
960 libvlc_exception_init(&ex);
962 char *psz_text = CStrFromBSTR(CP_UTF8, text);
963 libvlc_video_set_marquee_option_as_string(p_md, libvlc_marquee_Text, psz_text, &ex);
964 hr = exception_bridge(&ex);
965 CoTaskMemFree(psz_text);
970 STDMETHODIMP VLCMarquee::timeout(long val)
972 libvlc_media_player_t *p_md;
973 HRESULT hr = _p_instance->getMD(&p_md);
976 libvlc_exception_t ex;
977 libvlc_exception_init(&ex);
979 libvlc_video_set_marquee_option_as_int(p_md, libvlc_marquee_Timeout, val, &ex);
980 hr = exception_bridge(&ex);
985 STDMETHODIMP VLCMarquee::x(long val)
987 libvlc_media_player_t *p_md;
988 HRESULT hr = _p_instance->getMD(&p_md);
991 libvlc_exception_t ex;
992 libvlc_exception_init(&ex);
994 libvlc_video_set_marquee_option_as_int(p_md, libvlc_marquee_X, val, &ex);
995 hr = exception_bridge(&ex);
1000 STDMETHODIMP VLCMarquee::y(long val)
1002 libvlc_media_player_t *p_md;
1003 HRESULT hr = _p_instance->getMD(&p_md);
1006 libvlc_exception_t ex;
1007 libvlc_exception_init(&ex);
1009 libvlc_video_set_marquee_option_as_int(p_md, libvlc_marquee_Y, val, &ex);
1010 hr = exception_bridge(&ex);
1015 /*******************************************************************************/
1017 /* STL forward iterator used by VLCEnumIterator class to implement IEnumVARIANT */
1019 class VLCMessageSTLIterator
1024 VLCMessageSTLIterator(IVLCMessageIterator* iter) : iter(iter), msg(NULL)
1026 // get first message
1030 VLCMessageSTLIterator(const VLCMessageSTLIterator& other)
1040 virtual ~VLCMessageSTLIterator()
1049 // we only need prefix ++ operator
1050 VLCMessageSTLIterator& operator++()
1052 VARIANT_BOOL hasNext = VARIANT_FALSE;
1055 iter->get_hasNext(&hasNext);
1062 if( VARIANT_TRUE == hasNext ) {
1069 VARIANT operator*() const
1075 if( SUCCEEDED(msg->QueryInterface(IID_IDispatch,
1076 (LPVOID*)&V_DISPATCH(&v))) )
1078 V_VT(&v) = VT_DISPATCH;
1084 bool operator==(const VLCMessageSTLIterator& other) const
1086 return msg == other.msg;
1089 bool operator!=(const VLCMessageSTLIterator& other) const
1091 return msg != other.msg;
1095 IVLCMessageIterator* iter;
1099 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
1101 VLCMessages::~VLCMessages()
1104 _p_typeinfo->Release();
1107 HRESULT VLCMessages::loadTypeInfo(void)
1109 HRESULT hr = NOERROR;
1110 if( NULL == _p_typeinfo )
1112 ITypeLib *p_typelib;
1114 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
1117 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCMessages, &_p_typeinfo);
1122 p_typelib->Release();
1128 STDMETHODIMP VLCMessages::GetTypeInfoCount(UINT* pctInfo)
1130 if( NULL == pctInfo )
1131 return E_INVALIDARG;
1133 if( SUCCEEDED(loadTypeInfo()) )
1141 STDMETHODIMP VLCMessages::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
1143 if( NULL == ppTInfo )
1144 return E_INVALIDARG;
1146 if( SUCCEEDED(loadTypeInfo()) )
1148 _p_typeinfo->AddRef();
1149 *ppTInfo = _p_typeinfo;
1156 STDMETHODIMP VLCMessages::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
1157 UINT cNames, LCID lcid, DISPID* rgDispID)
1159 if( SUCCEEDED(loadTypeInfo()) )
1161 return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
1166 STDMETHODIMP VLCMessages::Invoke(DISPID dispIdMember, REFIID riid,
1167 LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
1168 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
1170 if( SUCCEEDED(loadTypeInfo()) )
1172 return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
1173 pVarResult, pExcepInfo, puArgErr);
1178 STDMETHODIMP VLCMessages::get__NewEnum(LPUNKNOWN* _NewEnum)
1180 if( NULL == _NewEnum )
1183 IVLCMessageIterator* iter = NULL;
1186 *_NewEnum= new VLCEnumIterator<IID_IEnumVARIANT,
1189 VLCMessageSTLIterator>
1190 (VLCMessageSTLIterator(iter), VLCMessageSTLIterator(NULL));
1192 return *_NewEnum ? S_OK : E_OUTOFMEMORY;
1195 STDMETHODIMP VLCMessages::clear()
1197 libvlc_log_t *p_log = _p_vlclog->_p_log;
1199 libvlc_log_clear(p_log);
1203 STDMETHODIMP VLCMessages::get_count(long* count)
1208 libvlc_log_t *p_log = _p_vlclog->_p_log;
1209 *count = libvlc_log_count(p_log);
1213 STDMETHODIMP VLCMessages::iterator(IVLCMessageIterator** iter)
1218 *iter = new VLCMessageIterator(_p_instance, _p_vlclog);
1220 return *iter ? S_OK : E_OUTOFMEMORY;
1223 /*******************************************************************************/
1225 VLCMessageIterator::VLCMessageIterator(VLCPlugin *p_instance, VLCLog* p_vlclog ) :
1226 _p_instance(p_instance),
1231 if( p_vlclog->_p_log )
1233 _p_iter = libvlc_log_get_iterator(p_vlclog->_p_log, NULL);
1239 VLCMessageIterator::~VLCMessageIterator()
1242 libvlc_log_iterator_free(_p_iter);
1245 _p_typeinfo->Release();
1248 HRESULT VLCMessageIterator::loadTypeInfo(void)
1250 HRESULT hr = NOERROR;
1251 if( NULL == _p_typeinfo )
1253 ITypeLib *p_typelib;
1255 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
1258 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCMessageIterator, &_p_typeinfo);
1263 p_typelib->Release();
1269 STDMETHODIMP VLCMessageIterator::GetTypeInfoCount(UINT* pctInfo)
1271 if( NULL == pctInfo )
1272 return E_INVALIDARG;
1274 if( SUCCEEDED(loadTypeInfo()) )
1282 STDMETHODIMP VLCMessageIterator::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
1284 if( NULL == ppTInfo )
1285 return E_INVALIDARG;
1287 if( SUCCEEDED(loadTypeInfo()) )
1289 _p_typeinfo->AddRef();
1290 *ppTInfo = _p_typeinfo;
1297 STDMETHODIMP VLCMessageIterator::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
1298 UINT cNames, LCID lcid, DISPID* rgDispID)
1300 if( SUCCEEDED(loadTypeInfo()) )
1302 return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
1307 STDMETHODIMP VLCMessageIterator::Invoke(DISPID dispIdMember, REFIID riid,
1308 LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
1309 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
1311 if( SUCCEEDED(loadTypeInfo()) )
1313 return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
1314 pVarResult, pExcepInfo, puArgErr);
1319 STDMETHODIMP VLCMessageIterator::get_hasNext(VARIANT_BOOL* hasNext)
1321 if( NULL == hasNext )
1324 if( _p_iter && _p_vlclog->_p_log )
1326 *hasNext = libvlc_log_iterator_has_next(_p_iter) ?
1327 VARIANT_TRUE : VARIANT_FALSE;
1331 *hasNext = VARIANT_FALSE;
1336 STDMETHODIMP VLCMessageIterator::next(IVLCMessage** message)
1340 if( NULL == message )
1343 if( _p_iter && _p_vlclog->_p_log )
1345 struct libvlc_log_message_t buffer;
1347 buffer.sizeof_msg = sizeof(buffer);
1349 libvlc_log_iterator_next(_p_iter, &buffer);
1350 *message = new VLCMessage(_p_instance, buffer);
1357 /*******************************************************************************/
1359 VLCMessage::~VLCMessage()
1362 _p_typeinfo->Release();
1365 HRESULT VLCMessage::loadTypeInfo(void)
1367 HRESULT hr = NOERROR;
1368 if( NULL == _p_typeinfo )
1370 ITypeLib *p_typelib;
1372 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
1375 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCMessage, &_p_typeinfo);
1380 p_typelib->Release();
1386 STDMETHODIMP VLCMessage::GetTypeInfoCount(UINT* pctInfo)
1388 if( NULL == pctInfo )
1389 return E_INVALIDARG;
1391 if( SUCCEEDED(loadTypeInfo()) )
1399 STDMETHODIMP VLCMessage::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
1401 if( NULL == ppTInfo )
1402 return E_INVALIDARG;
1404 if( SUCCEEDED(loadTypeInfo()) )
1406 _p_typeinfo->AddRef();
1407 *ppTInfo = _p_typeinfo;
1414 STDMETHODIMP VLCMessage::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
1415 UINT cNames, LCID lcid, DISPID* rgDispID)
1417 if( SUCCEEDED(loadTypeInfo()) )
1419 return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
1424 STDMETHODIMP VLCMessage::Invoke(DISPID dispIdMember, REFIID riid,
1425 LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
1426 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
1428 if( SUCCEEDED(loadTypeInfo()) )
1430 return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
1431 pVarResult, pExcepInfo, puArgErr);
1436 inline const char *msgSeverity(int sev)
1451 STDMETHODIMP VLCMessage::get__Value(VARIANT* _Value)
1453 if( NULL == _Value )
1458 snprintf(buffer, sizeof(buffer), "%s %s %s: %s",
1459 _msg.psz_type, _msg.psz_name, msgSeverity(_msg.i_severity), _msg.psz_message);
1461 V_VT(_Value) = VT_BSTR;
1462 V_BSTR(_Value) = BSTRFromCStr(CP_UTF8, buffer);
1467 STDMETHODIMP VLCMessage::get_severity(long* level)
1472 *level = _msg.i_severity;
1477 STDMETHODIMP VLCMessage::get_type(BSTR* type)
1482 *type = BSTRFromCStr(CP_UTF8, _msg.psz_type);
1487 STDMETHODIMP VLCMessage::get_name(BSTR* name)
1492 *name = BSTRFromCStr(CP_UTF8, _msg.psz_name);
1497 STDMETHODIMP VLCMessage::get_header(BSTR* header)
1499 if( NULL == header )
1502 *header = BSTRFromCStr(CP_UTF8, _msg.psz_header);
1507 STDMETHODIMP VLCMessage::get_message(BSTR* message)
1509 if( NULL == message )
1512 *message = BSTRFromCStr(CP_UTF8, _msg.psz_message);
1517 /*******************************************************************************/
1519 VLCPlaylistItems::~VLCPlaylistItems()
1522 _p_typeinfo->Release();
1525 HRESULT VLCPlaylistItems::loadTypeInfo(void)
1527 HRESULT hr = NOERROR;
1528 if( NULL == _p_typeinfo )
1530 ITypeLib *p_typelib;
1532 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
1535 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCPlaylistItems, &_p_typeinfo);
1540 p_typelib->Release();
1546 STDMETHODIMP VLCPlaylistItems::GetTypeInfoCount(UINT* pctInfo)
1548 if( NULL == pctInfo )
1549 return E_INVALIDARG;
1551 if( SUCCEEDED(loadTypeInfo()) )
1559 STDMETHODIMP VLCPlaylistItems::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
1561 if( NULL == ppTInfo )
1562 return E_INVALIDARG;
1564 if( SUCCEEDED(loadTypeInfo()) )
1566 _p_typeinfo->AddRef();
1567 *ppTInfo = _p_typeinfo;
1574 STDMETHODIMP VLCPlaylistItems::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
1575 UINT cNames, LCID lcid, DISPID* rgDispID)
1577 if( SUCCEEDED(loadTypeInfo()) )
1579 return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
1584 STDMETHODIMP VLCPlaylistItems::Invoke(DISPID dispIdMember, REFIID riid,
1585 LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
1586 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
1588 if( SUCCEEDED(loadTypeInfo()) )
1590 return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
1591 pVarResult, pExcepInfo, puArgErr);
1596 STDMETHODIMP VLCPlaylistItems::get_count(long* count)
1601 libvlc_exception_t ex;
1602 libvlc_exception_init(&ex);
1604 *count = _p_instance->playlist_count(&ex);
1605 return exception_bridge(&ex);
1608 STDMETHODIMP VLCPlaylistItems::clear()
1610 libvlc_exception_t ex;
1611 libvlc_exception_init(&ex);
1613 _p_instance->playlist_clear(&ex);
1614 return exception_bridge(&ex);
1617 STDMETHODIMP VLCPlaylistItems::remove(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 /*******************************************************************************/
1634 VLCPlaylist::~VLCPlaylist()
1636 delete _p_vlcplaylistitems;
1638 _p_typeinfo->Release();
1641 HRESULT VLCPlaylist::loadTypeInfo(void)
1643 HRESULT hr = NOERROR;
1644 if( NULL == _p_typeinfo )
1646 ITypeLib *p_typelib;
1648 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
1651 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCPlaylist, &_p_typeinfo);
1656 p_typelib->Release();
1662 STDMETHODIMP VLCPlaylist::GetTypeInfoCount(UINT* pctInfo)
1664 if( NULL == pctInfo )
1665 return E_INVALIDARG;
1667 if( SUCCEEDED(loadTypeInfo()) )
1675 STDMETHODIMP VLCPlaylist::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
1677 if( NULL == ppTInfo )
1678 return E_INVALIDARG;
1680 if( SUCCEEDED(loadTypeInfo()) )
1682 _p_typeinfo->AddRef();
1683 *ppTInfo = _p_typeinfo;
1690 STDMETHODIMP VLCPlaylist::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
1691 UINT cNames, LCID lcid, DISPID* rgDispID)
1693 if( SUCCEEDED(loadTypeInfo()) )
1695 return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
1700 STDMETHODIMP VLCPlaylist::Invoke(DISPID dispIdMember, REFIID riid,
1701 LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
1702 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
1704 if( SUCCEEDED(loadTypeInfo()) )
1706 return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
1707 pVarResult, pExcepInfo, puArgErr);
1712 STDMETHODIMP VLCPlaylist::get_itemCount(long* count)
1718 libvlc_exception_t ex;
1719 libvlc_exception_init(&ex);
1721 *count = _p_instance->playlist_count(&ex);
1722 return exception_bridge(&ex);
1725 STDMETHODIMP VLCPlaylist::get_isPlaying(VARIANT_BOOL* isPlaying)
1727 if( NULL == isPlaying )
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 *isPlaying = libvlc_media_player_is_playing(p_md, &ex) ?
1738 VARIANT_TRUE: VARIANT_FALSE;
1739 libvlc_exception_clear(&ex);
1744 STDMETHODIMP VLCPlaylist::add(BSTR uri, VARIANT name, VARIANT options, long* item)
1749 if( 0 == SysStringLen(uri) )
1750 return E_INVALIDARG;
1752 libvlc_instance_t* p_libvlc;
1753 HRESULT hr = _p_instance->getVLC(&p_libvlc);
1756 libvlc_exception_t ex;
1757 libvlc_exception_init(&ex);
1759 char *psz_uri = NULL;
1760 if( SysStringLen(_p_instance->getBaseURL()) > 0 )
1763 ** if the MRL a relative URL, we should end up with an absolute URL
1765 LPWSTR abs_url = CombineURL(_p_instance->getBaseURL(), uri);
1766 if( NULL != abs_url )
1768 psz_uri = CStrFromWSTR(CP_UTF8, abs_url, wcslen(abs_url));
1769 CoTaskMemFree(abs_url);
1773 psz_uri = CStrFromBSTR(CP_UTF8, uri);
1779 ** baseURL is empty, assume MRL is absolute
1781 psz_uri = CStrFromBSTR(CP_UTF8, uri);
1784 if( NULL == psz_uri )
1786 return E_OUTOFMEMORY;
1790 char **ppsz_options;
1792 hr = VLCControl::CreateTargetOptions(CP_UTF8, &options, &ppsz_options, &i_options);
1795 CoTaskMemFree(psz_uri);
1799 char *psz_name = NULL;
1801 VariantInit(&v_name);
1802 if( SUCCEEDED(VariantChangeType(&v_name, &name, 0, VT_BSTR)) )
1804 if( SysStringLen(V_BSTR(&v_name)) > 0 )
1805 psz_name = CStrFromBSTR(CP_UTF8, V_BSTR(&v_name));
1807 VariantClear(&v_name);
1810 *item = _p_instance->playlist_add_extended_untrusted(psz_uri,
1811 i_options, const_cast<const char **>(ppsz_options), &ex);
1813 VLCControl::FreeTargetOptions(ppsz_options, i_options);
1814 CoTaskMemFree(psz_uri);
1815 if( psz_name ) /* XXX Do we even need to check? */
1816 CoTaskMemFree(psz_name);
1817 hr = exception_bridge(&ex);
1822 STDMETHODIMP VLCPlaylist::play()
1824 libvlc_exception_t ex;
1825 libvlc_exception_init(&ex);
1827 _p_instance->playlist_play(&ex);
1828 return exception_bridge(&ex);
1831 STDMETHODIMP VLCPlaylist::playItem(long item)
1833 libvlc_exception_t ex;
1834 libvlc_exception_init(&ex);
1836 _p_instance->playlist_play_item(item,&ex);
1837 return exception_bridge(&ex);;
1840 STDMETHODIMP VLCPlaylist::togglePause()
1842 libvlc_media_player_t* p_md;
1843 HRESULT hr = _p_instance->getMD(&p_md);
1846 libvlc_exception_t ex;
1847 libvlc_exception_init(&ex);
1849 libvlc_media_player_pause(p_md, &ex);
1850 hr = exception_bridge(&ex);;
1855 STDMETHODIMP VLCPlaylist::stop()
1857 libvlc_media_player_t *p_md;
1858 HRESULT hr = _p_instance->getMD(&p_md);
1861 libvlc_exception_t ex;
1862 libvlc_exception_init(&ex);
1864 libvlc_media_player_stop(p_md, &ex);
1865 hr = exception_bridge(&ex);;
1870 STDMETHODIMP VLCPlaylist::next()
1872 libvlc_exception_t ex;
1873 libvlc_exception_init(&ex);
1875 _p_instance->playlist_next(&ex);
1876 return exception_bridge(&ex);;
1879 STDMETHODIMP VLCPlaylist::prev()
1881 libvlc_exception_t ex;
1882 libvlc_exception_init(&ex);
1884 _p_instance->playlist_prev(&ex);
1885 return exception_bridge(&ex);;
1888 STDMETHODIMP VLCPlaylist::clear()
1890 libvlc_exception_t ex;
1891 libvlc_exception_init(&ex);
1893 _p_instance->playlist_clear(&ex);
1894 return exception_bridge(&ex);;
1897 STDMETHODIMP VLCPlaylist::removeItem(long item)
1899 libvlc_instance_t* p_libvlc;
1900 HRESULT hr = _p_instance->getVLC(&p_libvlc);
1903 libvlc_exception_t ex;
1904 libvlc_exception_init(&ex);
1906 _p_instance->playlist_delete_item(item, &ex);
1907 hr = exception_bridge(&ex);;
1912 STDMETHODIMP VLCPlaylist::get_items(IVLCPlaylistItems** obj)
1917 *obj = _p_vlcplaylistitems;
1918 if( NULL != _p_vlcplaylistitems )
1920 _p_vlcplaylistitems->AddRef();
1923 return E_OUTOFMEMORY;
1926 /*******************************************************************************/
1928 VLCSubtitle::~VLCSubtitle()
1931 _p_typeinfo->Release();
1934 HRESULT VLCSubtitle::loadTypeInfo(void)
1936 HRESULT hr = NOERROR;
1937 if( NULL == _p_typeinfo )
1939 ITypeLib *p_typelib;
1941 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
1944 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCSubtitle, &_p_typeinfo);
1949 p_typelib->Release();
1955 STDMETHODIMP VLCSubtitle::GetTypeInfoCount(UINT* pctInfo)
1957 if( NULL == pctInfo )
1958 return E_INVALIDARG;
1960 if( SUCCEEDED(loadTypeInfo()) )
1968 STDMETHODIMP VLCSubtitle::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
1970 if( NULL == ppTInfo )
1971 return E_INVALIDARG;
1973 if( SUCCEEDED(loadTypeInfo()) )
1975 _p_typeinfo->AddRef();
1976 *ppTInfo = _p_typeinfo;
1983 STDMETHODIMP VLCSubtitle::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
1984 UINT cNames, LCID lcid, DISPID* rgDispID)
1986 if( SUCCEEDED(loadTypeInfo()) )
1988 return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
1993 STDMETHODIMP VLCSubtitle::Invoke(DISPID dispIdMember, REFIID riid,
1994 LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
1995 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
1997 if( SUCCEEDED(loadTypeInfo()) )
1999 return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
2000 pVarResult, pExcepInfo, puArgErr);
2005 STDMETHODIMP VLCSubtitle::get_track(long* spu)
2010 libvlc_media_player_t *p_md;
2011 HRESULT hr = _p_instance->getMD(&p_md);
2014 libvlc_exception_t ex;
2015 libvlc_exception_init(&ex);
2017 *spu = libvlc_video_get_spu(p_md, &ex);
2018 hr = exception_bridge(&ex);
2023 STDMETHODIMP VLCSubtitle::put_track(long spu)
2025 libvlc_media_player_t *p_md;
2026 HRESULT hr = _p_instance->getMD(&p_md);
2029 libvlc_exception_t ex;
2030 libvlc_exception_init(&ex);
2032 libvlc_video_set_spu(p_md, spu, &ex);
2033 hr = exception_bridge(&ex);
2038 STDMETHODIMP VLCSubtitle::get_count(long* spuNumber)
2040 if( NULL == spuNumber )
2043 libvlc_media_player_t *p_md;
2044 HRESULT hr = _p_instance->getMD(&p_md);
2047 libvlc_exception_t ex;
2048 libvlc_exception_init(&ex);
2049 // get the number of video subtitle available and return it
2050 *spuNumber = libvlc_video_get_spu_count(p_md, &ex);
2051 hr = exception_bridge(&ex);
2057 STDMETHODIMP VLCSubtitle::description(long nameID, BSTR* name)
2062 libvlc_media_player_t* p_md;
2063 libvlc_exception_t ex;
2064 libvlc_exception_init(&ex);
2066 HRESULT hr = _p_instance->getMD(&p_md);
2070 const char *psz_name;
2071 libvlc_track_description_t *p_spuDesc;
2073 // get subtitles description
2074 p_spuDesc = libvlc_video_get_spu_description(p_md, &ex);
2075 hr = exception_bridge(&ex);
2079 // get the number of available subtitle
2080 i_limit = libvlc_video_get_spu_count(p_md, &ex);
2081 hr = exception_bridge(&ex);
2085 // check if the number given is a good one
2086 if ( ( nameID > ( i_limit -1 ) ) || ( nameID < 0 ) )
2089 // get the good spuDesc
2090 for( i = 0 ; i < nameID ; i++ )
2092 p_spuDesc = p_spuDesc->p_next;
2094 // get the subtitle name
2095 psz_name = p_spuDesc->psz_name;
2098 if( psz_name != NULL )
2100 *name = BSTRFromCStr(CP_UTF8, psz_name);
2101 return (NULL == *name) ? E_OUTOFMEMORY : NOERROR;
2109 /*******************************************************************************/
2111 VLCVideo::~VLCVideo()
2113 delete _p_vlcmarquee;
2115 _p_typeinfo->Release();
2118 HRESULT VLCVideo::loadTypeInfo(void)
2120 HRESULT hr = NOERROR;
2121 if( NULL == _p_typeinfo )
2123 ITypeLib *p_typelib;
2125 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
2128 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCVideo, &_p_typeinfo);
2133 p_typelib->Release();
2139 STDMETHODIMP VLCVideo::GetTypeInfoCount(UINT* pctInfo)
2141 if( NULL == pctInfo )
2142 return E_INVALIDARG;
2144 if( SUCCEEDED(loadTypeInfo()) )
2152 STDMETHODIMP VLCVideo::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
2154 if( NULL == ppTInfo )
2155 return E_INVALIDARG;
2157 if( SUCCEEDED(loadTypeInfo()) )
2159 _p_typeinfo->AddRef();
2160 *ppTInfo = _p_typeinfo;
2167 STDMETHODIMP VLCVideo::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
2168 UINT cNames, LCID lcid, DISPID* rgDispID)
2170 if( SUCCEEDED(loadTypeInfo()) )
2172 return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
2177 STDMETHODIMP VLCVideo::Invoke(DISPID dispIdMember, REFIID riid,
2178 LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
2179 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
2181 if( SUCCEEDED(loadTypeInfo()) )
2183 return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
2184 pVarResult, pExcepInfo, puArgErr);
2189 STDMETHODIMP VLCVideo::get_fullscreen(VARIANT_BOOL* fullscreen)
2191 if( NULL == fullscreen )
2194 libvlc_media_player_t *p_md;
2195 HRESULT hr = _p_instance->getMD(&p_md);
2198 libvlc_exception_t ex;
2199 libvlc_exception_init(&ex);
2201 *fullscreen = libvlc_get_fullscreen(p_md, &ex) ?
2202 VARIANT_TRUE : VARIANT_FALSE;
2203 hr = exception_bridge(&ex);
2208 STDMETHODIMP VLCVideo::put_fullscreen(VARIANT_BOOL fullscreen)
2210 libvlc_media_player_t *p_md;
2211 HRESULT hr = _p_instance->getMD(&p_md);
2214 libvlc_exception_t ex;
2215 libvlc_exception_init(&ex);
2217 libvlc_set_fullscreen(p_md, VARIANT_FALSE != fullscreen, &ex);
2218 hr = exception_bridge(&ex);
2223 STDMETHODIMP VLCVideo::get_width(long* width)
2228 libvlc_media_player_t *p_md;
2229 HRESULT hr = _p_instance->getMD(&p_md);
2232 libvlc_exception_t ex;
2233 libvlc_exception_init(&ex);
2235 *width = libvlc_video_get_width(p_md, &ex);
2236 hr = exception_bridge(&ex);
2241 STDMETHODIMP VLCVideo::get_height(long* height)
2243 if( NULL == height )
2246 libvlc_media_player_t *p_md;
2247 HRESULT hr = _p_instance->getMD(&p_md);
2250 libvlc_exception_t ex;
2251 libvlc_exception_init(&ex);
2253 *height = libvlc_video_get_height(p_md, &ex);
2254 hr = exception_bridge(&ex);
2259 STDMETHODIMP VLCVideo::get_aspectRatio(BSTR* aspect)
2261 if( NULL == aspect )
2264 libvlc_media_player_t *p_md;
2265 HRESULT hr = _p_instance->getMD(&p_md);
2268 libvlc_exception_t ex;
2269 libvlc_exception_init(&ex);
2271 char *psz_aspect = libvlc_video_get_aspect_ratio(p_md, &ex);
2273 hr = exception_bridge(&ex);
2274 if( SUCCEEDED(hr) && NULL != psz_aspect )
2276 *aspect = BSTRFromCStr(CP_UTF8, psz_aspect);
2277 if( NULL == *aspect )
2279 } else if( NULL == psz_aspect) hr = E_OUTOFMEMORY; // strdup("") failed
2285 STDMETHODIMP VLCVideo::put_aspectRatio(BSTR aspect)
2287 if( NULL == aspect )
2290 libvlc_media_player_t *p_md;
2291 HRESULT hr = _p_instance->getMD(&p_md);
2294 libvlc_exception_t ex;
2295 libvlc_exception_init(&ex);
2297 char *psz_aspect = CStrFromBSTR(CP_UTF8, aspect);
2298 if( NULL == psz_aspect )
2300 return E_OUTOFMEMORY;
2303 libvlc_video_set_aspect_ratio(p_md, psz_aspect, &ex);
2305 CoTaskMemFree(psz_aspect);
2306 hr = exception_bridge(&ex);
2311 STDMETHODIMP VLCVideo::get_subtitle(long* spu)
2316 libvlc_media_player_t *p_md;
2317 HRESULT hr = _p_instance->getMD(&p_md);
2320 libvlc_exception_t ex;
2321 libvlc_exception_init(&ex);
2323 *spu = libvlc_video_get_spu(p_md, &ex);
2324 hr = exception_bridge(&ex);
2329 STDMETHODIMP VLCVideo::put_subtitle(long spu)
2331 libvlc_media_player_t *p_md;
2332 HRESULT hr = _p_instance->getMD(&p_md);
2335 libvlc_exception_t ex;
2336 libvlc_exception_init(&ex);
2338 libvlc_video_set_spu(p_md, spu, &ex);
2339 hr = exception_bridge(&ex);
2344 STDMETHODIMP VLCVideo::get_crop(BSTR* geometry)
2346 if( NULL == geometry )
2349 libvlc_media_player_t *p_md;
2350 HRESULT hr = _p_instance->getMD(&p_md);
2353 libvlc_exception_t ex;
2354 libvlc_exception_init(&ex);
2356 char *psz_geometry = libvlc_video_get_crop_geometry(p_md, &ex);
2358 hr = exception_bridge(&ex);
2359 if( SUCCEEDED(&ex) && NULL != psz_geometry )
2361 *geometry = BSTRFromCStr(CP_UTF8, psz_geometry);
2362 if( NULL == geometry ) hr = E_OUTOFMEMORY;
2363 } else if( NULL == psz_geometry ) hr = E_OUTOFMEMORY;
2364 free( psz_geometry );
2369 STDMETHODIMP VLCVideo::put_crop(BSTR geometry)
2371 if( NULL == geometry )
2374 if( 0 == SysStringLen(geometry) )
2375 return E_INVALIDARG;
2377 libvlc_media_player_t *p_md;
2378 HRESULT hr = _p_instance->getMD(&p_md);
2381 libvlc_exception_t ex;
2382 libvlc_exception_init(&ex);
2384 char *psz_geometry = CStrFromBSTR(CP_UTF8, geometry);
2385 if( NULL == psz_geometry )
2387 return E_OUTOFMEMORY;
2390 libvlc_video_set_crop_geometry(p_md, psz_geometry, &ex);
2392 CoTaskMemFree(psz_geometry);
2393 hr = exception_bridge(&ex);
2398 STDMETHODIMP VLCVideo::get_teletext(long* page)
2403 libvlc_media_player_t *p_md;
2404 HRESULT hr = _p_instance->getMD(&p_md);
2407 libvlc_exception_t ex;
2408 libvlc_exception_init(&ex);
2410 *page = libvlc_video_get_teletext(p_md, &ex);
2411 hr = exception_bridge(&ex);
2416 STDMETHODIMP VLCVideo::put_teletext(long page)
2418 libvlc_media_player_t *p_md;
2419 HRESULT hr = _p_instance->getMD(&p_md);
2422 libvlc_exception_t ex;
2423 libvlc_exception_init(&ex);
2425 libvlc_video_set_teletext(p_md, page, &ex);
2426 hr = exception_bridge(&ex);
2431 STDMETHODIMP VLCVideo::deinterlaceDisable()
2433 libvlc_media_player_t *p_md;
2434 HRESULT hr = _p_instance->getMD(&p_md);
2437 libvlc_exception_t ex;
2438 libvlc_exception_init(&ex);
2440 libvlc_video_set_deinterlace(p_md, 0, "", &ex);
2441 hr = exception_bridge(&ex);
2446 STDMETHODIMP VLCVideo::deinterlaceEnable(BSTR mode)
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);
2454 /* get deinterlace mode from the user */
2455 char *psz_mode = CStrFromBSTR(CP_UTF8, mode);
2456 /* enable deinterlace filter if possible */
2457 libvlc_video_set_deinterlace(p_md, 1, psz_mode, &ex);
2458 hr = exception_bridge(&ex);
2459 CoTaskMemFree(psz_mode);
2464 STDMETHODIMP VLCVideo::takeSnapshot(LPPICTUREDISP* picture)
2466 if( NULL == picture )
2469 libvlc_media_player_t *p_md;
2470 HRESULT hr = _p_instance->getMD(&p_md);
2473 libvlc_exception_t ex;
2474 libvlc_exception_init(&ex);
2476 static int uniqueId = 0;
2477 TCHAR path[MAX_PATH+1];
2479 int pathlen = GetTempPath(MAX_PATH-24, path);
2480 if( (0 == pathlen) || (pathlen > (MAX_PATH-24)) )
2483 /* check temp directory path by openning it */
2485 HANDLE dirHandle = CreateFile(path, GENERIC_READ,
2486 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
2487 NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
2488 if( INVALID_HANDLE_VALUE == dirHandle )
2490 _p_instance->setErrorInfo(IID_IVLCVideo,
2491 "Invalid temporary directory for snapshot images, check values of TMP, TEMP envars.");
2496 BY_HANDLE_FILE_INFORMATION bhfi;
2497 BOOL res = GetFileInformationByHandle(dirHandle, &bhfi);
2498 CloseHandle(dirHandle);
2499 if( !res || !(bhfi.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) )
2501 _p_instance->setErrorInfo(IID_IVLCVideo,
2502 "Invalid temporary directory for snapshot images, check values of TMP, TEMP envars.");
2508 TCHAR filepath[MAX_PATH+1];
2510 _stprintf(filepath, TEXT("%sAXVLC%lXS%lX.bmp"),
2511 path, GetCurrentProcessId(), ++uniqueId);
2514 /* reuse path storage for UTF8 string */
2515 char *psz_filepath = (char *)path;
2516 WCHAR* wpath = filepath;
2518 char *psz_filepath = path;
2519 /* first convert to unicode using current code page */
2520 WCHAR wpath[MAX_PATH+1];
2521 if( 0 == MultiByteToWideChar(CP_ACP, 0, filepath, -1,
2522 wpath, sizeof(wpath)/sizeof(WCHAR)) )
2525 /* convert to UTF8 */
2526 pathlen = WideCharToMultiByte(CP_UTF8, 0, wpath, -1,
2527 psz_filepath, sizeof(path), NULL, NULL);
2528 // fail if path is 0 or too short (i.e pathlen is the same as
2531 if( (0 == pathlen) || (sizeof(path) == pathlen) )
2534 /* take snapshot into file */
2535 libvlc_video_take_snapshot(p_md, psz_filepath, 0, 0, &ex);
2536 hr = exception_bridge(&ex);
2539 /* open snapshot file */
2540 HANDLE snapPic = LoadImage(NULL, filepath, IMAGE_BITMAP, 0, 0,
2541 LR_CREATEDIBSECTION|LR_LOADFROMFILE);
2546 snapDesc.cbSizeofstruct = sizeof(PICTDESC);
2547 snapDesc.picType = PICTYPE_BITMAP;
2548 snapDesc.bmp.hbitmap = (HBITMAP)snapPic;
2549 snapDesc.bmp.hpal = NULL;
2551 hr = OleCreatePictureIndirect(&snapDesc, IID_IPictureDisp,
2552 TRUE, (LPVOID*)picture);
2556 DeleteObject(snapPic);
2559 DeleteFile(filepath);
2565 STDMETHODIMP VLCVideo::toggleFullscreen()
2567 libvlc_media_player_t *p_md;
2568 HRESULT hr = _p_instance->getMD(&p_md);
2571 libvlc_exception_t ex;
2572 libvlc_exception_init(&ex);
2574 libvlc_toggle_fullscreen(p_md, &ex);
2575 hr = exception_bridge(&ex);
2580 STDMETHODIMP VLCVideo::toggleTeletext()
2582 libvlc_media_player_t *p_md;
2583 HRESULT hr = _p_instance->getMD(&p_md);
2586 libvlc_exception_t ex;
2587 libvlc_exception_init(&ex);
2589 libvlc_toggle_teletext(p_md, &ex);
2590 hr = exception_bridge(&ex);
2595 STDMETHODIMP VLCVideo::get_marquee(IVLCMarquee** obj)
2600 *obj = _p_vlcmarquee;
2601 if( NULL != _p_vlcmarquee )
2603 _p_vlcmarquee->AddRef();
2606 return E_OUTOFMEMORY;
2609 /*******************************************************************************/
2611 VLCControl2::VLCControl2(VLCPlugin *p_instance) :
2612 _p_instance(p_instance),
2616 _p_vlcplaylist(NULL),
2617 _p_vlcsubtitle(NULL),
2620 _p_vlcaudio = new VLCAudio(p_instance);
2621 _p_vlcinput = new VLCInput(p_instance);
2622 _p_vlclog = new VLCLog(p_instance);
2623 _p_vlcplaylist = new VLCPlaylist(p_instance);
2624 _p_vlcsubtitle = new VLCSubtitle(p_instance);
2625 _p_vlcvideo = new VLCVideo(p_instance);
2628 VLCControl2::~VLCControl2()
2631 delete _p_vlcsubtitle;
2632 delete _p_vlcplaylist;
2637 _p_typeinfo->Release();
2640 HRESULT VLCControl2::loadTypeInfo(void)
2642 HRESULT hr = NOERROR;
2643 if( NULL == _p_typeinfo )
2645 ITypeLib *p_typelib;
2647 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
2650 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCControl2, &_p_typeinfo);
2655 p_typelib->Release();
2661 STDMETHODIMP VLCControl2::GetTypeInfoCount(UINT* pctInfo)
2663 if( NULL == pctInfo )
2664 return E_INVALIDARG;
2666 if( SUCCEEDED(loadTypeInfo()) )
2674 STDMETHODIMP VLCControl2::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
2676 if( NULL == ppTInfo )
2677 return E_INVALIDARG;
2679 if( SUCCEEDED(loadTypeInfo()) )
2681 _p_typeinfo->AddRef();
2682 *ppTInfo = _p_typeinfo;
2689 STDMETHODIMP VLCControl2::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
2690 UINT cNames, LCID lcid, DISPID* rgDispID)
2692 if( SUCCEEDED(loadTypeInfo()) )
2694 return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
2699 STDMETHODIMP VLCControl2::Invoke(DISPID dispIdMember, REFIID riid,
2700 LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
2701 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
2703 if( SUCCEEDED(loadTypeInfo()) )
2705 return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
2706 pVarResult, pExcepInfo, puArgErr);
2711 STDMETHODIMP VLCControl2::get_AutoLoop(VARIANT_BOOL *autoloop)
2713 if( NULL == autoloop )
2716 *autoloop = _p_instance->getAutoLoop() ? VARIANT_TRUE: VARIANT_FALSE;
2720 STDMETHODIMP VLCControl2::put_AutoLoop(VARIANT_BOOL autoloop)
2722 _p_instance->setAutoLoop((VARIANT_FALSE != autoloop) ? TRUE: FALSE);
2726 STDMETHODIMP VLCControl2::get_AutoPlay(VARIANT_BOOL *autoplay)
2728 if( NULL == autoplay )
2731 *autoplay = _p_instance->getAutoPlay() ? VARIANT_TRUE: VARIANT_FALSE;
2735 STDMETHODIMP VLCControl2::put_AutoPlay(VARIANT_BOOL autoplay)
2737 _p_instance->setAutoPlay((VARIANT_FALSE != autoplay) ? TRUE: FALSE);
2741 STDMETHODIMP VLCControl2::get_BaseURL(BSTR *url)
2746 *url = SysAllocStringLen(_p_instance->getBaseURL(),
2747 SysStringLen(_p_instance->getBaseURL()));
2751 STDMETHODIMP VLCControl2::put_BaseURL(BSTR mrl)
2753 _p_instance->setBaseURL(mrl);
2758 STDMETHODIMP VLCControl2::get_MRL(BSTR *mrl)
2763 *mrl = SysAllocStringLen(_p_instance->getMRL(),
2764 SysStringLen(_p_instance->getMRL()));
2768 STDMETHODIMP VLCControl2::put_MRL(BSTR mrl)
2770 _p_instance->setMRL(mrl);
2776 STDMETHODIMP VLCControl2::get_Toolbar(VARIANT_BOOL *visible)
2778 if( NULL == visible )
2782 * Note to developers
2784 * Returning the _b_toolbar is closer to the method specification.
2785 * But returning True when toolbar is not implemented so not displayed
2786 * could be bad for ActiveX users which rely on this value to show their
2787 * own toolbar if not provided by the ActiveX.
2789 * This is the reason why FALSE is returned, until toolbar get implemented.
2792 /* DISABLED for now */
2793 // *visible = _p_instance->getShowToolbar() ? VARIANT_TRUE: VARIANT_FALSE;
2795 *visible = VARIANT_FALSE;
2800 STDMETHODIMP VLCControl2::put_Toolbar(VARIANT_BOOL visible)
2802 _p_instance->setShowToolbar((VARIANT_FALSE != visible) ? TRUE: FALSE);
2807 STDMETHODIMP VLCControl2::get_StartTime(long *seconds)
2809 if( NULL == seconds )
2812 *seconds = _p_instance->getStartTime();
2817 STDMETHODIMP VLCControl2::put_StartTime(long seconds)
2819 _p_instance->setStartTime(seconds);
2824 STDMETHODIMP VLCControl2::get_VersionInfo(BSTR *version)
2826 if( NULL == version )
2829 const char *versionStr = libvlc_get_version();
2830 if( NULL != versionStr )
2832 *version = BSTRFromCStr(CP_UTF8, versionStr);
2834 return (NULL == *version) ? E_OUTOFMEMORY : NOERROR;
2840 STDMETHODIMP VLCControl2::get_Visible(VARIANT_BOOL *isVisible)
2842 if( NULL == isVisible )
2845 *isVisible = _p_instance->getVisible() ? VARIANT_TRUE : VARIANT_FALSE;
2850 STDMETHODIMP VLCControl2::put_Visible(VARIANT_BOOL isVisible)
2852 _p_instance->setVisible(isVisible != VARIANT_FALSE);
2857 STDMETHODIMP VLCControl2::get_Volume(long *volume)
2859 if( NULL == volume )
2862 *volume = _p_instance->getVolume();
2866 STDMETHODIMP VLCControl2::put_Volume(long volume)
2868 _p_instance->setVolume(volume);
2872 STDMETHODIMP VLCControl2::get_BackColor(OLE_COLOR *backcolor)
2874 if( NULL == backcolor )
2877 *backcolor = _p_instance->getBackColor();
2881 STDMETHODIMP VLCControl2::put_BackColor(OLE_COLOR backcolor)
2883 _p_instance->setBackColor(backcolor);
2887 STDMETHODIMP VLCControl2::get_audio(IVLCAudio** obj)
2893 if( NULL != _p_vlcaudio )
2895 _p_vlcaudio->AddRef();
2898 return E_OUTOFMEMORY;
2901 STDMETHODIMP VLCControl2::get_input(IVLCInput** obj)
2907 if( NULL != _p_vlcinput )
2909 _p_vlcinput->AddRef();
2912 return E_OUTOFMEMORY;
2915 STDMETHODIMP VLCControl2::get_log(IVLCLog** obj)
2921 if( NULL != _p_vlclog )
2923 _p_vlclog->AddRef();
2926 return E_OUTOFMEMORY;
2929 STDMETHODIMP VLCControl2::get_playlist(IVLCPlaylist** obj)
2934 *obj = _p_vlcplaylist;
2935 if( NULL != _p_vlcplaylist )
2937 _p_vlcplaylist->AddRef();
2940 return E_OUTOFMEMORY;
2943 STDMETHODIMP VLCControl2::get_subtitle(IVLCSubtitle** obj)
2948 *obj = _p_vlcsubtitle;
2949 if( NULL != _p_vlcsubtitle )
2951 _p_vlcsubtitle->AddRef();
2954 return E_OUTOFMEMORY;
2957 STDMETHODIMP VLCControl2::get_video(IVLCVideo** obj)
2963 if( NULL != _p_vlcvideo )
2965 _p_vlcvideo->AddRef();
2968 return E_OUTOFMEMORY;