# include <mozilla-config.h>\r
#endif\r
\r
-#include "npolibvlc.h"\r
#include "vlcplugin.h"\r
+#include "npolibvlc.h"\r
\r
/*\r
** implementation of libvlc root object\r
*/\r
\r
-LibvlcRootNPObject::LibvlcRootNPObject(NPP instance, const NPClass *aClass) :\r
- RuntimeNPObject(instance, aClass)\r
-{\r
- audioObj = NPN_CreateObject(instance, RuntimeNPClass<LibvlcAudioNPObject>::getClass());\r
- inputObj = NPN_CreateObject(instance, RuntimeNPClass<LibvlcInputNPObject>::getClass());\r
- logObj = NPN_CreateObject(instance, RuntimeNPClass<LibvlcLogNPObject>::getClass());\r
- playlistObj = NPN_CreateObject(instance, RuntimeNPClass<LibvlcPlaylistNPObject>::getClass());\r
- videoObj = NPN_CreateObject(instance,RuntimeNPClass<LibvlcVideoNPObject>::getClass());\r
-}\r
-\r
LibvlcRootNPObject::~LibvlcRootNPObject()\r
{\r
- NPN_ReleaseObject(audioObj);\r
- NPN_ReleaseObject(inputObj);\r
- NPN_ReleaseObject(logObj);\r
- NPN_ReleaseObject(playlistObj);\r
- NPN_ReleaseObject(videoObj);\r
+ /*\r
+ ** when plugin is destroyed, firefox takes upon itself to destroy all 'live' script objects\r
+ ** and ignores refcounting. Therefore we cannot safely assume that refcounting will control\r
+ ** lifespan of objects. Hence they are only lazily created on request, so that firefox can\r
+ ** take ownership, and are not released when plugin is being destroyed.\r
+ */\r
+ if( isValid() )\r
+ {\r
+ if( audioObj ) NPN_ReleaseObject(audioObj);\r
+ if( inputObj ) NPN_ReleaseObject(inputObj);\r
+ if( logObj ) NPN_ReleaseObject(logObj);\r
+ if( playlistObj ) NPN_ReleaseObject(playlistObj);\r
+ if( videoObj ) NPN_ReleaseObject(videoObj);\r
+ }\r
}\r
\r
const NPUTF8 * const LibvlcRootNPObject::propertyNames[] = \r
\r
RuntimeNPObject::InvokeResult LibvlcRootNPObject::getProperty(int index, NPVariant &result)\r
{\r
- VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);\r
- if( p_plugin )\r
+ /* is plugin still running */\r
+ if( _instance->pdata )\r
{\r
switch( index )\r
{\r
case ID_root_audio:\r
+ // create child object in lazyman fashion to avoid ownership problem with firefox\r
+ if( ! audioObj )\r
+ audioObj = NPN_CreateObject(_instance, RuntimeNPClass<LibvlcAudioNPObject>::getClass());\r
OBJECT_TO_NPVARIANT(NPN_RetainObject(audioObj), result);\r
return INVOKERESULT_NO_ERROR;\r
case ID_root_input:\r
+ // create child object in lazyman fashion to avoid ownership problem with firefox\r
+ if( ! inputObj )\r
+ inputObj = NPN_CreateObject(_instance, RuntimeNPClass<LibvlcInputNPObject>::getClass());\r
OBJECT_TO_NPVARIANT(NPN_RetainObject(inputObj), result);\r
return INVOKERESULT_NO_ERROR;\r
case ID_root_log:\r
+ // create child object in lazyman fashion to avoid ownership problem with firefox\r
+ if( ! logObj )\r
+ logObj = NPN_CreateObject(_instance, RuntimeNPClass<LibvlcLogNPObject>::getClass());\r
OBJECT_TO_NPVARIANT(NPN_RetainObject(logObj), result);\r
return INVOKERESULT_NO_ERROR;\r
case ID_root_playlist:\r
+ // create child object in lazyman fashion to avoid ownership problem with firefox\r
+ if( ! playlistObj )\r
+ playlistObj = NPN_CreateObject(_instance, RuntimeNPClass<LibvlcPlaylistNPObject>::getClass());\r
OBJECT_TO_NPVARIANT(NPN_RetainObject(playlistObj), result);\r
return INVOKERESULT_NO_ERROR;\r
case ID_root_video:\r
+ // create child object in lazyman fashion to avoid ownership problem with firefox\r
+ if( ! videoObj )\r
+ videoObj = NPN_CreateObject(_instance,RuntimeNPClass<LibvlcVideoNPObject>::getClass());\r
OBJECT_TO_NPVARIANT(NPN_RetainObject(videoObj), result);\r
return INVOKERESULT_NO_ERROR;\r
case ID_root_VersionInfo:\r
\r
RuntimeNPObject::InvokeResult LibvlcRootNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)\r
{\r
- VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);\r
- if( p_plugin )\r
+ /* is plugin still running */\r
+ if( _instance->pdata )\r
{\r
libvlc_exception_t ex;\r
libvlc_exception_init(&ex);\r
{\r
"mute",\r
"volume",\r
+ "track",\r
+ "channel",\r
};\r
\r
const int LibvlcAudioNPObject::propertyCount = sizeof(LibvlcAudioNPObject::propertyNames)/sizeof(NPUTF8 *);\r
{\r
ID_audio_mute,\r
ID_audio_volume,\r
+ ID_audio_track,\r
+ ID_audio_channel,\r
};\r
\r
RuntimeNPObject::InvokeResult LibvlcAudioNPObject::getProperty(int index, NPVariant &result)\r
{\r
- VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);\r
- if( p_plugin )\r
+ /* is plugin still running */\r
+ if( _instance->pdata )\r
{\r
+ VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);\r
libvlc_exception_t ex;\r
libvlc_exception_init(&ex);\r
\r
INT32_TO_NPVARIANT(volume, result);\r
return INVOKERESULT_NO_ERROR;\r
}\r
+ case ID_audio_track:\r
+ {\r
+ libvlc_media_instance_t *p_md = libvlc_playlist_get_media_instance(p_plugin->getVLC(), &ex);\r
+ if( libvlc_exception_raised(&ex) )\r
+ {\r
+ NPN_SetException(this, libvlc_exception_get_message(&ex));\r
+ libvlc_exception_clear(&ex);\r
+ return INVOKERESULT_GENERIC_ERROR;\r
+ }\r
+ int track = libvlc_audio_get_track(p_md, &ex);\r
+ libvlc_media_instance_release(p_md);\r
+ if( libvlc_exception_raised(&ex) )\r
+ {\r
+ NPN_SetException(this, libvlc_exception_get_message(&ex));\r
+ libvlc_exception_clear(&ex);\r
+ return INVOKERESULT_GENERIC_ERROR;\r
+ }\r
+ INT32_TO_NPVARIANT(track, result);\r
+ return INVOKERESULT_NO_ERROR;\r
+ }\r
+ case ID_audio_channel:\r
+ {\r
+ int channel = libvlc_audio_get_channel(p_plugin->getVLC(), &ex);\r
+ if( libvlc_exception_raised(&ex) )\r
+ {\r
+ NPN_SetException(this, libvlc_exception_get_message(&ex));\r
+ libvlc_exception_clear(&ex);\r
+ return INVOKERESULT_GENERIC_ERROR;\r
+ }\r
+ INT32_TO_NPVARIANT(channel, result);\r
+ return INVOKERESULT_NO_ERROR;\r
+ }\r
default:\r
;\r
}\r
\r
RuntimeNPObject::InvokeResult LibvlcAudioNPObject::setProperty(int index, const NPVariant &value)\r
{\r
- VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);\r
- if( p_plugin )\r
+ /* is plugin still running */\r
+ if( _instance->pdata )\r
{\r
+ VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);\r
libvlc_exception_t ex;\r
libvlc_exception_init(&ex);\r
\r
return INVOKERESULT_NO_ERROR;\r
}\r
return INVOKERESULT_INVALID_VALUE;\r
+ case ID_audio_track:\r
+ if( isNumberValue(value) )\r
+ {\r
+ libvlc_media_instance_t *p_md = libvlc_playlist_get_media_instance(p_plugin->getVLC(), &ex);\r
+ if( libvlc_exception_raised(&ex) )\r
+ {\r
+ NPN_SetException(this, libvlc_exception_get_message(&ex));\r
+ libvlc_exception_clear(&ex);\r
+ return INVOKERESULT_GENERIC_ERROR;\r
+ }\r
+ libvlc_audio_set_track(p_md,\r
+ numberValue(value), &ex);\r
+ libvlc_media_instance_release(p_md);\r
+ if( libvlc_exception_raised(&ex) )\r
+ {\r
+ NPN_SetException(this, libvlc_exception_get_message(&ex));\r
+ libvlc_exception_clear(&ex);\r
+ return INVOKERESULT_GENERIC_ERROR;\r
+ }\r
+ return INVOKERESULT_NO_ERROR;\r
+ }\r
+ return INVOKERESULT_INVALID_VALUE;\r
+ case ID_audio_channel:\r
+ if( isNumberValue(value) )\r
+ {\r
+ libvlc_audio_set_channel(p_plugin->getVLC(),\r
+ numberValue(value), &ex);\r
+ if( libvlc_exception_raised(&ex) )\r
+ {\r
+ NPN_SetException(this, libvlc_exception_get_message(&ex));\r
+ libvlc_exception_clear(&ex);\r
+ return INVOKERESULT_GENERIC_ERROR;\r
+ }\r
+ return INVOKERESULT_NO_ERROR;\r
+ }\r
+ return INVOKERESULT_INVALID_VALUE;\r
default:\r
;\r
}\r
\r
RuntimeNPObject::InvokeResult LibvlcAudioNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)\r
{\r
- VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);\r
- if( p_plugin )\r
+ /* is plugin still running */\r
+ if( _instance->pdata )\r
{\r
+ VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);\r
libvlc_exception_t ex;\r
libvlc_exception_init(&ex);\r
\r
\r
RuntimeNPObject::InvokeResult LibvlcInputNPObject::getProperty(int index, NPVariant &result)\r
{\r
- VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);\r
- if( p_plugin )\r
+ /* is plugin still running */\r
+ if( _instance->pdata )\r
{\r
+ VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);\r
libvlc_exception_t ex;\r
libvlc_exception_init(&ex);\r
\r
- libvlc_input_t *p_input = libvlc_playlist_get_input(p_plugin->getVLC(), &ex);\r
+ libvlc_media_instance_t *p_md = libvlc_playlist_get_media_instance(p_plugin->getVLC(), &ex);\r
if( libvlc_exception_raised(&ex) )\r
{\r
if( index != ID_input_state )\r
{\r
case ID_input_length:\r
{\r
- double val = (double)libvlc_input_get_length(p_input, &ex);\r
- libvlc_input_free(p_input);\r
+ double val = (double)libvlc_media_instance_get_length(p_md, &ex);\r
+ libvlc_media_instance_release(p_md);\r
if( libvlc_exception_raised(&ex) )\r
{\r
NPN_SetException(this, libvlc_exception_get_message(&ex));\r
}\r
case ID_input_position:\r
{\r
- double val = libvlc_input_get_position(p_input, &ex);\r
- libvlc_input_free(p_input);\r
+ double val = libvlc_media_instance_get_position(p_md, &ex);\r
+ libvlc_media_instance_release(p_md);\r
if( libvlc_exception_raised(&ex) )\r
{\r
NPN_SetException(this, libvlc_exception_get_message(&ex));\r
}\r
case ID_input_time:\r
{\r
- double val = (double)libvlc_input_get_time(p_input, &ex);\r
- libvlc_input_free(p_input);\r
+ double val = (double)libvlc_media_instance_get_time(p_md, &ex);\r
+ libvlc_media_instance_release(p_md);\r
if( libvlc_exception_raised(&ex) )\r
{\r
NPN_SetException(this, libvlc_exception_get_message(&ex));\r
}\r
case ID_input_state:\r
{\r
- int val = libvlc_input_get_state(p_input, &ex);\r
- libvlc_input_free(p_input);\r
+ int val = libvlc_media_instance_get_state(p_md, &ex);\r
+ libvlc_media_instance_release(p_md);\r
if( libvlc_exception_raised(&ex) )\r
{\r
NPN_SetException(this, libvlc_exception_get_message(&ex));\r
}\r
case ID_input_rate:\r
{\r
- float val = libvlc_input_get_rate(p_input, &ex);\r
- libvlc_input_free(p_input);\r
+ float val = libvlc_media_instance_get_rate(p_md, &ex);\r
+ libvlc_media_instance_release(p_md);\r
if( libvlc_exception_raised(&ex) )\r
{\r
NPN_SetException(this, libvlc_exception_get_message(&ex));\r
}\r
case ID_input_fps:\r
{\r
- double val = libvlc_input_get_fps(p_input, &ex);\r
- libvlc_input_free(p_input);\r
+ double val = libvlc_media_instance_get_fps(p_md, &ex);\r
+ libvlc_media_instance_release(p_md);\r
if( libvlc_exception_raised(&ex) )\r
{\r
NPN_SetException(this, libvlc_exception_get_message(&ex));\r
}\r
case ID_input_hasvout:\r
{\r
- vlc_bool_t val = libvlc_input_has_vout(p_input, &ex);\r
- libvlc_input_free(p_input);\r
+ vlc_bool_t val = libvlc_media_instance_has_vout(p_md, &ex);\r
+ libvlc_media_instance_release(p_md);\r
if( libvlc_exception_raised(&ex) )\r
{\r
NPN_SetException(this, libvlc_exception_get_message(&ex));\r
default:\r
;\r
}\r
- libvlc_input_free(p_input);\r
+ libvlc_media_instance_release(p_md);\r
}\r
return INVOKERESULT_GENERIC_ERROR;\r
}\r
\r
RuntimeNPObject::InvokeResult LibvlcInputNPObject::setProperty(int index, const NPVariant &value)\r
{\r
- VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);\r
- if( p_plugin )\r
+ /* is plugin still running */\r
+ if( _instance->pdata )\r
{\r
+ VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);\r
libvlc_exception_t ex;\r
libvlc_exception_init(&ex);\r
\r
- libvlc_input_t *p_input = libvlc_playlist_get_input(p_plugin->getVLC(), &ex);\r
+ libvlc_media_instance_t *p_md = libvlc_playlist_get_media_instance(p_plugin->getVLC(), &ex);\r
if( libvlc_exception_raised(&ex) )\r
{\r
NPN_SetException(this, libvlc_exception_get_message(&ex));\r
{\r
if( ! NPVARIANT_IS_DOUBLE(value) )\r
{\r
- libvlc_input_free(p_input);\r
+ libvlc_media_instance_release(p_md);\r
return INVOKERESULT_INVALID_VALUE;\r
}\r
\r
float val = (float)NPVARIANT_TO_DOUBLE(value);\r
- libvlc_input_set_position(p_input, val, &ex);\r
- libvlc_input_free(p_input);\r
+ libvlc_media_instance_set_position(p_md, val, &ex);\r
+ libvlc_media_instance_release(p_md);\r
if( libvlc_exception_raised(&ex) )\r
{\r
NPN_SetException(this, libvlc_exception_get_message(&ex));\r
val = (vlc_int64_t)NPVARIANT_TO_DOUBLE(value);\r
else\r
{\r
- libvlc_input_free(p_input);\r
+ libvlc_media_instance_release(p_md);\r
return INVOKERESULT_INVALID_VALUE;\r
}\r
\r
- libvlc_input_set_time(p_input, val, &ex);\r
- libvlc_input_free(p_input);\r
+ libvlc_media_instance_set_time(p_md, val, &ex);\r
+ libvlc_media_instance_release(p_md);\r
if( libvlc_exception_raised(&ex) )\r
{\r
NPN_SetException(this, libvlc_exception_get_message(&ex));\r
val = (float)NPVARIANT_TO_DOUBLE(value);\r
else\r
{\r
- libvlc_input_free(p_input);\r
+ libvlc_media_instance_release(p_md);\r
return INVOKERESULT_INVALID_VALUE;\r
}\r
\r
- libvlc_input_set_rate(p_input, val, &ex);\r
- libvlc_input_free(p_input);\r
+ libvlc_media_instance_set_rate(p_md, val, &ex);\r
+ libvlc_media_instance_release(p_md);\r
if( libvlc_exception_raised(&ex) )\r
{\r
NPN_SetException(this, libvlc_exception_get_message(&ex));\r
default:\r
;\r
}\r
- libvlc_input_free(p_input);\r
+ libvlc_media_instance_release(p_md);\r
}\r
return INVOKERESULT_GENERIC_ERROR;\r
}\r
\r
RuntimeNPObject::InvokeResult LibvlcMessageNPObject::getProperty(int index, NPVariant &result)\r
{\r
- VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);\r
- if( p_plugin )\r
+ /* is plugin still running */\r
+ if( _instance->pdata )\r
{\r
switch( index )\r
{\r
RuntimeNPObject(instance, aClass),\r
_p_iter(NULL)\r
{\r
- VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);\r
- if( p_plugin )\r
+ /* is plugin still running */\r
+ if( instance->pdata )\r
{\r
+ VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(instance->pdata);\r
libvlc_log_t *p_log = p_plugin->getLog();\r
if( p_log )\r
{\r
\r
RuntimeNPObject::InvokeResult LibvlcMessageIteratorNPObject::getProperty(int index, NPVariant &result)\r
{\r
- VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);\r
- if( p_plugin )\r
+ /* is plugin still running */\r
+ if( _instance->pdata )\r
{\r
+ VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);\r
switch( index )\r
{\r
case ID_messageiterator_hasNext:\r
\r
RuntimeNPObject::InvokeResult LibvlcMessageIteratorNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)\r
{\r
- VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);\r
- if( p_plugin )\r
+ /* is plugin still running */\r
+ if( _instance->pdata )\r
{\r
+ VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);\r
libvlc_exception_t ex;\r
libvlc_exception_init(&ex);\r
\r
\r
RuntimeNPObject::InvokeResult LibvlcMessagesNPObject::getProperty(int index, NPVariant &result)\r
{\r
- VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);\r
- if( p_plugin )\r
+ /* is plugin still running */\r
+ if( _instance->pdata )\r
{\r
+ VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);\r
switch( index )\r
{\r
case ID_messages_count:\r
\r
RuntimeNPObject::InvokeResult LibvlcMessagesNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)\r
{\r
- VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);\r
- if( p_plugin )\r
+ /* is plugin still running */\r
+ if( _instance->pdata )\r
{\r
+ VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);\r
libvlc_exception_t ex;\r
libvlc_exception_init(&ex);\r
\r
*/\r
\r
\r
-LibvlcLogNPObject::LibvlcLogNPObject(NPP instance, const NPClass *aClass) :\r
- RuntimeNPObject(instance, aClass)\r
-{\r
- _p_vlcmessages = static_cast<LibvlcMessagesNPObject*>(NPN_CreateObject(instance, RuntimeNPClass<LibvlcMessagesNPObject>::getClass()));\r
-};\r
- \r
LibvlcLogNPObject::~LibvlcLogNPObject()\r
{\r
- NPN_ReleaseObject(_p_vlcmessages);\r
+ if( isValid() )\r
+ {\r
+ if( messagesObj ) NPN_ReleaseObject(messagesObj);\r
+ }\r
};\r
\r
const NPUTF8 * const LibvlcLogNPObject::propertyNames[] = \r
\r
RuntimeNPObject::InvokeResult LibvlcLogNPObject::getProperty(int index, NPVariant &result)\r
{\r
- VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);\r
- if( p_plugin )\r
+ /* is plugin still running */\r
+ if( _instance->pdata )\r
{\r
+ VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);\r
libvlc_exception_t ex;\r
libvlc_exception_init(&ex);\r
\r
{\r
case ID_log_messages:\r
{\r
- OBJECT_TO_NPVARIANT(NPN_RetainObject(_p_vlcmessages), result);\r
+ // create child object in lazyman fashion to avoid ownership problem with firefox\r
+ if( ! messagesObj )\r
+ messagesObj = NPN_CreateObject(_instance, RuntimeNPClass<LibvlcMessagesNPObject>::getClass());\r
+ OBJECT_TO_NPVARIANT(NPN_RetainObject(messagesObj), result);\r
return INVOKERESULT_NO_ERROR;\r
}\r
case ID_log_verbosity:\r
\r
RuntimeNPObject::InvokeResult LibvlcLogNPObject::setProperty(int index, const NPVariant &value)\r
{\r
- VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);\r
- if( p_plugin )\r
+ /* is plugin still running */\r
+ if( _instance->pdata )\r
{\r
+ VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);\r
libvlc_exception_t ex;\r
libvlc_exception_init(&ex);\r
\r
\r
RuntimeNPObject::InvokeResult LibvlcPlaylistItemsNPObject::getProperty(int index, NPVariant &result)\r
{\r
- VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);\r
- if( p_plugin )\r
+ /* is plugin still running */\r
+ if( _instance->pdata )\r
{\r
+ VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);\r
libvlc_exception_t ex;\r
libvlc_exception_init(&ex);\r
\r
\r
RuntimeNPObject::InvokeResult LibvlcPlaylistItemsNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)\r
{\r
- VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);\r
- if( p_plugin )\r
+ /* is plugin still running */\r
+ if( _instance->pdata )\r
{\r
+ VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);\r
libvlc_exception_t ex;\r
libvlc_exception_init(&ex);\r
\r
*/\r
\r
\r
-LibvlcPlaylistNPObject::LibvlcPlaylistNPObject(NPP instance, const NPClass *aClass) :\r
- RuntimeNPObject(instance, aClass)\r
-{\r
- _p_vlcplaylistitems = static_cast<LibvlcPlaylistItemsNPObject*>(NPN_CreateObject(instance, RuntimeNPClass<LibvlcPlaylistItemsNPObject>::getClass()));\r
-};\r
- \r
LibvlcPlaylistNPObject::~LibvlcPlaylistNPObject()\r
{\r
- NPN_ReleaseObject(_p_vlcplaylistitems);\r
+ if( isValid() )\r
+ {\r
+ if( playlistItemsObj ) NPN_ReleaseObject(playlistItemsObj);\r
+ }\r
};\r
\r
const NPUTF8 * const LibvlcPlaylistNPObject::propertyNames[] = \r
\r
RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::getProperty(int index, NPVariant &result)\r
{\r
- VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);\r
- if( p_plugin )\r
+ /* is plugin still running */\r
+ if( _instance->pdata )\r
{\r
+ VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);\r
libvlc_exception_t ex;\r
libvlc_exception_init(&ex);\r
\r
}\r
case ID_playlist_items:\r
{\r
- OBJECT_TO_NPVARIANT(NPN_RetainObject(_p_vlcplaylistitems), result);\r
+ // create child object in lazyman fashion to avoid ownership problem with firefox\r
+ if( ! playlistItemsObj )\r
+ playlistItemsObj = NPN_CreateObject(_instance, RuntimeNPClass<LibvlcPlaylistItemsNPObject>::getClass());\r
+ OBJECT_TO_NPVARIANT(NPN_RetainObject(playlistItemsObj), result);\r
return INVOKERESULT_NO_ERROR;\r
}\r
default:\r
\r
RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)\r
{\r
- VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);\r
- if( p_plugin )\r
+ /* is plugin still running */\r
+ if( _instance->pdata )\r
{\r
+ VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);\r
libvlc_exception_t ex;\r
libvlc_exception_init(&ex);\r
\r
name = stringValue(NPVARIANT_TO_STRING(args[0]));\r
}\r
else\r
- return INVOKERESULT_NO_SUCH_METHOD;\r
+ {\r
+ delete url;\r
+ return INVOKERESULT_INVALID_VALUE;\r
+ }\r
}\r
\r
int i_options = 0;\r
{\r
parseOptions(NPVARIANT_TO_OBJECT(args[2]), &i_options, &ppsz_options);\r
}\r
+ else\r
+ {\r
+ delete url;\r
+ delete name;\r
+ return INVOKERESULT_INVALID_VALUE;\r
+ }\r
}\r
\r
int item = libvlc_playlist_add_extended(p_plugin->getVLC(),\r
delete name;\r
for( int i=0; i< i_options; ++i )\r
{\r
- if( ppsz_options[i] )\r
- free(ppsz_options[i]);\r
+ delete ppsz_options[i];\r
}\r
- if( ppsz_options )\r
- free(ppsz_options);\r
+ delete ppsz_options;\r
+\r
if( libvlc_exception_raised(&ex) )\r
{\r
NPN_SetException(this, libvlc_exception_get_message(&ex));\r
return INVOKERESULT_GENERIC_ERROR;\r
}\r
\r
-void LibvlcPlaylistNPObject::parseOptions(const NPString &s, int *i_options, char*** ppsz_options)\r
+void LibvlcPlaylistNPObject::parseOptions(const NPString &nps, int *i_options, char*** ppsz_options)\r
{\r
- if( s.utf8length )\r
+ if( nps.utf8length )\r
{\r
- char *val = stringValue(s);\r
+ char *s = stringValue(nps);\r
+ char *val = s;\r
if( val )\r
{\r
long capacity = 16;\r
{\r
int nOptions = 0;\r
\r
- char *end = val + s.utf8length;\r
+ char *end = val + nps.utf8length;\r
while( val < end )\r
{\r
// skip leading blanks\r
if( ! moreOptions )\r
{\r
/* failed to allocate more memory */\r
- delete val;\r
+ delete s;\r
/* return what we got so far */\r
*i_options = nOptions;\r
*ppsz_options = options;\r
- break;\r
+ return;\r
}\r
options = moreOptions;\r
}\r
*i_options = nOptions;\r
*ppsz_options = options;\r
}\r
- delete val;\r
+ delete s;\r
}\r
}\r
}\r
"fullscreen",\r
"height",\r
"width",\r
- "aspectRatio"\r
+ "aspectRatio",\r
+ "subtitle",\r
+ "crop",\r
+ "teletext"\r
};\r
\r
enum LibvlcVideoNPObjectPropertyIds\r
ID_video_fullscreen,\r
ID_video_height,\r
ID_video_width,\r
- ID_video_aspectratio\r
+ ID_video_aspectratio,\r
+ ID_video_subtitle,\r
+ ID_video_crop,\r
+ ID_video_teletext\r
};\r
\r
const int LibvlcVideoNPObject::propertyCount = sizeof(LibvlcVideoNPObject::propertyNames)/sizeof(NPUTF8 *);\r
\r
RuntimeNPObject::InvokeResult LibvlcVideoNPObject::getProperty(int index, NPVariant &result)\r
{\r
- VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);\r
- if( p_plugin )\r
+ /* is plugin still running */\r
+ if( _instance->pdata )\r
{\r
+ VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);\r
libvlc_exception_t ex;\r
libvlc_exception_init(&ex);\r
\r
- libvlc_input_t *p_input = libvlc_playlist_get_input(p_plugin->getVLC(), &ex);\r
+ libvlc_media_instance_t *p_md = libvlc_playlist_get_media_instance(p_plugin->getVLC(), &ex);\r
if( libvlc_exception_raised(&ex) )\r
{\r
NPN_SetException(this, libvlc_exception_get_message(&ex));\r
{\r
case ID_video_fullscreen:\r
{\r
- int val = libvlc_get_fullscreen(p_input, &ex);\r
- libvlc_input_free(p_input);\r
+ int val = libvlc_get_fullscreen(p_md, &ex);\r
+ libvlc_media_instance_release(p_md);\r
if( libvlc_exception_raised(&ex) )\r
{\r
NPN_SetException(this, libvlc_exception_get_message(&ex));\r
}\r
case ID_video_height:\r
{\r
- int val = libvlc_video_get_height(p_input, &ex);\r
- libvlc_input_free(p_input);\r
+ int val = libvlc_video_get_height(p_md, &ex);\r
+ libvlc_media_instance_release(p_md);\r
if( libvlc_exception_raised(&ex) )\r
{\r
NPN_SetException(this, libvlc_exception_get_message(&ex));\r
}\r
case ID_video_width:\r
{\r
- int val = libvlc_video_get_width(p_input, &ex);\r
- libvlc_input_free(p_input);\r
+ int val = libvlc_video_get_width(p_md, &ex);\r
+ libvlc_media_instance_release(p_md);\r
if( libvlc_exception_raised(&ex) )\r
{\r
NPN_SetException(this, libvlc_exception_get_message(&ex));\r
}\r
case ID_video_aspectratio:\r
{\r
- NPUTF8 *psz_aspect = libvlc_video_get_aspect_ratio(p_input, &ex);\r
- libvlc_input_free(p_input);\r
+ NPUTF8 *psz_aspect = libvlc_video_get_aspect_ratio(p_md, &ex);\r
+ libvlc_media_instance_release(p_md);\r
if( libvlc_exception_raised(&ex) )\r
{\r
NPN_SetException(this, libvlc_exception_get_message(&ex));\r
STRINGZ_TO_NPVARIANT(psz_aspect, result);\r
return INVOKERESULT_NO_ERROR;\r
}\r
+ case ID_video_subtitle:\r
+ {\r
+ int i_spu = libvlc_video_get_spu(p_md, &ex);\r
+ libvlc_media_instance_release(p_md);\r
+ if( libvlc_exception_raised(&ex) )\r
+ {\r
+ NPN_SetException(this, libvlc_exception_get_message(&ex));\r
+ libvlc_exception_clear(&ex);\r
+ return INVOKERESULT_GENERIC_ERROR;\r
+ }\r
+ INT32_TO_NPVARIANT(i_spu, result);\r
+ return INVOKERESULT_NO_ERROR;\r
+ }\r
+ case ID_video_crop:\r
+ {\r
+ NPUTF8 *psz_geometry = libvlc_video_get_crop_geometry(p_md, &ex);\r
+ libvlc_media_instance_release(p_md);\r
+ if( libvlc_exception_raised(&ex) )\r
+ {\r
+ NPN_SetException(this, libvlc_exception_get_message(&ex));\r
+ libvlc_exception_clear(&ex);\r
+ return INVOKERESULT_GENERIC_ERROR;\r
+ }\r
+ if( !psz_geometry )\r
+ return INVOKERESULT_GENERIC_ERROR;\r
+\r
+ STRINGZ_TO_NPVARIANT(psz_geometry, result);\r
+ return INVOKERESULT_NO_ERROR;\r
+ }\r
+ case ID_video_teletext:\r
+ {\r
+ int i_page = libvlc_video_get_teletext(p_md, &ex);\r
+ libvlc_media_instance_release(p_md);\r
+ if( libvlc_exception_raised(&ex) )\r
+ {\r
+ NPN_SetException(this, libvlc_exception_get_message(&ex));\r
+ libvlc_exception_clear(&ex);\r
+ return INVOKERESULT_GENERIC_ERROR;\r
+ }\r
+ INT32_TO_NPVARIANT(i_page, result);\r
+ return INVOKERESULT_NO_ERROR;\r
+ }\r
}\r
- libvlc_input_free(p_input);\r
+ libvlc_media_instance_release(p_md);\r
}\r
return INVOKERESULT_GENERIC_ERROR;\r
}\r
\r
RuntimeNPObject::InvokeResult LibvlcVideoNPObject::setProperty(int index, const NPVariant &value)\r
{\r
- VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);\r
- if( p_plugin )\r
+ /* is plugin still running */\r
+ if( _instance->pdata )\r
{\r
+ VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);\r
libvlc_exception_t ex;\r
libvlc_exception_init(&ex);\r
\r
- libvlc_input_t *p_input = libvlc_playlist_get_input(p_plugin->getVLC(), &ex);\r
+ libvlc_media_instance_t *p_md = libvlc_playlist_get_media_instance(p_plugin->getVLC(), &ex);\r
if( libvlc_exception_raised(&ex) )\r
{\r
NPN_SetException(this, libvlc_exception_get_message(&ex));\r
{\r
if( ! NPVARIANT_IS_BOOLEAN(value) )\r
{\r
- libvlc_input_free(p_input);\r
+ libvlc_media_instance_release(p_md);\r
return INVOKERESULT_INVALID_VALUE;\r
}\r
\r
int val = NPVARIANT_TO_BOOLEAN(value);\r
- libvlc_set_fullscreen(p_input, val, &ex);\r
- libvlc_input_free(p_input);\r
+ libvlc_set_fullscreen(p_md, val, &ex);\r
+ libvlc_media_instance_release(p_md);\r
+\r
if( libvlc_exception_raised(&ex) )\r
{\r
NPN_SetException(this, libvlc_exception_get_message(&ex));\r
\r
if( ! NPVARIANT_IS_STRING(value) )\r
{\r
- libvlc_input_free(p_input);\r
+ libvlc_media_instance_release(p_md);\r
return INVOKERESULT_INVALID_VALUE;\r
}\r
\r
psz_aspect = stringValue(NPVARIANT_TO_STRING(value));\r
if( !psz_aspect )\r
+ {\r
+ libvlc_media_instance_release(p_md);\r
return INVOKERESULT_GENERIC_ERROR;\r
+ }\r
\r
- libvlc_video_set_aspect_ratio(p_input, psz_aspect, &ex);\r
- if( psz_aspect )\r
- free(psz_aspect );\r
+ libvlc_video_set_aspect_ratio(p_md, psz_aspect, &ex);\r
+ delete psz_aspect;\r
+ libvlc_media_instance_release(p_md);\r
\r
- libvlc_input_free(p_input);\r
if( libvlc_exception_raised(&ex) )\r
{\r
NPN_SetException(this, libvlc_exception_get_message(&ex));\r
}\r
return INVOKERESULT_NO_ERROR;\r
}\r
+ case ID_video_subtitle:\r
+ {\r
+ if( isNumberValue(value) )\r
+ {\r
+ libvlc_video_set_spu(p_md,\r
+ numberValue(value), &ex);\r
+ libvlc_media_instance_release(p_md);\r
+ if( libvlc_exception_raised(&ex) )\r
+ {\r
+ NPN_SetException(this, libvlc_exception_get_message(&ex));\r
+ libvlc_exception_clear(&ex);\r
+ return INVOKERESULT_GENERIC_ERROR;\r
+ }\r
+ return INVOKERESULT_NO_ERROR;\r
+ }\r
+ libvlc_media_instance_release(p_md);\r
+ return INVOKERESULT_INVALID_VALUE;\r
+ }\r
+ case ID_video_crop:\r
+ {\r
+ char *psz_geometry = NULL;\r
+\r
+ if( ! NPVARIANT_IS_STRING(value) )\r
+ {\r
+ libvlc_media_instance_release(p_md);\r
+ return INVOKERESULT_INVALID_VALUE;\r
+ }\r
+\r
+ psz_geometry = stringValue(NPVARIANT_TO_STRING(value));\r
+ if( !psz_geometry )\r
+ {\r
+ libvlc_media_instance_release(p_md);\r
+ return INVOKERESULT_GENERIC_ERROR;\r
+ }\r
+\r
+ libvlc_video_set_crop_geometry(p_md, psz_geometry, &ex);\r
+ delete psz_geometry;\r
+ libvlc_media_instance_release(p_md);\r
+\r
+ if( libvlc_exception_raised(&ex) )\r
+ {\r
+ NPN_SetException(this, libvlc_exception_get_message(&ex));\r
+ libvlc_exception_clear(&ex);\r
+ return INVOKERESULT_GENERIC_ERROR;\r
+ }\r
+ return INVOKERESULT_NO_ERROR;\r
+ }\r
+ case ID_video_teletext:\r
+ {\r
+ if( isNumberValue(value) )\r
+ {\r
+ libvlc_video_set_teletext(p_md,\r
+ numberValue(value), &ex);\r
+ libvlc_media_instance_release(p_md);\r
+ if( libvlc_exception_raised(&ex) )\r
+ {\r
+ NPN_SetException(this, libvlc_exception_get_message(&ex));\r
+ libvlc_exception_clear(&ex);\r
+ return INVOKERESULT_GENERIC_ERROR;\r
+ }\r
+ return INVOKERESULT_NO_ERROR;\r
+ }\r
+ libvlc_media_instance_release(p_md);\r
+ return INVOKERESULT_INVALID_VALUE;\r
+ }\r
}\r
- libvlc_input_free(p_input);\r
+ libvlc_media_instance_release(p_md);\r
}\r
return INVOKERESULT_GENERIC_ERROR;\r
}\r
\r
RuntimeNPObject::InvokeResult LibvlcVideoNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)\r
{\r
- VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);\r
- if( p_plugin )\r
+ /* is plugin still running */\r
+ if( _instance->pdata )\r
{\r
+ VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);\r
libvlc_exception_t ex;\r
libvlc_exception_init(&ex);\r
\r
- libvlc_input_t *p_input = libvlc_playlist_get_input(p_plugin->getVLC(), &ex);\r
+ libvlc_media_instance_t *p_md = libvlc_playlist_get_media_instance(p_plugin->getVLC(), &ex);\r
if( libvlc_exception_raised(&ex) )\r
{\r
NPN_SetException(this, libvlc_exception_get_message(&ex));\r
case ID_video_togglefullscreen:\r
if( argCount == 0 )\r
{\r
- libvlc_toggle_fullscreen(p_input, &ex);\r
- libvlc_input_free(p_input);\r
+ libvlc_toggle_fullscreen(p_md, &ex);\r
+ libvlc_media_instance_release(p_md);\r
if( libvlc_exception_raised(&ex) )\r
{\r
NPN_SetException(this, libvlc_exception_get_message(&ex));\r
}\r
else\r
{\r
- /* cannot get input, probably not playing */\r
+ /* cannot get md, probably not playing */\r
if( libvlc_exception_raised(&ex) )\r
{\r
NPN_SetException(this, libvlc_exception_get_message(&ex));\r