static void puffout_strings(libvchan_t * con) { size_t sz, len; vchan_header_t head; DPRINTF(DBG_SERVER,"hello: waiting for hello message\n"); /* Wait for hello */ libvchan_wait(con); sz = libvchan_read(con, &head, sizeof(head)); assert(sz == sizeof(head)); assert(head.msg_type == MSG_HELLO); head.msg_type = MSG_ACK; len = head.len; DPRINTF(DBG_SERVER,"hello: sending hello msg ack\n"); /* Send off ack */ sz = libvchan_write(con, &head, sizeof(head)); assert(sz == sizeof(head)); DPRINTF(DBG_SERVER,"hello: waiting for string\n"); /* Read data */ libvchan_wait(con); sz = libvchan_read(con, &char_buf, len); assert(sz == len); DPRINTF(DBG_SERVER,"hello: got string: %s\n", char_buf); // head.msg_type = MSG_CONC; // sz = libvchan_write(con, &head, sizeof(head)); // assert(sz == sizeof(head)); }
void reader(struct libvchan *ctrl) { unsigned long long read_size = 0; int size; struct timeval tv1, tv2; long t = 0, t1, t2; //int f = open("b", O_WRONLY | O_CREAT, 0); while (read_size < total_size) { size = read_size + blocksize > total_size ? total_size - read_size : blocksize; gettimeofday(&tv1, NULL); size = libvchan_read(ctrl, buf, size); gettimeofday(&tv2, NULL); t1 = tv1.tv_sec*1000000 + tv1.tv_usec; t2 = tv2.tv_sec*1000000 + tv2.tv_usec; t += (t2 - t1); if (size < 0) { perror("read vchan"); libvchan_close(ctrl); exit(1); } /*if (size > 0) write(f, buf, size);*/ read_size += size; } //close(f); printf("BW: %.3f MB/s (%llu bytes in %ld usec), Size: %.2fMB, time: %.3fsec\n", BW(read_size,t), read_size, t, ((double)read_size/(1024*1024)), ((double)t/1000000)); }
static int process_source_data(struct userdata *u) { ssize_t l; void *p; if (!u->memchunk_source.memblock) { u->memchunk_source.memblock = pa_memblock_new(u->core->mempool, 16*1024); // at least vchan buffer size u->memchunk_source.index = u->memchunk_source.length = 0; } pa_assert(pa_memblock_get_length(u->memchunk_source.memblock) > u->memchunk_source.index); p = pa_memblock_acquire(u->memchunk_source.memblock); l = libvchan_read(u->rec_ctrl, p + u->memchunk_source.index, pa_memblock_get_length(u->memchunk_source.memblock) - u->memchunk_source.index); pa_memblock_release(u->memchunk_source.memblock); pa_log_debug("process_source_data %lu", l); if (l <= 0) { /* vchan disconnected/error */ pa_log("Failed to read data from vchan"); return -1; } else { u->memchunk_source.length = (size_t) l; pa_source_post(u->source, &u->memchunk_source); u->memchunk_source.index += (size_t) l; if (u->memchunk_source.index >= pa_memblock_get_length(u->memchunk_source.memblock)) { pa_memblock_unref(u->memchunk_source.memblock); pa_memchunk_reset(&u->memchunk_source); } } return 0; }
int read_data(libvchan_t *vchan, char *buf, int size) { int written = 0; int ret; while (written < size) { ret = libvchan_read(vchan, buf + written, size - written); if (ret <= 0) handle_vchan_error(vchan, "read data"); written += ret; } // fprintf(stderr, "read %d bytes\n", size); return size; }
static void rec_packet(libvchan_t * con) { size_t sz; int x; char comp[6]; vchan_packet_t pak; for(x = 0; x < NUM_PACKETS; x++) { sprintf(comp, "I%d", x); libvchan_wait(con); sz = libvchan_read(con, &pak, sizeof(pak)); assert(sz == sizeof(pak)); assert(strcmp(comp, pak.pnum) == 0); } }
static void thread_func(void *userdata) { struct userdata *u = userdata; char buf[2048]; // max ring buffer size pa_assert(u); pa_log_debug("Thread starting up"); pa_thread_mq_install(&u->thread_mq); for (;;) { struct pollfd *play_pollfd; struct pollfd *rec_pollfd; int ret; play_pollfd = pa_rtpoll_item_get_pollfd(u->play_rtpoll_item, NULL); rec_pollfd = pa_rtpoll_item_get_pollfd(u->rec_rtpoll_item, NULL); if (play_pollfd->revents & POLLIN) { if (libvchan_wait(u->play_ctrl) < 0) goto fail; play_pollfd->revents = 0; } if (rec_pollfd->revents & POLLIN) { if (libvchan_wait(u->rec_ctrl) < 0) goto fail; rec_pollfd->revents = 0; } /* Render some data and write it to the fifo */ if (PA_SINK_IS_OPENED(u->sink->thread_info.state)) { if (u->sink->thread_info.rewind_requested) pa_sink_process_rewind(u->sink, 0); if (libvchan_buffer_space(u->play_ctrl)) { if (process_sink_render(u) < 0) goto fail; } } if (u->source->thread_info.state == PA_SOURCE_RUNNING) { while (libvchan_data_ready(u->rec_ctrl)) { if (process_source_data(u) < 0) goto fail; } } else { /* discard the data */ if (libvchan_data_ready(u->rec_ctrl)) if (libvchan_read(u->rec_ctrl, buf, sizeof(buf)) < 0) goto fail; } /* Hmm, nothing to do. Let's sleep */ play_pollfd->events = POLLIN; rec_pollfd->events = POLLIN; #if PA_CHECK_VERSION(6,0,0) if ((ret = pa_rtpoll_run(u->rtpoll)) < 0) #else if ((ret = pa_rtpoll_run(u->rtpoll, true)) < 0) #endif goto fail; if (ret == 0) goto finish; } fail: /* If this was no regular exit from the loop we have to continue * processing messages until we received PA_MESSAGE_SHUTDOWN */ pa_asyncmsgq_post(u->thread_mq.outq, PA_MSGOBJECT(u->core), PA_CORE_MESSAGE_UNLOAD_MODULE, u->module, 0, NULL, NULL); pa_asyncmsgq_wait_for(u->thread_mq.inq, PA_MESSAGE_SHUTDOWN); finish: pa_log_debug("Thread shutting down"); }