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 libvlc_playlist_lock(p_plugin->getVLC());
1353 int val = libvlc_playlist_isplaying(p_plugin->getVLC(), &ex);
1354 libvlc_playlist_unlock(p_plugin->getVLC());
1355 if( libvlc_exception_raised(&ex) )
1357 NPN_SetException(this, libvlc_exception_get_message(&ex));
1358 libvlc_exception_clear(&ex);
1359 return INVOKERESULT_GENERIC_ERROR;
1361 BOOLEAN_TO_NPVARIANT(val, result);
1362 return INVOKERESULT_NO_ERROR;
1364 case ID_playlist_items:
1366 // create child object in lazyman fashion to avoid ownership problem with firefox
1367 if( ! playlistItemsObj )
1368 playlistItemsObj = NPN_CreateObject(_instance, RuntimeNPClass<LibvlcPlaylistItemsNPObject>::getClass());
1369 OBJECT_TO_NPVARIANT(NPN_RetainObject(playlistItemsObj), result);
1370 return INVOKERESULT_NO_ERROR;
1376 return INVOKERESULT_GENERIC_ERROR;
1379 const NPUTF8 * const LibvlcPlaylistNPObject::methodNames[] =
1388 "clear", /* deprecated */
1389 "removeItem", /* deprecated */
1392 const int LibvlcPlaylistNPObject::methodCount = sizeof(LibvlcPlaylistNPObject::methodNames)/sizeof(NPUTF8 *);
1394 enum LibvlcPlaylistNPObjectMethodIds
1398 ID_playlist_playItem,
1399 ID_playlist_togglepause,
1404 ID_playlist_removeitem
1407 RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)
1409 /* is plugin still running */
1410 if( _instance->pdata )
1412 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
1413 libvlc_exception_t ex;
1414 libvlc_exception_init(&ex);
1418 case ID_playlist_add:
1420 if( (argCount < 1) || (argCount > 3) )
1421 return INVOKERESULT_NO_SUCH_METHOD;
1426 if( NPVARIANT_IS_STRING(args[0]) )
1428 char *s = stringValue(NPVARIANT_TO_STRING(args[0]));
1431 url = p_plugin->getAbsoluteURL(s);
1435 // problem with combining url, use argument
1439 return INVOKERESULT_OUT_OF_MEMORY;
1442 return INVOKERESULT_NO_SUCH_METHOD;
1446 // grab name if available
1449 if( NPVARIANT_IS_NULL(args[1]) )
1453 else if( NPVARIANT_IS_STRING(args[1]) )
1455 name = stringValue(NPVARIANT_TO_STRING(args[1]));
1460 return INVOKERESULT_INVALID_VALUE;
1465 char** ppsz_options = NULL;
1467 // grab options if available
1470 if( NPVARIANT_IS_NULL(args[2]) )
1474 else if( NPVARIANT_IS_STRING(args[2]) )
1476 parseOptions(NPVARIANT_TO_STRING(args[2]), &i_options, &ppsz_options);
1479 else if( NPVARIANT_IS_OBJECT(args[2]) )
1481 parseOptions(NPVARIANT_TO_OBJECT(args[2]), &i_options, &ppsz_options);
1487 return INVOKERESULT_INVALID_VALUE;
1491 int item = libvlc_playlist_add_extended_untrusted(p_plugin->getVLC(),
1495 const_cast<const char **>(ppsz_options),
1499 for( int i=0; i< i_options; ++i )
1501 free(ppsz_options[i]);
1505 if( libvlc_exception_raised(&ex) )
1507 NPN_SetException(this, libvlc_exception_get_message(&ex));
1508 libvlc_exception_clear(&ex);
1509 return INVOKERESULT_GENERIC_ERROR;
1513 INT32_TO_NPVARIANT(item, result);
1514 return INVOKERESULT_NO_ERROR;
1517 case ID_playlist_play:
1520 libvlc_playlist_play(p_plugin->getVLC(), -1, 0, NULL, &ex);
1521 if( libvlc_exception_raised(&ex) )
1523 NPN_SetException(this, libvlc_exception_get_message(&ex));
1524 libvlc_exception_clear(&ex);
1525 return INVOKERESULT_GENERIC_ERROR;
1529 VOID_TO_NPVARIANT(result);
1530 return INVOKERESULT_NO_ERROR;
1533 return INVOKERESULT_NO_SUCH_METHOD;
1534 case ID_playlist_playItem:
1535 if( (argCount == 1) && isNumberValue(args[0]) )
1537 libvlc_playlist_play(p_plugin->getVLC(), numberValue(args[0]), 0, NULL, &ex);
1538 if( libvlc_exception_raised(&ex) )
1540 NPN_SetException(this, libvlc_exception_get_message(&ex));
1541 libvlc_exception_clear(&ex);
1542 return INVOKERESULT_GENERIC_ERROR;
1546 VOID_TO_NPVARIANT(result);
1547 return INVOKERESULT_NO_ERROR;
1550 return INVOKERESULT_NO_SUCH_METHOD;
1551 case ID_playlist_togglepause:
1554 libvlc_playlist_pause(p_plugin->getVLC(), &ex);
1555 if( libvlc_exception_raised(&ex) )
1557 NPN_SetException(this, libvlc_exception_get_message(&ex));
1558 libvlc_exception_clear(&ex);
1559 return INVOKERESULT_GENERIC_ERROR;
1563 VOID_TO_NPVARIANT(result);
1564 return INVOKERESULT_NO_ERROR;
1567 return INVOKERESULT_NO_SUCH_METHOD;
1568 case ID_playlist_stop:
1571 libvlc_playlist_stop(p_plugin->getVLC(), &ex);
1572 if( libvlc_exception_raised(&ex) )
1574 NPN_SetException(this, libvlc_exception_get_message(&ex));
1575 libvlc_exception_clear(&ex);
1576 return INVOKERESULT_GENERIC_ERROR;
1580 VOID_TO_NPVARIANT(result);
1581 return INVOKERESULT_NO_ERROR;
1584 return INVOKERESULT_NO_SUCH_METHOD;
1585 case ID_playlist_next:
1588 libvlc_playlist_next(p_plugin->getVLC(), &ex);
1589 if( libvlc_exception_raised(&ex) )
1591 NPN_SetException(this, libvlc_exception_get_message(&ex));
1592 libvlc_exception_clear(&ex);
1593 return INVOKERESULT_GENERIC_ERROR;
1597 VOID_TO_NPVARIANT(result);
1598 return INVOKERESULT_NO_ERROR;
1601 return INVOKERESULT_NO_SUCH_METHOD;
1602 case ID_playlist_prev:
1605 libvlc_playlist_prev(p_plugin->getVLC(), &ex);
1606 if( libvlc_exception_raised(&ex) )
1608 NPN_SetException(this, libvlc_exception_get_message(&ex));
1609 libvlc_exception_clear(&ex);
1610 return INVOKERESULT_GENERIC_ERROR;
1614 VOID_TO_NPVARIANT(result);
1615 return INVOKERESULT_NO_ERROR;
1618 return INVOKERESULT_NO_SUCH_METHOD;
1619 case ID_playlist_clear: /* deprecated */
1622 libvlc_playlist_clear(p_plugin->getVLC(), &ex);
1623 if( libvlc_exception_raised(&ex) )
1625 NPN_SetException(this, libvlc_exception_get_message(&ex));
1626 libvlc_exception_clear(&ex);
1627 return INVOKERESULT_GENERIC_ERROR;
1631 VOID_TO_NPVARIANT(result);
1632 return INVOKERESULT_NO_ERROR;
1635 return INVOKERESULT_NO_SUCH_METHOD;
1636 case ID_playlist_removeitem: /* deprecated */
1637 if( (argCount == 1) && isNumberValue(args[0]) )
1639 libvlc_playlist_delete_item(p_plugin->getVLC(), numberValue(args[0]), &ex);
1640 if( libvlc_exception_raised(&ex) )
1642 NPN_SetException(this, libvlc_exception_get_message(&ex));
1643 libvlc_exception_clear(&ex);
1644 return INVOKERESULT_GENERIC_ERROR;
1648 VOID_TO_NPVARIANT(result);
1649 return INVOKERESULT_NO_ERROR;
1652 return INVOKERESULT_NO_SUCH_METHOD;
1657 return INVOKERESULT_GENERIC_ERROR;
1660 void LibvlcPlaylistNPObject::parseOptions(const NPString &nps, int *i_options, char*** ppsz_options)
1662 if( nps.utf8length )
1664 char *s = stringValue(nps);
1669 char **options = (char **)malloc(capacity*sizeof(char *));
1674 char *end = val + nps.utf8length;
1677 // skip leading blanks
1679 && ((*val == ' ' ) || (*val == '\t')) )
1683 // skip till we get a blank character
1689 if( ('\'' == c) || ('"' == c) )
1691 // skip till end of string
1692 while( (val < end) && (*(val++) != c ) );
1698 if( nOptions == capacity )
1701 char **moreOptions = (char **)realloc(options, capacity*sizeof(char*));
1704 /* failed to allocate more memory */
1706 /* return what we got so far */
1707 *i_options = nOptions;
1708 *ppsz_options = options;
1711 options = moreOptions;
1714 options[nOptions++] = strdup(start);
1717 // must be end of string
1720 *i_options = nOptions;
1721 *ppsz_options = options;
1728 void LibvlcPlaylistNPObject::parseOptions(NPObject *obj, int *i_options, char*** ppsz_options)
1730 /* WARNING: Safari does not implement NPN_HasProperty/NPN_HasMethod */
1734 /* we are expecting to have a Javascript Array object */
1735 NPIdentifier propId = NPN_GetStringIdentifier("length");
1736 if( NPN_GetProperty(_instance, obj, propId, &value) )
1738 int count = numberValue(value);
1739 NPN_ReleaseVariantValue(&value);
1744 char **options = (char **)malloc(capacity*sizeof(char *));
1749 while( nOptions < count )
1751 propId = NPN_GetIntIdentifier(nOptions);
1752 if( ! NPN_GetProperty(_instance, obj, propId, &value) )
1753 /* return what we got so far */
1756 if( ! NPVARIANT_IS_STRING(value) )
1758 /* return what we got so far */
1759 NPN_ReleaseVariantValue(&value);
1763 if( nOptions == capacity )
1766 char **moreOptions = (char **)realloc(options, capacity*sizeof(char*));
1769 /* failed to allocate more memory */
1770 NPN_ReleaseVariantValue(&value);
1771 /* return what we got so far */
1772 *i_options = nOptions;
1773 *ppsz_options = options;
1776 options = moreOptions;
1779 options[nOptions++] = stringValue(value);
1781 *i_options = nOptions;
1782 *ppsz_options = options;
1789 ** implementation of libvlc video object
1792 const NPUTF8 * const LibvlcVideoNPObject::propertyNames[] =
1803 enum LibvlcVideoNPObjectPropertyIds
1805 ID_video_fullscreen,
1808 ID_video_aspectratio,
1814 const int LibvlcVideoNPObject::propertyCount = sizeof(LibvlcVideoNPObject::propertyNames)/sizeof(NPUTF8 *);
1816 RuntimeNPObject::InvokeResult LibvlcVideoNPObject::getProperty(int index, NPVariant &result)
1818 /* is plugin still running */
1819 if( _instance->pdata )
1821 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
1822 libvlc_exception_t ex;
1823 libvlc_exception_init(&ex);
1825 libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_plugin->getVLC(), &ex);
1826 if( libvlc_exception_raised(&ex) )
1828 NPN_SetException(this, libvlc_exception_get_message(&ex));
1829 libvlc_exception_clear(&ex);
1830 return INVOKERESULT_GENERIC_ERROR;
1835 case ID_video_fullscreen:
1837 int val = libvlc_get_fullscreen(p_md, &ex);
1838 libvlc_media_player_release(p_md);
1839 if( libvlc_exception_raised(&ex) )
1841 NPN_SetException(this, libvlc_exception_get_message(&ex));
1842 libvlc_exception_clear(&ex);
1843 return INVOKERESULT_GENERIC_ERROR;
1845 BOOLEAN_TO_NPVARIANT(val, result);
1846 return INVOKERESULT_NO_ERROR;
1848 case ID_video_height:
1850 int val = libvlc_video_get_height(p_md, &ex);
1851 libvlc_media_player_release(p_md);
1852 if( libvlc_exception_raised(&ex) )
1854 NPN_SetException(this, libvlc_exception_get_message(&ex));
1855 libvlc_exception_clear(&ex);
1856 return INVOKERESULT_GENERIC_ERROR;
1858 INT32_TO_NPVARIANT(val, result);
1859 return INVOKERESULT_NO_ERROR;
1861 case ID_video_width:
1863 int val = libvlc_video_get_width(p_md, &ex);
1864 libvlc_media_player_release(p_md);
1865 if( libvlc_exception_raised(&ex) )
1867 NPN_SetException(this, libvlc_exception_get_message(&ex));
1868 libvlc_exception_clear(&ex);
1869 return INVOKERESULT_GENERIC_ERROR;
1871 INT32_TO_NPVARIANT(val, result);
1872 return INVOKERESULT_NO_ERROR;
1874 case ID_video_aspectratio:
1876 NPUTF8 *psz_aspect = libvlc_video_get_aspect_ratio(p_md, &ex);
1877 libvlc_media_player_release(p_md);
1878 if( libvlc_exception_raised(&ex) )
1880 NPN_SetException(this, libvlc_exception_get_message(&ex));
1881 libvlc_exception_clear(&ex);
1882 return INVOKERESULT_GENERIC_ERROR;
1885 return INVOKERESULT_GENERIC_ERROR;
1887 STRINGZ_TO_NPVARIANT(psz_aspect, result);
1888 return INVOKERESULT_NO_ERROR;
1890 case ID_video_subtitle:
1892 int i_spu = libvlc_video_get_spu(p_md, &ex);
1893 libvlc_media_player_release(p_md);
1894 if( libvlc_exception_raised(&ex) )
1896 NPN_SetException(this, libvlc_exception_get_message(&ex));
1897 libvlc_exception_clear(&ex);
1898 return INVOKERESULT_GENERIC_ERROR;
1900 INT32_TO_NPVARIANT(i_spu, result);
1901 return INVOKERESULT_NO_ERROR;
1905 NPUTF8 *psz_geometry = libvlc_video_get_crop_geometry(p_md, &ex);
1906 libvlc_media_player_release(p_md);
1907 if( libvlc_exception_raised(&ex) )
1909 NPN_SetException(this, libvlc_exception_get_message(&ex));
1910 libvlc_exception_clear(&ex);
1911 return INVOKERESULT_GENERIC_ERROR;
1914 return INVOKERESULT_GENERIC_ERROR;
1916 STRINGZ_TO_NPVARIANT(psz_geometry, result);
1917 return INVOKERESULT_NO_ERROR;
1919 case ID_video_teletext:
1921 int i_page = libvlc_video_get_teletext(p_md, &ex);
1922 libvlc_media_player_release(p_md);
1923 if( libvlc_exception_raised(&ex) )
1925 NPN_SetException(this, libvlc_exception_get_message(&ex));
1926 libvlc_exception_clear(&ex);
1927 return INVOKERESULT_GENERIC_ERROR;
1929 INT32_TO_NPVARIANT(i_page, result);
1930 return INVOKERESULT_NO_ERROR;
1933 libvlc_media_player_release(p_md);
1935 return INVOKERESULT_GENERIC_ERROR;
1938 RuntimeNPObject::InvokeResult LibvlcVideoNPObject::setProperty(int index, const NPVariant &value)
1940 /* is plugin still running */
1941 if( _instance->pdata )
1943 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
1944 libvlc_exception_t ex;
1945 libvlc_exception_init(&ex);
1947 libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_plugin->getVLC(), &ex);
1948 if( libvlc_exception_raised(&ex) )
1950 NPN_SetException(this, libvlc_exception_get_message(&ex));
1951 libvlc_exception_clear(&ex);
1952 return INVOKERESULT_GENERIC_ERROR;
1957 case ID_video_fullscreen:
1959 if( ! NPVARIANT_IS_BOOLEAN(value) )
1961 libvlc_media_player_release(p_md);
1962 return INVOKERESULT_INVALID_VALUE;
1965 int val = NPVARIANT_TO_BOOLEAN(value);
1966 libvlc_set_fullscreen(p_md, val, &ex);
1967 libvlc_media_player_release(p_md);
1969 if( libvlc_exception_raised(&ex) )
1971 NPN_SetException(this, libvlc_exception_get_message(&ex));
1972 libvlc_exception_clear(&ex);
1973 return INVOKERESULT_GENERIC_ERROR;
1975 return INVOKERESULT_NO_ERROR;
1977 case ID_video_aspectratio:
1979 char *psz_aspect = NULL;
1981 if( ! NPVARIANT_IS_STRING(value) )
1983 libvlc_media_player_release(p_md);
1984 return INVOKERESULT_INVALID_VALUE;
1987 psz_aspect = stringValue(NPVARIANT_TO_STRING(value));
1990 libvlc_media_player_release(p_md);
1991 return INVOKERESULT_GENERIC_ERROR;
1994 libvlc_video_set_aspect_ratio(p_md, psz_aspect, &ex);
1996 libvlc_media_player_release(p_md);
1998 if( libvlc_exception_raised(&ex) )
2000 NPN_SetException(this, libvlc_exception_get_message(&ex));
2001 libvlc_exception_clear(&ex);
2002 return INVOKERESULT_GENERIC_ERROR;
2004 return INVOKERESULT_NO_ERROR;
2006 case ID_video_subtitle:
2008 if( isNumberValue(value) )
2010 libvlc_video_set_spu(p_md,
2011 numberValue(value), &ex);
2012 libvlc_media_player_release(p_md);
2013 if( libvlc_exception_raised(&ex) )
2015 NPN_SetException(this, libvlc_exception_get_message(&ex));
2016 libvlc_exception_clear(&ex);
2017 return INVOKERESULT_GENERIC_ERROR;
2019 return INVOKERESULT_NO_ERROR;
2021 libvlc_media_player_release(p_md);
2022 return INVOKERESULT_INVALID_VALUE;
2026 char *psz_geometry = NULL;
2028 if( ! NPVARIANT_IS_STRING(value) )
2030 libvlc_media_player_release(p_md);
2031 return INVOKERESULT_INVALID_VALUE;
2034 psz_geometry = stringValue(NPVARIANT_TO_STRING(value));
2037 libvlc_media_player_release(p_md);
2038 return INVOKERESULT_GENERIC_ERROR;
2041 libvlc_video_set_crop_geometry(p_md, psz_geometry, &ex);
2043 libvlc_media_player_release(p_md);
2045 if( libvlc_exception_raised(&ex) )
2047 NPN_SetException(this, libvlc_exception_get_message(&ex));
2048 libvlc_exception_clear(&ex);
2049 return INVOKERESULT_GENERIC_ERROR;
2051 return INVOKERESULT_NO_ERROR;
2053 case ID_video_teletext:
2055 if( isNumberValue(value) )
2057 libvlc_video_set_teletext(p_md,
2058 numberValue(value), &ex);
2059 libvlc_media_player_release(p_md);
2060 if( libvlc_exception_raised(&ex) )
2062 NPN_SetException(this, libvlc_exception_get_message(&ex));
2063 libvlc_exception_clear(&ex);
2064 return INVOKERESULT_GENERIC_ERROR;
2066 return INVOKERESULT_NO_ERROR;
2068 libvlc_media_player_release(p_md);
2069 return INVOKERESULT_INVALID_VALUE;
2072 libvlc_media_player_release(p_md);
2074 return INVOKERESULT_GENERIC_ERROR;
2077 const NPUTF8 * const LibvlcVideoNPObject::methodNames[] =
2083 enum LibvlcVideoNPObjectMethodIds
2085 ID_video_togglefullscreen,
2086 ID_video_toggleteletext
2089 const int LibvlcVideoNPObject::methodCount = sizeof(LibvlcVideoNPObject::methodNames)/sizeof(NPUTF8 *);
2091 RuntimeNPObject::InvokeResult LibvlcVideoNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)
2093 /* is plugin still running */
2094 if( _instance->pdata )
2096 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
2097 libvlc_exception_t ex;
2098 libvlc_exception_init(&ex);
2100 libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_plugin->getVLC(), &ex);
2101 if( libvlc_exception_raised(&ex) )
2103 NPN_SetException(this, libvlc_exception_get_message(&ex));
2104 libvlc_exception_clear(&ex);
2105 return INVOKERESULT_GENERIC_ERROR;
2110 case ID_video_togglefullscreen:
2113 libvlc_toggle_fullscreen(p_md, &ex);
2114 libvlc_media_player_release(p_md);
2115 if( libvlc_exception_raised(&ex) )
2117 NPN_SetException(this, libvlc_exception_get_message(&ex));
2118 libvlc_exception_clear(&ex);
2119 return INVOKERESULT_GENERIC_ERROR;
2123 VOID_TO_NPVARIANT(result);
2124 return INVOKERESULT_NO_ERROR;
2129 /* cannot get md, probably not playing */
2130 if( libvlc_exception_raised(&ex) )
2132 NPN_SetException(this, libvlc_exception_get_message(&ex));
2133 libvlc_exception_clear(&ex);
2135 return INVOKERESULT_GENERIC_ERROR;
2137 return INVOKERESULT_NO_SUCH_METHOD;
2138 case ID_video_toggleteletext:
2141 libvlc_toggle_teletext(p_md, &ex);
2142 libvlc_media_player_release(p_md);
2143 if( libvlc_exception_raised(&ex) )
2145 NPN_SetException(this, libvlc_exception_get_message(&ex));
2146 libvlc_exception_clear(&ex);
2147 return INVOKERESULT_GENERIC_ERROR;
2151 VOID_TO_NPVARIANT(result);
2152 return INVOKERESULT_NO_ERROR;
2157 /* cannot get md, probably not playing */
2158 if( libvlc_exception_raised(&ex) )
2160 NPN_SetException(this, libvlc_exception_get_message(&ex));
2161 libvlc_exception_clear(&ex);
2163 return INVOKERESULT_GENERIC_ERROR;
2165 return INVOKERESULT_NO_SUCH_METHOD;
2167 return INVOKERESULT_NO_SUCH_METHOD;
2170 return INVOKERESULT_GENERIC_ERROR;