/** @internal @This allocates a avcdec pipe. * * @param mgr common management structure * @param uprobe structure used to raise events * @return pointer to upipe or NULL in case of allocation error */ static struct upipe *upipe_avcdec_alloc(struct upipe_mgr *mgr, struct uprobe *uprobe) { struct upipe_avcdec *upipe_avcdec = malloc(sizeof(struct upipe_avcdec)); if (unlikely(upipe_avcdec == NULL)) return NULL; struct upipe *upipe = upipe_avcdec_to_upipe(upipe_avcdec); upipe_init(upipe, mgr, uprobe); upipe_avcdec_init_uref_mgr(upipe); upipe_avcdec_init_ubuf_mgr(upipe); upipe_avcdec_init_upump_mgr(upipe); upipe_avcdec_init_output(upipe); upipe_avcdec->context = NULL; upipe_avcdec->upump_av_deal = NULL; upipe_avcdec->saved_uref = NULL; upipe_avcdec->saved_upump_mgr = NULL; upipe_avcdec->pixfmt = NULL; upipe_avcdec->frame = avcodec_alloc_frame(); upipe_avcdec->lowres = 0; upipe_avcdec->index_rap = 0; upipe_avcdec->prev_rap = 0; upipe_throw_ready(upipe); return upipe; }
/** helper phony pipe to count pictures */ static struct upipe *count_alloc(struct upipe_mgr *mgr, struct uprobe *uprobe) { struct upipe *upipe = malloc(sizeof(struct upipe)); assert(upipe != NULL); upipe_init(upipe, mgr, uprobe); return upipe; }
/** helper phony pipe to test uprobe_upump_mgr */ static struct upipe *uprobe_test_alloc(struct upipe_mgr *mgr, struct uprobe *uprobe) { struct upipe *upipe = malloc(sizeof(struct upipe)); assert(upipe != NULL); upipe_init(upipe, mgr, uprobe); upipe_throw_need_upump_mgr(upipe); assert(got_upump_mgr); return upipe; }
/** helper phony pipe */ static struct upipe *test_alloc(struct upipe_mgr *mgr, struct uprobe *uprobe, uint32_t signature, va_list args) { struct x264_test *x264_test = malloc(sizeof(struct x264_test)); assert(x264_test != NULL); upipe_init(&x264_test->upipe, mgr, uprobe); x264_test->counter = 0; upipe_throw_ready(&x264_test->upipe); return &x264_test->upipe; }
/** @internal @This allocates a multicat_probe pipe. * * @param mgr common management structure * @param uprobe structure used to raise events * @return pointer to upipe or NULL in case of allocation error */ static struct upipe *upipe_multicat_probe_alloc(struct upipe_mgr *mgr, struct uprobe *uprobe) { struct upipe_multicat_probe *upipe_multicat_probe = malloc(sizeof(struct upipe_multicat_probe)); if (unlikely(upipe_multicat_probe == NULL)) return NULL; struct upipe *upipe = upipe_multicat_probe_to_upipe(upipe_multicat_probe); upipe_init(upipe, mgr, uprobe); upipe_multicat_probe_init_output(upipe); upipe_multicat_probe->rotate = UPIPE_MULTICAT_PROBE_DEF_ROTATE; upipe_multicat_probe->idx = 0; upipe_throw_ready(upipe); return upipe; }
/** @internal @This allocates an nacl audio pipe. * * @param mgr common management structure * @param uprobe structure used to raise events * @param signature signature of the pipe allocator * @param args optional arguments * @return pointer to upipe or NULL in case of allocation error */ static struct upipe *upipe_nacl_audio_alloc(struct upipe_mgr *mgr, struct uprobe *uprobe, uint32_t signature, va_list args) { if (signature != UPIPE_VOID_SIGNATURE) return NULL; struct upipe_nacl_audio *upipe_nacl_audio = malloc(sizeof(struct upipe_nacl_audio) + uqueue_sizeof(MAX_QUEUE_LENGTH)); if (unlikely(upipe_nacl_audio == NULL)) return NULL; if(unlikely(!uqueue_init(&upipe_nacl_audio->uqueue, MAX_QUEUE_LENGTH, upipe_nacl_audio->uqueue_extra))) { free(upipe_nacl_audio); return NULL; } struct upipe *upipe = upipe_nacl_audio_to_upipe(upipe_nacl_audio); upipe_init(upipe, mgr, uprobe); upipe_nacl_audio_init_urefcount(upipe); upipe_nacl_audio_init_input(upipe); upipe_nacl_audio_init_upump_mgr(upipe); upipe_nacl_audio_init_upump(upipe); upipe_nacl_audio_init_uclock(upipe); upipe_nacl_audio->started = false; PPB_AudioConfig *audio_config_interface = (PPB_AudioConfig *)PSGetInterface(PPB_AUDIO_CONFIG_INTERFACE); upipe_nacl_audio->nb_samples = audio_config_interface->RecommendSampleFrameCount(PSGetInstanceId(), SAMPLE_RATE, NB_SAMPLES); upipe_nacl_audio->audio_config = audio_config_interface->CreateStereo16Bit(PSGetInstanceId(), SAMPLE_RATE, upipe_nacl_audio->nb_samples); upipe_nacl_audio->core_interface = (PPB_Core *)PSGetInterface(PPB_CORE_INTERFACE); upipe_nacl_audio->audio_interface = (PPB_Audio *)PSGetInterface(PPB_AUDIO_INTERFACE); upipe_nacl_audio->audio = upipe_nacl_audio->audio_interface->Create(PSGetInstanceId(), upipe_nacl_audio->audio_config, upipe_nacl_audio_worker, upipe); upipe_throw_ready(upipe); return upipe; }
/** helper phony pipe to test uprobe_pthread_upump_mgr */ static struct upipe *uprobe_test_alloc(struct upipe_mgr *mgr, struct uprobe *uprobe, uint32_t signature, va_list args) { struct upipe *upipe = malloc(sizeof(struct upipe)); assert(upipe != NULL); upipe_init(upipe, mgr, uprobe); struct upump_mgr *m = NULL; upipe_throw_need_upump_mgr(upipe, &m); if (m != NULL) { upump_mgr_set_opaque(m, upipe); upump_mgr_release(m); } return upipe; }
/** @internal @This allocates a skip pipe. * * @param mgr common management structure * @param uprobe structure used to raise events * @return pointer to upipe or NULL in case of allocation error */ static struct upipe *upipe_skip_alloc(struct upipe_mgr *mgr, struct uprobe *uprobe) { struct upipe_skip *upipe_skip = malloc(sizeof(struct upipe_skip)); if (unlikely(upipe_skip == NULL)) return NULL; struct upipe *upipe = upipe_skip_to_upipe(upipe_skip); upipe_init(upipe, mgr, uprobe); upipe_skip_init_output(upipe); upipe_skip->offset = 0; upipe_throw_ready(upipe); return upipe; }
/** @internal @This allocates a wsrc pipe. * * @param mgr common management structure * @param uprobe structure used to raise events * @param signature signature of the pipe allocator * @param args optional arguments * @return pointer to upipe or NULL in case of allocation error */ static struct upipe *_upipe_wsrc_alloc(struct upipe_mgr *mgr, struct uprobe *uprobe, uint32_t signature, va_list args) { struct upipe_wsrc_mgr *wsrc_mgr = upipe_wsrc_mgr_from_upipe_mgr(mgr); if (unlikely(signature != UPIPE_WSRC_SIGNATURE || wsrc_mgr->xfer_mgr == NULL)) goto upipe_wsrc_alloc_err; struct upipe *remote = va_arg(args, struct upipe *); struct uprobe *uprobe_remote = va_arg(args, struct uprobe *); unsigned int queue_length = va_arg(args, unsigned int); assert(queue_length); if (unlikely(remote == NULL)) goto upipe_wsrc_alloc_err2; struct upipe_wsrc *upipe_wsrc = malloc(sizeof(struct upipe_wsrc)); if (unlikely(upipe_wsrc == NULL)) goto upipe_wsrc_alloc_err2; struct upipe *upipe = upipe_wsrc_to_upipe(upipe_wsrc); upipe_init(upipe, mgr, uprobe); upipe_wsrc_init_urefcount(upipe); urefcount_init(upipe_wsrc_to_urefcount_real(upipe_wsrc), upipe_wsrc_free); upipe_wsrc_init_last_inner_probe(upipe); upipe_wsrc_init_bin_output(upipe); upipe_wsrc->source = NULL; uprobe_init(&upipe_wsrc->proxy_probe, upipe_wsrc_proxy_probe, NULL); upipe_wsrc->proxy_probe.refcount = upipe_wsrc_to_urefcount_real(upipe_wsrc); uprobe_init(&upipe_wsrc->qsrc_probe, upipe_wsrc_qsrc_probe, &upipe_wsrc->last_inner_probe); upipe_wsrc->qsrc_probe.refcount = upipe_wsrc_to_urefcount_real(upipe_wsrc); upipe_throw_ready(upipe); /* output queue */ struct upipe *out_qsrc = upipe_qsrc_alloc(wsrc_mgr->qsrc_mgr, uprobe_pfx_alloc(uprobe_use(&upipe_wsrc->qsrc_probe), UPROBE_LOG_VERBOSE, "out_qsrc"), queue_length > UINT8_MAX ? UINT8_MAX : queue_length); if (unlikely(out_qsrc == NULL)) goto upipe_wsrc_alloc_err3; struct upipe *out_qsink = upipe_qsink_alloc(wsrc_mgr->qsink_mgr, uprobe_pfx_alloc(uprobe_remote, UPROBE_LOG_VERBOSE, "out_qsink"), out_qsrc); if (unlikely(out_qsink == NULL)) { upipe_release(out_qsrc); goto upipe_wsrc_alloc_err3; } if (queue_length > UINT8_MAX) upipe_set_max_length(out_qsink, queue_length - UINT8_MAX); upipe_attach_upump_mgr(out_qsrc); upipe_wsrc_store_bin_output(upipe, out_qsrc); /* last remote */ struct upipe *last_remote = upipe_use(remote); struct upipe *tmp; /* upipe_get_output is a control command and may trigger a need_upump_mgr * event */ uprobe_throw(upipe->uprobe, NULL, UPROBE_FREEZE_UPUMP_MGR); while (ubase_check(upipe_get_output(last_remote, &tmp)) && tmp != NULL) { upipe_use(tmp); upipe_release(last_remote); last_remote = tmp; } uprobe_throw(upipe->uprobe, NULL, UPROBE_THAW_UPUMP_MGR); struct upipe *last_remote_xfer = upipe_xfer_alloc(wsrc_mgr->xfer_mgr, uprobe_pfx_alloc(uprobe_use(&upipe_wsrc->proxy_probe), UPROBE_LOG_VERBOSE, "src_last_xfer"), last_remote); if (unlikely(last_remote_xfer == NULL)) { upipe_release(out_qsink); goto upipe_wsrc_alloc_err3; } upipe_attach_upump_mgr(last_remote_xfer); upipe_set_output(last_remote_xfer, out_qsink); upipe_release(out_qsink); /* remote */ if (last_remote != remote) { upipe_wsrc->source = upipe_xfer_alloc(wsrc_mgr->xfer_mgr, uprobe_pfx_alloc(uprobe_use(&upipe_wsrc->proxy_probe), UPROBE_LOG_VERBOSE, "src_xfer"), remote); if (unlikely(upipe_wsrc->source == NULL)) { upipe_release(out_qsink); upipe_release(upipe); return NULL; } upipe_attach_upump_mgr(upipe_wsrc->source); upipe_release(last_remote_xfer); } else { upipe_wsrc->source = last_remote_xfer; upipe_release(remote); } return upipe; upipe_wsrc_alloc_err3: upipe_release(remote); upipe_release(upipe); return NULL; upipe_wsrc_alloc_err2: uprobe_release(uprobe_remote); upipe_release(remote); upipe_wsrc_alloc_err: uprobe_release(uprobe); return NULL; }
/** @internal @This allocates a wsink pipe. * * @param mgr common management structure * @param uprobe structure used to raise events * @param signature signature of the pipe allocator * @param args optional arguments * @return pointer to upipe or NULL in case of allocation error */ static struct upipe *_upipe_wsink_alloc(struct upipe_mgr *mgr, struct uprobe *uprobe, uint32_t signature, va_list args) { struct upipe_wsink_mgr *wsink_mgr = upipe_wsink_mgr_from_upipe_mgr(mgr); if (unlikely(signature != UPIPE_WSINK_SIGNATURE || wsink_mgr->xfer_mgr == NULL)) goto upipe_wsink_alloc_err; struct upipe *remote = va_arg(args, struct upipe *); struct uprobe *uprobe_remote = va_arg(args, struct uprobe *); unsigned int queue_length = va_arg(args, unsigned int); assert(queue_length); if (unlikely(remote == NULL)) goto upipe_wsink_alloc_err2; struct upipe_wsink *upipe_wsink = malloc(sizeof(struct upipe_wsink)); if (unlikely(upipe_wsink == NULL)) goto upipe_wsink_alloc_err2; struct upipe *upipe = upipe_wsink_to_upipe(upipe_wsink); upipe_init(upipe, mgr, uprobe); upipe_wsink_init_urefcount(upipe); urefcount_init(upipe_wsink_to_urefcount_real(upipe_wsink), upipe_wsink_free); upipe_wsink_init_bin_input(upipe); uprobe_init(&upipe_wsink->proxy_probe, upipe_wsink_proxy_probe, NULL); upipe_wsink->proxy_probe.refcount = upipe_wsink_to_urefcount_real(upipe_wsink); uprobe_init(&upipe_wsink->in_qsrc_probe, upipe_wsink_in_qsrc_probe, uprobe_remote); upipe_wsink->in_qsrc_probe.refcount = upipe_wsink_to_urefcount_real(upipe_wsink); upipe_throw_ready(upipe); /* remote */ upipe_use(remote); struct upipe *remote_xfer = upipe_xfer_alloc(wsink_mgr->xfer_mgr, uprobe_pfx_alloc(uprobe_use(&upipe_wsink->proxy_probe), UPROBE_LOG_VERBOSE, "sink_xfer"), remote); if (unlikely(remote_xfer == NULL)) { upipe_release(remote); upipe_release(upipe); return NULL; } upipe_attach_upump_mgr(remote_xfer); /* input queue */ struct upipe *in_qsrc = upipe_qsrc_alloc(wsink_mgr->qsrc_mgr, uprobe_pfx_alloc( uprobe_use(&upipe_wsink->in_qsrc_probe), UPROBE_LOG_VERBOSE, "in_qsrc"), queue_length > UINT8_MAX ? UINT8_MAX : queue_length); if (unlikely(in_qsrc == NULL)) goto upipe_wsink_alloc_err3; struct upipe *in_qsink = upipe_qsink_alloc(wsink_mgr->qsink_mgr, uprobe_pfx_alloc(uprobe_use(&upipe_wsink->proxy_probe), UPROBE_LOG_VERBOSE, "in_qsink"), in_qsrc); if (unlikely(in_qsink == NULL)) goto upipe_wsink_alloc_err3; upipe_wsink_store_bin_input(upipe, in_qsink); if (queue_length > UINT8_MAX) upipe_set_max_length(upipe_wsink->in_qsink, queue_length - UINT8_MAX); struct upipe *in_qsrc_xfer = upipe_xfer_alloc(wsink_mgr->xfer_mgr, uprobe_pfx_alloc(uprobe_use(&upipe_wsink->proxy_probe), UPROBE_LOG_VERBOSE, "in_qsrc_xfer"), in_qsrc); if (unlikely(in_qsrc_xfer == NULL)) goto upipe_wsink_alloc_err3; upipe_set_output(in_qsrc_xfer, remote); upipe_attach_upump_mgr(in_qsrc_xfer); upipe_release(remote); upipe_release(remote_xfer); upipe_release(in_qsrc_xfer); return upipe; upipe_wsink_alloc_err3: upipe_release(remote); upipe_release(remote_xfer); upipe_release(upipe); return NULL; upipe_wsink_alloc_err2: upipe_release(remote); upipe_wsink_alloc_err: uprobe_release(uprobe); return NULL; }