Commit acfc0a55 authored by Jean-Paul Saman's avatar Jean-Paul Saman

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

parent 76325233
...@@ -206,9 +206,9 @@ library AXVLC ...@@ -206,9 +206,9 @@ library AXVLC
HRESULT track([in] long track); HRESULT track([in] long track);
[propget, helpstring("Returns audio channel: reverse stereo, stereo, left, right, dolby.")] [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.")] [propput, helpstring("Sets audio channel to: reverse stereo, stereo, left, right, dolby.")]
HRESULT channel([in] BSTR channel); HRESULT channel([in] long channel);
}; };
[ [
......
...@@ -248,7 +248,7 @@ STDMETHODIMP VLCAudio::put_track(long track) ...@@ -248,7 +248,7 @@ STDMETHODIMP VLCAudio::put_track(long track)
return hr; return hr;
}; };
STDMETHODIMP VLCAudio::get_channel(BSTR *channel) STDMETHODIMP VLCAudio::get_channel(long *channel)
{ {
if( NULL == channel ) if( NULL == channel )
return E_POINTER; return E_POINTER;
...@@ -257,53 +257,32 @@ STDMETHODIMP VLCAudio::get_channel(BSTR *channel) ...@@ -257,53 +257,32 @@ STDMETHODIMP VLCAudio::get_channel(BSTR *channel)
HRESULT hr = _p_instance->getVLC(&p_libvlc); HRESULT hr = _p_instance->getVLC(&p_libvlc);
if( SUCCEEDED(hr) ) if( SUCCEEDED(hr) )
{ {
char *psz_channel = NULL;
libvlc_exception_t ex; libvlc_exception_t ex;
libvlc_exception_init(&ex); libvlc_exception_init(&ex);
psz_channel = libvlc_audio_get_channel(p_libvlc, &ex); *channel = libvlc_audio_get_channel(p_libvlc, &ex);
if( ! libvlc_exception_raised(&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;
}
if( psz_channel ) free( psz_channel );
psz_channel = NULL;
_p_instance->setErrorInfo(IID_IVLCAudio, _p_instance->setErrorInfo(IID_IVLCAudio,
libvlc_exception_get_message(&ex)); libvlc_exception_get_message(&ex));
libvlc_exception_clear(&ex); libvlc_exception_clear(&ex);
return E_FAIL; return E_FAIL;
} }
return NOERROR;
}
return hr; 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; libvlc_instance_t* p_libvlc;
HRESULT hr = _p_instance->getVLC(&p_libvlc); HRESULT hr = _p_instance->getVLC(&p_libvlc);
if( SUCCEEDED(hr) ) if( SUCCEEDED(hr) )
{ {
char *psz_channel = NULL;
libvlc_exception_t ex; libvlc_exception_t ex;
libvlc_exception_init(&ex); libvlc_exception_init(&ex);
psz_channel = CStrFromBSTR(CP_UTF8, channel); libvlc_audio_set_channel(p_libvlc, channel, &ex);
if( NULL == psz_channel )
return E_OUTOFMEMORY;
libvlc_audio_set_channel(p_libvlc, psz_channel, &ex);
CoTaskMemFree(psz_channel);
if( libvlc_exception_raised(&ex) ) if( libvlc_exception_raised(&ex) )
{ {
_p_instance->setErrorInfo(IID_IVLCAudio, _p_instance->setErrorInfo(IID_IVLCAudio,
......
...@@ -68,8 +68,8 @@ public: ...@@ -68,8 +68,8 @@ public:
STDMETHODIMP put_volume(long); STDMETHODIMP put_volume(long);
STDMETHODIMP get_track(long*); STDMETHODIMP get_track(long*);
STDMETHODIMP put_track(long); STDMETHODIMP put_track(long);
STDMETHODIMP get_channel(BSTR*); STDMETHODIMP get_channel(long*);
STDMETHODIMP put_channel(BSTR); STDMETHODIMP put_channel(long);
STDMETHODIMP toggleMute(); STDMETHODIMP toggleMute();
protected: protected:
......
...@@ -510,17 +510,17 @@ void libvlc_audio_set_track( libvlc_input_t *, int, libvlc_exception_t * ); ...@@ -510,17 +510,17 @@ void libvlc_audio_set_track( libvlc_input_t *, int, libvlc_exception_t * );
* Get current audio channel * Get current audio channel
* \param p_instance input instance * \param p_instance input instance
* \param p_exception an initialized exception * \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 * Set current audio channel
* \param p_instance input instance * \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 * \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 * );
/** @} */ /** @} */
......
...@@ -250,7 +250,7 @@ RuntimeNPObject::InvokeResult LibvlcAudioNPObject::getProperty(int index, NPVari ...@@ -250,7 +250,7 @@ RuntimeNPObject::InvokeResult LibvlcAudioNPObject::getProperty(int index, NPVari
} }
case ID_audio_channel: 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); libvlc_input_free(p_input);
if( libvlc_exception_raised(&ex) ) if( libvlc_exception_raised(&ex) )
{ {
...@@ -258,10 +258,7 @@ RuntimeNPObject::InvokeResult LibvlcAudioNPObject::getProperty(int index, NPVari ...@@ -258,10 +258,7 @@ RuntimeNPObject::InvokeResult LibvlcAudioNPObject::getProperty(int index, NPVari
libvlc_exception_clear(&ex); libvlc_exception_clear(&ex);
return INVOKERESULT_GENERIC_ERROR; return INVOKERESULT_GENERIC_ERROR;
} }
if( !psz_channel ) INT32_TO_NPVARIANT(channel, result);
return INVOKERESULT_GENERIC_ERROR;
STRINGZ_TO_NPVARIANT(psz_channel, result);
return INVOKERESULT_NO_ERROR; return INVOKERESULT_NO_ERROR;
} }
default: default:
...@@ -338,20 +335,11 @@ RuntimeNPObject::InvokeResult LibvlcAudioNPObject::setProperty(int index, const ...@@ -338,20 +335,11 @@ RuntimeNPObject::InvokeResult LibvlcAudioNPObject::setProperty(int index, const
return INVOKERESULT_INVALID_VALUE; return INVOKERESULT_INVALID_VALUE;
case ID_audio_channel: case ID_audio_channel:
{ {
char *psz_channel = NULL;
libvlc_input_free(p_input); libvlc_input_free(p_input);
if( ! NPVARIANT_IS_STRING(value) ) if( isNumberValue(value) )
return INVOKERESULT_INVALID_VALUE; {
libvlc_audio_set_channel(p_plugin->getVLC(),
psz_channel = stringValue(NPVARIANT_TO_STRING(value)); numberValue(value), &ex);
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( libvlc_exception_raised(&ex) )
{ {
NPN_SetException(this, libvlc_exception_get_message(&ex)); NPN_SetException(this, libvlc_exception_get_message(&ex));
...@@ -360,6 +348,8 @@ RuntimeNPObject::InvokeResult LibvlcAudioNPObject::setProperty(int index, const ...@@ -360,6 +348,8 @@ RuntimeNPObject::InvokeResult LibvlcAudioNPObject::setProperty(int index, const
} }
return INVOKERESULT_NO_ERROR; return INVOKERESULT_NO_ERROR;
} }
return INVOKERESULT_INVALID_VALUE;
}
default: default:
; ;
} }
......
...@@ -187,76 +187,47 @@ void libvlc_audio_set_track( libvlc_input_t *p_input, int i_track, ...@@ -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 * 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 ) libvlc_exception_t *p_e )
{ {
aout_instance_t *p_aout = GetAOut( p_instance, p_e ); aout_instance_t *p_aout = GetAOut( p_instance, p_e );
char *psz_channel = NULL;
vlc_value_t val; vlc_value_t val;
var_Get( p_aout, "audio-channels", &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 ); vlc_object_release( p_aout );
return psz_channel; return val.i_int;
} }
/***************************************************************************** /*****************************************************************************
* libvlc_audio_set_channel : Set the current audio channel * 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 ) libvlc_exception_t *p_e )
{ {
aout_instance_t *p_aout = GetAOut( p_instance, p_e ); aout_instance_t *p_aout = GetAOut( p_instance, p_e );
vlc_value_t val_list, text_list; vlc_value_t val;
int i_ret = -1, i; 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 )
{
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 ) val.i_int = i_channel;
switch( i_channel )
{ {
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 ); i_ret = var_Set( p_aout, "audio-channels", val );
if( i_ret < 0 ) 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 ); vlc_object_release( p_aout );
return; return;
} }
vlc_object_release( p_aout ); vlc_object_release( p_aout );
return; /* Found */ return; /* Found */
} default:
}
libvlc_exception_raise( p_e, "Audio channel out of range" ); libvlc_exception_raise( p_e, "Audio channel out of range" );
break;
}
vlc_object_release( p_aout ); vlc_object_release( p_aout );
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment