1 /*****************************************************************************
\r
2 * npolibvlc.cpp: official Javascript APIs
\r
3 *****************************************************************************
\r
4 * Copyright (C) 2002-2006 the VideoLAN team
\r
6 * Authors: Damien Fouilleul <Damien.Fouilleul@laposte.net>
\r
8 * This program is free software; you can redistribute it and/or modify
\r
9 * it under the terms of the GNU General Public License as published by
\r
10 * the Free Software Foundation; either version 2 of the License, or
\r
11 * (at your option) any later version.
\r
13 * This program is distributed in the hope that it will be useful,
\r
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
16 * GNU General Public License for more details.
\r
18 * You should have received a copy of the GNU General Public License
\r
19 * along with this program; if not, write to the Free Software
\r
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
\r
21 *****************************************************************************/
\r
30 #ifdef HAVE_MOZILLA_CONFIG_H
\r
31 # include <mozilla-config.h>
\r
34 #include "npolibvlc.h"
\r
35 #include "vlcplugin.h"
\r
38 ** implementation of libvlc root object
\r
41 LibvlcRootNPObject::LibvlcRootNPObject(NPP instance, const NPClass *aClass) :
\r
42 RuntimeNPObject(instance, aClass)
\r
44 audioObj = NPN_CreateObject(instance, RuntimeNPClass<LibvlcAudioNPObject>::getClass());
\r
45 inputObj = NPN_CreateObject(instance, RuntimeNPClass<LibvlcInputNPObject>::getClass());
\r
46 logObj = NPN_CreateObject(instance, RuntimeNPClass<LibvlcLogNPObject>::getClass());
\r
47 playlistObj = NPN_CreateObject(instance, RuntimeNPClass<LibvlcPlaylistNPObject>::getClass());
\r
48 videoObj = NPN_CreateObject(instance,RuntimeNPClass<LibvlcVideoNPObject>::getClass());
\r
51 LibvlcRootNPObject::~LibvlcRootNPObject()
\r
53 NPN_ReleaseObject(audioObj);
\r
54 NPN_ReleaseObject(inputObj);
\r
55 NPN_ReleaseObject(logObj);
\r
56 NPN_ReleaseObject(playlistObj);
\r
57 NPN_ReleaseObject(videoObj);
\r
60 const NPUTF8 * const LibvlcRootNPObject::propertyNames[] =
\r
70 const int LibvlcRootNPObject::propertyCount = sizeof(LibvlcRootNPObject::propertyNames)/sizeof(NPUTF8 *);
\r
72 enum LibvlcRootNPObjectPropertyIds
\r
79 ID_root_VersionInfo,
\r
82 RuntimeNPObject::InvokeResult LibvlcRootNPObject::getProperty(int index, NPVariant &result)
\r
84 VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);
\r
90 OBJECT_TO_NPVARIANT(NPN_RetainObject(audioObj), result);
\r
91 return INVOKERESULT_NO_ERROR;
\r
93 OBJECT_TO_NPVARIANT(NPN_RetainObject(inputObj), result);
\r
94 return INVOKERESULT_NO_ERROR;
\r
96 OBJECT_TO_NPVARIANT(NPN_RetainObject(logObj), result);
\r
97 return INVOKERESULT_NO_ERROR;
\r
98 case ID_root_playlist:
\r
99 OBJECT_TO_NPVARIANT(NPN_RetainObject(playlistObj), result);
\r
100 return INVOKERESULT_NO_ERROR;
\r
101 case ID_root_video:
\r
102 OBJECT_TO_NPVARIANT(NPN_RetainObject(videoObj), result);
\r
103 return INVOKERESULT_NO_ERROR;
\r
104 case ID_root_VersionInfo:
\r
106 int len = strlen(VLC_Version());
\r
107 NPUTF8 *retval =(NPUTF8*)NPN_MemAlloc(len);
\r
110 memcpy(retval, VLC_Version(), len);
\r
111 STRINGN_TO_NPVARIANT(retval, len, result);
\r
115 NULL_TO_NPVARIANT(result);
\r
117 return INVOKERESULT_NO_ERROR;
\r
123 return INVOKERESULT_GENERIC_ERROR;
\r
126 const NPUTF8 * const LibvlcRootNPObject::methodNames[] =
\r
131 const int LibvlcRootNPObject::methodCount = sizeof(LibvlcRootNPObject::methodNames)/sizeof(NPUTF8 *);
\r
133 enum LibvlcRootNPObjectMethodIds
\r
135 ID_root_versionInfo,
\r
138 RuntimeNPObject::InvokeResult LibvlcRootNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)
\r
140 VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);
\r
143 libvlc_exception_t ex;
\r
144 libvlc_exception_init(&ex);
\r
148 case ID_root_versionInfo:
\r
149 if( argCount == 0 )
\r
151 int len = strlen(VLC_Version());
\r
152 NPUTF8 *retval =(NPUTF8*)NPN_MemAlloc(len);
\r
155 memcpy(retval, VLC_Version(), len);
\r
156 STRINGN_TO_NPVARIANT(retval, len, result);
\r
160 NULL_TO_NPVARIANT(result);
\r
162 return INVOKERESULT_NO_ERROR;
\r
164 return INVOKERESULT_NO_SUCH_METHOD;
\r
169 return INVOKERESULT_GENERIC_ERROR;
\r
173 ** implementation of libvlc audio object
\r
176 const NPUTF8 * const LibvlcAudioNPObject::propertyNames[] =
\r
184 const int LibvlcAudioNPObject::propertyCount = sizeof(LibvlcAudioNPObject::propertyNames)/sizeof(NPUTF8 *);
\r
186 enum LibvlcAudioNPObjectPropertyIds
\r
194 RuntimeNPObject::InvokeResult LibvlcAudioNPObject::getProperty(int index, NPVariant &result)
\r
196 VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);
\r
199 libvlc_exception_t ex;
\r
200 libvlc_exception_init(&ex);
\r
204 case ID_audio_mute:
\r
206 vlc_bool_t muted = libvlc_audio_get_mute(p_plugin->getVLC(), &ex);
\r
207 if( libvlc_exception_raised(&ex) )
\r
209 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
210 libvlc_exception_clear(&ex);
\r
211 return INVOKERESULT_GENERIC_ERROR;
\r
213 BOOLEAN_TO_NPVARIANT(muted, result);
\r
214 return INVOKERESULT_NO_ERROR;
\r
216 case ID_audio_volume:
\r
218 int volume = libvlc_audio_get_volume(p_plugin->getVLC(), &ex);
\r
219 if( libvlc_exception_raised(&ex) )
\r
221 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
222 libvlc_exception_clear(&ex);
\r
223 return INVOKERESULT_GENERIC_ERROR;
\r
225 INT32_TO_NPVARIANT(volume, result);
\r
226 return INVOKERESULT_NO_ERROR;
\r
228 case ID_audio_track:
\r
230 int track = libvlc_audio_get_track(p_plugin->getVLC(), &ex);
\r
231 if( libvlc_exception_raised(&ex) )
\r
233 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
234 libvlc_exception_clear(&ex);
\r
235 return INVOKERESULT_GENERIC_ERROR;
\r
237 INT32_TO_NPVARIANT(track, result);
\r
238 return INVOKERESULT_NO_ERROR;
\r
240 case ID_audio_channel:
\r
242 char *channel = libvlc_audio_get_channel(p_plugin->getVLC(), &ex);
\r
243 if( libvlc_exception_raised(&ex) )
\r
245 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
246 libvlc_exception_clear(&ex);
\r
247 return INVOKERESULT_GENERIC_ERROR;
\r
251 int len = strlen(channel);
\r
252 NPUTF8 *retval = (NPUTF8*)NPN_MemAlloc(len);
\r
255 memcpy(retval, channel, len);
\r
256 STRINGN_TO_NPVARIANT(retval, len, result);
\r
260 NULL_TO_NPVARIANT(result);
\r
264 return INVOKERESULT_NO_ERROR;
\r
266 return INVOKERESULT_NO_SUCH_METHOD;
\r
272 return INVOKERESULT_GENERIC_ERROR;
\r
275 RuntimeNPObject::InvokeResult LibvlcAudioNPObject::setProperty(int index, const NPVariant &value)
\r
277 VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);
\r
280 libvlc_exception_t ex;
\r
281 libvlc_exception_init(&ex);
\r
285 case ID_audio_mute:
\r
286 if( NPVARIANT_IS_BOOLEAN(value) )
\r
288 libvlc_audio_set_mute(p_plugin->getVLC(),
\r
289 NPVARIANT_TO_BOOLEAN(value), &ex);
\r
290 if( libvlc_exception_raised(&ex) )
\r
292 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
293 libvlc_exception_clear(&ex);
\r
294 return INVOKERESULT_GENERIC_ERROR;
\r
296 return INVOKERESULT_NO_ERROR;
\r
298 return INVOKERESULT_INVALID_VALUE;
\r
299 case ID_audio_volume:
\r
300 if( isNumberValue(value) )
\r
302 libvlc_audio_set_volume(p_plugin->getVLC(),
\r
303 numberValue(value), &ex);
\r
304 if( libvlc_exception_raised(&ex) )
\r
306 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
307 libvlc_exception_clear(&ex);
\r
308 return INVOKERESULT_GENERIC_ERROR;
\r
310 return INVOKERESULT_NO_ERROR;
\r
312 return INVOKERESULT_INVALID_VALUE;
\r
313 case ID_audio_track:
\r
314 if( isNumberValue(value) )
\r
316 libvlc_audio_set_track(p_plugin->getVLC(),
\r
317 numberValue(value), &ex);
\r
318 if( libvlc_exception_raised(&ex) )
\r
320 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
321 libvlc_exception_clear(&ex);
\r
322 return INVOKERESULT_GENERIC_ERROR;
\r
324 return INVOKERESULT_NO_ERROR;
\r
326 return INVOKERESULT_INVALID_VALUE;
\r
327 case ID_audio_channel:
\r
329 char *psz_channel = NULL;
\r
331 if( ! NPVARIANT_IS_STRING(value) )
\r
333 return INVOKERESULT_INVALID_VALUE;
\r
336 psz_channel = stringValue(NPVARIANT_TO_STRING(value));
\r
338 return INVOKERESULT_GENERIC_ERROR;
\r
340 libvlc_audio_set_channel(p_plugin->getVLC(), psz_channel, &ex);
\r
342 free( psz_channel );
\r
344 if( libvlc_exception_raised(&ex) )
\r
346 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
347 libvlc_exception_clear(&ex);
\r
348 return INVOKERESULT_GENERIC_ERROR;
\r
350 return INVOKERESULT_NO_ERROR;
\r
356 return INVOKERESULT_GENERIC_ERROR;
\r
359 const NPUTF8 * const LibvlcAudioNPObject::methodNames[] =
\r
364 const int LibvlcAudioNPObject::methodCount = sizeof(LibvlcAudioNPObject::methodNames)/sizeof(NPUTF8 *);
\r
366 enum LibvlcAudioNPObjectMethodIds
\r
368 ID_audio_togglemute,
\r
371 RuntimeNPObject::InvokeResult LibvlcAudioNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)
\r
373 VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);
\r
376 libvlc_exception_t ex;
\r
377 libvlc_exception_init(&ex);
\r
381 case ID_audio_togglemute:
\r
382 if( argCount == 0 )
\r
384 libvlc_audio_toggle_mute(p_plugin->getVLC(), &ex);
\r
385 if( libvlc_exception_raised(&ex) )
\r
387 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
388 libvlc_exception_clear(&ex);
\r
389 return INVOKERESULT_GENERIC_ERROR;
\r
393 VOID_TO_NPVARIANT(result);
\r
394 return INVOKERESULT_NO_ERROR;
\r
397 return INVOKERESULT_NO_SUCH_METHOD;
\r
402 return INVOKERESULT_GENERIC_ERROR;
\r
406 ** implementation of libvlc input object
\r
409 const NPUTF8 * const LibvlcInputNPObject::propertyNames[] =
\r
420 const int LibvlcInputNPObject::propertyCount = sizeof(LibvlcInputNPObject::propertyNames)/sizeof(NPUTF8 *);
\r
422 enum LibvlcInputNPObjectPropertyIds
\r
433 RuntimeNPObject::InvokeResult LibvlcInputNPObject::getProperty(int index, NPVariant &result)
\r
435 VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);
\r
438 libvlc_exception_t ex;
\r
439 libvlc_exception_init(&ex);
\r
441 libvlc_input_t *p_input = libvlc_playlist_get_input(p_plugin->getVLC(), &ex);
\r
442 if( libvlc_exception_raised(&ex) )
\r
444 if( index != ID_input_state )
\r
446 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
447 libvlc_exception_clear(&ex);
\r
448 return INVOKERESULT_GENERIC_ERROR;
\r
452 /* for input state, return CLOSED rather than an exception */
\r
453 INT32_TO_NPVARIANT(0, result);
\r
454 return INVOKERESULT_NO_ERROR;
\r
460 case ID_input_length:
\r
462 double val = (double)libvlc_input_get_length(p_input, &ex);
\r
463 libvlc_input_free(p_input);
\r
464 if( libvlc_exception_raised(&ex) )
\r
466 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
467 libvlc_exception_clear(&ex);
\r
468 return INVOKERESULT_GENERIC_ERROR;
\r
470 DOUBLE_TO_NPVARIANT(val, result);
\r
471 return INVOKERESULT_NO_ERROR;
\r
473 case ID_input_position:
\r
475 double val = libvlc_input_get_position(p_input, &ex);
\r
476 libvlc_input_free(p_input);
\r
477 if( libvlc_exception_raised(&ex) )
\r
479 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
480 libvlc_exception_clear(&ex);
\r
481 return INVOKERESULT_GENERIC_ERROR;
\r
483 DOUBLE_TO_NPVARIANT(val, result);
\r
484 return INVOKERESULT_NO_ERROR;
\r
486 case ID_input_time:
\r
488 double val = (double)libvlc_input_get_time(p_input, &ex);
\r
489 libvlc_input_free(p_input);
\r
490 if( libvlc_exception_raised(&ex) )
\r
492 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
493 libvlc_exception_clear(&ex);
\r
494 return INVOKERESULT_GENERIC_ERROR;
\r
496 DOUBLE_TO_NPVARIANT(val, result);
\r
497 return INVOKERESULT_NO_ERROR;
\r
499 case ID_input_state:
\r
501 int val = libvlc_input_get_state(p_input, &ex);
\r
502 libvlc_input_free(p_input);
\r
503 if( libvlc_exception_raised(&ex) )
\r
505 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
506 libvlc_exception_clear(&ex);
\r
507 return INVOKERESULT_GENERIC_ERROR;
\r
509 INT32_TO_NPVARIANT(val, result);
\r
510 return INVOKERESULT_NO_ERROR;
\r
512 case ID_input_rate:
\r
514 float val = libvlc_input_get_rate(p_input, &ex);
\r
515 libvlc_input_free(p_input);
\r
516 if( libvlc_exception_raised(&ex) )
\r
518 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
519 libvlc_exception_clear(&ex);
\r
520 return INVOKERESULT_GENERIC_ERROR;
\r
522 DOUBLE_TO_NPVARIANT(val, result);
\r
523 return INVOKERESULT_NO_ERROR;
\r
527 double val = libvlc_input_get_fps(p_input, &ex);
\r
528 libvlc_input_free(p_input);
\r
529 if( libvlc_exception_raised(&ex) )
\r
531 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
532 libvlc_exception_clear(&ex);
\r
533 return INVOKERESULT_GENERIC_ERROR;
\r
535 DOUBLE_TO_NPVARIANT(val, result);
\r
536 return INVOKERESULT_NO_ERROR;
\r
538 case ID_input_hasvout:
\r
540 vlc_bool_t val = libvlc_input_has_vout(p_input, &ex);
\r
541 libvlc_input_free(p_input);
\r
542 if( libvlc_exception_raised(&ex) )
\r
544 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
545 libvlc_exception_clear(&ex);
\r
546 return INVOKERESULT_GENERIC_ERROR;
\r
548 BOOLEAN_TO_NPVARIANT(val, result);
\r
549 return INVOKERESULT_NO_ERROR;
\r
554 libvlc_input_free(p_input);
\r
556 return INVOKERESULT_GENERIC_ERROR;
\r
559 RuntimeNPObject::InvokeResult LibvlcInputNPObject::setProperty(int index, const NPVariant &value)
\r
561 VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);
\r
564 libvlc_exception_t ex;
\r
565 libvlc_exception_init(&ex);
\r
567 libvlc_input_t *p_input = libvlc_playlist_get_input(p_plugin->getVLC(), &ex);
\r
568 if( libvlc_exception_raised(&ex) )
\r
570 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
571 libvlc_exception_clear(&ex);
\r
572 return INVOKERESULT_GENERIC_ERROR;
\r
577 case ID_input_position:
\r
579 if( ! NPVARIANT_IS_DOUBLE(value) )
\r
581 libvlc_input_free(p_input);
\r
582 return INVOKERESULT_INVALID_VALUE;
\r
585 float val = (float)NPVARIANT_TO_DOUBLE(value);
\r
586 libvlc_input_set_position(p_input, val, &ex);
\r
587 libvlc_input_free(p_input);
\r
588 if( libvlc_exception_raised(&ex) )
\r
590 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
591 libvlc_exception_clear(&ex);
\r
592 return INVOKERESULT_GENERIC_ERROR;
\r
594 return INVOKERESULT_NO_ERROR;
\r
596 case ID_input_time:
\r
599 if( NPVARIANT_IS_INT32(value) )
\r
600 val = (vlc_int64_t)NPVARIANT_TO_INT32(value);
\r
601 else if( NPVARIANT_IS_DOUBLE(value) )
\r
602 val = (vlc_int64_t)NPVARIANT_TO_DOUBLE(value);
\r
605 libvlc_input_free(p_input);
\r
606 return INVOKERESULT_INVALID_VALUE;
\r
609 libvlc_input_set_time(p_input, val, &ex);
\r
610 libvlc_input_free(p_input);
\r
611 if( libvlc_exception_raised(&ex) )
\r
613 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
614 libvlc_exception_clear(&ex);
\r
615 return INVOKERESULT_GENERIC_ERROR;
\r
617 return INVOKERESULT_NO_ERROR;
\r
619 case ID_input_rate:
\r
622 if( NPVARIANT_IS_INT32(value) )
\r
623 val = (float)NPVARIANT_TO_INT32(value);
\r
624 else if( NPVARIANT_IS_DOUBLE(value) )
\r
625 val = (float)NPVARIANT_TO_DOUBLE(value);
\r
628 libvlc_input_free(p_input);
\r
629 return INVOKERESULT_INVALID_VALUE;
\r
632 libvlc_input_set_rate(p_input, val, &ex);
\r
633 libvlc_input_free(p_input);
\r
634 if( libvlc_exception_raised(&ex) )
\r
636 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
637 libvlc_exception_clear(&ex);
\r
638 return INVOKERESULT_GENERIC_ERROR;
\r
640 return INVOKERESULT_NO_ERROR;
\r
645 libvlc_input_free(p_input);
\r
647 return INVOKERESULT_GENERIC_ERROR;
\r
650 const NPUTF8 * const LibvlcInputNPObject::methodNames[] =
\r
655 const int LibvlcInputNPObject::methodCount = sizeof(LibvlcInputNPObject::methodNames)/sizeof(NPUTF8 *);
\r
658 ** implementation of libvlc message object
\r
661 const NPUTF8 * const LibvlcMessageNPObject::propertyNames[] =
\r
670 const int LibvlcMessageNPObject::propertyCount = sizeof(LibvlcMessageNPObject::propertyNames)/sizeof(NPUTF8 *);
\r
672 enum LibvlcMessageNPObjectPropertyIds
\r
674 ID_message_severity,
\r
678 ID_message_message,
\r
681 RuntimeNPObject::InvokeResult LibvlcMessageNPObject::getProperty(int index, NPVariant &result)
\r
683 VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);
\r
688 case ID_message_severity:
\r
690 INT32_TO_NPVARIANT(_msg.i_severity, result);
\r
691 return INVOKERESULT_NO_ERROR;
\r
693 case ID_message_type:
\r
695 if( _msg.psz_type )
\r
697 int len = strlen(_msg.psz_type);
\r
698 NPUTF8* retval = (NPUTF8*)NPN_MemAlloc(len);
\r
701 memcpy(retval, _msg.psz_type, len);
\r
702 STRINGN_TO_NPVARIANT(retval, len, result);
\r
707 NULL_TO_NPVARIANT(result);
\r
709 return INVOKERESULT_NO_ERROR;
\r
711 case ID_message_name:
\r
713 if( _msg.psz_name )
\r
715 int len = strlen(_msg.psz_name);
\r
716 NPUTF8* retval = (NPUTF8*)NPN_MemAlloc(len);
\r
719 memcpy(retval, _msg.psz_name, len);
\r
720 STRINGN_TO_NPVARIANT(retval, len, result);
\r
725 NULL_TO_NPVARIANT(result);
\r
727 return INVOKERESULT_NO_ERROR;
\r
729 case ID_message_header:
\r
731 if( _msg.psz_header )
\r
733 int len = strlen(_msg.psz_header);
\r
734 NPUTF8* retval = (NPUTF8*)NPN_MemAlloc(len);
\r
737 memcpy(retval, _msg.psz_header, len);
\r
738 STRINGN_TO_NPVARIANT(retval, len, result);
\r
743 NULL_TO_NPVARIANT(result);
\r
745 return INVOKERESULT_NO_ERROR;
\r
747 case ID_message_message:
\r
749 if( _msg.psz_message )
\r
751 int len = strlen(_msg.psz_message);
\r
752 NPUTF8* retval = (NPUTF8*)NPN_MemAlloc(len);
\r
755 memcpy(retval, _msg.psz_message, len);
\r
756 STRINGN_TO_NPVARIANT(retval, len, result);
\r
761 NULL_TO_NPVARIANT(result);
\r
763 return INVOKERESULT_NO_ERROR;
\r
769 return INVOKERESULT_GENERIC_ERROR;
\r
772 const NPUTF8 * const LibvlcMessageNPObject::methodNames[] =
\r
777 const int LibvlcMessageNPObject::methodCount = sizeof(LibvlcMessageNPObject::methodNames)/sizeof(NPUTF8 *);
\r
780 ** implementation of libvlc message iterator object
\r
783 LibvlcMessageIteratorNPObject::LibvlcMessageIteratorNPObject(NPP instance, const NPClass *aClass) :
\r
784 RuntimeNPObject(instance, aClass),
\r
787 VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);
\r
790 libvlc_log_t *p_log = p_plugin->getLog();
\r
793 _p_iter = libvlc_log_get_iterator(p_log, NULL);
\r
798 LibvlcMessageIteratorNPObject::~LibvlcMessageIteratorNPObject()
\r
801 libvlc_log_iterator_free(_p_iter, NULL);
\r
804 const NPUTF8 * const LibvlcMessageIteratorNPObject::propertyNames[] =
\r
809 const int LibvlcMessageIteratorNPObject::propertyCount = sizeof(LibvlcMessageIteratorNPObject::propertyNames)/sizeof(NPUTF8 *);
\r
811 enum LibvlcMessageIteratorNPObjectPropertyIds
\r
813 ID_messageiterator_hasNext,
\r
816 RuntimeNPObject::InvokeResult LibvlcMessageIteratorNPObject::getProperty(int index, NPVariant &result)
\r
818 VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);
\r
823 case ID_messageiterator_hasNext:
\r
825 if( _p_iter && p_plugin->getLog() )
\r
827 libvlc_exception_t ex;
\r
828 libvlc_exception_init(&ex);
\r
830 BOOLEAN_TO_NPVARIANT(libvlc_log_iterator_has_next(_p_iter, &ex), result);
\r
831 if( libvlc_exception_raised(&ex) )
\r
833 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
834 libvlc_exception_clear(&ex);
\r
835 return INVOKERESULT_GENERIC_ERROR;
\r
840 BOOLEAN_TO_NPVARIANT(0, result);
\r
842 return INVOKERESULT_NO_ERROR;
\r
848 return INVOKERESULT_GENERIC_ERROR;
\r
851 const NPUTF8 * const LibvlcMessageIteratorNPObject::methodNames[] =
\r
856 const int LibvlcMessageIteratorNPObject::methodCount = sizeof(LibvlcMessageIteratorNPObject::methodNames)/sizeof(NPUTF8 *);
\r
858 enum LibvlcMessageIteratorNPObjectMethodIds
\r
860 ID_messageiterator_next,
\r
863 RuntimeNPObject::InvokeResult LibvlcMessageIteratorNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)
\r
865 VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);
\r
868 libvlc_exception_t ex;
\r
869 libvlc_exception_init(&ex);
\r
873 case ID_messageiterator_next:
\r
874 if( argCount == 0 )
\r
876 if( _p_iter && p_plugin->getLog() )
\r
878 struct libvlc_log_message_t buffer;
\r
880 buffer.sizeof_msg = sizeof(buffer);
\r
882 libvlc_log_iterator_next(_p_iter, &buffer, &ex);
\r
883 if( libvlc_exception_raised(&ex) )
\r
885 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
886 libvlc_exception_clear(&ex);
\r
887 return INVOKERESULT_GENERIC_ERROR;
\r
891 LibvlcMessageNPObject* message =
\r
892 static_cast<LibvlcMessageNPObject*>(NPN_CreateObject(_instance, RuntimeNPClass<LibvlcMessageNPObject>::getClass()));
\r
895 message->setMessage(buffer);
\r
896 OBJECT_TO_NPVARIANT(message, result);
\r
897 return INVOKERESULT_NO_ERROR;
\r
899 return INVOKERESULT_OUT_OF_MEMORY;
\r
902 return INVOKERESULT_GENERIC_ERROR;
\r
904 return INVOKERESULT_NO_SUCH_METHOD;
\r
909 return INVOKERESULT_GENERIC_ERROR;
\r
913 ** implementation of libvlc message object
\r
916 const NPUTF8 * const LibvlcMessagesNPObject::propertyNames[] =
\r
921 const int LibvlcMessagesNPObject::propertyCount = sizeof(LibvlcMessagesNPObject::propertyNames)/sizeof(NPUTF8 *);
\r
923 enum LibvlcMessagesNPObjectPropertyIds
\r
928 RuntimeNPObject::InvokeResult LibvlcMessagesNPObject::getProperty(int index, NPVariant &result)
\r
930 VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);
\r
935 case ID_messages_count:
\r
937 libvlc_log_t *p_log = p_plugin->getLog();
\r
940 libvlc_exception_t ex;
\r
941 libvlc_exception_init(&ex);
\r
943 INT32_TO_NPVARIANT(libvlc_log_count(p_log, &ex), result);
\r
944 if( libvlc_exception_raised(&ex) )
\r
946 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
947 libvlc_exception_clear(&ex);
\r
948 return INVOKERESULT_GENERIC_ERROR;
\r
953 INT32_TO_NPVARIANT(0, result);
\r
955 return INVOKERESULT_NO_ERROR;
\r
961 return INVOKERESULT_GENERIC_ERROR;
\r
964 const NPUTF8 * const LibvlcMessagesNPObject::methodNames[] =
\r
970 const int LibvlcMessagesNPObject::methodCount = sizeof(LibvlcMessagesNPObject::methodNames)/sizeof(NPUTF8 *);
\r
972 enum LibvlcMessagesNPObjectMethodIds
\r
975 ID_messages_iterator,
\r
978 RuntimeNPObject::InvokeResult LibvlcMessagesNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)
\r
980 VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);
\r
983 libvlc_exception_t ex;
\r
984 libvlc_exception_init(&ex);
\r
988 case ID_messages_clear:
\r
989 if( argCount == 0 )
\r
991 libvlc_log_t *p_log = p_plugin->getLog();
\r
994 libvlc_log_clear(p_log, &ex);
\r
995 if( libvlc_exception_raised(&ex) )
\r
997 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
998 libvlc_exception_clear(&ex);
\r
999 return INVOKERESULT_GENERIC_ERROR;
\r
1002 return INVOKERESULT_NO_ERROR;
\r
1004 return INVOKERESULT_NO_SUCH_METHOD;
\r
1006 case ID_messages_iterator:
\r
1007 if( argCount == 0 )
\r
1009 LibvlcMessageIteratorNPObject* iter =
\r
1010 static_cast<LibvlcMessageIteratorNPObject*>(NPN_CreateObject(_instance, RuntimeNPClass<LibvlcMessageIteratorNPObject>::getClass()));
\r
1013 OBJECT_TO_NPVARIANT(iter, result);
\r
1014 return INVOKERESULT_NO_ERROR;
\r
1016 return INVOKERESULT_OUT_OF_MEMORY;
\r
1018 return INVOKERESULT_NO_SUCH_METHOD;
\r
1024 return INVOKERESULT_GENERIC_ERROR;
\r
1029 ** implementation of libvlc message object
\r
1033 LibvlcLogNPObject::LibvlcLogNPObject(NPP instance, const NPClass *aClass) :
\r
1034 RuntimeNPObject(instance, aClass)
\r
1036 _p_vlcmessages = static_cast<LibvlcMessagesNPObject*>(NPN_CreateObject(instance, RuntimeNPClass<LibvlcMessagesNPObject>::getClass()));
\r
1039 LibvlcLogNPObject::~LibvlcLogNPObject()
\r
1041 NPN_ReleaseObject(_p_vlcmessages);
\r
1044 const NPUTF8 * const LibvlcLogNPObject::propertyNames[] =
\r
1050 const int LibvlcLogNPObject::propertyCount = sizeof(LibvlcLogNPObject::propertyNames)/sizeof(NPUTF8 *);
\r
1052 enum LibvlcLogNPObjectPropertyIds
\r
1058 RuntimeNPObject::InvokeResult LibvlcLogNPObject::getProperty(int index, NPVariant &result)
\r
1060 VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);
\r
1063 libvlc_exception_t ex;
\r
1064 libvlc_exception_init(&ex);
\r
1068 case ID_log_messages:
\r
1070 OBJECT_TO_NPVARIANT(NPN_RetainObject(_p_vlcmessages), result);
\r
1071 return INVOKERESULT_NO_ERROR;
\r
1073 case ID_log_verbosity:
\r
1075 if( p_plugin->getLog() )
\r
1077 INT32_TO_NPVARIANT(libvlc_get_log_verbosity(p_plugin->getVLC(),
\r
1079 if( libvlc_exception_raised(&ex) )
\r
1081 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
1082 libvlc_exception_clear(&ex);
\r
1083 return INVOKERESULT_GENERIC_ERROR;
\r
1088 /* log is not enabled, return -1 */
\r
1089 DOUBLE_TO_NPVARIANT(-1.0, result);
\r
1091 return INVOKERESULT_NO_ERROR;
\r
1097 return INVOKERESULT_GENERIC_ERROR;
\r
1100 RuntimeNPObject::InvokeResult LibvlcLogNPObject::setProperty(int index, const NPVariant &value)
\r
1102 VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);
\r
1105 libvlc_exception_t ex;
\r
1106 libvlc_exception_init(&ex);
\r
1110 case ID_log_verbosity:
\r
1111 if( isNumberValue(value) )
\r
1113 libvlc_instance_t* p_libvlc = p_plugin->getVLC();
\r
1114 libvlc_log_t *p_log = p_plugin->getLog();
\r
1115 int verbosity = numberValue(value);
\r
1116 if( verbosity >= 0 )
\r
1120 p_log = libvlc_log_open(p_libvlc, &ex);
\r
1121 if( libvlc_exception_raised(&ex) )
\r
1123 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
1124 libvlc_exception_clear(&ex);
\r
1125 return INVOKERESULT_GENERIC_ERROR;
\r
1127 p_plugin->setLog(p_log);
\r
1129 libvlc_set_log_verbosity(p_libvlc, (unsigned)verbosity, &ex);
\r
1130 if( libvlc_exception_raised(&ex) )
\r
1132 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
1133 libvlc_exception_clear(&ex);
\r
1134 return INVOKERESULT_GENERIC_ERROR;
\r
1139 /* close log when verbosity is set to -1 */
\r
1140 p_plugin->setLog(NULL);
\r
1141 libvlc_log_close(p_log, &ex);
\r
1142 if( libvlc_exception_raised(&ex) )
\r
1144 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
1145 libvlc_exception_clear(&ex);
\r
1146 return INVOKERESULT_GENERIC_ERROR;
\r
1149 return INVOKERESULT_NO_ERROR;
\r
1151 return INVOKERESULT_INVALID_VALUE;
\r
1156 return INVOKERESULT_GENERIC_ERROR;
\r
1159 const NPUTF8 * const LibvlcLogNPObject::methodNames[] =
\r
1164 const int LibvlcLogNPObject::methodCount = sizeof(LibvlcLogNPObject::methodNames)/sizeof(NPUTF8 *);
\r
1167 ** implementation of libvlc playlist items object
\r
1170 const NPUTF8 * const LibvlcPlaylistItemsNPObject::propertyNames[] =
\r
1175 const int LibvlcPlaylistItemsNPObject::propertyCount = sizeof(LibvlcPlaylistItemsNPObject::propertyNames)/sizeof(NPUTF8 *);
\r
1177 enum LibvlcPlaylistItemsNPObjectPropertyIds
\r
1179 ID_playlistitems_count,
\r
1182 RuntimeNPObject::InvokeResult LibvlcPlaylistItemsNPObject::getProperty(int index, NPVariant &result)
\r
1184 VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);
\r
1187 libvlc_exception_t ex;
\r
1188 libvlc_exception_init(&ex);
\r
1192 case ID_playlistitems_count:
\r
1194 int val = libvlc_playlist_items_count(p_plugin->getVLC(), &ex);
\r
1195 if( libvlc_exception_raised(&ex) )
\r
1197 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
1198 libvlc_exception_clear(&ex);
\r
1199 return INVOKERESULT_GENERIC_ERROR;
\r
1201 INT32_TO_NPVARIANT(val, result);
\r
1202 return INVOKERESULT_NO_ERROR;
\r
1208 return INVOKERESULT_GENERIC_ERROR;
\r
1211 const NPUTF8 * const LibvlcPlaylistItemsNPObject::methodNames[] =
\r
1217 const int LibvlcPlaylistItemsNPObject::methodCount = sizeof(LibvlcPlaylistItemsNPObject::methodNames)/sizeof(NPUTF8 *);
\r
1219 enum LibvlcPlaylistItemsNPObjectMethodIds
\r
1221 ID_playlistitems_clear,
\r
1222 ID_playlistitems_remove,
\r
1225 RuntimeNPObject::InvokeResult LibvlcPlaylistItemsNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)
\r
1227 VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);
\r
1230 libvlc_exception_t ex;
\r
1231 libvlc_exception_init(&ex);
\r
1235 case ID_playlistitems_clear:
\r
1236 if( argCount == 0 )
\r
1238 libvlc_playlist_clear(p_plugin->getVLC(), &ex);
\r
1239 if( libvlc_exception_raised(&ex) )
\r
1241 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
1242 libvlc_exception_clear(&ex);
\r
1243 return INVOKERESULT_GENERIC_ERROR;
\r
1247 VOID_TO_NPVARIANT(result);
\r
1248 return INVOKERESULT_NO_ERROR;
\r
1251 return INVOKERESULT_NO_SUCH_METHOD;
\r
1252 case ID_playlistitems_remove:
\r
1253 if( (argCount == 1) && isNumberValue(args[0]) )
\r
1255 libvlc_playlist_delete_item(p_plugin->getVLC(), numberValue(args[0]), &ex);
\r
1256 if( libvlc_exception_raised(&ex) )
\r
1258 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
1259 libvlc_exception_clear(&ex);
\r
1260 return INVOKERESULT_GENERIC_ERROR;
\r
1264 VOID_TO_NPVARIANT(result);
\r
1265 return INVOKERESULT_NO_ERROR;
\r
1268 return INVOKERESULT_NO_SUCH_METHOD;
\r
1273 return INVOKERESULT_GENERIC_ERROR;
\r
1277 ** implementation of libvlc playlist object
\r
1281 LibvlcPlaylistNPObject::LibvlcPlaylistNPObject(NPP instance, const NPClass *aClass) :
\r
1282 RuntimeNPObject(instance, aClass)
\r
1284 _p_vlcplaylistitems = static_cast<LibvlcPlaylistItemsNPObject*>(NPN_CreateObject(instance, RuntimeNPClass<LibvlcPlaylistItemsNPObject>::getClass()));
\r
1287 LibvlcPlaylistNPObject::~LibvlcPlaylistNPObject()
\r
1289 NPN_ReleaseObject(_p_vlcplaylistitems);
\r
1292 const NPUTF8 * const LibvlcPlaylistNPObject::propertyNames[] =
\r
1294 "itemCount", /* deprecated */
\r
1299 const int LibvlcPlaylistNPObject::propertyCount = sizeof(LibvlcPlaylistNPObject::propertyNames)/sizeof(NPUTF8 *);
\r
1301 enum LibvlcPlaylistNPObjectPropertyIds
\r
1303 ID_playlist_itemcount,
\r
1304 ID_playlist_isplaying,
\r
1305 ID_playlist_items,
\r
1308 RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::getProperty(int index, NPVariant &result)
\r
1310 VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);
\r
1313 libvlc_exception_t ex;
\r
1314 libvlc_exception_init(&ex);
\r
1318 case ID_playlist_itemcount: /* deprecated */
\r
1320 int val = libvlc_playlist_items_count(p_plugin->getVLC(), &ex);
\r
1321 if( libvlc_exception_raised(&ex) )
\r
1323 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
1324 libvlc_exception_clear(&ex);
\r
1325 return INVOKERESULT_GENERIC_ERROR;
\r
1327 INT32_TO_NPVARIANT(val, result);
\r
1328 return INVOKERESULT_NO_ERROR;
\r
1330 case ID_playlist_isplaying:
\r
1332 int val = libvlc_playlist_isplaying(p_plugin->getVLC(), &ex);
\r
1333 if( libvlc_exception_raised(&ex) )
\r
1335 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
1336 libvlc_exception_clear(&ex);
\r
1337 return INVOKERESULT_GENERIC_ERROR;
\r
1339 BOOLEAN_TO_NPVARIANT(val, result);
\r
1340 return INVOKERESULT_NO_ERROR;
\r
1342 case ID_playlist_items:
\r
1344 OBJECT_TO_NPVARIANT(NPN_RetainObject(_p_vlcplaylistitems), result);
\r
1345 return INVOKERESULT_NO_ERROR;
\r
1351 return INVOKERESULT_GENERIC_ERROR;
\r
1354 const NPUTF8 * const LibvlcPlaylistNPObject::methodNames[] =
\r
1363 "clear", /* deprecated */
\r
1364 "removeItem", /* deprecated */
\r
1367 const int LibvlcPlaylistNPObject::methodCount = sizeof(LibvlcPlaylistNPObject::methodNames)/sizeof(NPUTF8 *);
\r
1369 enum LibvlcPlaylistNPObjectMethodIds
\r
1373 ID_playlist_playItem,
\r
1374 ID_playlist_togglepause,
\r
1378 ID_playlist_clear,
\r
1379 ID_playlist_removeitem
\r
1382 RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)
\r
1384 VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);
\r
1387 libvlc_exception_t ex;
\r
1388 libvlc_exception_init(&ex);
\r
1392 case ID_playlist_add:
\r
1394 if( (argCount < 1) || (argCount > 3) )
\r
1395 return INVOKERESULT_NO_SUCH_METHOD;
\r
1400 if( NPVARIANT_IS_STRING(args[0]) )
\r
1402 char *s = stringValue(NPVARIANT_TO_STRING(args[0]));
\r
1405 url = p_plugin->getAbsoluteURL(s);
\r
1409 // problem with combining url, use argument
\r
1413 return INVOKERESULT_OUT_OF_MEMORY;
\r
1416 return INVOKERESULT_NO_SUCH_METHOD;
\r
1418 char *name = NULL;
\r
1420 // grab name if available
\r
1421 if( argCount > 1 )
\r
1423 if( NPVARIANT_IS_NULL(args[1]) )
\r
1427 else if( NPVARIANT_IS_STRING(args[1]) )
\r
1429 name = stringValue(NPVARIANT_TO_STRING(args[0]));
\r
1432 return INVOKERESULT_NO_SUCH_METHOD;
\r
1435 int i_options = 0;
\r
1436 char** ppsz_options = NULL;
\r
1438 // grab options if available
\r
1439 if( argCount > 2 )
\r
1441 if( NPVARIANT_IS_NULL(args[2]) )
\r
1445 else if( NPVARIANT_IS_STRING(args[2]) )
\r
1447 parseOptions(NPVARIANT_TO_STRING(args[2]), &i_options, &ppsz_options);
\r
1450 else if( NPVARIANT_IS_OBJECT(args[2]) )
\r
1452 parseOptions(NPVARIANT_TO_OBJECT(args[2]), &i_options, &ppsz_options);
\r
1456 int item = libvlc_playlist_add_extended(p_plugin->getVLC(),
\r
1460 const_cast<const char **>(ppsz_options),
\r
1464 for( int i=0; i< i_options; ++i )
\r
1466 if( ppsz_options[i] )
\r
1467 free(ppsz_options[i]);
\r
1469 if( ppsz_options )
\r
1470 free(ppsz_options);
\r
1471 if( libvlc_exception_raised(&ex) )
\r
1473 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
1474 libvlc_exception_clear(&ex);
\r
1475 return INVOKERESULT_GENERIC_ERROR;
\r
1479 INT32_TO_NPVARIANT(item, result);
\r
1480 return INVOKERESULT_NO_ERROR;
\r
1483 case ID_playlist_play:
\r
1484 if( argCount == 0 )
\r
1486 libvlc_playlist_play(p_plugin->getVLC(), -1, 0, NULL, &ex);
\r
1487 if( libvlc_exception_raised(&ex) )
\r
1489 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
1490 libvlc_exception_clear(&ex);
\r
1491 return INVOKERESULT_GENERIC_ERROR;
\r
1495 VOID_TO_NPVARIANT(result);
\r
1496 return INVOKERESULT_NO_ERROR;
\r
1499 return INVOKERESULT_NO_SUCH_METHOD;
\r
1500 case ID_playlist_playItem:
\r
1501 if( (argCount == 1) && isNumberValue(args[0]) )
\r
1503 libvlc_playlist_play(p_plugin->getVLC(), numberValue(args[0]), 0, NULL, &ex);
\r
1504 if( libvlc_exception_raised(&ex) )
\r
1506 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
1507 libvlc_exception_clear(&ex);
\r
1508 return INVOKERESULT_GENERIC_ERROR;
\r
1512 VOID_TO_NPVARIANT(result);
\r
1513 return INVOKERESULT_NO_ERROR;
\r
1516 return INVOKERESULT_NO_SUCH_METHOD;
\r
1517 case ID_playlist_togglepause:
\r
1518 if( argCount == 0 )
\r
1520 libvlc_playlist_pause(p_plugin->getVLC(), &ex);
\r
1521 if( libvlc_exception_raised(&ex) )
\r
1523 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
1524 libvlc_exception_clear(&ex);
\r
1525 return INVOKERESULT_GENERIC_ERROR;
\r
1529 VOID_TO_NPVARIANT(result);
\r
1530 return INVOKERESULT_NO_ERROR;
\r
1533 return INVOKERESULT_NO_SUCH_METHOD;
\r
1534 case ID_playlist_stop:
\r
1535 if( argCount == 0 )
\r
1537 libvlc_playlist_stop(p_plugin->getVLC(), &ex);
\r
1538 if( libvlc_exception_raised(&ex) )
\r
1540 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
1541 libvlc_exception_clear(&ex);
\r
1542 return INVOKERESULT_GENERIC_ERROR;
\r
1546 VOID_TO_NPVARIANT(result);
\r
1547 return INVOKERESULT_NO_ERROR;
\r
1550 return INVOKERESULT_NO_SUCH_METHOD;
\r
1551 case ID_playlist_next:
\r
1552 if( argCount == 0 )
\r
1554 libvlc_playlist_next(p_plugin->getVLC(), &ex);
\r
1555 if( libvlc_exception_raised(&ex) )
\r
1557 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
1558 libvlc_exception_clear(&ex);
\r
1559 return INVOKERESULT_GENERIC_ERROR;
\r
1563 VOID_TO_NPVARIANT(result);
\r
1564 return INVOKERESULT_NO_ERROR;
\r
1567 return INVOKERESULT_NO_SUCH_METHOD;
\r
1568 case ID_playlist_prev:
\r
1569 if( argCount == 0 )
\r
1571 libvlc_playlist_prev(p_plugin->getVLC(), &ex);
\r
1572 if( libvlc_exception_raised(&ex) )
\r
1574 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
1575 libvlc_exception_clear(&ex);
\r
1576 return INVOKERESULT_GENERIC_ERROR;
\r
1580 VOID_TO_NPVARIANT(result);
\r
1581 return INVOKERESULT_NO_ERROR;
\r
1584 return INVOKERESULT_NO_SUCH_METHOD;
\r
1585 case ID_playlist_clear: /* deprecated */
\r
1586 if( argCount == 0 )
\r
1588 libvlc_playlist_clear(p_plugin->getVLC(), &ex);
\r
1589 if( libvlc_exception_raised(&ex) )
\r
1591 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
1592 libvlc_exception_clear(&ex);
\r
1593 return INVOKERESULT_GENERIC_ERROR;
\r
1597 VOID_TO_NPVARIANT(result);
\r
1598 return INVOKERESULT_NO_ERROR;
\r
1601 return INVOKERESULT_NO_SUCH_METHOD;
\r
1602 case ID_playlist_removeitem: /* deprecated */
\r
1603 if( (argCount == 1) && isNumberValue(args[0]) )
\r
1605 libvlc_playlist_delete_item(p_plugin->getVLC(), numberValue(args[0]), &ex);
\r
1606 if( libvlc_exception_raised(&ex) )
\r
1608 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
1609 libvlc_exception_clear(&ex);
\r
1610 return INVOKERESULT_GENERIC_ERROR;
\r
1614 VOID_TO_NPVARIANT(result);
\r
1615 return INVOKERESULT_NO_ERROR;
\r
1618 return INVOKERESULT_NO_SUCH_METHOD;
\r
1623 return INVOKERESULT_GENERIC_ERROR;
\r
1626 void LibvlcPlaylistNPObject::parseOptions(const NPString &s, int *i_options, char*** ppsz_options)
\r
1628 if( s.utf8length )
\r
1630 char *val = stringValue(s);
\r
1633 long capacity = 16;
\r
1634 char **options = (char **)malloc(capacity*sizeof(char *));
\r
1639 char *end = val + s.utf8length;
\r
1640 while( val < end )
\r
1642 // skip leading blanks
\r
1643 while( (val < end)
\r
1644 && ((*val == ' ' ) || (*val == '\t')) )
\r
1647 char *start = val;
\r
1648 // skip till we get a blank character
\r
1649 while( (val < end)
\r
1651 && (*val != '\t') )
\r
1653 char c = *(val++);
\r
1654 if( ('\'' == c) || ('"' == c) )
\r
1656 // skip till end of string
\r
1657 while( (val < end) && (*(val++) != c ) );
\r
1663 if( nOptions == capacity )
\r
1666 char **moreOptions = (char **)realloc(options, capacity*sizeof(char*));
\r
1667 if( ! moreOptions )
\r
1669 /* failed to allocate more memory */
\r
1671 /* return what we got so far */
\r
1672 *i_options = nOptions;
\r
1673 *ppsz_options = options;
\r
1676 options = moreOptions;
\r
1679 options[nOptions++] = strdup(start);
\r
1682 // must be end of string
\r
1685 *i_options = nOptions;
\r
1686 *ppsz_options = options;
\r
1693 void LibvlcPlaylistNPObject::parseOptions(NPObject *obj, int *i_options, char*** ppsz_options)
\r
1695 /* WARNING: Safari does not implement NPN_HasProperty/NPN_HasMethod */
\r
1699 /* we are expecting to have a Javascript Array object */
\r
1700 NPIdentifier propId = NPN_GetStringIdentifier("length");
\r
1701 if( NPN_GetProperty(_instance, obj, propId, &value) )
\r
1703 int count = numberValue(value);
\r
1704 NPN_ReleaseVariantValue(&value);
\r
1708 long capacity = 16;
\r
1709 char **options = (char **)malloc(capacity*sizeof(char *));
\r
1714 while( nOptions < count )
\r
1716 propId = NPN_GetIntIdentifier(nOptions);
\r
1717 if( ! NPN_GetProperty(_instance, obj, propId, &value) )
\r
1718 /* return what we got so far */
\r
1721 if( ! NPVARIANT_IS_STRING(value) )
\r
1723 /* return what we got so far */
\r
1724 NPN_ReleaseVariantValue(&value);
\r
1728 if( nOptions == capacity )
\r
1731 char **moreOptions = (char **)realloc(options, capacity*sizeof(char*));
\r
1732 if( ! moreOptions )
\r
1734 /* failed to allocate more memory */
\r
1735 NPN_ReleaseVariantValue(&value);
\r
1736 /* return what we got so far */
\r
1737 *i_options = nOptions;
\r
1738 *ppsz_options = options;
\r
1741 options = moreOptions;
\r
1744 options[nOptions++] = stringValue(value);
\r
1746 *i_options = nOptions;
\r
1747 *ppsz_options = options;
\r
1754 ** implementation of libvlc video object
\r
1757 const NPUTF8 * const LibvlcVideoNPObject::propertyNames[] =
\r
1765 enum LibvlcVideoNPObjectPropertyIds
\r
1767 ID_video_fullscreen,
\r
1770 ID_video_aspectratio
\r
1773 const int LibvlcVideoNPObject::propertyCount = sizeof(LibvlcVideoNPObject::propertyNames)/sizeof(NPUTF8 *);
\r
1775 RuntimeNPObject::InvokeResult LibvlcVideoNPObject::getProperty(int index, NPVariant &result)
\r
1777 VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);
\r
1780 libvlc_exception_t ex;
\r
1781 libvlc_exception_init(&ex);
\r
1783 libvlc_input_t *p_input = libvlc_playlist_get_input(p_plugin->getVLC(), &ex);
\r
1784 if( libvlc_exception_raised(&ex) )
\r
1786 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
1787 libvlc_exception_clear(&ex);
\r
1788 return INVOKERESULT_GENERIC_ERROR;
\r
1793 case ID_video_fullscreen:
\r
1795 int val = libvlc_get_fullscreen(p_input, &ex);
\r
1796 libvlc_input_free(p_input);
\r
1797 if( libvlc_exception_raised(&ex) )
\r
1799 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
1800 libvlc_exception_clear(&ex);
\r
1801 return INVOKERESULT_GENERIC_ERROR;
\r
1803 BOOLEAN_TO_NPVARIANT(val, result);
\r
1804 return INVOKERESULT_NO_ERROR;
\r
1806 case ID_video_height:
\r
1808 int val = libvlc_video_get_height(p_input, &ex);
\r
1809 libvlc_input_free(p_input);
\r
1810 if( libvlc_exception_raised(&ex) )
\r
1812 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
1813 libvlc_exception_clear(&ex);
\r
1814 return INVOKERESULT_GENERIC_ERROR;
\r
1816 INT32_TO_NPVARIANT(val, result);
\r
1817 return INVOKERESULT_NO_ERROR;
\r
1819 case ID_video_width:
\r
1821 int val = libvlc_video_get_width(p_input, &ex);
\r
1822 libvlc_input_free(p_input);
\r
1823 if( libvlc_exception_raised(&ex) )
\r
1825 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
1826 libvlc_exception_clear(&ex);
\r
1827 return INVOKERESULT_GENERIC_ERROR;
\r
1829 INT32_TO_NPVARIANT(val, result);
\r
1830 return INVOKERESULT_NO_ERROR;
\r
1832 case ID_video_aspectratio:
\r
1834 NPUTF8 *psz_aspect = libvlc_video_get_aspect_ratio(p_input, &ex);
\r
1835 libvlc_input_free(p_input);
\r
1836 if( libvlc_exception_raised(&ex) )
\r
1838 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
1839 libvlc_exception_clear(&ex);
\r
1840 return INVOKERESULT_GENERIC_ERROR;
\r
1843 return INVOKERESULT_GENERIC_ERROR;
\r
1845 STRINGZ_TO_NPVARIANT(psz_aspect, result);
\r
1846 return INVOKERESULT_NO_ERROR;
\r
1849 libvlc_input_free(p_input);
\r
1851 return INVOKERESULT_GENERIC_ERROR;
\r
1854 RuntimeNPObject::InvokeResult LibvlcVideoNPObject::setProperty(int index, const NPVariant &value)
\r
1856 VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);
\r
1859 libvlc_exception_t ex;
\r
1860 libvlc_exception_init(&ex);
\r
1862 libvlc_input_t *p_input = libvlc_playlist_get_input(p_plugin->getVLC(), &ex);
\r
1863 if( libvlc_exception_raised(&ex) )
\r
1865 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
1866 libvlc_exception_clear(&ex);
\r
1867 return INVOKERESULT_GENERIC_ERROR;
\r
1872 case ID_video_fullscreen:
\r
1874 if( ! NPVARIANT_IS_BOOLEAN(value) )
\r
1876 libvlc_input_free(p_input);
\r
1877 return INVOKERESULT_INVALID_VALUE;
\r
1880 int val = NPVARIANT_TO_BOOLEAN(value);
\r
1881 libvlc_set_fullscreen(p_input, val, &ex);
\r
1882 libvlc_input_free(p_input);
\r
1883 if( libvlc_exception_raised(&ex) )
\r
1885 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
1886 libvlc_exception_clear(&ex);
\r
1887 return INVOKERESULT_GENERIC_ERROR;
\r
1889 return INVOKERESULT_NO_ERROR;
\r
1891 case ID_video_aspectratio:
\r
1893 char *psz_aspect = NULL;
\r
1895 if( ! NPVARIANT_IS_STRING(value) )
\r
1897 libvlc_input_free(p_input);
\r
1898 return INVOKERESULT_INVALID_VALUE;
\r
1901 psz_aspect = stringValue(NPVARIANT_TO_STRING(value));
\r
1903 return INVOKERESULT_GENERIC_ERROR;
\r
1905 libvlc_video_set_aspect_ratio(p_input, psz_aspect, &ex);
\r
1907 free(psz_aspect );
\r
1909 libvlc_input_free(p_input);
\r
1910 if( libvlc_exception_raised(&ex) )
\r
1912 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
1913 libvlc_exception_clear(&ex);
\r
1914 return INVOKERESULT_GENERIC_ERROR;
\r
1916 return INVOKERESULT_NO_ERROR;
\r
1919 libvlc_input_free(p_input);
\r
1921 return INVOKERESULT_GENERIC_ERROR;
\r
1924 const NPUTF8 * const LibvlcVideoNPObject::methodNames[] =
\r
1926 "toggleFullscreen",
\r
1929 enum LibvlcVideoNPObjectMethodIds
\r
1931 ID_video_togglefullscreen,
\r
1934 const int LibvlcVideoNPObject::methodCount = sizeof(LibvlcVideoNPObject::methodNames)/sizeof(NPUTF8 *);
\r
1936 RuntimeNPObject::InvokeResult LibvlcVideoNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)
\r
1938 VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);
\r
1941 libvlc_exception_t ex;
\r
1942 libvlc_exception_init(&ex);
\r
1944 libvlc_input_t *p_input = libvlc_playlist_get_input(p_plugin->getVLC(), &ex);
\r
1945 if( libvlc_exception_raised(&ex) )
\r
1947 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
1948 libvlc_exception_clear(&ex);
\r
1949 return INVOKERESULT_GENERIC_ERROR;
\r
1954 case ID_video_togglefullscreen:
\r
1955 if( argCount == 0 )
\r
1957 libvlc_toggle_fullscreen(p_input, &ex);
\r
1958 libvlc_input_free(p_input);
\r
1959 if( libvlc_exception_raised(&ex) )
\r
1961 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
1962 libvlc_exception_clear(&ex);
\r
1963 return INVOKERESULT_GENERIC_ERROR;
\r
1967 VOID_TO_NPVARIANT(result);
\r
1968 return INVOKERESULT_NO_ERROR;
\r
1973 /* cannot get input, probably not playing */
\r
1974 if( libvlc_exception_raised(&ex) )
\r
1976 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
1977 libvlc_exception_clear(&ex);
\r
1979 return INVOKERESULT_GENERIC_ERROR;
\r
1981 return INVOKERESULT_NO_SUCH_METHOD;
\r
1983 return INVOKERESULT_NO_SUCH_METHOD;
\r
1986 return INVOKERESULT_GENERIC_ERROR;
\r