Exemple #1
0
/** helper phony pipe to count pictures */
static void count_input(struct upipe *upipe, struct uref *uref,
                        struct upump *upump)
{
    const char *def;
    if (uref_flow_get_def(uref, &def) && uref_flow_get_end(uref)) {
        uref_free(uref);
        return;
    }

    uint64_t uref_duration;
    if (uref_clock_get_duration(uref, &uref_duration))
        duration += uref_duration;
    uref_free(uref);
}
/** @internal @This merges the new access unit into a possibly existing
 * incomplete PES, and outputs the PES if possible.
 *
 * @param upipe description structure of the pipe
 * @param uref uref structure
 * @param upump_p reference to pump that generated the buffer
 * @return false if the input must be blocked
 */
static bool upipe_ts_pese_handle(struct upipe *upipe, struct uref *uref,
                                 struct upump **upump_p)
{
    struct upipe_ts_pese *upipe_ts_pese = upipe_ts_pese_from_upipe(upipe);
    const char *def;
    if (unlikely(ubase_check(uref_flow_get_def(uref, &def)))) {
        upipe_ts_pese_work(upipe, NULL);

        uref_ts_flow_get_pes_id(uref, &upipe_ts_pese->pes_id);
        upipe_ts_pese->pes_header_size = 0;
        uref_ts_flow_get_pes_header(uref, &upipe_ts_pese->pes_header_size);
        upipe_ts_pese->pes_min_duration = 0;
        uref_ts_flow_get_pes_min_duration(uref,
                                          &upipe_ts_pese->pes_min_duration);
        upipe_ts_pese->input_latency = 0;
        uref_clock_get_latency(uref, &upipe_ts_pese->input_latency);
        if (unlikely(!ubase_check(uref_clock_set_latency(uref,
                                        upipe_ts_pese->input_latency +
                                        upipe_ts_pese->pes_min_duration))))
            upipe_throw_fatal(upipe, UBASE_ERR_ALLOC);
        upipe_ts_pese_store_flow_def(upipe, NULL);
        upipe_ts_pese_require_ubuf_mgr(upipe, uref);
        return true;
    }

    if (upipe_ts_pese->flow_def == NULL)
        return false;

    uint64_t uref_duration = upipe_ts_pese->pes_min_duration;
    uref_clock_get_duration(uref, &uref_duration);
    size_t uref_size = 0;
    uref_block_size(uref, &uref_size);
    uref_block_delete_start(uref);

    ulist_add(&upipe_ts_pese->next_pes, uref_to_uchain(uref));
    upipe_ts_pese->next_pes_duration += uref_duration;
    upipe_ts_pese->next_pes_size += uref_size;

    if (upipe_ts_pese->next_pes_duration >= upipe_ts_pese->pes_min_duration)
        upipe_ts_pese_work(upipe, upump_p);
    return true;
}
Exemple #3
0
/** @internal @This allocates and initializes a void source pipe.
 *
 * @param mgr pointer to upipe manager
 * @param uprobe structure used to raise events
 * @param signature signature of the pipe allocator
 * @param args optional arguments
 * @return an alloocated and initialized pipe or NULL
 */
static struct upipe *upipe_voidsrc_alloc(struct upipe_mgr *mgr,
                                         struct uprobe *uprobe,
                                         uint32_t signature, va_list args)
{
    struct uref *flow;
    struct upipe *upipe = upipe_voidsrc_alloc_flow(mgr, uprobe,
                                                   signature, args,
                                                   &flow);
    if (unlikely(!upipe))
        return NULL;

    uint64_t duration = 0;
    if (unlikely(!ubase_check(
        uref_clock_get_duration(flow, &duration)))) {
        uref_free(flow);
        upipe_voidsrc_free_flow(upipe);
        return NULL;
    }

    upipe_voidsrc_init_urefcount(upipe);
    upipe_voidsrc_init_output(upipe);
    upipe_voidsrc_init_uref_mgr(upipe);
    upipe_voidsrc_init_uclock(upipe);
    upipe_voidsrc_init_upump_mgr(upipe);
    upipe_voidsrc_init_timer(upipe);

    struct upipe_voidsrc *upipe_voidsrc = upipe_voidsrc_from_upipe(upipe);
    upipe_voidsrc->interval = duration;
    upipe_voidsrc->pts = UINT64_MAX;

    upipe_throw_ready(upipe);

    upipe_voidsrc_store_flow_def(upipe, flow);

    return upipe;
}