1 /*****************************************************************************
2 * npolibvlc.cpp: official Javascript APIs
3 *****************************************************************************
4 * Copyright (C) 2002-2009 the VideoLAN team
5 * Copyright (C) 2010 M2X BV
7 * Authors: Damien Fouilleul <Damien.Fouilleul@laposte.net>
8 * JP Dinger <jpd@videolan.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
32 #ifdef HAVE_MOZILLA_CONFIG_H
33 # include <mozilla-config.h>
36 #include "vlcplugin.h"
37 #include "npolibvlc.h"
42 ** Local helper macros and function
44 #define COUNTNAMES(a,b,c) const int a::b = sizeof(a::c)/sizeof(NPUTF8 *)
45 #define RETURN_ON_EXCEPTION(this,ex) \
46 do { if( libvlc_exception_raised(&ex) ) \
48 NPN_SetException(this, libvlc_errmsg()); \
49 libvlc_exception_clear(&ex); \
50 return INVOKERESULT_GENERIC_ERROR; \
53 #define ERROR_EVENT_NOT_FOUND "ERROR: One or more events could not be found."
54 #define ERROR_API_VERSION "ERROR: NPAPI version not high enough. (Gecko >= 1.9 needed)"
56 // Make a copy of an NPVariant.
57 NPVariant copyNPVariant(const NPVariant& original)
61 if (NPVARIANT_IS_STRING(original))
62 STRINGZ_TO_NPVARIANT(strdup(NPVARIANT_TO_STRING(original).utf8characters), res);
63 else if (NPVARIANT_IS_INT32(original))
64 INT32_TO_NPVARIANT(NPVARIANT_TO_INT32(original), res);
65 else if (NPVARIANT_IS_DOUBLE(original))
66 DOUBLE_TO_NPVARIANT(NPVARIANT_TO_DOUBLE(original), res);
67 else if (NPVARIANT_IS_OBJECT(original))
69 NPObject *obj = NPVARIANT_TO_OBJECT(original);
70 NPN_RetainObject(obj);
71 OBJECT_TO_NPVARIANT(obj, res);
73 else if (NPVARIANT_IS_BOOLEAN(original))
74 BOOLEAN_TO_NPVARIANT(NPVARIANT_TO_BOOLEAN(original), res);
80 ** implementation of libvlc root object
83 LibvlcRootNPObject::~LibvlcRootNPObject()
86 ** When the plugin is destroyed, firefox takes it upon itself to
87 ** destroy all 'live' script objects and ignores refcounting.
88 ** Therefore we cannot safely assume that refcounting will control
89 ** lifespan of objects. Hence they are only lazily created on
90 ** request, so that firefox can take ownership, and are not released
91 ** when the plugin is destroyed.
95 if( audioObj ) NPN_ReleaseObject(audioObj);
96 if( inputObj ) NPN_ReleaseObject(inputObj);
97 if( playlistObj ) NPN_ReleaseObject(playlistObj);
98 if( subtitleObj ) NPN_ReleaseObject(subtitleObj);
99 if( videoObj ) NPN_ReleaseObject(videoObj);
103 const NPUTF8 * const LibvlcRootNPObject::propertyNames[] =
112 COUNTNAMES(LibvlcRootNPObject,propertyCount,propertyNames);
114 enum LibvlcRootNPObjectPropertyIds
124 RuntimeNPObject::InvokeResult
125 LibvlcRootNPObject::getProperty(int index, NPVariant &result)
127 /* is plugin still running */
128 if( isPluginRunning() )
133 InstantObj<LibvlcAudioNPObject>( audioObj );
134 OBJECT_TO_NPVARIANT(NPN_RetainObject(audioObj), result);
135 return INVOKERESULT_NO_ERROR;
137 InstantObj<LibvlcInputNPObject>( inputObj );
138 OBJECT_TO_NPVARIANT(NPN_RetainObject(inputObj), result);
139 return INVOKERESULT_NO_ERROR;
140 case ID_root_playlist:
141 InstantObj<LibvlcPlaylistNPObject>( playlistObj );
142 OBJECT_TO_NPVARIANT(NPN_RetainObject(playlistObj), result);
143 return INVOKERESULT_NO_ERROR;
144 case ID_root_subtitle:
145 InstantObj<LibvlcSubtitleNPObject>( subtitleObj );
146 OBJECT_TO_NPVARIANT(NPN_RetainObject(subtitleObj), result);
147 return INVOKERESULT_NO_ERROR;
149 InstantObj<LibvlcVideoNPObject>( videoObj );
150 OBJECT_TO_NPVARIANT(NPN_RetainObject(videoObj), result);
151 return INVOKERESULT_NO_ERROR;
152 case ID_root_VersionInfo:
153 return invokeResultString(libvlc_get_version(),result);
158 return INVOKERESULT_GENERIC_ERROR;
161 const NPUTF8 * const LibvlcRootNPObject::methodNames[] =
165 "removeEventListener",
167 COUNTNAMES(LibvlcRootNPObject,methodCount,methodNames);
169 enum LibvlcRootNPObjectMethodIds
172 ID_root_addeventlistener,
173 ID_root_removeeventlistener,
176 RuntimeNPObject::InvokeResult LibvlcRootNPObject::invoke(int index,
177 const NPVariant *args, uint32_t argCount, NPVariant &result)
179 /* is plugin still running */
180 if( !isPluginRunning() )
181 return INVOKERESULT_GENERIC_ERROR;
183 libvlc_exception_t ex;
184 libvlc_exception_init(&ex);
188 case ID_root_versionInfo:
190 return INVOKERESULT_NO_SUCH_METHOD;
191 return invokeResultString(libvlc_get_version(),result);
193 case ID_root_addeventlistener:
194 case ID_root_removeeventlistener:
195 if( (3 != argCount) ||
196 !NPVARIANT_IS_STRING(args[0]) ||
197 !NPVARIANT_IS_OBJECT(args[1]) ||
198 !NPVARIANT_IS_BOOLEAN(args[2]) )
201 if( !VlcPlugin::canUseEventListener() )
203 NPN_SetException(this, ERROR_API_VERSION);
204 return INVOKERESULT_GENERIC_ERROR;
207 NPObject *listener = NPVARIANT_TO_OBJECT(args[1]);
208 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
211 if(ID_root_removeeventlistener!=index)
212 b = p_plugin->events.insert(NPVARIANT_TO_STRING(args[0]),
213 listener, NPVARIANT_TO_BOOLEAN(args[2]));
215 b = p_plugin->events.remove(NPVARIANT_TO_STRING(args[0]),
216 listener, NPVARIANT_TO_BOOLEAN(args[2]));
218 VOID_TO_NPVARIANT(result);
220 return b ? INVOKERESULT_NO_ERROR : INVOKERESULT_GENERIC_ERROR;
222 return INVOKERESULT_NO_SUCH_METHOD;
226 ** implementation of libvlc audio object
229 const NPUTF8 * const LibvlcAudioNPObject::propertyNames[] =
237 COUNTNAMES(LibvlcAudioNPObject,propertyCount,propertyNames);
239 enum LibvlcAudioNPObjectPropertyIds
248 RuntimeNPObject::InvokeResult
249 LibvlcAudioNPObject::getProperty(int index, NPVariant &result)
251 /* is plugin still running */
252 if( isPluginRunning() )
254 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
255 libvlc_exception_t ex;
256 libvlc_exception_init(&ex);
258 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
259 RETURN_ON_EXCEPTION(this,ex);
265 bool muted = libvlc_audio_get_mute(p_md);
266 BOOLEAN_TO_NPVARIANT(muted, result);
267 return INVOKERESULT_NO_ERROR;
269 case ID_audio_volume:
271 int volume = libvlc_audio_get_volume(p_md);
272 INT32_TO_NPVARIANT(volume, result);
273 return INVOKERESULT_NO_ERROR;
277 int track = libvlc_audio_get_track(p_md);
278 INT32_TO_NPVARIANT(track, result);
279 return INVOKERESULT_NO_ERROR;
283 // get the number of audio track available
284 int i_track = libvlc_audio_get_track_count(p_md);
286 INT32_TO_NPVARIANT(i_track, result);
287 return INVOKERESULT_NO_ERROR;
289 case ID_audio_channel:
291 int channel = libvlc_audio_get_channel(p_md);
292 INT32_TO_NPVARIANT(channel, result);
293 return INVOKERESULT_NO_ERROR;
299 return INVOKERESULT_GENERIC_ERROR;
302 RuntimeNPObject::InvokeResult
303 LibvlcAudioNPObject::setProperty(int index, const NPVariant &value)
305 /* is plugin still running */
306 if( isPluginRunning() )
308 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
309 libvlc_exception_t ex;
310 libvlc_exception_init(&ex);
312 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
313 RETURN_ON_EXCEPTION(this,ex);
318 if( NPVARIANT_IS_BOOLEAN(value) )
320 libvlc_audio_set_mute(p_md,
321 NPVARIANT_TO_BOOLEAN(value));
322 return INVOKERESULT_NO_ERROR;
324 return INVOKERESULT_INVALID_VALUE;
325 case ID_audio_volume:
326 if( isNumberValue(value) )
328 libvlc_audio_set_volume(p_md, numberValue(value));
329 return INVOKERESULT_NO_ERROR;
331 return INVOKERESULT_INVALID_VALUE;
333 if( isNumberValue(value) )
335 libvlc_audio_set_track(p_md, numberValue(value));
336 return INVOKERESULT_NO_ERROR;
338 return INVOKERESULT_INVALID_VALUE;
339 case ID_audio_channel:
340 if( isNumberValue(value) )
342 libvlc_audio_set_channel(p_md, numberValue(value));
343 return INVOKERESULT_NO_ERROR;
345 return INVOKERESULT_INVALID_VALUE;
350 return INVOKERESULT_GENERIC_ERROR;
353 const NPUTF8 * const LibvlcAudioNPObject::methodNames[] =
358 COUNTNAMES(LibvlcAudioNPObject,methodCount,methodNames);
360 enum LibvlcAudioNPObjectMethodIds
363 ID_audio_description,
366 RuntimeNPObject::InvokeResult
367 LibvlcAudioNPObject::invoke(int index, const NPVariant *args,
368 uint32_t argCount, NPVariant &result)
370 /* is plugin still running */
371 if( isPluginRunning() )
373 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
374 libvlc_exception_t ex;
375 libvlc_exception_init(&ex);
377 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
378 RETURN_ON_EXCEPTION(this,ex);
382 case ID_audio_togglemute:
385 libvlc_audio_toggle_mute(p_md);
386 VOID_TO_NPVARIANT(result);
387 return INVOKERESULT_NO_ERROR;
389 return INVOKERESULT_NO_SUCH_METHOD;
390 case ID_audio_description:
395 int i_trackID, i_limit, i;
396 libvlc_track_description_t *p_trackDesc;
398 /* get tracks description */
399 p_trackDesc = libvlc_audio_get_track_description(p_md);
401 return INVOKERESULT_GENERIC_ERROR;
403 /* get the number of track available */
404 i_limit = libvlc_audio_get_track_count(p_md);
406 /* check if a number is given by the user
407 * and get the track number */
408 if( isNumberValue(args[0]) )
409 i_trackID = numberValue(args[0]);
411 return INVOKERESULT_INVALID_VALUE;
413 /* if bad number is given return invalid value */
414 if ( ( i_trackID > ( i_limit - 1 ) ) || ( i_trackID < 0 ) )
415 return INVOKERESULT_INVALID_VALUE;
417 /* get the good trackDesc */
418 for( i = 0 ; i < i_trackID ; i++ )
420 p_trackDesc = p_trackDesc->p_next;
422 psz_name = p_trackDesc->psz_name;
424 /* display the name of the track chosen */
425 return invokeResultString( psz_name, result );
427 return INVOKERESULT_NO_SUCH_METHOD;
433 return INVOKERESULT_GENERIC_ERROR;
437 ** implementation of libvlc input object
440 const NPUTF8 * const LibvlcInputNPObject::propertyNames[] =
450 COUNTNAMES(LibvlcInputNPObject,propertyCount,propertyNames);
452 enum LibvlcInputNPObjectPropertyIds
463 RuntimeNPObject::InvokeResult
464 LibvlcInputNPObject::getProperty(int index, NPVariant &result)
466 /* is plugin still running */
467 if( isPluginRunning() )
469 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
470 libvlc_exception_t ex;
471 libvlc_exception_init(&ex);
473 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
474 if( libvlc_exception_raised(&ex) )
476 if( index != ID_input_state )
478 NPN_SetException(this, libvlc_errmsg());
479 libvlc_exception_clear(&ex);
480 return INVOKERESULT_GENERIC_ERROR;
484 /* for input state, return CLOSED rather than an exception */
485 INT32_TO_NPVARIANT(0, result);
486 libvlc_exception_clear(&ex);
487 return INVOKERESULT_NO_ERROR;
493 case ID_input_length:
495 double val = (double)libvlc_media_player_get_length(p_md);
496 DOUBLE_TO_NPVARIANT(val, result);
497 return INVOKERESULT_NO_ERROR;
499 case ID_input_position:
501 double val = libvlc_media_player_get_position(p_md);
502 DOUBLE_TO_NPVARIANT(val, result);
503 return INVOKERESULT_NO_ERROR;
507 double val = (double)libvlc_media_player_get_time(p_md);
508 DOUBLE_TO_NPVARIANT(val, result);
509 return INVOKERESULT_NO_ERROR;
513 int val = libvlc_media_player_get_state(p_md);
514 RETURN_ON_EXCEPTION(this,ex);
515 INT32_TO_NPVARIANT(val, result);
516 return INVOKERESULT_NO_ERROR;
520 float val = libvlc_media_player_get_rate(p_md);
521 DOUBLE_TO_NPVARIANT(val, result);
522 return INVOKERESULT_NO_ERROR;
526 double val = libvlc_media_player_get_fps(p_md);
527 DOUBLE_TO_NPVARIANT(val, result);
528 return INVOKERESULT_NO_ERROR;
530 case ID_input_hasvout:
532 bool val = p_plugin->player_has_vout(&ex);
533 RETURN_ON_EXCEPTION(this,ex);
534 BOOLEAN_TO_NPVARIANT(val, result);
535 return INVOKERESULT_NO_ERROR;
541 return INVOKERESULT_GENERIC_ERROR;
544 RuntimeNPObject::InvokeResult
545 LibvlcInputNPObject::setProperty(int index, const NPVariant &value)
547 /* is plugin still running */
548 if( isPluginRunning() )
550 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
551 libvlc_exception_t ex;
552 libvlc_exception_init(&ex);
554 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
555 RETURN_ON_EXCEPTION(this,ex);
559 case ID_input_position:
561 if( ! NPVARIANT_IS_DOUBLE(value) )
563 return INVOKERESULT_INVALID_VALUE;
566 float val = (float)NPVARIANT_TO_DOUBLE(value);
567 libvlc_media_player_set_position(p_md, val);
568 return INVOKERESULT_NO_ERROR;
573 if( NPVARIANT_IS_INT32(value) )
574 val = (int64_t)NPVARIANT_TO_INT32(value);
575 else if( NPVARIANT_IS_DOUBLE(value) )
576 val = (int64_t)NPVARIANT_TO_DOUBLE(value);
579 return INVOKERESULT_INVALID_VALUE;
582 libvlc_media_player_set_time(p_md, val);
583 return INVOKERESULT_NO_ERROR;
588 if( NPVARIANT_IS_INT32(value) )
589 val = (float)NPVARIANT_TO_INT32(value);
590 else if( NPVARIANT_IS_DOUBLE(value) )
591 val = (float)NPVARIANT_TO_DOUBLE(value);
594 return INVOKERESULT_INVALID_VALUE;
597 libvlc_media_player_set_rate(p_md, val);
598 return INVOKERESULT_NO_ERROR;
604 return INVOKERESULT_GENERIC_ERROR;
607 const NPUTF8 * const LibvlcInputNPObject::methodNames[] =
612 COUNTNAMES(LibvlcInputNPObject,methodCount,methodNames);
614 enum LibvlcInputNPObjectMethodIds
619 RuntimeNPObject::InvokeResult
620 LibvlcInputNPObject::invoke(int index, const NPVariant *args,
621 uint32_t argCount, NPVariant &result)
623 /* is plugin still running */
624 if( isPluginRunning() )
629 return INVOKERESULT_NO_SUCH_METHOD;
634 return INVOKERESULT_GENERIC_ERROR;
638 ** implementation of libvlc playlist items object
641 const NPUTF8 * const LibvlcPlaylistItemsNPObject::propertyNames[] =
645 COUNTNAMES(LibvlcPlaylistItemsNPObject,propertyCount,propertyNames);
647 enum LibvlcPlaylistItemsNPObjectPropertyIds
649 ID_playlistitems_count,
652 RuntimeNPObject::InvokeResult
653 LibvlcPlaylistItemsNPObject::getProperty(int index, NPVariant &result)
655 /* is plugin still running */
656 if( isPluginRunning() )
658 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
662 case ID_playlistitems_count:
664 int val = p_plugin->playlist_count();
665 INT32_TO_NPVARIANT(val, result);
666 return INVOKERESULT_NO_ERROR;
672 return INVOKERESULT_GENERIC_ERROR;
675 const NPUTF8 * const LibvlcPlaylistItemsNPObject::methodNames[] =
680 COUNTNAMES(LibvlcPlaylistItemsNPObject,methodCount,methodNames);
682 enum LibvlcPlaylistItemsNPObjectMethodIds
684 ID_playlistitems_clear,
685 ID_playlistitems_remove,
688 RuntimeNPObject::InvokeResult
689 LibvlcPlaylistItemsNPObject::invoke(int index, const NPVariant *args,
690 uint32_t argCount, NPVariant &result)
692 /* is plugin still running */
693 if( isPluginRunning() )
695 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
696 libvlc_exception_t ex;
697 libvlc_exception_init(&ex);
701 case ID_playlistitems_clear:
704 p_plugin->playlist_clear(&ex);
705 RETURN_ON_EXCEPTION(this,ex);
706 VOID_TO_NPVARIANT(result);
707 return INVOKERESULT_NO_ERROR;
709 return INVOKERESULT_NO_SUCH_METHOD;
710 case ID_playlistitems_remove:
711 if( (argCount == 1) && isNumberValue(args[0]) )
713 p_plugin->playlist_delete_item(numberValue(args[0]),&ex);
714 RETURN_ON_EXCEPTION(this,ex);
715 VOID_TO_NPVARIANT(result);
716 return INVOKERESULT_NO_ERROR;
718 return INVOKERESULT_NO_SUCH_METHOD;
723 return INVOKERESULT_GENERIC_ERROR;
727 ** implementation of libvlc playlist object
730 LibvlcPlaylistNPObject::~LibvlcPlaylistNPObject()
732 // Why the isValid()?
733 if( isValid() && playlistItemsObj )
734 NPN_ReleaseObject(playlistItemsObj);
737 const NPUTF8 * const LibvlcPlaylistNPObject::propertyNames[] =
739 "itemCount", /* deprecated */
743 COUNTNAMES(LibvlcPlaylistNPObject,propertyCount,propertyNames);
745 enum LibvlcPlaylistNPObjectPropertyIds
747 ID_playlist_itemcount,
748 ID_playlist_isplaying,
752 RuntimeNPObject::InvokeResult
753 LibvlcPlaylistNPObject::getProperty(int index, NPVariant &result)
755 /* is plugin still running */
756 if( isPluginRunning() )
758 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
762 case ID_playlist_itemcount: /* deprecated */
764 int val = p_plugin->playlist_count();
765 INT32_TO_NPVARIANT(val, result);
766 return INVOKERESULT_NO_ERROR;
768 case ID_playlist_isplaying:
770 int val = p_plugin->playlist_isplaying();
771 BOOLEAN_TO_NPVARIANT(val, result);
772 return INVOKERESULT_NO_ERROR;
774 case ID_playlist_items:
776 InstantObj<LibvlcPlaylistItemsNPObject>( playlistItemsObj );
777 OBJECT_TO_NPVARIANT(NPN_RetainObject(playlistItemsObj), result);
778 return INVOKERESULT_NO_ERROR;
784 return INVOKERESULT_GENERIC_ERROR;
787 const NPUTF8 * const LibvlcPlaylistNPObject::methodNames[] =
796 "clear", /* deprecated */
797 "removeItem", /* deprecated */
799 COUNTNAMES(LibvlcPlaylistNPObject,methodCount,methodNames);
801 enum LibvlcPlaylistNPObjectMethodIds
805 ID_playlist_playItem,
806 ID_playlist_togglepause,
811 ID_playlist_removeitem
814 RuntimeNPObject::InvokeResult
815 LibvlcPlaylistNPObject::invoke(int index, const NPVariant *args,
816 uint32_t argCount, NPVariant &result)
818 /* is plugin still running */
819 if( isPluginRunning() )
821 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
822 libvlc_exception_t ex;
823 libvlc_exception_init(&ex);
827 // XXX FIXME this needs squashing into something much smaller
828 case ID_playlist_add:
830 if( (argCount < 1) || (argCount > 3) )
831 return INVOKERESULT_NO_SUCH_METHOD;
832 if( !NPVARIANT_IS_STRING(args[0]) )
833 return INVOKERESULT_NO_SUCH_METHOD;
836 if( NPVARIANT_IS_NULL(args[0]) )
837 return INVOKERESULT_NO_SUCH_METHOD;
839 char *s = stringValue(NPVARIANT_TO_STRING(args[0]));
841 return INVOKERESULT_OUT_OF_MEMORY;
843 char *url = p_plugin->getAbsoluteURL(s);
847 // problem with combining url, use argument
852 // grab name if available
855 if( NPVARIANT_IS_NULL(args[1]) )
859 else if( NPVARIANT_IS_STRING(args[1]) )
861 name = stringValue(NPVARIANT_TO_STRING(args[1]));
866 return INVOKERESULT_INVALID_VALUE;
871 char** ppsz_options = NULL;
873 // grab options if available
876 if( NPVARIANT_IS_NULL(args[2]) )
880 else if( NPVARIANT_IS_STRING(args[2]) )
882 parseOptions(NPVARIANT_TO_STRING(args[2]),
883 &i_options, &ppsz_options);
886 else if( NPVARIANT_IS_OBJECT(args[2]) )
888 parseOptions(NPVARIANT_TO_OBJECT(args[2]),
889 &i_options, &ppsz_options);
895 return INVOKERESULT_INVALID_VALUE;
899 int item = p_plugin->playlist_add_extended_untrusted(url, name,
900 i_options, const_cast<const char **>(ppsz_options), &ex);
903 for( int i=0; i< i_options; ++i )
905 free(ppsz_options[i]);
909 RETURN_ON_EXCEPTION(this,ex);
910 INT32_TO_NPVARIANT(item, result);
911 return INVOKERESULT_NO_ERROR;
913 case ID_playlist_play:
916 p_plugin->playlist_play(&ex);
917 RETURN_ON_EXCEPTION(this,ex);
918 VOID_TO_NPVARIANT(result);
919 return INVOKERESULT_NO_ERROR;
921 return INVOKERESULT_NO_SUCH_METHOD;
922 case ID_playlist_playItem:
923 if( (argCount == 1) && isNumberValue(args[0]) )
925 p_plugin->playlist_play_item(numberValue(args[0]),&ex);
926 RETURN_ON_EXCEPTION(this,ex);
927 VOID_TO_NPVARIANT(result);
928 return INVOKERESULT_NO_ERROR;
930 return INVOKERESULT_NO_SUCH_METHOD;
931 case ID_playlist_togglepause:
934 p_plugin->playlist_pause();
935 VOID_TO_NPVARIANT(result);
936 return INVOKERESULT_NO_ERROR;
938 return INVOKERESULT_NO_SUCH_METHOD;
939 case ID_playlist_stop:
942 p_plugin->playlist_stop();
943 VOID_TO_NPVARIANT(result);
944 return INVOKERESULT_NO_ERROR;
946 return INVOKERESULT_NO_SUCH_METHOD;
947 case ID_playlist_next:
950 p_plugin->playlist_next(&ex);
951 RETURN_ON_EXCEPTION(this,ex);
952 VOID_TO_NPVARIANT(result);
953 return INVOKERESULT_NO_ERROR;
955 return INVOKERESULT_NO_SUCH_METHOD;
956 case ID_playlist_prev:
959 p_plugin->playlist_prev(&ex);
960 RETURN_ON_EXCEPTION(this,ex);
961 VOID_TO_NPVARIANT(result);
962 return INVOKERESULT_NO_ERROR;
964 return INVOKERESULT_NO_SUCH_METHOD;
965 case ID_playlist_clear: /* deprecated */
968 p_plugin->playlist_clear(&ex);
969 RETURN_ON_EXCEPTION(this,ex);
970 VOID_TO_NPVARIANT(result);
971 return INVOKERESULT_NO_ERROR;
973 return INVOKERESULT_NO_SUCH_METHOD;
974 case ID_playlist_removeitem: /* deprecated */
975 if( (argCount == 1) && isNumberValue(args[0]) )
977 p_plugin->playlist_delete_item(numberValue(args[0]), &ex);
978 RETURN_ON_EXCEPTION(this,ex);
979 VOID_TO_NPVARIANT(result);
980 return INVOKERESULT_NO_ERROR;
982 return INVOKERESULT_NO_SUCH_METHOD;
987 return INVOKERESULT_GENERIC_ERROR;
990 // XXX FIXME The new playlist_add creates a media instance and feeds it
991 // XXX FIXME these options one at a time, so this hunk of code does lots
992 // XXX FIXME of unnecessairy work. Break out something that can do one
993 // XXX FIXME option at a time and doesn't need to realloc().
994 // XXX FIXME Same for the other version of parseOptions.
996 void LibvlcPlaylistNPObject::parseOptions(const NPString &nps,
997 int *i_options, char*** ppsz_options)
1001 char *s = stringValue(nps);
1006 char **options = (char **)malloc(capacity*sizeof(char *));
1011 char *end = val + nps.utf8length;
1014 // skip leading blanks
1016 && ((*val == ' ' ) || (*val == '\t')) )
1020 // skip till we get a blank character
1026 if( ('\'' == c) || ('"' == c) )
1028 // skip till end of string
1029 while( (val < end) && (*(val++) != c ) );
1035 if( nOptions == capacity )
1038 char **moreOptions = (char **)realloc(options, capacity*sizeof(char*));
1041 /* failed to allocate more memory */
1043 /* return what we got so far */
1044 *i_options = nOptions;
1045 *ppsz_options = options;
1048 options = moreOptions;
1051 options[nOptions++] = strdup(start);
1054 // must be end of string
1057 *i_options = nOptions;
1058 *ppsz_options = options;
1065 // XXX FIXME See comment at the other parseOptions variant.
1066 void LibvlcPlaylistNPObject::parseOptions(NPObject *obj, int *i_options,
1067 char*** ppsz_options)
1069 /* WARNING: Safari does not implement NPN_HasProperty/NPN_HasMethod */
1073 /* we are expecting to have a Javascript Array object */
1074 NPIdentifier propId = NPN_GetStringIdentifier("length");
1075 if( NPN_GetProperty(_instance, obj, propId, &value) )
1077 int count = numberValue(value);
1078 NPN_ReleaseVariantValue(&value);
1083 char **options = (char **)malloc(capacity*sizeof(char *));
1088 while( nOptions < count )
1090 propId = NPN_GetIntIdentifier(nOptions);
1091 if( ! NPN_GetProperty(_instance, obj, propId, &value) )
1092 /* return what we got so far */
1095 if( ! NPVARIANT_IS_STRING(value) )
1097 /* return what we got so far */
1098 NPN_ReleaseVariantValue(&value);
1102 if( nOptions == capacity )
1105 char **moreOptions = (char **)realloc(options, capacity*sizeof(char*));
1108 /* failed to allocate more memory */
1109 NPN_ReleaseVariantValue(&value);
1110 /* return what we got so far */
1111 *i_options = nOptions;
1112 *ppsz_options = options;
1115 options = moreOptions;
1118 options[nOptions++] = stringValue(value);
1119 NPN_ReleaseVariantValue(&value);
1121 *i_options = nOptions;
1122 *ppsz_options = options;
1129 ** implementation of libvlc subtitle object
1132 const NPUTF8 * const LibvlcSubtitleNPObject::propertyNames[] =
1138 enum LibvlcSubtitleNPObjectPropertyIds
1143 COUNTNAMES(LibvlcSubtitleNPObject,propertyCount,propertyNames);
1145 RuntimeNPObject::InvokeResult
1146 LibvlcSubtitleNPObject::getProperty(int index, NPVariant &result)
1148 /* is plugin still running */
1149 if( isPluginRunning() )
1151 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1152 libvlc_exception_t ex;
1153 libvlc_exception_init(&ex);
1155 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1156 RETURN_ON_EXCEPTION(this,ex);
1160 case ID_subtitle_track:
1162 /* get the current subtitle ID */
1163 int i_spu = libvlc_video_get_spu(p_md, &ex);
1164 RETURN_ON_EXCEPTION(this,ex);
1166 INT32_TO_NPVARIANT(i_spu, result);
1167 return INVOKERESULT_NO_ERROR;
1169 case ID_subtitle_count:
1171 /* get the number of subtitles available */
1172 int i_spu = libvlc_video_get_spu_count(p_md, &ex);
1173 RETURN_ON_EXCEPTION(this,ex);
1175 INT32_TO_NPVARIANT(i_spu, result);
1176 return INVOKERESULT_NO_ERROR;
1180 return INVOKERESULT_GENERIC_ERROR;
1183 RuntimeNPObject::InvokeResult
1184 LibvlcSubtitleNPObject::setProperty(int index, const NPVariant &value)
1186 /* is plugin still running */
1187 if( isPluginRunning() )
1189 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1190 libvlc_exception_t ex;
1191 libvlc_exception_init(&ex);
1193 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1194 RETURN_ON_EXCEPTION(this,ex);
1198 case ID_subtitle_track:
1200 if( isNumberValue(value) )
1202 /* set the new subtitle track to show */
1203 libvlc_video_set_spu(p_md, numberValue(value), &ex);
1204 RETURN_ON_EXCEPTION(this,ex);
1206 return INVOKERESULT_NO_ERROR;
1208 return INVOKERESULT_INVALID_VALUE;
1212 return INVOKERESULT_GENERIC_ERROR;
1215 const NPUTF8 * const LibvlcSubtitleNPObject::methodNames[] =
1219 COUNTNAMES(LibvlcSubtitleNPObject,methodCount,methodNames);
1221 enum LibvlcSubtitleNPObjectMethodIds
1223 ID_subtitle_description
1226 RuntimeNPObject::InvokeResult
1227 LibvlcSubtitleNPObject::invoke(int index, const NPVariant *args,
1228 uint32_t argCount, NPVariant &result)
1230 /* is plugin still running */
1231 if( isPluginRunning() )
1233 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1234 libvlc_exception_t ex;
1235 libvlc_exception_init(&ex);
1237 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1238 RETURN_ON_EXCEPTION(this,ex);
1242 case ID_subtitle_description:
1247 int i_spuID, i_limit, i;
1248 libvlc_track_description_t *p_spuDesc;
1250 /* get subtitles description */
1251 p_spuDesc = libvlc_video_get_spu_description(p_md);
1253 return INVOKERESULT_GENERIC_ERROR;
1255 /* get the number of subtitle available */
1256 i_limit = libvlc_video_get_spu_count(p_md, &ex);
1257 RETURN_ON_EXCEPTION(this,ex);
1259 /* check if a number is given by the user
1260 * and get the subtitle number */
1261 if( isNumberValue(args[0]) )
1262 i_spuID = numberValue(args[0]);
1264 return INVOKERESULT_INVALID_VALUE;
1266 /* if bad number is given return invalid value */
1267 if ( ( i_spuID > ( i_limit -1 ) ) || ( i_spuID < 0 ) )
1268 return INVOKERESULT_INVALID_VALUE;
1270 /* get the good spuDesc */
1271 for( i = 0 ; i < i_spuID ; i++ )
1273 p_spuDesc = p_spuDesc->p_next;
1275 psz_name = p_spuDesc->psz_name;
1277 /* return the name of the track chosen */
1278 return invokeResultString(psz_name, result);
1280 return INVOKERESULT_NO_SUCH_METHOD;
1283 return INVOKERESULT_NO_SUCH_METHOD;
1286 return INVOKERESULT_GENERIC_ERROR;
1290 ** implementation of libvlc video object
1293 LibvlcVideoNPObject::~LibvlcVideoNPObject()
1297 if( marqueeObj ) NPN_ReleaseObject(marqueeObj);
1298 if( logoObj ) NPN_ReleaseObject(logoObj);
1299 if( deintObj ) NPN_ReleaseObject(deintObj);
1303 const NPUTF8 * const LibvlcVideoNPObject::propertyNames[] =
1317 enum LibvlcVideoNPObjectPropertyIds
1319 ID_video_fullscreen,
1322 ID_video_aspectratio,
1328 ID_video_deinterlace,
1330 COUNTNAMES(LibvlcVideoNPObject,propertyCount,propertyNames);
1332 RuntimeNPObject::InvokeResult
1333 LibvlcVideoNPObject::getProperty(int index, NPVariant &result)
1335 /* is plugin still running */
1336 if( isPluginRunning() )
1338 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1339 libvlc_exception_t ex;
1340 libvlc_exception_init(&ex);
1342 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1343 RETURN_ON_EXCEPTION(this,ex);
1347 case ID_video_fullscreen:
1349 int val = p_plugin->get_fullscreen(&ex);
1350 RETURN_ON_EXCEPTION(this,ex);
1351 BOOLEAN_TO_NPVARIANT(val, result);
1352 return INVOKERESULT_NO_ERROR;
1354 case ID_video_height:
1356 int val = libvlc_video_get_height(p_md, &ex);
1357 RETURN_ON_EXCEPTION(this,ex);
1358 INT32_TO_NPVARIANT(val, result);
1359 return INVOKERESULT_NO_ERROR;
1361 case ID_video_width:
1363 int val = libvlc_video_get_width(p_md, &ex);
1364 RETURN_ON_EXCEPTION(this,ex);
1365 INT32_TO_NPVARIANT(val, result);
1366 return INVOKERESULT_NO_ERROR;
1368 case ID_video_aspectratio:
1370 NPUTF8 *psz_aspect = libvlc_video_get_aspect_ratio(p_md, &ex);
1371 RETURN_ON_EXCEPTION(this,ex);
1373 return INVOKERESULT_GENERIC_ERROR;
1375 STRINGZ_TO_NPVARIANT(psz_aspect, result);
1376 return INVOKERESULT_NO_ERROR;
1378 case ID_video_subtitle:
1380 int i_spu = libvlc_video_get_spu(p_md, &ex);
1381 RETURN_ON_EXCEPTION(this,ex);
1382 INT32_TO_NPVARIANT(i_spu, result);
1383 return INVOKERESULT_NO_ERROR;
1387 NPUTF8 *psz_geometry = libvlc_video_get_crop_geometry(p_md, &ex);
1388 RETURN_ON_EXCEPTION(this,ex);
1390 return INVOKERESULT_GENERIC_ERROR;
1392 STRINGZ_TO_NPVARIANT(psz_geometry, result);
1393 return INVOKERESULT_NO_ERROR;
1395 case ID_video_teletext:
1397 /* int i_page = libvlc_video_get_teletext(p_md, &ex);
1398 RETURN_ON_EXCEPTION(this,ex);
1399 INT32_TO_NPVARIANT(i_page, result);
1400 return INVOKERESULT_NO_ERROR;
1402 return INVOKERESULT_NO_SUCH_METHOD;
1404 case ID_video_marquee:
1406 InstantObj<LibvlcMarqueeNPObject>( marqueeObj );
1407 OBJECT_TO_NPVARIANT(NPN_RetainObject(marqueeObj), result);
1408 return INVOKERESULT_NO_ERROR;
1412 InstantObj<LibvlcLogoNPObject>( logoObj );
1413 OBJECT_TO_NPVARIANT(NPN_RetainObject(logoObj), result);
1414 return INVOKERESULT_NO_ERROR;
1416 case ID_video_deinterlace:
1418 InstantObj<LibvlcDeinterlaceNPObject>( deintObj );
1419 OBJECT_TO_NPVARIANT(NPN_RetainObject(deintObj), result);
1420 return INVOKERESULT_NO_ERROR;
1424 return INVOKERESULT_GENERIC_ERROR;
1427 RuntimeNPObject::InvokeResult
1428 LibvlcVideoNPObject::setProperty(int index, const NPVariant &value)
1430 /* is plugin still running */
1431 if( isPluginRunning() )
1433 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1434 libvlc_exception_t ex;
1435 libvlc_exception_init(&ex);
1437 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1438 RETURN_ON_EXCEPTION(this,ex);
1442 case ID_video_fullscreen:
1444 if( ! NPVARIANT_IS_BOOLEAN(value) )
1446 return INVOKERESULT_INVALID_VALUE;
1449 int val = NPVARIANT_TO_BOOLEAN(value);
1450 p_plugin->set_fullscreen(val, &ex);
1451 RETURN_ON_EXCEPTION(this,ex);
1452 return INVOKERESULT_NO_ERROR;
1454 case ID_video_aspectratio:
1456 char *psz_aspect = NULL;
1458 if( ! NPVARIANT_IS_STRING(value) )
1460 return INVOKERESULT_INVALID_VALUE;
1463 psz_aspect = stringValue(NPVARIANT_TO_STRING(value));
1466 return INVOKERESULT_GENERIC_ERROR;
1469 libvlc_video_set_aspect_ratio(p_md, psz_aspect, &ex);
1471 RETURN_ON_EXCEPTION(this,ex);
1473 return INVOKERESULT_NO_ERROR;
1475 case ID_video_subtitle:
1477 if( isNumberValue(value) )
1479 libvlc_video_set_spu(p_md, numberValue(value), &ex);
1480 RETURN_ON_EXCEPTION(this,ex);
1482 return INVOKERESULT_NO_ERROR;
1484 return INVOKERESULT_INVALID_VALUE;
1488 char *psz_geometry = NULL;
1490 if( ! NPVARIANT_IS_STRING(value) )
1492 return INVOKERESULT_INVALID_VALUE;
1495 psz_geometry = stringValue(NPVARIANT_TO_STRING(value));
1498 return INVOKERESULT_GENERIC_ERROR;
1501 libvlc_video_set_crop_geometry(p_md, psz_geometry, &ex);
1503 RETURN_ON_EXCEPTION(this,ex);
1505 return INVOKERESULT_NO_ERROR;
1507 case ID_video_teletext:
1509 if( isNumberValue(value) )
1512 libvlc_video_set_teletext(p_md, numberValue(value), &ex);
1513 RETURN_ON_EXCEPTION(this,ex);
1515 return INVOKERESULT_NO_ERROR;
1517 return INVOKERESULT_NO_SUCH_METHOD;
1519 return INVOKERESULT_INVALID_VALUE;
1523 return INVOKERESULT_GENERIC_ERROR;
1526 const NPUTF8 * const LibvlcVideoNPObject::methodNames[] =
1531 COUNTNAMES(LibvlcVideoNPObject,methodCount,methodNames);
1533 enum LibvlcVideoNPObjectMethodIds
1535 ID_video_togglefullscreen,
1536 ID_video_toggleteletext,
1539 RuntimeNPObject::InvokeResult
1540 LibvlcVideoNPObject::invoke(int index, const NPVariant *args,
1541 uint32_t argCount, NPVariant &result)
1543 /* is plugin still running */
1544 if( isPluginRunning() )
1546 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1547 libvlc_exception_t ex;
1548 libvlc_exception_init(&ex);
1550 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1551 RETURN_ON_EXCEPTION(this,ex);
1555 case ID_video_togglefullscreen:
1559 p_plugin->toggle_fullscreen(&ex);
1560 RETURN_ON_EXCEPTION(this,ex);
1561 VOID_TO_NPVARIANT(result);
1562 return INVOKERESULT_NO_ERROR;
1564 return INVOKERESULT_NO_SUCH_METHOD;
1566 case ID_video_toggleteletext:
1570 libvlc_toggle_teletext(p_md);
1571 VOID_TO_NPVARIANT(result);
1572 return INVOKERESULT_NO_ERROR;
1574 return INVOKERESULT_NO_SUCH_METHOD;
1577 return INVOKERESULT_NO_SUCH_METHOD;
1580 return INVOKERESULT_GENERIC_ERROR;
1584 ** implementation of libvlc marquee object
1587 const NPUTF8 * const LibvlcMarqueeNPObject::propertyNames[] =
1600 enum LibvlcMarqueeNPObjectPropertyIds
1604 ID_marquee_position,
1613 COUNTNAMES(LibvlcMarqueeNPObject,propertyCount,propertyNames);
1615 static const unsigned char marquee_idx[] = {
1616 libvlc_marquee_Color,
1617 libvlc_marquee_Opacity,
1618 libvlc_marquee_Position,
1619 libvlc_marquee_Refresh,
1620 libvlc_marquee_Size,
1622 libvlc_marquee_Timeout,
1627 RuntimeNPObject::InvokeResult
1628 LibvlcMarqueeNPObject::getProperty(int index, NPVariant &result)
1632 if( !isPluginRunning() )
1633 return INVOKERESULT_GENERIC_ERROR;
1635 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1636 libvlc_exception_t ex;
1637 libvlc_exception_init(&ex);
1639 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1640 RETURN_ON_EXCEPTION(this,ex);
1644 case ID_marquee_color:
1645 case ID_marquee_opacity:
1646 case ID_marquee_refresh:
1647 case ID_marquee_timeout:
1648 case ID_marquee_size:
1652 libvlc_video_get_marquee_int(p_md, marquee_idx[index], &ex),
1654 RETURN_ON_EXCEPTION(this,ex);
1655 return INVOKERESULT_NO_ERROR;
1657 case ID_marquee_position:
1658 STRINGZ_TO_NPVARIANT( position_bynumber(
1659 libvlc_video_get_marquee_int(p_md, libvlc_marquee_Position, &ex) ),
1662 RETURN_ON_EXCEPTION(this,ex);
1665 case ID_marquee_text:
1666 psz = libvlc_video_get_marquee_string(p_md, libvlc_marquee_Text, &ex);
1669 STRINGZ_TO_NPVARIANT(psz, result);
1670 return INVOKERESULT_NO_ERROR;
1674 return INVOKERESULT_GENERIC_ERROR;
1677 RuntimeNPObject::InvokeResult
1678 LibvlcMarqueeNPObject::setProperty(int index, const NPVariant &value)
1682 if( !isPluginRunning() )
1683 return INVOKERESULT_GENERIC_ERROR;
1685 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1686 libvlc_exception_t ex;
1687 libvlc_exception_init(&ex);
1688 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1689 RETURN_ON_EXCEPTION(this,ex);
1693 case ID_marquee_color:
1694 case ID_marquee_opacity:
1695 case ID_marquee_refresh:
1696 case ID_marquee_timeout:
1699 if( NPVARIANT_IS_INT32( value ) )
1701 libvlc_video_set_marquee_int(p_md, marquee_idx[index],
1702 NPVARIANT_TO_INT32( value ), &ex);
1703 RETURN_ON_EXCEPTION(this,ex);
1704 return INVOKERESULT_NO_ERROR;
1708 case ID_marquee_position:
1709 if( !NPVARIANT_IS_STRING(value) ||
1710 !position_byname( NPVARIANT_TO_STRING(value).utf8characters, i ) )
1711 return INVOKERESULT_INVALID_VALUE;
1713 libvlc_video_set_marquee_int(p_md, libvlc_marquee_Position, i, &ex);
1714 RETURN_ON_EXCEPTION(this,ex);
1715 return INVOKERESULT_NO_ERROR;
1717 case ID_marquee_text:
1718 if( NPVARIANT_IS_STRING( value ) )
1720 char *psz_text = stringValue( NPVARIANT_TO_STRING( value ) );
1721 libvlc_video_set_marquee_string(p_md, libvlc_marquee_Text,
1724 RETURN_ON_EXCEPTION(this,ex);
1725 return INVOKERESULT_NO_ERROR;
1729 return INVOKERESULT_NO_SUCH_METHOD;
1732 const NPUTF8 * const LibvlcMarqueeNPObject::methodNames[] =
1737 COUNTNAMES(LibvlcMarqueeNPObject,methodCount,methodNames);
1739 enum LibvlcMarqueeNPObjectMethodIds
1745 RuntimeNPObject::InvokeResult
1746 LibvlcMarqueeNPObject::invoke(int index, const NPVariant *args,
1747 uint32_t argCount, NPVariant &result)
1749 if( !isPluginRunning() )
1750 return INVOKERESULT_GENERIC_ERROR;
1752 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1753 libvlc_exception_t ex;
1754 libvlc_exception_init(&ex);
1756 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1757 RETURN_ON_EXCEPTION(this,ex);
1761 case ID_marquee_enable:
1762 case ID_marquee_disable:
1763 libvlc_video_set_marquee_int(p_md, libvlc_marquee_Enable,
1764 index!=ID_marquee_disable, &ex);
1765 RETURN_ON_EXCEPTION(this,ex);
1766 VOID_TO_NPVARIANT(result);
1767 return INVOKERESULT_NO_ERROR;
1769 return INVOKERESULT_NO_SUCH_METHOD;
1772 const NPUTF8 * const LibvlcLogoNPObject::propertyNames[] = {
1780 enum LibvlcLogoNPObjectPropertyIds {
1788 COUNTNAMES(LibvlcLogoNPObject,propertyCount,propertyNames);
1789 static const unsigned char logo_idx[] = {
1792 libvlc_logo_opacity,
1798 RuntimeNPObject::InvokeResult
1799 LibvlcLogoNPObject::getProperty(int index, NPVariant &result)
1801 if( !isPluginRunning() )
1802 return INVOKERESULT_GENERIC_ERROR;
1804 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1805 libvlc_exception_t ex;
1806 libvlc_exception_init(&ex);
1807 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1808 RETURN_ON_EXCEPTION(this,ex);
1813 case ID_logo_repeat:
1814 case ID_logo_opacity:
1819 libvlc_video_get_logo_int(p_md, logo_idx[index], &ex), result);
1821 RETURN_ON_EXCEPTION(this,ex);
1824 case ID_logo_position:
1825 STRINGZ_TO_NPVARIANT( position_bynumber(
1826 libvlc_video_get_logo_int(p_md, libvlc_logo_position, &ex) ),
1829 RETURN_ON_EXCEPTION(this,ex);
1832 return INVOKERESULT_GENERIC_ERROR;
1834 return INVOKERESULT_NO_ERROR;
1837 RuntimeNPObject::InvokeResult
1838 LibvlcLogoNPObject::setProperty(int index, const NPVariant &value)
1842 if( !isPluginRunning() )
1843 return INVOKERESULT_GENERIC_ERROR;
1845 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1846 libvlc_exception_t ex;
1847 libvlc_exception_init(&ex);
1849 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1850 RETURN_ON_EXCEPTION(this,ex);
1855 case ID_logo_repeat:
1856 case ID_logo_opacity:
1859 if( !NPVARIANT_IS_INT32(value) )
1860 return INVOKERESULT_INVALID_VALUE;
1862 libvlc_video_set_logo_int(p_md, logo_idx[index],
1863 NPVARIANT_TO_INT32( value ), &ex);
1865 RETURN_ON_EXCEPTION(this,ex);
1868 case ID_logo_position:
1869 if( !NPVARIANT_IS_STRING(value) ||
1870 !position_byname( NPVARIANT_TO_STRING(value).utf8characters, i ) )
1871 return INVOKERESULT_INVALID_VALUE;
1873 libvlc_video_set_logo_int(p_md, libvlc_logo_position, i, &ex);
1875 RETURN_ON_EXCEPTION(this,ex);
1878 return INVOKERESULT_GENERIC_ERROR;
1880 return INVOKERESULT_NO_ERROR;
1884 const NPUTF8 * const LibvlcLogoNPObject::methodNames[] = {
1889 enum LibvlcLogoNPObjectMethodIds {
1894 COUNTNAMES(LibvlcLogoNPObject,methodCount,methodNames);
1896 RuntimeNPObject::InvokeResult
1897 LibvlcLogoNPObject::invoke(int index, const NPVariant *args,
1898 uint32_t argCount, NPVariant &result)
1903 if( !isPluginRunning() )
1904 return INVOKERESULT_GENERIC_ERROR;
1906 libvlc_exception_t ex;
1907 libvlc_exception_init(&ex);
1908 libvlc_media_player_t *p_md = getPrivate<VlcPlugin>()->getMD(&ex);
1909 RETURN_ON_EXCEPTION(this,ex);
1913 case ID_logo_enable:
1914 case ID_logo_disable:
1916 return INVOKERESULT_GENERIC_ERROR;
1918 libvlc_video_set_logo_int(p_md, libvlc_logo_enable,
1919 index != ID_logo_disable, &ex);
1920 RETURN_ON_EXCEPTION(this,ex);
1921 VOID_TO_NPVARIANT(result);
1926 return INVOKERESULT_GENERIC_ERROR;
1928 for( len=0,i=0;i<argCount;++i )
1930 if( !NPVARIANT_IS_STRING(args[i]) )
1931 return INVOKERESULT_INVALID_VALUE;
1932 len+=NPVARIANT_TO_STRING(args[i]).utf8length+1;
1935 buf = (char *)malloc( len+1 );
1937 return INVOKERESULT_OUT_OF_MEMORY;
1939 for( h=buf,i=0;i<argCount;++i )
1942 len=NPVARIANT_TO_STRING(args[i]).utf8length;
1943 memcpy(h,NPVARIANT_TO_STRING(args[i]).utf8characters,len);
1948 libvlc_video_set_logo_string(p_md, libvlc_logo_file, buf, &ex);
1950 RETURN_ON_EXCEPTION(this,ex);
1951 VOID_TO_NPVARIANT(result);
1954 return INVOKERESULT_NO_SUCH_METHOD;
1956 return INVOKERESULT_NO_ERROR;
1960 const NPUTF8 * const LibvlcDeinterlaceNPObject::propertyNames[] = {
1962 enum LibvlcDeinterlaceNPObjectPropertyIds {
1964 COUNTNAMES(LibvlcDeinterlaceNPObject,propertyCount,propertyNames);
1966 RuntimeNPObject::InvokeResult
1967 LibvlcDeinterlaceNPObject::getProperty(int index, NPVariant &result)
1969 return INVOKERESULT_GENERIC_ERROR;
1972 RuntimeNPObject::InvokeResult
1973 LibvlcDeinterlaceNPObject::setProperty(int index, const NPVariant &value)
1975 return INVOKERESULT_GENERIC_ERROR;
1979 const NPUTF8 * const LibvlcDeinterlaceNPObject::methodNames[] = {
1983 enum LibvlcDeinterlaceNPObjectMethodIds {
1987 COUNTNAMES(LibvlcDeinterlaceNPObject,methodCount,methodNames);
1989 RuntimeNPObject::InvokeResult
1990 LibvlcDeinterlaceNPObject::invoke(int index, const NPVariant *args,
1991 uint32_t argCount, NPVariant &result)
1995 if( !isPluginRunning() )
1996 return INVOKERESULT_GENERIC_ERROR;
1998 libvlc_exception_t ex;
1999 libvlc_exception_init(&ex);
2000 libvlc_media_player_t *p_md = getPrivate<VlcPlugin>()->getMD(&ex);
2001 RETURN_ON_EXCEPTION(this,ex);
2005 case ID_deint_disable:
2006 libvlc_video_set_deinterlace(p_md, 0, "", &ex);
2007 RETURN_ON_EXCEPTION(this,ex);
2010 case ID_deint_enable:
2011 if( argCount != 1 || !NPVARIANT_IS_STRING( args[0] ) )
2012 return INVOKERESULT_INVALID_VALUE;
2014 psz = stringValue( NPVARIANT_TO_STRING( args[0] ) );
2015 libvlc_video_set_deinterlace(p_md, 1, psz, &ex);
2017 RETURN_ON_EXCEPTION(this,ex);
2021 return INVOKERESULT_NO_SUCH_METHOD;
2023 return INVOKERESULT_NO_ERROR;