Example #1
0
u08 cmd_draw(const u08 *cmd, u08 len)
{
    u08 result = 0;
    switch(cmd[1]) {
    case 'b':
        result = cmd_draw_border(cmd+1,len-1);
        break;
    case 'r':
        result = cmd_draw_rect(cmd+1,len-1);
        break;
    case 'g':
        result = cmd_draw_grid(cmd+1,len-1);
        break;
    case 'h':
    case 'v':
        result = cmd_draw_line(cmd+1, len-1);
        break;
    case 'c':
        result = cmd_chunk_define(cmd+1, len-1);
        break;
    case 'C':
        /* no reply on start */
        chunk_start();
        return CMD_NO_REPLY;
    default:
        return CMD_UNKNOWN_ERR;
    }
    return result;
}
Example #2
0
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;
}