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 libvlc_exception_clear(&ex);
462 return INVOKERESULT_NO_ERROR;
468 case ID_input_length:
470 double val = (double)libvlc_media_player_get_length(p_md, &ex);
471 libvlc_media_player_release(p_md);
472 if( libvlc_exception_raised(&ex) )
474 NPN_SetException(this, libvlc_exception_get_message(&ex));
475 libvlc_exception_clear(&ex);
476 return INVOKERESULT_GENERIC_ERROR;
478 DOUBLE_TO_NPVARIANT(val, result);
479 return INVOKERESULT_NO_ERROR;
481 case ID_input_position:
483 double val = libvlc_media_player_get_position(p_md, &ex);
484 libvlc_media_player_release(p_md);
485 if( libvlc_exception_raised(&ex) )
487 NPN_SetException(this, libvlc_exception_get_message(&ex));
488 libvlc_exception_clear(&ex);
489 return INVOKERESULT_GENERIC_ERROR;
491 DOUBLE_TO_NPVARIANT(val, result);
492 return INVOKERESULT_NO_ERROR;
496 double val = (double)libvlc_media_player_get_time(p_md, &ex);
497 libvlc_media_player_release(p_md);
498 if( libvlc_exception_raised(&ex) )
500 NPN_SetException(this, libvlc_exception_get_message(&ex));
501 libvlc_exception_clear(&ex);
502 return INVOKERESULT_GENERIC_ERROR;
504 DOUBLE_TO_NPVARIANT(val, result);
505 return INVOKERESULT_NO_ERROR;
509 int val = libvlc_media_player_get_state(p_md, &ex);
510 libvlc_media_player_release(p_md);
511 if( libvlc_exception_raised(&ex) )
513 NPN_SetException(this, libvlc_exception_get_message(&ex));
514 libvlc_exception_clear(&ex);
515 return INVOKERESULT_GENERIC_ERROR;
517 INT32_TO_NPVARIANT(val, result);
518 return INVOKERESULT_NO_ERROR;
522 float val = libvlc_media_player_get_rate(p_md, &ex);
523 libvlc_media_player_release(p_md);
524 if( libvlc_exception_raised(&ex) )
526 NPN_SetException(this, libvlc_exception_get_message(&ex));
527 libvlc_exception_clear(&ex);
528 return INVOKERESULT_GENERIC_ERROR;
530 DOUBLE_TO_NPVARIANT(val, result);
531 return INVOKERESULT_NO_ERROR;
535 double val = libvlc_media_player_get_fps(p_md, &ex);
536 libvlc_media_player_release(p_md);
537 if( libvlc_exception_raised(&ex) )
539 NPN_SetException(this, libvlc_exception_get_message(&ex));
540 libvlc_exception_clear(&ex);
541 return INVOKERESULT_GENERIC_ERROR;
543 DOUBLE_TO_NPVARIANT(val, result);
544 return INVOKERESULT_NO_ERROR;
546 case ID_input_hasvout:
548 bool val = libvlc_media_player_has_vout(p_md, &ex);
549 libvlc_media_player_release(p_md);
550 if( libvlc_exception_raised(&ex) )
552 NPN_SetException(this, libvlc_exception_get_message(&ex));
553 libvlc_exception_clear(&ex);
554 return INVOKERESULT_GENERIC_ERROR;
556 BOOLEAN_TO_NPVARIANT(val, result);
557 return INVOKERESULT_NO_ERROR;
562 libvlc_media_player_release(p_md);
564 return INVOKERESULT_GENERIC_ERROR;
567 RuntimeNPObject::InvokeResult LibvlcInputNPObject::setProperty(int index, const NPVariant &value)
569 /* is plugin still running */
570 if( _instance->pdata )
572 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
573 libvlc_exception_t ex;
574 libvlc_exception_init(&ex);
576 libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_plugin->getVLC(), &ex);
577 if( libvlc_exception_raised(&ex) )
579 NPN_SetException(this, libvlc_exception_get_message(&ex));
580 libvlc_exception_clear(&ex);
581 return INVOKERESULT_GENERIC_ERROR;
586 case ID_input_position:
588 if( ! NPVARIANT_IS_DOUBLE(value) )
590 libvlc_media_player_release(p_md);
591 return INVOKERESULT_INVALID_VALUE;
594 float val = (float)NPVARIANT_TO_DOUBLE(value);
595 libvlc_media_player_set_position(p_md, val, &ex);
596 libvlc_media_player_release(p_md);
597 if( libvlc_exception_raised(&ex) )
599 NPN_SetException(this, libvlc_exception_get_message(&ex));
600 libvlc_exception_clear(&ex);
601 return INVOKERESULT_GENERIC_ERROR;
603 return INVOKERESULT_NO_ERROR;
608 if( NPVARIANT_IS_INT32(value) )
609 val = (int64_t)NPVARIANT_TO_INT32(value);
610 else if( NPVARIANT_IS_DOUBLE(value) )
611 val = (int64_t)NPVARIANT_TO_DOUBLE(value);
614 libvlc_media_player_release(p_md);
615 return INVOKERESULT_INVALID_VALUE;
618 libvlc_media_player_set_time(p_md, val, &ex);
619 libvlc_media_player_release(p_md);
620 if( libvlc_exception_raised(&ex) )
622 NPN_SetException(this, libvlc_exception_get_message(&ex));
623 libvlc_exception_clear(&ex);
624 return INVOKERESULT_GENERIC_ERROR;
626 return INVOKERESULT_NO_ERROR;
631 if( NPVARIANT_IS_INT32(value) )
632 val = (float)NPVARIANT_TO_INT32(value);
633 else if( NPVARIANT_IS_DOUBLE(value) )
634 val = (float)NPVARIANT_TO_DOUBLE(value);
637 libvlc_media_player_release(p_md);
638 return INVOKERESULT_INVALID_VALUE;
641 libvlc_media_player_set_rate(p_md, val, &ex);
642 libvlc_media_player_release(p_md);
643 if( libvlc_exception_raised(&ex) )
645 NPN_SetException(this, libvlc_exception_get_message(&ex));
646 libvlc_exception_clear(&ex);
647 return INVOKERESULT_GENERIC_ERROR;
649 return INVOKERESULT_NO_ERROR;
654 libvlc_media_player_release(p_md);
656 return INVOKERESULT_GENERIC_ERROR;
659 const NPUTF8 * const LibvlcInputNPObject::methodNames[] =
664 const int LibvlcInputNPObject::methodCount = sizeof(LibvlcInputNPObject::methodNames)/sizeof(NPUTF8 *);
667 ** implementation of libvlc message object
670 const NPUTF8 * const LibvlcMessageNPObject::propertyNames[] =
679 const int LibvlcMessageNPObject::propertyCount = sizeof(LibvlcMessageNPObject::propertyNames)/sizeof(NPUTF8 *);
681 enum LibvlcMessageNPObjectPropertyIds
690 RuntimeNPObject::InvokeResult LibvlcMessageNPObject::getProperty(int index, NPVariant &result)
692 /* is plugin still running */
693 if( _instance->pdata )
697 case ID_message_severity:
699 INT32_TO_NPVARIANT(_msg.i_severity, result);
700 return INVOKERESULT_NO_ERROR;
702 case ID_message_type:
706 int len = strlen(_msg.psz_type);
707 NPUTF8* retval = (NPUTF8*)NPN_MemAlloc(len);
710 memcpy(retval, _msg.psz_type, len);
711 STRINGN_TO_NPVARIANT(retval, len, result);
716 NULL_TO_NPVARIANT(result);
718 return INVOKERESULT_NO_ERROR;
720 case ID_message_name:
724 int len = strlen(_msg.psz_name);
725 NPUTF8* retval = (NPUTF8*)NPN_MemAlloc(len);
728 memcpy(retval, _msg.psz_name, len);
729 STRINGN_TO_NPVARIANT(retval, len, result);
734 NULL_TO_NPVARIANT(result);
736 return INVOKERESULT_NO_ERROR;
738 case ID_message_header:
740 if( _msg.psz_header )
742 int len = strlen(_msg.psz_header);
743 NPUTF8* retval = (NPUTF8*)NPN_MemAlloc(len);
746 memcpy(retval, _msg.psz_header, len);
747 STRINGN_TO_NPVARIANT(retval, len, result);
752 NULL_TO_NPVARIANT(result);
754 return INVOKERESULT_NO_ERROR;
756 case ID_message_message:
758 if( _msg.psz_message )
760 int len = strlen(_msg.psz_message);
761 NPUTF8* retval = (NPUTF8*)NPN_MemAlloc(len);
764 memcpy(retval, _msg.psz_message, len);
765 STRINGN_TO_NPVARIANT(retval, len, result);
770 NULL_TO_NPVARIANT(result);
772 return INVOKERESULT_NO_ERROR;
778 return INVOKERESULT_GENERIC_ERROR;
781 const NPUTF8 * const LibvlcMessageNPObject::methodNames[] =
786 const int LibvlcMessageNPObject::methodCount = sizeof(LibvlcMessageNPObject::methodNames)/sizeof(NPUTF8 *);
789 ** implementation of libvlc message iterator object
792 LibvlcMessageIteratorNPObject::LibvlcMessageIteratorNPObject(NPP instance, const NPClass *aClass) :
793 RuntimeNPObject(instance, aClass),
796 /* is plugin still running */
797 if( instance->pdata )
799 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(instance->pdata);
800 libvlc_log_t *p_log = p_plugin->getLog();
803 _p_iter = libvlc_log_get_iterator(p_log, NULL);
808 LibvlcMessageIteratorNPObject::~LibvlcMessageIteratorNPObject()
811 libvlc_log_iterator_free(_p_iter, NULL);
814 const NPUTF8 * const LibvlcMessageIteratorNPObject::propertyNames[] =
819 const int LibvlcMessageIteratorNPObject::propertyCount = sizeof(LibvlcMessageIteratorNPObject::propertyNames)/sizeof(NPUTF8 *);
821 enum LibvlcMessageIteratorNPObjectPropertyIds
823 ID_messageiterator_hasNext,
826 RuntimeNPObject::InvokeResult LibvlcMessageIteratorNPObject::getProperty(int index, NPVariant &result)
828 /* is plugin still running */
829 if( _instance->pdata )
831 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
834 case ID_messageiterator_hasNext:
836 if( _p_iter && p_plugin->getLog() )
838 libvlc_exception_t ex;
839 libvlc_exception_init(&ex);
841 BOOLEAN_TO_NPVARIANT(libvlc_log_iterator_has_next(_p_iter, &ex), result);
842 if( libvlc_exception_raised(&ex) )
844 NPN_SetException(this, libvlc_exception_get_message(&ex));
845 libvlc_exception_clear(&ex);
846 return INVOKERESULT_GENERIC_ERROR;
851 BOOLEAN_TO_NPVARIANT(0, result);
853 return INVOKERESULT_NO_ERROR;
859 return INVOKERESULT_GENERIC_ERROR;
862 const NPUTF8 * const LibvlcMessageIteratorNPObject::methodNames[] =
867 const int LibvlcMessageIteratorNPObject::methodCount = sizeof(LibvlcMessageIteratorNPObject::methodNames)/sizeof(NPUTF8 *);
869 enum LibvlcMessageIteratorNPObjectMethodIds
871 ID_messageiterator_next,
874 RuntimeNPObject::InvokeResult LibvlcMessageIteratorNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)
876 /* is plugin still running */
877 if( _instance->pdata )
879 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
880 libvlc_exception_t ex;
881 libvlc_exception_init(&ex);
885 case ID_messageiterator_next:
888 if( _p_iter && p_plugin->getLog() )
890 struct libvlc_log_message_t buffer;
892 buffer.sizeof_msg = sizeof(buffer);
894 libvlc_log_iterator_next(_p_iter, &buffer, &ex);
895 if( libvlc_exception_raised(&ex) )
897 NPN_SetException(this, libvlc_exception_get_message(&ex));
898 libvlc_exception_clear(&ex);
899 return INVOKERESULT_GENERIC_ERROR;
903 LibvlcMessageNPObject* message =
904 static_cast<LibvlcMessageNPObject*>(NPN_CreateObject(_instance, RuntimeNPClass<LibvlcMessageNPObject>::getClass()));
907 message->setMessage(buffer);
908 OBJECT_TO_NPVARIANT(message, result);
909 return INVOKERESULT_NO_ERROR;
911 return INVOKERESULT_OUT_OF_MEMORY;
914 return INVOKERESULT_GENERIC_ERROR;
916 return INVOKERESULT_NO_SUCH_METHOD;
921 return INVOKERESULT_GENERIC_ERROR;
925 ** implementation of libvlc message object
928 const NPUTF8 * const LibvlcMessagesNPObject::propertyNames[] =
933 const int LibvlcMessagesNPObject::propertyCount = sizeof(LibvlcMessagesNPObject::propertyNames)/sizeof(NPUTF8 *);
935 enum LibvlcMessagesNPObjectPropertyIds
940 RuntimeNPObject::InvokeResult LibvlcMessagesNPObject::getProperty(int index, NPVariant &result)
942 /* is plugin still running */
943 if( _instance->pdata )
945 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
948 case ID_messages_count:
950 libvlc_log_t *p_log = p_plugin->getLog();
953 libvlc_exception_t ex;
954 libvlc_exception_init(&ex);
956 INT32_TO_NPVARIANT(libvlc_log_count(p_log, &ex), result);
957 if( libvlc_exception_raised(&ex) )
959 NPN_SetException(this, libvlc_exception_get_message(&ex));
960 libvlc_exception_clear(&ex);
961 return INVOKERESULT_GENERIC_ERROR;
966 INT32_TO_NPVARIANT(0, result);
968 return INVOKERESULT_NO_ERROR;
974 return INVOKERESULT_GENERIC_ERROR;
977 const NPUTF8 * const LibvlcMessagesNPObject::methodNames[] =
983 const int LibvlcMessagesNPObject::methodCount = sizeof(LibvlcMessagesNPObject::methodNames)/sizeof(NPUTF8 *);
985 enum LibvlcMessagesNPObjectMethodIds
988 ID_messages_iterator,
991 RuntimeNPObject::InvokeResult LibvlcMessagesNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)
993 /* is plugin still running */
994 if( _instance->pdata )
996 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
997 libvlc_exception_t ex;
998 libvlc_exception_init(&ex);
1002 case ID_messages_clear:
1005 libvlc_log_t *p_log = p_plugin->getLog();
1008 libvlc_log_clear(p_log, &ex);
1009 if( libvlc_exception_raised(&ex) )
1011 NPN_SetException(this, libvlc_exception_get_message(&ex));
1012 libvlc_exception_clear(&ex);
1013 return INVOKERESULT_GENERIC_ERROR;
1016 return INVOKERESULT_NO_ERROR;
1018 return INVOKERESULT_NO_SUCH_METHOD;
1020 case ID_messages_iterator:
1023 LibvlcMessageIteratorNPObject* iter =
1024 static_cast<LibvlcMessageIteratorNPObject*>(NPN_CreateObject(_instance, RuntimeNPClass<LibvlcMessageIteratorNPObject>::getClass()));
1027 OBJECT_TO_NPVARIANT(iter, result);
1028 return INVOKERESULT_NO_ERROR;
1030 return INVOKERESULT_OUT_OF_MEMORY;
1032 return INVOKERESULT_NO_SUCH_METHOD;
1038 return INVOKERESULT_GENERIC_ERROR;
1043 ** implementation of libvlc message object
1047 LibvlcLogNPObject::~LibvlcLogNPObject()
1051 if( messagesObj ) NPN_ReleaseObject(messagesObj);
1055 const NPUTF8 * const LibvlcLogNPObject::propertyNames[] =
1061 const int LibvlcLogNPObject::propertyCount = sizeof(LibvlcLogNPObject::propertyNames)/sizeof(NPUTF8 *);
1063 enum LibvlcLogNPObjectPropertyIds
1069 RuntimeNPObject::InvokeResult LibvlcLogNPObject::getProperty(int index, NPVariant &result)
1071 /* is plugin still running */
1072 if( _instance->pdata )
1074 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
1075 libvlc_exception_t ex;
1076 libvlc_exception_init(&ex);
1080 case ID_log_messages:
1082 // create child object in lazyman fashion to avoid ownership problem with firefox
1084 messagesObj = NPN_CreateObject(_instance, RuntimeNPClass<LibvlcMessagesNPObject>::getClass());
1085 OBJECT_TO_NPVARIANT(NPN_RetainObject(messagesObj), result);
1086 return INVOKERESULT_NO_ERROR;
1088 case ID_log_verbosity:
1090 if( p_plugin->getLog() )
1092 INT32_TO_NPVARIANT(libvlc_get_log_verbosity(p_plugin->getVLC(),
1094 if( libvlc_exception_raised(&ex) )
1096 NPN_SetException(this, libvlc_exception_get_message(&ex));
1097 libvlc_exception_clear(&ex);
1098 return INVOKERESULT_GENERIC_ERROR;
1103 /* log is not enabled, return -1 */
1104 DOUBLE_TO_NPVARIANT(-1.0, result);
1106 return INVOKERESULT_NO_ERROR;
1112 return INVOKERESULT_GENERIC_ERROR;
1115 RuntimeNPObject::InvokeResult LibvlcLogNPObject::setProperty(int index, const NPVariant &value)
1117 /* is plugin still running */
1118 if( _instance->pdata )
1120 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
1121 libvlc_exception_t ex;
1122 libvlc_exception_init(&ex);
1126 case ID_log_verbosity:
1127 if( isNumberValue(value) )
1129 libvlc_instance_t* p_libvlc = p_plugin->getVLC();
1130 libvlc_log_t *p_log = p_plugin->getLog();
1131 int verbosity = numberValue(value);
1132 if( verbosity >= 0 )
1136 p_log = libvlc_log_open(p_libvlc, &ex);
1137 if( libvlc_exception_raised(&ex) )
1139 NPN_SetException(this, libvlc_exception_get_message(&ex));
1140 libvlc_exception_clear(&ex);
1141 return INVOKERESULT_GENERIC_ERROR;
1143 p_plugin->setLog(p_log);
1145 libvlc_set_log_verbosity(p_libvlc, (unsigned)verbosity, &ex);
1146 if( libvlc_exception_raised(&ex) )
1148 NPN_SetException(this, libvlc_exception_get_message(&ex));
1149 libvlc_exception_clear(&ex);
1150 return INVOKERESULT_GENERIC_ERROR;
1155 /* close log when verbosity is set to -1 */
1156 p_plugin->setLog(NULL);
1157 libvlc_log_close(p_log, &ex);
1158 if( libvlc_exception_raised(&ex) )
1160 NPN_SetException(this, libvlc_exception_get_message(&ex));
1161 libvlc_exception_clear(&ex);
1162 return INVOKERESULT_GENERIC_ERROR;
1165 return INVOKERESULT_NO_ERROR;
1167 return INVOKERESULT_INVALID_VALUE;
1172 return INVOKERESULT_GENERIC_ERROR;
1175 const NPUTF8 * const LibvlcLogNPObject::methodNames[] =
1180 const int LibvlcLogNPObject::methodCount = sizeof(LibvlcLogNPObject::methodNames)/sizeof(NPUTF8 *);
1183 ** implementation of libvlc playlist items object
1186 const NPUTF8 * const LibvlcPlaylistItemsNPObject::propertyNames[] =
1191 const int LibvlcPlaylistItemsNPObject::propertyCount = sizeof(LibvlcPlaylistItemsNPObject::propertyNames)/sizeof(NPUTF8 *);
1193 enum LibvlcPlaylistItemsNPObjectPropertyIds
1195 ID_playlistitems_count,
1198 RuntimeNPObject::InvokeResult LibvlcPlaylistItemsNPObject::getProperty(int index, NPVariant &result)
1200 /* is plugin still running */
1201 if( _instance->pdata )
1203 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
1204 libvlc_exception_t ex;
1205 libvlc_exception_init(&ex);
1209 case ID_playlistitems_count:
1211 libvlc_playlist_lock(p_plugin->getVLC());
1212 int val = libvlc_playlist_items_count(p_plugin->getVLC(), &ex);
1213 libvlc_playlist_unlock(p_plugin->getVLC());
1214 if( libvlc_exception_raised(&ex) )
1216 NPN_SetException(this, libvlc_exception_get_message(&ex));
1217 libvlc_exception_clear(&ex);
1218 return INVOKERESULT_GENERIC_ERROR;
1220 INT32_TO_NPVARIANT(val, result);
1221 return INVOKERESULT_NO_ERROR;
1227 return INVOKERESULT_GENERIC_ERROR;
1230 const NPUTF8 * const LibvlcPlaylistItemsNPObject::methodNames[] =
1236 const int LibvlcPlaylistItemsNPObject::methodCount = sizeof(LibvlcPlaylistItemsNPObject::methodNames)/sizeof(NPUTF8 *);
1238 enum LibvlcPlaylistItemsNPObjectMethodIds
1240 ID_playlistitems_clear,
1241 ID_playlistitems_remove,
1244 RuntimeNPObject::InvokeResult LibvlcPlaylistItemsNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)
1246 /* is plugin still running */
1247 if( _instance->pdata )
1249 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
1250 libvlc_exception_t ex;
1251 libvlc_exception_init(&ex);
1255 case ID_playlistitems_clear:
1258 libvlc_playlist_clear(p_plugin->getVLC(), &ex);
1259 if( libvlc_exception_raised(&ex) )
1261 NPN_SetException(this, libvlc_exception_get_message(&ex));
1262 libvlc_exception_clear(&ex);
1263 return INVOKERESULT_GENERIC_ERROR;
1267 VOID_TO_NPVARIANT(result);
1268 return INVOKERESULT_NO_ERROR;
1271 return INVOKERESULT_NO_SUCH_METHOD;
1272 case ID_playlistitems_remove:
1273 if( (argCount == 1) && isNumberValue(args[0]) )
1275 libvlc_playlist_delete_item(p_plugin->getVLC(), numberValue(args[0]), &ex);
1276 if( libvlc_exception_raised(&ex) )
1278 NPN_SetException(this, libvlc_exception_get_message(&ex));
1279 libvlc_exception_clear(&ex);
1280 return INVOKERESULT_GENERIC_ERROR;
1284 VOID_TO_NPVARIANT(result);
1285 return INVOKERESULT_NO_ERROR;
1288 return INVOKERESULT_NO_SUCH_METHOD;
1293 return INVOKERESULT_GENERIC_ERROR;
1297 ** implementation of libvlc playlist object
1301 LibvlcPlaylistNPObject::~LibvlcPlaylistNPObject()
1305 if( playlistItemsObj ) NPN_ReleaseObject(playlistItemsObj);
1309 const NPUTF8 * const LibvlcPlaylistNPObject::propertyNames[] =
1311 "itemCount", /* deprecated */
1316 const int LibvlcPlaylistNPObject::propertyCount = sizeof(LibvlcPlaylistNPObject::propertyNames)/sizeof(NPUTF8 *);
1318 enum LibvlcPlaylistNPObjectPropertyIds
1320 ID_playlist_itemcount,
1321 ID_playlist_isplaying,
1325 RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::getProperty(int index, NPVariant &result)
1327 /* is plugin still running */
1328 if( _instance->pdata )
1330 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
1331 libvlc_exception_t ex;
1332 libvlc_exception_init(&ex);
1336 case ID_playlist_itemcount: /* deprecated */
1338 libvlc_playlist_lock(p_plugin->getVLC());
1339 int val = libvlc_playlist_items_count(p_plugin->getVLC(), &ex);
1340 libvlc_playlist_unlock(p_plugin->getVLC());
1341 if( libvlc_exception_raised(&ex) )
1343 NPN_SetException(this, libvlc_exception_get_message(&ex));
1344 libvlc_exception_clear(&ex);
1345 return INVOKERESULT_GENERIC_ERROR;
1347 INT32_TO_NPVARIANT(val, result);
1348 return INVOKERESULT_NO_ERROR;
1350 case ID_playlist_isplaying:
1352 int val = libvlc_playlist_isplaying(p_plugin->getVLC(), &ex);
1353 if( libvlc_exception_raised(&ex) )
1355 NPN_SetException(this, libvlc_exception_get_message(&ex));
1356 libvlc_exception_clear(&ex);
1357 return INVOKERESULT_GENERIC_ERROR;
1359 BOOLEAN_TO_NPVARIANT(val, result);
1360 return INVOKERESULT_NO_ERROR;
1362 case ID_playlist_items:
1364 // create child object in lazyman fashion to avoid ownership problem with firefox
1365 if( ! playlistItemsObj )
1366 playlistItemsObj = NPN_CreateObject(_instance, RuntimeNPClass<LibvlcPlaylistItemsNPObject>::getClass());
1367 OBJECT_TO_NPVARIANT(NPN_RetainObject(playlistItemsObj), result);
1368 return INVOKERESULT_NO_ERROR;
1374 return INVOKERESULT_GENERIC_ERROR;
1377 const NPUTF8 * const LibvlcPlaylistNPObject::methodNames[] =
1386 "clear", /* deprecated */
1387 "removeItem", /* deprecated */
1390 const int LibvlcPlaylistNPObject::methodCount = sizeof(LibvlcPlaylistNPObject::methodNames)/sizeof(NPUTF8 *);
1392 enum LibvlcPlaylistNPObjectMethodIds
1396 ID_playlist_playItem,
1397 ID_playlist_togglepause,
1402 ID_playlist_removeitem
1405 RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)
1407 /* is plugin still running */
1408 if( _instance->pdata )
1410 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
1411 libvlc_exception_t ex;
1412 libvlc_exception_init(&ex);
1416 case ID_playlist_add:
1418 if( (argCount < 1) || (argCount > 3) )
1419 return INVOKERESULT_NO_SUCH_METHOD;
1424 if( NPVARIANT_IS_STRING(args[0]) )
1426 char *s = stringValue(NPVARIANT_TO_STRING(args[0]));
1429 url = p_plugin->getAbsoluteURL(s);
1433 // problem with combining url, use argument
1437 return INVOKERESULT_OUT_OF_MEMORY;
1440 return INVOKERESULT_NO_SUCH_METHOD;
1444 // grab name if available
1447 if( NPVARIANT_IS_NULL(args[1]) )
1451 else if( NPVARIANT_IS_STRING(args[1]) )
1453 name = stringValue(NPVARIANT_TO_STRING(args[1]));
1458 return INVOKERESULT_INVALID_VALUE;
1463 char** ppsz_options = NULL;
1465 // grab options if available
1468 if( NPVARIANT_IS_NULL(args[2]) )
1472 else if( NPVARIANT_IS_STRING(args[2]) )
1474 parseOptions(NPVARIANT_TO_STRING(args[2]), &i_options, &ppsz_options);
1477 else if( NPVARIANT_IS_OBJECT(args[2]) )
1479 parseOptions(NPVARIANT_TO_OBJECT(args[2]), &i_options, &ppsz_options);
1485 return INVOKERESULT_INVALID_VALUE;
1489 int item = libvlc_playlist_add_extended_untrusted(p_plugin->getVLC(),
1493 const_cast<const char **>(ppsz_options),
1497 for( int i=0; i< i_options; ++i )
1499 free(ppsz_options[i]);
1503 if( libvlc_exception_raised(&ex) )
1505 NPN_SetException(this, libvlc_exception_get_message(&ex));
1506 libvlc_exception_clear(&ex);
1507 return INVOKERESULT_GENERIC_ERROR;
1511 INT32_TO_NPVARIANT(item, result);
1512 return INVOKERESULT_NO_ERROR;
1515 case ID_playlist_play:
1518 libvlc_playlist_play(p_plugin->getVLC(), -1, 0, NULL, &ex);
1519 if( libvlc_exception_raised(&ex) )
1521 NPN_SetException(this, libvlc_exception_get_message(&ex));
1522 libvlc_exception_clear(&ex);
1523 return INVOKERESULT_GENERIC_ERROR;
1527 VOID_TO_NPVARIANT(result);
1528 return INVOKERESULT_NO_ERROR;
1531 return INVOKERESULT_NO_SUCH_METHOD;
1532 case ID_playlist_playItem:
1533 if( (argCount == 1) && isNumberValue(args[0]) )
1535 libvlc_playlist_play(p_plugin->getVLC(), numberValue(args[0]), 0, NULL, &ex);
1536 if( libvlc_exception_raised(&ex) )
1538 NPN_SetException(this, libvlc_exception_get_message(&ex));
1539 libvlc_exception_clear(&ex);
1540 return INVOKERESULT_GENERIC_ERROR;
1544 VOID_TO_NPVARIANT(result);
1545 return INVOKERESULT_NO_ERROR;
1548 return INVOKERESULT_NO_SUCH_METHOD;
1549 case ID_playlist_togglepause:
1552 libvlc_playlist_pause(p_plugin->getVLC(), &ex);
1553 if( libvlc_exception_raised(&ex) )
1555 NPN_SetException(this, libvlc_exception_get_message(&ex));
1556 libvlc_exception_clear(&ex);
1557 return INVOKERESULT_GENERIC_ERROR;
1561 VOID_TO_NPVARIANT(result);
1562 return INVOKERESULT_NO_ERROR;
1565 return INVOKERESULT_NO_SUCH_METHOD;
1566 case ID_playlist_stop:
1569 libvlc_playlist_stop(p_plugin->getVLC(), &ex);
1570 if( libvlc_exception_raised(&ex) )
1572 NPN_SetException(this, libvlc_exception_get_message(&ex));
1573 libvlc_exception_clear(&ex);
1574 return INVOKERESULT_GENERIC_ERROR;
1578 VOID_TO_NPVARIANT(result);
1579 return INVOKERESULT_NO_ERROR;
1582 return INVOKERESULT_NO_SUCH_METHOD;
1583 case ID_playlist_next:
1586 libvlc_playlist_next(p_plugin->getVLC(), &ex);
1587 if( libvlc_exception_raised(&ex) )
1589 NPN_SetException(this, libvlc_exception_get_message(&ex));
1590 libvlc_exception_clear(&ex);
1591 return INVOKERESULT_GENERIC_ERROR;
1595 VOID_TO_NPVARIANT(result);
1596 return INVOKERESULT_NO_ERROR;
1599 return INVOKERESULT_NO_SUCH_METHOD;
1600 case ID_playlist_prev:
1603 libvlc_playlist_prev(p_plugin->getVLC(), &ex);
1604 if( libvlc_exception_raised(&ex) )
1606 NPN_SetException(this, libvlc_exception_get_message(&ex));
1607 libvlc_exception_clear(&ex);
1608 return INVOKERESULT_GENERIC_ERROR;
1612 VOID_TO_NPVARIANT(result);
1613 return INVOKERESULT_NO_ERROR;
1616 return INVOKERESULT_NO_SUCH_METHOD;
1617 case ID_playlist_clear: /* deprecated */
1620 libvlc_playlist_clear(p_plugin->getVLC(), &ex);
1621 if( libvlc_exception_raised(&ex) )
1623 NPN_SetException(this, libvlc_exception_get_message(&ex));
1624 libvlc_exception_clear(&ex);
1625 return INVOKERESULT_GENERIC_ERROR;
1629 VOID_TO_NPVARIANT(result);
1630 return INVOKERESULT_NO_ERROR;
1633 return INVOKERESULT_NO_SUCH_METHOD;
1634 case ID_playlist_removeitem: /* deprecated */
1635 if( (argCount == 1) && isNumberValue(args[0]) )
1637 libvlc_playlist_delete_item(p_plugin->getVLC(), numberValue(args[0]), &ex);
1638 if( libvlc_exception_raised(&ex) )
1640 NPN_SetException(this, libvlc_exception_get_message(&ex));
1641 libvlc_exception_clear(&ex);
1642 return INVOKERESULT_GENERIC_ERROR;
1646 VOID_TO_NPVARIANT(result);
1647 return INVOKERESULT_NO_ERROR;
1650 return INVOKERESULT_NO_SUCH_METHOD;
1655 return INVOKERESULT_GENERIC_ERROR;
1658 void LibvlcPlaylistNPObject::parseOptions(const NPString &nps, int *i_options, char*** ppsz_options)
1660 if( nps.utf8length )
1662 char *s = stringValue(nps);
1667 char **options = (char **)malloc(capacity*sizeof(char *));
1672 char *end = val + nps.utf8length;
1675 // skip leading blanks
1677 && ((*val == ' ' ) || (*val == '\t')) )
1681 // skip till we get a blank character
1687 if( ('\'' == c) || ('"' == c) )
1689 // skip till end of string
1690 while( (val < end) && (*(val++) != c ) );
1696 if( nOptions == capacity )
1699 char **moreOptions = (char **)realloc(options, capacity*sizeof(char*));
1702 /* failed to allocate more memory */
1704 /* return what we got so far */
1705 *i_options = nOptions;
1706 *ppsz_options = options;
1709 options = moreOptions;
1712 options[nOptions++] = strdup(start);
1715 // must be end of string
1718 *i_options = nOptions;
1719 *ppsz_options = options;
1726 void LibvlcPlaylistNPObject::parseOptions(NPObject *obj, int *i_options, char*** ppsz_options)
1728 /* WARNING: Safari does not implement NPN_HasProperty/NPN_HasMethod */
1732 /* we are expecting to have a Javascript Array object */
1733 NPIdentifier propId = NPN_GetStringIdentifier("length");
1734 if( NPN_GetProperty(_instance, obj, propId, &value) )
1736 int count = numberValue(value);
1737 NPN_ReleaseVariantValue(&value);
1742 char **options = (char **)malloc(capacity*sizeof(char *));
1747 while( nOptions < count )
1749 propId = NPN_GetIntIdentifier(nOptions);
1750 if( ! NPN_GetProperty(_instance, obj, propId, &value) )
1751 /* return what we got so far */
1754 if( ! NPVARIANT_IS_STRING(value) )
1756 /* return what we got so far */
1757 NPN_ReleaseVariantValue(&value);
1761 if( nOptions == capacity )
1764 char **moreOptions = (char **)realloc(options, capacity*sizeof(char*));
1767 /* failed to allocate more memory */
1768 NPN_ReleaseVariantValue(&value);
1769 /* return what we got so far */
1770 *i_options = nOptions;
1771 *ppsz_options = options;
1774 options = moreOptions;
1777 options[nOptions++] = stringValue(value);
1779 *i_options = nOptions;
1780 *ppsz_options = options;
1787 ** implementation of libvlc video object
1790 const NPUTF8 * const LibvlcVideoNPObject::propertyNames[] =
1801 enum LibvlcVideoNPObjectPropertyIds
1803 ID_video_fullscreen,
1806 ID_video_aspectratio,
1812 const int LibvlcVideoNPObject::propertyCount = sizeof(LibvlcVideoNPObject::propertyNames)/sizeof(NPUTF8 *);
1814 RuntimeNPObject::InvokeResult LibvlcVideoNPObject::getProperty(int index, NPVariant &result)
1816 /* is plugin still running */
1817 if( _instance->pdata )
1819 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
1820 libvlc_exception_t ex;
1821 libvlc_exception_init(&ex);
1823 libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_plugin->getVLC(), &ex);
1824 if( libvlc_exception_raised(&ex) )
1826 NPN_SetException(this, libvlc_exception_get_message(&ex));
1827 libvlc_exception_clear(&ex);
1828 return INVOKERESULT_GENERIC_ERROR;
1833 case ID_video_fullscreen:
1835 int val = libvlc_get_fullscreen(p_md, &ex);
1836 libvlc_media_player_release(p_md);
1837 if( libvlc_exception_raised(&ex) )
1839 NPN_SetException(this, libvlc_exception_get_message(&ex));
1840 libvlc_exception_clear(&ex);
1841 return INVOKERESULT_GENERIC_ERROR;
1843 BOOLEAN_TO_NPVARIANT(val, result);
1844 return INVOKERESULT_NO_ERROR;
1846 case ID_video_height:
1848 int val = libvlc_video_get_height(p_md, &ex);
1849 libvlc_media_player_release(p_md);
1850 if( libvlc_exception_raised(&ex) )
1852 NPN_SetException(this, libvlc_exception_get_message(&ex));
1853 libvlc_exception_clear(&ex);
1854 return INVOKERESULT_GENERIC_ERROR;
1856 INT32_TO_NPVARIANT(val, result);
1857 return INVOKERESULT_NO_ERROR;
1859 case ID_video_width:
1861 int val = libvlc_video_get_width(p_md, &ex);
1862 libvlc_media_player_release(p_md);
1863 if( libvlc_exception_raised(&ex) )
1865 NPN_SetException(this, libvlc_exception_get_message(&ex));
1866 libvlc_exception_clear(&ex);
1867 return INVOKERESULT_GENERIC_ERROR;
1869 INT32_TO_NPVARIANT(val, result);
1870 return INVOKERESULT_NO_ERROR;
1872 case ID_video_aspectratio:
1874 NPUTF8 *psz_aspect = libvlc_video_get_aspect_ratio(p_md, &ex);
1875 libvlc_media_player_release(p_md);
1876 if( libvlc_exception_raised(&ex) )
1878 NPN_SetException(this, libvlc_exception_get_message(&ex));
1879 libvlc_exception_clear(&ex);
1880 return INVOKERESULT_GENERIC_ERROR;
1883 return INVOKERESULT_GENERIC_ERROR;
1885 STRINGZ_TO_NPVARIANT(psz_aspect, result);
1886 return INVOKERESULT_NO_ERROR;
1888 case ID_video_subtitle:
1890 int i_spu = libvlc_video_get_spu(p_md, &ex);
1891 libvlc_media_player_release(p_md);
1892 if( libvlc_exception_raised(&ex) )
1894 NPN_SetException(this, libvlc_exception_get_message(&ex));
1895 libvlc_exception_clear(&ex);
1896 return INVOKERESULT_GENERIC_ERROR;
1898 INT32_TO_NPVARIANT(i_spu, result);
1899 return INVOKERESULT_NO_ERROR;
1903 NPUTF8 *psz_geometry = libvlc_video_get_crop_geometry(p_md, &ex);
1904 libvlc_media_player_release(p_md);
1905 if( libvlc_exception_raised(&ex) )
1907 NPN_SetException(this, libvlc_exception_get_message(&ex));
1908 libvlc_exception_clear(&ex);
1909 return INVOKERESULT_GENERIC_ERROR;
1912 return INVOKERESULT_GENERIC_ERROR;
1914 STRINGZ_TO_NPVARIANT(psz_geometry, result);
1915 return INVOKERESULT_NO_ERROR;
1917 case ID_video_teletext:
1919 int i_page = libvlc_video_get_teletext(p_md, &ex);
1920 libvlc_media_player_release(p_md);
1921 if( libvlc_exception_raised(&ex) )
1923 NPN_SetException(this, libvlc_exception_get_message(&ex));
1924 libvlc_exception_clear(&ex);
1925 return INVOKERESULT_GENERIC_ERROR;
1927 INT32_TO_NPVARIANT(i_page, result);
1928 return INVOKERESULT_NO_ERROR;
1931 libvlc_media_player_release(p_md);
1933 return INVOKERESULT_GENERIC_ERROR;
1936 RuntimeNPObject::InvokeResult LibvlcVideoNPObject::setProperty(int index, const NPVariant &value)
1938 /* is plugin still running */
1939 if( _instance->pdata )
1941 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
1942 libvlc_exception_t ex;
1943 libvlc_exception_init(&ex);
1945 libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_plugin->getVLC(), &ex);
1946 if( libvlc_exception_raised(&ex) )
1948 NPN_SetException(this, libvlc_exception_get_message(&ex));
1949 libvlc_exception_clear(&ex);
1950 return INVOKERESULT_GENERIC_ERROR;
1955 case ID_video_fullscreen:
1957 if( ! NPVARIANT_IS_BOOLEAN(value) )
1959 libvlc_media_player_release(p_md);
1960 return INVOKERESULT_INVALID_VALUE;
1963 int val = NPVARIANT_TO_BOOLEAN(value);
1964 libvlc_set_fullscreen(p_md, val, &ex);
1965 libvlc_media_player_release(p_md);
1967 if( libvlc_exception_raised(&ex) )
1969 NPN_SetException(this, libvlc_exception_get_message(&ex));
1970 libvlc_exception_clear(&ex);
1971 return INVOKERESULT_GENERIC_ERROR;
1973 return INVOKERESULT_NO_ERROR;
1975 case ID_video_aspectratio:
1977 char *psz_aspect = NULL;
1979 if( ! NPVARIANT_IS_STRING(value) )
1981 libvlc_media_player_release(p_md);
1982 return INVOKERESULT_INVALID_VALUE;
1985 psz_aspect = stringValue(NPVARIANT_TO_STRING(value));
1988 libvlc_media_player_release(p_md);
1989 return INVOKERESULT_GENERIC_ERROR;
1992 libvlc_video_set_aspect_ratio(p_md, psz_aspect, &ex);
1994 libvlc_media_player_release(p_md);
1996 if( libvlc_exception_raised(&ex) )
1998 NPN_SetException(this, libvlc_exception_get_message(&ex));
1999 libvlc_exception_clear(&ex);
2000 return INVOKERESULT_GENERIC_ERROR;
2002 return INVOKERESULT_NO_ERROR;
2004 case ID_video_subtitle:
2006 if( isNumberValue(value) )
2008 libvlc_video_set_spu(p_md,
2009 numberValue(value), &ex);
2010 libvlc_media_player_release(p_md);
2011 if( libvlc_exception_raised(&ex) )
2013 NPN_SetException(this, libvlc_exception_get_message(&ex));
2014 libvlc_exception_clear(&ex);
2015 return INVOKERESULT_GENERIC_ERROR;
2017 return INVOKERESULT_NO_ERROR;
2019 libvlc_media_player_release(p_md);
2020 return INVOKERESULT_INVALID_VALUE;
2024 char *psz_geometry = NULL;
2026 if( ! NPVARIANT_IS_STRING(value) )
2028 libvlc_media_player_release(p_md);
2029 return INVOKERESULT_INVALID_VALUE;
2032 psz_geometry = stringValue(NPVARIANT_TO_STRING(value));
2035 libvlc_media_player_release(p_md);
2036 return INVOKERESULT_GENERIC_ERROR;
2039 libvlc_video_set_crop_geometry(p_md, psz_geometry, &ex);
2041 libvlc_media_player_release(p_md);
2043 if( libvlc_exception_raised(&ex) )
2045 NPN_SetException(this, libvlc_exception_get_message(&ex));
2046 libvlc_exception_clear(&ex);
2047 return INVOKERESULT_GENERIC_ERROR;
2049 return INVOKERESULT_NO_ERROR;
2051 case ID_video_teletext:
2053 if( isNumberValue(value) )
2055 libvlc_video_set_teletext(p_md,
2056 numberValue(value), &ex);
2057 libvlc_media_player_release(p_md);
2058 if( libvlc_exception_raised(&ex) )
2060 NPN_SetException(this, libvlc_exception_get_message(&ex));
2061 libvlc_exception_clear(&ex);
2062 return INVOKERESULT_GENERIC_ERROR;
2064 return INVOKERESULT_NO_ERROR;
2066 libvlc_media_player_release(p_md);
2067 return INVOKERESULT_INVALID_VALUE;
2070 libvlc_media_player_release(p_md);
2072 return INVOKERESULT_GENERIC_ERROR;
2075 const NPUTF8 * const LibvlcVideoNPObject::methodNames[] =
2081 enum LibvlcVideoNPObjectMethodIds
2083 ID_video_togglefullscreen,
2084 ID_video_toggleteletext
2087 const int LibvlcVideoNPObject::methodCount = sizeof(LibvlcVideoNPObject::methodNames)/sizeof(NPUTF8 *);
2089 RuntimeNPObject::InvokeResult LibvlcVideoNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)
2091 /* is plugin still running */
2092 if( _instance->pdata )
2094 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
2095 libvlc_exception_t ex;
2096 libvlc_exception_init(&ex);
2098 libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_plugin->getVLC(), &ex);
2099 if( libvlc_exception_raised(&ex) )
2101 NPN_SetException(this, libvlc_exception_get_message(&ex));
2102 libvlc_exception_clear(&ex);
2103 return INVOKERESULT_GENERIC_ERROR;
2108 case ID_video_togglefullscreen:
2111 libvlc_toggle_fullscreen(p_md, &ex);
2112 libvlc_media_player_release(p_md);
2113 if( libvlc_exception_raised(&ex) )
2115 NPN_SetException(this, libvlc_exception_get_message(&ex));
2116 libvlc_exception_clear(&ex);
2117 return INVOKERESULT_GENERIC_ERROR;
2121 VOID_TO_NPVARIANT(result);
2122 return INVOKERESULT_NO_ERROR;
2127 /* cannot get md, probably not playing */
2128 if( libvlc_exception_raised(&ex) )
2130 NPN_SetException(this, libvlc_exception_get_message(&ex));
2131 libvlc_exception_clear(&ex);
2133 return INVOKERESULT_GENERIC_ERROR;
2135 return INVOKERESULT_NO_SUCH_METHOD;
2136 case ID_video_toggleteletext:
2139 libvlc_toggle_teletext(p_md, &ex);
2140 libvlc_media_player_release(p_md);
2141 if( libvlc_exception_raised(&ex) )
2143 NPN_SetException(this, libvlc_exception_get_message(&ex));
2144 libvlc_exception_clear(&ex);
2145 return INVOKERESULT_GENERIC_ERROR;
2149 VOID_TO_NPVARIANT(result);
2150 return INVOKERESULT_NO_ERROR;
2155 /* cannot get md, probably not playing */
2156 if( libvlc_exception_raised(&ex) )
2158 NPN_SetException(this, libvlc_exception_get_message(&ex));
2159 libvlc_exception_clear(&ex);
2161 return INVOKERESULT_GENERIC_ERROR;
2163 return INVOKERESULT_NO_SUCH_METHOD;
2165 return INVOKERESULT_NO_SUCH_METHOD;
2168 return INVOKERESULT_GENERIC_ERROR;