1 /*****************************************************************************
2 * plugin.cpp: ActiveX control for VLC
3 *****************************************************************************
4 * Copyright (C) 2006-2010 the VideoLAN team
6 * Authors: Damien Fouilleul <Damien.Fouilleul@laposte.net>
7 * Jean-Paul Saman <jpsaman@videolan.org>
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 *****************************************************************************/
26 #include "oleobject.h"
27 #include "olecontrol.h"
28 #include "oleinplaceobject.h"
29 #include "oleinplaceactiveobject.h"
30 #include "persistpropbag.h"
31 #include "persiststreaminit.h"
32 #include "persiststorage.h"
33 #include "provideclassinfo.h"
34 #include "connectioncontainer.h"
35 #include "objectsafety.h"
36 #include "vlccontrol.h"
37 #include "vlccontrol2.h"
38 #include "viewobject.h"
39 #include "dataobject.h"
40 #include "supporterrorinfo.h"
55 ////////////////////////////////////////////////////////////////////////
58 static LRESULT CALLBACK VLCInPlaceClassWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
59 VLCPlugin *p_instance = reinterpret_cast<VLCPlugin *>(GetWindowLongPtr(hWnd, GWLP_USERDATA));
69 if( GetUpdateRect(hWnd, &pr, FALSE) )
72 GetClientRect(hWnd, &bounds);
73 BeginPaint(hWnd, &ps);
74 p_instance->onPaint(ps.hdc, bounds, pr);
80 return DefWindowProc(hWnd, uMsg, wParam, lParam);
84 VLCPluginClass::VLCPluginClass(LONG *p_class_ref, HINSTANCE hInstance, REFCLSID rclsid) :
85 _p_class_ref(p_class_ref),
86 _hinstance(hInstance),
88 _inplace_picture(NULL)
92 if( ! GetClassInfo(hInstance, getInPlaceWndClassName(), &wClass) )
94 wClass.style = CS_NOCLOSE|CS_DBLCLKS;
95 wClass.lpfnWndProc = VLCInPlaceClassWndProc;
96 wClass.cbClsExtra = 0;
97 wClass.cbWndExtra = 0;
98 wClass.hInstance = hInstance;
100 wClass.hCursor = LoadCursor(NULL, IDC_ARROW);
101 wClass.hbrBackground = NULL;
102 wClass.lpszMenuName = NULL;
103 wClass.lpszClassName = getInPlaceWndClassName();
105 _inplace_wndclass_atom = RegisterClass(&wClass);
109 _inplace_wndclass_atom = 0;
112 HBITMAP hbitmap = (HBITMAP)LoadImage(getHInstance(), MAKEINTRESOURCE(2), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR);
113 if( NULL != hbitmap )
117 pictDesc.cbSizeofstruct = sizeof(PICTDESC);
118 pictDesc.picType = PICTYPE_BITMAP;
119 pictDesc.bmp.hbitmap = hbitmap;
120 pictDesc.bmp.hpal = NULL;
122 if( FAILED(OleCreatePictureIndirect(&pictDesc, IID_IPicture, TRUE, reinterpret_cast<LPVOID*>(&_inplace_picture))) )
123 _inplace_picture = NULL;
128 VLCPluginClass::~VLCPluginClass()
130 if( 0 != _inplace_wndclass_atom )
131 UnregisterClass(MAKEINTATOM(_inplace_wndclass_atom), _hinstance);
133 if( NULL != _inplace_picture )
134 _inplace_picture->Release();
137 STDMETHODIMP VLCPluginClass::QueryInterface(REFIID riid, void **ppv)
142 if( (IID_IUnknown == riid)
143 || (IID_IClassFactory == riid) )
146 *ppv = reinterpret_cast<LPVOID>(this);
153 return E_NOINTERFACE;
156 STDMETHODIMP_(ULONG) VLCPluginClass::AddRef(void)
158 return InterlockedIncrement(_p_class_ref);
161 STDMETHODIMP_(ULONG) VLCPluginClass::Release(void)
163 ULONG refcount = InterlockedDecrement(_p_class_ref);
172 STDMETHODIMP VLCPluginClass::CreateInstance(LPUNKNOWN pUnkOuter, REFIID riid, void **ppv)
179 if( (NULL != pUnkOuter) && (IID_IUnknown != riid) ) {
180 return CLASS_E_NOAGGREGATION;
183 VLCPlugin *plugin = new VLCPlugin(this, pUnkOuter);
186 HRESULT hr = plugin->QueryInterface(riid, ppv);
187 // the following will destroy the object if QueryInterface() failed
191 return E_OUTOFMEMORY;
194 STDMETHODIMP VLCPluginClass::LockServer(BOOL fLock)
204 ////////////////////////////////////////////////////////////////////////
206 VLCPlugin::VLCPlugin(VLCPluginClass *p_class, LPUNKNOWN pUnkOuter) :
218 ** bump refcount to avoid recursive release from
219 ** following interfaces when releasing this interface
224 vlcOleControl = new VLCOleControl(this);
225 vlcOleInPlaceObject = new VLCOleInPlaceObject(this);
226 vlcOleInPlaceActiveObject = new VLCOleInPlaceActiveObject(this);
227 vlcPersistStorage = new VLCPersistStorage(this);
228 vlcPersistStreamInit = new VLCPersistStreamInit(this);
229 vlcPersistPropertyBag = new VLCPersistPropertyBag(this);
230 vlcProvideClassInfo = new VLCProvideClassInfo(this);
231 vlcConnectionPointContainer = new VLCConnectionPointContainer(this);
232 vlcObjectSafety = new VLCObjectSafety(this);
233 vlcControl = new VLCControl(this);
234 vlcControl2 = new VLCControl2(this);
235 vlcViewObject = new VLCViewObject(this);
236 vlcDataObject = new VLCDataObject(this);
237 vlcOleObject = new VLCOleObject(this);
238 vlcSupportErrorInfo = new VLCSupportErrorInfo(this);
240 // configure controlling IUnknown interface for implemented interfaces
241 this->pUnkOuter = (NULL != pUnkOuter) ? pUnkOuter : dynamic_cast<LPUNKNOWN>(this);
244 _p_pict = p_class->getInPlacePict();
246 // make sure that persistable properties are initialized
250 VLCPlugin::~VLCPlugin()
252 delete vlcSupportErrorInfo;
254 delete vlcDataObject;
255 delete vlcViewObject;
258 delete vlcConnectionPointContainer;
259 delete vlcProvideClassInfo;
260 delete vlcPersistPropertyBag;
261 delete vlcPersistStreamInit;
262 delete vlcPersistStorage;
263 delete vlcOleInPlaceActiveObject;
264 delete vlcOleInPlaceObject;
265 delete vlcObjectSafety;
267 delete vlcOleControl;
271 SysFreeString(_bstr_mrl);
272 SysFreeString(_bstr_baseurl);
279 player_unregister_events();
280 libvlc_media_player_release(_p_mplayer);
283 if( _p_mlist ) { libvlc_media_list_release(_p_mlist); _p_mlist=NULL; }
284 if( _p_libvlc ) { libvlc_release(_p_libvlc); _p_libvlc=NULL; }
290 STDMETHODIMP VLCPlugin::QueryInterface(REFIID riid, void **ppv)
295 if( IID_IUnknown == riid )
296 *ppv = reinterpret_cast<LPVOID>(this);
297 else if( IID_IOleObject == riid )
298 *ppv = reinterpret_cast<LPVOID>(vlcOleObject);
299 else if( IID_IOleControl == riid )
300 *ppv = reinterpret_cast<LPVOID>(vlcOleControl);
301 else if( IID_IOleWindow == riid )
302 *ppv = reinterpret_cast<LPVOID>(vlcOleInPlaceObject);
303 else if( IID_IOleInPlaceObject == riid )
304 *ppv = reinterpret_cast<LPVOID>(vlcOleInPlaceObject);
305 else if( IID_IOleInPlaceActiveObject == riid )
306 *ppv = reinterpret_cast<LPVOID>(vlcOleInPlaceActiveObject);
307 else if( IID_IPersist == riid )
308 *ppv = reinterpret_cast<LPVOID>(vlcPersistStreamInit);
309 else if( IID_IPersistStreamInit == riid )
310 *ppv = reinterpret_cast<LPVOID>(vlcPersistStreamInit);
311 else if( IID_IPersistStorage == riid )
312 *ppv = reinterpret_cast<LPVOID>(vlcPersistStorage);
313 else if( IID_IPersistPropertyBag == riid )
314 *ppv = reinterpret_cast<LPVOID>(vlcPersistPropertyBag);
315 else if( IID_IProvideClassInfo == riid )
316 *ppv = reinterpret_cast<LPVOID>(vlcProvideClassInfo);
317 else if( IID_IProvideClassInfo2 == riid )
318 *ppv = reinterpret_cast<LPVOID>(vlcProvideClassInfo);
319 else if( IID_IConnectionPointContainer == riid )
320 *ppv = reinterpret_cast<LPVOID>(vlcConnectionPointContainer);
321 else if( IID_IObjectSafety == riid )
322 *ppv = reinterpret_cast<LPVOID>(vlcObjectSafety);
323 else if( IID_IDispatch == riid )
324 *ppv = (CLSID_VLCPlugin2 == getClassID()) ?
325 reinterpret_cast<LPVOID>(vlcControl2) :
326 reinterpret_cast<LPVOID>(vlcControl);
327 else if( IID_IVLCControl == riid )
328 *ppv = reinterpret_cast<LPVOID>(vlcControl);
329 else if( IID_IVLCControl2 == riid )
330 *ppv = reinterpret_cast<LPVOID>(vlcControl2);
331 else if( IID_IViewObject == riid )
332 *ppv = reinterpret_cast<LPVOID>(vlcViewObject);
333 else if( IID_IViewObject2 == riid )
334 *ppv = reinterpret_cast<LPVOID>(vlcViewObject);
335 else if( IID_IDataObject == riid )
336 *ppv = reinterpret_cast<LPVOID>(vlcDataObject);
337 else if( IID_ISupportErrorInfo == riid )
338 *ppv = reinterpret_cast<LPVOID>(vlcSupportErrorInfo);
342 return E_NOINTERFACE;
344 ((LPUNKNOWN)*ppv)->AddRef();
348 STDMETHODIMP_(ULONG) VLCPlugin::AddRef(void)
350 return InterlockedIncrement((LONG *)&_i_ref);
353 STDMETHODIMP_(ULONG) VLCPlugin::Release(void)
355 if( ! InterlockedDecrement((LONG *)&_i_ref) )
363 //////////////////////////////////////
365 HRESULT VLCPlugin::onInit(void)
367 if( NULL == _p_libvlc )
369 // initialize persistable properties
373 _bstr_baseurl = NULL;
380 // set default/preferred size (320x240) pixels in HIMETRIC
381 HDC hDC = CreateDevDC(NULL);
384 HimetricFromDP(hDC, (LPPOINT)&_extent, 1);
389 return CO_E_ALREADYINITIALIZED;
392 HRESULT VLCPlugin::onLoad(void)
394 if( SysStringLen(_bstr_baseurl) == 0 )
397 ** try to retreive the base URL using the client site moniker, which for Internet Explorer
398 ** is the URL of the page the plugin is embedded into.
400 LPOLECLIENTSITE pClientSite;
401 if( SUCCEEDED(vlcOleObject->GetClientSite(&pClientSite)) && (NULL != pClientSite) )
404 if( SUCCEEDED(CreateBindCtx(0, &pBC)) )
406 LPMONIKER pContMoniker = NULL;
407 if( SUCCEEDED(pClientSite->GetMoniker(OLEGETMONIKER_ONLYIFTHERE,
408 OLEWHICHMK_CONTAINER, &pContMoniker)) )
411 if( SUCCEEDED(pContMoniker->GetDisplayName(pBC, NULL, &base_url)) )
414 ** check that the moniker name is a URL
416 if( UrlIsW(base_url, URLIS_URL) )
419 _bstr_baseurl = SysAllocString(base_url);
421 CoTaskMemFree(base_url);
431 void VLCPlugin::initVLC()
433 extern HMODULE DllGetModule();
436 ** default initialization options
438 const char *ppsz_argv[32] = { };
441 char p_progpath[MAX_PATH];
443 TCHAR w_progpath[MAX_PATH];
444 DWORD len = GetModuleFileName(DllGetModule(), w_progpath, MAX_PATH);
445 w_progpath[MAX_PATH-1] = '\0';
448 len = WideCharToMultiByte(CP_UTF8, 0, w_progpath, len, p_progpath,
449 sizeof(p_progpath)-1, NULL, NULL);
452 p_progpath[len] = '\0';
453 ppsz_argv[0] = p_progpath;
458 ppsz_argv[ppsz_argc++] = "-vv";
461 char p_pluginpath[MAX_PATH];
462 if( RegOpenKeyEx( HKEY_LOCAL_MACHINE, TEXT("Software\\VideoLAN\\VLC"),
463 0, KEY_READ, &h_key ) == ERROR_SUCCESS )
465 DWORD i_type, i_data = MAX_PATH;
466 TCHAR w_pluginpath[MAX_PATH];
467 if( RegQueryValueEx( h_key, TEXT("InstallDir"), 0, &i_type,
468 (LPBYTE)w_pluginpath, &i_data ) == ERROR_SUCCESS )
470 w_pluginpath[MAX_PATH-1] = '\0';
471 if( i_type == REG_SZ )
473 if( WideCharToMultiByte(CP_UTF8, 0, w_pluginpath, -1, p_pluginpath,
474 sizeof(p_pluginpath)-sizeof("\\plugins")+1, NULL, NULL) )
476 strcat( p_pluginpath, "\\plugins" );
477 ppsz_argv[ppsz_argc++] = "--plugin-path";
478 ppsz_argv[ppsz_argc++] = p_pluginpath;
482 RegCloseKey( h_key );
485 // make sure plugin isn't affected with VLC single instance mode
486 ppsz_argv[ppsz_argc++] = "--no-one-instance";
488 /* common settings */
489 ppsz_argv[ppsz_argc++] = "-vv";
490 ppsz_argv[ppsz_argc++] = "--no-stats";
491 ppsz_argv[ppsz_argc++] = "--no-media-library";
492 ppsz_argv[ppsz_argc++] = "--intf=dummy";
493 ppsz_argv[ppsz_argc++] = "--no-video-title-show";
496 // loop mode is a configuration option only
498 ppsz_argv[ppsz_argc++] = "--loop";
500 _p_libvlc = libvlc_new(ppsz_argc, ppsz_argv);
504 _p_mlist = libvlc_media_list_new(_p_libvlc);
506 // initial playlist item
507 if( SysStringLen(_bstr_mrl) > 0 )
509 char *psz_mrl = NULL;
511 if( SysStringLen(_bstr_baseurl) > 0 )
514 ** if the MRL a relative URL, we should end up with an absolute URL
516 LPWSTR abs_url = CombineURL(_bstr_baseurl, _bstr_mrl);
517 if( NULL != abs_url )
519 psz_mrl = CStrFromWSTR(CP_UTF8, abs_url, wcslen(abs_url));
520 CoTaskMemFree(abs_url);
524 psz_mrl = CStrFromBSTR(CP_UTF8, _bstr_mrl);
530 ** baseURL is empty, assume MRL is absolute
532 psz_mrl = CStrFromBSTR(CP_UTF8, _bstr_mrl);
534 if( NULL != psz_mrl )
536 const char *options[1];
542 snprintf(timeBuffer, sizeof(timeBuffer), ":start-time=%d", _i_time);
543 options[i_options++] = timeBuffer;
545 // add default target to playlist
546 playlist_add_extended_untrusted(psz_mrl, i_options, options);
547 CoTaskMemFree(psz_mrl);
552 void VLCPlugin::setErrorInfo(REFIID riid, const char *description)
554 vlcSupportErrorInfo->setErrorInfo( getClassID() == CLSID_VLCPlugin2 ?
555 OLESTR("VideoLAN.VLCPlugin.2") : OLESTR("VideoLAN.VLCPlugin.1"),
559 HRESULT VLCPlugin::onAmbientChanged(LPUNKNOWN pContainer, DISPID dispID)
564 case DISPID_AMBIENT_BACKCOLOR:
567 if( SUCCEEDED(GetObjectProperty(pContainer, dispID, v)) )
569 setBackColor(V_I4(&v));
572 case DISPID_AMBIENT_DISPLAYNAME:
574 case DISPID_AMBIENT_FONT:
576 case DISPID_AMBIENT_FORECOLOR:
578 case DISPID_AMBIENT_LOCALEID:
580 case DISPID_AMBIENT_MESSAGEREFLECT:
582 case DISPID_AMBIENT_SCALEUNITS:
584 case DISPID_AMBIENT_TEXTALIGN:
586 case DISPID_AMBIENT_USERMODE:
589 if( SUCCEEDED(GetObjectProperty(pContainer, dispID, v)) )
591 setUserMode(V_BOOL(&v) != VARIANT_FALSE);
594 case DISPID_AMBIENT_UIDEAD:
596 case DISPID_AMBIENT_SHOWGRABHANDLES:
598 case DISPID_AMBIENT_SHOWHATCHING:
600 case DISPID_AMBIENT_DISPLAYASDEFAULT:
602 case DISPID_AMBIENT_SUPPORTSMNEMONICS:
604 case DISPID_AMBIENT_AUTOCLIP:
606 case DISPID_AMBIENT_APPEARANCE:
608 case DISPID_AMBIENT_CODEPAGE:
611 if( SUCCEEDED(GetObjectProperty(pContainer, dispID, v)) )
613 setCodePage(V_I4(&v));
616 case DISPID_AMBIENT_PALETTE:
618 case DISPID_AMBIENT_CHARSET:
620 case DISPID_AMBIENT_RIGHTTOLEFT:
622 case DISPID_AMBIENT_TOPTOBOTTOM:
626 ** multiple property change, look up the ones we are interested in
630 if( SUCCEEDED(GetObjectProperty(pContainer, DISPID_AMBIENT_USERMODE, v)) )
632 setUserMode(V_BOOL(&v) != VARIANT_FALSE);
636 if( SUCCEEDED(GetObjectProperty(pContainer, DISPID_AMBIENT_CODEPAGE, v)) )
638 setCodePage(V_I4(&v));
645 HRESULT VLCPlugin::onClose(DWORD dwSaveOption)
647 if( isInPlaceActive() )
649 onInPlaceDeactivate();
653 libvlc_instance_t* p_libvlc = _p_libvlc;
656 vlcDataObject->onClose();
659 libvlc_release(p_libvlc);
664 BOOL VLCPlugin::isInPlaceActive(void)
666 return (NULL != _inplacewnd);
669 HRESULT VLCPlugin::onActivateInPlace(LPMSG lpMesg, HWND hwndParent, LPCRECT lprcPosRect, LPCRECT lprcClipRect)
671 RECT clipRect = *lprcClipRect;
674 ** record keeping of control geometry within container
676 _posRect = *lprcPosRect;
679 ** Create a window for in place activated control.
680 ** the window geometry matches the control viewport
681 ** within container so that embedded video is always
682 ** properly displayed.
684 _inplacewnd = CreateWindow(_p_class->getInPlaceWndClassName(),
685 TEXT("VLC Plugin In-Place Window"),
686 WS_CHILD|WS_CLIPCHILDREN|WS_CLIPSIBLINGS,
689 lprcPosRect->right-lprcPosRect->left,
690 lprcPosRect->bottom-lprcPosRect->top,
693 _p_class->getHInstance(),
697 if( NULL == _inplacewnd )
700 SetWindowLongPtr(_inplacewnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this));
702 /* change cliprect coordinates system relative to window bounding rect */
703 OffsetRect(&clipRect, -lprcPosRect->left, -lprcPosRect->top);
705 HRGN clipRgn = CreateRectRgnIndirect(&clipRect);
706 SetWindowRgn(_inplacewnd, clipRgn, TRUE);
710 /* will run vlc if not done already */
711 libvlc_instance_t* p_libvlc;
712 HRESULT result = getVLC(&p_libvlc);
716 if( _b_autoplay && playlist_select(0) )
718 libvlc_media_player_play(_p_mplayer);
724 ShowWindow(_inplacewnd, SW_SHOW);
729 HRESULT VLCPlugin::onInPlaceDeactivate(void)
737 DestroyWindow(_inplacewnd);
743 void VLCPlugin::setVisible(BOOL fVisible)
745 if( fVisible != _b_visible )
747 _b_visible = fVisible;
748 if( isInPlaceActive() )
750 ShowWindow(_inplacewnd, fVisible ? SW_SHOW : SW_HIDE);
752 InvalidateRect(_inplacewnd, NULL, TRUE);
755 firePropChangedEvent(DISPID_Visible);
759 void VLCPlugin::setVolume(int volume)
763 else if( volume > 200 )
766 if( volume != _i_volume )
771 libvlc_media_player_t *p_md;
772 HRESULT hr = getMD(&p_md);
774 libvlc_audio_set_volume(p_md, _i_volume);
780 void VLCPlugin::setBackColor(OLE_COLOR backcolor)
782 if( _i_backcolor != backcolor )
784 _i_backcolor = backcolor;
785 if( isInPlaceActive() )
793 void VLCPlugin::setTime(int seconds)
798 if( seconds != _i_time )
800 setStartTime(_i_time);
801 if( NULL != _p_mplayer )
803 libvlc_media_player_set_time(_p_mplayer, _i_time);
808 void VLCPlugin::setFocus(BOOL fFocus)
811 SetActiveWindow(_inplacewnd);
814 BOOL VLCPlugin::hasFocus(void)
816 return GetActiveWindow() == _inplacewnd;
819 void VLCPlugin::onDraw(DVTARGETDEVICE * ptd, HDC hicTargetDev,
820 HDC hdcDraw, LPCRECTL lprcBounds, LPCRECTL lprcWBounds)
824 long width = lprcBounds->right-lprcBounds->left;
825 long height = lprcBounds->bottom-lprcBounds->top;
827 RECT bounds = { lprcBounds->left, lprcBounds->top, lprcBounds->right, lprcBounds->bottom };
831 /* VLC is in user mode, just draw background color */
832 COLORREF colorref = RGB(0, 0, 0);
833 OleTranslateColor(_i_backcolor, (HPALETTE)GetStockObject(DEFAULT_PALETTE), &colorref);
834 if( colorref != RGB(0, 0, 0) )
836 /* custom background */
837 HBRUSH colorbrush = CreateSolidBrush(colorref);
838 FillRect(hdcDraw, &bounds, colorbrush);
839 DeleteObject((HANDLE)colorbrush);
843 /* black background */
844 FillRect(hdcDraw, &bounds, (HBRUSH)GetStockObject(BLACK_BRUSH));
849 /* VLC is in design mode, draw the VLC logo */
850 FillRect(hdcDraw, &bounds, (HBRUSH)GetStockObject(WHITE_BRUSH));
852 LPPICTURE pict = getPicture();
855 OLE_XSIZE_HIMETRIC picWidth;
856 OLE_YSIZE_HIMETRIC picHeight;
858 pict->get_Width(&picWidth);
859 pict->get_Height(&picHeight);
861 SIZEL picSize = { picWidth, picHeight };
863 if( NULL != hicTargetDev )
865 DPFromHimetric(hicTargetDev, (LPPOINT)&picSize, 1);
867 else if( NULL != (hicTargetDev = CreateDevDC(ptd)) )
869 DPFromHimetric(hicTargetDev, (LPPOINT)&picSize, 1);
870 DeleteDC(hicTargetDev);
873 if( picSize.cx > width-4 )
874 picSize.cx = width-4;
875 if( picSize.cy > height-4 )
876 picSize.cy = height-4;
878 LONG dstX = lprcBounds->left+(width-picSize.cx)/2;
879 LONG dstY = lprcBounds->top+(height-picSize.cy)/2;
881 if( NULL != lprcWBounds )
883 RECT wBounds = { lprcWBounds->left, lprcWBounds->top, lprcWBounds->right, lprcWBounds->bottom };
884 pict->Render(hdcDraw, dstX, dstY, picSize.cx, picSize.cy,
885 0L, picHeight, picWidth, -picHeight, &wBounds);
888 pict->Render(hdcDraw, dstX, dstY, picSize.cx, picSize.cy,
889 0L, picHeight, picWidth, -picHeight, NULL);
894 SelectObject(hdcDraw, GetStockObject(BLACK_BRUSH));
896 MoveToEx(hdcDraw, bounds.left, bounds.top, NULL);
897 LineTo(hdcDraw, bounds.left+width-1, bounds.top);
898 LineTo(hdcDraw, bounds.left+width-1, bounds.top+height-1);
899 LineTo(hdcDraw, bounds.left, bounds.top+height-1);
900 LineTo(hdcDraw, bounds.left, bounds.top);
905 void VLCPlugin::onPaint(HDC hdc, const RECT &bounds, const RECT &clipRect)
909 /* if VLC is in design mode, draw control logo */
910 HDC hdcDraw = CreateCompatibleDC(hdc);
911 if( NULL != hdcDraw )
913 SIZEL size = getExtent();
914 DPFromHimetric(hdc, (LPPOINT)&size, 1);
915 RECTL posRect = { 0, 0, size.cx, size.cy };
917 int width = bounds.right-bounds.left;
918 int height = bounds.bottom-bounds.top;
920 HBITMAP hBitmap = CreateCompatibleBitmap(hdc, width, height);
921 if( NULL != hBitmap )
923 HBITMAP oldBmp = (HBITMAP)SelectObject(hdcDraw, hBitmap);
925 if( (size.cx != width) || (size.cy != height) )
927 // needs to scale canvas
928 SetMapMode(hdcDraw, MM_ANISOTROPIC);
929 SetWindowExtEx(hdcDraw, size.cx, size.cy, NULL);
930 SetViewportExtEx(hdcDraw, width, height, NULL);
933 onDraw(NULL, hdc, hdcDraw, &posRect, NULL);
935 SetMapMode(hdcDraw, MM_TEXT);
936 BitBlt(hdc, bounds.left, bounds.top,
941 SelectObject(hdcDraw, oldBmp);
942 DeleteObject(hBitmap);
949 void VLCPlugin::onPositionChange(LPCRECT lprcPosRect, LPCRECT lprcClipRect)
951 RECT clipRect = *lprcClipRect;
953 //RedrawWindow(GetParent(_inplacewnd), &_posRect, NULL, RDW_INVALIDATE|RDW_ERASE|RDW_ALLCHILDREN);
956 ** record keeping of control geometry within container
958 _posRect = *lprcPosRect;
961 ** change in-place window geometry to match clipping region
963 SetWindowPos(_inplacewnd, NULL,
966 lprcPosRect->right-lprcPosRect->left,
967 lprcPosRect->bottom-lprcPosRect->top,
973 /* change cliprect coordinates system relative to window bounding rect */
974 OffsetRect(&clipRect, -lprcPosRect->left, -lprcPosRect->top);
975 HRGN clipRgn = CreateRectRgnIndirect(&clipRect);
976 SetWindowRgn(_inplacewnd, clipRgn, FALSE);
978 //RedrawWindow(_videownd, &posRect, NULL, RDW_INVALIDATE|RDW_ERASE|RDW_ALLCHILDREN);
981 void VLCPlugin::freezeEvents(BOOL freeze)
983 vlcConnectionPointContainer->freezeEvents(freeze);
986 void VLCPlugin::firePropChangedEvent(DISPID dispid)
988 vlcConnectionPointContainer->firePropChangedEvent(dispid);
991 void VLCPlugin::fireOnPlayEvent(void)
993 DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
994 vlcConnectionPointContainer->fireEvent(DISPID_PlayEvent, &dispparamsNoArgs);
997 void VLCPlugin::fireOnPauseEvent(void)
999 DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
1000 vlcConnectionPointContainer->fireEvent(DISPID_PauseEvent, &dispparamsNoArgs);
1003 void VLCPlugin::fireOnStopEvent(void)
1005 DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
1006 vlcConnectionPointContainer->fireEvent(DISPID_StopEvent, &dispparamsNoArgs);
1012 void VLCPlugin::fireOnMediaPlayerNothingSpecialEvent()
1014 DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
1015 vlcConnectionPointContainer->fireEvent(DISPID_MediaPlayerNothingSpecialEvent, &dispparamsNoArgs);
1018 void VLCPlugin::fireOnMediaPlayerOpeningEvent()
1020 DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
1021 vlcConnectionPointContainer->fireEvent(DISPID_MediaPlayerOpeningEvent, &dispparamsNoArgs);
1024 void VLCPlugin::fireOnMediaPlayerBufferingEvent()
1026 DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
1027 vlcConnectionPointContainer->fireEvent(DISPID_MediaPlayerBufferingEvent, &dispparamsNoArgs);
1030 void VLCPlugin::fireOnMediaPlayerPlayingEvent()
1032 DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
1033 vlcConnectionPointContainer->fireEvent(DISPID_MediaPlayerPlayingEvent, &dispparamsNoArgs);
1036 void VLCPlugin::fireOnMediaPlayerPausedEvent()
1038 DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
1039 vlcConnectionPointContainer->fireEvent(DISPID_MediaPlayerPausedEvent, &dispparamsNoArgs);
1042 void VLCPlugin::fireOnMediaPlayerEncounteredErrorEvent()
1044 DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
1045 vlcConnectionPointContainer->fireEvent(DISPID_MediaPlayerEncounteredErrorEvent, &dispparamsNoArgs);
1048 void VLCPlugin::fireOnMediaPlayerEndReachedEvent()
1050 DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
1051 vlcConnectionPointContainer->fireEvent(DISPID_MediaPlayerEndReachedEvent, &dispparamsNoArgs);
1054 void VLCPlugin::fireOnMediaPlayerStoppedEvent()
1056 DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
1057 vlcConnectionPointContainer->fireEvent(DISPID_MediaPlayerStoppedEvent, &dispparamsNoArgs);
1060 void VLCPlugin::fireOnMediaPlayerForwardEvent()
1062 DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
1063 vlcConnectionPointContainer->fireEvent(DISPID_MediaPlayerForwardEvent, &dispparamsNoArgs);
1066 void VLCPlugin::fireOnMediaPlayerBackwardEvent()
1068 DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
1069 vlcConnectionPointContainer->fireEvent(DISPID_MediaPlayerBackwardEvent, &dispparamsNoArgs);
1072 static void handle_input_state_event(const libvlc_event_t* event, void *param)
1074 VLCPlugin *plugin = (VLCPlugin*)param;
1075 switch( event->type )
1077 case libvlc_MediaPlayerNothingSpecial:
1078 plugin->fireOnMediaPlayerNothingSpecialEvent();
1080 case libvlc_MediaPlayerOpening:
1081 plugin->fireOnMediaPlayerOpeningEvent();
1083 case libvlc_MediaPlayerBuffering:
1084 plugin->fireOnMediaPlayerBufferingEvent();
1086 case libvlc_MediaPlayerPlaying:
1087 plugin->fireOnMediaPlayerPlayingEvent();
1089 case libvlc_MediaPlayerPaused:
1090 plugin->fireOnMediaPlayerPausedEvent();
1092 case libvlc_MediaPlayerStopped:
1093 plugin->fireOnMediaPlayerStoppedEvent();
1095 case libvlc_MediaPlayerForward:
1096 plugin->fireOnMediaPlayerForwardEvent();
1098 case libvlc_MediaPlayerBackward:
1099 plugin->fireOnMediaPlayerBackwardEvent();
1101 case libvlc_MediaPlayerEndReached:
1102 plugin->fireOnMediaPlayerEndReachedEvent();
1104 case libvlc_MediaPlayerEncounteredError:
1105 plugin->fireOnMediaPlayerEncounteredErrorEvent();
1110 void VLCPlugin::fireOnMediaPlayerTimeChangedEvent(long time)
1114 params.rgvarg = (VARIANTARG *) CoTaskMemAlloc(sizeof(VARIANTARG) * params.cArgs) ;
1115 memset(params.rgvarg, 0, sizeof(VARIANTARG) * params.cArgs);
1116 params.rgvarg[0].vt = VT_I4;
1117 params.rgvarg[0].lVal = time;
1118 params.rgdispidNamedArgs = NULL;
1119 params.cNamedArgs = 0;
1120 vlcConnectionPointContainer->fireEvent(DISPID_MediaPlayerTimeChangedEvent, ¶ms);
1123 static void handle_time_changed_event(const libvlc_event_t* event, void *param)
1125 VLCPlugin *plugin = (VLCPlugin*)param;
1126 plugin->fireOnMediaPlayerTimeChangedEvent(event->u.media_player_time_changed.new_time);
1129 void VLCPlugin::fireOnMediaPlayerPositionChangedEvent(long position)
1133 params.rgvarg = (VARIANTARG *) CoTaskMemAlloc(sizeof(VARIANTARG) * params.cArgs) ;
1134 memset(params.rgvarg, 0, sizeof(VARIANTARG) * params.cArgs);
1135 params.rgvarg[0].vt = VT_I4;
1136 params.rgvarg[0].lVal = position;
1137 params.rgdispidNamedArgs = NULL;
1138 params.cNamedArgs = 0;
1139 vlcConnectionPointContainer->fireEvent(DISPID_MediaPlayerPositionChangedEvent, ¶ms);
1142 static void handle_position_changed_event(const libvlc_event_t* event, void *param)
1144 VLCPlugin *plugin = (VLCPlugin*)param;
1145 plugin->fireOnMediaPlayerPositionChangedEvent(event->u.media_player_position_changed.new_position);
1148 #define B(val) ((val) ? 0xFFFF : 0x0000)
1149 void VLCPlugin::fireOnMediaPlayerSeekableChangedEvent(VARIANT_BOOL seekable)
1153 params.rgvarg = (VARIANTARG *) CoTaskMemAlloc(sizeof(VARIANTARG) * params.cArgs) ;
1154 memset(params.rgvarg, 0, sizeof(VARIANTARG) * params.cArgs);
1155 params.rgvarg[0].vt = VT_BOOL;
1156 params.rgvarg[0].boolVal = seekable;
1157 params.rgdispidNamedArgs = NULL;
1158 params.cNamedArgs = 0;
1159 vlcConnectionPointContainer->fireEvent(DISPID_MediaPlayerSeekableChangedEvent, ¶ms);
1162 static void handle_seekable_changed_event(const libvlc_event_t* event, void *param)
1164 VLCPlugin *plugin = (VLCPlugin*)param;
1165 plugin->fireOnMediaPlayerSeekableChangedEvent(B(event->u.media_player_seekable_changed.new_seekable));
1168 void VLCPlugin::fireOnMediaPlayerPausableChangedEvent(VARIANT_BOOL pausable)
1172 params.rgvarg = (VARIANTARG *) CoTaskMemAlloc(sizeof(VARIANTARG) * params.cArgs) ;
1173 memset(params.rgvarg, 0, sizeof(VARIANTARG) * params.cArgs);
1174 params.rgvarg[0].vt = VT_BOOL;
1175 params.rgvarg[0].boolVal = pausable;
1176 params.rgdispidNamedArgs = NULL;
1177 params.cNamedArgs = 0;
1178 vlcConnectionPointContainer->fireEvent(DISPID_MediaPlayerPausableChangedEvent, ¶ms);
1181 static void handle_pausable_changed_event(const libvlc_event_t* event, void *param)
1183 VLCPlugin *plugin = (VLCPlugin*)param;
1184 plugin->fireOnMediaPlayerPausableChangedEvent(B(event->u.media_player_pausable_changed.new_pausable));
1190 bool VLCPlugin::playlist_select( int idx )
1192 libvlc_media_t *p_m = NULL;
1196 libvlc_media_list_lock(_p_mlist);
1198 int count = libvlc_media_list_count(_p_mlist);
1200 if( (idx < 0) || (idx >= count) )
1205 p_m = libvlc_media_list_item_at_index(_p_mlist,_i_midx);
1206 libvlc_media_list_unlock(_p_mlist);
1214 player_unregister_events();
1215 libvlc_media_player_release( _p_mplayer );
1219 _p_mplayer = libvlc_media_player_new_from_media(p_m);
1222 // initial volume setting
1223 libvlc_audio_set_volume(_p_mplayer, _i_volume);
1225 libvlc_audio_set_mute(_p_mplayer, TRUE);
1226 set_player_window();
1227 player_register_events();
1230 libvlc_media_release(p_m);
1231 return _p_mplayer ? true : false;
1234 libvlc_media_list_unlock(_p_mlist);
1238 void VLCPlugin::set_player_window()
1240 // XXX FIXME no idea if this is correct or not
1241 libvlc_media_player_set_hwnd(_p_mplayer,getInPlaceWindow());
1244 void VLCPlugin::player_register_events()
1246 libvlc_event_manager_t *eventManager = NULL;
1249 eventManager = libvlc_media_player_event_manager(_p_mplayer);
1251 libvlc_event_attach(eventManager, libvlc_MediaPlayerNothingSpecial,
1252 handle_input_state_event, this);
1253 libvlc_event_attach(eventManager, libvlc_MediaPlayerOpening,
1254 handle_input_state_event, this);
1255 libvlc_event_attach(eventManager, libvlc_MediaPlayerBuffering,
1256 handle_input_state_event, this);
1257 libvlc_event_attach(eventManager, libvlc_MediaPlayerPlaying,
1258 handle_input_state_event, this);
1259 libvlc_event_attach(eventManager, libvlc_MediaPlayerPaused,
1260 handle_input_state_event, this);
1261 libvlc_event_attach(eventManager, libvlc_MediaPlayerStopped,
1262 handle_input_state_event, this);
1263 libvlc_event_attach(eventManager, libvlc_MediaPlayerForward,
1264 handle_input_state_event, this);
1265 libvlc_event_attach(eventManager, libvlc_MediaPlayerBackward,
1266 handle_input_state_event, this);
1267 libvlc_event_attach(eventManager, libvlc_MediaPlayerEndReached,
1268 handle_input_state_event, this);
1269 libvlc_event_attach(eventManager, libvlc_MediaPlayerEncounteredError,
1270 handle_input_state_event, this);
1272 libvlc_event_attach(eventManager, libvlc_MediaPlayerTimeChanged,
1273 handle_time_changed_event, this);
1274 libvlc_event_attach(eventManager, libvlc_MediaPlayerPositionChanged,
1275 handle_position_changed_event, this);
1276 libvlc_event_attach(eventManager, libvlc_MediaPlayerSeekableChanged,
1277 handle_seekable_changed_event, this);
1278 libvlc_event_attach(eventManager, libvlc_MediaPlayerPausableChanged,
1279 handle_pausable_changed_event, this);
1283 void VLCPlugin::player_unregister_events()
1285 libvlc_event_manager_t *eventManager = NULL;
1288 eventManager = libvlc_media_player_event_manager(_p_mplayer);
1290 libvlc_event_detach(eventManager, libvlc_MediaPlayerNothingSpecial,
1291 handle_input_state_event, this);
1292 libvlc_event_detach(eventManager, libvlc_MediaPlayerOpening,
1293 handle_input_state_event, this);
1294 libvlc_event_detach(eventManager, libvlc_MediaPlayerBuffering,
1295 handle_input_state_event, this);
1296 libvlc_event_detach(eventManager, libvlc_MediaPlayerPlaying,
1297 handle_input_state_event, this);
1298 libvlc_event_detach(eventManager, libvlc_MediaPlayerPaused,
1299 handle_input_state_event, this);
1300 libvlc_event_detach(eventManager, libvlc_MediaPlayerStopped,
1301 handle_input_state_event, this);
1302 libvlc_event_detach(eventManager, libvlc_MediaPlayerForward,
1303 handle_input_state_event, this);
1304 libvlc_event_detach(eventManager, libvlc_MediaPlayerBackward,
1305 handle_input_state_event, this);
1306 libvlc_event_detach(eventManager, libvlc_MediaPlayerEndReached,
1307 handle_input_state_event, this);
1308 libvlc_event_detach(eventManager, libvlc_MediaPlayerEncounteredError,
1309 handle_input_state_event, this);
1311 libvlc_event_detach(eventManager, libvlc_MediaPlayerTimeChanged,
1312 handle_time_changed_event, this);
1313 libvlc_event_detach(eventManager, libvlc_MediaPlayerPositionChanged,
1314 handle_position_changed_event, this);
1315 libvlc_event_detach(eventManager, libvlc_MediaPlayerSeekableChanged,
1316 handle_seekable_changed_event, this);
1317 libvlc_event_detach(eventManager, libvlc_MediaPlayerPausableChanged,
1318 handle_pausable_changed_event, this);
1322 int VLCPlugin::playlist_add_extended_untrusted(const char *mrl, int optc, const char **optv)
1325 libvlc_media_t *p_m = libvlc_media_new_location(_p_libvlc,mrl);
1329 for( int i = 0; i < optc; ++i )
1330 libvlc_media_add_option_flag(p_m, optv[i], libvlc_media_option_unique);
1332 libvlc_media_list_lock(_p_mlist);
1333 if( libvlc_media_list_add_media(_p_mlist,p_m) == 0 )
1334 item = libvlc_media_list_count(_p_mlist)-1;
1335 libvlc_media_list_unlock(_p_mlist);
1336 libvlc_media_release(p_m);