📄 npolibvlc.cpp
字号:
libvlc_exception_t ex; libvlc_exception_init(&ex); switch( index ) { case ID_audio_togglemute: if( argCount == 0 ) { libvlc_audio_toggle_mute(p_plugin->getVLC(), &ex); if( libvlc_exception_raised(&ex) ) { NPN_SetException(this, libvlc_exception_get_message(&ex)); libvlc_exception_clear(&ex); return INVOKERESULT_GENERIC_ERROR; } else { VOID_TO_NPVARIANT(result); return INVOKERESULT_NO_ERROR; } } return INVOKERESULT_NO_SUCH_METHOD; default: ; } } return INVOKERESULT_GENERIC_ERROR;}/*** implementation of libvlc input object*/const NPUTF8 * const LibvlcInputNPObject::propertyNames[] = { "length", "position", "time", "state", "rate", "fps", "hasVout",};const int LibvlcInputNPObject::propertyCount = sizeof(LibvlcInputNPObject::propertyNames)/sizeof(NPUTF8 *);enum LibvlcInputNPObjectPropertyIds{ ID_input_length, ID_input_position, ID_input_time, ID_input_state, ID_input_rate, ID_input_fps, ID_input_hasvout,};RuntimeNPObject::InvokeResult LibvlcInputNPObject::getProperty(int index, NPVariant &result){ /* is plugin still running */ if( _instance->pdata ) { VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata); libvlc_exception_t ex; libvlc_exception_init(&ex); libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_plugin->getVLC(), &ex); if( libvlc_exception_raised(&ex) ) { if( index != ID_input_state ) { NPN_SetException(this, libvlc_exception_get_message(&ex)); libvlc_exception_clear(&ex); return INVOKERESULT_GENERIC_ERROR; } else { /* for input state, return CLOSED rather than an exception */ INT32_TO_NPVARIANT(0, result); return INVOKERESULT_NO_ERROR; } } switch( index ) { case ID_input_length: { double val = (double)libvlc_media_player_get_length(p_md, &ex); libvlc_media_player_release(p_md); if( libvlc_exception_raised(&ex) ) { NPN_SetException(this, libvlc_exception_get_message(&ex)); libvlc_exception_clear(&ex); return INVOKERESULT_GENERIC_ERROR; } DOUBLE_TO_NPVARIANT(val, result); return INVOKERESULT_NO_ERROR; } case ID_input_position: { double val = libvlc_media_player_get_position(p_md, &ex); libvlc_media_player_release(p_md); if( libvlc_exception_raised(&ex) ) { NPN_SetException(this, libvlc_exception_get_message(&ex)); libvlc_exception_clear(&ex); return INVOKERESULT_GENERIC_ERROR; } DOUBLE_TO_NPVARIANT(val, result); return INVOKERESULT_NO_ERROR; } case ID_input_time: { double val = (double)libvlc_media_player_get_time(p_md, &ex); libvlc_media_player_release(p_md); if( libvlc_exception_raised(&ex) ) { NPN_SetException(this, libvlc_exception_get_message(&ex)); libvlc_exception_clear(&ex); return INVOKERESULT_GENERIC_ERROR; } DOUBLE_TO_NPVARIANT(val, result); return INVOKERESULT_NO_ERROR; } case ID_input_state: { int val = libvlc_media_player_get_state(p_md, &ex); libvlc_media_player_release(p_md); if( libvlc_exception_raised(&ex) ) { NPN_SetException(this, libvlc_exception_get_message(&ex)); libvlc_exception_clear(&ex); return INVOKERESULT_GENERIC_ERROR; } INT32_TO_NPVARIANT(val, result); return INVOKERESULT_NO_ERROR; } case ID_input_rate: { float val = libvlc_media_player_get_rate(p_md, &ex); libvlc_media_player_release(p_md); if( libvlc_exception_raised(&ex) ) { NPN_SetException(this, libvlc_exception_get_message(&ex)); libvlc_exception_clear(&ex); return INVOKERESULT_GENERIC_ERROR; } DOUBLE_TO_NPVARIANT(val, result); return INVOKERESULT_NO_ERROR; } case ID_input_fps: { double val = libvlc_media_player_get_fps(p_md, &ex); libvlc_media_player_release(p_md); if( libvlc_exception_raised(&ex) ) { NPN_SetException(this, libvlc_exception_get_message(&ex)); libvlc_exception_clear(&ex); return INVOKERESULT_GENERIC_ERROR; } DOUBLE_TO_NPVARIANT(val, result); return INVOKERESULT_NO_ERROR; } case ID_input_hasvout: { bool val = libvlc_media_player_has_vout(p_md, &ex); libvlc_media_player_release(p_md); if( libvlc_exception_raised(&ex) ) { NPN_SetException(this, libvlc_exception_get_message(&ex)); libvlc_exception_clear(&ex); return INVOKERESULT_GENERIC_ERROR; } BOOLEAN_TO_NPVARIANT(val, result); return INVOKERESULT_NO_ERROR; } default: ; } libvlc_media_player_release(p_md); } return INVOKERESULT_GENERIC_ERROR;}RuntimeNPObject::InvokeResult LibvlcInputNPObject::setProperty(int index, const NPVariant &value){ /* is plugin still running */ if( _instance->pdata ) { VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata); libvlc_exception_t ex; libvlc_exception_init(&ex); libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_plugin->getVLC(), &ex); if( libvlc_exception_raised(&ex) ) { NPN_SetException(this, libvlc_exception_get_message(&ex)); libvlc_exception_clear(&ex); return INVOKERESULT_GENERIC_ERROR; } switch( index ) { case ID_input_position: { if( ! NPVARIANT_IS_DOUBLE(value) ) { libvlc_media_player_release(p_md); return INVOKERESULT_INVALID_VALUE; } float val = (float)NPVARIANT_TO_DOUBLE(value); libvlc_media_player_set_position(p_md, val, &ex); libvlc_media_player_release(p_md); if( libvlc_exception_raised(&ex) ) { NPN_SetException(this, libvlc_exception_get_message(&ex)); libvlc_exception_clear(&ex); return INVOKERESULT_GENERIC_ERROR; } return INVOKERESULT_NO_ERROR; } case ID_input_time: { int64_t val; if( NPVARIANT_IS_INT32(value) ) val = (int64_t)NPVARIANT_TO_INT32(value); else if( NPVARIANT_IS_DOUBLE(value) ) val = (int64_t)NPVARIANT_TO_DOUBLE(value); else { libvlc_media_player_release(p_md); return INVOKERESULT_INVALID_VALUE; } libvlc_media_player_set_time(p_md, val, &ex); libvlc_media_player_release(p_md); if( libvlc_exception_raised(&ex) ) { NPN_SetException(this, libvlc_exception_get_message(&ex)); libvlc_exception_clear(&ex); return INVOKERESULT_GENERIC_ERROR; } return INVOKERESULT_NO_ERROR; } case ID_input_rate: { float val; if( NPVARIANT_IS_INT32(value) ) val = (float)NPVARIANT_TO_INT32(value); else if( NPVARIANT_IS_DOUBLE(value) ) val = (float)NPVARIANT_TO_DOUBLE(value); else { libvlc_media_player_release(p_md); return INVOKERESULT_INVALID_VALUE; } libvlc_media_player_set_rate(p_md, val, &ex); libvlc_media_player_release(p_md); if( libvlc_exception_raised(&ex) ) { NPN_SetException(this, libvlc_exception_get_message(&ex)); libvlc_exception_clear(&ex); return INVOKERESULT_GENERIC_ERROR; } return INVOKERESULT_NO_ERROR; } default: ; } libvlc_media_player_release(p_md); } return INVOKERESULT_GENERIC_ERROR;}const NPUTF8 * const LibvlcInputNPObject::methodNames[] ={ /* no methods */};const int LibvlcInputNPObject::methodCount = sizeof(LibvlcInputNPObject::methodNames)/sizeof(NPUTF8 *);/*** implementation of libvlc message object*/const NPUTF8 * const LibvlcMessageNPObject::propertyNames[] = { "severity", "type", "name", "header", "message",};const int LibvlcMessageNPObject::propertyCount = sizeof(LibvlcMessageNPObject::propertyNames)/sizeof(NPUTF8 *);enum LibvlcMessageNPObjectPropertyIds{ ID_message_severity, ID_message_type, ID_message_name, ID_message_header, ID_message_message,};RuntimeNPObject::InvokeResult LibvlcMessageNPObject::getProperty(int index, NPVariant &result){ /* is plugin still running */ if( _instance->pdata ) { switch( index ) { case ID_message_severity: { INT32_TO_NPVARIANT(_msg.i_severity, result); return INVOKERESULT_NO_ERROR; } case ID_message_type: { if( _msg.psz_type ) { int len = strlen(_msg.psz_type); NPUTF8* retval = (NPUTF8*)NPN_MemAlloc(len); if( retval ) { memcpy(retval, _msg.psz_type, len); STRINGN_TO_NPVARIANT(retval, len, result); } } else { NULL_TO_NPVARIANT(result); } return INVOKERESULT_NO_ERROR; } case ID_message_name: { if( _msg.psz_name ) { int len = strlen(_msg.psz_name); NPUTF8* retval = (NPUTF8*)NPN_MemAlloc(len); if( retval ) { memcpy(retval, _msg.psz_name, len); STRINGN_TO_NPVARIANT(retval, len, result); } } else { NULL_TO_NPVARIANT(result); } return INVOKERESULT_NO_ERROR; } case ID_message_header: { if( _msg.psz_header ) { int len = strlen(_msg.psz_header); NPUTF8* retval = (NPUTF8*)NPN_MemAlloc(len); if( retval ) { memcpy(retval, _msg.psz_header, len); STRINGN_TO_NPVARIANT(retval, len, result); } } else { NULL_TO_NPVARIANT(result); } return INVOKERESULT_NO_ERROR; } case ID_message_message: { if( _msg.psz_message ) { int len = strlen(_msg.psz_message); NPUTF8* retval = (NPUTF8*)NPN_MemAlloc(len); if( retval ) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -