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; \
54 ** implementation of libvlc root object
57 LibvlcRootNPObject::~LibvlcRootNPObject()
60 ** When the plugin is destroyed, firefox takes it upon itself to
61 ** destroy all 'live' script objects and ignores refcounting.
62 ** Therefore we cannot safely assume that refcounting will control
63 ** lifespan of objects. Hence they are only lazily created on
64 ** request, so that firefox can take ownership, and are not released
65 ** when the plugin is destroyed.
69 if( audioObj ) NPN_ReleaseObject(audioObj);
70 if( inputObj ) NPN_ReleaseObject(inputObj);
71 if( playlistObj ) NPN_ReleaseObject(playlistObj);
72 if( videoObj ) NPN_ReleaseObject(videoObj);
76 const NPUTF8 * const LibvlcRootNPObject::propertyNames[] =
85 COUNTNAMES(LibvlcRootNPObject,propertyCount,propertyNames);
87 enum LibvlcRootNPObjectPropertyIds
97 RuntimeNPObject::InvokeResult
98 LibvlcRootNPObject::getProperty(int index, NPVariant &result)
100 /* is plugin still running */
101 if( isPluginRunning() )
106 InstantObj<LibvlcAudioNPObject>( audioObj );
107 OBJECT_TO_NPVARIANT(NPN_RetainObject(audioObj), result);
108 return INVOKERESULT_NO_ERROR;
110 InstantObj<LibvlcInputNPObject>( inputObj );
111 OBJECT_TO_NPVARIANT(NPN_RetainObject(inputObj), result);
112 return INVOKERESULT_NO_ERROR;
113 case ID_root_playlist:
114 InstantObj<LibvlcPlaylistNPObject>( playlistObj );
115 OBJECT_TO_NPVARIANT(NPN_RetainObject(playlistObj), result);
116 return INVOKERESULT_NO_ERROR;
117 case ID_root_subtitle:
118 InstantObj<LibvlcSubtitleNPObject>( subtitleObj );
119 OBJECT_TO_NPVARIANT(NPN_RetainObject(subtitleObj), result);
120 return INVOKERESULT_NO_ERROR;
122 InstantObj<LibvlcVideoNPObject>( videoObj );
123 OBJECT_TO_NPVARIANT(NPN_RetainObject(videoObj), result);
124 return INVOKERESULT_NO_ERROR;
125 case ID_root_VersionInfo:
126 return invokeResultString(libvlc_get_version(),result);
131 return INVOKERESULT_GENERIC_ERROR;
134 const NPUTF8 * const LibvlcRootNPObject::methodNames[] =
138 COUNTNAMES(LibvlcRootNPObject,methodCount,methodNames);
140 enum LibvlcRootNPObjectMethodIds
145 RuntimeNPObject::InvokeResult LibvlcRootNPObject::invoke(int index,
146 const NPVariant *args, uint32_t argCount, NPVariant &result)
148 /* is plugin still running */
149 if( isPluginRunning() )
151 libvlc_exception_t ex;
152 libvlc_exception_init(&ex);
156 case ID_root_versionInfo:
158 return INVOKERESULT_NO_SUCH_METHOD;
159 return invokeResultString(libvlc_get_version(),result);
164 return INVOKERESULT_GENERIC_ERROR;
168 ** implementation of libvlc audio object
171 const NPUTF8 * const LibvlcAudioNPObject::propertyNames[] =
179 COUNTNAMES(LibvlcAudioNPObject,propertyCount,propertyNames);
181 enum LibvlcAudioNPObjectPropertyIds
190 RuntimeNPObject::InvokeResult
191 LibvlcAudioNPObject::getProperty(int index, NPVariant &result)
193 /* is plugin still running */
194 if( isPluginRunning() )
196 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
197 libvlc_exception_t ex;
198 libvlc_exception_init(&ex);
204 bool muted = libvlc_audio_get_mute(p_plugin->getVLC());
205 BOOLEAN_TO_NPVARIANT(muted, result);
206 return INVOKERESULT_NO_ERROR;
208 case ID_audio_volume:
210 int volume = libvlc_audio_get_volume(p_plugin->getVLC());
211 INT32_TO_NPVARIANT(volume, result);
212 return INVOKERESULT_NO_ERROR;
216 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
217 RETURN_ON_EXCEPTION(this,ex);
218 int track = libvlc_audio_get_track(p_md, &ex);
219 RETURN_ON_EXCEPTION(this,ex);
220 INT32_TO_NPVARIANT(track, result);
221 return INVOKERESULT_NO_ERROR;
225 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
226 RETURN_ON_EXCEPTION(this,ex);
227 // get the number of audio track available
228 int i_track = libvlc_audio_get_track_count(p_md, &ex);
229 RETURN_ON_EXCEPTION(this,ex);
231 INT32_TO_NPVARIANT(i_track, result);
232 return INVOKERESULT_NO_ERROR;
234 case ID_audio_channel:
236 int channel = libvlc_audio_get_channel(p_plugin->getVLC(), &ex);
237 RETURN_ON_EXCEPTION(this,ex);
238 INT32_TO_NPVARIANT(channel, result);
239 return INVOKERESULT_NO_ERROR;
245 return INVOKERESULT_GENERIC_ERROR;
248 RuntimeNPObject::InvokeResult
249 LibvlcAudioNPObject::setProperty(int index, const NPVariant &value)
251 /* is plugin still running */
252 if( isPluginRunning() )
254 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
255 libvlc_exception_t ex;
256 libvlc_exception_init(&ex);
261 if( NPVARIANT_IS_BOOLEAN(value) )
263 libvlc_audio_set_mute(p_plugin->getVLC(),
264 NPVARIANT_TO_BOOLEAN(value));
265 return INVOKERESULT_NO_ERROR;
267 return INVOKERESULT_INVALID_VALUE;
268 case ID_audio_volume:
269 if( isNumberValue(value) )
271 libvlc_audio_set_volume(p_plugin->getVLC(),
272 numberValue(value), &ex);
273 RETURN_ON_EXCEPTION(this,ex);
274 return INVOKERESULT_NO_ERROR;
276 return INVOKERESULT_INVALID_VALUE;
278 if( isNumberValue(value) )
280 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
281 RETURN_ON_EXCEPTION(this,ex);
282 libvlc_audio_set_track(p_md, numberValue(value), &ex);
283 RETURN_ON_EXCEPTION(this,ex);
284 return INVOKERESULT_NO_ERROR;
286 return INVOKERESULT_INVALID_VALUE;
287 case ID_audio_channel:
288 if( isNumberValue(value) )
290 libvlc_audio_set_channel(p_plugin->getVLC(),
291 numberValue(value), &ex);
292 RETURN_ON_EXCEPTION(this,ex);
293 return INVOKERESULT_NO_ERROR;
295 return INVOKERESULT_INVALID_VALUE;
300 return INVOKERESULT_GENERIC_ERROR;
303 const NPUTF8 * const LibvlcAudioNPObject::methodNames[] =
308 COUNTNAMES(LibvlcAudioNPObject,methodCount,methodNames);
310 enum LibvlcAudioNPObjectMethodIds
313 ID_audio_description,
316 RuntimeNPObject::InvokeResult
317 LibvlcAudioNPObject::invoke(int index, const NPVariant *args,
318 uint32_t argCount, NPVariant &result)
320 /* is plugin still running */
321 if( isPluginRunning() )
323 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
324 libvlc_exception_t ex;
325 libvlc_exception_init(&ex);
329 case ID_audio_togglemute:
332 libvlc_audio_toggle_mute(p_plugin->getVLC());
333 VOID_TO_NPVARIANT(result);
334 return INVOKERESULT_NO_ERROR;
336 return INVOKERESULT_NO_SUCH_METHOD;
337 case ID_audio_description:
342 int i_trackID, i_limit, i;
343 libvlc_track_description_t *p_trackDesc;
345 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
346 RETURN_ON_EXCEPTION(this,ex);
348 /* get tracks description */
349 p_trackDesc = libvlc_audio_get_track_description(p_md, &ex);
350 RETURN_ON_EXCEPTION(this,ex);
352 return INVOKERESULT_GENERIC_ERROR;
354 /* get the number of track available */
355 i_limit = libvlc_audio_get_track_count(p_md, &ex);
356 RETURN_ON_EXCEPTION(this,ex);
358 /* check if a number is given by the user
359 * and get the track number */
360 if( isNumberValue(args[0]) )
361 i_trackID = numberValue(args[0]);
363 return INVOKERESULT_INVALID_VALUE;
365 /* if bad number is given return invalid value */
366 if ( ( i_trackID > ( i_limit - 1 ) ) || ( i_trackID < 0 ) )
367 return INVOKERESULT_INVALID_VALUE;
369 /* get the good trackDesc */
370 for( i = 0 ; i < i_trackID ; i++ )
372 p_trackDesc = p_trackDesc->p_next;
374 psz_name = p_trackDesc->psz_name;
376 /* display the name of the track chosen */
377 return invokeResultString( psz_name, result );
379 return INVOKERESULT_NO_SUCH_METHOD;
385 return INVOKERESULT_GENERIC_ERROR;
389 ** implementation of libvlc input object
392 const NPUTF8 * const LibvlcInputNPObject::propertyNames[] =
402 COUNTNAMES(LibvlcInputNPObject,propertyCount,propertyNames);
404 enum LibvlcInputNPObjectPropertyIds
415 RuntimeNPObject::InvokeResult
416 LibvlcInputNPObject::getProperty(int index, NPVariant &result)
418 /* is plugin still running */
419 if( isPluginRunning() )
421 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
422 libvlc_exception_t ex;
423 libvlc_exception_init(&ex);
425 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
426 if( libvlc_exception_raised(&ex) )
428 if( index != ID_input_state )
430 NPN_SetException(this, libvlc_errmsg());
431 libvlc_exception_clear(&ex);
432 return INVOKERESULT_GENERIC_ERROR;
436 /* for input state, return CLOSED rather than an exception */
437 INT32_TO_NPVARIANT(0, result);
438 libvlc_exception_clear(&ex);
439 return INVOKERESULT_NO_ERROR;
445 case ID_input_length:
447 double val = (double)libvlc_media_player_get_length(p_md, &ex);
448 RETURN_ON_EXCEPTION(this,ex);
449 DOUBLE_TO_NPVARIANT(val, result);
450 return INVOKERESULT_NO_ERROR;
452 case ID_input_position:
454 double val = libvlc_media_player_get_position(p_md, &ex);
455 RETURN_ON_EXCEPTION(this,ex);
456 DOUBLE_TO_NPVARIANT(val, result);
457 return INVOKERESULT_NO_ERROR;
461 double val = (double)libvlc_media_player_get_time(p_md, &ex);
462 RETURN_ON_EXCEPTION(this,ex);
463 DOUBLE_TO_NPVARIANT(val, result);
464 return INVOKERESULT_NO_ERROR;
468 int val = libvlc_media_player_get_state(p_md);
469 RETURN_ON_EXCEPTION(this,ex);
470 INT32_TO_NPVARIANT(val, result);
471 return INVOKERESULT_NO_ERROR;
475 float val = libvlc_media_player_get_rate(p_md, &ex);
476 RETURN_ON_EXCEPTION(this,ex);
477 DOUBLE_TO_NPVARIANT(val, result);
478 return INVOKERESULT_NO_ERROR;
482 double val = libvlc_media_player_get_fps(p_md, &ex);
483 RETURN_ON_EXCEPTION(this,ex);
484 DOUBLE_TO_NPVARIANT(val, result);
485 return INVOKERESULT_NO_ERROR;
487 case ID_input_hasvout:
489 bool val = p_plugin->player_has_vout(&ex);
490 RETURN_ON_EXCEPTION(this,ex);
491 BOOLEAN_TO_NPVARIANT(val, result);
492 return INVOKERESULT_NO_ERROR;
498 return INVOKERESULT_GENERIC_ERROR;
501 RuntimeNPObject::InvokeResult
502 LibvlcInputNPObject::setProperty(int index, const NPVariant &value)
504 /* is plugin still running */
505 if( isPluginRunning() )
507 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
508 libvlc_exception_t ex;
509 libvlc_exception_init(&ex);
511 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
512 RETURN_ON_EXCEPTION(this,ex);
516 case ID_input_position:
518 if( ! NPVARIANT_IS_DOUBLE(value) )
520 return INVOKERESULT_INVALID_VALUE;
523 float val = (float)NPVARIANT_TO_DOUBLE(value);
524 libvlc_media_player_set_position(p_md, val, &ex);
525 RETURN_ON_EXCEPTION(this,ex);
526 return INVOKERESULT_NO_ERROR;
531 if( NPVARIANT_IS_INT32(value) )
532 val = (int64_t)NPVARIANT_TO_INT32(value);
533 else if( NPVARIANT_IS_DOUBLE(value) )
534 val = (int64_t)NPVARIANT_TO_DOUBLE(value);
537 return INVOKERESULT_INVALID_VALUE;
540 libvlc_media_player_set_time(p_md, val, &ex);
541 RETURN_ON_EXCEPTION(this,ex);
542 return INVOKERESULT_NO_ERROR;
547 if( NPVARIANT_IS_INT32(value) )
548 val = (float)NPVARIANT_TO_INT32(value);
549 else if( NPVARIANT_IS_DOUBLE(value) )
550 val = (float)NPVARIANT_TO_DOUBLE(value);
553 return INVOKERESULT_INVALID_VALUE;
556 libvlc_media_player_set_rate(p_md, val, &ex);
557 RETURN_ON_EXCEPTION(this,ex);
558 return INVOKERESULT_NO_ERROR;
564 return INVOKERESULT_GENERIC_ERROR;
567 const NPUTF8 * const LibvlcInputNPObject::methodNames[] =
572 COUNTNAMES(LibvlcInputNPObject,methodCount,methodNames);
574 enum LibvlcInputNPObjectMethodIds
579 RuntimeNPObject::InvokeResult
580 LibvlcInputNPObject::invoke(int index, const NPVariant *args,
581 uint32_t argCount, NPVariant &result)
583 /* is plugin still running */
584 if( isPluginRunning() )
589 return INVOKERESULT_NO_SUCH_METHOD;
594 return INVOKERESULT_GENERIC_ERROR;
598 ** implementation of libvlc playlist items object
601 const NPUTF8 * const LibvlcPlaylistItemsNPObject::propertyNames[] =
605 COUNTNAMES(LibvlcPlaylistItemsNPObject,propertyCount,propertyNames);
607 enum LibvlcPlaylistItemsNPObjectPropertyIds
609 ID_playlistitems_count,
612 RuntimeNPObject::InvokeResult
613 LibvlcPlaylistItemsNPObject::getProperty(int index, NPVariant &result)
615 /* is plugin still running */
616 if( isPluginRunning() )
618 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
622 case ID_playlistitems_count:
624 int val = p_plugin->playlist_count();
625 INT32_TO_NPVARIANT(val, result);
626 return INVOKERESULT_NO_ERROR;
632 return INVOKERESULT_GENERIC_ERROR;
635 const NPUTF8 * const LibvlcPlaylistItemsNPObject::methodNames[] =
640 COUNTNAMES(LibvlcPlaylistItemsNPObject,methodCount,methodNames);
642 enum LibvlcPlaylistItemsNPObjectMethodIds
644 ID_playlistitems_clear,
645 ID_playlistitems_remove,
648 RuntimeNPObject::InvokeResult
649 LibvlcPlaylistItemsNPObject::invoke(int index, const NPVariant *args,
650 uint32_t argCount, NPVariant &result)
652 /* is plugin still running */
653 if( isPluginRunning() )
655 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
656 libvlc_exception_t ex;
657 libvlc_exception_init(&ex);
661 case ID_playlistitems_clear:
664 p_plugin->playlist_clear(&ex);
665 RETURN_ON_EXCEPTION(this,ex);
666 VOID_TO_NPVARIANT(result);
667 return INVOKERESULT_NO_ERROR;
669 return INVOKERESULT_NO_SUCH_METHOD;
670 case ID_playlistitems_remove:
671 if( (argCount == 1) && isNumberValue(args[0]) )
673 p_plugin->playlist_delete_item(numberValue(args[0]),&ex);
674 RETURN_ON_EXCEPTION(this,ex);
675 VOID_TO_NPVARIANT(result);
676 return INVOKERESULT_NO_ERROR;
678 return INVOKERESULT_NO_SUCH_METHOD;
683 return INVOKERESULT_GENERIC_ERROR;
687 ** implementation of libvlc playlist object
690 LibvlcPlaylistNPObject::~LibvlcPlaylistNPObject()
692 // Why the isValid()?
693 if( isValid() && playlistItemsObj )
694 NPN_ReleaseObject(playlistItemsObj);
697 const NPUTF8 * const LibvlcPlaylistNPObject::propertyNames[] =
699 "itemCount", /* deprecated */
703 COUNTNAMES(LibvlcPlaylistNPObject,propertyCount,propertyNames);
705 enum LibvlcPlaylistNPObjectPropertyIds
707 ID_playlist_itemcount,
708 ID_playlist_isplaying,
712 RuntimeNPObject::InvokeResult
713 LibvlcPlaylistNPObject::getProperty(int index, NPVariant &result)
715 /* is plugin still running */
716 if( isPluginRunning() )
718 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
722 case ID_playlist_itemcount: /* deprecated */
724 int val = p_plugin->playlist_count();
725 INT32_TO_NPVARIANT(val, result);
726 return INVOKERESULT_NO_ERROR;
728 case ID_playlist_isplaying:
730 int val = p_plugin->playlist_isplaying();
731 BOOLEAN_TO_NPVARIANT(val, result);
732 return INVOKERESULT_NO_ERROR;
734 case ID_playlist_items:
736 InstantObj<LibvlcPlaylistItemsNPObject>( playlistItemsObj );
737 OBJECT_TO_NPVARIANT(NPN_RetainObject(playlistItemsObj), result);
738 return INVOKERESULT_NO_ERROR;
744 return INVOKERESULT_GENERIC_ERROR;
747 const NPUTF8 * const LibvlcPlaylistNPObject::methodNames[] =
756 "clear", /* deprecated */
757 "removeItem", /* deprecated */
759 COUNTNAMES(LibvlcPlaylistNPObject,methodCount,methodNames);
761 enum LibvlcPlaylistNPObjectMethodIds
765 ID_playlist_playItem,
766 ID_playlist_togglepause,
771 ID_playlist_removeitem
774 RuntimeNPObject::InvokeResult
775 LibvlcPlaylistNPObject::invoke(int index, const NPVariant *args,
776 uint32_t argCount, NPVariant &result)
778 /* is plugin still running */
779 if( isPluginRunning() )
781 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
782 libvlc_exception_t ex;
783 libvlc_exception_init(&ex);
787 // XXX FIXME this needs squashing into something much smaller
788 case ID_playlist_add:
790 if( (argCount < 1) || (argCount > 3) )
791 return INVOKERESULT_NO_SUCH_METHOD;
792 if( !NPVARIANT_IS_STRING(args[0]) )
793 return INVOKERESULT_NO_SUCH_METHOD;
796 if( NPVARIANT_IS_NULL(args[0]) )
797 return INVOKERESULT_NO_SUCH_METHOD;
799 char *s = stringValue(NPVARIANT_TO_STRING(args[0]));
801 return INVOKERESULT_OUT_OF_MEMORY;
803 char *url = p_plugin->getAbsoluteURL(s);
807 // problem with combining url, use argument
812 // grab name if available
815 if( NPVARIANT_IS_NULL(args[1]) )
819 else if( NPVARIANT_IS_STRING(args[1]) )
821 name = stringValue(NPVARIANT_TO_STRING(args[1]));
826 return INVOKERESULT_INVALID_VALUE;
831 char** ppsz_options = NULL;
833 // grab options if available
836 if( NPVARIANT_IS_NULL(args[2]) )
840 else if( NPVARIANT_IS_STRING(args[2]) )
842 parseOptions(NPVARIANT_TO_STRING(args[2]),
843 &i_options, &ppsz_options);
846 else if( NPVARIANT_IS_OBJECT(args[2]) )
848 parseOptions(NPVARIANT_TO_OBJECT(args[2]),
849 &i_options, &ppsz_options);
855 return INVOKERESULT_INVALID_VALUE;
859 int item = p_plugin->playlist_add_extended_untrusted(url, name,
860 i_options, const_cast<const char **>(ppsz_options), &ex);
863 for( int i=0; i< i_options; ++i )
865 free(ppsz_options[i]);
869 RETURN_ON_EXCEPTION(this,ex);
870 INT32_TO_NPVARIANT(item, result);
871 return INVOKERESULT_NO_ERROR;
873 case ID_playlist_play:
876 p_plugin->playlist_play(&ex);
877 RETURN_ON_EXCEPTION(this,ex);
878 VOID_TO_NPVARIANT(result);
879 return INVOKERESULT_NO_ERROR;
881 return INVOKERESULT_NO_SUCH_METHOD;
882 case ID_playlist_playItem:
883 if( (argCount == 1) && isNumberValue(args[0]) )
885 p_plugin->playlist_play_item(numberValue(args[0]),&ex);
886 RETURN_ON_EXCEPTION(this,ex);
887 VOID_TO_NPVARIANT(result);
888 return INVOKERESULT_NO_ERROR;
890 return INVOKERESULT_NO_SUCH_METHOD;
891 case ID_playlist_togglepause:
894 p_plugin->playlist_pause(&ex);
895 RETURN_ON_EXCEPTION(this,ex);
896 VOID_TO_NPVARIANT(result);
897 return INVOKERESULT_NO_ERROR;
899 return INVOKERESULT_NO_SUCH_METHOD;
900 case ID_playlist_stop:
903 p_plugin->playlist_stop();
904 VOID_TO_NPVARIANT(result);
905 return INVOKERESULT_NO_ERROR;
907 return INVOKERESULT_NO_SUCH_METHOD;
908 case ID_playlist_next:
911 p_plugin->playlist_next(&ex);
912 RETURN_ON_EXCEPTION(this,ex);
913 VOID_TO_NPVARIANT(result);
914 return INVOKERESULT_NO_ERROR;
916 return INVOKERESULT_NO_SUCH_METHOD;
917 case ID_playlist_prev:
920 p_plugin->playlist_prev(&ex);
921 RETURN_ON_EXCEPTION(this,ex);
922 VOID_TO_NPVARIANT(result);
923 return INVOKERESULT_NO_ERROR;
925 return INVOKERESULT_NO_SUCH_METHOD;
926 case ID_playlist_clear: /* deprecated */
929 p_plugin->playlist_clear(&ex);
930 RETURN_ON_EXCEPTION(this,ex);
931 VOID_TO_NPVARIANT(result);
932 return INVOKERESULT_NO_ERROR;
934 return INVOKERESULT_NO_SUCH_METHOD;
935 case ID_playlist_removeitem: /* deprecated */
936 if( (argCount == 1) && isNumberValue(args[0]) )
938 p_plugin->playlist_delete_item(numberValue(args[0]), &ex);
939 RETURN_ON_EXCEPTION(this,ex);
940 VOID_TO_NPVARIANT(result);
941 return INVOKERESULT_NO_ERROR;
943 return INVOKERESULT_NO_SUCH_METHOD;
948 return INVOKERESULT_GENERIC_ERROR;
951 // XXX FIXME The new playlist_add creates a media instance and feeds it
952 // XXX FIXME these options one at a time, so this hunk of code does lots
953 // XXX FIXME of unnecessairy work. Break out something that can do one
954 // XXX FIXME option at a time and doesn't need to realloc().
955 // XXX FIXME Same for the other version of parseOptions.
957 void LibvlcPlaylistNPObject::parseOptions(const NPString &nps,
958 int *i_options, char*** ppsz_options)
962 char *s = stringValue(nps);
967 char **options = (char **)malloc(capacity*sizeof(char *));
972 char *end = val + nps.utf8length;
975 // skip leading blanks
977 && ((*val == ' ' ) || (*val == '\t')) )
981 // skip till we get a blank character
987 if( ('\'' == c) || ('"' == c) )
989 // skip till end of string
990 while( (val < end) && (*(val++) != c ) );
996 if( nOptions == capacity )
999 char **moreOptions = (char **)realloc(options, capacity*sizeof(char*));
1002 /* failed to allocate more memory */
1004 /* return what we got so far */
1005 *i_options = nOptions;
1006 *ppsz_options = options;
1009 options = moreOptions;
1012 options[nOptions++] = strdup(start);
1015 // must be end of string
1018 *i_options = nOptions;
1019 *ppsz_options = options;
1026 // XXX FIXME See comment at the other parseOptions variant.
1027 void LibvlcPlaylistNPObject::parseOptions(NPObject *obj, int *i_options,
1028 char*** ppsz_options)
1030 /* WARNING: Safari does not implement NPN_HasProperty/NPN_HasMethod */
1034 /* we are expecting to have a Javascript Array object */
1035 NPIdentifier propId = NPN_GetStringIdentifier("length");
1036 if( NPN_GetProperty(_instance, obj, propId, &value) )
1038 int count = numberValue(value);
1039 NPN_ReleaseVariantValue(&value);
1044 char **options = (char **)malloc(capacity*sizeof(char *));
1049 while( nOptions < count )
1051 propId = NPN_GetIntIdentifier(nOptions);
1052 if( ! NPN_GetProperty(_instance, obj, propId, &value) )
1053 /* return what we got so far */
1056 if( ! NPVARIANT_IS_STRING(value) )
1058 /* return what we got so far */
1059 NPN_ReleaseVariantValue(&value);
1063 if( nOptions == capacity )
1066 char **moreOptions = (char **)realloc(options, capacity*sizeof(char*));
1069 /* failed to allocate more memory */
1070 NPN_ReleaseVariantValue(&value);
1071 /* return what we got so far */
1072 *i_options = nOptions;
1073 *ppsz_options = options;
1076 options = moreOptions;
1079 options[nOptions++] = stringValue(value);
1080 NPN_ReleaseVariantValue(&value);
1082 *i_options = nOptions;
1083 *ppsz_options = options;
1090 ** implementation of libvlc subtitle object
1093 const NPUTF8 * const LibvlcSubtitleNPObject::propertyNames[] =
1099 enum LibvlcSubtitleNPObjectPropertyIds
1104 COUNTNAMES(LibvlcSubtitleNPObject,propertyCount,propertyNames);
1106 RuntimeNPObject::InvokeResult
1107 LibvlcSubtitleNPObject::getProperty(int index, NPVariant &result)
1109 /* is plugin still running */
1110 if( isPluginRunning() )
1112 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1113 libvlc_exception_t ex;
1114 libvlc_exception_init(&ex);
1116 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1117 RETURN_ON_EXCEPTION(this,ex);
1121 case ID_subtitle_track:
1123 /* get the current subtitle ID */
1124 int i_spu = libvlc_video_get_spu(p_md, &ex);
1125 RETURN_ON_EXCEPTION(this,ex);
1127 INT32_TO_NPVARIANT(i_spu, result);
1128 return INVOKERESULT_NO_ERROR;
1130 case ID_subtitle_count:
1132 /* get the number of subtitles available */
1133 int i_spu = libvlc_video_get_spu_count(p_md, &ex);
1134 RETURN_ON_EXCEPTION(this,ex);
1136 INT32_TO_NPVARIANT(i_spu, result);
1137 return INVOKERESULT_NO_ERROR;
1141 return INVOKERESULT_GENERIC_ERROR;
1144 RuntimeNPObject::InvokeResult
1145 LibvlcSubtitleNPObject::setProperty(int index, const NPVariant &value)
1147 /* is plugin still running */
1148 if( isPluginRunning() )
1150 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1151 libvlc_exception_t ex;
1152 libvlc_exception_init(&ex);
1154 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1155 RETURN_ON_EXCEPTION(this,ex);
1159 case ID_subtitle_track:
1161 if( isNumberValue(value) )
1163 /* set the new subtitle track to show */
1164 libvlc_video_set_spu(p_md, numberValue(value), &ex);
1165 RETURN_ON_EXCEPTION(this,ex);
1167 return INVOKERESULT_NO_ERROR;
1169 return INVOKERESULT_INVALID_VALUE;
1173 return INVOKERESULT_GENERIC_ERROR;
1176 const NPUTF8 * const LibvlcSubtitleNPObject::methodNames[] =
1180 COUNTNAMES(LibvlcSubtitleNPObject,methodCount,methodNames);
1182 enum LibvlcSubtitleNPObjectMethodIds
1184 ID_subtitle_description
1187 RuntimeNPObject::InvokeResult
1188 LibvlcSubtitleNPObject::invoke(int index, const NPVariant *args,
1189 uint32_t argCount, NPVariant &result)
1191 /* is plugin still running */
1192 if( isPluginRunning() )
1194 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1195 libvlc_exception_t ex;
1196 libvlc_exception_init(&ex);
1198 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1199 RETURN_ON_EXCEPTION(this,ex);
1203 case ID_subtitle_description:
1208 int i_spuID, i_limit, i;
1209 libvlc_track_description_t *p_spuDesc;
1211 /* get subtitles description */
1212 p_spuDesc = libvlc_video_get_spu_description(p_md, &ex);
1213 RETURN_ON_EXCEPTION(this,ex);
1215 return INVOKERESULT_GENERIC_ERROR;
1217 /* get the number of subtitle available */
1218 i_limit = libvlc_video_get_spu_count(p_md, &ex);
1219 RETURN_ON_EXCEPTION(this,ex);
1221 /* check if a number is given by the user
1222 * and get the subtitle number */
1223 if( isNumberValue(args[0]) )
1224 i_spuID = numberValue(args[0]);
1226 return INVOKERESULT_INVALID_VALUE;
1228 /* if bad number is given return invalid value */
1229 if ( ( i_spuID > ( i_limit -1 ) ) || ( i_spuID < 0 ) )
1230 return INVOKERESULT_INVALID_VALUE;
1232 /* get the good spuDesc */
1233 for( i = 0 ; i < i_spuID ; i++ )
1235 p_spuDesc = p_spuDesc->p_next;
1237 psz_name = p_spuDesc->psz_name;
1239 /* return the name of the track chosen */
1240 return invokeResultString(psz_name, result);
1242 return INVOKERESULT_NO_SUCH_METHOD;
1245 return INVOKERESULT_NO_SUCH_METHOD;
1248 return INVOKERESULT_GENERIC_ERROR;
1252 ** implementation of libvlc video object
1255 const NPUTF8 * const LibvlcVideoNPObject::propertyNames[] =
1268 enum LibvlcVideoNPObjectPropertyIds
1270 ID_video_fullscreen,
1273 ID_video_aspectratio,
1280 COUNTNAMES(LibvlcVideoNPObject,propertyCount,propertyNames);
1282 RuntimeNPObject::InvokeResult
1283 LibvlcVideoNPObject::getProperty(int index, NPVariant &result)
1285 /* is plugin still running */
1286 if( isPluginRunning() )
1288 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1289 libvlc_exception_t ex;
1290 libvlc_exception_init(&ex);
1292 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1293 RETURN_ON_EXCEPTION(this,ex);
1297 case ID_video_fullscreen:
1299 int val = p_plugin->get_fullscreen(&ex);
1300 RETURN_ON_EXCEPTION(this,ex);
1301 BOOLEAN_TO_NPVARIANT(val, result);
1302 return INVOKERESULT_NO_ERROR;
1304 case ID_video_height:
1306 int val = libvlc_video_get_height(p_md, &ex);
1307 RETURN_ON_EXCEPTION(this,ex);
1308 INT32_TO_NPVARIANT(val, result);
1309 return INVOKERESULT_NO_ERROR;
1311 case ID_video_width:
1313 int val = libvlc_video_get_width(p_md, &ex);
1314 RETURN_ON_EXCEPTION(this,ex);
1315 INT32_TO_NPVARIANT(val, result);
1316 return INVOKERESULT_NO_ERROR;
1318 case ID_video_aspectratio:
1320 NPUTF8 *psz_aspect = libvlc_video_get_aspect_ratio(p_md, &ex);
1321 RETURN_ON_EXCEPTION(this,ex);
1323 return INVOKERESULT_GENERIC_ERROR;
1325 STRINGZ_TO_NPVARIANT(psz_aspect, result);
1326 return INVOKERESULT_NO_ERROR;
1328 case ID_video_subtitle:
1330 int i_spu = libvlc_video_get_spu(p_md, &ex);
1331 RETURN_ON_EXCEPTION(this,ex);
1332 INT32_TO_NPVARIANT(i_spu, result);
1333 return INVOKERESULT_NO_ERROR;
1337 NPUTF8 *psz_geometry = libvlc_video_get_crop_geometry(p_md, &ex);
1338 RETURN_ON_EXCEPTION(this,ex);
1340 return INVOKERESULT_GENERIC_ERROR;
1342 STRINGZ_TO_NPVARIANT(psz_geometry, result);
1343 return INVOKERESULT_NO_ERROR;
1345 case ID_video_teletext:
1347 /* int i_page = libvlc_video_get_teletext(p_md, &ex);
1348 RETURN_ON_EXCEPTION(this,ex);
1349 INT32_TO_NPVARIANT(i_page, result);
1350 return INVOKERESULT_NO_ERROR;
1352 return INVOKERESULT_NO_SUCH_METHOD;
1354 case ID_video_marquee:
1356 InstantObj<LibvlcMarqueeNPObject>( marqueeObj );
1357 OBJECT_TO_NPVARIANT(NPN_RetainObject(marqueeObj), result);
1358 return INVOKERESULT_NO_ERROR;
1362 InstantObj<LibvlcLogoNPObject>( logoObj );
1363 OBJECT_TO_NPVARIANT(NPN_RetainObject(logoObj), result);
1364 return INVOKERESULT_NO_ERROR;
1368 return INVOKERESULT_GENERIC_ERROR;
1371 RuntimeNPObject::InvokeResult
1372 LibvlcVideoNPObject::setProperty(int index, const NPVariant &value)
1374 /* is plugin still running */
1375 if( isPluginRunning() )
1377 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1378 libvlc_exception_t ex;
1379 libvlc_exception_init(&ex);
1381 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1382 RETURN_ON_EXCEPTION(this,ex);
1386 case ID_video_fullscreen:
1388 if( ! NPVARIANT_IS_BOOLEAN(value) )
1390 return INVOKERESULT_INVALID_VALUE;
1393 int val = NPVARIANT_TO_BOOLEAN(value);
1394 p_plugin->set_fullscreen(val, &ex);
1395 RETURN_ON_EXCEPTION(this,ex);
1396 return INVOKERESULT_NO_ERROR;
1398 case ID_video_aspectratio:
1400 char *psz_aspect = NULL;
1402 if( ! NPVARIANT_IS_STRING(value) )
1404 return INVOKERESULT_INVALID_VALUE;
1407 psz_aspect = stringValue(NPVARIANT_TO_STRING(value));
1410 return INVOKERESULT_GENERIC_ERROR;
1413 libvlc_video_set_aspect_ratio(p_md, psz_aspect, &ex);
1415 RETURN_ON_EXCEPTION(this,ex);
1417 return INVOKERESULT_NO_ERROR;
1419 case ID_video_subtitle:
1421 if( isNumberValue(value) )
1423 libvlc_video_set_spu(p_md, numberValue(value), &ex);
1424 RETURN_ON_EXCEPTION(this,ex);
1426 return INVOKERESULT_NO_ERROR;
1428 return INVOKERESULT_INVALID_VALUE;
1432 char *psz_geometry = NULL;
1434 if( ! NPVARIANT_IS_STRING(value) )
1436 return INVOKERESULT_INVALID_VALUE;
1439 psz_geometry = stringValue(NPVARIANT_TO_STRING(value));
1442 return INVOKERESULT_GENERIC_ERROR;
1445 libvlc_video_set_crop_geometry(p_md, psz_geometry, &ex);
1447 RETURN_ON_EXCEPTION(this,ex);
1449 return INVOKERESULT_NO_ERROR;
1451 case ID_video_teletext:
1453 if( isNumberValue(value) )
1456 libvlc_video_set_teletext(p_md, numberValue(value), &ex);
1457 RETURN_ON_EXCEPTION(this,ex);
1459 return INVOKERESULT_NO_ERROR;
1461 return INVOKERESULT_NO_SUCH_METHOD;
1463 return INVOKERESULT_INVALID_VALUE;
1467 return INVOKERESULT_GENERIC_ERROR;
1470 const NPUTF8 * const LibvlcVideoNPObject::methodNames[] =
1474 "deinterlaceEnable",
1475 "deinterlaceDisable"
1477 COUNTNAMES(LibvlcVideoNPObject,methodCount,methodNames);
1479 enum LibvlcVideoNPObjectMethodIds
1481 ID_video_togglefullscreen,
1482 ID_video_toggleteletext,
1483 ID_video_deinterlaceenable,
1484 ID_video_deinterlacedisable
1487 RuntimeNPObject::InvokeResult
1488 LibvlcVideoNPObject::invoke(int index, const NPVariant *args,
1489 uint32_t argCount, NPVariant &result)
1491 /* is plugin still running */
1492 if( isPluginRunning() )
1494 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1495 libvlc_exception_t ex;
1496 libvlc_exception_init(&ex);
1498 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1499 RETURN_ON_EXCEPTION(this,ex);
1503 case ID_video_togglefullscreen:
1507 p_plugin->toggle_fullscreen(&ex);
1508 RETURN_ON_EXCEPTION(this,ex);
1509 VOID_TO_NPVARIANT(result);
1510 return INVOKERESULT_NO_ERROR;
1512 return INVOKERESULT_NO_SUCH_METHOD;
1514 case ID_video_toggleteletext:
1518 libvlc_toggle_teletext(p_md, &ex);
1519 RETURN_ON_EXCEPTION(this,ex);
1520 VOID_TO_NPVARIANT(result);
1521 return INVOKERESULT_NO_ERROR;
1523 return INVOKERESULT_NO_SUCH_METHOD;
1525 case ID_video_deinterlacedisable:
1527 libvlc_video_set_deinterlace(p_md, 0, "", &ex);
1528 RETURN_ON_EXCEPTION(this,ex);
1529 return INVOKERESULT_NO_ERROR;
1531 case ID_video_deinterlaceenable:
1535 if( NPVARIANT_IS_STRING( args[0] ) )
1537 /* get deinterlace mode from the user */
1538 char *psz_mode = stringValue( NPVARIANT_TO_STRING( args[0] ) );
1539 /* enable deinterlace filter if possible */
1540 libvlc_video_set_deinterlace(p_md, 1, psz_mode, &ex);
1542 RETURN_ON_EXCEPTION(this,ex);
1543 return INVOKERESULT_NO_ERROR;
1547 return INVOKERESULT_INVALID_VALUE;
1552 return INVOKERESULT_NO_SUCH_METHOD;
1555 return INVOKERESULT_GENERIC_ERROR;
1559 ** implementation of libvlc marquee object
1562 const NPUTF8 * const LibvlcMarqueeNPObject::propertyNames[] =
1575 enum LibvlcMarqueeNPObjectPropertyIds
1579 ID_marquee_position,
1588 COUNTNAMES(LibvlcMarqueeNPObject,propertyCount,propertyNames);
1590 static const unsigned char marquee_idx[] = {
1591 libvlc_marquee_Color,
1592 libvlc_marquee_Opacity,
1593 libvlc_marquee_Position,
1594 libvlc_marquee_Refresh,
1595 libvlc_marquee_Size,
1597 libvlc_marquee_Timeout,
1602 RuntimeNPObject::InvokeResult
1603 LibvlcMarqueeNPObject::getProperty(int index, NPVariant &result)
1607 if( !isPluginRunning() )
1608 return INVOKERESULT_GENERIC_ERROR;
1610 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1611 libvlc_exception_t ex;
1612 libvlc_exception_init(&ex);
1614 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1615 RETURN_ON_EXCEPTION(this,ex);
1619 case ID_marquee_color:
1620 case ID_marquee_opacity:
1621 case ID_marquee_refresh:
1622 case ID_marquee_timeout:
1623 case ID_marquee_size:
1627 libvlc_video_get_marquee_int(p_md, marquee_idx[index], &ex),
1629 RETURN_ON_EXCEPTION(this,ex);
1630 return INVOKERESULT_NO_ERROR;
1632 case ID_marquee_position:
1633 STRINGZ_TO_NPVARIANT( position_bynumber(
1634 libvlc_video_get_marquee_int(p_md, libvlc_marquee_Position, &ex) ),
1637 RETURN_ON_EXCEPTION(this,ex);
1640 case ID_marquee_text:
1641 psz = libvlc_video_get_marquee_string(p_md, libvlc_marquee_Text, &ex);
1644 STRINGZ_TO_NPVARIANT(psz, result);
1645 return INVOKERESULT_NO_ERROR;
1649 return INVOKERESULT_GENERIC_ERROR;
1652 RuntimeNPObject::InvokeResult
1653 LibvlcMarqueeNPObject::setProperty(int index, const NPVariant &value)
1657 if( !isPluginRunning() )
1658 return INVOKERESULT_GENERIC_ERROR;
1660 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1661 libvlc_exception_t ex;
1662 libvlc_exception_init(&ex);
1663 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1664 RETURN_ON_EXCEPTION(this,ex);
1668 case ID_marquee_color:
1669 case ID_marquee_opacity:
1670 case ID_marquee_refresh:
1671 case ID_marquee_timeout:
1674 if( NPVARIANT_IS_INT32( value ) )
1676 libvlc_video_set_marquee_int(p_md, marquee_idx[index],
1677 NPVARIANT_TO_INT32( value ), &ex);
1678 RETURN_ON_EXCEPTION(this,ex);
1679 return INVOKERESULT_NO_ERROR;
1683 case ID_marquee_position:
1684 if( !NPVARIANT_IS_STRING(value) ||
1685 !position_byname( NPVARIANT_TO_STRING(value).utf8characters, i ) )
1686 return INVOKERESULT_INVALID_VALUE;
1688 libvlc_video_set_marquee_int(p_md, libvlc_marquee_Position, i, &ex);
1689 RETURN_ON_EXCEPTION(this,ex);
1690 return INVOKERESULT_NO_ERROR;
1692 case ID_marquee_text:
1693 if( NPVARIANT_IS_STRING( value ) )
1695 char *psz_text = stringValue( NPVARIANT_TO_STRING( value ) );
1696 libvlc_video_set_marquee_string(p_md, libvlc_marquee_Text,
1699 RETURN_ON_EXCEPTION(this,ex);
1700 return INVOKERESULT_NO_ERROR;
1704 return INVOKERESULT_NO_SUCH_METHOD;
1707 const NPUTF8 * const LibvlcMarqueeNPObject::methodNames[] =
1712 COUNTNAMES(LibvlcMarqueeNPObject,methodCount,methodNames);
1714 enum LibvlcMarqueeNPObjectMethodIds
1720 RuntimeNPObject::InvokeResult
1721 LibvlcMarqueeNPObject::invoke(int index, const NPVariant *args,
1722 uint32_t argCount, NPVariant &result)
1724 if( !isPluginRunning() )
1725 return INVOKERESULT_GENERIC_ERROR;
1727 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1728 libvlc_exception_t ex;
1729 libvlc_exception_init(&ex);
1731 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1732 RETURN_ON_EXCEPTION(this,ex);
1736 case ID_marquee_enable:
1737 case ID_marquee_disable:
1738 libvlc_video_set_marquee_int(p_md, libvlc_marquee_Enable,
1739 index!=ID_marquee_disable, &ex);
1740 RETURN_ON_EXCEPTION(this,ex);
1741 VOID_TO_NPVARIANT(result);
1742 return INVOKERESULT_NO_ERROR;
1744 return INVOKERESULT_NO_SUCH_METHOD;
1747 const NPUTF8 * const LibvlcLogoNPObject::propertyNames[] = {
1755 enum LibvlcLogoNPObjectPropertyIds {
1763 COUNTNAMES(LibvlcLogoNPObject,propertyCount,propertyNames);
1764 static const unsigned char logo_idx[] = {
1767 libvlc_logo_opacity,
1773 RuntimeNPObject::InvokeResult
1774 LibvlcLogoNPObject::getProperty(int index, NPVariant &result)
1776 if( !isPluginRunning() )
1777 return INVOKERESULT_GENERIC_ERROR;
1779 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1780 libvlc_exception_t ex;
1781 libvlc_exception_init(&ex);
1782 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1783 RETURN_ON_EXCEPTION(this,ex);
1788 case ID_logo_repeat:
1789 case ID_logo_opacity:
1794 libvlc_video_get_logo_int(p_md, logo_idx[index], &ex), result);
1796 RETURN_ON_EXCEPTION(this,ex);
1799 case ID_logo_position:
1800 STRINGZ_TO_NPVARIANT( position_bynumber(
1801 libvlc_video_get_logo_int(p_md, libvlc_logo_position, &ex) ),
1804 RETURN_ON_EXCEPTION(this,ex);
1807 return INVOKERESULT_GENERIC_ERROR;
1809 return INVOKERESULT_NO_ERROR;
1812 RuntimeNPObject::InvokeResult
1813 LibvlcLogoNPObject::setProperty(int index, const NPVariant &value)
1817 if( !isPluginRunning() )
1818 return INVOKERESULT_GENERIC_ERROR;
1820 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1821 libvlc_exception_t ex;
1822 libvlc_exception_init(&ex);
1824 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1825 RETURN_ON_EXCEPTION(this,ex);
1830 case ID_logo_repeat:
1831 case ID_logo_opacity:
1834 if( !NPVARIANT_IS_INT32(value) )
1835 return INVOKERESULT_INVALID_VALUE;
1837 libvlc_video_set_logo_int(p_md, logo_idx[index],
1838 NPVARIANT_TO_INT32( value ), &ex);
1840 RETURN_ON_EXCEPTION(this,ex);
1843 case ID_logo_position:
1844 if( !NPVARIANT_IS_STRING(value) ||
1845 !position_byname( NPVARIANT_TO_STRING(value).utf8characters, i ) )
1846 return INVOKERESULT_INVALID_VALUE;
1848 libvlc_video_set_logo_int(p_md, libvlc_logo_position, i, &ex);
1850 RETURN_ON_EXCEPTION(this,ex);
1853 return INVOKERESULT_GENERIC_ERROR;
1855 return INVOKERESULT_NO_ERROR;
1859 const NPUTF8 * const LibvlcLogoNPObject::methodNames[] = {
1864 enum LibvlcLogoNPObjectMethodIds {
1869 COUNTNAMES(LibvlcLogoNPObject,methodCount,methodNames);
1871 RuntimeNPObject::InvokeResult
1872 LibvlcLogoNPObject::invoke(int index, const NPVariant *args,
1873 uint32_t argCount, NPVariant &result)
1878 if( !isPluginRunning() )
1879 return INVOKERESULT_GENERIC_ERROR;
1881 libvlc_exception_t ex;
1882 libvlc_exception_init(&ex);
1883 libvlc_media_player_t *p_md = getPrivate<VlcPlugin>()->getMD(&ex);
1884 RETURN_ON_EXCEPTION(this,ex);
1888 case ID_logo_enable:
1889 case ID_logo_disable:
1891 return INVOKERESULT_GENERIC_ERROR;
1893 libvlc_video_set_logo_int(p_md, libvlc_logo_enable,
1894 index != ID_logo_disable, &ex);
1895 RETURN_ON_EXCEPTION(this,ex);
1896 VOID_TO_NPVARIANT(result);
1901 return INVOKERESULT_GENERIC_ERROR;
1903 for( len=0,i=0;i<argCount;++i )
1905 if( !NPVARIANT_IS_STRING(args[i]) )
1906 return INVOKERESULT_INVALID_VALUE;
1907 len+=NPVARIANT_TO_STRING(args[i]).utf8length+1;
1910 buf = (char *)malloc( len+1 );
1912 return INVOKERESULT_OUT_OF_MEMORY;
1914 for( h=buf,i=0;i<argCount;++i )
1917 len=NPVARIANT_TO_STRING(args[i]).utf8length;
1918 memcpy(h,NPVARIANT_TO_STRING(args[i]).utf8characters,len);
1923 libvlc_video_set_logo_string(p_md, libvlc_logo_file, buf, &ex);
1925 RETURN_ON_EXCEPTION(this,ex);
1926 VOID_TO_NPVARIANT(result);
1929 return INVOKERESULT_NO_ERROR;