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

mozilla: no longer use libvlc depreceated API

Original rewrite done by JP Dinger <jpd@m2x.nl> and cleaned up by jpsaman.
parent e3965395
...@@ -70,7 +70,7 @@ LibvlcRootNPObject::~LibvlcRootNPObject() ...@@ -70,7 +70,7 @@ LibvlcRootNPObject::~LibvlcRootNPObject()
} }
} }
const NPUTF8 * const LibvlcRootNPObject::propertyNames[] = const NPUTF8 * const LibvlcRootNPObject::propertyNames[] =
{ {
"audio", "audio",
"input", "input",
...@@ -141,17 +141,14 @@ LibvlcRootNPObject::getProperty(int index, NPVariant &result) ...@@ -141,17 +141,14 @@ LibvlcRootNPObject::getProperty(int index, NPVariant &result)
return INVOKERESULT_NO_ERROR; return INVOKERESULT_NO_ERROR;
case ID_root_VersionInfo: case ID_root_VersionInfo:
{ {
int len = strlen(libvlc_get_version()); const char *s = libvlc_get_version();
int len = strlen(s);
NPUTF8 *retval =(NPUTF8*)NPN_MemAlloc(len); NPUTF8 *retval =(NPUTF8*)NPN_MemAlloc(len);
if( retval ) if( !retval )
{ return INVOKERESULT_OUT_OF_MEMORY;
memcpy(retval, libvlc_get_version(), len);
STRINGN_TO_NPVARIANT(retval, len, result); memcpy(retval, s, len);
} STRINGN_TO_NPVARIANT(retval, len, result);
else
{
NULL_TO_NPVARIANT(result);
}
return INVOKERESULT_NO_ERROR; return INVOKERESULT_NO_ERROR;
} }
default: default:
...@@ -186,17 +183,13 @@ RuntimeNPObject::InvokeResult LibvlcRootNPObject::invoke(int index, ...@@ -186,17 +183,13 @@ RuntimeNPObject::InvokeResult LibvlcRootNPObject::invoke(int index,
case ID_root_versionInfo: case ID_root_versionInfo:
if( argCount == 0 ) if( argCount == 0 )
{ {
int len = strlen(libvlc_get_version()); const char *s = libvlc_get_version();
int len = strlen(s);
NPUTF8 *retval =(NPUTF8*)NPN_MemAlloc(len); NPUTF8 *retval =(NPUTF8*)NPN_MemAlloc(len);
if( retval ) if( !retval )
{ return INVOKERESULT_OUT_OF_MEMORY;
memcpy(retval, libvlc_get_version(), len); memcpy(retval, s, len);
STRINGN_TO_NPVARIANT(retval, len, result); STRINGN_TO_NPVARIANT(retval, len, result);
}
else
{
NULL_TO_NPVARIANT(result);
}
return INVOKERESULT_NO_ERROR; return INVOKERESULT_NO_ERROR;
} }
return INVOKERESULT_NO_SUCH_METHOD; return INVOKERESULT_NO_SUCH_METHOD;
...@@ -211,7 +204,7 @@ RuntimeNPObject::InvokeResult LibvlcRootNPObject::invoke(int index, ...@@ -211,7 +204,7 @@ RuntimeNPObject::InvokeResult LibvlcRootNPObject::invoke(int index,
** implementation of libvlc audio object ** implementation of libvlc audio object
*/ */
const NPUTF8 * const LibvlcAudioNPObject::propertyNames[] = const NPUTF8 * const LibvlcAudioNPObject::propertyNames[] =
{ {
"mute", "mute",
"volume", "volume",
...@@ -256,11 +249,9 @@ LibvlcAudioNPObject::getProperty(int index, NPVariant &result) ...@@ -256,11 +249,9 @@ LibvlcAudioNPObject::getProperty(int index, NPVariant &result)
} }
case ID_audio_track: case ID_audio_track:
{ {
libvlc_media_player_t *p_md = libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
libvlc_playlist_get_media_player(p_plugin->getVLC(), &ex);
RETURN_ON_EXCEPTION(this,ex); RETURN_ON_EXCEPTION(this,ex);
int track = libvlc_audio_get_track(p_md, &ex); int track = libvlc_audio_get_track(p_md, &ex);
libvlc_media_player_release(p_md);
RETURN_ON_EXCEPTION(this,ex); RETURN_ON_EXCEPTION(this,ex);
INT32_TO_NPVARIANT(track, result); INT32_TO_NPVARIANT(track, result);
return INVOKERESULT_NO_ERROR; return INVOKERESULT_NO_ERROR;
...@@ -312,11 +303,9 @@ LibvlcAudioNPObject::setProperty(int index, const NPVariant &value) ...@@ -312,11 +303,9 @@ LibvlcAudioNPObject::setProperty(int index, const NPVariant &value)
case ID_audio_track: case ID_audio_track:
if( isNumberValue(value) ) if( isNumberValue(value) )
{ {
libvlc_media_player_t *p_md = libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
libvlc_playlist_get_media_player(p_plugin->getVLC(), &ex);
RETURN_ON_EXCEPTION(this,ex); RETURN_ON_EXCEPTION(this,ex);
libvlc_audio_set_track(p_md, numberValue(value), &ex); libvlc_audio_set_track(p_md, numberValue(value), &ex);
libvlc_media_player_release(p_md);
RETURN_ON_EXCEPTION(this,ex); RETURN_ON_EXCEPTION(this,ex);
return INVOKERESULT_NO_ERROR; return INVOKERESULT_NO_ERROR;
} }
...@@ -381,7 +370,7 @@ LibvlcAudioNPObject::invoke(int index, const NPVariant *args, ...@@ -381,7 +370,7 @@ LibvlcAudioNPObject::invoke(int index, const NPVariant *args,
** implementation of libvlc input object ** implementation of libvlc input object
*/ */
const NPUTF8 * const LibvlcInputNPObject::propertyNames[] = const NPUTF8 * const LibvlcInputNPObject::propertyNames[] =
{ {
"length", "length",
"position", "position",
...@@ -414,8 +403,7 @@ LibvlcInputNPObject::getProperty(int index, NPVariant &result) ...@@ -414,8 +403,7 @@ LibvlcInputNPObject::getProperty(int index, NPVariant &result)
libvlc_exception_t ex; libvlc_exception_t ex;
libvlc_exception_init(&ex); libvlc_exception_init(&ex);
libvlc_media_player_t *p_md = libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
libvlc_playlist_get_media_player(p_plugin->getVLC(), &ex);
if( libvlc_exception_raised(&ex) ) if( libvlc_exception_raised(&ex) )
{ {
if( index != ID_input_state ) if( index != ID_input_state )
...@@ -438,7 +426,6 @@ LibvlcInputNPObject::getProperty(int index, NPVariant &result) ...@@ -438,7 +426,6 @@ LibvlcInputNPObject::getProperty(int index, NPVariant &result)
case ID_input_length: case ID_input_length:
{ {
double val = (double)libvlc_media_player_get_length(p_md, &ex); double val = (double)libvlc_media_player_get_length(p_md, &ex);
libvlc_media_player_release(p_md);
RETURN_ON_EXCEPTION(this,ex); RETURN_ON_EXCEPTION(this,ex);
DOUBLE_TO_NPVARIANT(val, result); DOUBLE_TO_NPVARIANT(val, result);
return INVOKERESULT_NO_ERROR; return INVOKERESULT_NO_ERROR;
...@@ -446,7 +433,6 @@ LibvlcInputNPObject::getProperty(int index, NPVariant &result) ...@@ -446,7 +433,6 @@ LibvlcInputNPObject::getProperty(int index, NPVariant &result)
case ID_input_position: case ID_input_position:
{ {
double val = libvlc_media_player_get_position(p_md, &ex); double val = libvlc_media_player_get_position(p_md, &ex);
libvlc_media_player_release(p_md);
RETURN_ON_EXCEPTION(this,ex); RETURN_ON_EXCEPTION(this,ex);
DOUBLE_TO_NPVARIANT(val, result); DOUBLE_TO_NPVARIANT(val, result);
return INVOKERESULT_NO_ERROR; return INVOKERESULT_NO_ERROR;
...@@ -454,7 +440,6 @@ LibvlcInputNPObject::getProperty(int index, NPVariant &result) ...@@ -454,7 +440,6 @@ LibvlcInputNPObject::getProperty(int index, NPVariant &result)
case ID_input_time: case ID_input_time:
{ {
double val = (double)libvlc_media_player_get_time(p_md, &ex); double val = (double)libvlc_media_player_get_time(p_md, &ex);
libvlc_media_player_release(p_md);
RETURN_ON_EXCEPTION(this,ex); RETURN_ON_EXCEPTION(this,ex);
DOUBLE_TO_NPVARIANT(val, result); DOUBLE_TO_NPVARIANT(val, result);
return INVOKERESULT_NO_ERROR; return INVOKERESULT_NO_ERROR;
...@@ -462,7 +447,6 @@ LibvlcInputNPObject::getProperty(int index, NPVariant &result) ...@@ -462,7 +447,6 @@ LibvlcInputNPObject::getProperty(int index, NPVariant &result)
case ID_input_state: case ID_input_state:
{ {
int val = libvlc_media_player_get_state(p_md, &ex); int val = libvlc_media_player_get_state(p_md, &ex);
libvlc_media_player_release(p_md);
RETURN_ON_EXCEPTION(this,ex); RETURN_ON_EXCEPTION(this,ex);
INT32_TO_NPVARIANT(val, result); INT32_TO_NPVARIANT(val, result);
return INVOKERESULT_NO_ERROR; return INVOKERESULT_NO_ERROR;
...@@ -470,7 +454,6 @@ LibvlcInputNPObject::getProperty(int index, NPVariant &result) ...@@ -470,7 +454,6 @@ LibvlcInputNPObject::getProperty(int index, NPVariant &result)
case ID_input_rate: case ID_input_rate:
{ {
float val = libvlc_media_player_get_rate(p_md, &ex); float val = libvlc_media_player_get_rate(p_md, &ex);
libvlc_media_player_release(p_md);
RETURN_ON_EXCEPTION(this,ex); RETURN_ON_EXCEPTION(this,ex);
DOUBLE_TO_NPVARIANT(val, result); DOUBLE_TO_NPVARIANT(val, result);
return INVOKERESULT_NO_ERROR; return INVOKERESULT_NO_ERROR;
...@@ -478,15 +461,13 @@ LibvlcInputNPObject::getProperty(int index, NPVariant &result) ...@@ -478,15 +461,13 @@ LibvlcInputNPObject::getProperty(int index, NPVariant &result)
case ID_input_fps: case ID_input_fps:
{ {
double val = libvlc_media_player_get_fps(p_md, &ex); double val = libvlc_media_player_get_fps(p_md, &ex);
libvlc_media_player_release(p_md);
RETURN_ON_EXCEPTION(this,ex); RETURN_ON_EXCEPTION(this,ex);
DOUBLE_TO_NPVARIANT(val, result); DOUBLE_TO_NPVARIANT(val, result);
return INVOKERESULT_NO_ERROR; return INVOKERESULT_NO_ERROR;
} }
case ID_input_hasvout: case ID_input_hasvout:
{ {
bool val = libvlc_media_player_has_vout(p_md, &ex); bool val = p_plugin->player_has_vout(&ex);
libvlc_media_player_release(p_md);
RETURN_ON_EXCEPTION(this,ex); RETURN_ON_EXCEPTION(this,ex);
BOOLEAN_TO_NPVARIANT(val, result); BOOLEAN_TO_NPVARIANT(val, result);
return INVOKERESULT_NO_ERROR; return INVOKERESULT_NO_ERROR;
...@@ -494,7 +475,6 @@ LibvlcInputNPObject::getProperty(int index, NPVariant &result) ...@@ -494,7 +475,6 @@ LibvlcInputNPObject::getProperty(int index, NPVariant &result)
default: default:
; ;
} }
libvlc_media_player_release(p_md);
} }
return INVOKERESULT_GENERIC_ERROR; return INVOKERESULT_GENERIC_ERROR;
} }
...@@ -509,8 +489,7 @@ LibvlcInputNPObject::setProperty(int index, const NPVariant &value) ...@@ -509,8 +489,7 @@ LibvlcInputNPObject::setProperty(int index, const NPVariant &value)
libvlc_exception_t ex; libvlc_exception_t ex;
libvlc_exception_init(&ex); libvlc_exception_init(&ex);
libvlc_media_player_t *p_md = libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
libvlc_playlist_get_media_player(p_plugin->getVLC(), &ex);
RETURN_ON_EXCEPTION(this,ex); RETURN_ON_EXCEPTION(this,ex);
switch( index ) switch( index )
...@@ -519,13 +498,11 @@ LibvlcInputNPObject::setProperty(int index, const NPVariant &value) ...@@ -519,13 +498,11 @@ LibvlcInputNPObject::setProperty(int index, const NPVariant &value)
{ {
if( ! NPVARIANT_IS_DOUBLE(value) ) if( ! NPVARIANT_IS_DOUBLE(value) )
{ {
libvlc_media_player_release(p_md);
return INVOKERESULT_INVALID_VALUE; return INVOKERESULT_INVALID_VALUE;
} }
float val = (float)NPVARIANT_TO_DOUBLE(value); float val = (float)NPVARIANT_TO_DOUBLE(value);
libvlc_media_player_set_position(p_md, val, &ex); libvlc_media_player_set_position(p_md, val, &ex);
libvlc_media_player_release(p_md);
RETURN_ON_EXCEPTION(this,ex); RETURN_ON_EXCEPTION(this,ex);
return INVOKERESULT_NO_ERROR; return INVOKERESULT_NO_ERROR;
} }
...@@ -538,12 +515,10 @@ LibvlcInputNPObject::setProperty(int index, const NPVariant &value) ...@@ -538,12 +515,10 @@ LibvlcInputNPObject::setProperty(int index, const NPVariant &value)
val = (int64_t)NPVARIANT_TO_DOUBLE(value); val = (int64_t)NPVARIANT_TO_DOUBLE(value);
else else
{ {
libvlc_media_player_release(p_md);
return INVOKERESULT_INVALID_VALUE; return INVOKERESULT_INVALID_VALUE;
} }
libvlc_media_player_set_time(p_md, val, &ex); libvlc_media_player_set_time(p_md, val, &ex);
libvlc_media_player_release(p_md);
RETURN_ON_EXCEPTION(this,ex); RETURN_ON_EXCEPTION(this,ex);
return INVOKERESULT_NO_ERROR; return INVOKERESULT_NO_ERROR;
} }
...@@ -556,19 +531,16 @@ LibvlcInputNPObject::setProperty(int index, const NPVariant &value) ...@@ -556,19 +531,16 @@ LibvlcInputNPObject::setProperty(int index, const NPVariant &value)
val = (float)NPVARIANT_TO_DOUBLE(value); val = (float)NPVARIANT_TO_DOUBLE(value);
else else
{ {
libvlc_media_player_release(p_md);
return INVOKERESULT_INVALID_VALUE; return INVOKERESULT_INVALID_VALUE;
} }
libvlc_media_player_set_rate(p_md, val, &ex); libvlc_media_player_set_rate(p_md, val, &ex);
libvlc_media_player_release(p_md);
RETURN_ON_EXCEPTION(this,ex); RETURN_ON_EXCEPTION(this,ex);
return INVOKERESULT_NO_ERROR; return INVOKERESULT_NO_ERROR;
} }
default: default:
; ;
} }
libvlc_media_player_release(p_md);
} }
return INVOKERESULT_GENERIC_ERROR; return INVOKERESULT_GENERIC_ERROR;
} }
...@@ -584,7 +556,7 @@ COUNTNAMES(LibvlcInputNPObject,methodCount,methodNames); ...@@ -584,7 +556,7 @@ COUNTNAMES(LibvlcInputNPObject,methodCount,methodNames);
** implementation of libvlc message object ** implementation of libvlc message object
*/ */
const NPUTF8 * const LibvlcMessageNPObject::propertyNames[] = const NPUTF8 * const LibvlcMessageNPObject::propertyNames[] =
{ {
"severity", "severity",
"type", "type",
...@@ -730,7 +702,7 @@ LibvlcMessageIteratorNPObject::~LibvlcMessageIteratorNPObject() ...@@ -730,7 +702,7 @@ LibvlcMessageIteratorNPObject::~LibvlcMessageIteratorNPObject()
libvlc_log_iterator_free(_p_iter, NULL); libvlc_log_iterator_free(_p_iter, NULL);
} }
const NPUTF8 * const LibvlcMessageIteratorNPObject::propertyNames[] = const NPUTF8 * const LibvlcMessageIteratorNPObject::propertyNames[] =
{ {
"hasNext", "hasNext",
}; };
...@@ -836,7 +808,7 @@ LibvlcMessageIteratorNPObject::invoke(int index, const NPVariant *args, ...@@ -836,7 +808,7 @@ LibvlcMessageIteratorNPObject::invoke(int index, const NPVariant *args,
** implementation of libvlc message object ** implementation of libvlc message object
*/ */
const NPUTF8 * const LibvlcMessagesNPObject::propertyNames[] = const NPUTF8 * const LibvlcMessagesNPObject::propertyNames[] =
{ {
"count", "count",
}; };
...@@ -956,7 +928,7 @@ LibvlcLogNPObject::~LibvlcLogNPObject() ...@@ -956,7 +928,7 @@ LibvlcLogNPObject::~LibvlcLogNPObject()
} }
}; };
const NPUTF8 * const LibvlcLogNPObject::propertyNames[] = const NPUTF8 * const LibvlcLogNPObject::propertyNames[] =
{ {
"messages", "messages",
"verbosity", "verbosity",
...@@ -1069,7 +1041,7 @@ COUNTNAMES(LibvlcLogNPObject,methodCount,methodNames); ...@@ -1069,7 +1041,7 @@ COUNTNAMES(LibvlcLogNPObject,methodCount,methodNames);
** implementation of libvlc playlist items object ** implementation of libvlc playlist items object
*/ */
const NPUTF8 * const LibvlcPlaylistItemsNPObject::propertyNames[] = const NPUTF8 * const LibvlcPlaylistItemsNPObject::propertyNames[] =
{ {
"count", "count",
}; };
...@@ -1094,9 +1066,7 @@ LibvlcPlaylistItemsNPObject::getProperty(int index, NPVariant &result) ...@@ -1094,9 +1066,7 @@ LibvlcPlaylistItemsNPObject::getProperty(int index, NPVariant &result)
{ {
case ID_playlistitems_count: case ID_playlistitems_count:
{ {
libvlc_playlist_lock(p_plugin->getVLC()); int val = p_plugin->playlist_count(&ex);
int val = libvlc_playlist_items_count(p_plugin->getVLC(), &ex);
libvlc_playlist_unlock(p_plugin->getVLC());
RETURN_ON_EXCEPTION(this,ex); RETURN_ON_EXCEPTION(this,ex);
INT32_TO_NPVARIANT(val, result); INT32_TO_NPVARIANT(val, result);
return INVOKERESULT_NO_ERROR; return INVOKERESULT_NO_ERROR;
...@@ -1137,7 +1107,7 @@ LibvlcPlaylistItemsNPObject::invoke(int index, const NPVariant *args, ...@@ -1137,7 +1107,7 @@ LibvlcPlaylistItemsNPObject::invoke(int index, const NPVariant *args,
case ID_playlistitems_clear: case ID_playlistitems_clear:
if( argCount == 0 ) if( argCount == 0 )
{ {
libvlc_playlist_clear(p_plugin->getVLC(), &ex); p_plugin->playlist_clear(&ex);
RETURN_ON_EXCEPTION(this,ex); RETURN_ON_EXCEPTION(this,ex);
VOID_TO_NPVARIANT(result); VOID_TO_NPVARIANT(result);
return INVOKERESULT_NO_ERROR; return INVOKERESULT_NO_ERROR;
...@@ -1146,8 +1116,7 @@ LibvlcPlaylistItemsNPObject::invoke(int index, const NPVariant *args, ...@@ -1146,8 +1116,7 @@ LibvlcPlaylistItemsNPObject::invoke(int index, const NPVariant *args,
case ID_playlistitems_remove: case ID_playlistitems_remove:
if( (argCount == 1) && isNumberValue(args[0]) ) if( (argCount == 1) && isNumberValue(args[0]) )
{ {
libvlc_playlist_delete_item(p_plugin->getVLC(), p_plugin->playlist_delete_item(numberValue(args[0]),&ex);
numberValue(args[0]), &ex);
RETURN_ON_EXCEPTION(this,ex); RETURN_ON_EXCEPTION(this,ex);
VOID_TO_NPVARIANT(result); VOID_TO_NPVARIANT(result);
return INVOKERESULT_NO_ERROR; return INVOKERESULT_NO_ERROR;
...@@ -1173,7 +1142,7 @@ LibvlcPlaylistNPObject::~LibvlcPlaylistNPObject() ...@@ -1173,7 +1142,7 @@ LibvlcPlaylistNPObject::~LibvlcPlaylistNPObject()
} }
}; };
const NPUTF8 * const LibvlcPlaylistNPObject::propertyNames[] = const NPUTF8 * const LibvlcPlaylistNPObject::propertyNames[] =
{ {
"itemCount", /* deprecated */ "itemCount", /* deprecated */
"isPlaying", "isPlaying",
...@@ -1202,18 +1171,14 @@ LibvlcPlaylistNPObject::getProperty(int index, NPVariant &result) ...@@ -1202,18 +1171,14 @@ LibvlcPlaylistNPObject::getProperty(int index, NPVariant &result)
{ {
case ID_playlist_itemcount: /* deprecated */ case ID_playlist_itemcount: /* deprecated */
{ {
libvlc_playlist_lock(p_plugin->getVLC()); int val = p_plugin->playlist_count(&ex);
int val = libvlc_playlist_items_count(p_plugin->getVLC(), &ex);
libvlc_playlist_unlock(p_plugin->getVLC());
RETURN_ON_EXCEPTION(this,ex); RETURN_ON_EXCEPTION(this,ex);
INT32_TO_NPVARIANT(val, result); INT32_TO_NPVARIANT(val, result);
return INVOKERESULT_NO_ERROR; return INVOKERESULT_NO_ERROR;
} }
case ID_playlist_isplaying: case ID_playlist_isplaying:
{ {
libvlc_playlist_lock(p_plugin->getVLC()); int val = p_plugin->playlist_isplaying(&ex);
int val = libvlc_playlist_isplaying(p_plugin->getVLC(), &ex);
libvlc_playlist_unlock(p_plugin->getVLC());
RETURN_ON_EXCEPTION(this,ex); RETURN_ON_EXCEPTION(this,ex);
BOOLEAN_TO_NPVARIANT(val, result); BOOLEAN_TO_NPVARIANT(val, result);
return INVOKERESULT_NO_ERROR; return INVOKERESULT_NO_ERROR;
...@@ -1276,6 +1241,7 @@ LibvlcPlaylistNPObject::invoke(int index, const NPVariant *args, ...@@ -1276,6 +1241,7 @@ LibvlcPlaylistNPObject::invoke(int index, const NPVariant *args,
switch( index ) switch( index )
{ {
// XXX FIXME this needs squashing into something much smaller
case ID_playlist_add: case ID_playlist_add:
{ {
if( (argCount < 1) || (argCount > 3) ) if( (argCount < 1) || (argCount > 3) )
...@@ -1351,8 +1317,7 @@ LibvlcPlaylistNPObject::invoke(int index, const NPVariant *args, ...@@ -1351,8 +1317,7 @@ LibvlcPlaylistNPObject::invoke(int index, const NPVariant *args,
} }
} }
int item = libvlc_playlist_add_extended_untrusted( int item = p_plugin->playlist_add_extended_untrusted(url, name, i_options,
p_plugin->getVLC(), url, name, i_options,
const_cast<const char **>(ppsz_options), &ex); const_cast<const char **>(ppsz_options), &ex);
free(url); free(url);
free(name); free(name);
...@@ -1369,7 +1334,7 @@ LibvlcPlaylistNPObject::invoke(int index, const NPVariant *args, ...@@ -1369,7 +1334,7 @@ LibvlcPlaylistNPObject::invoke(int index, const NPVariant *args,
case ID_playlist_play: case ID_playlist_play:
if( argCount == 0 ) if( argCount == 0 )
{ {
libvlc_playlist_play(p_plugin->getVLC(), -1, 0, NULL, &ex); p_plugin->playlist_play(&ex);
RETURN_ON_EXCEPTION(this,ex); RETURN_ON_EXCEPTION(this,ex);
VOID_TO_NPVARIANT(result); VOID_TO_NPVARIANT(result);
return INVOKERESULT_NO_ERROR; return INVOKERESULT_NO_ERROR;
...@@ -1378,8 +1343,7 @@ LibvlcPlaylistNPObject::invoke(int index, const NPVariant *args, ...@@ -1378,8 +1343,7 @@ LibvlcPlaylistNPObject::invoke(int index, const NPVariant *args,
case ID_playlist_playItem: case ID_playlist_playItem:
if( (argCount == 1) && isNumberValue(args[0]) ) if( (argCount == 1) && isNumberValue(args[0]) )
{ {
libvlc_playlist_play(p_plugin->getVLC(), p_plugin->playlist_play_item(numberValue(args[0]),&ex);
numberValue(args[0]), 0, NULL, &ex);
RETURN_ON_EXCEPTION(this,ex); RETURN_ON_EXCEPTION(this,ex);
VOID_TO_NPVARIANT(result); VOID_TO_NPVARIANT(result);
return INVOKERESULT_NO_ERROR; return INVOKERESULT_NO_ERROR;
...@@ -1388,7 +1352,7 @@ LibvlcPlaylistNPObject::invoke(int index, const NPVariant *args, ...@@ -1388,7 +1352,7 @@ LibvlcPlaylistNPObject::invoke(int index, const NPVariant *args,
case ID_playlist_togglepause: case ID_playlist_togglepause:
if( argCount == 0 ) if( argCount == 0 )
{ {
libvlc_playlist_pause(p_plugin->getVLC(), &ex); p_plugin->playlist_pause(&ex);
RETURN_ON_EXCEPTION(this,ex); RETURN_ON_EXCEPTION(this,ex);
VOID_TO_NPVARIANT(result); VOID_TO_NPVARIANT(result);
return INVOKERESULT_NO_ERROR; return INVOKERESULT_NO_ERROR;
...@@ -1397,7 +1361,7 @@ LibvlcPlaylistNPObject::invoke(int index, const NPVariant *args, ...@@ -1397,7 +1361,7 @@ LibvlcPlaylistNPObject::invoke(int index, const NPVariant *args,
case ID_playlist_stop: case ID_playlist_stop:
if( argCount == 0 ) if( argCount == 0 )
{ {
libvlc_playlist_stop(p_plugin->getVLC(), &ex); p_plugin->playlist_stop(&ex);
RETURN_ON_EXCEPTION(this,ex); RETURN_ON_EXCEPTION(this,ex);
VOID_TO_NPVARIANT(result); VOID_TO_NPVARIANT(result);
return INVOKERESULT_NO_ERROR; return INVOKERESULT_NO_ERROR;
...@@ -1406,7 +1370,7 @@ LibvlcPlaylistNPObject::invoke(int index, const NPVariant *args, ...@@ -1406,7 +1370,7 @@ LibvlcPlaylistNPObject::invoke(int index, const NPVariant *args,
case ID_playlist_next: case ID_playlist_next:
if( argCount == 0 ) if( argCount == 0 )
{ {
libvlc_playlist_next(p_plugin->getVLC(), &ex); p_plugin->playlist_next(&ex);
RETURN_ON_EXCEPTION(this,ex); RETURN_ON_EXCEPTION(this,ex);
VOID_TO_NPVARIANT(result); VOID_TO_NPVARIANT(result);
return INVOKERESULT_NO_ERROR; return INVOKERESULT_NO_ERROR;
...@@ -1415,7 +1379,7 @@ LibvlcPlaylistNPObject::invoke(int index, const NPVariant *args, ...@@ -1415,7 +1379,7 @@ LibvlcPlaylistNPObject::invoke(int index, const NPVariant *args,
case ID_playlist_prev: case ID_playlist_prev:
if( argCount == 0 ) if( argCount == 0 )
{ {
libvlc_playlist_prev(p_plugin->getVLC(), &ex); p_plugin->playlist_prev(&ex);
RETURN_ON_EXCEPTION(this,ex); RETURN_ON_EXCEPTION(this,ex);
VOID_TO_NPVARIANT(result); VOID_TO_NPVARIANT(result);
return INVOKERESULT_NO_ERROR; return INVOKERESULT_NO_ERROR;
...@@ -1424,7 +1388,7 @@ LibvlcPlaylistNPObject::invoke(int index, const NPVariant *args, ...@@ -1424,7 +1388,7 @@ LibvlcPlaylistNPObject::invoke(int index, const NPVariant *args,
case ID_playlist_clear: /* deprecated */ case ID_playlist_clear: /* deprecated */
if( argCount == 0 ) if( argCount == 0 )
{ {
libvlc_playlist_clear(p_plugin->getVLC(), &ex); p_plugin->playlist_clear(&ex);
RETURN_ON_EXCEPTION(this,ex); RETURN_ON_EXCEPTION(this,ex);
VOID_TO_NPVARIANT(result); VOID_TO_NPVARIANT(result);
return INVOKERESULT_NO_ERROR; return INVOKERESULT_NO_ERROR;
...@@ -1433,8 +1397,7 @@ LibvlcPlaylistNPObject::invoke(int index, const NPVariant *args, ...@@ -1433,8 +1397,7 @@ LibvlcPlaylistNPObject::invoke(int index, const NPVariant *args,
case ID_playlist_removeitem: /* deprecated */ case ID_playlist_removeitem: /* deprecated */
if( (argCount == 1) && isNumberValue(args[0]) ) if( (argCount == 1) && isNumberValue(args[0]) )
{ {
libvlc_playlist_delete_item(p_plugin->getVLC(), p_plugin->playlist_delete_item(numberValue(args[0]), &ex);
numberValue(args[0]), &ex);
RETURN_ON_EXCEPTION(this,ex); RETURN_ON_EXCEPTION(this,ex);
VOID_TO_NPVARIANT(result); VOID_TO_NPVARIANT(result);
return INVOKERESULT_NO_ERROR; return INVOKERESULT_NO_ERROR;
...@@ -1447,6 +1410,12 @@ LibvlcPlaylistNPObject::invoke(int index, const NPVariant *args, ...@@ -1447,6 +1410,12 @@ LibvlcPlaylistNPObject::invoke(int index, const NPVariant *args,
return INVOKERESULT_GENERIC_ERROR; return INVOKERESULT_GENERIC_ERROR;
} }
// XXX FIXME The new playlist_add creates a media instance and feeds it
// XXX FIXME these options one at a time, so this hunk of code does lots
// XXX FIXME of unnecessairy work. Break out something that can do one
// XXX FIXME option at a time and doesn't need to realloc().
// XXX FIXME Same for the other version of parseOptions.
void LibvlcPlaylistNPObject::parseOptions(const NPString &nps, void LibvlcPlaylistNPObject::parseOptions(const NPString &nps,
int *i_options, char*** ppsz_options) int *i_options, char*** ppsz_options)
{ {
...@@ -1489,7 +1458,7 @@ void LibvlcPlaylistNPObject::parseOptions(const NPString &nps, ...@@ -1489,7 +1458,7 @@ void LibvlcPlaylistNPObject::parseOptions(const NPString &nps,
if( nOptions == capacity ) if( nOptions == capacity )
{ {
capacity += 16; capacity += 16;
char **moreOptions = (char **)realloc(options, capacity*sizeof(char*)); char **moreOptions = (char **)realloc(options, capacity*sizeof(char*));
if( ! moreOptions ) if( ! moreOptions )
{ {
/* failed to allocate more memory */ /* failed to allocate more memory */
...@@ -1516,6 +1485,7 @@ void LibvlcPlaylistNPObject::parseOptions(const NPString &nps, ...@@ -1516,6 +1485,7 @@ void LibvlcPlaylistNPObject::parseOptions(const NPString &nps,
} }
} }
// XXX FIXME See comment at the other parseOptions variant.
void LibvlcPlaylistNPObject::parseOptions(NPObject *obj, int *i_options, void LibvlcPlaylistNPObject::parseOptions(NPObject *obj, int *i_options,
char*** ppsz_options) char*** ppsz_options)
{ {
...@@ -1555,7 +1525,7 @@ void LibvlcPlaylistNPObject::parseOptions(NPObject *obj, int *i_options, ...@@ -1555,7 +1525,7 @@ void LibvlcPlaylistNPObject::parseOptions(NPObject *obj, int *i_options,
if( nOptions == capacity ) if( nOptions == capacity )
{ {
capacity += 16; capacity += 16;
char **moreOptions = (char **)realloc(options, capacity*sizeof(char*)); char **moreOptions = (char **)realloc(options, capacity*sizeof(char*));
if( ! moreOptions ) if( ! moreOptions )
{ {
/* failed to allocate more memory */ /* failed to allocate more memory */
...@@ -1581,7 +1551,7 @@ void LibvlcPlaylistNPObject::parseOptions(NPObject *obj, int *i_options, ...@@ -1581,7 +1551,7 @@ void LibvlcPlaylistNPObject::parseOptions(NPObject *obj, int *i_options,
** implementation of libvlc video object ** implementation of libvlc video object
*/ */
const NPUTF8 * const LibvlcVideoNPObject::propertyNames[] = const NPUTF8 * const LibvlcVideoNPObject::propertyNames[] =
{ {
"fullscreen", "fullscreen",
"height", "height",
...@@ -1614,15 +1584,14 @@ LibvlcVideoNPObject::getProperty(int index, NPVariant &result) ...@@ -1614,15 +1584,14 @@ LibvlcVideoNPObject::getProperty(int index, NPVariant &result)
libvlc_exception_t ex; libvlc_exception_t ex;
libvlc_exception_init(&ex); libvlc_exception_init(&ex);
libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_plugin->getVLC(), &ex); libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
RETURN_ON_EXCEPTION(this,ex); RETURN_ON_EXCEPTION(this,ex);
switch( index ) switch( index )
{ {
case ID_video_fullscreen: case ID_video_fullscreen:
{ {
int val = libvlc_get_fullscreen(p_md, &ex); int val = p_plugin->get_fullscreen(&ex);
libvlc_media_player_release(p_md);
RETURN_ON_EXCEPTION(this,ex); RETURN_ON_EXCEPTION(this,ex);
BOOLEAN_TO_NPVARIANT(val, result); BOOLEAN_TO_NPVARIANT(val, result);
return INVOKERESULT_NO_ERROR; return INVOKERESULT_NO_ERROR;
...@@ -1630,7 +1599,6 @@ LibvlcVideoNPObject::getProperty(int index, NPVariant &result) ...@@ -1630,7 +1599,6 @@ LibvlcVideoNPObject::getProperty(int index, NPVariant &result)
case ID_video_height: case ID_video_height:
{ {
int val = libvlc_video_get_height(p_md, &ex); int val = libvlc_video_get_height(p_md, &ex);
libvlc_media_player_release(p_md);
RETURN_ON_EXCEPTION(this,ex); RETURN_ON_EXCEPTION(this,ex);
INT32_TO_NPVARIANT(val, result); INT32_TO_NPVARIANT(val, result);
return INVOKERESULT_NO_ERROR; return INVOKERESULT_NO_ERROR;
...@@ -1638,7 +1606,6 @@ LibvlcVideoNPObject::getProperty(int index, NPVariant &result) ...@@ -1638,7 +1606,6 @@ LibvlcVideoNPObject::getProperty(int index, NPVariant &result)
case ID_video_width: case ID_video_width:
{ {
int val = libvlc_video_get_width(p_md, &ex); int val = libvlc_video_get_width(p_md, &ex);
libvlc_media_player_release(p_md);
RETURN_ON_EXCEPTION(this,ex); RETURN_ON_EXCEPTION(this,ex);
INT32_TO_NPVARIANT(val, result); INT32_TO_NPVARIANT(val, result);
return INVOKERESULT_NO_ERROR; return INVOKERESULT_NO_ERROR;
...@@ -1646,7 +1613,6 @@ LibvlcVideoNPObject::getProperty(int index, NPVariant &result) ...@@ -1646,7 +1613,6 @@ LibvlcVideoNPObject::getProperty(int index, NPVariant &result)
case ID_video_aspectratio: case ID_video_aspectratio:
{ {
NPUTF8 *psz_aspect = libvlc_video_get_aspect_ratio(p_md, &ex); NPUTF8 *psz_aspect = libvlc_video_get_aspect_ratio(p_md, &ex);
libvlc_media_player_release(p_md);
RETURN_ON_EXCEPTION(this,ex); RETURN_ON_EXCEPTION(this,ex);
if( !psz_aspect ) if( !psz_aspect )
return INVOKERESULT_GENERIC_ERROR; return INVOKERESULT_GENERIC_ERROR;
...@@ -1657,7 +1623,6 @@ LibvlcVideoNPObject::getProperty(int index, NPVariant &result) ...@@ -1657,7 +1623,6 @@ LibvlcVideoNPObject::getProperty(int index, NPVariant &result)
case ID_video_subtitle: case ID_video_subtitle:
{ {
int i_spu = libvlc_video_get_spu(p_md, &ex); int i_spu = libvlc_video_get_spu(p_md, &ex);
libvlc_media_player_release(p_md);
RETURN_ON_EXCEPTION(this,ex); RETURN_ON_EXCEPTION(this,ex);
INT32_TO_NPVARIANT(i_spu, result); INT32_TO_NPVARIANT(i_spu, result);
return INVOKERESULT_NO_ERROR; return INVOKERESULT_NO_ERROR;
...@@ -1665,7 +1630,6 @@ LibvlcVideoNPObject::getProperty(int index, NPVariant &result) ...@@ -1665,7 +1630,6 @@ LibvlcVideoNPObject::getProperty(int index, NPVariant &result)
case ID_video_crop: case ID_video_crop:
{ {
NPUTF8 *psz_geometry = libvlc_video_get_crop_geometry(p_md, &ex); NPUTF8 *psz_geometry = libvlc_video_get_crop_geometry(p_md, &ex);
libvlc_media_player_release(p_md);
RETURN_ON_EXCEPTION(this,ex); RETURN_ON_EXCEPTION(this,ex);
if( !psz_geometry ) if( !psz_geometry )
return INVOKERESULT_GENERIC_ERROR; return INVOKERESULT_GENERIC_ERROR;
...@@ -1676,13 +1640,11 @@ LibvlcVideoNPObject::getProperty(int index, NPVariant &result) ...@@ -1676,13 +1640,11 @@ LibvlcVideoNPObject::getProperty(int index, NPVariant &result)
case ID_video_teletext: case ID_video_teletext:
{ {
int i_page = libvlc_video_get_teletext(p_md, &ex); int i_page = libvlc_video_get_teletext(p_md, &ex);
libvlc_media_player_release(p_md);
RETURN_ON_EXCEPTION(this,ex); RETURN_ON_EXCEPTION(this,ex);
INT32_TO_NPVARIANT(i_page, result); INT32_TO_NPVARIANT(i_page, result);
return INVOKERESULT_NO_ERROR; return INVOKERESULT_NO_ERROR;
} }
} }
libvlc_media_player_release(p_md);
} }
return INVOKERESULT_GENERIC_ERROR; return INVOKERESULT_GENERIC_ERROR;
} }
...@@ -1697,7 +1659,7 @@ LibvlcVideoNPObject::setProperty(int index, const NPVariant &value) ...@@ -1697,7 +1659,7 @@ LibvlcVideoNPObject::setProperty(int index, const NPVariant &value)
libvlc_exception_t ex; libvlc_exception_t ex;
libvlc_exception_init(&ex); libvlc_exception_init(&ex);
libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_plugin->getVLC(), &ex); libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
RETURN_ON_EXCEPTION(this,ex); RETURN_ON_EXCEPTION(this,ex);
switch( index ) switch( index )
...@@ -1706,14 +1668,11 @@ LibvlcVideoNPObject::setProperty(int index, const NPVariant &value) ...@@ -1706,14 +1668,11 @@ LibvlcVideoNPObject::setProperty(int index, const NPVariant &value)
{ {
if( ! NPVARIANT_IS_BOOLEAN(value) ) if( ! NPVARIANT_IS_BOOLEAN(value) )
{ {
libvlc_media_player_release(p_md);
return INVOKERESULT_INVALID_VALUE; return INVOKERESULT_INVALID_VALUE;
} }
int val = NPVARIANT_TO_BOOLEAN(value); int val = NPVARIANT_TO_BOOLEAN(value);
libvlc_set_fullscreen(p_md, val, &ex); p_plugin->set_fullscreen(val, &ex);
libvlc_media_player_release(p_md);
RETURN_ON_EXCEPTION(this,ex); RETURN_ON_EXCEPTION(this,ex);
return INVOKERESULT_NO_ERROR; return INVOKERESULT_NO_ERROR;
} }
...@@ -1723,20 +1682,17 @@ LibvlcVideoNPObject::setProperty(int index, const NPVariant &value) ...@@ -1723,20 +1682,17 @@ LibvlcVideoNPObject::setProperty(int index, const NPVariant &value)
if( ! NPVARIANT_IS_STRING(value) ) if( ! NPVARIANT_IS_STRING(value) )
{ {
libvlc_media_player_release(p_md);
return INVOKERESULT_INVALID_VALUE; return INVOKERESULT_INVALID_VALUE;
} }
psz_aspect = stringValue(NPVARIANT_TO_STRING(value)); psz_aspect = stringValue(NPVARIANT_TO_STRING(value));
if( !psz_aspect ) if( !psz_aspect )
{ {
libvlc_media_player_release(p_md);
return INVOKERESULT_GENERIC_ERROR; return INVOKERESULT_GENERIC_ERROR;
} }
libvlc_video_set_aspect_ratio(p_md, psz_aspect, &ex); libvlc_video_set_aspect_ratio(p_md, psz_aspect, &ex);
free(psz_aspect); free(psz_aspect);
libvlc_media_player_release(p_md);
RETURN_ON_EXCEPTION(this,ex); RETURN_ON_EXCEPTION(this,ex);
return INVOKERESULT_NO_ERROR; return INVOKERESULT_NO_ERROR;
...@@ -1745,14 +1701,11 @@ LibvlcVideoNPObject::setProperty(int index, const NPVariant &value) ...@@ -1745,14 +1701,11 @@ LibvlcVideoNPObject::setProperty(int index, const NPVariant &value)
{ {
if( isNumberValue(value) ) if( isNumberValue(value) )
{ {
libvlc_video_set_spu(p_md, libvlc_video_set_spu(p_md, numberValue(value), &ex);
numberValue(value), &ex);
libvlc_media_player_release(p_md);
RETURN_ON_EXCEPTION(this,ex); RETURN_ON_EXCEPTION(this,ex);
return INVOKERESULT_NO_ERROR; return INVOKERESULT_NO_ERROR;
} }
libvlc_media_player_release(p_md);
return INVOKERESULT_INVALID_VALUE; return INVOKERESULT_INVALID_VALUE;
} }
case ID_video_crop: case ID_video_crop:
...@@ -1761,20 +1714,17 @@ LibvlcVideoNPObject::setProperty(int index, const NPVariant &value) ...@@ -1761,20 +1714,17 @@ LibvlcVideoNPObject::setProperty(int index, const NPVariant &value)
if( ! NPVARIANT_IS_STRING(value) ) if( ! NPVARIANT_IS_STRING(value) )
{ {
libvlc_media_player_release(p_md);
return INVOKERESULT_INVALID_VALUE; return INVOKERESULT_INVALID_VALUE;
} }
psz_geometry = stringValue(NPVARIANT_TO_STRING(value)); psz_geometry = stringValue(NPVARIANT_TO_STRING(value));
if( !psz_geometry ) if( !psz_geometry )
{ {
libvlc_media_player_release(p_md);
return INVOKERESULT_GENERIC_ERROR; return INVOKERESULT_GENERIC_ERROR;
} }
libvlc_video_set_crop_geometry(p_md, psz_geometry, &ex); libvlc_video_set_crop_geometry(p_md, psz_geometry, &ex);
free(psz_geometry); free(psz_geometry);
libvlc_media_player_release(p_md);
RETURN_ON_EXCEPTION(this,ex); RETURN_ON_EXCEPTION(this,ex);
return INVOKERESULT_NO_ERROR; return INVOKERESULT_NO_ERROR;
...@@ -1783,18 +1733,14 @@ LibvlcVideoNPObject::setProperty(int index, const NPVariant &value) ...@@ -1783,18 +1733,14 @@ LibvlcVideoNPObject::setProperty(int index, const NPVariant &value)
{ {
if( isNumberValue(value) ) if( isNumberValue(value) )
{ {
libvlc_video_set_teletext(p_md, libvlc_video_set_teletext(p_md, numberValue(value), &ex);
numberValue(value), &ex);
libvlc_media_player_release(p_md);
RETURN_ON_EXCEPTION(this,ex); RETURN_ON_EXCEPTION(this,ex);
return INVOKERESULT_NO_ERROR; return INVOKERESULT_NO_ERROR;
} }
libvlc_media_player_release(p_md);
return INVOKERESULT_INVALID_VALUE; return INVOKERESULT_INVALID_VALUE;
} }
} }
libvlc_media_player_release(p_md);
} }
return INVOKERESULT_GENERIC_ERROR; return INVOKERESULT_GENERIC_ERROR;
} }
...@@ -1823,7 +1769,7 @@ LibvlcVideoNPObject::invoke(int index, const NPVariant *args, ...@@ -1823,7 +1769,7 @@ LibvlcVideoNPObject::invoke(int index, const NPVariant *args,
libvlc_exception_t ex; libvlc_exception_t ex;
libvlc_exception_init(&ex); libvlc_exception_init(&ex);
libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_plugin->getVLC(), &ex); libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
RETURN_ON_EXCEPTION(this,ex); RETURN_ON_EXCEPTION(this,ex);
switch( index ) switch( index )
...@@ -1831,8 +1777,7 @@ LibvlcVideoNPObject::invoke(int index, const NPVariant *args, ...@@ -1831,8 +1777,7 @@ LibvlcVideoNPObject::invoke(int index, const NPVariant *args,
case ID_video_togglefullscreen: case ID_video_togglefullscreen:
if( argCount == 0 ) if( argCount == 0 )
{ {
libvlc_toggle_fullscreen(p_md, &ex); p_plugin->toggle_fullscreen(&ex);
libvlc_media_player_release(p_md);
RETURN_ON_EXCEPTION(this,ex); RETURN_ON_EXCEPTION(this,ex);
VOID_TO_NPVARIANT(result); VOID_TO_NPVARIANT(result);
return INVOKERESULT_NO_ERROR; return INVOKERESULT_NO_ERROR;
...@@ -1842,7 +1787,6 @@ LibvlcVideoNPObject::invoke(int index, const NPVariant *args, ...@@ -1842,7 +1787,6 @@ LibvlcVideoNPObject::invoke(int index, const NPVariant *args,
if( argCount == 0 ) if( argCount == 0 )
{ {
libvlc_toggle_teletext(p_md, &ex); libvlc_toggle_teletext(p_md, &ex);
libvlc_media_player_release(p_md);
RETURN_ON_EXCEPTION(this,ex); RETURN_ON_EXCEPTION(this,ex);
VOID_TO_NPVARIANT(result); VOID_TO_NPVARIANT(result);
return INVOKERESULT_NO_ERROR; return INVOKERESULT_NO_ERROR;
......
...@@ -46,7 +46,10 @@ VlcPlugin::VlcPlugin( NPP instance, uint16 mode ) : ...@@ -46,7 +46,10 @@ VlcPlugin::VlcPlugin( NPP instance, uint16 mode ) :
b_autoplay(1), b_autoplay(1),
b_toolbar(0), b_toolbar(0),
psz_target(NULL), psz_target(NULL),
playlist_index(-1),
libvlc_instance(NULL), libvlc_instance(NULL),
libvlc_media_list(NULL),
libvlc_media_player(NULL),
libvlc_log(NULL), libvlc_log(NULL),
p_scriptClass(NULL), p_scriptClass(NULL),
p_browser(instance), p_browser(instance),
...@@ -190,12 +193,19 @@ NPError VlcPlugin::init(int argc, char* const argn[], char* const argv[]) ...@@ -190,12 +193,19 @@ NPError VlcPlugin::init(int argc, char* const argn[], char* const argv[])
libvlc_exception_init(&ex); libvlc_exception_init(&ex);
libvlc_instance = libvlc_new(ppsz_argc, ppsz_argv, &ex); libvlc_instance = libvlc_new(ppsz_argc, ppsz_argv, &ex);
if( libvlc_exception_raised(&ex) )
{
libvlc_exception_clear(&ex);
return NPERR_GENERIC_ERROR;
}
libvlc_media_list = libvlc_media_list_new(libvlc_instance,&ex);
if( libvlc_exception_raised(&ex) ) if( libvlc_exception_raised(&ex) )
{ {
libvlc_exception_clear(&ex); libvlc_exception_clear(&ex);
return NPERR_GENERIC_ERROR; return NPERR_GENERIC_ERROR;
} }
libvlc_exception_clear(&ex);
/* /*
** fetch plugin base URL, which is the URL of the page containing the plugin ** fetch plugin base URL, which is the URL of the page containing the plugin
...@@ -254,10 +264,215 @@ VlcPlugin::~VlcPlugin() ...@@ -254,10 +264,215 @@ VlcPlugin::~VlcPlugin()
free(psz_target); free(psz_target);
if( libvlc_log ) if( libvlc_log )
libvlc_log_close(libvlc_log, NULL); libvlc_log_close(libvlc_log, NULL);
if( libvlc_media_player )
libvlc_media_player_release( libvlc_media_player );
if( libvlc_media_list )
libvlc_media_list_release( libvlc_media_list );
if( libvlc_instance ) if( libvlc_instance )
libvlc_release(libvlc_instance); libvlc_release(libvlc_instance);
} }
/*****************************************************************************
* VlcPlugin playlist replacement methods
*****************************************************************************/
void VlcPlugin::set_player_window( libvlc_exception_t *ex )
{
#ifdef XP_UNIX
libvlc_media_player_set_xwindow(libvlc_media_player,
(libvlc_drawable_t)getWindow().window,
ex);
#endif
#ifdef XP_MACOSX
// XXX FIXME insert appropriate call here
#endif
#ifdef XP_WIN
libvlc_media_player_set_hwnd(libvlc_media_player,
getWindow().window,
ex);
#endif
}
int VlcPlugin::playlist_add( const char *mrl, libvlc_exception_t *ex )
{
int item = -1;
libvlc_media_t *p_m = libvlc_media_new(libvlc_instance,mrl,ex);
if( libvlc_exception_raised(ex) )
return -1;
libvlc_media_list_lock(libvlc_media_list);
libvlc_media_list_add_media(libvlc_media_list,p_m,ex);
if( !libvlc_exception_raised(ex) )
item = libvlc_media_list_count(libvlc_media_list,ex)-1;
libvlc_media_list_unlock(libvlc_media_list);
libvlc_media_release(p_m);
return item;
}
int VlcPlugin::playlist_add_extended_untrusted( const char *mrl, const char *name,
int optc, const char **optv, libvlc_exception_t *ex )
{
libvlc_media_t *p_m = libvlc_media_new(libvlc_instance, mrl,ex);
int item = -1;
if( libvlc_exception_raised(ex) )
return -1;
for( int i = 0; i < optc; ++i )
{
libvlc_media_add_option_untrusted(p_m, optv[i],ex);
if( libvlc_exception_raised(ex) )
{
libvlc_media_release(p_m);
return -1;
}
}
libvlc_media_list_lock(libvlc_media_list);
libvlc_media_list_add_media(libvlc_media_list,p_m,ex);
if( !libvlc_exception_raised(ex) )
item = libvlc_media_list_count(libvlc_media_list,ex)-1;
libvlc_media_list_unlock(libvlc_media_list);
libvlc_media_release(p_m);
return item;
}
void VlcPlugin::playlist_play( libvlc_exception_t *ex )
{
if( libvlc_media_player||playlist_select(0,ex) )
libvlc_media_player_play(libvlc_media_player,ex);
}
void VlcPlugin::playlist_play_item( int idx, libvlc_exception_t *ex )
{
if( playlist_select(idx,ex) )
libvlc_media_player_play(libvlc_media_player,ex);
}
void VlcPlugin::playlist_stop( libvlc_exception_t *ex )
{
if( libvlc_media_player )
libvlc_media_player_stop(libvlc_media_player,ex);
}
bool VlcPlugin::playlist_select( int idx, libvlc_exception_t *ex )
{
libvlc_media_t *p_m = NULL;
libvlc_media_list_lock(libvlc_media_list);
int count = libvlc_media_list_count(libvlc_media_list,ex);
if( libvlc_exception_raised(ex) )
goto bad_unlock;
if( idx<0||idx>=count )
goto bad_unlock;
playlist_index = idx;
p_m = libvlc_media_list_item_at_index(libvlc_media_list,playlist_index,ex);
libvlc_media_list_unlock(libvlc_media_list);
if( libvlc_exception_raised(ex) )
return false;
if( libvlc_media_player )
{
libvlc_media_player_release( libvlc_media_player );
libvlc_media_player = NULL;
}
libvlc_media_player = libvlc_media_player_new_from_media(p_m,ex);
if( libvlc_media_player )
set_player_window(ex);
libvlc_media_release( p_m );
return !libvlc_exception_raised(ex);
bad_unlock:
libvlc_media_list_unlock(libvlc_media_list);
return false;
}
void VlcPlugin::playlist_next( libvlc_exception_t *ex )
{
if( playlist_select(playlist_index+1,ex) )
libvlc_media_player_play(libvlc_media_player,ex);
}
void VlcPlugin::playlist_prev( libvlc_exception_t *ex )
{
if( playlist_select(playlist_index-1,ex) )
libvlc_media_player_play(libvlc_media_player,ex);
}
void VlcPlugin::playlist_pause( libvlc_exception_t *ex )
{
if( libvlc_media_player )
libvlc_media_player_pause(libvlc_media_player,ex);
}
void VlcPlugin::playlist_delete_item( int idx, libvlc_exception_t *ex )
{
libvlc_media_list_lock(libvlc_media_list);
libvlc_media_list_remove_index(libvlc_media_list,idx,ex);
libvlc_media_list_unlock(libvlc_media_list);
}
void VlcPlugin::playlist_clear( libvlc_exception_t *ex )
{
if( libvlc_media_list )
libvlc_media_list_release(libvlc_media_list);
libvlc_media_list = libvlc_media_list_new(getVLC(),ex);
}
int VlcPlugin::playlist_count( libvlc_exception_t *ex )
{
int items_count = 0;
libvlc_media_list_lock(libvlc_media_list);
items_count = libvlc_media_list_count(libvlc_media_list,ex);
libvlc_media_list_unlock(libvlc_media_list);
return items_count;
}
int VlcPlugin::playlist_isplaying( libvlc_exception_t *ex )
{
int is_playing = 0;
if( libvlc_media_player )
libvlc_media_player_is_playing( libvlc_media_player, ex );
return is_playing;
}
void VlcPlugin::toggle_fullscreen( libvlc_exception_t *ex )
{
if( playlist_isplaying(ex) )
libvlc_toggle_fullscreen(libvlc_media_player,ex);
}
void VlcPlugin::set_fullscreen( int yes, libvlc_exception_t *ex )
{
if( playlist_isplaying(ex) )
libvlc_set_fullscreen(libvlc_media_player,yes,ex);
}
int VlcPlugin::get_fullscreen( libvlc_exception_t *ex )
{
int r = 0;
if( playlist_isplaying(ex) )
r = libvlc_get_fullscreen(libvlc_media_player,ex);
return r;
}
int VlcPlugin::player_has_vout( libvlc_exception_t *ex )
{
int r = 0;
if( playlist_isplaying(ex) )
r = libvlc_media_player_has_vout(libvlc_media_player, ex);
return r;
}
/***************************************************************************** /*****************************************************************************
* VlcPlugin methods * VlcPlugin methods
*****************************************************************************/ *****************************************************************************/
...@@ -559,9 +774,7 @@ void VlcPlugin::hideToolbar() ...@@ -559,9 +774,7 @@ void VlcPlugin::hideToolbar()
void VlcPlugin::redrawToolbar() void VlcPlugin::redrawToolbar()
{ {
libvlc_media_player_t *p_md = NULL;
libvlc_exception_t ex; libvlc_exception_t ex;
float f_position = 0.0;
int is_playing = 0; int is_playing = 0;
bool b_mute = false; bool b_mute = false;
unsigned int dst_x, dst_y; unsigned int dst_x, dst_y;
...@@ -579,26 +792,7 @@ void VlcPlugin::redrawToolbar() ...@@ -579,26 +792,7 @@ void VlcPlugin::redrawToolbar()
getToolbarSize( &i_tb_width, &i_tb_height ); getToolbarSize( &i_tb_width, &i_tb_height );
/* get media instance */
libvlc_exception_init( &ex ); libvlc_exception_init( &ex );
p_md = libvlc_playlist_get_media_player( getVLC(), &ex );
libvlc_exception_clear( &ex );
if( p_md )
{
/* get isplaying */
libvlc_playlist_lock( getVLC() );
is_playing = libvlc_playlist_isplaying( getVLC(), &ex );
libvlc_playlist_unlock( getVLC() );
libvlc_exception_clear( &ex );
/* get movie position in % */
if( is_playing == 1 )
{
f_position = libvlc_media_player_get_position( p_md, &ex ) * 100.0;
libvlc_exception_clear( &ex );
}
libvlc_media_player_release( p_md );
}
/* get mute info */ /* get mute info */
b_mute = libvlc_audio_get_mute( getVLC(), &ex ); b_mute = libvlc_audio_get_mute( getVLC(), &ex );
...@@ -667,9 +861,15 @@ void VlcPlugin::redrawToolbar() ...@@ -667,9 +861,15 @@ void VlcPlugin::redrawToolbar()
dst_y - (p_timeline->height >> 1), dst_y - (p_timeline->height >> 1),
(window.width-(dst_x+BTN_SPACE)), p_timeline->height ); (window.width-(dst_x+BTN_SPACE)), p_timeline->height );
if( f_position > 0 )
i_last_position = (int)( f_position *
( ((float)(window.width-(dst_x+BTN_SPACE))) / 100.0 )); /* get movie position in % */
if( playlist_isplaying(&ex) )
{
i_last_position = (int)((window.width-(dst_x+BTN_SPACE))*
libvlc_media_player_get_position(libvlc_media_player,&ex));
}
libvlc_exception_clear( &ex );
if( p_btnTime ) if( p_btnTime )
XPutImage( p_display, control, gc, p_btnTime, XPutImage( p_display, control, gc, p_btnTime,
...@@ -701,9 +901,7 @@ vlc_toolbar_clicked_t VlcPlugin::getToolbarButtonClicked( int i_xpos, int i_ypos ...@@ -701,9 +901,7 @@ vlc_toolbar_clicked_t VlcPlugin::getToolbarButtonClicked( int i_xpos, int i_ypos
/* get isplaying */ /* get isplaying */
libvlc_exception_init( &ex ); libvlc_exception_init( &ex );
libvlc_playlist_lock( getVLC() ); is_playing = playlist_isplaying( &ex );
is_playing = libvlc_playlist_isplaying( getVLC(), &ex );
libvlc_playlist_unlock( getVLC() );
libvlc_exception_clear( &ex ); libvlc_exception_clear( &ex );
/* get mute info */ /* get mute info */
......
...@@ -88,6 +88,14 @@ public: ...@@ -88,6 +88,14 @@ public:
NPError init(int argc, char* const argn[], char* const argv[]); NPError init(int argc, char* const argn[], char* const argv[]);
libvlc_instance_t* getVLC() libvlc_instance_t* getVLC()
{ return libvlc_instance; }; { return libvlc_instance; };
libvlc_media_player_t* getMD(libvlc_exception_t *ex)
{
if( !libvlc_media_player )
{
libvlc_exception_raise(ex,"null mediaplayer");
}
return libvlc_media_player;
}
NPP getBrowser() NPP getBrowser()
{ return p_browser; }; { return p_browser; };
char* getAbsoluteURL(const char *url); char* getAbsoluteURL(const char *url);
...@@ -139,9 +147,37 @@ public: ...@@ -139,9 +147,37 @@ public:
int b_toolbar; int b_toolbar;
char * psz_target; char * psz_target;
bool playlist_select(int,libvlc_exception_t *);
int playlist_add( const char *, libvlc_exception_t * );
int playlist_add_extended_untrusted( const char *, const char *, int,
const char **, libvlc_exception_t * );
void playlist_play( libvlc_exception_t * );
void playlist_play_item( int, libvlc_exception_t * );
void playlist_stop( libvlc_exception_t * );
void playlist_next( libvlc_exception_t * );
void playlist_prev( libvlc_exception_t * );
void playlist_pause( libvlc_exception_t * );
void playlist_delete_item( int, libvlc_exception_t * );
void playlist_clear( libvlc_exception_t * );
int playlist_count( libvlc_exception_t * );
int playlist_isplaying( libvlc_exception_t * );
void toggle_fullscreen( libvlc_exception_t * );
void set_fullscreen( int, libvlc_exception_t * );
int get_fullscreen( libvlc_exception_t * );
int player_has_vout( libvlc_exception_t * );
private: private:
void set_player_window( libvlc_exception_t * );
/* VLC reference */ /* VLC reference */
int playlist_index;
libvlc_instance_t *libvlc_instance; libvlc_instance_t *libvlc_instance;
libvlc_media_list_t *libvlc_media_list;
libvlc_media_player_t *libvlc_media_player;
libvlc_log_t *libvlc_log; libvlc_log_t *libvlc_log;
NPClass *p_scriptClass; NPClass *p_scriptClass;
......
...@@ -157,6 +157,8 @@ NPError NPP_SetValue( NPP instance, NPNVariable variable, void *value ) ...@@ -157,6 +157,8 @@ NPError NPP_SetValue( NPP instance, NPNVariable variable, void *value )
int16 NPP_HandleEvent( NPP instance, void * event ) int16 NPP_HandleEvent( NPP instance, void * event )
{ {
static UInt32 lastMouseUp = 0; static UInt32 lastMouseUp = 0;
libvlc_exception_t ex;
libvlc_exception_init(&ex);
if( instance == NULL ) if( instance == NULL )
{ {
...@@ -181,24 +183,8 @@ int16 NPP_HandleEvent( NPP instance, void * event ) ...@@ -181,24 +183,8 @@ int16 NPP_HandleEvent( NPP instance, void * event )
if( (myEvent->when - lastMouseUp) < GetDblTime() ) if( (myEvent->when - lastMouseUp) < GetDblTime() )
{ {
/* double click */ /* double click */
libvlc_instance_t *p_vlc = p_plugin->getVLC(); p_plugin->toggle_fullscreen(&ex);
if( p_vlc ) libvlc_exception_clear(&ex);
{
int is_playing;
libvlc_playlist_lock(p_vlc);
is_playing = libvlc_playlist_isplaying(p_vlc, NULL);
libvlc_playlist_unlock(p_vlc);
if( is_playing )
{
libvlc_media_player_t *p_md =
libvlc_playlist_get_media_player(p_vlc, NULL);
if( p_md )
{
libvlc_toggle_fullscreen(p_md, NULL);
libvlc_media_player_release(p_md);
}
}
}
} }
return true; return true;
} }
...@@ -215,36 +201,21 @@ int16 NPP_HandleEvent( NPP instance, void * event ) ...@@ -215,36 +201,21 @@ int16 NPP_HandleEvent( NPP instance, void * event )
if( npwindow.window ) if( npwindow.window )
{ {
int hasVout = FALSE; int hasVout = FALSE;
libvlc_instance_t *p_vlc = p_plugin->getVLC();
if( p_vlc ) if( p_plugin->playlist_isplaying(&ex) )
{ {
int is_playing; hasVout = p_plugin->player_has_vout(NULL);
libvlc_playlist_lock(p_vlc); if( hasVout )
is_playing = libvlc_playlist_isplaying(p_vlc, NULL);
libvlc_playlist_unlock(p_vlc);
if( is_playing )
{ {
libvlc_media_player_t *p_md = libvlc_rectangle_t area;
libvlc_playlist_get_media_player(p_vlc, NULL); area.left = 0;
if( p_md ) area.top = 0;
{ area.right = npwindow.width;
hasVout = libvlc_media_player_has_vout(p_md, area.bottom = npwindow.height;
NULL); libvlc_video_redraw_rectangle(p_md, &area, NULL);
if( hasVout )
{
libvlc_rectangle_t area;
area.left = 0;
area.top = 0;
area.right = npwindow.width;
area.bottom = npwindow.height;
libvlc_video_redraw_rectangle(p_md, &area,
NULL);
}
libvlc_media_player_release(p_md);
}
} }
} }
libvlc_exception_clear(&ex);
if( ! hasVout ) if( ! hasVout )
{ {
...@@ -548,8 +519,8 @@ NPError NPP_SetWindow( NPP instance, NPWindow* window ) ...@@ -548,8 +519,8 @@ NPError NPP_SetWindow( NPP instance, NPWindow* window )
libvlc_exception_t ex; libvlc_exception_t ex;
libvlc_exception_init(& ex ); libvlc_exception_init(& ex );
p_md = libvlc_playlist_get_media_player( p_plugin->getVLC(), &ex ); p_md = p_plugin->getMD( &ex );
libvlc_exception_init( &ex ); libvlc_exception_clear( &ex );
libvlc_event_attach( libvlc_media_player_event_manager( p_md, &ex ), libvlc_event_attach( libvlc_media_player_event_manager( p_md, &ex ),
libvlc_MediaPlayerPositionChanged, Redraw, NULL, &ex ); libvlc_MediaPlayerPositionChanged, Redraw, NULL, &ex );
*/ */
...@@ -583,12 +554,11 @@ NPError NPP_SetWindow( NPP instance, NPWindow* window ) ...@@ -583,12 +554,11 @@ NPError NPP_SetWindow( NPP instance, NPWindow* window )
{ {
if( p_plugin->psz_target ) if( p_plugin->psz_target )
{ {
if( libvlc_playlist_add( p_vlc, p_plugin->psz_target, if( p_plugin->playlist_add( p_plugin->psz_target, NULL ) != -1 )
NULL, NULL ) != -1 )
{ {
if( p_plugin->b_autoplay ) if( p_plugin->b_autoplay )
{ {
libvlc_playlist_play(p_vlc, 0, 0, NULL, NULL); p_plugin->playlist_play(NULL);
} }
} }
p_plugin->b_stream = true; p_plugin->b_stream = true;
...@@ -665,12 +635,11 @@ void NPP_StreamAsFile( NPP instance, NPStream *stream, const char* fname ) ...@@ -665,12 +635,11 @@ void NPP_StreamAsFile( NPP instance, NPStream *stream, const char* fname )
return; return;
} }
if( libvlc_playlist_add( p_plugin->getVLC(), fname, stream->url, NULL ) if( p_plugin->playlist_add( stream->url, NULL ) != -1 )
!= -1 )
{ {
if( p_plugin->b_autoplay ) if( p_plugin->b_autoplay )
{ {
libvlc_playlist_play( p_plugin->getVLC(), 0, 0, NULL, NULL); p_plugin->playlist_play(NULL);
} }
} }
} }
...@@ -848,15 +817,12 @@ static void ControlHandler( Widget w, XtPointer closure, XEvent *event ) ...@@ -848,15 +817,12 @@ static void ControlHandler( Widget w, XtPointer closure, XEvent *event )
libvlc_exception_t ex; libvlc_exception_t ex;
libvlc_exception_init( &ex ); libvlc_exception_init( &ex );
libvlc_media_player_t *p_md = libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
libvlc_playlist_get_media_player(p_plugin->getVLC(), &ex);
if( libvlc_exception_raised(&ex) ) if( libvlc_exception_raised(&ex) )
fprintf( stderr, "%s\n", libvlc_exception_get_message(&ex)); fprintf( stderr, "%s\n", libvlc_exception_get_message(&ex));
libvlc_exception_clear( &ex ); libvlc_exception_clear( &ex );
libvlc_playlist_lock( p_plugin->getVLC() ); i_playing = p_plugin->playlist_isplaying( &ex );
i_playing = libvlc_playlist_isplaying( p_plugin->getVLC(), &ex );
libvlc_playlist_unlock( p_plugin->getVLC() );
if( libvlc_exception_raised(&ex) ) if( libvlc_exception_raised(&ex) )
fprintf( stderr, "%s\n", libvlc_exception_get_message(&ex)); fprintf( stderr, "%s\n", libvlc_exception_get_message(&ex));
libvlc_exception_clear( &ex ); libvlc_exception_clear( &ex );
...@@ -869,9 +835,9 @@ static void ControlHandler( Widget w, XtPointer closure, XEvent *event ) ...@@ -869,9 +835,9 @@ static void ControlHandler( Widget w, XtPointer closure, XEvent *event )
case clicked_Pause: case clicked_Pause:
{ {
if( i_playing == 1 ) if( i_playing == 1 )
libvlc_playlist_pause( p_plugin->getVLC(), &ex ); p_plugin->playlist_pause( &ex );
else else
libvlc_playlist_play( p_plugin->getVLC(), -1, 0, NULL, &ex ); p_plugin->playlist_play( &ex );
if( libvlc_exception_raised(&ex) ) if( libvlc_exception_raised(&ex) )
fprintf( stderr, "%s\n", libvlc_exception_get_message(&ex)); fprintf( stderr, "%s\n", libvlc_exception_get_message(&ex));
...@@ -881,7 +847,7 @@ static void ControlHandler( Widget w, XtPointer closure, XEvent *event ) ...@@ -881,7 +847,7 @@ static void ControlHandler( Widget w, XtPointer closure, XEvent *event )
case clicked_Stop: case clicked_Stop:
{ {
libvlc_playlist_stop( p_plugin->getVLC(), &ex ); p_plugin->playlist_stop(&ex);
if( libvlc_exception_raised(&ex) ) if( libvlc_exception_raised(&ex) )
fprintf( stderr, "%s\n", libvlc_exception_get_message(&ex)); fprintf( stderr, "%s\n", libvlc_exception_get_message(&ex));
libvlc_exception_clear( &ex ); libvlc_exception_clear( &ex );
...@@ -890,13 +856,10 @@ static void ControlHandler( Widget w, XtPointer closure, XEvent *event ) ...@@ -890,13 +856,10 @@ static void ControlHandler( Widget w, XtPointer closure, XEvent *event )
case clicked_Fullscreen: case clicked_Fullscreen:
{ {
if( (i_playing == 1) && p_md ) p_plugin->set_fullscreen( 1, &ex );
{ if( libvlc_exception_raised(&ex) )
libvlc_set_fullscreen( p_md, 1, &ex ); fprintf( stderr, "%s\n", libvlc_exception_get_message(&ex));
if( libvlc_exception_raised(&ex) ) libvlc_exception_clear( &ex );
fprintf( stderr, "%s\n", libvlc_exception_get_message(&ex));
libvlc_exception_clear( &ex );
}
} }
break; break;
...@@ -939,7 +902,6 @@ static void ControlHandler( Widget w, XtPointer closure, XEvent *event ) ...@@ -939,7 +902,6 @@ static void ControlHandler( Widget w, XtPointer closure, XEvent *event )
default: /* button_Unknown */ default: /* button_Unknown */
break; break;
} }
if( p_md ) libvlc_media_player_release( p_md );
} }
Redraw( w, closure, event ); Redraw( w, closure, event );
} }
......
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