1 /*****************************************************************************
2 * npolibvlc.cpp: official Javascript APIs
3 *****************************************************************************
4 * Copyright (C) 2002-2009 the VideoLAN team
5 * Copyright (C) 2010 M2X BV
7 * Authors: Damien Fouilleul <Damien.Fouilleul@laposte.net>
8 * JP Dinger <jpd@videolan.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
32 #ifdef HAVE_MOZILLA_CONFIG_H
33 # include <mozilla-config.h>
36 #include "vlcplugin.h"
37 #include "npolibvlc.h"
42 ** Local helper macros and function
44 #define COUNTNAMES(a,b,c) const int a::b = sizeof(a::c)/sizeof(NPUTF8 *)
45 #define RETURN_ON_EXCEPTION(this,ex) \
46 do { if( libvlc_exception_raised(&ex) ) \
48 NPN_SetException(this, libvlc_errmsg()); \
49 libvlc_exception_clear(&ex); \
50 return INVOKERESULT_GENERIC_ERROR; \
53 #define ERROR_EVENT_NOT_FOUND "ERROR: One or more events could not be found."
54 #define ERROR_API_VERSION "ERROR: NPAPI version not high enough. (Gecko >= 1.9 needed)"
56 // Make a copy of an NPVariant.
57 NPVariant copyNPVariant(const NPVariant& original)
61 if (NPVARIANT_IS_STRING(original))
62 STRINGZ_TO_NPVARIANT(strdup(NPVARIANT_TO_STRING(original).utf8characters), res);
63 else if (NPVARIANT_IS_INT32(original))
64 INT32_TO_NPVARIANT(NPVARIANT_TO_INT32(original), res);
65 else if (NPVARIANT_IS_DOUBLE(original))
66 DOUBLE_TO_NPVARIANT(NPVARIANT_TO_DOUBLE(original), res);
67 else if (NPVARIANT_IS_OBJECT(original))
69 NPObject *obj = NPVARIANT_TO_OBJECT(original);
70 NPN_RetainObject(obj);
71 OBJECT_TO_NPVARIANT(obj, res);
73 else if (NPVARIANT_IS_BOOLEAN(original))
74 BOOLEAN_TO_NPVARIANT(NPVARIANT_TO_BOOLEAN(original), res);
79 // Parse an event Array given as a NPObject by JS.
80 // This function is similar to LibvlcPlaylistNPObject::parseOptions,
81 // but we don't use it because it's not clearly accessible and the FIXME flags
82 // implie that it might be modified.
83 bool parseEventArray(NPObject *obj, eventtypes_bitmap_t &eventToGet, NPP instance)
85 NPIdentifier propId = NPN_GetStringIdentifier("length");
88 if (!NPN_GetProperty(instance, obj, propId, &value))
91 int count = NPVARIANT_TO_INT32(value);
92 NPN_ReleaseVariantValue(&value);
97 while (nOptions < count)
99 propId = NPN_GetIntIdentifier(nOptions);
100 // if there is no other string in the array.
101 if( ! NPN_GetProperty(instance, obj, propId, &value) )
104 // if the element is not a string.
105 if( ! NPVARIANT_IS_STRING(value) )
107 NPN_ReleaseVariantValue(&value);
111 if (!eventToGet.add_event(NPVARIANT_TO_STRING(value).utf8characters))
119 ** implementation of libvlc root object
122 LibvlcRootNPObject::~LibvlcRootNPObject()
125 ** When the plugin is destroyed, firefox takes it upon itself to
126 ** destroy all 'live' script objects and ignores refcounting.
127 ** Therefore we cannot safely assume that refcounting will control
128 ** lifespan of objects. Hence they are only lazily created on
129 ** request, so that firefox can take ownership, and are not released
130 ** when the plugin is destroyed.
134 if( audioObj ) NPN_ReleaseObject(audioObj);
135 if( inputObj ) NPN_ReleaseObject(inputObj);
136 if( playlistObj ) NPN_ReleaseObject(playlistObj);
137 if( videoObj ) NPN_ReleaseObject(videoObj);
141 const NPUTF8 * const LibvlcRootNPObject::propertyNames[] =
151 COUNTNAMES(LibvlcRootNPObject,propertyCount,propertyNames);
153 enum LibvlcRootNPObjectPropertyIds
164 RuntimeNPObject::InvokeResult
165 LibvlcRootNPObject::getProperty(int index, NPVariant &result)
167 /* is plugin still running */
168 if( isPluginRunning() )
173 InstantObj<LibvlcAudioNPObject>( audioObj );
174 OBJECT_TO_NPVARIANT(NPN_RetainObject(audioObj), result);
175 return INVOKERESULT_NO_ERROR;
177 InstantObj<LibvlcInputNPObject>( inputObj );
178 OBJECT_TO_NPVARIANT(NPN_RetainObject(inputObj), result);
179 return INVOKERESULT_NO_ERROR;
180 case ID_root_playlist:
181 InstantObj<LibvlcPlaylistNPObject>( playlistObj );
182 OBJECT_TO_NPVARIANT(NPN_RetainObject(playlistObj), result);
183 return INVOKERESULT_NO_ERROR;
184 case ID_root_subtitle:
185 InstantObj<LibvlcSubtitleNPObject>( subtitleObj );
186 OBJECT_TO_NPVARIANT(NPN_RetainObject(subtitleObj), result);
187 return INVOKERESULT_NO_ERROR;
189 InstantObj<LibvlcVideoNPObject>( videoObj );
190 OBJECT_TO_NPVARIANT(NPN_RetainObject(videoObj), result);
191 return INVOKERESULT_NO_ERROR;
193 // create child object in lazyman fashion to avoid
194 // ownership problem with firefox
196 eventObj = NPN_CreateObject(_instance,
197 RuntimeNPClass<LibvlcEventNPObject>::getClass());
198 OBJECT_TO_NPVARIANT(NPN_RetainObject(eventObj), result);
199 return INVOKERESULT_NO_ERROR;
200 case ID_root_VersionInfo:
201 return invokeResultString(libvlc_get_version(),result);
206 return INVOKERESULT_GENERIC_ERROR;
209 const NPUTF8 * const LibvlcRootNPObject::methodNames[] =
213 COUNTNAMES(LibvlcRootNPObject,methodCount,methodNames);
215 enum LibvlcRootNPObjectMethodIds
220 RuntimeNPObject::InvokeResult LibvlcRootNPObject::invoke(int index,
221 const NPVariant *args, uint32_t argCount, NPVariant &result)
223 /* is plugin still running */
224 if( isPluginRunning() )
226 libvlc_exception_t ex;
227 libvlc_exception_init(&ex);
231 case ID_root_versionInfo:
233 return INVOKERESULT_NO_SUCH_METHOD;
234 return invokeResultString(libvlc_get_version(),result);
239 return INVOKERESULT_GENERIC_ERROR;
243 ** implementation of libvlc audio object
246 const NPUTF8 * const LibvlcAudioNPObject::propertyNames[] =
254 COUNTNAMES(LibvlcAudioNPObject,propertyCount,propertyNames);
256 enum LibvlcAudioNPObjectPropertyIds
265 RuntimeNPObject::InvokeResult
266 LibvlcAudioNPObject::getProperty(int index, NPVariant &result)
268 /* is plugin still running */
269 if( isPluginRunning() )
271 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
272 libvlc_exception_t ex;
273 libvlc_exception_init(&ex);
279 bool muted = libvlc_audio_get_mute(p_plugin->getVLC());
280 BOOLEAN_TO_NPVARIANT(muted, result);
281 return INVOKERESULT_NO_ERROR;
283 case ID_audio_volume:
285 int volume = libvlc_audio_get_volume(p_plugin->getVLC());
286 INT32_TO_NPVARIANT(volume, result);
287 return INVOKERESULT_NO_ERROR;
291 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
292 RETURN_ON_EXCEPTION(this,ex);
293 int track = libvlc_audio_get_track(p_md, &ex);
294 RETURN_ON_EXCEPTION(this,ex);
295 INT32_TO_NPVARIANT(track, result);
296 return INVOKERESULT_NO_ERROR;
300 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
301 RETURN_ON_EXCEPTION(this,ex);
302 // get the number of audio track available
303 int i_track = libvlc_audio_get_track_count(p_md, &ex);
304 RETURN_ON_EXCEPTION(this,ex);
306 INT32_TO_NPVARIANT(i_track, result);
307 return INVOKERESULT_NO_ERROR;
309 case ID_audio_channel:
311 int channel = libvlc_audio_get_channel(p_plugin->getVLC(), &ex);
312 RETURN_ON_EXCEPTION(this,ex);
313 INT32_TO_NPVARIANT(channel, result);
314 return INVOKERESULT_NO_ERROR;
320 return INVOKERESULT_GENERIC_ERROR;
323 RuntimeNPObject::InvokeResult
324 LibvlcAudioNPObject::setProperty(int index, const NPVariant &value)
326 /* is plugin still running */
327 if( isPluginRunning() )
329 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
330 libvlc_exception_t ex;
331 libvlc_exception_init(&ex);
336 if( NPVARIANT_IS_BOOLEAN(value) )
338 libvlc_audio_set_mute(p_plugin->getVLC(),
339 NPVARIANT_TO_BOOLEAN(value));
340 return INVOKERESULT_NO_ERROR;
342 return INVOKERESULT_INVALID_VALUE;
343 case ID_audio_volume:
344 if( isNumberValue(value) )
346 libvlc_audio_set_volume(p_plugin->getVLC(),
347 numberValue(value), &ex);
348 RETURN_ON_EXCEPTION(this,ex);
349 return INVOKERESULT_NO_ERROR;
351 return INVOKERESULT_INVALID_VALUE;
353 if( isNumberValue(value) )
355 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
356 RETURN_ON_EXCEPTION(this,ex);
357 libvlc_audio_set_track(p_md, numberValue(value), &ex);
358 RETURN_ON_EXCEPTION(this,ex);
359 return INVOKERESULT_NO_ERROR;
361 return INVOKERESULT_INVALID_VALUE;
362 case ID_audio_channel:
363 if( isNumberValue(value) )
365 libvlc_audio_set_channel(p_plugin->getVLC(),
366 numberValue(value), &ex);
367 RETURN_ON_EXCEPTION(this,ex);
368 return INVOKERESULT_NO_ERROR;
370 return INVOKERESULT_INVALID_VALUE;
375 return INVOKERESULT_GENERIC_ERROR;
378 const NPUTF8 * const LibvlcAudioNPObject::methodNames[] =
383 COUNTNAMES(LibvlcAudioNPObject,methodCount,methodNames);
385 enum LibvlcAudioNPObjectMethodIds
388 ID_audio_description,
391 RuntimeNPObject::InvokeResult
392 LibvlcAudioNPObject::invoke(int index, const NPVariant *args,
393 uint32_t argCount, NPVariant &result)
395 /* is plugin still running */
396 if( isPluginRunning() )
398 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
399 libvlc_exception_t ex;
400 libvlc_exception_init(&ex);
404 case ID_audio_togglemute:
407 libvlc_audio_toggle_mute(p_plugin->getVLC());
408 VOID_TO_NPVARIANT(result);
409 return INVOKERESULT_NO_ERROR;
411 return INVOKERESULT_NO_SUCH_METHOD;
412 case ID_audio_description:
417 int i_trackID, i_limit, i;
418 libvlc_track_description_t *p_trackDesc;
420 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
421 RETURN_ON_EXCEPTION(this,ex);
423 /* get tracks description */
424 p_trackDesc = libvlc_audio_get_track_description(p_md, &ex);
425 RETURN_ON_EXCEPTION(this,ex);
427 return INVOKERESULT_GENERIC_ERROR;
429 /* get the number of track available */
430 i_limit = libvlc_audio_get_track_count(p_md, &ex);
431 RETURN_ON_EXCEPTION(this,ex);
433 /* check if a number is given by the user
434 * and get the track number */
435 if( isNumberValue(args[0]) )
436 i_trackID = numberValue(args[0]);
438 return INVOKERESULT_INVALID_VALUE;
440 /* if bad number is given return invalid value */
441 if ( ( i_trackID > ( i_limit - 1 ) ) || ( i_trackID < 0 ) )
442 return INVOKERESULT_INVALID_VALUE;
444 /* get the good trackDesc */
445 for( i = 0 ; i < i_trackID ; i++ )
447 p_trackDesc = p_trackDesc->p_next;
449 psz_name = p_trackDesc->psz_name;
451 /* display the name of the track chosen */
452 return invokeResultString( psz_name, result );
454 return INVOKERESULT_NO_SUCH_METHOD;
460 return INVOKERESULT_GENERIC_ERROR;
464 ** implementation of libvlc input object
467 const NPUTF8 * const LibvlcInputNPObject::propertyNames[] =
477 COUNTNAMES(LibvlcInputNPObject,propertyCount,propertyNames);
479 enum LibvlcInputNPObjectPropertyIds
490 RuntimeNPObject::InvokeResult
491 LibvlcInputNPObject::getProperty(int index, NPVariant &result)
493 /* is plugin still running */
494 if( isPluginRunning() )
496 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
497 libvlc_exception_t ex;
498 libvlc_exception_init(&ex);
500 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
501 if( libvlc_exception_raised(&ex) )
503 if( index != ID_input_state )
505 NPN_SetException(this, libvlc_errmsg());
506 libvlc_exception_clear(&ex);
507 return INVOKERESULT_GENERIC_ERROR;
511 /* for input state, return CLOSED rather than an exception */
512 INT32_TO_NPVARIANT(0, result);
513 libvlc_exception_clear(&ex);
514 return INVOKERESULT_NO_ERROR;
520 case ID_input_length:
522 double val = (double)libvlc_media_player_get_length(p_md, &ex);
523 RETURN_ON_EXCEPTION(this,ex);
524 DOUBLE_TO_NPVARIANT(val, result);
525 return INVOKERESULT_NO_ERROR;
527 case ID_input_position:
529 double val = libvlc_media_player_get_position(p_md, &ex);
530 RETURN_ON_EXCEPTION(this,ex);
531 DOUBLE_TO_NPVARIANT(val, result);
532 return INVOKERESULT_NO_ERROR;
536 double val = (double)libvlc_media_player_get_time(p_md, &ex);
537 RETURN_ON_EXCEPTION(this,ex);
538 DOUBLE_TO_NPVARIANT(val, result);
539 return INVOKERESULT_NO_ERROR;
543 int val = libvlc_media_player_get_state(p_md);
544 RETURN_ON_EXCEPTION(this,ex);
545 INT32_TO_NPVARIANT(val, result);
546 return INVOKERESULT_NO_ERROR;
550 float val = libvlc_media_player_get_rate(p_md, &ex);
551 RETURN_ON_EXCEPTION(this,ex);
552 DOUBLE_TO_NPVARIANT(val, result);
553 return INVOKERESULT_NO_ERROR;
557 double val = libvlc_media_player_get_fps(p_md, &ex);
558 RETURN_ON_EXCEPTION(this,ex);
559 DOUBLE_TO_NPVARIANT(val, result);
560 return INVOKERESULT_NO_ERROR;
562 case ID_input_hasvout:
564 bool val = p_plugin->player_has_vout(&ex);
565 RETURN_ON_EXCEPTION(this,ex);
566 BOOLEAN_TO_NPVARIANT(val, result);
567 return INVOKERESULT_NO_ERROR;
573 return INVOKERESULT_GENERIC_ERROR;
576 RuntimeNPObject::InvokeResult
577 LibvlcInputNPObject::setProperty(int index, const NPVariant &value)
579 /* is plugin still running */
580 if( isPluginRunning() )
582 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
583 libvlc_exception_t ex;
584 libvlc_exception_init(&ex);
586 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
587 RETURN_ON_EXCEPTION(this,ex);
591 case ID_input_position:
593 if( ! NPVARIANT_IS_DOUBLE(value) )
595 return INVOKERESULT_INVALID_VALUE;
598 float val = (float)NPVARIANT_TO_DOUBLE(value);
599 libvlc_media_player_set_position(p_md, val, &ex);
600 RETURN_ON_EXCEPTION(this,ex);
601 return INVOKERESULT_NO_ERROR;
606 if( NPVARIANT_IS_INT32(value) )
607 val = (int64_t)NPVARIANT_TO_INT32(value);
608 else if( NPVARIANT_IS_DOUBLE(value) )
609 val = (int64_t)NPVARIANT_TO_DOUBLE(value);
612 return INVOKERESULT_INVALID_VALUE;
615 libvlc_media_player_set_time(p_md, val, &ex);
616 RETURN_ON_EXCEPTION(this,ex);
617 return INVOKERESULT_NO_ERROR;
622 if( NPVARIANT_IS_INT32(value) )
623 val = (float)NPVARIANT_TO_INT32(value);
624 else if( NPVARIANT_IS_DOUBLE(value) )
625 val = (float)NPVARIANT_TO_DOUBLE(value);
628 return INVOKERESULT_INVALID_VALUE;
631 libvlc_media_player_set_rate(p_md, val, &ex);
632 RETURN_ON_EXCEPTION(this,ex);
633 return INVOKERESULT_NO_ERROR;
639 return INVOKERESULT_GENERIC_ERROR;
642 const NPUTF8 * const LibvlcInputNPObject::methodNames[] =
647 COUNTNAMES(LibvlcInputNPObject,methodCount,methodNames);
649 enum LibvlcInputNPObjectMethodIds
654 RuntimeNPObject::InvokeResult
655 LibvlcInputNPObject::invoke(int index, const NPVariant *args,
656 uint32_t argCount, NPVariant &result)
658 /* is plugin still running */
659 if( isPluginRunning() )
664 return INVOKERESULT_NO_SUCH_METHOD;
669 return INVOKERESULT_GENERIC_ERROR;
673 ** implementation of libvlc playlist items object
676 const NPUTF8 * const LibvlcPlaylistItemsNPObject::propertyNames[] =
680 COUNTNAMES(LibvlcPlaylistItemsNPObject,propertyCount,propertyNames);
682 enum LibvlcPlaylistItemsNPObjectPropertyIds
684 ID_playlistitems_count,
687 RuntimeNPObject::InvokeResult
688 LibvlcPlaylistItemsNPObject::getProperty(int index, NPVariant &result)
690 /* is plugin still running */
691 if( isPluginRunning() )
693 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
697 case ID_playlistitems_count:
699 int val = p_plugin->playlist_count();
700 INT32_TO_NPVARIANT(val, result);
701 return INVOKERESULT_NO_ERROR;
707 return INVOKERESULT_GENERIC_ERROR;
710 const NPUTF8 * const LibvlcPlaylistItemsNPObject::methodNames[] =
715 COUNTNAMES(LibvlcPlaylistItemsNPObject,methodCount,methodNames);
717 enum LibvlcPlaylistItemsNPObjectMethodIds
719 ID_playlistitems_clear,
720 ID_playlistitems_remove,
723 RuntimeNPObject::InvokeResult
724 LibvlcPlaylistItemsNPObject::invoke(int index, const NPVariant *args,
725 uint32_t argCount, NPVariant &result)
727 /* is plugin still running */
728 if( isPluginRunning() )
730 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
731 libvlc_exception_t ex;
732 libvlc_exception_init(&ex);
736 case ID_playlistitems_clear:
739 p_plugin->playlist_clear(&ex);
740 RETURN_ON_EXCEPTION(this,ex);
741 VOID_TO_NPVARIANT(result);
742 return INVOKERESULT_NO_ERROR;
744 return INVOKERESULT_NO_SUCH_METHOD;
745 case ID_playlistitems_remove:
746 if( (argCount == 1) && isNumberValue(args[0]) )
748 p_plugin->playlist_delete_item(numberValue(args[0]),&ex);
749 RETURN_ON_EXCEPTION(this,ex);
750 VOID_TO_NPVARIANT(result);
751 return INVOKERESULT_NO_ERROR;
753 return INVOKERESULT_NO_SUCH_METHOD;
758 return INVOKERESULT_GENERIC_ERROR;
762 ** implementation of libvlc playlist object
765 LibvlcPlaylistNPObject::~LibvlcPlaylistNPObject()
767 // Why the isValid()?
768 if( isValid() && playlistItemsObj )
769 NPN_ReleaseObject(playlistItemsObj);
772 const NPUTF8 * const LibvlcPlaylistNPObject::propertyNames[] =
774 "itemCount", /* deprecated */
778 COUNTNAMES(LibvlcPlaylistNPObject,propertyCount,propertyNames);
780 enum LibvlcPlaylistNPObjectPropertyIds
782 ID_playlist_itemcount,
783 ID_playlist_isplaying,
787 RuntimeNPObject::InvokeResult
788 LibvlcPlaylistNPObject::getProperty(int index, NPVariant &result)
790 /* is plugin still running */
791 if( isPluginRunning() )
793 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
797 case ID_playlist_itemcount: /* deprecated */
799 int val = p_plugin->playlist_count();
800 INT32_TO_NPVARIANT(val, result);
801 return INVOKERESULT_NO_ERROR;
803 case ID_playlist_isplaying:
805 int val = p_plugin->playlist_isplaying();
806 BOOLEAN_TO_NPVARIANT(val, result);
807 return INVOKERESULT_NO_ERROR;
809 case ID_playlist_items:
811 InstantObj<LibvlcPlaylistItemsNPObject>( playlistItemsObj );
812 OBJECT_TO_NPVARIANT(NPN_RetainObject(playlistItemsObj), result);
813 return INVOKERESULT_NO_ERROR;
819 return INVOKERESULT_GENERIC_ERROR;
822 const NPUTF8 * const LibvlcPlaylistNPObject::methodNames[] =
831 "clear", /* deprecated */
832 "removeItem", /* deprecated */
834 COUNTNAMES(LibvlcPlaylistNPObject,methodCount,methodNames);
836 enum LibvlcPlaylistNPObjectMethodIds
840 ID_playlist_playItem,
841 ID_playlist_togglepause,
846 ID_playlist_removeitem
849 RuntimeNPObject::InvokeResult
850 LibvlcPlaylistNPObject::invoke(int index, const NPVariant *args,
851 uint32_t argCount, NPVariant &result)
853 /* is plugin still running */
854 if( isPluginRunning() )
856 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
857 libvlc_exception_t ex;
858 libvlc_exception_init(&ex);
862 // XXX FIXME this needs squashing into something much smaller
863 case ID_playlist_add:
865 if( (argCount < 1) || (argCount > 3) )
866 return INVOKERESULT_NO_SUCH_METHOD;
867 if( !NPVARIANT_IS_STRING(args[0]) )
868 return INVOKERESULT_NO_SUCH_METHOD;
871 if( NPVARIANT_IS_NULL(args[0]) )
872 return INVOKERESULT_NO_SUCH_METHOD;
874 char *s = stringValue(NPVARIANT_TO_STRING(args[0]));
876 return INVOKERESULT_OUT_OF_MEMORY;
878 char *url = p_plugin->getAbsoluteURL(s);
882 // problem with combining url, use argument
887 // grab name if available
890 if( NPVARIANT_IS_NULL(args[1]) )
894 else if( NPVARIANT_IS_STRING(args[1]) )
896 name = stringValue(NPVARIANT_TO_STRING(args[1]));
901 return INVOKERESULT_INVALID_VALUE;
906 char** ppsz_options = NULL;
908 // grab options if available
911 if( NPVARIANT_IS_NULL(args[2]) )
915 else if( NPVARIANT_IS_STRING(args[2]) )
917 parseOptions(NPVARIANT_TO_STRING(args[2]),
918 &i_options, &ppsz_options);
921 else if( NPVARIANT_IS_OBJECT(args[2]) )
923 parseOptions(NPVARIANT_TO_OBJECT(args[2]),
924 &i_options, &ppsz_options);
930 return INVOKERESULT_INVALID_VALUE;
934 int item = p_plugin->playlist_add_extended_untrusted(url, name,
935 i_options, const_cast<const char **>(ppsz_options), &ex);
938 for( int i=0; i< i_options; ++i )
940 free(ppsz_options[i]);
944 RETURN_ON_EXCEPTION(this,ex);
945 INT32_TO_NPVARIANT(item, result);
946 return INVOKERESULT_NO_ERROR;
948 case ID_playlist_play:
951 p_plugin->playlist_play(&ex);
952 RETURN_ON_EXCEPTION(this,ex);
953 VOID_TO_NPVARIANT(result);
954 return INVOKERESULT_NO_ERROR;
956 return INVOKERESULT_NO_SUCH_METHOD;
957 case ID_playlist_playItem:
958 if( (argCount == 1) && isNumberValue(args[0]) )
960 p_plugin->playlist_play_item(numberValue(args[0]),&ex);
961 RETURN_ON_EXCEPTION(this,ex);
962 VOID_TO_NPVARIANT(result);
963 return INVOKERESULT_NO_ERROR;
965 return INVOKERESULT_NO_SUCH_METHOD;
966 case ID_playlist_togglepause:
969 p_plugin->playlist_pause(&ex);
970 RETURN_ON_EXCEPTION(this,ex);
971 VOID_TO_NPVARIANT(result);
972 return INVOKERESULT_NO_ERROR;
974 return INVOKERESULT_NO_SUCH_METHOD;
975 case ID_playlist_stop:
978 p_plugin->playlist_stop();
979 VOID_TO_NPVARIANT(result);
980 return INVOKERESULT_NO_ERROR;
982 return INVOKERESULT_NO_SUCH_METHOD;
983 case ID_playlist_next:
986 p_plugin->playlist_next(&ex);
987 RETURN_ON_EXCEPTION(this,ex);
988 VOID_TO_NPVARIANT(result);
989 return INVOKERESULT_NO_ERROR;
991 return INVOKERESULT_NO_SUCH_METHOD;
992 case ID_playlist_prev:
995 p_plugin->playlist_prev(&ex);
996 RETURN_ON_EXCEPTION(this,ex);
997 VOID_TO_NPVARIANT(result);
998 return INVOKERESULT_NO_ERROR;
1000 return INVOKERESULT_NO_SUCH_METHOD;
1001 case ID_playlist_clear: /* deprecated */
1004 p_plugin->playlist_clear(&ex);
1005 RETURN_ON_EXCEPTION(this,ex);
1006 VOID_TO_NPVARIANT(result);
1007 return INVOKERESULT_NO_ERROR;
1009 return INVOKERESULT_NO_SUCH_METHOD;
1010 case ID_playlist_removeitem: /* deprecated */
1011 if( (argCount == 1) && isNumberValue(args[0]) )
1013 p_plugin->playlist_delete_item(numberValue(args[0]), &ex);
1014 RETURN_ON_EXCEPTION(this,ex);
1015 VOID_TO_NPVARIANT(result);
1016 return INVOKERESULT_NO_ERROR;
1018 return INVOKERESULT_NO_SUCH_METHOD;
1023 return INVOKERESULT_GENERIC_ERROR;
1026 // XXX FIXME The new playlist_add creates a media instance and feeds it
1027 // XXX FIXME these options one at a time, so this hunk of code does lots
1028 // XXX FIXME of unnecessairy work. Break out something that can do one
1029 // XXX FIXME option at a time and doesn't need to realloc().
1030 // XXX FIXME Same for the other version of parseOptions.
1032 void LibvlcPlaylistNPObject::parseOptions(const NPString &nps,
1033 int *i_options, char*** ppsz_options)
1035 if( nps.utf8length )
1037 char *s = stringValue(nps);
1042 char **options = (char **)malloc(capacity*sizeof(char *));
1047 char *end = val + nps.utf8length;
1050 // skip leading blanks
1052 && ((*val == ' ' ) || (*val == '\t')) )
1056 // skip till we get a blank character
1062 if( ('\'' == c) || ('"' == c) )
1064 // skip till end of string
1065 while( (val < end) && (*(val++) != c ) );
1071 if( nOptions == capacity )
1074 char **moreOptions = (char **)realloc(options, capacity*sizeof(char*));
1077 /* failed to allocate more memory */
1079 /* return what we got so far */
1080 *i_options = nOptions;
1081 *ppsz_options = options;
1084 options = moreOptions;
1087 options[nOptions++] = strdup(start);
1090 // must be end of string
1093 *i_options = nOptions;
1094 *ppsz_options = options;
1101 // XXX FIXME See comment at the other parseOptions variant.
1102 void LibvlcPlaylistNPObject::parseOptions(NPObject *obj, int *i_options,
1103 char*** ppsz_options)
1105 /* WARNING: Safari does not implement NPN_HasProperty/NPN_HasMethod */
1109 /* we are expecting to have a Javascript Array object */
1110 NPIdentifier propId = NPN_GetStringIdentifier("length");
1111 if( NPN_GetProperty(_instance, obj, propId, &value) )
1113 int count = numberValue(value);
1114 NPN_ReleaseVariantValue(&value);
1119 char **options = (char **)malloc(capacity*sizeof(char *));
1124 while( nOptions < count )
1126 propId = NPN_GetIntIdentifier(nOptions);
1127 if( ! NPN_GetProperty(_instance, obj, propId, &value) )
1128 /* return what we got so far */
1131 if( ! NPVARIANT_IS_STRING(value) )
1133 /* return what we got so far */
1134 NPN_ReleaseVariantValue(&value);
1138 if( nOptions == capacity )
1141 char **moreOptions = (char **)realloc(options, capacity*sizeof(char*));
1144 /* failed to allocate more memory */
1145 NPN_ReleaseVariantValue(&value);
1146 /* return what we got so far */
1147 *i_options = nOptions;
1148 *ppsz_options = options;
1151 options = moreOptions;
1154 options[nOptions++] = stringValue(value);
1155 NPN_ReleaseVariantValue(&value);
1157 *i_options = nOptions;
1158 *ppsz_options = options;
1165 ** implementation of libvlc subtitle object
1168 const NPUTF8 * const LibvlcSubtitleNPObject::propertyNames[] =
1174 enum LibvlcSubtitleNPObjectPropertyIds
1179 COUNTNAMES(LibvlcSubtitleNPObject,propertyCount,propertyNames);
1181 RuntimeNPObject::InvokeResult
1182 LibvlcSubtitleNPObject::getProperty(int index, NPVariant &result)
1184 /* is plugin still running */
1185 if( isPluginRunning() )
1187 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1188 libvlc_exception_t ex;
1189 libvlc_exception_init(&ex);
1191 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1192 RETURN_ON_EXCEPTION(this,ex);
1196 case ID_subtitle_track:
1198 /* get the current subtitle ID */
1199 int i_spu = libvlc_video_get_spu(p_md, &ex);
1200 RETURN_ON_EXCEPTION(this,ex);
1202 INT32_TO_NPVARIANT(i_spu, result);
1203 return INVOKERESULT_NO_ERROR;
1205 case ID_subtitle_count:
1207 /* get the number of subtitles available */
1208 int i_spu = libvlc_video_get_spu_count(p_md, &ex);
1209 RETURN_ON_EXCEPTION(this,ex);
1211 INT32_TO_NPVARIANT(i_spu, result);
1212 return INVOKERESULT_NO_ERROR;
1216 return INVOKERESULT_GENERIC_ERROR;
1219 RuntimeNPObject::InvokeResult
1220 LibvlcSubtitleNPObject::setProperty(int index, const NPVariant &value)
1222 /* is plugin still running */
1223 if( isPluginRunning() )
1225 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1226 libvlc_exception_t ex;
1227 libvlc_exception_init(&ex);
1229 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1230 RETURN_ON_EXCEPTION(this,ex);
1234 case ID_subtitle_track:
1236 if( isNumberValue(value) )
1238 /* set the new subtitle track to show */
1239 libvlc_video_set_spu(p_md, numberValue(value), &ex);
1240 RETURN_ON_EXCEPTION(this,ex);
1242 return INVOKERESULT_NO_ERROR;
1244 return INVOKERESULT_INVALID_VALUE;
1248 return INVOKERESULT_GENERIC_ERROR;
1251 const NPUTF8 * const LibvlcSubtitleNPObject::methodNames[] =
1255 COUNTNAMES(LibvlcSubtitleNPObject,methodCount,methodNames);
1257 enum LibvlcSubtitleNPObjectMethodIds
1259 ID_subtitle_description
1262 RuntimeNPObject::InvokeResult
1263 LibvlcSubtitleNPObject::invoke(int index, const NPVariant *args,
1264 uint32_t argCount, NPVariant &result)
1266 /* is plugin still running */
1267 if( isPluginRunning() )
1269 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1270 libvlc_exception_t ex;
1271 libvlc_exception_init(&ex);
1273 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1274 RETURN_ON_EXCEPTION(this,ex);
1278 case ID_subtitle_description:
1283 int i_spuID, i_limit, i;
1284 libvlc_track_description_t *p_spuDesc;
1286 /* get subtitles description */
1287 p_spuDesc = libvlc_video_get_spu_description(p_md, &ex);
1288 RETURN_ON_EXCEPTION(this,ex);
1290 return INVOKERESULT_GENERIC_ERROR;
1292 /* get the number of subtitle available */
1293 i_limit = libvlc_video_get_spu_count(p_md, &ex);
1294 RETURN_ON_EXCEPTION(this,ex);
1296 /* check if a number is given by the user
1297 * and get the subtitle number */
1298 if( isNumberValue(args[0]) )
1299 i_spuID = numberValue(args[0]);
1301 return INVOKERESULT_INVALID_VALUE;
1303 /* if bad number is given return invalid value */
1304 if ( ( i_spuID > ( i_limit -1 ) ) || ( i_spuID < 0 ) )
1305 return INVOKERESULT_INVALID_VALUE;
1307 /* get the good spuDesc */
1308 for( i = 0 ; i < i_spuID ; i++ )
1310 p_spuDesc = p_spuDesc->p_next;
1312 psz_name = p_spuDesc->psz_name;
1314 /* return the name of the track chosen */
1315 return invokeResultString(psz_name, result);
1317 return INVOKERESULT_NO_SUCH_METHOD;
1320 return INVOKERESULT_NO_SUCH_METHOD;
1323 return INVOKERESULT_GENERIC_ERROR;
1327 ** implementation of libvlc video object
1330 LibvlcVideoNPObject::~LibvlcVideoNPObject()
1334 if( marqueeObj ) NPN_ReleaseObject(marqueeObj);
1335 if( logoObj ) NPN_ReleaseObject(logoObj);
1336 if( deintObj ) NPN_ReleaseObject(deintObj);
1340 const NPUTF8 * const LibvlcVideoNPObject::propertyNames[] =
1354 enum LibvlcVideoNPObjectPropertyIds
1356 ID_video_fullscreen,
1359 ID_video_aspectratio,
1365 ID_video_deinterlace,
1367 COUNTNAMES(LibvlcVideoNPObject,propertyCount,propertyNames);
1369 RuntimeNPObject::InvokeResult
1370 LibvlcVideoNPObject::getProperty(int index, NPVariant &result)
1372 /* is plugin still running */
1373 if( isPluginRunning() )
1375 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1376 libvlc_exception_t ex;
1377 libvlc_exception_init(&ex);
1379 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1380 RETURN_ON_EXCEPTION(this,ex);
1384 case ID_video_fullscreen:
1386 int val = p_plugin->get_fullscreen(&ex);
1387 RETURN_ON_EXCEPTION(this,ex);
1388 BOOLEAN_TO_NPVARIANT(val, result);
1389 return INVOKERESULT_NO_ERROR;
1391 case ID_video_height:
1393 int val = libvlc_video_get_height(p_md, &ex);
1394 RETURN_ON_EXCEPTION(this,ex);
1395 INT32_TO_NPVARIANT(val, result);
1396 return INVOKERESULT_NO_ERROR;
1398 case ID_video_width:
1400 int val = libvlc_video_get_width(p_md, &ex);
1401 RETURN_ON_EXCEPTION(this,ex);
1402 INT32_TO_NPVARIANT(val, result);
1403 return INVOKERESULT_NO_ERROR;
1405 case ID_video_aspectratio:
1407 NPUTF8 *psz_aspect = libvlc_video_get_aspect_ratio(p_md, &ex);
1408 RETURN_ON_EXCEPTION(this,ex);
1410 return INVOKERESULT_GENERIC_ERROR;
1412 STRINGZ_TO_NPVARIANT(psz_aspect, result);
1413 return INVOKERESULT_NO_ERROR;
1415 case ID_video_subtitle:
1417 int i_spu = libvlc_video_get_spu(p_md, &ex);
1418 RETURN_ON_EXCEPTION(this,ex);
1419 INT32_TO_NPVARIANT(i_spu, result);
1420 return INVOKERESULT_NO_ERROR;
1424 NPUTF8 *psz_geometry = libvlc_video_get_crop_geometry(p_md, &ex);
1425 RETURN_ON_EXCEPTION(this,ex);
1427 return INVOKERESULT_GENERIC_ERROR;
1429 STRINGZ_TO_NPVARIANT(psz_geometry, result);
1430 return INVOKERESULT_NO_ERROR;
1432 case ID_video_teletext:
1434 /* int i_page = libvlc_video_get_teletext(p_md, &ex);
1435 RETURN_ON_EXCEPTION(this,ex);
1436 INT32_TO_NPVARIANT(i_page, result);
1437 return INVOKERESULT_NO_ERROR;
1439 return INVOKERESULT_NO_SUCH_METHOD;
1441 case ID_video_marquee:
1443 InstantObj<LibvlcMarqueeNPObject>( marqueeObj );
1444 OBJECT_TO_NPVARIANT(NPN_RetainObject(marqueeObj), result);
1445 return INVOKERESULT_NO_ERROR;
1449 InstantObj<LibvlcLogoNPObject>( logoObj );
1450 OBJECT_TO_NPVARIANT(NPN_RetainObject(logoObj), result);
1451 return INVOKERESULT_NO_ERROR;
1453 case ID_video_deinterlace:
1455 InstantObj<LibvlcDeinterlaceNPObject>( deintObj );
1456 OBJECT_TO_NPVARIANT(NPN_RetainObject(deintObj), result);
1457 return INVOKERESULT_NO_ERROR;
1461 return INVOKERESULT_GENERIC_ERROR;
1464 RuntimeNPObject::InvokeResult
1465 LibvlcVideoNPObject::setProperty(int index, const NPVariant &value)
1467 /* is plugin still running */
1468 if( isPluginRunning() )
1470 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1471 libvlc_exception_t ex;
1472 libvlc_exception_init(&ex);
1474 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1475 RETURN_ON_EXCEPTION(this,ex);
1479 case ID_video_fullscreen:
1481 if( ! NPVARIANT_IS_BOOLEAN(value) )
1483 return INVOKERESULT_INVALID_VALUE;
1486 int val = NPVARIANT_TO_BOOLEAN(value);
1487 p_plugin->set_fullscreen(val, &ex);
1488 RETURN_ON_EXCEPTION(this,ex);
1489 return INVOKERESULT_NO_ERROR;
1491 case ID_video_aspectratio:
1493 char *psz_aspect = NULL;
1495 if( ! NPVARIANT_IS_STRING(value) )
1497 return INVOKERESULT_INVALID_VALUE;
1500 psz_aspect = stringValue(NPVARIANT_TO_STRING(value));
1503 return INVOKERESULT_GENERIC_ERROR;
1506 libvlc_video_set_aspect_ratio(p_md, psz_aspect, &ex);
1508 RETURN_ON_EXCEPTION(this,ex);
1510 return INVOKERESULT_NO_ERROR;
1512 case ID_video_subtitle:
1514 if( isNumberValue(value) )
1516 libvlc_video_set_spu(p_md, numberValue(value), &ex);
1517 RETURN_ON_EXCEPTION(this,ex);
1519 return INVOKERESULT_NO_ERROR;
1521 return INVOKERESULT_INVALID_VALUE;
1525 char *psz_geometry = NULL;
1527 if( ! NPVARIANT_IS_STRING(value) )
1529 return INVOKERESULT_INVALID_VALUE;
1532 psz_geometry = stringValue(NPVARIANT_TO_STRING(value));
1535 return INVOKERESULT_GENERIC_ERROR;
1538 libvlc_video_set_crop_geometry(p_md, psz_geometry, &ex);
1540 RETURN_ON_EXCEPTION(this,ex);
1542 return INVOKERESULT_NO_ERROR;
1544 case ID_video_teletext:
1546 if( isNumberValue(value) )
1549 libvlc_video_set_teletext(p_md, numberValue(value), &ex);
1550 RETURN_ON_EXCEPTION(this,ex);
1552 return INVOKERESULT_NO_ERROR;
1554 return INVOKERESULT_NO_SUCH_METHOD;
1556 return INVOKERESULT_INVALID_VALUE;
1560 return INVOKERESULT_GENERIC_ERROR;
1563 const NPUTF8 * const LibvlcVideoNPObject::methodNames[] =
1568 COUNTNAMES(LibvlcVideoNPObject,methodCount,methodNames);
1570 enum LibvlcVideoNPObjectMethodIds
1572 ID_video_togglefullscreen,
1573 ID_video_toggleteletext,
1576 RuntimeNPObject::InvokeResult
1577 LibvlcVideoNPObject::invoke(int index, const NPVariant *args,
1578 uint32_t argCount, NPVariant &result)
1580 /* is plugin still running */
1581 if( isPluginRunning() )
1583 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1584 libvlc_exception_t ex;
1585 libvlc_exception_init(&ex);
1587 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1588 RETURN_ON_EXCEPTION(this,ex);
1592 case ID_video_togglefullscreen:
1596 p_plugin->toggle_fullscreen(&ex);
1597 RETURN_ON_EXCEPTION(this,ex);
1598 VOID_TO_NPVARIANT(result);
1599 return INVOKERESULT_NO_ERROR;
1601 return INVOKERESULT_NO_SUCH_METHOD;
1603 case ID_video_toggleteletext:
1607 libvlc_toggle_teletext(p_md, &ex);
1608 RETURN_ON_EXCEPTION(this,ex);
1609 VOID_TO_NPVARIANT(result);
1610 return INVOKERESULT_NO_ERROR;
1612 return INVOKERESULT_NO_SUCH_METHOD;
1615 return INVOKERESULT_NO_SUCH_METHOD;
1618 return INVOKERESULT_GENERIC_ERROR;
1622 ** implementation of libvlc marquee object
1625 const NPUTF8 * const LibvlcMarqueeNPObject::propertyNames[] =
1638 enum LibvlcMarqueeNPObjectPropertyIds
1642 ID_marquee_position,
1651 COUNTNAMES(LibvlcMarqueeNPObject,propertyCount,propertyNames);
1653 static const unsigned char marquee_idx[] = {
1654 libvlc_marquee_Color,
1655 libvlc_marquee_Opacity,
1656 libvlc_marquee_Position,
1657 libvlc_marquee_Refresh,
1658 libvlc_marquee_Size,
1660 libvlc_marquee_Timeout,
1665 RuntimeNPObject::InvokeResult
1666 LibvlcMarqueeNPObject::getProperty(int index, NPVariant &result)
1670 if( !isPluginRunning() )
1671 return INVOKERESULT_GENERIC_ERROR;
1673 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1674 libvlc_exception_t ex;
1675 libvlc_exception_init(&ex);
1677 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1678 RETURN_ON_EXCEPTION(this,ex);
1682 case ID_marquee_color:
1683 case ID_marquee_opacity:
1684 case ID_marquee_refresh:
1685 case ID_marquee_timeout:
1686 case ID_marquee_size:
1690 libvlc_video_get_marquee_int(p_md, marquee_idx[index], &ex),
1692 RETURN_ON_EXCEPTION(this,ex);
1693 return INVOKERESULT_NO_ERROR;
1695 case ID_marquee_position:
1696 STRINGZ_TO_NPVARIANT( position_bynumber(
1697 libvlc_video_get_marquee_int(p_md, libvlc_marquee_Position, &ex) ),
1700 RETURN_ON_EXCEPTION(this,ex);
1703 case ID_marquee_text:
1704 psz = libvlc_video_get_marquee_string(p_md, libvlc_marquee_Text, &ex);
1707 STRINGZ_TO_NPVARIANT(psz, result);
1708 return INVOKERESULT_NO_ERROR;
1712 return INVOKERESULT_GENERIC_ERROR;
1715 RuntimeNPObject::InvokeResult
1716 LibvlcMarqueeNPObject::setProperty(int index, const NPVariant &value)
1720 if( !isPluginRunning() )
1721 return INVOKERESULT_GENERIC_ERROR;
1723 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1724 libvlc_exception_t ex;
1725 libvlc_exception_init(&ex);
1726 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1727 RETURN_ON_EXCEPTION(this,ex);
1731 case ID_marquee_color:
1732 case ID_marquee_opacity:
1733 case ID_marquee_refresh:
1734 case ID_marquee_timeout:
1737 if( NPVARIANT_IS_INT32( value ) )
1739 libvlc_video_set_marquee_int(p_md, marquee_idx[index],
1740 NPVARIANT_TO_INT32( value ), &ex);
1741 RETURN_ON_EXCEPTION(this,ex);
1742 return INVOKERESULT_NO_ERROR;
1746 case ID_marquee_position:
1747 if( !NPVARIANT_IS_STRING(value) ||
1748 !position_byname( NPVARIANT_TO_STRING(value).utf8characters, i ) )
1749 return INVOKERESULT_INVALID_VALUE;
1751 libvlc_video_set_marquee_int(p_md, libvlc_marquee_Position, i, &ex);
1752 RETURN_ON_EXCEPTION(this,ex);
1753 return INVOKERESULT_NO_ERROR;
1755 case ID_marquee_text:
1756 if( NPVARIANT_IS_STRING( value ) )
1758 char *psz_text = stringValue( NPVARIANT_TO_STRING( value ) );
1759 libvlc_video_set_marquee_string(p_md, libvlc_marquee_Text,
1762 RETURN_ON_EXCEPTION(this,ex);
1763 return INVOKERESULT_NO_ERROR;
1767 return INVOKERESULT_NO_SUCH_METHOD;
1770 const NPUTF8 * const LibvlcMarqueeNPObject::methodNames[] =
1775 COUNTNAMES(LibvlcMarqueeNPObject,methodCount,methodNames);
1777 enum LibvlcMarqueeNPObjectMethodIds
1783 RuntimeNPObject::InvokeResult
1784 LibvlcMarqueeNPObject::invoke(int index, const NPVariant *args,
1785 uint32_t argCount, NPVariant &result)
1787 if( !isPluginRunning() )
1788 return INVOKERESULT_GENERIC_ERROR;
1790 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1791 libvlc_exception_t ex;
1792 libvlc_exception_init(&ex);
1794 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1795 RETURN_ON_EXCEPTION(this,ex);
1799 case ID_marquee_enable:
1800 case ID_marquee_disable:
1801 libvlc_video_set_marquee_int(p_md, libvlc_marquee_Enable,
1802 index!=ID_marquee_disable, &ex);
1803 RETURN_ON_EXCEPTION(this,ex);
1804 VOID_TO_NPVARIANT(result);
1805 return INVOKERESULT_NO_ERROR;
1807 return INVOKERESULT_NO_SUCH_METHOD;
1810 const NPUTF8 * const LibvlcLogoNPObject::propertyNames[] = {
1818 enum LibvlcLogoNPObjectPropertyIds {
1826 COUNTNAMES(LibvlcLogoNPObject,propertyCount,propertyNames);
1827 static const unsigned char logo_idx[] = {
1830 libvlc_logo_opacity,
1836 RuntimeNPObject::InvokeResult
1837 LibvlcLogoNPObject::getProperty(int index, NPVariant &result)
1839 if( !isPluginRunning() )
1840 return INVOKERESULT_GENERIC_ERROR;
1842 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1843 libvlc_exception_t ex;
1844 libvlc_exception_init(&ex);
1845 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1846 RETURN_ON_EXCEPTION(this,ex);
1851 case ID_logo_repeat:
1852 case ID_logo_opacity:
1857 libvlc_video_get_logo_int(p_md, logo_idx[index], &ex), result);
1859 RETURN_ON_EXCEPTION(this,ex);
1862 case ID_logo_position:
1863 STRINGZ_TO_NPVARIANT( position_bynumber(
1864 libvlc_video_get_logo_int(p_md, libvlc_logo_position, &ex) ),
1867 RETURN_ON_EXCEPTION(this,ex);
1870 return INVOKERESULT_GENERIC_ERROR;
1872 return INVOKERESULT_NO_ERROR;
1875 RuntimeNPObject::InvokeResult
1876 LibvlcLogoNPObject::setProperty(int index, const NPVariant &value)
1880 if( !isPluginRunning() )
1881 return INVOKERESULT_GENERIC_ERROR;
1883 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1884 libvlc_exception_t ex;
1885 libvlc_exception_init(&ex);
1887 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1888 RETURN_ON_EXCEPTION(this,ex);
1893 case ID_logo_repeat:
1894 case ID_logo_opacity:
1897 if( !NPVARIANT_IS_INT32(value) )
1898 return INVOKERESULT_INVALID_VALUE;
1900 libvlc_video_set_logo_int(p_md, logo_idx[index],
1901 NPVARIANT_TO_INT32( value ), &ex);
1903 RETURN_ON_EXCEPTION(this,ex);
1906 case ID_logo_position:
1907 if( !NPVARIANT_IS_STRING(value) ||
1908 !position_byname( NPVARIANT_TO_STRING(value).utf8characters, i ) )
1909 return INVOKERESULT_INVALID_VALUE;
1911 libvlc_video_set_logo_int(p_md, libvlc_logo_position, i, &ex);
1913 RETURN_ON_EXCEPTION(this,ex);
1916 return INVOKERESULT_GENERIC_ERROR;
1918 return INVOKERESULT_NO_ERROR;
1922 const NPUTF8 * const LibvlcLogoNPObject::methodNames[] = {
1927 enum LibvlcLogoNPObjectMethodIds {
1932 COUNTNAMES(LibvlcLogoNPObject,methodCount,methodNames);
1934 RuntimeNPObject::InvokeResult
1935 LibvlcLogoNPObject::invoke(int index, const NPVariant *args,
1936 uint32_t argCount, NPVariant &result)
1941 if( !isPluginRunning() )
1942 return INVOKERESULT_GENERIC_ERROR;
1944 libvlc_exception_t ex;
1945 libvlc_exception_init(&ex);
1946 libvlc_media_player_t *p_md = getPrivate<VlcPlugin>()->getMD(&ex);
1947 RETURN_ON_EXCEPTION(this,ex);
1951 case ID_logo_enable:
1952 case ID_logo_disable:
1954 return INVOKERESULT_GENERIC_ERROR;
1956 libvlc_video_set_logo_int(p_md, libvlc_logo_enable,
1957 index != ID_logo_disable, &ex);
1958 RETURN_ON_EXCEPTION(this,ex);
1959 VOID_TO_NPVARIANT(result);
1964 return INVOKERESULT_GENERIC_ERROR;
1966 for( len=0,i=0;i<argCount;++i )
1968 if( !NPVARIANT_IS_STRING(args[i]) )
1969 return INVOKERESULT_INVALID_VALUE;
1970 len+=NPVARIANT_TO_STRING(args[i]).utf8length+1;
1973 buf = (char *)malloc( len+1 );
1975 return INVOKERESULT_OUT_OF_MEMORY;
1977 for( h=buf,i=0;i<argCount;++i )
1980 len=NPVARIANT_TO_STRING(args[i]).utf8length;
1981 memcpy(h,NPVARIANT_TO_STRING(args[i]).utf8characters,len);
1986 libvlc_video_set_logo_string(p_md, libvlc_logo_file, buf, &ex);
1988 RETURN_ON_EXCEPTION(this,ex);
1989 VOID_TO_NPVARIANT(result);
1992 return INVOKERESULT_NO_SUCH_METHOD;
1994 return INVOKERESULT_NO_ERROR;
1998 const NPUTF8 * const LibvlcDeinterlaceNPObject::propertyNames[] = {
2000 enum LibvlcDeinterlaceNPObjectPropertyIds {
2002 COUNTNAMES(LibvlcDeinterlaceNPObject,propertyCount,propertyNames);
2004 RuntimeNPObject::InvokeResult
2005 LibvlcDeinterlaceNPObject::getProperty(int index, NPVariant &result)
2007 return INVOKERESULT_GENERIC_ERROR;
2010 RuntimeNPObject::InvokeResult
2011 LibvlcDeinterlaceNPObject::setProperty(int index, const NPVariant &value)
2013 return INVOKERESULT_GENERIC_ERROR;
2017 const NPUTF8 * const LibvlcDeinterlaceNPObject::methodNames[] = {
2021 enum LibvlcDeinterlaceNPObjectMethodIds {
2025 COUNTNAMES(LibvlcDeinterlaceNPObject,methodCount,methodNames);
2027 RuntimeNPObject::InvokeResult
2028 LibvlcDeinterlaceNPObject::invoke(int index, const NPVariant *args,
2029 uint32_t argCount, NPVariant &result)
2033 if( !isPluginRunning() )
2034 return INVOKERESULT_GENERIC_ERROR;
2036 libvlc_exception_t ex;
2037 libvlc_exception_init(&ex);
2038 libvlc_media_player_t *p_md = getPrivate<VlcPlugin>()->getMD(&ex);
2039 RETURN_ON_EXCEPTION(this,ex);
2043 case ID_deint_disable:
2044 libvlc_video_set_deinterlace(p_md, 0, "", &ex);
2045 RETURN_ON_EXCEPTION(this,ex);
2048 case ID_deint_enable:
2049 if( argCount != 1 || !NPVARIANT_IS_STRING( args[0] ) )
2050 return INVOKERESULT_INVALID_VALUE;
2052 psz = stringValue( NPVARIANT_TO_STRING( args[0] ) );
2053 libvlc_video_set_deinterlace(p_md, 1, psz, &ex);
2055 RETURN_ON_EXCEPTION(this,ex);
2059 return INVOKERESULT_NO_SUCH_METHOD;
2061 return INVOKERESULT_NO_ERROR;
2067 ** implementation of libvlc event object
2070 const NPUTF8 * const LibvlcEventNPObject::propertyNames[] =
2074 enum LibvlcEventNPObjectPropertyIds
2077 COUNTNAMES(LibvlcEventNPObject,propertyCount,propertyNames);
2079 const NPUTF8 * const LibvlcEventNPObject::methodNames[] =
2084 COUNTNAMES(LibvlcEventNPObject,methodCount,methodNames);
2086 enum LibvlcEventNPObjectMethodIds
2088 ID_event_addListener,
2089 ID_event_removeListeners,
2092 bool LibvlcEventNPObject::parseArgs(const NPVariant *args, uint32_t argCount,
2093 eventtypes_bitmap_t &eventToGet)
2098 for (int argIndex = 2; argIndex < argCount; argIndex++)
2100 if (NPVARIANT_IS_STRING(args[argIndex]))
2102 if (!eventToGet.add_event(NPVARIANT_TO_STRING(args[argIndex]).utf8characters))
2105 else if (NPVARIANT_IS_OBJECT(args[argIndex]))
2107 if (!parseEventArray(NPVARIANT_TO_OBJECT(args[argIndex]), eventToGet, _instance))
2116 RuntimeNPObject::InvokeResult
2117 LibvlcEventNPObject::invoke(int index, const NPVariant *args,
2118 uint32_t argCount, NPVariant &result)
2120 /* is plugin still running */
2121 if( isPluginRunning() )
2123 libvlc_exception_t ex;
2124 libvlc_exception_init(&ex);
2128 case ID_event_addListener:
2131 // Checks if the first argument is a NPObject
2132 if (!NPVARIANT_IS_OBJECT(args[0]))
2133 return INVOKERESULT_NO_SUCH_METHOD;
2135 // Checks if the browser has the NPAPI version 0.19 at least.
2136 if (!VlcPlugin::canUseEventListener())
2138 NPN_SetException(this, strdup(ERROR_API_VERSION));
2139 return INVOKERESULT_GENERIC_ERROR;
2142 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
2144 // Gets the binary field corresponding to the events the
2145 // listener must listen to if specified.
2146 // Else, listen to all events.
2147 eventtypes_bitmap_t eventToGet;
2148 eventToGet.set_all_events();
2150 if (!parseArgs(args, argCount, eventToGet))
2152 NPN_SetException(this, strdup(ERROR_EVENT_NOT_FOUND));
2153 return INVOKERESULT_GENERIC_ERROR;
2156 NPObject *listener = NPVARIANT_TO_OBJECT(args[0]);
2157 NPN_RetainObject(listener);
2159 EventListener *eventListener = new EventListener();
2160 eventListener->listener = listener;
2161 eventListener->id = copyNPVariant(args[1]);
2162 eventListener->eventMap = eventToGet;
2164 p_plugin->eventToCatch.add_event(eventToGet);
2166 p_plugin->eventListeners.push_back(eventListener);
2168 return INVOKERESULT_NO_ERROR;
2170 return INVOKERESULT_NO_SUCH_METHOD;
2171 case ID_event_removeListeners:
2174 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
2175 p_plugin->eventListeners.clear();
2176 p_plugin->eventToCatch.clear();
2177 return INVOKERESULT_NO_ERROR;
2179 return INVOKERESULT_NO_SUCH_METHOD;
2184 return INVOKERESULT_GENERIC_ERROR;