📄 npolibvlc.cpp
字号:
return INVOKERESULT_NO_SUCH_METHOD;
case ID_playlist_next:
if( argCount == 0 )
{
libvlc_playlist_next(p_plugin->getVLC(), &ex);
if( libvlc_exception_raised(&ex) )
{
NPN_SetException(this, libvlc_exception_get_message(&ex));
libvlc_exception_clear(&ex);
return INVOKERESULT_GENERIC_ERROR;
}
else
{
VOID_TO_NPVARIANT(result);
return INVOKERESULT_NO_ERROR;
}
}
return INVOKERESULT_NO_SUCH_METHOD;
case ID_playlist_prev:
if( argCount == 0 )
{
libvlc_playlist_prev(p_plugin->getVLC(), &ex);
if( libvlc_exception_raised(&ex) )
{
NPN_SetException(this, libvlc_exception_get_message(&ex));
libvlc_exception_clear(&ex);
return INVOKERESULT_GENERIC_ERROR;
}
else
{
VOID_TO_NPVARIANT(result);
return INVOKERESULT_NO_ERROR;
}
}
return INVOKERESULT_NO_SUCH_METHOD;
case ID_playlist_clear: /* deprecated */
if( argCount == 0 )
{
libvlc_playlist_clear(p_plugin->getVLC(), &ex);
if( libvlc_exception_raised(&ex) )
{
NPN_SetException(this, libvlc_exception_get_message(&ex));
libvlc_exception_clear(&ex);
return INVOKERESULT_GENERIC_ERROR;
}
else
{
VOID_TO_NPVARIANT(result);
return INVOKERESULT_NO_ERROR;
}
}
return INVOKERESULT_NO_SUCH_METHOD;
case ID_playlist_removeitem: /* deprecated */
if( (argCount == 1) && isNumberValue(args[0]) )
{
libvlc_playlist_delete_item(p_plugin->getVLC(), numberValue(args[0]), &ex);
if( libvlc_exception_raised(&ex) )
{
NPN_SetException(this, libvlc_exception_get_message(&ex));
libvlc_exception_clear(&ex);
return INVOKERESULT_GENERIC_ERROR;
}
else
{
VOID_TO_NPVARIANT(result);
return INVOKERESULT_NO_ERROR;
}
}
return INVOKERESULT_NO_SUCH_METHOD;
default:
;
}
}
return INVOKERESULT_GENERIC_ERROR;
}
void LibvlcPlaylistNPObject::parseOptions(const NPString &nps, int *i_options, char*** ppsz_options)
{
if( nps.utf8length )
{
char *s = stringValue(nps);
char *val = s;
if( val )
{
long capacity = 16;
char **options = (char **)malloc(capacity*sizeof(char *));
if( options )
{
int nOptions = 0;
char *end = val + nps.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 s;
/* return what we got so far */
*i_options = nOptions;
*ppsz_options = options;
return;
}
options = moreOptions;
}
*(val++) = '\0';
options[nOptions++] = strdup(start);
}
else
// must be end of string
break;
}
*i_options = nOptions;
*ppsz_options = options;
}
delete s;
}
}
}
void LibvlcPlaylistNPObject::parseOptions(NPObject *obj, int *i_options, char*** ppsz_options)
{
/* WARNING: Safari does not implement NPN_HasProperty/NPN_HasMethod */
NPVariant value;
/* we are expecting to have a Javascript Array object */
NPIdentifier propId = NPN_GetStringIdentifier("length");
if( NPN_GetProperty(_instance, obj, propId, &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 )
{
propId = NPN_GetIntIdentifier(nOptions);
if( ! NPN_GetProperty(_instance, obj, propId, &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
*/
const NPUTF8 * const LibvlcVideoNPObject::propertyNames[] =
{
"fullscreen",
"height",
"width",
"aspectRatio"
};
enum LibvlcVideoNPObjectPropertyIds
{
ID_video_fullscreen,
ID_video_height,
ID_video_width,
ID_video_aspectratio
};
const int LibvlcVideoNPObject::propertyCount = sizeof(LibvlcVideoNPObject::propertyNames)/sizeof(NPUTF8 *);
RuntimeNPObject::InvokeResult LibvlcVideoNPObject::getProperty(int index, NPVariant &result)
{
/* is plugin still running */
if( _instance->pdata )
{
VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
libvlc_exception_t ex;
libvlc_exception_init(&ex);
libvlc_input_t *p_input = libvlc_playlist_get_input(p_plugin->getVLC(), &ex);
if( libvlc_exception_raised(&ex) )
{
NPN_SetException(this, libvlc_exception_get_message(&ex));
libvlc_exception_clear(&ex);
return INVOKERESULT_GENERIC_ERROR;
}
switch( index )
{
case ID_video_fullscreen:
{
int val = libvlc_get_fullscreen(p_input, &ex);
libvlc_input_free(p_input);
if( libvlc_exception_raised(&ex) )
{
NPN_SetException(this, libvlc_exception_get_message(&ex));
libvlc_exception_clear(&ex);
return INVOKERESULT_GENERIC_ERROR;
}
BOOLEAN_TO_NPVARIANT(val, result);
return INVOKERESULT_NO_ERROR;
}
case ID_video_height:
{
int val = libvlc_video_get_height(p_input, &ex);
libvlc_input_free(p_input);
if( libvlc_exception_raised(&ex) )
{
NPN_SetException(this, libvlc_exception_get_message(&ex));
libvlc_exception_clear(&ex);
return INVOKERESULT_GENERIC_ERROR;
}
INT32_TO_NPVARIANT(val, result);
return INVOKERESULT_NO_ERROR;
}
case ID_video_width:
{
int val = libvlc_video_get_width(p_input, &ex);
libvlc_input_free(p_input);
if( libvlc_exception_raised(&ex) )
{
NPN_SetException(this, libvlc_exception_get_message(&ex));
libvlc_exception_clear(&ex);
return INVOKERESULT_GENERIC_ERROR;
}
INT32_TO_NPVARIANT(val, result);
return INVOKERESULT_NO_ERROR;
}
case ID_video_aspectratio:
{
NPUTF8 *psz_aspect = libvlc_video_get_aspect_ratio(p_input, &ex);
libvlc_input_free(p_input);
if( libvlc_exception_raised(&ex) )
{
NPN_SetException(this, libvlc_exception_get_message(&ex));
libvlc_exception_clear(&ex);
return INVOKERESULT_GENERIC_ERROR;
}
if( !psz_aspect )
return INVOKERESULT_GENERIC_ERROR;
STRINGZ_TO_NPVARIANT(psz_aspect, result);
return INVOKERESULT_NO_ERROR;
}
}
libvlc_input_free(p_input);
}
return INVOKERESULT_GENERIC_ERROR;
}
RuntimeNPObject::InvokeResult LibvlcVideoNPObject::setProperty(int index, const NPVariant &value)
{
/* is plugin still running */
if( _instance->pdata )
{
VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
libvlc_exception_t ex;
libvlc_exception_init(&ex);
libvlc_input_t *p_input = libvlc_playlist_get_input(p_plugin->getVLC(), &ex);
if( libvlc_exception_raised(&ex) )
{
NPN_SetException(this, libvlc_exception_get_message(&ex));
libvlc_exception_clear(&ex);
return INVOKERESULT_GENERIC_ERROR;
}
switch( index )
{
case ID_video_fullscreen:
{
if( ! NPVARIANT_IS_BOOLEAN(value) )
{
libvlc_input_free(p_input);
return INVOKERESULT_INVALID_VALUE;
}
int val = NPVARIANT_TO_BOOLEAN(value);
libvlc_set_fullscreen(p_input, val, &ex);
libvlc_input_free(p_input);
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;
}
case ID_video_aspectratio:
{
char *psz_aspect = NULL;
if( ! NPVARIANT_IS_STRING(value) )
{
libvlc_input_free(p_input);
return INVOKERESULT_INVALID_VALUE;
}
psz_aspect = stringValue(NPVARIANT_TO_STRING(value));
if( !psz_aspect )
{
libvlc_input_free(p_input);
return INVOKERESULT_GENERIC_ERROR;
}
libvlc_video_set_aspect_ratio(p_input, psz_aspect, &ex);
delete psz_aspect;
libvlc_input_free(p_input);
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;
}
}
libvlc_input_free(p_input);
}
return INVOKERESULT_GENER
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -