1 /*****************************************************************************
2 * vlccontrol2.cpp: ActiveX control for VLC
3 *****************************************************************************
4 * Copyright (C) 2006 the VideoLAN team
5 * Copyright (C) 2010 M2X BV
7 * Authors: Damien Fouilleul <Damien.Fouilleul@laposte.net>
8 * Jean-Paul Saman <jpsaman _at_ m2x _dot_ nl>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
32 #include "vlccontrol2.h"
33 #include "vlccontrol.h"
39 HRESULT VLCInterfaceBase::report_exception(REFIID riid, libvlc_exception_t *ex)
41 _plug->setErrorInfo(riid,libvlc_errmsg());
42 libvlc_exception_clear(ex);
46 HRESULT VLCInterfaceBase::loadTypeInfo(REFIID riid)
48 // if( _ti ) return NOERROR; // unnecessairy
51 HRESULT hr = _plug->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
54 hr = p_typelib->GetTypeInfoOfGuid(riid, &_ti);
55 if( FAILED(hr) ) _ti = NULL;
61 #define BIND_INTERFACE( class ) \
62 template<> REFIID VLCInterface<class, I##class>::_riid = IID_I##class;
64 BIND_INTERFACE( VLCAudio )
65 BIND_INTERFACE( VLCInput )
66 BIND_INTERFACE( VLCMarquee )
67 BIND_INTERFACE( VLCLogo )
68 BIND_INTERFACE( VLCPlaylistItems )
69 BIND_INTERFACE( VLCPlaylist )
70 BIND_INTERFACE( VLCVideo )
71 BIND_INTERFACE( VLCSubtitle )
75 template<class I> static inline
76 HRESULT object_get(I **dst, I *src)
91 VARIANT_BOOL varbool(bool b) { return b ? VARIANT_TRUE : VARIANT_FALSE; }
95 STDMETHODIMP VLCAudio::get_mute(VARIANT_BOOL* mute)
100 libvlc_instance_t* p_libvlc;
101 HRESULT hr = getVLC(&p_libvlc);
103 *mute = varbool( libvlc_audio_get_mute(p_libvlc) );
107 STDMETHODIMP VLCAudio::put_mute(VARIANT_BOOL mute)
109 libvlc_instance_t* p_libvlc;
110 HRESULT hr = getVLC(&p_libvlc);
112 libvlc_audio_set_mute(p_libvlc, VARIANT_FALSE != mute);
116 STDMETHODIMP VLCAudio::get_volume(long* volume)
121 libvlc_instance_t* p_libvlc;
122 HRESULT hr = getVLC(&p_libvlc);
124 *volume = libvlc_audio_get_volume(p_libvlc);
128 STDMETHODIMP VLCAudio::put_volume(long volume)
130 libvlc_instance_t* p_libvlc;
131 HRESULT hr = getVLC(&p_libvlc);
134 libvlc_exception_t ex;
135 libvlc_exception_init(&ex);
137 libvlc_audio_set_volume(p_libvlc, volume, &ex);
138 hr = exception_bridge(&ex);
143 STDMETHODIMP VLCAudio::get_track(long* track)
148 libvlc_media_player_t* p_md;
149 HRESULT hr = getMD(&p_md);
152 libvlc_exception_t ex;
153 libvlc_exception_init(&ex);
155 *track = libvlc_audio_get_track(p_md, &ex);
156 hr = exception_bridge(&ex);
161 STDMETHODIMP VLCAudio::put_track(long track)
163 libvlc_media_player_t *p_md;
164 HRESULT hr = getMD(&p_md);
167 libvlc_exception_t ex;
168 libvlc_exception_init(&ex);
170 libvlc_audio_set_track(p_md, track, &ex);
171 hr = exception_bridge(&ex);
176 STDMETHODIMP VLCAudio::get_count(long* trackNumber)
178 if( NULL == trackNumber )
181 libvlc_media_player_t* p_md;
182 HRESULT hr = getMD(&p_md);
185 libvlc_exception_t ex;
186 libvlc_exception_init(&ex);
187 // get the number of audio track available and return it
188 *trackNumber = libvlc_audio_get_track_count(p_md, &ex);
189 hr = exception_bridge(&ex);
195 STDMETHODIMP VLCAudio::description(long trackID, BSTR* name)
200 libvlc_media_player_t* p_md;
201 libvlc_exception_t ex;
202 libvlc_exception_init(&ex);
204 HRESULT hr = getMD(&p_md);
208 const char *psz_name;
209 libvlc_track_description_t *p_trackDesc;
211 // get tracks description
212 p_trackDesc = libvlc_audio_get_track_description(p_md, &ex);
213 hr = exception_bridge(&ex);
217 //get the number of available track
218 i_limit = libvlc_audio_get_track_count(p_md, &ex);
219 hr = exception_bridge(&ex);
223 // check if the number given is a good one
224 if ( ( trackID > ( i_limit -1 ) ) || ( trackID < 0 ) )
227 // get the good trackDesc
228 for( i = 0 ; i < trackID ; i++ )
230 p_trackDesc = p_trackDesc->p_next;
232 // get the track name
233 psz_name = p_trackDesc->psz_name;
236 if( psz_name != NULL )
238 *name = BSTRFromCStr(CP_UTF8, psz_name);
239 return (NULL == *name) ? E_OUTOFMEMORY : NOERROR;
247 STDMETHODIMP VLCAudio::get_channel(long *channel)
249 if( NULL == channel )
252 libvlc_instance_t* p_libvlc;
253 HRESULT hr = getVLC(&p_libvlc);
256 libvlc_exception_t ex;
257 libvlc_exception_init(&ex);
259 *channel = libvlc_audio_get_channel(p_libvlc, &ex);
260 hr = exception_bridge(&ex);
265 STDMETHODIMP VLCAudio::put_channel(long channel)
267 libvlc_instance_t* p_libvlc;
268 HRESULT hr = getVLC(&p_libvlc);
271 libvlc_exception_t ex;
272 libvlc_exception_init(&ex);
274 libvlc_audio_set_channel(p_libvlc, channel, &ex);
275 hr = exception_bridge(&ex);
280 STDMETHODIMP VLCAudio::toggleMute()
282 libvlc_instance_t* p_libvlc;
283 HRESULT hr = getVLC(&p_libvlc);
285 libvlc_audio_toggle_mute(p_libvlc);
289 /****************************************************************************/
291 STDMETHODIMP VLCInput::get_length(double* length)
297 libvlc_media_player_t *p_md;
298 HRESULT hr = getMD(&p_md);
301 libvlc_exception_t ex;
302 libvlc_exception_init(&ex);
304 *length = (double)libvlc_media_player_get_length(p_md, &ex);
305 hr = exception_bridge(&ex);
310 STDMETHODIMP VLCInput::get_position(double* position)
312 if( NULL == position )
316 libvlc_media_player_t *p_md;
317 HRESULT hr = getMD(&p_md);
320 libvlc_exception_t ex;
321 libvlc_exception_init(&ex);
323 *position = libvlc_media_player_get_position(p_md, &ex);
324 hr = exception_bridge(&ex);
329 STDMETHODIMP VLCInput::put_position(double position)
331 libvlc_media_player_t *p_md;
332 HRESULT hr = getMD(&p_md);
335 libvlc_exception_t ex;
336 libvlc_exception_init(&ex);
338 libvlc_media_player_set_position(p_md, position, &ex);
339 hr = exception_bridge(&ex);
344 STDMETHODIMP VLCInput::get_time(double* time)
349 libvlc_media_player_t *p_md;
350 HRESULT hr = getMD(&p_md);
353 libvlc_exception_t ex;
354 libvlc_exception_init(&ex);
356 *time = (double)libvlc_media_player_get_time(p_md, &ex);
357 hr = exception_bridge(&ex);
362 STDMETHODIMP VLCInput::put_time(double time)
364 libvlc_media_player_t *p_md;
365 HRESULT hr = getMD(&p_md);
368 libvlc_exception_t ex;
369 libvlc_exception_init(&ex);
371 libvlc_media_player_set_time(p_md, (int64_t)time, &ex);
372 hr = exception_bridge(&ex);
377 STDMETHODIMP VLCInput::get_state(long* state)
382 libvlc_media_player_t *p_md;
383 HRESULT hr = getMD(&p_md);
386 libvlc_exception_t ex;
387 libvlc_exception_init(&ex);
389 *state = libvlc_media_player_get_state(p_md);
390 if( libvlc_exception_raised(&ex) )
392 // don't fail, just return the idle state
394 libvlc_exception_clear(&ex);
400 STDMETHODIMP VLCInput::get_rate(double* rate)
405 libvlc_media_player_t *p_md;
406 HRESULT hr = getMD(&p_md);
409 libvlc_exception_t ex;
410 libvlc_exception_init(&ex);
412 *rate = libvlc_media_player_get_rate(p_md, &ex);
413 hr = exception_bridge(&ex);
418 STDMETHODIMP VLCInput::put_rate(double rate)
420 libvlc_media_player_t *p_md;
421 HRESULT hr = getMD(&p_md);
424 libvlc_exception_t ex;
425 libvlc_exception_init(&ex);
427 libvlc_media_player_set_rate(p_md, rate, &ex);
428 hr = exception_bridge(&ex);
433 STDMETHODIMP VLCInput::get_fps(double* fps)
439 libvlc_media_player_t *p_md;
440 HRESULT hr = getMD(&p_md);
443 libvlc_exception_t ex;
444 libvlc_exception_init(&ex);
446 *fps = libvlc_media_player_get_fps(p_md, &ex);
447 hr = exception_bridge(&ex);
452 STDMETHODIMP VLCInput::get_hasVout(VARIANT_BOOL* hasVout)
454 if( NULL == hasVout )
457 libvlc_media_player_t *p_md;
458 HRESULT hr = getMD(&p_md);
461 libvlc_exception_t ex;
462 libvlc_exception_init(&ex);
464 *hasVout = varbool( libvlc_media_player_has_vout(p_md, &ex) );
465 hr = exception_bridge(&ex);
470 /****************************************************************************/
472 HRESULT VLCMarquee::do_put_int(unsigned idx, LONG val)
474 libvlc_media_player_t *p_md;
475 HRESULT hr = getMD(&p_md);
478 libvlc_exception_t ex;
479 libvlc_exception_init(&ex);
480 libvlc_video_set_marquee_int(p_md, idx, val, &ex);
481 hr = exception_bridge(&ex);
486 HRESULT VLCMarquee::do_get_int(unsigned idx, LONG *val)
491 libvlc_media_player_t *p_md;
492 HRESULT hr = getMD(&p_md);
495 libvlc_exception_t ex;
496 libvlc_exception_init(&ex);
497 *val = libvlc_video_get_marquee_int(p_md, idx, &ex);
498 hr = exception_bridge(&ex);
503 STDMETHODIMP VLCMarquee::get_position(BSTR* val)
509 HRESULT hr = do_get_int(libvlc_marquee_Position, &i);
512 *val = BSTRFromCStr(CP_UTF8, position_bynumber(i));
517 STDMETHODIMP VLCMarquee::put_position(BSTR val)
519 char *n = CStrFromBSTR(CP_UTF8, val);
520 if( !n ) return E_OUTOFMEMORY;
524 if( position_byname( n, i ) )
525 hr = do_put_int(libvlc_marquee_Position,i);
533 STDMETHODIMP VLCMarquee::get_text(BSTR *val)
539 libvlc_media_player_t *p_md;
540 HRESULT hr = getMD(&p_md);
543 libvlc_exception_t ex;
544 libvlc_exception_init(&ex);
546 psz = libvlc_video_get_marquee_string(p_md, libvlc_marquee_Text, &ex);
548 hr = exception_bridge(&ex);
550 *val = BSTRFromCStr(CP_UTF8, psz);
555 STDMETHODIMP VLCMarquee::put_text(BSTR val)
557 libvlc_media_player_t *p_md;
558 HRESULT hr = getMD(&p_md);
561 libvlc_exception_t ex;
562 libvlc_exception_init(&ex);
564 char *psz_text = CStrFromBSTR(CP_UTF8, val);
565 libvlc_video_set_marquee_string(p_md, libvlc_marquee_Text,
567 hr = exception_bridge(&ex);
568 CoTaskMemFree(psz_text);
573 /****************************************************************************/
575 STDMETHODIMP VLCPlaylistItems::get_count(long* count)
580 libvlc_exception_t ex;
581 libvlc_exception_init(&ex);
583 *count = Instance()->playlist_count(&ex);
584 return exception_bridge(&ex);
587 STDMETHODIMP VLCPlaylistItems::clear()
589 libvlc_exception_t ex;
590 libvlc_exception_init(&ex);
592 Instance()->playlist_clear(&ex);
593 return exception_bridge(&ex);
596 STDMETHODIMP VLCPlaylistItems::remove(long item)
598 libvlc_instance_t* p_libvlc;
599 HRESULT hr = getVLC(&p_libvlc);
602 libvlc_exception_t ex;
603 libvlc_exception_init(&ex);
605 Instance()->playlist_delete_item(item, &ex);
606 hr = exception_bridge(&ex);
611 /****************************************************************************/
613 STDMETHODIMP VLCPlaylist::get_itemCount(long* count)
619 libvlc_exception_t ex;
620 libvlc_exception_init(&ex);
622 *count = Instance()->playlist_count(&ex);
623 return exception_bridge(&ex);
626 STDMETHODIMP VLCPlaylist::get_isPlaying(VARIANT_BOOL* isPlaying)
628 if( NULL == isPlaying )
631 libvlc_media_player_t *p_md;
632 HRESULT hr = getMD(&p_md);
635 libvlc_exception_t ex;
636 libvlc_exception_init(&ex);
638 *isPlaying = varbool( libvlc_media_player_is_playing(p_md) );
639 libvlc_exception_clear(&ex);
644 STDMETHODIMP VLCPlaylist::add(BSTR uri, VARIANT name, VARIANT options, long* item)
649 if( 0 == SysStringLen(uri) )
652 libvlc_instance_t* p_libvlc;
653 HRESULT hr = getVLC(&p_libvlc);
656 libvlc_exception_t ex;
657 libvlc_exception_init(&ex);
659 char *psz_uri = NULL;
660 if( SysStringLen(Instance()->getBaseURL()) > 0 )
663 ** if the MRL a relative URL, we should end up with an absolute URL
665 LPWSTR abs_url = CombineURL(Instance()->getBaseURL(), uri);
666 if( NULL != abs_url )
668 psz_uri = CStrFromWSTR(CP_UTF8, abs_url, wcslen(abs_url));
669 CoTaskMemFree(abs_url);
673 psz_uri = CStrFromBSTR(CP_UTF8, uri);
679 ** baseURL is empty, assume MRL is absolute
681 psz_uri = CStrFromBSTR(CP_UTF8, uri);
684 if( NULL == psz_uri )
686 return E_OUTOFMEMORY;
692 hr = VLCControl::CreateTargetOptions(CP_UTF8, &options, &ppsz_options, &i_options);
695 CoTaskMemFree(psz_uri);
699 char *psz_name = NULL;
701 VariantInit(&v_name);
702 if( SUCCEEDED(VariantChangeType(&v_name, &name, 0, VT_BSTR)) )
704 if( SysStringLen(V_BSTR(&v_name)) > 0 )
705 psz_name = CStrFromBSTR(CP_UTF8, V_BSTR(&v_name));
707 VariantClear(&v_name);
710 *item = Instance()->playlist_add_extended_untrusted(psz_uri,
711 i_options, const_cast<const char **>(ppsz_options), &ex);
713 VLCControl::FreeTargetOptions(ppsz_options, i_options);
714 CoTaskMemFree(psz_uri);
715 if( psz_name ) /* XXX Do we even need to check? */
716 CoTaskMemFree(psz_name);
717 hr = exception_bridge(&ex);
722 STDMETHODIMP VLCPlaylist::play()
724 libvlc_exception_t ex;
725 libvlc_exception_init(&ex);
727 Instance()->playlist_play(&ex);
728 return exception_bridge(&ex);
731 STDMETHODIMP VLCPlaylist::playItem(long item)
733 libvlc_exception_t ex;
734 libvlc_exception_init(&ex);
736 Instance()->playlist_play_item(item,&ex);
737 return exception_bridge(&ex);;
740 STDMETHODIMP VLCPlaylist::togglePause()
742 libvlc_media_player_t* p_md;
743 HRESULT hr = getMD(&p_md);
746 libvlc_exception_t ex;
747 libvlc_exception_init(&ex);
749 libvlc_media_player_pause(p_md, &ex);
750 hr = exception_bridge(&ex);;
755 STDMETHODIMP VLCPlaylist::stop()
757 libvlc_media_player_t *p_md;
758 HRESULT hr = getMD(&p_md);
761 libvlc_exception_t ex;
762 libvlc_exception_init(&ex);
764 libvlc_media_player_stop(p_md);
765 hr = exception_bridge(&ex);;
770 STDMETHODIMP VLCPlaylist::next()
772 libvlc_exception_t ex;
773 libvlc_exception_init(&ex);
775 Instance()->playlist_next(&ex);
776 return exception_bridge(&ex);;
779 STDMETHODIMP VLCPlaylist::prev()
781 libvlc_exception_t ex;
782 libvlc_exception_init(&ex);
784 Instance()->playlist_prev(&ex);
785 return exception_bridge(&ex);;
788 STDMETHODIMP VLCPlaylist::clear()
790 libvlc_exception_t ex;
791 libvlc_exception_init(&ex);
793 Instance()->playlist_clear(&ex);
794 return exception_bridge(&ex);;
797 STDMETHODIMP VLCPlaylist::removeItem(long item)
799 libvlc_instance_t* p_libvlc;
800 HRESULT hr = getVLC(&p_libvlc);
803 libvlc_exception_t ex;
804 libvlc_exception_init(&ex);
806 Instance()->playlist_delete_item(item, &ex);
807 hr = exception_bridge(&ex);;
812 STDMETHODIMP VLCPlaylist::get_items(IVLCPlaylistItems** obj)
817 *obj = _p_vlcplaylistitems;
818 if( NULL != _p_vlcplaylistitems )
820 _p_vlcplaylistitems->AddRef();
823 return E_OUTOFMEMORY;
826 /****************************************************************************/
828 STDMETHODIMP VLCSubtitle::get_track(long* spu)
833 libvlc_media_player_t *p_md;
834 HRESULT hr = getMD(&p_md);
837 libvlc_exception_t ex;
838 libvlc_exception_init(&ex);
840 *spu = libvlc_video_get_spu(p_md, &ex);
841 hr = exception_bridge(&ex);
846 STDMETHODIMP VLCSubtitle::put_track(long spu)
848 libvlc_media_player_t *p_md;
849 HRESULT hr = getMD(&p_md);
852 libvlc_exception_t ex;
853 libvlc_exception_init(&ex);
855 libvlc_video_set_spu(p_md, spu, &ex);
856 hr = exception_bridge(&ex);
861 STDMETHODIMP VLCSubtitle::get_count(long* spuNumber)
863 if( NULL == spuNumber )
866 libvlc_media_player_t *p_md;
867 HRESULT hr = getMD(&p_md);
870 libvlc_exception_t ex;
871 libvlc_exception_init(&ex);
872 // get the number of video subtitle available and return it
873 *spuNumber = libvlc_video_get_spu_count(p_md, &ex);
874 hr = exception_bridge(&ex);
880 STDMETHODIMP VLCSubtitle::description(long nameID, BSTR* name)
885 libvlc_media_player_t* p_md;
886 libvlc_exception_t ex;
887 libvlc_exception_init(&ex);
889 HRESULT hr = getMD(&p_md);
893 const char *psz_name;
894 libvlc_track_description_t *p_spuDesc;
896 // get subtitles description
897 p_spuDesc = libvlc_video_get_spu_description(p_md, &ex);
898 hr = exception_bridge(&ex);
902 // get the number of available subtitle
903 i_limit = libvlc_video_get_spu_count(p_md, &ex);
904 hr = exception_bridge(&ex);
908 // check if the number given is a good one
909 if ( ( nameID > ( i_limit -1 ) ) || ( nameID < 0 ) )
912 // get the good spuDesc
913 for( i = 0 ; i < nameID ; i++ )
915 p_spuDesc = p_spuDesc->p_next;
917 // get the subtitle name
918 psz_name = p_spuDesc->psz_name;
921 if( psz_name != NULL )
923 *name = BSTRFromCStr(CP_UTF8, psz_name);
924 return (NULL == *name) ? E_OUTOFMEMORY : NOERROR;
932 /****************************************************************************/
934 STDMETHODIMP VLCVideo::get_fullscreen(VARIANT_BOOL* fullscreen)
936 if( NULL == fullscreen )
939 libvlc_media_player_t *p_md;
940 HRESULT hr = getMD(&p_md);
943 libvlc_exception_t ex;
944 libvlc_exception_init(&ex);
946 *fullscreen = varbool( libvlc_get_fullscreen(p_md, &ex) );
947 hr = exception_bridge(&ex);
952 STDMETHODIMP VLCVideo::put_fullscreen(VARIANT_BOOL fullscreen)
954 libvlc_media_player_t *p_md;
955 HRESULT hr = getMD(&p_md);
958 libvlc_exception_t ex;
959 libvlc_exception_init(&ex);
961 libvlc_set_fullscreen(p_md, VARIANT_FALSE != fullscreen, &ex);
962 hr = exception_bridge(&ex);
967 STDMETHODIMP VLCVideo::get_width(long* width)
972 libvlc_media_player_t *p_md;
973 HRESULT hr = getMD(&p_md);
976 libvlc_exception_t ex;
977 libvlc_exception_init(&ex);
979 *width = libvlc_video_get_width(p_md, &ex);
980 hr = exception_bridge(&ex);
985 STDMETHODIMP VLCVideo::get_height(long* height)
990 libvlc_media_player_t *p_md;
991 HRESULT hr = getMD(&p_md);
994 libvlc_exception_t ex;
995 libvlc_exception_init(&ex);
997 *height = libvlc_video_get_height(p_md, &ex);
998 hr = exception_bridge(&ex);
1003 STDMETHODIMP VLCVideo::get_aspectRatio(BSTR* aspect)
1005 if( NULL == aspect )
1008 libvlc_media_player_t *p_md;
1009 HRESULT hr = getMD(&p_md);
1012 libvlc_exception_t ex;
1013 libvlc_exception_init(&ex);
1015 char *psz_aspect = libvlc_video_get_aspect_ratio(p_md, &ex);
1017 hr = exception_bridge(&ex);
1018 if( SUCCEEDED(hr) && NULL != psz_aspect )
1020 *aspect = BSTRFromCStr(CP_UTF8, psz_aspect);
1021 if( NULL == *aspect )
1023 } else if( NULL == psz_aspect) hr = E_OUTOFMEMORY; // strdup("") failed
1029 STDMETHODIMP VLCVideo::put_aspectRatio(BSTR aspect)
1031 if( NULL == aspect )
1034 libvlc_media_player_t *p_md;
1035 HRESULT hr = getMD(&p_md);
1038 libvlc_exception_t ex;
1039 libvlc_exception_init(&ex);
1041 char *psz_aspect = CStrFromBSTR(CP_UTF8, aspect);
1042 if( NULL == psz_aspect )
1044 return E_OUTOFMEMORY;
1047 libvlc_video_set_aspect_ratio(p_md, psz_aspect, &ex);
1049 CoTaskMemFree(psz_aspect);
1050 hr = exception_bridge(&ex);
1055 STDMETHODIMP VLCVideo::get_subtitle(long* spu)
1060 libvlc_media_player_t *p_md;
1061 HRESULT hr = getMD(&p_md);
1064 libvlc_exception_t ex;
1065 libvlc_exception_init(&ex);
1067 *spu = libvlc_video_get_spu(p_md, &ex);
1068 hr = exception_bridge(&ex);
1073 STDMETHODIMP VLCVideo::put_subtitle(long spu)
1075 libvlc_media_player_t *p_md;
1076 HRESULT hr = getMD(&p_md);
1079 libvlc_exception_t ex;
1080 libvlc_exception_init(&ex);
1082 libvlc_video_set_spu(p_md, spu, &ex);
1083 hr = exception_bridge(&ex);
1088 STDMETHODIMP VLCVideo::get_crop(BSTR* geometry)
1090 if( NULL == geometry )
1093 libvlc_media_player_t *p_md;
1094 HRESULT hr = getMD(&p_md);
1097 libvlc_exception_t ex;
1098 libvlc_exception_init(&ex);
1100 char *psz_geometry = libvlc_video_get_crop_geometry(p_md, &ex);
1102 hr = exception_bridge(&ex);
1103 if( SUCCEEDED(&ex) && NULL != psz_geometry )
1105 *geometry = BSTRFromCStr(CP_UTF8, psz_geometry);
1106 if( NULL == geometry ) hr = E_OUTOFMEMORY;
1107 } else if( NULL == psz_geometry ) hr = E_OUTOFMEMORY;
1108 free( psz_geometry );
1113 STDMETHODIMP VLCVideo::put_crop(BSTR geometry)
1115 if( NULL == geometry )
1118 if( 0 == SysStringLen(geometry) )
1119 return E_INVALIDARG;
1121 libvlc_media_player_t *p_md;
1122 HRESULT hr = getMD(&p_md);
1125 libvlc_exception_t ex;
1126 libvlc_exception_init(&ex);
1128 char *psz_geometry = CStrFromBSTR(CP_UTF8, geometry);
1129 if( NULL == psz_geometry )
1131 return E_OUTOFMEMORY;
1134 libvlc_video_set_crop_geometry(p_md, psz_geometry, &ex);
1136 CoTaskMemFree(psz_geometry);
1137 hr = exception_bridge(&ex);
1142 STDMETHODIMP VLCVideo::get_teletext(long* page)
1147 libvlc_media_player_t *p_md;
1148 HRESULT hr = getMD(&p_md);
1152 libvlc_exception_t ex;
1153 libvlc_exception_init(&ex);
1155 *page = libvlc_video_get_teletext(p_md);
1156 hr = exception_bridge(&ex);
1162 STDMETHODIMP VLCVideo::put_teletext(long page)
1165 libvlc_media_player_t *p_md;
1166 HRESULT hr = getMD(&p_md);
1170 libvlc_exception_t ex;
1171 libvlc_exception_init(&ex);
1173 libvlc_video_set_teletext(p_md, page);
1174 hr = exception_bridge(&ex);
1180 STDMETHODIMP VLCVideo::deinterlaceDisable()
1182 libvlc_media_player_t *p_md;
1183 HRESULT hr = getMD(&p_md);
1186 libvlc_exception_t ex;
1187 libvlc_exception_init(&ex);
1189 libvlc_video_set_deinterlace(p_md, 0, "", &ex);
1190 hr = exception_bridge(&ex);
1195 STDMETHODIMP VLCVideo::deinterlaceEnable(BSTR mode)
1197 libvlc_media_player_t *p_md;
1198 HRESULT hr = getMD(&p_md);
1201 libvlc_exception_t ex;
1202 libvlc_exception_init(&ex);
1203 /* get deinterlace mode from the user */
1204 char *psz_mode = CStrFromBSTR(CP_UTF8, mode);
1205 /* enable deinterlace filter if possible */
1206 libvlc_video_set_deinterlace(p_md, 1, psz_mode, &ex);
1207 hr = exception_bridge(&ex);
1208 CoTaskMemFree(psz_mode);
1213 STDMETHODIMP VLCVideo::takeSnapshot(LPPICTUREDISP* picture)
1215 if( NULL == picture )
1218 libvlc_media_player_t *p_md;
1219 HRESULT hr = getMD(&p_md);
1222 libvlc_exception_t ex;
1223 libvlc_exception_init(&ex);
1225 static int uniqueId = 0;
1226 TCHAR path[MAX_PATH+1];
1228 int pathlen = GetTempPath(MAX_PATH-24, path);
1229 if( (0 == pathlen) || (pathlen > (MAX_PATH-24)) )
1232 /* check temp directory path by openning it */
1234 HANDLE dirHandle = CreateFile(path, GENERIC_READ,
1235 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
1236 NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
1237 if( INVALID_HANDLE_VALUE == dirHandle )
1239 Instance()->setErrorInfo(IID_IVLCVideo,
1240 "Invalid temporary directory for snapshot images, check values of TMP, TEMP envars.");
1245 BY_HANDLE_FILE_INFORMATION bhfi;
1246 BOOL res = GetFileInformationByHandle(dirHandle, &bhfi);
1247 CloseHandle(dirHandle);
1248 if( !res || !(bhfi.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) )
1250 Instance()->setErrorInfo(IID_IVLCVideo,
1251 "Invalid temporary directory for snapshot images, check values of TMP, TEMP envars.");
1257 TCHAR filepath[MAX_PATH+1];
1259 _stprintf(filepath, TEXT("%sAXVLC%lXS%lX.bmp"),
1260 path, GetCurrentProcessId(), ++uniqueId);
1263 /* reuse path storage for UTF8 string */
1264 char *psz_filepath = (char *)path;
1265 WCHAR* wpath = filepath;
1267 char *psz_filepath = path;
1268 /* first convert to unicode using current code page */
1269 WCHAR wpath[MAX_PATH+1];
1270 if( 0 == MultiByteToWideChar(CP_ACP, 0, filepath, -1,
1271 wpath, sizeof(wpath)/sizeof(WCHAR)) )
1274 /* convert to UTF8 */
1275 pathlen = WideCharToMultiByte(CP_UTF8, 0, wpath, -1,
1276 psz_filepath, sizeof(path), NULL, NULL);
1277 // fail if path is 0 or too short (i.e pathlen is the same as
1280 if( (0 == pathlen) || (sizeof(path) == pathlen) )
1283 /* take snapshot into file */
1284 libvlc_video_take_snapshot(p_md, psz_filepath, 0, 0, &ex);
1285 hr = exception_bridge(&ex);
1288 /* open snapshot file */
1289 HANDLE snapPic = LoadImage(NULL, filepath, IMAGE_BITMAP, 0, 0,
1290 LR_CREATEDIBSECTION|LR_LOADFROMFILE);
1295 snapDesc.cbSizeofstruct = sizeof(PICTDESC);
1296 snapDesc.picType = PICTYPE_BITMAP;
1297 snapDesc.bmp.hbitmap = (HBITMAP)snapPic;
1298 snapDesc.bmp.hpal = NULL;
1300 hr = OleCreatePictureIndirect(&snapDesc, IID_IPictureDisp,
1301 TRUE, (LPVOID*)picture);
1305 DeleteObject(snapPic);
1308 DeleteFile(filepath);
1314 STDMETHODIMP VLCVideo::toggleFullscreen()
1316 libvlc_media_player_t *p_md;
1317 HRESULT hr = getMD(&p_md);
1320 libvlc_exception_t ex;
1321 libvlc_exception_init(&ex);
1323 libvlc_toggle_fullscreen(p_md, &ex);
1324 hr = exception_bridge(&ex);
1329 STDMETHODIMP VLCVideo::toggleTeletext()
1331 libvlc_media_player_t *p_md;
1332 HRESULT hr = getMD(&p_md);
1335 libvlc_exception_t ex;
1336 libvlc_exception_init(&ex);
1338 libvlc_toggle_teletext(p_md, &ex);
1339 hr = exception_bridge(&ex);
1344 STDMETHODIMP VLCVideo::get_marquee(IVLCMarquee** obj)
1346 return object_get(obj,_p_vlcmarquee);
1349 STDMETHODIMP VLCVideo::get_logo(IVLCLogo** obj)
1351 return object_get(obj,_p_vlclogo);
1355 /****************************************************************************/
1357 HRESULT VLCLogo::do_put_int(unsigned idx, LONG val)
1359 libvlc_media_player_t *p_md;
1360 HRESULT hr = getMD(&p_md);
1363 libvlc_exception_t ex;
1364 libvlc_exception_init(&ex);
1365 libvlc_video_set_logo_int(p_md, idx, val, &ex);
1366 hr = exception_bridge(&ex);
1371 HRESULT VLCLogo::do_get_int(unsigned idx, LONG *val)
1376 libvlc_media_player_t *p_md;
1377 HRESULT hr = getMD(&p_md);
1380 libvlc_exception_t ex;
1381 libvlc_exception_init(&ex);
1382 *val = libvlc_video_get_logo_int(p_md, idx, &ex);
1383 hr = exception_bridge(&ex);
1388 STDMETHODIMP VLCLogo::file(BSTR fname)
1390 libvlc_media_player_t *p_md;
1391 HRESULT hr = getMD(&p_md);
1393 char *n = CStrFromBSTR(CP_UTF8, fname);
1394 if( !n ) hr = E_OUTOFMEMORY;
1398 libvlc_exception_t ex;
1399 libvlc_exception_init(&ex);
1400 libvlc_video_set_logo_string(p_md, libvlc_logo_file, n, &ex);
1401 hr = exception_bridge(&ex);
1408 STDMETHODIMP VLCLogo::get_position(BSTR* val)
1414 HRESULT hr = do_get_int(libvlc_logo_position, &i);
1417 *val = BSTRFromCStr(CP_UTF8, position_bynumber(i));
1422 STDMETHODIMP VLCLogo::put_position(BSTR val)
1424 char *n = CStrFromBSTR(CP_UTF8, val);
1425 if( !n ) return E_OUTOFMEMORY;
1429 if( position_byname( n, i ) )
1430 hr = do_put_int(libvlc_logo_position,i);
1438 /****************************************************************************/
1440 VLCControl2::VLCControl2(VLCPlugin *p_instance) :
1441 _p_instance(p_instance),
1443 _p_vlcaudio(new VLCAudio(p_instance)),
1444 _p_vlcinput(new VLCInput(p_instance)),
1445 _p_vlcplaylist(new VLCPlaylist(p_instance)),
1446 _p_vlcsubtitle(new VLCSubtitle(p_instance)),
1447 _p_vlcvideo(new VLCVideo(p_instance))
1451 VLCControl2::~VLCControl2()
1454 delete _p_vlcsubtitle;
1455 delete _p_vlcplaylist;
1459 _p_typeinfo->Release();
1462 HRESULT VLCControl2::loadTypeInfo(void)
1464 HRESULT hr = NOERROR;
1465 if( NULL == _p_typeinfo )
1467 ITypeLib *p_typelib;
1469 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
1472 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCControl2, &_p_typeinfo);
1477 p_typelib->Release();
1483 STDMETHODIMP VLCControl2::GetTypeInfoCount(UINT* pctInfo)
1485 if( NULL == pctInfo )
1486 return E_INVALIDARG;
1488 if( SUCCEEDED(loadTypeInfo()) )
1496 STDMETHODIMP VLCControl2::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
1498 if( NULL == ppTInfo )
1499 return E_INVALIDARG;
1501 if( SUCCEEDED(loadTypeInfo()) )
1503 _p_typeinfo->AddRef();
1504 *ppTInfo = _p_typeinfo;
1511 STDMETHODIMP VLCControl2::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
1512 UINT cNames, LCID lcid, DISPID* rgDispID)
1514 if( SUCCEEDED(loadTypeInfo()) )
1516 return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
1521 STDMETHODIMP VLCControl2::Invoke(DISPID dispIdMember, REFIID riid,
1522 LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
1523 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
1525 if( SUCCEEDED(loadTypeInfo()) )
1527 return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
1528 pVarResult, pExcepInfo, puArgErr);
1533 STDMETHODIMP VLCControl2::get_AutoLoop(VARIANT_BOOL *autoloop)
1535 if( NULL == autoloop )
1538 *autoloop = varbool( _p_instance->getAutoLoop() );
1542 STDMETHODIMP VLCControl2::put_AutoLoop(VARIANT_BOOL autoloop)
1544 _p_instance->setAutoLoop((VARIANT_FALSE != autoloop) ? TRUE: FALSE);
1548 STDMETHODIMP VLCControl2::get_AutoPlay(VARIANT_BOOL *autoplay)
1550 if( NULL == autoplay )
1553 *autoplay = varbool( _p_instance->getAutoPlay() );
1557 STDMETHODIMP VLCControl2::put_AutoPlay(VARIANT_BOOL autoplay)
1559 _p_instance->setAutoPlay((VARIANT_FALSE != autoplay) ? TRUE: FALSE);
1563 STDMETHODIMP VLCControl2::get_BaseURL(BSTR *url)
1568 *url = SysAllocStringLen(_p_instance->getBaseURL(),
1569 SysStringLen(_p_instance->getBaseURL()));
1573 STDMETHODIMP VLCControl2::put_BaseURL(BSTR mrl)
1575 _p_instance->setBaseURL(mrl);
1580 STDMETHODIMP VLCControl2::get_MRL(BSTR *mrl)
1585 *mrl = SysAllocStringLen(_p_instance->getMRL(),
1586 SysStringLen(_p_instance->getMRL()));
1590 STDMETHODIMP VLCControl2::put_MRL(BSTR mrl)
1592 _p_instance->setMRL(mrl);
1598 STDMETHODIMP VLCControl2::get_Toolbar(VARIANT_BOOL *visible)
1600 if( NULL == visible )
1604 * Note to developers
1606 * Returning the _b_toolbar is closer to the method specification.
1607 * But returning True when toolbar is not implemented so not displayed
1608 * could be bad for ActiveX users which rely on this value to show their
1609 * own toolbar if not provided by the ActiveX.
1611 * This is the reason why FALSE is returned, until toolbar get implemented.
1614 /* DISABLED for now */
1615 // *visible = varbool( _p_instance->getShowToolbar() );
1617 *visible = VARIANT_FALSE;
1622 STDMETHODIMP VLCControl2::put_Toolbar(VARIANT_BOOL visible)
1624 _p_instance->setShowToolbar((VARIANT_FALSE != visible) ? TRUE: FALSE);
1629 STDMETHODIMP VLCControl2::get_StartTime(long *seconds)
1631 if( NULL == seconds )
1634 *seconds = _p_instance->getStartTime();
1639 STDMETHODIMP VLCControl2::put_StartTime(long seconds)
1641 _p_instance->setStartTime(seconds);
1646 STDMETHODIMP VLCControl2::get_VersionInfo(BSTR *version)
1648 if( NULL == version )
1651 const char *versionStr = libvlc_get_version();
1652 if( NULL != versionStr )
1654 *version = BSTRFromCStr(CP_UTF8, versionStr);
1656 return (NULL == *version) ? E_OUTOFMEMORY : NOERROR;
1662 STDMETHODIMP VLCControl2::get_Visible(VARIANT_BOOL *isVisible)
1664 if( NULL == isVisible )
1667 *isVisible = varbool( _p_instance->getVisible() );
1672 STDMETHODIMP VLCControl2::put_Visible(VARIANT_BOOL isVisible)
1674 _p_instance->setVisible(isVisible != VARIANT_FALSE);
1679 STDMETHODIMP VLCControl2::get_Volume(long *volume)
1681 if( NULL == volume )
1684 *volume = _p_instance->getVolume();
1688 STDMETHODIMP VLCControl2::put_Volume(long volume)
1690 _p_instance->setVolume(volume);
1694 STDMETHODIMP VLCControl2::get_BackColor(OLE_COLOR *backcolor)
1696 if( NULL == backcolor )
1699 *backcolor = _p_instance->getBackColor();
1703 STDMETHODIMP VLCControl2::put_BackColor(OLE_COLOR backcolor)
1705 _p_instance->setBackColor(backcolor);
1709 STDMETHODIMP VLCControl2::get_audio(IVLCAudio** obj)
1711 return object_get(obj,_p_vlcaudio);
1714 STDMETHODIMP VLCControl2::get_input(IVLCInput** obj)
1716 return object_get(obj,_p_vlcinput);
1719 STDMETHODIMP VLCControl2::get_playlist(IVLCPlaylist** obj)
1721 return object_get(obj,_p_vlcplaylist);
1724 STDMETHODIMP VLCControl2::get_subtitle(IVLCSubtitle** obj)
1726 return object_get(obj,_p_vlcsubtitle);
1729 STDMETHODIMP VLCControl2::get_video(IVLCVideo** obj)
1731 return object_get(obj,_p_vlcvideo);