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"
37 #define COUNTNAMES(a,b,c) const int a::b = sizeof(a::c)/sizeof(NPUTF8 *)
40 ** implementation of libvlc root object
43 LibvlcRootNPObject::~LibvlcRootNPObject()
46 ** When the plugin is destroyed, firefox takes it upon itself to
47 ** destroy all 'live' script objects and ignores refcounting.
48 ** Therefore we cannot safely assume that refcounting will control
49 ** lifespan of objects. Hence they are only lazily created on
50 ** request, so that firefox can take ownership, and are not released
51 ** when the plugin is destroyed.
55 if( audioObj ) NPN_ReleaseObject(audioObj);
56 if( inputObj ) NPN_ReleaseObject(inputObj);
57 if( logObj ) NPN_ReleaseObject(logObj);
58 if( playlistObj ) NPN_ReleaseObject(playlistObj);
59 if( videoObj ) NPN_ReleaseObject(videoObj);
63 const NPUTF8 * const LibvlcRootNPObject::propertyNames[] =
72 COUNTNAMES(LibvlcRootNPObject,propertyCount,propertyNames);
74 enum LibvlcRootNPObjectPropertyIds
84 RuntimeNPObject::InvokeResult
85 LibvlcRootNPObject::getProperty(int index, NPVariant &result)
87 /* is plugin still running */
88 if( _instance->pdata )
93 // create child object in lazyman fashion to avoid
94 // ownership problem with firefox
96 audioObj = NPN_CreateObject(_instance,
97 RuntimeNPClass<LibvlcAudioNPObject>::getClass());
98 OBJECT_TO_NPVARIANT(NPN_RetainObject(audioObj), result);
99 return INVOKERESULT_NO_ERROR;
101 // create child object in lazyman fashion to avoid
102 // ownership problem with firefox
104 inputObj = NPN_CreateObject(_instance,
105 RuntimeNPClass<LibvlcInputNPObject>::getClass());
106 OBJECT_TO_NPVARIANT(NPN_RetainObject(inputObj), result);
107 return INVOKERESULT_NO_ERROR;
109 // create child object in lazyman fashion to avoid
110 // ownership problem with firefox
112 logObj = NPN_CreateObject(_instance,
113 RuntimeNPClass<LibvlcLogNPObject>::getClass());
114 OBJECT_TO_NPVARIANT(NPN_RetainObject(logObj), result);
115 return INVOKERESULT_NO_ERROR;
116 case ID_root_playlist:
117 // create child object in lazyman fashion to avoid
118 // ownership problem with firefox
120 playlistObj = NPN_CreateObject(_instance,
121 RuntimeNPClass<LibvlcPlaylistNPObject>::getClass());
122 OBJECT_TO_NPVARIANT(NPN_RetainObject(playlistObj), result);
123 return INVOKERESULT_NO_ERROR;
125 // create child object in lazyman fashion to avoid
126 // ownership problem with firefox
128 videoObj = NPN_CreateObject(_instance,
129 RuntimeNPClass<LibvlcVideoNPObject>::getClass());
130 OBJECT_TO_NPVARIANT(NPN_RetainObject(videoObj), result);
131 return INVOKERESULT_NO_ERROR;
132 case ID_root_VersionInfo:
134 int len = strlen(libvlc_get_version());
135 NPUTF8 *retval =(NPUTF8*)NPN_MemAlloc(len);
138 memcpy(retval, libvlc_get_version(), len);
139 STRINGN_TO_NPVARIANT(retval, len, result);
143 NULL_TO_NPVARIANT(result);
145 return INVOKERESULT_NO_ERROR;
151 return INVOKERESULT_GENERIC_ERROR;
154 const NPUTF8 * const LibvlcRootNPObject::methodNames[] =
158 COUNTNAMES(LibvlcRootNPObject,methodCount,methodNames);
160 enum LibvlcRootNPObjectMethodIds
165 RuntimeNPObject::InvokeResult LibvlcRootNPObject::invoke(int index,
166 const NPVariant *args, uint32_t argCount, NPVariant &result)
168 /* is plugin still running */
169 if( _instance->pdata )
171 libvlc_exception_t ex;
172 libvlc_exception_init(&ex);
176 case ID_root_versionInfo:
179 int len = strlen(libvlc_get_version());
180 NPUTF8 *retval =(NPUTF8*)NPN_MemAlloc(len);
183 memcpy(retval, libvlc_get_version(), len);
184 STRINGN_TO_NPVARIANT(retval, len, result);
188 NULL_TO_NPVARIANT(result);
190 return INVOKERESULT_NO_ERROR;
192 return INVOKERESULT_NO_SUCH_METHOD;
197 return INVOKERESULT_GENERIC_ERROR;
201 ** implementation of libvlc audio object
204 const NPUTF8 * const LibvlcAudioNPObject::propertyNames[] =
211 COUNTNAMES(LibvlcAudioNPObject,propertyCount,propertyNames);
213 enum LibvlcAudioNPObjectPropertyIds
221 RuntimeNPObject::InvokeResult
222 LibvlcAudioNPObject::getProperty(int index, NPVariant &result)
224 /* is plugin still running */
225 if( _instance->pdata )
227 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
228 libvlc_exception_t ex;
229 libvlc_exception_init(&ex);
235 bool muted = libvlc_audio_get_mute(p_plugin->getVLC(), &ex);
236 if( libvlc_exception_raised(&ex) )
238 NPN_SetException(this, libvlc_exception_get_message(&ex));
239 libvlc_exception_clear(&ex);
240 return INVOKERESULT_GENERIC_ERROR;
242 BOOLEAN_TO_NPVARIANT(muted, result);
243 return INVOKERESULT_NO_ERROR;
245 case ID_audio_volume:
247 int volume = libvlc_audio_get_volume(p_plugin->getVLC(), &ex);
248 if( libvlc_exception_raised(&ex) )
250 NPN_SetException(this, libvlc_exception_get_message(&ex));
251 libvlc_exception_clear(&ex);
252 return INVOKERESULT_GENERIC_ERROR;
254 INT32_TO_NPVARIANT(volume, result);
255 return INVOKERESULT_NO_ERROR;
259 libvlc_media_player_t *p_md =
260 libvlc_playlist_get_media_player(p_plugin->getVLC(), &ex);
261 if( libvlc_exception_raised(&ex) )
263 NPN_SetException(this, libvlc_exception_get_message(&ex));
264 libvlc_exception_clear(&ex);
265 return INVOKERESULT_GENERIC_ERROR;
267 int track = libvlc_audio_get_track(p_md, &ex);
268 libvlc_media_player_release(p_md);
269 if( libvlc_exception_raised(&ex) )
271 NPN_SetException(this, libvlc_exception_get_message(&ex));
272 libvlc_exception_clear(&ex);
273 return INVOKERESULT_GENERIC_ERROR;
275 INT32_TO_NPVARIANT(track, result);
276 return INVOKERESULT_NO_ERROR;
278 case ID_audio_channel:
280 int channel = libvlc_audio_get_channel(p_plugin->getVLC(), &ex);
281 if( libvlc_exception_raised(&ex) )
283 NPN_SetException(this, libvlc_exception_get_message(&ex));
284 libvlc_exception_clear(&ex);
285 return INVOKERESULT_GENERIC_ERROR;
287 INT32_TO_NPVARIANT(channel, result);
288 return INVOKERESULT_NO_ERROR;
294 return INVOKERESULT_GENERIC_ERROR;
297 RuntimeNPObject::InvokeResult
298 LibvlcAudioNPObject::setProperty(int index, const NPVariant &value)
300 /* is plugin still running */
301 if( _instance->pdata )
303 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
304 libvlc_exception_t ex;
305 libvlc_exception_init(&ex);
310 if( NPVARIANT_IS_BOOLEAN(value) )
312 libvlc_audio_set_mute(p_plugin->getVLC(),
313 NPVARIANT_TO_BOOLEAN(value), &ex);
314 if( libvlc_exception_raised(&ex) )
316 NPN_SetException(this, libvlc_exception_get_message(&ex));
317 libvlc_exception_clear(&ex);
318 return INVOKERESULT_GENERIC_ERROR;
320 return INVOKERESULT_NO_ERROR;
322 return INVOKERESULT_INVALID_VALUE;
323 case ID_audio_volume:
324 if( isNumberValue(value) )
326 libvlc_audio_set_volume(p_plugin->getVLC(),
327 numberValue(value), &ex);
328 if( libvlc_exception_raised(&ex) )
330 NPN_SetException(this, libvlc_exception_get_message(&ex));
331 libvlc_exception_clear(&ex);
332 return INVOKERESULT_GENERIC_ERROR;
334 return INVOKERESULT_NO_ERROR;
336 return INVOKERESULT_INVALID_VALUE;
338 if( isNumberValue(value) )
340 libvlc_media_player_t *p_md =
341 libvlc_playlist_get_media_player(p_plugin->getVLC(), &ex);
342 if( libvlc_exception_raised(&ex) )
344 NPN_SetException(this, libvlc_exception_get_message(&ex));
345 libvlc_exception_clear(&ex);
346 return INVOKERESULT_GENERIC_ERROR;
348 libvlc_audio_set_track(p_md,
349 numberValue(value), &ex);
350 libvlc_media_player_release(p_md);
351 if( libvlc_exception_raised(&ex) )
353 NPN_SetException(this, libvlc_exception_get_message(&ex));
354 libvlc_exception_clear(&ex);
355 return INVOKERESULT_GENERIC_ERROR;
357 return INVOKERESULT_NO_ERROR;
359 return INVOKERESULT_INVALID_VALUE;
360 case ID_audio_channel:
361 if( isNumberValue(value) )
363 libvlc_audio_set_channel(p_plugin->getVLC(),
364 numberValue(value), &ex);
365 if( libvlc_exception_raised(&ex) )
367 NPN_SetException(this, libvlc_exception_get_message(&ex));
368 libvlc_exception_clear(&ex);
369 return INVOKERESULT_GENERIC_ERROR;
371 return INVOKERESULT_NO_ERROR;
373 return INVOKERESULT_INVALID_VALUE;
378 return INVOKERESULT_GENERIC_ERROR;
381 const NPUTF8 * const LibvlcAudioNPObject::methodNames[] =
385 COUNTNAMES(LibvlcAudioNPObject,methodCount,methodNames);
387 enum LibvlcAudioNPObjectMethodIds
392 RuntimeNPObject::InvokeResult
393 LibvlcAudioNPObject::invoke(int index, const NPVariant *args,
394 uint32_t argCount, NPVariant &result)
396 /* is plugin still running */
397 if( _instance->pdata )
399 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
400 libvlc_exception_t ex;
401 libvlc_exception_init(&ex);
405 case ID_audio_togglemute:
408 libvlc_audio_toggle_mute(p_plugin->getVLC(), &ex);
409 if( libvlc_exception_raised(&ex) )
411 NPN_SetException(this, libvlc_exception_get_message(&ex));
412 libvlc_exception_clear(&ex);
413 return INVOKERESULT_GENERIC_ERROR;
417 VOID_TO_NPVARIANT(result);
418 return INVOKERESULT_NO_ERROR;
421 return INVOKERESULT_NO_SUCH_METHOD;
426 return INVOKERESULT_GENERIC_ERROR;
430 ** implementation of libvlc input object
433 const NPUTF8 * const LibvlcInputNPObject::propertyNames[] =
443 COUNTNAMES(LibvlcInputNPObject,propertyCount,propertyNames);
445 enum LibvlcInputNPObjectPropertyIds
456 RuntimeNPObject::InvokeResult
457 LibvlcInputNPObject::getProperty(int index, NPVariant &result)
459 /* is plugin still running */
460 if( _instance->pdata )
462 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
463 libvlc_exception_t ex;
464 libvlc_exception_init(&ex);
466 libvlc_media_player_t *p_md =
467 libvlc_playlist_get_media_player(p_plugin->getVLC(), &ex);
468 if( libvlc_exception_raised(&ex) )
470 if( index != ID_input_state )
472 NPN_SetException(this, libvlc_exception_get_message(&ex));
473 libvlc_exception_clear(&ex);
474 return INVOKERESULT_GENERIC_ERROR;
478 /* for input state, return CLOSED rather than an exception */
479 INT32_TO_NPVARIANT(0, result);
480 libvlc_exception_clear(&ex);
481 return INVOKERESULT_NO_ERROR;
487 case ID_input_length:
489 double val = (double)libvlc_media_player_get_length(p_md, &ex);
490 libvlc_media_player_release(p_md);
491 if( libvlc_exception_raised(&ex) )
493 NPN_SetException(this, libvlc_exception_get_message(&ex));
494 libvlc_exception_clear(&ex);
495 return INVOKERESULT_GENERIC_ERROR;
497 DOUBLE_TO_NPVARIANT(val, result);
498 return INVOKERESULT_NO_ERROR;
500 case ID_input_position:
502 double val = libvlc_media_player_get_position(p_md, &ex);
503 libvlc_media_player_release(p_md);
504 if( libvlc_exception_raised(&ex) )
506 NPN_SetException(this, libvlc_exception_get_message(&ex));
507 libvlc_exception_clear(&ex);
508 return INVOKERESULT_GENERIC_ERROR;
510 DOUBLE_TO_NPVARIANT(val, result);
511 return INVOKERESULT_NO_ERROR;
515 double val = (double)libvlc_media_player_get_time(p_md, &ex);
516 libvlc_media_player_release(p_md);
517 if( libvlc_exception_raised(&ex) )
519 NPN_SetException(this, libvlc_exception_get_message(&ex));
520 libvlc_exception_clear(&ex);
521 return INVOKERESULT_GENERIC_ERROR;
523 DOUBLE_TO_NPVARIANT(val, result);
524 return INVOKERESULT_NO_ERROR;
528 int val = libvlc_media_player_get_state(p_md, &ex);
529 libvlc_media_player_release(p_md);
530 if( libvlc_exception_raised(&ex) )
532 NPN_SetException(this, libvlc_exception_get_message(&ex));
533 libvlc_exception_clear(&ex);
534 return INVOKERESULT_GENERIC_ERROR;
536 INT32_TO_NPVARIANT(val, result);
537 return INVOKERESULT_NO_ERROR;
541 float val = libvlc_media_player_get_rate(p_md, &ex);
542 libvlc_media_player_release(p_md);
543 if( libvlc_exception_raised(&ex) )
545 NPN_SetException(this, libvlc_exception_get_message(&ex));
546 libvlc_exception_clear(&ex);
547 return INVOKERESULT_GENERIC_ERROR;
549 DOUBLE_TO_NPVARIANT(val, result);
550 return INVOKERESULT_NO_ERROR;
554 double val = libvlc_media_player_get_fps(p_md, &ex);
555 libvlc_media_player_release(p_md);
556 if( libvlc_exception_raised(&ex) )
558 NPN_SetException(this, libvlc_exception_get_message(&ex));
559 libvlc_exception_clear(&ex);
560 return INVOKERESULT_GENERIC_ERROR;
562 DOUBLE_TO_NPVARIANT(val, result);
563 return INVOKERESULT_NO_ERROR;
565 case ID_input_hasvout:
567 bool val = libvlc_media_player_has_vout(p_md, &ex);
568 libvlc_media_player_release(p_md);
569 if( libvlc_exception_raised(&ex) )
571 NPN_SetException(this, libvlc_exception_get_message(&ex));
572 libvlc_exception_clear(&ex);
573 return INVOKERESULT_GENERIC_ERROR;
575 BOOLEAN_TO_NPVARIANT(val, result);
576 return INVOKERESULT_NO_ERROR;
581 libvlc_media_player_release(p_md);
583 return INVOKERESULT_GENERIC_ERROR;
586 RuntimeNPObject::InvokeResult
587 LibvlcInputNPObject::setProperty(int index, const NPVariant &value)
589 /* is plugin still running */
590 if( _instance->pdata )
592 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
593 libvlc_exception_t ex;
594 libvlc_exception_init(&ex);
596 libvlc_media_player_t *p_md =
597 libvlc_playlist_get_media_player(p_plugin->getVLC(), &ex);
598 if( libvlc_exception_raised(&ex) )
600 NPN_SetException(this, libvlc_exception_get_message(&ex));
601 libvlc_exception_clear(&ex);
602 return INVOKERESULT_GENERIC_ERROR;
607 case ID_input_position:
609 if( ! NPVARIANT_IS_DOUBLE(value) )
611 libvlc_media_player_release(p_md);
612 return INVOKERESULT_INVALID_VALUE;
615 float val = (float)NPVARIANT_TO_DOUBLE(value);
616 libvlc_media_player_set_position(p_md, val, &ex);
617 libvlc_media_player_release(p_md);
618 if( libvlc_exception_raised(&ex) )
620 NPN_SetException(this, libvlc_exception_get_message(&ex));
621 libvlc_exception_clear(&ex);
622 return INVOKERESULT_GENERIC_ERROR;
624 return INVOKERESULT_NO_ERROR;
629 if( NPVARIANT_IS_INT32(value) )
630 val = (int64_t)NPVARIANT_TO_INT32(value);
631 else if( NPVARIANT_IS_DOUBLE(value) )
632 val = (int64_t)NPVARIANT_TO_DOUBLE(value);
635 libvlc_media_player_release(p_md);
636 return INVOKERESULT_INVALID_VALUE;
639 libvlc_media_player_set_time(p_md, val, &ex);
640 libvlc_media_player_release(p_md);
641 if( libvlc_exception_raised(&ex) )
643 NPN_SetException(this, libvlc_exception_get_message(&ex));
644 libvlc_exception_clear(&ex);
645 return INVOKERESULT_GENERIC_ERROR;
647 return INVOKERESULT_NO_ERROR;
652 if( NPVARIANT_IS_INT32(value) )
653 val = (float)NPVARIANT_TO_INT32(value);
654 else if( NPVARIANT_IS_DOUBLE(value) )
655 val = (float)NPVARIANT_TO_DOUBLE(value);
658 libvlc_media_player_release(p_md);
659 return INVOKERESULT_INVALID_VALUE;
662 libvlc_media_player_set_rate(p_md, val, &ex);
663 libvlc_media_player_release(p_md);
664 if( libvlc_exception_raised(&ex) )
666 NPN_SetException(this, libvlc_exception_get_message(&ex));
667 libvlc_exception_clear(&ex);
668 return INVOKERESULT_GENERIC_ERROR;
670 return INVOKERESULT_NO_ERROR;
675 libvlc_media_player_release(p_md);
677 return INVOKERESULT_GENERIC_ERROR;
680 const NPUTF8 * const LibvlcInputNPObject::methodNames[] =
685 COUNTNAMES(LibvlcInputNPObject,methodCount,methodNames);
688 ** implementation of libvlc message object
691 const NPUTF8 * const LibvlcMessageNPObject::propertyNames[] =
699 COUNTNAMES(LibvlcMessageNPObject,propertyCount,propertyNames);
701 enum LibvlcMessageNPObjectPropertyIds
710 RuntimeNPObject::InvokeResult
711 LibvlcMessageNPObject::getProperty(int index, NPVariant &result)
713 /* is plugin still running */
714 if( _instance->pdata )
718 case ID_message_severity:
720 INT32_TO_NPVARIANT(_msg.i_severity, result);
721 return INVOKERESULT_NO_ERROR;
723 case ID_message_type:
727 int len = strlen(_msg.psz_type);
728 NPUTF8* retval = (NPUTF8*)NPN_MemAlloc(len);
731 memcpy(retval, _msg.psz_type, len);
732 STRINGN_TO_NPVARIANT(retval, len, result);
737 NULL_TO_NPVARIANT(result);
739 return INVOKERESULT_NO_ERROR;
741 case ID_message_name:
745 int len = strlen(_msg.psz_name);
746 NPUTF8* retval = (NPUTF8*)NPN_MemAlloc(len);
749 memcpy(retval, _msg.psz_name, len);
750 STRINGN_TO_NPVARIANT(retval, len, result);
755 NULL_TO_NPVARIANT(result);
757 return INVOKERESULT_NO_ERROR;
759 case ID_message_header:
761 if( _msg.psz_header )
763 int len = strlen(_msg.psz_header);
764 NPUTF8* retval = (NPUTF8*)NPN_MemAlloc(len);
767 memcpy(retval, _msg.psz_header, len);
768 STRINGN_TO_NPVARIANT(retval, len, result);
773 NULL_TO_NPVARIANT(result);
775 return INVOKERESULT_NO_ERROR;
777 case ID_message_message:
779 if( _msg.psz_message )
781 int len = strlen(_msg.psz_message);
782 NPUTF8* retval = (NPUTF8*)NPN_MemAlloc(len);
785 memcpy(retval, _msg.psz_message, len);
786 STRINGN_TO_NPVARIANT(retval, len, result);
791 NULL_TO_NPVARIANT(result);
793 return INVOKERESULT_NO_ERROR;
799 return INVOKERESULT_GENERIC_ERROR;
802 const NPUTF8 * const LibvlcMessageNPObject::methodNames[] =
806 COUNTNAMES(LibvlcMessageNPObject,methodCount,methodNames);
809 ** implementation of libvlc message iterator object
812 LibvlcMessageIteratorNPObject::LibvlcMessageIteratorNPObject(NPP instance,
813 const NPClass *aClass) :
814 RuntimeNPObject(instance, aClass),
817 /* is plugin still running */
818 if( instance->pdata )
820 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(instance->pdata);
821 libvlc_log_t *p_log = p_plugin->getLog();
824 _p_iter = libvlc_log_get_iterator(p_log, NULL);
829 LibvlcMessageIteratorNPObject::~LibvlcMessageIteratorNPObject()
832 libvlc_log_iterator_free(_p_iter, NULL);
835 const NPUTF8 * const LibvlcMessageIteratorNPObject::propertyNames[] =
839 COUNTNAMES(LibvlcMessageIteratorNPObject,propertyCount,propertyNames);
841 enum LibvlcMessageIteratorNPObjectPropertyIds
843 ID_messageiterator_hasNext,
846 RuntimeNPObject::InvokeResult
847 LibvlcMessageIteratorNPObject::getProperty(int index, NPVariant &result)
849 /* is plugin still running */
850 if( _instance->pdata )
852 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
855 case ID_messageiterator_hasNext:
857 if( _p_iter && p_plugin->getLog() )
859 libvlc_exception_t ex;
860 libvlc_exception_init(&ex);
862 BOOLEAN_TO_NPVARIANT(
863 libvlc_log_iterator_has_next(_p_iter, &ex), result );
864 if( libvlc_exception_raised(&ex) )
866 NPN_SetException(this, libvlc_exception_get_message(&ex));
867 libvlc_exception_clear(&ex);
868 return INVOKERESULT_GENERIC_ERROR;
873 BOOLEAN_TO_NPVARIANT(0, result);
875 return INVOKERESULT_NO_ERROR;
881 return INVOKERESULT_GENERIC_ERROR;
884 const NPUTF8 * const LibvlcMessageIteratorNPObject::methodNames[] =
888 COUNTNAMES(LibvlcMessageIteratorNPObject,methodCount,methodNames);
890 enum LibvlcMessageIteratorNPObjectMethodIds
892 ID_messageiterator_next,
895 RuntimeNPObject::InvokeResult
896 LibvlcMessageIteratorNPObject::invoke(int index, const NPVariant *args,
897 uint32_t argCount, NPVariant &result)
899 /* is plugin still running */
900 if( _instance->pdata )
902 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
903 libvlc_exception_t ex;
904 libvlc_exception_init(&ex);
908 case ID_messageiterator_next:
911 if( _p_iter && p_plugin->getLog() )
913 struct libvlc_log_message_t buffer;
915 buffer.sizeof_msg = sizeof(buffer);
917 libvlc_log_iterator_next(_p_iter, &buffer, &ex);
918 if( libvlc_exception_raised(&ex) )
920 NPN_SetException(this, libvlc_exception_get_message(&ex));
921 libvlc_exception_clear(&ex);
922 return INVOKERESULT_GENERIC_ERROR;
926 LibvlcMessageNPObject* message =
927 static_cast<LibvlcMessageNPObject*>(
928 NPN_CreateObject(_instance, RuntimeNPClass<
929 LibvlcMessageNPObject>::getClass()));
932 message->setMessage(buffer);
933 OBJECT_TO_NPVARIANT(message, result);
934 return INVOKERESULT_NO_ERROR;
936 return INVOKERESULT_OUT_OF_MEMORY;
939 return INVOKERESULT_GENERIC_ERROR;
941 return INVOKERESULT_NO_SUCH_METHOD;
946 return INVOKERESULT_GENERIC_ERROR;
950 ** implementation of libvlc message object
953 const NPUTF8 * const LibvlcMessagesNPObject::propertyNames[] =
957 COUNTNAMES(LibvlcMessagesNPObject,propertyCount,propertyNames);
959 enum LibvlcMessagesNPObjectPropertyIds
964 RuntimeNPObject::InvokeResult
965 LibvlcMessagesNPObject::getProperty(int index, NPVariant &result)
967 /* is plugin still running */
968 if( _instance->pdata )
970 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
973 case ID_messages_count:
975 libvlc_log_t *p_log = p_plugin->getLog();
978 libvlc_exception_t ex;
979 libvlc_exception_init(&ex);
981 INT32_TO_NPVARIANT(libvlc_log_count(p_log, &ex), result);
982 if( libvlc_exception_raised(&ex) )
984 NPN_SetException(this, libvlc_exception_get_message(&ex));
985 libvlc_exception_clear(&ex);
986 return INVOKERESULT_GENERIC_ERROR;
991 INT32_TO_NPVARIANT(0, result);
993 return INVOKERESULT_NO_ERROR;
999 return INVOKERESULT_GENERIC_ERROR;
1002 const NPUTF8 * const LibvlcMessagesNPObject::methodNames[] =
1007 COUNTNAMES(LibvlcMessagesNPObject,methodCount,methodNames);
1009 enum LibvlcMessagesNPObjectMethodIds
1012 ID_messages_iterator,
1015 RuntimeNPObject::InvokeResult
1016 LibvlcMessagesNPObject::invoke(int index, const NPVariant *args,
1017 uint32_t argCount, NPVariant &result)
1019 /* is plugin still running */
1020 if( _instance->pdata )
1022 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
1023 libvlc_exception_t ex;
1024 libvlc_exception_init(&ex);
1028 case ID_messages_clear:
1031 libvlc_log_t *p_log = p_plugin->getLog();
1034 libvlc_log_clear(p_log, &ex);
1035 if( libvlc_exception_raised(&ex) )
1037 NPN_SetException(this, libvlc_exception_get_message(&ex));
1038 libvlc_exception_clear(&ex);
1039 return INVOKERESULT_GENERIC_ERROR;
1042 return INVOKERESULT_NO_ERROR;
1044 return INVOKERESULT_NO_SUCH_METHOD;
1046 case ID_messages_iterator:
1049 LibvlcMessageIteratorNPObject* iter =
1050 static_cast<LibvlcMessageIteratorNPObject*>(
1051 NPN_CreateObject(_instance, RuntimeNPClass<
1052 LibvlcMessageIteratorNPObject>::getClass()));
1055 OBJECT_TO_NPVARIANT(iter, result);
1056 return INVOKERESULT_NO_ERROR;
1058 return INVOKERESULT_OUT_OF_MEMORY;
1060 return INVOKERESULT_NO_SUCH_METHOD;
1066 return INVOKERESULT_GENERIC_ERROR;
1071 ** implementation of libvlc message object
1075 LibvlcLogNPObject::~LibvlcLogNPObject()
1079 if( messagesObj ) NPN_ReleaseObject(messagesObj);
1083 const NPUTF8 * const LibvlcLogNPObject::propertyNames[] =
1088 COUNTNAMES(LibvlcLogNPObject,propertyCount,propertyNames);
1090 enum LibvlcLogNPObjectPropertyIds
1096 RuntimeNPObject::InvokeResult
1097 LibvlcLogNPObject::getProperty(int index, NPVariant &result)
1099 /* is plugin still running */
1100 if( _instance->pdata )
1102 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
1103 libvlc_exception_t ex;
1104 libvlc_exception_init(&ex);
1108 case ID_log_messages:
1110 // create child object in lazyman fashion to avoid
1111 // ownership problem with firefox
1113 messagesObj = NPN_CreateObject(_instance,
1114 RuntimeNPClass<LibvlcMessagesNPObject>::getClass());
1115 OBJECT_TO_NPVARIANT(NPN_RetainObject(messagesObj), result);
1116 return INVOKERESULT_NO_ERROR;
1118 case ID_log_verbosity:
1120 if( p_plugin->getLog() )
1122 INT32_TO_NPVARIANT( libvlc_get_log_verbosity(
1123 p_plugin->getVLC(), &ex), result);
1124 if( libvlc_exception_raised(&ex) )
1126 NPN_SetException(this, libvlc_exception_get_message(&ex));
1127 libvlc_exception_clear(&ex);
1128 return INVOKERESULT_GENERIC_ERROR;
1133 /* log is not enabled, return -1 */
1134 DOUBLE_TO_NPVARIANT(-1.0, result);
1136 return INVOKERESULT_NO_ERROR;
1142 return INVOKERESULT_GENERIC_ERROR;
1145 RuntimeNPObject::InvokeResult
1146 LibvlcLogNPObject::setProperty(int index, const NPVariant &value)
1148 /* is plugin still running */
1149 if( _instance->pdata )
1151 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
1152 libvlc_exception_t ex;
1153 libvlc_exception_init(&ex);
1157 case ID_log_verbosity:
1158 if( isNumberValue(value) )
1160 libvlc_instance_t* p_libvlc = p_plugin->getVLC();
1161 libvlc_log_t *p_log = p_plugin->getLog();
1162 int verbosity = numberValue(value);
1163 if( verbosity >= 0 )
1167 p_log = libvlc_log_open(p_libvlc, &ex);
1168 if( libvlc_exception_raised(&ex) )
1170 NPN_SetException(this, libvlc_exception_get_message(&ex));
1171 libvlc_exception_clear(&ex);
1172 return INVOKERESULT_GENERIC_ERROR;
1174 p_plugin->setLog(p_log);
1176 libvlc_set_log_verbosity(p_libvlc, (unsigned)verbosity, &ex);
1177 if( libvlc_exception_raised(&ex) )
1179 NPN_SetException(this, libvlc_exception_get_message(&ex));
1180 libvlc_exception_clear(&ex);
1181 return INVOKERESULT_GENERIC_ERROR;
1186 /* close log when verbosity is set to -1 */
1187 p_plugin->setLog(NULL);
1188 libvlc_log_close(p_log, &ex);
1189 if( libvlc_exception_raised(&ex) )
1191 NPN_SetException(this, libvlc_exception_get_message(&ex));
1192 libvlc_exception_clear(&ex);
1193 return INVOKERESULT_GENERIC_ERROR;
1196 return INVOKERESULT_NO_ERROR;
1198 return INVOKERESULT_INVALID_VALUE;
1203 return INVOKERESULT_GENERIC_ERROR;
1206 const NPUTF8 * const LibvlcLogNPObject::methodNames[] =
1210 COUNTNAMES(LibvlcLogNPObject,methodCount,methodNames);
1213 ** implementation of libvlc playlist items object
1216 const NPUTF8 * const LibvlcPlaylistItemsNPObject::propertyNames[] =
1220 COUNTNAMES(LibvlcPlaylistItemsNPObject,propertyCount,propertyNames);
1222 enum LibvlcPlaylistItemsNPObjectPropertyIds
1224 ID_playlistitems_count,
1227 RuntimeNPObject::InvokeResult
1228 LibvlcPlaylistItemsNPObject::getProperty(int index, NPVariant &result)
1230 /* is plugin still running */
1231 if( _instance->pdata )
1233 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
1234 libvlc_exception_t ex;
1235 libvlc_exception_init(&ex);
1239 case ID_playlistitems_count:
1241 libvlc_playlist_lock(p_plugin->getVLC());
1242 int val = libvlc_playlist_items_count(p_plugin->getVLC(), &ex);
1243 libvlc_playlist_unlock(p_plugin->getVLC());
1244 if( libvlc_exception_raised(&ex) )
1246 NPN_SetException(this, libvlc_exception_get_message(&ex));
1247 libvlc_exception_clear(&ex);
1248 return INVOKERESULT_GENERIC_ERROR;
1250 INT32_TO_NPVARIANT(val, result);
1251 return INVOKERESULT_NO_ERROR;
1257 return INVOKERESULT_GENERIC_ERROR;
1260 const NPUTF8 * const LibvlcPlaylistItemsNPObject::methodNames[] =
1265 COUNTNAMES(LibvlcPlaylistItemsNPObject,methodCount,methodNames);
1267 enum LibvlcPlaylistItemsNPObjectMethodIds
1269 ID_playlistitems_clear,
1270 ID_playlistitems_remove,
1273 RuntimeNPObject::InvokeResult
1274 LibvlcPlaylistItemsNPObject::invoke(int index, const NPVariant *args,
1275 uint32_t argCount, NPVariant &result)
1277 /* is plugin still running */
1278 if( _instance->pdata )
1280 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
1281 libvlc_exception_t ex;
1282 libvlc_exception_init(&ex);
1286 case ID_playlistitems_clear:
1289 libvlc_playlist_clear(p_plugin->getVLC(), &ex);
1290 if( libvlc_exception_raised(&ex) )
1292 NPN_SetException(this, libvlc_exception_get_message(&ex));
1293 libvlc_exception_clear(&ex);
1294 return INVOKERESULT_GENERIC_ERROR;
1298 VOID_TO_NPVARIANT(result);
1299 return INVOKERESULT_NO_ERROR;
1302 return INVOKERESULT_NO_SUCH_METHOD;
1303 case ID_playlistitems_remove:
1304 if( (argCount == 1) && isNumberValue(args[0]) )
1306 libvlc_playlist_delete_item(p_plugin->getVLC(),
1307 numberValue(args[0]), &ex);
1308 if( libvlc_exception_raised(&ex) )
1310 NPN_SetException(this, libvlc_exception_get_message(&ex));
1311 libvlc_exception_clear(&ex);
1312 return INVOKERESULT_GENERIC_ERROR;
1316 VOID_TO_NPVARIANT(result);
1317 return INVOKERESULT_NO_ERROR;
1320 return INVOKERESULT_NO_SUCH_METHOD;
1325 return INVOKERESULT_GENERIC_ERROR;
1329 ** implementation of libvlc playlist object
1333 LibvlcPlaylistNPObject::~LibvlcPlaylistNPObject()
1337 if( playlistItemsObj ) NPN_ReleaseObject(playlistItemsObj);
1341 const NPUTF8 * const LibvlcPlaylistNPObject::propertyNames[] =
1343 "itemCount", /* deprecated */
1347 COUNTNAMES(LibvlcPlaylistNPObject,propertyCount,propertyNames);
1349 enum LibvlcPlaylistNPObjectPropertyIds
1351 ID_playlist_itemcount,
1352 ID_playlist_isplaying,
1356 RuntimeNPObject::InvokeResult
1357 LibvlcPlaylistNPObject::getProperty(int index, NPVariant &result)
1359 /* is plugin still running */
1360 if( _instance->pdata )
1362 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
1363 libvlc_exception_t ex;
1364 libvlc_exception_init(&ex);
1368 case ID_playlist_itemcount: /* deprecated */
1370 libvlc_playlist_lock(p_plugin->getVLC());
1371 int val = libvlc_playlist_items_count(p_plugin->getVLC(), &ex);
1372 libvlc_playlist_unlock(p_plugin->getVLC());
1373 if( libvlc_exception_raised(&ex) )
1375 NPN_SetException(this, libvlc_exception_get_message(&ex));
1376 libvlc_exception_clear(&ex);
1377 return INVOKERESULT_GENERIC_ERROR;
1379 INT32_TO_NPVARIANT(val, result);
1380 return INVOKERESULT_NO_ERROR;
1382 case ID_playlist_isplaying:
1384 libvlc_playlist_lock(p_plugin->getVLC());
1385 int val = libvlc_playlist_isplaying(p_plugin->getVLC(), &ex);
1386 libvlc_playlist_unlock(p_plugin->getVLC());
1387 if( libvlc_exception_raised(&ex) )
1389 NPN_SetException(this, libvlc_exception_get_message(&ex));
1390 libvlc_exception_clear(&ex);
1391 return INVOKERESULT_GENERIC_ERROR;
1393 BOOLEAN_TO_NPVARIANT(val, result);
1394 return INVOKERESULT_NO_ERROR;
1396 case ID_playlist_items:
1398 // create child object in lazyman fashion to avoid
1399 // ownership problem with firefox
1400 if( ! playlistItemsObj )
1402 NPN_CreateObject(_instance, RuntimeNPClass<
1403 LibvlcPlaylistItemsNPObject>::getClass());
1404 OBJECT_TO_NPVARIANT(NPN_RetainObject(playlistItemsObj), result);
1405 return INVOKERESULT_NO_ERROR;
1411 return INVOKERESULT_GENERIC_ERROR;
1414 const NPUTF8 * const LibvlcPlaylistNPObject::methodNames[] =
1423 "clear", /* deprecated */
1424 "removeItem", /* deprecated */
1426 COUNTNAMES(LibvlcPlaylistNPObject,methodCount,methodNames);
1428 enum LibvlcPlaylistNPObjectMethodIds
1432 ID_playlist_playItem,
1433 ID_playlist_togglepause,
1438 ID_playlist_removeitem
1441 RuntimeNPObject::InvokeResult
1442 LibvlcPlaylistNPObject::invoke(int index, const NPVariant *args,
1443 uint32_t argCount, NPVariant &result)
1445 /* is plugin still running */
1446 if( _instance->pdata )
1448 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
1449 libvlc_exception_t ex;
1450 libvlc_exception_init(&ex);
1454 case ID_playlist_add:
1456 if( (argCount < 1) || (argCount > 3) )
1457 return INVOKERESULT_NO_SUCH_METHOD;
1462 if( NPVARIANT_IS_STRING(args[0]) )
1464 char *s = stringValue(NPVARIANT_TO_STRING(args[0]));
1467 url = p_plugin->getAbsoluteURL(s);
1471 // problem with combining url, use argument
1475 return INVOKERESULT_OUT_OF_MEMORY;
1478 return INVOKERESULT_NO_SUCH_METHOD;
1482 // grab name if available
1485 if( NPVARIANT_IS_NULL(args[1]) )
1489 else if( NPVARIANT_IS_STRING(args[1]) )
1491 name = stringValue(NPVARIANT_TO_STRING(args[1]));
1496 return INVOKERESULT_INVALID_VALUE;
1501 char** ppsz_options = NULL;
1503 // grab options if available
1506 if( NPVARIANT_IS_NULL(args[2]) )
1510 else if( NPVARIANT_IS_STRING(args[2]) )
1512 parseOptions(NPVARIANT_TO_STRING(args[2]),
1513 &i_options, &ppsz_options);
1516 else if( NPVARIANT_IS_OBJECT(args[2]) )
1518 parseOptions(NPVARIANT_TO_OBJECT(args[2]),
1519 &i_options, &ppsz_options);
1525 return INVOKERESULT_INVALID_VALUE;
1529 int item = libvlc_playlist_add_extended_untrusted(
1530 p_plugin->getVLC(), url, name, i_options,
1531 const_cast<const char **>(ppsz_options), &ex);
1534 for( int i=0; i< i_options; ++i )
1536 free(ppsz_options[i]);
1540 if( libvlc_exception_raised(&ex) )
1542 NPN_SetException(this, libvlc_exception_get_message(&ex));
1543 libvlc_exception_clear(&ex);
1544 return INVOKERESULT_GENERIC_ERROR;
1548 INT32_TO_NPVARIANT(item, result);
1549 return INVOKERESULT_NO_ERROR;
1552 case ID_playlist_play:
1555 libvlc_playlist_play(p_plugin->getVLC(), -1, 0, NULL, &ex);
1556 if( libvlc_exception_raised(&ex) )
1558 NPN_SetException(this, libvlc_exception_get_message(&ex));
1559 libvlc_exception_clear(&ex);
1560 return INVOKERESULT_GENERIC_ERROR;
1564 VOID_TO_NPVARIANT(result);
1565 return INVOKERESULT_NO_ERROR;
1568 return INVOKERESULT_NO_SUCH_METHOD;
1569 case ID_playlist_playItem:
1570 if( (argCount == 1) && isNumberValue(args[0]) )
1572 libvlc_playlist_play(p_plugin->getVLC(),
1573 numberValue(args[0]), 0, NULL, &ex);
1574 if( libvlc_exception_raised(&ex) )
1576 NPN_SetException(this, libvlc_exception_get_message(&ex));
1577 libvlc_exception_clear(&ex);
1578 return INVOKERESULT_GENERIC_ERROR;
1582 VOID_TO_NPVARIANT(result);
1583 return INVOKERESULT_NO_ERROR;
1586 return INVOKERESULT_NO_SUCH_METHOD;
1587 case ID_playlist_togglepause:
1590 libvlc_playlist_pause(p_plugin->getVLC(), &ex);
1591 if( libvlc_exception_raised(&ex) )
1593 NPN_SetException(this, libvlc_exception_get_message(&ex));
1594 libvlc_exception_clear(&ex);
1595 return INVOKERESULT_GENERIC_ERROR;
1599 VOID_TO_NPVARIANT(result);
1600 return INVOKERESULT_NO_ERROR;
1603 return INVOKERESULT_NO_SUCH_METHOD;
1604 case ID_playlist_stop:
1607 libvlc_playlist_stop(p_plugin->getVLC(), &ex);
1608 if( libvlc_exception_raised(&ex) )
1610 NPN_SetException(this, libvlc_exception_get_message(&ex));
1611 libvlc_exception_clear(&ex);
1612 return INVOKERESULT_GENERIC_ERROR;
1616 VOID_TO_NPVARIANT(result);
1617 return INVOKERESULT_NO_ERROR;
1620 return INVOKERESULT_NO_SUCH_METHOD;
1621 case ID_playlist_next:
1624 libvlc_playlist_next(p_plugin->getVLC(), &ex);
1625 if( libvlc_exception_raised(&ex) )
1627 NPN_SetException(this, libvlc_exception_get_message(&ex));
1628 libvlc_exception_clear(&ex);
1629 return INVOKERESULT_GENERIC_ERROR;
1633 VOID_TO_NPVARIANT(result);
1634 return INVOKERESULT_NO_ERROR;
1637 return INVOKERESULT_NO_SUCH_METHOD;
1638 case ID_playlist_prev:
1641 libvlc_playlist_prev(p_plugin->getVLC(), &ex);
1642 if( libvlc_exception_raised(&ex) )
1644 NPN_SetException(this, libvlc_exception_get_message(&ex));
1645 libvlc_exception_clear(&ex);
1646 return INVOKERESULT_GENERIC_ERROR;
1650 VOID_TO_NPVARIANT(result);
1651 return INVOKERESULT_NO_ERROR;
1654 return INVOKERESULT_NO_SUCH_METHOD;
1655 case ID_playlist_clear: /* deprecated */
1658 libvlc_playlist_clear(p_plugin->getVLC(), &ex);
1659 if( libvlc_exception_raised(&ex) )
1661 NPN_SetException(this, libvlc_exception_get_message(&ex));
1662 libvlc_exception_clear(&ex);
1663 return INVOKERESULT_GENERIC_ERROR;
1667 VOID_TO_NPVARIANT(result);
1668 return INVOKERESULT_NO_ERROR;
1671 return INVOKERESULT_NO_SUCH_METHOD;
1672 case ID_playlist_removeitem: /* deprecated */
1673 if( (argCount == 1) && isNumberValue(args[0]) )
1675 libvlc_playlist_delete_item(p_plugin->getVLC(),
1676 numberValue(args[0]), &ex);
1677 if( libvlc_exception_raised(&ex) )
1679 NPN_SetException(this, libvlc_exception_get_message(&ex));
1680 libvlc_exception_clear(&ex);
1681 return INVOKERESULT_GENERIC_ERROR;
1685 VOID_TO_NPVARIANT(result);
1686 return INVOKERESULT_NO_ERROR;
1689 return INVOKERESULT_NO_SUCH_METHOD;
1694 return INVOKERESULT_GENERIC_ERROR;
1697 void LibvlcPlaylistNPObject::parseOptions(const NPString &nps,
1698 int *i_options, char*** ppsz_options)
1700 if( nps.utf8length )
1702 char *s = stringValue(nps);
1707 char **options = (char **)malloc(capacity*sizeof(char *));
1712 char *end = val + nps.utf8length;
1715 // skip leading blanks
1717 && ((*val == ' ' ) || (*val == '\t')) )
1721 // skip till we get a blank character
1727 if( ('\'' == c) || ('"' == c) )
1729 // skip till end of string
1730 while( (val < end) && (*(val++) != c ) );
1736 if( nOptions == capacity )
1739 char **moreOptions = (char **)realloc(options, capacity*sizeof(char*));
1742 /* failed to allocate more memory */
1744 /* return what we got so far */
1745 *i_options = nOptions;
1746 *ppsz_options = options;
1749 options = moreOptions;
1752 options[nOptions++] = strdup(start);
1755 // must be end of string
1758 *i_options = nOptions;
1759 *ppsz_options = options;
1766 void LibvlcPlaylistNPObject::parseOptions(NPObject *obj, int *i_options,
1767 char*** ppsz_options)
1769 /* WARNING: Safari does not implement NPN_HasProperty/NPN_HasMethod */
1773 /* we are expecting to have a Javascript Array object */
1774 NPIdentifier propId = NPN_GetStringIdentifier("length");
1775 if( NPN_GetProperty(_instance, obj, propId, &value) )
1777 int count = numberValue(value);
1778 NPN_ReleaseVariantValue(&value);
1783 char **options = (char **)malloc(capacity*sizeof(char *));
1788 while( nOptions < count )
1790 propId = NPN_GetIntIdentifier(nOptions);
1791 if( ! NPN_GetProperty(_instance, obj, propId, &value) )
1792 /* return what we got so far */
1795 if( ! NPVARIANT_IS_STRING(value) )
1797 /* return what we got so far */
1798 NPN_ReleaseVariantValue(&value);
1802 if( nOptions == capacity )
1805 char **moreOptions = (char **)realloc(options, capacity*sizeof(char*));
1808 /* failed to allocate more memory */
1809 NPN_ReleaseVariantValue(&value);
1810 /* return what we got so far */
1811 *i_options = nOptions;
1812 *ppsz_options = options;
1815 options = moreOptions;
1818 options[nOptions++] = stringValue(value);
1820 *i_options = nOptions;
1821 *ppsz_options = options;
1828 ** implementation of libvlc video object
1831 const NPUTF8 * const LibvlcVideoNPObject::propertyNames[] =
1842 enum LibvlcVideoNPObjectPropertyIds
1844 ID_video_fullscreen,
1847 ID_video_aspectratio,
1852 COUNTNAMES(LibvlcVideoNPObject,propertyCount,propertyNames);
1854 RuntimeNPObject::InvokeResult
1855 LibvlcVideoNPObject::getProperty(int index, NPVariant &result)
1857 /* is plugin still running */
1858 if( _instance->pdata )
1860 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
1861 libvlc_exception_t ex;
1862 libvlc_exception_init(&ex);
1864 libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_plugin->getVLC(), &ex);
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;
1874 case ID_video_fullscreen:
1876 int val = libvlc_get_fullscreen(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;
1884 BOOLEAN_TO_NPVARIANT(val, result);
1885 return INVOKERESULT_NO_ERROR;
1887 case ID_video_height:
1889 int val = libvlc_video_get_height(p_md, &ex);
1890 libvlc_media_player_release(p_md);
1891 if( libvlc_exception_raised(&ex) )
1893 NPN_SetException(this, libvlc_exception_get_message(&ex));
1894 libvlc_exception_clear(&ex);
1895 return INVOKERESULT_GENERIC_ERROR;
1897 INT32_TO_NPVARIANT(val, result);
1898 return INVOKERESULT_NO_ERROR;
1900 case ID_video_width:
1902 int val = libvlc_video_get_width(p_md, &ex);
1903 libvlc_media_player_release(p_md);
1904 if( libvlc_exception_raised(&ex) )
1906 NPN_SetException(this, libvlc_exception_get_message(&ex));
1907 libvlc_exception_clear(&ex);
1908 return INVOKERESULT_GENERIC_ERROR;
1910 INT32_TO_NPVARIANT(val, result);
1911 return INVOKERESULT_NO_ERROR;
1913 case ID_video_aspectratio:
1915 NPUTF8 *psz_aspect = libvlc_video_get_aspect_ratio(p_md, &ex);
1916 libvlc_media_player_release(p_md);
1917 if( libvlc_exception_raised(&ex) )
1919 NPN_SetException(this, libvlc_exception_get_message(&ex));
1920 libvlc_exception_clear(&ex);
1921 return INVOKERESULT_GENERIC_ERROR;
1924 return INVOKERESULT_GENERIC_ERROR;
1926 STRINGZ_TO_NPVARIANT(psz_aspect, result);
1927 return INVOKERESULT_NO_ERROR;
1929 case ID_video_subtitle:
1931 int i_spu = libvlc_video_get_spu(p_md, &ex);
1932 libvlc_media_player_release(p_md);
1933 if( libvlc_exception_raised(&ex) )
1935 NPN_SetException(this, libvlc_exception_get_message(&ex));
1936 libvlc_exception_clear(&ex);
1937 return INVOKERESULT_GENERIC_ERROR;
1939 INT32_TO_NPVARIANT(i_spu, result);
1940 return INVOKERESULT_NO_ERROR;
1944 NPUTF8 *psz_geometry = libvlc_video_get_crop_geometry(p_md, &ex);
1945 libvlc_media_player_release(p_md);
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;
1953 return INVOKERESULT_GENERIC_ERROR;
1955 STRINGZ_TO_NPVARIANT(psz_geometry, result);
1956 return INVOKERESULT_NO_ERROR;
1958 case ID_video_teletext:
1960 int i_page = libvlc_video_get_teletext(p_md, &ex);
1961 libvlc_media_player_release(p_md);
1962 if( libvlc_exception_raised(&ex) )
1964 NPN_SetException(this, libvlc_exception_get_message(&ex));
1965 libvlc_exception_clear(&ex);
1966 return INVOKERESULT_GENERIC_ERROR;
1968 INT32_TO_NPVARIANT(i_page, result);
1969 return INVOKERESULT_NO_ERROR;
1972 libvlc_media_player_release(p_md);
1974 return INVOKERESULT_GENERIC_ERROR;
1977 RuntimeNPObject::InvokeResult
1978 LibvlcVideoNPObject::setProperty(int index, const NPVariant &value)
1980 /* is plugin still running */
1981 if( _instance->pdata )
1983 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
1984 libvlc_exception_t ex;
1985 libvlc_exception_init(&ex);
1987 libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_plugin->getVLC(), &ex);
1988 if( libvlc_exception_raised(&ex) )
1990 NPN_SetException(this, libvlc_exception_get_message(&ex));
1991 libvlc_exception_clear(&ex);
1992 return INVOKERESULT_GENERIC_ERROR;
1997 case ID_video_fullscreen:
1999 if( ! NPVARIANT_IS_BOOLEAN(value) )
2001 libvlc_media_player_release(p_md);
2002 return INVOKERESULT_INVALID_VALUE;
2005 int val = NPVARIANT_TO_BOOLEAN(value);
2006 libvlc_set_fullscreen(p_md, val, &ex);
2007 libvlc_media_player_release(p_md);
2009 if( libvlc_exception_raised(&ex) )
2011 NPN_SetException(this, libvlc_exception_get_message(&ex));
2012 libvlc_exception_clear(&ex);
2013 return INVOKERESULT_GENERIC_ERROR;
2015 return INVOKERESULT_NO_ERROR;
2017 case ID_video_aspectratio:
2019 char *psz_aspect = NULL;
2021 if( ! NPVARIANT_IS_STRING(value) )
2023 libvlc_media_player_release(p_md);
2024 return INVOKERESULT_INVALID_VALUE;
2027 psz_aspect = stringValue(NPVARIANT_TO_STRING(value));
2030 libvlc_media_player_release(p_md);
2031 return INVOKERESULT_GENERIC_ERROR;
2034 libvlc_video_set_aspect_ratio(p_md, psz_aspect, &ex);
2036 libvlc_media_player_release(p_md);
2038 if( libvlc_exception_raised(&ex) )
2040 NPN_SetException(this, libvlc_exception_get_message(&ex));
2041 libvlc_exception_clear(&ex);
2042 return INVOKERESULT_GENERIC_ERROR;
2044 return INVOKERESULT_NO_ERROR;
2046 case ID_video_subtitle:
2048 if( isNumberValue(value) )
2050 libvlc_video_set_spu(p_md,
2051 numberValue(value), &ex);
2052 libvlc_media_player_release(p_md);
2053 if( libvlc_exception_raised(&ex) )
2055 NPN_SetException(this, libvlc_exception_get_message(&ex));
2056 libvlc_exception_clear(&ex);
2057 return INVOKERESULT_GENERIC_ERROR;
2059 return INVOKERESULT_NO_ERROR;
2061 libvlc_media_player_release(p_md);
2062 return INVOKERESULT_INVALID_VALUE;
2066 char *psz_geometry = NULL;
2068 if( ! NPVARIANT_IS_STRING(value) )
2070 libvlc_media_player_release(p_md);
2071 return INVOKERESULT_INVALID_VALUE;
2074 psz_geometry = stringValue(NPVARIANT_TO_STRING(value));
2077 libvlc_media_player_release(p_md);
2078 return INVOKERESULT_GENERIC_ERROR;
2081 libvlc_video_set_crop_geometry(p_md, psz_geometry, &ex);
2083 libvlc_media_player_release(p_md);
2085 if( libvlc_exception_raised(&ex) )
2087 NPN_SetException(this, libvlc_exception_get_message(&ex));
2088 libvlc_exception_clear(&ex);
2089 return INVOKERESULT_GENERIC_ERROR;
2091 return INVOKERESULT_NO_ERROR;
2093 case ID_video_teletext:
2095 if( isNumberValue(value) )
2097 libvlc_video_set_teletext(p_md,
2098 numberValue(value), &ex);
2099 libvlc_media_player_release(p_md);
2100 if( libvlc_exception_raised(&ex) )
2102 NPN_SetException(this, libvlc_exception_get_message(&ex));
2103 libvlc_exception_clear(&ex);
2104 return INVOKERESULT_GENERIC_ERROR;
2106 return INVOKERESULT_NO_ERROR;
2108 libvlc_media_player_release(p_md);
2109 return INVOKERESULT_INVALID_VALUE;
2112 libvlc_media_player_release(p_md);
2114 return INVOKERESULT_GENERIC_ERROR;
2117 const NPUTF8 * const LibvlcVideoNPObject::methodNames[] =
2122 COUNTNAMES(LibvlcVideoNPObject,methodCount,methodNames);
2124 enum LibvlcVideoNPObjectMethodIds
2126 ID_video_togglefullscreen,
2127 ID_video_toggleteletext
2130 RuntimeNPObject::InvokeResult
2131 LibvlcVideoNPObject::invoke(int index, const NPVariant *args,
2132 uint32_t argCount, NPVariant &result)
2134 /* is plugin still running */
2135 if( _instance->pdata )
2137 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
2138 libvlc_exception_t ex;
2139 libvlc_exception_init(&ex);
2141 libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_plugin->getVLC(), &ex);
2142 if( libvlc_exception_raised(&ex) )
2144 NPN_SetException(this, libvlc_exception_get_message(&ex));
2145 libvlc_exception_clear(&ex);
2146 return INVOKERESULT_GENERIC_ERROR;
2151 case ID_video_togglefullscreen:
2154 libvlc_toggle_fullscreen(p_md, &ex);
2155 libvlc_media_player_release(p_md);
2156 if( libvlc_exception_raised(&ex) )
2158 NPN_SetException(this, libvlc_exception_get_message(&ex));
2159 libvlc_exception_clear(&ex);
2160 return INVOKERESULT_GENERIC_ERROR;
2164 VOID_TO_NPVARIANT(result);
2165 return INVOKERESULT_NO_ERROR;
2170 /* cannot get md, probably not playing */
2171 if( libvlc_exception_raised(&ex) )
2173 NPN_SetException(this, libvlc_exception_get_message(&ex));
2174 libvlc_exception_clear(&ex);
2176 return INVOKERESULT_GENERIC_ERROR;
2178 return INVOKERESULT_NO_SUCH_METHOD;
2179 case ID_video_toggleteletext:
2182 libvlc_toggle_teletext(p_md, &ex);
2183 libvlc_media_player_release(p_md);
2184 if( libvlc_exception_raised(&ex) )
2186 NPN_SetException(this, libvlc_exception_get_message(&ex));
2187 libvlc_exception_clear(&ex);
2188 return INVOKERESULT_GENERIC_ERROR;
2192 VOID_TO_NPVARIANT(result);
2193 return INVOKERESULT_NO_ERROR;
2198 /* cannot get md, probably not playing */
2199 if( libvlc_exception_raised(&ex) )
2201 NPN_SetException(this, libvlc_exception_get_message(&ex));
2202 libvlc_exception_clear(&ex);
2204 return INVOKERESULT_GENERIC_ERROR;
2206 return INVOKERESULT_NO_SUCH_METHOD;
2208 return INVOKERESULT_NO_SUCH_METHOD;
2211 return INVOKERESULT_GENERIC_ERROR;