1 /*****************************************************************************
\r
2 * npolibvlc.cpp: official Javascript APIs
\r
3 *****************************************************************************
\r
4 * Copyright (C) 2002-2006 the VideoLAN team
\r
6 * Authors: Damien Fouilleul <Damien.Fouilleul@laposte.net>
\r
8 * This program is free software; you can redistribute it and/or modify
\r
9 * it under the terms of the GNU General Public License as published by
\r
10 * the Free Software Foundation; either version 2 of the License, or
\r
11 * (at your option) any later version.
\r
13 * This program is distributed in the hope that it will be useful,
\r
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
16 * GNU General Public License for more details.
\r
18 * You should have received a copy of the GNU General Public License
\r
19 * along with this program; if not, write to the Free Software
\r
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
\r
21 *****************************************************************************/
\r
30 #ifdef HAVE_MOZILLA_CONFIG_H
\r
31 # include <mozilla-config.h>
\r
34 #include "npolibvlc.h"
\r
35 #include "vlcplugin.h"
\r
38 ** implementation of libvlc root object
\r
41 LibvlcRootNPObject::LibvlcRootNPObject(NPP instance, const NPClass *aClass) :
\r
42 RuntimeNPObject(instance, aClass)
\r
44 audioObj = NPN_CreateObject(instance, RuntimeNPClass<LibvlcAudioNPObject>::getClass());
\r
45 inputObj = NPN_CreateObject(instance, RuntimeNPClass<LibvlcInputNPObject>::getClass());
\r
46 playlistObj = NPN_CreateObject(instance, RuntimeNPClass<LibvlcPlaylistNPObject>::getClass());
\r
47 videoObj = NPN_CreateObject(instance,RuntimeNPClass<LibvlcVideoNPObject>::getClass());
\r
50 LibvlcRootNPObject::~LibvlcRootNPObject()
\r
52 NPN_ReleaseObject(audioObj);
\r
53 NPN_ReleaseObject(inputObj);
\r
54 NPN_ReleaseObject(playlistObj);
\r
55 NPN_ReleaseObject(videoObj);
\r
58 const NPUTF8 * const LibvlcRootNPObject::propertyNames[] =
\r
66 const int LibvlcRootNPObject::propertyCount = sizeof(LibvlcRootNPObject::propertyNames)/sizeof(NPUTF8 *);
\r
68 enum LibvlcRootNPObjectPropertyIds
\r
76 RuntimeNPObject::InvokeResult LibvlcRootNPObject::getProperty(int index, NPVariant &result)
\r
81 OBJECT_TO_NPVARIANT(NPN_RetainObject(audioObj), result);
\r
82 return INVOKERESULT_NO_ERROR;
\r
84 OBJECT_TO_NPVARIANT(NPN_RetainObject(inputObj), result);
\r
85 return INVOKERESULT_NO_ERROR;
\r
87 OBJECT_TO_NPVARIANT(NPN_RetainObject(playlistObj), result);
\r
88 return INVOKERESULT_NO_ERROR;
\r
90 OBJECT_TO_NPVARIANT(NPN_RetainObject(videoObj), result);
\r
91 return INVOKERESULT_NO_ERROR;
\r
93 return INVOKERESULT_GENERIC_ERROR;
\r
96 const NPUTF8 * const LibvlcRootNPObject::methodNames[] =
\r
101 const int LibvlcRootNPObject::methodCount = sizeof(LibvlcRootNPObject::methodNames)/sizeof(NPUTF8 *);
\r
104 ** implementation of libvlc audio object
\r
107 const NPUTF8 * const LibvlcAudioNPObject::propertyNames[] =
\r
113 const int LibvlcAudioNPObject::propertyCount = sizeof(LibvlcAudioNPObject::propertyNames)/sizeof(NPUTF8 *);
\r
115 enum LibvlcAudioNPObjectPropertyIds
\r
121 RuntimeNPObject::InvokeResult LibvlcAudioNPObject::getProperty(int index, NPVariant &result)
\r
123 VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);
\r
126 libvlc_exception_t ex;
\r
127 libvlc_exception_init(&ex);
\r
133 vlc_bool_t muted = libvlc_audio_get_mute(p_plugin->getVLC(), &ex);
\r
134 if( libvlc_exception_raised(&ex) )
\r
136 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
137 libvlc_exception_clear(&ex);
\r
138 return INVOKERESULT_GENERIC_ERROR;
\r
140 BOOLEAN_TO_NPVARIANT(muted, result);
\r
141 return INVOKERESULT_NO_ERROR;
\r
145 int volume = libvlc_audio_get_volume(p_plugin->getVLC(), &ex);
\r
146 if( libvlc_exception_raised(&ex) )
\r
148 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
149 libvlc_exception_clear(&ex);
\r
150 return INVOKERESULT_GENERIC_ERROR;
\r
152 INT32_TO_NPVARIANT(volume, result);
\r
153 return INVOKERESULT_NO_ERROR;
\r
157 return INVOKERESULT_GENERIC_ERROR;
\r
160 RuntimeNPObject::InvokeResult LibvlcAudioNPObject::setProperty(int index, const NPVariant &value)
\r
162 VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);
\r
165 libvlc_exception_t ex;
\r
166 libvlc_exception_init(&ex);
\r
171 if( NPVARIANT_IS_BOOLEAN(value) )
\r
173 libvlc_audio_set_mute(p_plugin->getVLC(),
\r
174 NPVARIANT_TO_BOOLEAN(value), &ex);
\r
175 if( libvlc_exception_raised(&ex) )
\r
177 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
178 libvlc_exception_clear(&ex);
\r
179 return INVOKERESULT_GENERIC_ERROR;
\r
181 return INVOKERESULT_NO_ERROR;
\r
183 return INVOKERESULT_INVALID_VALUE;
\r
185 if( isNumberValue(value) )
\r
187 libvlc_audio_set_volume(p_plugin->getVLC(),
\r
188 numberValue(value), &ex);
\r
189 if( libvlc_exception_raised(&ex) )
\r
191 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
192 libvlc_exception_clear(&ex);
\r
193 return INVOKERESULT_GENERIC_ERROR;
\r
195 return INVOKERESULT_NO_ERROR;
\r
197 return INVOKERESULT_INVALID_VALUE;
\r
200 return INVOKERESULT_GENERIC_ERROR;
\r
203 const NPUTF8 * const LibvlcAudioNPObject::methodNames[] =
\r
208 const int LibvlcAudioNPObject::methodCount = sizeof(LibvlcAudioNPObject::methodNames)/sizeof(NPUTF8 *);
\r
210 enum LibvlcAudioNPObjectMethodIds
\r
215 RuntimeNPObject::InvokeResult LibvlcAudioNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)
\r
217 VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);
\r
220 libvlc_exception_t ex;
\r
221 libvlc_exception_init(&ex);
\r
225 case ID_togglemute:
\r
226 if( argCount == 0 )
\r
228 libvlc_audio_toggle_mute(p_plugin->getVLC(), &ex);
\r
229 if( libvlc_exception_raised(&ex) )
\r
231 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
232 libvlc_exception_clear(&ex);
\r
233 return INVOKERESULT_GENERIC_ERROR;
\r
237 VOID_TO_NPVARIANT(result);
\r
238 return INVOKERESULT_NO_ERROR;
\r
241 return INVOKERESULT_NO_SUCH_METHOD;
\r
243 return INVOKERESULT_NO_SUCH_METHOD;
\r
246 return INVOKERESULT_GENERIC_ERROR;
\r
250 ** implementation of libvlc input object
\r
253 const NPUTF8 * const LibvlcInputNPObject::propertyNames[] =
\r
262 const int LibvlcInputNPObject::propertyCount = sizeof(LibvlcInputNPObject::propertyNames)/sizeof(NPUTF8 *);
\r
264 enum LibvlcInputNPObjectPropertyIds
\r
273 RuntimeNPObject::InvokeResult LibvlcInputNPObject::getProperty(int index, NPVariant &result)
\r
275 VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);
\r
278 libvlc_exception_t ex;
\r
279 libvlc_exception_init(&ex);
\r
281 libvlc_input_t *p_input = libvlc_playlist_get_input(p_plugin->getVLC(), &ex);
\r
282 if( libvlc_exception_raised(&ex) )
\r
284 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
285 libvlc_exception_clear(&ex);
\r
286 return INVOKERESULT_GENERIC_ERROR;
\r
293 double val = (double)libvlc_input_get_length(p_input, &ex);
\r
294 libvlc_input_free(p_input);
\r
295 if( libvlc_exception_raised(&ex) )
\r
297 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
298 libvlc_exception_clear(&ex);
\r
299 return INVOKERESULT_GENERIC_ERROR;
\r
301 DOUBLE_TO_NPVARIANT(val, result);
\r
302 return INVOKERESULT_NO_ERROR;
\r
306 double val = libvlc_input_get_position(p_input, &ex);
\r
307 libvlc_input_free(p_input);
\r
308 if( libvlc_exception_raised(&ex) )
\r
310 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
311 libvlc_exception_clear(&ex);
\r
312 return INVOKERESULT_GENERIC_ERROR;
\r
314 DOUBLE_TO_NPVARIANT(val, result);
\r
315 return INVOKERESULT_NO_ERROR;
\r
319 double val = (double)libvlc_input_get_time(p_input, &ex);
\r
320 libvlc_input_free(p_input);
\r
321 if( libvlc_exception_raised(&ex) )
\r
323 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
324 libvlc_exception_clear(&ex);
\r
325 return INVOKERESULT_GENERIC_ERROR;
\r
327 DOUBLE_TO_NPVARIANT(val, result);
\r
328 return INVOKERESULT_NO_ERROR;
\r
332 double val = libvlc_input_get_fps(p_input, &ex);
\r
333 libvlc_input_free(p_input);
\r
334 if( libvlc_exception_raised(&ex) )
\r
336 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
337 libvlc_exception_clear(&ex);
\r
338 return INVOKERESULT_GENERIC_ERROR;
\r
340 DOUBLE_TO_NPVARIANT(val, result);
\r
341 return INVOKERESULT_NO_ERROR;
\r
345 vlc_bool_t val = libvlc_input_has_vout(p_input, &ex);
\r
346 libvlc_input_free(p_input);
\r
347 if( libvlc_exception_raised(&ex) )
\r
349 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
350 libvlc_exception_clear(&ex);
\r
351 return INVOKERESULT_GENERIC_ERROR;
\r
353 BOOLEAN_TO_NPVARIANT(val, result);
\r
354 return INVOKERESULT_NO_ERROR;
\r
357 libvlc_input_free(p_input);
\r
359 return INVOKERESULT_GENERIC_ERROR;
\r
362 RuntimeNPObject::InvokeResult LibvlcInputNPObject::setProperty(int index, const NPVariant &value)
\r
364 VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);
\r
367 libvlc_exception_t ex;
\r
368 libvlc_exception_init(&ex);
\r
370 libvlc_input_t *p_input = libvlc_playlist_get_input(p_plugin->getVLC(), &ex);
\r
371 if( libvlc_exception_raised(&ex) )
\r
373 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
374 libvlc_exception_clear(&ex);
\r
375 return INVOKERESULT_GENERIC_ERROR;
\r
382 if( ! NPVARIANT_IS_DOUBLE(value) )
\r
384 libvlc_input_free(p_input);
\r
385 return INVOKERESULT_INVALID_VALUE;
\r
388 float val = (float)NPVARIANT_TO_DOUBLE(value);
\r
389 libvlc_input_set_position(p_input, val, &ex);
\r
390 libvlc_input_free(p_input);
\r
391 if( libvlc_exception_raised(&ex) )
\r
393 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
394 libvlc_exception_clear(&ex);
\r
395 return INVOKERESULT_GENERIC_ERROR;
\r
397 return INVOKERESULT_NO_ERROR;
\r
402 if( NPVARIANT_IS_INT32(value) )
\r
403 val = (vlc_int64_t)NPVARIANT_TO_INT32(value);
\r
404 else if( NPVARIANT_IS_DOUBLE(value) )
\r
405 val = (vlc_int64_t)NPVARIANT_TO_DOUBLE(value);
\r
408 libvlc_input_free(p_input);
\r
409 return INVOKERESULT_INVALID_VALUE;
\r
412 libvlc_input_set_time(p_input, val, &ex);
\r
413 libvlc_input_free(p_input);
\r
414 if( libvlc_exception_raised(&ex) )
\r
416 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
417 libvlc_exception_clear(&ex);
\r
418 return INVOKERESULT_GENERIC_ERROR;
\r
420 return INVOKERESULT_NO_ERROR;
\r
423 libvlc_input_free(p_input);
\r
425 return INVOKERESULT_GENERIC_ERROR;
\r
428 const NPUTF8 * const LibvlcInputNPObject::methodNames[] =
\r
433 const int LibvlcInputNPObject::methodCount = sizeof(LibvlcInputNPObject::methodNames)/sizeof(NPUTF8 *);
\r
436 ** implementation of libvlc playlist object
\r
440 const NPUTF8 * const LibvlcPlaylistNPObject::propertyNames[] =
\r
446 const int LibvlcPlaylistNPObject::propertyCount = sizeof(LibvlcPlaylistNPObject::propertyNames)/sizeof(NPUTF8 *);
\r
448 enum LibvlcPlaylistNPObjectPropertyIds
\r
454 RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::getProperty(int index, NPVariant &result)
\r
456 VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);
\r
459 libvlc_exception_t ex;
\r
460 libvlc_exception_init(&ex);
\r
464 case ID_itemscount:
\r
466 int val = libvlc_playlist_items_count(p_plugin->getVLC(), &ex);
\r
467 if( libvlc_exception_raised(&ex) )
\r
469 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
470 libvlc_exception_clear(&ex);
\r
471 return INVOKERESULT_GENERIC_ERROR;
\r
473 INT32_TO_NPVARIANT(val, result);
\r
474 return INVOKERESULT_NO_ERROR;
\r
478 int val = libvlc_playlist_isplaying(p_plugin->getVLC(), &ex);
\r
479 if( libvlc_exception_raised(&ex) )
\r
481 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
482 libvlc_exception_clear(&ex);
\r
483 return INVOKERESULT_GENERIC_ERROR;
\r
485 BOOLEAN_TO_NPVARIANT(val, result);
\r
486 return INVOKERESULT_NO_ERROR;
\r
490 return INVOKERESULT_GENERIC_ERROR;
\r
493 const NPUTF8 * const LibvlcPlaylistNPObject::methodNames[] =
\r
505 const int LibvlcPlaylistNPObject::methodCount = sizeof(LibvlcPlaylistNPObject::methodNames)/sizeof(NPUTF8 *);
\r
507 enum LibvlcPlaylistNPObjectMethodIds
\r
519 RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)
\r
521 VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);
\r
524 libvlc_exception_t ex;
\r
525 libvlc_exception_init(&ex);
\r
531 if( (argCount < 1) || (argCount > 3) )
\r
532 return INVOKERESULT_NO_SUCH_METHOD;
\r
537 if( NPVARIANT_IS_STRING(args[0]) )
\r
539 char *s = stringValue(NPVARIANT_TO_STRING(args[0]));
\r
542 url = p_plugin->getAbsoluteURL(s);
\r
546 return INVOKERESULT_GENERIC_ERROR;
\r
549 return INVOKERESULT_OUT_OF_MEMORY;
\r
552 return INVOKERESULT_NO_SUCH_METHOD;
\r
556 // grab name if available
\r
559 if( NPVARIANT_IS_NULL(args[1]) )
\r
563 else if( NPVARIANT_IS_STRING(args[1]) )
\r
565 name = stringValue(NPVARIANT_TO_STRING(args[0]));
\r
568 return INVOKERESULT_NO_SUCH_METHOD;
\r
572 char** ppsz_options = NULL;
\r
574 // grab options if available
\r
577 if( NPVARIANT_IS_NULL(args[2]) )
\r
581 else if( NPVARIANT_IS_STRING(args[2]) )
\r
583 parseOptions(NPVARIANT_TO_STRING(args[2]), &i_options, &ppsz_options);
\r
586 else if( NPVARIANT_IS_OBJECT(args[2]) )
\r
588 parseOptions(NPVARIANT_TO_OBJECT(args[2]), &i_options, &ppsz_options);
\r
592 int item = libvlc_playlist_add_extended(p_plugin->getVLC(),
\r
596 const_cast<const char **>(ppsz_options),
\r
600 for( int i=0; i< i_options; ++i )
\r
602 if( ppsz_options[i] )
\r
603 free(ppsz_options[i]);
\r
606 free(ppsz_options);
\r
607 if( libvlc_exception_raised(&ex) )
\r
609 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
610 libvlc_exception_clear(&ex);
\r
611 return INVOKERESULT_GENERIC_ERROR;
\r
615 INT32_TO_NPVARIANT(item, result);
\r
616 return INVOKERESULT_NO_ERROR;
\r
620 if( argCount == 0 )
\r
622 libvlc_playlist_play(p_plugin->getVLC(), -1, 0, NULL, &ex);
\r
623 if( libvlc_exception_raised(&ex) )
\r
625 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
626 libvlc_exception_clear(&ex);
\r
627 return INVOKERESULT_GENERIC_ERROR;
\r
631 VOID_TO_NPVARIANT(result);
\r
632 return INVOKERESULT_NO_ERROR;
\r
635 return INVOKERESULT_NO_SUCH_METHOD;
\r
636 case ID_togglepause:
\r
637 if( argCount == 0 )
\r
639 libvlc_playlist_pause(p_plugin->getVLC(), &ex);
\r
640 if( libvlc_exception_raised(&ex) )
\r
642 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
643 libvlc_exception_clear(&ex);
\r
644 return INVOKERESULT_GENERIC_ERROR;
\r
648 VOID_TO_NPVARIANT(result);
\r
649 return INVOKERESULT_NO_ERROR;
\r
652 return INVOKERESULT_NO_SUCH_METHOD;
\r
654 if( argCount == 0 )
\r
656 libvlc_playlist_stop(p_plugin->getVLC(), &ex);
\r
657 if( libvlc_exception_raised(&ex) )
\r
659 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
660 libvlc_exception_clear(&ex);
\r
661 return INVOKERESULT_GENERIC_ERROR;
\r
665 VOID_TO_NPVARIANT(result);
\r
666 return INVOKERESULT_NO_ERROR;
\r
669 return INVOKERESULT_NO_SUCH_METHOD;
\r
671 if( argCount == 0 )
\r
673 libvlc_playlist_next(p_plugin->getVLC(), &ex);
\r
674 if( libvlc_exception_raised(&ex) )
\r
676 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
677 libvlc_exception_clear(&ex);
\r
678 return INVOKERESULT_GENERIC_ERROR;
\r
682 VOID_TO_NPVARIANT(result);
\r
683 return INVOKERESULT_NO_ERROR;
\r
686 return INVOKERESULT_NO_SUCH_METHOD;
\r
688 if( argCount == 0 )
\r
690 libvlc_playlist_prev(p_plugin->getVLC(), &ex);
\r
691 if( libvlc_exception_raised(&ex) )
\r
693 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
694 libvlc_exception_clear(&ex);
\r
695 return INVOKERESULT_GENERIC_ERROR;
\r
699 VOID_TO_NPVARIANT(result);
\r
700 return INVOKERESULT_NO_ERROR;
\r
703 return INVOKERESULT_NO_SUCH_METHOD;
\r
705 if( argCount == 0 )
\r
707 libvlc_playlist_clear(p_plugin->getVLC(), &ex);
\r
708 if( libvlc_exception_raised(&ex) )
\r
710 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
711 libvlc_exception_clear(&ex);
\r
712 return INVOKERESULT_GENERIC_ERROR;
\r
716 VOID_TO_NPVARIANT(result);
\r
717 return INVOKERESULT_NO_ERROR;
\r
720 return INVOKERESULT_NO_SUCH_METHOD;
\r
721 case ID_deleteitem:
\r
722 if( (argCount == 1) && isNumberValue(args[0]) )
\r
724 libvlc_playlist_delete_item(p_plugin->getVLC(), numberValue(args[0]), &ex);
\r
725 if( libvlc_exception_raised(&ex) )
\r
727 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
728 libvlc_exception_clear(&ex);
\r
729 return INVOKERESULT_GENERIC_ERROR;
\r
733 VOID_TO_NPVARIANT(result);
\r
734 return INVOKERESULT_NO_ERROR;
\r
737 return INVOKERESULT_NO_SUCH_METHOD;
\r
739 return INVOKERESULT_NO_SUCH_METHOD;
\r
742 return INVOKERESULT_GENERIC_ERROR;
\r
745 void LibvlcPlaylistNPObject::parseOptions(const NPString &s, int *i_options, char*** ppsz_options)
\r
749 char *val = stringValue(s);
\r
752 long capacity = 16;
\r
753 char **options = (char **)malloc(capacity*sizeof(char *));
\r
758 char *end = val + s.utf8length;
\r
761 // skip leading blanks
\r
763 && ((*val == ' ' ) || (*val == '\t')) )
\r
767 // skip till we get a blank character
\r
770 && (*val != '\t') )
\r
773 if( ('\'' == c) || ('"' == c) )
\r
775 // skip till end of string
\r
776 while( (val < end) && (*(val++) != c ) );
\r
782 if( nOptions == capacity )
\r
785 char **moreOptions = (char **)realloc(options, capacity*sizeof(char*));
\r
786 if( ! moreOptions )
\r
788 /* failed to allocate more memory */
\r
790 /* return what we got so far */
\r
791 *i_options = nOptions;
\r
792 *ppsz_options = options;
\r
795 options = moreOptions;
\r
798 options[nOptions++] = strdup(start);
\r
801 // must be end of string
\r
804 *i_options = nOptions;
\r
805 *ppsz_options = options;
\r
812 void LibvlcPlaylistNPObject::parseOptions(NPObject *obj, int *i_options, char*** ppsz_options)
\r
814 /* WARNING: Safari does not implement NPN_HasProperty/NPN_HasMethod */
\r
818 /* we are expecting to have a Javascript Array object */
\r
819 NPIdentifier propId = NPN_GetStringIdentifier("length");
\r
820 if( NPN_GetProperty(_instance, obj, propId, &value) )
\r
822 int count = numberValue(value);
\r
823 NPN_ReleaseVariantValue(&value);
\r
827 long capacity = 16;
\r
828 char **options = (char **)malloc(capacity*sizeof(char *));
\r
833 while( nOptions < count )
\r
835 propId = NPN_GetIntIdentifier(nOptions);
\r
836 if( ! NPN_GetProperty(_instance, obj, propId, &value) )
\r
837 /* return what we got so far */
\r
840 if( ! NPVARIANT_IS_STRING(value) )
\r
842 /* return what we got so far */
\r
843 NPN_ReleaseVariantValue(&value);
\r
847 if( nOptions == capacity )
\r
850 char **moreOptions = (char **)realloc(options, capacity*sizeof(char*));
\r
851 if( ! moreOptions )
\r
853 /* failed to allocate more memory */
\r
854 NPN_ReleaseVariantValue(&value);
\r
855 /* return what we got so far */
\r
856 *i_options = nOptions;
\r
857 *ppsz_options = options;
\r
860 options = moreOptions;
\r
863 options[nOptions++] = stringValue(value);
\r
865 *i_options = nOptions;
\r
866 *ppsz_options = options;
\r
873 ** implementation of libvlc video object
\r
876 const NPUTF8 * const LibvlcVideoNPObject::propertyNames[] =
\r
883 enum LibvlcVideoNPObjectPropertyIds
\r
890 const int LibvlcVideoNPObject::propertyCount = sizeof(LibvlcVideoNPObject::propertyNames)/sizeof(NPUTF8 *);
\r
892 RuntimeNPObject::InvokeResult LibvlcVideoNPObject::getProperty(int index, NPVariant &result)
\r
894 VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);
\r
897 libvlc_exception_t ex;
\r
898 libvlc_exception_init(&ex);
\r
900 libvlc_input_t *p_input = libvlc_playlist_get_input(p_plugin->getVLC(), &ex);
\r
901 if( libvlc_exception_raised(&ex) )
\r
903 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
904 libvlc_exception_clear(&ex);
\r
905 return INVOKERESULT_GENERIC_ERROR;
\r
910 case ID_fullscreen:
\r
912 int val = libvlc_get_fullscreen(p_input, &ex);
\r
913 libvlc_input_free(p_input);
\r
914 if( libvlc_exception_raised(&ex) )
\r
916 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
917 libvlc_exception_clear(&ex);
\r
918 return INVOKERESULT_GENERIC_ERROR;
\r
920 BOOLEAN_TO_NPVARIANT(val, result);
\r
921 return INVOKERESULT_NO_ERROR;
\r
925 int val = libvlc_video_get_height(p_input, &ex);
\r
926 libvlc_input_free(p_input);
\r
927 if( libvlc_exception_raised(&ex) )
\r
929 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
930 libvlc_exception_clear(&ex);
\r
931 return INVOKERESULT_GENERIC_ERROR;
\r
933 INT32_TO_NPVARIANT(val, result);
\r
934 return INVOKERESULT_NO_ERROR;
\r
938 int val = libvlc_video_get_width(p_input, &ex);
\r
939 libvlc_input_free(p_input);
\r
940 if( libvlc_exception_raised(&ex) )
\r
942 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
943 libvlc_exception_clear(&ex);
\r
944 return INVOKERESULT_GENERIC_ERROR;
\r
946 INT32_TO_NPVARIANT(val, result);
\r
947 return INVOKERESULT_NO_ERROR;
\r
950 libvlc_input_free(p_input);
\r
952 return INVOKERESULT_GENERIC_ERROR;
\r
955 RuntimeNPObject::InvokeResult LibvlcVideoNPObject::setProperty(int index, const NPVariant &value)
\r
957 VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);
\r
960 libvlc_exception_t ex;
\r
961 libvlc_exception_init(&ex);
\r
963 libvlc_input_t *p_input = libvlc_playlist_get_input(p_plugin->getVLC(), &ex);
\r
964 if( libvlc_exception_raised(&ex) )
\r
966 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
967 libvlc_exception_clear(&ex);
\r
968 return INVOKERESULT_GENERIC_ERROR;
\r
973 case ID_fullscreen:
\r
975 if( ! NPVARIANT_IS_BOOLEAN(value) )
\r
977 libvlc_input_free(p_input);
\r
978 return INVOKERESULT_INVALID_VALUE;
\r
981 int val = NPVARIANT_TO_BOOLEAN(value);
\r
982 libvlc_set_fullscreen(p_input, val, &ex);
\r
983 libvlc_input_free(p_input);
\r
984 if( libvlc_exception_raised(&ex) )
\r
986 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
987 libvlc_exception_clear(&ex);
\r
988 return INVOKERESULT_GENERIC_ERROR;
\r
990 return INVOKERESULT_NO_ERROR;
\r
993 libvlc_input_free(p_input);
\r
995 return INVOKERESULT_GENERIC_ERROR;
\r
998 const NPUTF8 * const LibvlcVideoNPObject::methodNames[] =
\r
1000 "togglefullscreen",
\r
1003 enum LibvlcVideoNPObjectMethodIds
\r
1005 ID_togglefullscreen,
\r
1008 const int LibvlcVideoNPObject::methodCount = sizeof(LibvlcVideoNPObject::methodNames)/sizeof(NPUTF8 *);
\r
1010 RuntimeNPObject::InvokeResult LibvlcVideoNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)
\r
1012 VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);
\r
1015 libvlc_exception_t ex;
\r
1016 libvlc_exception_init(&ex);
\r
1018 libvlc_input_t *p_input = libvlc_playlist_get_input(p_plugin->getVLC(), &ex);
\r
1019 if( libvlc_exception_raised(&ex) )
\r
1021 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
1022 libvlc_exception_clear(&ex);
\r
1023 return INVOKERESULT_GENERIC_ERROR;
\r
1028 case ID_togglefullscreen:
\r
1029 if( argCount == 0 )
\r
1031 libvlc_toggle_fullscreen(p_input, &ex);
\r
1032 libvlc_input_free(p_input);
\r
1033 if( libvlc_exception_raised(&ex) )
\r
1035 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
1036 libvlc_exception_clear(&ex);
\r
1037 return INVOKERESULT_GENERIC_ERROR;
\r
1041 VOID_TO_NPVARIANT(result);
\r
1042 return INVOKERESULT_NO_ERROR;
\r
1047 /* cannot get input, probably not playing */
\r
1048 if( libvlc_exception_raised(&ex) )
\r
1050 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
1051 libvlc_exception_clear(&ex);
\r
1053 return INVOKERESULT_GENERIC_ERROR;
\r
1055 return INVOKERESULT_NO_SUCH_METHOD;
\r
1057 return INVOKERESULT_NO_SUCH_METHOD;
\r
1060 return INVOKERESULT_GENERIC_ERROR;
\r