1
mirror of https://code.videolan.org/videolan/vlc synced 2024-10-03 01:31:53 +02:00

Reworked vlc.audio.channel API for JavaScript. All documentation is already updated.

This commit is contained in:
Jean-Paul Saman 2007-01-07 13:22:37 +00:00
parent 763252337d
commit acfc0a55ff
6 changed files with 47 additions and 107 deletions

View File

@ -206,9 +206,9 @@ library AXVLC
HRESULT track([in] long track);
[propget, helpstring("Returns audio channel: reverse stereo, stereo, left, right, dolby.")]
HRESULT channel([out, retval] BSTR* channel);
HRESULT channel([out, retval] long* channel);
[propput, helpstring("Sets audio channel to: reverse stereo, stereo, left, right, dolby.")]
HRESULT channel([in] BSTR channel);
HRESULT channel([in] long channel);
};
[

View File

@ -248,7 +248,7 @@ STDMETHODIMP VLCAudio::put_track(long track)
return hr;
};
STDMETHODIMP VLCAudio::get_channel(BSTR *channel)
STDMETHODIMP VLCAudio::get_channel(long *channel)
{
if( NULL == channel )
return E_POINTER;
@ -257,53 +257,32 @@ STDMETHODIMP VLCAudio::get_channel(BSTR *channel)
HRESULT hr = _p_instance->getVLC(&p_libvlc);
if( SUCCEEDED(hr) )
{
char *psz_channel = NULL;
libvlc_exception_t ex;
libvlc_exception_init(&ex);
psz_channel = libvlc_audio_get_channel(p_libvlc, &ex);
if( ! libvlc_exception_raised(&ex) )
*channel = libvlc_audio_get_channel(p_libvlc, &ex);
if( libvlc_exception_raised(&ex) )
{
if( NULL == psz_channel )
return E_OUTOFMEMORY;
*channel = BSTRFromCStr(CP_UTF8, psz_channel);
free( psz_channel );
psz_channel = NULL;
return (NULL == channel) ? E_OUTOFMEMORY : NOERROR;
_p_instance->setErrorInfo(IID_IVLCAudio,
libvlc_exception_get_message(&ex));
libvlc_exception_clear(&ex);
return E_FAIL;
}
if( psz_channel ) free( psz_channel );
psz_channel = NULL;
_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(BSTR channel)
STDMETHODIMP VLCAudio::put_channel(long channel)
{
if( NULL == channel )
return E_POINTER;
if( 0 == SysStringLen(channel) )
return E_INVALIDARG;
libvlc_instance_t* p_libvlc;
HRESULT hr = _p_instance->getVLC(&p_libvlc);
if( SUCCEEDED(hr) )
{
char *psz_channel = NULL;
libvlc_exception_t ex;
libvlc_exception_init(&ex);
psz_channel = CStrFromBSTR(CP_UTF8, channel);
if( NULL == psz_channel )
return E_OUTOFMEMORY;
libvlc_audio_set_channel(p_libvlc, psz_channel, &ex);
CoTaskMemFree(psz_channel);
libvlc_audio_set_channel(p_libvlc, channel, &ex);
if( libvlc_exception_raised(&ex) )
{
_p_instance->setErrorInfo(IID_IVLCAudio,

View File

@ -68,8 +68,8 @@ public:
STDMETHODIMP put_volume(long);
STDMETHODIMP get_track(long*);
STDMETHODIMP put_track(long);
STDMETHODIMP get_channel(BSTR*);
STDMETHODIMP put_channel(BSTR);
STDMETHODIMP get_channel(long*);
STDMETHODIMP put_channel(long);
STDMETHODIMP toggleMute();
protected:

View File

@ -510,17 +510,17 @@ void libvlc_audio_set_track( libvlc_input_t *, int, libvlc_exception_t * );
* Get current audio channel
* \param p_instance input instance
* \param p_exception an initialized exception
* \return the audio channel (char *)
* \return the audio channel (int)
*/
char *libvlc_audio_get_channel( libvlc_instance_t *, libvlc_exception_t * );
int libvlc_audio_get_channel( libvlc_instance_t *, libvlc_exception_t * );
/**
* Set current audio channel
* \param p_instance input instance
* \param psz_channel the audio channel (char *)
* \param i_channel the audio channel (int)
* \param p_exception an initialized exception
*/
void libvlc_audio_set_channel( libvlc_instance_t *, char *, libvlc_exception_t * );
void libvlc_audio_set_channel( libvlc_instance_t *, int, libvlc_exception_t * );
/** @} */

View File

@ -250,7 +250,7 @@ RuntimeNPObject::InvokeResult LibvlcAudioNPObject::getProperty(int index, NPVari
}
case ID_audio_channel:
{
NPUTF8 *psz_channel = libvlc_audio_get_channel(p_plugin->getVLC(), &ex);
int channel = libvlc_audio_get_channel(p_plugin->getVLC(), &ex);
libvlc_input_free(p_input);
if( libvlc_exception_raised(&ex) )
{
@ -258,10 +258,7 @@ RuntimeNPObject::InvokeResult LibvlcAudioNPObject::getProperty(int index, NPVari
libvlc_exception_clear(&ex);
return INVOKERESULT_GENERIC_ERROR;
}
if( !psz_channel )
return INVOKERESULT_GENERIC_ERROR;
STRINGZ_TO_NPVARIANT(psz_channel, result);
INT32_TO_NPVARIANT(channel, result);
return INVOKERESULT_NO_ERROR;
}
default:
@ -338,27 +335,20 @@ RuntimeNPObject::InvokeResult LibvlcAudioNPObject::setProperty(int index, const
return INVOKERESULT_INVALID_VALUE;
case ID_audio_channel:
{
char *psz_channel = NULL;
libvlc_input_free(p_input);
if( ! NPVARIANT_IS_STRING(value) )
return INVOKERESULT_INVALID_VALUE;
psz_channel = stringValue(NPVARIANT_TO_STRING(value));
if( !psz_channel )
return INVOKERESULT_GENERIC_ERROR;
libvlc_audio_set_channel(p_plugin->getVLC(), psz_channel, &ex);
if( psz_channel )
free( psz_channel );
if( libvlc_exception_raised(&ex) )
if( isNumberValue(value) )
{
NPN_SetException(this, libvlc_exception_get_message(&ex));
libvlc_exception_clear(&ex);
return INVOKERESULT_GENERIC_ERROR;
libvlc_audio_set_channel(p_plugin->getVLC(),
numberValue(value), &ex);
if( libvlc_exception_raised(&ex) )
{
NPN_SetException(this, libvlc_exception_get_message(&ex));
libvlc_exception_clear(&ex);
return INVOKERESULT_GENERIC_ERROR;
}
return INVOKERESULT_NO_ERROR;
}
return INVOKERESULT_NO_ERROR;
return INVOKERESULT_INVALID_VALUE;
}
default:
;

View File

@ -187,76 +187,47 @@ void libvlc_audio_set_track( libvlc_input_t *p_input, int i_track,
/*****************************************************************************
* libvlc_audio_get_channel : Get the current audio channel
*****************************************************************************/
char *libvlc_audio_get_channel( libvlc_instance_t *p_instance,
int libvlc_audio_get_channel( libvlc_instance_t *p_instance,
libvlc_exception_t *p_e )
{
aout_instance_t *p_aout = GetAOut( p_instance, p_e );
char *psz_channel = NULL;
vlc_value_t val;
var_Get( p_aout, "audio-channels", &val );
switch( val.i_int )
{
case AOUT_VAR_CHAN_RSTEREO:
psz_channel = strdup("reverse stereo");
break;
case AOUT_VAR_CHAN_STEREO:
psz_channel = strdup("stereo");
break;
case AOUT_VAR_CHAN_LEFT:
psz_channel = strdup("left");
break;
case AOUT_VAR_CHAN_RIGHT:
psz_channel = strdup("right");
break;
case AOUT_VAR_CHAN_DOLBYS:
psz_channel = strdup("dolby");
break;
default:
psz_channel = strdup("disabled");
break;
}
vlc_object_release( p_aout );
return psz_channel;
return val.i_int;
}
/*****************************************************************************
* libvlc_audio_set_channel : Set the current audio channel
*****************************************************************************/
void libvlc_audio_set_channel( libvlc_instance_t *p_instance, char *psz_channel,
void libvlc_audio_set_channel( libvlc_instance_t *p_instance, int i_channel,
libvlc_exception_t *p_e )
{
aout_instance_t *p_aout = GetAOut( p_instance, p_e );
vlc_value_t val_list, text_list;
int i_ret = -1, i;
vlc_value_t val;
int i_ret = -1;
i_ret = var_Change( p_aout, "audio-channels", VLC_VAR_GETCHOICES, &val_list, &text_list );
if( (i_ret < 0) || !psz_channel )
val.i_int = i_channel;
switch( i_channel )
{
libvlc_exception_raise( p_e, "Audio channel out of range" );
vlc_object_release( p_aout );
return;
}
for( i = 0; i < val_list.p_list->i_count; i++ )
{
vlc_value_t val = val_list.p_list->p_values[i];
vlc_value_t text = text_list.p_list->p_values[i];
if( strncasecmp( psz_channel, text.psz_string, strlen(text.psz_string) ) == 0 )
{
case AOUT_VAR_CHAN_RSTEREO:
case AOUT_VAR_CHAN_STEREO:
case AOUT_VAR_CHAN_LEFT:
case AOUT_VAR_CHAN_RIGHT:
case AOUT_VAR_CHAN_DOLBYS:
i_ret = var_Set( p_aout, "audio-channels", val );
if( i_ret < 0 )
{
libvlc_exception_raise( p_e, "failed setting audio range" );
libvlc_exception_raise( p_e, "Failed setting audio channel" );
vlc_object_release( p_aout );
return;
}
vlc_object_release( p_aout );
return; /* Found */
}
default:
libvlc_exception_raise( p_e, "Audio channel out of range" );
break;
}
libvlc_exception_raise( p_e, "Audio channel out of range" );
vlc_object_release( p_aout );
}