/*****************************************************************************
* npolibvlc.cpp: official Javascript APIs
*****************************************************************************
- * Copyright (C) 2002-2006 the VideoLAN team
+ * Copyright (C) 2002-2009 the VideoLAN team
*
* Authors: Damien Fouilleul <Damien.Fouilleul@laposte.net>
+ * JP Dinger <jpd@m2x.nl>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
{
if( audioObj ) NPN_ReleaseObject(audioObj);
if( inputObj ) NPN_ReleaseObject(inputObj);
- if( logObj ) NPN_ReleaseObject(logObj);
if( playlistObj ) NPN_ReleaseObject(playlistObj);
if( videoObj ) NPN_ReleaseObject(videoObj);
}
{
"audio",
"input",
- "log",
"playlist",
"video",
"VersionInfo",
{
ID_root_audio = 0,
ID_root_input,
- ID_root_log,
ID_root_playlist,
ID_root_video,
ID_root_VersionInfo,
RuntimeNPClass<LibvlcInputNPObject>::getClass());
OBJECT_TO_NPVARIANT(NPN_RetainObject(inputObj), result);
return INVOKERESULT_NO_ERROR;
- case ID_root_log:
- // create child object in lazyman fashion to avoid
- // ownership problem with firefox
- if( ! logObj )
- logObj = NPN_CreateObject(_instance,
- RuntimeNPClass<LibvlcLogNPObject>::getClass());
- OBJECT_TO_NPVARIANT(NPN_RetainObject(logObj), result);
- return INVOKERESULT_NO_ERROR;
case ID_root_playlist:
// create child object in lazyman fashion to avoid
// ownership problem with firefox
OBJECT_TO_NPVARIANT(NPN_RetainObject(videoObj), result);
return INVOKERESULT_NO_ERROR;
case ID_root_VersionInfo:
- {
- const char *s = libvlc_get_version();
- int len = strlen(s);
- NPUTF8 *retval =(NPUTF8*)NPN_MemAlloc(len);
- if( !retval )
- return INVOKERESULT_OUT_OF_MEMORY;
-
- memcpy(retval, s, len);
- STRINGN_TO_NPVARIANT(retval, len, result);
- return INVOKERESULT_NO_ERROR;
- }
+ return invokeResultString(libvlc_get_version(),result);
default:
;
}
switch( index )
{
case ID_root_versionInfo:
- if( argCount == 0 )
- {
- const char *s = libvlc_get_version();
- int len = strlen(s);
- NPUTF8 *retval =(NPUTF8*)NPN_MemAlloc(len);
- if( !retval )
- return INVOKERESULT_OUT_OF_MEMORY;
- memcpy(retval, s, len);
- STRINGN_TO_NPVARIANT(retval, len, result);
- return INVOKERESULT_NO_ERROR;
- }
- return INVOKERESULT_NO_SUCH_METHOD;
+ if( 0 != argCount )
+ return INVOKERESULT_NO_SUCH_METHOD;
+ return invokeResultString(libvlc_get_version(),result);
default:
;
}
COUNTNAMES(LibvlcInputNPObject,methodCount,methodNames);
-/*
-** implementation of libvlc message object
-*/
-
-const NPUTF8 * const LibvlcMessageNPObject::propertyNames[] =
-{
- "severity",
- "type",
- "name",
- "header",
- "message",
-};
-COUNTNAMES(LibvlcMessageNPObject,propertyCount,propertyNames);
-
-enum LibvlcMessageNPObjectPropertyIds
-{
- ID_message_severity,
- ID_message_type,
- ID_message_name,
- ID_message_header,
- ID_message_message,
-};
-
-RuntimeNPObject::InvokeResult
-LibvlcMessageNPObject::getProperty(int index, NPVariant &result)
-{
- /* is plugin still running */
- if( isPluginRunning() )
- {
- switch( index )
- {
- case ID_message_severity:
- {
- INT32_TO_NPVARIANT(_msg.i_severity, result);
- return INVOKERESULT_NO_ERROR;
- }
- case ID_message_type:
- {
- if( _msg.psz_type )
- {
- int len = strlen(_msg.psz_type);
- NPUTF8* retval = (NPUTF8*)NPN_MemAlloc(len);
- if( retval )
- {
- memcpy(retval, _msg.psz_type, len);
- STRINGN_TO_NPVARIANT(retval, len, result);
- }
- }
- else
- {
- NULL_TO_NPVARIANT(result);
- }
- return INVOKERESULT_NO_ERROR;
- }
- case ID_message_name:
- {
- if( _msg.psz_name )
- {
- int len = strlen(_msg.psz_name);
- NPUTF8* retval = (NPUTF8*)NPN_MemAlloc(len);
- if( retval )
- {
- memcpy(retval, _msg.psz_name, len);
- STRINGN_TO_NPVARIANT(retval, len, result);
- }
- }
- else
- {
- NULL_TO_NPVARIANT(result);
- }
- return INVOKERESULT_NO_ERROR;
- }
- case ID_message_header:
- {
- if( _msg.psz_header )
- {
- int len = strlen(_msg.psz_header);
- NPUTF8* retval = (NPUTF8*)NPN_MemAlloc(len);
- if( retval )
- {
- memcpy(retval, _msg.psz_header, len);
- STRINGN_TO_NPVARIANT(retval, len, result);
- }
- }
- else
- {
- NULL_TO_NPVARIANT(result);
- }
- return INVOKERESULT_NO_ERROR;
- }
- case ID_message_message:
- {
- if( _msg.psz_message )
- {
- int len = strlen(_msg.psz_message);
- NPUTF8* retval = (NPUTF8*)NPN_MemAlloc(len);
- if( retval )
- {
- memcpy(retval, _msg.psz_message, len);
- STRINGN_TO_NPVARIANT(retval, len, result);
- }
- }
- else
- {
- NULL_TO_NPVARIANT(result);
- }
- return INVOKERESULT_NO_ERROR;
- }
- default:
- ;
- }
- }
- return INVOKERESULT_GENERIC_ERROR;
-}
-
-const NPUTF8 * const LibvlcMessageNPObject::methodNames[] =
-{
- /* no methods */
-};
-COUNTNAMES(LibvlcMessageNPObject,methodCount,methodNames);
-
-/*
-** implementation of libvlc message iterator object
-*/
-
-LibvlcMessageIteratorNPObject::LibvlcMessageIteratorNPObject(NPP instance,
- const NPClass *aClass) :
- RuntimeNPObject(instance, aClass),
- _p_iter(NULL)
-{
- // XXX FIXME use _instance or instance in this method?
-
- /* is plugin still running */
- if( instance->pdata )
- {
- VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(instance->pdata);
- libvlc_log_t *p_log = p_plugin->getLog();
- if( p_log )
- {
- _p_iter = libvlc_log_get_iterator(p_log, NULL);
- }
- }
-};
-
-LibvlcMessageIteratorNPObject::~LibvlcMessageIteratorNPObject()
-{
- if( _p_iter )
- libvlc_log_iterator_free(_p_iter, NULL);
-}
-
-const NPUTF8 * const LibvlcMessageIteratorNPObject::propertyNames[] =
-{
- "hasNext",
-};
-COUNTNAMES(LibvlcMessageIteratorNPObject,propertyCount,propertyNames);
-
-enum LibvlcMessageIteratorNPObjectPropertyIds
-{
- ID_messageiterator_hasNext,
-};
-
-RuntimeNPObject::InvokeResult
-LibvlcMessageIteratorNPObject::getProperty(int index, NPVariant &result)
-{
- /* is plugin still running */
- if( isPluginRunning() )
- {
- VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
- switch( index )
- {
- case ID_messageiterator_hasNext:
- {
- if( _p_iter && p_plugin->getLog() )
- {
- libvlc_exception_t ex;
- libvlc_exception_init(&ex);
-
- BOOLEAN_TO_NPVARIANT(
- libvlc_log_iterator_has_next(_p_iter, &ex), result );
- RETURN_ON_EXCEPTION(this,ex);
- }
- else
- {
- BOOLEAN_TO_NPVARIANT(0, result);
- }
- return INVOKERESULT_NO_ERROR;
- }
- default:
- ;
- }
- }
- return INVOKERESULT_GENERIC_ERROR;
-}
-
-const NPUTF8 * const LibvlcMessageIteratorNPObject::methodNames[] =
-{
- "next",
-};
-COUNTNAMES(LibvlcMessageIteratorNPObject,methodCount,methodNames);
-
-enum LibvlcMessageIteratorNPObjectMethodIds
-{
- ID_messageiterator_next,
-};
-
-RuntimeNPObject::InvokeResult
-LibvlcMessageIteratorNPObject::invoke(int index, const NPVariant *args,
- uint32_t argCount, NPVariant &result)
-{
- /* is plugin still running */
- if( isPluginRunning() )
- {
- VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
- libvlc_exception_t ex;
- libvlc_exception_init(&ex);
-
- switch( index )
- {
- case ID_messageiterator_next:
- if( argCount == 0 )
- {
- if( _p_iter && p_plugin->getLog() )
- {
- struct libvlc_log_message_t buffer;
-
- buffer.sizeof_msg = sizeof(buffer);
-
- libvlc_log_iterator_next(_p_iter, &buffer, &ex);
- RETURN_ON_EXCEPTION(this,ex);
-
- LibvlcMessageNPObject* message =
- static_cast<LibvlcMessageNPObject*>(
- NPN_CreateObject(_instance, RuntimeNPClass<
- LibvlcMessageNPObject>::getClass()));
- if( message )
- {
- message->setMessage(buffer);
- OBJECT_TO_NPVARIANT(message, result);
- return INVOKERESULT_NO_ERROR;
- }
- return INVOKERESULT_OUT_OF_MEMORY;
- }
- return INVOKERESULT_GENERIC_ERROR;
- }
- return INVOKERESULT_NO_SUCH_METHOD;
- default:
- ;
- }
- }
- return INVOKERESULT_GENERIC_ERROR;
-}
-
-/*
-** implementation of libvlc message object
-*/
-
-const NPUTF8 * const LibvlcMessagesNPObject::propertyNames[] =
-{
- "count",
-};
-COUNTNAMES(LibvlcMessagesNPObject,propertyCount,propertyNames);
-
-enum LibvlcMessagesNPObjectPropertyIds
-{
- ID_messages_count,
-};
-
-RuntimeNPObject::InvokeResult
-LibvlcMessagesNPObject::getProperty(int index, NPVariant &result)
-{
- /* is plugin still running */
- if( isPluginRunning() )
- {
- VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
- switch( index )
- {
- case ID_messages_count:
- {
- libvlc_log_t *p_log = p_plugin->getLog();
- if( p_log )
- {
- libvlc_exception_t ex;
- libvlc_exception_init(&ex);
-
- INT32_TO_NPVARIANT(libvlc_log_count(p_log, &ex), result);
- RETURN_ON_EXCEPTION(this,ex);
- }
- else
- {
- INT32_TO_NPVARIANT(0, result);
- }
- return INVOKERESULT_NO_ERROR;
- }
- default:
- ;
- }
- }
- return INVOKERESULT_GENERIC_ERROR;
-}
-
-const NPUTF8 * const LibvlcMessagesNPObject::methodNames[] =
-{
- "clear",
- "iterator",
-};
-COUNTNAMES(LibvlcMessagesNPObject,methodCount,methodNames);
-
-enum LibvlcMessagesNPObjectMethodIds
-{
- ID_messages_clear,
- ID_messages_iterator,
-};
-
-RuntimeNPObject::InvokeResult
-LibvlcMessagesNPObject::invoke(int index, const NPVariant *args,
- uint32_t argCount, NPVariant &result)
-{
- /* is plugin still running */
- if( isPluginRunning() )
- {
- VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
- libvlc_exception_t ex;
- libvlc_exception_init(&ex);
-
- switch( index )
- {
- case ID_messages_clear:
- if( argCount == 0 )
- {
- libvlc_log_t *p_log = p_plugin->getLog();
- if( p_log )
- {
- libvlc_log_clear(p_log, &ex);
- RETURN_ON_EXCEPTION(this,ex);
- }
- return INVOKERESULT_NO_ERROR;
- }
- return INVOKERESULT_NO_SUCH_METHOD;
-
- case ID_messages_iterator:
- if( argCount == 0 )
- {
- LibvlcMessageIteratorNPObject* iter =
- static_cast<LibvlcMessageIteratorNPObject*>(
- NPN_CreateObject(_instance, RuntimeNPClass<
- LibvlcMessageIteratorNPObject>::getClass()));
- if( iter )
- {
- OBJECT_TO_NPVARIANT(iter, result);
- return INVOKERESULT_NO_ERROR;
- }
- return INVOKERESULT_OUT_OF_MEMORY;
- }
- return INVOKERESULT_NO_SUCH_METHOD;
-
- default:
- ;
- }
- }
- return INVOKERESULT_GENERIC_ERROR;
-}
-
-
-/*
-** implementation of libvlc message object
-*/
-
-
-LibvlcLogNPObject::~LibvlcLogNPObject()
-{
- if( isValid() )
- {
- if( messagesObj ) NPN_ReleaseObject(messagesObj);
- }
-};
-
-const NPUTF8 * const LibvlcLogNPObject::propertyNames[] =
-{
- "messages",
- "verbosity",
-};
-COUNTNAMES(LibvlcLogNPObject,propertyCount,propertyNames);
-
-enum LibvlcLogNPObjectPropertyIds
-{
- ID_log_messages,
- ID_log_verbosity,
-};
-
-RuntimeNPObject::InvokeResult
-LibvlcLogNPObject::getProperty(int index, NPVariant &result)
-{
- /* is plugin still running */
- if( isPluginRunning() )
- {
- VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
- libvlc_exception_t ex;
- libvlc_exception_init(&ex);
-
- switch( index )
- {
- case ID_log_messages:
- {
- // create child object in lazyman fashion to avoid
- // ownership problem with firefox
- if( ! messagesObj )
- messagesObj = NPN_CreateObject(_instance,
- RuntimeNPClass<LibvlcMessagesNPObject>::getClass());
- OBJECT_TO_NPVARIANT(NPN_RetainObject(messagesObj), result);
- return INVOKERESULT_NO_ERROR;
- }
- case ID_log_verbosity:
- {
- if( p_plugin->getLog() )
- {
- INT32_TO_NPVARIANT( libvlc_get_log_verbosity(
- p_plugin->getVLC(), &ex), result);
- RETURN_ON_EXCEPTION(this,ex);
- }
- else
- {
- /* log is not enabled, return -1 */
- DOUBLE_TO_NPVARIANT(-1.0, result);
- }
- return INVOKERESULT_NO_ERROR;
- }
- default:
- ;
- }
- }
- return INVOKERESULT_GENERIC_ERROR;
-}
-
-RuntimeNPObject::InvokeResult
-LibvlcLogNPObject::setProperty(int index, const NPVariant &value)
-{
- /* is plugin still running */
- if( isPluginRunning() )
- {
- VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
- libvlc_exception_t ex;
- libvlc_exception_init(&ex);
-
- switch( index )
- {
- case ID_log_verbosity:
- if( isNumberValue(value) )
- {
- libvlc_instance_t* p_libvlc = p_plugin->getVLC();
- libvlc_log_t *p_log = p_plugin->getLog();
- int verbosity = numberValue(value);
- if( verbosity >= 0 )
- {
- if( !p_log )
- {
- p_log = libvlc_log_open(p_libvlc, &ex);
- RETURN_ON_EXCEPTION(this,ex);
- p_plugin->setLog(p_log);
- }
- libvlc_set_log_verbosity(p_libvlc, (unsigned)verbosity, &ex);
- RETURN_ON_EXCEPTION(this,ex);
- }
- else if( p_log )
- {
- /* close log when verbosity is set to -1 */
- p_plugin->setLog(NULL);
- libvlc_log_close(p_log, &ex);
- RETURN_ON_EXCEPTION(this,ex);
- }
- return INVOKERESULT_NO_ERROR;
- }
- return INVOKERESULT_INVALID_VALUE;
- default:
- ;
- }
- }
- return INVOKERESULT_GENERIC_ERROR;
-}
-
-const NPUTF8 * const LibvlcLogNPObject::methodNames[] =
-{
- /* no methods */
-};
-COUNTNAMES(LibvlcLogNPObject,methodCount,methodNames);
-
/*
** implementation of libvlc playlist items object
*/
** implementation of libvlc playlist object
*/
-
LibvlcPlaylistNPObject::~LibvlcPlaylistNPObject()
{
- if( isValid() )
- {
- if( playlistItemsObj ) NPN_ReleaseObject(playlistItemsObj);
- }
+ // Why the isValid()?
+ if( isValid() && playlistItemsObj )
+ NPN_ReleaseObject(playlistItemsObj);
};
const NPUTF8 * const LibvlcPlaylistNPObject::propertyNames[] =
}
else
{
- free(url);
+ free(url);
free(name);
return INVOKERESULT_INVALID_VALUE;
}
}
- int item = p_plugin->playlist_add_extended_untrusted(url, name, i_options,
- const_cast<const char **>(ppsz_options), &ex);
+ int item = p_plugin->playlist_add_extended_untrusted(url, name,
+ i_options, const_cast<const char **>(ppsz_options), &ex);
free(url);
free(name);
for( int i=0; i< i_options; ++i )