static GstFlowReturn gst_fluid_dec_chain (GstPad * sinkpad, GstObject * parent, GstBuffer * buffer) { GstFlowReturn res = GST_FLOW_OK; GstFluidDec *fluiddec; GstClockTime pts; fluiddec = GST_FLUID_DEC (parent); if (GST_BUFFER_IS_DISCONT (buffer)) { fluiddec->discont = TRUE; } pts = GST_BUFFER_PTS (buffer); if (pts != GST_CLOCK_TIME_NONE) { guint64 sample = gst_util_uint64_scale_int (pts, FLUID_DEC_RATE, GST_SECOND); if (fluiddec->last_pts == GST_CLOCK_TIME_NONE) { fluiddec->last_pts = pts; fluiddec->last_sample = sample; } else if (fluiddec->last_pts < pts) { /* generate samples for the elapsed time */ res = produce_samples (fluiddec, pts, sample); } } if (res == GST_FLOW_OK) { handle_buffer (fluiddec, buffer); } gst_buffer_unref (buffer); return res; }
/* * Tries to convert @a buffer into UTF-8 encoding. Unlike encodings_convert_to_utf8() * and encodings_convert_to_utf8_from_charset() it handles the possible BOM in the data. * * @param buf a pointer to modifiable null-terminated buffer to convert. * It may or may not be modified, and should be freed whatever happens. * @param size a pointer to the size of the buffer (expected to be e.g. the on-disk * file size). It will be updated to the new size. * @param forced_enc forced encoding to use, or @c NULL * @param used_encoding return location for the actually used encoding, or @c NULL * @param has_bom return location to store whether the data had a BOM, or @c NULL * @param partial return location to store whether the conversion may be partial, or @c NULL * * @return @C TRUE if the conversion succeeded, @c FALSE otherwise. */ gboolean encodings_convert_to_utf8_auto(gchar **buf, gsize *size, const gchar *forced_enc, gchar **used_encoding, gboolean *has_bom, gboolean *partial) { BufferData buffer; buffer.data = *buf; buffer.size = *size; /* use strlen to check for null chars */ buffer.len = strlen(buffer.data); buffer.enc = NULL; buffer.bom = FALSE; buffer.partial = FALSE; if (! handle_buffer(&buffer, forced_enc)) return FALSE; *size = buffer.len; if (used_encoding) *used_encoding = buffer.enc; else g_free(buffer.enc); if (has_bom) *has_bom = buffer.bom; if (partial) *partial = buffer.partial; *buf = buffer.data; return TRUE; }
int rev_pump_network(struct rev_server *revsrv, struct rev_client *cl) { /* handle/parse avaiable messages in buffer */ while (handle_buffer(revsrv, cl)); return 0; }
void AsyncConnection::on_handle_read( const boost::system::error_code& ec, size_t bytes_transferred) { if (ec) return; bytes_recv_ += bytes_transferred; assert(bytes_recv_ <= recv_buffer_.size()); handle_buffer(); }
static GstFlowReturn gst_rtp_onvif_parse_chain (GstPad * pad, GstObject * parent, GstBuffer * buf) { GstRtpOnvifParse *self = GST_RTP_ONVIF_PARSE (parent); if (!handle_buffer (self, buf)) { gst_buffer_unref (buf); return GST_FLOW_ERROR; } return gst_pad_push (self->srcpad, buf); }
/* Read from a connection */ static int readConn(conn_t* conn, char* buffer, size_t buf_size) { int nread; if (verbose) fprintf(stderr, "Reading conn #%d [%s]\n", conn->index, state_names[conn->state]); nread = read(conn->pfd->fd, buffer, buf_size-1); if (nread < 0) { if (errno == EWOULDBLOCK) return ST_CONTINUE; error(conn, "first read"); return ST_ERROR; } buffer[nread] = '\0'; if (nread == 0) /* EOF: reset everything. (Should conn->local_buffer be processed?) */ return ST_OK; if (conn->state == SENT_DATA) { char* first_line = buffer; conn->state = READING_HEADERS; conn->local_buffer[0] = '\0'; if ((buffer = strstr(buffer, "\r\n")) == NULL) { fprintf(stderr, "Couldn't find status line!"); return ST_ERROR; } buffer += 2; nread -= buffer - first_line; if (strstr(first_line, "HTTP/1.1 200 OK") == NULL) { if (strstr(first_line, "HTTP/1.1 404 ") != NULL) return ST_404; if (strstr(first_line, "already+exists") != NULL) return ST_DUP; fputs("\nGot bad reply! ", stderr); dump(buffer); fputs("\n", stderr); return ST_ERROR; } } return handle_buffer(conn, buffer, nread); }
/*@ requires range == 0 || \valid(vet+(0..range-1));*/ void check_range(int range, int vet[]){ int i; int var_a = 2; for(i=0;i<MAX;i++){ //@ assert i < range_updated; vet[i]=1*var_a; var_a = i * var_a + range; } if(range < MAX){ range_updated=range; handle_buffer(); } }
void AsyncConnection::on_handle_write( const boost::system::error_code& ec, size_t bytes_transferred) { if (ec) return; assert(bytes_recv_ >= frame_size_+sizeof(uint32_t)); if (bytes_recv_ == frame_size_+sizeof(uint32_t)) { //buffer is empty, restart start_recv(true); } else { //consume the previous frame buffer, and handle the buffer remained memcpy(&recv_buffer_[0], &recv_buffer_[frame_size_+sizeof(uint32_t)], bytes_recv_-frame_size_-sizeof(uint32_t)); bytes_recv_ -= (frame_size_+sizeof(uint32_t)); frame_size_ = 0; state_ = kReadFrameSize; handle_buffer(); } }
static GstFlowReturn gst_sub_parse_chain (GstPad * sinkpad, GstBuffer * buf) { GstFlowReturn ret; GstSubParse *self; self = GST_SUBPARSE (GST_PAD_PARENT (sinkpad)); /* Push newsegment if needed */ if (self->need_segment) { GST_LOG_OBJECT (self, "pushing newsegment event with %" GST_SEGMENT_FORMAT, &self->segment); gst_pad_push_event (self->srcpad, gst_event_new_new_segment (FALSE, self->segment.rate, self->segment.format, self->segment.last_stop, self->segment.stop, self->segment.time)); self->need_segment = FALSE; } ret = handle_buffer (self, buf); return ret; }
void DeviceManager::process_buffer_done (ImageProcessor *processor, const SmartPtr<VideoBuffer> &buf) { ImageProcessCallback::process_buffer_done (processor, buf); handle_buffer (buf); }
/* * Reads RX responses for a single packet */ static int netfront_get_responses(struct netfront_dev *dev, RING_IDX rp) { struct netif_rx_response *rsp = &(dev->rsp); int32_t realsize = rsp->status; int16_t size = rsp->status; uint16_t id = rsp->id; uint16_t flags = rsp->flags; RING_IDX cons = rp; uint16_t slots = 1; int drop = 0; #ifdef HAVE_LWIP struct pbuf *p; struct pbuf *first_p; #endif dprintk("rx: ring: len %d %s\n", size, (flags & NETRXF_more_data ? "(more true) ": "")); BUG_ON(id >= NET_RX_RING_SIZE); if (flags & NETRXF_extra_info) { memset(dev->extras, 0, sizeof(dev->extras)); netfront_get_extras(dev, dev->extras, cons); cons = dev->rx.rsp_cons; } if (flags & NETRXF_more_data) { dprintk("rx: scan: slot 0 len %d %s\n", size, (flags & NETRXF_more_data ? "(more true)": "")); realsize = size + netfront_get_size(dev, cons); } dprintk("rx: %c%c- %"PRIi32" bytes\n", flags & NETRXF_extra_info ? 'S' : '-', flags & ((NETRXF_csum_blank) | (NETRXF_data_validated)) ? 'C' : '-', realsize); #ifdef HAVE_LWIP if (likely(dev->netif_rx_pbuf)) { #ifdef CONFIG_NETFRONT_PERSISTENT_GRANTS first_p = p = netfront_alloc_pbuf(dev, realsize); drop = (p == NULL); #else first_p = p = &dev->rx_buffers[id]->cpbuf.pbuf; drop = 0; dev->pbuf_cur = p; #endif /* CONFIG_NETFRONT_PERSISTENT_GRANTS */ #if ETH_PAD_SIZE if (likely(!drop)) pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */ #endif /* ETH_PAD_SIZE */ } #endif /* HAVE_LWIP */ for (;;) { if (unlikely(rsp->status < 0 || (rsp->offset + rsp->status > PAGE_SIZE))) { printk("rx: ring<%u>: status %d, flags %04x, offset %d\n", cons + slots, size, flags, rsp->offset); } else if (likely(!drop)) { #ifdef CONFIG_NETFRONT_PERSISTENT_GRANTS handle_buffer(dev, rsp, &dev->rx_buffers[id], realsize); #else handle_buffer(dev, rsp, dev->rx_buffers[id], realsize); #endif } #ifndef CONFIG_NETFRONT_PERSISTENT_GRANTS BUG_ON(dev->rx_buffers[id]->gref == GRANT_INVALID_REF); gnttab_end_access(dev->rx_buffers[id]->gref); dev->rx_buffers[id]->gref = GRANT_INVALID_REF; dev->rx_buffers[id] = NULL; #endif if (!(flags & NETRXF_more_data)) break; if (dev->rx.sring->rsp_prod <= cons + slots) break; rsp = RING_GET_RESPONSE(&dev->rx, cons + slots); id = rsp->id; BUG_ON(id >= NET_RX_RING_SIZE); size = rsp->status; flags = rsp->flags; slots++; #ifndef CONFIG_NETFRONT_PERSISTENT_GRANTS if (likely(dev->netif_rx_pbuf && (!drop))) { /* set tot_len */ p->tot_len = realsize; realsize -= p->len; /* ..and link it to next pbuf */ p->next = &dev->rx_buffers[id]->cpbuf.pbuf; dev->pbuf_cur = p = p->next; } else { netfront_release_rxbuffer(dev->rx_buffers[id], dev); } #endif dprintk("rx: ring: len %d %s %s\n", size, (flags & NETRXF_more_data ? "(more true) ": ""), (drop ? "DROP" : "")); } BUG_ON(slots > dev->rx.sring->rsp_prod - dev->rx.rsp_cons); dev->rx.rsp_cons = cons + slots; if (unlikely(drop)) goto err_drop; #ifdef HAVE_LWIP if (likely(dev->netif_rx_pbuf)) { #if ETH_PAD_SIZE pbuf_header(p, ETH_PAD_SIZE); /* reclaim the padding word */ #endif /* ETH_PAD_SIZE */ if (first_p->ref != 1) printk("first_p->ref = %u\n", first_p->ref); dev->netif_rx_pbuf(first_p, dev->netif_rx_arg); } #endif /* HAVE_LWIP */ return 1; err_drop: dprintk(" rx: dropped\n"); #ifdef HAVE_LWIP if (first_p) { #ifdef CONFIG_NETFRONT_PERSISTENT_GRANTS pbuf_free(first_p); #else /* CONFIG_NETFRONT_PERSISTENT_GRANTS */ struct pbuf *next; /* unchain pbuf and release */ p = first_p; while (p != NULL) { next = p->next; p->tot_len = p->len; p->next = NULL; netfront_free_rxpbuf(p); p = next; } #endif /* CONFIG_NETFRONT_PERSISTENT_GRANTS */ } if (likely(dev->netif_rx_pbuf)) dev->netif_rx_pbuf(NULL, dev->netif_rx_arg); /* notify drop */ #endif return 0; }
void child(int incoming_fd, int connect_port) { int connect_socket, err, max_fd; struct sockaddr_in connect_addr; fd_set rfds, efds; struct timeval tv; int is_first, is_z; z_stream in_z_stream; z_stream out_z_stream; is_first=1; is_z=0; connect_socket=socket(PF_INET, SOCK_STREAM, 0); if (connect_socket < 0) { perror("cannot create socket"); exit(1); } memset(&connect_addr, 0, sizeof(connect_addr)); connect_addr.sin_family = AF_INET; connect_addr.sin_port = htons(connect_port); connect_addr.sin_addr.s_addr = inet_addr("127.0.0.1"); /* fprintf(stderr, "connecting to %d", connect_port); */ err=connect(connect_socket, (struct sockaddr *)&connect_addr, sizeof(connect_addr)); if (err<0) { perror("cannot connect to localhost on port"); close(connect_socket); exit(2); } fprintf(stderr, "\n"); max_fd=incoming_fd; if (connect_socket>max_fd) max_fd=connect_socket; ++max_fd; for(;;) { FD_ZERO(&rfds); FD_SET(incoming_fd, &rfds); FD_SET(connect_socket, &rfds); FD_ZERO(&efds); FD_SET(incoming_fd, &efds); FD_SET(connect_socket, &efds); tv.tv_sec = 60*60; tv.tv_usec = 0; err=select(max_fd, &rfds, NULL, &efds, &tv); if (err == -1) { perror("error in select"); goto error; } if (FD_ISSET(incoming_fd, &efds) || FD_ISSET(connect_socket, &efds) ) { goto error; } if (FD_ISSET(incoming_fd, &rfds)) { /*fprintf(stderr, "read from incoming\n");*/ if (handle_buffer(incoming_fd, connect_socket, &is_first, &is_z, 0, &in_z_stream, &out_z_stream)==-1) goto error; } if (FD_ISSET(connect_socket, &rfds)) { /* fprintf(stderr, "read from outgoing\n");*/ if (handle_buffer(connect_socket, incoming_fd, &is_first, &is_z, 1, &in_z_stream, &out_z_stream)==-1) goto error; } } error: if (is_z) { inflateEnd(&in_z_stream); deflateEnd(&out_z_stream); } fprintf(stderr, "closing connections\n"); close(incoming_fd); close(connect_socket); exit(1); }