📄 atmo.cpp
字号:
} /* close serial port if it is open (all OS specific is inside CAtmoSerialConnection implemented / defined) */ CAtmoConnection *p_atmo_connection = p_atmo_dyndata->getAtmoConnection(); p_atmo_dyndata->setAtmoConnection(NULL); if(p_atmo_connection) { p_atmo_connection->CloseConnection(); delete p_atmo_connection; } p_atmo_dyndata->UnLockCriticalSection(); } }#if defined(WIN32) } else if(p_sys->pf_ctrl_atmo_finalize) { /* on win32 with active ctrl dll */ p_sys->pf_ctrl_atmo_finalize(what);#endif }}/*switch the current light effect - does only something on win32, with theexternal libraries - if the buildin effects are used nothing happens*/static int32_t AtmoSwitchEffect(filter_t *p_filter, int32_t newMode){ filter_sys_t *p_sys = p_filter->p_sys; if(p_sys->p_atmo_config) { /* buildin driver doesnt know different modes for effects so this function call would just do nothing special in this case */#if defined(WIN32) } else if(p_sys->pf_ctrl_atmo_switch_effect) { /* on win32 with active ctrl dll */ return p_sys->pf_ctrl_atmo_switch_effect(newMode);#endif } return emDisabled;}/*set the current live picture source, does only something on win32,with the external libraries - if the buildin effects are used nothinghappens...*/static int32_t AtmoSetLiveSource(filter_t *p_filter, int32_t newSource){ filter_sys_t *p_sys = p_filter->p_sys; if(p_sys->p_atmo_config) { /* buildin driver doesnt know different sources so this function call would just do nothing special in this case */#if defined(WIN32) } else if(p_sys->pf_ctrl_atmo_set_live_source) { /* on win32 with active ctrl dll */ return p_sys->pf_ctrl_atmo_set_live_source(newSource);#endif } return lvsGDI;}/*setup the pixel transferbuffers which is used to transfer pixeldata fromthe filter to the effect thread, and possible accross the processboundaries on win32, with the external DLL*/static void AtmoCreateTransferBuffers(filter_t *p_filter, int32_t FourCC, int32_t bytePerPixel, int32_t width, int32_t height){ filter_sys_t *p_sys = p_filter->p_sys; if(p_sys->p_atmo_config) { /* we need a buffer where the image is stored (only for transfer to the processing thread) */ if(p_sys->p_atmo_transfer_buffer) free(p_sys->p_atmo_transfer_buffer); p_sys->p_atmo_transfer_buffer = (uint8_t *)malloc(bytePerPixel * width * height); memset(&p_sys->mini_image_format,0,sizeof(BITMAPINFOHEADER)); p_sys->mini_image_format.biSize = sizeof(BITMAPINFOHEADER); p_sys->mini_image_format.biWidth = width; p_sys->mini_image_format.biHeight = height; p_sys->mini_image_format.biBitCount = bytePerPixel*8; p_sys->mini_image_format.biCompression = FourCC;#if defined(WIN32) } else if(p_sys->pf_ctrl_atmo_create_transfer_buffers) { /* on win32 with active ctrl dll */ p_sys->pf_ctrl_atmo_create_transfer_buffers(FourCC, bytePerPixel, width, height);#endif }}/*acquire the transfer buffer pointer the buildin version onlyreturns the pointer to the allocated buffer ... theexternal version on win32 has to do some COM stuff to lock theVariant Byte array which is behind the buffer*/static uint8_t* AtmoLockTransferBuffer(filter_t *p_filter){ filter_sys_t *p_sys = p_filter->p_sys; if(p_sys->p_atmo_config) { return p_sys->p_atmo_transfer_buffer;#if defined(WIN32) } else if(p_sys->pf_ctrl_atmo_lock_transfer_buffer) { /* on win32 with active ctrl dll */ return p_sys->pf_ctrl_atmo_lock_transfer_buffer();#endif } return NULL;}/*send the content of current pixel buffer got with AtmoLockTransferBufferto the processing threads- build in version - will forward the data to AtmoExternalCaptureInput Thread- win32 external - will do the same, but across the process boundaries viaCOM to the AtmoWinA.exe Process*/static void AtmoSendPixelData(filter_t *p_filter){ filter_sys_t *p_sys = p_filter->p_sys; if(p_sys->p_atmo_config && p_sys->p_atmo_transfer_buffer) { CAtmoDynData *p_atmo_dyndata = p_sys->p_atmo_dyndata; if(p_atmo_dyndata) { /* the cast will go Ok because we are inside videolan there is only this kind of effect thread implemented! */ CAtmoLiveView *p_atmo_live_view_thread = (CAtmoLiveView *)p_atmo_dyndata->getEffectThread(); if(p_atmo_live_view_thread) { /* the same as above inside videolan only this single kind of input exists so we can cast without further tests! */ CAtmoExternalCaptureInput *p_atmo_external_capture_input_thread = (CAtmoExternalCaptureInput *)p_atmo_live_view_thread->getAtmoInput(); if(p_atmo_external_capture_input_thread) { /* this call will do a 1:1 copy of this buffer, and wakeup the thread from normal sleeping */ p_atmo_external_capture_input_thread-> DeliverNewSourceDataPaket(&p_sys->mini_image_format, p_sys->p_atmo_transfer_buffer); } } }#if defined(WIN32) } else if(p_sys->pf_ctrl_atmo_send_pixel_data) { /* on win32 with active ctrl dll */ p_sys->pf_ctrl_atmo_send_pixel_data();#endif }}/* Shutdown AtmoLight finally - is call from DestroyFilter does the cleanup restores the effectmode on the external Software (only win32) and possible setup the final light ...*/static void Atmo_Shutdown(filter_t *p_filter){ filter_sys_t *p_sys = p_filter->p_sys; if(p_sys->b_enabled == true) { /* if there is a still running show pause color thread kill him! */ CheckAndStopFadeThread(p_filter); if(p_sys->p_atmo_config || (p_sys->i_AtmoOldEffect == emStaticColor)) { /* fade to end color (in case of external AtmoWin Software assume that the static color will equal to this one to get a soft change and no flash! */ p_sys->b_pause_live = true; // perpare spawn fadeing thread vlc_mutex_lock( &p_sys->filter_lock ); p_sys->p_fadethread = (fadethread_t *)vlc_object_create( p_filter, sizeof(fadethread_t) ); p_sys->p_fadethread->p_filter = p_filter; p_sys->p_fadethread->ui_red = p_sys->ui_endcolor_red; p_sys->p_fadethread->ui_green = p_sys->ui_endcolor_green; p_sys->p_fadethread->ui_blue = p_sys->ui_endcolor_blue; p_sys->p_fadethread->i_steps = p_sys->i_endfadesteps; if( vlc_thread_create( p_sys->p_fadethread, "AtmoLight fadeing", FadeToColorThread, VLC_THREAD_PRIORITY_LOW, false ) ) { msg_Err( p_filter, "cannot create FadeToColorThread" ); vlc_object_release( p_sys->p_fadethread ); p_sys->p_fadethread = NULL; vlc_mutex_unlock( &p_sys->filter_lock ); } else { vlc_mutex_unlock( &p_sys->filter_lock ); /* wait for the thread... */ vlc_thread_join(p_sys->p_fadethread); vlc_object_release(p_sys->p_fadethread); p_sys->p_fadethread = NULL; } } if(p_sys->i_AtmoOldEffect != emLivePicture) AtmoSwitchEffect(p_filter, p_sys->i_AtmoOldEffect); else AtmoSetLiveSource(p_filter, lvsGDI); AtmoFinalize(p_filter, 1); /* disable filter method .. */ p_sys->b_enabled = false; }}/*initialize the filter_sys_t structure with the data from the settingsvariables - if the external filter on win32 is enabled try loading the DLL,if this fails fallback to the buildin software*/static void Atmo_SetupParameters(filter_t *p_filter){ bool b_use_buildin_driver = true; char *psz_path; filter_sys_t *p_sys = p_filter->p_sys; /* default filter disabled until DLL loaded and Init Success!*/ p_sys->b_enabled = false; /* setup default mini image size (may be later a user option) */ p_sys->i_atmo_width = 64; p_sys->i_atmo_height = 48; vlc_mutex_init( &p_sys->filter_lock );#if defined(WIN32) /* only on WIN32 the user has the choice between internal driver and external */ b_use_buildin_driver = var_CreateGetBoolCommand( p_filter, CFG_PREFIX "usebuildin" ); if(b_use_buildin_driver == false) { /* Load the Com Wrapper Library (source available) */ p_sys->h_AtmoCtrl = LoadLibraryA("AtmoCtrlLib.dll"); if(p_sys->h_AtmoCtrl != NULL) { msg_Dbg( p_filter, "LoadLibrary('AtmoCtrlLib.dll'); Success"); /* importing all required functions I hope*/ p_sys->pf_ctrl_atmo_initialize = (int32_t (*)(void))GetProcAddress(p_sys->h_AtmoCtrl,"AtmoInitialize"); if(!p_sys->pf_ctrl_atmo_initialize) msg_Err( p_filter, "export AtmoInitialize missing."); p_sys->pf_ctrl_atmo_finalize = (void (*)(int32_t))GetProcAddress(p_sys->h_AtmoCtrl,"AtmoFinalize"); if(!p_sys->pf_ctrl_atmo_finalize) msg_Err( p_filter, "export AtmoFinalize missing."); p_sys->pf_ctrl_atmo_switch_effect = (int32_t(*)(int32_t))GetProcAddress(p_sys->h_AtmoCtrl,"AtmoSwitchEffect"); if(!p_sys->pf_ctrl_atmo_switch_effect) msg_Err( p_filter, "export AtmoSwitchEffect missing."); p_sys->pf_ctrl_atmo_set_live_source = (int32_t(*)(int32_t))GetProcAddress(p_sys->h_AtmoCtrl,"AtmoSetLiveSource"); if(!p_sys->pf_ctrl_atmo_set_live_source) msg_Err( p_filter, "export AtmoSetLiveSource missing."); p_sys->pf_ctrl_atmo_create_transfer_buffers = (void (*)(int32_t, int32_t, int32_t , int32_t))GetProcAddress(p_sys->h_AtmoCtrl,"AtmoCreateTransferBuffers"); if(!p_sys->pf_ctrl_atmo_create_transfer_buffers) msg_Err( p_filter, "export AtmoCreateTransferBuffers missing."); p_sys->pf_ctrl_atmo_lock_transfer_buffer= (uint8_t*(*) (void))GetProcAddress(p_sys->h_AtmoCtrl,"AtmoLockTransferBuffer"); if(!p_sys->pf_ctrl_atmo_lock_transfer_buffer) msg_Err( p_filter, "export AtmoLockTransferBuffer missing."); p_sys->pf_ctrl_atmo_send_pixel_data = (void (*)(void))GetProcAddress(p_sys->h_AtmoCtrl,"AtmoSendPixelData"); if(!p_sys->pf_ctrl_atmo_send_pixel_data) msg_Err( p_filter, "export AtmoSendPixelData missing."); } else { /* the DLL is missing try internal filter ...*/ msg_Warn( p_filter, "AtmoCtrlLib.dll missing fallback to internal driver"); b_use_buildin_driver = true; } }#endif if(b_use_buildin_driver == true) { msg_Dbg( p_filter, "use buildin driver"); /*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -