void window_slide( window_t* window) { debug_print("window_slide()\n"); queue_node_t* node; packet_t* packet; window_lock(window); while (window->buffer->size > 0) { node = queue_head(window->buffer); packet = node->data; if (!packet->needs_ack && packet->transmission_time) { node = queue_dequeue(window->buffer, false); packet_free(node->data); free(node); if (window->size) { window->size--; } } else { break; } } window_unlock(window); window_out_commit(window); success_print("window_slide() succeed\n"); }
int zbar_window_get_overlay (const zbar_window_t *w) { zbar_window_t *ncw = (zbar_window_t*)w; if(window_lock(ncw)) return(-1); int lvl = w->overlay; (void)window_unlock(ncw); return(lvl); }
void window_max_size_set( window_t* window, uint8_t max_size) { if (window) { window_lock(window); window->max_size = max_size; window_unlock(window); } }
int zbar_window_resize (zbar_window_t *w, unsigned width, unsigned height) { if(window_lock(w)) return(-1); w->width = width; w->height = height; w->scaled_size.x = 0; _zbar_window_resize(w); return(window_unlock(w)); }
void zbar_window_set_overlay (zbar_window_t *w, int lvl) { if(lvl < 0) lvl = 0; if(lvl > 2) lvl = 2; if(window_lock(w)) return; if(w->overlay != lvl) w->overlay = lvl; (void)window_unlock(w); }
void window_out_commit( window_t* window) { debug_print("window_out_commit()\n"); window_lock(window); if (!window->buffer->size) { window->size = 0; window->head = 0; window->tail = 0; } else { window->size = MIN(window->max_size, window->buffer->size); window->head = queue_head(window->buffer); window->tail = window_get(window, window->size-1); //printf("head: %p, tail: %p\n", window->head, window->tail); if (!window->tail || !window->head) { return; } queue_node_t* node = window->head; packet_t* packet = (packet_t*) node->data; while(node != window->tail) { packet = (packet_t*) node->data; if (!packet->transmission_time) { channel_send_packet(packet); } node = node->next; } if (node == window->tail) { if (!packet->transmission_time) { channel_send_packet(packet); } } } window_unlock(window); success_print("window_out_commit() succeed\n"); }
int zbar_window_draw (zbar_window_t *w, zbar_image_t *img) { if(window_lock(w)) return(-1); if(!w->draw_image) img = NULL; if(img) { _zbar_image_refcnt(img, 1); if(img->width != w->src_width || img->height != w->src_height) w->dst_width = 0; } if(w->image) _zbar_image_refcnt(w->image, -1); w->image = img; return(window_unlock(w)); }
inline int zbar_window_redraw (zbar_window_t *w) { if(window_lock(w)) return(-1); if(!w->display || _zbar_window_begin(w)) { (void)window_unlock(w); return(-1); } int rc = 0; zbar_image_t *img = w->image; if(w->init && w->draw_image && img) { int format_change = (w->src_format != img->format && w->format != img->format); if(format_change) { _zbar_best_format(img->format, &w->format, w->formats); if(!w->format) rc = err_capture_int(w, SEV_ERROR, ZBAR_ERR_UNSUPPORTED, __func__, "no conversion from %x to supported formats", img->format); w->src_format = img->format; } if(!rc && (format_change || !w->scaled_size.x || !w->dst_width)) { zprintf(24, "init: src=%.4s(%08lx) %dx%d dst=%.4s(%08lx) %dx%d\n", (char*)&w->src_format, w->src_format, w->src_width, w->src_height, (char*)&w->format, w->format, w->dst_width, w->dst_height); if(!w->dst_width) { w->src_width = img->width; w->src_height = img->height; } point_t size = { w->width, w->height }; if(size.x > w->max_width) size.x = w->max_width; if(size.y > w->max_height) size.y = w->max_height; if(size.x * w->src_height < size.y * w->src_width) { w->scale_num = size.x; w->scale_den = w->src_width; } else { w->scale_num = size.y; w->scale_den = w->src_height; } rc = w->init(w, img, format_change); if(!rc) { size.x = w->src_width; size.y = w->src_height; w->scaled_size = size = window_scale_pt(w, size); w->scaled_offset.x = ((int)w->width - size.x) / 2; w->scaled_offset.y = ((int)w->height - size.y) / 2; zprintf(24, "scale: src=%dx%d win=%dx%d by %d/%d => %dx%d @%d,%d\n", w->src_width, w->src_height, w->width, w->height, w->scale_num, w->scale_den, size.x, size.y, w->scaled_offset.x, w->scaled_offset.y); } else { /* unable to display this image */ _zbar_image_refcnt(img, -1); w->image = img = NULL; } } if(!rc && (img->format != w->format || img->width != w->dst_width || img->height != w->dst_height)) { /* save *converted* image for redraw */ zprintf(48, "convert: %.4s(%08lx) %dx%d => %.4s(%08lx) %dx%d\n", (char*)&img->format, img->format, img->width, img->height, (char*)&w->format, w->format, w->dst_width, w->dst_height); w->image = zbar_image_convert_resize(img, w->format, w->dst_width, w->dst_height); w->image->syms = img->syms; if(img->syms) zbar_symbol_set_ref(img->syms, 1); zbar_image_destroy(img); img = w->image; } if(!rc) { rc = w->draw_image(w, img); point_t org = w->scaled_offset; if(org.x > 0) { point_t p = { 0, org.y }; point_t s = { org.x, w->scaled_size.y }; _zbar_window_fill_rect(w, 0, p, s); s.x = w->width - w->scaled_size.x - s.x; if(s.x > 0) { p.x = w->width - s.x; _zbar_window_fill_rect(w, 0, p, s); } } if(org.y > 0) { point_t p = { 0, 0 }; point_t s = { w->width, org.y }; _zbar_window_fill_rect(w, 0, p, s); s.y = w->height - w->scaled_size.y - s.y; if(s.y > 0) { p.y = w->height - s.y; _zbar_window_fill_rect(w, 0, p, s); } } } if(!rc) rc = window_draw_overlay(w); } else rc = 1; if(rc) rc = _zbar_window_draw_logo(w); _zbar_window_end(w); (void)window_unlock(w); return(rc); }
void window_in_commit( window_t* window) { debug_print("window_in_commit()\n"); window_lock(window); if (!window->buffer->size) { window->size = 0; window->head = 0; window->tail = 0; } else { if (!window->head) { window->head = queue_head(window->buffer); } packet_t* packet; while (window->head->next) { packet = window->head->data; //printf("%08X == %08X, %08X == %08X\n", //packet->header->sequence, packet->socket->channel->acknowledge, //packet->header->acknowledge, packet->socket->channel->sequence +1); if (packet->header->sequence == packet->socket->channel->acknowledge && packet->header->acknowledge == packet->socket->channel->sequence /*+ (packet->socket->options->state == STATE_ESTABLISHED? 1:0)*/) { packet->socket->channel->acknowledge += packet->data_buffer_size; //packet->socket->channel->acknowledge = // packet->header->sequence + packet->data_buffer_size; //packet->socket->channel->sequence = packet->header->acknowledge; channel_send_ack(packet->socket, packet); window->head = window->head->next; } else { goto cleanup; } } if (window->head) { packet = window->head->data; //printf("%08X == %08X, %08X == %08X\n", //packet->header->sequence, packet->socket->channel->acknowledge, //packet->header->acknowledge, packet->socket->channel->sequence +1); if (packet->header->sequence == packet->socket->channel->acknowledge && packet->header->acknowledge == packet->socket->channel->sequence /*+ (packet->socket->options->state == STATE_ESTABLISHED? 1:0)*/) { packet->socket->channel->acknowledge += packet->data_buffer_size; //packet->socket->channel->sequence = packet->header->acknowledge; channel_send_ack(packet->socket, packet); sem_post(&window->available); window->head = window->head->next; } else { } } } /* queue_node_t* node = window->head; packet_t* packet; uint32_t current_size = 0; while (node && current_size++ < window->size) { window->tail = node; packet = node->data; if (!packet->ack || !packet->ack->transmission_time && window_sequenced(window, node->prev, node)) { printf("seq:%08X == %08X, ack:%08X == %08X\n", packet->socket->channel->sequence, packet->header->sequence, packet->socket->channel->acknowledge, packet->header->acknowledge); channel_send_ack(packet->socket, packet); } node = node->next; } } window_unlock(window); success_print("window_in_commit() succeed\n"); //socket->channel->acknowledge = // packet->header->sequence + packet->data_buffer_size; //socket->channel->sequence = packet->header->acknowledge; //if (channel_send_ack(socket, packet) < 0) // goto failed; * */ cleanup: window_unlock(window); success_print("window_in_commit() succeed\n"); }