Exemple #1
0
static bool write_CMD_chunk(IOStream *ios, size_t chunk_size)
{
    if (!chunk_begin(ios, "CMD ", chunk_size))
        return false;

    Command *commands = AR_data(&ar_commands);
    size_t ncommand = AR_size(&ar_commands);

    if (!write_int32(ios, 1) || !write_int32(ios, (int)ncommand))
        return false;

    size_t n;
    for (n = 0; n < ncommand; ++n)
    {
        if (!write_grammar_symbol(ios, &commands[n].symbol) ||
            !write_int32(ios, commands[n].guard) ||
            !write_int32(ios, commands[n].function))
            return false;
    }

    return chunk_end(ios, chunk_size);
}
static int webm_chunk_write_packet(AVFormatContext *s, AVPacket *pkt)
{
    WebMChunkContext *wc = s->priv_data;
    AVFormatContext *oc = wc->avf;
    AVStream *st = s->streams[pkt->stream_index];
    int ret;

    if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
        wc->duration_written += av_rescale_q(pkt->pts - wc->prev_pts,
                                             st->time_base,
                                             (AVRational) {1, 1000});
        wc->prev_pts = pkt->pts;
    }

    // For video, a new chunk is started only on key frames. For audio, a new
    // chunk is started based on chunk_duration.
    if ((st->codec->codec_type == AVMEDIA_TYPE_VIDEO &&
         (pkt->flags & AV_PKT_FLAG_KEY)) ||
        (st->codec->codec_type == AVMEDIA_TYPE_AUDIO &&
         (pkt->pts == 0 || wc->duration_written >= wc->chunk_duration))) {
        wc->duration_written = 0;
        if ((ret = chunk_end(s)) < 0 || (ret = chunk_start(s)) < 0) {
            goto fail;
        }
    }

    ret = oc->oformat->write_packet(oc, pkt);
    if (ret < 0)
        goto fail;

fail:
    if (ret < 0) {
        oc->streams = NULL;
        oc->nb_streams = 0;
        avformat_free_context(oc);
    }

    return ret;
}
Exemple #3
0
static bool write_GRM_chunk(IOStream *ios, size_t chunk_size)
{
    if (!chunk_begin(ios, "GRM ", chunk_size) ||
        !write_int32(ios, get_num_nonterm()) ||
        !write_int32(ios, get_num_rules()) ||
        !write_int32(ios, get_num_symrefs()))
        return false;

    GrammarRuleSet **rulesets = AR_data(&ar_grammar);
    size_t nruleset = AR_size(&ar_grammar), n, m;
    for (n = 0; n < nruleset; ++n)
    {
        if (!write_int32(ios, (int)rulesets[n]->nrule))
            return false;
        for (m = 0; m < rulesets[n]->nrule; ++m)
        {
            if (!write_grammar_rule(ios, rulesets[n]->rules[m]))
                return false;
        }
    }
    return chunk_end(ios, chunk_size);
}