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 LibvlcVideoNPObject::~LibvlcVideoNPObject()
1259 if( marqueeObj ) NPN_ReleaseObject(marqueeObj);
1260 if( logoObj ) NPN_ReleaseObject(logoObj);
1261 if( deintObj ) NPN_ReleaseObject(deintObj);
1265 const NPUTF8 * const LibvlcVideoNPObject::propertyNames[] =
1279 enum LibvlcVideoNPObjectPropertyIds
1281 ID_video_fullscreen,
1284 ID_video_aspectratio,
1290 ID_video_deinterlace,
1292 COUNTNAMES(LibvlcVideoNPObject,propertyCount,propertyNames);
1294 RuntimeNPObject::InvokeResult
1295 LibvlcVideoNPObject::getProperty(int index, NPVariant &result)
1297 /* is plugin still running */
1298 if( isPluginRunning() )
1300 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1301 libvlc_exception_t ex;
1302 libvlc_exception_init(&ex);
1304 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1305 RETURN_ON_EXCEPTION(this,ex);
1309 case ID_video_fullscreen:
1311 int val = p_plugin->get_fullscreen(&ex);
1312 RETURN_ON_EXCEPTION(this,ex);
1313 BOOLEAN_TO_NPVARIANT(val, result);
1314 return INVOKERESULT_NO_ERROR;
1316 case ID_video_height:
1318 int val = libvlc_video_get_height(p_md, &ex);
1319 RETURN_ON_EXCEPTION(this,ex);
1320 INT32_TO_NPVARIANT(val, result);
1321 return INVOKERESULT_NO_ERROR;
1323 case ID_video_width:
1325 int val = libvlc_video_get_width(p_md, &ex);
1326 RETURN_ON_EXCEPTION(this,ex);
1327 INT32_TO_NPVARIANT(val, result);
1328 return INVOKERESULT_NO_ERROR;
1330 case ID_video_aspectratio:
1332 NPUTF8 *psz_aspect = libvlc_video_get_aspect_ratio(p_md, &ex);
1333 RETURN_ON_EXCEPTION(this,ex);
1335 return INVOKERESULT_GENERIC_ERROR;
1337 STRINGZ_TO_NPVARIANT(psz_aspect, result);
1338 return INVOKERESULT_NO_ERROR;
1340 case ID_video_subtitle:
1342 int i_spu = libvlc_video_get_spu(p_md, &ex);
1343 RETURN_ON_EXCEPTION(this,ex);
1344 INT32_TO_NPVARIANT(i_spu, result);
1345 return INVOKERESULT_NO_ERROR;
1349 NPUTF8 *psz_geometry = libvlc_video_get_crop_geometry(p_md, &ex);
1350 RETURN_ON_EXCEPTION(this,ex);
1352 return INVOKERESULT_GENERIC_ERROR;
1354 STRINGZ_TO_NPVARIANT(psz_geometry, result);
1355 return INVOKERESULT_NO_ERROR;
1357 case ID_video_teletext:
1359 /* int i_page = libvlc_video_get_teletext(p_md, &ex);
1360 RETURN_ON_EXCEPTION(this,ex);
1361 INT32_TO_NPVARIANT(i_page, result);
1362 return INVOKERESULT_NO_ERROR;
1364 return INVOKERESULT_NO_SUCH_METHOD;
1366 case ID_video_marquee:
1368 InstantObj<LibvlcMarqueeNPObject>( marqueeObj );
1369 OBJECT_TO_NPVARIANT(NPN_RetainObject(marqueeObj), result);
1370 return INVOKERESULT_NO_ERROR;
1374 InstantObj<LibvlcLogoNPObject>( logoObj );
1375 OBJECT_TO_NPVARIANT(NPN_RetainObject(logoObj), result);
1376 return INVOKERESULT_NO_ERROR;
1378 case ID_video_deinterlace:
1380 InstantObj<LibvlcDeinterlaceNPObject>( deintObj );
1381 OBJECT_TO_NPVARIANT(NPN_RetainObject(deintObj), result);
1382 return INVOKERESULT_NO_ERROR;
1386 return INVOKERESULT_GENERIC_ERROR;
1389 RuntimeNPObject::InvokeResult
1390 LibvlcVideoNPObject::setProperty(int index, const NPVariant &value)
1392 /* is plugin still running */
1393 if( isPluginRunning() )
1395 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1396 libvlc_exception_t ex;
1397 libvlc_exception_init(&ex);
1399 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1400 RETURN_ON_EXCEPTION(this,ex);
1404 case ID_video_fullscreen:
1406 if( ! NPVARIANT_IS_BOOLEAN(value) )
1408 return INVOKERESULT_INVALID_VALUE;
1411 int val = NPVARIANT_TO_BOOLEAN(value);
1412 p_plugin->set_fullscreen(val, &ex);
1413 RETURN_ON_EXCEPTION(this,ex);
1414 return INVOKERESULT_NO_ERROR;
1416 case ID_video_aspectratio:
1418 char *psz_aspect = NULL;
1420 if( ! NPVARIANT_IS_STRING(value) )
1422 return INVOKERESULT_INVALID_VALUE;
1425 psz_aspect = stringValue(NPVARIANT_TO_STRING(value));
1428 return INVOKERESULT_GENERIC_ERROR;
1431 libvlc_video_set_aspect_ratio(p_md, psz_aspect, &ex);
1433 RETURN_ON_EXCEPTION(this,ex);
1435 return INVOKERESULT_NO_ERROR;
1437 case ID_video_subtitle:
1439 if( isNumberValue(value) )
1441 libvlc_video_set_spu(p_md, numberValue(value), &ex);
1442 RETURN_ON_EXCEPTION(this,ex);
1444 return INVOKERESULT_NO_ERROR;
1446 return INVOKERESULT_INVALID_VALUE;
1450 char *psz_geometry = NULL;
1452 if( ! NPVARIANT_IS_STRING(value) )
1454 return INVOKERESULT_INVALID_VALUE;
1457 psz_geometry = stringValue(NPVARIANT_TO_STRING(value));
1460 return INVOKERESULT_GENERIC_ERROR;
1463 libvlc_video_set_crop_geometry(p_md, psz_geometry, &ex);
1465 RETURN_ON_EXCEPTION(this,ex);
1467 return INVOKERESULT_NO_ERROR;
1469 case ID_video_teletext:
1471 if( isNumberValue(value) )
1474 libvlc_video_set_teletext(p_md, numberValue(value), &ex);
1475 RETURN_ON_EXCEPTION(this,ex);
1477 return INVOKERESULT_NO_ERROR;
1479 return INVOKERESULT_NO_SUCH_METHOD;
1481 return INVOKERESULT_INVALID_VALUE;
1485 return INVOKERESULT_GENERIC_ERROR;
1488 const NPUTF8 * const LibvlcVideoNPObject::methodNames[] =
1493 COUNTNAMES(LibvlcVideoNPObject,methodCount,methodNames);
1495 enum LibvlcVideoNPObjectMethodIds
1497 ID_video_togglefullscreen,
1498 ID_video_toggleteletext,
1501 RuntimeNPObject::InvokeResult
1502 LibvlcVideoNPObject::invoke(int index, const NPVariant *args,
1503 uint32_t argCount, NPVariant &result)
1505 /* is plugin still running */
1506 if( isPluginRunning() )
1508 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1509 libvlc_exception_t ex;
1510 libvlc_exception_init(&ex);
1512 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1513 RETURN_ON_EXCEPTION(this,ex);
1517 case ID_video_togglefullscreen:
1521 p_plugin->toggle_fullscreen(&ex);
1522 RETURN_ON_EXCEPTION(this,ex);
1523 VOID_TO_NPVARIANT(result);
1524 return INVOKERESULT_NO_ERROR;
1526 return INVOKERESULT_NO_SUCH_METHOD;
1528 case ID_video_toggleteletext:
1532 libvlc_toggle_teletext(p_md, &ex);
1533 RETURN_ON_EXCEPTION(this,ex);
1534 VOID_TO_NPVARIANT(result);
1535 return INVOKERESULT_NO_ERROR;
1537 return INVOKERESULT_NO_SUCH_METHOD;
1540 return INVOKERESULT_NO_SUCH_METHOD;
1543 return INVOKERESULT_GENERIC_ERROR;
1547 ** implementation of libvlc marquee object
1550 const NPUTF8 * const LibvlcMarqueeNPObject::propertyNames[] =
1563 enum LibvlcMarqueeNPObjectPropertyIds
1567 ID_marquee_position,
1576 COUNTNAMES(LibvlcMarqueeNPObject,propertyCount,propertyNames);
1578 static const unsigned char marquee_idx[] = {
1579 libvlc_marquee_Color,
1580 libvlc_marquee_Opacity,
1581 libvlc_marquee_Position,
1582 libvlc_marquee_Refresh,
1583 libvlc_marquee_Size,
1585 libvlc_marquee_Timeout,
1590 RuntimeNPObject::InvokeResult
1591 LibvlcMarqueeNPObject::getProperty(int index, NPVariant &result)
1595 if( !isPluginRunning() )
1596 return INVOKERESULT_GENERIC_ERROR;
1598 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1599 libvlc_exception_t ex;
1600 libvlc_exception_init(&ex);
1602 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1603 RETURN_ON_EXCEPTION(this,ex);
1607 case ID_marquee_color:
1608 case ID_marquee_opacity:
1609 case ID_marquee_refresh:
1610 case ID_marquee_timeout:
1611 case ID_marquee_size:
1615 libvlc_video_get_marquee_int(p_md, marquee_idx[index], &ex),
1617 RETURN_ON_EXCEPTION(this,ex);
1618 return INVOKERESULT_NO_ERROR;
1620 case ID_marquee_position:
1621 STRINGZ_TO_NPVARIANT( position_bynumber(
1622 libvlc_video_get_marquee_int(p_md, libvlc_marquee_Position, &ex) ),
1625 RETURN_ON_EXCEPTION(this,ex);
1628 case ID_marquee_text:
1629 psz = libvlc_video_get_marquee_string(p_md, libvlc_marquee_Text, &ex);
1632 STRINGZ_TO_NPVARIANT(psz, result);
1633 return INVOKERESULT_NO_ERROR;
1637 return INVOKERESULT_GENERIC_ERROR;
1640 RuntimeNPObject::InvokeResult
1641 LibvlcMarqueeNPObject::setProperty(int index, const NPVariant &value)
1645 if( !isPluginRunning() )
1646 return INVOKERESULT_GENERIC_ERROR;
1648 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1649 libvlc_exception_t ex;
1650 libvlc_exception_init(&ex);
1651 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1652 RETURN_ON_EXCEPTION(this,ex);
1656 case ID_marquee_color:
1657 case ID_marquee_opacity:
1658 case ID_marquee_refresh:
1659 case ID_marquee_timeout:
1662 if( NPVARIANT_IS_INT32( value ) )
1664 libvlc_video_set_marquee_int(p_md, marquee_idx[index],
1665 NPVARIANT_TO_INT32( value ), &ex);
1666 RETURN_ON_EXCEPTION(this,ex);
1667 return INVOKERESULT_NO_ERROR;
1671 case ID_marquee_position:
1672 if( !NPVARIANT_IS_STRING(value) ||
1673 !position_byname( NPVARIANT_TO_STRING(value).utf8characters, i ) )
1674 return INVOKERESULT_INVALID_VALUE;
1676 libvlc_video_set_marquee_int(p_md, libvlc_marquee_Position, i, &ex);
1677 RETURN_ON_EXCEPTION(this,ex);
1678 return INVOKERESULT_NO_ERROR;
1680 case ID_marquee_text:
1681 if( NPVARIANT_IS_STRING( value ) )
1683 char *psz_text = stringValue( NPVARIANT_TO_STRING( value ) );
1684 libvlc_video_set_marquee_string(p_md, libvlc_marquee_Text,
1687 RETURN_ON_EXCEPTION(this,ex);
1688 return INVOKERESULT_NO_ERROR;
1692 return INVOKERESULT_NO_SUCH_METHOD;
1695 const NPUTF8 * const LibvlcMarqueeNPObject::methodNames[] =
1700 COUNTNAMES(LibvlcMarqueeNPObject,methodCount,methodNames);
1702 enum LibvlcMarqueeNPObjectMethodIds
1708 RuntimeNPObject::InvokeResult
1709 LibvlcMarqueeNPObject::invoke(int index, const NPVariant *args,
1710 uint32_t argCount, NPVariant &result)
1712 if( !isPluginRunning() )
1713 return INVOKERESULT_GENERIC_ERROR;
1715 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1716 libvlc_exception_t ex;
1717 libvlc_exception_init(&ex);
1719 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1720 RETURN_ON_EXCEPTION(this,ex);
1724 case ID_marquee_enable:
1725 case ID_marquee_disable:
1726 libvlc_video_set_marquee_int(p_md, libvlc_marquee_Enable,
1727 index!=ID_marquee_disable, &ex);
1728 RETURN_ON_EXCEPTION(this,ex);
1729 VOID_TO_NPVARIANT(result);
1730 return INVOKERESULT_NO_ERROR;
1732 return INVOKERESULT_NO_SUCH_METHOD;
1735 const NPUTF8 * const LibvlcLogoNPObject::propertyNames[] = {
1743 enum LibvlcLogoNPObjectPropertyIds {
1751 COUNTNAMES(LibvlcLogoNPObject,propertyCount,propertyNames);
1752 static const unsigned char logo_idx[] = {
1755 libvlc_logo_opacity,
1761 RuntimeNPObject::InvokeResult
1762 LibvlcLogoNPObject::getProperty(int index, NPVariant &result)
1764 if( !isPluginRunning() )
1765 return INVOKERESULT_GENERIC_ERROR;
1767 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1768 libvlc_exception_t ex;
1769 libvlc_exception_init(&ex);
1770 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1771 RETURN_ON_EXCEPTION(this,ex);
1776 case ID_logo_repeat:
1777 case ID_logo_opacity:
1782 libvlc_video_get_logo_int(p_md, logo_idx[index], &ex), result);
1784 RETURN_ON_EXCEPTION(this,ex);
1787 case ID_logo_position:
1788 STRINGZ_TO_NPVARIANT( position_bynumber(
1789 libvlc_video_get_logo_int(p_md, libvlc_logo_position, &ex) ),
1792 RETURN_ON_EXCEPTION(this,ex);
1795 return INVOKERESULT_GENERIC_ERROR;
1797 return INVOKERESULT_NO_ERROR;
1800 RuntimeNPObject::InvokeResult
1801 LibvlcLogoNPObject::setProperty(int index, const NPVariant &value)
1805 if( !isPluginRunning() )
1806 return INVOKERESULT_GENERIC_ERROR;
1808 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1809 libvlc_exception_t ex;
1810 libvlc_exception_init(&ex);
1812 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1813 RETURN_ON_EXCEPTION(this,ex);
1818 case ID_logo_repeat:
1819 case ID_logo_opacity:
1822 if( !NPVARIANT_IS_INT32(value) )
1823 return INVOKERESULT_INVALID_VALUE;
1825 libvlc_video_set_logo_int(p_md, logo_idx[index],
1826 NPVARIANT_TO_INT32( value ), &ex);
1828 RETURN_ON_EXCEPTION(this,ex);
1831 case ID_logo_position:
1832 if( !NPVARIANT_IS_STRING(value) ||
1833 !position_byname( NPVARIANT_TO_STRING(value).utf8characters, i ) )
1834 return INVOKERESULT_INVALID_VALUE;
1836 libvlc_video_set_logo_int(p_md, libvlc_logo_position, i, &ex);
1838 RETURN_ON_EXCEPTION(this,ex);
1841 return INVOKERESULT_GENERIC_ERROR;
1843 return INVOKERESULT_NO_ERROR;
1847 const NPUTF8 * const LibvlcLogoNPObject::methodNames[] = {
1852 enum LibvlcLogoNPObjectMethodIds {
1857 COUNTNAMES(LibvlcLogoNPObject,methodCount,methodNames);
1859 RuntimeNPObject::InvokeResult
1860 LibvlcLogoNPObject::invoke(int index, const NPVariant *args,
1861 uint32_t argCount, NPVariant &result)
1866 if( !isPluginRunning() )
1867 return INVOKERESULT_GENERIC_ERROR;
1869 libvlc_exception_t ex;
1870 libvlc_exception_init(&ex);
1871 libvlc_media_player_t *p_md = getPrivate<VlcPlugin>()->getMD(&ex);
1872 RETURN_ON_EXCEPTION(this,ex);
1876 case ID_logo_enable:
1877 case ID_logo_disable:
1879 return INVOKERESULT_GENERIC_ERROR;
1881 libvlc_video_set_logo_int(p_md, libvlc_logo_enable,
1882 index != ID_logo_disable, &ex);
1883 RETURN_ON_EXCEPTION(this,ex);
1884 VOID_TO_NPVARIANT(result);
1889 return INVOKERESULT_GENERIC_ERROR;
1891 for( len=0,i=0;i<argCount;++i )
1893 if( !NPVARIANT_IS_STRING(args[i]) )
1894 return INVOKERESULT_INVALID_VALUE;
1895 len+=NPVARIANT_TO_STRING(args[i]).utf8length+1;
1898 buf = (char *)malloc( len+1 );
1900 return INVOKERESULT_OUT_OF_MEMORY;
1902 for( h=buf,i=0;i<argCount;++i )
1905 len=NPVARIANT_TO_STRING(args[i]).utf8length;
1906 memcpy(h,NPVARIANT_TO_STRING(args[i]).utf8characters,len);
1911 libvlc_video_set_logo_string(p_md, libvlc_logo_file, buf, &ex);
1913 RETURN_ON_EXCEPTION(this,ex);
1914 VOID_TO_NPVARIANT(result);
1917 return INVOKERESULT_NO_SUCH_METHOD;
1919 return INVOKERESULT_NO_ERROR;
1923 const NPUTF8 * const LibvlcDeinterlaceNPObject::propertyNames[] = {
1925 enum LibvlcDeinterlaceNPObjectPropertyIds {
1927 COUNTNAMES(LibvlcDeinterlaceNPObject,propertyCount,propertyNames);
1929 RuntimeNPObject::InvokeResult
1930 LibvlcDeinterlaceNPObject::getProperty(int index, NPVariant &result)
1932 return INVOKERESULT_GENERIC_ERROR;
1935 RuntimeNPObject::InvokeResult
1936 LibvlcDeinterlaceNPObject::setProperty(int index, const NPVariant &value)
1938 return INVOKERESULT_GENERIC_ERROR;
1942 const NPUTF8 * const LibvlcDeinterlaceNPObject::methodNames[] = {
1946 enum LibvlcDeinterlaceNPObjectMethodIds {
1950 COUNTNAMES(LibvlcDeinterlaceNPObject,methodCount,methodNames);
1952 RuntimeNPObject::InvokeResult
1953 LibvlcDeinterlaceNPObject::invoke(int index, const NPVariant *args,
1954 uint32_t argCount, NPVariant &result)
1958 if( !isPluginRunning() )
1959 return INVOKERESULT_GENERIC_ERROR;
1961 libvlc_exception_t ex;
1962 libvlc_exception_init(&ex);
1963 libvlc_media_player_t *p_md = getPrivate<VlcPlugin>()->getMD(&ex);
1964 RETURN_ON_EXCEPTION(this,ex);
1968 case ID_deint_disable:
1969 libvlc_video_set_deinterlace(p_md, 0, "", &ex);
1970 RETURN_ON_EXCEPTION(this,ex);
1973 case ID_deint_enable:
1974 if( argCount != 1 || !NPVARIANT_IS_STRING( args[0] ) )
1975 return INVOKERESULT_INVALID_VALUE;
1977 psz = stringValue( NPVARIANT_TO_STRING( args[0] ) );
1978 libvlc_video_set_deinterlace(p_md, 1, psz, &ex);
1980 RETURN_ON_EXCEPTION(this,ex);
1984 return INVOKERESULT_NO_SUCH_METHOD;
1986 return INVOKERESULT_NO_ERROR;