📄 vlccontrol2.cpp
字号:
{ if( NULL == time ) 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; p_md = libvlc_playlist_get_media_player(p_libvlc, &ex); if( ! libvlc_exception_raised(&ex) ) { *time = (double)libvlc_media_player_get_time(p_md, &ex); libvlc_media_player_release(p_md); if( ! libvlc_exception_raised(&ex) ) { return NOERROR; } } _p_instance->setErrorInfo(IID_IVLCInput, libvlc_exception_get_message(&ex)); libvlc_exception_clear(&ex); return E_FAIL; } return hr;};STDMETHODIMP VLCInput::put_time(double time){ 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; p_md = libvlc_playlist_get_media_player(p_libvlc, &ex); if( ! libvlc_exception_raised(&ex) ) { libvlc_media_player_set_time(p_md, (int64_t)time, &ex); libvlc_media_player_release(p_md); if( ! libvlc_exception_raised(&ex) ) { return NOERROR; } } _p_instance->setErrorInfo(IID_IVLCInput, libvlc_exception_get_message(&ex)); libvlc_exception_clear(&ex); return E_FAIL; } return hr;};STDMETHODIMP VLCInput::get_state(long* state){ if( NULL == state ) 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; p_md = libvlc_playlist_get_media_player(p_libvlc, &ex); if( ! libvlc_exception_raised(&ex) ) { *state = libvlc_media_player_get_state(p_md, &ex); libvlc_media_player_release(p_md); if( ! libvlc_exception_raised(&ex) ) { return NOERROR; } } libvlc_exception_clear(&ex); // don't fail, just return the idle state *state = 0; return NOERROR; } return hr;};STDMETHODIMP VLCInput::get_rate(double* rate){ if( NULL == rate ) 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; p_md = libvlc_playlist_get_media_player(p_libvlc, &ex); if( ! libvlc_exception_raised(&ex) ) { *rate = libvlc_media_player_get_rate(p_md, &ex); libvlc_media_player_release(p_md); if( ! libvlc_exception_raised(&ex) ) { return NOERROR; } } _p_instance->setErrorInfo(IID_IVLCInput, libvlc_exception_get_message(&ex)); libvlc_exception_clear(&ex); return E_FAIL; } return hr;};STDMETHODIMP VLCInput::put_rate(double rate){ 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; p_md = libvlc_playlist_get_media_player(p_libvlc, &ex); if( ! libvlc_exception_raised(&ex) ) { libvlc_media_player_set_rate(p_md, rate, &ex); libvlc_media_player_release(p_md); if( ! libvlc_exception_raised(&ex) ) { return NOERROR; } } _p_instance->setErrorInfo(IID_IVLCInput, libvlc_exception_get_message(&ex)); libvlc_exception_clear(&ex); return E_FAIL; } return hr;};STDMETHODIMP VLCInput::get_fps(double* fps){ if( NULL == fps ) return E_POINTER; *fps = 0.0; 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; p_md = libvlc_playlist_get_media_player(p_libvlc, &ex); if( ! libvlc_exception_raised(&ex) ) { *fps = libvlc_media_player_get_fps(p_md, &ex); libvlc_media_player_release(p_md); if( ! libvlc_exception_raised(&ex) ) { return NOERROR; } } _p_instance->setErrorInfo(IID_IVLCInput, libvlc_exception_get_message(&ex)); libvlc_exception_clear(&ex); return E_FAIL; } return hr;};STDMETHODIMP VLCInput::get_hasVout(VARIANT_BOOL* hasVout){ if( NULL == hasVout ) 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; p_md = libvlc_playlist_get_media_player(p_libvlc, &ex); if( ! libvlc_exception_raised(&ex) ) { *hasVout = libvlc_media_player_has_vout(p_md, &ex) ? VARIANT_TRUE : VARIANT_FALSE; libvlc_media_player_release(p_md); if( ! libvlc_exception_raised(&ex) ) { return NOERROR; } } _p_instance->setErrorInfo(IID_IVLCInput, libvlc_exception_get_message(&ex)); libvlc_exception_clear(&ex); return E_FAIL; } return hr;};/*******************************************************************************/VLCLog::~VLCLog(){ delete _p_vlcmessages; if( _p_log ) libvlc_log_close(_p_log, NULL); if( _p_typeinfo ) _p_typeinfo->Release();};HRESULT VLCLog::loadTypeInfo(void){ 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_IVLCLog, &_p_typeinfo); if( FAILED(hr) ) { _p_typeinfo = NULL; } p_typelib->Release(); } } return hr;};STDMETHODIMP VLCLog::GetTypeInfoCount(UINT* pctInfo){ if( NULL == pctInfo ) return E_INVALIDARG; if( SUCCEEDED(loadTypeInfo()) ) *pctInfo = 1; else *pctInfo = 0; return NOERROR;};STDMETHODIMP VLCLog::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 VLCLog::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 VLCLog::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 VLCLog::get_messages(IVLCMessages** obj){ if( NULL == obj ) return E_POINTER; *obj = _p_vlcmessages; if( NULL != _p_vlcmessages ) { _p_vlcmessages->AddRef(); return NOERROR; } return E_OUTOFMEMORY;};STDMETHODIMP VLCLog::get_verbosity(long* level){ if( NULL == level ) return E_POINTER; if( _p_log ) { libvlc_instance_t* p_libvlc; HRESULT hr = _p_instance->getVLC(&p_libvlc); if( SUCCEEDED(hr) ) { libvlc_exception_t ex; libvlc_exception_init(&ex); *level = libvlc_get_log_verbosity(p_libvlc, &ex); if( libvlc_exception_raised(&ex) ) { _p_instance->setErrorInfo(IID_IVLCLog, libvlc_exception_get_message(&ex)); libvlc_exception_clear(&ex); return E_FAIL; } } return hr; } else { /* log is not enabled, return -1 */ *level = -1; return NOERROR; }};STDMETHODIMP VLCLog::put_verbosity(long verbosity){ libvlc_exception_t ex; libvlc_exception_init(&ex); libvlc_instance_t* p_libvlc; HRESULT hr = _p_instance->getVLC(&p_libvlc); if( SUCCEEDED(hr) ) { if( verbosity >= 0 ) { if( ! _p_log ) { _p_log = libvlc_log_open(p_libvlc, &ex); if( libvlc_exception_raised(&ex) ) { _p_instance->setErrorInfo(IID_IVLCLog, libvlc_exception_get_message(&ex)); libvlc_exception_clear(&ex); return E_FAIL; } } libvlc_set_log_verbosity(p_libvlc, (unsigned)verbosity, &ex); if( libvlc_exception_raised(&ex) ) { _p_instance->setErrorInfo(IID_IVLCLog, libvlc_exception_get_message(&ex)); libvlc_exception_clear(&ex); return E_FAIL; } } else if( _p_log ) { /* close log when verbosity is set to -1 */ libvlc_log_close(_p_log, &ex); _p_log = NULL; if( libvlc_exception_raised(&ex) ) { _p_instance->setErrorInfo(IID_IVLCLog, libvlc_exception_get_message(&ex)); libvlc_exception_clear(&ex); return E_FAIL; } } } return hr;};/*******************************************************************************//* STL forward iterator used by VLCEnumIterator class to implement IEnumVARIANT */class VLCMessageSTLIterator{public: VLCMessageSTLIterator(IVLCMessageIterator* iter) : iter(iter), msg(NULL) { // get first message operator++(); }; VLCMessageSTLIterator(const VLCMessageSTLIterator& other) { iter = other.iter; if( iter ) iter->AddRef(); msg = other.msg; if( msg ) msg->AddRef(); }; virtual ~VLCMessageSTLIterator() { if( msg ) msg->Release(); if( iter ) iter->Release(); }; // we only need prefix ++ operator VLCMessageSTLIterator& operator++() { VARIANT_BOOL hasNext = VARIANT_FALSE; if( iter ) { iter->get_hasNext(&hasNext); if( msg ) { msg->Release(); msg = NULL; } if( VARIANT_TRUE == hasNext ) { iter->next(&msg); } } return *this; }; VARIANT operator*() const { VARIANT v; VariantInit(&v); if( msg ) { if( SUCCEEDED(msg->QueryInterface(IID_IDispatch, (LPVOID*)&V_DISPATCH(&v))) ) { V_VT(&v) = VT_DISPATCH; } } return v; }; bool operator==(const VLCMessageSTLIterator& other) const { return msg == other.msg; }; bool operator!=(const VLCMessageSTLIterator& other) const { return msg != other.msg; };private: IVLCMessageIterator* iter; IVLCMessage* msg;};////////////////////////////////////////////////////////////////////////////////////////////////////////////VLCMessages::~VLCMessages(){ if( _p_typeinfo ) _p_typeinfo->Release();};HRESULT VLCMessages::loadTypeInfo(void){ 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_IVLCMessages, &_p_typeinfo); if( FAILED(hr) ) { _p_typeinfo = NULL; } p_typelib->Release(); } } return hr;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -