/** @This is called when there is no external reference to the pipe anymore. * * @param upipe description structure of the pipe */ static void upipe_fdec_no_ref(struct upipe *upipe) { struct upipe_fdec *upipe_fdec = upipe_fdec_from_upipe(upipe); upipe_fdec_clean_bin_input(upipe); upipe_fdec_clean_bin_output(upipe); urefcount_release(upipe_fdec_to_urefcount_real(upipe_fdec)); }
/** @internal @This allocates the options uref. * * @param upipe description structure of the pipe * @param unused unused argument * @return an error code */ static int upipe_fdec_provide(struct upipe *upipe, struct uref *unused) { struct upipe_fdec *upipe_fdec = upipe_fdec_from_upipe(upipe); if (upipe_fdec->uref_mgr != NULL && upipe_fdec->options == NULL) upipe_fdec->options = uref_alloc_control(upipe_fdec->uref_mgr); return UBASE_ERR_NONE; }
/** @internal @This gets the value of an option. * * @param upipe description structure of the pipe * @param key name of the option * @param value of the option, or NULL to delete it * @return an error code */ static int upipe_fdec_get_option(struct upipe *upipe, const char *key, const char **value_p) { struct upipe_fdec *upipe_fdec = upipe_fdec_from_upipe(upipe); assert(key != NULL); if (upipe_fdec->options == NULL) return UBASE_ERR_INVALID; return udict_get_string(upipe_fdec->options->udict, value_p, UDICT_TYPE_STRING, key); }
/** @internal @This sets the input flow definition. * * @param upipe description structure of the pipe * @param flow_def flow definition packet * @return an error code */ static int upipe_fdec_set_flow_def(struct upipe *upipe, struct uref *flow_def) { struct upipe_fdec_mgr *fdec_mgr = upipe_fdec_mgr_from_upipe_mgr(upipe->mgr); struct upipe_fdec *upipe_fdec = upipe_fdec_from_upipe(upipe); if (flow_def == NULL) return UBASE_ERR_INVALID; if (upipe_fdec->last_inner != NULL) { if (ubase_check(upipe_set_flow_def(upipe_fdec->last_inner, flow_def))) return UBASE_ERR_NONE; } upipe_fdec_store_bin_input(upipe, NULL); upipe_fdec_store_bin_output(upipe, NULL); struct upipe *avcdec = upipe_void_alloc(fdec_mgr->avcdec_mgr, uprobe_pfx_alloc( uprobe_use(&upipe_fdec->last_inner_probe), UPROBE_LOG_VERBOSE, "avcdec")); if (unlikely(avcdec == NULL)) { upipe_err_va(upipe, "couldn't allocate avcdec"); return UBASE_ERR_UNHANDLED; } if (unlikely(!ubase_check(upipe_set_flow_def(avcdec, flow_def)))) { upipe_err_va(upipe, "couldn't set avcdec flow def"); upipe_release(avcdec); return UBASE_ERR_UNHANDLED; } if (upipe_fdec->options != NULL && upipe_fdec->options->udict != NULL) { const char *key = NULL; enum udict_type type = UDICT_TYPE_END; while (ubase_check(udict_iterate(upipe_fdec->options->udict, &key, &type)) && type != UDICT_TYPE_END) { const char *value; if (key == NULL || !ubase_check(udict_get_string(upipe_fdec->options->udict, &value, type, key))) continue; if (!ubase_check(upipe_set_option(avcdec, key, value))) upipe_warn_va(upipe, "option %s=%s invalid", key, value); } } upipe_fdec_store_bin_input(upipe, upipe_use(avcdec)); upipe_fdec_store_bin_output(upipe, avcdec); return UBASE_ERR_NONE; }
/** @internal @This sets the value of an option. * * @param upipe description structure of the pipe * @param key name of the option * @param value of the option, or NULL to delete it * @return an error code */ static int upipe_fdec_set_option(struct upipe *upipe, const char *key, const char *value) { struct upipe_fdec *upipe_fdec = upipe_fdec_from_upipe(upipe); assert(key != NULL); if (upipe_fdec->options == NULL) return UBASE_ERR_ALLOC; if (upipe_fdec->last_inner != NULL) { UBASE_RETURN(upipe_set_option(upipe_fdec->last_inner, key, value)) } if (value != NULL) return udict_set_string(upipe_fdec->options->udict, value, UDICT_TYPE_STRING, key); else udict_delete(upipe_fdec->options->udict, UDICT_TYPE_STRING, key); return UBASE_ERR_NONE; }
/** @internal @This allocates a fdec 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_fdec_alloc(struct upipe_mgr *mgr, struct uprobe *uprobe, uint32_t signature, va_list args) { struct upipe *upipe = upipe_fdec_alloc_void(mgr, uprobe, signature, args); if (unlikely(upipe == NULL)) return NULL; struct upipe_fdec *upipe_fdec = upipe_fdec_from_upipe(upipe); upipe_fdec_init_urefcount(upipe); urefcount_init(upipe_fdec_to_urefcount_real(upipe_fdec), upipe_fdec_free); upipe_fdec_init_uref_mgr(upipe); upipe_fdec_init_bin_input(upipe); upipe_fdec_init_bin_output(upipe, upipe_fdec_to_urefcount_real(upipe_fdec)); upipe_fdec->options = NULL; upipe_throw_ready(upipe); upipe_fdec_demand_uref_mgr(upipe); return upipe; }