static void *thread(void *unused)
{
    struct ev_loop *loop = ev_loop_new(0);
    struct upump_mgr *upump_mgr =
        upump_ev_mgr_alloc(loop, UPUMP_POOL, UPUMP_BLOCKER_POOL);
    assert(upump_mgr != NULL);

    struct upipe *upipe;
    upipe = upipe_void_alloc(&uprobe_test_mgr, uprobe_use(uprobe));
    assert(upump_mgr_get_opaque(upump_mgr, struct upipe *) == NULL);
    uprobe_test_free(upipe);

    uprobe_pthread_upump_mgr_set(uprobe, upump_mgr);
    upipe = upipe_void_alloc(&uprobe_test_mgr, uprobe_use(uprobe));
    assert(upump_mgr_get_opaque(upump_mgr, struct upipe *) == upipe);
    uprobe_test_free(upipe);
    upump_mgr_set_opaque(upump_mgr, NULL);

    uprobe_throw(uprobe, NULL, UPROBE_FREEZE_UPUMP_MGR);
    upipe = upipe_void_alloc(&uprobe_test_mgr, uprobe_use(uprobe));
    assert(upump_mgr_get_opaque(upump_mgr, struct upipe *) == NULL);
    uprobe_test_free(upipe);

    uprobe_throw(uprobe, NULL, UPROBE_THAW_UPUMP_MGR);
    upipe = upipe_void_alloc(&uprobe_test_mgr, uprobe_use(uprobe));
    assert(upump_mgr_get_opaque(upump_mgr, struct upipe *) == upipe);
    uprobe_test_free(upipe);

    upump_mgr_release(upump_mgr);
    ev_loop_destroy(loop);
    return NULL;
}
Beispiel #2
0
/** @internal @This catches events of the qsrc of the glx (main) thread.
 *
 * @param uprobe pointer to probe
 * @param upipe pointer to pipe throwing the event
 * @param event event thrown
 * @param args optional event-specific parameters
 * @return an error code
 */
static int upipe_glxplayer_catch_glx_qsrc(struct uprobe *uprobe,
                                          struct upipe *upipe,
                                          int event, va_list args)
{
    switch (event) {
        case UPROBE_SOURCE_END: {
            struct upipe_glxplayer *glxplayer =
                container_of(uprobe, struct upipe_glxplayer,
                             uprobe_glx_qsrc_s);
            upipe_release(upipe);
            pthread_join(glxplayer->src_thread_id, NULL);
            if (glxplayer->trickp)
                upipe_release(glxplayer->upipe_trickp);
            free(glxplayer->uri);
            return UBASE_ERR_NONE;
        }
        case UPROBE_NEED_OUTPUT: {
            struct upipe_glxplayer *glxplayer =
                container_of(uprobe, struct upipe_glxplayer,
                             uprobe_glx_qsrc_s);
            struct upipe *trickp_pic;
            if (glxplayer->trickp) {
                glxplayer->upipe_trickp =
                    upipe_void_alloc(glxplayer->upipe_trickp_mgr,
                         uprobe_pfx_alloc(uprobe_use(glxplayer->uprobe_logger),
                                          glxplayer->loglevel, "trickp"));
                if (unlikely(glxplayer->upipe_trickp == NULL))
                    return UBASE_ERR_ALLOC;
                upipe_attach_uclock(glxplayer->upipe_trickp);
                trickp_pic = upipe_void_alloc_output_sub(upipe,
                        glxplayer->upipe_trickp,
                        uprobe_pfx_alloc(uprobe_use(glxplayer->uprobe_logger),
                                         glxplayer->loglevel, "trickp pic"));
                if (unlikely(trickp_pic == NULL))
                    return UBASE_ERR_ALLOC;
            } else
                trickp_pic = upipe;

            /* glx sink */
            struct upipe *glx_sink = upipe_void_alloc_output(trickp_pic,
                    glxplayer->upipe_glx_mgr,
                    uprobe_gl_sink_cube_alloc(
                         uprobe_pfx_alloc(
                             uprobe_use(&glxplayer->uprobe_glx_s),
                             glxplayer->loglevel, "glx")));
            if (glxplayer->trickp)
                upipe_release(trickp_pic);
            if (unlikely(glx_sink == NULL))
                return UBASE_ERR_ALLOC;
            upipe_glx_sink_init(glx_sink, 0, 0, 800, 480);
            upipe_attach_uclock(glx_sink);
            upipe_release(glx_sink);
            return UBASE_ERR_NONE;
        }
        default:
            return uprobe_throw_next(uprobe, upipe, event, args);
    }
}
Beispiel #3
0
/** @internal @This handles inner reader pipe events.
 *
 * @param uprobe structure used to raise events
 * @param inner pointer to inner pipe
 * @param event event thrown
 * @param args optional arguments
 * @return an error code
 */
static int probe_reader(struct uprobe *uprobe, struct upipe *inner,
                        int event, va_list args)
{
    struct upipe_hls *upipe_hls = upipe_hls_from_probe_reader(uprobe);
    struct upipe *upipe = upipe_hls_to_upipe(upipe_hls);

    if (event >= UPROBE_LOCAL)
        return UBASE_ERR_NONE;

    if (event == UPROBE_NEED_OUTPUT) {
        struct uref *flow_format = va_arg(args, struct uref *);
        const char *def;
        UBASE_RETURN(uref_flow_get_def(flow_format, &def));

        struct uref *flow_format_dup = uref_dup(flow_format);
        if (unlikely(!flow_format_dup)) {
            upipe_throw_fatal(upipe, UBASE_ERR_ALLOC);
            return UBASE_ERR_ALLOC;
        }
        upipe_hls_store_flow_def(upipe, flow_format_dup);

        if (!strcmp(def, "block.m3u.playlist.")) {
            struct upipe_mgr *upipe_null_mgr = upipe_null_mgr_alloc();
            struct upipe *output = upipe_void_alloc_output(
                inner, upipe_null_mgr,
                uprobe_pfx_alloc(uprobe_use(&upipe_hls->probe_null),
                                 UPROBE_LOG_VERBOSE, "null"));
            upipe_mgr_release(upipe_null_mgr);
            upipe_release(output);

            upipe_split_throw_update(upipe);
            return UBASE_ERR_NONE;
        }
        else if (!strcmp(def, "block.m3u.master.")) {
            struct upipe_mgr *upipe_hls_master_mgr =
                upipe_hls_master_mgr_alloc();
            UBASE_ALLOC_RETURN(upipe_hls_master_mgr);
            struct upipe *output = upipe_void_alloc_output(
                inner, upipe_hls_master_mgr,
                uprobe_pfx_alloc(uprobe_use(&upipe_hls->probe_master),
                                 UPROBE_LOG_VERBOSE, "master"));
            upipe_mgr_release(upipe_hls_master_mgr);
            UBASE_ALLOC_RETURN(output);
            upipe_hls_store_bin_output(upipe, output);
            return UBASE_ERR_NONE;
        }
        else
            upipe_warn_va(upipe, "unsupported flow format %s", def);
        return UBASE_ERR_INVALID;
    }

    return upipe_throw_proxy(upipe, inner, event, args);
}
Beispiel #4
0
/** @internal @This catches events of the avcdec.
 *
 * @param uprobe pointer to probe
 * @param upipe pointer to pipe throwing the event
 * @param event event thrown
 * @param args optional event-specific parameters
 * @return an error code
 */
static int upipe_glxplayer_catch_avcdec(struct uprobe *uprobe,
                                        struct upipe *upipe,
                                        int event, va_list args)
{
    switch (event) {
        case UPROBE_NEED_OUTPUT: {
            struct upipe_glxplayer *glxplayer =
                container_of(uprobe, struct upipe_glxplayer, uprobe_avcdec_s);
            struct uref *flow_def = va_arg(args, struct uref *);
            struct upipe *deint =
                upipe_void_alloc_output(upipe,
                        glxplayer->upipe_filter_blend_mgr,
                        uprobe_pfx_alloc(uprobe_use(glxplayer->uprobe_logger),
                                         glxplayer->loglevel, "deint"));
            if (unlikely(deint == NULL))
                return UBASE_ERR_ALLOC;

            struct uref *output_flow = uref_dup(flow_def);
            if (unlikely(output_flow == NULL))
                return UBASE_ERR_ALLOC;
            uref_pic_flow_clear_format(output_flow);
            if (unlikely(!ubase_check(uref_pic_flow_set_macropixel(output_flow, 1)) ||
                         !ubase_check(uref_pic_flow_set_planes(output_flow, 0)) ||
                         !ubase_check(uref_pic_flow_add_plane(output_flow, 1, 1, 3,
                                                  "r8g8b8")))) {
                uref_free(output_flow);
                return UBASE_ERR_ALLOC;
            }

            struct upipe *yuvrgb = upipe_flow_alloc_output(deint,
                    glxplayer->upipe_sws_mgr,
                    uprobe_pfx_alloc_va(uprobe_use(glxplayer->uprobe_logger),
                                        glxplayer->loglevel, "rgb"),
                    output_flow);
            assert(yuvrgb != NULL);
            uref_free(output_flow);
            upipe_release(deint);

            glxplayer->upipe_glx_qsink =
                upipe_qsink_alloc(glxplayer->upipe_qsink_mgr,
                    uprobe_pfx_alloc(uprobe_use(glxplayer->uprobe_logger),
                    glxplayer->loglevel, "glx qsink"),
                    glxplayer->upipe_glx_qsrc);
            if (unlikely(glxplayer->upipe_glx_qsink == NULL))
                return UBASE_ERR_ALLOC;
            upipe_set_output(yuvrgb, glxplayer->upipe_glx_qsink);
            upipe_release(yuvrgb);
            return UBASE_ERR_NONE;
        }
        default:
            return uprobe_throw_next(uprobe, upipe, event, args);
    }
}
Beispiel #5
0
/** @internal @This catches events of the dec queue source.
 *
 * @param uprobe pointer to probe
 * @param upipe pointer to pipe throwing the event
 * @param event event thrown
 * @param args optional event-specific parameters
 * @return an error code
 */
static int upipe_glxplayer_catch_dec_qsrc(struct uprobe *uprobe,
                                          struct upipe *upipe,
                                          int event, va_list args)
{
    switch (event) {
        case UPROBE_SOURCE_END: {
            struct upipe_glxplayer *glxplayer =
                container_of(uprobe, struct upipe_glxplayer, uprobe_dec_qsrc_s);
            upipe_flush(glxplayer->upipe_glx_qsink);
            upipe_release(glxplayer->upipe_glx_qsink);
            return UBASE_ERR_NONE;
        }
        case UPROBE_NEED_OUTPUT: {
            struct upipe_glxplayer *glxplayer =
                container_of(uprobe, struct upipe_glxplayer, uprobe_dec_qsrc_s);
            struct upipe *avcdec = upipe_void_alloc_output(upipe,
                    glxplayer->upipe_avcdec_mgr,
                    uprobe_pfx_alloc_va(
                            uprobe_use(&glxplayer->uprobe_avcdec_s),
                        glxplayer->loglevel, "avcdec"));
            if (unlikely(avcdec == NULL))
                return UBASE_ERR_ALLOC;
            upipe_set_option(avcdec, "threads", "2");
            upipe_release(avcdec);
            return UBASE_ERR_NONE;
        }
        default:
            return uprobe_throw_next(uprobe, upipe, event, args);
    }
}
Beispiel #6
0
/** @internal @This allocates a hls pipe.
 *
 * @param mgr management structure for this pipe type
 * @param uprobe structure used to raise events
 * @param signature signature of the pipe allocator
 * @param args optional arguments
 * @return pointer to allocated pipe, or NULL in case of failure
 */
static struct upipe *upipe_hls_alloc(struct upipe_mgr *mgr,
                                     struct uprobe *uprobe,
                                     uint32_t signature,
                                     va_list args)
{
    struct upipe *upipe =
        upipe_hls_alloc_void(mgr, uprobe, signature, args);
    if (unlikely(upipe == NULL))
        return NULL;

    struct upipe_hls *upipe_hls = upipe_hls_from_upipe(upipe);

    upipe_hls_init_urefcount(upipe);
    upipe_hls_init_urefcount_real(upipe);
    upipe_hls_init_probe_reader(upipe);
    upipe_hls_init_probe_master(upipe);
    upipe_hls_init_probe_null(upipe);
    upipe_hls_init_first_inner(upipe);
    upipe_hls_init_last_inner(upipe);
    upipe_hls_init_bin_input(upipe);
    upipe_hls_init_bin_output(upipe);
    upipe_hls->flow_def = NULL;
    upipe_hls->item = NULL;
    upipe_hls->sub_pipe_mgr = NULL;

    upipe_throw_ready(upipe);

    struct upipe *inner = NULL;
    struct upipe_mgr *upipe_m3u_reader_mgr = upipe_m3u_reader_mgr_alloc();
    if (unlikely(!upipe_m3u_reader_mgr)) {
        upipe_err(upipe, "fail to allocate m3u reader manager");
        upipe_release(upipe);
        return NULL;
    }

    inner = upipe_void_alloc(
        upipe_m3u_reader_mgr,
        uprobe_pfx_alloc(uprobe_use(&upipe_hls->probe_reader),
                         UPROBE_LOG_VERBOSE, "reader"));
    upipe_mgr_release(upipe_m3u_reader_mgr);
    if (unlikely(!inner)) {
        upipe_err(upipe, "fail to allocate m3u reader");
        upipe_release(upipe);
        return NULL;
    }
    upipe_hls_store_bin_input(upipe, inner);

    return upipe;
}
Beispiel #7
0
/** @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;
}
Beispiel #8
0
/** split callback */
static int split_catch(struct uprobe *uprobe, struct upipe *upipe,
                       int event, va_list args)
{
    if (event != UPROBE_NEED_OUTPUT)
        return uprobe_throw_next(uprobe, upipe, event, args);

    upipe_release(upipe_split_output);
    upipe_split_output = upipe_use(upipe);

    struct upipe *avcdec = upipe_void_alloc_output(upipe, upipe_avcdec_mgr,
            uprobe_pfx_alloc_va(uprobe_use(&uprobe_avcdec),
                                loglevel, "avcdec"));
    if (avcdec == NULL) {
        upipe_err_va(upipe, "incompatible flow def");
        upipe_release(upipe_source);
        return UBASE_ERR_UNHANDLED;
    }
    upipe_release(avcdec);
    return UBASE_ERR_NONE;
}
Beispiel #9
0
/** @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;
}
Beispiel #10
0
/** @internal @This allocates a blank source 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_blksrc_alloc(struct upipe_mgr *mgr,
                                        struct uprobe *uprobe,
                                        uint32_t signature, va_list args)
{
    struct uref *flow_def;
    struct upipe *upipe = upipe_blksrc_alloc_flow(mgr, uprobe, signature, args,
                                                  &flow_def);
    if (unlikely(!upipe)) {
        return NULL;
    }

    struct upipe_blksrc *upipe_blksrc = upipe_blksrc_from_upipe(upipe);
    upipe_blksrc_init_urefcount(upipe);
    upipe_blksrc_init_urefcount_real(upipe);
    upipe_blksrc_init_src_probe(upipe);
    upipe_blksrc_init_blk_probe(upipe);
    upipe_blksrc_init_bin_input(upipe);
    upipe_blksrc_init_bin_output(upipe);
    upipe_blksrc->flow_def = flow_def;

    upipe_throw_ready(upipe);

    uint64_t duration = 0;
    if (ubase_check(uref_flow_match_def(flow_def, UREF_PIC_FLOW_DEF))) {
        struct urational fps;
        if (unlikely(!ubase_check(uref_pic_flow_get_fps(flow_def, &fps)))) {
            upipe_release(upipe);
            return NULL;
        }
        duration = (uint64_t)UCLOCK_FREQ * fps.den / fps.num;
    }
    else if (ubase_check(uref_flow_match_def(flow_def, UREF_SOUND_FLOW_DEF))) {
        uint64_t samples, rate;
        if (unlikely(!ubase_check(uref_sound_flow_get_samples(flow_def,
                                                              &samples))) ||
            unlikely(!ubase_check(uref_sound_flow_get_rate(flow_def,
                                                           &rate)))) {
            upipe_release(upipe);
            return NULL;
        }
        duration = samples * UCLOCK_FREQ / rate;
    }
    else {
        upipe_warn(upipe, "unsupported flow def");
        upipe_release(upipe);
        return NULL;
    }

    struct uref *src_flow_def = uref_void_flow_alloc_def(flow_def->mgr);
    if (unlikely(!src_flow_def)) {
        upipe_err(upipe, "fail to allocate source pipe flow def");
        upipe_release(upipe);
        return NULL;
    }

    if (unlikely(!ubase_check(uref_clock_set_duration(src_flow_def,
                                                      duration)))) {
        uref_free(src_flow_def);
        upipe_release(upipe);
        return NULL;
    }

    struct upipe_mgr *upipe_voidsrc_mgr = upipe_voidsrc_mgr_alloc();
    if (unlikely(!upipe_voidsrc_mgr)) {
        upipe_err(upipe, "fail to get void source manager");
        uref_free(src_flow_def);
        upipe_release(upipe);
        return NULL;
    }

    struct upipe *src =
        upipe_flow_alloc(upipe_voidsrc_mgr,
                         uprobe_pfx_alloc(
                            uprobe_use(&upipe_blksrc->src_probe),
                                       UPROBE_LOG_VERBOSE,
                                       "src"),
                         src_flow_def);
    upipe_mgr_release(upipe_voidsrc_mgr);
    uref_free(src_flow_def);
    if (unlikely(!src)) {
        upipe_err(upipe, "fail to allocate source pipe");
        upipe_release(upipe);
        return NULL;
    }

    upipe_blksrc_store_bin_input(upipe, src);

    struct upipe_mgr *upipe_blk_mgr = NULL;
    if (ubase_check(uref_flow_match_def(flow_def, UREF_PIC_FLOW_DEF))) {
        upipe_blk_mgr = upipe_vblk_mgr_alloc();
    }
    else if (ubase_check(uref_flow_match_def(flow_def, UREF_SOUND_FLOW_DEF))) {
        upipe_blk_mgr = upipe_ablk_mgr_alloc();
    }

    if (unlikely(!upipe_blk_mgr)) {
        upipe_err(upipe, "fail to get blank generator manager");
        upipe_release(upipe);
        return NULL;
    }

    struct upipe *blk =
        upipe_flow_alloc(upipe_blk_mgr,
                         uprobe_pfx_alloc(
                            uprobe_use(&upipe_blksrc->blk_probe),
                                       UPROBE_LOG_VERBOSE,
                                       "blk"),
                         flow_def);
    upipe_mgr_release(upipe_blk_mgr);
    if (unlikely(!blk)) {
        upipe_err(upipe, "fail to allocate blank generator pipe");
        upipe_release(upipe);
        return NULL;
    }

    upipe_blksrc_store_bin_output(upipe, blk);

    if (unlikely(!ubase_check(upipe_set_output(src, blk)))) {
        upipe_release(upipe);
        return NULL;
    }

    return upipe;
}
Beispiel #11
0
int main(int argc, char **argv)
{
    int opt;

    /* parse options */
    while ((opt = getopt(argc, argv, "dqD:")) != -1) {
        switch (opt) {
            case 'd':
                if (loglevel > 0) loglevel--;
                break;
            case 'q':
                if (loglevel < UPROBE_LOG_ERROR) loglevel++;
                break;
            case 'D':
                dump = optarg;
                break;
            default:
                usage(argv[0]);
        }
    }
    if (optind >= argc - 1) {
        usage(argv[0]);
    }
    srcpath = argv[optind++];
    dstpath = argv[optind++];

    /* choose log fd */
    logstream = stderr;

    /* setup environnement */
    struct umem_mgr *umem_mgr = umem_alloc_mgr_alloc();
    struct udict_mgr *udict_mgr = udict_inline_mgr_alloc(UDICT_POOL_DEPTH,
                                                         umem_mgr, -1, -1);
    uref_mgr = uref_std_mgr_alloc(UREF_POOL_DEPTH, udict_mgr,
                                                   0);

    struct upump_mgr *upump_mgr = upump_ev_mgr_alloc_default(UPUMP_POOL,
            UPUMP_BLOCKER_POOL);

    /* default probe */
    logger = uprobe_stdio_alloc(NULL, logstream, loglevel);
    assert(logger != NULL);
    logger = uprobe_uref_mgr_alloc(logger, uref_mgr);
    assert(logger != NULL);
    logger = uprobe_upump_mgr_alloc(logger, upump_mgr);
    assert(logger != NULL);
    logger = uprobe_ubuf_mem_alloc(logger, umem_mgr, UBUF_POOL_DEPTH,
                                   UBUF_POOL_DEPTH);
    assert(logger != NULL);
    uref_mgr_release(uref_mgr);
    upump_mgr_release(upump_mgr);

    /* split probe */
    struct uprobe uprobe_catch;
    uprobe_init(&uprobe_catch, split_catch, uprobe_use(logger));

    /* other probes */
    uprobe_init(&uprobe_avcdec, avcdec_catch, uprobe_use(logger));
    uprobe_init(&uprobe_uref, uref_catch, uprobe_use(logger));

    /* upipe-av */
    upipe_av_init(true, uprobe_use(logger));

    /* global pipe managers */
    upipe_avcdec_mgr = upipe_avcdec_mgr_alloc();
    upipe_avcenc_mgr = upipe_avcenc_mgr_alloc();
    upipe_sws_mgr = upipe_sws_mgr_alloc();
    upipe_filter_blend_mgr = upipe_filter_blend_mgr_alloc();
    upipe_fsink_mgr = upipe_fsink_mgr_alloc();
    upipe_probe_uref_mgr = upipe_probe_uref_mgr_alloc();

    /* null */
    struct upipe_mgr *upipe_null_mgr = upipe_null_mgr_alloc();
    upipe_null = upipe_void_alloc(upipe_null_mgr,
            uprobe_pfx_alloc(uprobe_use(logger), loglevel, "null"));
    assert(upipe_null != NULL);
    upipe_mgr_release(upipe_null_mgr);

    /* file source */
    struct upipe_mgr *upipe_fsrc_mgr = upipe_fsrc_mgr_alloc();
    upipe_source = upipe_void_alloc(upipe_fsrc_mgr,
            uprobe_pfx_alloc(uprobe_use(logger), loglevel, "fsrc"));
    assert(upipe_source != NULL);
    upipe_mgr_release(upipe_fsrc_mgr);
    if (!ubase_check(upipe_set_uri(upipe_source, srcpath)))
        exit(EXIT_FAILURE);

    /* upipe-ts */
    struct upipe_mgr *upipe_ts_demux_mgr = upipe_ts_demux_mgr_alloc();
    struct upipe_mgr *upipe_autof_mgr = upipe_autof_mgr_alloc();
    upipe_ts_demux_mgr_set_autof_mgr(upipe_ts_demux_mgr, upipe_autof_mgr);
    upipe_mgr_release(upipe_autof_mgr);
    struct upipe *ts_demux = upipe_void_alloc_output(upipe_source,
            upipe_ts_demux_mgr,
            uprobe_pfx_alloc(
                uprobe_selflow_alloc(uprobe_use(logger),
                    uprobe_selflow_alloc(uprobe_use(logger), &uprobe_catch,
                        UPROBE_SELFLOW_PIC, "auto"),
                    UPROBE_SELFLOW_VOID, "auto"),
                 loglevel, "tsdemux"));
    assert(ts_demux != NULL);
    upipe_mgr_release(upipe_ts_demux_mgr);
    upipe_release(ts_demux);

    /* fire loop ! */
    upump_mgr_run(upump_mgr, NULL);

    /* release everyhing */
    upipe_release(upipe_source);
    upipe_release(upipe_split_output);
    upipe_release(upipe_null);
    uprobe_release(logger);
    uprobe_clean(&uprobe_catch);
    uprobe_clean(&uprobe_avcdec);
    uprobe_clean(&uprobe_uref);

    upipe_mgr_release(upipe_avcdec_mgr);
    upipe_mgr_release(upipe_avcenc_mgr);
    upipe_mgr_release(upipe_sws_mgr);
    upipe_mgr_release(upipe_filter_blend_mgr);
    upipe_mgr_release(upipe_fsink_mgr);
    upipe_mgr_release(upipe_probe_uref_mgr);

    udict_mgr_release(udict_mgr);
    umem_mgr_release(umem_mgr);

    upipe_av_clean();

    return 0;
}
Beispiel #12
0
/** avcdec callback */
static int avcdec_catch(struct uprobe *uprobe, struct upipe *upipe,
                        int event, va_list args)
{
    if (event != UPROBE_NEED_OUTPUT)
        return uprobe_throw_next(uprobe, upipe, event, args);

    struct uref *flow_def = va_arg(args, struct uref *);

    uint64_t hsize, vsize, wanted_hsize;
    struct urational sar;
    bool progressive;
    if (unlikely(!ubase_check(uref_pic_flow_get_hsize(flow_def, &hsize)) ||
                 !ubase_check(uref_pic_flow_get_vsize(flow_def, &vsize)) ||
                 !ubase_check(uref_pic_flow_get_sar(flow_def, &sar)))) {
        upipe_err_va(upipe, "incompatible flow def");
        upipe_release(upipe_source);
        return UBASE_ERR_UNHANDLED;
    }
    wanted_hsize = (hsize * sar.num / sar.den / 2) * 2;
    progressive = ubase_check(uref_pic_get_progressive(flow_def));

    struct uref *flow_def2 = uref_dup(flow_def);
    upipe_use(upipe);

    if (!progressive) {
        uref_pic_set_progressive(flow_def2);
        struct upipe *deint = upipe_void_alloc_output(upipe,
                upipe_filter_blend_mgr,
                uprobe_pfx_alloc(uprobe_use(logger),
                                 loglevel, "deint"));
        assert(deint != NULL);
        upipe_release(upipe);
        upipe = deint;
    }

    if (wanted_hsize != hsize) {
        uref_pic_flow_set_hsize(flow_def2, wanted_hsize);
        struct upipe *sws = upipe_flow_alloc_output(upipe, upipe_sws_mgr,
                uprobe_pfx_alloc_va(uprobe_use(logger),
                                    loglevel, "sws"), flow_def2);
        assert(sws != NULL);
        upipe_release(upipe);
        upipe = sws;
    }

    uref_pic_flow_clear_format(flow_def2);
    uref_flow_set_def(flow_def2, "block.mjpeg.pic.");
    struct upipe *jpegenc = upipe_flow_alloc_output(upipe, upipe_avcenc_mgr,
            uprobe_pfx_alloc_va(uprobe_use(logger),
                                loglevel, "jpeg"), flow_def2);
    assert(jpegenc != NULL);
    upipe_release(upipe);
    upipe_set_option(jpegenc, "qmax", "2");
    upipe = jpegenc;

    struct upipe *urefprobe = upipe_void_alloc_output(upipe,
            upipe_probe_uref_mgr,
            uprobe_pfx_alloc_va(uprobe_use(&uprobe_uref),
                                loglevel, "urefprobe"));
    assert(urefprobe != NULL);
    upipe_release(upipe);
    upipe = urefprobe;

    struct upipe *fsink = upipe_void_alloc_output(upipe, upipe_fsink_mgr,
            uprobe_pfx_alloc_va(uprobe_use(logger),
            ((loglevel > UPROBE_LOG_DEBUG) ? UPROBE_LOG_WARNING : loglevel),
            "jpegsink"));
    assert(fsink != NULL);
    upipe_release(upipe);
    upipe_fsink_set_path(fsink, dstpath, UPIPE_FSINK_OVERWRITE);
    upipe = fsink;

    uref_free(flow_def2);
    upipe_release(upipe);
    return UBASE_ERR_NONE;
}
Beispiel #13
0
/** @This starts playing the given URI.
 *
 * @param glxplayer glxplayer context
 * @param upump_mgr upump manager of the main thread
 * @param uri URI to play
 * @param upipe_ts set to true to use Upipe's TS demux, false for libavformat
 * @return false in case of error
 */
static bool upipe_glxplayer_play(struct upipe_glxplayer *glxplayer,
                                 struct upump_mgr *upump_mgr, const char *uri,
                                 bool upipe_ts)
{
    struct upipe *upipe_src;
    uprobe_pthread_upump_mgr_set(glxplayer->uprobe_logger, upump_mgr);
    uprobe_throw(glxplayer->uprobe_logger, NULL, UPROBE_FREEZE_UPUMP_MGR);
    if (!upipe_ts) {
        /* use avformat source (and internal demuxer) */
        struct upipe_mgr *upipe_avfsrc_mgr = upipe_avfsrc_mgr_alloc();
        if (unlikely(upipe_avfsrc_mgr == NULL))
            return false;

        upipe_src = upipe_void_alloc(upipe_avfsrc_mgr,
                    uprobe_pfx_alloc(uprobe_use(glxplayer->uprobe_selflow),
                                     glxplayer->loglevel, "avfsrc"));
        upipe_mgr_release(upipe_avfsrc_mgr);
        if (unlikely(upipe_src == NULL))
            return false;
        if (unlikely(!ubase_check(upipe_attach_uclock(upipe_src)) ||
                     !ubase_check(upipe_set_uri(upipe_src, uri)))) {
            upipe_release(upipe_src);
            return false;
        }
        glxplayer->trickp = true;
    } else {
        /* try file source */
        struct upipe_mgr *upipe_fsrc_mgr = upipe_fsrc_mgr_alloc();
        if (unlikely(upipe_fsrc_mgr == NULL))
            return false;

        upipe_src = upipe_void_alloc(upipe_fsrc_mgr,
                    uprobe_pfx_alloc(uprobe_use(&glxplayer->uprobe_source_s),
                                     glxplayer->loglevel, "fsrc"));
        upipe_mgr_release(upipe_fsrc_mgr);
        if (unlikely(upipe_src == NULL))
            return false;
        if (ubase_check(upipe_set_uri(upipe_src, uri))) {
            glxplayer->trickp = true;
        } else {
            upipe_release(upipe_src);
            glxplayer->trickp = false;

            /* try udp source */
            struct upipe_mgr *upipe_udpsrc_mgr = upipe_udpsrc_mgr_alloc();
            if (unlikely(upipe_udpsrc_mgr == NULL))
                return false;

            upipe_src = upipe_void_alloc(upipe_udpsrc_mgr,
                    uprobe_pfx_alloc(uprobe_use(&glxplayer->uprobe_source_s),
                                     glxplayer->loglevel, "udpsrc"));
            upipe_mgr_release(upipe_udpsrc_mgr);
            if (unlikely(upipe_src == NULL))
                return false;
            if (ubase_check(upipe_set_uri(upipe_src, uri))) {
                upipe_attach_uclock(upipe_src);
            } else {
                upipe_release(upipe_src);

                /* try http source */
                struct upipe_mgr *upipe_http_src_mgr =
                    upipe_http_src_mgr_alloc();
                if (unlikely(upipe_http_src_mgr == NULL))
                    return false;

                upipe_src = upipe_void_alloc(upipe_http_src_mgr,
                    uprobe_pfx_alloc(uprobe_use(&glxplayer->uprobe_source_s),
                                     glxplayer->loglevel, "httpsrc"));
                upipe_mgr_release(upipe_http_src_mgr);
                if (unlikely(upipe_src == NULL))
                    return false;
                if (!ubase_check(upipe_set_uri(upipe_src, uri))) {
                    upipe_release(upipe_src);
                    return false;
                }
            }
        }

        /* upipe-ts demuxer */
        struct upipe_mgr *upipe_ts_demux_mgr = upipe_ts_demux_mgr_alloc();
        if (unlikely(upipe_ts_demux_mgr == NULL)) {
            upipe_release(upipe_src);
            return false;
        }
        struct upipe_mgr *upipe_mpgvf_mgr = upipe_mpgvf_mgr_alloc();
        if (upipe_mpgvf_mgr != NULL) {
            upipe_ts_demux_mgr_set_mpgvf_mgr(upipe_ts_demux_mgr,
                                             upipe_mpgvf_mgr);
            upipe_mgr_release(upipe_mpgvf_mgr);
        }
        struct upipe_mgr *upipe_h264f_mgr = upipe_h264f_mgr_alloc();
        if (upipe_h264f_mgr != NULL) {
            upipe_ts_demux_mgr_set_h264f_mgr(upipe_ts_demux_mgr,
                                             upipe_h264f_mgr);
            upipe_mgr_release(upipe_h264f_mgr);
        }

        struct upipe *upipe_ts_demux =
            upipe_void_alloc_output(upipe_src, upipe_ts_demux_mgr,
                uprobe_pfx_alloc(uprobe_use(glxplayer->uprobe_selprog),
                                 glxplayer->loglevel, "ts demux"));
        if (unlikely(upipe_ts_demux == NULL)) {
            upipe_mgr_release(upipe_ts_demux_mgr);
            upipe_release(upipe_src);
            return false;
        }
        upipe_release(upipe_ts_demux);
        upipe_mgr_release(upipe_ts_demux_mgr);
    }

    if (!glxplayer->trickp)
        uprobe_dejitter_set(glxplayer->uprobe_dejitter, true, 0);

    /* prepare a queue source for the decoded video frames */
    uprobe_throw(glxplayer->uprobe_logger, NULL, UPROBE_THAW_UPUMP_MGR);
    glxplayer->upipe_glx_qsrc = upipe_qsrc_alloc(glxplayer->upipe_qsrc_mgr,
            uprobe_pfx_alloc(
                    uprobe_use(&glxplayer->uprobe_glx_qsrc_s),
                glxplayer->loglevel, "glx qsrc"), GLX_QUEUE_LENGTH);
    if (unlikely(glxplayer->upipe_glx_qsrc == NULL)) {
        upipe_release(upipe_src);
        return false;
    }
    upipe_attach_upump_mgr(glxplayer->upipe_glx_qsrc);

    /* prepare to transfer the source to a new thread */
    glxplayer->src_xfer = upipe_xfer_mgr_alloc(XFER_QUEUE, XFER_POOL);
    if (unlikely(glxplayer->src_xfer == NULL)) {
        upipe_release(upipe_src);
        upipe_release(glxplayer->upipe_glx_qsrc);
        return false;
    }

    /* spawn a thread for the source */
    if (pthread_create(&glxplayer->src_thread_id, NULL,
                       upipe_glxplayer_source_thread, glxplayer)) {
        upipe_mgr_release(glxplayer->src_xfer);
        upipe_release(glxplayer->upipe_glx_qsrc);
        return false;
    }

    glxplayer->upipe_src_xfer = upipe_xfer_alloc(glxplayer->src_xfer,
                uprobe_pfx_alloc(uprobe_use(glxplayer->uprobe_logger),
                                 glxplayer->loglevel, "source xfer"),
                upipe_src);
    if (unlikely(glxplayer->upipe_src_xfer == NULL)) {
        upipe_mgr_release(glxplayer->src_xfer);
        upipe_release(upipe_src);
        upipe_release(glxplayer->upipe_glx_qsrc);
        return false;
    }
    /* from now on upipe_src should not be accessed */
    upipe_attach_upump_mgr(glxplayer->upipe_src_xfer);

    glxplayer->upipe_ts = upipe_ts;
    glxplayer->uri = strdup(uri);
    return true;
}
Beispiel #14
0
/** @This allocates and initializes a glxplayer context.
 *
 * @param loglevel minimum log level to print
 * @return pointer to glxplayer context, or NULL in case of error
 */
static struct upipe_glxplayer *upipe_glxplayer_alloc(enum uprobe_log_level loglevel)
{
    struct upipe_glxplayer *glxplayer = malloc(sizeof(struct upipe_glxplayer));
    if (unlikely(glxplayer == NULL))
        return NULL;
    glxplayer->loglevel = loglevel;
    glxplayer->uri = NULL;
    glxplayer->upipe_ts = false;
    glxplayer->paused = false;

    struct umem_mgr *umem_mgr = umem_pool_mgr_alloc_simple(UMEM_POOL);
    if (unlikely(umem_mgr == NULL))
        goto fail_umem_mgr;

    struct udict_mgr *udict_mgr = udict_inline_mgr_alloc(UDICT_POOL_DEPTH,
                                                         umem_mgr, -1, -1);
    if (unlikely(udict_mgr == NULL))
        goto fail_udict_mgr;

    struct uref_mgr *uref_mgr = uref_std_mgr_alloc(UREF_POOL_DEPTH, udict_mgr,
                                                   0);
    if (unlikely(uref_mgr == NULL))
        goto fail_uref_mgr;

    struct uclock *uclock = uclock_std_alloc(0);
    if (unlikely(uclock == NULL))
        goto fail_probe_logger;

    /* probes common to all threads */
    glxplayer->uprobe_logger =
        uprobe_pthread_upump_mgr_alloc(
            uprobe_ubuf_mem_alloc(
                uprobe_uclock_alloc(
                    uprobe_uref_mgr_alloc(
                         uprobe_stdio_alloc(NULL, stderr, glxplayer->loglevel),
                         uref_mgr), uclock),
                umem_mgr, UBUF_POOL_DEPTH, UBUF_SHARED_POOL_DEPTH));
    uclock_release(uclock);
    if (unlikely(glxplayer->uprobe_logger == NULL))
        goto fail_probe_logger;

    /* upipe-av */
    if (unlikely(!upipe_av_init(false, uprobe_use(glxplayer->uprobe_logger))))
        goto fail_av;

    /* pipes managers */
    glxplayer->upipe_filter_blend_mgr = upipe_filter_blend_mgr_alloc();
    glxplayer->upipe_sws_mgr = upipe_sws_mgr_alloc();
    glxplayer->upipe_qsink_mgr = upipe_qsink_mgr_alloc();
    glxplayer->upipe_qsrc_mgr = upipe_qsrc_mgr_alloc();
    glxplayer->upipe_glx_mgr = upipe_glx_sink_mgr_alloc();
    glxplayer->upipe_trickp_mgr = upipe_trickp_mgr_alloc();
    glxplayer->upipe_avcdec_mgr = upipe_avcdec_mgr_alloc();
    glxplayer->upipe_null_mgr = upipe_null_mgr_alloc();
    if (unlikely(glxplayer->upipe_filter_blend_mgr == NULL ||
                 glxplayer->upipe_sws_mgr == NULL ||
                 glxplayer->upipe_qsink_mgr == NULL ||
                 glxplayer->upipe_qsrc_mgr == NULL ||
                 glxplayer->upipe_glx_mgr == NULL ||
                 glxplayer->upipe_trickp_mgr == NULL ||
                 glxplayer->upipe_avcdec_mgr == NULL ||
                 glxplayer->upipe_null_mgr == NULL))
        goto fail_pipe_mgrs;

    /* probe specific to the source pipe */
    uprobe_init(&glxplayer->uprobe_source_s, upipe_glxplayer_catch_source,
                uprobe_use(glxplayer->uprobe_logger));

    /* probes specific to the demux pipe */
    glxplayer->uprobe_dejitter =
        uprobe_dejitter_alloc(uprobe_use(glxplayer->uprobe_logger), false, 0);
    if (unlikely(glxplayer->uprobe_dejitter == NULL))
        goto fail_dejitter;

    uprobe_init(&glxplayer->uprobe_demux_output_s,
                upipe_glxplayer_catch_demux_output,
                uprobe_use(glxplayer->uprobe_dejitter));

    glxplayer->uprobe_selflow =
        uprobe_selflow_alloc(uprobe_use(glxplayer->uprobe_dejitter),
                             uprobe_use(&glxplayer->uprobe_demux_output_s),
                             UPROBE_SELFLOW_PIC, "auto");
    if (unlikely(glxplayer->uprobe_selflow == NULL))
        goto fail_selflow;
    glxplayer->uprobe_selprog =
        uprobe_selflow_alloc(uprobe_use(glxplayer->uprobe_logger),
                             uprobe_use(glxplayer->uprobe_selflow),
                             UPROBE_SELFLOW_VOID, "auto");
    if (unlikely(glxplayer->uprobe_selprog == NULL))
        goto fail_selprog;

    /* probe specific to the dec queue source */
    uprobe_init(&glxplayer->uprobe_dec_qsrc_s,
                upipe_glxplayer_catch_dec_qsrc,
                uprobe_use(glxplayer->uprobe_logger));

    /* probe specific to the avcdec */
    uprobe_init(&glxplayer->uprobe_avcdec_s,
                upipe_glxplayer_catch_avcdec,
                uprobe_use(glxplayer->uprobe_logger));

    /* probe specific to the glx queue source */
    uprobe_init(&glxplayer->uprobe_glx_qsrc_s,
                upipe_glxplayer_catch_glx_qsrc,
                uprobe_use(glxplayer->uprobe_logger));

    /* probe specific to the glx pipe */
    uprobe_init(&glxplayer->uprobe_glx_s,
                upipe_glxplayer_catch_glx,
                uprobe_use(glxplayer->uprobe_logger));

    uref_mgr_release(uref_mgr);
    umem_mgr_release(umem_mgr);
    udict_mgr_release(udict_mgr);
    return glxplayer;

fail_selprog:
    uprobe_release(glxplayer->uprobe_selflow);
fail_selflow:
    uprobe_clean(&glxplayer->uprobe_demux_output_s);
    uprobe_release(glxplayer->uprobe_dejitter);
fail_dejitter:
    uprobe_clean(&glxplayer->uprobe_source_s);
fail_pipe_mgrs:
    if (glxplayer->upipe_filter_blend_mgr != NULL)
        upipe_mgr_release(glxplayer->upipe_filter_blend_mgr);
    if (glxplayer->upipe_sws_mgr != NULL)
        upipe_mgr_release(glxplayer->upipe_sws_mgr);
    if (glxplayer->upipe_qsink_mgr != NULL)
        upipe_mgr_release(glxplayer->upipe_qsink_mgr);
    if (glxplayer->upipe_qsrc_mgr != NULL)
        upipe_mgr_release(glxplayer->upipe_qsrc_mgr);
    if (glxplayer->upipe_glx_mgr != NULL)
        upipe_mgr_release(glxplayer->upipe_glx_mgr);
    if (glxplayer->upipe_trickp_mgr != NULL)
        upipe_mgr_release(glxplayer->upipe_trickp_mgr);
    if (glxplayer->upipe_avcdec_mgr != NULL)
        upipe_mgr_release(glxplayer->upipe_avcdec_mgr);
    if (glxplayer->upipe_null_mgr != NULL)
        upipe_mgr_release(glxplayer->upipe_null_mgr);
    upipe_av_clean();
fail_av:
    uprobe_release(glxplayer->uprobe_logger);
fail_probe_logger:
    uref_mgr_release(uref_mgr);
fail_uref_mgr:
    udict_mgr_release(udict_mgr);
fail_udict_mgr:
    umem_mgr_release(umem_mgr);
fail_umem_mgr:
    free(glxplayer);
    return NULL;
}
Beispiel #15
0
/** @internal @This catches events of the video output of the demux.
 *
 * @param uprobe pointer to probe
 * @param upipe pointer to pipe throwing the event
 * @param event event thrown
 * @param args optional event-specific parameters
 * @return an error code
 */
static int upipe_glxplayer_catch_demux_output(struct uprobe *uprobe,
                                              struct upipe *upipe,
                                              int event, va_list args)
{
    struct upipe_glxplayer *glxplayer =
        container_of(uprobe, struct upipe_glxplayer, uprobe_demux_output_s);
    switch (event) {
        case UPROBE_NEED_OUTPUT: {
            struct uref *flow_def = va_arg(args, struct uref *);
            const char *def = "(none)";
            if (!ubase_check(uref_flow_get_def(flow_def, &def)) ||
                ubase_ncmp(def, "block.")) {
                upipe_warn_va(upipe, "flow def %s is not supported", def);
                return UBASE_ERR_UNHANDLED;
            }

            upipe_dbg_va(upipe, "add flow %s", def);

            /* prepare a queue to deport avcodec to a new thread */
            uprobe_throw(glxplayer->uprobe_logger, NULL, UPROBE_FREEZE_UPUMP_MGR);
            struct upipe *upipe_dec_qsrc =
                upipe_qsrc_alloc(glxplayer->upipe_qsrc_mgr,
                    uprobe_pfx_alloc_va(uprobe_use(&glxplayer->uprobe_dec_qsrc_s),
                                              glxplayer->loglevel, "dec qsrc"),
                    DEC_QUEUE_LENGTH);
            if (unlikely(upipe_dec_qsrc == NULL)) {
                return UBASE_ERR_ALLOC;
            }
            uprobe_throw(glxplayer->uprobe_logger, NULL, UPROBE_THAW_UPUMP_MGR);

            glxplayer->upipe_dec_qsink =
                upipe_qsink_alloc(glxplayer->upipe_qsink_mgr,
                    uprobe_pfx_alloc_va(
                            uprobe_use(glxplayer->uprobe_logger),
                            glxplayer->loglevel, "dec qsink"),
                    upipe_dec_qsrc);
            if (unlikely(glxplayer->upipe_dec_qsink == NULL)) {
                upipe_release(upipe_dec_qsrc);
                return UBASE_ERR_ALLOC;
            }
            upipe_set_output(upipe, glxplayer->upipe_dec_qsink);

            /* prepare to transfer the queue source */
            glxplayer->dec_xfer = upipe_xfer_mgr_alloc(XFER_QUEUE, XFER_POOL);
            if (unlikely(glxplayer->dec_xfer == NULL)) {
                upipe_release(upipe_dec_qsrc);
                return UBASE_ERR_ALLOC;
            }

            /* spawn a thread for the decoder */
            if (pthread_create(&glxplayer->dec_thread_id, NULL,
                               upipe_glxplayer_dec_thread, glxplayer)) {
                upipe_mgr_release(glxplayer->dec_xfer);
                upipe_release(upipe_dec_qsrc);
                return UBASE_ERR_ALLOC;
            }

            glxplayer->upipe_dec_qsrc_handle =
                upipe_xfer_alloc(glxplayer->dec_xfer,
                    uprobe_pfx_alloc(uprobe_use(glxplayer->uprobe_logger),
                                     glxplayer->loglevel, "dec qsrc xfer"),
                    upipe_dec_qsrc);
            if (unlikely(glxplayer->upipe_dec_qsrc_handle == NULL)) {
                upipe_mgr_release(glxplayer->dec_xfer);
                upipe_release(upipe_dec_qsrc);
                return UBASE_ERR_ALLOC;
            }
            upipe_attach_upump_mgr(glxplayer->upipe_dec_qsrc_handle);
            upipe_set_output(glxplayer->upipe_dec_qsink, glxplayer->upipe_dec_qsrc_handle);
            return UBASE_ERR_NONE;
        }
        case UPROBE_SOURCE_END: {
            upipe_flush(glxplayer->upipe_dec_qsink);
            upipe_release(glxplayer->upipe_dec_qsink);
            glxplayer->upipe_dec_qsink = NULL;

            /* set dec_qsrc output to null */
            struct upipe *null = upipe_void_alloc(glxplayer->upipe_null_mgr,
                    uprobe_pfx_alloc(uprobe_use(glxplayer->uprobe_logger),
                                     glxplayer->loglevel, "dec qsrc null"));
            if (likely(null != NULL)) {
                upipe_set_output(glxplayer->upipe_dec_qsrc_handle, null);
                upipe_release(null);
            }
            upipe_release(glxplayer->upipe_dec_qsrc_handle);
            return UBASE_ERR_NONE;
        }
        default:
            return uprobe_throw_next(uprobe, upipe, event, args);
    }
}
Beispiel #16
0
/** @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;
}
Beispiel #17
0
int main(int argc, char *argv[])
{
    assert(argc >= 2);
    nb_files = argc - 1;
    files = argv + 1;

    struct upump_mgr *upump_mgr = upump_ev_mgr_alloc_default(UPUMP_POOL,
            UPUMP_BLOCKER_POOL);
    assert(upump_mgr != NULL);

    struct umem_mgr *umem_mgr = umem_alloc_mgr_alloc();
    assert(umem_mgr != NULL);
    struct udict_mgr *udict_mgr = udict_inline_mgr_alloc(UDICT_POOL_DEPTH,
                                                         umem_mgr, -1, -1);
    assert(udict_mgr != NULL);
    struct uref_mgr *uref_mgr = uref_std_mgr_alloc(UREF_POOL_DEPTH, udict_mgr,
                                                   0);
    /* main probe */
    struct uprobe *logger =
        uprobe_stdio_alloc(NULL, stderr, UPROBE_LOG_VERBOSE);
    assert(logger != NULL);
    logger = uprobe_uref_mgr_alloc(logger, uref_mgr);
    assert(logger != NULL);
    logger = uprobe_upump_mgr_alloc(logger, upump_mgr);
    assert(logger != NULL);
    logger = uprobe_ubuf_mem_alloc(logger, umem_mgr, UBUF_POOL_DEPTH,
                                   UBUF_POOL_DEPTH);
    assert(logger != NULL);

    /* file source */
    struct uprobe uprobe_fsrc;
    uprobe_init(&uprobe_fsrc, catch_fsrc, uprobe_use(logger));
    struct upipe_mgr *upipe_fsrc_mgr = upipe_fsrc_mgr_alloc();
    assert(upipe_fsrc_mgr != NULL);
    struct upipe *upipe_fsrc = upipe_void_alloc(upipe_fsrc_mgr,
            uprobe_pfx_alloc(uprobe_use(&uprobe_fsrc),
                             UPROBE_LOG_DEBUG, "file source"));
    assert(upipe_fsrc != NULL);
    upipe_mgr_release(upipe_fsrc_mgr);
    ubase_assert(upipe_set_uri(upipe_fsrc, files[current]));

    /* m3u reader */
    struct upipe_mgr *upipe_m3u_reader_mgr = upipe_m3u_reader_mgr_alloc();
    assert(upipe_m3u_reader_mgr != NULL);
    struct upipe *upipe_m3u_reader = upipe_void_alloc_output(
        upipe_fsrc, upipe_m3u_reader_mgr,
        uprobe_pfx_alloc(uprobe_use(logger),
                         UPROBE_LOG_VERBOSE, "m3u reader"));
    upipe_mgr_release(upipe_m3u_reader_mgr);
    assert(upipe_m3u_reader != NULL);

    struct uprobe uprobe_uref;
    uprobe_init(&uprobe_uref, catch_uref, uprobe_use(logger));
    struct upipe_mgr *upipe_probe_uref_mgr = upipe_probe_uref_mgr_alloc();
    assert(upipe_probe_uref_mgr != NULL);
    struct upipe *upipe_probe_uref = upipe_void_chain_output(
        upipe_m3u_reader, upipe_probe_uref_mgr,
        uprobe_pfx_alloc(uprobe_use(&uprobe_uref),
                         UPROBE_LOG_DEBUG, "probe uref"));
    upipe_mgr_release(upipe_probe_uref_mgr);
    assert(upipe_probe_uref != NULL);

    /* null output */
    struct upipe_mgr *upipe_null_mgr = upipe_null_mgr_alloc();
    assert(upipe_null_mgr != NULL);
    struct upipe *upipe_null = upipe_void_chain_output(
        upipe_probe_uref, upipe_null_mgr,
        uprobe_pfx_alloc(uprobe_use(logger),
                         UPROBE_LOG_DEBUG, "null"));
    upipe_mgr_release(upipe_null_mgr);
    assert(upipe_null != NULL);
    upipe_release(upipe_null);

    /* run main loop */
    upump_mgr_run(upump_mgr, NULL);

    /* release */
    upipe_release(upipe_fsrc);
    upump_mgr_release(upump_mgr);
    uref_mgr_release(uref_mgr);
    udict_mgr_release(udict_mgr);
    umem_mgr_release(umem_mgr);
    uprobe_clean(&uprobe_fsrc);
    uprobe_clean(&uprobe_uref);
    uprobe_release(logger);
    return 0;
}