static void write_idler_cb(struct upump *upump) { ssize_t ret = write(pipefd[1], padding, strlen(padding) + 1); if (ret == -1 && (errno == EWOULDBLOCK || errno == EAGAIN)) { printf("write idler blocked\n"); blocker = upump_blocker_alloc(write_idler, blocker_cb, NULL); assert(blocker != NULL); upump_start(write_watcher); upump_start(read_timer); } else { assert(ret != -1); bytes_written += ret; } }
/** @internal @This processes control commands on the pipe. * * @param upipe description structure of the pipe * @param control type of command to process * @param args arguments of the command * @return an error code */ static int upipe_nacl_audio_control(struct upipe *upipe, int command, va_list args) { UBASE_RETURN(_upipe_nacl_audio_control(upipe, command, args)); struct upipe_nacl_audio *upipe_nacl_audio = upipe_nacl_audio_from_upipe(upipe); if (unlikely(!upipe_nacl_audio_check_input(upipe))) { upipe_nacl_audio_check_watcher(upipe); upump_start(upipe_nacl_audio->upump); } return UBASE_ERR_NONE; }
int main(int argc, char **argv) { long flags; assert(ecore_init()); mgr = upump_ecore_mgr_alloc(UPUMP_POOL, UPUMP_BLOCKER_POOL); assert(mgr != NULL); /* Create a pipe with non-blocking write */ assert(pipe(pipefd) != -1); flags = fcntl(pipefd[1], F_GETFL); assert(flags != -1); flags |= O_NONBLOCK; assert(fcntl(pipefd[1], F_SETFL, flags) != -1); /* Create watchers */ write_idler = upump_alloc_idler(mgr, write_idler_cb, NULL, NULL); assert(write_idler != NULL); write_watcher = upump_alloc_fd_write(mgr, write_watcher_cb, NULL, NULL, pipefd[1]); assert(write_watcher != NULL); read_timer = upump_alloc_timer(mgr, read_timer_cb, NULL, NULL, timeout, 0); assert(read_timer != NULL); read_watcher = upump_alloc_fd_read(mgr, read_watcher_cb, NULL, NULL, pipefd[0]); assert(read_watcher != NULL); /* Start tests */ upump_start(write_idler); ecore_main_loop_begin(); printf("\nread: \t%zd\nwrite: \t%zd\n", bytes_read, bytes_written); assert(bytes_read); assert(bytes_read == bytes_written); /* Clean up */ upump_free(write_idler); upump_free(write_watcher); upump_free(read_timer); upump_free(read_watcher); upump_mgr_release(mgr); ecore_shutdown(); return 0; }
/** @This starts the watcher waiting for the sink to unblock. * * @param upipe description structure of the pipe */ static void upipe_dveo_asi_sink_poll(struct upipe *upipe) { struct upipe_dveo_asi_sink *upipe_dveo_asi_sink = upipe_dveo_asi_sink_from_upipe(upipe); if (unlikely(!ubase_check(upipe_dveo_asi_sink_check_upump_mgr(upipe)))) { upipe_err_va(upipe, "can't get upump_mgr"); upipe_throw_fatal(upipe, UBASE_ERR_UPUMP); return; } struct upump *watcher = upump_alloc_fd_write(upipe_dveo_asi_sink->upump_mgr, upipe_dveo_asi_sink_watcher, upipe, upipe->refcount, upipe_dveo_asi_sink->fd); if (unlikely(watcher == NULL)) { upipe_err(upipe, "can't create watcher"); upipe_throw_fatal(upipe, UBASE_ERR_UPUMP); } else { upipe_dveo_asi_sink_set_upump(upipe, watcher); upump_start(watcher); } }
int main(int argc, char **argv) { long flags; loop = ev_default_loop(0); mgr = upump_ev_mgr_alloc(loop, UPUMP_POOL, UPUMP_BLOCKER_POOL); assert(mgr != NULL); /* Create a pipe with non-blocking write */ assert(pipe(pipefd) != -1); flags = fcntl(pipefd[1], F_GETFL); assert(flags != -1); flags |= O_NONBLOCK; assert(fcntl(pipefd[1], F_SETFL, flags) != -1); /* Create watchers */ write_idler = upump_alloc_idler(mgr, write_idler_cb, NULL); assert(write_idler != NULL); write_watcher = upump_alloc_fd_write(mgr, write_watcher_cb, NULL, pipefd[1]); assert(write_watcher != NULL); read_timer = upump_alloc_timer(mgr, read_timer_cb, NULL, timeout, 0); assert(read_timer != NULL); read_watcher = upump_alloc_fd_read(mgr, read_watcher_cb, NULL, pipefd[0]); assert(read_watcher != NULL); /* Start tests */ upump_start(write_idler); ev_loop(loop, 0); assert(bytes_read); assert(bytes_read == bytes_written); /* Clean up */ upump_free(write_idler); upump_free(write_watcher); upump_free(read_timer); upump_free(read_watcher); upump_mgr_release(mgr); ev_default_destroy(); return 0; }
/** @internal @This allocates the upump if needed. * * @param upipe description structure of the pipe * @return an error code */ static int upipe_burst_check(struct upipe *upipe) { struct upipe_burst *upipe_burst = upipe_burst_from_upipe(upipe); upipe_burst_check_upump_mgr(upipe); if (unlikely(upipe_burst->upump_mgr == NULL)) return UBASE_ERR_INVALID; if (unlikely(upipe_burst->upump == NULL)) { struct upump *upump = ueventfd_upump_alloc( &upipe_burst->ueventfd, upipe_burst->upump_mgr, upipe_burst_worker, upipe, upipe->refcount); if (unlikely(upump == NULL)) return UBASE_ERR_UPUMP; upump_start(upump); upipe_burst_set_upump(upipe, upump); if (unlikely(!ulist_empty(&upipe_burst->urefs))) ueventfd_write(&upipe_burst->ueventfd); } return UBASE_ERR_NONE; }
void run(struct upump_mgr *mgr) { long flags; assert(mgr != NULL); /* Create a pipe with non-blocking write */ assert(pipe(pipefd) != -1); flags = fcntl(pipefd[1], F_GETFL); assert(flags != -1); flags |= O_NONBLOCK; assert(fcntl(pipefd[1], F_SETFL, flags) != -1); /* Create watchers */ write_idler = upump_alloc_idler(mgr, write_idler_cb, NULL, NULL); assert(write_idler != NULL); write_watcher = upump_alloc_fd_write(mgr, write_watcher_cb, NULL, NULL, pipefd[1]); assert(write_watcher != NULL); read_timer = upump_alloc_timer(mgr, read_timer_cb, NULL, NULL, timeout, 0); assert(read_timer != NULL); read_watcher = upump_alloc_fd_read(mgr, read_watcher_cb, NULL, NULL, pipefd[0]); assert(read_watcher != NULL); /* Start tests */ upump_start(write_idler); upump_mgr_run(mgr, NULL); assert(bytes_read); assert(bytes_read == bytes_written); /* Clean up */ upump_free(write_idler); upump_free(write_watcher); upump_free(read_timer); upump_free(read_watcher); upump_mgr_release(mgr); }
/** @internal @This inputs data. * * @param upipe description structure of the pipe * @param uref uref structure * @param upump_p reference to upump structure */ static void upipe_nacl_audio_input(struct upipe *upipe, struct uref *uref, struct upump **upump_p) { struct upipe_nacl_audio *upipe_nacl_audio = upipe_nacl_audio_from_upipe(upipe); size_t uref_size; if (unlikely(!ubase_check(uref_sound_size(uref, &uref_size, NULL)))) { upipe_warn(upipe, "unable to read uref"); uref_free(uref); return; } if (unlikely(!upipe_nacl_audio->started && !upipe_nacl_audio_open(upipe))) { upipe_warn(upipe, "unable to open device"); uref_free(uref); return; } uint64_t uref_pts; if (likely(ubase_check(uref_clock_get_pts_sys(uref, &uref_pts)))) { uref_pts += upipe_nacl_audio->latency; uref_clock_set_pts_sys(uref, uref_pts); } if (!upipe_nacl_audio_check_input(upipe)) { upipe_nacl_audio_hold_input(upipe, uref); upipe_nacl_audio_block_input(upipe, upump_p); } else if (!upipe_nacl_audio_handle(upipe, uref, upump_p)) { if (!upipe_nacl_audio_check_watcher(upipe)) { upipe_warn(upipe, "unable to spool uref"); uref_free(uref); return; } upipe_nacl_audio_hold_input(upipe, uref); upipe_nacl_audio_block_input(upipe, upump_p); upump_start(upipe_nacl_audio->upump); } }
/** @internal @This is the callback of upumpstart, start the QT Thread * * @param upumpstart pump that start this */ void start(struct upump *upumpstart){ struct upipe *upipe = upump_get_opaque(upumpstart, struct upipe *); struct upipe_qt_html *upipe_qt_html = upipe_qt_html_from_upipe(upipe); upipe_qt_html->qtthreadfree = false; upipe_qt_html->uqueue_extra = (uint8_t*)malloc(uqueue_sizeof(MAX_QUEUE_LENGTH)); uqueue_init(&upipe_qt_html->uqueue, MAX_QUEUE_LENGTH, upipe_qt_html->uqueue_extra); upipe_qt_html->uqueue_extra2 = (uint8_t*)malloc(uqueue_sizeof(MAX_QUEUE_LENGTH)); uqueue_init(&upipe_qt_html->uqueue2, MAX_QUEUE_LENGTH, upipe_qt_html->uqueue_extra2); struct upump *upump = uqueue_upump_alloc_pop(&upipe_qt_html->uqueue, upipe_qt_html->upump_mgr, upipe_qt_html_worker, upipe, upipe->refcount); upipe_qt_html_set_upump(upipe, upump); upump_start(upump); upipe_qt_html->url = "http://upipe.org/blog/"; pthread_create(&upipe_qt_html->thread, NULL, thread_start, (void *)upipe_qt_html); upipe_qt_html_clean_upumpstart(upipe); upipe_qt_html_set_upumpstart(upipe,NULL); }
/** @internal @This checks if the pump may be allocated. * * @param upipe description structure of the pipe * @param flow requested output flow format * @return an error code */ static int upipe_voidsrc_check(struct upipe *upipe, struct uref *flow) { struct upipe_voidsrc *upipe_voidsrc = upipe_voidsrc_from_upipe(upipe); if (flow != NULL) upipe_voidsrc_store_flow_def(upipe, flow); if (!upipe_voidsrc->uref_mgr) { upipe_voidsrc_require_uref_mgr(upipe); return UBASE_ERR_NONE; } if (!upipe_voidsrc->uclock) { upipe_voidsrc_require_uclock(upipe); return UBASE_ERR_NONE; } upipe_voidsrc_check_upump_mgr(upipe); if (unlikely(!upipe_voidsrc->upump_mgr)) return UBASE_ERR_NONE; if (!upipe_voidsrc->timer) { struct upump *timer = upump_alloc_timer(upipe_voidsrc->upump_mgr, upipe_voidsrc_worker, upipe, upipe->refcount, upipe_voidsrc->interval, 0); if (unlikely(!timer)) { upipe_throw_fatal(upipe, UBASE_ERR_UPUMP); return UBASE_ERR_UPUMP; } upipe_voidsrc_set_timer(upipe, timer); upump_start(timer); } return UBASE_ERR_NONE; }
static void read_timer_cb(struct upump *unused) { printf("read timer passed\n"); upump_start(read_watcher); /* The timer is automatically stopped */ }