Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

vlccontrol.cpp

00001 /*****************************************************************************
00002  * vlccontrol.cpp: ActiveX control for VLC
00003  *****************************************************************************
00004  * Copyright (C) 2005 the VideoLAN team
00005  *
00006  * Authors: Damien Fouilleul <[email protected]>
00007  *
00008  * This program is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * This program is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program; if not, write to the Free Software
00020  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00021  *****************************************************************************/
00022 
00023 #include "plugin.h"
00024 #include "vlccontrol.h"
00025 
00026 #include "utils.h"
00027 
00028 using namespace std;
00029 
00030 VLCControl::~VLCControl()
00031 {
00032     if( _p_typeinfo )
00033         _p_typeinfo->Release();
00034 };
00035 
00036 HRESULT VLCControl::getTypeInfo(void)
00037 {
00038     HRESULT hr = NOERROR;
00039     if( NULL == _p_typeinfo )
00040     {
00041         ITypeLib *p_typelib;
00042 
00043         HRESULT hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
00044         if( SUCCEEDED(hr) )
00045         {
00046             hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCControl, &_p_typeinfo);
00047             if( FAILED(hr) )
00048             {
00049                 _p_typeinfo = NULL;
00050             }
00051             p_typelib->Release();
00052         }
00053     }
00054     return hr;
00055 };
00056 
00057 STDMETHODIMP VLCControl::GetTypeInfoCount(UINT* pctInfo)
00058 {
00059     if( NULL == pctInfo )
00060         return E_INVALIDARG;
00061 
00062     if( SUCCEEDED(getTypeInfo()) )
00063         *pctInfo = 1;
00064     else
00065         *pctInfo = 0;
00066 
00067     return NOERROR;
00068 };
00069 
00070 STDMETHODIMP VLCControl::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
00071 {
00072     if( NULL == ppTInfo )
00073         return E_INVALIDARG;
00074 
00075     if( SUCCEEDED(getTypeInfo()) )
00076     {
00077         _p_typeinfo->AddRef();
00078         *ppTInfo = _p_typeinfo;
00079         return NO_ERROR;
00080     }
00081     *ppTInfo = NULL;
00082     return E_NOTIMPL;
00083 };
00084 
00085 STDMETHODIMP VLCControl::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames, 
00086         UINT cNames, LCID lcid, DISPID* rgDispID)
00087 {
00088     if( SUCCEEDED(getTypeInfo()) )
00089     {
00090         return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
00091     }
00092     return E_NOTIMPL;
00093 };
00094 
00095 STDMETHODIMP VLCControl::Invoke(DISPID dispIdMember, REFIID riid,
00096         LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
00097         VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
00098 {
00099     if( SUCCEEDED(getTypeInfo()) )
00100     {
00101         return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
00102                 pVarResult, pExcepInfo, puArgErr);
00103     }
00104     return E_NOTIMPL;
00105 };
00106 
00107 STDMETHODIMP VLCControl::get_Visible(VARIANT_BOOL *isVisible)
00108 {
00109     if( NULL == isVisible )
00110         return E_POINTER;
00111 
00112     *isVisible = _p_instance->getVisible() ? VARIANT_TRUE : VARIANT_FALSE;
00113 
00114     return NOERROR;
00115 };
00116         
00117 STDMETHODIMP VLCControl::put_Visible(VARIANT_BOOL isVisible)
00118 {
00119     _p_instance->setVisible(isVisible != VARIANT_FALSE);
00120 
00121     return NOERROR;
00122 };
00123 
00124 STDMETHODIMP VLCControl::play(void)
00125 {
00126     int i_vlc = _p_instance->getVLCObject();
00127     if( i_vlc )
00128     {
00129         VLC_Play(i_vlc);
00130         _p_instance->fireOnPlayEvent();
00131         return NOERROR;
00132     }
00133     return E_UNEXPECTED;
00134 };
00135  
00136 STDMETHODIMP VLCControl::pause(void)
00137 {
00138     int i_vlc = _p_instance->getVLCObject();
00139     if( i_vlc )
00140     {
00141         VLC_Pause(i_vlc);
00142         _p_instance->fireOnPauseEvent();
00143         return NOERROR;
00144     }
00145     return E_UNEXPECTED;
00146 };
00147         
00148 STDMETHODIMP VLCControl::stop(void)
00149 {
00150     int i_vlc = _p_instance->getVLCObject();
00151     if( i_vlc )
00152     {
00153         VLC_Stop(i_vlc);
00154         _p_instance->fireOnStopEvent();
00155         return NOERROR;
00156     }
00157     return E_UNEXPECTED;
00158 };
00159         
00160 STDMETHODIMP VLCControl::get_Playing(VARIANT_BOOL *isPlaying)
00161 {
00162     if( NULL == isPlaying )
00163         return E_POINTER;
00164 
00165     int i_vlc = _p_instance->getVLCObject();
00166     if( i_vlc )
00167     {
00168         *isPlaying = VLC_IsPlaying(i_vlc) ? VARIANT_TRUE : VARIANT_FALSE;
00169         return NOERROR;
00170     }
00171     *isPlaying = VARIANT_FALSE;
00172     return E_UNEXPECTED;
00173 };
00174         
00175 STDMETHODIMP VLCControl::get_Position(float *position)
00176 {
00177     if( NULL == position )
00178         return E_POINTER;
00179 
00180     int i_vlc = _p_instance->getVLCObject();
00181     if( i_vlc )
00182     {
00183         *position = VLC_PositionGet(i_vlc);
00184         return NOERROR;
00185     }
00186     *position = 0.0f;
00187     return E_UNEXPECTED;
00188 };
00189         
00190 STDMETHODIMP VLCControl::put_Position(float position)
00191 {
00192     int i_vlc = _p_instance->getVLCObject();
00193     if( i_vlc )
00194     {
00195         VLC_PositionSet(i_vlc, position);
00196         return NOERROR;
00197     }
00198     return E_UNEXPECTED;
00199 };
00200         
00201 STDMETHODIMP VLCControl::get_Time(int *seconds)
00202 {
00203     if( NULL == seconds )
00204         return E_POINTER;
00205 
00206     int i_vlc = _p_instance->getVLCObject();
00207     if( i_vlc )
00208     {
00209         *seconds = VLC_TimeGet(i_vlc);
00210         return NOERROR;
00211     }
00212     *seconds = 0;
00213     return E_UNEXPECTED;
00214 };
00215         
00216 STDMETHODIMP VLCControl::put_Time(int seconds)
00217 {
00218     int i_vlc = _p_instance->getVLCObject();
00219     if( i_vlc )
00220     {
00221         VLC_TimeSet(i_vlc, seconds, VLC_FALSE);
00222         return NOERROR;
00223     }
00224     return E_UNEXPECTED;
00225 };
00226         
00227 STDMETHODIMP VLCControl::shuttle(int seconds)
00228 {
00229     int i_vlc = _p_instance->getVLCObject();
00230     if( i_vlc )
00231     {
00232         VLC_TimeSet(i_vlc, seconds, VLC_TRUE);
00233         return NOERROR;
00234     }
00235     return E_UNEXPECTED;
00236 };
00237         
00238 STDMETHODIMP VLCControl::fullscreen(void)
00239 {
00240     int i_vlc = _p_instance->getVLCObject();
00241     if( i_vlc )
00242     {
00243         VLC_FullScreen(i_vlc);
00244         return NOERROR;
00245     }
00246     return E_UNEXPECTED;
00247 };
00248         
00249 STDMETHODIMP VLCControl::get_Length(int *seconds)
00250 {
00251     if( NULL == seconds )
00252         return E_POINTER;
00253 
00254     int i_vlc = _p_instance->getVLCObject();
00255     if( i_vlc )
00256     {
00257         *seconds = VLC_LengthGet(i_vlc);
00258         return NOERROR;
00259     }
00260     *seconds = 0;
00261     return E_UNEXPECTED;
00262 };
00263         
00264 STDMETHODIMP VLCControl::playFaster(void)
00265 {
00266     int i_vlc = _p_instance->getVLCObject();
00267     if( i_vlc )
00268     {
00269         VLC_SpeedFaster(i_vlc);
00270         return NOERROR;
00271     }
00272     return E_UNEXPECTED;
00273 };
00274         
00275 STDMETHODIMP VLCControl::playSlower(void)
00276 {
00277     int i_vlc = _p_instance->getVLCObject();
00278     if( i_vlc )
00279     {
00280         VLC_SpeedSlower(i_vlc);
00281         return NOERROR;
00282     }
00283     return E_UNEXPECTED;
00284 };
00285         
00286 STDMETHODIMP VLCControl::get_Volume(int *volume)
00287 {
00288     if( NULL == volume )
00289         return E_POINTER;
00290 
00291     int i_vlc = _p_instance->getVLCObject();
00292     if( i_vlc )
00293     {
00294         *volume  = VLC_VolumeGet(i_vlc);
00295         return NOERROR;
00296     }
00297     *volume = 0;
00298     return E_UNEXPECTED;
00299 };
00300         
00301 STDMETHODIMP VLCControl::put_Volume(int volume)
00302 {
00303     int i_vlc = _p_instance->getVLCObject();
00304     if( i_vlc )
00305     {
00306         VLC_VolumeSet(i_vlc, volume);
00307         return NOERROR;
00308     }
00309     return E_UNEXPECTED;
00310 };
00311         
00312 STDMETHODIMP VLCControl::toggleMute(void)
00313 {
00314     int i_vlc = _p_instance->getVLCObject();
00315     if( i_vlc )
00316     {
00317         VLC_VolumeMute(i_vlc);
00318         return NOERROR;
00319     }
00320     return E_UNEXPECTED;
00321 };
00322 
00323 STDMETHODIMP VLCControl::setVariable(BSTR name, VARIANT value)
00324 {
00325     if( 0 == SysStringLen(name) )
00326         return E_INVALIDARG;
00327 
00328     int i_vlc = _p_instance->getVLCObject();
00329     if( i_vlc )
00330     {
00331         int codePage = _p_instance->getCodePage();
00332         char *psz_varname = CStrFromBSTR(codePage, name);
00333         if( NULL == psz_varname )
00334             return E_OUTOFMEMORY;
00335 
00336         HRESULT hr = E_INVALIDARG;
00337         int i_type;
00338         vlc_value_t val;
00339         
00340         if( VLC_SUCCESS == VLC_VariableType(i_vlc, psz_varname, &i_type) )
00341         {
00342             VARIANT arg;
00343             VariantInit(&arg);
00344 
00345             switch( i_type )
00346             {
00347                 case VLC_VAR_BOOL:
00348                     hr = VariantChangeType(&arg, &value, 0, VT_BOOL);
00349                     if( SUCCEEDED(hr) )
00350                         val.b_bool = (VARIANT_TRUE == V_BOOL(&arg)) ? VLC_TRUE : VLC_FALSE;
00351                     break;
00352 
00353                 case VLC_VAR_INTEGER:
00354                 case VLC_VAR_HOTKEY:
00355                     hr = VariantChangeType(&arg, &value, 0, VT_I4);
00356                     if( SUCCEEDED(hr) )
00357                         val.i_int = V_I4(&arg);
00358                     break;
00359 
00360                 case VLC_VAR_FLOAT:
00361                     hr = VariantChangeType(&arg, &value, 0, VT_R4);
00362                     if( SUCCEEDED(hr) )
00363                         val.f_float = V_R4(&arg);
00364                     break;
00365 
00366                 case VLC_VAR_STRING:
00367                 case VLC_VAR_MODULE:
00368                 case VLC_VAR_FILE:
00369                 case VLC_VAR_DIRECTORY:
00370                 case VLC_VAR_VARIABLE:
00371                     hr = VariantChangeType(&arg, &value, 0, VT_BSTR);
00372                     if( SUCCEEDED(hr) )
00373                     {
00374                         val.psz_string = CStrFromBSTR(codePage, V_BSTR(&arg));
00375                         VariantClear(&arg);
00376                     }
00377                     break;
00378 
00379                 case VLC_VAR_TIME:
00380                     // use a double value to represent time (base is expressed in seconds)
00381                     hr = VariantChangeType(&arg, &value, 0, VT_R8);
00382                     if( SUCCEEDED(hr) )
00383                         val.i_time = (signed __int64)(V_R8(&arg)*1000000.0);
00384                     break;
00385 
00386                 default:
00387                     hr = DISP_E_TYPEMISMATCH;
00388             }
00389         }
00390         else {
00391             // no defined type, defaults to VARIANT type
00392             hr = NO_ERROR;
00393             switch( V_VT(&value) )
00394             {
00395                 case VT_BOOL:
00396                     val.b_bool = (VARIANT_TRUE == V_BOOL(&value)) ? VLC_TRUE : VLC_FALSE;
00397                     i_type = VLC_VAR_BOOL;
00398                     break;
00399                 case VT_I4:
00400                     val.i_int = V_I4(&value);
00401                     i_type = VLC_VAR_INTEGER;
00402                     break;
00403                 case VT_R4:
00404                     val.f_float = V_R4(&value);
00405                     i_type = VLC_VAR_FLOAT;
00406                     break;
00407                 case VT_BSTR:
00408                     val.psz_string = CStrFromBSTR(codePage, V_BSTR(&value));
00409                     i_type = VLC_VAR_STRING;
00410                     break;
00411                 case VT_R8:
00412                     // use a double value to represent time (base is expressed in seconds)
00413                     val.i_time = (signed __int64)(V_R8(&value)*1000000.0);
00414                     i_type = VLC_VAR_TIME;
00415                     break;
00416                 default:
00417                     hr = DISP_E_TYPEMISMATCH;
00418             }
00419         }
00420         if( SUCCEEDED(hr) )
00421         {
00422             hr = (VLC_SUCCESS == VLC_VariableSet(i_vlc, psz_varname, val)) ? NOERROR : E_FAIL;
00423 
00424             if( (VLC_VAR_STRING == i_type) && (NULL != val.psz_string) )
00425                 CoTaskMemFree(val.psz_string);
00426         }
00427         CoTaskMemFree(psz_varname);
00428 
00429         return hr;
00430     }
00431     return E_UNEXPECTED;
00432 };
00433 
00434 STDMETHODIMP VLCControl::getVariable( BSTR name, VARIANT *value)
00435 {
00436     if( NULL == value )
00437         return E_POINTER;
00438 
00439     VariantInit(value);
00440 
00441     if( 0 == SysStringLen(name) )
00442         return E_INVALIDARG;
00443 
00444     int i_vlc = _p_instance->getVLCObject();
00445     if( i_vlc )
00446     {
00447         UINT codePage = _p_instance->getCodePage();
00448         char *psz_varname = CStrFromBSTR(codePage, name);
00449         if( NULL == psz_varname )
00450             return E_OUTOFMEMORY;
00451 
00452         HRESULT hr = E_INVALIDARG;
00453 
00454         vlc_value_t val;
00455         int i_type;
00456 
00457         if( (VLC_SUCCESS == VLC_VariableGet(i_vlc, psz_varname, &val))
00458          && (VLC_SUCCESS == VLC_VariableType(i_vlc, psz_varname, &i_type)) )
00459         {
00460             hr = NOERROR;
00461             switch( i_type )
00462             {
00463                 case VLC_VAR_BOOL:
00464                     V_VT(value) = VT_BOOL;
00465                     V_BOOL(value) = val.b_bool ? VARIANT_TRUE : VARIANT_FALSE;
00466                     break;
00467 
00468                 case VLC_VAR_INTEGER:
00469                 case VLC_VAR_HOTKEY:
00470                     V_VT(value) = VT_I4;
00471                     V_I4(value) = val.i_int;
00472                     break;
00473 
00474                 case VLC_VAR_FLOAT:
00475                     V_VT(value) = VT_R4;
00476                     V_R4(value) = val.f_float;
00477                     break;
00478 
00479                 case VLC_VAR_STRING:
00480                 case VLC_VAR_MODULE:
00481                 case VLC_VAR_FILE:
00482                 case VLC_VAR_DIRECTORY:
00483                 case VLC_VAR_VARIABLE:
00484                     V_VT(value) = VT_BSTR;
00485                     V_BSTR(value) = BSTRFromCStr(codePage, val.psz_string);
00486                     if( NULL != val.psz_string)
00487                         free(val.psz_string);
00488                     break;
00489 
00490                 case VLC_VAR_TIME:
00491                     // use a double value to represent time (base is expressed in seconds)
00492                     V_VT(value) = VT_R8;
00493                     V_R8(value) = ((double)val.i_time)/1000000.0;
00494                     break;
00495 
00496                 default:
00497                     hr = DISP_E_TYPEMISMATCH;
00498             }
00499         }
00500         CoTaskMemFree(psz_varname);
00501         return hr;
00502     }
00503     return E_UNEXPECTED;
00504 };
00505 
00506 static void freeTargetOptions(char **cOptions, int cOptionCount)
00507 {
00508     // clean up 
00509     if( NULL != cOptions )
00510     {
00511         for( int pos=0; pos<cOptionCount; ++pos )
00512         {
00513             char *cOption = cOptions[pos];
00514             if( NULL != cOption )
00515                 CoTaskMemFree(cOption);
00516             else
00517                 break;
00518         }
00519         CoTaskMemFree(cOptions);
00520     }
00521 };
00522 
00523 static HRESULT createTargetOptions(int codePage, VARIANT *options, char ***cOptions, int *cOptionCount)
00524 {
00525     HRESULT hr = E_INVALIDARG;
00526     if( VT_ERROR == V_VT(options) )
00527     {
00528         if( DISP_E_PARAMNOTFOUND == V_ERROR(options) )
00529         {
00530             // optional parameter not set
00531             *cOptions = NULL;
00532             *cOptionCount = 0;
00533             return NOERROR;
00534         }
00535     }
00536     else if( (VT_EMPTY == V_VT(options)) || (VT_NULL == V_VT(options)) )
00537     {
00538         // null parameter
00539         *cOptions = NULL;
00540         *cOptionCount = 0;
00541         return NOERROR;
00542     }
00543     else if( VT_DISPATCH == V_VT(options) )
00544     {
00545         // collection parameter
00546         VARIANT colEnum;
00547         V_VT(&colEnum) = VT_UNKNOWN;
00548         hr = GetObjectProperty(V_DISPATCH(options), DISPID_NEWENUM, colEnum);
00549         if( SUCCEEDED(hr) )
00550         {
00551             IEnumVARIANT *enumVar;
00552             hr = V_UNKNOWN(&colEnum)->QueryInterface(IID_IEnumVARIANT, (LPVOID *)&enumVar);
00553             if( SUCCEEDED(hr) )
00554             {
00555                 long pos = 0;
00556                 long capacity = 16;
00557                 VARIANT option;
00558 
00559                 *cOptions = (char **)CoTaskMemAlloc(capacity*sizeof(char *));
00560                 if( NULL != *cOptions )
00561                 {
00562                     ZeroMemory(*cOptions, sizeof(char *)*capacity);
00563                     while( SUCCEEDED(hr) && (S_OK == enumVar->Next(1, &option, NULL)) )
00564                     {
00565                         if( VT_BSTR == V_VT(&option) )
00566                         {
00567                             char *cOption = CStrFromBSTR(codePage, V_BSTR(&option));
00568                             (*cOptions)[pos] = cOption;
00569                             if( NULL != cOption )
00570                             {
00571                                 ++pos;
00572                                 if( pos == capacity )
00573                                 {
00574                                     char **moreOptions = (char **)CoTaskMemRealloc(*cOptions, (capacity+16)*sizeof(char *));
00575                                     if( NULL != moreOptions )
00576                                     {
00577                                         ZeroMemory(moreOptions+capacity, sizeof(char *)*16);
00578                                         capacity += 16;
00579                                         *cOptions = moreOptions;
00580                                     }
00581                                     else
00582                                         hr = E_OUTOFMEMORY;
00583                                 }
00584                             }
00585                             else
00586                                 hr = ( SysStringLen(V_BSTR(&option)) > 0 ) ?
00587                                     E_OUTOFMEMORY : E_INVALIDARG;
00588                         }
00589                         else
00590                             hr = E_INVALIDARG;
00591 
00592                         VariantClear(&option);
00593                     }
00594                     *cOptionCount = pos;
00595                     if( FAILED(hr) )
00596                     {
00597                         // free already processed elements
00598                         freeTargetOptions(*cOptions, *cOptionCount);
00599                     }
00600                 }
00601                 else
00602                     hr = E_OUTOFMEMORY;
00603 
00604                 enumVar->Release();
00605             }
00606         }
00607     }
00608     else if( V_ISARRAY(options) )
00609     {
00610         // array parameter
00611         SAFEARRAY *array = V_ISBYREF(options) ? *V_ARRAYREF(options) : V_ARRAY(options);
00612 
00613         if( SafeArrayGetDim(array) != 1 )
00614             return E_INVALIDARG;
00615 
00616         long lBound = 0;
00617         long uBound = 0;
00618         SafeArrayGetLBound(array, 1, &lBound);
00619         SafeArrayGetUBound(array, 1, &uBound);
00620 
00621         // have we got any options
00622         if( uBound >= lBound )
00623         {
00624             VARTYPE vType;
00625             hr = SafeArrayGetVartype(array, &vType);
00626             if( FAILED(hr) )
00627                 return hr;
00628 
00629             long pos;
00630 
00631             // marshall options into an array of C strings
00632             if( VT_VARIANT == vType )
00633             {
00634                 *cOptions = (char **)CoTaskMemAlloc(sizeof(char *)*(uBound-lBound));
00635                 if( NULL == *cOptions )
00636                     return E_OUTOFMEMORY;
00637 
00638                 ZeroMemory(*cOptions, sizeof(char *)*(uBound-lBound));
00639                 for(pos=lBound; SUCCEEDED(hr) && (pos<=uBound); ++pos )
00640                 {
00641                     VARIANT option;
00642                     hr = SafeArrayGetElement(array, &pos, &option);
00643                     if( SUCCEEDED(hr) )
00644                     {
00645                         if( VT_BSTR == V_VT(&option) ) 
00646                         {
00647                             char *cOption = CStrFromBSTR(codePage, V_BSTR(&option));
00648                             (*cOptions)[pos-lBound] = cOption;
00649                             if( NULL == cOption )
00650                                 hr = ( SysStringLen(V_BSTR(&option)) > 0 ) ?
00651                                     E_OUTOFMEMORY : E_INVALIDARG;
00652                         }
00653                         else
00654                             hr = E_INVALIDARG;
00655                         VariantClear(&option);
00656                     }
00657                 }
00658             }
00659             else if( VT_BSTR == vType )
00660             {
00661                 *cOptions = (char **)CoTaskMemAlloc(sizeof(char *)*(uBound-lBound));
00662                 if( NULL == *cOptions )
00663                     return E_OUTOFMEMORY;
00664 
00665                 ZeroMemory(*cOptions, sizeof(char *)*(uBound-lBound));
00666                 for(pos=lBound; (pos<uBound) && SUCCEEDED(hr); ++pos )
00667                 {
00668                     BSTR option;
00669                     hr = SafeArrayGetElement(array, &pos, &option);
00670                     if( SUCCEEDED(hr) )
00671                     {
00672                         char *cOption = CStrFromBSTR(codePage, option);
00673 
00674                         (*cOptions)[pos-lBound] = cOption;
00675                         if( NULL == cOption )
00676                             hr = ( SysStringLen(option) > 0 ) ?
00677                                 E_OUTOFMEMORY : E_INVALIDARG;
00678                         SysFreeString(option);
00679                     }
00680                 }
00681             }
00682             else 
00683             {
00684                 // unsupported type
00685                 return E_INVALIDARG;
00686             }
00687 
00688             *cOptionCount = pos-lBound;
00689             if( FAILED(hr) )
00690             {
00691                 // free already processed elements
00692                 freeTargetOptions(*cOptions, *cOptionCount);
00693             }
00694         }
00695         else
00696         {
00697             // empty array
00698             *cOptions = NULL;
00699             *cOptionCount = 0;
00700             return NOERROR;
00701         }
00702     }
00703     return hr;
00704 };
00705 
00706 /*
00707 ** use VARIANT rather than a SAFEARRAY as argument type
00708 ** for compatibility with some scripting language (JScript)
00709 */
00710 
00711 STDMETHODIMP VLCControl::addTarget( BSTR uri, VARIANT options, enum VLCPlaylistMode mode, int position)
00712 {
00713     if( 0 == SysStringLen(uri) )
00714         return E_INVALIDARG;
00715 
00716     HRESULT hr = E_UNEXPECTED;
00717 
00718     int i_vlc = _p_instance->getVLCObject();
00719     if( i_vlc )
00720     {
00721         char *cUri = CStrFromBSTR(CP_UTF8, uri);
00722         if( NULL == cUri )
00723             return E_OUTOFMEMORY;
00724 
00725         int cOptionsCount;
00726         char **cOptions;
00727 
00728         if( FAILED(createTargetOptions(CP_UTF8, &options, &cOptions, &cOptionsCount)) )
00729             return E_INVALIDARG;
00730 
00731         if( VLC_SUCCESS <= VLC_AddTarget(i_vlc, cUri, (const char **)cOptions, cOptionsCount, mode, position) )
00732         {
00733             hr = NOERROR;
00734             if( mode & PLAYLIST_GO )
00735                 _p_instance->fireOnPlayEvent();
00736         }
00737         else
00738         {
00739             hr = E_FAIL;
00740             if( mode & PLAYLIST_GO )
00741                 _p_instance->fireOnStopEvent();
00742         }
00743 
00744         freeTargetOptions(cOptions, cOptionsCount);
00745         CoTaskMemFree(cUri);
00746     }
00747     return hr;
00748 };
00749         
00750 STDMETHODIMP VLCControl::get_PlaylistIndex(int *index)
00751 {
00752     if( NULL == index )
00753         return E_POINTER;
00754 
00755     int i_vlc = _p_instance->getVLCObject();
00756     if( i_vlc )
00757     {
00758         *index = VLC_PlaylistIndex(i_vlc);
00759         return NOERROR;
00760     }
00761     *index = 0;
00762     return E_UNEXPECTED;
00763 };
00764         
00765 STDMETHODIMP VLCControl::get_PlaylistCount(int *count)
00766 {
00767     int i_vlc = _p_instance->getVLCObject();
00768     if( i_vlc )
00769     {
00770         *count = VLC_PlaylistNumberOfItems(i_vlc);
00771         return NOERROR;
00772     }
00773     *count = 0;
00774     return E_UNEXPECTED;
00775 };
00776         
00777 STDMETHODIMP VLCControl::playlistNext(void)
00778 {
00779     int i_vlc = _p_instance->getVLCObject();
00780     if( i_vlc )
00781     {
00782         VLC_PlaylistNext(i_vlc);
00783         return NOERROR;
00784     }
00785     return E_UNEXPECTED;
00786 };
00787         
00788 STDMETHODIMP VLCControl::playlistPrev(void)
00789 {
00790     int i_vlc = _p_instance->getVLCObject();
00791     if( i_vlc )
00792     {
00793         VLC_PlaylistPrev(i_vlc);
00794         return NOERROR;
00795     }
00796     return E_UNEXPECTED;
00797 };
00798         
00799 STDMETHODIMP VLCControl::playlistClear(void)
00800 {
00801     int i_vlc = _p_instance->getVLCObject();
00802     if( i_vlc )
00803     {
00804         VLC_PlaylistClear(i_vlc);
00805         return NOERROR;
00806     }
00807     return E_UNEXPECTED;
00808 };
00809         
00810 STDMETHODIMP VLCControl::get_VersionInfo(BSTR *version)
00811 {
00812     if( NULL == version )
00813         return E_POINTER;
00814 
00815     const char *versionStr = VLC_Version();
00816     if( NULL != versionStr )
00817     {
00818         *version = BSTRFromCStr(_p_instance->getCodePage(), versionStr);
00819         
00820         return NULL == *version ? E_OUTOFMEMORY : NOERROR;
00821     }
00822     *version = NULL;
00823     return E_FAIL;
00824 };
00825  
00826 STDMETHODIMP VLCControl::get_MRL(BSTR *mrl)
00827 {
00828     if( NULL == mrl )
00829         return E_POINTER;
00830 
00831     *mrl = SysAllocStringLen(_p_instance->getMRL(),
00832                 SysStringLen(_p_instance->getMRL()));
00833     return NOERROR;
00834 };
00835 
00836 STDMETHODIMP VLCControl::put_MRL(BSTR mrl)
00837 {
00838     _p_instance->setMRL(mrl);
00839 
00840     return S_OK;
00841 };
00842 
00843 STDMETHODIMP VLCControl::get_AutoPlay(VARIANT_BOOL *autoplay)
00844 {
00845     if( NULL == autoplay )
00846         return E_POINTER;
00847 
00848     *autoplay = _p_instance->getAutoPlay() ? VARIANT_TRUE: VARIANT_FALSE;
00849     return S_OK;
00850 };
00851 
00852 STDMETHODIMP VLCControl::put_AutoPlay(VARIANT_BOOL autoplay)
00853 {
00854     _p_instance->setAutoPlay((VARIANT_FALSE != autoplay) ? TRUE: FALSE);
00855     return S_OK;
00856 };
00857 
00858 STDMETHODIMP VLCControl::get_AutoLoop(VARIANT_BOOL *autoloop)
00859 {
00860     if( NULL == autoloop )
00861         return E_POINTER;
00862 
00863     *autoloop = _p_instance->getAutoLoop() ? VARIANT_TRUE: VARIANT_FALSE;
00864     return S_OK;
00865 };
00866 
00867 STDMETHODIMP VLCControl::put_AutoLoop(VARIANT_BOOL autoloop)
00868 {
00869     _p_instance->setAutoLoop((VARIANT_FALSE != autoloop) ? TRUE: FALSE);
00870     return S_OK;
00871 };
00872 

Generated on Tue Dec 20 10:14:18 2005 for vlc-0.8.4a by  doxygen 1.4.2