2021SC@SDUSC
目录
一、processor头文件分析
二、processor源文件_zbar_processor_handle_input函数分析
一、processor头文件分析
#define MAX_INPUT_BLOCK 15 typedef struct processor_state_s processor_state_t; typedef struct proc_waiter_s { struct proc_waiter_s *next; zbar_event_t notify; zbar_thread_id_t requester; unsigned events; } proc_waiter_t; #define EVENT_INPUT 0x01 #define EVENT_OUTPUT 0x02 #define EVENT_CANCELED 0x80 #define EVENTS_PENDING (EVENT_INPUT | EVENT_OUTPUT)
定义最大输入等待时间MAX_INPUT_BLOCK(15ms)
定义平台特定状态包装器processor_state_t(主体)
定义特定通知跟踪proc_waiter_s
定义高级API事件:输入事件(用户输入)、输出事件(解码输出数据可用)、取消事件(取消标志)、待定事件
struct zbar_processor_s { errinfo_t err; const void *userdata; zbar_video_t *video; zbar_window_t *window; zbar_image_scanner_t *scanner; zbar_image_data_handler_t *handler; unsigned req_width, req_height; int req_intf, req_iomode; uint32_t force_input; uint32_t force_output; int input; int threaded; int visible; int streaming; int dumping; void *display; unsigned long xwin; zbar_thread_t input_thread; zbar_thread_t video_thread; const zbar_symbol_set_t *syms; zbar_mutex_t mutex; int lock_level; zbar_thread_id_t lock_owner; proc_waiter_t *wait_head, *wait_tail, *wait_next; proc_waiter_t *free_waiter; processor_state_t *state; };
定义主体zbar_processor_s(属性分析见代码注释)
extern int _zbar_processor_lock(zbar_processor_t*); extern int _zbar_processor_unlock(zbar_processor_t*, int); extern void _zbar_processor_notify(zbar_processor_t*, unsigned); extern int _zbar_processor_wait(zbar_processor_t*, unsigned, zbar_timer_t*);
处理器锁API包括四个函数:
_zbar_processor_lock(上锁)
_zbar_processor_unlock(解锁)
_zbar_processor_notify(通知)
_zbar_processor_wait(等待)
extern int _zbar_processor_init(zbar_processor_t*); extern int _zbar_processor_cleanup(zbar_processor_t*); extern int _zbar_processor_input_wait(zbar_processor_t*, zbar_event_t*, int); extern int _zbar_processor_enable(zbar_processor_t*); extern int _zbar_process_image(zbar_processor_t*, zbar_image_t*); extern int _zbar_processor_handle_input(zbar_processor_t*, int);
平台API包括六个函数:
_zbar_processor_init(初始化)
_zbar_processor_cleanup(清理)
_zbar_processor_input_wait(等待输入)
_zbar_processor_enable(允许允许)
_zbar_process_image(图像处理)
_zbar_processor_handle_input(输入处理)
extern int _zbar_processor_open(zbar_processor_t*, char*, unsigned, unsigned); extern int _zbar_processor_close(zbar_processor_t*); extern int _zbar_processor_set_visible(zbar_processor_t*, int); extern int _zbar_processor_set_size(zbar_processor_t*, unsigned, unsigned); extern int _zbar_processor_invalidate(zbar_processor_t*);
窗口平台API包括五个函数:
_zbar_processor_open(打开窗口)
_zbar_processor_close(关闭窗口)
_zbar_processor_set_visible(设置窗口可见)
_zbar_processor_set_size(设置窗口大小)
_zbar_processor_invalidate(无效化)
二、processor源文件_zbar_processor_handle_input函数分析int _zbar_processor_handle_input (zbar_processor_t *proc, int input)
函数传入两个参数:zbar_processor_t(processor.h中定义的主体结构体)、input(int类型)
int event = EVENT_INPUT; switch(input) { case -1: event |= EVENT_CANCELED; _zbar_processor_set_visible(proc, 0); err_capture(proc, SEV_WARNING, ZBAR_ERR_CLOSED, __func__, "user closed display window"); break; case 'd': proc->dumping = 1; return(0); case '+': case '=': if(proc->window) { int ovl = zbar_window_get_overlay(proc->window); zbar_window_set_overlay(proc->window, ovl + 1); } break; case '-': if(proc->window) { int ovl = zbar_window_get_overlay(proc->window); zbar_window_set_overlay(proc->window, ovl - 1); } break; }
定义event变量为输入事件
如果input为-1:event变量等于取消事件,调用_zbar_processor_set_visible函数关闭窗口,调用err_capture函数记录用户关闭窗口;
如果input为'd':设置映像转储属性dumping为1,函数结束;
如果input为'+'或'=':如果存在输出窗口,则让该窗口的ovl属性加一;
如果input为'-':如果存在输出窗口,则让该窗口的ovl属性减一。
_zbar_mutex_lock(&proc->mutex); proc->input = input; if(input == -1 && proc->visible && proc->streaming) event |= EVENT_OUTPUT; _zbar_processor_notify(proc, event); _zbar_mutex_unlock(&proc->mutex); return(input);
进行共享数据上锁
根据input、visible、streaming取消未完成的输出等待者
完成后进行通知和解锁
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)