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(libvlc_get_version());
121 NPUTF8 *retval =(NPUTF8*)NPN_MemAlloc(len);
124 memcpy(retval, libvlc_get_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(libvlc_get_version());
166 NPUTF8 *retval =(NPUTF8*)NPN_MemAlloc(len);
169 memcpy(retval, libvlc_get_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 = (int64_t)NPVARIANT_TO_INT32(value);
609 else if( NPVARIANT_IS_DOUBLE(value) )
610 val = (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 libvlc_playlist_lock(p_plugin->getVLC());
1211 int val = libvlc_playlist_items_count(p_plugin->getVLC(), &ex);
1212 libvlc_playlist_unlock(p_plugin->getVLC());
1213 if( libvlc_exception_raised(&ex) )
1215 NPN_SetException(this, libvlc_exception_get_message(&ex));
1216 libvlc_exception_clear(&ex);
1217 return INVOKERESULT_GENERIC_ERROR;
1219 INT32_TO_NPVARIANT(val, result);
1220 return INVOKERESULT_NO_ERROR;
1226 return INVOKERESULT_GENERIC_ERROR;
1229 const NPUTF8 * const LibvlcPlaylistItemsNPObject::methodNames[] =
1235 const int LibvlcPlaylistItemsNPObject::methodCount = sizeof(LibvlcPlaylistItemsNPObject::methodNames)/sizeof(NPUTF8 *);
1237 enum LibvlcPlaylistItemsNPObjectMethodIds
1239 ID_playlistitems_clear,
1240 ID_playlistitems_remove,
1243 RuntimeNPObject::InvokeResult LibvlcPlaylistItemsNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)
1245 /* is plugin still running */
1246 if( _instance->pdata )
1248 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
1249 libvlc_exception_t ex;
1250 libvlc_exception_init(&ex);
1254 case ID_playlistitems_clear:
1257 libvlc_playlist_clear(p_plugin->getVLC(), &ex);
1258 if( libvlc_exception_raised(&ex) )
1260 NPN_SetException(this, libvlc_exception_get_message(&ex));
1261 libvlc_exception_clear(&ex);
1262 return INVOKERESULT_GENERIC_ERROR;
1266 VOID_TO_NPVARIANT(result);
1267 return INVOKERESULT_NO_ERROR;
1270 return INVOKERESULT_NO_SUCH_METHOD;
1271 case ID_playlistitems_remove:
1272 if( (argCount == 1) && isNumberValue(args[0]) )
1274 libvlc_playlist_delete_item(p_plugin->getVLC(), numberValue(args[0]), &ex);
1275 if( libvlc_exception_raised(&ex) )
1277 NPN_SetException(this, libvlc_exception_get_message(&ex));
1278 libvlc_exception_clear(&ex);
1279 return INVOKERESULT_GENERIC_ERROR;
1283 VOID_TO_NPVARIANT(result);
1284 return INVOKERESULT_NO_ERROR;
1287 return INVOKERESULT_NO_SUCH_METHOD;
1292 return INVOKERESULT_GENERIC_ERROR;
1296 ** implementation of libvlc playlist object
1300 LibvlcPlaylistNPObject::~LibvlcPlaylistNPObject()
1304 if( playlistItemsObj ) NPN_ReleaseObject(playlistItemsObj);
1308 const NPUTF8 * const LibvlcPlaylistNPObject::propertyNames[] =
1310 "itemCount", /* deprecated */
1315 const int LibvlcPlaylistNPObject::propertyCount = sizeof(LibvlcPlaylistNPObject::propertyNames)/sizeof(NPUTF8 *);
1317 enum LibvlcPlaylistNPObjectPropertyIds
1319 ID_playlist_itemcount,
1320 ID_playlist_isplaying,
1324 RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::getProperty(int index, NPVariant &result)
1326 /* is plugin still running */
1327 if( _instance->pdata )
1329 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
1330 libvlc_exception_t ex;
1331 libvlc_exception_init(&ex);
1335 case ID_playlist_itemcount: /* deprecated */
1337 libvlc_playlist_lock(p_plugin->getVLC());
1338 int val = libvlc_playlist_items_count(p_plugin->getVLC(), &ex);
1339 libvlc_playlist_unlock(p_plugin->getVLC());
1340 if( libvlc_exception_raised(&ex) )
1342 NPN_SetException(this, libvlc_exception_get_message(&ex));
1343 libvlc_exception_clear(&ex);
1344 return INVOKERESULT_GENERIC_ERROR;
1346 INT32_TO_NPVARIANT(val, result);
1347 return INVOKERESULT_NO_ERROR;
1349 case ID_playlist_isplaying:
1351 int val = libvlc_playlist_isplaying(p_plugin->getVLC(), &ex);
1352 if( libvlc_exception_raised(&ex) )
1354 NPN_SetException(this, libvlc_exception_get_message(&ex));
1355 libvlc_exception_clear(&ex);
1356 return INVOKERESULT_GENERIC_ERROR;
1358 BOOLEAN_TO_NPVARIANT(val, result);
1359 return INVOKERESULT_NO_ERROR;
1361 case ID_playlist_items:
1363 // create child object in lazyman fashion to avoid ownership problem with firefox
1364 if( ! playlistItemsObj )
1365 playlistItemsObj = NPN_CreateObject(_instance, RuntimeNPClass<LibvlcPlaylistItemsNPObject>::getClass());
1366 OBJECT_TO_NPVARIANT(NPN_RetainObject(playlistItemsObj), result);
1367 return INVOKERESULT_NO_ERROR;
1373 return INVOKERESULT_GENERIC_ERROR;
1376 const NPUTF8 * const LibvlcPlaylistNPObject::methodNames[] =
1385 "clear", /* deprecated */
1386 "removeItem", /* deprecated */
1389 const int LibvlcPlaylistNPObject::methodCount = sizeof(LibvlcPlaylistNPObject::methodNames)/sizeof(NPUTF8 *);
1391 enum LibvlcPlaylistNPObjectMethodIds
1395 ID_playlist_playItem,
1396 ID_playlist_togglepause,
1401 ID_playlist_removeitem
1404 RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)
1406 /* is plugin still running */
1407 if( _instance->pdata )
1409 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
1410 libvlc_exception_t ex;
1411 libvlc_exception_init(&ex);
1415 case ID_playlist_add:
1417 if( (argCount < 1) || (argCount > 3) )
1418 return INVOKERESULT_NO_SUCH_METHOD;
1423 if( NPVARIANT_IS_STRING(args[0]) )
1425 char *s = stringValue(NPVARIANT_TO_STRING(args[0]));
1428 url = p_plugin->getAbsoluteURL(s);
1432 // problem with combining url, use argument
1436 return INVOKERESULT_OUT_OF_MEMORY;
1439 return INVOKERESULT_NO_SUCH_METHOD;
1443 // grab name if available
1446 if( NPVARIANT_IS_NULL(args[1]) )
1450 else if( NPVARIANT_IS_STRING(args[1]) )
1452 name = stringValue(NPVARIANT_TO_STRING(args[1]));
1457 return INVOKERESULT_INVALID_VALUE;
1462 char** ppsz_options = NULL;
1464 // grab options if available
1467 if( NPVARIANT_IS_NULL(args[2]) )
1471 else if( NPVARIANT_IS_STRING(args[2]) )
1473 parseOptions(NPVARIANT_TO_STRING(args[2]), &i_options, &ppsz_options);
1476 else if( NPVARIANT_IS_OBJECT(args[2]) )
1478 parseOptions(NPVARIANT_TO_OBJECT(args[2]), &i_options, &ppsz_options);
1484 return INVOKERESULT_INVALID_VALUE;
1488 int item = libvlc_playlist_add_extended_untrusted(p_plugin->getVLC(),
1492 const_cast<const char **>(ppsz_options),
1496 for( int i=0; i< i_options; ++i )
1498 free(ppsz_options[i]);
1502 if( libvlc_exception_raised(&ex) )
1504 NPN_SetException(this, libvlc_exception_get_message(&ex));
1505 libvlc_exception_clear(&ex);
1506 return INVOKERESULT_GENERIC_ERROR;
1510 INT32_TO_NPVARIANT(item, result);
1511 return INVOKERESULT_NO_ERROR;
1514 case ID_playlist_play:
1517 libvlc_playlist_play(p_plugin->getVLC(), -1, 0, NULL, &ex);
1518 if( libvlc_exception_raised(&ex) )
1520 NPN_SetException(this, libvlc_exception_get_message(&ex));
1521 libvlc_exception_clear(&ex);
1522 return INVOKERESULT_GENERIC_ERROR;
1526 VOID_TO_NPVARIANT(result);
1527 return INVOKERESULT_NO_ERROR;
1530 return INVOKERESULT_NO_SUCH_METHOD;
1531 case ID_playlist_playItem:
1532 if( (argCount == 1) && isNumberValue(args[0]) )
1534 libvlc_playlist_play(p_plugin->getVLC(), numberValue(args[0]), 0, NULL, &ex);
1535 if( libvlc_exception_raised(&ex) )
1537 NPN_SetException(this, libvlc_exception_get_message(&ex));
1538 libvlc_exception_clear(&ex);
1539 return INVOKERESULT_GENERIC_ERROR;
1543 VOID_TO_NPVARIANT(result);
1544 return INVOKERESULT_NO_ERROR;
1547 return INVOKERESULT_NO_SUCH_METHOD;
1548 case ID_playlist_togglepause:
1551 libvlc_playlist_pause(p_plugin->getVLC(), &ex);
1552 if( libvlc_exception_raised(&ex) )
1554 NPN_SetException(this, libvlc_exception_get_message(&ex));
1555 libvlc_exception_clear(&ex);
1556 return INVOKERESULT_GENERIC_ERROR;
1560 VOID_TO_NPVARIANT(result);
1561 return INVOKERESULT_NO_ERROR;
1564 return INVOKERESULT_NO_SUCH_METHOD;
1565 case ID_playlist_stop:
1568 libvlc_playlist_stop(p_plugin->getVLC(), &ex);
1569 if( libvlc_exception_raised(&ex) )
1571 NPN_SetException(this, libvlc_exception_get_message(&ex));
1572 libvlc_exception_clear(&ex);
1573 return INVOKERESULT_GENERIC_ERROR;
1577 VOID_TO_NPVARIANT(result);
1578 return INVOKERESULT_NO_ERROR;
1581 return INVOKERESULT_NO_SUCH_METHOD;
1582 case ID_playlist_next:
1585 libvlc_playlist_next(p_plugin->getVLC(), &ex);
1586 if( libvlc_exception_raised(&ex) )
1588 NPN_SetException(this, libvlc_exception_get_message(&ex));
1589 libvlc_exception_clear(&ex);
1590 return INVOKERESULT_GENERIC_ERROR;
1594 VOID_TO_NPVARIANT(result);
1595 return INVOKERESULT_NO_ERROR;
1598 return INVOKERESULT_NO_SUCH_METHOD;
1599 case ID_playlist_prev:
1602 libvlc_playlist_prev(p_plugin->getVLC(), &ex);
1603 if( libvlc_exception_raised(&ex) )
1605 NPN_SetException(this, libvlc_exception_get_message(&ex));
1606 libvlc_exception_clear(&ex);
1607 return INVOKERESULT_GENERIC_ERROR;
1611 VOID_TO_NPVARIANT(result);
1612 return INVOKERESULT_NO_ERROR;
1615 return INVOKERESULT_NO_SUCH_METHOD;
1616 case ID_playlist_clear: /* deprecated */
1619 libvlc_playlist_clear(p_plugin->getVLC(), &ex);
1620 if( libvlc_exception_raised(&ex) )
1622 NPN_SetException(this, libvlc_exception_get_message(&ex));
1623 libvlc_exception_clear(&ex);
1624 return INVOKERESULT_GENERIC_ERROR;
1628 VOID_TO_NPVARIANT(result);
1629 return INVOKERESULT_NO_ERROR;
1632 return INVOKERESULT_NO_SUCH_METHOD;
1633 case ID_playlist_removeitem: /* deprecated */
1634 if( (argCount == 1) && isNumberValue(args[0]) )
1636 libvlc_playlist_delete_item(p_plugin->getVLC(), numberValue(args[0]), &ex);
1637 if( libvlc_exception_raised(&ex) )
1639 NPN_SetException(this, libvlc_exception_get_message(&ex));
1640 libvlc_exception_clear(&ex);
1641 return INVOKERESULT_GENERIC_ERROR;
1645 VOID_TO_NPVARIANT(result);
1646 return INVOKERESULT_NO_ERROR;
1649 return INVOKERESULT_NO_SUCH_METHOD;
1654 return INVOKERESULT_GENERIC_ERROR;
1657 void LibvlcPlaylistNPObject::parseOptions(const NPString &nps, int *i_options, char*** ppsz_options)
1659 if( nps.utf8length )
1661 char *s = stringValue(nps);
1666 char **options = (char **)malloc(capacity*sizeof(char *));
1671 char *end = val + nps.utf8length;
1674 // skip leading blanks
1676 && ((*val == ' ' ) || (*val == '\t')) )
1680 // skip till we get a blank character
1686 if( ('\'' == c) || ('"' == c) )
1688 // skip till end of string
1689 while( (val < end) && (*(val++) != c ) );
1695 if( nOptions == capacity )
1698 char **moreOptions = (char **)realloc(options, capacity*sizeof(char*));
1701 /* failed to allocate more memory */
1703 /* return what we got so far */
1704 *i_options = nOptions;
1705 *ppsz_options = options;
1708 options = moreOptions;
1711 options[nOptions++] = strdup(start);
1714 // must be end of string
1717 *i_options = nOptions;
1718 *ppsz_options = options;
1725 void LibvlcPlaylistNPObject::parseOptions(NPObject *obj, int *i_options, char*** ppsz_options)
1727 /* WARNING: Safari does not implement NPN_HasProperty/NPN_HasMethod */
1731 /* we are expecting to have a Javascript Array object */
1732 NPIdentifier propId = NPN_GetStringIdentifier("length");
1733 if( NPN_GetProperty(_instance, obj, propId, &value) )
1735 int count = numberValue(value);
1736 NPN_ReleaseVariantValue(&value);
1741 char **options = (char **)malloc(capacity*sizeof(char *));
1746 while( nOptions < count )
1748 propId = NPN_GetIntIdentifier(nOptions);
1749 if( ! NPN_GetProperty(_instance, obj, propId, &value) )
1750 /* return what we got so far */
1753 if( ! NPVARIANT_IS_STRING(value) )
1755 /* return what we got so far */
1756 NPN_ReleaseVariantValue(&value);
1760 if( nOptions == capacity )
1763 char **moreOptions = (char **)realloc(options, capacity*sizeof(char*));
1766 /* failed to allocate more memory */
1767 NPN_ReleaseVariantValue(&value);
1768 /* return what we got so far */
1769 *i_options = nOptions;
1770 *ppsz_options = options;
1773 options = moreOptions;
1776 options[nOptions++] = stringValue(value);
1778 *i_options = nOptions;
1779 *ppsz_options = options;
1786 ** implementation of libvlc video object
1789 const NPUTF8 * const LibvlcVideoNPObject::propertyNames[] =
1800 enum LibvlcVideoNPObjectPropertyIds
1802 ID_video_fullscreen,
1805 ID_video_aspectratio,
1811 const int LibvlcVideoNPObject::propertyCount = sizeof(LibvlcVideoNPObject::propertyNames)/sizeof(NPUTF8 *);
1813 RuntimeNPObject::InvokeResult LibvlcVideoNPObject::getProperty(int index, NPVariant &result)
1815 /* is plugin still running */
1816 if( _instance->pdata )
1818 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
1819 libvlc_exception_t ex;
1820 libvlc_exception_init(&ex);
1822 libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_plugin->getVLC(), &ex);
1823 if( libvlc_exception_raised(&ex) )
1825 NPN_SetException(this, libvlc_exception_get_message(&ex));
1826 libvlc_exception_clear(&ex);
1827 return INVOKERESULT_GENERIC_ERROR;
1832 case ID_video_fullscreen:
1834 int val = libvlc_get_fullscreen(p_md, &ex);
1835 libvlc_media_player_release(p_md);
1836 if( libvlc_exception_raised(&ex) )
1838 NPN_SetException(this, libvlc_exception_get_message(&ex));
1839 libvlc_exception_clear(&ex);
1840 return INVOKERESULT_GENERIC_ERROR;
1842 BOOLEAN_TO_NPVARIANT(val, result);
1843 return INVOKERESULT_NO_ERROR;
1845 case ID_video_height:
1847 int val = libvlc_video_get_height(p_md, &ex);
1848 libvlc_media_player_release(p_md);
1849 if( libvlc_exception_raised(&ex) )
1851 NPN_SetException(this, libvlc_exception_get_message(&ex));
1852 libvlc_exception_clear(&ex);
1853 return INVOKERESULT_GENERIC_ERROR;
1855 INT32_TO_NPVARIANT(val, result);
1856 return INVOKERESULT_NO_ERROR;
1858 case ID_video_width:
1860 int val = libvlc_video_get_width(p_md, &ex);
1861 libvlc_media_player_release(p_md);
1862 if( libvlc_exception_raised(&ex) )
1864 NPN_SetException(this, libvlc_exception_get_message(&ex));
1865 libvlc_exception_clear(&ex);
1866 return INVOKERESULT_GENERIC_ERROR;
1868 INT32_TO_NPVARIANT(val, result);
1869 return INVOKERESULT_NO_ERROR;
1871 case ID_video_aspectratio:
1873 NPUTF8 *psz_aspect = libvlc_video_get_aspect_ratio(p_md, &ex);
1874 libvlc_media_player_release(p_md);
1875 if( libvlc_exception_raised(&ex) )
1877 NPN_SetException(this, libvlc_exception_get_message(&ex));
1878 libvlc_exception_clear(&ex);
1879 return INVOKERESULT_GENERIC_ERROR;
1882 return INVOKERESULT_GENERIC_ERROR;
1884 STRINGZ_TO_NPVARIANT(psz_aspect, result);
1885 return INVOKERESULT_NO_ERROR;
1887 case ID_video_subtitle:
1889 int i_spu = libvlc_video_get_spu(p_md, &ex);
1890 libvlc_media_player_release(p_md);
1891 if( libvlc_exception_raised(&ex) )
1893 NPN_SetException(this, libvlc_exception_get_message(&ex));
1894 libvlc_exception_clear(&ex);
1895 return INVOKERESULT_GENERIC_ERROR;
1897 INT32_TO_NPVARIANT(i_spu, result);
1898 return INVOKERESULT_NO_ERROR;
1902 NPUTF8 *psz_geometry = libvlc_video_get_crop_geometry(p_md, &ex);
1903 libvlc_media_player_release(p_md);
1904 if( libvlc_exception_raised(&ex) )
1906 NPN_SetException(this, libvlc_exception_get_message(&ex));
1907 libvlc_exception_clear(&ex);
1908 return INVOKERESULT_GENERIC_ERROR;
1911 return INVOKERESULT_GENERIC_ERROR;
1913 STRINGZ_TO_NPVARIANT(psz_geometry, result);
1914 return INVOKERESULT_NO_ERROR;
1916 case ID_video_teletext:
1918 int i_page = libvlc_video_get_teletext(p_md, &ex);
1919 libvlc_media_player_release(p_md);
1920 if( libvlc_exception_raised(&ex) )
1922 NPN_SetException(this, libvlc_exception_get_message(&ex));
1923 libvlc_exception_clear(&ex);
1924 return INVOKERESULT_GENERIC_ERROR;
1926 INT32_TO_NPVARIANT(i_page, result);
1927 return INVOKERESULT_NO_ERROR;
1930 libvlc_media_player_release(p_md);
1932 return INVOKERESULT_GENERIC_ERROR;
1935 RuntimeNPObject::InvokeResult LibvlcVideoNPObject::setProperty(int index, const NPVariant &value)
1937 /* is plugin still running */
1938 if( _instance->pdata )
1940 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
1941 libvlc_exception_t ex;
1942 libvlc_exception_init(&ex);
1944 libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_plugin->getVLC(), &ex);
1945 if( libvlc_exception_raised(&ex) )
1947 NPN_SetException(this, libvlc_exception_get_message(&ex));
1948 libvlc_exception_clear(&ex);
1949 return INVOKERESULT_GENERIC_ERROR;
1954 case ID_video_fullscreen:
1956 if( ! NPVARIANT_IS_BOOLEAN(value) )
1958 libvlc_media_player_release(p_md);
1959 return INVOKERESULT_INVALID_VALUE;
1962 int val = NPVARIANT_TO_BOOLEAN(value);
1963 libvlc_set_fullscreen(p_md, val, &ex);
1964 libvlc_media_player_release(p_md);
1966 if( libvlc_exception_raised(&ex) )
1968 NPN_SetException(this, libvlc_exception_get_message(&ex));
1969 libvlc_exception_clear(&ex);
1970 return INVOKERESULT_GENERIC_ERROR;
1972 return INVOKERESULT_NO_ERROR;
1974 case ID_video_aspectratio:
1976 char *psz_aspect = NULL;
1978 if( ! NPVARIANT_IS_STRING(value) )
1980 libvlc_media_player_release(p_md);
1981 return INVOKERESULT_INVALID_VALUE;
1984 psz_aspect = stringValue(NPVARIANT_TO_STRING(value));
1987 libvlc_media_player_release(p_md);
1988 return INVOKERESULT_GENERIC_ERROR;
1991 libvlc_video_set_aspect_ratio(p_md, psz_aspect, &ex);
1993 libvlc_media_player_release(p_md);
1995 if( libvlc_exception_raised(&ex) )
1997 NPN_SetException(this, libvlc_exception_get_message(&ex));
1998 libvlc_exception_clear(&ex);
1999 return INVOKERESULT_GENERIC_ERROR;
2001 return INVOKERESULT_NO_ERROR;
2003 case ID_video_subtitle:
2005 if( isNumberValue(value) )
2007 libvlc_video_set_spu(p_md,
2008 numberValue(value), &ex);
2009 libvlc_media_player_release(p_md);
2010 if( libvlc_exception_raised(&ex) )
2012 NPN_SetException(this, libvlc_exception_get_message(&ex));
2013 libvlc_exception_clear(&ex);
2014 return INVOKERESULT_GENERIC_ERROR;
2016 return INVOKERESULT_NO_ERROR;
2018 libvlc_media_player_release(p_md);
2019 return INVOKERESULT_INVALID_VALUE;
2023 char *psz_geometry = NULL;
2025 if( ! NPVARIANT_IS_STRING(value) )
2027 libvlc_media_player_release(p_md);
2028 return INVOKERESULT_INVALID_VALUE;
2031 psz_geometry = stringValue(NPVARIANT_TO_STRING(value));
2034 libvlc_media_player_release(p_md);
2035 return INVOKERESULT_GENERIC_ERROR;
2038 libvlc_video_set_crop_geometry(p_md, psz_geometry, &ex);
2040 libvlc_media_player_release(p_md);
2042 if( libvlc_exception_raised(&ex) )
2044 NPN_SetException(this, libvlc_exception_get_message(&ex));
2045 libvlc_exception_clear(&ex);
2046 return INVOKERESULT_GENERIC_ERROR;
2048 return INVOKERESULT_NO_ERROR;
2050 case ID_video_teletext:
2052 if( isNumberValue(value) )
2054 libvlc_video_set_teletext(p_md,
2055 numberValue(value), &ex);
2056 libvlc_media_player_release(p_md);
2057 if( libvlc_exception_raised(&ex) )
2059 NPN_SetException(this, libvlc_exception_get_message(&ex));
2060 libvlc_exception_clear(&ex);
2061 return INVOKERESULT_GENERIC_ERROR;
2063 return INVOKERESULT_NO_ERROR;
2065 libvlc_media_player_release(p_md);
2066 return INVOKERESULT_INVALID_VALUE;
2069 libvlc_media_player_release(p_md);
2071 return INVOKERESULT_GENERIC_ERROR;
2074 const NPUTF8 * const LibvlcVideoNPObject::methodNames[] =
2080 enum LibvlcVideoNPObjectMethodIds
2082 ID_video_togglefullscreen,
2083 ID_video_toggleteletext
2086 const int LibvlcVideoNPObject::methodCount = sizeof(LibvlcVideoNPObject::methodNames)/sizeof(NPUTF8 *);
2088 RuntimeNPObject::InvokeResult LibvlcVideoNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)
2090 /* is plugin still running */
2091 if( _instance->pdata )
2093 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
2094 libvlc_exception_t ex;
2095 libvlc_exception_init(&ex);
2097 libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_plugin->getVLC(), &ex);
2098 if( libvlc_exception_raised(&ex) )
2100 NPN_SetException(this, libvlc_exception_get_message(&ex));
2101 libvlc_exception_clear(&ex);
2102 return INVOKERESULT_GENERIC_ERROR;
2107 case ID_video_togglefullscreen:
2110 libvlc_toggle_fullscreen(p_md, &ex);
2111 libvlc_media_player_release(p_md);
2112 if( libvlc_exception_raised(&ex) )
2114 NPN_SetException(this, libvlc_exception_get_message(&ex));
2115 libvlc_exception_clear(&ex);
2116 return INVOKERESULT_GENERIC_ERROR;
2120 VOID_TO_NPVARIANT(result);
2121 return INVOKERESULT_NO_ERROR;
2126 /* cannot get md, probably not playing */
2127 if( libvlc_exception_raised(&ex) )
2129 NPN_SetException(this, libvlc_exception_get_message(&ex));
2130 libvlc_exception_clear(&ex);
2132 return INVOKERESULT_GENERIC_ERROR;
2134 return INVOKERESULT_NO_SUCH_METHOD;
2135 case ID_video_toggleteletext:
2138 libvlc_toggle_teletext(p_md, &ex);
2139 libvlc_media_player_release(p_md);
2140 if( libvlc_exception_raised(&ex) )
2142 NPN_SetException(this, libvlc_exception_get_message(&ex));
2143 libvlc_exception_clear(&ex);
2144 return INVOKERESULT_GENERIC_ERROR;
2148 VOID_TO_NPVARIANT(result);
2149 return INVOKERESULT_NO_ERROR;
2154 /* cannot get md, probably not playing */
2155 if( libvlc_exception_raised(&ex) )
2157 NPN_SetException(this, libvlc_exception_get_message(&ex));
2158 libvlc_exception_clear(&ex);
2160 return INVOKERESULT_GENERIC_ERROR;
2162 return INVOKERESULT_NO_SUCH_METHOD;
2164 return INVOKERESULT_NO_SUCH_METHOD;
2167 return INVOKERESULT_GENERIC_ERROR;