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"
40 ** Local helper macros and function
42 #define COUNTNAMES(a,b,c) const int a::b = sizeof(a::c)/sizeof(NPUTF8 *)
43 #define RETURN_ON_EXCEPTION(this,ex) \
44 do { if( libvlc_exception_raised(&ex) ) \
46 NPN_SetException(this, libvlc_errmsg()); \
47 libvlc_exception_clear(&ex); \
48 return INVOKERESULT_GENERIC_ERROR; \
52 ** implementation of libvlc root object
55 LibvlcRootNPObject::~LibvlcRootNPObject()
58 ** When the plugin is destroyed, firefox takes it upon itself to
59 ** destroy all 'live' script objects and ignores refcounting.
60 ** Therefore we cannot safely assume that refcounting will control
61 ** lifespan of objects. Hence they are only lazily created on
62 ** request, so that firefox can take ownership, and are not released
63 ** when the plugin is destroyed.
67 if( audioObj ) NPN_ReleaseObject(audioObj);
68 if( inputObj ) NPN_ReleaseObject(inputObj);
69 if( playlistObj ) NPN_ReleaseObject(playlistObj);
70 if( videoObj ) NPN_ReleaseObject(videoObj);
74 const NPUTF8 * const LibvlcRootNPObject::propertyNames[] =
83 COUNTNAMES(LibvlcRootNPObject,propertyCount,propertyNames);
85 enum LibvlcRootNPObjectPropertyIds
95 RuntimeNPObject::InvokeResult
96 LibvlcRootNPObject::getProperty(int index, NPVariant &result)
98 /* is plugin still running */
99 if( isPluginRunning() )
104 InstantObj<LibvlcAudioNPObject>( audioObj );
105 OBJECT_TO_NPVARIANT(NPN_RetainObject(audioObj), result);
106 return INVOKERESULT_NO_ERROR;
108 InstantObj<LibvlcInputNPObject>( inputObj );
109 OBJECT_TO_NPVARIANT(NPN_RetainObject(inputObj), result);
110 return INVOKERESULT_NO_ERROR;
111 case ID_root_playlist:
112 InstantObj<LibvlcPlaylistNPObject>( playlistObj );
113 OBJECT_TO_NPVARIANT(NPN_RetainObject(playlistObj), result);
114 return INVOKERESULT_NO_ERROR;
115 case ID_root_subtitle:
116 InstantObj<LibvlcSubtitleNPObject>( subtitleObj );
117 OBJECT_TO_NPVARIANT(NPN_RetainObject(subtitleObj), result);
118 return INVOKERESULT_NO_ERROR;
120 InstantObj<LibvlcVideoNPObject>( videoObj );
121 OBJECT_TO_NPVARIANT(NPN_RetainObject(videoObj), result);
122 return INVOKERESULT_NO_ERROR;
123 case ID_root_VersionInfo:
124 return invokeResultString(libvlc_get_version(),result);
129 return INVOKERESULT_GENERIC_ERROR;
132 const NPUTF8 * const LibvlcRootNPObject::methodNames[] =
136 COUNTNAMES(LibvlcRootNPObject,methodCount,methodNames);
138 enum LibvlcRootNPObjectMethodIds
143 RuntimeNPObject::InvokeResult LibvlcRootNPObject::invoke(int index,
144 const NPVariant *args, uint32_t argCount, NPVariant &result)
146 /* is plugin still running */
147 if( isPluginRunning() )
149 libvlc_exception_t ex;
150 libvlc_exception_init(&ex);
154 case ID_root_versionInfo:
156 return INVOKERESULT_NO_SUCH_METHOD;
157 return invokeResultString(libvlc_get_version(),result);
162 return INVOKERESULT_GENERIC_ERROR;
166 ** implementation of libvlc audio object
169 const NPUTF8 * const LibvlcAudioNPObject::propertyNames[] =
177 COUNTNAMES(LibvlcAudioNPObject,propertyCount,propertyNames);
179 enum LibvlcAudioNPObjectPropertyIds
188 RuntimeNPObject::InvokeResult
189 LibvlcAudioNPObject::getProperty(int index, NPVariant &result)
191 /* is plugin still running */
192 if( isPluginRunning() )
194 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
195 libvlc_exception_t ex;
196 libvlc_exception_init(&ex);
202 bool muted = libvlc_audio_get_mute(p_plugin->getVLC());
203 BOOLEAN_TO_NPVARIANT(muted, result);
204 return INVOKERESULT_NO_ERROR;
206 case ID_audio_volume:
208 int volume = libvlc_audio_get_volume(p_plugin->getVLC());
209 INT32_TO_NPVARIANT(volume, result);
210 return INVOKERESULT_NO_ERROR;
214 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
215 RETURN_ON_EXCEPTION(this,ex);
216 int track = libvlc_audio_get_track(p_md, &ex);
217 RETURN_ON_EXCEPTION(this,ex);
218 INT32_TO_NPVARIANT(track, result);
219 return INVOKERESULT_NO_ERROR;
223 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
224 RETURN_ON_EXCEPTION(this,ex);
225 // get the number of audio track available
226 int i_track = libvlc_audio_get_track_count(p_md, &ex);
227 RETURN_ON_EXCEPTION(this,ex);
229 INT32_TO_NPVARIANT(i_track, result);
230 return INVOKERESULT_NO_ERROR;
232 case ID_audio_channel:
234 int channel = libvlc_audio_get_channel(p_plugin->getVLC(), &ex);
235 RETURN_ON_EXCEPTION(this,ex);
236 INT32_TO_NPVARIANT(channel, result);
237 return INVOKERESULT_NO_ERROR;
243 return INVOKERESULT_GENERIC_ERROR;
246 RuntimeNPObject::InvokeResult
247 LibvlcAudioNPObject::setProperty(int index, const NPVariant &value)
249 /* is plugin still running */
250 if( isPluginRunning() )
252 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
253 libvlc_exception_t ex;
254 libvlc_exception_init(&ex);
259 if( NPVARIANT_IS_BOOLEAN(value) )
261 libvlc_audio_set_mute(p_plugin->getVLC(),
262 NPVARIANT_TO_BOOLEAN(value));
263 return INVOKERESULT_NO_ERROR;
265 return INVOKERESULT_INVALID_VALUE;
266 case ID_audio_volume:
267 if( isNumberValue(value) )
269 libvlc_audio_set_volume(p_plugin->getVLC(),
270 numberValue(value), &ex);
271 RETURN_ON_EXCEPTION(this,ex);
272 return INVOKERESULT_NO_ERROR;
274 return INVOKERESULT_INVALID_VALUE;
276 if( isNumberValue(value) )
278 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
279 RETURN_ON_EXCEPTION(this,ex);
280 libvlc_audio_set_track(p_md, numberValue(value), &ex);
281 RETURN_ON_EXCEPTION(this,ex);
282 return INVOKERESULT_NO_ERROR;
284 return INVOKERESULT_INVALID_VALUE;
285 case ID_audio_channel:
286 if( isNumberValue(value) )
288 libvlc_audio_set_channel(p_plugin->getVLC(),
289 numberValue(value), &ex);
290 RETURN_ON_EXCEPTION(this,ex);
291 return INVOKERESULT_NO_ERROR;
293 return INVOKERESULT_INVALID_VALUE;
298 return INVOKERESULT_GENERIC_ERROR;
301 const NPUTF8 * const LibvlcAudioNPObject::methodNames[] =
306 COUNTNAMES(LibvlcAudioNPObject,methodCount,methodNames);
308 enum LibvlcAudioNPObjectMethodIds
311 ID_audio_description,
314 RuntimeNPObject::InvokeResult
315 LibvlcAudioNPObject::invoke(int index, const NPVariant *args,
316 uint32_t argCount, NPVariant &result)
318 /* is plugin still running */
319 if( isPluginRunning() )
321 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
322 libvlc_exception_t ex;
323 libvlc_exception_init(&ex);
327 case ID_audio_togglemute:
330 libvlc_audio_toggle_mute(p_plugin->getVLC());
331 VOID_TO_NPVARIANT(result);
332 return INVOKERESULT_NO_ERROR;
334 return INVOKERESULT_NO_SUCH_METHOD;
335 case ID_audio_description:
340 int i_trackID, i_limit, i;
341 libvlc_track_description_t *p_trackDesc;
343 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
344 RETURN_ON_EXCEPTION(this,ex);
346 /* get tracks description */
347 p_trackDesc = libvlc_audio_get_track_description(p_md, &ex);
348 RETURN_ON_EXCEPTION(this,ex);
350 return INVOKERESULT_GENERIC_ERROR;
352 /* get the number of track available */
353 i_limit = libvlc_audio_get_track_count(p_md, &ex);
354 RETURN_ON_EXCEPTION(this,ex);
356 /* check if a number is given by the user
357 * and get the track number */
358 if( isNumberValue(args[0]) )
359 i_trackID = numberValue(args[0]);
361 return INVOKERESULT_INVALID_VALUE;
363 /* if bad number is given return invalid value */
364 if ( ( i_trackID > ( i_limit - 1 ) ) || ( i_trackID < 0 ) )
365 return INVOKERESULT_INVALID_VALUE;
367 /* get the good trackDesc */
368 for( i = 0 ; i < i_trackID ; i++ )
370 p_trackDesc = p_trackDesc->p_next;
372 psz_name = p_trackDesc->psz_name;
374 /* display the name of the track chosen */
375 return invokeResultString( psz_name, result );
377 return INVOKERESULT_NO_SUCH_METHOD;
383 return INVOKERESULT_GENERIC_ERROR;
387 ** implementation of libvlc input object
390 const NPUTF8 * const LibvlcInputNPObject::propertyNames[] =
400 COUNTNAMES(LibvlcInputNPObject,propertyCount,propertyNames);
402 enum LibvlcInputNPObjectPropertyIds
413 RuntimeNPObject::InvokeResult
414 LibvlcInputNPObject::getProperty(int index, NPVariant &result)
416 /* is plugin still running */
417 if( isPluginRunning() )
419 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
420 libvlc_exception_t ex;
421 libvlc_exception_init(&ex);
423 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
424 if( libvlc_exception_raised(&ex) )
426 if( index != ID_input_state )
428 NPN_SetException(this, libvlc_errmsg());
429 libvlc_exception_clear(&ex);
430 return INVOKERESULT_GENERIC_ERROR;
434 /* for input state, return CLOSED rather than an exception */
435 INT32_TO_NPVARIANT(0, result);
436 libvlc_exception_clear(&ex);
437 return INVOKERESULT_NO_ERROR;
443 case ID_input_length:
445 double val = (double)libvlc_media_player_get_length(p_md, &ex);
446 RETURN_ON_EXCEPTION(this,ex);
447 DOUBLE_TO_NPVARIANT(val, result);
448 return INVOKERESULT_NO_ERROR;
450 case ID_input_position:
452 double val = libvlc_media_player_get_position(p_md, &ex);
453 RETURN_ON_EXCEPTION(this,ex);
454 DOUBLE_TO_NPVARIANT(val, result);
455 return INVOKERESULT_NO_ERROR;
459 double val = (double)libvlc_media_player_get_time(p_md, &ex);
460 RETURN_ON_EXCEPTION(this,ex);
461 DOUBLE_TO_NPVARIANT(val, result);
462 return INVOKERESULT_NO_ERROR;
466 int val = libvlc_media_player_get_state(p_md, &ex);
467 RETURN_ON_EXCEPTION(this,ex);
468 INT32_TO_NPVARIANT(val, result);
469 return INVOKERESULT_NO_ERROR;
473 float val = libvlc_media_player_get_rate(p_md, &ex);
474 RETURN_ON_EXCEPTION(this,ex);
475 DOUBLE_TO_NPVARIANT(val, result);
476 return INVOKERESULT_NO_ERROR;
480 double val = libvlc_media_player_get_fps(p_md, &ex);
481 RETURN_ON_EXCEPTION(this,ex);
482 DOUBLE_TO_NPVARIANT(val, result);
483 return INVOKERESULT_NO_ERROR;
485 case ID_input_hasvout:
487 bool val = p_plugin->player_has_vout(&ex);
488 RETURN_ON_EXCEPTION(this,ex);
489 BOOLEAN_TO_NPVARIANT(val, result);
490 return INVOKERESULT_NO_ERROR;
496 return INVOKERESULT_GENERIC_ERROR;
499 RuntimeNPObject::InvokeResult
500 LibvlcInputNPObject::setProperty(int index, const NPVariant &value)
502 /* is plugin still running */
503 if( isPluginRunning() )
505 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
506 libvlc_exception_t ex;
507 libvlc_exception_init(&ex);
509 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
510 RETURN_ON_EXCEPTION(this,ex);
514 case ID_input_position:
516 if( ! NPVARIANT_IS_DOUBLE(value) )
518 return INVOKERESULT_INVALID_VALUE;
521 float val = (float)NPVARIANT_TO_DOUBLE(value);
522 libvlc_media_player_set_position(p_md, val, &ex);
523 RETURN_ON_EXCEPTION(this,ex);
524 return INVOKERESULT_NO_ERROR;
529 if( NPVARIANT_IS_INT32(value) )
530 val = (int64_t)NPVARIANT_TO_INT32(value);
531 else if( NPVARIANT_IS_DOUBLE(value) )
532 val = (int64_t)NPVARIANT_TO_DOUBLE(value);
535 return INVOKERESULT_INVALID_VALUE;
538 libvlc_media_player_set_time(p_md, val, &ex);
539 RETURN_ON_EXCEPTION(this,ex);
540 return INVOKERESULT_NO_ERROR;
545 if( NPVARIANT_IS_INT32(value) )
546 val = (float)NPVARIANT_TO_INT32(value);
547 else if( NPVARIANT_IS_DOUBLE(value) )
548 val = (float)NPVARIANT_TO_DOUBLE(value);
551 return INVOKERESULT_INVALID_VALUE;
554 libvlc_media_player_set_rate(p_md, val, &ex);
555 RETURN_ON_EXCEPTION(this,ex);
556 return INVOKERESULT_NO_ERROR;
562 return INVOKERESULT_GENERIC_ERROR;
565 const NPUTF8 * const LibvlcInputNPObject::methodNames[] =
570 COUNTNAMES(LibvlcInputNPObject,methodCount,methodNames);
572 enum LibvlcInputNPObjectMethodIds
577 RuntimeNPObject::InvokeResult
578 LibvlcInputNPObject::invoke(int index, const NPVariant *args,
579 uint32_t argCount, NPVariant &result)
581 /* is plugin still running */
582 if( isPluginRunning() )
587 return INVOKERESULT_NO_SUCH_METHOD;
592 return INVOKERESULT_GENERIC_ERROR;
596 ** implementation of libvlc playlist items object
599 const NPUTF8 * const LibvlcPlaylistItemsNPObject::propertyNames[] =
603 COUNTNAMES(LibvlcPlaylistItemsNPObject,propertyCount,propertyNames);
605 enum LibvlcPlaylistItemsNPObjectPropertyIds
607 ID_playlistitems_count,
610 RuntimeNPObject::InvokeResult
611 LibvlcPlaylistItemsNPObject::getProperty(int index, NPVariant &result)
613 /* is plugin still running */
614 if( isPluginRunning() )
616 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
617 libvlc_exception_t ex;
618 libvlc_exception_init(&ex);
622 case ID_playlistitems_count:
624 int val = p_plugin->playlist_count(&ex);
625 RETURN_ON_EXCEPTION(this,ex);
626 INT32_TO_NPVARIANT(val, result);
627 return INVOKERESULT_NO_ERROR;
633 return INVOKERESULT_GENERIC_ERROR;
636 const NPUTF8 * const LibvlcPlaylistItemsNPObject::methodNames[] =
641 COUNTNAMES(LibvlcPlaylistItemsNPObject,methodCount,methodNames);
643 enum LibvlcPlaylistItemsNPObjectMethodIds
645 ID_playlistitems_clear,
646 ID_playlistitems_remove,
649 RuntimeNPObject::InvokeResult
650 LibvlcPlaylistItemsNPObject::invoke(int index, const NPVariant *args,
651 uint32_t argCount, NPVariant &result)
653 /* is plugin still running */
654 if( isPluginRunning() )
656 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
657 libvlc_exception_t ex;
658 libvlc_exception_init(&ex);
662 case ID_playlistitems_clear:
665 p_plugin->playlist_clear(&ex);
666 RETURN_ON_EXCEPTION(this,ex);
667 VOID_TO_NPVARIANT(result);
668 return INVOKERESULT_NO_ERROR;
670 return INVOKERESULT_NO_SUCH_METHOD;
671 case ID_playlistitems_remove:
672 if( (argCount == 1) && isNumberValue(args[0]) )
674 p_plugin->playlist_delete_item(numberValue(args[0]),&ex);
675 RETURN_ON_EXCEPTION(this,ex);
676 VOID_TO_NPVARIANT(result);
677 return INVOKERESULT_NO_ERROR;
679 return INVOKERESULT_NO_SUCH_METHOD;
684 return INVOKERESULT_GENERIC_ERROR;
688 ** implementation of libvlc playlist object
691 LibvlcPlaylistNPObject::~LibvlcPlaylistNPObject()
693 // Why the isValid()?
694 if( isValid() && playlistItemsObj )
695 NPN_ReleaseObject(playlistItemsObj);
698 const NPUTF8 * const LibvlcPlaylistNPObject::propertyNames[] =
700 "itemCount", /* deprecated */
704 COUNTNAMES(LibvlcPlaylistNPObject,propertyCount,propertyNames);
706 enum LibvlcPlaylistNPObjectPropertyIds
708 ID_playlist_itemcount,
709 ID_playlist_isplaying,
713 RuntimeNPObject::InvokeResult
714 LibvlcPlaylistNPObject::getProperty(int index, NPVariant &result)
716 /* is plugin still running */
717 if( isPluginRunning() )
719 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
720 libvlc_exception_t ex;
721 libvlc_exception_init(&ex);
725 case ID_playlist_itemcount: /* deprecated */
727 int val = p_plugin->playlist_count(&ex);
728 RETURN_ON_EXCEPTION(this,ex);
729 INT32_TO_NPVARIANT(val, result);
730 return INVOKERESULT_NO_ERROR;
732 case ID_playlist_isplaying:
734 int val = p_plugin->playlist_isplaying(&ex);
735 RETURN_ON_EXCEPTION(this,ex);
736 BOOLEAN_TO_NPVARIANT(val, result);
737 return INVOKERESULT_NO_ERROR;
739 case ID_playlist_items:
741 InstantObj<LibvlcPlaylistItemsNPObject>( playlistItemsObj );
742 OBJECT_TO_NPVARIANT(NPN_RetainObject(playlistItemsObj), result);
743 return INVOKERESULT_NO_ERROR;
749 return INVOKERESULT_GENERIC_ERROR;
752 const NPUTF8 * const LibvlcPlaylistNPObject::methodNames[] =
761 "clear", /* deprecated */
762 "removeItem", /* deprecated */
764 COUNTNAMES(LibvlcPlaylistNPObject,methodCount,methodNames);
766 enum LibvlcPlaylistNPObjectMethodIds
770 ID_playlist_playItem,
771 ID_playlist_togglepause,
776 ID_playlist_removeitem
779 RuntimeNPObject::InvokeResult
780 LibvlcPlaylistNPObject::invoke(int index, const NPVariant *args,
781 uint32_t argCount, NPVariant &result)
783 /* is plugin still running */
784 if( isPluginRunning() )
786 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
787 libvlc_exception_t ex;
788 libvlc_exception_init(&ex);
792 // XXX FIXME this needs squashing into something much smaller
793 case ID_playlist_add:
795 if( (argCount < 1) || (argCount > 3) )
796 return INVOKERESULT_NO_SUCH_METHOD;
797 if( !NPVARIANT_IS_STRING(args[0]) )
798 return INVOKERESULT_NO_SUCH_METHOD;
801 if( NPVARIANT_IS_NULL(args[0]) )
802 return INVOKERESULT_NO_SUCH_METHOD;
804 char *s = stringValue(NPVARIANT_TO_STRING(args[0]));
806 return INVOKERESULT_OUT_OF_MEMORY;
808 char *url = p_plugin->getAbsoluteURL(s);
812 // problem with combining url, use argument
817 // grab name if available
820 if( NPVARIANT_IS_NULL(args[1]) )
824 else if( NPVARIANT_IS_STRING(args[1]) )
826 name = stringValue(NPVARIANT_TO_STRING(args[1]));
831 return INVOKERESULT_INVALID_VALUE;
836 char** ppsz_options = NULL;
838 // grab options if available
841 if( NPVARIANT_IS_NULL(args[2]) )
845 else if( NPVARIANT_IS_STRING(args[2]) )
847 parseOptions(NPVARIANT_TO_STRING(args[2]),
848 &i_options, &ppsz_options);
851 else if( NPVARIANT_IS_OBJECT(args[2]) )
853 parseOptions(NPVARIANT_TO_OBJECT(args[2]),
854 &i_options, &ppsz_options);
860 return INVOKERESULT_INVALID_VALUE;
864 int item = p_plugin->playlist_add_extended_untrusted(url, name,
865 i_options, const_cast<const char **>(ppsz_options), &ex);
868 for( int i=0; i< i_options; ++i )
870 free(ppsz_options[i]);
874 RETURN_ON_EXCEPTION(this,ex);
875 INT32_TO_NPVARIANT(item, result);
876 return INVOKERESULT_NO_ERROR;
878 case ID_playlist_play:
881 p_plugin->playlist_play(&ex);
882 RETURN_ON_EXCEPTION(this,ex);
883 VOID_TO_NPVARIANT(result);
884 return INVOKERESULT_NO_ERROR;
886 return INVOKERESULT_NO_SUCH_METHOD;
887 case ID_playlist_playItem:
888 if( (argCount == 1) && isNumberValue(args[0]) )
890 p_plugin->playlist_play_item(numberValue(args[0]),&ex);
891 RETURN_ON_EXCEPTION(this,ex);
892 VOID_TO_NPVARIANT(result);
893 return INVOKERESULT_NO_ERROR;
895 return INVOKERESULT_NO_SUCH_METHOD;
896 case ID_playlist_togglepause:
899 p_plugin->playlist_pause(&ex);
900 RETURN_ON_EXCEPTION(this,ex);
901 VOID_TO_NPVARIANT(result);
902 return INVOKERESULT_NO_ERROR;
904 return INVOKERESULT_NO_SUCH_METHOD;
905 case ID_playlist_stop:
908 p_plugin->playlist_stop(&ex);
909 RETURN_ON_EXCEPTION(this,ex);
910 VOID_TO_NPVARIANT(result);
911 return INVOKERESULT_NO_ERROR;
913 return INVOKERESULT_NO_SUCH_METHOD;
914 case ID_playlist_next:
917 p_plugin->playlist_next(&ex);
918 RETURN_ON_EXCEPTION(this,ex);
919 VOID_TO_NPVARIANT(result);
920 return INVOKERESULT_NO_ERROR;
922 return INVOKERESULT_NO_SUCH_METHOD;
923 case ID_playlist_prev:
926 p_plugin->playlist_prev(&ex);
927 RETURN_ON_EXCEPTION(this,ex);
928 VOID_TO_NPVARIANT(result);
929 return INVOKERESULT_NO_ERROR;
931 return INVOKERESULT_NO_SUCH_METHOD;
932 case ID_playlist_clear: /* deprecated */
935 p_plugin->playlist_clear(&ex);
936 RETURN_ON_EXCEPTION(this,ex);
937 VOID_TO_NPVARIANT(result);
938 return INVOKERESULT_NO_ERROR;
940 return INVOKERESULT_NO_SUCH_METHOD;
941 case ID_playlist_removeitem: /* deprecated */
942 if( (argCount == 1) && isNumberValue(args[0]) )
944 p_plugin->playlist_delete_item(numberValue(args[0]), &ex);
945 RETURN_ON_EXCEPTION(this,ex);
946 VOID_TO_NPVARIANT(result);
947 return INVOKERESULT_NO_ERROR;
949 return INVOKERESULT_NO_SUCH_METHOD;
954 return INVOKERESULT_GENERIC_ERROR;
957 // XXX FIXME The new playlist_add creates a media instance and feeds it
958 // XXX FIXME these options one at a time, so this hunk of code does lots
959 // XXX FIXME of unnecessairy work. Break out something that can do one
960 // XXX FIXME option at a time and doesn't need to realloc().
961 // XXX FIXME Same for the other version of parseOptions.
963 void LibvlcPlaylistNPObject::parseOptions(const NPString &nps,
964 int *i_options, char*** ppsz_options)
968 char *s = stringValue(nps);
973 char **options = (char **)malloc(capacity*sizeof(char *));
978 char *end = val + nps.utf8length;
981 // skip leading blanks
983 && ((*val == ' ' ) || (*val == '\t')) )
987 // skip till we get a blank character
993 if( ('\'' == c) || ('"' == c) )
995 // skip till end of string
996 while( (val < end) && (*(val++) != c ) );
1002 if( nOptions == capacity )
1005 char **moreOptions = (char **)realloc(options, capacity*sizeof(char*));
1008 /* failed to allocate more memory */
1010 /* return what we got so far */
1011 *i_options = nOptions;
1012 *ppsz_options = options;
1015 options = moreOptions;
1018 options[nOptions++] = strdup(start);
1021 // must be end of string
1024 *i_options = nOptions;
1025 *ppsz_options = options;
1032 // XXX FIXME See comment at the other parseOptions variant.
1033 void LibvlcPlaylistNPObject::parseOptions(NPObject *obj, int *i_options,
1034 char*** ppsz_options)
1036 /* WARNING: Safari does not implement NPN_HasProperty/NPN_HasMethod */
1040 /* we are expecting to have a Javascript Array object */
1041 NPIdentifier propId = NPN_GetStringIdentifier("length");
1042 if( NPN_GetProperty(_instance, obj, propId, &value) )
1044 int count = numberValue(value);
1045 NPN_ReleaseVariantValue(&value);
1050 char **options = (char **)malloc(capacity*sizeof(char *));
1055 while( nOptions < count )
1057 propId = NPN_GetIntIdentifier(nOptions);
1058 if( ! NPN_GetProperty(_instance, obj, propId, &value) )
1059 /* return what we got so far */
1062 if( ! NPVARIANT_IS_STRING(value) )
1064 /* return what we got so far */
1065 NPN_ReleaseVariantValue(&value);
1069 if( nOptions == capacity )
1072 char **moreOptions = (char **)realloc(options, capacity*sizeof(char*));
1075 /* failed to allocate more memory */
1076 NPN_ReleaseVariantValue(&value);
1077 /* return what we got so far */
1078 *i_options = nOptions;
1079 *ppsz_options = options;
1082 options = moreOptions;
1085 options[nOptions++] = stringValue(value);
1086 NPN_ReleaseVariantValue(&value);
1088 *i_options = nOptions;
1089 *ppsz_options = options;
1096 ** implementation of libvlc subtitle object
1099 const NPUTF8 * const LibvlcSubtitleNPObject::propertyNames[] =
1105 enum LibvlcSubtitleNPObjectPropertyIds
1110 COUNTNAMES(LibvlcSubtitleNPObject,propertyCount,propertyNames);
1112 RuntimeNPObject::InvokeResult
1113 LibvlcSubtitleNPObject::getProperty(int index, NPVariant &result)
1115 /* is plugin still running */
1116 if( isPluginRunning() )
1118 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1119 libvlc_exception_t ex;
1120 libvlc_exception_init(&ex);
1122 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1123 RETURN_ON_EXCEPTION(this,ex);
1127 case ID_subtitle_track:
1129 /* get the current subtitle ID */
1130 int i_spu = libvlc_video_get_spu(p_md, &ex);
1131 RETURN_ON_EXCEPTION(this,ex);
1133 INT32_TO_NPVARIANT(i_spu, result);
1134 return INVOKERESULT_NO_ERROR;
1136 case ID_subtitle_count:
1138 /* get the number of subtitles available */
1139 int i_spu = libvlc_video_get_spu_count(p_md, &ex);
1140 RETURN_ON_EXCEPTION(this,ex);
1142 INT32_TO_NPVARIANT(i_spu, result);
1143 return INVOKERESULT_NO_ERROR;
1147 return INVOKERESULT_GENERIC_ERROR;
1150 RuntimeNPObject::InvokeResult
1151 LibvlcSubtitleNPObject::setProperty(int index, const NPVariant &value)
1153 /* is plugin still running */
1154 if( isPluginRunning() )
1156 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1157 libvlc_exception_t ex;
1158 libvlc_exception_init(&ex);
1160 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1161 RETURN_ON_EXCEPTION(this,ex);
1165 case ID_subtitle_track:
1167 if( isNumberValue(value) )
1169 /* set the new subtitle track to show */
1170 libvlc_video_set_spu(p_md, numberValue(value), &ex);
1171 RETURN_ON_EXCEPTION(this,ex);
1173 return INVOKERESULT_NO_ERROR;
1175 return INVOKERESULT_INVALID_VALUE;
1179 return INVOKERESULT_GENERIC_ERROR;
1182 const NPUTF8 * const LibvlcSubtitleNPObject::methodNames[] =
1186 COUNTNAMES(LibvlcSubtitleNPObject,methodCount,methodNames);
1188 enum LibvlcSubtitleNPObjectMethodIds
1190 ID_subtitle_description
1193 RuntimeNPObject::InvokeResult
1194 LibvlcSubtitleNPObject::invoke(int index, const NPVariant *args,
1195 uint32_t argCount, NPVariant &result)
1197 /* is plugin still running */
1198 if( isPluginRunning() )
1200 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1201 libvlc_exception_t ex;
1202 libvlc_exception_init(&ex);
1204 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1205 RETURN_ON_EXCEPTION(this,ex);
1209 case ID_subtitle_description:
1214 int i_spuID, i_limit, i;
1215 libvlc_track_description_t *p_spuDesc;
1217 /* get subtitles description */
1218 p_spuDesc = libvlc_video_get_spu_description(p_md, &ex);
1219 RETURN_ON_EXCEPTION(this,ex);
1221 return INVOKERESULT_GENERIC_ERROR;
1223 /* get the number of subtitle available */
1224 i_limit = libvlc_video_get_spu_count(p_md, &ex);
1225 RETURN_ON_EXCEPTION(this,ex);
1227 /* check if a number is given by the user
1228 * and get the subtitle number */
1229 if( isNumberValue(args[0]) )
1230 i_spuID = numberValue(args[0]);
1232 return INVOKERESULT_INVALID_VALUE;
1234 /* if bad number is given return invalid value */
1235 if ( ( i_spuID > ( i_limit -1 ) ) || ( i_spuID < 0 ) )
1236 return INVOKERESULT_INVALID_VALUE;
1238 /* get the good spuDesc */
1239 for( i = 0 ; i < i_spuID ; i++ )
1241 p_spuDesc = p_spuDesc->p_next;
1243 psz_name = p_spuDesc->psz_name;
1245 /* return the name of the track chosen */
1246 return invokeResultString(psz_name, result);
1248 return INVOKERESULT_NO_SUCH_METHOD;
1251 return INVOKERESULT_NO_SUCH_METHOD;
1254 return INVOKERESULT_GENERIC_ERROR;
1258 ** implementation of libvlc video object
1261 const NPUTF8 * const LibvlcVideoNPObject::propertyNames[] =
1274 enum LibvlcVideoNPObjectPropertyIds
1276 ID_video_fullscreen,
1279 ID_video_aspectratio,
1286 COUNTNAMES(LibvlcVideoNPObject,propertyCount,propertyNames);
1288 RuntimeNPObject::InvokeResult
1289 LibvlcVideoNPObject::getProperty(int index, NPVariant &result)
1291 /* is plugin still running */
1292 if( isPluginRunning() )
1294 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1295 libvlc_exception_t ex;
1296 libvlc_exception_init(&ex);
1298 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1299 RETURN_ON_EXCEPTION(this,ex);
1303 case ID_video_fullscreen:
1305 int val = p_plugin->get_fullscreen(&ex);
1306 RETURN_ON_EXCEPTION(this,ex);
1307 BOOLEAN_TO_NPVARIANT(val, result);
1308 return INVOKERESULT_NO_ERROR;
1310 case ID_video_height:
1312 int val = libvlc_video_get_height(p_md, &ex);
1313 RETURN_ON_EXCEPTION(this,ex);
1314 INT32_TO_NPVARIANT(val, result);
1315 return INVOKERESULT_NO_ERROR;
1317 case ID_video_width:
1319 int val = libvlc_video_get_width(p_md, &ex);
1320 RETURN_ON_EXCEPTION(this,ex);
1321 INT32_TO_NPVARIANT(val, result);
1322 return INVOKERESULT_NO_ERROR;
1324 case ID_video_aspectratio:
1326 NPUTF8 *psz_aspect = libvlc_video_get_aspect_ratio(p_md, &ex);
1327 RETURN_ON_EXCEPTION(this,ex);
1329 return INVOKERESULT_GENERIC_ERROR;
1331 STRINGZ_TO_NPVARIANT(psz_aspect, result);
1332 return INVOKERESULT_NO_ERROR;
1334 case ID_video_subtitle:
1336 int i_spu = libvlc_video_get_spu(p_md, &ex);
1337 RETURN_ON_EXCEPTION(this,ex);
1338 INT32_TO_NPVARIANT(i_spu, result);
1339 return INVOKERESULT_NO_ERROR;
1343 NPUTF8 *psz_geometry = libvlc_video_get_crop_geometry(p_md, &ex);
1344 RETURN_ON_EXCEPTION(this,ex);
1346 return INVOKERESULT_GENERIC_ERROR;
1348 STRINGZ_TO_NPVARIANT(psz_geometry, result);
1349 return INVOKERESULT_NO_ERROR;
1351 case ID_video_teletext:
1353 int i_page = libvlc_video_get_teletext(p_md, &ex);
1354 RETURN_ON_EXCEPTION(this,ex);
1355 INT32_TO_NPVARIANT(i_page, result);
1356 return INVOKERESULT_NO_ERROR;
1358 case ID_video_marquee:
1360 InstantObj<LibvlcMarqueeNPObject>( marqueeObj );
1361 OBJECT_TO_NPVARIANT(NPN_RetainObject(marqueeObj), result);
1362 return INVOKERESULT_NO_ERROR;
1366 InstantObj<LibvlcLogoNPObject>( logoObj );
1367 OBJECT_TO_NPVARIANT(NPN_RetainObject(logoObj), result);
1368 return INVOKERESULT_NO_ERROR;
1372 return INVOKERESULT_GENERIC_ERROR;
1375 RuntimeNPObject::InvokeResult
1376 LibvlcVideoNPObject::setProperty(int index, const NPVariant &value)
1378 /* is plugin still running */
1379 if( isPluginRunning() )
1381 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1382 libvlc_exception_t ex;
1383 libvlc_exception_init(&ex);
1385 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1386 RETURN_ON_EXCEPTION(this,ex);
1390 case ID_video_fullscreen:
1392 if( ! NPVARIANT_IS_BOOLEAN(value) )
1394 return INVOKERESULT_INVALID_VALUE;
1397 int val = NPVARIANT_TO_BOOLEAN(value);
1398 p_plugin->set_fullscreen(val, &ex);
1399 RETURN_ON_EXCEPTION(this,ex);
1400 return INVOKERESULT_NO_ERROR;
1402 case ID_video_aspectratio:
1404 char *psz_aspect = NULL;
1406 if( ! NPVARIANT_IS_STRING(value) )
1408 return INVOKERESULT_INVALID_VALUE;
1411 psz_aspect = stringValue(NPVARIANT_TO_STRING(value));
1414 return INVOKERESULT_GENERIC_ERROR;
1417 libvlc_video_set_aspect_ratio(p_md, psz_aspect, &ex);
1419 RETURN_ON_EXCEPTION(this,ex);
1421 return INVOKERESULT_NO_ERROR;
1423 case ID_video_subtitle:
1425 if( isNumberValue(value) )
1427 libvlc_video_set_spu(p_md, numberValue(value), &ex);
1428 RETURN_ON_EXCEPTION(this,ex);
1430 return INVOKERESULT_NO_ERROR;
1432 return INVOKERESULT_INVALID_VALUE;
1436 char *psz_geometry = NULL;
1438 if( ! NPVARIANT_IS_STRING(value) )
1440 return INVOKERESULT_INVALID_VALUE;
1443 psz_geometry = stringValue(NPVARIANT_TO_STRING(value));
1446 return INVOKERESULT_GENERIC_ERROR;
1449 libvlc_video_set_crop_geometry(p_md, psz_geometry, &ex);
1451 RETURN_ON_EXCEPTION(this,ex);
1453 return INVOKERESULT_NO_ERROR;
1455 case ID_video_teletext:
1457 if( isNumberValue(value) )
1459 libvlc_video_set_teletext(p_md, numberValue(value), &ex);
1460 RETURN_ON_EXCEPTION(this,ex);
1462 return INVOKERESULT_NO_ERROR;
1464 return INVOKERESULT_INVALID_VALUE;
1468 return INVOKERESULT_GENERIC_ERROR;
1471 const NPUTF8 * const LibvlcVideoNPObject::methodNames[] =
1475 "deinterlaceEnable",
1476 "deinterlaceDisable"
1478 COUNTNAMES(LibvlcVideoNPObject,methodCount,methodNames);
1480 enum LibvlcVideoNPObjectMethodIds
1482 ID_video_togglefullscreen,
1483 ID_video_toggleteletext,
1484 ID_video_deinterlaceenable,
1485 ID_video_deinterlacedisable
1488 RuntimeNPObject::InvokeResult
1489 LibvlcVideoNPObject::invoke(int index, const NPVariant *args,
1490 uint32_t argCount, NPVariant &result)
1492 /* is plugin still running */
1493 if( isPluginRunning() )
1495 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1496 libvlc_exception_t ex;
1497 libvlc_exception_init(&ex);
1499 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1500 RETURN_ON_EXCEPTION(this,ex);
1504 case ID_video_togglefullscreen:
1508 p_plugin->toggle_fullscreen(&ex);
1509 RETURN_ON_EXCEPTION(this,ex);
1510 VOID_TO_NPVARIANT(result);
1511 return INVOKERESULT_NO_ERROR;
1513 return INVOKERESULT_NO_SUCH_METHOD;
1515 case ID_video_toggleteletext:
1519 libvlc_toggle_teletext(p_md, &ex);
1520 RETURN_ON_EXCEPTION(this,ex);
1521 VOID_TO_NPVARIANT(result);
1522 return INVOKERESULT_NO_ERROR;
1524 return INVOKERESULT_NO_SUCH_METHOD;
1526 case ID_video_deinterlacedisable:
1528 libvlc_video_set_deinterlace(p_md, 0, "", &ex);
1529 RETURN_ON_EXCEPTION(this,ex);
1530 return INVOKERESULT_NO_ERROR;
1532 case ID_video_deinterlaceenable:
1536 if( NPVARIANT_IS_STRING( args[0] ) )
1538 /* get deinterlace mode from the user */
1539 char *psz_mode = stringValue( NPVARIANT_TO_STRING( args[0] ) );
1540 /* enable deinterlace filter if possible */
1541 libvlc_video_set_deinterlace(p_md, 1, psz_mode, &ex);
1543 RETURN_ON_EXCEPTION(this,ex);
1544 return INVOKERESULT_NO_ERROR;
1548 return INVOKERESULT_INVALID_VALUE;
1553 return INVOKERESULT_NO_SUCH_METHOD;
1556 return INVOKERESULT_GENERIC_ERROR;
1560 ** implementation of libvlc marquee object
1563 const NPUTF8 * const LibvlcMarqueeNPObject::propertyNames[] =
1567 enum LibvlcMarqueeNPObjectPropertyIds
1570 COUNTNAMES(LibvlcMarqueeNPObject,propertyCount,propertyNames);
1572 RuntimeNPObject::InvokeResult
1573 LibvlcMarqueeNPObject::getProperty(int index, NPVariant &result)
1575 /* is plugin still running */
1576 if( isPluginRunning() )
1578 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1579 libvlc_exception_t ex;
1580 libvlc_exception_init(&ex);
1582 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1583 RETURN_ON_EXCEPTION(this,ex);
1589 return INVOKERESULT_GENERIC_ERROR;
1592 RuntimeNPObject::InvokeResult
1593 LibvlcMarqueeNPObject::setProperty(int index, const NPVariant &value)
1595 /* is plugin still running */
1596 if( isPluginRunning() )
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);
1609 return INVOKERESULT_GENERIC_ERROR;
1612 const NPUTF8 * const LibvlcMarqueeNPObject::methodNames[] =
1626 COUNTNAMES(LibvlcMarqueeNPObject,methodCount,methodNames);
1628 enum LibvlcMarqueeNPObjectMethodIds
1634 ID_marquee_position,
1643 RuntimeNPObject::InvokeResult
1644 LibvlcMarqueeNPObject::invoke(int index, const NPVariant *args,
1645 uint32_t argCount, NPVariant &result)
1647 /* is plugin still running */
1648 if( isPluginRunning() )
1650 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1651 libvlc_exception_t ex;
1652 libvlc_exception_init(&ex);
1654 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1655 RETURN_ON_EXCEPTION(this,ex);
1659 case ID_marquee_enable:
1661 libvlc_video_set_marquee_option_as_int(p_md, libvlc_marquee_Enabled, true, &ex);
1662 RETURN_ON_EXCEPTION(this,ex);
1663 return INVOKERESULT_NO_ERROR;
1665 case ID_marquee_disable:
1667 libvlc_video_set_marquee_option_as_int(p_md, libvlc_marquee_Enabled, false, &ex);
1668 RETURN_ON_EXCEPTION(this,ex);
1669 return INVOKERESULT_NO_ERROR;
1671 case ID_marquee_color:
1675 if( NPVARIANT_IS_INT32( args[0] ) )
1677 int i_color = NPVARIANT_TO_INT32( args[0] );
1678 libvlc_video_set_marquee_option_as_int(p_md, libvlc_marquee_Color, i_color, &ex);
1679 RETURN_ON_EXCEPTION(this,ex);
1680 return INVOKERESULT_NO_ERROR;
1683 return INVOKERESULT_GENERIC_ERROR;
1685 return INVOKERESULT_NO_SUCH_METHOD;
1687 case ID_marquee_opacity:
1691 if( NPVARIANT_IS_INT32( args[0] ) )
1693 int i_opacity = NPVARIANT_TO_INT32( args[0] );
1694 libvlc_video_set_marquee_option_as_int(p_md, libvlc_marquee_Opacity, i_opacity, &ex);
1695 RETURN_ON_EXCEPTION(this,ex);
1696 return INVOKERESULT_NO_ERROR;
1699 return INVOKERESULT_GENERIC_ERROR;
1701 return INVOKERESULT_NO_SUCH_METHOD;
1703 case ID_marquee_position:
1707 if( NPVARIANT_IS_INT32( args[0] ) )
1709 int i_position = NPVARIANT_TO_INT32( args[0] );
1710 libvlc_video_set_marquee_option_as_int(p_md, libvlc_marquee_Position, i_position, &ex);
1711 RETURN_ON_EXCEPTION(this,ex);
1712 return INVOKERESULT_NO_ERROR;
1715 return INVOKERESULT_GENERIC_ERROR;
1717 return INVOKERESULT_NO_SUCH_METHOD;
1719 case ID_marquee_refresh:
1723 if( NPVARIANT_IS_INT32( args[0] ) )
1725 int i_refresh = NPVARIANT_TO_INT32( args[0] );
1726 libvlc_video_set_marquee_option_as_int(p_md, libvlc_marquee_Refresh, i_refresh, &ex);
1727 RETURN_ON_EXCEPTION(this,ex);
1728 return INVOKERESULT_NO_ERROR;
1731 return INVOKERESULT_GENERIC_ERROR;
1733 return INVOKERESULT_NO_SUCH_METHOD;
1735 case ID_marquee_size:
1739 if( NPVARIANT_IS_INT32( args[0] ) )
1741 int i_size = NPVARIANT_TO_INT32( args[0] );
1742 libvlc_video_set_marquee_option_as_int(p_md, libvlc_marquee_Size, i_size, &ex);
1743 RETURN_ON_EXCEPTION(this,ex);
1744 return INVOKERESULT_NO_ERROR;
1747 return INVOKERESULT_GENERIC_ERROR;
1749 return INVOKERESULT_NO_SUCH_METHOD;
1751 case ID_marquee_text:
1755 if( NPVARIANT_IS_STRING( args[0] ) )
1757 char *psz_text = stringValue( NPVARIANT_TO_STRING( args[0] ) );
1758 libvlc_video_set_marquee_option_as_string(p_md, libvlc_marquee_Text, psz_text, &ex);
1759 RETURN_ON_EXCEPTION(this,ex);
1761 return INVOKERESULT_NO_ERROR;
1764 return INVOKERESULT_GENERIC_ERROR;
1766 return INVOKERESULT_NO_SUCH_METHOD;
1768 case ID_marquee_timeout:
1772 if( NPVARIANT_IS_INT32( args[0] ) )
1774 int i_timeout = NPVARIANT_TO_INT32( args[0] );
1775 libvlc_video_set_marquee_option_as_int(p_md, libvlc_marquee_Timeout, i_timeout, &ex);
1776 RETURN_ON_EXCEPTION(this,ex);
1777 return INVOKERESULT_NO_ERROR;
1780 return INVOKERESULT_GENERIC_ERROR;
1782 return INVOKERESULT_NO_SUCH_METHOD;
1788 if( NPVARIANT_IS_INT32( args[0] ) )
1790 int i_x = NPVARIANT_TO_INT32( args[0] );
1791 libvlc_video_set_marquee_option_as_int(p_md, libvlc_marquee_X, i_x, &ex);
1792 RETURN_ON_EXCEPTION(this,ex);
1793 return INVOKERESULT_NO_ERROR;
1796 return INVOKERESULT_GENERIC_ERROR;
1798 return INVOKERESULT_NO_SUCH_METHOD;
1804 if( NPVARIANT_IS_INT32( args[0] ) )
1806 int i_y = NPVARIANT_TO_INT32( args[0] );
1807 libvlc_video_set_marquee_option_as_int(p_md, libvlc_marquee_Y, i_y, &ex);
1808 RETURN_ON_EXCEPTION(this,ex);
1809 return INVOKERESULT_NO_ERROR;
1812 return INVOKERESULT_GENERIC_ERROR;
1814 return INVOKERESULT_NO_SUCH_METHOD;
1817 return INVOKERESULT_NO_SUCH_METHOD;
1820 return INVOKERESULT_GENERIC_ERROR;
1823 const NPUTF8 * const LibvlcLogoNPObject::propertyNames[] = {
1831 enum LibvlcLogoNPObjectPropertyIds {
1839 COUNTNAMES(LibvlcLogoNPObject,propertyCount,propertyNames);
1840 static const unsigned char logo_idx[] = {
1843 libvlc_logo_opacity,
1849 struct posidx_s { const char *n; size_t i; };
1850 static const posidx_s posidx[] = {
1858 { "bottom-left", 9 },
1859 { "bottom-right", 10 },
1861 enum { num_posidx = sizeof(posidx)/sizeof(*posidx) };
1863 static inline const char *logo_numtopos( size_t i )
1865 for( const posidx_s *h=posidx; h<posidx+num_posidx; ++h )
1871 static inline bool logo_postonum( const char *n, size_t &i )
1873 for( const posidx_s *h=posidx; h<posidx+num_posidx; ++h )
1874 if( !strcasecmp( n, h->n ) )
1875 { i=h->i; return true; }
1879 RuntimeNPObject::InvokeResult
1880 LibvlcLogoNPObject::getProperty(int index, NPVariant &result)
1882 if( !isPluginRunning() )
1883 return INVOKERESULT_GENERIC_ERROR;
1885 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1886 libvlc_exception_t ex;
1887 libvlc_exception_init(&ex);
1888 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1889 RETURN_ON_EXCEPTION(this,ex);
1894 case ID_logo_repeat:
1895 case ID_logo_opacity:
1900 libvlc_video_get_logo_int(p_md, logo_idx[index], &ex), result);
1902 RETURN_ON_EXCEPTION(this,ex);
1905 case ID_logo_position:
1906 STRINGZ_TO_NPVARIANT( logo_numtopos(
1907 libvlc_video_get_logo_int(p_md, libvlc_logo_position, &ex) ),
1910 RETURN_ON_EXCEPTION(this,ex);
1913 return INVOKERESULT_GENERIC_ERROR;
1915 return INVOKERESULT_NO_ERROR;
1918 RuntimeNPObject::InvokeResult
1919 LibvlcLogoNPObject::setProperty(int index, const NPVariant &value)
1923 if( !isPluginRunning() )
1924 return INVOKERESULT_GENERIC_ERROR;
1926 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1927 libvlc_exception_t ex;
1928 libvlc_exception_init(&ex);
1930 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1931 RETURN_ON_EXCEPTION(this,ex);
1936 case ID_logo_repeat:
1937 case ID_logo_opacity:
1940 if( !NPVARIANT_IS_INT32(value) )
1941 return INVOKERESULT_INVALID_VALUE;
1943 libvlc_video_set_logo_int(p_md, logo_idx[index],
1944 NPVARIANT_TO_INT32( value ), &ex);
1946 RETURN_ON_EXCEPTION(this,ex);
1949 case ID_logo_position:
1950 if( !NPVARIANT_IS_STRING(value) ||
1951 !logo_postonum( NPVARIANT_TO_STRING(value).utf8characters, i ) )
1952 return INVOKERESULT_INVALID_VALUE;
1954 libvlc_video_set_logo_int(p_md, libvlc_logo_position, i, &ex);
1956 RETURN_ON_EXCEPTION(this,ex);
1959 return INVOKERESULT_GENERIC_ERROR;
1961 return INVOKERESULT_NO_ERROR;
1965 const NPUTF8 * const LibvlcLogoNPObject::methodNames[] = {
1970 enum LibvlcLogoNPObjectMethodIds {
1975 COUNTNAMES(LibvlcLogoNPObject,methodCount,methodNames);
1977 RuntimeNPObject::InvokeResult
1978 LibvlcLogoNPObject::invoke(int index, const NPVariant *args,
1979 uint32_t argCount, NPVariant &result)
1984 if( !isPluginRunning() )
1985 return INVOKERESULT_GENERIC_ERROR;
1987 libvlc_exception_t ex;
1988 libvlc_exception_init(&ex);
1989 libvlc_media_player_t *p_md = getPrivate<VlcPlugin>()->getMD(&ex);
1990 RETURN_ON_EXCEPTION(this,ex);
1994 case ID_logo_enable:
1995 case ID_logo_disable:
1997 return INVOKERESULT_GENERIC_ERROR;
1999 libvlc_video_set_logo_int(p_md, libvlc_logo_enable,
2000 index != ID_logo_disable, &ex);
2001 RETURN_ON_EXCEPTION(this,ex);
2002 VOID_TO_NPVARIANT(result);
2007 return INVOKERESULT_GENERIC_ERROR;
2009 for( len=0,i=0;i<argCount;++i )
2011 if( !NPVARIANT_IS_STRING(args[i]) )
2012 return INVOKERESULT_INVALID_VALUE;
2013 len+=NPVARIANT_TO_STRING(args[i]).utf8length+1;
2016 buf = (char *)malloc( len+1 );
2018 return INVOKERESULT_OUT_OF_MEMORY;
2020 for( h=buf,i=0;i<argCount;++i )
2023 len=NPVARIANT_TO_STRING(args[i]).utf8length;
2024 memcpy(h,NPVARIANT_TO_STRING(args[i]).utf8characters,len);
2029 libvlc_video_set_logo_string(p_md, libvlc_logo_file, buf, &ex);
2031 RETURN_ON_EXCEPTION(this,ex);
2032 VOID_TO_NPVARIANT(result);
2035 return INVOKERESULT_NO_ERROR;