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);
262 bool muted = libvlc_audio_get_mute(p_plugin->getVLC());
263 BOOLEAN_TO_NPVARIANT(muted, result);
264 return INVOKERESULT_NO_ERROR;
266 case ID_audio_volume:
268 int volume = libvlc_audio_get_volume(p_plugin->getVLC());
269 INT32_TO_NPVARIANT(volume, result);
270 return INVOKERESULT_NO_ERROR;
274 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
275 RETURN_ON_EXCEPTION(this,ex);
276 int track = libvlc_audio_get_track(p_md, &ex);
277 RETURN_ON_EXCEPTION(this,ex);
278 INT32_TO_NPVARIANT(track, result);
279 return INVOKERESULT_NO_ERROR;
283 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
284 RETURN_ON_EXCEPTION(this,ex);
285 // get the number of audio track available
286 int i_track = libvlc_audio_get_track_count(p_md, &ex);
287 RETURN_ON_EXCEPTION(this,ex);
289 INT32_TO_NPVARIANT(i_track, result);
290 return INVOKERESULT_NO_ERROR;
292 case ID_audio_channel:
294 int channel = libvlc_audio_get_channel(p_plugin->getVLC(), &ex);
295 RETURN_ON_EXCEPTION(this,ex);
296 INT32_TO_NPVARIANT(channel, result);
297 return INVOKERESULT_NO_ERROR;
303 return INVOKERESULT_GENERIC_ERROR;
306 RuntimeNPObject::InvokeResult
307 LibvlcAudioNPObject::setProperty(int index, const NPVariant &value)
309 /* is plugin still running */
310 if( isPluginRunning() )
312 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
313 libvlc_exception_t ex;
314 libvlc_exception_init(&ex);
319 if( NPVARIANT_IS_BOOLEAN(value) )
321 libvlc_audio_set_mute(p_plugin->getVLC(),
322 NPVARIANT_TO_BOOLEAN(value));
323 return INVOKERESULT_NO_ERROR;
325 return INVOKERESULT_INVALID_VALUE;
326 case ID_audio_volume:
327 if( isNumberValue(value) )
329 libvlc_audio_set_volume(p_plugin->getVLC(),
330 numberValue(value), &ex);
331 RETURN_ON_EXCEPTION(this,ex);
332 return INVOKERESULT_NO_ERROR;
334 return INVOKERESULT_INVALID_VALUE;
336 if( isNumberValue(value) )
338 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
339 RETURN_ON_EXCEPTION(this,ex);
340 libvlc_audio_set_track(p_md, numberValue(value), &ex);
341 RETURN_ON_EXCEPTION(this,ex);
342 return INVOKERESULT_NO_ERROR;
344 return INVOKERESULT_INVALID_VALUE;
345 case ID_audio_channel:
346 if( isNumberValue(value) )
348 libvlc_audio_set_channel(p_plugin->getVLC(),
349 numberValue(value), &ex);
350 RETURN_ON_EXCEPTION(this,ex);
351 return INVOKERESULT_NO_ERROR;
353 return INVOKERESULT_INVALID_VALUE;
358 return INVOKERESULT_GENERIC_ERROR;
361 const NPUTF8 * const LibvlcAudioNPObject::methodNames[] =
366 COUNTNAMES(LibvlcAudioNPObject,methodCount,methodNames);
368 enum LibvlcAudioNPObjectMethodIds
371 ID_audio_description,
374 RuntimeNPObject::InvokeResult
375 LibvlcAudioNPObject::invoke(int index, const NPVariant *args,
376 uint32_t argCount, NPVariant &result)
378 /* is plugin still running */
379 if( isPluginRunning() )
381 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
382 libvlc_exception_t ex;
383 libvlc_exception_init(&ex);
387 case ID_audio_togglemute:
390 libvlc_audio_toggle_mute(p_plugin->getVLC());
391 VOID_TO_NPVARIANT(result);
392 return INVOKERESULT_NO_ERROR;
394 return INVOKERESULT_NO_SUCH_METHOD;
395 case ID_audio_description:
400 int i_trackID, i_limit, i;
401 libvlc_track_description_t *p_trackDesc;
403 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
404 RETURN_ON_EXCEPTION(this,ex);
406 /* get tracks description */
407 p_trackDesc = libvlc_audio_get_track_description(p_md, &ex);
408 RETURN_ON_EXCEPTION(this,ex);
410 return INVOKERESULT_GENERIC_ERROR;
412 /* get the number of track available */
413 i_limit = libvlc_audio_get_track_count(p_md, &ex);
414 RETURN_ON_EXCEPTION(this,ex);
416 /* check if a number is given by the user
417 * and get the track number */
418 if( isNumberValue(args[0]) )
419 i_trackID = numberValue(args[0]);
421 return INVOKERESULT_INVALID_VALUE;
423 /* if bad number is given return invalid value */
424 if ( ( i_trackID > ( i_limit - 1 ) ) || ( i_trackID < 0 ) )
425 return INVOKERESULT_INVALID_VALUE;
427 /* get the good trackDesc */
428 for( i = 0 ; i < i_trackID ; i++ )
430 p_trackDesc = p_trackDesc->p_next;
432 psz_name = p_trackDesc->psz_name;
434 /* display the name of the track chosen */
435 return invokeResultString( psz_name, result );
437 return INVOKERESULT_NO_SUCH_METHOD;
443 return INVOKERESULT_GENERIC_ERROR;
447 ** implementation of libvlc input object
450 const NPUTF8 * const LibvlcInputNPObject::propertyNames[] =
460 COUNTNAMES(LibvlcInputNPObject,propertyCount,propertyNames);
462 enum LibvlcInputNPObjectPropertyIds
473 RuntimeNPObject::InvokeResult
474 LibvlcInputNPObject::getProperty(int index, NPVariant &result)
476 /* is plugin still running */
477 if( isPluginRunning() )
479 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
480 libvlc_exception_t ex;
481 libvlc_exception_init(&ex);
483 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
484 if( libvlc_exception_raised(&ex) )
486 if( index != ID_input_state )
488 NPN_SetException(this, libvlc_errmsg());
489 libvlc_exception_clear(&ex);
490 return INVOKERESULT_GENERIC_ERROR;
494 /* for input state, return CLOSED rather than an exception */
495 INT32_TO_NPVARIANT(0, result);
496 libvlc_exception_clear(&ex);
497 return INVOKERESULT_NO_ERROR;
503 case ID_input_length:
505 double val = (double)libvlc_media_player_get_length(p_md, &ex);
506 RETURN_ON_EXCEPTION(this,ex);
507 DOUBLE_TO_NPVARIANT(val, result);
508 return INVOKERESULT_NO_ERROR;
510 case ID_input_position:
512 double val = libvlc_media_player_get_position(p_md, &ex);
513 RETURN_ON_EXCEPTION(this,ex);
514 DOUBLE_TO_NPVARIANT(val, result);
515 return INVOKERESULT_NO_ERROR;
519 double val = (double)libvlc_media_player_get_time(p_md, &ex);
520 RETURN_ON_EXCEPTION(this,ex);
521 DOUBLE_TO_NPVARIANT(val, result);
522 return INVOKERESULT_NO_ERROR;
526 int val = libvlc_media_player_get_state(p_md);
527 RETURN_ON_EXCEPTION(this,ex);
528 INT32_TO_NPVARIANT(val, result);
529 return INVOKERESULT_NO_ERROR;
533 float val = libvlc_media_player_get_rate(p_md, &ex);
534 RETURN_ON_EXCEPTION(this,ex);
535 DOUBLE_TO_NPVARIANT(val, result);
536 return INVOKERESULT_NO_ERROR;
540 double val = libvlc_media_player_get_fps(p_md, &ex);
541 RETURN_ON_EXCEPTION(this,ex);
542 DOUBLE_TO_NPVARIANT(val, result);
543 return INVOKERESULT_NO_ERROR;
545 case ID_input_hasvout:
547 bool val = p_plugin->player_has_vout(&ex);
548 RETURN_ON_EXCEPTION(this,ex);
549 BOOLEAN_TO_NPVARIANT(val, result);
550 return INVOKERESULT_NO_ERROR;
556 return INVOKERESULT_GENERIC_ERROR;
559 RuntimeNPObject::InvokeResult
560 LibvlcInputNPObject::setProperty(int index, const NPVariant &value)
562 /* is plugin still running */
563 if( isPluginRunning() )
565 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
566 libvlc_exception_t ex;
567 libvlc_exception_init(&ex);
569 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
570 RETURN_ON_EXCEPTION(this,ex);
574 case ID_input_position:
576 if( ! NPVARIANT_IS_DOUBLE(value) )
578 return INVOKERESULT_INVALID_VALUE;
581 float val = (float)NPVARIANT_TO_DOUBLE(value);
582 libvlc_media_player_set_position(p_md, val, &ex);
583 RETURN_ON_EXCEPTION(this,ex);
584 return INVOKERESULT_NO_ERROR;
589 if( NPVARIANT_IS_INT32(value) )
590 val = (int64_t)NPVARIANT_TO_INT32(value);
591 else if( NPVARIANT_IS_DOUBLE(value) )
592 val = (int64_t)NPVARIANT_TO_DOUBLE(value);
595 return INVOKERESULT_INVALID_VALUE;
598 libvlc_media_player_set_time(p_md, val, &ex);
599 RETURN_ON_EXCEPTION(this,ex);
600 return INVOKERESULT_NO_ERROR;
605 if( NPVARIANT_IS_INT32(value) )
606 val = (float)NPVARIANT_TO_INT32(value);
607 else if( NPVARIANT_IS_DOUBLE(value) )
608 val = (float)NPVARIANT_TO_DOUBLE(value);
611 return INVOKERESULT_INVALID_VALUE;
614 libvlc_media_player_set_rate(p_md, val, &ex);
615 RETURN_ON_EXCEPTION(this,ex);
616 return INVOKERESULT_NO_ERROR;
622 return INVOKERESULT_GENERIC_ERROR;
625 const NPUTF8 * const LibvlcInputNPObject::methodNames[] =
630 COUNTNAMES(LibvlcInputNPObject,methodCount,methodNames);
632 enum LibvlcInputNPObjectMethodIds
637 RuntimeNPObject::InvokeResult
638 LibvlcInputNPObject::invoke(int index, const NPVariant *args,
639 uint32_t argCount, NPVariant &result)
641 /* is plugin still running */
642 if( isPluginRunning() )
647 return INVOKERESULT_NO_SUCH_METHOD;
652 return INVOKERESULT_GENERIC_ERROR;
656 ** implementation of libvlc playlist items object
659 const NPUTF8 * const LibvlcPlaylistItemsNPObject::propertyNames[] =
663 COUNTNAMES(LibvlcPlaylistItemsNPObject,propertyCount,propertyNames);
665 enum LibvlcPlaylistItemsNPObjectPropertyIds
667 ID_playlistitems_count,
670 RuntimeNPObject::InvokeResult
671 LibvlcPlaylistItemsNPObject::getProperty(int index, NPVariant &result)
673 /* is plugin still running */
674 if( isPluginRunning() )
676 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
680 case ID_playlistitems_count:
682 int val = p_plugin->playlist_count();
683 INT32_TO_NPVARIANT(val, result);
684 return INVOKERESULT_NO_ERROR;
690 return INVOKERESULT_GENERIC_ERROR;
693 const NPUTF8 * const LibvlcPlaylistItemsNPObject::methodNames[] =
698 COUNTNAMES(LibvlcPlaylistItemsNPObject,methodCount,methodNames);
700 enum LibvlcPlaylistItemsNPObjectMethodIds
702 ID_playlistitems_clear,
703 ID_playlistitems_remove,
706 RuntimeNPObject::InvokeResult
707 LibvlcPlaylistItemsNPObject::invoke(int index, const NPVariant *args,
708 uint32_t argCount, NPVariant &result)
710 /* is plugin still running */
711 if( isPluginRunning() )
713 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
714 libvlc_exception_t ex;
715 libvlc_exception_init(&ex);
719 case ID_playlistitems_clear:
722 p_plugin->playlist_clear(&ex);
723 RETURN_ON_EXCEPTION(this,ex);
724 VOID_TO_NPVARIANT(result);
725 return INVOKERESULT_NO_ERROR;
727 return INVOKERESULT_NO_SUCH_METHOD;
728 case ID_playlistitems_remove:
729 if( (argCount == 1) && isNumberValue(args[0]) )
731 p_plugin->playlist_delete_item(numberValue(args[0]),&ex);
732 RETURN_ON_EXCEPTION(this,ex);
733 VOID_TO_NPVARIANT(result);
734 return INVOKERESULT_NO_ERROR;
736 return INVOKERESULT_NO_SUCH_METHOD;
741 return INVOKERESULT_GENERIC_ERROR;
745 ** implementation of libvlc playlist object
748 LibvlcPlaylistNPObject::~LibvlcPlaylistNPObject()
750 // Why the isValid()?
751 if( isValid() && playlistItemsObj )
752 NPN_ReleaseObject(playlistItemsObj);
755 const NPUTF8 * const LibvlcPlaylistNPObject::propertyNames[] =
757 "itemCount", /* deprecated */
761 COUNTNAMES(LibvlcPlaylistNPObject,propertyCount,propertyNames);
763 enum LibvlcPlaylistNPObjectPropertyIds
765 ID_playlist_itemcount,
766 ID_playlist_isplaying,
770 RuntimeNPObject::InvokeResult
771 LibvlcPlaylistNPObject::getProperty(int index, NPVariant &result)
773 /* is plugin still running */
774 if( isPluginRunning() )
776 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
780 case ID_playlist_itemcount: /* deprecated */
782 int val = p_plugin->playlist_count();
783 INT32_TO_NPVARIANT(val, result);
784 return INVOKERESULT_NO_ERROR;
786 case ID_playlist_isplaying:
788 int val = p_plugin->playlist_isplaying();
789 BOOLEAN_TO_NPVARIANT(val, result);
790 return INVOKERESULT_NO_ERROR;
792 case ID_playlist_items:
794 InstantObj<LibvlcPlaylistItemsNPObject>( playlistItemsObj );
795 OBJECT_TO_NPVARIANT(NPN_RetainObject(playlistItemsObj), result);
796 return INVOKERESULT_NO_ERROR;
802 return INVOKERESULT_GENERIC_ERROR;
805 const NPUTF8 * const LibvlcPlaylistNPObject::methodNames[] =
814 "clear", /* deprecated */
815 "removeItem", /* deprecated */
817 COUNTNAMES(LibvlcPlaylistNPObject,methodCount,methodNames);
819 enum LibvlcPlaylistNPObjectMethodIds
823 ID_playlist_playItem,
824 ID_playlist_togglepause,
829 ID_playlist_removeitem
832 RuntimeNPObject::InvokeResult
833 LibvlcPlaylistNPObject::invoke(int index, const NPVariant *args,
834 uint32_t argCount, NPVariant &result)
836 /* is plugin still running */
837 if( isPluginRunning() )
839 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
840 libvlc_exception_t ex;
841 libvlc_exception_init(&ex);
845 // XXX FIXME this needs squashing into something much smaller
846 case ID_playlist_add:
848 if( (argCount < 1) || (argCount > 3) )
849 return INVOKERESULT_NO_SUCH_METHOD;
850 if( !NPVARIANT_IS_STRING(args[0]) )
851 return INVOKERESULT_NO_SUCH_METHOD;
854 if( NPVARIANT_IS_NULL(args[0]) )
855 return INVOKERESULT_NO_SUCH_METHOD;
857 char *s = stringValue(NPVARIANT_TO_STRING(args[0]));
859 return INVOKERESULT_OUT_OF_MEMORY;
861 char *url = p_plugin->getAbsoluteURL(s);
865 // problem with combining url, use argument
870 // grab name if available
873 if( NPVARIANT_IS_NULL(args[1]) )
877 else if( NPVARIANT_IS_STRING(args[1]) )
879 name = stringValue(NPVARIANT_TO_STRING(args[1]));
884 return INVOKERESULT_INVALID_VALUE;
889 char** ppsz_options = NULL;
891 // grab options if available
894 if( NPVARIANT_IS_NULL(args[2]) )
898 else if( NPVARIANT_IS_STRING(args[2]) )
900 parseOptions(NPVARIANT_TO_STRING(args[2]),
901 &i_options, &ppsz_options);
904 else if( NPVARIANT_IS_OBJECT(args[2]) )
906 parseOptions(NPVARIANT_TO_OBJECT(args[2]),
907 &i_options, &ppsz_options);
913 return INVOKERESULT_INVALID_VALUE;
917 int item = p_plugin->playlist_add_extended_untrusted(url, name,
918 i_options, const_cast<const char **>(ppsz_options), &ex);
921 for( int i=0; i< i_options; ++i )
923 free(ppsz_options[i]);
927 RETURN_ON_EXCEPTION(this,ex);
928 INT32_TO_NPVARIANT(item, result);
929 return INVOKERESULT_NO_ERROR;
931 case ID_playlist_play:
934 p_plugin->playlist_play(&ex);
935 RETURN_ON_EXCEPTION(this,ex);
936 VOID_TO_NPVARIANT(result);
937 return INVOKERESULT_NO_ERROR;
939 return INVOKERESULT_NO_SUCH_METHOD;
940 case ID_playlist_playItem:
941 if( (argCount == 1) && isNumberValue(args[0]) )
943 p_plugin->playlist_play_item(numberValue(args[0]),&ex);
944 RETURN_ON_EXCEPTION(this,ex);
945 VOID_TO_NPVARIANT(result);
946 return INVOKERESULT_NO_ERROR;
948 return INVOKERESULT_NO_SUCH_METHOD;
949 case ID_playlist_togglepause:
952 p_plugin->playlist_pause(&ex);
953 RETURN_ON_EXCEPTION(this,ex);
954 VOID_TO_NPVARIANT(result);
955 return INVOKERESULT_NO_ERROR;
957 return INVOKERESULT_NO_SUCH_METHOD;
958 case ID_playlist_stop:
961 p_plugin->playlist_stop();
962 VOID_TO_NPVARIANT(result);
963 return INVOKERESULT_NO_ERROR;
965 return INVOKERESULT_NO_SUCH_METHOD;
966 case ID_playlist_next:
969 p_plugin->playlist_next(&ex);
970 RETURN_ON_EXCEPTION(this,ex);
971 VOID_TO_NPVARIANT(result);
972 return INVOKERESULT_NO_ERROR;
974 return INVOKERESULT_NO_SUCH_METHOD;
975 case ID_playlist_prev:
978 p_plugin->playlist_prev(&ex);
979 RETURN_ON_EXCEPTION(this,ex);
980 VOID_TO_NPVARIANT(result);
981 return INVOKERESULT_NO_ERROR;
983 return INVOKERESULT_NO_SUCH_METHOD;
984 case ID_playlist_clear: /* deprecated */
987 p_plugin->playlist_clear(&ex);
988 RETURN_ON_EXCEPTION(this,ex);
989 VOID_TO_NPVARIANT(result);
990 return INVOKERESULT_NO_ERROR;
992 return INVOKERESULT_NO_SUCH_METHOD;
993 case ID_playlist_removeitem: /* deprecated */
994 if( (argCount == 1) && isNumberValue(args[0]) )
996 p_plugin->playlist_delete_item(numberValue(args[0]), &ex);
997 RETURN_ON_EXCEPTION(this,ex);
998 VOID_TO_NPVARIANT(result);
999 return INVOKERESULT_NO_ERROR;
1001 return INVOKERESULT_NO_SUCH_METHOD;
1006 return INVOKERESULT_GENERIC_ERROR;
1009 // XXX FIXME The new playlist_add creates a media instance and feeds it
1010 // XXX FIXME these options one at a time, so this hunk of code does lots
1011 // XXX FIXME of unnecessairy work. Break out something that can do one
1012 // XXX FIXME option at a time and doesn't need to realloc().
1013 // XXX FIXME Same for the other version of parseOptions.
1015 void LibvlcPlaylistNPObject::parseOptions(const NPString &nps,
1016 int *i_options, char*** ppsz_options)
1018 if( nps.utf8length )
1020 char *s = stringValue(nps);
1025 char **options = (char **)malloc(capacity*sizeof(char *));
1030 char *end = val + nps.utf8length;
1033 // skip leading blanks
1035 && ((*val == ' ' ) || (*val == '\t')) )
1039 // skip till we get a blank character
1045 if( ('\'' == c) || ('"' == c) )
1047 // skip till end of string
1048 while( (val < end) && (*(val++) != c ) );
1054 if( nOptions == capacity )
1057 char **moreOptions = (char **)realloc(options, capacity*sizeof(char*));
1060 /* failed to allocate more memory */
1062 /* return what we got so far */
1063 *i_options = nOptions;
1064 *ppsz_options = options;
1067 options = moreOptions;
1070 options[nOptions++] = strdup(start);
1073 // must be end of string
1076 *i_options = nOptions;
1077 *ppsz_options = options;
1084 // XXX FIXME See comment at the other parseOptions variant.
1085 void LibvlcPlaylistNPObject::parseOptions(NPObject *obj, int *i_options,
1086 char*** ppsz_options)
1088 /* WARNING: Safari does not implement NPN_HasProperty/NPN_HasMethod */
1092 /* we are expecting to have a Javascript Array object */
1093 NPIdentifier propId = NPN_GetStringIdentifier("length");
1094 if( NPN_GetProperty(_instance, obj, propId, &value) )
1096 int count = numberValue(value);
1097 NPN_ReleaseVariantValue(&value);
1102 char **options = (char **)malloc(capacity*sizeof(char *));
1107 while( nOptions < count )
1109 propId = NPN_GetIntIdentifier(nOptions);
1110 if( ! NPN_GetProperty(_instance, obj, propId, &value) )
1111 /* return what we got so far */
1114 if( ! NPVARIANT_IS_STRING(value) )
1116 /* return what we got so far */
1117 NPN_ReleaseVariantValue(&value);
1121 if( nOptions == capacity )
1124 char **moreOptions = (char **)realloc(options, capacity*sizeof(char*));
1127 /* failed to allocate more memory */
1128 NPN_ReleaseVariantValue(&value);
1129 /* return what we got so far */
1130 *i_options = nOptions;
1131 *ppsz_options = options;
1134 options = moreOptions;
1137 options[nOptions++] = stringValue(value);
1138 NPN_ReleaseVariantValue(&value);
1140 *i_options = nOptions;
1141 *ppsz_options = options;
1148 ** implementation of libvlc subtitle object
1151 const NPUTF8 * const LibvlcSubtitleNPObject::propertyNames[] =
1157 enum LibvlcSubtitleNPObjectPropertyIds
1162 COUNTNAMES(LibvlcSubtitleNPObject,propertyCount,propertyNames);
1164 RuntimeNPObject::InvokeResult
1165 LibvlcSubtitleNPObject::getProperty(int index, NPVariant &result)
1167 /* is plugin still running */
1168 if( isPluginRunning() )
1170 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1171 libvlc_exception_t ex;
1172 libvlc_exception_init(&ex);
1174 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1175 RETURN_ON_EXCEPTION(this,ex);
1179 case ID_subtitle_track:
1181 /* get the current subtitle ID */
1182 int i_spu = libvlc_video_get_spu(p_md, &ex);
1183 RETURN_ON_EXCEPTION(this,ex);
1185 INT32_TO_NPVARIANT(i_spu, result);
1186 return INVOKERESULT_NO_ERROR;
1188 case ID_subtitle_count:
1190 /* get the number of subtitles available */
1191 int i_spu = libvlc_video_get_spu_count(p_md, &ex);
1192 RETURN_ON_EXCEPTION(this,ex);
1194 INT32_TO_NPVARIANT(i_spu, result);
1195 return INVOKERESULT_NO_ERROR;
1199 return INVOKERESULT_GENERIC_ERROR;
1202 RuntimeNPObject::InvokeResult
1203 LibvlcSubtitleNPObject::setProperty(int index, const NPVariant &value)
1205 /* is plugin still running */
1206 if( isPluginRunning() )
1208 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1209 libvlc_exception_t ex;
1210 libvlc_exception_init(&ex);
1212 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1213 RETURN_ON_EXCEPTION(this,ex);
1217 case ID_subtitle_track:
1219 if( isNumberValue(value) )
1221 /* set the new subtitle track to show */
1222 libvlc_video_set_spu(p_md, numberValue(value), &ex);
1223 RETURN_ON_EXCEPTION(this,ex);
1225 return INVOKERESULT_NO_ERROR;
1227 return INVOKERESULT_INVALID_VALUE;
1231 return INVOKERESULT_GENERIC_ERROR;
1234 const NPUTF8 * const LibvlcSubtitleNPObject::methodNames[] =
1238 COUNTNAMES(LibvlcSubtitleNPObject,methodCount,methodNames);
1240 enum LibvlcSubtitleNPObjectMethodIds
1242 ID_subtitle_description
1245 RuntimeNPObject::InvokeResult
1246 LibvlcSubtitleNPObject::invoke(int index, const NPVariant *args,
1247 uint32_t argCount, NPVariant &result)
1249 /* is plugin still running */
1250 if( isPluginRunning() )
1252 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1253 libvlc_exception_t ex;
1254 libvlc_exception_init(&ex);
1256 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1257 RETURN_ON_EXCEPTION(this,ex);
1261 case ID_subtitle_description:
1266 int i_spuID, i_limit, i;
1267 libvlc_track_description_t *p_spuDesc;
1269 /* get subtitles description */
1270 p_spuDesc = libvlc_video_get_spu_description(p_md, &ex);
1271 RETURN_ON_EXCEPTION(this,ex);
1273 return INVOKERESULT_GENERIC_ERROR;
1275 /* get the number of subtitle available */
1276 i_limit = libvlc_video_get_spu_count(p_md, &ex);
1277 RETURN_ON_EXCEPTION(this,ex);
1279 /* check if a number is given by the user
1280 * and get the subtitle number */
1281 if( isNumberValue(args[0]) )
1282 i_spuID = numberValue(args[0]);
1284 return INVOKERESULT_INVALID_VALUE;
1286 /* if bad number is given return invalid value */
1287 if ( ( i_spuID > ( i_limit -1 ) ) || ( i_spuID < 0 ) )
1288 return INVOKERESULT_INVALID_VALUE;
1290 /* get the good spuDesc */
1291 for( i = 0 ; i < i_spuID ; i++ )
1293 p_spuDesc = p_spuDesc->p_next;
1295 psz_name = p_spuDesc->psz_name;
1297 /* return the name of the track chosen */
1298 return invokeResultString(psz_name, result);
1300 return INVOKERESULT_NO_SUCH_METHOD;
1303 return INVOKERESULT_NO_SUCH_METHOD;
1306 return INVOKERESULT_GENERIC_ERROR;
1310 ** implementation of libvlc video object
1313 LibvlcVideoNPObject::~LibvlcVideoNPObject()
1317 if( marqueeObj ) NPN_ReleaseObject(marqueeObj);
1318 if( logoObj ) NPN_ReleaseObject(logoObj);
1319 if( deintObj ) NPN_ReleaseObject(deintObj);
1323 const NPUTF8 * const LibvlcVideoNPObject::propertyNames[] =
1337 enum LibvlcVideoNPObjectPropertyIds
1339 ID_video_fullscreen,
1342 ID_video_aspectratio,
1348 ID_video_deinterlace,
1350 COUNTNAMES(LibvlcVideoNPObject,propertyCount,propertyNames);
1352 RuntimeNPObject::InvokeResult
1353 LibvlcVideoNPObject::getProperty(int index, NPVariant &result)
1355 /* is plugin still running */
1356 if( isPluginRunning() )
1358 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1359 libvlc_exception_t ex;
1360 libvlc_exception_init(&ex);
1362 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1363 RETURN_ON_EXCEPTION(this,ex);
1367 case ID_video_fullscreen:
1369 int val = p_plugin->get_fullscreen(&ex);
1370 RETURN_ON_EXCEPTION(this,ex);
1371 BOOLEAN_TO_NPVARIANT(val, result);
1372 return INVOKERESULT_NO_ERROR;
1374 case ID_video_height:
1376 int val = libvlc_video_get_height(p_md, &ex);
1377 RETURN_ON_EXCEPTION(this,ex);
1378 INT32_TO_NPVARIANT(val, result);
1379 return INVOKERESULT_NO_ERROR;
1381 case ID_video_width:
1383 int val = libvlc_video_get_width(p_md, &ex);
1384 RETURN_ON_EXCEPTION(this,ex);
1385 INT32_TO_NPVARIANT(val, result);
1386 return INVOKERESULT_NO_ERROR;
1388 case ID_video_aspectratio:
1390 NPUTF8 *psz_aspect = libvlc_video_get_aspect_ratio(p_md, &ex);
1391 RETURN_ON_EXCEPTION(this,ex);
1393 return INVOKERESULT_GENERIC_ERROR;
1395 STRINGZ_TO_NPVARIANT(psz_aspect, result);
1396 return INVOKERESULT_NO_ERROR;
1398 case ID_video_subtitle:
1400 int i_spu = libvlc_video_get_spu(p_md, &ex);
1401 RETURN_ON_EXCEPTION(this,ex);
1402 INT32_TO_NPVARIANT(i_spu, result);
1403 return INVOKERESULT_NO_ERROR;
1407 NPUTF8 *psz_geometry = libvlc_video_get_crop_geometry(p_md, &ex);
1408 RETURN_ON_EXCEPTION(this,ex);
1410 return INVOKERESULT_GENERIC_ERROR;
1412 STRINGZ_TO_NPVARIANT(psz_geometry, result);
1413 return INVOKERESULT_NO_ERROR;
1415 case ID_video_teletext:
1417 /* int i_page = libvlc_video_get_teletext(p_md, &ex);
1418 RETURN_ON_EXCEPTION(this,ex);
1419 INT32_TO_NPVARIANT(i_page, result);
1420 return INVOKERESULT_NO_ERROR;
1422 return INVOKERESULT_NO_SUCH_METHOD;
1424 case ID_video_marquee:
1426 InstantObj<LibvlcMarqueeNPObject>( marqueeObj );
1427 OBJECT_TO_NPVARIANT(NPN_RetainObject(marqueeObj), result);
1428 return INVOKERESULT_NO_ERROR;
1432 InstantObj<LibvlcLogoNPObject>( logoObj );
1433 OBJECT_TO_NPVARIANT(NPN_RetainObject(logoObj), result);
1434 return INVOKERESULT_NO_ERROR;
1436 case ID_video_deinterlace:
1438 InstantObj<LibvlcDeinterlaceNPObject>( deintObj );
1439 OBJECT_TO_NPVARIANT(NPN_RetainObject(deintObj), result);
1440 return INVOKERESULT_NO_ERROR;
1444 return INVOKERESULT_GENERIC_ERROR;
1447 RuntimeNPObject::InvokeResult
1448 LibvlcVideoNPObject::setProperty(int index, const NPVariant &value)
1450 /* is plugin still running */
1451 if( isPluginRunning() )
1453 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1454 libvlc_exception_t ex;
1455 libvlc_exception_init(&ex);
1457 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1458 RETURN_ON_EXCEPTION(this,ex);
1462 case ID_video_fullscreen:
1464 if( ! NPVARIANT_IS_BOOLEAN(value) )
1466 return INVOKERESULT_INVALID_VALUE;
1469 int val = NPVARIANT_TO_BOOLEAN(value);
1470 p_plugin->set_fullscreen(val, &ex);
1471 RETURN_ON_EXCEPTION(this,ex);
1472 return INVOKERESULT_NO_ERROR;
1474 case ID_video_aspectratio:
1476 char *psz_aspect = NULL;
1478 if( ! NPVARIANT_IS_STRING(value) )
1480 return INVOKERESULT_INVALID_VALUE;
1483 psz_aspect = stringValue(NPVARIANT_TO_STRING(value));
1486 return INVOKERESULT_GENERIC_ERROR;
1489 libvlc_video_set_aspect_ratio(p_md, psz_aspect, &ex);
1491 RETURN_ON_EXCEPTION(this,ex);
1493 return INVOKERESULT_NO_ERROR;
1495 case ID_video_subtitle:
1497 if( isNumberValue(value) )
1499 libvlc_video_set_spu(p_md, numberValue(value), &ex);
1500 RETURN_ON_EXCEPTION(this,ex);
1502 return INVOKERESULT_NO_ERROR;
1504 return INVOKERESULT_INVALID_VALUE;
1508 char *psz_geometry = NULL;
1510 if( ! NPVARIANT_IS_STRING(value) )
1512 return INVOKERESULT_INVALID_VALUE;
1515 psz_geometry = stringValue(NPVARIANT_TO_STRING(value));
1518 return INVOKERESULT_GENERIC_ERROR;
1521 libvlc_video_set_crop_geometry(p_md, psz_geometry, &ex);
1523 RETURN_ON_EXCEPTION(this,ex);
1525 return INVOKERESULT_NO_ERROR;
1527 case ID_video_teletext:
1529 if( isNumberValue(value) )
1532 libvlc_video_set_teletext(p_md, numberValue(value), &ex);
1533 RETURN_ON_EXCEPTION(this,ex);
1535 return INVOKERESULT_NO_ERROR;
1537 return INVOKERESULT_NO_SUCH_METHOD;
1539 return INVOKERESULT_INVALID_VALUE;
1543 return INVOKERESULT_GENERIC_ERROR;
1546 const NPUTF8 * const LibvlcVideoNPObject::methodNames[] =
1551 COUNTNAMES(LibvlcVideoNPObject,methodCount,methodNames);
1553 enum LibvlcVideoNPObjectMethodIds
1555 ID_video_togglefullscreen,
1556 ID_video_toggleteletext,
1559 RuntimeNPObject::InvokeResult
1560 LibvlcVideoNPObject::invoke(int index, const NPVariant *args,
1561 uint32_t argCount, NPVariant &result)
1563 /* is plugin still running */
1564 if( isPluginRunning() )
1566 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1567 libvlc_exception_t ex;
1568 libvlc_exception_init(&ex);
1570 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1571 RETURN_ON_EXCEPTION(this,ex);
1575 case ID_video_togglefullscreen:
1579 p_plugin->toggle_fullscreen(&ex);
1580 RETURN_ON_EXCEPTION(this,ex);
1581 VOID_TO_NPVARIANT(result);
1582 return INVOKERESULT_NO_ERROR;
1584 return INVOKERESULT_NO_SUCH_METHOD;
1586 case ID_video_toggleteletext:
1590 libvlc_toggle_teletext(p_md, &ex);
1591 RETURN_ON_EXCEPTION(this,ex);
1592 VOID_TO_NPVARIANT(result);
1593 return INVOKERESULT_NO_ERROR;
1595 return INVOKERESULT_NO_SUCH_METHOD;
1598 return INVOKERESULT_NO_SUCH_METHOD;
1601 return INVOKERESULT_GENERIC_ERROR;
1605 ** implementation of libvlc marquee object
1608 const NPUTF8 * const LibvlcMarqueeNPObject::propertyNames[] =
1621 enum LibvlcMarqueeNPObjectPropertyIds
1625 ID_marquee_position,
1634 COUNTNAMES(LibvlcMarqueeNPObject,propertyCount,propertyNames);
1636 static const unsigned char marquee_idx[] = {
1637 libvlc_marquee_Color,
1638 libvlc_marquee_Opacity,
1639 libvlc_marquee_Position,
1640 libvlc_marquee_Refresh,
1641 libvlc_marquee_Size,
1643 libvlc_marquee_Timeout,
1648 RuntimeNPObject::InvokeResult
1649 LibvlcMarqueeNPObject::getProperty(int index, NPVariant &result)
1653 if( !isPluginRunning() )
1654 return INVOKERESULT_GENERIC_ERROR;
1656 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1657 libvlc_exception_t ex;
1658 libvlc_exception_init(&ex);
1660 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1661 RETURN_ON_EXCEPTION(this,ex);
1665 case ID_marquee_color:
1666 case ID_marquee_opacity:
1667 case ID_marquee_refresh:
1668 case ID_marquee_timeout:
1669 case ID_marquee_size:
1673 libvlc_video_get_marquee_int(p_md, marquee_idx[index], &ex),
1675 RETURN_ON_EXCEPTION(this,ex);
1676 return INVOKERESULT_NO_ERROR;
1678 case ID_marquee_position:
1679 STRINGZ_TO_NPVARIANT( position_bynumber(
1680 libvlc_video_get_marquee_int(p_md, libvlc_marquee_Position, &ex) ),
1683 RETURN_ON_EXCEPTION(this,ex);
1686 case ID_marquee_text:
1687 psz = libvlc_video_get_marquee_string(p_md, libvlc_marquee_Text, &ex);
1690 STRINGZ_TO_NPVARIANT(psz, result);
1691 return INVOKERESULT_NO_ERROR;
1695 return INVOKERESULT_GENERIC_ERROR;
1698 RuntimeNPObject::InvokeResult
1699 LibvlcMarqueeNPObject::setProperty(int index, const NPVariant &value)
1703 if( !isPluginRunning() )
1704 return INVOKERESULT_GENERIC_ERROR;
1706 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1707 libvlc_exception_t ex;
1708 libvlc_exception_init(&ex);
1709 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1710 RETURN_ON_EXCEPTION(this,ex);
1714 case ID_marquee_color:
1715 case ID_marquee_opacity:
1716 case ID_marquee_refresh:
1717 case ID_marquee_timeout:
1720 if( NPVARIANT_IS_INT32( value ) )
1722 libvlc_video_set_marquee_int(p_md, marquee_idx[index],
1723 NPVARIANT_TO_INT32( value ), &ex);
1724 RETURN_ON_EXCEPTION(this,ex);
1725 return INVOKERESULT_NO_ERROR;
1729 case ID_marquee_position:
1730 if( !NPVARIANT_IS_STRING(value) ||
1731 !position_byname( NPVARIANT_TO_STRING(value).utf8characters, i ) )
1732 return INVOKERESULT_INVALID_VALUE;
1734 libvlc_video_set_marquee_int(p_md, libvlc_marquee_Position, i, &ex);
1735 RETURN_ON_EXCEPTION(this,ex);
1736 return INVOKERESULT_NO_ERROR;
1738 case ID_marquee_text:
1739 if( NPVARIANT_IS_STRING( value ) )
1741 char *psz_text = stringValue( NPVARIANT_TO_STRING( value ) );
1742 libvlc_video_set_marquee_string(p_md, libvlc_marquee_Text,
1745 RETURN_ON_EXCEPTION(this,ex);
1746 return INVOKERESULT_NO_ERROR;
1750 return INVOKERESULT_NO_SUCH_METHOD;
1753 const NPUTF8 * const LibvlcMarqueeNPObject::methodNames[] =
1758 COUNTNAMES(LibvlcMarqueeNPObject,methodCount,methodNames);
1760 enum LibvlcMarqueeNPObjectMethodIds
1766 RuntimeNPObject::InvokeResult
1767 LibvlcMarqueeNPObject::invoke(int index, const NPVariant *args,
1768 uint32_t argCount, NPVariant &result)
1770 if( !isPluginRunning() )
1771 return INVOKERESULT_GENERIC_ERROR;
1773 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1774 libvlc_exception_t ex;
1775 libvlc_exception_init(&ex);
1777 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1778 RETURN_ON_EXCEPTION(this,ex);
1782 case ID_marquee_enable:
1783 case ID_marquee_disable:
1784 libvlc_video_set_marquee_int(p_md, libvlc_marquee_Enable,
1785 index!=ID_marquee_disable, &ex);
1786 RETURN_ON_EXCEPTION(this,ex);
1787 VOID_TO_NPVARIANT(result);
1788 return INVOKERESULT_NO_ERROR;
1790 return INVOKERESULT_NO_SUCH_METHOD;
1793 const NPUTF8 * const LibvlcLogoNPObject::propertyNames[] = {
1801 enum LibvlcLogoNPObjectPropertyIds {
1809 COUNTNAMES(LibvlcLogoNPObject,propertyCount,propertyNames);
1810 static const unsigned char logo_idx[] = {
1813 libvlc_logo_opacity,
1819 RuntimeNPObject::InvokeResult
1820 LibvlcLogoNPObject::getProperty(int index, NPVariant &result)
1822 if( !isPluginRunning() )
1823 return INVOKERESULT_GENERIC_ERROR;
1825 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1826 libvlc_exception_t ex;
1827 libvlc_exception_init(&ex);
1828 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1829 RETURN_ON_EXCEPTION(this,ex);
1834 case ID_logo_repeat:
1835 case ID_logo_opacity:
1840 libvlc_video_get_logo_int(p_md, logo_idx[index], &ex), result);
1842 RETURN_ON_EXCEPTION(this,ex);
1845 case ID_logo_position:
1846 STRINGZ_TO_NPVARIANT( position_bynumber(
1847 libvlc_video_get_logo_int(p_md, libvlc_logo_position, &ex) ),
1850 RETURN_ON_EXCEPTION(this,ex);
1853 return INVOKERESULT_GENERIC_ERROR;
1855 return INVOKERESULT_NO_ERROR;
1858 RuntimeNPObject::InvokeResult
1859 LibvlcLogoNPObject::setProperty(int index, const NPVariant &value)
1863 if( !isPluginRunning() )
1864 return INVOKERESULT_GENERIC_ERROR;
1866 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1867 libvlc_exception_t ex;
1868 libvlc_exception_init(&ex);
1870 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1871 RETURN_ON_EXCEPTION(this,ex);
1876 case ID_logo_repeat:
1877 case ID_logo_opacity:
1880 if( !NPVARIANT_IS_INT32(value) )
1881 return INVOKERESULT_INVALID_VALUE;
1883 libvlc_video_set_logo_int(p_md, logo_idx[index],
1884 NPVARIANT_TO_INT32( value ), &ex);
1886 RETURN_ON_EXCEPTION(this,ex);
1889 case ID_logo_position:
1890 if( !NPVARIANT_IS_STRING(value) ||
1891 !position_byname( NPVARIANT_TO_STRING(value).utf8characters, i ) )
1892 return INVOKERESULT_INVALID_VALUE;
1894 libvlc_video_set_logo_int(p_md, libvlc_logo_position, i, &ex);
1896 RETURN_ON_EXCEPTION(this,ex);
1899 return INVOKERESULT_GENERIC_ERROR;
1901 return INVOKERESULT_NO_ERROR;
1905 const NPUTF8 * const LibvlcLogoNPObject::methodNames[] = {
1910 enum LibvlcLogoNPObjectMethodIds {
1915 COUNTNAMES(LibvlcLogoNPObject,methodCount,methodNames);
1917 RuntimeNPObject::InvokeResult
1918 LibvlcLogoNPObject::invoke(int index, const NPVariant *args,
1919 uint32_t argCount, NPVariant &result)
1924 if( !isPluginRunning() )
1925 return INVOKERESULT_GENERIC_ERROR;
1927 libvlc_exception_t ex;
1928 libvlc_exception_init(&ex);
1929 libvlc_media_player_t *p_md = getPrivate<VlcPlugin>()->getMD(&ex);
1930 RETURN_ON_EXCEPTION(this,ex);
1934 case ID_logo_enable:
1935 case ID_logo_disable:
1937 return INVOKERESULT_GENERIC_ERROR;
1939 libvlc_video_set_logo_int(p_md, libvlc_logo_enable,
1940 index != ID_logo_disable, &ex);
1941 RETURN_ON_EXCEPTION(this,ex);
1942 VOID_TO_NPVARIANT(result);
1947 return INVOKERESULT_GENERIC_ERROR;
1949 for( len=0,i=0;i<argCount;++i )
1951 if( !NPVARIANT_IS_STRING(args[i]) )
1952 return INVOKERESULT_INVALID_VALUE;
1953 len+=NPVARIANT_TO_STRING(args[i]).utf8length+1;
1956 buf = (char *)malloc( len+1 );
1958 return INVOKERESULT_OUT_OF_MEMORY;
1960 for( h=buf,i=0;i<argCount;++i )
1963 len=NPVARIANT_TO_STRING(args[i]).utf8length;
1964 memcpy(h,NPVARIANT_TO_STRING(args[i]).utf8characters,len);
1969 libvlc_video_set_logo_string(p_md, libvlc_logo_file, buf, &ex);
1971 RETURN_ON_EXCEPTION(this,ex);
1972 VOID_TO_NPVARIANT(result);
1975 return INVOKERESULT_NO_SUCH_METHOD;
1977 return INVOKERESULT_NO_ERROR;
1981 const NPUTF8 * const LibvlcDeinterlaceNPObject::propertyNames[] = {
1983 enum LibvlcDeinterlaceNPObjectPropertyIds {
1985 COUNTNAMES(LibvlcDeinterlaceNPObject,propertyCount,propertyNames);
1987 RuntimeNPObject::InvokeResult
1988 LibvlcDeinterlaceNPObject::getProperty(int index, NPVariant &result)
1990 return INVOKERESULT_GENERIC_ERROR;
1993 RuntimeNPObject::InvokeResult
1994 LibvlcDeinterlaceNPObject::setProperty(int index, const NPVariant &value)
1996 return INVOKERESULT_GENERIC_ERROR;
2000 const NPUTF8 * const LibvlcDeinterlaceNPObject::methodNames[] = {
2004 enum LibvlcDeinterlaceNPObjectMethodIds {
2008 COUNTNAMES(LibvlcDeinterlaceNPObject,methodCount,methodNames);
2010 RuntimeNPObject::InvokeResult
2011 LibvlcDeinterlaceNPObject::invoke(int index, const NPVariant *args,
2012 uint32_t argCount, NPVariant &result)
2016 if( !isPluginRunning() )
2017 return INVOKERESULT_GENERIC_ERROR;
2019 libvlc_exception_t ex;
2020 libvlc_exception_init(&ex);
2021 libvlc_media_player_t *p_md = getPrivate<VlcPlugin>()->getMD(&ex);
2022 RETURN_ON_EXCEPTION(this,ex);
2026 case ID_deint_disable:
2027 libvlc_video_set_deinterlace(p_md, 0, "", &ex);
2028 RETURN_ON_EXCEPTION(this,ex);
2031 case ID_deint_enable:
2032 if( argCount != 1 || !NPVARIANT_IS_STRING( args[0] ) )
2033 return INVOKERESULT_INVALID_VALUE;
2035 psz = stringValue( NPVARIANT_TO_STRING( args[0] ) );
2036 libvlc_video_set_deinterlace(p_md, 1, psz, &ex);
2038 RETURN_ON_EXCEPTION(this,ex);
2042 return INVOKERESULT_NO_SUCH_METHOD;
2044 return INVOKERESULT_NO_ERROR;