📄 vlccontrol2.cpp
字号:
HRESULT hr = NOERROR; if( NULL == _p_typeinfo ) { ITypeLib *p_typelib; hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib); if( SUCCEEDED(hr) ) { hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCVideo, &_p_typeinfo); if( FAILED(hr) ) { _p_typeinfo = NULL; } p_typelib->Release(); } } return hr;};STDMETHODIMP VLCVideo::GetTypeInfoCount(UINT* pctInfo){ if( NULL == pctInfo ) return E_INVALIDARG; if( SUCCEEDED(loadTypeInfo()) ) *pctInfo = 1; else *pctInfo = 0; return NOERROR;};STDMETHODIMP VLCVideo::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo){ if( NULL == ppTInfo ) return E_INVALIDARG; if( SUCCEEDED(loadTypeInfo()) ) { _p_typeinfo->AddRef(); *ppTInfo = _p_typeinfo; return NOERROR; } *ppTInfo = NULL; return E_NOTIMPL;};STDMETHODIMP VLCVideo::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames, UINT cNames, LCID lcid, DISPID* rgDispID){ if( SUCCEEDED(loadTypeInfo()) ) { return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID); } return E_NOTIMPL;};STDMETHODIMP VLCVideo::Invoke(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr){ if( SUCCEEDED(loadTypeInfo()) ) { return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr); } return E_NOTIMPL;};STDMETHODIMP VLCVideo::get_fullscreen(VARIANT_BOOL* fullscreen){ if( NULL == fullscreen ) return E_POINTER; libvlc_instance_t* p_libvlc; HRESULT hr = _p_instance->getVLC(&p_libvlc); if( SUCCEEDED(hr) ) { libvlc_exception_t ex; libvlc_exception_init(&ex); libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_libvlc, &ex); if( ! libvlc_exception_raised(&ex) ) { *fullscreen = libvlc_get_fullscreen(p_md, &ex) ? VARIANT_TRUE : VARIANT_FALSE; libvlc_media_player_release(p_md); if( ! libvlc_exception_raised(&ex) ) { return NOERROR; } } _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex)); libvlc_exception_clear(&ex); return E_FAIL; } return hr;};STDMETHODIMP VLCVideo::put_fullscreen(VARIANT_BOOL fullscreen){ libvlc_instance_t* p_libvlc; HRESULT hr = _p_instance->getVLC(&p_libvlc); if( SUCCEEDED(hr) ) { libvlc_exception_t ex; libvlc_exception_init(&ex); libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_libvlc, &ex); if( ! libvlc_exception_raised(&ex) ) { libvlc_set_fullscreen(p_md, VARIANT_FALSE != fullscreen, &ex); libvlc_media_player_release(p_md); if( ! libvlc_exception_raised(&ex) ) { return NOERROR; } } _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex)); libvlc_exception_clear(&ex); return E_FAIL; } return hr;};STDMETHODIMP VLCVideo::get_width(long* width){ if( NULL == width ) return E_POINTER; libvlc_instance_t* p_libvlc; HRESULT hr = _p_instance->getVLC(&p_libvlc); if( SUCCEEDED(hr) ) { libvlc_exception_t ex; libvlc_exception_init(&ex); libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_libvlc, &ex); if( ! libvlc_exception_raised(&ex) ) { *width = libvlc_video_get_width(p_md, &ex); libvlc_media_player_release(p_md); if( ! libvlc_exception_raised(&ex) ) { return NOERROR; } } _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex)); libvlc_exception_clear(&ex); return E_FAIL; } return hr;};STDMETHODIMP VLCVideo::get_height(long* height){ if( NULL == height ) return E_POINTER; libvlc_instance_t* p_libvlc; HRESULT hr = _p_instance->getVLC(&p_libvlc); if( SUCCEEDED(hr) ) { libvlc_exception_t ex; libvlc_exception_init(&ex); libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_libvlc, &ex); if( ! libvlc_exception_raised(&ex) ) { *height = libvlc_video_get_height(p_md, &ex); libvlc_media_player_release(p_md); if( ! libvlc_exception_raised(&ex) ) { return NOERROR; } } _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex)); libvlc_exception_clear(&ex); return E_FAIL; } return hr;};STDMETHODIMP VLCVideo::get_aspectRatio(BSTR* aspect){ if( NULL == aspect ) return E_POINTER; libvlc_instance_t* p_libvlc; HRESULT hr = _p_instance->getVLC(&p_libvlc); if( SUCCEEDED(hr) ) { libvlc_exception_t ex; libvlc_exception_init(&ex); libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_libvlc, &ex); if( ! libvlc_exception_raised(&ex) ) { char *psz_aspect = libvlc_video_get_aspect_ratio(p_md, &ex); libvlc_media_player_release(p_md); if( ! libvlc_exception_raised(&ex) ) { if( NULL == psz_aspect ) return E_OUTOFMEMORY; *aspect = BSTRFromCStr(CP_UTF8, psz_aspect); free( psz_aspect ); psz_aspect = NULL; return (NULL == *aspect) ? E_OUTOFMEMORY : NOERROR; } free( psz_aspect ); psz_aspect = NULL; } _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex)); libvlc_exception_clear(&ex); return E_FAIL; } return hr;};STDMETHODIMP VLCVideo::put_aspectRatio(BSTR aspect){ if( NULL == aspect ) return E_POINTER; if( 0 == SysStringLen(aspect) ) return E_INVALIDARG; libvlc_instance_t* p_libvlc; HRESULT hr = _p_instance->getVLC(&p_libvlc); if( SUCCEEDED(hr) ) { libvlc_exception_t ex; libvlc_exception_init(&ex); libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_libvlc, &ex); if( ! libvlc_exception_raised(&ex) ) { char *psz_aspect = CStrFromBSTR(CP_UTF8, aspect); if( NULL == psz_aspect ) { return E_OUTOFMEMORY; } libvlc_video_set_aspect_ratio(p_md, psz_aspect, &ex); CoTaskMemFree(psz_aspect); libvlc_media_player_release(p_md); if( libvlc_exception_raised(&ex) ) { _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex)); libvlc_exception_clear(&ex); return E_FAIL; } } return NOERROR; } return hr;};STDMETHODIMP VLCVideo::get_subtitle(long* spu){ if( NULL == spu ) return E_POINTER; libvlc_instance_t* p_libvlc; HRESULT hr = _p_instance->getVLC(&p_libvlc); if( SUCCEEDED(hr) ) { libvlc_exception_t ex; libvlc_exception_init(&ex); libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_libvlc, &ex); if( ! libvlc_exception_raised(&ex) ) { *spu = libvlc_video_get_spu(p_md, &ex); libvlc_media_player_release(p_md); if( ! libvlc_exception_raised(&ex) ) { return NOERROR; } } _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex)); libvlc_exception_clear(&ex); return E_FAIL; } return hr;};STDMETHODIMP VLCVideo::put_subtitle(long spu){ libvlc_instance_t* p_libvlc; HRESULT hr = _p_instance->getVLC(&p_libvlc); if( SUCCEEDED(hr) ) { libvlc_exception_t ex; libvlc_exception_init(&ex); libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_libvlc, &ex); libvlc_video_set_spu(p_md, spu, &ex); libvlc_media_player_release(p_md); if( libvlc_exception_raised(&ex) ) { _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex)); libvlc_exception_clear(&ex); return E_FAIL; } return NOERROR; } return hr;};STDMETHODIMP VLCVideo::get_crop(BSTR* geometry){ if( NULL == geometry ) return E_POINTER; libvlc_instance_t* p_libvlc; HRESULT hr = _p_instance->getVLC(&p_libvlc); if( SUCCEEDED(hr) ) { libvlc_exception_t ex; libvlc_exception_init(&ex); libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_libvlc, &ex); if( ! libvlc_exception_raised(&ex) ) { char *psz_geometry = libvlc_video_get_crop_geometry(p_md, &ex); libvlc_media_player_release(p_md); if( ! libvlc_exception_raised(&ex) ) { if( NULL == psz_geometry ) return E_OUTOFMEMORY; *geometry = BSTRFromCStr(CP_UTF8, psz_geometry); free( psz_geometry ); psz_geometry = NULL; return (NULL == geometry) ? E_OUTOFMEMORY : NOERROR; } free( psz_geometry ); psz_geometry = NULL; } _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex)); libvlc_exception_clear(&ex); return E_FAIL; } return hr;};STDMETHODIMP VLCVideo::put_crop(BSTR geometry){ if( NULL == geometry ) return E_POINTER; if( 0 == SysStringLen(geometry) ) return E_INVALIDARG; libvlc_instance_t* p_libvlc; HRESULT hr = _p_instance->getVLC(&p_libvlc); if( SUCCEEDED(hr) ) { libvlc_exception_t ex; libvlc_exception_init(&ex); libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_libvlc, &ex); if( ! libvlc_exception_raised(&ex) ) { char *psz_geometry = CStrFromBSTR(CP_UTF8, geometry); if( NULL == psz_geometry ) { return E_OUTOFMEMORY; } libvlc_video_set_crop_geometry(p_md, psz_geometry, &ex); CoTaskMemFree(psz_geometry); libvlc_media_player_release(p_md); if( libvlc_exception_raised(&ex) ) { _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex)); libvlc_exception_clear(&ex); return E_FAIL; } } return NOERROR; } return hr;};STDMETHODIMP VLCVideo::get_teletext(long* page){ if( NULL == page ) return E_POINTER; libvlc_instance_t* p_libvlc; HRESULT hr = _p_instance->getVLC(&p_libvlc); if( SUCCEEDED(hr) ) { libvlc_exception_t ex; libvlc_exception_init(&ex); libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_libvlc, &ex); if( ! libvlc_exception_raised(&ex) ) { *page = libvlc_video_get_teletext(p_md, &ex); libvlc_media_player_release(p_md); if( ! libvlc_exception_raised(&ex) ) { return NOERROR; } } _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex)); libvlc_exception_clear(&ex); return E_FAIL; } return hr;};STDMETHODIMP VLCVideo::put_teletext(long page){ libvlc_instance_t* p_libvlc; HRESULT hr = _p_instance->getVLC(&p_libvlc); if( SUCCEEDED(hr) ) { libvlc_exception_t ex; libvlc_exception_init(&ex); libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_libvlc, &ex); libvlc_video_set_teletext(p_md, page, &ex); libvlc_media_player_release(p_md); if( libvlc_exception_raised(&ex) ) { _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex)); libvlc_exception_clear(&ex); return E_FAIL; } return NOERROR; } return hr;};STDMETHODIMP VLCVideo::takeSnapshot(LPPICTUREDISP* picture){ if( NULL == picture ) return E_POINTER; libvlc_instance_t* p_libvlc; HRESULT hr = _p_instance->getVLC(&p_libvlc); if( SUCCEEDED(hr) ) { libvlc_exception_t ex; libvlc_exception_init(&ex); libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_libvlc, &ex); if( ! libvlc_exception_raised(&ex) ) { static int uniqueId = 0; TCHAR path[MAX_PATH+1]; int pathlen = GetTempPath(MAX_PATH-24, path); if( (0 == pathlen) || (pathlen > (MAX_PATH-24)) ) return E_FAIL; /* check temp directory path by openning it */ { HANDLE dirHandle = CreateFile(path, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); if( INVALID_HANDLE_VALUE == dirHandle ) { _p_instance->setErrorInfo(IID_IVLCVideo, "Invalid temporary directory for snapshot images, check values of TMP, TEMP envars."); return E_FAIL; } else { BY_HANDLE_FILE_INFORMATION bhfi; BOOL res = GetFileInformationByHandle(dirHandle, &bhfi); CloseHandle(dirHandle); if( !res || !(bhfi.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ) { _p_instance->setErrorInfo(IID_IVLCVideo, "Invalid temporary directory for snapshot images, check values of TMP, TEMP envars."); return E_FAIL; } } } TCHAR filepath[MAX_PATH+1]; _stprintf(filepath, TEXT("%sAXVLC%lXS%lX.bmp"), path, GetCurrentProcessId(), ++uniqueId);#ifdef _UNICODE /* reuse path
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -