Beispiel #1
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 #2
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;
}