1 /*****************************************************************************
2 * npolibvlc.cpp: official Javascript APIs
3 *****************************************************************************
4 * Copyright (C) 2002-2006 the VideoLAN team
6 * Authors: Damien Fouilleul <Damien.Fouilleul@laposte.net>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21 *****************************************************************************/
30 #ifdef HAVE_MOZILLA_CONFIG_H
31 # include <mozilla-config.h>
34 #include "vlcplugin.h"
35 #include "npolibvlc.h"
38 ** implementation of libvlc root object
41 LibvlcRootNPObject::~LibvlcRootNPObject()
44 ** when plugin is destroyed, firefox takes upon itself to destroy all 'live' script objects
45 ** and ignores refcounting. Therefore we cannot safely assume that refcounting will control
46 ** lifespan of objects. Hence they are only lazily created on request, so that firefox can
47 ** take ownership, and are not released when plugin is being destroyed.
51 if( audioObj ) NPN_ReleaseObject(audioObj);
52 if( inputObj ) NPN_ReleaseObject(inputObj);
53 if( logObj ) NPN_ReleaseObject(logObj);
54 if( playlistObj ) NPN_ReleaseObject(playlistObj);
55 if( videoObj ) NPN_ReleaseObject(videoObj);
59 const NPUTF8 * const LibvlcRootNPObject::propertyNames[] =
69 const int LibvlcRootNPObject::propertyCount = sizeof(LibvlcRootNPObject::propertyNames)/sizeof(NPUTF8 *);
71 enum LibvlcRootNPObjectPropertyIds
81 RuntimeNPObject::InvokeResult LibvlcRootNPObject::getProperty(int index, NPVariant &result)
83 /* is plugin still running */
84 if( _instance->pdata )
89 // create child object in lazyman fashion to avoid ownership problem with firefox
91 audioObj = NPN_CreateObject(_instance, RuntimeNPClass<LibvlcAudioNPObject>::getClass());
92 OBJECT_TO_NPVARIANT(NPN_RetainObject(audioObj), result);
93 return INVOKERESULT_NO_ERROR;
95 // create child object in lazyman fashion to avoid ownership problem with firefox
97 inputObj = NPN_CreateObject(_instance, RuntimeNPClass<LibvlcInputNPObject>::getClass());
98 OBJECT_TO_NPVARIANT(NPN_RetainObject(inputObj), result);
99 return INVOKERESULT_NO_ERROR;
101 // create child object in lazyman fashion to avoid ownership problem with firefox
103 logObj = NPN_CreateObject(_instance, RuntimeNPClass<LibvlcLogNPObject>::getClass());
104 OBJECT_TO_NPVARIANT(NPN_RetainObject(logObj), result);
105 return INVOKERESULT_NO_ERROR;
106 case ID_root_playlist:
107 // create child object in lazyman fashion to avoid ownership problem with firefox
109 playlistObj = NPN_CreateObject(_instance, RuntimeNPClass<LibvlcPlaylistNPObject>::getClass());
110 OBJECT_TO_NPVARIANT(NPN_RetainObject(playlistObj), result);
111 return INVOKERESULT_NO_ERROR;
113 // create child object in lazyman fashion to avoid ownership problem with firefox
115 videoObj = NPN_CreateObject(_instance,RuntimeNPClass<LibvlcVideoNPObject>::getClass());
116 OBJECT_TO_NPVARIANT(NPN_RetainObject(videoObj), result);
117 return INVOKERESULT_NO_ERROR;
118 case ID_root_VersionInfo:
120 int len = strlen(VLC_Version());
121 NPUTF8 *retval =(NPUTF8*)NPN_MemAlloc(len);
124 memcpy(retval, VLC_Version(), len);
125 STRINGN_TO_NPVARIANT(retval, len, result);
129 NULL_TO_NPVARIANT(result);
131 return INVOKERESULT_NO_ERROR;
137 return INVOKERESULT_GENERIC_ERROR;
140 const NPUTF8 * const LibvlcRootNPObject::methodNames[] =
145 const int LibvlcRootNPObject::methodCount = sizeof(LibvlcRootNPObject::methodNames)/sizeof(NPUTF8 *);
147 enum LibvlcRootNPObjectMethodIds
152 RuntimeNPObject::InvokeResult LibvlcRootNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)
154 /* is plugin still running */
155 if( _instance->pdata )
157 libvlc_exception_t ex;
158 libvlc_exception_init(&ex);
162 case ID_root_versionInfo:
165 int len = strlen(VLC_Version());
166 NPUTF8 *retval =(NPUTF8*)NPN_MemAlloc(len);
169 memcpy(retval, VLC_Version(), len);
170 STRINGN_TO_NPVARIANT(retval, len, result);
174 NULL_TO_NPVARIANT(result);
176 return INVOKERESULT_NO_ERROR;
178 return INVOKERESULT_NO_SUCH_METHOD;
183 return INVOKERESULT_GENERIC_ERROR;
187 ** implementation of libvlc audio object
190 const NPUTF8 * const LibvlcAudioNPObject::propertyNames[] =
198 const int LibvlcAudioNPObject::propertyCount = sizeof(LibvlcAudioNPObject::propertyNames)/sizeof(NPUTF8 *);
200 enum LibvlcAudioNPObjectPropertyIds
208 RuntimeNPObject::InvokeResult LibvlcAudioNPObject::getProperty(int index, NPVariant &result)
210 /* is plugin still running */
211 if( _instance->pdata )
213 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
214 libvlc_exception_t ex;
215 libvlc_exception_init(&ex);
221 bool muted = libvlc_audio_get_mute(p_plugin->getVLC(), &ex);
222 if( libvlc_exception_raised(&ex) )
224 NPN_SetException(this, libvlc_exception_get_message(&ex));
225 libvlc_exception_clear(&ex);
226 return INVOKERESULT_GENERIC_ERROR;
228 BOOLEAN_TO_NPVARIANT(muted, result);
229 return INVOKERESULT_NO_ERROR;
231 case ID_audio_volume:
233 int volume = libvlc_audio_get_volume(p_plugin->getVLC(), &ex);
234 if( libvlc_exception_raised(&ex) )
236 NPN_SetException(this, libvlc_exception_get_message(&ex));
237 libvlc_exception_clear(&ex);
238 return INVOKERESULT_GENERIC_ERROR;
240 INT32_TO_NPVARIANT(volume, result);
241 return INVOKERESULT_NO_ERROR;
245 libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_plugin->getVLC(), &ex);
246 if( libvlc_exception_raised(&ex) )
248 NPN_SetException(this, libvlc_exception_get_message(&ex));
249 libvlc_exception_clear(&ex);
250 return INVOKERESULT_GENERIC_ERROR;
252 int track = libvlc_audio_get_track(p_md, &ex);
253 libvlc_media_player_release(p_md);
254 if( libvlc_exception_raised(&ex) )
256 NPN_SetException(this, libvlc_exception_get_message(&ex));
257 libvlc_exception_clear(&ex);
258 return INVOKERESULT_GENERIC_ERROR;
260 INT32_TO_NPVARIANT(track, result);
261 return INVOKERESULT_NO_ERROR;
263 case ID_audio_channel:
265 int channel = libvlc_audio_get_channel(p_plugin->getVLC(), &ex);
266 if( libvlc_exception_raised(&ex) )
268 NPN_SetException(this, libvlc_exception_get_message(&ex));
269 libvlc_exception_clear(&ex);
270 return INVOKERESULT_GENERIC_ERROR;
272 INT32_TO_NPVARIANT(channel, result);
273 return INVOKERESULT_NO_ERROR;
279 return INVOKERESULT_GENERIC_ERROR;
282 RuntimeNPObject::InvokeResult LibvlcAudioNPObject::setProperty(int index, const NPVariant &value)
284 /* is plugin still running */
285 if( _instance->pdata )
287 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
288 libvlc_exception_t ex;
289 libvlc_exception_init(&ex);
294 if( NPVARIANT_IS_BOOLEAN(value) )
296 libvlc_audio_set_mute(p_plugin->getVLC(),
297 NPVARIANT_TO_BOOLEAN(value), &ex);
298 if( libvlc_exception_raised(&ex) )
300 NPN_SetException(this, libvlc_exception_get_message(&ex));
301 libvlc_exception_clear(&ex);
302 return INVOKERESULT_GENERIC_ERROR;
304 return INVOKERESULT_NO_ERROR;
306 return INVOKERESULT_INVALID_VALUE;
307 case ID_audio_volume:
308 if( isNumberValue(value) )
310 libvlc_audio_set_volume(p_plugin->getVLC(),
311 numberValue(value), &ex);
312 if( libvlc_exception_raised(&ex) )
314 NPN_SetException(this, libvlc_exception_get_message(&ex));
315 libvlc_exception_clear(&ex);
316 return INVOKERESULT_GENERIC_ERROR;
318 return INVOKERESULT_NO_ERROR;
320 return INVOKERESULT_INVALID_VALUE;
322 if( isNumberValue(value) )
324 libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_plugin->getVLC(), &ex);
325 if( libvlc_exception_raised(&ex) )
327 NPN_SetException(this, libvlc_exception_get_message(&ex));
328 libvlc_exception_clear(&ex);
329 return INVOKERESULT_GENERIC_ERROR;
331 libvlc_audio_set_track(p_md,
332 numberValue(value), &ex);
333 libvlc_media_player_release(p_md);
334 if( libvlc_exception_raised(&ex) )
336 NPN_SetException(this, libvlc_exception_get_message(&ex));
337 libvlc_exception_clear(&ex);
338 return INVOKERESULT_GENERIC_ERROR;
340 return INVOKERESULT_NO_ERROR;
342 return INVOKERESULT_INVALID_VALUE;
343 case ID_audio_channel:
344 if( isNumberValue(value) )
346 libvlc_audio_set_channel(p_plugin->getVLC(),
347 numberValue(value), &ex);
348 if( libvlc_exception_raised(&ex) )
350 NPN_SetException(this, libvlc_exception_get_message(&ex));
351 libvlc_exception_clear(&ex);
352 return INVOKERESULT_GENERIC_ERROR;
354 return INVOKERESULT_NO_ERROR;
356 return INVOKERESULT_INVALID_VALUE;
361 return INVOKERESULT_GENERIC_ERROR;
364 const NPUTF8 * const LibvlcAudioNPObject::methodNames[] =
369 const int LibvlcAudioNPObject::methodCount = sizeof(LibvlcAudioNPObject::methodNames)/sizeof(NPUTF8 *);
371 enum LibvlcAudioNPObjectMethodIds
376 RuntimeNPObject::InvokeResult LibvlcAudioNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)
378 /* is plugin still running */
379 if( _instance->pdata )
381 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
382 libvlc_exception_t ex;
383 libvlc_exception_init(&ex);
387 case ID_audio_togglemute:
390 libvlc_audio_toggle_mute(p_plugin->getVLC(), &ex);
391 if( libvlc_exception_raised(&ex) )
393 NPN_SetException(this, libvlc_exception_get_message(&ex));
394 libvlc_exception_clear(&ex);
395 return INVOKERESULT_GENERIC_ERROR;
399 VOID_TO_NPVARIANT(result);
400 return INVOKERESULT_NO_ERROR;
403 return INVOKERESULT_NO_SUCH_METHOD;
408 return INVOKERESULT_GENERIC_ERROR;
412 ** implementation of libvlc input object
415 const NPUTF8 * const LibvlcInputNPObject::propertyNames[] =
426 const int LibvlcInputNPObject::propertyCount = sizeof(LibvlcInputNPObject::propertyNames)/sizeof(NPUTF8 *);
428 enum LibvlcInputNPObjectPropertyIds
439 RuntimeNPObject::InvokeResult LibvlcInputNPObject::getProperty(int index, NPVariant &result)
441 /* is plugin still running */
442 if( _instance->pdata )
444 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
445 libvlc_exception_t ex;
446 libvlc_exception_init(&ex);
448 libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_plugin->getVLC(), &ex);
449 if( libvlc_exception_raised(&ex) )
451 if( index != ID_input_state )
453 NPN_SetException(this, libvlc_exception_get_message(&ex));
454 libvlc_exception_clear(&ex);
455 return INVOKERESULT_GENERIC_ERROR;
459 /* for input state, return CLOSED rather than an exception */
460 INT32_TO_NPVARIANT(0, result);
461 return INVOKERESULT_NO_ERROR;
467 case ID_input_length:
469 double val = (double)libvlc_media_player_get_length(p_md, &ex);
470 libvlc_media_player_release(p_md);
471 if( libvlc_exception_raised(&ex) )
473 NPN_SetException(this, libvlc_exception_get_message(&ex));
474 libvlc_exception_clear(&ex);
475 return INVOKERESULT_GENERIC_ERROR;
477 DOUBLE_TO_NPVARIANT(val, result);
478 return INVOKERESULT_NO_ERROR;
480 case ID_input_position:
482 double val = libvlc_media_player_get_position(p_md, &ex);
483 libvlc_media_player_release(p_md);
484 if( libvlc_exception_raised(&ex) )
486 NPN_SetException(this, libvlc_exception_get_message(&ex));
487 libvlc_exception_clear(&ex);
488 return INVOKERESULT_GENERIC_ERROR;
490 DOUBLE_TO_NPVARIANT(val, result);
491 return INVOKERESULT_NO_ERROR;
495 double val = (double)libvlc_media_player_get_time(p_md, &ex);
496 libvlc_media_player_release(p_md);
497 if( libvlc_exception_raised(&ex) )
499 NPN_SetException(this, libvlc_exception_get_message(&ex));
500 libvlc_exception_clear(&ex);
501 return INVOKERESULT_GENERIC_ERROR;
503 DOUBLE_TO_NPVARIANT(val, result);
504 return INVOKERESULT_NO_ERROR;
508 int val = libvlc_media_player_get_state(p_md, &ex);
509 libvlc_media_player_release(p_md);
510 if( libvlc_exception_raised(&ex) )
512 NPN_SetException(this, libvlc_exception_get_message(&ex));
513 libvlc_exception_clear(&ex);
514 return INVOKERESULT_GENERIC_ERROR;
516 INT32_TO_NPVARIANT(val, result);
517 return INVOKERESULT_NO_ERROR;
521 float val = libvlc_media_player_get_rate(p_md, &ex);
522 libvlc_media_player_release(p_md);
523 if( libvlc_exception_raised(&ex) )
525 NPN_SetException(this, libvlc_exception_get_message(&ex));
526 libvlc_exception_clear(&ex);
527 return INVOKERESULT_GENERIC_ERROR;
529 DOUBLE_TO_NPVARIANT(val, result);
530 return INVOKERESULT_NO_ERROR;
534 double val = libvlc_media_player_get_fps(p_md, &ex);
535 libvlc_media_player_release(p_md);
536 if( libvlc_exception_raised(&ex) )
538 NPN_SetException(this, libvlc_exception_get_message(&ex));
539 libvlc_exception_clear(&ex);
540 return INVOKERESULT_GENERIC_ERROR;
542 DOUBLE_TO_NPVARIANT(val, result);
543 return INVOKERESULT_NO_ERROR;
545 case ID_input_hasvout:
547 bool val = libvlc_media_player_has_vout(p_md, &ex);
548 libvlc_media_player_release(p_md);
549 if( libvlc_exception_raised(&ex) )
551 NPN_SetException(this, libvlc_exception_get_message(&ex));
552 libvlc_exception_clear(&ex);
553 return INVOKERESULT_GENERIC_ERROR;
555 BOOLEAN_TO_NPVARIANT(val, result);
556 return INVOKERESULT_NO_ERROR;
561 libvlc_media_player_release(p_md);
563 return INVOKERESULT_GENERIC_ERROR;
566 RuntimeNPObject::InvokeResult LibvlcInputNPObject::setProperty(int index, const NPVariant &value)
568 /* is plugin still running */
569 if( _instance->pdata )
571 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
572 libvlc_exception_t ex;
573 libvlc_exception_init(&ex);
575 libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_plugin->getVLC(), &ex);
576 if( libvlc_exception_raised(&ex) )
578 NPN_SetException(this, libvlc_exception_get_message(&ex));
579 libvlc_exception_clear(&ex);
580 return INVOKERESULT_GENERIC_ERROR;
585 case ID_input_position:
587 if( ! NPVARIANT_IS_DOUBLE(value) )
589 libvlc_media_player_release(p_md);
590 return INVOKERESULT_INVALID_VALUE;
593 float val = (float)NPVARIANT_TO_DOUBLE(value);
594 libvlc_media_player_set_position(p_md, val, &ex);
595 libvlc_media_player_release(p_md);
596 if( libvlc_exception_raised(&ex) )
598 NPN_SetException(this, libvlc_exception_get_message(&ex));
599 libvlc_exception_clear(&ex);
600 return INVOKERESULT_GENERIC_ERROR;
602 return INVOKERESULT_NO_ERROR;
607 if( NPVARIANT_IS_INT32(value) )
608 val = (vlc_int64_t)NPVARIANT_TO_INT32(value);
609 else if( NPVARIANT_IS_DOUBLE(value) )
610 val = (vlc_int64_t)NPVARIANT_TO_DOUBLE(value);
613 libvlc_media_player_release(p_md);
614 return INVOKERESULT_INVALID_VALUE;
617 libvlc_media_player_set_time(p_md, val, &ex);
618 libvlc_media_player_release(p_md);
619 if( libvlc_exception_raised(&ex) )
621 NPN_SetException(this, libvlc_exception_get_message(&ex));
622 libvlc_exception_clear(&ex);
623 return INVOKERESULT_GENERIC_ERROR;
625 return INVOKERESULT_NO_ERROR;
630 if( NPVARIANT_IS_INT32(value) )
631 val = (float)NPVARIANT_TO_INT32(value);
632 else if( NPVARIANT_IS_DOUBLE(value) )
633 val = (float)NPVARIANT_TO_DOUBLE(value);
636 libvlc_media_player_release(p_md);
637 return INVOKERESULT_INVALID_VALUE;
640 libvlc_media_player_set_rate(p_md, val, &ex);
641 libvlc_media_player_release(p_md);
642 if( libvlc_exception_raised(&ex) )
644 NPN_SetException(this, libvlc_exception_get_message(&ex));
645 libvlc_exception_clear(&ex);
646 return INVOKERESULT_GENERIC_ERROR;
648 return INVOKERESULT_NO_ERROR;
653 libvlc_media_player_release(p_md);
655 return INVOKERESULT_GENERIC_ERROR;
658 const NPUTF8 * const LibvlcInputNPObject::methodNames[] =
663 const int LibvlcInputNPObject::methodCount = sizeof(LibvlcInputNPObject::methodNames)/sizeof(NPUTF8 *);
666 ** implementation of libvlc message object
669 const NPUTF8 * const LibvlcMessageNPObject::propertyNames[] =
678 const int LibvlcMessageNPObject::propertyCount = sizeof(LibvlcMessageNPObject::propertyNames)/sizeof(NPUTF8 *);
680 enum LibvlcMessageNPObjectPropertyIds
689 RuntimeNPObject::InvokeResult LibvlcMessageNPObject::getProperty(int index, NPVariant &result)
691 /* is plugin still running */
692 if( _instance->pdata )
696 case ID_message_severity:
698 INT32_TO_NPVARIANT(_msg.i_severity, result);
699 return INVOKERESULT_NO_ERROR;
701 case ID_message_type:
705 int len = strlen(_msg.psz_type);
706 NPUTF8* retval = (NPUTF8*)NPN_MemAlloc(len);
709 memcpy(retval, _msg.psz_type, len);
710 STRINGN_TO_NPVARIANT(retval, len, result);
715 NULL_TO_NPVARIANT(result);
717 return INVOKERESULT_NO_ERROR;
719 case ID_message_name:
723 int len = strlen(_msg.psz_name);
724 NPUTF8* retval = (NPUTF8*)NPN_MemAlloc(len);
727 memcpy(retval, _msg.psz_name, len);
728 STRINGN_TO_NPVARIANT(retval, len, result);
733 NULL_TO_NPVARIANT(result);
735 return INVOKERESULT_NO_ERROR;
737 case ID_message_header:
739 if( _msg.psz_header )
741 int len = strlen(_msg.psz_header);
742 NPUTF8* retval = (NPUTF8*)NPN_MemAlloc(len);
745 memcpy(retval, _msg.psz_header, len);
746 STRINGN_TO_NPVARIANT(retval, len, result);
751 NULL_TO_NPVARIANT(result);
753 return INVOKERESULT_NO_ERROR;
755 case ID_message_message:
757 if( _msg.psz_message )
759 int len = strlen(_msg.psz_message);
760 NPUTF8* retval = (NPUTF8*)NPN_MemAlloc(len);
763 memcpy(retval, _msg.psz_message, len);
764 STRINGN_TO_NPVARIANT(retval, len, result);
769 NULL_TO_NPVARIANT(result);
771 return INVOKERESULT_NO_ERROR;
777 return INVOKERESULT_GENERIC_ERROR;
780 const NPUTF8 * const LibvlcMessageNPObject::methodNames[] =
785 const int LibvlcMessageNPObject::methodCount = sizeof(LibvlcMessageNPObject::methodNames)/sizeof(NPUTF8 *);
788 ** implementation of libvlc message iterator object
791 LibvlcMessageIteratorNPObject::LibvlcMessageIteratorNPObject(NPP instance, const NPClass *aClass) :
792 RuntimeNPObject(instance, aClass),
795 /* is plugin still running */
796 if( instance->pdata )
798 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(instance->pdata);
799 libvlc_log_t *p_log = p_plugin->getLog();
802 _p_iter = libvlc_log_get_iterator(p_log, NULL);
807 LibvlcMessageIteratorNPObject::~LibvlcMessageIteratorNPObject()
810 libvlc_log_iterator_free(_p_iter, NULL);
813 const NPUTF8 * const LibvlcMessageIteratorNPObject::propertyNames[] =
818 const int LibvlcMessageIteratorNPObject::propertyCount = sizeof(LibvlcMessageIteratorNPObject::propertyNames)/sizeof(NPUTF8 *);
820 enum LibvlcMessageIteratorNPObjectPropertyIds
822 ID_messageiterator_hasNext,
825 RuntimeNPObject::InvokeResult LibvlcMessageIteratorNPObject::getProperty(int index, NPVariant &result)
827 /* is plugin still running */
828 if( _instance->pdata )
830 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
833 case ID_messageiterator_hasNext:
835 if( _p_iter && p_plugin->getLog() )
837 libvlc_exception_t ex;
838 libvlc_exception_init(&ex);
840 BOOLEAN_TO_NPVARIANT(libvlc_log_iterator_has_next(_p_iter, &ex), result);
841 if( libvlc_exception_raised(&ex) )
843 NPN_SetException(this, libvlc_exception_get_message(&ex));
844 libvlc_exception_clear(&ex);
845 return INVOKERESULT_GENERIC_ERROR;
850 BOOLEAN_TO_NPVARIANT(0, result);
852 return INVOKERESULT_NO_ERROR;
858 return INVOKERESULT_GENERIC_ERROR;
861 const NPUTF8 * const LibvlcMessageIteratorNPObject::methodNames[] =
866 const int LibvlcMessageIteratorNPObject::methodCount = sizeof(LibvlcMessageIteratorNPObject::methodNames)/sizeof(NPUTF8 *);
868 enum LibvlcMessageIteratorNPObjectMethodIds
870 ID_messageiterator_next,
873 RuntimeNPObject::InvokeResult LibvlcMessageIteratorNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)
875 /* is plugin still running */
876 if( _instance->pdata )
878 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
879 libvlc_exception_t ex;
880 libvlc_exception_init(&ex);
884 case ID_messageiterator_next:
887 if( _p_iter && p_plugin->getLog() )
889 struct libvlc_log_message_t buffer;
891 buffer.sizeof_msg = sizeof(buffer);
893 libvlc_log_iterator_next(_p_iter, &buffer, &ex);
894 if( libvlc_exception_raised(&ex) )
896 NPN_SetException(this, libvlc_exception_get_message(&ex));
897 libvlc_exception_clear(&ex);
898 return INVOKERESULT_GENERIC_ERROR;
902 LibvlcMessageNPObject* message =
903 static_cast<LibvlcMessageNPObject*>(NPN_CreateObject(_instance, RuntimeNPClass<LibvlcMessageNPObject>::getClass()));
906 message->setMessage(buffer);
907 OBJECT_TO_NPVARIANT(message, result);
908 return INVOKERESULT_NO_ERROR;
910 return INVOKERESULT_OUT_OF_MEMORY;
913 return INVOKERESULT_GENERIC_ERROR;
915 return INVOKERESULT_NO_SUCH_METHOD;
920 return INVOKERESULT_GENERIC_ERROR;
924 ** implementation of libvlc message object
927 const NPUTF8 * const LibvlcMessagesNPObject::propertyNames[] =
932 const int LibvlcMessagesNPObject::propertyCount = sizeof(LibvlcMessagesNPObject::propertyNames)/sizeof(NPUTF8 *);
934 enum LibvlcMessagesNPObjectPropertyIds
939 RuntimeNPObject::InvokeResult LibvlcMessagesNPObject::getProperty(int index, NPVariant &result)
941 /* is plugin still running */
942 if( _instance->pdata )
944 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
947 case ID_messages_count:
949 libvlc_log_t *p_log = p_plugin->getLog();
952 libvlc_exception_t ex;
953 libvlc_exception_init(&ex);
955 INT32_TO_NPVARIANT(libvlc_log_count(p_log, &ex), result);
956 if( libvlc_exception_raised(&ex) )
958 NPN_SetException(this, libvlc_exception_get_message(&ex));
959 libvlc_exception_clear(&ex);
960 return INVOKERESULT_GENERIC_ERROR;
965 INT32_TO_NPVARIANT(0, result);
967 return INVOKERESULT_NO_ERROR;
973 return INVOKERESULT_GENERIC_ERROR;
976 const NPUTF8 * const LibvlcMessagesNPObject::methodNames[] =
982 const int LibvlcMessagesNPObject::methodCount = sizeof(LibvlcMessagesNPObject::methodNames)/sizeof(NPUTF8 *);
984 enum LibvlcMessagesNPObjectMethodIds
987 ID_messages_iterator,
990 RuntimeNPObject::InvokeResult LibvlcMessagesNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)
992 /* is plugin still running */
993 if( _instance->pdata )
995 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
996 libvlc_exception_t ex;
997 libvlc_exception_init(&ex);
1001 case ID_messages_clear:
1004 libvlc_log_t *p_log = p_plugin->getLog();
1007 libvlc_log_clear(p_log, &ex);
1008 if( libvlc_exception_raised(&ex) )
1010 NPN_SetException(this, libvlc_exception_get_message(&ex));
1011 libvlc_exception_clear(&ex);
1012 return INVOKERESULT_GENERIC_ERROR;
1015 return INVOKERESULT_NO_ERROR;
1017 return INVOKERESULT_NO_SUCH_METHOD;
1019 case ID_messages_iterator:
1022 LibvlcMessageIteratorNPObject* iter =
1023 static_cast<LibvlcMessageIteratorNPObject*>(NPN_CreateObject(_instance, RuntimeNPClass<LibvlcMessageIteratorNPObject>::getClass()));
1026 OBJECT_TO_NPVARIANT(iter, result);
1027 return INVOKERESULT_NO_ERROR;
1029 return INVOKERESULT_OUT_OF_MEMORY;
1031 return INVOKERESULT_NO_SUCH_METHOD;
1037 return INVOKERESULT_GENERIC_ERROR;
1042 ** implementation of libvlc message object
1046 LibvlcLogNPObject::~LibvlcLogNPObject()
1050 if( messagesObj ) NPN_ReleaseObject(messagesObj);
1054 const NPUTF8 * const LibvlcLogNPObject::propertyNames[] =
1060 const int LibvlcLogNPObject::propertyCount = sizeof(LibvlcLogNPObject::propertyNames)/sizeof(NPUTF8 *);
1062 enum LibvlcLogNPObjectPropertyIds
1068 RuntimeNPObject::InvokeResult LibvlcLogNPObject::getProperty(int index, NPVariant &result)
1070 /* is plugin still running */
1071 if( _instance->pdata )
1073 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
1074 libvlc_exception_t ex;
1075 libvlc_exception_init(&ex);
1079 case ID_log_messages:
1081 // create child object in lazyman fashion to avoid ownership problem with firefox
1083 messagesObj = NPN_CreateObject(_instance, RuntimeNPClass<LibvlcMessagesNPObject>::getClass());
1084 OBJECT_TO_NPVARIANT(NPN_RetainObject(messagesObj), result);
1085 return INVOKERESULT_NO_ERROR;
1087 case ID_log_verbosity:
1089 if( p_plugin->getLog() )
1091 INT32_TO_NPVARIANT(libvlc_get_log_verbosity(p_plugin->getVLC(),
1093 if( libvlc_exception_raised(&ex) )
1095 NPN_SetException(this, libvlc_exception_get_message(&ex));
1096 libvlc_exception_clear(&ex);
1097 return INVOKERESULT_GENERIC_ERROR;
1102 /* log is not enabled, return -1 */
1103 DOUBLE_TO_NPVARIANT(-1.0, result);
1105 return INVOKERESULT_NO_ERROR;
1111 return INVOKERESULT_GENERIC_ERROR;
1114 RuntimeNPObject::InvokeResult LibvlcLogNPObject::setProperty(int index, const NPVariant &value)
1116 /* is plugin still running */
1117 if( _instance->pdata )
1119 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
1120 libvlc_exception_t ex;
1121 libvlc_exception_init(&ex);
1125 case ID_log_verbosity:
1126 if( isNumberValue(value) )
1128 libvlc_instance_t* p_libvlc = p_plugin->getVLC();
1129 libvlc_log_t *p_log = p_plugin->getLog();
1130 int verbosity = numberValue(value);
1131 if( verbosity >= 0 )
1135 p_log = libvlc_log_open(p_libvlc, &ex);
1136 if( libvlc_exception_raised(&ex) )
1138 NPN_SetException(this, libvlc_exception_get_message(&ex));
1139 libvlc_exception_clear(&ex);
1140 return INVOKERESULT_GENERIC_ERROR;
1142 p_plugin->setLog(p_log);
1144 libvlc_set_log_verbosity(p_libvlc, (unsigned)verbosity, &ex);
1145 if( libvlc_exception_raised(&ex) )
1147 NPN_SetException(this, libvlc_exception_get_message(&ex));
1148 libvlc_exception_clear(&ex);
1149 return INVOKERESULT_GENERIC_ERROR;
1154 /* close log when verbosity is set to -1 */
1155 p_plugin->setLog(NULL);
1156 libvlc_log_close(p_log, &ex);
1157 if( libvlc_exception_raised(&ex) )
1159 NPN_SetException(this, libvlc_exception_get_message(&ex));
1160 libvlc_exception_clear(&ex);
1161 return INVOKERESULT_GENERIC_ERROR;
1164 return INVOKERESULT_NO_ERROR;
1166 return INVOKERESULT_INVALID_VALUE;
1171 return INVOKERESULT_GENERIC_ERROR;
1174 const NPUTF8 * const LibvlcLogNPObject::methodNames[] =
1179 const int LibvlcLogNPObject::methodCount = sizeof(LibvlcLogNPObject::methodNames)/sizeof(NPUTF8 *);
1182 ** implementation of libvlc playlist items object
1185 const NPUTF8 * const LibvlcPlaylistItemsNPObject::propertyNames[] =
1190 const int LibvlcPlaylistItemsNPObject::propertyCount = sizeof(LibvlcPlaylistItemsNPObject::propertyNames)/sizeof(NPUTF8 *);
1192 enum LibvlcPlaylistItemsNPObjectPropertyIds
1194 ID_playlistitems_count,
1197 RuntimeNPObject::InvokeResult LibvlcPlaylistItemsNPObject::getProperty(int index, NPVariant &result)
1199 /* is plugin still running */
1200 if( _instance->pdata )
1202 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
1203 libvlc_exception_t ex;
1204 libvlc_exception_init(&ex);
1208 case ID_playlistitems_count:
1210 int val = libvlc_playlist_items_count(p_plugin->getVLC(), &ex);
1211 if( libvlc_exception_raised(&ex) )
1213 NPN_SetException(this, libvlc_exception_get_message(&ex));
1214 libvlc_exception_clear(&ex);
1215 return INVOKERESULT_GENERIC_ERROR;
1217 INT32_TO_NPVARIANT(val, result);
1218 return INVOKERESULT_NO_ERROR;
1224 return INVOKERESULT_GENERIC_ERROR;
1227 const NPUTF8 * const LibvlcPlaylistItemsNPObject::methodNames[] =
1233 const int LibvlcPlaylistItemsNPObject::methodCount = sizeof(LibvlcPlaylistItemsNPObject::methodNames)/sizeof(NPUTF8 *);
1235 enum LibvlcPlaylistItemsNPObjectMethodIds
1237 ID_playlistitems_clear,
1238 ID_playlistitems_remove,
1241 RuntimeNPObject::InvokeResult LibvlcPlaylistItemsNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)
1243 /* is plugin still running */
1244 if( _instance->pdata )
1246 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
1247 libvlc_exception_t ex;
1248 libvlc_exception_init(&ex);
1252 case ID_playlistitems_clear:
1255 libvlc_playlist_clear(p_plugin->getVLC(), &ex);
1256 if( libvlc_exception_raised(&ex) )
1258 NPN_SetException(this, libvlc_exception_get_message(&ex));
1259 libvlc_exception_clear(&ex);
1260 return INVOKERESULT_GENERIC_ERROR;
1264 VOID_TO_NPVARIANT(result);
1265 return INVOKERESULT_NO_ERROR;
1268 return INVOKERESULT_NO_SUCH_METHOD;
1269 case ID_playlistitems_remove:
1270 if( (argCount == 1) && isNumberValue(args[0]) )
1272 libvlc_playlist_delete_item(p_plugin->getVLC(), numberValue(args[0]), &ex);
1273 if( libvlc_exception_raised(&ex) )
1275 NPN_SetException(this, libvlc_exception_get_message(&ex));
1276 libvlc_exception_clear(&ex);
1277 return INVOKERESULT_GENERIC_ERROR;
1281 VOID_TO_NPVARIANT(result);
1282 return INVOKERESULT_NO_ERROR;
1285 return INVOKERESULT_NO_SUCH_METHOD;
1290 return INVOKERESULT_GENERIC_ERROR;
1294 ** implementation of libvlc playlist object
1298 LibvlcPlaylistNPObject::~LibvlcPlaylistNPObject()
1302 if( playlistItemsObj ) NPN_ReleaseObject(playlistItemsObj);
1306 const NPUTF8 * const LibvlcPlaylistNPObject::propertyNames[] =
1308 "itemCount", /* deprecated */
1313 const int LibvlcPlaylistNPObject::propertyCount = sizeof(LibvlcPlaylistNPObject::propertyNames)/sizeof(NPUTF8 *);
1315 enum LibvlcPlaylistNPObjectPropertyIds
1317 ID_playlist_itemcount,
1318 ID_playlist_isplaying,
1322 RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::getProperty(int index, NPVariant &result)
1324 /* is plugin still running */
1325 if( _instance->pdata )
1327 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
1328 libvlc_exception_t ex;
1329 libvlc_exception_init(&ex);
1333 case ID_playlist_itemcount: /* deprecated */
1335 int val = libvlc_playlist_items_count(p_plugin->getVLC(), &ex);
1336 if( libvlc_exception_raised(&ex) )
1338 NPN_SetException(this, libvlc_exception_get_message(&ex));
1339 libvlc_exception_clear(&ex);
1340 return INVOKERESULT_GENERIC_ERROR;
1342 INT32_TO_NPVARIANT(val, result);
1343 return INVOKERESULT_NO_ERROR;
1345 case ID_playlist_isplaying:
1347 int val = libvlc_playlist_isplaying(p_plugin->getVLC(), &ex);
1348 if( libvlc_exception_raised(&ex) )
1350 NPN_SetException(this, libvlc_exception_get_message(&ex));
1351 libvlc_exception_clear(&ex);
1352 return INVOKERESULT_GENERIC_ERROR;
1354 BOOLEAN_TO_NPVARIANT(val, result);
1355 return INVOKERESULT_NO_ERROR;
1357 case ID_playlist_items:
1359 // create child object in lazyman fashion to avoid ownership problem with firefox
1360 if( ! playlistItemsObj )
1361 playlistItemsObj = NPN_CreateObject(_instance, RuntimeNPClass<LibvlcPlaylistItemsNPObject>::getClass());
1362 OBJECT_TO_NPVARIANT(NPN_RetainObject(playlistItemsObj), result);
1363 return INVOKERESULT_NO_ERROR;
1369 return INVOKERESULT_GENERIC_ERROR;
1372 const NPUTF8 * const LibvlcPlaylistNPObject::methodNames[] =
1381 "clear", /* deprecated */
1382 "removeItem", /* deprecated */
1385 const int LibvlcPlaylistNPObject::methodCount = sizeof(LibvlcPlaylistNPObject::methodNames)/sizeof(NPUTF8 *);
1387 enum LibvlcPlaylistNPObjectMethodIds
1391 ID_playlist_playItem,
1392 ID_playlist_togglepause,
1397 ID_playlist_removeitem
1400 RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)
1402 /* is plugin still running */
1403 if( _instance->pdata )
1405 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
1406 libvlc_exception_t ex;
1407 libvlc_exception_init(&ex);
1411 case ID_playlist_add:
1413 if( (argCount < 1) || (argCount > 3) )
1414 return INVOKERESULT_NO_SUCH_METHOD;
1419 if( NPVARIANT_IS_STRING(args[0]) )
1421 char *s = stringValue(NPVARIANT_TO_STRING(args[0]));
1424 url = p_plugin->getAbsoluteURL(s);
1428 // problem with combining url, use argument
1432 return INVOKERESULT_OUT_OF_MEMORY;
1435 return INVOKERESULT_NO_SUCH_METHOD;
1439 // grab name if available
1442 if( NPVARIANT_IS_NULL(args[1]) )
1446 else if( NPVARIANT_IS_STRING(args[1]) )
1448 name = stringValue(NPVARIANT_TO_STRING(args[1]));
1453 return INVOKERESULT_INVALID_VALUE;
1458 char** ppsz_options = NULL;
1460 // grab options if available
1463 if( NPVARIANT_IS_NULL(args[2]) )
1467 else if( NPVARIANT_IS_STRING(args[2]) )
1469 parseOptions(NPVARIANT_TO_STRING(args[2]), &i_options, &ppsz_options);
1472 else if( NPVARIANT_IS_OBJECT(args[2]) )
1474 parseOptions(NPVARIANT_TO_OBJECT(args[2]), &i_options, &ppsz_options);
1480 return INVOKERESULT_INVALID_VALUE;
1484 int item = libvlc_playlist_add_extended(p_plugin->getVLC(),
1488 const_cast<const char **>(ppsz_options),
1492 for( int i=0; i< i_options; ++i )
1494 delete ppsz_options[i];
1496 delete ppsz_options;
1498 if( libvlc_exception_raised(&ex) )
1500 NPN_SetException(this, libvlc_exception_get_message(&ex));
1501 libvlc_exception_clear(&ex);
1502 return INVOKERESULT_GENERIC_ERROR;
1506 INT32_TO_NPVARIANT(item, result);
1507 return INVOKERESULT_NO_ERROR;
1510 case ID_playlist_play:
1513 libvlc_playlist_play(p_plugin->getVLC(), -1, 0, NULL, &ex);
1514 if( libvlc_exception_raised(&ex) )
1516 NPN_SetException(this, libvlc_exception_get_message(&ex));
1517 libvlc_exception_clear(&ex);
1518 return INVOKERESULT_GENERIC_ERROR;
1522 VOID_TO_NPVARIANT(result);
1523 return INVOKERESULT_NO_ERROR;
1526 return INVOKERESULT_NO_SUCH_METHOD;
1527 case ID_playlist_playItem:
1528 if( (argCount == 1) && isNumberValue(args[0]) )
1530 libvlc_playlist_play(p_plugin->getVLC(), numberValue(args[0]), 0, NULL, &ex);
1531 if( libvlc_exception_raised(&ex) )
1533 NPN_SetException(this, libvlc_exception_get_message(&ex));
1534 libvlc_exception_clear(&ex);
1535 return INVOKERESULT_GENERIC_ERROR;
1539 VOID_TO_NPVARIANT(result);
1540 return INVOKERESULT_NO_ERROR;
1543 return INVOKERESULT_NO_SUCH_METHOD;
1544 case ID_playlist_togglepause:
1547 libvlc_playlist_pause(p_plugin->getVLC(), &ex);
1548 if( libvlc_exception_raised(&ex) )
1550 NPN_SetException(this, libvlc_exception_get_message(&ex));
1551 libvlc_exception_clear(&ex);
1552 return INVOKERESULT_GENERIC_ERROR;
1556 VOID_TO_NPVARIANT(result);
1557 return INVOKERESULT_NO_ERROR;
1560 return INVOKERESULT_NO_SUCH_METHOD;
1561 case ID_playlist_stop:
1564 libvlc_playlist_stop(p_plugin->getVLC(), &ex);
1565 if( libvlc_exception_raised(&ex) )
1567 NPN_SetException(this, libvlc_exception_get_message(&ex));
1568 libvlc_exception_clear(&ex);
1569 return INVOKERESULT_GENERIC_ERROR;
1573 VOID_TO_NPVARIANT(result);
1574 return INVOKERESULT_NO_ERROR;
1577 return INVOKERESULT_NO_SUCH_METHOD;
1578 case ID_playlist_next:
1581 libvlc_playlist_next(p_plugin->getVLC(), &ex);
1582 if( libvlc_exception_raised(&ex) )
1584 NPN_SetException(this, libvlc_exception_get_message(&ex));
1585 libvlc_exception_clear(&ex);
1586 return INVOKERESULT_GENERIC_ERROR;
1590 VOID_TO_NPVARIANT(result);
1591 return INVOKERESULT_NO_ERROR;
1594 return INVOKERESULT_NO_SUCH_METHOD;
1595 case ID_playlist_prev:
1598 libvlc_playlist_prev(p_plugin->getVLC(), &ex);
1599 if( libvlc_exception_raised(&ex) )
1601 NPN_SetException(this, libvlc_exception_get_message(&ex));
1602 libvlc_exception_clear(&ex);
1603 return INVOKERESULT_GENERIC_ERROR;
1607 VOID_TO_NPVARIANT(result);
1608 return INVOKERESULT_NO_ERROR;
1611 return INVOKERESULT_NO_SUCH_METHOD;
1612 case ID_playlist_clear: /* deprecated */
1615 libvlc_playlist_clear(p_plugin->getVLC(), &ex);
1616 if( libvlc_exception_raised(&ex) )
1618 NPN_SetException(this, libvlc_exception_get_message(&ex));
1619 libvlc_exception_clear(&ex);
1620 return INVOKERESULT_GENERIC_ERROR;
1624 VOID_TO_NPVARIANT(result);
1625 return INVOKERESULT_NO_ERROR;
1628 return INVOKERESULT_NO_SUCH_METHOD;
1629 case ID_playlist_removeitem: /* deprecated */
1630 if( (argCount == 1) && isNumberValue(args[0]) )
1632 libvlc_playlist_delete_item(p_plugin->getVLC(), numberValue(args[0]), &ex);
1633 if( libvlc_exception_raised(&ex) )
1635 NPN_SetException(this, libvlc_exception_get_message(&ex));
1636 libvlc_exception_clear(&ex);
1637 return INVOKERESULT_GENERIC_ERROR;
1641 VOID_TO_NPVARIANT(result);
1642 return INVOKERESULT_NO_ERROR;
1645 return INVOKERESULT_NO_SUCH_METHOD;
1650 return INVOKERESULT_GENERIC_ERROR;
1653 void LibvlcPlaylistNPObject::parseOptions(const NPString &nps, int *i_options, char*** ppsz_options)
1655 if( nps.utf8length )
1657 char *s = stringValue(nps);
1662 char **options = (char **)malloc(capacity*sizeof(char *));
1667 char *end = val + nps.utf8length;
1670 // skip leading blanks
1672 && ((*val == ' ' ) || (*val == '\t')) )
1676 // skip till we get a blank character
1682 if( ('\'' == c) || ('"' == c) )
1684 // skip till end of string
1685 while( (val < end) && (*(val++) != c ) );
1691 if( nOptions == capacity )
1694 char **moreOptions = (char **)realloc(options, capacity*sizeof(char*));
1697 /* failed to allocate more memory */
1699 /* return what we got so far */
1700 *i_options = nOptions;
1701 *ppsz_options = options;
1704 options = moreOptions;
1707 options[nOptions++] = strdup(start);
1710 // must be end of string
1713 *i_options = nOptions;
1714 *ppsz_options = options;
1721 void LibvlcPlaylistNPObject::parseOptions(NPObject *obj, int *i_options, char*** ppsz_options)
1723 /* WARNING: Safari does not implement NPN_HasProperty/NPN_HasMethod */
1727 /* we are expecting to have a Javascript Array object */
1728 NPIdentifier propId = NPN_GetStringIdentifier("length");
1729 if( NPN_GetProperty(_instance, obj, propId, &value) )
1731 int count = numberValue(value);
1732 NPN_ReleaseVariantValue(&value);
1737 char **options = (char **)malloc(capacity*sizeof(char *));
1742 while( nOptions < count )
1744 propId = NPN_GetIntIdentifier(nOptions);
1745 if( ! NPN_GetProperty(_instance, obj, propId, &value) )
1746 /* return what we got so far */
1749 if( ! NPVARIANT_IS_STRING(value) )
1751 /* return what we got so far */
1752 NPN_ReleaseVariantValue(&value);
1756 if( nOptions == capacity )
1759 char **moreOptions = (char **)realloc(options, capacity*sizeof(char*));
1762 /* failed to allocate more memory */
1763 NPN_ReleaseVariantValue(&value);
1764 /* return what we got so far */
1765 *i_options = nOptions;
1766 *ppsz_options = options;
1769 options = moreOptions;
1772 options[nOptions++] = stringValue(value);
1774 *i_options = nOptions;
1775 *ppsz_options = options;
1782 ** implementation of libvlc video object
1785 const NPUTF8 * const LibvlcVideoNPObject::propertyNames[] =
1796 enum LibvlcVideoNPObjectPropertyIds
1798 ID_video_fullscreen,
1801 ID_video_aspectratio,
1807 const int LibvlcVideoNPObject::propertyCount = sizeof(LibvlcVideoNPObject::propertyNames)/sizeof(NPUTF8 *);
1809 RuntimeNPObject::InvokeResult LibvlcVideoNPObject::getProperty(int index, NPVariant &result)
1811 /* is plugin still running */
1812 if( _instance->pdata )
1814 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
1815 libvlc_exception_t ex;
1816 libvlc_exception_init(&ex);
1818 libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_plugin->getVLC(), &ex);
1819 if( libvlc_exception_raised(&ex) )
1821 NPN_SetException(this, libvlc_exception_get_message(&ex));
1822 libvlc_exception_clear(&ex);
1823 return INVOKERESULT_GENERIC_ERROR;
1828 case ID_video_fullscreen:
1830 int val = libvlc_get_fullscreen(p_md, &ex);
1831 libvlc_media_player_release(p_md);
1832 if( libvlc_exception_raised(&ex) )
1834 NPN_SetException(this, libvlc_exception_get_message(&ex));
1835 libvlc_exception_clear(&ex);
1836 return INVOKERESULT_GENERIC_ERROR;
1838 BOOLEAN_TO_NPVARIANT(val, result);
1839 return INVOKERESULT_NO_ERROR;
1841 case ID_video_height:
1843 int val = libvlc_video_get_height(p_md, &ex);
1844 libvlc_media_player_release(p_md);
1845 if( libvlc_exception_raised(&ex) )
1847 NPN_SetException(this, libvlc_exception_get_message(&ex));
1848 libvlc_exception_clear(&ex);
1849 return INVOKERESULT_GENERIC_ERROR;
1851 INT32_TO_NPVARIANT(val, result);
1852 return INVOKERESULT_NO_ERROR;
1854 case ID_video_width:
1856 int val = libvlc_video_get_width(p_md, &ex);
1857 libvlc_media_player_release(p_md);
1858 if( libvlc_exception_raised(&ex) )
1860 NPN_SetException(this, libvlc_exception_get_message(&ex));
1861 libvlc_exception_clear(&ex);
1862 return INVOKERESULT_GENERIC_ERROR;
1864 INT32_TO_NPVARIANT(val, result);
1865 return INVOKERESULT_NO_ERROR;
1867 case ID_video_aspectratio:
1869 NPUTF8 *psz_aspect = libvlc_video_get_aspect_ratio(p_md, &ex);
1870 libvlc_media_player_release(p_md);
1871 if( libvlc_exception_raised(&ex) )
1873 NPN_SetException(this, libvlc_exception_get_message(&ex));
1874 libvlc_exception_clear(&ex);
1875 return INVOKERESULT_GENERIC_ERROR;
1878 return INVOKERESULT_GENERIC_ERROR;
1880 STRINGZ_TO_NPVARIANT(psz_aspect, result);
1881 return INVOKERESULT_NO_ERROR;
1883 case ID_video_subtitle:
1885 int i_spu = libvlc_video_get_spu(p_md, &ex);
1886 libvlc_media_player_release(p_md);
1887 if( libvlc_exception_raised(&ex) )
1889 NPN_SetException(this, libvlc_exception_get_message(&ex));
1890 libvlc_exception_clear(&ex);
1891 return INVOKERESULT_GENERIC_ERROR;
1893 INT32_TO_NPVARIANT(i_spu, result);
1894 return INVOKERESULT_NO_ERROR;
1898 NPUTF8 *psz_geometry = libvlc_video_get_crop_geometry(p_md, &ex);
1899 libvlc_media_player_release(p_md);
1900 if( libvlc_exception_raised(&ex) )
1902 NPN_SetException(this, libvlc_exception_get_message(&ex));
1903 libvlc_exception_clear(&ex);
1904 return INVOKERESULT_GENERIC_ERROR;
1907 return INVOKERESULT_GENERIC_ERROR;
1909 STRINGZ_TO_NPVARIANT(psz_geometry, result);
1910 return INVOKERESULT_NO_ERROR;
1912 case ID_video_teletext:
1914 int i_page = libvlc_video_get_teletext(p_md, &ex);
1915 libvlc_media_player_release(p_md);
1916 if( libvlc_exception_raised(&ex) )
1918 NPN_SetException(this, libvlc_exception_get_message(&ex));
1919 libvlc_exception_clear(&ex);
1920 return INVOKERESULT_GENERIC_ERROR;
1922 INT32_TO_NPVARIANT(i_page, result);
1923 return INVOKERESULT_NO_ERROR;
1926 libvlc_media_player_release(p_md);
1928 return INVOKERESULT_GENERIC_ERROR;
1931 RuntimeNPObject::InvokeResult LibvlcVideoNPObject::setProperty(int index, const NPVariant &value)
1933 /* is plugin still running */
1934 if( _instance->pdata )
1936 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
1937 libvlc_exception_t ex;
1938 libvlc_exception_init(&ex);
1940 libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_plugin->getVLC(), &ex);
1941 if( libvlc_exception_raised(&ex) )
1943 NPN_SetException(this, libvlc_exception_get_message(&ex));
1944 libvlc_exception_clear(&ex);
1945 return INVOKERESULT_GENERIC_ERROR;
1950 case ID_video_fullscreen:
1952 if( ! NPVARIANT_IS_BOOLEAN(value) )
1954 libvlc_media_player_release(p_md);
1955 return INVOKERESULT_INVALID_VALUE;
1958 int val = NPVARIANT_TO_BOOLEAN(value);
1959 libvlc_set_fullscreen(p_md, val, &ex);
1960 libvlc_media_player_release(p_md);
1962 if( libvlc_exception_raised(&ex) )
1964 NPN_SetException(this, libvlc_exception_get_message(&ex));
1965 libvlc_exception_clear(&ex);
1966 return INVOKERESULT_GENERIC_ERROR;
1968 return INVOKERESULT_NO_ERROR;
1970 case ID_video_aspectratio:
1972 char *psz_aspect = NULL;
1974 if( ! NPVARIANT_IS_STRING(value) )
1976 libvlc_media_player_release(p_md);
1977 return INVOKERESULT_INVALID_VALUE;
1980 psz_aspect = stringValue(NPVARIANT_TO_STRING(value));
1983 libvlc_media_player_release(p_md);
1984 return INVOKERESULT_GENERIC_ERROR;
1987 libvlc_video_set_aspect_ratio(p_md, psz_aspect, &ex);
1989 libvlc_media_player_release(p_md);
1991 if( libvlc_exception_raised(&ex) )
1993 NPN_SetException(this, libvlc_exception_get_message(&ex));
1994 libvlc_exception_clear(&ex);
1995 return INVOKERESULT_GENERIC_ERROR;
1997 return INVOKERESULT_NO_ERROR;
1999 case ID_video_subtitle:
2001 if( isNumberValue(value) )
2003 libvlc_video_set_spu(p_md,
2004 numberValue(value), &ex);
2005 libvlc_media_player_release(p_md);
2006 if( libvlc_exception_raised(&ex) )
2008 NPN_SetException(this, libvlc_exception_get_message(&ex));
2009 libvlc_exception_clear(&ex);
2010 return INVOKERESULT_GENERIC_ERROR;
2012 return INVOKERESULT_NO_ERROR;
2014 libvlc_media_player_release(p_md);
2015 return INVOKERESULT_INVALID_VALUE;
2019 char *psz_geometry = NULL;
2021 if( ! NPVARIANT_IS_STRING(value) )
2023 libvlc_media_player_release(p_md);
2024 return INVOKERESULT_INVALID_VALUE;
2027 psz_geometry = stringValue(NPVARIANT_TO_STRING(value));
2030 libvlc_media_player_release(p_md);
2031 return INVOKERESULT_GENERIC_ERROR;
2034 libvlc_video_set_crop_geometry(p_md, psz_geometry, &ex);
2035 delete psz_geometry;
2036 libvlc_media_player_release(p_md);
2038 if( libvlc_exception_raised(&ex) )
2040 NPN_SetException(this, libvlc_exception_get_message(&ex));
2041 libvlc_exception_clear(&ex);
2042 return INVOKERESULT_GENERIC_ERROR;
2044 return INVOKERESULT_NO_ERROR;
2046 case ID_video_teletext:
2048 if( isNumberValue(value) )
2050 libvlc_video_set_teletext(p_md,
2051 numberValue(value), &ex);
2052 libvlc_media_player_release(p_md);
2053 if( libvlc_exception_raised(&ex) )
2055 NPN_SetException(this, libvlc_exception_get_message(&ex));
2056 libvlc_exception_clear(&ex);
2057 return INVOKERESULT_GENERIC_ERROR;
2059 return INVOKERESULT_NO_ERROR;
2061 libvlc_media_player_release(p_md);
2062 return INVOKERESULT_INVALID_VALUE;
2065 libvlc_media_player_release(p_md);
2067 return INVOKERESULT_GENERIC_ERROR;
2070 const NPUTF8 * const LibvlcVideoNPObject::methodNames[] =
2076 enum LibvlcVideoNPObjectMethodIds
2078 ID_video_togglefullscreen,
2079 ID_video_toggleteletext
2082 const int LibvlcVideoNPObject::methodCount = sizeof(LibvlcVideoNPObject::methodNames)/sizeof(NPUTF8 *);
2084 RuntimeNPObject::InvokeResult LibvlcVideoNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)
2086 /* is plugin still running */
2087 if( _instance->pdata )
2089 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
2090 libvlc_exception_t ex;
2091 libvlc_exception_init(&ex);
2093 libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_plugin->getVLC(), &ex);
2094 if( libvlc_exception_raised(&ex) )
2096 NPN_SetException(this, libvlc_exception_get_message(&ex));
2097 libvlc_exception_clear(&ex);
2098 return INVOKERESULT_GENERIC_ERROR;
2103 case ID_video_togglefullscreen:
2106 libvlc_toggle_fullscreen(p_md, &ex);
2107 libvlc_media_player_release(p_md);
2108 if( libvlc_exception_raised(&ex) )
2110 NPN_SetException(this, libvlc_exception_get_message(&ex));
2111 libvlc_exception_clear(&ex);
2112 return INVOKERESULT_GENERIC_ERROR;
2116 VOID_TO_NPVARIANT(result);
2117 return INVOKERESULT_NO_ERROR;
2122 /* cannot get md, probably not playing */
2123 if( libvlc_exception_raised(&ex) )
2125 NPN_SetException(this, libvlc_exception_get_message(&ex));
2126 libvlc_exception_clear(&ex);
2128 return INVOKERESULT_GENERIC_ERROR;
2130 return INVOKERESULT_NO_SUCH_METHOD;
2131 case ID_video_toggleteletext:
2134 libvlc_toggle_teletext(p_md, &ex);
2135 libvlc_media_player_release(p_md);
2136 if( libvlc_exception_raised(&ex) )
2138 NPN_SetException(this, libvlc_exception_get_message(&ex));
2139 libvlc_exception_clear(&ex);
2140 return INVOKERESULT_GENERIC_ERROR;
2144 VOID_TO_NPVARIANT(result);
2145 return INVOKERESULT_NO_ERROR;
2150 /* cannot get md, probably not playing */
2151 if( libvlc_exception_raised(&ex) )
2153 NPN_SetException(this, libvlc_exception_get_message(&ex));
2154 libvlc_exception_clear(&ex);
2156 return INVOKERESULT_GENERIC_ERROR;
2158 return INVOKERESULT_NO_SUCH_METHOD;
2160 return INVOKERESULT_NO_SUCH_METHOD;
2163 return INVOKERESULT_GENERIC_ERROR;