* Copyright (C) 2006 the VideoLAN team
*
* Authors: Damien Fouilleul <Damien.Fouilleul@laposte.net>
+ * Jean-Paul Saman <jpsaman _at_ m2x _dot_ nl>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include <shlwapi.h>
#include <wininet.h>
+#include <tchar.h>
using namespace std;
return E_NOTIMPL;
};
-STDMETHODIMP VLCAudio::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
+STDMETHODIMP VLCAudio::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
UINT cNames, LCID lcid, DISPID* rgDispID)
{
if( SUCCEEDED(loadTypeInfo()) )
libvlc_audio_set_volume(p_libvlc, volume, &ex);
if( libvlc_exception_raised(&ex) )
{
- _p_instance->setErrorInfo(IID_IVLCAudio, libvlc_exception_get_message(&ex));
+ _p_instance->setErrorInfo(IID_IVLCAudio,
+ libvlc_exception_get_message(&ex));
+ libvlc_exception_clear(&ex);
+ return E_FAIL;
+ }
+ return NOERROR;
+ }
+ return hr;
+};
+
+STDMETHODIMP VLCAudio::get_track(long* track)
+{
+ if( NULL == track )
+ 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_input_t *p_input = libvlc_playlist_get_input(p_libvlc, &ex);
+ *track = libvlc_audio_get_track(p_input, &ex);
+ libvlc_input_free(p_input);
+ if( libvlc_exception_raised(&ex) )
+ {
+ _p_instance->setErrorInfo(IID_IVLCAudio,
+ libvlc_exception_get_message(&ex));
+ libvlc_exception_clear(&ex);
+ return E_FAIL;
+ }
+ return NOERROR;
+ }
+ return hr;
+};
+
+STDMETHODIMP VLCAudio::put_track(long track)
+{
+ libvlc_instance_t* p_libvlc;
+ HRESULT hr = _p_instance->getVLC(&p_libvlc);
+ if( SUCCEEDED(hr) )
+ {
+ libvlc_exception_t ex;
+ libvlc_exception_init(&ex);
+
+ libvlc_input_t *p_input = libvlc_playlist_get_input(p_libvlc, &ex);
+ libvlc_audio_set_track(p_input, track, &ex);
+ libvlc_input_free(p_input);
+ if( libvlc_exception_raised(&ex) )
+ {
+ _p_instance->setErrorInfo(IID_IVLCAudio,
+ libvlc_exception_get_message(&ex));
+ libvlc_exception_clear(&ex);
+ return E_FAIL;
+ }
+ return NOERROR;
+ }
+ return hr;
+};
+
+STDMETHODIMP VLCAudio::get_channel(long *channel)
+{
+ if( NULL == channel )
+ 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);
+
+ *channel = libvlc_audio_get_channel(p_libvlc, &ex);
+ if( libvlc_exception_raised(&ex) )
+ {
+ _p_instance->setErrorInfo(IID_IVLCAudio,
+ libvlc_exception_get_message(&ex));
+ libvlc_exception_clear(&ex);
+ return E_FAIL;
+ }
+ return NOERROR;
+ }
+ return hr;
+};
+
+STDMETHODIMP VLCAudio::put_channel(long channel)
+{
+ libvlc_instance_t* p_libvlc;
+ HRESULT hr = _p_instance->getVLC(&p_libvlc);
+ if( SUCCEEDED(hr) )
+ {
+ libvlc_exception_t ex;
+ libvlc_exception_init(&ex);
+
+ libvlc_audio_set_channel(p_libvlc, channel, &ex);
+ if( libvlc_exception_raised(&ex) )
+ {
+ _p_instance->setErrorInfo(IID_IVLCAudio,
+ libvlc_exception_get_message(&ex));
libvlc_exception_clear(&ex);
return E_FAIL;
}
libvlc_audio_toggle_mute(p_libvlc, &ex);
if( libvlc_exception_raised(&ex) )
{
- _p_instance->setErrorInfo(IID_IVLCAudio, libvlc_exception_get_message(&ex));
+ _p_instance->setErrorInfo(IID_IVLCAudio,
+ libvlc_exception_get_message(&ex));
libvlc_exception_clear(&ex);
return E_FAIL;
}
return E_NOTIMPL;
};
-STDMETHODIMP VLCInput::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
+STDMETHODIMP VLCInput::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
UINT cNames, LCID lcid, DISPID* rgDispID)
{
if( SUCCEEDED(loadTypeInfo()) )
if( NULL == fps )
return E_POINTER;
+ *fps = 0.0;
libvlc_instance_t* p_libvlc;
HRESULT hr = _p_instance->getVLC(&p_libvlc);
if( SUCCEEDED(hr) )
return E_NOTIMPL;
};
-STDMETHODIMP VLCLog::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
+STDMETHODIMP VLCLog::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
UINT cNames, LCID lcid, DISPID* rgDispID)
{
if( SUCCEEDED(loadTypeInfo()) )
/*******************************************************************************/
+/* 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 )
return E_NOTIMPL;
};
-STDMETHODIMP VLCMessages::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
+STDMETHODIMP VLCMessages::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
UINT cNames, LCID lcid, DISPID* rgDispID)
{
if( SUCCEEDED(loadTypeInfo()) )
if( NULL == _NewEnum )
return E_POINTER;
- // TODO
- *_NewEnum = NULL;
- return E_NOTIMPL;
+ IVLCMessageIterator* iter = NULL;
+ iterator(&iter);
+
+ *_NewEnum= new VLCEnumIterator<IID_IEnumVARIANT,
+ IEnumVARIANT,
+ VARIANT,
+ VLCMessageSTLIterator>
+ (VLCMessageSTLIterator(iter), VLCMessageSTLIterator(NULL));
+
+ return *_NewEnum ? S_OK : E_OUTOFMEMORY;
};
STDMETHODIMP VLCMessages::clear()
return E_NOTIMPL;
};
-STDMETHODIMP VLCMessageIterator::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
+STDMETHODIMP VLCMessageIterator::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
UINT cNames, LCID lcid, DISPID* rgDispID)
{
if( SUCCEEDED(loadTypeInfo()) )
return E_NOTIMPL;
};
-STDMETHODIMP VLCMessage::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
+STDMETHODIMP VLCMessage::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
UINT cNames, LCID lcid, DISPID* rgDispID)
{
if( SUCCEEDED(loadTypeInfo()) )
return E_NOTIMPL;
};
-STDMETHODIMP VLCPlaylistItems::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
+STDMETHODIMP VLCPlaylistItems::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
UINT cNames, LCID lcid, DISPID* rgDispID)
{
if( SUCCEEDED(loadTypeInfo()) )
return E_NOTIMPL;
};
-STDMETHODIMP VLCPlaylist::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
+STDMETHODIMP VLCPlaylist::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
UINT cNames, LCID lcid, DISPID* rgDispID)
{
if( SUCCEEDED(loadTypeInfo()) )
}
*item = libvlc_playlist_add_extended(p_libvlc,
- psz_uri,
- psz_name,
- i_options,
- const_cast<const char **>(ppsz_options),
- &ex);
+ psz_uri,
+ psz_name,
+ i_options,
+ const_cast<const char **>(ppsz_options),
+ &ex);
VLCControl::FreeTargetOptions(ppsz_options, i_options);
CoTaskMemFree(psz_uri);
return E_NOTIMPL;
};
-STDMETHODIMP VLCVideo::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
+STDMETHODIMP VLCVideo::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
UINT cNames, LCID lcid, DISPID* rgDispID)
{
if( SUCCEEDED(loadTypeInfo()) )
if( NULL == psz_aspect )
return E_OUTOFMEMORY;
- *aspect = SysAllocStringByteLen(psz_aspect, strlen(psz_aspect));
+ *aspect = BSTRFromCStr(CP_UTF8, psz_aspect);
free( psz_aspect );
psz_aspect = NULL;
- return NOERROR;
+ return (NULL == *aspect) ? E_OUTOFMEMORY : NOERROR;
}
if( psz_aspect ) free( psz_aspect );
+ psz_aspect = NULL;
}
_p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
libvlc_exception_clear(&ex);
HRESULT hr = _p_instance->getVLC(&p_libvlc);
if( SUCCEEDED(hr) )
{
- char *psz_aspect = NULL;
libvlc_exception_t ex;
libvlc_exception_init(&ex);
libvlc_input_t *p_input = libvlc_playlist_get_input(p_libvlc, &ex);
if( ! libvlc_exception_raised(&ex) )
{
- psz_aspect = CStrFromBSTR(CP_UTF8, aspect);
+ char *psz_aspect = CStrFromBSTR(CP_UTF8, aspect);
if( NULL == psz_aspect )
{
return E_OUTOFMEMORY;
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_input_t *p_input = libvlc_playlist_get_input(p_libvlc, &ex);
+ if( ! libvlc_exception_raised(&ex) )
+ {
+ *spu = libvlc_video_get_spu(p_input, &ex);
+ libvlc_input_free(p_input);
+ 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_input_t *p_input = libvlc_playlist_get_input(p_libvlc, &ex);
+ libvlc_video_set_spu(p_input, spu, &ex);
+ libvlc_input_free(p_input);
+ 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_input_t *p_input = libvlc_playlist_get_input(p_libvlc, &ex);
+ if( ! libvlc_exception_raised(&ex) )
+ {
+ char *psz_geometry = libvlc_video_get_crop_geometry(p_input, &ex);
+
+ libvlc_input_free(p_input);
+ 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;
+ }
+ if( psz_geometry ) 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_input_t *p_input = libvlc_playlist_get_input(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_input, psz_geometry, &ex);
+
+ CoTaskMemFree(psz_geometry);
+ libvlc_input_free(p_input);
+ 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_input_t *p_input = libvlc_playlist_get_input(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 storage for UTF8 string */
+ char *psz_filepath = (char *)path;
+ WCHAR* wpath = filepath;
+#else
+ char *psz_filepath = path;
+ /* first convert to unicode using current code page */
+ WCHAR wpath[MAX_PATH+1];
+ if( 0 == MultiByteToWideChar(CP_ACP, 0, filepath, -1, wpath, sizeof(wpath)/sizeof(WCHAR)) )
+ return E_FAIL;
+#endif
+ /* convert to UTF8 */
+ pathlen = WideCharToMultiByte(CP_UTF8, 0, wpath, -1, psz_filepath, sizeof(path), NULL, NULL);
+ // fail if path is 0 or too short (i.e pathlen is the same as storage size)
+ if( (0 == pathlen) || (sizeof(path) == pathlen) )
+ return E_FAIL;
+
+ /* take snapshot into file */
+ libvlc_video_take_snapshot(p_input, psz_filepath, &ex);
+ libvlc_input_free(p_input);
+ if( ! libvlc_exception_raised(&ex) )
+ {
+ hr = E_FAIL;
+ /* open snapshot file */
+ HANDLE snapPic = LoadImage(NULL, filepath, IMAGE_BITMAP,0, 0, LR_CREATEDIBSECTION|LR_LOADFROMFILE);
+ if( snapPic )
+ {
+ PICTDESC snapDesc;
+
+ snapDesc.cbSizeofstruct = sizeof(PICTDESC);
+ snapDesc.picType = PICTYPE_BITMAP;
+ snapDesc.bmp.hbitmap = (HBITMAP)snapPic;
+ snapDesc.bmp.hpal = NULL;
+
+ hr = OleCreatePictureIndirect(&snapDesc, IID_IPictureDisp, TRUE, (LPVOID*)picture);
+ if( FAILED(hr) )
+ {
+ *picture = NULL;
+ DeleteObject(snapPic);
+ }
+ }
+ DeleteFile(filepath);
+ return hr;
+ }
+ }
+ _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
+ libvlc_exception_clear(&ex);
+ return E_FAIL;
+ }
+ return hr;
+};
+
STDMETHODIMP VLCVideo::toggleFullscreen()
{
libvlc_instance_t* p_libvlc;
return E_NOTIMPL;
};
-STDMETHODIMP VLCControl2::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
+STDMETHODIMP VLCControl2::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
UINT cNames, LCID lcid, DISPID* rgDispID)
{
if( SUCCEEDED(loadTypeInfo()) )
return S_OK;
};
-
+
STDMETHODIMP VLCControl2::put_StartTime(long seconds)
{
_p_instance->setStartTime(seconds);
return NOERROR;
};
-
+
STDMETHODIMP VLCControl2::get_VersionInfo(BSTR *version)
{
if( NULL == version )
const char *versionStr = VLC_Version();
if( NULL != versionStr )
{
- *version = BSTRFromCStr(_p_instance->getCodePage(), versionStr);
-
+ *version = BSTRFromCStr(CP_UTF8, versionStr);
+
return NULL == *version ? E_OUTOFMEMORY : NOERROR;
}
*version = NULL;
return E_FAIL;
};
-
+
STDMETHODIMP VLCControl2::get_Visible(VARIANT_BOOL *isVisible)
{
if( NULL == isVisible )
return NOERROR;
};
-
+
STDMETHODIMP VLCControl2::put_Visible(VARIANT_BOOL isVisible)
{
_p_instance->setVisible(isVisible != VARIANT_FALSE);
*volume = _p_instance->getVolume();
return NOERROR;
};
-
+
STDMETHODIMP VLCControl2::put_Volume(long volume)
{
_p_instance->setVolume(volume);
}
return E_OUTOFMEMORY;
};
-