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 "vlcplugin.h"
\r
35 #include "npolibvlc.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 /* is plugin still running */
\r
85 if( _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 /* is plugin still running */
\r
141 if( _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 /* is plugin still running */
\r
197 if( _instance->pdata )
\r
199 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
\r
200 libvlc_exception_t ex;
\r
201 libvlc_exception_init(&ex);
\r
203 libvlc_input_t *p_input = libvlc_playlist_get_input(p_plugin->getVLC(), &ex);
\r
204 if( libvlc_exception_raised(&ex) )
\r
206 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
207 libvlc_exception_clear(&ex);
\r
208 return INVOKERESULT_GENERIC_ERROR;
\r
213 case ID_audio_mute:
\r
215 vlc_bool_t muted = libvlc_audio_get_mute(p_plugin->getVLC(), &ex);
\r
216 libvlc_input_free(p_input);
\r
217 if( libvlc_exception_raised(&ex) )
\r
219 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
220 libvlc_exception_clear(&ex);
\r
221 return INVOKERESULT_GENERIC_ERROR;
\r
223 BOOLEAN_TO_NPVARIANT(muted, result);
\r
224 return INVOKERESULT_NO_ERROR;
\r
226 case ID_audio_volume:
\r
228 int volume = libvlc_audio_get_volume(p_plugin->getVLC(), &ex);
\r
229 libvlc_input_free(p_input);
\r
230 if( libvlc_exception_raised(&ex) )
\r
232 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
233 libvlc_exception_clear(&ex);
\r
234 return INVOKERESULT_GENERIC_ERROR;
\r
236 INT32_TO_NPVARIANT(volume, result);
\r
237 return INVOKERESULT_NO_ERROR;
\r
239 case ID_audio_track:
\r
241 int track = libvlc_audio_get_track(p_input, &ex);
\r
242 libvlc_input_free(p_input);
\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
249 INT32_TO_NPVARIANT(track, result);
\r
250 return INVOKERESULT_NO_ERROR;
\r
252 case ID_audio_channel:
\r
254 int channel = libvlc_audio_get_channel(p_plugin->getVLC(), &ex);
\r
255 libvlc_input_free(p_input);
\r
256 if( libvlc_exception_raised(&ex) )
\r
258 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
259 libvlc_exception_clear(&ex);
\r
260 return INVOKERESULT_GENERIC_ERROR;
\r
262 INT32_TO_NPVARIANT(channel, result);
\r
263 return INVOKERESULT_NO_ERROR;
\r
268 libvlc_input_free(p_input);
\r
270 return INVOKERESULT_GENERIC_ERROR;
\r
273 RuntimeNPObject::InvokeResult LibvlcAudioNPObject::setProperty(int index, const NPVariant &value)
\r
275 /* is plugin still running */
\r
276 if( _instance->pdata )
\r
278 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
\r
279 libvlc_exception_t ex;
\r
280 libvlc_exception_init(&ex);
\r
282 libvlc_input_t *p_input = libvlc_playlist_get_input(p_plugin->getVLC(), &ex);
\r
283 if( libvlc_exception_raised(&ex) )
\r
285 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
286 libvlc_exception_clear(&ex);
\r
287 return INVOKERESULT_GENERIC_ERROR;
\r
292 case ID_audio_mute:
\r
293 if( NPVARIANT_IS_BOOLEAN(value) )
\r
295 libvlc_audio_set_mute(p_plugin->getVLC(),
\r
296 NPVARIANT_TO_BOOLEAN(value), &ex);
\r
297 libvlc_input_free(p_input);
\r
298 if( libvlc_exception_raised(&ex) )
\r
300 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
301 libvlc_exception_clear(&ex);
\r
302 return INVOKERESULT_GENERIC_ERROR;
\r
304 return INVOKERESULT_NO_ERROR;
\r
306 return INVOKERESULT_INVALID_VALUE;
\r
307 case ID_audio_volume:
\r
308 libvlc_input_free(p_input);
\r
309 if( isNumberValue(value) )
\r
311 libvlc_audio_set_volume(p_plugin->getVLC(),
\r
312 numberValue(value), &ex);
\r
313 if( libvlc_exception_raised(&ex) )
\r
315 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
316 libvlc_exception_clear(&ex);
\r
317 return INVOKERESULT_GENERIC_ERROR;
\r
319 return INVOKERESULT_NO_ERROR;
\r
321 return INVOKERESULT_INVALID_VALUE;
\r
322 case ID_audio_track:
\r
323 if( isNumberValue(value) )
\r
325 libvlc_audio_set_track(p_input,
\r
326 numberValue(value), &ex);
\r
327 libvlc_input_free(p_input);
\r
328 if( libvlc_exception_raised(&ex) )
\r
330 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
331 libvlc_exception_clear(&ex);
\r
332 return INVOKERESULT_GENERIC_ERROR;
\r
334 return INVOKERESULT_NO_ERROR;
\r
336 libvlc_input_free(p_input);
\r
337 return INVOKERESULT_INVALID_VALUE;
\r
338 case ID_audio_channel:
\r
339 libvlc_input_free(p_input);
\r
340 if( isNumberValue(value) )
\r
342 libvlc_audio_set_channel(p_plugin->getVLC(),
\r
343 numberValue(value), &ex);
\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
352 return INVOKERESULT_INVALID_VALUE;
\r
356 libvlc_input_free(p_input);
\r
358 return INVOKERESULT_GENERIC_ERROR;
\r
361 const NPUTF8 * const LibvlcAudioNPObject::methodNames[] =
\r
366 const int LibvlcAudioNPObject::methodCount = sizeof(LibvlcAudioNPObject::methodNames)/sizeof(NPUTF8 *);
\r
368 enum LibvlcAudioNPObjectMethodIds
\r
370 ID_audio_togglemute,
\r
373 RuntimeNPObject::InvokeResult LibvlcAudioNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)
\r
375 /* is plugin still running */
\r
376 if( _instance->pdata )
\r
378 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
\r
379 libvlc_exception_t ex;
\r
380 libvlc_exception_init(&ex);
\r
384 case ID_audio_togglemute:
\r
385 if( argCount == 0 )
\r
387 libvlc_audio_toggle_mute(p_plugin->getVLC(), &ex);
\r
388 if( libvlc_exception_raised(&ex) )
\r
390 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
391 libvlc_exception_clear(&ex);
\r
392 return INVOKERESULT_GENERIC_ERROR;
\r
396 VOID_TO_NPVARIANT(result);
\r
397 return INVOKERESULT_NO_ERROR;
\r
400 return INVOKERESULT_NO_SUCH_METHOD;
\r
405 return INVOKERESULT_GENERIC_ERROR;
\r
409 ** implementation of libvlc input object
\r
412 const NPUTF8 * const LibvlcInputNPObject::propertyNames[] =
\r
423 const int LibvlcInputNPObject::propertyCount = sizeof(LibvlcInputNPObject::propertyNames)/sizeof(NPUTF8 *);
\r
425 enum LibvlcInputNPObjectPropertyIds
\r
436 RuntimeNPObject::InvokeResult LibvlcInputNPObject::getProperty(int index, NPVariant &result)
\r
438 /* is plugin still running */
\r
439 if( _instance->pdata )
\r
441 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
\r
442 libvlc_exception_t ex;
\r
443 libvlc_exception_init(&ex);
\r
445 libvlc_input_t *p_input = libvlc_playlist_get_input(p_plugin->getVLC(), &ex);
\r
446 if( libvlc_exception_raised(&ex) )
\r
448 if( index != ID_input_state )
\r
450 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
451 libvlc_exception_clear(&ex);
\r
452 return INVOKERESULT_GENERIC_ERROR;
\r
456 /* for input state, return CLOSED rather than an exception */
\r
457 INT32_TO_NPVARIANT(0, result);
\r
458 return INVOKERESULT_NO_ERROR;
\r
464 case ID_input_length:
\r
466 double val = (double)libvlc_input_get_length(p_input, &ex);
\r
467 libvlc_input_free(p_input);
\r
468 if( libvlc_exception_raised(&ex) )
\r
470 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
471 libvlc_exception_clear(&ex);
\r
472 return INVOKERESULT_GENERIC_ERROR;
\r
474 DOUBLE_TO_NPVARIANT(val, result);
\r
475 return INVOKERESULT_NO_ERROR;
\r
477 case ID_input_position:
\r
479 double val = libvlc_input_get_position(p_input, &ex);
\r
480 libvlc_input_free(p_input);
\r
481 if( libvlc_exception_raised(&ex) )
\r
483 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
484 libvlc_exception_clear(&ex);
\r
485 return INVOKERESULT_GENERIC_ERROR;
\r
487 DOUBLE_TO_NPVARIANT(val, result);
\r
488 return INVOKERESULT_NO_ERROR;
\r
490 case ID_input_time:
\r
492 double val = (double)libvlc_input_get_time(p_input, &ex);
\r
493 libvlc_input_free(p_input);
\r
494 if( libvlc_exception_raised(&ex) )
\r
496 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
497 libvlc_exception_clear(&ex);
\r
498 return INVOKERESULT_GENERIC_ERROR;
\r
500 DOUBLE_TO_NPVARIANT(val, result);
\r
501 return INVOKERESULT_NO_ERROR;
\r
503 case ID_input_state:
\r
505 int val = libvlc_input_get_state(p_input, &ex);
\r
506 libvlc_input_free(p_input);
\r
507 if( libvlc_exception_raised(&ex) )
\r
509 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
510 libvlc_exception_clear(&ex);
\r
511 return INVOKERESULT_GENERIC_ERROR;
\r
513 INT32_TO_NPVARIANT(val, result);
\r
514 return INVOKERESULT_NO_ERROR;
\r
516 case ID_input_rate:
\r
518 float val = libvlc_input_get_rate(p_input, &ex);
\r
519 libvlc_input_free(p_input);
\r
520 if( libvlc_exception_raised(&ex) )
\r
522 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
523 libvlc_exception_clear(&ex);
\r
524 return INVOKERESULT_GENERIC_ERROR;
\r
526 DOUBLE_TO_NPVARIANT(val, result);
\r
527 return INVOKERESULT_NO_ERROR;
\r
531 double val = libvlc_input_get_fps(p_input, &ex);
\r
532 libvlc_input_free(p_input);
\r
533 if( libvlc_exception_raised(&ex) )
\r
535 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
536 libvlc_exception_clear(&ex);
\r
537 return INVOKERESULT_GENERIC_ERROR;
\r
539 DOUBLE_TO_NPVARIANT(val, result);
\r
540 return INVOKERESULT_NO_ERROR;
\r
542 case ID_input_hasvout:
\r
544 vlc_bool_t val = libvlc_input_has_vout(p_input, &ex);
\r
545 libvlc_input_free(p_input);
\r
546 if( libvlc_exception_raised(&ex) )
\r
548 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
549 libvlc_exception_clear(&ex);
\r
550 return INVOKERESULT_GENERIC_ERROR;
\r
552 BOOLEAN_TO_NPVARIANT(val, result);
\r
553 return INVOKERESULT_NO_ERROR;
\r
558 libvlc_input_free(p_input);
\r
560 return INVOKERESULT_GENERIC_ERROR;
\r
563 RuntimeNPObject::InvokeResult LibvlcInputNPObject::setProperty(int index, const NPVariant &value)
\r
565 /* is plugin still running */
\r
566 if( _instance->pdata )
\r
568 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
\r
569 libvlc_exception_t ex;
\r
570 libvlc_exception_init(&ex);
\r
572 libvlc_input_t *p_input = libvlc_playlist_get_input(p_plugin->getVLC(), &ex);
\r
573 if( libvlc_exception_raised(&ex) )
\r
575 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
576 libvlc_exception_clear(&ex);
\r
577 return INVOKERESULT_GENERIC_ERROR;
\r
582 case ID_input_position:
\r
584 if( ! NPVARIANT_IS_DOUBLE(value) )
\r
586 libvlc_input_free(p_input);
\r
587 return INVOKERESULT_INVALID_VALUE;
\r
590 float val = (float)NPVARIANT_TO_DOUBLE(value);
\r
591 libvlc_input_set_position(p_input, val, &ex);
\r
592 libvlc_input_free(p_input);
\r
593 if( libvlc_exception_raised(&ex) )
\r
595 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
596 libvlc_exception_clear(&ex);
\r
597 return INVOKERESULT_GENERIC_ERROR;
\r
599 return INVOKERESULT_NO_ERROR;
\r
601 case ID_input_time:
\r
604 if( NPVARIANT_IS_INT32(value) )
\r
605 val = (vlc_int64_t)NPVARIANT_TO_INT32(value);
\r
606 else if( NPVARIANT_IS_DOUBLE(value) )
\r
607 val = (vlc_int64_t)NPVARIANT_TO_DOUBLE(value);
\r
610 libvlc_input_free(p_input);
\r
611 return INVOKERESULT_INVALID_VALUE;
\r
614 libvlc_input_set_time(p_input, val, &ex);
\r
615 libvlc_input_free(p_input);
\r
616 if( libvlc_exception_raised(&ex) )
\r
618 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
619 libvlc_exception_clear(&ex);
\r
620 return INVOKERESULT_GENERIC_ERROR;
\r
622 return INVOKERESULT_NO_ERROR;
\r
624 case ID_input_rate:
\r
627 if( NPVARIANT_IS_INT32(value) )
\r
628 val = (float)NPVARIANT_TO_INT32(value);
\r
629 else if( NPVARIANT_IS_DOUBLE(value) )
\r
630 val = (float)NPVARIANT_TO_DOUBLE(value);
\r
633 libvlc_input_free(p_input);
\r
634 return INVOKERESULT_INVALID_VALUE;
\r
637 libvlc_input_set_rate(p_input, val, &ex);
\r
638 libvlc_input_free(p_input);
\r
639 if( libvlc_exception_raised(&ex) )
\r
641 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
642 libvlc_exception_clear(&ex);
\r
643 return INVOKERESULT_GENERIC_ERROR;
\r
645 return INVOKERESULT_NO_ERROR;
\r
650 libvlc_input_free(p_input);
\r
652 return INVOKERESULT_GENERIC_ERROR;
\r
655 const NPUTF8 * const LibvlcInputNPObject::methodNames[] =
\r
660 const int LibvlcInputNPObject::methodCount = sizeof(LibvlcInputNPObject::methodNames)/sizeof(NPUTF8 *);
\r
663 ** implementation of libvlc message object
\r
666 const NPUTF8 * const LibvlcMessageNPObject::propertyNames[] =
\r
675 const int LibvlcMessageNPObject::propertyCount = sizeof(LibvlcMessageNPObject::propertyNames)/sizeof(NPUTF8 *);
\r
677 enum LibvlcMessageNPObjectPropertyIds
\r
679 ID_message_severity,
\r
683 ID_message_message,
\r
686 RuntimeNPObject::InvokeResult LibvlcMessageNPObject::getProperty(int index, NPVariant &result)
\r
688 /* is plugin still running */
\r
689 if( _instance->pdata )
\r
693 case ID_message_severity:
\r
695 INT32_TO_NPVARIANT(_msg.i_severity, result);
\r
696 return INVOKERESULT_NO_ERROR;
\r
698 case ID_message_type:
\r
700 if( _msg.psz_type )
\r
702 int len = strlen(_msg.psz_type);
\r
703 NPUTF8* retval = (NPUTF8*)NPN_MemAlloc(len);
\r
706 memcpy(retval, _msg.psz_type, len);
\r
707 STRINGN_TO_NPVARIANT(retval, len, result);
\r
712 NULL_TO_NPVARIANT(result);
\r
714 return INVOKERESULT_NO_ERROR;
\r
716 case ID_message_name:
\r
718 if( _msg.psz_name )
\r
720 int len = strlen(_msg.psz_name);
\r
721 NPUTF8* retval = (NPUTF8*)NPN_MemAlloc(len);
\r
724 memcpy(retval, _msg.psz_name, len);
\r
725 STRINGN_TO_NPVARIANT(retval, len, result);
\r
730 NULL_TO_NPVARIANT(result);
\r
732 return INVOKERESULT_NO_ERROR;
\r
734 case ID_message_header:
\r
736 if( _msg.psz_header )
\r
738 int len = strlen(_msg.psz_header);
\r
739 NPUTF8* retval = (NPUTF8*)NPN_MemAlloc(len);
\r
742 memcpy(retval, _msg.psz_header, len);
\r
743 STRINGN_TO_NPVARIANT(retval, len, result);
\r
748 NULL_TO_NPVARIANT(result);
\r
750 return INVOKERESULT_NO_ERROR;
\r
752 case ID_message_message:
\r
754 if( _msg.psz_message )
\r
756 int len = strlen(_msg.psz_message);
\r
757 NPUTF8* retval = (NPUTF8*)NPN_MemAlloc(len);
\r
760 memcpy(retval, _msg.psz_message, len);
\r
761 STRINGN_TO_NPVARIANT(retval, len, result);
\r
766 NULL_TO_NPVARIANT(result);
\r
768 return INVOKERESULT_NO_ERROR;
\r
774 return INVOKERESULT_GENERIC_ERROR;
\r
777 const NPUTF8 * const LibvlcMessageNPObject::methodNames[] =
\r
782 const int LibvlcMessageNPObject::methodCount = sizeof(LibvlcMessageNPObject::methodNames)/sizeof(NPUTF8 *);
\r
785 ** implementation of libvlc message iterator object
\r
788 LibvlcMessageIteratorNPObject::LibvlcMessageIteratorNPObject(NPP instance, const NPClass *aClass) :
\r
789 RuntimeNPObject(instance, aClass),
\r
792 /* is plugin still running */
\r
793 if( instance->pdata )
\r
795 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(instance->pdata);
\r
796 libvlc_log_t *p_log = p_plugin->getLog();
\r
799 _p_iter = libvlc_log_get_iterator(p_log, NULL);
\r
804 LibvlcMessageIteratorNPObject::~LibvlcMessageIteratorNPObject()
\r
807 libvlc_log_iterator_free(_p_iter, NULL);
\r
810 const NPUTF8 * const LibvlcMessageIteratorNPObject::propertyNames[] =
\r
815 const int LibvlcMessageIteratorNPObject::propertyCount = sizeof(LibvlcMessageIteratorNPObject::propertyNames)/sizeof(NPUTF8 *);
\r
817 enum LibvlcMessageIteratorNPObjectPropertyIds
\r
819 ID_messageiterator_hasNext,
\r
822 RuntimeNPObject::InvokeResult LibvlcMessageIteratorNPObject::getProperty(int index, NPVariant &result)
\r
824 /* is plugin still running */
\r
825 if( _instance->pdata )
\r
827 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
\r
830 case ID_messageiterator_hasNext:
\r
832 if( _p_iter && p_plugin->getLog() )
\r
834 libvlc_exception_t ex;
\r
835 libvlc_exception_init(&ex);
\r
837 BOOLEAN_TO_NPVARIANT(libvlc_log_iterator_has_next(_p_iter, &ex), result);
\r
838 if( libvlc_exception_raised(&ex) )
\r
840 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
841 libvlc_exception_clear(&ex);
\r
842 return INVOKERESULT_GENERIC_ERROR;
\r
847 BOOLEAN_TO_NPVARIANT(0, result);
\r
849 return INVOKERESULT_NO_ERROR;
\r
855 return INVOKERESULT_GENERIC_ERROR;
\r
858 const NPUTF8 * const LibvlcMessageIteratorNPObject::methodNames[] =
\r
863 const int LibvlcMessageIteratorNPObject::methodCount = sizeof(LibvlcMessageIteratorNPObject::methodNames)/sizeof(NPUTF8 *);
\r
865 enum LibvlcMessageIteratorNPObjectMethodIds
\r
867 ID_messageiterator_next,
\r
870 RuntimeNPObject::InvokeResult LibvlcMessageIteratorNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)
\r
872 /* is plugin still running */
\r
873 if( _instance->pdata )
\r
875 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
\r
876 libvlc_exception_t ex;
\r
877 libvlc_exception_init(&ex);
\r
881 case ID_messageiterator_next:
\r
882 if( argCount == 0 )
\r
884 if( _p_iter && p_plugin->getLog() )
\r
886 struct libvlc_log_message_t buffer;
\r
888 buffer.sizeof_msg = sizeof(buffer);
\r
890 libvlc_log_iterator_next(_p_iter, &buffer, &ex);
\r
891 if( libvlc_exception_raised(&ex) )
\r
893 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
894 libvlc_exception_clear(&ex);
\r
895 return INVOKERESULT_GENERIC_ERROR;
\r
899 LibvlcMessageNPObject* message =
\r
900 static_cast<LibvlcMessageNPObject*>(NPN_CreateObject(_instance, RuntimeNPClass<LibvlcMessageNPObject>::getClass()));
\r
903 message->setMessage(buffer);
\r
904 OBJECT_TO_NPVARIANT(message, result);
\r
905 return INVOKERESULT_NO_ERROR;
\r
907 return INVOKERESULT_OUT_OF_MEMORY;
\r
910 return INVOKERESULT_GENERIC_ERROR;
\r
912 return INVOKERESULT_NO_SUCH_METHOD;
\r
917 return INVOKERESULT_GENERIC_ERROR;
\r
921 ** implementation of libvlc message object
\r
924 const NPUTF8 * const LibvlcMessagesNPObject::propertyNames[] =
\r
929 const int LibvlcMessagesNPObject::propertyCount = sizeof(LibvlcMessagesNPObject::propertyNames)/sizeof(NPUTF8 *);
\r
931 enum LibvlcMessagesNPObjectPropertyIds
\r
936 RuntimeNPObject::InvokeResult LibvlcMessagesNPObject::getProperty(int index, NPVariant &result)
\r
938 /* is plugin still running */
\r
939 if( _instance->pdata )
\r
941 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
\r
944 case ID_messages_count:
\r
946 libvlc_log_t *p_log = p_plugin->getLog();
\r
949 libvlc_exception_t ex;
\r
950 libvlc_exception_init(&ex);
\r
952 INT32_TO_NPVARIANT(libvlc_log_count(p_log, &ex), result);
\r
953 if( libvlc_exception_raised(&ex) )
\r
955 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
956 libvlc_exception_clear(&ex);
\r
957 return INVOKERESULT_GENERIC_ERROR;
\r
962 INT32_TO_NPVARIANT(0, result);
\r
964 return INVOKERESULT_NO_ERROR;
\r
970 return INVOKERESULT_GENERIC_ERROR;
\r
973 const NPUTF8 * const LibvlcMessagesNPObject::methodNames[] =
\r
979 const int LibvlcMessagesNPObject::methodCount = sizeof(LibvlcMessagesNPObject::methodNames)/sizeof(NPUTF8 *);
\r
981 enum LibvlcMessagesNPObjectMethodIds
\r
984 ID_messages_iterator,
\r
987 RuntimeNPObject::InvokeResult LibvlcMessagesNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)
\r
989 /* is plugin still running */
\r
990 if( _instance->pdata )
\r
992 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
\r
993 libvlc_exception_t ex;
\r
994 libvlc_exception_init(&ex);
\r
998 case ID_messages_clear:
\r
999 if( argCount == 0 )
\r
1001 libvlc_log_t *p_log = p_plugin->getLog();
\r
1004 libvlc_log_clear(p_log, &ex);
\r
1005 if( libvlc_exception_raised(&ex) )
\r
1007 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
1008 libvlc_exception_clear(&ex);
\r
1009 return INVOKERESULT_GENERIC_ERROR;
\r
1012 return INVOKERESULT_NO_ERROR;
\r
1014 return INVOKERESULT_NO_SUCH_METHOD;
\r
1016 case ID_messages_iterator:
\r
1017 if( argCount == 0 )
\r
1019 LibvlcMessageIteratorNPObject* iter =
\r
1020 static_cast<LibvlcMessageIteratorNPObject*>(NPN_CreateObject(_instance, RuntimeNPClass<LibvlcMessageIteratorNPObject>::getClass()));
\r
1023 OBJECT_TO_NPVARIANT(iter, result);
\r
1024 return INVOKERESULT_NO_ERROR;
\r
1026 return INVOKERESULT_OUT_OF_MEMORY;
\r
1028 return INVOKERESULT_NO_SUCH_METHOD;
\r
1034 return INVOKERESULT_GENERIC_ERROR;
\r
1039 ** implementation of libvlc message object
\r
1043 LibvlcLogNPObject::LibvlcLogNPObject(NPP instance, const NPClass *aClass) :
\r
1044 RuntimeNPObject(instance, aClass)
\r
1046 _p_vlcmessages = NPN_CreateObject(instance, RuntimeNPClass<LibvlcMessagesNPObject>::getClass());
\r
1049 LibvlcLogNPObject::~LibvlcLogNPObject()
\r
1051 NPN_ReleaseObject(_p_vlcmessages);
\r
1054 const NPUTF8 * const LibvlcLogNPObject::propertyNames[] =
\r
1060 const int LibvlcLogNPObject::propertyCount = sizeof(LibvlcLogNPObject::propertyNames)/sizeof(NPUTF8 *);
\r
1062 enum LibvlcLogNPObjectPropertyIds
\r
1068 RuntimeNPObject::InvokeResult LibvlcLogNPObject::getProperty(int index, NPVariant &result)
\r
1070 /* is plugin still running */
\r
1071 if( _instance->pdata )
\r
1073 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
\r
1074 libvlc_exception_t ex;
\r
1075 libvlc_exception_init(&ex);
\r
1079 case ID_log_messages:
\r
1081 OBJECT_TO_NPVARIANT(NPN_RetainObject(_p_vlcmessages), result);
\r
1082 return INVOKERESULT_NO_ERROR;
\r
1084 case ID_log_verbosity:
\r
1086 if( p_plugin->getLog() )
\r
1088 INT32_TO_NPVARIANT(libvlc_get_log_verbosity(p_plugin->getVLC(),
\r
1090 if( libvlc_exception_raised(&ex) )
\r
1092 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
1093 libvlc_exception_clear(&ex);
\r
1094 return INVOKERESULT_GENERIC_ERROR;
\r
1099 /* log is not enabled, return -1 */
\r
1100 DOUBLE_TO_NPVARIANT(-1.0, result);
\r
1102 return INVOKERESULT_NO_ERROR;
\r
1108 return INVOKERESULT_GENERIC_ERROR;
\r
1111 RuntimeNPObject::InvokeResult LibvlcLogNPObject::setProperty(int index, const NPVariant &value)
\r
1113 /* is plugin still running */
\r
1114 if( _instance->pdata )
\r
1116 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
\r
1117 libvlc_exception_t ex;
\r
1118 libvlc_exception_init(&ex);
\r
1122 case ID_log_verbosity:
\r
1123 if( isNumberValue(value) )
\r
1125 libvlc_instance_t* p_libvlc = p_plugin->getVLC();
\r
1126 libvlc_log_t *p_log = p_plugin->getLog();
\r
1127 int verbosity = numberValue(value);
\r
1128 if( verbosity >= 0 )
\r
1132 p_log = libvlc_log_open(p_libvlc, &ex);
\r
1133 if( libvlc_exception_raised(&ex) )
\r
1135 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
1136 libvlc_exception_clear(&ex);
\r
1137 return INVOKERESULT_GENERIC_ERROR;
\r
1139 p_plugin->setLog(p_log);
\r
1141 libvlc_set_log_verbosity(p_libvlc, (unsigned)verbosity, &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
1151 /* close log when verbosity is set to -1 */
\r
1152 p_plugin->setLog(NULL);
\r
1153 libvlc_log_close(p_log, &ex);
\r
1154 if( libvlc_exception_raised(&ex) )
\r
1156 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
1157 libvlc_exception_clear(&ex);
\r
1158 return INVOKERESULT_GENERIC_ERROR;
\r
1161 return INVOKERESULT_NO_ERROR;
\r
1163 return INVOKERESULT_INVALID_VALUE;
\r
1168 return INVOKERESULT_GENERIC_ERROR;
\r
1171 const NPUTF8 * const LibvlcLogNPObject::methodNames[] =
\r
1176 const int LibvlcLogNPObject::methodCount = sizeof(LibvlcLogNPObject::methodNames)/sizeof(NPUTF8 *);
\r
1179 ** implementation of libvlc playlist items object
\r
1182 const NPUTF8 * const LibvlcPlaylistItemsNPObject::propertyNames[] =
\r
1187 const int LibvlcPlaylistItemsNPObject::propertyCount = sizeof(LibvlcPlaylistItemsNPObject::propertyNames)/sizeof(NPUTF8 *);
\r
1189 enum LibvlcPlaylistItemsNPObjectPropertyIds
\r
1191 ID_playlistitems_count,
\r
1194 RuntimeNPObject::InvokeResult LibvlcPlaylistItemsNPObject::getProperty(int index, NPVariant &result)
\r
1196 /* is plugin still running */
\r
1197 if( _instance->pdata )
\r
1199 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
\r
1200 libvlc_exception_t ex;
\r
1201 libvlc_exception_init(&ex);
\r
1205 case ID_playlistitems_count:
\r
1207 int val = libvlc_playlist_items_count(p_plugin->getVLC(), &ex);
\r
1208 if( libvlc_exception_raised(&ex) )
\r
1210 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
1211 libvlc_exception_clear(&ex);
\r
1212 return INVOKERESULT_GENERIC_ERROR;
\r
1214 INT32_TO_NPVARIANT(val, result);
\r
1215 return INVOKERESULT_NO_ERROR;
\r
1221 return INVOKERESULT_GENERIC_ERROR;
\r
1224 const NPUTF8 * const LibvlcPlaylistItemsNPObject::methodNames[] =
\r
1230 const int LibvlcPlaylistItemsNPObject::methodCount = sizeof(LibvlcPlaylistItemsNPObject::methodNames)/sizeof(NPUTF8 *);
\r
1232 enum LibvlcPlaylistItemsNPObjectMethodIds
\r
1234 ID_playlistitems_clear,
\r
1235 ID_playlistitems_remove,
\r
1238 RuntimeNPObject::InvokeResult LibvlcPlaylistItemsNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)
\r
1240 /* is plugin still running */
\r
1241 if( _instance->pdata )
\r
1243 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
\r
1244 libvlc_exception_t ex;
\r
1245 libvlc_exception_init(&ex);
\r
1249 case ID_playlistitems_clear:
\r
1250 if( argCount == 0 )
\r
1252 libvlc_playlist_clear(p_plugin->getVLC(), &ex);
\r
1253 if( libvlc_exception_raised(&ex) )
\r
1255 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
1256 libvlc_exception_clear(&ex);
\r
1257 return INVOKERESULT_GENERIC_ERROR;
\r
1261 VOID_TO_NPVARIANT(result);
\r
1262 return INVOKERESULT_NO_ERROR;
\r
1265 return INVOKERESULT_NO_SUCH_METHOD;
\r
1266 case ID_playlistitems_remove:
\r
1267 if( (argCount == 1) && isNumberValue(args[0]) )
\r
1269 libvlc_playlist_delete_item(p_plugin->getVLC(), numberValue(args[0]), &ex);
\r
1270 if( libvlc_exception_raised(&ex) )
\r
1272 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
1273 libvlc_exception_clear(&ex);
\r
1274 return INVOKERESULT_GENERIC_ERROR;
\r
1278 VOID_TO_NPVARIANT(result);
\r
1279 return INVOKERESULT_NO_ERROR;
\r
1282 return INVOKERESULT_NO_SUCH_METHOD;
\r
1287 return INVOKERESULT_GENERIC_ERROR;
\r
1291 ** implementation of libvlc playlist object
\r
1295 LibvlcPlaylistNPObject::LibvlcPlaylistNPObject(NPP instance, const NPClass *aClass) :
\r
1296 RuntimeNPObject(instance, aClass)
\r
1298 _p_vlcplaylistitems = NPN_CreateObject(instance, RuntimeNPClass<LibvlcPlaylistItemsNPObject>::getClass());
\r
1301 LibvlcPlaylistNPObject::~LibvlcPlaylistNPObject()
\r
1303 NPN_ReleaseObject(_p_vlcplaylistitems);
\r
1306 const NPUTF8 * const LibvlcPlaylistNPObject::propertyNames[] =
\r
1308 "itemCount", /* deprecated */
\r
1313 const int LibvlcPlaylistNPObject::propertyCount = sizeof(LibvlcPlaylistNPObject::propertyNames)/sizeof(NPUTF8 *);
\r
1315 enum LibvlcPlaylistNPObjectPropertyIds
\r
1317 ID_playlist_itemcount,
\r
1318 ID_playlist_isplaying,
\r
1319 ID_playlist_items,
\r
1322 RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::getProperty(int index, NPVariant &result)
\r
1324 /* is plugin still running */
\r
1325 if( _instance->pdata )
\r
1327 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
\r
1328 libvlc_exception_t ex;
\r
1329 libvlc_exception_init(&ex);
\r
1333 case ID_playlist_itemcount: /* deprecated */
\r
1335 int val = libvlc_playlist_items_count(p_plugin->getVLC(), &ex);
\r
1336 if( libvlc_exception_raised(&ex) )
\r
1338 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
1339 libvlc_exception_clear(&ex);
\r
1340 return INVOKERESULT_GENERIC_ERROR;
\r
1342 INT32_TO_NPVARIANT(val, result);
\r
1343 return INVOKERESULT_NO_ERROR;
\r
1345 case ID_playlist_isplaying:
\r
1347 int val = libvlc_playlist_isplaying(p_plugin->getVLC(), &ex);
\r
1348 if( libvlc_exception_raised(&ex) )
\r
1350 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
1351 libvlc_exception_clear(&ex);
\r
1352 return INVOKERESULT_GENERIC_ERROR;
\r
1354 BOOLEAN_TO_NPVARIANT(val, result);
\r
1355 return INVOKERESULT_NO_ERROR;
\r
1357 case ID_playlist_items:
\r
1359 OBJECT_TO_NPVARIANT(NPN_RetainObject(_p_vlcplaylistitems), result);
\r
1360 return INVOKERESULT_NO_ERROR;
\r
1366 return INVOKERESULT_GENERIC_ERROR;
\r
1369 const NPUTF8 * const LibvlcPlaylistNPObject::methodNames[] =
\r
1378 "clear", /* deprecated */
\r
1379 "removeItem", /* deprecated */
\r
1382 const int LibvlcPlaylistNPObject::methodCount = sizeof(LibvlcPlaylistNPObject::methodNames)/sizeof(NPUTF8 *);
\r
1384 enum LibvlcPlaylistNPObjectMethodIds
\r
1388 ID_playlist_playItem,
\r
1389 ID_playlist_togglepause,
\r
1393 ID_playlist_clear,
\r
1394 ID_playlist_removeitem
\r
1397 RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)
\r
1399 /* is plugin still running */
\r
1400 if( _instance->pdata )
\r
1402 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
\r
1403 libvlc_exception_t ex;
\r
1404 libvlc_exception_init(&ex);
\r
1408 case ID_playlist_add:
\r
1410 if( (argCount < 1) || (argCount > 3) )
\r
1411 return INVOKERESULT_NO_SUCH_METHOD;
\r
1416 if( NPVARIANT_IS_STRING(args[0]) )
\r
1418 char *s = stringValue(NPVARIANT_TO_STRING(args[0]));
\r
1421 url = p_plugin->getAbsoluteURL(s);
\r
1425 // problem with combining url, use argument
\r
1429 return INVOKERESULT_OUT_OF_MEMORY;
\r
1432 return INVOKERESULT_NO_SUCH_METHOD;
\r
1434 char *name = NULL;
\r
1436 // grab name if available
\r
1437 if( argCount > 1 )
\r
1439 if( NPVARIANT_IS_NULL(args[1]) )
\r
1443 else if( NPVARIANT_IS_STRING(args[1]) )
\r
1445 name = stringValue(NPVARIANT_TO_STRING(args[0]));
\r
1450 return INVOKERESULT_INVALID_VALUE;
\r
1454 int i_options = 0;
\r
1455 char** ppsz_options = NULL;
\r
1457 // grab options if available
\r
1458 if( argCount > 2 )
\r
1460 if( NPVARIANT_IS_NULL(args[2]) )
\r
1464 else if( NPVARIANT_IS_STRING(args[2]) )
\r
1466 parseOptions(NPVARIANT_TO_STRING(args[2]), &i_options, &ppsz_options);
\r
1469 else if( NPVARIANT_IS_OBJECT(args[2]) )
\r
1471 parseOptions(NPVARIANT_TO_OBJECT(args[2]), &i_options, &ppsz_options);
\r
1477 return INVOKERESULT_INVALID_VALUE;
\r
1481 int item = libvlc_playlist_add_extended(p_plugin->getVLC(),
\r
1485 const_cast<const char **>(ppsz_options),
\r
1489 for( int i=0; i< i_options; ++i )
\r
1491 delete ppsz_options[i];
\r
1493 delete ppsz_options;
\r
1495 if( libvlc_exception_raised(&ex) )
\r
1497 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
1498 libvlc_exception_clear(&ex);
\r
1499 return INVOKERESULT_GENERIC_ERROR;
\r
1503 INT32_TO_NPVARIANT(item, result);
\r
1504 return INVOKERESULT_NO_ERROR;
\r
1507 case ID_playlist_play:
\r
1508 if( argCount == 0 )
\r
1510 libvlc_playlist_play(p_plugin->getVLC(), -1, 0, NULL, &ex);
\r
1511 if( libvlc_exception_raised(&ex) )
\r
1513 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
1514 libvlc_exception_clear(&ex);
\r
1515 return INVOKERESULT_GENERIC_ERROR;
\r
1519 VOID_TO_NPVARIANT(result);
\r
1520 return INVOKERESULT_NO_ERROR;
\r
1523 return INVOKERESULT_NO_SUCH_METHOD;
\r
1524 case ID_playlist_playItem:
\r
1525 if( (argCount == 1) && isNumberValue(args[0]) )
\r
1527 libvlc_playlist_play(p_plugin->getVLC(), numberValue(args[0]), 0, NULL, &ex);
\r
1528 if( libvlc_exception_raised(&ex) )
\r
1530 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
1531 libvlc_exception_clear(&ex);
\r
1532 return INVOKERESULT_GENERIC_ERROR;
\r
1536 VOID_TO_NPVARIANT(result);
\r
1537 return INVOKERESULT_NO_ERROR;
\r
1540 return INVOKERESULT_NO_SUCH_METHOD;
\r
1541 case ID_playlist_togglepause:
\r
1542 if( argCount == 0 )
\r
1544 libvlc_playlist_pause(p_plugin->getVLC(), &ex);
\r
1545 if( libvlc_exception_raised(&ex) )
\r
1547 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
1548 libvlc_exception_clear(&ex);
\r
1549 return INVOKERESULT_GENERIC_ERROR;
\r
1553 VOID_TO_NPVARIANT(result);
\r
1554 return INVOKERESULT_NO_ERROR;
\r
1557 return INVOKERESULT_NO_SUCH_METHOD;
\r
1558 case ID_playlist_stop:
\r
1559 if( argCount == 0 )
\r
1561 libvlc_playlist_stop(p_plugin->getVLC(), &ex);
\r
1562 if( libvlc_exception_raised(&ex) )
\r
1564 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
1565 libvlc_exception_clear(&ex);
\r
1566 return INVOKERESULT_GENERIC_ERROR;
\r
1570 VOID_TO_NPVARIANT(result);
\r
1571 return INVOKERESULT_NO_ERROR;
\r
1574 return INVOKERESULT_NO_SUCH_METHOD;
\r
1575 case ID_playlist_next:
\r
1576 if( argCount == 0 )
\r
1578 libvlc_playlist_next(p_plugin->getVLC(), &ex);
\r
1579 if( libvlc_exception_raised(&ex) )
\r
1581 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
1582 libvlc_exception_clear(&ex);
\r
1583 return INVOKERESULT_GENERIC_ERROR;
\r
1587 VOID_TO_NPVARIANT(result);
\r
1588 return INVOKERESULT_NO_ERROR;
\r
1591 return INVOKERESULT_NO_SUCH_METHOD;
\r
1592 case ID_playlist_prev:
\r
1593 if( argCount == 0 )
\r
1595 libvlc_playlist_prev(p_plugin->getVLC(), &ex);
\r
1596 if( libvlc_exception_raised(&ex) )
\r
1598 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
1599 libvlc_exception_clear(&ex);
\r
1600 return INVOKERESULT_GENERIC_ERROR;
\r
1604 VOID_TO_NPVARIANT(result);
\r
1605 return INVOKERESULT_NO_ERROR;
\r
1608 return INVOKERESULT_NO_SUCH_METHOD;
\r
1609 case ID_playlist_clear: /* deprecated */
\r
1610 if( argCount == 0 )
\r
1612 libvlc_playlist_clear(p_plugin->getVLC(), &ex);
\r
1613 if( libvlc_exception_raised(&ex) )
\r
1615 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
1616 libvlc_exception_clear(&ex);
\r
1617 return INVOKERESULT_GENERIC_ERROR;
\r
1621 VOID_TO_NPVARIANT(result);
\r
1622 return INVOKERESULT_NO_ERROR;
\r
1625 return INVOKERESULT_NO_SUCH_METHOD;
\r
1626 case ID_playlist_removeitem: /* deprecated */
\r
1627 if( (argCount == 1) && isNumberValue(args[0]) )
\r
1629 libvlc_playlist_delete_item(p_plugin->getVLC(), numberValue(args[0]), &ex);
\r
1630 if( libvlc_exception_raised(&ex) )
\r
1632 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
1633 libvlc_exception_clear(&ex);
\r
1634 return INVOKERESULT_GENERIC_ERROR;
\r
1638 VOID_TO_NPVARIANT(result);
\r
1639 return INVOKERESULT_NO_ERROR;
\r
1642 return INVOKERESULT_NO_SUCH_METHOD;
\r
1647 return INVOKERESULT_GENERIC_ERROR;
\r
1650 void LibvlcPlaylistNPObject::parseOptions(const NPString &s, int *i_options, char*** ppsz_options)
\r
1652 if( s.utf8length )
\r
1654 char *val = stringValue(s);
\r
1657 long capacity = 16;
\r
1658 char **options = (char **)malloc(capacity*sizeof(char *));
\r
1663 char *end = val + s.utf8length;
\r
1664 while( val < end )
\r
1666 // skip leading blanks
\r
1667 while( (val < end)
\r
1668 && ((*val == ' ' ) || (*val == '\t')) )
\r
1671 char *start = val;
\r
1672 // skip till we get a blank character
\r
1673 while( (val < end)
\r
1675 && (*val != '\t') )
\r
1677 char c = *(val++);
\r
1678 if( ('\'' == c) || ('"' == c) )
\r
1680 // skip till end of string
\r
1681 while( (val < end) && (*(val++) != c ) );
\r
1687 if( nOptions == capacity )
\r
1690 char **moreOptions = (char **)realloc(options, capacity*sizeof(char*));
\r
1691 if( ! moreOptions )
\r
1693 /* failed to allocate more memory */
\r
1695 /* return what we got so far */
\r
1696 *i_options = nOptions;
\r
1697 *ppsz_options = options;
\r
1700 options = moreOptions;
\r
1703 options[nOptions++] = strdup(start);
\r
1706 // must be end of string
\r
1709 *i_options = nOptions;
\r
1710 *ppsz_options = options;
\r
1717 void LibvlcPlaylistNPObject::parseOptions(NPObject *obj, int *i_options, char*** ppsz_options)
\r
1719 /* WARNING: Safari does not implement NPN_HasProperty/NPN_HasMethod */
\r
1723 /* we are expecting to have a Javascript Array object */
\r
1724 NPIdentifier propId = NPN_GetStringIdentifier("length");
\r
1725 if( NPN_GetProperty(_instance, obj, propId, &value) )
\r
1727 int count = numberValue(value);
\r
1728 NPN_ReleaseVariantValue(&value);
\r
1732 long capacity = 16;
\r
1733 char **options = (char **)malloc(capacity*sizeof(char *));
\r
1738 while( nOptions < count )
\r
1740 propId = NPN_GetIntIdentifier(nOptions);
\r
1741 if( ! NPN_GetProperty(_instance, obj, propId, &value) )
\r
1742 /* return what we got so far */
\r
1745 if( ! NPVARIANT_IS_STRING(value) )
\r
1747 /* return what we got so far */
\r
1748 NPN_ReleaseVariantValue(&value);
\r
1752 if( nOptions == capacity )
\r
1755 char **moreOptions = (char **)realloc(options, capacity*sizeof(char*));
\r
1756 if( ! moreOptions )
\r
1758 /* failed to allocate more memory */
\r
1759 NPN_ReleaseVariantValue(&value);
\r
1760 /* return what we got so far */
\r
1761 *i_options = nOptions;
\r
1762 *ppsz_options = options;
\r
1765 options = moreOptions;
\r
1768 options[nOptions++] = stringValue(value);
\r
1770 *i_options = nOptions;
\r
1771 *ppsz_options = options;
\r
1778 ** implementation of libvlc video object
\r
1781 const NPUTF8 * const LibvlcVideoNPObject::propertyNames[] =
\r
1791 enum LibvlcVideoNPObjectPropertyIds
\r
1793 ID_video_fullscreen,
\r
1796 ID_video_aspectratio,
\r
1797 ID_video_subtitle,
\r
1801 const int LibvlcVideoNPObject::propertyCount = sizeof(LibvlcVideoNPObject::propertyNames)/sizeof(NPUTF8 *);
\r
1803 RuntimeNPObject::InvokeResult LibvlcVideoNPObject::getProperty(int index, NPVariant &result)
\r
1805 /* is plugin still running */
\r
1806 if( _instance->pdata )
\r
1808 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
\r
1809 libvlc_exception_t ex;
\r
1810 libvlc_exception_init(&ex);
\r
1812 libvlc_input_t *p_input = libvlc_playlist_get_input(p_plugin->getVLC(), &ex);
\r
1813 if( libvlc_exception_raised(&ex) )
\r
1815 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
1816 libvlc_exception_clear(&ex);
\r
1817 return INVOKERESULT_GENERIC_ERROR;
\r
1822 case ID_video_fullscreen:
\r
1824 int val = libvlc_get_fullscreen(p_input, &ex);
\r
1825 libvlc_input_free(p_input);
\r
1826 if( libvlc_exception_raised(&ex) )
\r
1828 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
1829 libvlc_exception_clear(&ex);
\r
1830 return INVOKERESULT_GENERIC_ERROR;
\r
1832 BOOLEAN_TO_NPVARIANT(val, result);
\r
1833 return INVOKERESULT_NO_ERROR;
\r
1835 case ID_video_height:
\r
1837 int val = libvlc_video_get_height(p_input, &ex);
\r
1838 libvlc_input_free(p_input);
\r
1839 if( libvlc_exception_raised(&ex) )
\r
1841 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
1842 libvlc_exception_clear(&ex);
\r
1843 return INVOKERESULT_GENERIC_ERROR;
\r
1845 INT32_TO_NPVARIANT(val, result);
\r
1846 return INVOKERESULT_NO_ERROR;
\r
1848 case ID_video_width:
\r
1850 int val = libvlc_video_get_width(p_input, &ex);
\r
1851 libvlc_input_free(p_input);
\r
1852 if( libvlc_exception_raised(&ex) )
\r
1854 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
1855 libvlc_exception_clear(&ex);
\r
1856 return INVOKERESULT_GENERIC_ERROR;
\r
1858 INT32_TO_NPVARIANT(val, result);
\r
1859 return INVOKERESULT_NO_ERROR;
\r
1861 case ID_video_aspectratio:
\r
1863 NPUTF8 *psz_aspect = libvlc_video_get_aspect_ratio(p_input, &ex);
\r
1864 libvlc_input_free(p_input);
\r
1865 if( libvlc_exception_raised(&ex) )
\r
1867 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
1868 libvlc_exception_clear(&ex);
\r
1869 return INVOKERESULT_GENERIC_ERROR;
\r
1872 return INVOKERESULT_GENERIC_ERROR;
\r
1874 STRINGZ_TO_NPVARIANT(psz_aspect, result);
\r
1875 return INVOKERESULT_NO_ERROR;
\r
1877 case ID_video_subtitle:
\r
1879 int i_spu = libvlc_video_get_spu(p_input, &ex);
\r
1880 libvlc_input_free(p_input);
\r
1881 if( libvlc_exception_raised(&ex) )
\r
1883 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
1884 libvlc_exception_clear(&ex);
\r
1885 return INVOKERESULT_GENERIC_ERROR;
\r
1887 INT32_TO_NPVARIANT(i_spu, result);
\r
1888 return INVOKERESULT_NO_ERROR;
\r
1890 case ID_video_crop:
\r
1892 NPUTF8 *psz_geometry = libvlc_video_get_crop_geometry(p_input, &ex);
\r
1893 libvlc_input_free(p_input);
\r
1894 if( libvlc_exception_raised(&ex) )
\r
1896 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
1897 libvlc_exception_clear(&ex);
\r
1898 return INVOKERESULT_GENERIC_ERROR;
\r
1900 if( !psz_geometry )
\r
1901 return INVOKERESULT_GENERIC_ERROR;
\r
1903 STRINGZ_TO_NPVARIANT(psz_geometry, result);
\r
1904 return INVOKERESULT_NO_ERROR;
\r
1907 libvlc_input_free(p_input);
\r
1909 return INVOKERESULT_GENERIC_ERROR;
\r
1912 RuntimeNPObject::InvokeResult LibvlcVideoNPObject::setProperty(int index, const NPVariant &value)
\r
1914 /* is plugin still running */
\r
1915 if( _instance->pdata )
\r
1917 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
\r
1918 libvlc_exception_t ex;
\r
1919 libvlc_exception_init(&ex);
\r
1921 libvlc_input_t *p_input = libvlc_playlist_get_input(p_plugin->getVLC(), &ex);
\r
1922 if( libvlc_exception_raised(&ex) )
\r
1924 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
1925 libvlc_exception_clear(&ex);
\r
1926 return INVOKERESULT_GENERIC_ERROR;
\r
1931 case ID_video_fullscreen:
\r
1933 if( ! NPVARIANT_IS_BOOLEAN(value) )
\r
1935 libvlc_input_free(p_input);
\r
1936 return INVOKERESULT_INVALID_VALUE;
\r
1939 int val = NPVARIANT_TO_BOOLEAN(value);
\r
1940 libvlc_set_fullscreen(p_input, val, &ex);
\r
1941 libvlc_input_free(p_input);
\r
1943 if( libvlc_exception_raised(&ex) )
\r
1945 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
1946 libvlc_exception_clear(&ex);
\r
1947 return INVOKERESULT_GENERIC_ERROR;
\r
1949 return INVOKERESULT_NO_ERROR;
\r
1951 case ID_video_aspectratio:
\r
1953 char *psz_aspect = NULL;
\r
1955 if( ! NPVARIANT_IS_STRING(value) )
\r
1957 libvlc_input_free(p_input);
\r
1958 return INVOKERESULT_INVALID_VALUE;
\r
1961 psz_aspect = stringValue(NPVARIANT_TO_STRING(value));
\r
1964 libvlc_input_free(p_input);
\r
1965 return INVOKERESULT_GENERIC_ERROR;
\r
1968 libvlc_video_set_aspect_ratio(p_input, psz_aspect, &ex);
\r
1969 delete psz_aspect;
\r
1970 libvlc_input_free(p_input);
\r
1972 if( libvlc_exception_raised(&ex) )
\r
1974 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
1975 libvlc_exception_clear(&ex);
\r
1976 return INVOKERESULT_GENERIC_ERROR;
\r
1978 return INVOKERESULT_NO_ERROR;
\r
1980 case ID_video_subtitle:
\r
1982 if( isNumberValue(value) )
\r
1984 libvlc_video_set_spu(p_input,
\r
1985 numberValue(value), &ex);
\r
1986 libvlc_input_free(p_input);
\r
1987 if( libvlc_exception_raised(&ex) )
\r
1989 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
1990 libvlc_exception_clear(&ex);
\r
1991 return INVOKERESULT_GENERIC_ERROR;
\r
1993 return INVOKERESULT_NO_ERROR;
\r
1995 libvlc_input_free(p_input);
\r
1996 return INVOKERESULT_INVALID_VALUE;
\r
1998 case ID_video_crop:
\r
2000 char *psz_geometry = NULL;
\r
2002 if( ! NPVARIANT_IS_STRING(value) )
\r
2004 libvlc_input_free(p_input);
\r
2005 return INVOKERESULT_INVALID_VALUE;
\r
2008 psz_geometry = stringValue(NPVARIANT_TO_STRING(value));
\r
2009 if( !psz_geometry )
\r
2011 libvlc_input_free(p_input);
\r
2012 return INVOKERESULT_GENERIC_ERROR;
\r
2015 libvlc_video_set_crop_geometry(p_input, psz_geometry, &ex);
\r
2016 delete psz_geometry;
\r
2017 libvlc_input_free(p_input);
\r
2019 if( libvlc_exception_raised(&ex) )
\r
2021 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
2022 libvlc_exception_clear(&ex);
\r
2023 return INVOKERESULT_GENERIC_ERROR;
\r
2025 return INVOKERESULT_NO_ERROR;
\r
2028 libvlc_input_free(p_input);
\r
2030 return INVOKERESULT_GENERIC_ERROR;
\r
2033 const NPUTF8 * const LibvlcVideoNPObject::methodNames[] =
\r
2035 "toggleFullscreen",
\r
2038 enum LibvlcVideoNPObjectMethodIds
\r
2040 ID_video_togglefullscreen,
\r
2043 const int LibvlcVideoNPObject::methodCount = sizeof(LibvlcVideoNPObject::methodNames)/sizeof(NPUTF8 *);
\r
2045 RuntimeNPObject::InvokeResult LibvlcVideoNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)
\r
2047 /* is plugin still running */
\r
2048 if( _instance->pdata )
\r
2050 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
\r
2051 libvlc_exception_t ex;
\r
2052 libvlc_exception_init(&ex);
\r
2054 libvlc_input_t *p_input = libvlc_playlist_get_input(p_plugin->getVLC(), &ex);
\r
2055 if( libvlc_exception_raised(&ex) )
\r
2057 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
2058 libvlc_exception_clear(&ex);
\r
2059 return INVOKERESULT_GENERIC_ERROR;
\r
2064 case ID_video_togglefullscreen:
\r
2065 if( argCount == 0 )
\r
2067 libvlc_toggle_fullscreen(p_input, &ex);
\r
2068 libvlc_input_free(p_input);
\r
2069 if( libvlc_exception_raised(&ex) )
\r
2071 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
2072 libvlc_exception_clear(&ex);
\r
2073 return INVOKERESULT_GENERIC_ERROR;
\r
2077 VOID_TO_NPVARIANT(result);
\r
2078 return INVOKERESULT_NO_ERROR;
\r
2083 /* cannot get input, probably not playing */
\r
2084 if( libvlc_exception_raised(&ex) )
\r
2086 NPN_SetException(this, libvlc_exception_get_message(&ex));
\r
2087 libvlc_exception_clear(&ex);
\r
2089 return INVOKERESULT_GENERIC_ERROR;
\r
2091 return INVOKERESULT_NO_SUCH_METHOD;
\r
2093 return INVOKERESULT_NO_SUCH_METHOD;
\r
2096 return INVOKERESULT_GENERIC_ERROR;
\r