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 p_plugin->playlist_delete_item(numberValue(args[0]),&ex);
712 RETURN_ON_EXCEPTION(this,ex);
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 p_plugin->playlist_delete_item(numberValue(args[0]), &ex);
975 RETURN_ON_EXCEPTION(this,ex);
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, &ex);
1385 RETURN_ON_EXCEPTION(this,ex);
1386 INT32_TO_NPVARIANT(i_page, result);
1387 return INVOKERESULT_NO_ERROR;
1389 return INVOKERESULT_NO_SUCH_METHOD;
1391 case ID_video_marquee:
1393 InstantObj<LibvlcMarqueeNPObject>( marqueeObj );
1394 OBJECT_TO_NPVARIANT(NPN_RetainObject(marqueeObj), result);
1395 return INVOKERESULT_NO_ERROR;
1399 InstantObj<LibvlcLogoNPObject>( logoObj );
1400 OBJECT_TO_NPVARIANT(NPN_RetainObject(logoObj), result);
1401 return INVOKERESULT_NO_ERROR;
1403 case ID_video_deinterlace:
1405 InstantObj<LibvlcDeinterlaceNPObject>( deintObj );
1406 OBJECT_TO_NPVARIANT(NPN_RetainObject(deintObj), result);
1407 return INVOKERESULT_NO_ERROR;
1411 return INVOKERESULT_GENERIC_ERROR;
1414 RuntimeNPObject::InvokeResult
1415 LibvlcVideoNPObject::setProperty(int index, const NPVariant &value)
1417 /* is plugin still running */
1418 if( isPluginRunning() )
1420 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1421 libvlc_exception_t ex;
1422 libvlc_exception_init(&ex);
1424 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1425 RETURN_ON_EXCEPTION(this,ex);
1429 case ID_video_fullscreen:
1431 if( ! NPVARIANT_IS_BOOLEAN(value) )
1433 return INVOKERESULT_INVALID_VALUE;
1436 int val = NPVARIANT_TO_BOOLEAN(value);
1437 p_plugin->set_fullscreen(val);
1438 return INVOKERESULT_NO_ERROR;
1440 case ID_video_aspectratio:
1442 char *psz_aspect = NULL;
1444 if( ! NPVARIANT_IS_STRING(value) )
1446 return INVOKERESULT_INVALID_VALUE;
1449 psz_aspect = stringValue(NPVARIANT_TO_STRING(value));
1452 return INVOKERESULT_GENERIC_ERROR;
1455 libvlc_video_set_aspect_ratio(p_md, psz_aspect);
1458 return INVOKERESULT_NO_ERROR;
1460 case ID_video_subtitle:
1462 if( isNumberValue(value) )
1464 libvlc_video_set_spu(p_md, numberValue(value));
1466 return INVOKERESULT_NO_ERROR;
1468 return INVOKERESULT_INVALID_VALUE;
1472 char *psz_geometry = NULL;
1474 if( ! NPVARIANT_IS_STRING(value) )
1476 return INVOKERESULT_INVALID_VALUE;
1479 psz_geometry = stringValue(NPVARIANT_TO_STRING(value));
1482 return INVOKERESULT_GENERIC_ERROR;
1485 libvlc_video_set_crop_geometry(p_md, psz_geometry);
1488 return INVOKERESULT_NO_ERROR;
1490 case ID_video_teletext:
1492 if( isNumberValue(value) )
1495 libvlc_video_set_teletext(p_md, numberValue(value), &ex);
1496 RETURN_ON_EXCEPTION(this,ex);
1498 return INVOKERESULT_NO_ERROR;
1500 return INVOKERESULT_NO_SUCH_METHOD;
1502 return INVOKERESULT_INVALID_VALUE;
1506 return INVOKERESULT_GENERIC_ERROR;
1509 const NPUTF8 * const LibvlcVideoNPObject::methodNames[] =
1514 COUNTNAMES(LibvlcVideoNPObject,methodCount,methodNames);
1516 enum LibvlcVideoNPObjectMethodIds
1518 ID_video_togglefullscreen,
1519 ID_video_toggleteletext,
1522 RuntimeNPObject::InvokeResult
1523 LibvlcVideoNPObject::invoke(int index, const NPVariant *args,
1524 uint32_t argCount, NPVariant &result)
1526 /* is plugin still running */
1527 if( isPluginRunning() )
1529 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1530 libvlc_exception_t ex;
1531 libvlc_exception_init(&ex);
1533 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1534 RETURN_ON_EXCEPTION(this,ex);
1538 case ID_video_togglefullscreen:
1542 p_plugin->toggle_fullscreen();
1543 VOID_TO_NPVARIANT(result);
1544 return INVOKERESULT_NO_ERROR;
1546 return INVOKERESULT_NO_SUCH_METHOD;
1548 case ID_video_toggleteletext:
1552 libvlc_toggle_teletext(p_md);
1553 VOID_TO_NPVARIANT(result);
1554 return INVOKERESULT_NO_ERROR;
1556 return INVOKERESULT_NO_SUCH_METHOD;
1559 return INVOKERESULT_NO_SUCH_METHOD;
1562 return INVOKERESULT_GENERIC_ERROR;
1566 ** implementation of libvlc marquee object
1569 const NPUTF8 * const LibvlcMarqueeNPObject::propertyNames[] =
1582 enum LibvlcMarqueeNPObjectPropertyIds
1586 ID_marquee_position,
1595 COUNTNAMES(LibvlcMarqueeNPObject,propertyCount,propertyNames);
1597 static const unsigned char marquee_idx[] = {
1598 libvlc_marquee_Color,
1599 libvlc_marquee_Opacity,
1600 libvlc_marquee_Position,
1601 libvlc_marquee_Refresh,
1602 libvlc_marquee_Size,
1604 libvlc_marquee_Timeout,
1609 RuntimeNPObject::InvokeResult
1610 LibvlcMarqueeNPObject::getProperty(int index, NPVariant &result)
1614 if( !isPluginRunning() )
1615 return INVOKERESULT_GENERIC_ERROR;
1617 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1618 libvlc_exception_t ex;
1619 libvlc_exception_init(&ex);
1621 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1622 RETURN_ON_EXCEPTION(this,ex);
1626 case ID_marquee_color:
1627 case ID_marquee_opacity:
1628 case ID_marquee_refresh:
1629 case ID_marquee_timeout:
1630 case ID_marquee_size:
1634 libvlc_video_get_marquee_int(p_md, marquee_idx[index], &ex),
1636 RETURN_ON_EXCEPTION(this,ex);
1637 return INVOKERESULT_NO_ERROR;
1639 case ID_marquee_position:
1640 STRINGZ_TO_NPVARIANT( position_bynumber(
1641 libvlc_video_get_marquee_int(p_md, libvlc_marquee_Position, &ex) ),
1644 RETURN_ON_EXCEPTION(this,ex);
1647 case ID_marquee_text:
1648 psz = libvlc_video_get_marquee_string(p_md, libvlc_marquee_Text, &ex);
1651 STRINGZ_TO_NPVARIANT(psz, result);
1652 return INVOKERESULT_NO_ERROR;
1656 return INVOKERESULT_GENERIC_ERROR;
1659 RuntimeNPObject::InvokeResult
1660 LibvlcMarqueeNPObject::setProperty(int index, const NPVariant &value)
1664 if( !isPluginRunning() )
1665 return INVOKERESULT_GENERIC_ERROR;
1667 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1668 libvlc_exception_t ex;
1669 libvlc_exception_init(&ex);
1670 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1671 RETURN_ON_EXCEPTION(this,ex);
1675 case ID_marquee_color:
1676 case ID_marquee_opacity:
1677 case ID_marquee_refresh:
1678 case ID_marquee_timeout:
1681 if( NPVARIANT_IS_INT32( value ) )
1683 libvlc_video_set_marquee_int(p_md, marquee_idx[index],
1684 NPVARIANT_TO_INT32( value ), &ex);
1685 RETURN_ON_EXCEPTION(this,ex);
1686 return INVOKERESULT_NO_ERROR;
1690 case ID_marquee_position:
1691 if( !NPVARIANT_IS_STRING(value) ||
1692 !position_byname( NPVARIANT_TO_STRING(value).utf8characters, i ) )
1693 return INVOKERESULT_INVALID_VALUE;
1695 libvlc_video_set_marquee_int(p_md, libvlc_marquee_Position, i, &ex);
1696 RETURN_ON_EXCEPTION(this,ex);
1697 return INVOKERESULT_NO_ERROR;
1699 case ID_marquee_text:
1700 if( NPVARIANT_IS_STRING( value ) )
1702 char *psz_text = stringValue( NPVARIANT_TO_STRING( value ) );
1703 libvlc_video_set_marquee_string(p_md, libvlc_marquee_Text,
1706 RETURN_ON_EXCEPTION(this,ex);
1707 return INVOKERESULT_NO_ERROR;
1711 return INVOKERESULT_NO_SUCH_METHOD;
1714 const NPUTF8 * const LibvlcMarqueeNPObject::methodNames[] =
1719 COUNTNAMES(LibvlcMarqueeNPObject,methodCount,methodNames);
1721 enum LibvlcMarqueeNPObjectMethodIds
1727 RuntimeNPObject::InvokeResult
1728 LibvlcMarqueeNPObject::invoke(int index, const NPVariant *args,
1729 uint32_t argCount, NPVariant &result)
1731 if( !isPluginRunning() )
1732 return INVOKERESULT_GENERIC_ERROR;
1734 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1735 libvlc_exception_t ex;
1736 libvlc_exception_init(&ex);
1738 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1739 RETURN_ON_EXCEPTION(this,ex);
1743 case ID_marquee_enable:
1744 case ID_marquee_disable:
1745 libvlc_video_set_marquee_int(p_md, libvlc_marquee_Enable,
1746 index!=ID_marquee_disable, &ex);
1747 RETURN_ON_EXCEPTION(this,ex);
1748 VOID_TO_NPVARIANT(result);
1749 return INVOKERESULT_NO_ERROR;
1751 return INVOKERESULT_NO_SUCH_METHOD;
1754 const NPUTF8 * const LibvlcLogoNPObject::propertyNames[] = {
1762 enum LibvlcLogoNPObjectPropertyIds {
1770 COUNTNAMES(LibvlcLogoNPObject,propertyCount,propertyNames);
1771 static const unsigned char logo_idx[] = {
1774 libvlc_logo_opacity,
1780 RuntimeNPObject::InvokeResult
1781 LibvlcLogoNPObject::getProperty(int index, NPVariant &result)
1783 if( !isPluginRunning() )
1784 return INVOKERESULT_GENERIC_ERROR;
1786 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1787 libvlc_exception_t ex;
1788 libvlc_exception_init(&ex);
1789 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1790 RETURN_ON_EXCEPTION(this,ex);
1795 case ID_logo_repeat:
1796 case ID_logo_opacity:
1801 libvlc_video_get_logo_int(p_md, logo_idx[index], &ex), result);
1803 RETURN_ON_EXCEPTION(this,ex);
1806 case ID_logo_position:
1807 STRINGZ_TO_NPVARIANT( position_bynumber(
1808 libvlc_video_get_logo_int(p_md, libvlc_logo_position, &ex) ),
1811 RETURN_ON_EXCEPTION(this,ex);
1814 return INVOKERESULT_GENERIC_ERROR;
1816 return INVOKERESULT_NO_ERROR;
1819 RuntimeNPObject::InvokeResult
1820 LibvlcLogoNPObject::setProperty(int index, const NPVariant &value)
1824 if( !isPluginRunning() )
1825 return INVOKERESULT_GENERIC_ERROR;
1827 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1828 libvlc_exception_t ex;
1829 libvlc_exception_init(&ex);
1831 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1832 RETURN_ON_EXCEPTION(this,ex);
1837 case ID_logo_repeat:
1838 case ID_logo_opacity:
1841 if( !NPVARIANT_IS_INT32(value) )
1842 return INVOKERESULT_INVALID_VALUE;
1844 libvlc_video_set_logo_int(p_md, logo_idx[index],
1845 NPVARIANT_TO_INT32( value ), &ex);
1847 RETURN_ON_EXCEPTION(this,ex);
1850 case ID_logo_position:
1851 if( !NPVARIANT_IS_STRING(value) ||
1852 !position_byname( NPVARIANT_TO_STRING(value).utf8characters, i ) )
1853 return INVOKERESULT_INVALID_VALUE;
1855 libvlc_video_set_logo_int(p_md, libvlc_logo_position, i, &ex);
1857 RETURN_ON_EXCEPTION(this,ex);
1860 return INVOKERESULT_GENERIC_ERROR;
1862 return INVOKERESULT_NO_ERROR;
1866 const NPUTF8 * const LibvlcLogoNPObject::methodNames[] = {
1871 enum LibvlcLogoNPObjectMethodIds {
1876 COUNTNAMES(LibvlcLogoNPObject,methodCount,methodNames);
1878 RuntimeNPObject::InvokeResult
1879 LibvlcLogoNPObject::invoke(int index, const NPVariant *args,
1880 uint32_t argCount, NPVariant &result)
1885 if( !isPluginRunning() )
1886 return INVOKERESULT_GENERIC_ERROR;
1888 libvlc_exception_t ex;
1889 libvlc_exception_init(&ex);
1890 libvlc_media_player_t *p_md = getPrivate<VlcPlugin>()->getMD(&ex);
1891 RETURN_ON_EXCEPTION(this,ex);
1895 case ID_logo_enable:
1896 case ID_logo_disable:
1898 return INVOKERESULT_GENERIC_ERROR;
1900 libvlc_video_set_logo_int(p_md, libvlc_logo_enable,
1901 index != ID_logo_disable, &ex);
1902 RETURN_ON_EXCEPTION(this,ex);
1903 VOID_TO_NPVARIANT(result);
1908 return INVOKERESULT_GENERIC_ERROR;
1910 for( len=0,i=0;i<argCount;++i )
1912 if( !NPVARIANT_IS_STRING(args[i]) )
1913 return INVOKERESULT_INVALID_VALUE;
1914 len+=NPVARIANT_TO_STRING(args[i]).utf8length+1;
1917 buf = (char *)malloc( len+1 );
1919 return INVOKERESULT_OUT_OF_MEMORY;
1921 for( h=buf,i=0;i<argCount;++i )
1924 len=NPVARIANT_TO_STRING(args[i]).utf8length;
1925 memcpy(h,NPVARIANT_TO_STRING(args[i]).utf8characters,len);
1930 libvlc_video_set_logo_string(p_md, libvlc_logo_file, buf, &ex);
1932 RETURN_ON_EXCEPTION(this,ex);
1933 VOID_TO_NPVARIANT(result);
1936 return INVOKERESULT_NO_SUCH_METHOD;
1938 return INVOKERESULT_NO_ERROR;
1942 const NPUTF8 * const LibvlcDeinterlaceNPObject::propertyNames[] = {
1944 enum LibvlcDeinterlaceNPObjectPropertyIds {
1946 COUNTNAMES(LibvlcDeinterlaceNPObject,propertyCount,propertyNames);
1948 RuntimeNPObject::InvokeResult
1949 LibvlcDeinterlaceNPObject::getProperty(int index, NPVariant &result)
1951 return INVOKERESULT_GENERIC_ERROR;
1954 RuntimeNPObject::InvokeResult
1955 LibvlcDeinterlaceNPObject::setProperty(int index, const NPVariant &value)
1957 return INVOKERESULT_GENERIC_ERROR;
1961 const NPUTF8 * const LibvlcDeinterlaceNPObject::methodNames[] = {
1965 enum LibvlcDeinterlaceNPObjectMethodIds {
1969 COUNTNAMES(LibvlcDeinterlaceNPObject,methodCount,methodNames);
1971 RuntimeNPObject::InvokeResult
1972 LibvlcDeinterlaceNPObject::invoke(int index, const NPVariant *args,
1973 uint32_t argCount, NPVariant &result)
1977 if( !isPluginRunning() )
1978 return INVOKERESULT_GENERIC_ERROR;
1980 libvlc_exception_t ex;
1981 libvlc_exception_init(&ex);
1982 libvlc_media_player_t *p_md = getPrivate<VlcPlugin>()->getMD(&ex);
1983 RETURN_ON_EXCEPTION(this,ex);
1987 case ID_deint_disable:
1988 libvlc_video_set_deinterlace(p_md, NULL);
1991 case ID_deint_enable:
1992 if( argCount != 1 || !NPVARIANT_IS_STRING( args[0] ) )
1993 return INVOKERESULT_INVALID_VALUE;
1995 psz = stringValue( NPVARIANT_TO_STRING( args[0] ) );
1996 libvlc_video_set_deinterlace(p_md, psz);
2001 return INVOKERESULT_NO_SUCH_METHOD;
2003 return INVOKERESULT_NO_ERROR;