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, &ex);
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>();
619 libvlc_exception_t ex;
620 libvlc_exception_init(&ex);
624 case ID_playlistitems_count:
626 int val = p_plugin->playlist_count(&ex);
627 RETURN_ON_EXCEPTION(this,ex);
628 INT32_TO_NPVARIANT(val, result);
629 return INVOKERESULT_NO_ERROR;
635 return INVOKERESULT_GENERIC_ERROR;
638 const NPUTF8 * const LibvlcPlaylistItemsNPObject::methodNames[] =
643 COUNTNAMES(LibvlcPlaylistItemsNPObject,methodCount,methodNames);
645 enum LibvlcPlaylistItemsNPObjectMethodIds
647 ID_playlistitems_clear,
648 ID_playlistitems_remove,
651 RuntimeNPObject::InvokeResult
652 LibvlcPlaylistItemsNPObject::invoke(int index, const NPVariant *args,
653 uint32_t argCount, NPVariant &result)
655 /* is plugin still running */
656 if( isPluginRunning() )
658 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
659 libvlc_exception_t ex;
660 libvlc_exception_init(&ex);
664 case ID_playlistitems_clear:
667 p_plugin->playlist_clear(&ex);
668 RETURN_ON_EXCEPTION(this,ex);
669 VOID_TO_NPVARIANT(result);
670 return INVOKERESULT_NO_ERROR;
672 return INVOKERESULT_NO_SUCH_METHOD;
673 case ID_playlistitems_remove:
674 if( (argCount == 1) && isNumberValue(args[0]) )
676 p_plugin->playlist_delete_item(numberValue(args[0]),&ex);
677 RETURN_ON_EXCEPTION(this,ex);
678 VOID_TO_NPVARIANT(result);
679 return INVOKERESULT_NO_ERROR;
681 return INVOKERESULT_NO_SUCH_METHOD;
686 return INVOKERESULT_GENERIC_ERROR;
690 ** implementation of libvlc playlist object
693 LibvlcPlaylistNPObject::~LibvlcPlaylistNPObject()
695 // Why the isValid()?
696 if( isValid() && playlistItemsObj )
697 NPN_ReleaseObject(playlistItemsObj);
700 const NPUTF8 * const LibvlcPlaylistNPObject::propertyNames[] =
702 "itemCount", /* deprecated */
706 COUNTNAMES(LibvlcPlaylistNPObject,propertyCount,propertyNames);
708 enum LibvlcPlaylistNPObjectPropertyIds
710 ID_playlist_itemcount,
711 ID_playlist_isplaying,
715 RuntimeNPObject::InvokeResult
716 LibvlcPlaylistNPObject::getProperty(int index, NPVariant &result)
718 /* is plugin still running */
719 if( isPluginRunning() )
721 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
722 libvlc_exception_t ex;
723 libvlc_exception_init(&ex);
727 case ID_playlist_itemcount: /* deprecated */
729 int val = p_plugin->playlist_count(&ex);
730 RETURN_ON_EXCEPTION(this,ex);
731 INT32_TO_NPVARIANT(val, result);
732 return INVOKERESULT_NO_ERROR;
734 case ID_playlist_isplaying:
736 int val = p_plugin->playlist_isplaying(&ex);
737 RETURN_ON_EXCEPTION(this,ex);
738 BOOLEAN_TO_NPVARIANT(val, result);
739 return INVOKERESULT_NO_ERROR;
741 case ID_playlist_items:
743 InstantObj<LibvlcPlaylistItemsNPObject>( playlistItemsObj );
744 OBJECT_TO_NPVARIANT(NPN_RetainObject(playlistItemsObj), result);
745 return INVOKERESULT_NO_ERROR;
751 return INVOKERESULT_GENERIC_ERROR;
754 const NPUTF8 * const LibvlcPlaylistNPObject::methodNames[] =
763 "clear", /* deprecated */
764 "removeItem", /* deprecated */
766 COUNTNAMES(LibvlcPlaylistNPObject,methodCount,methodNames);
768 enum LibvlcPlaylistNPObjectMethodIds
772 ID_playlist_playItem,
773 ID_playlist_togglepause,
778 ID_playlist_removeitem
781 RuntimeNPObject::InvokeResult
782 LibvlcPlaylistNPObject::invoke(int index, const NPVariant *args,
783 uint32_t argCount, NPVariant &result)
785 /* is plugin still running */
786 if( isPluginRunning() )
788 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
789 libvlc_exception_t ex;
790 libvlc_exception_init(&ex);
794 // XXX FIXME this needs squashing into something much smaller
795 case ID_playlist_add:
797 if( (argCount < 1) || (argCount > 3) )
798 return INVOKERESULT_NO_SUCH_METHOD;
799 if( !NPVARIANT_IS_STRING(args[0]) )
800 return INVOKERESULT_NO_SUCH_METHOD;
803 if( NPVARIANT_IS_NULL(args[0]) )
804 return INVOKERESULT_NO_SUCH_METHOD;
806 char *s = stringValue(NPVARIANT_TO_STRING(args[0]));
808 return INVOKERESULT_OUT_OF_MEMORY;
810 char *url = p_plugin->getAbsoluteURL(s);
814 // problem with combining url, use argument
819 // grab name if available
822 if( NPVARIANT_IS_NULL(args[1]) )
826 else if( NPVARIANT_IS_STRING(args[1]) )
828 name = stringValue(NPVARIANT_TO_STRING(args[1]));
833 return INVOKERESULT_INVALID_VALUE;
838 char** ppsz_options = NULL;
840 // grab options if available
843 if( NPVARIANT_IS_NULL(args[2]) )
847 else if( NPVARIANT_IS_STRING(args[2]) )
849 parseOptions(NPVARIANT_TO_STRING(args[2]),
850 &i_options, &ppsz_options);
853 else if( NPVARIANT_IS_OBJECT(args[2]) )
855 parseOptions(NPVARIANT_TO_OBJECT(args[2]),
856 &i_options, &ppsz_options);
862 return INVOKERESULT_INVALID_VALUE;
866 int item = p_plugin->playlist_add_extended_untrusted(url, name,
867 i_options, const_cast<const char **>(ppsz_options), &ex);
870 for( int i=0; i< i_options; ++i )
872 free(ppsz_options[i]);
876 RETURN_ON_EXCEPTION(this,ex);
877 INT32_TO_NPVARIANT(item, result);
878 return INVOKERESULT_NO_ERROR;
880 case ID_playlist_play:
883 p_plugin->playlist_play(&ex);
884 RETURN_ON_EXCEPTION(this,ex);
885 VOID_TO_NPVARIANT(result);
886 return INVOKERESULT_NO_ERROR;
888 return INVOKERESULT_NO_SUCH_METHOD;
889 case ID_playlist_playItem:
890 if( (argCount == 1) && isNumberValue(args[0]) )
892 p_plugin->playlist_play_item(numberValue(args[0]),&ex);
893 RETURN_ON_EXCEPTION(this,ex);
894 VOID_TO_NPVARIANT(result);
895 return INVOKERESULT_NO_ERROR;
897 return INVOKERESULT_NO_SUCH_METHOD;
898 case ID_playlist_togglepause:
901 p_plugin->playlist_pause(&ex);
902 RETURN_ON_EXCEPTION(this,ex);
903 VOID_TO_NPVARIANT(result);
904 return INVOKERESULT_NO_ERROR;
906 return INVOKERESULT_NO_SUCH_METHOD;
907 case ID_playlist_stop:
910 p_plugin->playlist_stop(&ex);
911 RETURN_ON_EXCEPTION(this,ex);
912 VOID_TO_NPVARIANT(result);
913 return INVOKERESULT_NO_ERROR;
915 return INVOKERESULT_NO_SUCH_METHOD;
916 case ID_playlist_next:
919 p_plugin->playlist_next(&ex);
920 RETURN_ON_EXCEPTION(this,ex);
921 VOID_TO_NPVARIANT(result);
922 return INVOKERESULT_NO_ERROR;
924 return INVOKERESULT_NO_SUCH_METHOD;
925 case ID_playlist_prev:
928 p_plugin->playlist_prev(&ex);
929 RETURN_ON_EXCEPTION(this,ex);
930 VOID_TO_NPVARIANT(result);
931 return INVOKERESULT_NO_ERROR;
933 return INVOKERESULT_NO_SUCH_METHOD;
934 case ID_playlist_clear: /* deprecated */
937 p_plugin->playlist_clear(&ex);
938 RETURN_ON_EXCEPTION(this,ex);
939 VOID_TO_NPVARIANT(result);
940 return INVOKERESULT_NO_ERROR;
942 return INVOKERESULT_NO_SUCH_METHOD;
943 case ID_playlist_removeitem: /* deprecated */
944 if( (argCount == 1) && isNumberValue(args[0]) )
946 p_plugin->playlist_delete_item(numberValue(args[0]), &ex);
947 RETURN_ON_EXCEPTION(this,ex);
948 VOID_TO_NPVARIANT(result);
949 return INVOKERESULT_NO_ERROR;
951 return INVOKERESULT_NO_SUCH_METHOD;
956 return INVOKERESULT_GENERIC_ERROR;
959 // XXX FIXME The new playlist_add creates a media instance and feeds it
960 // XXX FIXME these options one at a time, so this hunk of code does lots
961 // XXX FIXME of unnecessairy work. Break out something that can do one
962 // XXX FIXME option at a time and doesn't need to realloc().
963 // XXX FIXME Same for the other version of parseOptions.
965 void LibvlcPlaylistNPObject::parseOptions(const NPString &nps,
966 int *i_options, char*** ppsz_options)
970 char *s = stringValue(nps);
975 char **options = (char **)malloc(capacity*sizeof(char *));
980 char *end = val + nps.utf8length;
983 // skip leading blanks
985 && ((*val == ' ' ) || (*val == '\t')) )
989 // skip till we get a blank character
995 if( ('\'' == c) || ('"' == c) )
997 // skip till end of string
998 while( (val < end) && (*(val++) != c ) );
1004 if( nOptions == capacity )
1007 char **moreOptions = (char **)realloc(options, capacity*sizeof(char*));
1010 /* failed to allocate more memory */
1012 /* return what we got so far */
1013 *i_options = nOptions;
1014 *ppsz_options = options;
1017 options = moreOptions;
1020 options[nOptions++] = strdup(start);
1023 // must be end of string
1026 *i_options = nOptions;
1027 *ppsz_options = options;
1034 // XXX FIXME See comment at the other parseOptions variant.
1035 void LibvlcPlaylistNPObject::parseOptions(NPObject *obj, int *i_options,
1036 char*** ppsz_options)
1038 /* WARNING: Safari does not implement NPN_HasProperty/NPN_HasMethod */
1042 /* we are expecting to have a Javascript Array object */
1043 NPIdentifier propId = NPN_GetStringIdentifier("length");
1044 if( NPN_GetProperty(_instance, obj, propId, &value) )
1046 int count = numberValue(value);
1047 NPN_ReleaseVariantValue(&value);
1052 char **options = (char **)malloc(capacity*sizeof(char *));
1057 while( nOptions < count )
1059 propId = NPN_GetIntIdentifier(nOptions);
1060 if( ! NPN_GetProperty(_instance, obj, propId, &value) )
1061 /* return what we got so far */
1064 if( ! NPVARIANT_IS_STRING(value) )
1066 /* return what we got so far */
1067 NPN_ReleaseVariantValue(&value);
1071 if( nOptions == capacity )
1074 char **moreOptions = (char **)realloc(options, capacity*sizeof(char*));
1077 /* failed to allocate more memory */
1078 NPN_ReleaseVariantValue(&value);
1079 /* return what we got so far */
1080 *i_options = nOptions;
1081 *ppsz_options = options;
1084 options = moreOptions;
1087 options[nOptions++] = stringValue(value);
1088 NPN_ReleaseVariantValue(&value);
1090 *i_options = nOptions;
1091 *ppsz_options = options;
1098 ** implementation of libvlc subtitle object
1101 const NPUTF8 * const LibvlcSubtitleNPObject::propertyNames[] =
1107 enum LibvlcSubtitleNPObjectPropertyIds
1112 COUNTNAMES(LibvlcSubtitleNPObject,propertyCount,propertyNames);
1114 RuntimeNPObject::InvokeResult
1115 LibvlcSubtitleNPObject::getProperty(int index, NPVariant &result)
1117 /* is plugin still running */
1118 if( isPluginRunning() )
1120 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1121 libvlc_exception_t ex;
1122 libvlc_exception_init(&ex);
1124 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1125 RETURN_ON_EXCEPTION(this,ex);
1129 case ID_subtitle_track:
1131 /* get the current subtitle ID */
1132 int i_spu = libvlc_video_get_spu(p_md, &ex);
1133 RETURN_ON_EXCEPTION(this,ex);
1135 INT32_TO_NPVARIANT(i_spu, result);
1136 return INVOKERESULT_NO_ERROR;
1138 case ID_subtitle_count:
1140 /* get the number of subtitles available */
1141 int i_spu = libvlc_video_get_spu_count(p_md, &ex);
1142 RETURN_ON_EXCEPTION(this,ex);
1144 INT32_TO_NPVARIANT(i_spu, result);
1145 return INVOKERESULT_NO_ERROR;
1149 return INVOKERESULT_GENERIC_ERROR;
1152 RuntimeNPObject::InvokeResult
1153 LibvlcSubtitleNPObject::setProperty(int index, const NPVariant &value)
1155 /* is plugin still running */
1156 if( isPluginRunning() )
1158 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1159 libvlc_exception_t ex;
1160 libvlc_exception_init(&ex);
1162 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1163 RETURN_ON_EXCEPTION(this,ex);
1167 case ID_subtitle_track:
1169 if( isNumberValue(value) )
1171 /* set the new subtitle track to show */
1172 libvlc_video_set_spu(p_md, numberValue(value), &ex);
1173 RETURN_ON_EXCEPTION(this,ex);
1175 return INVOKERESULT_NO_ERROR;
1177 return INVOKERESULT_INVALID_VALUE;
1181 return INVOKERESULT_GENERIC_ERROR;
1184 const NPUTF8 * const LibvlcSubtitleNPObject::methodNames[] =
1188 COUNTNAMES(LibvlcSubtitleNPObject,methodCount,methodNames);
1190 enum LibvlcSubtitleNPObjectMethodIds
1192 ID_subtitle_description
1195 RuntimeNPObject::InvokeResult
1196 LibvlcSubtitleNPObject::invoke(int index, const NPVariant *args,
1197 uint32_t argCount, NPVariant &result)
1199 /* is plugin still running */
1200 if( isPluginRunning() )
1202 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1203 libvlc_exception_t ex;
1204 libvlc_exception_init(&ex);
1206 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1207 RETURN_ON_EXCEPTION(this,ex);
1211 case ID_subtitle_description:
1216 int i_spuID, i_limit, i;
1217 libvlc_track_description_t *p_spuDesc;
1219 /* get subtitles description */
1220 p_spuDesc = libvlc_video_get_spu_description(p_md, &ex);
1221 RETURN_ON_EXCEPTION(this,ex);
1223 return INVOKERESULT_GENERIC_ERROR;
1225 /* get the number of subtitle available */
1226 i_limit = libvlc_video_get_spu_count(p_md, &ex);
1227 RETURN_ON_EXCEPTION(this,ex);
1229 /* check if a number is given by the user
1230 * and get the subtitle number */
1231 if( isNumberValue(args[0]) )
1232 i_spuID = numberValue(args[0]);
1234 return INVOKERESULT_INVALID_VALUE;
1236 /* if bad number is given return invalid value */
1237 if ( ( i_spuID > ( i_limit -1 ) ) || ( i_spuID < 0 ) )
1238 return INVOKERESULT_INVALID_VALUE;
1240 /* get the good spuDesc */
1241 for( i = 0 ; i < i_spuID ; i++ )
1243 p_spuDesc = p_spuDesc->p_next;
1245 psz_name = p_spuDesc->psz_name;
1247 /* return the name of the track chosen */
1248 return invokeResultString(psz_name, result);
1250 return INVOKERESULT_NO_SUCH_METHOD;
1253 return INVOKERESULT_NO_SUCH_METHOD;
1256 return INVOKERESULT_GENERIC_ERROR;
1260 ** implementation of libvlc video object
1263 const NPUTF8 * const LibvlcVideoNPObject::propertyNames[] =
1276 enum LibvlcVideoNPObjectPropertyIds
1278 ID_video_fullscreen,
1281 ID_video_aspectratio,
1288 COUNTNAMES(LibvlcVideoNPObject,propertyCount,propertyNames);
1290 RuntimeNPObject::InvokeResult
1291 LibvlcVideoNPObject::getProperty(int index, NPVariant &result)
1293 /* is plugin still running */
1294 if( isPluginRunning() )
1296 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1297 libvlc_exception_t ex;
1298 libvlc_exception_init(&ex);
1300 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1301 RETURN_ON_EXCEPTION(this,ex);
1305 case ID_video_fullscreen:
1307 int val = p_plugin->get_fullscreen(&ex);
1308 RETURN_ON_EXCEPTION(this,ex);
1309 BOOLEAN_TO_NPVARIANT(val, result);
1310 return INVOKERESULT_NO_ERROR;
1312 case ID_video_height:
1314 int val = libvlc_video_get_height(p_md, &ex);
1315 RETURN_ON_EXCEPTION(this,ex);
1316 INT32_TO_NPVARIANT(val, result);
1317 return INVOKERESULT_NO_ERROR;
1319 case ID_video_width:
1321 int val = libvlc_video_get_width(p_md, &ex);
1322 RETURN_ON_EXCEPTION(this,ex);
1323 INT32_TO_NPVARIANT(val, result);
1324 return INVOKERESULT_NO_ERROR;
1326 case ID_video_aspectratio:
1328 NPUTF8 *psz_aspect = libvlc_video_get_aspect_ratio(p_md, &ex);
1329 RETURN_ON_EXCEPTION(this,ex);
1331 return INVOKERESULT_GENERIC_ERROR;
1333 STRINGZ_TO_NPVARIANT(psz_aspect, result);
1334 return INVOKERESULT_NO_ERROR;
1336 case ID_video_subtitle:
1338 int i_spu = libvlc_video_get_spu(p_md, &ex);
1339 RETURN_ON_EXCEPTION(this,ex);
1340 INT32_TO_NPVARIANT(i_spu, result);
1341 return INVOKERESULT_NO_ERROR;
1345 NPUTF8 *psz_geometry = libvlc_video_get_crop_geometry(p_md, &ex);
1346 RETURN_ON_EXCEPTION(this,ex);
1348 return INVOKERESULT_GENERIC_ERROR;
1350 STRINGZ_TO_NPVARIANT(psz_geometry, result);
1351 return INVOKERESULT_NO_ERROR;
1353 case ID_video_teletext:
1355 int i_page = libvlc_video_get_teletext(p_md, &ex);
1356 RETURN_ON_EXCEPTION(this,ex);
1357 INT32_TO_NPVARIANT(i_page, result);
1358 return INVOKERESULT_NO_ERROR;
1360 case ID_video_marquee:
1362 InstantObj<LibvlcMarqueeNPObject>( marqueeObj );
1363 OBJECT_TO_NPVARIANT(NPN_RetainObject(marqueeObj), result);
1364 return INVOKERESULT_NO_ERROR;
1368 InstantObj<LibvlcLogoNPObject>( logoObj );
1369 OBJECT_TO_NPVARIANT(NPN_RetainObject(logoObj), result);
1370 return INVOKERESULT_NO_ERROR;
1374 return INVOKERESULT_GENERIC_ERROR;
1377 RuntimeNPObject::InvokeResult
1378 LibvlcVideoNPObject::setProperty(int index, const NPVariant &value)
1380 /* is plugin still running */
1381 if( isPluginRunning() )
1383 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1384 libvlc_exception_t ex;
1385 libvlc_exception_init(&ex);
1387 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1388 RETURN_ON_EXCEPTION(this,ex);
1392 case ID_video_fullscreen:
1394 if( ! NPVARIANT_IS_BOOLEAN(value) )
1396 return INVOKERESULT_INVALID_VALUE;
1399 int val = NPVARIANT_TO_BOOLEAN(value);
1400 p_plugin->set_fullscreen(val, &ex);
1401 RETURN_ON_EXCEPTION(this,ex);
1402 return INVOKERESULT_NO_ERROR;
1404 case ID_video_aspectratio:
1406 char *psz_aspect = NULL;
1408 if( ! NPVARIANT_IS_STRING(value) )
1410 return INVOKERESULT_INVALID_VALUE;
1413 psz_aspect = stringValue(NPVARIANT_TO_STRING(value));
1416 return INVOKERESULT_GENERIC_ERROR;
1419 libvlc_video_set_aspect_ratio(p_md, psz_aspect, &ex);
1421 RETURN_ON_EXCEPTION(this,ex);
1423 return INVOKERESULT_NO_ERROR;
1425 case ID_video_subtitle:
1427 if( isNumberValue(value) )
1429 libvlc_video_set_spu(p_md, numberValue(value), &ex);
1430 RETURN_ON_EXCEPTION(this,ex);
1432 return INVOKERESULT_NO_ERROR;
1434 return INVOKERESULT_INVALID_VALUE;
1438 char *psz_geometry = NULL;
1440 if( ! NPVARIANT_IS_STRING(value) )
1442 return INVOKERESULT_INVALID_VALUE;
1445 psz_geometry = stringValue(NPVARIANT_TO_STRING(value));
1448 return INVOKERESULT_GENERIC_ERROR;
1451 libvlc_video_set_crop_geometry(p_md, psz_geometry, &ex);
1453 RETURN_ON_EXCEPTION(this,ex);
1455 return INVOKERESULT_NO_ERROR;
1457 case ID_video_teletext:
1459 if( isNumberValue(value) )
1461 libvlc_video_set_teletext(p_md, numberValue(value), &ex);
1462 RETURN_ON_EXCEPTION(this,ex);
1464 return INVOKERESULT_NO_ERROR;
1466 return INVOKERESULT_INVALID_VALUE;
1470 return INVOKERESULT_GENERIC_ERROR;
1473 const NPUTF8 * const LibvlcVideoNPObject::methodNames[] =
1477 "deinterlaceEnable",
1478 "deinterlaceDisable"
1480 COUNTNAMES(LibvlcVideoNPObject,methodCount,methodNames);
1482 enum LibvlcVideoNPObjectMethodIds
1484 ID_video_togglefullscreen,
1485 ID_video_toggleteletext,
1486 ID_video_deinterlaceenable,
1487 ID_video_deinterlacedisable
1490 RuntimeNPObject::InvokeResult
1491 LibvlcVideoNPObject::invoke(int index, const NPVariant *args,
1492 uint32_t argCount, NPVariant &result)
1494 /* is plugin still running */
1495 if( isPluginRunning() )
1497 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1498 libvlc_exception_t ex;
1499 libvlc_exception_init(&ex);
1501 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1502 RETURN_ON_EXCEPTION(this,ex);
1506 case ID_video_togglefullscreen:
1510 p_plugin->toggle_fullscreen(&ex);
1511 RETURN_ON_EXCEPTION(this,ex);
1512 VOID_TO_NPVARIANT(result);
1513 return INVOKERESULT_NO_ERROR;
1515 return INVOKERESULT_NO_SUCH_METHOD;
1517 case ID_video_toggleteletext:
1521 libvlc_toggle_teletext(p_md, &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_deinterlacedisable:
1530 libvlc_video_set_deinterlace(p_md, 0, "", &ex);
1531 RETURN_ON_EXCEPTION(this,ex);
1532 return INVOKERESULT_NO_ERROR;
1534 case ID_video_deinterlaceenable:
1538 if( NPVARIANT_IS_STRING( args[0] ) )
1540 /* get deinterlace mode from the user */
1541 char *psz_mode = stringValue( NPVARIANT_TO_STRING( args[0] ) );
1542 /* enable deinterlace filter if possible */
1543 libvlc_video_set_deinterlace(p_md, 1, psz_mode, &ex);
1545 RETURN_ON_EXCEPTION(this,ex);
1546 return INVOKERESULT_NO_ERROR;
1550 return INVOKERESULT_INVALID_VALUE;
1555 return INVOKERESULT_NO_SUCH_METHOD;
1558 return INVOKERESULT_GENERIC_ERROR;
1562 ** implementation of libvlc marquee object
1565 const NPUTF8 * const LibvlcMarqueeNPObject::propertyNames[] =
1578 enum LibvlcMarqueeNPObjectPropertyIds
1582 ID_marquee_position,
1591 COUNTNAMES(LibvlcMarqueeNPObject,propertyCount,propertyNames);
1593 static const unsigned char marquee_idx[] = {
1594 libvlc_marquee_Color,
1595 libvlc_marquee_Opacity,
1596 libvlc_marquee_Position,
1597 libvlc_marquee_Refresh,
1598 libvlc_marquee_Size,
1600 libvlc_marquee_Timeout,
1605 RuntimeNPObject::InvokeResult
1606 LibvlcMarqueeNPObject::getProperty(int index, NPVariant &result)
1610 if( !isPluginRunning() )
1611 return INVOKERESULT_GENERIC_ERROR;
1613 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1614 libvlc_exception_t ex;
1615 libvlc_exception_init(&ex);
1617 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1618 RETURN_ON_EXCEPTION(this,ex);
1622 case ID_marquee_color:
1623 case ID_marquee_opacity:
1624 case ID_marquee_refresh:
1625 case ID_marquee_timeout:
1626 case ID_marquee_size:
1630 libvlc_video_get_marquee_int(p_md, marquee_idx[index], &ex),
1632 RETURN_ON_EXCEPTION(this,ex);
1633 return INVOKERESULT_NO_ERROR;
1635 case ID_marquee_position:
1636 STRINGZ_TO_NPVARIANT( position_bynumber(
1637 libvlc_video_get_marquee_int(p_md, libvlc_marquee_Position, &ex) ),
1640 RETURN_ON_EXCEPTION(this,ex);
1643 case ID_marquee_text:
1644 psz = libvlc_video_get_marquee_string(p_md, libvlc_marquee_Text, &ex);
1647 STRINGZ_TO_NPVARIANT(psz, result);
1648 return INVOKERESULT_NO_ERROR;
1652 return INVOKERESULT_GENERIC_ERROR;
1655 RuntimeNPObject::InvokeResult
1656 LibvlcMarqueeNPObject::setProperty(int index, const NPVariant &value)
1660 if( !isPluginRunning() )
1661 return INVOKERESULT_GENERIC_ERROR;
1663 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1664 libvlc_exception_t ex;
1665 libvlc_exception_init(&ex);
1666 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1667 RETURN_ON_EXCEPTION(this,ex);
1671 case ID_marquee_color:
1672 case ID_marquee_opacity:
1673 case ID_marquee_refresh:
1674 case ID_marquee_timeout:
1677 if( NPVARIANT_IS_INT32( value ) )
1679 libvlc_video_set_marquee_int(p_md, marquee_idx[index],
1680 NPVARIANT_TO_INT32( value ), &ex);
1681 RETURN_ON_EXCEPTION(this,ex);
1682 return INVOKERESULT_NO_ERROR;
1686 case ID_marquee_position:
1687 if( !NPVARIANT_IS_STRING(value) ||
1688 !position_byname( NPVARIANT_TO_STRING(value).utf8characters, i ) )
1689 return INVOKERESULT_INVALID_VALUE;
1691 libvlc_video_set_marquee_int(p_md, libvlc_marquee_Position, i, &ex);
1692 RETURN_ON_EXCEPTION(this,ex);
1693 return INVOKERESULT_NO_ERROR;
1695 case ID_marquee_text:
1696 if( NPVARIANT_IS_STRING( value ) )
1698 char *psz_text = stringValue( NPVARIANT_TO_STRING( value ) );
1699 libvlc_video_set_marquee_string(p_md, libvlc_marquee_Text,
1702 RETURN_ON_EXCEPTION(this,ex);
1703 return INVOKERESULT_NO_ERROR;
1707 return INVOKERESULT_NO_SUCH_METHOD;
1710 const NPUTF8 * const LibvlcMarqueeNPObject::methodNames[] =
1715 COUNTNAMES(LibvlcMarqueeNPObject,methodCount,methodNames);
1717 enum LibvlcMarqueeNPObjectMethodIds
1723 RuntimeNPObject::InvokeResult
1724 LibvlcMarqueeNPObject::invoke(int index, const NPVariant *args,
1725 uint32_t argCount, NPVariant &result)
1727 if( !isPluginRunning() )
1728 return INVOKERESULT_GENERIC_ERROR;
1730 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1731 libvlc_exception_t ex;
1732 libvlc_exception_init(&ex);
1734 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1735 RETURN_ON_EXCEPTION(this,ex);
1739 case ID_marquee_enable:
1740 case ID_marquee_disable:
1741 libvlc_video_set_marquee_int(p_md, libvlc_marquee_Enable,
1742 index!=ID_marquee_disable, &ex);
1743 RETURN_ON_EXCEPTION(this,ex);
1744 VOID_TO_NPVARIANT(result);
1745 return INVOKERESULT_NO_ERROR;
1747 return INVOKERESULT_NO_SUCH_METHOD;
1750 const NPUTF8 * const LibvlcLogoNPObject::propertyNames[] = {
1758 enum LibvlcLogoNPObjectPropertyIds {
1766 COUNTNAMES(LibvlcLogoNPObject,propertyCount,propertyNames);
1767 static const unsigned char logo_idx[] = {
1770 libvlc_logo_opacity,
1776 RuntimeNPObject::InvokeResult
1777 LibvlcLogoNPObject::getProperty(int index, NPVariant &result)
1779 if( !isPluginRunning() )
1780 return INVOKERESULT_GENERIC_ERROR;
1782 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1783 libvlc_exception_t ex;
1784 libvlc_exception_init(&ex);
1785 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1786 RETURN_ON_EXCEPTION(this,ex);
1791 case ID_logo_repeat:
1792 case ID_logo_opacity:
1797 libvlc_video_get_logo_int(p_md, logo_idx[index], &ex), result);
1799 RETURN_ON_EXCEPTION(this,ex);
1802 case ID_logo_position:
1803 STRINGZ_TO_NPVARIANT( position_bynumber(
1804 libvlc_video_get_logo_int(p_md, libvlc_logo_position, &ex) ),
1807 RETURN_ON_EXCEPTION(this,ex);
1810 return INVOKERESULT_GENERIC_ERROR;
1812 return INVOKERESULT_NO_ERROR;
1815 RuntimeNPObject::InvokeResult
1816 LibvlcLogoNPObject::setProperty(int index, const NPVariant &value)
1820 if( !isPluginRunning() )
1821 return INVOKERESULT_GENERIC_ERROR;
1823 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1824 libvlc_exception_t ex;
1825 libvlc_exception_init(&ex);
1827 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1828 RETURN_ON_EXCEPTION(this,ex);
1833 case ID_logo_repeat:
1834 case ID_logo_opacity:
1837 if( !NPVARIANT_IS_INT32(value) )
1838 return INVOKERESULT_INVALID_VALUE;
1840 libvlc_video_set_logo_int(p_md, logo_idx[index],
1841 NPVARIANT_TO_INT32( value ), &ex);
1843 RETURN_ON_EXCEPTION(this,ex);
1846 case ID_logo_position:
1847 if( !NPVARIANT_IS_STRING(value) ||
1848 !position_byname( NPVARIANT_TO_STRING(value).utf8characters, i ) )
1849 return INVOKERESULT_INVALID_VALUE;
1851 libvlc_video_set_logo_int(p_md, libvlc_logo_position, i, &ex);
1853 RETURN_ON_EXCEPTION(this,ex);
1856 return INVOKERESULT_GENERIC_ERROR;
1858 return INVOKERESULT_NO_ERROR;
1862 const NPUTF8 * const LibvlcLogoNPObject::methodNames[] = {
1867 enum LibvlcLogoNPObjectMethodIds {
1872 COUNTNAMES(LibvlcLogoNPObject,methodCount,methodNames);
1874 RuntimeNPObject::InvokeResult
1875 LibvlcLogoNPObject::invoke(int index, const NPVariant *args,
1876 uint32_t argCount, NPVariant &result)
1881 if( !isPluginRunning() )
1882 return INVOKERESULT_GENERIC_ERROR;
1884 libvlc_exception_t ex;
1885 libvlc_exception_init(&ex);
1886 libvlc_media_player_t *p_md = getPrivate<VlcPlugin>()->getMD(&ex);
1887 RETURN_ON_EXCEPTION(this,ex);
1891 case ID_logo_enable:
1892 case ID_logo_disable:
1894 return INVOKERESULT_GENERIC_ERROR;
1896 libvlc_video_set_logo_int(p_md, libvlc_logo_enable,
1897 index != ID_logo_disable, &ex);
1898 RETURN_ON_EXCEPTION(this,ex);
1899 VOID_TO_NPVARIANT(result);
1904 return INVOKERESULT_GENERIC_ERROR;
1906 for( len=0,i=0;i<argCount;++i )
1908 if( !NPVARIANT_IS_STRING(args[i]) )
1909 return INVOKERESULT_INVALID_VALUE;
1910 len+=NPVARIANT_TO_STRING(args[i]).utf8length+1;
1913 buf = (char *)malloc( len+1 );
1915 return INVOKERESULT_OUT_OF_MEMORY;
1917 for( h=buf,i=0;i<argCount;++i )
1920 len=NPVARIANT_TO_STRING(args[i]).utf8length;
1921 memcpy(h,NPVARIANT_TO_STRING(args[i]).utf8characters,len);
1926 libvlc_video_set_logo_string(p_md, libvlc_logo_file, buf, &ex);
1928 RETURN_ON_EXCEPTION(this,ex);
1929 VOID_TO_NPVARIANT(result);
1932 return INVOKERESULT_NO_ERROR;