int main (void) { int i=0; struct buf_info test_buffer; unsigned char real_buf[20]; rb_init (&test_buffer, (unsigned char*)&real_buf, 20); rb_write (&test_buffer, 'a'); rb_write (&test_buffer, 'a'); printf ("got %hhc %hhc\n", rb_read(&test_buffer), rb_read(&test_buffer)); for (i = 0; i<52; i++) { rb_write (&test_buffer, (char)(i+33)); } int chr = rb_read (&test_buffer); char str [21]; int npos = 0; while (chr != EEMPTY) { str[npos++]=(char)chr; chr = rb_read (&test_buffer); } str[npos]=0; printf ("npos=%d, got %s\n", npos, str); return 0; }
END_TEST START_TEST (test_to_rb_from_fd) { int fds[2]; ck_assert(pipe(fds) == 0); ck_assert(write(fds[1], sample16, 16) == 16); ck_assert(rb_is_empty(rb)); ck_assert_int_eq(rb_used(rb), 0); ck_assert_int_eq(rb_space(rb), 16); ssize_t result = rb_read(rb, fds[0], 10); ck_assert_int_eq(result, 10); ck_assert_int_eq(rb_used(rb), 10); ck_assert_int_eq(rb_space(rb), 6); ck_assert(!rb_is_empty(rb)); ck_assert(!rb_is_full(rb)); result = rb_read(rb, fds[0], 10); ck_assert_int_eq(result, 6); ck_assert_int_eq(rb_used(rb), 16); ck_assert_int_eq(rb_space(rb), 0); ck_assert(!rb_is_empty(rb)); ck_assert(rb_is_full(rb)); ck_assert(memcmp(rb->buffer, "0123456789ABCDEF", 16) == 0); }
int main(int argc, char* argv[]) { unsigned int left = 0; unsigned int size = 0; unsigned int i = 0; struct ring_buffer rb; char buffer[100]; for(i = 0; i < 100; ++i) { buffer[i] = i; } rb_alloc(&rb, 100); for(i = 0; i < 100; ++i) { rb_write(&rb, buffer, 33); rb_read(&rb, buffer, 32); } printf("%d,%d %d,%d\n", rb_length(&rb), rb_left(&rb), rb_is_full(&rb), rb_is_empty(&rb)); rb_free(&rb); return 0; }
gint cdda_timeout_callback(gpointer data) { cdda_notify_t notify; while (rb_read_space(cdda_notify_rb) >= sizeof(cdda_notify_t)) { rb_read(cdda_notify_rb, (char *)¬ify, sizeof(cdda_notify_t)); switch (notify.event_type) { case CDDA_EVENT_NEW_DRIVE: AQUALUNG_MUTEX_LOCK(cdda_mutex) insert_cdda_drive_node(notify.device_path); AQUALUNG_MUTEX_UNLOCK(cdda_mutex) free(notify.device_path); break; case CDDA_EVENT_CHANGED_DRIVE: AQUALUNG_MUTEX_LOCK(cdda_mutex) refresh_cdda_drive_node(notify.device_path); AQUALUNG_MUTEX_UNLOCK(cdda_mutex) free(notify.device_path); break; case CDDA_EVENT_REMOVED_DRIVE: AQUALUNG_MUTEX_LOCK(cdda_mutex) remove_cdda_drive_node(notify.device_path); AQUALUNG_MUTEX_UNLOCK(cdda_mutex) free(notify.device_path); break; } } return TRUE; }
size_t rb_read(RingBuffer *rb, void *data, size_t count) { //assert(rb != NULL); //assert(data != NULL); if (rb->rb_head < rb->rb_tail) { int copy_sz = min(count, rb_can_read(rb)); memcpy(data, rb->rb_head, copy_sz); rb->rb_head += copy_sz; return copy_sz; } else { if (count < rb_capacity(rb)-(rb->rb_head - rb->rb_buff)) { int copy_sz = count; memcpy(data, rb->rb_head, copy_sz); rb->rb_head += copy_sz; return copy_sz; } else { int copy_sz = rb_capacity(rb) - (rb->rb_head - rb->rb_buff); memcpy(data, rb->rb_head, copy_sz); rb->rb_head = rb->rb_buff; copy_sz += rb_read(rb, (char*)data+copy_sz, count-copy_sz); return copy_sz; } } }
static void rb_read_timerfd(rb_fde_t *F, void *data) { struct ev_entry *event = (struct ev_entry *)data; int retlen; uint64_t count; if(event == NULL) { rb_close(F); return; } retlen = rb_read(F, &count, sizeof(count)); if(retlen == 0 || (retlen < 0 && !rb_ignore_errno(errno))) { rb_close(F); rb_lib_log("rb_read_timerfd: timerfd[%s] closed on error: %s", event->name, strerror(errno)); return; } rb_setselect(F, RB_SELECT_READ, rb_read_timerfd, event); rb_run_event(event); }
unsigned int speex_dec_read(decoder_t * dec, float * dest, int num) { speex_pdata_t * pd = (speex_pdata_t *)dec->pdata; unsigned int numread = 0; unsigned int n_avail = 0; while ((rb_read_space(pd->rb) < num * pd->channels * sample_size) && (!pd->is_eos)) { pd->is_eos = decode_speex(dec); } n_avail = rb_read_space(pd->rb) / (pd->channels * sample_size); if (n_avail > num) n_avail = num; rb_read(pd->rb, (char *)dest, n_avail * pd->channels * sample_size); numread = n_avail; return numread; }
static ssize_t mydev_read(struct file *filp, char __user *buf, size_t nbuf, loff_t *offs) { unsigned minor = MINOR(filp->f_dentry->d_inode->i_rdev); int rc; /* obtain lock before accessing rwbuf */ if (mutex_lock_interruptible(&mydev_mutex)) return -EINTR; if ((rc = chk_rwbuf(nbuf))) { return rc; } /* read data from device into the tmp buffer, since device cannot write directly to user-space memory */ nbuf = rb_read(mydev_ring[minor], rwbuf, nbuf); /* copy the data from the user-supplied buffer to the tmp buffer, since device cannot directly read from user-space memory */ copy_to_user(buf, rwbuf, nbuf); /* done with rwbuf, unlock mutex */ mutex_unlock(&mydev_mutex); /* adjust file offset */ *offs += nbuf; /* return number of bytes read */ return nbuf; }
static lua_Integer get_integer(lua_State *L, struct read_block *rb, int cookie) { switch (cookie) { case TYPE_NUMBER_ZERO: return 0; case TYPE_NUMBER_BYTE: { uint8_t n; uint8_t * pn = rb_read(rb, &n, sizeof(n)); if (pn == NULL) invalid_stream(L, rb); n = *pn; return n; } case TYPE_NUMBER_WORD: { uint16_t n; uint16_t * pn = rb_read(rb, &n, sizeof(n)); if (pn == NULL) invalid_stream(L, rb); memcpy(&n, pn, sizeof(n)); return n; } case TYPE_NUMBER_DWORD: { int32_t n; int32_t * pn = rb_read(rb, &n, sizeof(n)); if (pn == NULL) invalid_stream(L, rb); memcpy(&n, pn, sizeof(n)); return n; } case TYPE_NUMBER_QWORD: { int64_t n; int64_t * pn = rb_read(rb, &n, sizeof(n)); if (pn == NULL) invalid_stream(L, rb); memcpy(&n, pn, sizeof(n)); return n; } default: invalid_stream(L, rb); return 0; } }
static void get_buffer(lua_State *L, struct read_block *rb, int len) { char * p = rb_read(rb,len); if (p == NULL) { invalid_stream(L,rb); } lua_pushlstring(L,p,len); }
static void * get_pointer(lua_State *L, struct read_block *rb) { void * userdata = 0; void ** v = (void **)rb_read(rb,&userdata,sizeof(userdata)); if (v == NULL) { invalid_stream(L,rb); } return *v; }
static double get_real(lua_State *L, struct read_block *rb) { double n; double * pn = rb_read(rb,sizeof(n)); if (pn == NULL) invalid_stream(L,rb); memcpy(&n, pn, sizeof(n)); return n; }
//The recording stuff runs in its own thread //this prevents dropouts in the recording, in case the //bandwidth is smaller than the selected streaming bitrate void* snd_rec_thread(void *data) { int rb_read_bytes; int ogg_header_written; int enc_bytes_read; char *enc_buf = (char*)malloc(rec_rb.size * sizeof(char)*10); char *audio_buf = (char*)malloc(rec_rb.size * sizeof(short)); ogg_header_written = 0; while(record) { pthread_cond_wait(&rec_cond, &rec_mut); rb_read_bytes = rb_read(&rec_rb, audio_buf); if(rb_read_bytes == 0) continue; #if HAVE_LIBLAME if(!strcmp(cfg.rec.codec, "mp3")) { enc_bytes_read = lame_enc_encode(&lame_rec, (short int*)audio_buf, enc_buf, rb_read_bytes/(2*cfg.rec.channel), rec_rb.size*10); bytes_written += fwrite(enc_buf, 1, enc_bytes_read, cfg.rec.fd); } #endif #if HAVE_LIBVORBIS if (!strcmp(cfg.rec.codec, "ogg")) { if(!ogg_header_written) { vorbis_enc_write_header(&vorbis_rec); ogg_header_written = 1; } enc_bytes_read = vorbis_enc_encode(&vorbis_rec, (short int*)audio_buf, enc_buf, rb_read_bytes/(2*cfg.rec.channel)); bytes_written += fwrite(enc_buf, 1, enc_bytes_read, cfg.rec.fd); } #endif if (!strcmp(cfg.rec.codec, "wav")) { //this permanently updates the filesize value in the WAV header //so we still have a valid WAV file in case of a crash wav_write_header(cfg.rec.fd, cfg.audio.channel, cfg.audio.samplerate, /*bps*/ 16); bytes_written += fwrite(audio_buf, sizeof(char), rb_read_bytes, cfg.rec.fd); } } fclose(cfg.rec.fd); free(enc_buf); free(audio_buf); return NULL; }
static void _get_buffer(lua_State *L, struct read_block *rb, int len) { #ifdef _MSC_VER char *tmp = (char *)_alloca(len); #else char tmp[len]; #endif char * p = rb_read(rb, tmp, len); lua_pushlstring(L, p, len); }
END_TEST START_TEST (test_return_enobufs_if_full) { rb_append(rb, sample16, 16); ck_assert(rb_read(rb, 0, 1) < 0); ck_assert_int_eq(errno, ENOBUFS); }
//============================================================================= static void *reader_thread_func(void *arg) { if(rb_==NULL) { fprintf(stderr,"ringbuffer was NULL.\n"); exit(1); } debug(rb_,READER_THREAD); //srand(4321); int buf_size=32; //22 to match write thread content size char buf[buf_size]; memset(buf,0,buf_size); int read=0; int read_total=0; while(1==1) { if(read_total>=buf_size) { //memset(buf,0,buf_size); read_total=0; fprintf(stdout,"\n"); fflush(stdout); } read=rb_read( rb_ //read from this ringbuffer ,buf+read_total //read into buf at offset read_total ,buf_size-read_total //request to read remaining bytes to fill buf ); //buffer to indicate which part was read into buffer char buf_read[read+1]; //+1 for null termination for printing buf_read[read]='\0'; //copy from main read buffer memcpy(buf_read,buf+read_total,read); read_total+=read; fprintf(stderr,"read %d read_total %d '%s'\n" ,read //bytes read in last rb_read ,read_total //bytes read relative to main read buffer pos 0 ,buf_read //contents that were read in last rb_read ); fprintf(stdout,"%s",buf_read); fflush(stdout); debug(rb_,READER_THREAD); //int r=rand()/50000; //fprintf(stderr,"rand %d\n",r); //usleep(r); //sleep random } }
static ssize_t mydev_read(struct file *filp, char __user *buf, size_t nbuf, loff_t *offs) { unsigned minor = MINOR(filp->f_dentry->d_inode->i_rdev); int rc; /* obtain lock before entering critical section */ if (mutex_lock_interruptible(&mydev_mutex)) return -ERESTARTSYS; if ((rc = chk_rwbuf(nbuf))) { return rc; } /* check if data is ready to be read */ while (!rb_data_size(mydev_ring[minor])) { /* no data to be read, we're either going to return (non-blocking case) or block. in either case we need to release the lock first to avoid deadlock */ mutex_unlock(&mydev_mutex); /* handle non-blocking reads */ if (filp->f_flags & O_NONBLOCK) return -EAGAIN; /* block until notified (by write) that data is present */ if (wait_event_interruptible(mydev_rqueue, rb_data_size(mydev_ring[minor]) > 0)) return -ERESTARTSYS; /* restore lock before proceeding */ if (mutex_lock_interruptible(&mydev_mutex)) return -ERESTARTSYS; } /* assumptions at this point: (a) there is data to be read, and (b) we own the lock */ /* read data from device into the tmp buffer, since device cannot write directly to user-space memory */ nbuf = rb_read(mydev_ring[minor], rwbuf, nbuf); /* copy the data from the user-supplied buffer to the tmp buffer, since device cannot directly read from user-space memory */ copy_to_user(buf, rwbuf, nbuf); /* done critical section, unlock mutex */ mutex_unlock(&mydev_mutex); /* adjust file offset */ *offs += nbuf; wake_up_interruptible(&mydev_wqueue); /* return number of bytes read */ return nbuf; }
void vc_iterate(VCSession *vc) { if (!vc) { return; } pthread_mutex_lock(vc->queue_mutex); struct RTPMessage *p; if (!rb_read(vc->vbuf_raw, (void **)&p)) { LOGGER_TRACE(vc->log, "no Video frame data available"); pthread_mutex_unlock(vc->queue_mutex); return; } pthread_mutex_unlock(vc->queue_mutex); const struct RTPHeader *const header = &p->header; uint32_t full_data_len; if (header->flags & RTP_LARGE_FRAME) { full_data_len = header->data_length_full; LOGGER_DEBUG(vc->log, "vc_iterate:001:full_data_len=%d", (int)full_data_len); } else { full_data_len = p->len; LOGGER_DEBUG(vc->log, "vc_iterate:002"); } LOGGER_DEBUG(vc->log, "vc_iterate: rb_read p->len=%d p->header.xe=%d", (int)full_data_len, p->header.xe); LOGGER_DEBUG(vc->log, "vc_iterate: rb_read rb size=%d", (int)rb_size(vc->vbuf_raw)); const vpx_codec_err_t rc = vpx_codec_decode(vc->decoder, p->data, full_data_len, nullptr, MAX_DECODE_TIME_US); free(p); if (rc != VPX_CODEC_OK) { LOGGER_ERROR(vc->log, "Error decoding video: %d %s", (int)rc, vpx_codec_err_to_string(rc)); return; } /* Play decoded images */ vpx_codec_iter_t iter = nullptr; for (vpx_image_t *dest = vpx_codec_get_frame(vc->decoder, &iter); dest != nullptr; dest = vpx_codec_get_frame(vc->decoder, &iter)) { if (vc->vcb) { vc->vcb(vc->av, vc->friend_number, dest->d_w, dest->d_h, (const uint8_t *)dest->planes[0], (const uint8_t *)dest->planes[1], (const uint8_t *)dest->planes[2], dest->stride[0], dest->stride[1], dest->stride[2], vc->vcb_user_data); } vpx_img_free(dest); // is this needed? none of the VPx examples show that } }
uint8_t Pro_GetFrame() { if(rb_can_read(&u_ring_buff) >= 1) { if(packageFlag ==0) { rb_read(&u_ring_buff, &curValue, 1); if((lastValue == 0xFF)&&(curValue == 0xFF)) { tmp_buf[0] = 0xFF; tmp_buf[1] = 0xFF; count = 2; return 1; } if((lastValue == 0xFF)&&(curValue == 0x55)) { lastValue = curValue; return 1; } tmp_buf[count] = curValue; count ++ ; lastValue = curValue; if(count ==4) { dataLen = tmp_buf[2]*256+ tmp_buf[3]; } if(count == (dataLen + 4)) { memcpy(UART_HandleStruct.Message_Buf, tmp_buf, dataLen + 4); UART_HandleStruct.Message_Len = dataLen + 4; #ifdef PROTOCOL_DEBUG Serial.print(F("[")); Serial.print(SystemTimeCount, DEC); Serial.print(F("]")); Serial.print(F(" GAgentToMCU:")); for(uint8_t i = 0; i < dataLen + 4; i++) { Serial.print(" "); Serial.print(tmp_buf[i], HEX); } Serial.println(""); #endif memset(tmp_buf, 0, (dataLen + 4)); packageFlag = 1; lastValue = curValue =0; return 0; } } } return 1; }
/* * Read buffer until first occurrence of a substring * (buffer, string) -> string */ int rb_readuntil(lua_State *L) { size_t l, m; ringbuffer *b = luaL_checkudata(L, 1, "ringbuffer_mt"); const char *s = luaL_checklstring(L, 2, &l); m = find(b, s, l); if(m > 0) { lua_settop(L, 1); lua_pushinteger(L, m); return rb_read(L); } return 0; }
void pause_vorbis_stream(decoder_t * dec) { vorbis_pdata_t * pd = (vorbis_pdata_t *)dec->pdata; char flush_dest; httpc_close(pd->session); if (pd->session->type == HTTPC_SESSION_STREAM) { /* empty vorbis decoder ringbuffer */ while (rb_read_space(pd->rb)) rb_read(pd->rb, &flush_dest, sizeof(char)); } }
void *snd_stream_thread(void *data) { int sent; int rb_read_bytes; int encode_bytes_read; char *enc_buf = (char*)malloc(stream_rb.size * sizeof(char)*10); char *audio_buf = (char*)malloc(stream_rb.size * sizeof(short)); int (*xc_send)(char *buf, int buf_len) = NULL; encode_bytes_read = 0; if(cfg.srv[cfg.selected_srv]->type == SHOUTCAST) xc_send = &sc_send; if(cfg.srv[cfg.selected_srv]->type == ICECAST) xc_send = &ic_send; while(connected) { pthread_cond_wait(&stream_cond, &stream_mut); if(!connected) break; rb_read_bytes = rb_read(&stream_rb, audio_buf); if(rb_read_bytes == 0) continue; #if HAVE_LIBLAME if(!strcmp(cfg.audio.codec, "mp3")) encode_bytes_read = lame_enc_encode(&lame_stream, (short int*)audio_buf, enc_buf, rb_read_bytes/(2*cfg.audio.channel), stream_rb.size*10); #endif #if HAVE_LIBVORBIS if(!strcmp(cfg.audio.codec, "ogg")) encode_bytes_read = vorbis_enc_encode(&vorbis_stream, (short int*)audio_buf, enc_buf, rb_read_bytes/(2*cfg.audio.channel)); #endif if((sent = xc_send(enc_buf, encode_bytes_read)) == -1) connected = 0; else bytes_sent += encode_bytes_read; } free(enc_buf); free(audio_buf); return NULL; }
static void unpack_table(lua_State *L, struct read_block *rb, int array_size) { if (array_size == MAX_COOKIE-1) { uint8_t type; uint8_t *t = rb_read(rb, sizeof(type)); if (t==NULL) { invalid_stream(L,rb); } type = *t; int cookie = type >> 3; if ((type & 7) != TYPE_NUMBER || cookie == TYPE_NUMBER_REAL) { invalid_stream(L,rb); } array_size = get_integer(L,rb,cookie); }
int rbs_seek(rbstream_p rbsp, ssize_t offset, int whence) { medvdbg("[%s] offset %ld, whence %d\n", __FUNCTION__, offset, whence); RETURN_VAL_IF_FAIL(rbsp != NULL, ERROR); switch (whence) { case SEEK_SET: // checking underflow RETURN_VAL_IF_FAIL(((size_t) offset >= rbsp->rd_size), ERROR); while ((size_t) offset > rbsp->wr_size) { size_t least = (size_t) offset - rbsp->wr_size; size_t wlen; // pull stream data, then wr_size will be increased wlen = _pull(rb_avail(rbsp->rbp), least, rbsp); if ((size_t) offset > rbsp->wr_size) { // not enough if (rb_avail(rbsp->rbp) == SIZE_ZERO) { // ring-buffer is full RETURN_VAL_IF_FAIL((RBS_OPTION_TEST(rbsp, OPTION_ALLOW_TO_DEQUEUE)), ERROR); // overflow // dequeue minimal data from ring-buffer size_t len = rbsp->wr_size - rbsp->rd_size; least = (size_t) offset - rbsp->wr_size; len = MINIMUM(len, least); size_t rlen = rb_read(rbsp->rbp, NULL, len); assert(rlen == len); rbsp->rd_size += rlen; } else { RETURN_VAL_IF_FAIL((wlen != SIZE_ZERO), ERROR); // EOS } // request more data continue; } // got enough data break; } rbsp->cur_pos = (size_t) offset; break; } return OK; }
size_t rbs_read(void *ptr, size_t size, size_t nmemb, rbstream_p rbsp) { medvdbg("[%s] ptr %p nmemb %lu\n", __FUNCTION__, ptr, nmemb); RETURN_VAL_IF_FAIL(ptr != NULL, SIZE_ZERO); RETURN_VAL_IF_FAIL(rbsp != NULL, SIZE_ZERO); // only size:1 supported assert(size == 1); size_t len = size * nmemb; size_t read = SIZE_ZERO; while (read < len) { void *_ptr = (void *) ((uint8_t *) ptr + read); size_t need = len - read; size_t offset = rbsp->cur_pos - rbsp->rd_size; // read data desired size_t rlen = rb_read_ext(rbsp->rbp, _ptr, need, offset); read += rlen; rbsp->cur_pos += rlen; // increase cur_pos if (read < len) { // need to read more data size_t least = len - read; size_t avail = rb_avail(rbsp->rbp); if (least > avail) { // need to dequeue data if (RBS_OPTION_TEST(rbsp, OPTION_ALLOW_TO_DEQUEUE)) { offset = rbsp->cur_pos - rbsp->rd_size; size_t _len = MINIMUM(offset, (least - avail)); size_t _rlen = rb_read(rbsp->rbp, NULL, _len); assert(_rlen == _len); rbsp->rd_size += _rlen; } } // pull stream data, then it's available to read more. if (_pull(rb_avail(rbsp->rbp), least, rbsp) == SIZE_ZERO) { // pull data failed break; } } } medvdbg("[%s] done, read %lu\n", __FUNCTION__, read); return read; }
int rb_recv_fd_buf(rb_fde_t *F, void *data, size_t datasize, rb_fde_t **xF, int nfds) { size_t minsize = sizeof(uint32_t) + sizeof(uint8_t) + sizeof(size_t); size_t datalen; ssize_t retlen; uint32_t magic; uint8_t count; unsigned int i; void *ptr; ssize_t ret; memset(fd_buf, 0, sizeof(fd_buf)); /* some paranoia here... */ ret = rb_read(F, fd_buf, sizeof(fd_buf)); if(ret <= 0) { return ret; } if(ret < (ssize_t) minsize) { errno = EINVAL; return -1; } ptr = fd_buf; memcpy(&magic, ptr, sizeof(uint32_t)); if(magic != MAGIC_CONTROL) { errno = EAGAIN; return -1; } ptr = (void *)((uintptr_t)ptr + (uintptr_t)sizeof(uint32_t)); memcpy(&count, ptr, sizeof(uint8_t)); ptr = (void *)((uintptr_t)ptr + (uintptr_t)sizeof(uint8_t)); for(i = 0; i < count && i < (unsigned int)nfds; i++) { rb_fde_t *tF = make_fde_from_wsaprotocol_info(ptr); if(tF == NULL) return -1; xF[i] = tF; ptr = (void *)((uintptr_t)ptr + (uintptr_t)sizeof(WSAPROTOCOL_INFO)); } memcpy(&datalen, ptr, sizeof(size_t)); ptr = (void *)((uintptr_t)ptr + (uintptr_t)sizeof(size_t)); retlen = MYMIN(datalen, datasize); memcpy(data, ptr, datalen); return retlen; }
// seek and dequeue data from ring-buffer int rbs_seek_ext(rbstream_p rbsp, ssize_t offset, int whence) { medvdbg("[%s] offset %ld, whence %d\n", __FUNCTION__, offset, whence); assert(RBS_OPTION_TEST(rbsp, OPTION_ALLOW_TO_DEQUEUE)); // seek int ret = rbs_seek(rbsp, offset, whence); RETURN_VAL_IF_FAIL(ret == OK, ret); // dequeue data from ring-buffer size_t len = rbsp->cur_pos - rbsp->rd_size; size_t rlen = rb_read(rbsp->rbp, NULL, len); assert(rlen == len); // rbs_seek returned success! rbsp->rd_size += rlen; return ret; }
void vorbis_decoder_seek(decoder_t * dec, unsigned long long seek_to_pos) { vorbis_pdata_t * pd = (vorbis_pdata_t *)dec->pdata; file_decoder_t * fdec = dec->fdec; char flush_dest; if (fdec->is_stream && pd->session->type != HTTPC_SESSION_NORMAL) return; if (ov_pcm_seek(&(pd->vf), seek_to_pos) == 0) { fdec->samples_left = fdec->fileinfo.total_samples - seek_to_pos; /* empty vorbis decoder ringbuffer */ while (rb_read_space(pd->rb)) rb_read(pd->rb, &flush_dest, sizeof(char)); } else { fprintf(stderr, "vorbis_decoder_seek: warning: ov_pcm_seek() failed\n"); } }
void vc_kill(VCSession *vc) { if (!vc) { return; } vpx_codec_destroy(vc->encoder); vpx_codec_destroy(vc->decoder); void *p; while (rb_read(vc->vbuf_raw, &p)) { free(p); } rb_kill(vc->vbuf_raw); pthread_mutex_destroy(vc->queue_mutex); LOGGER_DEBUG(vc->log, "Terminated video handler: %p", (void *)vc); free(vc); }
static void rb_helper_read_cb(rb_fde_t *F, void *data) { rb_helper *helper = (rb_helper *)data; char buf[4096]; ssize_t length; if(helper == NULL) return; while((length = rb_read(helper->ifd, buf, sizeof(buf))) > 0) { rb_linebuf_parse(helper->recvq, buf, (size_t)length, 0); helper->read_cb(helper); } if(length == 0 || (length < 0 && !rb_ignore_errno(errno))) { rb_helper_restart(helper); return; } rb_setselect(helper->ifd, RB_SELECT_READ, rb_helper_read_cb, helper); }