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