Commit 310dfdca authored by Damien Fouilleul's avatar Damien Fouilleul

- formating

- javascript fixes
parent 2454f03d
......@@ -79,21 +79,21 @@ enum LibvlcRootNPObjectPropertyIds
const int LibvlcRootNPObject::propertyCount = sizeof(LibvlcRootNPObject::propertyNames)/sizeof(NPUTF8 *);
RuntimeNPObject::InvokeResult LibvlcRootNPObject::getProperty(int index, NPVariant *result)
RuntimeNPObject::InvokeResult LibvlcRootNPObject::getProperty(int index, NPVariant &result)
{
switch( index )
{
case ID_audio:
OBJECT_TO_NPVARIANT(NPN_RetainObject(audioObj), *result);
OBJECT_TO_NPVARIANT(NPN_RetainObject(audioObj), result);
return INVOKERESULT_NO_ERROR;
case ID_input:
OBJECT_TO_NPVARIANT(NPN_RetainObject(inputObj), *result);
OBJECT_TO_NPVARIANT(NPN_RetainObject(inputObj), result);
return INVOKERESULT_NO_ERROR;
case ID_playlist:
OBJECT_TO_NPVARIANT(NPN_RetainObject(playlistObj), *result);
OBJECT_TO_NPVARIANT(NPN_RetainObject(playlistObj), result);
return INVOKERESULT_NO_ERROR;
case ID_video:
OBJECT_TO_NPVARIANT(NPN_RetainObject(videoObj), *result);
OBJECT_TO_NPVARIANT(NPN_RetainObject(videoObj), result);
return INVOKERESULT_NO_ERROR;
}
return INVOKERESULT_GENERIC_ERROR;
......@@ -124,7 +124,7 @@ enum LibvlcAudioNPObjectPropertyIds
const int LibvlcAudioNPObject::propertyCount = sizeof(LibvlcAudioNPObject::propertyNames)/sizeof(NPUTF8 *);
RuntimeNPObject::InvokeResult LibvlcAudioNPObject::getProperty(int index, NPVariant *result)
RuntimeNPObject::InvokeResult LibvlcAudioNPObject::getProperty(int index, NPVariant &result)
{
VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);
if( p_plugin )
......@@ -143,7 +143,7 @@ RuntimeNPObject::InvokeResult LibvlcAudioNPObject::getProperty(int index, NPVari
libvlc_exception_clear(&ex);
return INVOKERESULT_GENERIC_ERROR;
}
BOOLEAN_TO_NPVARIANT(muted, *result);
BOOLEAN_TO_NPVARIANT(muted, result);
return INVOKERESULT_NO_ERROR;
}
case ID_volume:
......@@ -155,7 +155,7 @@ RuntimeNPObject::InvokeResult LibvlcAudioNPObject::getProperty(int index, NPVari
libvlc_exception_clear(&ex);
return INVOKERESULT_GENERIC_ERROR;
}
INT32_TO_NPVARIANT(volume, *result);
INT32_TO_NPVARIANT(volume, result);
return INVOKERESULT_NO_ERROR;
}
}
......@@ -163,7 +163,7 @@ RuntimeNPObject::InvokeResult LibvlcAudioNPObject::getProperty(int index, NPVari
return INVOKERESULT_GENERIC_ERROR;
}
RuntimeNPObject::InvokeResult LibvlcAudioNPObject::setProperty(int index, const NPVariant *value)
RuntimeNPObject::InvokeResult LibvlcAudioNPObject::setProperty(int index, const NPVariant &value)
{
VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);
if( p_plugin )
......@@ -174,10 +174,10 @@ RuntimeNPObject::InvokeResult LibvlcAudioNPObject::setProperty(int index, const
switch( index )
{
case ID_mute:
if( NPVARIANT_IS_BOOLEAN(*value) )
if( NPVARIANT_IS_BOOLEAN(value) )
{
libvlc_audio_set_mute(p_plugin->getVLC(),
NPVARIANT_TO_BOOLEAN(*value), &ex);
NPVARIANT_TO_BOOLEAN(value), &ex);
if( libvlc_exception_raised(&ex) )
{
NPN_SetException(this, libvlc_exception_get_message(&ex));
......@@ -188,10 +188,10 @@ RuntimeNPObject::InvokeResult LibvlcAudioNPObject::setProperty(int index, const
}
return INVOKERESULT_INVALID_VALUE;
case ID_volume:
if( isNumberValue(*value) )
if( isNumberValue(value) )
{
libvlc_audio_set_volume(p_plugin->getVLC(),
numberValue(*value), &ex);
numberValue(value), &ex);
if( libvlc_exception_raised(&ex) )
{
NPN_SetException(this, libvlc_exception_get_message(&ex));
......@@ -218,7 +218,7 @@ enum LibvlcAudioNPObjectMethodIds
const int LibvlcAudioNPObject::methodCount = sizeof(LibvlcAudioNPObject::methodNames)/sizeof(NPUTF8 *);
RuntimeNPObject::InvokeResult LibvlcAudioNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant *result)
RuntimeNPObject::InvokeResult LibvlcAudioNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)
{
VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);
if( p_plugin )
......@@ -240,7 +240,7 @@ RuntimeNPObject::InvokeResult LibvlcAudioNPObject::invoke(int index, const NPVar
}
else
{
VOID_TO_NPVARIANT(*result);
VOID_TO_NPVARIANT(result);
return INVOKERESULT_NO_ERROR;
}
}
......@@ -276,7 +276,7 @@ enum LibvlcInputNPObjectPropertyIds
const int LibvlcInputNPObject::propertyCount = sizeof(LibvlcInputNPObject::propertyNames)/sizeof(NPUTF8 *);
RuntimeNPObject::InvokeResult LibvlcInputNPObject::getProperty(int index, NPVariant *result)
RuntimeNPObject::InvokeResult LibvlcInputNPObject::getProperty(int index, NPVariant &result)
{
VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);
if( p_plugin )
......@@ -304,7 +304,7 @@ RuntimeNPObject::InvokeResult LibvlcInputNPObject::getProperty(int index, NPVari
libvlc_exception_clear(&ex);
return INVOKERESULT_GENERIC_ERROR;
}
DOUBLE_TO_NPVARIANT(val, *result);
DOUBLE_TO_NPVARIANT(val, result);
return INVOKERESULT_NO_ERROR;
}
case ID_position:
......@@ -317,7 +317,7 @@ RuntimeNPObject::InvokeResult LibvlcInputNPObject::getProperty(int index, NPVari
libvlc_exception_clear(&ex);
return INVOKERESULT_GENERIC_ERROR;
}
DOUBLE_TO_NPVARIANT(val, *result);
DOUBLE_TO_NPVARIANT(val, result);
return INVOKERESULT_NO_ERROR;
}
case ID_time:
......@@ -330,7 +330,7 @@ RuntimeNPObject::InvokeResult LibvlcInputNPObject::getProperty(int index, NPVari
libvlc_exception_clear(&ex);
return INVOKERESULT_GENERIC_ERROR;
}
DOUBLE_TO_NPVARIANT(val, *result);
DOUBLE_TO_NPVARIANT(val, result);
return INVOKERESULT_NO_ERROR;
}
case ID_fps:
......@@ -343,7 +343,7 @@ RuntimeNPObject::InvokeResult LibvlcInputNPObject::getProperty(int index, NPVari
libvlc_exception_clear(&ex);
return INVOKERESULT_GENERIC_ERROR;
}
DOUBLE_TO_NPVARIANT(val, *result);
DOUBLE_TO_NPVARIANT(val, result);
return INVOKERESULT_NO_ERROR;
}
case ID_hasvout:
......@@ -356,7 +356,7 @@ RuntimeNPObject::InvokeResult LibvlcInputNPObject::getProperty(int index, NPVari
libvlc_exception_clear(&ex);
return INVOKERESULT_GENERIC_ERROR;
}
BOOLEAN_TO_NPVARIANT(val, *result);
BOOLEAN_TO_NPVARIANT(val, result);
return INVOKERESULT_NO_ERROR;
}
}
......@@ -365,7 +365,7 @@ RuntimeNPObject::InvokeResult LibvlcInputNPObject::getProperty(int index, NPVari
return INVOKERESULT_GENERIC_ERROR;
}
RuntimeNPObject::InvokeResult LibvlcInputNPObject::setProperty(int index, const NPVariant *value)
RuntimeNPObject::InvokeResult LibvlcInputNPObject::setProperty(int index, const NPVariant &value)
{
VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);
if( p_plugin )
......@@ -385,13 +385,13 @@ RuntimeNPObject::InvokeResult LibvlcInputNPObject::setProperty(int index, const
{
case ID_position:
{
if( ! NPVARIANT_IS_DOUBLE(*value) )
if( ! NPVARIANT_IS_DOUBLE(value) )
{
libvlc_input_free(p_input);
return INVOKERESULT_INVALID_VALUE;
}
float val = (float)NPVARIANT_TO_DOUBLE(*value);
float val = (float)NPVARIANT_TO_DOUBLE(value);
libvlc_input_set_position(p_input, val, &ex);
libvlc_input_free(p_input);
if( libvlc_exception_raised(&ex) )
......@@ -405,10 +405,10 @@ RuntimeNPObject::InvokeResult LibvlcInputNPObject::setProperty(int index, const
case ID_time:
{
vlc_int64_t val;
if( NPVARIANT_IS_INT32(*value) )
val = (vlc_int64_t)NPVARIANT_TO_INT32(*value);
else if( NPVARIANT_IS_DOUBLE(*value) )
val = (vlc_int64_t)NPVARIANT_TO_DOUBLE(*value);
if( NPVARIANT_IS_INT32(value) )
val = (vlc_int64_t)NPVARIANT_TO_INT32(value);
else if( NPVARIANT_IS_DOUBLE(value) )
val = (vlc_int64_t)NPVARIANT_TO_DOUBLE(value);
else
{
libvlc_input_free(p_input);
......@@ -457,7 +457,7 @@ enum LibvlcPlaylistNPObjectPropertyIds
const int LibvlcPlaylistNPObject::propertyCount = sizeof(LibvlcPlaylistNPObject::propertyNames)/sizeof(NPUTF8 *);
RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::getProperty(int index, NPVariant *result)
RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::getProperty(int index, NPVariant &result)
{
VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);
if( p_plugin )
......@@ -476,7 +476,7 @@ RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::getProperty(int index, NPV
libvlc_exception_clear(&ex);
return INVOKERESULT_GENERIC_ERROR;
}
INT32_TO_NPVARIANT(val, *result);
INT32_TO_NPVARIANT(val, result);
return INVOKERESULT_NO_ERROR;
}
case ID_isplaying:
......@@ -488,7 +488,7 @@ RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::getProperty(int index, NPV
libvlc_exception_clear(&ex);
return INVOKERESULT_GENERIC_ERROR;
}
BOOLEAN_TO_NPVARIANT(val, *result);
BOOLEAN_TO_NPVARIANT(val, result);
return INVOKERESULT_NO_ERROR;
}
}
......@@ -522,7 +522,7 @@ enum LibvlcPlaylistNPObjectMethodIds
const int LibvlcPlaylistNPObject::methodCount = sizeof(LibvlcPlaylistNPObject::methodNames)/sizeof(NPUTF8 *);
RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant *result)
RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)
{
VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);
if( p_plugin )
......@@ -533,39 +533,91 @@ RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::invoke(int index, const NP
switch( index )
{
case ID_add:
if( (argCount == 1) && NPVARIANT_IS_STRING(args[0]) )
{
char *url = NULL;
char *name = NULL;
int i_options = 0;
char** ppsz_options = NULL;
if( (argCount < 1) || (argCount > 3) )
return INVOKERESULT_NO_SUCH_METHOD;
// grab URL
if( NPVARIANT_IS_STRING(args[0]) )
{
const NPString &name = NPVARIANT_TO_STRING(args[0]);
NPUTF8 *s = new NPUTF8[name.utf8length+1];
char *s = stringValue(NPVARIANT_TO_STRING(args[0]));
if( s )
{
strncpy(s, name.utf8characters, name.utf8length);
s[name.utf8length] = '\0';
char *url = p_plugin->getAbsoluteURL(s);
delete s;
if( ! url )
// what happened ?
return INVOKERESULT_GENERIC_ERROR;
int item = libvlc_playlist_add(p_plugin->getVLC(), url, NULL, &ex);
free(url);
if( libvlc_exception_raised(&ex) )
{
NPN_SetException(this, libvlc_exception_get_message(&ex));
libvlc_exception_clear(&ex);
return INVOKERESULT_GENERIC_ERROR;
}
else
{
INT32_TO_NPVARIANT(item, *result);
return INVOKERESULT_NO_ERROR;
}
}
else
return INVOKERESULT_OUT_OF_MEMORY;
}
return INVOKERESULT_NO_SUCH_METHOD;
else
return INVOKERESULT_NO_SUCH_METHOD;
// grab name if available
if( argCount > 1 )
{
if( NPVARIANT_IS_NULL(args[1]) )
{
// do nothing
}
else if( NPVARIANT_IS_STRING(args[1]) )
{
name = stringValue(NPVARIANT_TO_STRING(args[0]));
}
else
return INVOKERESULT_NO_SUCH_METHOD;
}
// grab options if available
if( argCount > 2 )
{
if( NPVARIANT_IS_NULL(args[2]) )
{
// do nothing
}
else if( NPVARIANT_IS_STRING(args[2]) )
{
parseOptions(NPVARIANT_TO_STRING(args[0]), &i_options, &ppsz_options);
}
else if( NPVARIANT_IS_OBJECT(args[3]) )
{
parseOptions(NPVARIANT_TO_OBJECT(args[0]), &i_options, &ppsz_options);
}
}
int item = libvlc_playlist_add_extended(p_plugin->getVLC(),
url,
name,
i_options,
const_cast<const char **>(ppsz_options),
&ex);
delete url;
delete name;
for( int i=0; i< i_options; ++i )
{
delete ppsz_options[i];
}
delete ppsz_options;
if( libvlc_exception_raised(&ex) )
{
NPN_SetException(this, libvlc_exception_get_message(&ex));
libvlc_exception_clear(&ex);
return INVOKERESULT_GENERIC_ERROR;
}
else
{
INT32_TO_NPVARIANT(item, result);
return INVOKERESULT_NO_ERROR;
}
}
case ID_play:
if( argCount == 0 )
{
......@@ -578,7 +630,7 @@ RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::invoke(int index, const NP
}
else
{
VOID_TO_NPVARIANT(*result);
VOID_TO_NPVARIANT(result);
return INVOKERESULT_NO_ERROR;
}
}
......@@ -595,7 +647,7 @@ RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::invoke(int index, const NP
}
else
{
VOID_TO_NPVARIANT(*result);
VOID_TO_NPVARIANT(result);
return INVOKERESULT_NO_ERROR;
}
}
......@@ -612,7 +664,7 @@ RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::invoke(int index, const NP
}
else
{
VOID_TO_NPVARIANT(*result);
VOID_TO_NPVARIANT(result);
return INVOKERESULT_NO_ERROR;
}
}
......@@ -629,7 +681,7 @@ RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::invoke(int index, const NP
}
else
{
VOID_TO_NPVARIANT(*result);
VOID_TO_NPVARIANT(result);
return INVOKERESULT_NO_ERROR;
}
}
......@@ -646,7 +698,7 @@ RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::invoke(int index, const NP
}
else
{
VOID_TO_NPVARIANT(*result);
VOID_TO_NPVARIANT(result);
return INVOKERESULT_NO_ERROR;
}
}
......@@ -663,7 +715,7 @@ RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::invoke(int index, const NP
}
else
{
VOID_TO_NPVARIANT(*result);
VOID_TO_NPVARIANT(result);
return INVOKERESULT_NO_ERROR;
}
}
......@@ -680,7 +732,7 @@ RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::invoke(int index, const NP
}
else
{
VOID_TO_NPVARIANT(*result);
VOID_TO_NPVARIANT(result);
return INVOKERESULT_NO_ERROR;
}
}
......@@ -691,6 +743,136 @@ RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::invoke(int index, const NP
}
return INVOKERESULT_GENERIC_ERROR;
}
void LibvlcPlaylistNPObject::parseOptions(const NPString &s, int *i_options, char*** ppsz_options)
{
if( s.utf8length )
{
char *val = stringValue(s);
if( val )
{
long capacity = 16;
char **options = (char **)malloc(capacity*sizeof(char *));
if( options )
{
int nOptions = 0;
char *end = val + s.utf8length;
while( val < end )
{
// skip leading blanks
while( (val < end)
&& ((*val == ' ' ) || (*val != '\t')) )
++val;
char *start = val;
// skip till we get a blank character
while( (val < end)
&& (*val != ' ' )
&& (*val != '\t') )
{
char c = *(val++);
if( ('\'' == c) || ('"' == c) )
{
// skip till end of string
while( (val < end) && (*(val++) != c ) );
}
}
if( val > start )
{
if( nOptions == capacity )
{
capacity += 16;
char **moreOptions = (char **)realloc(options, capacity*sizeof(char*));
if( ! moreOptions )
{
/* failed to allocate more memory */
delete val;
/* return what we got so far */
*i_options = nOptions;
*ppsz_options = options;
break;
}
options = moreOptions;
}
*(val++) = '\0';
options[nOptions++] = strdup(start);
}
else
// must be end of string
break;
}
*i_options = nOptions;
*ppsz_options = options;
}
delete val;
}
}
}
void LibvlcPlaylistNPObject::parseOptions(NPObject *obj, int *i_options, char*** ppsz_options)
{
NPIdentifier name = NPN_GetStringIdentifier("length");
/* we are expecting to have a Javascript Array object */
if( NPN_HasProperty(_instance, obj, name) )
{
NPVariant value;
if( NPN_GetProperty(_instance, obj, name, &value) )
{
int count = numberValue(value);
NPN_ReleaseVariantValue(&value);
if( count )
{
long capacity = 16;
char **options = (char **)malloc(capacity*sizeof(char *));
if( options )
{
int nOptions = 0;
while( nOptions < count )
{
name = NPN_GetIntIdentifier(nOptions);
if( ! NPN_HasProperty(_instance, obj, name) )
/* return what we got so far */
break;
if( ! NPN_GetProperty(_instance, obj, name, &value) )
/* return what we got so far */
break;
if( ! NPVARIANT_IS_STRING(value) )
{
/* return what we got so far */
NPN_ReleaseVariantValue(&value);
break;
}
if( nOptions == capacity )
{
capacity += 16;
char **moreOptions = (char **)realloc(options, capacity*sizeof(char*));
if( ! moreOptions )
{
/* failed to allocate more memory */
NPN_ReleaseVariantValue(&value);
/* return what we got so far */
*i_options = nOptions;
*ppsz_options = options;
break;
}
options = moreOptions;
}
options[nOptions++] = stringValue(value);
}
*i_options = nOptions;
*ppsz_options = options;
}
}
}
}
}
/*
** implementation of libvlc video object
......@@ -712,7 +894,7 @@ enum LibvlcVideoNPObjectPropertyIds
const int LibvlcVideoNPObject::propertyCount = sizeof(LibvlcVideoNPObject::propertyNames)/sizeof(NPUTF8 *);
RuntimeNPObject::InvokeResult LibvlcVideoNPObject::getProperty(int index, NPVariant *result)
RuntimeNPObject::InvokeResult LibvlcVideoNPObject::getProperty(int index, NPVariant &result)
{
VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);
if( p_plugin )
......@@ -740,7 +922,7 @@ RuntimeNPObject::InvokeResult LibvlcVideoNPObject::getProperty(int index, NPVari
libvlc_exception_clear(&ex);
return INVOKERESULT_GENERIC_ERROR;
}
BOOLEAN_TO_NPVARIANT(val, *result);
BOOLEAN_TO_NPVARIANT(val, result);
return INVOKERESULT_NO_ERROR;
}
case ID_height:
......@@ -753,7 +935,7 @@ RuntimeNPObject::InvokeResult LibvlcVideoNPObject::getProperty(int index, NPVari
libvlc_exception_clear(&ex);
return INVOKERESULT_GENERIC_ERROR;
}
INT32_TO_NPVARIANT(val, *result);
INT32_TO_NPVARIANT(val, result);
return INVOKERESULT_NO_ERROR;
}
case ID_width:
......@@ -766,7 +948,7 @@ RuntimeNPObject::InvokeResult LibvlcVideoNPObject::getProperty(int index, NPVari
libvlc_exception_clear(&ex);
return INVOKERESULT_GENERIC_ERROR;
}
INT32_TO_NPVARIANT(val, *result);
INT32_TO_NPVARIANT(val, result);
return INVOKERESULT_NO_ERROR;
}
}
......@@ -775,7 +957,7 @@ RuntimeNPObject::InvokeResult LibvlcVideoNPObject::getProperty(int index, NPVari
return INVOKERESULT_GENERIC_ERROR;
}
RuntimeNPObject::InvokeResult LibvlcVideoNPObject::setProperty(int index, const NPVariant *value)
RuntimeNPObject::InvokeResult LibvlcVideoNPObject::setProperty(int index, const NPVariant &value)
{
VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);
if( p_plugin )
......@@ -795,13 +977,13 @@ RuntimeNPObject::InvokeResult LibvlcVideoNPObject::setProperty(int index, const
{
case ID_fullscreen:
{
if( ! NPVARIANT_IS_BOOLEAN(*value) )
if( ! NPVARIANT_IS_BOOLEAN(value) )
{
libvlc_input_free(p_input);
return INVOKERESULT_INVALID_VALUE;
}
int val = NPVARIANT_TO_BOOLEAN(*value);
int val = NPVARIANT_TO_BOOLEAN(value);
libvlc_set_fullscreen(p_input, val, &ex);
libvlc_input_free(p_input);
if( libvlc_exception_raised(&ex) )
......@@ -830,7 +1012,7 @@ enum LibvlcVideoNPObjectMethodIds
const int LibvlcVideoNPObject::methodCount = sizeof(LibvlcVideoNPObject::methodNames)/sizeof(NPUTF8 *);
RuntimeNPObject::InvokeResult LibvlcVideoNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant *result)
RuntimeNPObject::InvokeResult LibvlcVideoNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)
{
VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);
if( p_plugin )
......@@ -861,7 +1043,7 @@ RuntimeNPObject::InvokeResult LibvlcVideoNPObject::invoke(int index, const NPVar
}
else
{
VOID_TO_NPVARIANT(*result);
VOID_TO_NPVARIANT(result);
return INVOKERESULT_NO_ERROR;
}
}
......
......@@ -39,7 +39,7 @@ protected:
static const int propertyCount;
static const NPUTF8 * const propertyNames[];
InvokeResult getProperty(int index, NPVariant *result);
InvokeResult getProperty(int index, NPVariant &result);
static const int methodCount;
static const NPUTF8 * const methodNames[];
......@@ -63,13 +63,13 @@ protected:
static const int propertyCount;
static const NPUTF8 * const propertyNames[];
InvokeResult getProperty(int index, NPVariant *result);
InvokeResult setProperty(int index, const NPVariant *value);
InvokeResult getProperty(int index, NPVariant &result);
InvokeResult setProperty(int index, const NPVariant &value);
static const int methodCount;
static const NPUTF8 * const methodNames[];
InvokeResult invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant *result);
InvokeResult invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result);
};
class LibvlcInputNPObject: public RuntimeNPObject
......@@ -86,8 +86,8 @@ protected:
static const int propertyCount;
static const NPUTF8 * const propertyNames[];
InvokeResult getProperty(int index, NPVariant *result);
InvokeResult setProperty(int index, const NPVariant *value);
InvokeResult getProperty(int index, NPVariant &result);
InvokeResult setProperty(int index, const NPVariant &value);
static const int methodCount;
static const NPUTF8 * const methodNames[];
......@@ -106,12 +106,15 @@ protected:
static const int propertyCount;
static const NPUTF8 * const propertyNames[];
InvokeResult getProperty(int index, NPVariant *result);
InvokeResult getProperty(int index, NPVariant &result);
static const int methodCount;
static const NPUTF8 * const methodNames[];
InvokeResult invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant *result);
InvokeResult invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result);
void parseOptions(const NPString &s, int *i_options, char*** ppsz_options);
void parseOptions(NPObject *obj, int *i_options, char*** ppsz_options);
};
class LibvlcVideoNPObject: public RuntimeNPObject
......@@ -127,13 +130,13 @@ protected:
static const int propertyCount;
static const NPUTF8 * const propertyNames[];
InvokeResult getProperty(int index, NPVariant *result);
InvokeResult setProperty(int index, const NPVariant *value);
InvokeResult getProperty(int index, NPVariant &result);
InvokeResult setProperty(int index, const NPVariant &value);
static const int methodCount;
static const NPUTF8 * const methodNames[];
InvokeResult invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant *result);
InvokeResult invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result);
};
......@@ -35,13 +35,34 @@
#include "nporuntime.h"
#include "vlcplugin.h"
RuntimeNPObject::InvokeResult RuntimeNPObject::getProperty(int index, NPVariant *result)
char* RuntimeNPObject::stringValue(const NPString &s)
{
NPUTF8 *val = new NPUTF8[s.utf8length+1];
if( val )
{
strncpy(val, s.utf8characters, s.utf8length);
val[s.utf8length] = '\0';
}
return val;
}
char* RuntimeNPObject::stringValue(const NPVariant &v)
{
char *s = NULL;
if( NPVARIANT_IS_STRING(v) )
{
return stringValue(NPVARIANT_TO_STRING(v));
}
return s;
}
RuntimeNPObject::InvokeResult RuntimeNPObject::getProperty(int index, NPVariant &result)
{
/* default behaviour */
return INVOKERESULT_GENERIC_ERROR;
}
RuntimeNPObject::InvokeResult RuntimeNPObject::setProperty(int index, const NPVariant *value)
RuntimeNPObject::InvokeResult RuntimeNPObject::setProperty(int index, const NPVariant &value)
{
/* default behaviour */
return INVOKERESULT_GENERIC_ERROR;
......@@ -53,16 +74,16 @@ RuntimeNPObject::InvokeResult RuntimeNPObject::removeProperty(int index)
return INVOKERESULT_GENERIC_ERROR;
}
RuntimeNPObject::InvokeResult RuntimeNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant *result)
RuntimeNPObject::InvokeResult RuntimeNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)
{
/* default beahviour */
return INVOKERESULT_GENERIC_ERROR;
}
RuntimeNPObject::InvokeResult RuntimeNPObject::invokeDefault(const NPVariant *args, uint32_t argCount, NPVariant *result)
RuntimeNPObject::InvokeResult RuntimeNPObject::invokeDefault(const NPVariant *args, uint32_t argCount, NPVariant &result)
{
/* return void */
VOID_TO_NPVARIANT(*result);
VOID_TO_NPVARIANT(result);
return INVOKERESULT_NO_ERROR;
}
......
......@@ -52,6 +52,9 @@ public:
}
};
static char* stringValue(const NPString &v);
static char* stringValue(const NPVariant &v);
RuntimeNPObject(NPP instance, const NPClass *aClass) :
_instance(instance)
{
......@@ -88,11 +91,11 @@ protected:
uint32_t argCount,
NPVariant *result);
virtual InvokeResult getProperty(int index, NPVariant *result);
virtual InvokeResult setProperty(int index, const NPVariant *value);
virtual InvokeResult getProperty(int index, NPVariant &result);
virtual InvokeResult setProperty(int index, const NPVariant &value);
virtual InvokeResult removeProperty(int index);
virtual InvokeResult invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant *result);
virtual InvokeResult invokeDefault(const NPVariant *args, uint32_t argCount, NPVariant *result);
virtual InvokeResult invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result);
virtual InvokeResult invokeDefault(const NPVariant *args, uint32_t argCount, NPVariant &result);
bool returnInvokeResult(InvokeResult result);
......@@ -162,7 +165,7 @@ static bool RuntimeNPClassGetProperty(NPObject *npobj, NPIdentifier name, NPVari
if( index != -1 )
{
RuntimeNPObject *vObj = static_cast<RuntimeNPObject *>(npobj);
return vObj->returnInvokeResult(vObj->getProperty(index, result));
return vObj->returnInvokeResult(vObj->getProperty(index, *result));
}
return false;
}
......@@ -175,7 +178,7 @@ static bool RuntimeNPClassSetProperty(NPObject *npobj, NPIdentifier name, const
if( index != -1 )
{
RuntimeNPObject *vObj = static_cast<RuntimeNPObject *>(npobj);
return vObj->returnInvokeResult(vObj->setProperty(index, value));
return vObj->returnInvokeResult(vObj->setProperty(index, *value));
}
return false;
}
......@@ -203,7 +206,7 @@ static bool RuntimeNPClassInvoke(NPObject *npobj, NPIdentifier name,
if( index != -1 )
{
RuntimeNPObject *vObj = static_cast<RuntimeNPObject *>(npobj);
return vObj->returnInvokeResult(vObj->invoke(index, args, argCount, result));
return vObj->returnInvokeResult(vObj->invoke(index, args, argCount, *result));
}
return false;
......@@ -216,7 +219,7 @@ static bool RuntimeNPClassInvokeDefault(NPObject *npobj,
NPVariant *result)
{
RuntimeNPObject *vObj = static_cast<RuntimeNPObject *>(npobj);
return vObj->returnInvokeResult(vObj->invokeDefault(args, argCount, result));
return vObj->returnInvokeResult(vObj->invokeDefault(args, argCount, *result));
}
template<class T>
......
......@@ -102,7 +102,7 @@ enum VlcNPObjectMethodIds
const int VlcNPObject::methodCount = sizeof(VlcNPObject::methodNames)/sizeof(NPUTF8 *);
RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant *result)
RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)
{
VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);
if( p_plugin )
......@@ -124,7 +124,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
}
else
{
VOID_TO_NPVARIANT(*result);
VOID_TO_NPVARIANT(result);
return INVOKERESULT_NO_ERROR;
}
}
......@@ -141,7 +141,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
}
else
{
VOID_TO_NPVARIANT(*result);
VOID_TO_NPVARIANT(result);
return INVOKERESULT_NO_ERROR;
}
}
......@@ -158,7 +158,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
}
else
{
VOID_TO_NPVARIANT(*result);
VOID_TO_NPVARIANT(result);
return INVOKERESULT_NO_ERROR;
}
}
......@@ -179,7 +179,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
}
else
{
VOID_TO_NPVARIANT(*result);
VOID_TO_NPVARIANT(result);
return INVOKERESULT_NO_ERROR;
}
}
......@@ -207,7 +207,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
}
else
{
VOID_TO_NPVARIANT(*result);
VOID_TO_NPVARIANT(result);
return INVOKERESULT_NO_ERROR;
}
}
......@@ -224,7 +224,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
}
else
{
INT32_TO_NPVARIANT(val, *result);
INT32_TO_NPVARIANT(val, result);
return INVOKERESULT_NO_ERROR;
}
}
......@@ -241,7 +241,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
}
else
{
VOID_TO_NPVARIANT(*result);
VOID_TO_NPVARIANT(result);
return INVOKERESULT_NO_ERROR;
}
}
......@@ -249,18 +249,15 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
case ID_get_int_variable:
if( (argCount == 1) && NPVARIANT_IS_STRING(args[0]) )
{
const NPString &name = NPVARIANT_TO_STRING(args[0]);
NPUTF8 *s = new NPUTF8[name.utf8length+1];
char *s = stringValue(NPVARIANT_TO_STRING(args[0]));
if( s )
{
int vlc_id = libvlc_get_vlc_id(p_plugin->getVLC());
vlc_value_t val;
strncpy(s, name.utf8characters, name.utf8length);
s[name.utf8length] = '\0';
if( VLC_SUCCESS == VLC_VariableGet(vlc_id, s, &val) )
{
delete s;
INT32_TO_NPVARIANT(val.i_int, *result);
INT32_TO_NPVARIANT(val.i_int, result);
return INVOKERESULT_NO_ERROR;
}
else
......@@ -278,19 +275,16 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
&& NPVARIANT_IS_STRING(args[0])
&& isNumberValue(args[1]) )
{
const NPString &name = NPVARIANT_TO_STRING(args[0]);
NPUTF8 *s = new NPUTF8[name.utf8length+1];
char *s = stringValue(NPVARIANT_TO_STRING(args[0]));
if( s )
{
int vlc_id = libvlc_get_vlc_id(p_plugin->getVLC());
vlc_value_t val;
strncpy(s, name.utf8characters, name.utf8length);
s[name.utf8length] = '\0';
val.i_int = numberValue(args[1]);
if( VLC_SUCCESS == VLC_VariableSet(vlc_id, s, val) )
{
delete s;
VOID_TO_NPVARIANT(*result);
VOID_TO_NPVARIANT(result);
return INVOKERESULT_NO_ERROR;
}
else
......@@ -306,18 +300,15 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
case ID_get_bool_variable:
if( (argCount == 1) && NPVARIANT_IS_STRING(args[0]) )
{
const NPString &name = NPVARIANT_TO_STRING(args[0]);
NPUTF8 *s = new NPUTF8[name.utf8length+1];
char *s = stringValue(NPVARIANT_TO_STRING(args[0]));
if( s )
{
int vlc_id = libvlc_get_vlc_id(p_plugin->getVLC());
vlc_value_t val;
strncpy(s, name.utf8characters, name.utf8length);
s[name.utf8length] = '\0';
if( VLC_SUCCESS == VLC_VariableGet(vlc_id, s, &val) )
{
delete s;
BOOLEAN_TO_NPVARIANT(val.b_bool, *result);
BOOLEAN_TO_NPVARIANT(val.b_bool, result);
return INVOKERESULT_NO_ERROR;
}
else
......@@ -335,19 +326,16 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
&& NPVARIANT_IS_STRING(args[0])
&& NPVARIANT_IS_BOOLEAN(args[1]) )
{
const NPString &name = NPVARIANT_TO_STRING(args[0]);
NPUTF8 *s = new NPUTF8[name.utf8length+1];
char *s = stringValue(NPVARIANT_TO_STRING(args[0]));
if( s )
{
int vlc_id = libvlc_get_vlc_id(p_plugin->getVLC());
vlc_value_t val;
strncpy(s, name.utf8characters, name.utf8length);
s[name.utf8length] = '\0';
val.b_bool = NPVARIANT_TO_BOOLEAN(args[1]);
if( VLC_SUCCESS == VLC_VariableSet(vlc_id, s, val) )
{
delete s;
VOID_TO_NPVARIANT(*result);
VOID_TO_NPVARIANT(result);
return INVOKERESULT_NO_ERROR;
}
else
......@@ -363,14 +351,11 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
case ID_get_str_variable:
if( (argCount == 1) && NPVARIANT_IS_STRING(args[0]) )
{
const NPString &name = NPVARIANT_TO_STRING(args[0]);
NPUTF8 *s = new NPUTF8[name.utf8length+1];
char *s = stringValue(NPVARIANT_TO_STRING(args[0]));
if( s )
{
int vlc_id = libvlc_get_vlc_id(p_plugin->getVLC());
vlc_value_t val;
strncpy(s, name.utf8characters, name.utf8length);
s[name.utf8length] = '\0';
if( VLC_SUCCESS == VLC_VariableGet(vlc_id, s, &val) )
{
delete s;
......@@ -381,7 +366,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
if( retval )
{
memcpy(retval, val.psz_string, len);
STRINGN_TO_NPVARIANT(retval, len, *result);
STRINGN_TO_NPVARIANT(retval, len, result);
free(val.psz_string);
return INVOKERESULT_NO_ERROR;
}
......@@ -393,7 +378,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
else
{
/* null string */
STRINGN_TO_NPVARIANT(NULL, 0, *result);
STRINGN_TO_NPVARIANT(NULL, 0, result);
return INVOKERESULT_NO_ERROR;
}
}
......@@ -412,25 +397,19 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
&& NPVARIANT_IS_STRING(args[0])
&& NPVARIANT_IS_STRING(args[1]) )
{
const NPString &name = NPVARIANT_TO_STRING(args[0]);
NPUTF8 *s = new NPUTF8[name.utf8length+1];
char *s = stringValue(NPVARIANT_TO_STRING(args[0]));
if( s )
{
int vlc_id = libvlc_get_vlc_id(p_plugin->getVLC());
vlc_value_t val;
strncpy(s, name.utf8characters, name.utf8length);
s[name.utf8length] = '\0';
const NPString &v = NPVARIANT_TO_STRING(args[1]);
val.psz_string = new NPUTF8[v.utf8length+1];
val.psz_string = stringValue(NPVARIANT_TO_STRING(args[1]));
if( val.psz_string )
{
strncpy(val.psz_string, v.utf8characters, v.utf8length);
val.psz_string[v.utf8length] = '\0';
if( VLC_SUCCESS == VLC_VariableSet(vlc_id, s, val) )
{
delete s;
delete val.psz_string;
VOID_TO_NPVARIANT(*result);
VOID_TO_NPVARIANT(result);
return INVOKERESULT_NO_ERROR;
}
else
......@@ -462,7 +441,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
}
else
{
VOID_TO_NPVARIANT(*result);
VOID_TO_NPVARIANT(result);
return INVOKERESULT_NO_ERROR;
}
}
......@@ -470,13 +449,9 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
case ID_add_item:
if( (argCount == 1) && NPVARIANT_IS_STRING(args[0]) )
{
const NPString &name = NPVARIANT_TO_STRING(args[0]);
NPUTF8 *s = new NPUTF8[name.utf8length+1];
char *s = stringValue(NPVARIANT_TO_STRING(args[0]));
if( s )
{
strncpy(s, name.utf8characters, name.utf8length);
s[name.utf8length] = '\0';
char *url = p_plugin->getAbsoluteURL(s);
delete s;
if( ! url )
......@@ -493,7 +468,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
}
else
{
INT32_TO_NPVARIANT(item, *result);
INT32_TO_NPVARIANT(item, result);
return INVOKERESULT_NO_ERROR;
}
}
......@@ -513,7 +488,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
}
else
{
VOID_TO_NPVARIANT(*result);
VOID_TO_NPVARIANT(result);
return INVOKERESULT_NO_ERROR;
}
}
......@@ -530,7 +505,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
}
else
{
VOID_TO_NPVARIANT(*result);
VOID_TO_NPVARIANT(result);
return INVOKERESULT_NO_ERROR;
}
}
......@@ -547,7 +522,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
}
else
{
BOOLEAN_TO_NPVARIANT(isplaying, *result);
BOOLEAN_TO_NPVARIANT(isplaying, result);
return INVOKERESULT_NO_ERROR;
}
}
......@@ -568,7 +543,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
}
else
{
INT32_TO_NPVARIANT((uint32_t)(val/1000LL), *result);
INT32_TO_NPVARIANT((uint32_t)(val/1000LL), result);
return INVOKERESULT_NO_ERROR;
}
}
......@@ -600,7 +575,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
}
else
{
DOUBLE_TO_NPVARIANT((double)val, *result);
DOUBLE_TO_NPVARIANT((double)val, result);
return INVOKERESULT_NO_ERROR;
}
}
......@@ -632,7 +607,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
}
else
{
DOUBLE_TO_NPVARIANT((uint32_t)(val/1000LL), *result);
DOUBLE_TO_NPVARIANT((uint32_t)(val/1000LL), result);
return INVOKERESULT_NO_ERROR;
}
}
......@@ -680,7 +655,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
libvlc_exception_clear(&ex);
return INVOKERESULT_GENERIC_ERROR;
}
VOID_TO_NPVARIANT(*result);
VOID_TO_NPVARIANT(result);
return INVOKERESULT_NO_ERROR;
}
else
......
......@@ -43,6 +43,6 @@ protected:
static const int methodCount;
static const NPUTF8 * const methodNames[];
virtual InvokeResult invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant *result);
virtual InvokeResult invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result);
};
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