示例#1
0
文件: upipe_rtcp.c 项目: tmatth/upipe
static int upipe_rtcp_check(struct upipe *upipe, struct uref *flow_format)
{
    struct upipe_rtcp *upipe_rtcp = upipe_rtcp_from_upipe(upipe);

    if (flow_format != NULL)
        upipe_rtcp_store_flow_def(upipe, flow_format);

    if (upipe_rtcp->flow_def == NULL)
        return UBASE_ERR_NONE;

    if (upipe_rtcp->uref_mgr == NULL) {
        upipe_rtcp_require_uref_mgr(upipe);
        return UBASE_ERR_NONE;
    }

    if (upipe_rtcp->ubuf_mgr == NULL) {
        struct uref *flow_format =
            uref_block_flow_alloc_def(upipe_rtcp->uref_mgr, NULL);
        if (unlikely(flow_format == NULL)) {
            upipe_throw_fatal(upipe, UBASE_ERR_ALLOC);
            return UBASE_ERR_ALLOC;
        }
        upipe_rtcp_require_ubuf_mgr(upipe, flow_format);
        return UBASE_ERR_NONE;
    }

    return UBASE_ERR_NONE;
}
示例#2
0
/** @internal @This outputs audio buffers
 *
 * @param upipe description structure of the pipe
 * @param frame AVFrame structure
 * @param upump upump structure
 */
static void upipe_avcdec_output_audio(struct upipe *upipe, AVFrame *frame,
                                     struct upump *upump)
{
    struct ubuf *ubuf;
    struct upipe_avcdec *upipe_avcdec = upipe_avcdec_from_upipe(upipe);
    struct uref *uref = frame->opaque;
    int bufsize = -1, avbufsize;
    size_t size = 0;
    uint8_t *buf;
    AVCodecContext *context = upipe_avcdec->context;

    /* fetch audio sample size (in case it has been reduced) */
    avbufsize = av_samples_get_buffer_size(NULL, context->channels,
                       frame->nb_samples, context->sample_fmt, 1);

    /* if uref has no attached ubuf (ie DR not supported) */
    if (unlikely(!uref->ubuf)) {
        ubuf = ubuf_block_alloc(upipe_avcdec->ubuf_mgr, avbufsize);
        if (unlikely(!ubuf)) {
            upipe_throw_aerror(upipe);
            return;
        }

        ubuf_block_write(ubuf, 0, &bufsize, &buf);
        memcpy(buf, frame->data[0], bufsize);

        uref_attach_ubuf(uref, ubuf);
    }

    /* unmap, reduce block if needed */
    uref_block_unmap(uref, 0);
    uref_block_size(uref, &size);
    if (unlikely(size != avbufsize)) {
        uref_block_resize(uref, 0, avbufsize);
    }

    /* TODO: set attributes/need a real ubuf_audio structure (?) */
    if (!upipe_avcdec->output_flow) {
        #if 0
        struct uref *outflow = uref_sound_flow_alloc_def(upipe_avcdec->uref_mgr,
                    context->channels,
                    av_get_bytes_per_sample(context->sample_fmt));
        #else

        struct uref *outflow = uref_block_flow_alloc_def(upipe_avcdec->uref_mgr,
                                                        "sound.");

        #endif
        uref_sound_flow_set_channels(outflow, context->channels);
        uref_sound_flow_set_sample_size(outflow,
                                 av_get_bytes_per_sample(context->sample_fmt));
        uref_sound_flow_set_rate(outflow, context->sample_rate);

        upipe_avcdec_store_flow_def(upipe, outflow);
    }

    /* samples in uref */
    uref_sound_flow_set_samples(uref, frame->nb_samples);

    /* index rap attribute */
    upipe_avcdec_set_index_rap(upipe, uref);

    upipe_avcdec_output(upipe, uref, upump);
}