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 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
263 RETURN_ON_EXCEPTION(this,ex);
264 bool muted = libvlc_audio_get_mute(p_md);
265 BOOLEAN_TO_NPVARIANT(muted, result);
266 return INVOKERESULT_NO_ERROR;
268 case ID_audio_volume:
270 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
271 RETURN_ON_EXCEPTION(this,ex);
272 int volume = libvlc_audio_get_volume(p_md);
273 INT32_TO_NPVARIANT(volume, result);
274 return INVOKERESULT_NO_ERROR;
278 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
279 RETURN_ON_EXCEPTION(this,ex);
280 int track = libvlc_audio_get_track(p_md);
281 INT32_TO_NPVARIANT(track, result);
282 return INVOKERESULT_NO_ERROR;
286 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
287 RETURN_ON_EXCEPTION(this,ex);
288 // get the number of audio track available
289 int i_track = libvlc_audio_get_track_count(p_md);
291 INT32_TO_NPVARIANT(i_track, result);
292 return INVOKERESULT_NO_ERROR;
294 case ID_audio_channel:
296 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
297 RETURN_ON_EXCEPTION(this,ex);
298 int channel = libvlc_audio_get_channel(p_md);
299 INT32_TO_NPVARIANT(channel, result);
300 return INVOKERESULT_NO_ERROR;
306 return INVOKERESULT_GENERIC_ERROR;
309 RuntimeNPObject::InvokeResult
310 LibvlcAudioNPObject::setProperty(int index, const NPVariant &value)
312 /* is plugin still running */
313 if( isPluginRunning() )
315 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
316 libvlc_exception_t ex;
317 libvlc_exception_init(&ex);
322 if( NPVARIANT_IS_BOOLEAN(value) )
324 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
325 RETURN_ON_EXCEPTION(this,ex);
326 libvlc_audio_set_mute(p_md,
327 NPVARIANT_TO_BOOLEAN(value));
328 return INVOKERESULT_NO_ERROR;
330 return INVOKERESULT_INVALID_VALUE;
331 case ID_audio_volume:
332 if( isNumberValue(value) )
334 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
335 RETURN_ON_EXCEPTION(this,ex);
336 libvlc_audio_set_volume(p_md, numberValue(value));
337 return INVOKERESULT_NO_ERROR;
339 return INVOKERESULT_INVALID_VALUE;
341 if( isNumberValue(value) )
343 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
344 RETURN_ON_EXCEPTION(this,ex);
345 libvlc_audio_set_track(p_md, numberValue(value));
346 return INVOKERESULT_NO_ERROR;
348 return INVOKERESULT_INVALID_VALUE;
349 case ID_audio_channel:
350 if( isNumberValue(value) )
352 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
353 RETURN_ON_EXCEPTION(this,ex);
354 libvlc_audio_set_channel(p_md, numberValue(value));
355 return INVOKERESULT_NO_ERROR;
357 return INVOKERESULT_INVALID_VALUE;
362 return INVOKERESULT_GENERIC_ERROR;
365 const NPUTF8 * const LibvlcAudioNPObject::methodNames[] =
370 COUNTNAMES(LibvlcAudioNPObject,methodCount,methodNames);
372 enum LibvlcAudioNPObjectMethodIds
375 ID_audio_description,
378 RuntimeNPObject::InvokeResult
379 LibvlcAudioNPObject::invoke(int index, const NPVariant *args,
380 uint32_t argCount, NPVariant &result)
382 /* is plugin still running */
383 if( isPluginRunning() )
385 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
386 libvlc_exception_t ex;
387 libvlc_exception_init(&ex);
391 case ID_audio_togglemute:
394 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
395 RETURN_ON_EXCEPTION(this,ex);
396 libvlc_audio_toggle_mute(p_md);
397 VOID_TO_NPVARIANT(result);
398 return INVOKERESULT_NO_ERROR;
400 return INVOKERESULT_NO_SUCH_METHOD;
401 case ID_audio_description:
406 int i_trackID, i_limit, i;
407 libvlc_track_description_t *p_trackDesc;
409 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
410 RETURN_ON_EXCEPTION(this,ex);
412 /* get tracks description */
413 p_trackDesc = libvlc_audio_get_track_description(p_md);
415 return INVOKERESULT_GENERIC_ERROR;
417 /* get the number of track available */
418 i_limit = libvlc_audio_get_track_count(p_md);
420 /* check if a number is given by the user
421 * and get the track number */
422 if( isNumberValue(args[0]) )
423 i_trackID = numberValue(args[0]);
425 return INVOKERESULT_INVALID_VALUE;
427 /* if bad number is given return invalid value */
428 if ( ( i_trackID > ( i_limit - 1 ) ) || ( i_trackID < 0 ) )
429 return INVOKERESULT_INVALID_VALUE;
431 /* get the good trackDesc */
432 for( i = 0 ; i < i_trackID ; i++ )
434 p_trackDesc = p_trackDesc->p_next;
436 psz_name = p_trackDesc->psz_name;
438 /* display the name of the track chosen */
439 return invokeResultString( psz_name, result );
441 return INVOKERESULT_NO_SUCH_METHOD;
447 return INVOKERESULT_GENERIC_ERROR;
451 ** implementation of libvlc input object
454 const NPUTF8 * const LibvlcInputNPObject::propertyNames[] =
464 COUNTNAMES(LibvlcInputNPObject,propertyCount,propertyNames);
466 enum LibvlcInputNPObjectPropertyIds
477 RuntimeNPObject::InvokeResult
478 LibvlcInputNPObject::getProperty(int index, NPVariant &result)
480 /* is plugin still running */
481 if( isPluginRunning() )
483 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
484 libvlc_exception_t ex;
485 libvlc_exception_init(&ex);
487 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
488 if( libvlc_exception_raised(&ex) )
490 if( index != ID_input_state )
492 NPN_SetException(this, libvlc_errmsg());
493 libvlc_exception_clear(&ex);
494 return INVOKERESULT_GENERIC_ERROR;
498 /* for input state, return CLOSED rather than an exception */
499 INT32_TO_NPVARIANT(0, result);
500 libvlc_exception_clear(&ex);
501 return INVOKERESULT_NO_ERROR;
507 case ID_input_length:
509 double val = (double)libvlc_media_player_get_length(p_md);
510 DOUBLE_TO_NPVARIANT(val, result);
511 return INVOKERESULT_NO_ERROR;
513 case ID_input_position:
515 double val = libvlc_media_player_get_position(p_md);
516 DOUBLE_TO_NPVARIANT(val, result);
517 return INVOKERESULT_NO_ERROR;
521 double val = (double)libvlc_media_player_get_time(p_md);
522 DOUBLE_TO_NPVARIANT(val, result);
523 return INVOKERESULT_NO_ERROR;
527 int val = libvlc_media_player_get_state(p_md);
528 RETURN_ON_EXCEPTION(this,ex);
529 INT32_TO_NPVARIANT(val, result);
530 return INVOKERESULT_NO_ERROR;
534 float val = libvlc_media_player_get_rate(p_md);
535 DOUBLE_TO_NPVARIANT(val, result);
536 return INVOKERESULT_NO_ERROR;
540 double val = libvlc_media_player_get_fps(p_md);
541 DOUBLE_TO_NPVARIANT(val, result);
542 return INVOKERESULT_NO_ERROR;
544 case ID_input_hasvout:
546 bool val = p_plugin->player_has_vout(&ex);
547 RETURN_ON_EXCEPTION(this,ex);
548 BOOLEAN_TO_NPVARIANT(val, result);
549 return INVOKERESULT_NO_ERROR;
555 return INVOKERESULT_GENERIC_ERROR;
558 RuntimeNPObject::InvokeResult
559 LibvlcInputNPObject::setProperty(int index, const NPVariant &value)
561 /* is plugin still running */
562 if( isPluginRunning() )
564 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
565 libvlc_exception_t ex;
566 libvlc_exception_init(&ex);
568 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
569 RETURN_ON_EXCEPTION(this,ex);
573 case ID_input_position:
575 if( ! NPVARIANT_IS_DOUBLE(value) )
577 return INVOKERESULT_INVALID_VALUE;
580 float val = (float)NPVARIANT_TO_DOUBLE(value);
581 libvlc_media_player_set_position(p_md, val);
582 return INVOKERESULT_NO_ERROR;
587 if( NPVARIANT_IS_INT32(value) )
588 val = (int64_t)NPVARIANT_TO_INT32(value);
589 else if( NPVARIANT_IS_DOUBLE(value) )
590 val = (int64_t)NPVARIANT_TO_DOUBLE(value);
593 return INVOKERESULT_INVALID_VALUE;
596 libvlc_media_player_set_time(p_md, val);
597 return INVOKERESULT_NO_ERROR;
602 if( NPVARIANT_IS_INT32(value) )
603 val = (float)NPVARIANT_TO_INT32(value);
604 else if( NPVARIANT_IS_DOUBLE(value) )
605 val = (float)NPVARIANT_TO_DOUBLE(value);
608 return INVOKERESULT_INVALID_VALUE;
611 libvlc_media_player_set_rate(p_md, val);
612 return INVOKERESULT_NO_ERROR;
618 return INVOKERESULT_GENERIC_ERROR;
621 const NPUTF8 * const LibvlcInputNPObject::methodNames[] =
626 COUNTNAMES(LibvlcInputNPObject,methodCount,methodNames);
628 enum LibvlcInputNPObjectMethodIds
633 RuntimeNPObject::InvokeResult
634 LibvlcInputNPObject::invoke(int index, const NPVariant *args,
635 uint32_t argCount, NPVariant &result)
637 /* is plugin still running */
638 if( isPluginRunning() )
643 return INVOKERESULT_NO_SUCH_METHOD;
648 return INVOKERESULT_GENERIC_ERROR;
652 ** implementation of libvlc playlist items object
655 const NPUTF8 * const LibvlcPlaylistItemsNPObject::propertyNames[] =
659 COUNTNAMES(LibvlcPlaylistItemsNPObject,propertyCount,propertyNames);
661 enum LibvlcPlaylistItemsNPObjectPropertyIds
663 ID_playlistitems_count,
666 RuntimeNPObject::InvokeResult
667 LibvlcPlaylistItemsNPObject::getProperty(int index, NPVariant &result)
669 /* is plugin still running */
670 if( isPluginRunning() )
672 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
676 case ID_playlistitems_count:
678 int val = p_plugin->playlist_count();
679 INT32_TO_NPVARIANT(val, result);
680 return INVOKERESULT_NO_ERROR;
686 return INVOKERESULT_GENERIC_ERROR;
689 const NPUTF8 * const LibvlcPlaylistItemsNPObject::methodNames[] =
694 COUNTNAMES(LibvlcPlaylistItemsNPObject,methodCount,methodNames);
696 enum LibvlcPlaylistItemsNPObjectMethodIds
698 ID_playlistitems_clear,
699 ID_playlistitems_remove,
702 RuntimeNPObject::InvokeResult
703 LibvlcPlaylistItemsNPObject::invoke(int index, const NPVariant *args,
704 uint32_t argCount, NPVariant &result)
706 /* is plugin still running */
707 if( isPluginRunning() )
709 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
710 libvlc_exception_t ex;
711 libvlc_exception_init(&ex);
715 case ID_playlistitems_clear:
718 p_plugin->playlist_clear(&ex);
719 RETURN_ON_EXCEPTION(this,ex);
720 VOID_TO_NPVARIANT(result);
721 return INVOKERESULT_NO_ERROR;
723 return INVOKERESULT_NO_SUCH_METHOD;
724 case ID_playlistitems_remove:
725 if( (argCount == 1) && isNumberValue(args[0]) )
727 p_plugin->playlist_delete_item(numberValue(args[0]),&ex);
728 RETURN_ON_EXCEPTION(this,ex);
729 VOID_TO_NPVARIANT(result);
730 return INVOKERESULT_NO_ERROR;
732 return INVOKERESULT_NO_SUCH_METHOD;
737 return INVOKERESULT_GENERIC_ERROR;
741 ** implementation of libvlc playlist object
744 LibvlcPlaylistNPObject::~LibvlcPlaylistNPObject()
746 // Why the isValid()?
747 if( isValid() && playlistItemsObj )
748 NPN_ReleaseObject(playlistItemsObj);
751 const NPUTF8 * const LibvlcPlaylistNPObject::propertyNames[] =
753 "itemCount", /* deprecated */
757 COUNTNAMES(LibvlcPlaylistNPObject,propertyCount,propertyNames);
759 enum LibvlcPlaylistNPObjectPropertyIds
761 ID_playlist_itemcount,
762 ID_playlist_isplaying,
766 RuntimeNPObject::InvokeResult
767 LibvlcPlaylistNPObject::getProperty(int index, NPVariant &result)
769 /* is plugin still running */
770 if( isPluginRunning() )
772 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
776 case ID_playlist_itemcount: /* deprecated */
778 int val = p_plugin->playlist_count();
779 INT32_TO_NPVARIANT(val, result);
780 return INVOKERESULT_NO_ERROR;
782 case ID_playlist_isplaying:
784 int val = p_plugin->playlist_isplaying();
785 BOOLEAN_TO_NPVARIANT(val, result);
786 return INVOKERESULT_NO_ERROR;
788 case ID_playlist_items:
790 InstantObj<LibvlcPlaylistItemsNPObject>( playlistItemsObj );
791 OBJECT_TO_NPVARIANT(NPN_RetainObject(playlistItemsObj), result);
792 return INVOKERESULT_NO_ERROR;
798 return INVOKERESULT_GENERIC_ERROR;
801 const NPUTF8 * const LibvlcPlaylistNPObject::methodNames[] =
810 "clear", /* deprecated */
811 "removeItem", /* deprecated */
813 COUNTNAMES(LibvlcPlaylistNPObject,methodCount,methodNames);
815 enum LibvlcPlaylistNPObjectMethodIds
819 ID_playlist_playItem,
820 ID_playlist_togglepause,
825 ID_playlist_removeitem
828 RuntimeNPObject::InvokeResult
829 LibvlcPlaylistNPObject::invoke(int index, const NPVariant *args,
830 uint32_t argCount, NPVariant &result)
832 /* is plugin still running */
833 if( isPluginRunning() )
835 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
836 libvlc_exception_t ex;
837 libvlc_exception_init(&ex);
841 // XXX FIXME this needs squashing into something much smaller
842 case ID_playlist_add:
844 if( (argCount < 1) || (argCount > 3) )
845 return INVOKERESULT_NO_SUCH_METHOD;
846 if( !NPVARIANT_IS_STRING(args[0]) )
847 return INVOKERESULT_NO_SUCH_METHOD;
850 if( NPVARIANT_IS_NULL(args[0]) )
851 return INVOKERESULT_NO_SUCH_METHOD;
853 char *s = stringValue(NPVARIANT_TO_STRING(args[0]));
855 return INVOKERESULT_OUT_OF_MEMORY;
857 char *url = p_plugin->getAbsoluteURL(s);
861 // problem with combining url, use argument
866 // grab name if available
869 if( NPVARIANT_IS_NULL(args[1]) )
873 else if( NPVARIANT_IS_STRING(args[1]) )
875 name = stringValue(NPVARIANT_TO_STRING(args[1]));
880 return INVOKERESULT_INVALID_VALUE;
885 char** ppsz_options = NULL;
887 // grab options if available
890 if( NPVARIANT_IS_NULL(args[2]) )
894 else if( NPVARIANT_IS_STRING(args[2]) )
896 parseOptions(NPVARIANT_TO_STRING(args[2]),
897 &i_options, &ppsz_options);
900 else if( NPVARIANT_IS_OBJECT(args[2]) )
902 parseOptions(NPVARIANT_TO_OBJECT(args[2]),
903 &i_options, &ppsz_options);
909 return INVOKERESULT_INVALID_VALUE;
913 int item = p_plugin->playlist_add_extended_untrusted(url, name,
914 i_options, const_cast<const char **>(ppsz_options), &ex);
917 for( int i=0; i< i_options; ++i )
919 free(ppsz_options[i]);
923 RETURN_ON_EXCEPTION(this,ex);
924 INT32_TO_NPVARIANT(item, result);
925 return INVOKERESULT_NO_ERROR;
927 case ID_playlist_play:
930 p_plugin->playlist_play(&ex);
931 RETURN_ON_EXCEPTION(this,ex);
932 VOID_TO_NPVARIANT(result);
933 return INVOKERESULT_NO_ERROR;
935 return INVOKERESULT_NO_SUCH_METHOD;
936 case ID_playlist_playItem:
937 if( (argCount == 1) && isNumberValue(args[0]) )
939 p_plugin->playlist_play_item(numberValue(args[0]),&ex);
940 RETURN_ON_EXCEPTION(this,ex);
941 VOID_TO_NPVARIANT(result);
942 return INVOKERESULT_NO_ERROR;
944 return INVOKERESULT_NO_SUCH_METHOD;
945 case ID_playlist_togglepause:
948 p_plugin->playlist_pause(&ex);
949 RETURN_ON_EXCEPTION(this,ex);
950 VOID_TO_NPVARIANT(result);
951 return INVOKERESULT_NO_ERROR;
953 return INVOKERESULT_NO_SUCH_METHOD;
954 case ID_playlist_stop:
957 p_plugin->playlist_stop();
958 VOID_TO_NPVARIANT(result);
959 return INVOKERESULT_NO_ERROR;
961 return INVOKERESULT_NO_SUCH_METHOD;
962 case ID_playlist_next:
965 p_plugin->playlist_next(&ex);
966 RETURN_ON_EXCEPTION(this,ex);
967 VOID_TO_NPVARIANT(result);
968 return INVOKERESULT_NO_ERROR;
970 return INVOKERESULT_NO_SUCH_METHOD;
971 case ID_playlist_prev:
974 p_plugin->playlist_prev(&ex);
975 RETURN_ON_EXCEPTION(this,ex);
976 VOID_TO_NPVARIANT(result);
977 return INVOKERESULT_NO_ERROR;
979 return INVOKERESULT_NO_SUCH_METHOD;
980 case ID_playlist_clear: /* deprecated */
983 p_plugin->playlist_clear(&ex);
984 RETURN_ON_EXCEPTION(this,ex);
985 VOID_TO_NPVARIANT(result);
986 return INVOKERESULT_NO_ERROR;
988 return INVOKERESULT_NO_SUCH_METHOD;
989 case ID_playlist_removeitem: /* deprecated */
990 if( (argCount == 1) && isNumberValue(args[0]) )
992 p_plugin->playlist_delete_item(numberValue(args[0]), &ex);
993 RETURN_ON_EXCEPTION(this,ex);
994 VOID_TO_NPVARIANT(result);
995 return INVOKERESULT_NO_ERROR;
997 return INVOKERESULT_NO_SUCH_METHOD;
1002 return INVOKERESULT_GENERIC_ERROR;
1005 // XXX FIXME The new playlist_add creates a media instance and feeds it
1006 // XXX FIXME these options one at a time, so this hunk of code does lots
1007 // XXX FIXME of unnecessairy work. Break out something that can do one
1008 // XXX FIXME option at a time and doesn't need to realloc().
1009 // XXX FIXME Same for the other version of parseOptions.
1011 void LibvlcPlaylistNPObject::parseOptions(const NPString &nps,
1012 int *i_options, char*** ppsz_options)
1014 if( nps.utf8length )
1016 char *s = stringValue(nps);
1021 char **options = (char **)malloc(capacity*sizeof(char *));
1026 char *end = val + nps.utf8length;
1029 // skip leading blanks
1031 && ((*val == ' ' ) || (*val == '\t')) )
1035 // skip till we get a blank character
1041 if( ('\'' == c) || ('"' == c) )
1043 // skip till end of string
1044 while( (val < end) && (*(val++) != c ) );
1050 if( nOptions == capacity )
1053 char **moreOptions = (char **)realloc(options, capacity*sizeof(char*));
1056 /* failed to allocate more memory */
1058 /* return what we got so far */
1059 *i_options = nOptions;
1060 *ppsz_options = options;
1063 options = moreOptions;
1066 options[nOptions++] = strdup(start);
1069 // must be end of string
1072 *i_options = nOptions;
1073 *ppsz_options = options;
1080 // XXX FIXME See comment at the other parseOptions variant.
1081 void LibvlcPlaylistNPObject::parseOptions(NPObject *obj, int *i_options,
1082 char*** ppsz_options)
1084 /* WARNING: Safari does not implement NPN_HasProperty/NPN_HasMethod */
1088 /* we are expecting to have a Javascript Array object */
1089 NPIdentifier propId = NPN_GetStringIdentifier("length");
1090 if( NPN_GetProperty(_instance, obj, propId, &value) )
1092 int count = numberValue(value);
1093 NPN_ReleaseVariantValue(&value);
1098 char **options = (char **)malloc(capacity*sizeof(char *));
1103 while( nOptions < count )
1105 propId = NPN_GetIntIdentifier(nOptions);
1106 if( ! NPN_GetProperty(_instance, obj, propId, &value) )
1107 /* return what we got so far */
1110 if( ! NPVARIANT_IS_STRING(value) )
1112 /* return what we got so far */
1113 NPN_ReleaseVariantValue(&value);
1117 if( nOptions == capacity )
1120 char **moreOptions = (char **)realloc(options, capacity*sizeof(char*));
1123 /* failed to allocate more memory */
1124 NPN_ReleaseVariantValue(&value);
1125 /* return what we got so far */
1126 *i_options = nOptions;
1127 *ppsz_options = options;
1130 options = moreOptions;
1133 options[nOptions++] = stringValue(value);
1134 NPN_ReleaseVariantValue(&value);
1136 *i_options = nOptions;
1137 *ppsz_options = options;
1144 ** implementation of libvlc subtitle object
1147 const NPUTF8 * const LibvlcSubtitleNPObject::propertyNames[] =
1153 enum LibvlcSubtitleNPObjectPropertyIds
1158 COUNTNAMES(LibvlcSubtitleNPObject,propertyCount,propertyNames);
1160 RuntimeNPObject::InvokeResult
1161 LibvlcSubtitleNPObject::getProperty(int index, NPVariant &result)
1163 /* is plugin still running */
1164 if( isPluginRunning() )
1166 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1167 libvlc_exception_t ex;
1168 libvlc_exception_init(&ex);
1170 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1171 RETURN_ON_EXCEPTION(this,ex);
1175 case ID_subtitle_track:
1177 /* get the current subtitle ID */
1178 int i_spu = libvlc_video_get_spu(p_md, &ex);
1179 RETURN_ON_EXCEPTION(this,ex);
1181 INT32_TO_NPVARIANT(i_spu, result);
1182 return INVOKERESULT_NO_ERROR;
1184 case ID_subtitle_count:
1186 /* get the number of subtitles available */
1187 int i_spu = libvlc_video_get_spu_count(p_md, &ex);
1188 RETURN_ON_EXCEPTION(this,ex);
1190 INT32_TO_NPVARIANT(i_spu, result);
1191 return INVOKERESULT_NO_ERROR;
1195 return INVOKERESULT_GENERIC_ERROR;
1198 RuntimeNPObject::InvokeResult
1199 LibvlcSubtitleNPObject::setProperty(int index, const NPVariant &value)
1201 /* is plugin still running */
1202 if( isPluginRunning() )
1204 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1205 libvlc_exception_t ex;
1206 libvlc_exception_init(&ex);
1208 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1209 RETURN_ON_EXCEPTION(this,ex);
1213 case ID_subtitle_track:
1215 if( isNumberValue(value) )
1217 /* set the new subtitle track to show */
1218 libvlc_video_set_spu(p_md, numberValue(value), &ex);
1219 RETURN_ON_EXCEPTION(this,ex);
1221 return INVOKERESULT_NO_ERROR;
1223 return INVOKERESULT_INVALID_VALUE;
1227 return INVOKERESULT_GENERIC_ERROR;
1230 const NPUTF8 * const LibvlcSubtitleNPObject::methodNames[] =
1234 COUNTNAMES(LibvlcSubtitleNPObject,methodCount,methodNames);
1236 enum LibvlcSubtitleNPObjectMethodIds
1238 ID_subtitle_description
1241 RuntimeNPObject::InvokeResult
1242 LibvlcSubtitleNPObject::invoke(int index, const NPVariant *args,
1243 uint32_t argCount, NPVariant &result)
1245 /* is plugin still running */
1246 if( isPluginRunning() )
1248 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1249 libvlc_exception_t ex;
1250 libvlc_exception_init(&ex);
1252 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1253 RETURN_ON_EXCEPTION(this,ex);
1257 case ID_subtitle_description:
1262 int i_spuID, i_limit, i;
1263 libvlc_track_description_t *p_spuDesc;
1265 /* get subtitles description */
1266 p_spuDesc = libvlc_video_get_spu_description(p_md);
1268 return INVOKERESULT_GENERIC_ERROR;
1270 /* get the number of subtitle available */
1271 i_limit = libvlc_video_get_spu_count(p_md, &ex);
1272 RETURN_ON_EXCEPTION(this,ex);
1274 /* check if a number is given by the user
1275 * and get the subtitle number */
1276 if( isNumberValue(args[0]) )
1277 i_spuID = numberValue(args[0]);
1279 return INVOKERESULT_INVALID_VALUE;
1281 /* if bad number is given return invalid value */
1282 if ( ( i_spuID > ( i_limit -1 ) ) || ( i_spuID < 0 ) )
1283 return INVOKERESULT_INVALID_VALUE;
1285 /* get the good spuDesc */
1286 for( i = 0 ; i < i_spuID ; i++ )
1288 p_spuDesc = p_spuDesc->p_next;
1290 psz_name = p_spuDesc->psz_name;
1292 /* return the name of the track chosen */
1293 return invokeResultString(psz_name, result);
1295 return INVOKERESULT_NO_SUCH_METHOD;
1298 return INVOKERESULT_NO_SUCH_METHOD;
1301 return INVOKERESULT_GENERIC_ERROR;
1305 ** implementation of libvlc video object
1308 LibvlcVideoNPObject::~LibvlcVideoNPObject()
1312 if( marqueeObj ) NPN_ReleaseObject(marqueeObj);
1313 if( logoObj ) NPN_ReleaseObject(logoObj);
1314 if( deintObj ) NPN_ReleaseObject(deintObj);
1318 const NPUTF8 * const LibvlcVideoNPObject::propertyNames[] =
1332 enum LibvlcVideoNPObjectPropertyIds
1334 ID_video_fullscreen,
1337 ID_video_aspectratio,
1343 ID_video_deinterlace,
1345 COUNTNAMES(LibvlcVideoNPObject,propertyCount,propertyNames);
1347 RuntimeNPObject::InvokeResult
1348 LibvlcVideoNPObject::getProperty(int index, NPVariant &result)
1350 /* is plugin still running */
1351 if( isPluginRunning() )
1353 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1354 libvlc_exception_t ex;
1355 libvlc_exception_init(&ex);
1357 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1358 RETURN_ON_EXCEPTION(this,ex);
1362 case ID_video_fullscreen:
1364 int val = p_plugin->get_fullscreen(&ex);
1365 RETURN_ON_EXCEPTION(this,ex);
1366 BOOLEAN_TO_NPVARIANT(val, result);
1367 return INVOKERESULT_NO_ERROR;
1369 case ID_video_height:
1371 int val = libvlc_video_get_height(p_md, &ex);
1372 RETURN_ON_EXCEPTION(this,ex);
1373 INT32_TO_NPVARIANT(val, result);
1374 return INVOKERESULT_NO_ERROR;
1376 case ID_video_width:
1378 int val = libvlc_video_get_width(p_md, &ex);
1379 RETURN_ON_EXCEPTION(this,ex);
1380 INT32_TO_NPVARIANT(val, result);
1381 return INVOKERESULT_NO_ERROR;
1383 case ID_video_aspectratio:
1385 NPUTF8 *psz_aspect = libvlc_video_get_aspect_ratio(p_md, &ex);
1386 RETURN_ON_EXCEPTION(this,ex);
1388 return INVOKERESULT_GENERIC_ERROR;
1390 STRINGZ_TO_NPVARIANT(psz_aspect, result);
1391 return INVOKERESULT_NO_ERROR;
1393 case ID_video_subtitle:
1395 int i_spu = libvlc_video_get_spu(p_md, &ex);
1396 RETURN_ON_EXCEPTION(this,ex);
1397 INT32_TO_NPVARIANT(i_spu, result);
1398 return INVOKERESULT_NO_ERROR;
1402 NPUTF8 *psz_geometry = libvlc_video_get_crop_geometry(p_md, &ex);
1403 RETURN_ON_EXCEPTION(this,ex);
1405 return INVOKERESULT_GENERIC_ERROR;
1407 STRINGZ_TO_NPVARIANT(psz_geometry, result);
1408 return INVOKERESULT_NO_ERROR;
1410 case ID_video_teletext:
1412 /* int i_page = libvlc_video_get_teletext(p_md, &ex);
1413 RETURN_ON_EXCEPTION(this,ex);
1414 INT32_TO_NPVARIANT(i_page, result);
1415 return INVOKERESULT_NO_ERROR;
1417 return INVOKERESULT_NO_SUCH_METHOD;
1419 case ID_video_marquee:
1421 InstantObj<LibvlcMarqueeNPObject>( marqueeObj );
1422 OBJECT_TO_NPVARIANT(NPN_RetainObject(marqueeObj), result);
1423 return INVOKERESULT_NO_ERROR;
1427 InstantObj<LibvlcLogoNPObject>( logoObj );
1428 OBJECT_TO_NPVARIANT(NPN_RetainObject(logoObj), result);
1429 return INVOKERESULT_NO_ERROR;
1431 case ID_video_deinterlace:
1433 InstantObj<LibvlcDeinterlaceNPObject>( deintObj );
1434 OBJECT_TO_NPVARIANT(NPN_RetainObject(deintObj), result);
1435 return INVOKERESULT_NO_ERROR;
1439 return INVOKERESULT_GENERIC_ERROR;
1442 RuntimeNPObject::InvokeResult
1443 LibvlcVideoNPObject::setProperty(int index, const NPVariant &value)
1445 /* is plugin still running */
1446 if( isPluginRunning() )
1448 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1449 libvlc_exception_t ex;
1450 libvlc_exception_init(&ex);
1452 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1453 RETURN_ON_EXCEPTION(this,ex);
1457 case ID_video_fullscreen:
1459 if( ! NPVARIANT_IS_BOOLEAN(value) )
1461 return INVOKERESULT_INVALID_VALUE;
1464 int val = NPVARIANT_TO_BOOLEAN(value);
1465 p_plugin->set_fullscreen(val, &ex);
1466 RETURN_ON_EXCEPTION(this,ex);
1467 return INVOKERESULT_NO_ERROR;
1469 case ID_video_aspectratio:
1471 char *psz_aspect = NULL;
1473 if( ! NPVARIANT_IS_STRING(value) )
1475 return INVOKERESULT_INVALID_VALUE;
1478 psz_aspect = stringValue(NPVARIANT_TO_STRING(value));
1481 return INVOKERESULT_GENERIC_ERROR;
1484 libvlc_video_set_aspect_ratio(p_md, psz_aspect, &ex);
1486 RETURN_ON_EXCEPTION(this,ex);
1488 return INVOKERESULT_NO_ERROR;
1490 case ID_video_subtitle:
1492 if( isNumberValue(value) )
1494 libvlc_video_set_spu(p_md, numberValue(value), &ex);
1495 RETURN_ON_EXCEPTION(this,ex);
1497 return INVOKERESULT_NO_ERROR;
1499 return INVOKERESULT_INVALID_VALUE;
1503 char *psz_geometry = NULL;
1505 if( ! NPVARIANT_IS_STRING(value) )
1507 return INVOKERESULT_INVALID_VALUE;
1510 psz_geometry = stringValue(NPVARIANT_TO_STRING(value));
1513 return INVOKERESULT_GENERIC_ERROR;
1516 libvlc_video_set_crop_geometry(p_md, psz_geometry, &ex);
1518 RETURN_ON_EXCEPTION(this,ex);
1520 return INVOKERESULT_NO_ERROR;
1522 case ID_video_teletext:
1524 if( isNumberValue(value) )
1527 libvlc_video_set_teletext(p_md, numberValue(value), &ex);
1528 RETURN_ON_EXCEPTION(this,ex);
1530 return INVOKERESULT_NO_ERROR;
1532 return INVOKERESULT_NO_SUCH_METHOD;
1534 return INVOKERESULT_INVALID_VALUE;
1538 return INVOKERESULT_GENERIC_ERROR;
1541 const NPUTF8 * const LibvlcVideoNPObject::methodNames[] =
1546 COUNTNAMES(LibvlcVideoNPObject,methodCount,methodNames);
1548 enum LibvlcVideoNPObjectMethodIds
1550 ID_video_togglefullscreen,
1551 ID_video_toggleteletext,
1554 RuntimeNPObject::InvokeResult
1555 LibvlcVideoNPObject::invoke(int index, const NPVariant *args,
1556 uint32_t argCount, NPVariant &result)
1558 /* is plugin still running */
1559 if( isPluginRunning() )
1561 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1562 libvlc_exception_t ex;
1563 libvlc_exception_init(&ex);
1565 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1566 RETURN_ON_EXCEPTION(this,ex);
1570 case ID_video_togglefullscreen:
1574 p_plugin->toggle_fullscreen(&ex);
1575 RETURN_ON_EXCEPTION(this,ex);
1576 VOID_TO_NPVARIANT(result);
1577 return INVOKERESULT_NO_ERROR;
1579 return INVOKERESULT_NO_SUCH_METHOD;
1581 case ID_video_toggleteletext:
1585 libvlc_toggle_teletext(p_md);
1586 VOID_TO_NPVARIANT(result);
1587 return INVOKERESULT_NO_ERROR;
1589 return INVOKERESULT_NO_SUCH_METHOD;
1592 return INVOKERESULT_NO_SUCH_METHOD;
1595 return INVOKERESULT_GENERIC_ERROR;
1599 ** implementation of libvlc marquee object
1602 const NPUTF8 * const LibvlcMarqueeNPObject::propertyNames[] =
1615 enum LibvlcMarqueeNPObjectPropertyIds
1619 ID_marquee_position,
1628 COUNTNAMES(LibvlcMarqueeNPObject,propertyCount,propertyNames);
1630 static const unsigned char marquee_idx[] = {
1631 libvlc_marquee_Color,
1632 libvlc_marquee_Opacity,
1633 libvlc_marquee_Position,
1634 libvlc_marquee_Refresh,
1635 libvlc_marquee_Size,
1637 libvlc_marquee_Timeout,
1642 RuntimeNPObject::InvokeResult
1643 LibvlcMarqueeNPObject::getProperty(int index, NPVariant &result)
1647 if( !isPluginRunning() )
1648 return INVOKERESULT_GENERIC_ERROR;
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_color:
1660 case ID_marquee_opacity:
1661 case ID_marquee_refresh:
1662 case ID_marquee_timeout:
1663 case ID_marquee_size:
1667 libvlc_video_get_marquee_int(p_md, marquee_idx[index], &ex),
1669 RETURN_ON_EXCEPTION(this,ex);
1670 return INVOKERESULT_NO_ERROR;
1672 case ID_marquee_position:
1673 STRINGZ_TO_NPVARIANT( position_bynumber(
1674 libvlc_video_get_marquee_int(p_md, libvlc_marquee_Position, &ex) ),
1677 RETURN_ON_EXCEPTION(this,ex);
1680 case ID_marquee_text:
1681 psz = libvlc_video_get_marquee_string(p_md, libvlc_marquee_Text, &ex);
1684 STRINGZ_TO_NPVARIANT(psz, result);
1685 return INVOKERESULT_NO_ERROR;
1689 return INVOKERESULT_GENERIC_ERROR;
1692 RuntimeNPObject::InvokeResult
1693 LibvlcMarqueeNPObject::setProperty(int index, const NPVariant &value)
1697 if( !isPluginRunning() )
1698 return INVOKERESULT_GENERIC_ERROR;
1700 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1701 libvlc_exception_t ex;
1702 libvlc_exception_init(&ex);
1703 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1704 RETURN_ON_EXCEPTION(this,ex);
1708 case ID_marquee_color:
1709 case ID_marquee_opacity:
1710 case ID_marquee_refresh:
1711 case ID_marquee_timeout:
1714 if( NPVARIANT_IS_INT32( value ) )
1716 libvlc_video_set_marquee_int(p_md, marquee_idx[index],
1717 NPVARIANT_TO_INT32( value ), &ex);
1718 RETURN_ON_EXCEPTION(this,ex);
1719 return INVOKERESULT_NO_ERROR;
1723 case ID_marquee_position:
1724 if( !NPVARIANT_IS_STRING(value) ||
1725 !position_byname( NPVARIANT_TO_STRING(value).utf8characters, i ) )
1726 return INVOKERESULT_INVALID_VALUE;
1728 libvlc_video_set_marquee_int(p_md, libvlc_marquee_Position, i, &ex);
1729 RETURN_ON_EXCEPTION(this,ex);
1730 return INVOKERESULT_NO_ERROR;
1732 case ID_marquee_text:
1733 if( NPVARIANT_IS_STRING( value ) )
1735 char *psz_text = stringValue( NPVARIANT_TO_STRING( value ) );
1736 libvlc_video_set_marquee_string(p_md, libvlc_marquee_Text,
1739 RETURN_ON_EXCEPTION(this,ex);
1740 return INVOKERESULT_NO_ERROR;
1744 return INVOKERESULT_NO_SUCH_METHOD;
1747 const NPUTF8 * const LibvlcMarqueeNPObject::methodNames[] =
1752 COUNTNAMES(LibvlcMarqueeNPObject,methodCount,methodNames);
1754 enum LibvlcMarqueeNPObjectMethodIds
1760 RuntimeNPObject::InvokeResult
1761 LibvlcMarqueeNPObject::invoke(int index, const NPVariant *args,
1762 uint32_t argCount, NPVariant &result)
1764 if( !isPluginRunning() )
1765 return INVOKERESULT_GENERIC_ERROR;
1767 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1768 libvlc_exception_t ex;
1769 libvlc_exception_init(&ex);
1771 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1772 RETURN_ON_EXCEPTION(this,ex);
1776 case ID_marquee_enable:
1777 case ID_marquee_disable:
1778 libvlc_video_set_marquee_int(p_md, libvlc_marquee_Enable,
1779 index!=ID_marquee_disable, &ex);
1780 RETURN_ON_EXCEPTION(this,ex);
1781 VOID_TO_NPVARIANT(result);
1782 return INVOKERESULT_NO_ERROR;
1784 return INVOKERESULT_NO_SUCH_METHOD;
1787 const NPUTF8 * const LibvlcLogoNPObject::propertyNames[] = {
1795 enum LibvlcLogoNPObjectPropertyIds {
1803 COUNTNAMES(LibvlcLogoNPObject,propertyCount,propertyNames);
1804 static const unsigned char logo_idx[] = {
1807 libvlc_logo_opacity,
1813 RuntimeNPObject::InvokeResult
1814 LibvlcLogoNPObject::getProperty(int index, NPVariant &result)
1816 if( !isPluginRunning() )
1817 return INVOKERESULT_GENERIC_ERROR;
1819 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1820 libvlc_exception_t ex;
1821 libvlc_exception_init(&ex);
1822 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1823 RETURN_ON_EXCEPTION(this,ex);
1828 case ID_logo_repeat:
1829 case ID_logo_opacity:
1834 libvlc_video_get_logo_int(p_md, logo_idx[index], &ex), result);
1836 RETURN_ON_EXCEPTION(this,ex);
1839 case ID_logo_position:
1840 STRINGZ_TO_NPVARIANT( position_bynumber(
1841 libvlc_video_get_logo_int(p_md, libvlc_logo_position, &ex) ),
1844 RETURN_ON_EXCEPTION(this,ex);
1847 return INVOKERESULT_GENERIC_ERROR;
1849 return INVOKERESULT_NO_ERROR;
1852 RuntimeNPObject::InvokeResult
1853 LibvlcLogoNPObject::setProperty(int index, const NPVariant &value)
1857 if( !isPluginRunning() )
1858 return INVOKERESULT_GENERIC_ERROR;
1860 VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
1861 libvlc_exception_t ex;
1862 libvlc_exception_init(&ex);
1864 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
1865 RETURN_ON_EXCEPTION(this,ex);
1870 case ID_logo_repeat:
1871 case ID_logo_opacity:
1874 if( !NPVARIANT_IS_INT32(value) )
1875 return INVOKERESULT_INVALID_VALUE;
1877 libvlc_video_set_logo_int(p_md, logo_idx[index],
1878 NPVARIANT_TO_INT32( value ), &ex);
1880 RETURN_ON_EXCEPTION(this,ex);
1883 case ID_logo_position:
1884 if( !NPVARIANT_IS_STRING(value) ||
1885 !position_byname( NPVARIANT_TO_STRING(value).utf8characters, i ) )
1886 return INVOKERESULT_INVALID_VALUE;
1888 libvlc_video_set_logo_int(p_md, libvlc_logo_position, i, &ex);
1890 RETURN_ON_EXCEPTION(this,ex);
1893 return INVOKERESULT_GENERIC_ERROR;
1895 return INVOKERESULT_NO_ERROR;
1899 const NPUTF8 * const LibvlcLogoNPObject::methodNames[] = {
1904 enum LibvlcLogoNPObjectMethodIds {
1909 COUNTNAMES(LibvlcLogoNPObject,methodCount,methodNames);
1911 RuntimeNPObject::InvokeResult
1912 LibvlcLogoNPObject::invoke(int index, const NPVariant *args,
1913 uint32_t argCount, NPVariant &result)
1918 if( !isPluginRunning() )
1919 return INVOKERESULT_GENERIC_ERROR;
1921 libvlc_exception_t ex;
1922 libvlc_exception_init(&ex);
1923 libvlc_media_player_t *p_md = getPrivate<VlcPlugin>()->getMD(&ex);
1924 RETURN_ON_EXCEPTION(this,ex);
1928 case ID_logo_enable:
1929 case ID_logo_disable:
1931 return INVOKERESULT_GENERIC_ERROR;
1933 libvlc_video_set_logo_int(p_md, libvlc_logo_enable,
1934 index != ID_logo_disable, &ex);
1935 RETURN_ON_EXCEPTION(this,ex);
1936 VOID_TO_NPVARIANT(result);
1941 return INVOKERESULT_GENERIC_ERROR;
1943 for( len=0,i=0;i<argCount;++i )
1945 if( !NPVARIANT_IS_STRING(args[i]) )
1946 return INVOKERESULT_INVALID_VALUE;
1947 len+=NPVARIANT_TO_STRING(args[i]).utf8length+1;
1950 buf = (char *)malloc( len+1 );
1952 return INVOKERESULT_OUT_OF_MEMORY;
1954 for( h=buf,i=0;i<argCount;++i )
1957 len=NPVARIANT_TO_STRING(args[i]).utf8length;
1958 memcpy(h,NPVARIANT_TO_STRING(args[i]).utf8characters,len);
1963 libvlc_video_set_logo_string(p_md, libvlc_logo_file, buf, &ex);
1965 RETURN_ON_EXCEPTION(this,ex);
1966 VOID_TO_NPVARIANT(result);
1969 return INVOKERESULT_NO_SUCH_METHOD;
1971 return INVOKERESULT_NO_ERROR;
1975 const NPUTF8 * const LibvlcDeinterlaceNPObject::propertyNames[] = {
1977 enum LibvlcDeinterlaceNPObjectPropertyIds {
1979 COUNTNAMES(LibvlcDeinterlaceNPObject,propertyCount,propertyNames);
1981 RuntimeNPObject::InvokeResult
1982 LibvlcDeinterlaceNPObject::getProperty(int index, NPVariant &result)
1984 return INVOKERESULT_GENERIC_ERROR;
1987 RuntimeNPObject::InvokeResult
1988 LibvlcDeinterlaceNPObject::setProperty(int index, const NPVariant &value)
1990 return INVOKERESULT_GENERIC_ERROR;
1994 const NPUTF8 * const LibvlcDeinterlaceNPObject::methodNames[] = {
1998 enum LibvlcDeinterlaceNPObjectMethodIds {
2002 COUNTNAMES(LibvlcDeinterlaceNPObject,methodCount,methodNames);
2004 RuntimeNPObject::InvokeResult
2005 LibvlcDeinterlaceNPObject::invoke(int index, const NPVariant *args,
2006 uint32_t argCount, NPVariant &result)
2010 if( !isPluginRunning() )
2011 return INVOKERESULT_GENERIC_ERROR;
2013 libvlc_exception_t ex;
2014 libvlc_exception_init(&ex);
2015 libvlc_media_player_t *p_md = getPrivate<VlcPlugin>()->getMD(&ex);
2016 RETURN_ON_EXCEPTION(this,ex);
2020 case ID_deint_disable:
2021 libvlc_video_set_deinterlace(p_md, 0, "", &ex);
2022 RETURN_ON_EXCEPTION(this,ex);
2025 case ID_deint_enable:
2026 if( argCount != 1 || !NPVARIANT_IS_STRING( args[0] ) )
2027 return INVOKERESULT_INVALID_VALUE;
2029 psz = stringValue( NPVARIANT_TO_STRING( args[0] ) );
2030 libvlc_video_set_deinterlace(p_md, 1, psz, &ex);
2032 RETURN_ON_EXCEPTION(this,ex);
2036 return INVOKERESULT_NO_SUCH_METHOD;
2038 return INVOKERESULT_NO_ERROR;