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);
80 ** implementation of libvlc root object
83 LibvlcRootNPObject::~LibvlcRootNPObject()
86 ** When the plugin is destroyed, firefox takes it upon itself to
87 ** destroy all 'live' script objects and ignores refcounting.
88 ** Therefore we cannot safely assume that refcounting will control
89 ** lifespan of objects. Hence they are only lazily created on
90 ** request, so that firefox can take ownership, and are not released
91 ** when the plugin is destroyed.
95 if( audioObj ) NPN_ReleaseObject(audioObj);
96 if( inputObj ) NPN_ReleaseObject(inputObj);
97 if( playlistObj ) NPN_ReleaseObject(playlistObj);
98 if( subtitleObj ) NPN_ReleaseObject(subtitleObj);
99 if( videoObj ) NPN_ReleaseObject(videoObj);
103 const NPUTF8 * const LibvlcRootNPObject::propertyNames[] =
112 COUNTNAMES(LibvlcRootNPObject,propertyCount,propertyNames);
114 enum LibvlcRootNPObjectPropertyIds
124 RuntimeNPObject::InvokeResult
125 LibvlcRootNPObject::getProperty(int index, NPVariant &result)
127 /* is plugin still running */
128 if( isPluginRunning() )
133 InstantObj<LibvlcAudioNPObject>( audioObj );
134 OBJECT_TO_NPVARIANT(NPN_RetainObject(audioObj), result);
135 return INVOKERESULT_NO_ERROR;
137 InstantObj<LibvlcInputNPObject>( inputObj );
138 OBJECT_TO_NPVARIANT(NPN_RetainObject(inputObj), result);
139 return INVOKERESULT_NO_ERROR;
140 case ID_root_playlist:
141 InstantObj<LibvlcPlaylistNPObject>( playlistObj );
142 OBJECT_TO_NPVARIANT(NPN_RetainObject(playlistObj), result);
143 return INVOKERESULT_NO_ERROR;
144 case ID_root_subtitle:
145 InstantObj<LibvlcSubtitleNPObject>( subtitleObj );
146 OBJECT_TO_NPVARIANT(NPN_RetainObject(subtitleObj), result);
147 return INVOKERESULT_NO_ERROR;
149 InstantObj<LibvlcVideoNPObject>( videoObj );
150 OBJECT_TO_NPVARIANT(NPN_RetainObject(videoObj), result);
151 return INVOKERESULT_NO_ERROR;
152 case ID_root_VersionInfo:
153 return invokeResultString(libvlc_get_version(),result);
158 return INVOKERESULT_GENERIC_ERROR;
161 const NPUTF8 * const LibvlcRootNPObject::methodNames[] =
165 "removeEventListener",
167 COUNTNAMES(LibvlcRootNPObject,methodCount,methodNames);
169 enum LibvlcRootNPObjectMethodIds
172 ID_root_addeventlistener,
173 ID_root_removeeventlistener,
176 RuntimeNPObject::InvokeResult LibvlcRootNPObject::invoke(int index,
177 const NPVariant *args, uint32_t argCount, NPVariant &result)
179 /* is plugin still running */
180 if( !isPluginRunning() )
181 return INVOKERESULT_GENERIC_ERROR;
183 libvlc_exception_t ex;
184 libvlc_exception_init(&ex);
188 case ID_root_versionInfo:
190 return INVOKERESULT_NO_SUCH_METHOD;
191 return invokeResultString(libvlc_get_version(),result);
193 case ID_root_addeventlistener:
194 case ID_root_removeeventlistener:
195 if( (3 != argCount) ||
196 !NPVARIANT_IS_STRING(args[0]) ||
197 !NPVARIANT_IS_OBJECT(args[1]) ||
198 !NPVARIANT_IS_BOOLEAN(args[2]) )
201 if( !VlcPlugin::canUseEventListener() )
203 NPN_SetException(this, ERROR_API_VERSION);
204 return INVOKERESULT_GENERIC_ERROR;
207 NPObject *listener = NPVARIANT_TO_OBJECT(args[1]);
208 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
211 if(ID_root_removeeventlistener!=index)
212 b = p_plugin->events.insert(NPVARIANT_TO_STRING(args[0]),
213 listener, NPVARIANT_TO_BOOLEAN(args[2]));
215 b = p_plugin->events.remove(NPVARIANT_TO_STRING(args[0]),
216 listener, NPVARIANT_TO_BOOLEAN(args[2]));
218 VOID_TO_NPVARIANT(result);
220 return b ? INVOKERESULT_NO_ERROR : INVOKERESULT_GENERIC_ERROR;
222 return INVOKERESULT_NO_SUCH_METHOD;
226 ** implementation of libvlc audio object
229 const NPUTF8 * const LibvlcAudioNPObject::propertyNames[] =
237 COUNTNAMES(LibvlcAudioNPObject,propertyCount,propertyNames);
239 enum LibvlcAudioNPObjectPropertyIds
248 RuntimeNPObject::InvokeResult
249 LibvlcAudioNPObject::getProperty(int index, NPVariant &result)
251 /* is plugin still running */
252 if( isPluginRunning() )
254 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
255 libvlc_exception_t ex;
256 libvlc_exception_init(&ex);
258 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
259 RETURN_ON_EXCEPTION(this,ex);
265 bool muted = libvlc_audio_get_mute(p_md);
266 BOOLEAN_TO_NPVARIANT(muted, result);
267 return INVOKERESULT_NO_ERROR;
269 case ID_audio_volume:
271 int volume = libvlc_audio_get_volume(p_md);
272 INT32_TO_NPVARIANT(volume, result);
273 return INVOKERESULT_NO_ERROR;
277 int track = libvlc_audio_get_track(p_md);
278 INT32_TO_NPVARIANT(track, result);
279 return INVOKERESULT_NO_ERROR;
283 // get the number of audio track available
284 int i_track = libvlc_audio_get_track_count(p_md);
286 INT32_TO_NPVARIANT(i_track, result);
287 return INVOKERESULT_NO_ERROR;
289 case ID_audio_channel:
291 int channel = libvlc_audio_get_channel(p_md);
292 INT32_TO_NPVARIANT(channel, result);
293 return INVOKERESULT_NO_ERROR;
299 return INVOKERESULT_GENERIC_ERROR;
302 RuntimeNPObject::InvokeResult
303 LibvlcAudioNPObject::setProperty(int index, const NPVariant &value)
305 /* is plugin still running */
306 if( isPluginRunning() )
308 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
309 libvlc_exception_t ex;
310 libvlc_exception_init(&ex);
312 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
313 RETURN_ON_EXCEPTION(this,ex);
318 if( NPVARIANT_IS_BOOLEAN(value) )
320 libvlc_audio_set_mute(p_md,
321 NPVARIANT_TO_BOOLEAN(value));
322 return INVOKERESULT_NO_ERROR;
324 return INVOKERESULT_INVALID_VALUE;
325 case ID_audio_volume:
326 if( isNumberValue(value) )
328 libvlc_audio_set_volume(p_md, numberValue(value));
329 return INVOKERESULT_NO_ERROR;
331 return INVOKERESULT_INVALID_VALUE;
333 if( isNumberValue(value) )
335 libvlc_audio_set_track(p_md, numberValue(value));
336 return INVOKERESULT_NO_ERROR;
338 return INVOKERESULT_INVALID_VALUE;
339 case ID_audio_channel:
340 if( isNumberValue(value) )
342 libvlc_audio_set_channel(p_md, numberValue(value));
343 return INVOKERESULT_NO_ERROR;
345 return INVOKERESULT_INVALID_VALUE;
350 return INVOKERESULT_GENERIC_ERROR;
353 const NPUTF8 * const LibvlcAudioNPObject::methodNames[] =
358 COUNTNAMES(LibvlcAudioNPObject,methodCount,methodNames);
360 enum LibvlcAudioNPObjectMethodIds
363 ID_audio_description,
366 RuntimeNPObject::InvokeResult
367 LibvlcAudioNPObject::invoke(int index, const NPVariant *args,
368 uint32_t argCount, NPVariant &result)
370 /* is plugin still running */
371 if( isPluginRunning() )
373 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
374 libvlc_exception_t ex;
375 libvlc_exception_init(&ex);
377 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
378 RETURN_ON_EXCEPTION(this,ex);
382 case ID_audio_togglemute:
385 libvlc_audio_toggle_mute(p_md);
386 VOID_TO_NPVARIANT(result);
387 return INVOKERESULT_NO_ERROR;
389 return INVOKERESULT_NO_SUCH_METHOD;
390 case ID_audio_description:
395 int i_trackID, i_limit, i;
396 libvlc_track_description_t *p_trackDesc;
398 /* get tracks description */
399 p_trackDesc = libvlc_audio_get_track_description(p_md);
401 return INVOKERESULT_GENERIC_ERROR;
403 /* get the number of track available */
404 i_limit = libvlc_audio_get_track_count(p_md);
406 /* check if a number is given by the user
407 * and get the track number */
408 if( isNumberValue(args[0]) )
409 i_trackID = numberValue(args[0]);
411 return INVOKERESULT_INVALID_VALUE;
413 /* if bad number is given return invalid value */
414 if ( ( i_trackID > ( i_limit - 1 ) ) || ( i_trackID < 0 ) )
415 return INVOKERESULT_INVALID_VALUE;
417 /* get the good trackDesc */
418 for( i = 0 ; i < i_trackID ; i++ )
420 p_trackDesc = p_trackDesc->p_next;
422 psz_name = p_trackDesc->psz_name;
424 /* display the name of the track chosen */
425 return invokeResultString( psz_name, result );
427 return INVOKERESULT_NO_SUCH_METHOD;
433 return INVOKERESULT_GENERIC_ERROR;
437 ** implementation of libvlc input object
440 const NPUTF8 * const LibvlcInputNPObject::propertyNames[] =
450 COUNTNAMES(LibvlcInputNPObject,propertyCount,propertyNames);
452 enum LibvlcInputNPObjectPropertyIds
463 RuntimeNPObject::InvokeResult
464 LibvlcInputNPObject::getProperty(int index, NPVariant &result)
466 /* is plugin still running */
467 if( isPluginRunning() )
469 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
470 libvlc_exception_t ex;
471 libvlc_exception_init(&ex);
473 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
474 if( libvlc_exception_raised(&ex) )
476 if( index != ID_input_state )
478 NPN_SetException(this, libvlc_errmsg());
479 libvlc_exception_clear(&ex);
480 return INVOKERESULT_GENERIC_ERROR;
484 /* for input state, return CLOSED rather than an exception */
485 INT32_TO_NPVARIANT(0, result);
486 libvlc_exception_clear(&ex);
487 return INVOKERESULT_NO_ERROR;
493 case ID_input_length:
495 double val = (double)libvlc_media_player_get_length(p_md);
496 DOUBLE_TO_NPVARIANT(val, result);
497 return INVOKERESULT_NO_ERROR;
499 case ID_input_position:
501 double val = libvlc_media_player_get_position(p_md);
502 DOUBLE_TO_NPVARIANT(val, result);
503 return INVOKERESULT_NO_ERROR;
507 double val = (double)libvlc_media_player_get_time(p_md);
508 DOUBLE_TO_NPVARIANT(val, result);
509 return INVOKERESULT_NO_ERROR;
513 int val = libvlc_media_player_get_state(p_md);
514 RETURN_ON_EXCEPTION(this,ex);
515 INT32_TO_NPVARIANT(val, result);
516 return INVOKERESULT_NO_ERROR;
520 float val = libvlc_media_player_get_rate(p_md);
521 DOUBLE_TO_NPVARIANT(val, result);
522 return INVOKERESULT_NO_ERROR;
526 double val = libvlc_media_player_get_fps(p_md);
527 DOUBLE_TO_NPVARIANT(val, result);
528 return INVOKERESULT_NO_ERROR;
530 case ID_input_hasvout:
532 bool val = p_plugin->player_has_vout();
533 BOOLEAN_TO_NPVARIANT(val, result);
534 return INVOKERESULT_NO_ERROR;
540 return INVOKERESULT_GENERIC_ERROR;
543 RuntimeNPObject::InvokeResult
544 LibvlcInputNPObject::setProperty(int index, const NPVariant &value)
546 /* is plugin still running */
547 if( isPluginRunning() )
549 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
550 libvlc_exception_t ex;
551 libvlc_exception_init(&ex);
553 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
554 RETURN_ON_EXCEPTION(this,ex);
558 case ID_input_position:
560 if( ! NPVARIANT_IS_DOUBLE(value) )
562 return INVOKERESULT_INVALID_VALUE;
565 float val = (float)NPVARIANT_TO_DOUBLE(value);
566 libvlc_media_player_set_position(p_md, val);
567 return INVOKERESULT_NO_ERROR;
572 if( NPVARIANT_IS_INT32(value) )
573 val = (int64_t)NPVARIANT_TO_INT32(value);
574 else if( NPVARIANT_IS_DOUBLE(value) )
575 val = (int64_t)NPVARIANT_TO_DOUBLE(value);
578 return INVOKERESULT_INVALID_VALUE;
581 libvlc_media_player_set_time(p_md, val);
582 return INVOKERESULT_NO_ERROR;
587 if( NPVARIANT_IS_INT32(value) )
588 val = (float)NPVARIANT_TO_INT32(value);
589 else if( NPVARIANT_IS_DOUBLE(value) )
590 val = (float)NPVARIANT_TO_DOUBLE(value);
593 return INVOKERESULT_INVALID_VALUE;
596 libvlc_media_player_set_rate(p_md, val);
597 return INVOKERESULT_NO_ERROR;
603 return INVOKERESULT_GENERIC_ERROR;
606 const NPUTF8 * const LibvlcInputNPObject::methodNames[] =
611 COUNTNAMES(LibvlcInputNPObject,methodCount,methodNames);
613 enum LibvlcInputNPObjectMethodIds
618 RuntimeNPObject::InvokeResult
619 LibvlcInputNPObject::invoke(int index, const NPVariant *args,
620 uint32_t argCount, NPVariant &result)
622 /* is plugin still running */
623 if( isPluginRunning() )
628 return INVOKERESULT_NO_SUCH_METHOD;
633 return INVOKERESULT_GENERIC_ERROR;
637 ** implementation of libvlc playlist items object
640 const NPUTF8 * const LibvlcPlaylistItemsNPObject::propertyNames[] =
644 COUNTNAMES(LibvlcPlaylistItemsNPObject,propertyCount,propertyNames);
646 enum LibvlcPlaylistItemsNPObjectPropertyIds
648 ID_playlistitems_count,
651 RuntimeNPObject::InvokeResult
652 LibvlcPlaylistItemsNPObject::getProperty(int index, NPVariant &result)
654 /* is plugin still running */
655 if( isPluginRunning() )
657 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
661 case ID_playlistitems_count:
663 int val = p_plugin->playlist_count();
664 INT32_TO_NPVARIANT(val, result);
665 return INVOKERESULT_NO_ERROR;
671 return INVOKERESULT_GENERIC_ERROR;
674 const NPUTF8 * const LibvlcPlaylistItemsNPObject::methodNames[] =
679 COUNTNAMES(LibvlcPlaylistItemsNPObject,methodCount,methodNames);
681 enum LibvlcPlaylistItemsNPObjectMethodIds
683 ID_playlistitems_clear,
684 ID_playlistitems_remove,
687 RuntimeNPObject::InvokeResult
688 LibvlcPlaylistItemsNPObject::invoke(int index, const NPVariant *args,
689 uint32_t argCount, NPVariant &result)
691 /* is plugin still running */
692 if( isPluginRunning() )
694 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
695 libvlc_exception_t ex;
696 libvlc_exception_init(&ex);
700 case ID_playlistitems_clear:
703 p_plugin->playlist_clear();
704 VOID_TO_NPVARIANT(result);
705 return INVOKERESULT_NO_ERROR;
707 return INVOKERESULT_NO_SUCH_METHOD;
708 case ID_playlistitems_remove:
709 if( (argCount == 1) && isNumberValue(args[0]) )
711 if( !p_plugin->playlist_delete_item(numberValue(args[0])) )
712 return INVOKERESULT_GENERIC_ERROR;
713 VOID_TO_NPVARIANT(result);
714 return INVOKERESULT_NO_ERROR;
716 return INVOKERESULT_NO_SUCH_METHOD;
721 return INVOKERESULT_GENERIC_ERROR;
725 ** implementation of libvlc playlist object
728 LibvlcPlaylistNPObject::~LibvlcPlaylistNPObject()
730 // Why the isValid()?
731 if( isValid() && playlistItemsObj )
732 NPN_ReleaseObject(playlistItemsObj);
735 const NPUTF8 * const LibvlcPlaylistNPObject::propertyNames[] =
737 "itemCount", /* deprecated */
741 COUNTNAMES(LibvlcPlaylistNPObject,propertyCount,propertyNames);
743 enum LibvlcPlaylistNPObjectPropertyIds
745 ID_playlist_itemcount,
746 ID_playlist_isplaying,
750 RuntimeNPObject::InvokeResult
751 LibvlcPlaylistNPObject::getProperty(int index, NPVariant &result)
753 /* is plugin still running */
754 if( isPluginRunning() )
756 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
760 case ID_playlist_itemcount: /* deprecated */
762 int val = p_plugin->playlist_count();
763 INT32_TO_NPVARIANT(val, result);
764 return INVOKERESULT_NO_ERROR;
766 case ID_playlist_isplaying:
768 int val = p_plugin->playlist_isplaying();
769 BOOLEAN_TO_NPVARIANT(val, result);
770 return INVOKERESULT_NO_ERROR;
772 case ID_playlist_items:
774 InstantObj<LibvlcPlaylistItemsNPObject>( playlistItemsObj );
775 OBJECT_TO_NPVARIANT(NPN_RetainObject(playlistItemsObj), result);
776 return INVOKERESULT_NO_ERROR;
782 return INVOKERESULT_GENERIC_ERROR;
785 const NPUTF8 * const LibvlcPlaylistNPObject::methodNames[] =
794 "clear", /* deprecated */
795 "removeItem", /* deprecated */
797 COUNTNAMES(LibvlcPlaylistNPObject,methodCount,methodNames);
799 enum LibvlcPlaylistNPObjectMethodIds
803 ID_playlist_playItem,
804 ID_playlist_togglepause,
809 ID_playlist_removeitem
812 RuntimeNPObject::InvokeResult
813 LibvlcPlaylistNPObject::invoke(int index, const NPVariant *args,
814 uint32_t argCount, NPVariant &result)
816 /* is plugin still running */
817 if( isPluginRunning() )
819 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
820 libvlc_exception_t ex;
821 libvlc_exception_init(&ex);
825 // XXX FIXME this needs squashing into something much smaller
826 case ID_playlist_add:
828 if( (argCount < 1) || (argCount > 3) )
829 return INVOKERESULT_NO_SUCH_METHOD;
830 if( !NPVARIANT_IS_STRING(args[0]) )
831 return INVOKERESULT_NO_SUCH_METHOD;
834 if( NPVARIANT_IS_NULL(args[0]) )
835 return INVOKERESULT_NO_SUCH_METHOD;
837 char *s = stringValue(NPVARIANT_TO_STRING(args[0]));
839 return INVOKERESULT_OUT_OF_MEMORY;
841 char *url = p_plugin->getAbsoluteURL(s);
845 // problem with combining url, use argument
850 // grab name if available
853 if( NPVARIANT_IS_NULL(args[1]) )
857 else if( NPVARIANT_IS_STRING(args[1]) )
859 name = stringValue(NPVARIANT_TO_STRING(args[1]));
864 return INVOKERESULT_INVALID_VALUE;
869 char** ppsz_options = NULL;
871 // grab options if available
874 if( NPVARIANT_IS_NULL(args[2]) )
878 else if( NPVARIANT_IS_STRING(args[2]) )
880 parseOptions(NPVARIANT_TO_STRING(args[2]),
881 &i_options, &ppsz_options);
884 else if( NPVARIANT_IS_OBJECT(args[2]) )
886 parseOptions(NPVARIANT_TO_OBJECT(args[2]),
887 &i_options, &ppsz_options);
893 return INVOKERESULT_INVALID_VALUE;
897 int item = p_plugin->playlist_add_extended_untrusted(url, name,
898 i_options, const_cast<const char **>(ppsz_options), &ex);
901 for( int i=0; i< i_options; ++i )
903 free(ppsz_options[i]);
907 RETURN_ON_EXCEPTION(this,ex);
908 INT32_TO_NPVARIANT(item, result);
909 return INVOKERESULT_NO_ERROR;
911 case ID_playlist_play:
914 p_plugin->playlist_play(&ex);
915 RETURN_ON_EXCEPTION(this,ex);
916 VOID_TO_NPVARIANT(result);
917 return INVOKERESULT_NO_ERROR;
919 return INVOKERESULT_NO_SUCH_METHOD;
920 case ID_playlist_playItem:
921 if( (argCount == 1) && isNumberValue(args[0]) )
923 p_plugin->playlist_play_item(numberValue(args[0]),&ex);
924 RETURN_ON_EXCEPTION(this,ex);
925 VOID_TO_NPVARIANT(result);
926 return INVOKERESULT_NO_ERROR;
928 return INVOKERESULT_NO_SUCH_METHOD;
929 case ID_playlist_togglepause:
932 p_plugin->playlist_pause();
933 VOID_TO_NPVARIANT(result);
934 return INVOKERESULT_NO_ERROR;
936 return INVOKERESULT_NO_SUCH_METHOD;
937 case ID_playlist_stop:
940 p_plugin->playlist_stop();
941 VOID_TO_NPVARIANT(result);
942 return INVOKERESULT_NO_ERROR;
944 return INVOKERESULT_NO_SUCH_METHOD;
945 case ID_playlist_next:
948 p_plugin->playlist_next(&ex);
949 RETURN_ON_EXCEPTION(this,ex);
950 VOID_TO_NPVARIANT(result);
951 return INVOKERESULT_NO_ERROR;
953 return INVOKERESULT_NO_SUCH_METHOD;
954 case ID_playlist_prev:
957 p_plugin->playlist_prev(&ex);
958 RETURN_ON_EXCEPTION(this,ex);
959 VOID_TO_NPVARIANT(result);
960 return INVOKERESULT_NO_ERROR;
962 return INVOKERESULT_NO_SUCH_METHOD;
963 case ID_playlist_clear: /* deprecated */
966 p_plugin->playlist_clear();
967 VOID_TO_NPVARIANT(result);
968 return INVOKERESULT_NO_ERROR;
970 return INVOKERESULT_NO_SUCH_METHOD;
971 case ID_playlist_removeitem: /* deprecated */
972 if( (argCount == 1) && isNumberValue(args[0]) )
974 if( !p_plugin->playlist_delete_item(numberValue(args[0])) )
975 return INVOKERESULT_GENERIC_ERROR;
976 VOID_TO_NPVARIANT(result);
977 return INVOKERESULT_NO_ERROR;
979 return INVOKERESULT_NO_SUCH_METHOD;
984 return INVOKERESULT_GENERIC_ERROR;
987 // XXX FIXME The new playlist_add creates a media instance and feeds it
988 // XXX FIXME these options one at a time, so this hunk of code does lots
989 // XXX FIXME of unnecessairy work. Break out something that can do one
990 // XXX FIXME option at a time and doesn't need to realloc().
991 // XXX FIXME Same for the other version of parseOptions.
993 void LibvlcPlaylistNPObject::parseOptions(const NPString &nps,
994 int *i_options, char*** ppsz_options)
998 char *s = stringValue(nps);
1003 char **options = (char **)malloc(capacity*sizeof(char *));
1008 char *end = val + nps.utf8length;
1011 // skip leading blanks
1013 && ((*val == ' ' ) || (*val == '\t')) )
1017 // skip till we get a blank character
1023 if( ('\'' == c) || ('"' == c) )
1025 // skip till end of string
1026 while( (val < end) && (*(val++) != c ) );
1032 if( nOptions == capacity )
1035 char **moreOptions = (char **)realloc(options, capacity*sizeof(char*));
1038 /* failed to allocate more memory */
1040 /* return what we got so far */
1041 *i_options = nOptions;
1042 *ppsz_options = options;
1045 options = moreOptions;
1048 options[nOptions++] = strdup(start);
1051 // must be end of string
1054 *i_options = nOptions;
1055 *ppsz_options = options;
1062 // XXX FIXME See comment at the other parseOptions variant.
1063 void LibvlcPlaylistNPObject::parseOptions(NPObject *obj, int *i_options,
1064 char*** ppsz_options)
1066 /* WARNING: Safari does not implement NPN_HasProperty/NPN_HasMethod */
1070 /* we are expecting to have a Javascript Array object */
1071 NPIdentifier propId = NPN_GetStringIdentifier("length");
1072 if( NPN_GetProperty(_instance, obj, propId, &value) )
1074 int count = numberValue(value);
1075 NPN_ReleaseVariantValue(&value);
1080 char **options = (char **)malloc(capacity*sizeof(char *));
1085 while( nOptions < count )
1087 propId = NPN_GetIntIdentifier(nOptions);
1088 if( ! NPN_GetProperty(_instance, obj, propId, &value) )
1089 /* return what we got so far */
1092 if( ! NPVARIANT_IS_STRING(value) )
1094 /* return what we got so far */
1095 NPN_ReleaseVariantValue(&value);
1099 if( nOptions == capacity )
1102 char **moreOptions = (char **)realloc(options, capacity*sizeof(char*));
1105 /* failed to allocate more memory */
1106 NPN_ReleaseVariantValue(&value);
1107 /* return what we got so far */
1108 *i_options = nOptions;
1109 *ppsz_options = options;
1112 options = moreOptions;
1115 options[nOptions++] = stringValue(value);
1116 NPN_ReleaseVariantValue(&value);
1118 *i_options = nOptions;
1119 *ppsz_options = options;
1126 ** implementation of libvlc subtitle object
1129 const NPUTF8 * const LibvlcSubtitleNPObject::propertyNames[] =
1135 enum LibvlcSubtitleNPObjectPropertyIds
1140 COUNTNAMES(LibvlcSubtitleNPObject,propertyCount,propertyNames);
1142 RuntimeNPObject::InvokeResult
1143 LibvlcSubtitleNPObject::getProperty(int index, NPVariant &result)
1145 /* is plugin still running */
1146 if( isPluginRunning() )
1148 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1149 libvlc_exception_t ex;
1150 libvlc_exception_init(&ex);
1152 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1153 RETURN_ON_EXCEPTION(this,ex);
1157 case ID_subtitle_track:
1159 /* get the current subtitle ID */
1160 int i_spu = libvlc_video_get_spu(p_md);
1162 INT32_TO_NPVARIANT(i_spu, result);
1163 return INVOKERESULT_NO_ERROR;
1165 case ID_subtitle_count:
1167 /* get the number of subtitles available */
1168 int i_spu = libvlc_video_get_spu_count(p_md);
1170 INT32_TO_NPVARIANT(i_spu, result);
1171 return INVOKERESULT_NO_ERROR;
1175 return INVOKERESULT_GENERIC_ERROR;
1178 RuntimeNPObject::InvokeResult
1179 LibvlcSubtitleNPObject::setProperty(int index, const NPVariant &value)
1181 /* is plugin still running */
1182 if( isPluginRunning() )
1184 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1185 libvlc_exception_t ex;
1186 libvlc_exception_init(&ex);
1188 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1189 RETURN_ON_EXCEPTION(this,ex);
1193 case ID_subtitle_track:
1195 if( isNumberValue(value) )
1197 /* set the new subtitle track to show */
1198 libvlc_video_set_spu(p_md, numberValue(value));
1200 return INVOKERESULT_NO_ERROR;
1202 return INVOKERESULT_INVALID_VALUE;
1206 return INVOKERESULT_GENERIC_ERROR;
1209 const NPUTF8 * const LibvlcSubtitleNPObject::methodNames[] =
1213 COUNTNAMES(LibvlcSubtitleNPObject,methodCount,methodNames);
1215 enum LibvlcSubtitleNPObjectMethodIds
1217 ID_subtitle_description
1220 RuntimeNPObject::InvokeResult
1221 LibvlcSubtitleNPObject::invoke(int index, const NPVariant *args,
1222 uint32_t argCount, NPVariant &result)
1224 /* is plugin still running */
1225 if( isPluginRunning() )
1227 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1228 libvlc_exception_t ex;
1229 libvlc_exception_init(&ex);
1231 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1232 RETURN_ON_EXCEPTION(this,ex);
1236 case ID_subtitle_description:
1241 int i_spuID, i_limit, i;
1242 libvlc_track_description_t *p_spuDesc;
1244 /* get subtitles description */
1245 p_spuDesc = libvlc_video_get_spu_description(p_md);
1247 return INVOKERESULT_GENERIC_ERROR;
1249 /* get the number of subtitle available */
1250 i_limit = libvlc_video_get_spu_count(p_md);
1252 /* check if a number is given by the user
1253 * and get the subtitle number */
1254 if( isNumberValue(args[0]) )
1255 i_spuID = numberValue(args[0]);
1257 return INVOKERESULT_INVALID_VALUE;
1259 /* if bad number is given return invalid value */
1260 if ( ( i_spuID > ( i_limit -1 ) ) || ( i_spuID < 0 ) )
1261 return INVOKERESULT_INVALID_VALUE;
1263 /* get the good spuDesc */
1264 for( i = 0 ; i < i_spuID ; i++ )
1266 p_spuDesc = p_spuDesc->p_next;
1268 psz_name = p_spuDesc->psz_name;
1270 /* return the name of the track chosen */
1271 return invokeResultString(psz_name, result);
1273 return INVOKERESULT_NO_SUCH_METHOD;
1276 return INVOKERESULT_NO_SUCH_METHOD;
1279 return INVOKERESULT_GENERIC_ERROR;
1283 ** implementation of libvlc video object
1286 LibvlcVideoNPObject::~LibvlcVideoNPObject()
1290 if( marqueeObj ) NPN_ReleaseObject(marqueeObj);
1291 if( logoObj ) NPN_ReleaseObject(logoObj);
1292 if( deintObj ) NPN_ReleaseObject(deintObj);
1296 const NPUTF8 * const LibvlcVideoNPObject::propertyNames[] =
1310 enum LibvlcVideoNPObjectPropertyIds
1312 ID_video_fullscreen,
1315 ID_video_aspectratio,
1321 ID_video_deinterlace,
1323 COUNTNAMES(LibvlcVideoNPObject,propertyCount,propertyNames);
1325 RuntimeNPObject::InvokeResult
1326 LibvlcVideoNPObject::getProperty(int index, NPVariant &result)
1328 /* is plugin still running */
1329 if( isPluginRunning() )
1331 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1332 libvlc_exception_t ex;
1333 libvlc_exception_init(&ex);
1335 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1336 RETURN_ON_EXCEPTION(this,ex);
1340 case ID_video_fullscreen:
1342 int val = p_plugin->get_fullscreen();
1343 BOOLEAN_TO_NPVARIANT(val, result);
1344 return INVOKERESULT_NO_ERROR;
1346 case ID_video_height:
1348 int val = libvlc_video_get_height(p_md);
1349 INT32_TO_NPVARIANT(val, result);
1350 return INVOKERESULT_NO_ERROR;
1352 case ID_video_width:
1354 int val = libvlc_video_get_width(p_md);
1355 INT32_TO_NPVARIANT(val, result);
1356 return INVOKERESULT_NO_ERROR;
1358 case ID_video_aspectratio:
1360 NPUTF8 *psz_aspect = libvlc_video_get_aspect_ratio(p_md);
1362 return INVOKERESULT_GENERIC_ERROR;
1364 STRINGZ_TO_NPVARIANT(psz_aspect, result);
1365 return INVOKERESULT_NO_ERROR;
1367 case ID_video_subtitle:
1369 int i_spu = libvlc_video_get_spu(p_md);
1370 INT32_TO_NPVARIANT(i_spu, result);
1371 return INVOKERESULT_NO_ERROR;
1375 NPUTF8 *psz_geometry = libvlc_video_get_crop_geometry(p_md);
1377 return INVOKERESULT_GENERIC_ERROR;
1379 STRINGZ_TO_NPVARIANT(psz_geometry, result);
1380 return INVOKERESULT_NO_ERROR;
1382 case ID_video_teletext:
1384 int i_page = libvlc_video_get_teletext(p_md);
1386 return INVOKERESULT_GENERIC_ERROR;
1387 INT32_TO_NPVARIANT(i_page, result);
1388 return INVOKERESULT_NO_ERROR;
1390 case ID_video_marquee:
1392 InstantObj<LibvlcMarqueeNPObject>( marqueeObj );
1393 OBJECT_TO_NPVARIANT(NPN_RetainObject(marqueeObj), result);
1394 return INVOKERESULT_NO_ERROR;
1398 InstantObj<LibvlcLogoNPObject>( logoObj );
1399 OBJECT_TO_NPVARIANT(NPN_RetainObject(logoObj), result);
1400 return INVOKERESULT_NO_ERROR;
1402 case ID_video_deinterlace:
1404 InstantObj<LibvlcDeinterlaceNPObject>( deintObj );
1405 OBJECT_TO_NPVARIANT(NPN_RetainObject(deintObj), result);
1406 return INVOKERESULT_NO_ERROR;
1410 return INVOKERESULT_GENERIC_ERROR;
1413 RuntimeNPObject::InvokeResult
1414 LibvlcVideoNPObject::setProperty(int index, const NPVariant &value)
1416 /* is plugin still running */
1417 if( isPluginRunning() )
1419 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1420 libvlc_exception_t ex;
1421 libvlc_exception_init(&ex);
1423 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1424 RETURN_ON_EXCEPTION(this,ex);
1428 case ID_video_fullscreen:
1430 if( ! NPVARIANT_IS_BOOLEAN(value) )
1432 return INVOKERESULT_INVALID_VALUE;
1435 int val = NPVARIANT_TO_BOOLEAN(value);
1436 p_plugin->set_fullscreen(val);
1437 return INVOKERESULT_NO_ERROR;
1439 case ID_video_aspectratio:
1441 char *psz_aspect = NULL;
1443 if( ! NPVARIANT_IS_STRING(value) )
1445 return INVOKERESULT_INVALID_VALUE;
1448 psz_aspect = stringValue(NPVARIANT_TO_STRING(value));
1451 return INVOKERESULT_GENERIC_ERROR;
1454 libvlc_video_set_aspect_ratio(p_md, psz_aspect);
1457 return INVOKERESULT_NO_ERROR;
1459 case ID_video_subtitle:
1461 if( isNumberValue(value) )
1463 libvlc_video_set_spu(p_md, numberValue(value));
1465 return INVOKERESULT_NO_ERROR;
1467 return INVOKERESULT_INVALID_VALUE;
1471 char *psz_geometry = NULL;
1473 if( ! NPVARIANT_IS_STRING(value) )
1475 return INVOKERESULT_INVALID_VALUE;
1478 psz_geometry = stringValue(NPVARIANT_TO_STRING(value));
1481 return INVOKERESULT_GENERIC_ERROR;
1484 libvlc_video_set_crop_geometry(p_md, psz_geometry);
1487 return INVOKERESULT_NO_ERROR;
1489 case ID_video_teletext:
1491 if( isNumberValue(value) )
1493 libvlc_video_set_teletext(p_md, numberValue(value), &ex);
1494 RETURN_ON_EXCEPTION(this,ex);
1496 return INVOKERESULT_NO_ERROR;
1498 return INVOKERESULT_INVALID_VALUE;
1502 return INVOKERESULT_GENERIC_ERROR;
1505 const NPUTF8 * const LibvlcVideoNPObject::methodNames[] =
1510 COUNTNAMES(LibvlcVideoNPObject,methodCount,methodNames);
1512 enum LibvlcVideoNPObjectMethodIds
1514 ID_video_togglefullscreen,
1515 ID_video_toggleteletext,
1518 RuntimeNPObject::InvokeResult
1519 LibvlcVideoNPObject::invoke(int index, const NPVariant *args,
1520 uint32_t argCount, NPVariant &result)
1522 /* is plugin still running */
1523 if( isPluginRunning() )
1525 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1526 libvlc_exception_t ex;
1527 libvlc_exception_init(&ex);
1529 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1530 RETURN_ON_EXCEPTION(this,ex);
1534 case ID_video_togglefullscreen:
1538 p_plugin->toggle_fullscreen();
1539 VOID_TO_NPVARIANT(result);
1540 return INVOKERESULT_NO_ERROR;
1542 return INVOKERESULT_NO_SUCH_METHOD;
1544 case ID_video_toggleteletext:
1548 libvlc_toggle_teletext(p_md);
1549 VOID_TO_NPVARIANT(result);
1550 return INVOKERESULT_NO_ERROR;
1552 return INVOKERESULT_NO_SUCH_METHOD;
1555 return INVOKERESULT_NO_SUCH_METHOD;
1558 return INVOKERESULT_GENERIC_ERROR;
1562 ** implementation of libvlc marquee object
1565 const NPUTF8 * const LibvlcMarqueeNPObject::propertyNames[] =
1578 enum LibvlcMarqueeNPObjectPropertyIds
1582 ID_marquee_position,
1591 COUNTNAMES(LibvlcMarqueeNPObject,propertyCount,propertyNames);
1593 static const unsigned char marquee_idx[] = {
1594 libvlc_marquee_Color,
1595 libvlc_marquee_Opacity,
1596 libvlc_marquee_Position,
1597 libvlc_marquee_Refresh,
1598 libvlc_marquee_Size,
1600 libvlc_marquee_Timeout,
1605 RuntimeNPObject::InvokeResult
1606 LibvlcMarqueeNPObject::getProperty(int index, NPVariant &result)
1610 if( !isPluginRunning() )
1611 return INVOKERESULT_GENERIC_ERROR;
1613 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1614 libvlc_exception_t ex;
1615 libvlc_exception_init(&ex);
1617 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1618 RETURN_ON_EXCEPTION(this,ex);
1622 case ID_marquee_color:
1623 case ID_marquee_opacity:
1624 case ID_marquee_refresh:
1625 case ID_marquee_timeout:
1626 case ID_marquee_size:
1630 libvlc_video_get_marquee_int(p_md, marquee_idx[index], &ex),
1632 RETURN_ON_EXCEPTION(this,ex);
1633 return INVOKERESULT_NO_ERROR;
1635 case ID_marquee_position:
1636 STRINGZ_TO_NPVARIANT( position_bynumber(
1637 libvlc_video_get_marquee_int(p_md, libvlc_marquee_Position, &ex) ),
1640 RETURN_ON_EXCEPTION(this,ex);
1643 case ID_marquee_text:
1644 psz = libvlc_video_get_marquee_string(p_md, libvlc_marquee_Text, &ex);
1647 STRINGZ_TO_NPVARIANT(psz, result);
1648 return INVOKERESULT_NO_ERROR;
1652 return INVOKERESULT_GENERIC_ERROR;
1655 RuntimeNPObject::InvokeResult
1656 LibvlcMarqueeNPObject::setProperty(int index, const NPVariant &value)
1660 if( !isPluginRunning() )
1661 return INVOKERESULT_GENERIC_ERROR;
1663 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1664 libvlc_exception_t ex;
1665 libvlc_exception_init(&ex);
1666 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1667 RETURN_ON_EXCEPTION(this,ex);
1671 case ID_marquee_color:
1672 case ID_marquee_opacity:
1673 case ID_marquee_refresh:
1674 case ID_marquee_timeout:
1677 if( NPVARIANT_IS_INT32( value ) )
1679 libvlc_video_set_marquee_int(p_md, marquee_idx[index],
1680 NPVARIANT_TO_INT32( value ), &ex);
1681 RETURN_ON_EXCEPTION(this,ex);
1682 return INVOKERESULT_NO_ERROR;
1686 case ID_marquee_position:
1687 if( !NPVARIANT_IS_STRING(value) ||
1688 !position_byname( NPVARIANT_TO_STRING(value).utf8characters, i ) )
1689 return INVOKERESULT_INVALID_VALUE;
1691 libvlc_video_set_marquee_int(p_md, libvlc_marquee_Position, i, &ex);
1692 RETURN_ON_EXCEPTION(this,ex);
1693 return INVOKERESULT_NO_ERROR;
1695 case ID_marquee_text:
1696 if( NPVARIANT_IS_STRING( value ) )
1698 char *psz_text = stringValue( NPVARIANT_TO_STRING( value ) );
1699 libvlc_video_set_marquee_string(p_md, libvlc_marquee_Text,
1702 RETURN_ON_EXCEPTION(this,ex);
1703 return INVOKERESULT_NO_ERROR;
1707 return INVOKERESULT_NO_SUCH_METHOD;
1710 const NPUTF8 * const LibvlcMarqueeNPObject::methodNames[] =
1715 COUNTNAMES(LibvlcMarqueeNPObject,methodCount,methodNames);
1717 enum LibvlcMarqueeNPObjectMethodIds
1723 RuntimeNPObject::InvokeResult
1724 LibvlcMarqueeNPObject::invoke(int index, const NPVariant *args,
1725 uint32_t argCount, NPVariant &result)
1727 if( !isPluginRunning() )
1728 return INVOKERESULT_GENERIC_ERROR;
1730 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1731 libvlc_exception_t ex;
1732 libvlc_exception_init(&ex);
1734 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1735 RETURN_ON_EXCEPTION(this,ex);
1739 case ID_marquee_enable:
1740 case ID_marquee_disable:
1741 libvlc_video_set_marquee_int(p_md, libvlc_marquee_Enable,
1742 index!=ID_marquee_disable, &ex);
1743 RETURN_ON_EXCEPTION(this,ex);
1744 VOID_TO_NPVARIANT(result);
1745 return INVOKERESULT_NO_ERROR;
1747 return INVOKERESULT_NO_SUCH_METHOD;
1750 const NPUTF8 * const LibvlcLogoNPObject::propertyNames[] = {
1758 enum LibvlcLogoNPObjectPropertyIds {
1766 COUNTNAMES(LibvlcLogoNPObject,propertyCount,propertyNames);
1767 static const unsigned char logo_idx[] = {
1770 libvlc_logo_opacity,
1776 RuntimeNPObject::InvokeResult
1777 LibvlcLogoNPObject::getProperty(int index, NPVariant &result)
1779 if( !isPluginRunning() )
1780 return INVOKERESULT_GENERIC_ERROR;
1782 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1783 libvlc_exception_t ex;
1784 libvlc_exception_init(&ex);
1785 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1786 RETURN_ON_EXCEPTION(this,ex);
1791 case ID_logo_repeat:
1792 case ID_logo_opacity:
1797 libvlc_video_get_logo_int(p_md, logo_idx[index], &ex), result);
1799 RETURN_ON_EXCEPTION(this,ex);
1802 case ID_logo_position:
1803 STRINGZ_TO_NPVARIANT( position_bynumber(
1804 libvlc_video_get_logo_int(p_md, libvlc_logo_position, &ex) ),
1807 RETURN_ON_EXCEPTION(this,ex);
1810 return INVOKERESULT_GENERIC_ERROR;
1812 return INVOKERESULT_NO_ERROR;
1815 RuntimeNPObject::InvokeResult
1816 LibvlcLogoNPObject::setProperty(int index, const NPVariant &value)
1820 if( !isPluginRunning() )
1821 return INVOKERESULT_GENERIC_ERROR;
1823 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1824 libvlc_exception_t ex;
1825 libvlc_exception_init(&ex);
1827 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1828 RETURN_ON_EXCEPTION(this,ex);
1833 case ID_logo_repeat:
1834 case ID_logo_opacity:
1837 if( !NPVARIANT_IS_INT32(value) )
1838 return INVOKERESULT_INVALID_VALUE;
1840 libvlc_video_set_logo_int(p_md, logo_idx[index],
1841 NPVARIANT_TO_INT32( value ), &ex);
1843 RETURN_ON_EXCEPTION(this,ex);
1846 case ID_logo_position:
1847 if( !NPVARIANT_IS_STRING(value) ||
1848 !position_byname( NPVARIANT_TO_STRING(value).utf8characters, i ) )
1849 return INVOKERESULT_INVALID_VALUE;
1851 libvlc_video_set_logo_int(p_md, libvlc_logo_position, i, &ex);
1853 RETURN_ON_EXCEPTION(this,ex);
1856 return INVOKERESULT_GENERIC_ERROR;
1858 return INVOKERESULT_NO_ERROR;
1862 const NPUTF8 * const LibvlcLogoNPObject::methodNames[] = {
1867 enum LibvlcLogoNPObjectMethodIds {
1872 COUNTNAMES(LibvlcLogoNPObject,methodCount,methodNames);
1874 RuntimeNPObject::InvokeResult
1875 LibvlcLogoNPObject::invoke(int index, const NPVariant *args,
1876 uint32_t argCount, NPVariant &result)
1881 if( !isPluginRunning() )
1882 return INVOKERESULT_GENERIC_ERROR;
1884 libvlc_exception_t ex;
1885 libvlc_exception_init(&ex);
1886 libvlc_media_player_t *p_md = getPrivate<VlcPlugin>()->getMD(&ex);
1887 RETURN_ON_EXCEPTION(this,ex);
1891 case ID_logo_enable:
1892 case ID_logo_disable:
1894 return INVOKERESULT_GENERIC_ERROR;
1896 libvlc_video_set_logo_int(p_md, libvlc_logo_enable,
1897 index != ID_logo_disable, &ex);
1898 RETURN_ON_EXCEPTION(this,ex);
1899 VOID_TO_NPVARIANT(result);
1904 return INVOKERESULT_GENERIC_ERROR;
1906 for( len=0,i=0;i<argCount;++i )
1908 if( !NPVARIANT_IS_STRING(args[i]) )
1909 return INVOKERESULT_INVALID_VALUE;
1910 len+=NPVARIANT_TO_STRING(args[i]).utf8length+1;
1913 buf = (char *)malloc( len+1 );
1915 return INVOKERESULT_OUT_OF_MEMORY;
1917 for( h=buf,i=0;i<argCount;++i )
1920 len=NPVARIANT_TO_STRING(args[i]).utf8length;
1921 memcpy(h,NPVARIANT_TO_STRING(args[i]).utf8characters,len);
1926 libvlc_video_set_logo_string(p_md, libvlc_logo_file, buf, &ex);
1928 RETURN_ON_EXCEPTION(this,ex);
1929 VOID_TO_NPVARIANT(result);
1932 return INVOKERESULT_NO_SUCH_METHOD;
1934 return INVOKERESULT_NO_ERROR;
1938 const NPUTF8 * const LibvlcDeinterlaceNPObject::propertyNames[] = {
1940 enum LibvlcDeinterlaceNPObjectPropertyIds {
1942 COUNTNAMES(LibvlcDeinterlaceNPObject,propertyCount,propertyNames);
1944 RuntimeNPObject::InvokeResult
1945 LibvlcDeinterlaceNPObject::getProperty(int index, NPVariant &result)
1947 return INVOKERESULT_GENERIC_ERROR;
1950 RuntimeNPObject::InvokeResult
1951 LibvlcDeinterlaceNPObject::setProperty(int index, const NPVariant &value)
1953 return INVOKERESULT_GENERIC_ERROR;
1957 const NPUTF8 * const LibvlcDeinterlaceNPObject::methodNames[] = {
1961 enum LibvlcDeinterlaceNPObjectMethodIds {
1965 COUNTNAMES(LibvlcDeinterlaceNPObject,methodCount,methodNames);
1967 RuntimeNPObject::InvokeResult
1968 LibvlcDeinterlaceNPObject::invoke(int index, const NPVariant *args,
1969 uint32_t argCount, NPVariant &result)
1973 if( !isPluginRunning() )
1974 return INVOKERESULT_GENERIC_ERROR;
1976 libvlc_exception_t ex;
1977 libvlc_exception_init(&ex);
1978 libvlc_media_player_t *p_md = getPrivate<VlcPlugin>()->getMD(&ex);
1979 RETURN_ON_EXCEPTION(this,ex);
1983 case ID_deint_disable:
1984 libvlc_video_set_deinterlace(p_md, NULL);
1987 case ID_deint_enable:
1988 if( argCount != 1 || !NPVARIANT_IS_STRING( args[0] ) )
1989 return INVOKERESULT_INVALID_VALUE;
1991 psz = stringValue( NPVARIANT_TO_STRING( args[0] ) );
1992 libvlc_video_set_deinterlace(p_md, psz);
1997 return INVOKERESULT_NO_SUCH_METHOD;
1999 return INVOKERESULT_NO_ERROR;