[demux/avi] Enable dirac support (Set PTS on first output block)
[vlc/davidf-public.git] / projects / activex / vlccontrol2.cpp
blob2a3c62b7183a9bfbac643e609cff930a2ab2face
1 /*****************************************************************************
2 * vlccontrol2.cpp: ActiveX control for VLC
3 *****************************************************************************
4 * Copyright (C) 2006 the VideoLAN team
6 * Authors: Damien Fouilleul <Damien.Fouilleul@laposte.net>
7 * Jean-Paul Saman <jpsaman _at_ m2x _dot_ nl>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 #include "plugin.h"
25 #include "vlccontrol2.h"
26 #include "vlccontrol.h"
28 #include "utils.h"
30 #include <shlwapi.h>
31 #include <wininet.h>
32 #include <tchar.h>
34 using namespace std;
36 VLCAudio::~VLCAudio()
38 if( _p_typeinfo )
39 _p_typeinfo->Release();
42 HRESULT VLCAudio::loadTypeInfo(void)
44 HRESULT hr = NOERROR;
45 if( NULL == _p_typeinfo )
47 ITypeLib *p_typelib;
49 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
50 if( SUCCEEDED(hr) )
52 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCAudio, &_p_typeinfo);
53 if( FAILED(hr) )
55 _p_typeinfo = NULL;
57 p_typelib->Release();
60 return hr;
63 STDMETHODIMP VLCAudio::GetTypeInfoCount(UINT* pctInfo)
65 if( NULL == pctInfo )
66 return E_INVALIDARG;
68 if( SUCCEEDED(loadTypeInfo()) )
69 *pctInfo = 1;
70 else
71 *pctInfo = 0;
73 return NOERROR;
76 STDMETHODIMP VLCAudio::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
78 if( NULL == ppTInfo )
79 return E_INVALIDARG;
81 if( SUCCEEDED(loadTypeInfo()) )
83 _p_typeinfo->AddRef();
84 *ppTInfo = _p_typeinfo;
85 return NOERROR;
87 *ppTInfo = NULL;
88 return E_NOTIMPL;
91 STDMETHODIMP VLCAudio::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
92 UINT cNames, LCID lcid, DISPID* rgDispID)
94 if( SUCCEEDED(loadTypeInfo()) )
96 return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
98 return E_NOTIMPL;
101 STDMETHODIMP VLCAudio::Invoke(DISPID dispIdMember, REFIID riid,
102 LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
103 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
105 if( SUCCEEDED(loadTypeInfo()) )
107 return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
108 pVarResult, pExcepInfo, puArgErr);
110 return E_NOTIMPL;
113 STDMETHODIMP VLCAudio::get_mute(VARIANT_BOOL* mute)
115 if( NULL == mute )
116 return E_POINTER;
118 libvlc_instance_t* p_libvlc;
119 HRESULT hr = _p_instance->getVLC(&p_libvlc);
120 if( SUCCEEDED(hr) )
122 libvlc_exception_t ex;
123 libvlc_exception_init(&ex);
125 *mute = libvlc_audio_get_mute(p_libvlc, &ex) ?
126 VARIANT_TRUE : VARIANT_FALSE;
127 if( libvlc_exception_raised(&ex) )
129 _p_instance->setErrorInfo(IID_IVLCAudio,
130 libvlc_exception_get_message(&ex));
131 libvlc_exception_clear(&ex);
132 return E_FAIL;
134 return NOERROR;
136 return hr;
139 STDMETHODIMP VLCAudio::put_mute(VARIANT_BOOL mute)
141 libvlc_instance_t* p_libvlc;
142 HRESULT hr = _p_instance->getVLC(&p_libvlc);
143 if( SUCCEEDED(hr) )
145 libvlc_exception_t ex;
146 libvlc_exception_init(&ex);
148 libvlc_audio_set_mute(p_libvlc, VARIANT_FALSE != mute, &ex);
149 if( libvlc_exception_raised(&ex) )
151 _p_instance->setErrorInfo(IID_IVLCAudio,
152 libvlc_exception_get_message(&ex));
153 libvlc_exception_clear(&ex);
154 return E_FAIL;
156 return NOERROR;
158 return hr;
161 STDMETHODIMP VLCAudio::get_volume(long* volume)
163 if( NULL == volume )
164 return E_POINTER;
166 libvlc_instance_t* p_libvlc;
167 HRESULT hr = _p_instance->getVLC(&p_libvlc);
168 if( SUCCEEDED(hr) )
170 libvlc_exception_t ex;
171 libvlc_exception_init(&ex);
173 *volume = libvlc_audio_get_volume(p_libvlc, &ex);
174 if( libvlc_exception_raised(&ex) )
176 _p_instance->setErrorInfo(IID_IVLCAudio,
177 libvlc_exception_get_message(&ex));
178 libvlc_exception_clear(&ex);
179 return E_FAIL;
181 return NOERROR;
183 return hr;
186 STDMETHODIMP VLCAudio::put_volume(long volume)
188 libvlc_instance_t* p_libvlc;
189 HRESULT hr = _p_instance->getVLC(&p_libvlc);
190 if( SUCCEEDED(hr) )
192 libvlc_exception_t ex;
193 libvlc_exception_init(&ex);
195 libvlc_audio_set_volume(p_libvlc, volume, &ex);
196 if( libvlc_exception_raised(&ex) )
198 _p_instance->setErrorInfo(IID_IVLCAudio,
199 libvlc_exception_get_message(&ex));
200 libvlc_exception_clear(&ex);
201 return E_FAIL;
203 return NOERROR;
205 return hr;
208 STDMETHODIMP VLCAudio::get_track(long* track)
210 if( NULL == track )
211 return E_POINTER;
213 libvlc_instance_t* p_libvlc;
214 HRESULT hr = _p_instance->getVLC(&p_libvlc);
215 if( SUCCEEDED(hr) )
217 libvlc_exception_t ex;
218 libvlc_exception_init(&ex);
220 libvlc_media_player_t *p_md;
221 p_md = libvlc_playlist_get_media_player(p_libvlc, &ex);
222 *track = libvlc_audio_get_track(p_md, &ex);
223 libvlc_media_player_release(p_md);
224 if( libvlc_exception_raised(&ex) )
226 _p_instance->setErrorInfo(IID_IVLCAudio,
227 libvlc_exception_get_message(&ex));
228 libvlc_exception_clear(&ex);
229 return E_FAIL;
231 return NOERROR;
233 return hr;
236 STDMETHODIMP VLCAudio::put_track(long track)
238 libvlc_instance_t* p_libvlc;
239 HRESULT hr = _p_instance->getVLC(&p_libvlc);
240 if( SUCCEEDED(hr) )
242 libvlc_exception_t ex;
243 libvlc_exception_init(&ex);
245 libvlc_media_player_t *p_md;
246 p_md = libvlc_playlist_get_media_player(p_libvlc, &ex);
247 libvlc_audio_set_track(p_md, track, &ex);
248 libvlc_media_player_release(p_md);
249 if( libvlc_exception_raised(&ex) )
251 _p_instance->setErrorInfo(IID_IVLCAudio,
252 libvlc_exception_get_message(&ex));
253 libvlc_exception_clear(&ex);
254 return E_FAIL;
256 return NOERROR;
258 return hr;
261 STDMETHODIMP VLCAudio::get_channel(long *channel)
263 if( NULL == channel )
264 return E_POINTER;
266 libvlc_instance_t* p_libvlc;
267 HRESULT hr = _p_instance->getVLC(&p_libvlc);
268 if( SUCCEEDED(hr) )
270 libvlc_exception_t ex;
271 libvlc_exception_init(&ex);
273 *channel = libvlc_audio_get_channel(p_libvlc, &ex);
274 if( libvlc_exception_raised(&ex) )
276 _p_instance->setErrorInfo(IID_IVLCAudio,
277 libvlc_exception_get_message(&ex));
278 libvlc_exception_clear(&ex);
279 return E_FAIL;
281 return NOERROR;
283 return hr;
286 STDMETHODIMP VLCAudio::put_channel(long channel)
288 libvlc_instance_t* p_libvlc;
289 HRESULT hr = _p_instance->getVLC(&p_libvlc);
290 if( SUCCEEDED(hr) )
292 libvlc_exception_t ex;
293 libvlc_exception_init(&ex);
295 libvlc_audio_set_channel(p_libvlc, channel, &ex);
296 if( libvlc_exception_raised(&ex) )
298 _p_instance->setErrorInfo(IID_IVLCAudio,
299 libvlc_exception_get_message(&ex));
300 libvlc_exception_clear(&ex);
301 return E_FAIL;
303 return NOERROR;
305 return hr;
308 STDMETHODIMP VLCAudio::toggleMute()
310 libvlc_instance_t* p_libvlc;
311 HRESULT hr = _p_instance->getVLC(&p_libvlc);
312 if( SUCCEEDED(hr) )
314 libvlc_exception_t ex;
315 libvlc_exception_init(&ex);
317 libvlc_audio_toggle_mute(p_libvlc, &ex);
318 if( libvlc_exception_raised(&ex) )
320 _p_instance->setErrorInfo(IID_IVLCAudio,
321 libvlc_exception_get_message(&ex));
322 libvlc_exception_clear(&ex);
323 return E_FAIL;
325 return NOERROR;
327 return hr;
330 /*******************************************************************************/
332 VLCInput::~VLCInput()
334 if( _p_typeinfo )
335 _p_typeinfo->Release();
338 HRESULT VLCInput::loadTypeInfo(void)
340 HRESULT hr = NOERROR;
341 if( NULL == _p_typeinfo )
343 ITypeLib *p_typelib;
345 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
346 if( SUCCEEDED(hr) )
348 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCInput, &_p_typeinfo);
349 if( FAILED(hr) )
351 _p_typeinfo = NULL;
353 p_typelib->Release();
356 return hr;
359 STDMETHODIMP VLCInput::GetTypeInfoCount(UINT* pctInfo)
361 if( NULL == pctInfo )
362 return E_INVALIDARG;
364 if( SUCCEEDED(loadTypeInfo()) )
365 *pctInfo = 1;
366 else
367 *pctInfo = 0;
369 return NOERROR;
372 STDMETHODIMP VLCInput::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
374 if( NULL == ppTInfo )
375 return E_INVALIDARG;
377 if( SUCCEEDED(loadTypeInfo()) )
379 _p_typeinfo->AddRef();
380 *ppTInfo = _p_typeinfo;
381 return NOERROR;
383 *ppTInfo = NULL;
384 return E_NOTIMPL;
387 STDMETHODIMP VLCInput::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
388 UINT cNames, LCID lcid, DISPID* rgDispID)
390 if( SUCCEEDED(loadTypeInfo()) )
392 return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
394 return E_NOTIMPL;
397 STDMETHODIMP VLCInput::Invoke(DISPID dispIdMember, REFIID riid,
398 LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
399 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
401 if( SUCCEEDED(loadTypeInfo()) )
403 return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
404 pVarResult, pExcepInfo, puArgErr);
406 return E_NOTIMPL;
409 STDMETHODIMP VLCInput::get_length(double* length)
411 if( NULL == length )
412 return E_POINTER;
413 *length = 0;
415 libvlc_instance_t* p_libvlc;
416 HRESULT hr = _p_instance->getVLC(&p_libvlc);
417 if( SUCCEEDED(hr) )
419 libvlc_exception_t ex;
420 libvlc_exception_init(&ex);
422 libvlc_media_player_t *p_md;
423 p_md = libvlc_playlist_get_media_player(p_libvlc, &ex);
424 if( ! libvlc_exception_raised(&ex) )
426 *length = (double)libvlc_media_player_get_length(p_md, &ex);
427 libvlc_media_player_release(p_md);
428 if( ! libvlc_exception_raised(&ex) )
430 return NOERROR;
433 _p_instance->setErrorInfo(IID_IVLCInput,
434 libvlc_exception_get_message(&ex));
435 libvlc_exception_clear(&ex);
436 return E_FAIL;
438 return hr;
441 STDMETHODIMP VLCInput::get_position(double* position)
443 if( NULL == position )
444 return E_POINTER;
446 *position = 0.0f;
447 libvlc_instance_t* p_libvlc;
448 HRESULT hr = _p_instance->getVLC(&p_libvlc);
449 if( SUCCEEDED(hr) )
451 libvlc_exception_t ex;
452 libvlc_exception_init(&ex);
454 libvlc_media_player_t *p_md;
455 p_md = libvlc_playlist_get_media_player(p_libvlc, &ex);
456 if( ! libvlc_exception_raised(&ex) )
458 *position = libvlc_media_player_get_position(p_md, &ex);
459 libvlc_media_player_release(p_md);
460 if( ! libvlc_exception_raised(&ex) )
462 return NOERROR;
465 _p_instance->setErrorInfo(IID_IVLCInput,
466 libvlc_exception_get_message(&ex));
467 libvlc_exception_clear(&ex);
468 return E_FAIL;
470 return hr;
473 STDMETHODIMP VLCInput::put_position(double position)
475 libvlc_instance_t* p_libvlc;
476 HRESULT hr = _p_instance->getVLC(&p_libvlc);
477 if( SUCCEEDED(hr) )
479 libvlc_exception_t ex;
480 libvlc_exception_init(&ex);
482 libvlc_media_player_t *p_md;
483 p_md = libvlc_playlist_get_media_player(p_libvlc, &ex);
484 if( ! libvlc_exception_raised(&ex) )
486 libvlc_media_player_set_position(p_md, position, &ex);
487 libvlc_media_player_release(p_md);
488 if( ! libvlc_exception_raised(&ex) )
490 return NOERROR;
493 _p_instance->setErrorInfo(IID_IVLCInput,
494 libvlc_exception_get_message(&ex));
495 libvlc_exception_clear(&ex);
496 return E_FAIL;
498 return hr;
501 STDMETHODIMP VLCInput::get_time(double* time)
503 if( NULL == time )
504 return E_POINTER;
506 libvlc_instance_t* p_libvlc;
507 HRESULT hr = _p_instance->getVLC(&p_libvlc);
508 if( SUCCEEDED(hr) )
510 libvlc_exception_t ex;
511 libvlc_exception_init(&ex);
513 libvlc_media_player_t *p_md;
514 p_md = libvlc_playlist_get_media_player(p_libvlc, &ex);
515 if( ! libvlc_exception_raised(&ex) )
517 *time = (double)libvlc_media_player_get_time(p_md, &ex);
518 libvlc_media_player_release(p_md);
519 if( ! libvlc_exception_raised(&ex) )
521 return NOERROR;
524 _p_instance->setErrorInfo(IID_IVLCInput,
525 libvlc_exception_get_message(&ex));
526 libvlc_exception_clear(&ex);
527 return E_FAIL;
529 return hr;
532 STDMETHODIMP VLCInput::put_time(double time)
534 libvlc_instance_t* p_libvlc;
535 HRESULT hr = _p_instance->getVLC(&p_libvlc);
536 if( SUCCEEDED(hr) )
538 libvlc_exception_t ex;
539 libvlc_exception_init(&ex);
541 libvlc_media_player_t *p_md;
542 p_md = libvlc_playlist_get_media_player(p_libvlc, &ex);
543 if( ! libvlc_exception_raised(&ex) )
545 libvlc_media_player_set_time(p_md, (int64_t)time, &ex);
546 libvlc_media_player_release(p_md);
547 if( ! libvlc_exception_raised(&ex) )
549 return NOERROR;
552 _p_instance->setErrorInfo(IID_IVLCInput,
553 libvlc_exception_get_message(&ex));
554 libvlc_exception_clear(&ex);
555 return E_FAIL;
557 return hr;
560 STDMETHODIMP VLCInput::get_state(long* state)
562 if( NULL == state )
563 return E_POINTER;
565 libvlc_instance_t* p_libvlc;
566 HRESULT hr = _p_instance->getVLC(&p_libvlc);
567 if( SUCCEEDED(hr) )
569 libvlc_exception_t ex;
570 libvlc_exception_init(&ex);
572 libvlc_media_player_t *p_md;
573 p_md = libvlc_playlist_get_media_player(p_libvlc, &ex);
574 if( ! libvlc_exception_raised(&ex) )
576 *state = libvlc_media_player_get_state(p_md, &ex);
577 libvlc_media_player_release(p_md);
578 if( ! libvlc_exception_raised(&ex) )
580 return NOERROR;
583 libvlc_exception_clear(&ex);
584 // don't fail, just return the idle state
585 *state = 0;
586 return NOERROR;
588 return hr;
591 STDMETHODIMP VLCInput::get_rate(double* rate)
593 if( NULL == rate )
594 return E_POINTER;
596 libvlc_instance_t* p_libvlc;
597 HRESULT hr = _p_instance->getVLC(&p_libvlc);
598 if( SUCCEEDED(hr) )
600 libvlc_exception_t ex;
601 libvlc_exception_init(&ex);
603 libvlc_media_player_t *p_md;
604 p_md = libvlc_playlist_get_media_player(p_libvlc, &ex);
605 if( ! libvlc_exception_raised(&ex) )
607 *rate = libvlc_media_player_get_rate(p_md, &ex);
608 libvlc_media_player_release(p_md);
609 if( ! libvlc_exception_raised(&ex) )
611 return NOERROR;
614 _p_instance->setErrorInfo(IID_IVLCInput,
615 libvlc_exception_get_message(&ex));
616 libvlc_exception_clear(&ex);
617 return E_FAIL;
619 return hr;
622 STDMETHODIMP VLCInput::put_rate(double rate)
624 libvlc_instance_t* p_libvlc;
625 HRESULT hr = _p_instance->getVLC(&p_libvlc);
626 if( SUCCEEDED(hr) )
628 libvlc_exception_t ex;
629 libvlc_exception_init(&ex);
631 libvlc_media_player_t *p_md;
632 p_md = libvlc_playlist_get_media_player(p_libvlc, &ex);
633 if( ! libvlc_exception_raised(&ex) )
635 libvlc_media_player_set_rate(p_md, rate, &ex);
636 libvlc_media_player_release(p_md);
637 if( ! libvlc_exception_raised(&ex) )
639 return NOERROR;
642 _p_instance->setErrorInfo(IID_IVLCInput,
643 libvlc_exception_get_message(&ex));
644 libvlc_exception_clear(&ex);
645 return E_FAIL;
647 return hr;
650 STDMETHODIMP VLCInput::get_fps(double* fps)
652 if( NULL == fps )
653 return E_POINTER;
655 *fps = 0.0;
656 libvlc_instance_t* p_libvlc;
657 HRESULT hr = _p_instance->getVLC(&p_libvlc);
658 if( SUCCEEDED(hr) )
660 libvlc_exception_t ex;
661 libvlc_exception_init(&ex);
663 libvlc_media_player_t *p_md;
664 p_md = libvlc_playlist_get_media_player(p_libvlc, &ex);
665 if( ! libvlc_exception_raised(&ex) )
667 *fps = libvlc_media_player_get_fps(p_md, &ex);
668 libvlc_media_player_release(p_md);
669 if( ! libvlc_exception_raised(&ex) )
671 return NOERROR;
674 _p_instance->setErrorInfo(IID_IVLCInput,
675 libvlc_exception_get_message(&ex));
676 libvlc_exception_clear(&ex);
677 return E_FAIL;
679 return hr;
682 STDMETHODIMP VLCInput::get_hasVout(VARIANT_BOOL* hasVout)
684 if( NULL == hasVout )
685 return E_POINTER;
687 libvlc_instance_t* p_libvlc;
688 HRESULT hr = _p_instance->getVLC(&p_libvlc);
689 if( SUCCEEDED(hr) )
691 libvlc_exception_t ex;
692 libvlc_exception_init(&ex);
694 libvlc_media_player_t *p_md;
695 p_md = libvlc_playlist_get_media_player(p_libvlc, &ex);
696 if( ! libvlc_exception_raised(&ex) )
698 *hasVout = libvlc_media_player_has_vout(p_md, &ex) ?
699 VARIANT_TRUE : VARIANT_FALSE;
700 libvlc_media_player_release(p_md);
701 if( ! libvlc_exception_raised(&ex) )
703 return NOERROR;
706 _p_instance->setErrorInfo(IID_IVLCInput,
707 libvlc_exception_get_message(&ex));
708 libvlc_exception_clear(&ex);
709 return E_FAIL;
711 return hr;
714 /*******************************************************************************/
716 VLCLog::~VLCLog()
718 delete _p_vlcmessages;
719 if( _p_log )
720 libvlc_log_close(_p_log, NULL);
722 if( _p_typeinfo )
723 _p_typeinfo->Release();
726 HRESULT VLCLog::loadTypeInfo(void)
728 HRESULT hr = NOERROR;
729 if( NULL == _p_typeinfo )
731 ITypeLib *p_typelib;
733 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
734 if( SUCCEEDED(hr) )
736 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCLog, &_p_typeinfo);
737 if( FAILED(hr) )
739 _p_typeinfo = NULL;
741 p_typelib->Release();
744 return hr;
747 STDMETHODIMP VLCLog::GetTypeInfoCount(UINT* pctInfo)
749 if( NULL == pctInfo )
750 return E_INVALIDARG;
752 if( SUCCEEDED(loadTypeInfo()) )
753 *pctInfo = 1;
754 else
755 *pctInfo = 0;
757 return NOERROR;
760 STDMETHODIMP VLCLog::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
762 if( NULL == ppTInfo )
763 return E_INVALIDARG;
765 if( SUCCEEDED(loadTypeInfo()) )
767 _p_typeinfo->AddRef();
768 *ppTInfo = _p_typeinfo;
769 return NOERROR;
771 *ppTInfo = NULL;
772 return E_NOTIMPL;
775 STDMETHODIMP VLCLog::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
776 UINT cNames, LCID lcid, DISPID* rgDispID)
778 if( SUCCEEDED(loadTypeInfo()) )
780 return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
782 return E_NOTIMPL;
785 STDMETHODIMP VLCLog::Invoke(DISPID dispIdMember, REFIID riid,
786 LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
787 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
789 if( SUCCEEDED(loadTypeInfo()) )
791 return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
792 pVarResult, pExcepInfo, puArgErr);
794 return E_NOTIMPL;
797 STDMETHODIMP VLCLog::get_messages(IVLCMessages** obj)
799 if( NULL == obj )
800 return E_POINTER;
802 *obj = _p_vlcmessages;
803 if( NULL != _p_vlcmessages )
805 _p_vlcmessages->AddRef();
806 return NOERROR;
808 return E_OUTOFMEMORY;
811 STDMETHODIMP VLCLog::get_verbosity(long* level)
813 if( NULL == level )
814 return E_POINTER;
816 if( _p_log )
818 libvlc_instance_t* p_libvlc;
819 HRESULT hr = _p_instance->getVLC(&p_libvlc);
820 if( SUCCEEDED(hr) )
822 libvlc_exception_t ex;
823 libvlc_exception_init(&ex);
825 *level = libvlc_get_log_verbosity(p_libvlc, &ex);
826 if( libvlc_exception_raised(&ex) )
828 _p_instance->setErrorInfo(IID_IVLCLog,
829 libvlc_exception_get_message(&ex));
830 libvlc_exception_clear(&ex);
831 return E_FAIL;
834 return hr;
836 else
838 /* log is not enabled, return -1 */
839 *level = -1;
840 return NOERROR;
844 STDMETHODIMP VLCLog::put_verbosity(long verbosity)
846 libvlc_exception_t ex;
847 libvlc_exception_init(&ex);
849 libvlc_instance_t* p_libvlc;
850 HRESULT hr = _p_instance->getVLC(&p_libvlc);
851 if( SUCCEEDED(hr) )
853 if( verbosity >= 0 )
855 if( ! _p_log )
857 _p_log = libvlc_log_open(p_libvlc, &ex);
858 if( libvlc_exception_raised(&ex) )
860 _p_instance->setErrorInfo(IID_IVLCLog,
861 libvlc_exception_get_message(&ex));
862 libvlc_exception_clear(&ex);
863 return E_FAIL;
866 libvlc_set_log_verbosity(p_libvlc, (unsigned)verbosity, &ex);
867 if( libvlc_exception_raised(&ex) )
869 _p_instance->setErrorInfo(IID_IVLCLog,
870 libvlc_exception_get_message(&ex));
871 libvlc_exception_clear(&ex);
872 return E_FAIL;
875 else if( _p_log )
877 /* close log when verbosity is set to -1 */
878 libvlc_log_close(_p_log, &ex);
879 _p_log = NULL;
880 if( libvlc_exception_raised(&ex) )
882 _p_instance->setErrorInfo(IID_IVLCLog,
883 libvlc_exception_get_message(&ex));
884 libvlc_exception_clear(&ex);
885 return E_FAIL;
889 return hr;
892 /*******************************************************************************/
894 /* STL forward iterator used by VLCEnumIterator class to implement IEnumVARIANT */
896 class VLCMessageSTLIterator
899 public:
901 VLCMessageSTLIterator(IVLCMessageIterator* iter) : iter(iter), msg(NULL)
903 // get first message
904 operator++();
907 VLCMessageSTLIterator(const VLCMessageSTLIterator& other)
909 iter = other.iter;
910 if( iter )
911 iter->AddRef();
912 msg = other.msg;
913 if( msg )
914 msg->AddRef();
917 virtual ~VLCMessageSTLIterator()
919 if( msg )
920 msg->Release();
922 if( iter )
923 iter->Release();
926 // we only need prefix ++ operator
927 VLCMessageSTLIterator& operator++()
929 VARIANT_BOOL hasNext = VARIANT_FALSE;
930 if( iter )
932 iter->get_hasNext(&hasNext);
934 if( msg )
936 msg->Release();
937 msg = NULL;
939 if( VARIANT_TRUE == hasNext ) {
940 iter->next(&msg);
943 return *this;
946 VARIANT operator*() const
948 VARIANT v;
949 VariantInit(&v);
950 if( msg )
952 if( SUCCEEDED(msg->QueryInterface(IID_IDispatch,
953 (LPVOID*)&V_DISPATCH(&v))) )
955 V_VT(&v) = VT_DISPATCH;
958 return v;
961 bool operator==(const VLCMessageSTLIterator& other) const
963 return msg == other.msg;
966 bool operator!=(const VLCMessageSTLIterator& other) const
968 return msg != other.msg;
971 private:
972 IVLCMessageIterator* iter;
973 IVLCMessage* msg;
976 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
978 VLCMessages::~VLCMessages()
980 if( _p_typeinfo )
981 _p_typeinfo->Release();
984 HRESULT VLCMessages::loadTypeInfo(void)
986 HRESULT hr = NOERROR;
987 if( NULL == _p_typeinfo )
989 ITypeLib *p_typelib;
991 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
992 if( SUCCEEDED(hr) )
994 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCMessages, &_p_typeinfo);
995 if( FAILED(hr) )
997 _p_typeinfo = NULL;
999 p_typelib->Release();
1002 return hr;
1005 STDMETHODIMP VLCMessages::GetTypeInfoCount(UINT* pctInfo)
1007 if( NULL == pctInfo )
1008 return E_INVALIDARG;
1010 if( SUCCEEDED(loadTypeInfo()) )
1011 *pctInfo = 1;
1012 else
1013 *pctInfo = 0;
1015 return NOERROR;
1018 STDMETHODIMP VLCMessages::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
1020 if( NULL == ppTInfo )
1021 return E_INVALIDARG;
1023 if( SUCCEEDED(loadTypeInfo()) )
1025 _p_typeinfo->AddRef();
1026 *ppTInfo = _p_typeinfo;
1027 return NOERROR;
1029 *ppTInfo = NULL;
1030 return E_NOTIMPL;
1033 STDMETHODIMP VLCMessages::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
1034 UINT cNames, LCID lcid, DISPID* rgDispID)
1036 if( SUCCEEDED(loadTypeInfo()) )
1038 return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
1040 return E_NOTIMPL;
1043 STDMETHODIMP VLCMessages::Invoke(DISPID dispIdMember, REFIID riid,
1044 LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
1045 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
1047 if( SUCCEEDED(loadTypeInfo()) )
1049 return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
1050 pVarResult, pExcepInfo, puArgErr);
1052 return E_NOTIMPL;
1055 STDMETHODIMP VLCMessages::get__NewEnum(LPUNKNOWN* _NewEnum)
1057 if( NULL == _NewEnum )
1058 return E_POINTER;
1060 IVLCMessageIterator* iter = NULL;
1061 iterator(&iter);
1063 *_NewEnum= new VLCEnumIterator<IID_IEnumVARIANT,
1064 IEnumVARIANT,
1065 VARIANT,
1066 VLCMessageSTLIterator>
1067 (VLCMessageSTLIterator(iter), VLCMessageSTLIterator(NULL));
1069 return *_NewEnum ? S_OK : E_OUTOFMEMORY;
1072 STDMETHODIMP VLCMessages::clear()
1074 libvlc_log_t *p_log = _p_vlclog->_p_log;
1075 if( p_log )
1077 libvlc_exception_t ex;
1078 libvlc_exception_init(&ex);
1080 libvlc_log_clear(p_log, &ex);
1081 if( libvlc_exception_raised(&ex) )
1083 _p_instance->setErrorInfo(IID_IVLCMessages,
1084 libvlc_exception_get_message(&ex));
1085 libvlc_exception_clear(&ex);
1086 return E_FAIL;
1089 return NOERROR;
1092 STDMETHODIMP VLCMessages::get_count(long* count)
1094 if( NULL == count )
1095 return E_POINTER;
1097 libvlc_log_t *p_log = _p_vlclog->_p_log;
1098 if( p_log )
1100 libvlc_exception_t ex;
1101 libvlc_exception_init(&ex);
1103 *count = libvlc_log_count(p_log, &ex);
1104 if( libvlc_exception_raised(&ex) )
1106 _p_instance->setErrorInfo(IID_IVLCMessages,
1107 libvlc_exception_get_message(&ex));
1108 libvlc_exception_clear(&ex);
1109 return E_FAIL;
1112 else
1113 *count = 0;
1114 return S_OK;
1117 STDMETHODIMP VLCMessages::iterator(IVLCMessageIterator** iter)
1119 if( NULL == iter )
1120 return E_POINTER;
1122 *iter = new VLCMessageIterator(_p_instance, _p_vlclog);
1124 return *iter ? S_OK : E_OUTOFMEMORY;
1127 /*******************************************************************************/
1129 VLCMessageIterator::VLCMessageIterator(VLCPlugin *p_instance, VLCLog* p_vlclog ) :
1130 _p_instance(p_instance),
1131 _p_typeinfo(NULL),
1132 _refcount(1),
1133 _p_vlclog(p_vlclog)
1135 if( p_vlclog->_p_log )
1137 _p_iter = libvlc_log_get_iterator(p_vlclog->_p_log, NULL);
1139 else
1140 _p_iter = NULL;
1143 VLCMessageIterator::~VLCMessageIterator()
1145 if( _p_iter )
1146 libvlc_log_iterator_free(_p_iter, NULL);
1148 if( _p_typeinfo )
1149 _p_typeinfo->Release();
1152 HRESULT VLCMessageIterator::loadTypeInfo(void)
1154 HRESULT hr = NOERROR;
1155 if( NULL == _p_typeinfo )
1157 ITypeLib *p_typelib;
1159 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
1160 if( SUCCEEDED(hr) )
1162 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCMessageIterator, &_p_typeinfo);
1163 if( FAILED(hr) )
1165 _p_typeinfo = NULL;
1167 p_typelib->Release();
1170 return hr;
1173 STDMETHODIMP VLCMessageIterator::GetTypeInfoCount(UINT* pctInfo)
1175 if( NULL == pctInfo )
1176 return E_INVALIDARG;
1178 if( SUCCEEDED(loadTypeInfo()) )
1179 *pctInfo = 1;
1180 else
1181 *pctInfo = 0;
1183 return NOERROR;
1186 STDMETHODIMP VLCMessageIterator::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
1188 if( NULL == ppTInfo )
1189 return E_INVALIDARG;
1191 if( SUCCEEDED(loadTypeInfo()) )
1193 _p_typeinfo->AddRef();
1194 *ppTInfo = _p_typeinfo;
1195 return NOERROR;
1197 *ppTInfo = NULL;
1198 return E_NOTIMPL;
1201 STDMETHODIMP VLCMessageIterator::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
1202 UINT cNames, LCID lcid, DISPID* rgDispID)
1204 if( SUCCEEDED(loadTypeInfo()) )
1206 return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
1208 return E_NOTIMPL;
1211 STDMETHODIMP VLCMessageIterator::Invoke(DISPID dispIdMember, REFIID riid,
1212 LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
1213 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
1215 if( SUCCEEDED(loadTypeInfo()) )
1217 return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
1218 pVarResult, pExcepInfo, puArgErr);
1220 return E_NOTIMPL;
1223 STDMETHODIMP VLCMessageIterator::get_hasNext(VARIANT_BOOL* hasNext)
1225 if( NULL == hasNext )
1226 return E_POINTER;
1228 if( _p_iter && _p_vlclog->_p_log )
1230 libvlc_exception_t ex;
1231 libvlc_exception_init(&ex);
1233 *hasNext = libvlc_log_iterator_has_next(_p_iter, &ex) ?
1234 VARIANT_TRUE : VARIANT_FALSE;
1235 if( libvlc_exception_raised(&ex) )
1237 _p_instance->setErrorInfo(IID_IVLCMessageIterator,
1238 libvlc_exception_get_message(&ex));
1239 libvlc_exception_clear(&ex);
1240 return E_FAIL;
1243 else
1245 *hasNext = VARIANT_FALSE;
1247 return S_OK;
1250 STDMETHODIMP VLCMessageIterator::next(IVLCMessage** message)
1252 if( NULL == message )
1253 return E_POINTER;
1255 if( _p_iter && _p_vlclog->_p_log )
1257 struct libvlc_log_message_t buffer;
1259 buffer.sizeof_msg = sizeof(buffer);
1261 libvlc_exception_t ex;
1262 libvlc_exception_init(&ex);
1264 libvlc_log_iterator_next(_p_iter, &buffer, &ex);
1265 if( libvlc_exception_raised(&ex) )
1267 _p_instance->setErrorInfo(IID_IVLCMessageIterator,
1268 libvlc_exception_get_message(&ex));
1269 libvlc_exception_clear(&ex);
1270 return E_FAIL;
1272 *message = new VLCMessage(_p_instance, buffer);
1273 return *message ? NOERROR : E_OUTOFMEMORY;
1275 return E_FAIL;
1278 /*******************************************************************************/
1280 VLCMessage::~VLCMessage()
1282 if( _p_typeinfo )
1283 _p_typeinfo->Release();
1286 HRESULT VLCMessage::loadTypeInfo(void)
1288 HRESULT hr = NOERROR;
1289 if( NULL == _p_typeinfo )
1291 ITypeLib *p_typelib;
1293 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
1294 if( SUCCEEDED(hr) )
1296 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCMessage, &_p_typeinfo);
1297 if( FAILED(hr) )
1299 _p_typeinfo = NULL;
1301 p_typelib->Release();
1304 return hr;
1307 STDMETHODIMP VLCMessage::GetTypeInfoCount(UINT* pctInfo)
1309 if( NULL == pctInfo )
1310 return E_INVALIDARG;
1312 if( SUCCEEDED(loadTypeInfo()) )
1313 *pctInfo = 1;
1314 else
1315 *pctInfo = 0;
1317 return NOERROR;
1320 STDMETHODIMP VLCMessage::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
1322 if( NULL == ppTInfo )
1323 return E_INVALIDARG;
1325 if( SUCCEEDED(loadTypeInfo()) )
1327 _p_typeinfo->AddRef();
1328 *ppTInfo = _p_typeinfo;
1329 return NOERROR;
1331 *ppTInfo = NULL;
1332 return E_NOTIMPL;
1335 STDMETHODIMP VLCMessage::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
1336 UINT cNames, LCID lcid, DISPID* rgDispID)
1338 if( SUCCEEDED(loadTypeInfo()) )
1340 return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
1342 return E_NOTIMPL;
1345 STDMETHODIMP VLCMessage::Invoke(DISPID dispIdMember, REFIID riid,
1346 LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
1347 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
1349 if( SUCCEEDED(loadTypeInfo()) )
1351 return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
1352 pVarResult, pExcepInfo, puArgErr);
1354 return E_NOTIMPL;
1357 inline const char *msgSeverity(int sev)
1359 switch( sev )
1361 case 0:
1362 return "info";
1363 case 1:
1364 return "error";
1365 case 2:
1366 return "warning";
1367 default:
1368 return "debug";
1372 STDMETHODIMP VLCMessage::get__Value(VARIANT* _Value)
1374 if( NULL == _Value )
1375 return E_POINTER;
1377 char buffer[256];
1379 snprintf(buffer, sizeof(buffer), "%s %s %s: %s",
1380 _msg.psz_type, _msg.psz_name, msgSeverity(_msg.i_severity), _msg.psz_message);
1382 V_VT(_Value) = VT_BSTR;
1383 V_BSTR(_Value) = BSTRFromCStr(CP_UTF8, buffer);
1385 return S_OK;
1388 STDMETHODIMP VLCMessage::get_severity(long* level)
1390 if( NULL == level )
1391 return E_POINTER;
1393 *level = _msg.i_severity;
1395 return S_OK;
1398 STDMETHODIMP VLCMessage::get_type(BSTR* type)
1400 if( NULL == type )
1401 return E_POINTER;
1403 *type = BSTRFromCStr(CP_UTF8, _msg.psz_type);
1405 return NOERROR;
1408 STDMETHODIMP VLCMessage::get_name(BSTR* name)
1410 if( NULL == name )
1411 return E_POINTER;
1413 *name = BSTRFromCStr(CP_UTF8, _msg.psz_name);
1415 return NOERROR;
1418 STDMETHODIMP VLCMessage::get_header(BSTR* header)
1420 if( NULL == header )
1421 return E_POINTER;
1423 *header = BSTRFromCStr(CP_UTF8, _msg.psz_header);
1425 return NOERROR;
1428 STDMETHODIMP VLCMessage::get_message(BSTR* message)
1430 if( NULL == message )
1431 return E_POINTER;
1433 *message = BSTRFromCStr(CP_UTF8, _msg.psz_message);
1435 return NOERROR;
1438 /*******************************************************************************/
1440 VLCPlaylistItems::~VLCPlaylistItems()
1442 if( _p_typeinfo )
1443 _p_typeinfo->Release();
1446 HRESULT VLCPlaylistItems::loadTypeInfo(void)
1448 HRESULT hr = NOERROR;
1449 if( NULL == _p_typeinfo )
1451 ITypeLib *p_typelib;
1453 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
1454 if( SUCCEEDED(hr) )
1456 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCPlaylistItems, &_p_typeinfo);
1457 if( FAILED(hr) )
1459 _p_typeinfo = NULL;
1461 p_typelib->Release();
1464 return hr;
1467 STDMETHODIMP VLCPlaylistItems::GetTypeInfoCount(UINT* pctInfo)
1469 if( NULL == pctInfo )
1470 return E_INVALIDARG;
1472 if( SUCCEEDED(loadTypeInfo()) )
1473 *pctInfo = 1;
1474 else
1475 *pctInfo = 0;
1477 return NOERROR;
1480 STDMETHODIMP VLCPlaylistItems::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
1482 if( NULL == ppTInfo )
1483 return E_INVALIDARG;
1485 if( SUCCEEDED(loadTypeInfo()) )
1487 _p_typeinfo->AddRef();
1488 *ppTInfo = _p_typeinfo;
1489 return NOERROR;
1491 *ppTInfo = NULL;
1492 return E_NOTIMPL;
1495 STDMETHODIMP VLCPlaylistItems::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
1496 UINT cNames, LCID lcid, DISPID* rgDispID)
1498 if( SUCCEEDED(loadTypeInfo()) )
1500 return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
1502 return E_NOTIMPL;
1505 STDMETHODIMP VLCPlaylistItems::Invoke(DISPID dispIdMember, REFIID riid,
1506 LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
1507 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
1509 if( SUCCEEDED(loadTypeInfo()) )
1511 return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
1512 pVarResult, pExcepInfo, puArgErr);
1514 return E_NOTIMPL;
1517 STDMETHODIMP VLCPlaylistItems::get_count(long* count)
1519 if( NULL == count )
1520 return E_POINTER;
1522 libvlc_instance_t* p_libvlc;
1523 HRESULT hr = _p_instance->getVLC(&p_libvlc);
1524 if( SUCCEEDED(hr) )
1526 libvlc_exception_t ex;
1527 libvlc_exception_init(&ex);
1529 *count = libvlc_playlist_items_count(p_libvlc, &ex);
1530 if( libvlc_exception_raised(&ex) )
1532 _p_instance->setErrorInfo(IID_IVLCPlaylistItems,
1533 libvlc_exception_get_message(&ex));
1534 libvlc_exception_clear(&ex);
1535 return E_FAIL;
1537 return NOERROR;
1539 return hr;
1542 STDMETHODIMP VLCPlaylistItems::clear()
1544 libvlc_instance_t* p_libvlc;
1545 HRESULT hr = _p_instance->getVLC(&p_libvlc);
1546 if( SUCCEEDED(hr) )
1548 libvlc_exception_t ex;
1549 libvlc_exception_init(&ex);
1551 libvlc_playlist_clear(p_libvlc, &ex);
1552 if( libvlc_exception_raised(&ex) )
1554 _p_instance->setErrorInfo(IID_IVLCPlaylistItems,
1555 libvlc_exception_get_message(&ex));
1556 libvlc_exception_clear(&ex);
1557 return E_FAIL;
1559 return NOERROR;
1561 return hr;
1564 STDMETHODIMP VLCPlaylistItems::remove(long item)
1566 libvlc_instance_t* p_libvlc;
1567 HRESULT hr = _p_instance->getVLC(&p_libvlc);
1568 if( SUCCEEDED(hr) )
1570 libvlc_exception_t ex;
1571 libvlc_exception_init(&ex);
1573 libvlc_playlist_delete_item(p_libvlc, item, &ex);
1574 if( libvlc_exception_raised(&ex) )
1576 _p_instance->setErrorInfo(IID_IVLCPlaylistItems,
1577 libvlc_exception_get_message(&ex));
1578 libvlc_exception_clear(&ex);
1579 return E_FAIL;
1581 return NOERROR;
1583 return hr;
1586 /*******************************************************************************/
1588 VLCPlaylist::~VLCPlaylist()
1590 delete _p_vlcplaylistitems;
1591 if( _p_typeinfo )
1592 _p_typeinfo->Release();
1595 HRESULT VLCPlaylist::loadTypeInfo(void)
1597 HRESULT hr = NOERROR;
1598 if( NULL == _p_typeinfo )
1600 ITypeLib *p_typelib;
1602 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
1603 if( SUCCEEDED(hr) )
1605 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCPlaylist, &_p_typeinfo);
1606 if( FAILED(hr) )
1608 _p_typeinfo = NULL;
1610 p_typelib->Release();
1613 return hr;
1616 STDMETHODIMP VLCPlaylist::GetTypeInfoCount(UINT* pctInfo)
1618 if( NULL == pctInfo )
1619 return E_INVALIDARG;
1621 if( SUCCEEDED(loadTypeInfo()) )
1622 *pctInfo = 1;
1623 else
1624 *pctInfo = 0;
1626 return NOERROR;
1629 STDMETHODIMP VLCPlaylist::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
1631 if( NULL == ppTInfo )
1632 return E_INVALIDARG;
1634 if( SUCCEEDED(loadTypeInfo()) )
1636 _p_typeinfo->AddRef();
1637 *ppTInfo = _p_typeinfo;
1638 return NOERROR;
1640 *ppTInfo = NULL;
1641 return E_NOTIMPL;
1644 STDMETHODIMP VLCPlaylist::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
1645 UINT cNames, LCID lcid, DISPID* rgDispID)
1647 if( SUCCEEDED(loadTypeInfo()) )
1649 return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
1651 return E_NOTIMPL;
1654 STDMETHODIMP VLCPlaylist::Invoke(DISPID dispIdMember, REFIID riid,
1655 LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
1656 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
1658 if( SUCCEEDED(loadTypeInfo()) )
1660 return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
1661 pVarResult, pExcepInfo, puArgErr);
1663 return E_NOTIMPL;
1666 STDMETHODIMP VLCPlaylist::get_itemCount(long* count)
1668 if( NULL == count )
1669 return E_POINTER;
1671 *count = 0;
1672 libvlc_instance_t* p_libvlc;
1673 HRESULT hr = _p_instance->getVLC(&p_libvlc);
1674 if( SUCCEEDED(hr) )
1676 libvlc_exception_t ex;
1677 libvlc_exception_init(&ex);
1679 *count = libvlc_playlist_items_count(p_libvlc, &ex);
1680 if( libvlc_exception_raised(&ex) )
1682 _p_instance->setErrorInfo(IID_IVLCPlaylist,
1683 libvlc_exception_get_message(&ex));
1684 libvlc_exception_clear(&ex);
1685 return E_FAIL;
1687 return NOERROR;
1689 return hr;
1692 STDMETHODIMP VLCPlaylist::get_isPlaying(VARIANT_BOOL* isPlaying)
1694 if( NULL == isPlaying )
1695 return E_POINTER;
1697 libvlc_instance_t* p_libvlc;
1698 HRESULT hr = _p_instance->getVLC(&p_libvlc);
1699 if( SUCCEEDED(hr) )
1701 libvlc_exception_t ex;
1702 libvlc_exception_init(&ex);
1704 *isPlaying = libvlc_playlist_isplaying(p_libvlc, &ex) ?
1705 VARIANT_TRUE: VARIANT_FALSE;
1706 if( libvlc_exception_raised(&ex) )
1708 _p_instance->setErrorInfo(IID_IVLCPlaylist,
1709 libvlc_exception_get_message(&ex));
1710 libvlc_exception_clear(&ex);
1711 return E_FAIL;
1713 return NOERROR;
1715 return hr;
1718 STDMETHODIMP VLCPlaylist::add(BSTR uri, VARIANT name, VARIANT options, long* item)
1720 if( NULL == item )
1721 return E_POINTER;
1723 if( 0 == SysStringLen(uri) )
1724 return E_INVALIDARG;
1726 libvlc_instance_t* p_libvlc;
1727 HRESULT hr = _p_instance->getVLC(&p_libvlc);
1728 if( SUCCEEDED(hr) )
1730 libvlc_exception_t ex;
1731 libvlc_exception_init(&ex);
1733 char *psz_uri = NULL;
1734 if( SysStringLen(_p_instance->getBaseURL()) > 0 )
1737 ** if the MRL a relative URL, we should end up with an absolute URL
1739 LPWSTR abs_url = CombineURL(_p_instance->getBaseURL(), uri);
1740 if( NULL != abs_url )
1742 psz_uri = CStrFromWSTR(CP_UTF8, abs_url, wcslen(abs_url));
1743 CoTaskMemFree(abs_url);
1745 else
1747 psz_uri = CStrFromBSTR(CP_UTF8, uri);
1750 else
1753 ** baseURL is empty, assume MRL is absolute
1755 psz_uri = CStrFromBSTR(CP_UTF8, uri);
1758 if( NULL == psz_uri )
1760 return E_OUTOFMEMORY;
1763 int i_options;
1764 char **ppsz_options;
1766 hr = VLCControl::CreateTargetOptions(CP_UTF8, &options, &ppsz_options, &i_options);
1767 if( FAILED(hr) )
1769 CoTaskMemFree(psz_uri);
1770 return hr;
1773 char *psz_name = NULL;
1774 VARIANT v_name;
1775 VariantInit(&v_name);
1776 if( SUCCEEDED(VariantChangeType(&v_name, &name, 0, VT_BSTR)) )
1778 if( SysStringLen(V_BSTR(&v_name)) > 0 )
1779 psz_name = CStrFromBSTR(CP_UTF8, V_BSTR(&v_name));
1781 VariantClear(&v_name);
1784 *item = libvlc_playlist_add_extended(p_libvlc,
1785 psz_uri,
1786 psz_name,
1787 i_options,
1788 const_cast<const char **>(ppsz_options),
1789 &ex);
1791 VLCControl::FreeTargetOptions(ppsz_options, i_options);
1792 CoTaskMemFree(psz_uri);
1793 if( psz_name )
1794 CoTaskMemFree(psz_name);
1795 if( libvlc_exception_raised(&ex) )
1797 _p_instance->setErrorInfo(IID_IVLCPlaylist,
1798 libvlc_exception_get_message(&ex));
1799 libvlc_exception_clear(&ex);
1800 return E_FAIL;
1802 return NOERROR;
1804 return hr;
1807 STDMETHODIMP VLCPlaylist::play()
1809 libvlc_instance_t* p_libvlc;
1810 HRESULT hr = _p_instance->getVLC(&p_libvlc);
1811 if( SUCCEEDED(hr) )
1813 libvlc_exception_t ex;
1814 libvlc_exception_init(&ex);
1816 libvlc_playlist_play(p_libvlc, -1, 0, NULL, &ex);
1817 if( libvlc_exception_raised(&ex) )
1819 libvlc_exception_clear(&ex);
1820 return E_FAIL;
1822 return NOERROR;
1824 return hr;
1827 STDMETHODIMP VLCPlaylist::playItem(long item)
1829 libvlc_instance_t* p_libvlc;
1830 HRESULT hr = _p_instance->getVLC(&p_libvlc);
1831 if( SUCCEEDED(hr) )
1833 libvlc_exception_t ex;
1834 libvlc_exception_init(&ex);
1836 libvlc_playlist_play(p_libvlc, item, 0, NULL, &ex);
1837 if( libvlc_exception_raised(&ex) )
1839 _p_instance->setErrorInfo(IID_IVLCPlaylist,
1840 libvlc_exception_get_message(&ex));
1841 libvlc_exception_clear(&ex);
1842 return E_FAIL;
1844 return NOERROR;
1846 return hr;
1849 STDMETHODIMP VLCPlaylist::togglePause()
1851 libvlc_instance_t* p_libvlc;
1852 HRESULT hr = _p_instance->getVLC(&p_libvlc);
1853 if( SUCCEEDED(hr) )
1855 libvlc_exception_t ex;
1856 libvlc_exception_init(&ex);
1858 libvlc_playlist_pause(p_libvlc, &ex);
1859 if( libvlc_exception_raised(&ex) )
1861 _p_instance->setErrorInfo(IID_IVLCPlaylist,
1862 libvlc_exception_get_message(&ex));
1863 libvlc_exception_clear(&ex);
1864 return E_FAIL;
1866 return NOERROR;
1868 return hr;
1871 STDMETHODIMP VLCPlaylist::stop()
1873 libvlc_instance_t* p_libvlc;
1874 HRESULT hr = _p_instance->getVLC(&p_libvlc);
1875 if( SUCCEEDED(hr) )
1877 libvlc_exception_t ex;
1878 libvlc_exception_init(&ex);
1880 libvlc_playlist_stop(p_libvlc, &ex);
1881 if( libvlc_exception_raised(&ex) )
1883 _p_instance->setErrorInfo(IID_IVLCPlaylist,
1884 libvlc_exception_get_message(&ex));
1885 libvlc_exception_clear(&ex);
1886 return E_FAIL;
1888 return NOERROR;
1890 return hr;
1893 STDMETHODIMP VLCPlaylist::next()
1895 libvlc_instance_t* p_libvlc;
1896 HRESULT hr = _p_instance->getVLC(&p_libvlc);
1897 if( SUCCEEDED(hr) )
1899 libvlc_exception_t ex;
1900 libvlc_exception_init(&ex);
1902 libvlc_playlist_next(p_libvlc, &ex);
1903 if( libvlc_exception_raised(&ex) )
1905 _p_instance->setErrorInfo(IID_IVLCPlaylist,
1906 libvlc_exception_get_message(&ex));
1907 libvlc_exception_clear(&ex);
1908 return E_FAIL;
1910 return NOERROR;
1912 return hr;
1915 STDMETHODIMP VLCPlaylist::prev()
1917 libvlc_instance_t* p_libvlc;
1918 HRESULT hr = _p_instance->getVLC(&p_libvlc);
1919 if( SUCCEEDED(hr) )
1921 libvlc_exception_t ex;
1922 libvlc_exception_init(&ex);
1924 libvlc_playlist_prev(p_libvlc, &ex);
1925 if( libvlc_exception_raised(&ex) )
1927 _p_instance->setErrorInfo(IID_IVLCPlaylist,
1928 libvlc_exception_get_message(&ex));
1929 libvlc_exception_clear(&ex);
1930 return E_FAIL;
1932 return NOERROR;
1934 return hr;
1937 STDMETHODIMP VLCPlaylist::clear()
1939 libvlc_instance_t* p_libvlc;
1940 HRESULT hr = _p_instance->getVLC(&p_libvlc);
1941 if( SUCCEEDED(hr) )
1943 libvlc_exception_t ex;
1944 libvlc_exception_init(&ex);
1946 libvlc_playlist_clear(p_libvlc, &ex);
1947 if( libvlc_exception_raised(&ex) )
1949 _p_instance->setErrorInfo(IID_IVLCPlaylist,
1950 libvlc_exception_get_message(&ex));
1951 libvlc_exception_clear(&ex);
1952 return E_FAIL;
1954 return NOERROR;
1956 return hr;
1959 STDMETHODIMP VLCPlaylist::removeItem(long item)
1961 libvlc_instance_t* p_libvlc;
1962 HRESULT hr = _p_instance->getVLC(&p_libvlc);
1963 if( SUCCEEDED(hr) )
1965 libvlc_exception_t ex;
1966 libvlc_exception_init(&ex);
1968 libvlc_playlist_delete_item(p_libvlc, item, &ex);
1969 if( libvlc_exception_raised(&ex) )
1971 _p_instance->setErrorInfo(IID_IVLCPlaylist,
1972 libvlc_exception_get_message(&ex));
1973 libvlc_exception_clear(&ex);
1974 return E_FAIL;
1976 return NOERROR;
1978 return hr;
1981 STDMETHODIMP VLCPlaylist::get_items(IVLCPlaylistItems** obj)
1983 if( NULL == obj )
1984 return E_POINTER;
1986 *obj = _p_vlcplaylistitems;
1987 if( NULL != _p_vlcplaylistitems )
1989 _p_vlcplaylistitems->AddRef();
1990 return NOERROR;
1992 return E_OUTOFMEMORY;
1995 /*******************************************************************************/
1997 VLCVideo::~VLCVideo()
1999 if( _p_typeinfo )
2000 _p_typeinfo->Release();
2003 HRESULT VLCVideo::loadTypeInfo(void)
2005 HRESULT hr = NOERROR;
2006 if( NULL == _p_typeinfo )
2008 ITypeLib *p_typelib;
2010 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
2011 if( SUCCEEDED(hr) )
2013 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCVideo, &_p_typeinfo);
2014 if( FAILED(hr) )
2016 _p_typeinfo = NULL;
2018 p_typelib->Release();
2021 return hr;
2024 STDMETHODIMP VLCVideo::GetTypeInfoCount(UINT* pctInfo)
2026 if( NULL == pctInfo )
2027 return E_INVALIDARG;
2029 if( SUCCEEDED(loadTypeInfo()) )
2030 *pctInfo = 1;
2031 else
2032 *pctInfo = 0;
2034 return NOERROR;
2037 STDMETHODIMP VLCVideo::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
2039 if( NULL == ppTInfo )
2040 return E_INVALIDARG;
2042 if( SUCCEEDED(loadTypeInfo()) )
2044 _p_typeinfo->AddRef();
2045 *ppTInfo = _p_typeinfo;
2046 return NOERROR;
2048 *ppTInfo = NULL;
2049 return E_NOTIMPL;
2052 STDMETHODIMP VLCVideo::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
2053 UINT cNames, LCID lcid, DISPID* rgDispID)
2055 if( SUCCEEDED(loadTypeInfo()) )
2057 return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
2059 return E_NOTIMPL;
2062 STDMETHODIMP VLCVideo::Invoke(DISPID dispIdMember, REFIID riid,
2063 LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
2064 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
2066 if( SUCCEEDED(loadTypeInfo()) )
2068 return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
2069 pVarResult, pExcepInfo, puArgErr);
2071 return E_NOTIMPL;
2074 STDMETHODIMP VLCVideo::get_fullscreen(VARIANT_BOOL* fullscreen)
2076 if( NULL == fullscreen )
2077 return E_POINTER;
2079 libvlc_instance_t* p_libvlc;
2080 HRESULT hr = _p_instance->getVLC(&p_libvlc);
2081 if( SUCCEEDED(hr) )
2083 libvlc_exception_t ex;
2084 libvlc_exception_init(&ex);
2086 libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_libvlc, &ex);
2087 if( ! libvlc_exception_raised(&ex) )
2089 *fullscreen = libvlc_get_fullscreen(p_md, &ex) ? VARIANT_TRUE : VARIANT_FALSE;
2090 libvlc_media_player_release(p_md);
2091 if( ! libvlc_exception_raised(&ex) )
2093 return NOERROR;
2096 _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
2097 libvlc_exception_clear(&ex);
2098 return E_FAIL;
2100 return hr;
2103 STDMETHODIMP VLCVideo::put_fullscreen(VARIANT_BOOL fullscreen)
2105 libvlc_instance_t* p_libvlc;
2106 HRESULT hr = _p_instance->getVLC(&p_libvlc);
2107 if( SUCCEEDED(hr) )
2109 libvlc_exception_t ex;
2110 libvlc_exception_init(&ex);
2112 libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_libvlc, &ex);
2113 if( ! libvlc_exception_raised(&ex) )
2115 libvlc_set_fullscreen(p_md, VARIANT_FALSE != fullscreen, &ex);
2116 libvlc_media_player_release(p_md);
2117 if( ! libvlc_exception_raised(&ex) )
2119 return NOERROR;
2122 _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
2123 libvlc_exception_clear(&ex);
2124 return E_FAIL;
2126 return hr;
2129 STDMETHODIMP VLCVideo::get_width(long* width)
2131 if( NULL == width )
2132 return E_POINTER;
2134 libvlc_instance_t* p_libvlc;
2135 HRESULT hr = _p_instance->getVLC(&p_libvlc);
2136 if( SUCCEEDED(hr) )
2138 libvlc_exception_t ex;
2139 libvlc_exception_init(&ex);
2141 libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_libvlc, &ex);
2142 if( ! libvlc_exception_raised(&ex) )
2144 *width = libvlc_video_get_width(p_md, &ex);
2145 libvlc_media_player_release(p_md);
2146 if( ! libvlc_exception_raised(&ex) )
2148 return NOERROR;
2151 _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
2152 libvlc_exception_clear(&ex);
2153 return E_FAIL;
2155 return hr;
2158 STDMETHODIMP VLCVideo::get_height(long* height)
2160 if( NULL == height )
2161 return E_POINTER;
2163 libvlc_instance_t* p_libvlc;
2164 HRESULT hr = _p_instance->getVLC(&p_libvlc);
2165 if( SUCCEEDED(hr) )
2167 libvlc_exception_t ex;
2168 libvlc_exception_init(&ex);
2170 libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_libvlc, &ex);
2171 if( ! libvlc_exception_raised(&ex) )
2173 *height = libvlc_video_get_height(p_md, &ex);
2174 libvlc_media_player_release(p_md);
2175 if( ! libvlc_exception_raised(&ex) )
2177 return NOERROR;
2180 _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
2181 libvlc_exception_clear(&ex);
2182 return E_FAIL;
2184 return hr;
2187 STDMETHODIMP VLCVideo::get_aspectRatio(BSTR* aspect)
2189 if( NULL == aspect )
2190 return E_POINTER;
2192 libvlc_instance_t* p_libvlc;
2193 HRESULT hr = _p_instance->getVLC(&p_libvlc);
2194 if( SUCCEEDED(hr) )
2196 libvlc_exception_t ex;
2197 libvlc_exception_init(&ex);
2199 libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_libvlc, &ex);
2200 if( ! libvlc_exception_raised(&ex) )
2202 char *psz_aspect = libvlc_video_get_aspect_ratio(p_md, &ex);
2204 libvlc_media_player_release(p_md);
2205 if( ! libvlc_exception_raised(&ex) )
2207 if( NULL == psz_aspect )
2208 return E_OUTOFMEMORY;
2210 *aspect = BSTRFromCStr(CP_UTF8, psz_aspect);
2211 free( psz_aspect );
2212 psz_aspect = NULL;
2213 return (NULL == *aspect) ? E_OUTOFMEMORY : NOERROR;
2215 free( psz_aspect );
2216 psz_aspect = NULL;
2218 _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
2219 libvlc_exception_clear(&ex);
2220 return E_FAIL;
2222 return hr;
2225 STDMETHODIMP VLCVideo::put_aspectRatio(BSTR aspect)
2227 if( NULL == aspect )
2228 return E_POINTER;
2230 if( 0 == SysStringLen(aspect) )
2231 return E_INVALIDARG;
2233 libvlc_instance_t* p_libvlc;
2234 HRESULT hr = _p_instance->getVLC(&p_libvlc);
2235 if( SUCCEEDED(hr) )
2237 libvlc_exception_t ex;
2238 libvlc_exception_init(&ex);
2240 libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_libvlc, &ex);
2241 if( ! libvlc_exception_raised(&ex) )
2243 char *psz_aspect = CStrFromBSTR(CP_UTF8, aspect);
2244 if( NULL == psz_aspect )
2246 return E_OUTOFMEMORY;
2249 libvlc_video_set_aspect_ratio(p_md, psz_aspect, &ex);
2251 CoTaskMemFree(psz_aspect);
2252 libvlc_media_player_release(p_md);
2253 if( libvlc_exception_raised(&ex) )
2255 _p_instance->setErrorInfo(IID_IVLCVideo,
2256 libvlc_exception_get_message(&ex));
2257 libvlc_exception_clear(&ex);
2258 return E_FAIL;
2261 return NOERROR;
2263 return hr;
2266 STDMETHODIMP VLCVideo::get_subtitle(long* spu)
2268 if( NULL == spu )
2269 return E_POINTER;
2271 libvlc_instance_t* p_libvlc;
2272 HRESULT hr = _p_instance->getVLC(&p_libvlc);
2273 if( SUCCEEDED(hr) )
2275 libvlc_exception_t ex;
2276 libvlc_exception_init(&ex);
2278 libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_libvlc, &ex);
2279 if( ! libvlc_exception_raised(&ex) )
2281 *spu = libvlc_video_get_spu(p_md, &ex);
2282 libvlc_media_player_release(p_md);
2283 if( ! libvlc_exception_raised(&ex) )
2285 return NOERROR;
2288 _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
2289 libvlc_exception_clear(&ex);
2290 return E_FAIL;
2292 return hr;
2295 STDMETHODIMP VLCVideo::put_subtitle(long spu)
2297 libvlc_instance_t* p_libvlc;
2298 HRESULT hr = _p_instance->getVLC(&p_libvlc);
2299 if( SUCCEEDED(hr) )
2301 libvlc_exception_t ex;
2302 libvlc_exception_init(&ex);
2304 libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_libvlc, &ex);
2305 libvlc_video_set_spu(p_md, spu, &ex);
2306 libvlc_media_player_release(p_md);
2307 if( libvlc_exception_raised(&ex) )
2309 _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
2310 libvlc_exception_clear(&ex);
2311 return E_FAIL;
2313 return NOERROR;
2315 return hr;
2318 STDMETHODIMP VLCVideo::get_crop(BSTR* geometry)
2320 if( NULL == geometry )
2321 return E_POINTER;
2323 libvlc_instance_t* p_libvlc;
2324 HRESULT hr = _p_instance->getVLC(&p_libvlc);
2325 if( SUCCEEDED(hr) )
2327 libvlc_exception_t ex;
2328 libvlc_exception_init(&ex);
2330 libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_libvlc, &ex);
2331 if( ! libvlc_exception_raised(&ex) )
2333 char *psz_geometry = libvlc_video_get_crop_geometry(p_md, &ex);
2335 libvlc_media_player_release(p_md);
2336 if( ! libvlc_exception_raised(&ex) )
2338 if( NULL == psz_geometry )
2339 return E_OUTOFMEMORY;
2341 *geometry = BSTRFromCStr(CP_UTF8, psz_geometry);
2342 free( psz_geometry );
2343 psz_geometry = NULL;
2344 return (NULL == geometry) ? E_OUTOFMEMORY : NOERROR;
2346 free( psz_geometry );
2347 psz_geometry = NULL;
2349 _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
2350 libvlc_exception_clear(&ex);
2351 return E_FAIL;
2353 return hr;
2356 STDMETHODIMP VLCVideo::put_crop(BSTR geometry)
2358 if( NULL == geometry )
2359 return E_POINTER;
2361 if( 0 == SysStringLen(geometry) )
2362 return E_INVALIDARG;
2364 libvlc_instance_t* p_libvlc;
2365 HRESULT hr = _p_instance->getVLC(&p_libvlc);
2366 if( SUCCEEDED(hr) )
2368 libvlc_exception_t ex;
2369 libvlc_exception_init(&ex);
2371 libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_libvlc, &ex);
2372 if( ! libvlc_exception_raised(&ex) )
2374 char *psz_geometry = CStrFromBSTR(CP_UTF8, geometry);
2375 if( NULL == psz_geometry )
2377 return E_OUTOFMEMORY;
2380 libvlc_video_set_crop_geometry(p_md, psz_geometry, &ex);
2382 CoTaskMemFree(psz_geometry);
2383 libvlc_media_player_release(p_md);
2384 if( libvlc_exception_raised(&ex) )
2386 _p_instance->setErrorInfo(IID_IVLCVideo,
2387 libvlc_exception_get_message(&ex));
2388 libvlc_exception_clear(&ex);
2389 return E_FAIL;
2392 return NOERROR;
2394 return hr;
2397 STDMETHODIMP VLCVideo::get_teletext(long* page)
2399 if( NULL == page )
2400 return E_POINTER;
2402 libvlc_instance_t* p_libvlc;
2403 HRESULT hr = _p_instance->getVLC(&p_libvlc);
2404 if( SUCCEEDED(hr) )
2406 libvlc_exception_t ex;
2407 libvlc_exception_init(&ex);
2409 libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_libvlc, &ex);
2410 if( ! libvlc_exception_raised(&ex) )
2412 *page = libvlc_video_get_teletext(p_md, &ex);
2413 libvlc_media_player_release(p_md);
2414 if( ! libvlc_exception_raised(&ex) )
2416 return NOERROR;
2419 _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
2420 libvlc_exception_clear(&ex);
2421 return E_FAIL;
2423 return hr;
2426 STDMETHODIMP VLCVideo::put_teletext(long page)
2428 libvlc_instance_t* p_libvlc;
2429 HRESULT hr = _p_instance->getVLC(&p_libvlc);
2430 if( SUCCEEDED(hr) )
2432 libvlc_exception_t ex;
2433 libvlc_exception_init(&ex);
2435 libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_libvlc, &ex);
2436 libvlc_video_set_teletext(p_md, page, &ex);
2437 libvlc_media_player_release(p_md);
2438 if( libvlc_exception_raised(&ex) )
2440 _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
2441 libvlc_exception_clear(&ex);
2442 return E_FAIL;
2444 return NOERROR;
2446 return hr;
2449 STDMETHODIMP VLCVideo::takeSnapshot(LPPICTUREDISP* picture)
2451 if( NULL == picture )
2452 return E_POINTER;
2454 libvlc_instance_t* p_libvlc;
2455 HRESULT hr = _p_instance->getVLC(&p_libvlc);
2456 if( SUCCEEDED(hr) )
2458 libvlc_exception_t ex;
2459 libvlc_exception_init(&ex);
2461 libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_libvlc, &ex);
2462 if( ! libvlc_exception_raised(&ex) )
2464 static int uniqueId = 0;
2465 TCHAR path[MAX_PATH+1];
2467 int pathlen = GetTempPath(MAX_PATH-24, path);
2468 if( (0 == pathlen) || (pathlen > (MAX_PATH-24)) )
2469 return E_FAIL;
2471 /* check temp directory path by openning it */
2473 HANDLE dirHandle = CreateFile(path,
2474 GENERIC_READ,
2475 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
2476 NULL,
2477 OPEN_EXISTING,
2478 FILE_FLAG_BACKUP_SEMANTICS, NULL);
2479 if( INVALID_HANDLE_VALUE == dirHandle )
2481 _p_instance->setErrorInfo(IID_IVLCVideo,
2482 "Invalid temporary directory for snapshot images, check values of TMP, TEMP envars.");
2483 return E_FAIL;
2485 else
2487 BY_HANDLE_FILE_INFORMATION bhfi;
2488 BOOL res = GetFileInformationByHandle(dirHandle, &bhfi);
2489 CloseHandle(dirHandle);
2490 if( !res || !(bhfi.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) )
2492 _p_instance->setErrorInfo(IID_IVLCVideo,
2493 "Invalid temporary directory for snapshot images, check values of TMP, TEMP envars.");
2494 return E_FAIL;
2499 TCHAR filepath[MAX_PATH+1];
2501 _stprintf(filepath, TEXT("%sAXVLC%lXS%lX.bmp"),
2502 path, GetCurrentProcessId(), ++uniqueId);
2504 #ifdef _UNICODE
2505 /* reuse path storage for UTF8 string */
2506 char *psz_filepath = (char *)path;
2507 WCHAR* wpath = filepath;
2508 #else
2509 char *psz_filepath = path;
2510 /* first convert to unicode using current code page */
2511 WCHAR wpath[MAX_PATH+1];
2512 if( 0 == MultiByteToWideChar(CP_ACP, 0, filepath, -1, wpath, sizeof(wpath)/sizeof(WCHAR)) )
2513 return E_FAIL;
2514 #endif
2515 /* convert to UTF8 */
2516 pathlen = WideCharToMultiByte(CP_UTF8, 0, wpath, -1, psz_filepath, sizeof(path), NULL, NULL);
2517 // fail if path is 0 or too short (i.e pathlen is the same as storage size)
2518 if( (0 == pathlen) || (sizeof(path) == pathlen) )
2519 return E_FAIL;
2521 /* take snapshot into file */
2522 libvlc_video_take_snapshot(p_md, psz_filepath, 0, 0, &ex);
2523 libvlc_media_player_release(p_md);
2524 if( ! libvlc_exception_raised(&ex) )
2526 hr = E_FAIL;
2527 /* open snapshot file */
2528 HANDLE snapPic = LoadImage(NULL, filepath, IMAGE_BITMAP,0, 0, LR_CREATEDIBSECTION|LR_LOADFROMFILE);
2529 if( snapPic )
2531 PICTDESC snapDesc;
2533 snapDesc.cbSizeofstruct = sizeof(PICTDESC);
2534 snapDesc.picType = PICTYPE_BITMAP;
2535 snapDesc.bmp.hbitmap = (HBITMAP)snapPic;
2536 snapDesc.bmp.hpal = NULL;
2538 hr = OleCreatePictureIndirect(&snapDesc, IID_IPictureDisp, TRUE, (LPVOID*)picture);
2539 if( FAILED(hr) )
2541 *picture = NULL;
2542 DeleteObject(snapPic);
2545 DeleteFile(filepath);
2546 return hr;
2549 _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
2550 libvlc_exception_clear(&ex);
2551 return E_FAIL;
2553 return hr;
2556 STDMETHODIMP VLCVideo::toggleFullscreen()
2558 libvlc_instance_t* p_libvlc;
2559 HRESULT hr = _p_instance->getVLC(&p_libvlc);
2560 if( SUCCEEDED(hr) )
2562 libvlc_exception_t ex;
2563 libvlc_exception_init(&ex);
2565 libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_libvlc, &ex);
2566 if( ! libvlc_exception_raised(&ex) )
2568 libvlc_toggle_fullscreen(p_md, &ex);
2569 libvlc_media_player_release(p_md);
2570 if( ! libvlc_exception_raised(&ex) )
2572 return NOERROR;
2575 _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
2576 libvlc_exception_clear(&ex);
2577 return E_FAIL;
2579 return hr;
2582 STDMETHODIMP VLCVideo::toggleTeletext()
2584 libvlc_instance_t* p_libvlc;
2585 HRESULT hr = _p_instance->getVLC(&p_libvlc);
2586 if( SUCCEEDED(hr) )
2588 libvlc_exception_t ex;
2589 libvlc_exception_init(&ex);
2591 libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_libvlc, &ex);
2592 if( ! libvlc_exception_raised(&ex) )
2594 libvlc_toggle_teletext(p_md, &ex);
2595 libvlc_media_player_release(p_md);
2596 if( ! libvlc_exception_raised(&ex) )
2598 return NOERROR;
2601 _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
2602 libvlc_exception_clear(&ex);
2603 return E_FAIL;
2605 return hr;
2608 /*******************************************************************************/
2610 VLCControl2::VLCControl2(VLCPlugin *p_instance) :
2611 _p_instance(p_instance),
2612 _p_typeinfo(NULL),
2613 _p_vlcaudio(NULL),
2614 _p_vlcinput(NULL),
2615 _p_vlcplaylist(NULL),
2616 _p_vlcvideo(NULL)
2618 _p_vlcaudio = new VLCAudio(p_instance);
2619 _p_vlcinput = new VLCInput(p_instance);
2620 _p_vlclog = new VLCLog(p_instance);
2621 _p_vlcplaylist = new VLCPlaylist(p_instance);
2622 _p_vlcvideo = new VLCVideo(p_instance);
2625 VLCControl2::~VLCControl2()
2627 delete _p_vlcvideo;
2628 delete _p_vlcplaylist;
2629 delete _p_vlclog;
2630 delete _p_vlcinput;
2631 delete _p_vlcaudio;
2632 if( _p_typeinfo )
2633 _p_typeinfo->Release();
2636 HRESULT VLCControl2::loadTypeInfo(void)
2638 HRESULT hr = NOERROR;
2639 if( NULL == _p_typeinfo )
2641 ITypeLib *p_typelib;
2643 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
2644 if( SUCCEEDED(hr) )
2646 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCControl2, &_p_typeinfo);
2647 if( FAILED(hr) )
2649 _p_typeinfo = NULL;
2651 p_typelib->Release();
2654 return hr;
2657 STDMETHODIMP VLCControl2::GetTypeInfoCount(UINT* pctInfo)
2659 if( NULL == pctInfo )
2660 return E_INVALIDARG;
2662 if( SUCCEEDED(loadTypeInfo()) )
2663 *pctInfo = 1;
2664 else
2665 *pctInfo = 0;
2667 return NOERROR;
2670 STDMETHODIMP VLCControl2::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
2672 if( NULL == ppTInfo )
2673 return E_INVALIDARG;
2675 if( SUCCEEDED(loadTypeInfo()) )
2677 _p_typeinfo->AddRef();
2678 *ppTInfo = _p_typeinfo;
2679 return NOERROR;
2681 *ppTInfo = NULL;
2682 return E_NOTIMPL;
2685 STDMETHODIMP VLCControl2::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
2686 UINT cNames, LCID lcid, DISPID* rgDispID)
2688 if( SUCCEEDED(loadTypeInfo()) )
2690 return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
2692 return E_NOTIMPL;
2695 STDMETHODIMP VLCControl2::Invoke(DISPID dispIdMember, REFIID riid,
2696 LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
2697 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
2699 if( SUCCEEDED(loadTypeInfo()) )
2701 return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
2702 pVarResult, pExcepInfo, puArgErr);
2704 return E_NOTIMPL;
2707 STDMETHODIMP VLCControl2::get_AutoLoop(VARIANT_BOOL *autoloop)
2709 if( NULL == autoloop )
2710 return E_POINTER;
2712 *autoloop = _p_instance->getAutoLoop() ? VARIANT_TRUE: VARIANT_FALSE;
2713 return S_OK;
2716 STDMETHODIMP VLCControl2::put_AutoLoop(VARIANT_BOOL autoloop)
2718 _p_instance->setAutoLoop((VARIANT_FALSE != autoloop) ? TRUE: FALSE);
2719 return S_OK;
2722 STDMETHODIMP VLCControl2::get_AutoPlay(VARIANT_BOOL *autoplay)
2724 if( NULL == autoplay )
2725 return E_POINTER;
2727 *autoplay = _p_instance->getAutoPlay() ? VARIANT_TRUE: VARIANT_FALSE;
2728 return S_OK;
2731 STDMETHODIMP VLCControl2::put_AutoPlay(VARIANT_BOOL autoplay)
2733 _p_instance->setAutoPlay((VARIANT_FALSE != autoplay) ? TRUE: FALSE);
2734 return S_OK;
2737 STDMETHODIMP VLCControl2::get_BaseURL(BSTR *url)
2739 if( NULL == url )
2740 return E_POINTER;
2742 *url = SysAllocStringLen(_p_instance->getBaseURL(),
2743 SysStringLen(_p_instance->getBaseURL()));
2744 return NOERROR;
2747 STDMETHODIMP VLCControl2::put_BaseURL(BSTR mrl)
2749 _p_instance->setBaseURL(mrl);
2751 return S_OK;
2754 STDMETHODIMP VLCControl2::get_MRL(BSTR *mrl)
2756 if( NULL == mrl )
2757 return E_POINTER;
2759 *mrl = SysAllocStringLen(_p_instance->getMRL(),
2760 SysStringLen(_p_instance->getMRL()));
2761 return NOERROR;
2764 STDMETHODIMP VLCControl2::put_MRL(BSTR mrl)
2766 _p_instance->setMRL(mrl);
2768 return S_OK;
2772 STDMETHODIMP VLCControl2::get_Toolbar(VARIANT_BOOL *visible)
2774 if( NULL == visible )
2775 return E_POINTER;
2778 * Note to developpers
2780 * Returning the _b_toolbar is closer to the method specification.
2781 * But returning True when toolbar is not implemented so not displayed
2782 * could be bad for ActiveX users which rely on this value to show their
2783 * own toolbar if not provided by the ActiveX.
2785 * This is the reason why FALSE is returned, until toolbar get implemented.
2788 /* DISABLED for now */
2789 // *visible = _p_instance->getShowToolbar() ? VARIANT_TRUE: VARIANT_FALSE;
2791 *visible = VARIANT_FALSE;
2793 return S_OK;
2796 STDMETHODIMP VLCControl2::put_Toolbar(VARIANT_BOOL visible)
2798 _p_instance->setShowToolbar((VARIANT_FALSE != visible) ? TRUE: FALSE);
2799 return S_OK;
2803 STDMETHODIMP VLCControl2::get_StartTime(long *seconds)
2805 if( NULL == seconds )
2806 return E_POINTER;
2808 *seconds = _p_instance->getStartTime();
2810 return S_OK;
2813 STDMETHODIMP VLCControl2::put_StartTime(long seconds)
2815 _p_instance->setStartTime(seconds);
2817 return NOERROR;
2820 STDMETHODIMP VLCControl2::get_VersionInfo(BSTR *version)
2822 if( NULL == version )
2823 return E_POINTER;
2825 const char *versionStr = libvlc_get_version();
2826 if( NULL != versionStr )
2828 *version = BSTRFromCStr(CP_UTF8, versionStr);
2830 return (NULL == *version) ? E_OUTOFMEMORY : NOERROR;
2832 *version = NULL;
2833 return E_FAIL;
2836 STDMETHODIMP VLCControl2::get_Visible(VARIANT_BOOL *isVisible)
2838 if( NULL == isVisible )
2839 return E_POINTER;
2841 *isVisible = _p_instance->getVisible() ? VARIANT_TRUE : VARIANT_FALSE;
2843 return NOERROR;
2846 STDMETHODIMP VLCControl2::put_Visible(VARIANT_BOOL isVisible)
2848 _p_instance->setVisible(isVisible != VARIANT_FALSE);
2850 return NOERROR;
2853 STDMETHODIMP VLCControl2::get_Volume(long *volume)
2855 if( NULL == volume )
2856 return E_POINTER;
2858 *volume = _p_instance->getVolume();
2859 return NOERROR;
2862 STDMETHODIMP VLCControl2::put_Volume(long volume)
2864 _p_instance->setVolume(volume);
2865 return NOERROR;
2868 STDMETHODIMP VLCControl2::get_BackColor(OLE_COLOR *backcolor)
2870 if( NULL == backcolor )
2871 return E_POINTER;
2873 *backcolor = _p_instance->getBackColor();
2874 return NOERROR;
2877 STDMETHODIMP VLCControl2::put_BackColor(OLE_COLOR backcolor)
2879 _p_instance->setBackColor(backcolor);
2880 return NOERROR;
2883 STDMETHODIMP VLCControl2::get_audio(IVLCAudio** obj)
2885 if( NULL == obj )
2886 return E_POINTER;
2888 *obj = _p_vlcaudio;
2889 if( NULL != _p_vlcaudio )
2891 _p_vlcaudio->AddRef();
2892 return NOERROR;
2894 return E_OUTOFMEMORY;
2897 STDMETHODIMP VLCControl2::get_input(IVLCInput** obj)
2899 if( NULL == obj )
2900 return E_POINTER;
2902 *obj = _p_vlcinput;
2903 if( NULL != _p_vlcinput )
2905 _p_vlcinput->AddRef();
2906 return NOERROR;
2908 return E_OUTOFMEMORY;
2911 STDMETHODIMP VLCControl2::get_log(IVLCLog** obj)
2913 if( NULL == obj )
2914 return E_POINTER;
2916 *obj = _p_vlclog;
2917 if( NULL != _p_vlclog )
2919 _p_vlclog->AddRef();
2920 return NOERROR;
2922 return E_OUTOFMEMORY;
2925 STDMETHODIMP VLCControl2::get_playlist(IVLCPlaylist** obj)
2927 if( NULL == obj )
2928 return E_POINTER;
2930 *obj = _p_vlcplaylist;
2931 if( NULL != _p_vlcplaylist )
2933 _p_vlcplaylist->AddRef();
2934 return NOERROR;
2936 return E_OUTOFMEMORY;
2939 STDMETHODIMP VLCControl2::get_video(IVLCVideo** obj)
2941 if( NULL == obj )
2942 return E_POINTER;
2944 *obj = _p_vlcvideo;
2945 if( NULL != _p_vlcvideo )
2947 _p_vlcvideo->AddRef();
2948 return NOERROR;
2950 return E_OUTOFMEMORY;