static int decode_pic_hdr(IVI5DecContext *ctx, AVCodecContext *avctx)
{
    if (get_bits(&ctx->gb, 5) != 0x1F) {
        av_log(avctx, AV_LOG_ERROR, "Invalid picture start code!\n");
        return -1;
    ctx->prev_frame_type = ctx->frame_type;
    ctx->frame_type      = get_bits(&ctx->gb, 3);
    if (ctx->frame_type >= 5) {
        av_log(avctx, AV_LOG_ERROR, "Invalid frame type: %d \n", ctx->frame_type);
        return -1;
    ctx->frame_num = get_bits(&ctx->gb, 8);
    if (ctx->frame_type == FRAMETYPE_INTRA) {
        ctx->gop_invalid = 1;
        if (decode_gop_header(ctx, avctx))
            return -1;
        ctx->gop_invalid = 0;
    if (ctx->frame_type != FRAMETYPE_NULL) {
        ctx->frame_flags = get_bits(&ctx->gb, 8);
        ctx->pic_hdr_size = (ctx->frame_flags & 1) ? get_bits_long(&ctx->gb, 24) : 0;
        ctx->checksum = (ctx->frame_flags & 0x10) ? get_bits(&ctx->gb, 16) : 0;
        /* skip unknown extension if any */
        if (ctx->frame_flags & 0x20)
            skip_hdr_extension(&ctx->gb); /* XXX: untested */
        /* decode macroblock huffman codebook */
        if (ff_ivi_dec_huff_desc(&ctx->gb, ctx->frame_flags & 0x40, IVI_MB_HUFF, &ctx->mb_vlc, avctx))
            return -1;
        skip_bits(&ctx->gb, 3); /* FIXME: unknown meaning! */
    align_get_bits(&ctx->gb);
    return 0;
static int decode_pic_hdr(IVI5DecContext *ctx, AVCodecContext *avctx)
{
    if (get_bits(&ctx->gb, 5) != 0x1F) {
        av_log(avctx, AV_LOG_ERROR, "Invalid picture start code!\n");
        return -1;
    ctx->prev_frame_type = ctx->frame_type;
    ctx->frame_type      = get_bits(&ctx->gb, 3);
    if (ctx->frame_type >= 5) {
        av_log(avctx, AV_LOG_ERROR, "Invalid frame type: %d \n", ctx->frame_type);
        return -1;
    ctx->frame_num = get_bits(&ctx->gb, 8);
    if (ctx->frame_type == FRAMETYPE_INTRA) {
        ctx->gop_invalid = 1;
        if (decode_gop_header(ctx, avctx))
            return -1;
        ctx->gop_invalid = 0;
    if (ctx->frame_type != FRAMETYPE_NULL) {
        ctx->frame_flags = get_bits(&ctx->gb, 8);
        ctx->pic_hdr_size = (ctx->frame_flags & 1) ? get_bits_long(&ctx->gb, 24) : 0;
        ctx->checksum = (ctx->frame_flags & 0x10) ? get_bits(&ctx->gb, 16) : 0;
        
        if (ctx->frame_flags & 0x20)
            skip_hdr_extension(&ctx->gb); 
        
        if (ff_ivi_dec_huff_desc(&ctx->gb, ctx->frame_flags & 0x40, IVI_MB_HUFF, &ctx->mb_vlc, avctx))
            return -1;
        skip_bits(&ctx->gb, 3); 
    align_get_bits(&ctx->gb);
    return 0;
static int FUNC_0(IVI5DecContext *VAR_0, AVCodecContext *VAR_1)
{
    if (get_bits(&VAR_0->gb, 5) != 0x1F) {
        av_log(VAR_1, AV_LOG_ERROR, "Invalid picture start code!\n");
        return -1;
    VAR_0->prev_frame_type = VAR_0->frame_type;
    VAR_0->frame_type      = get_bits(&VAR_0->gb, 3);
    if (VAR_0->frame_type >= 5) {
        av_log(VAR_1, AV_LOG_ERROR, "Invalid frame type: %d \n", VAR_0->frame_type);
        return -1;
    VAR_0->frame_num = get_bits(&VAR_0->gb, 8);
    if (VAR_0->frame_type == FRAMETYPE_INTRA) {
        VAR_0->gop_invalid = 1;
        if (decode_gop_header(VAR_0, VAR_1))
            return -1;
        VAR_0->gop_invalid = 0;
    if (VAR_0->frame_type != FRAMETYPE_NULL) {
        VAR_0->frame_flags = get_bits(&VAR_0->gb, 8);
        VAR_0->pic_hdr_size = (VAR_0->frame_flags & 1) ? get_bits_long(&VAR_0->gb, 24) : 0;
        VAR_0->checksum = (VAR_0->frame_flags & 0x10) ? get_bits(&VAR_0->gb, 16) : 0;
        
        if (VAR_0->frame_flags & 0x20)
            skip_hdr_extension(&VAR_0->gb); 
        
        if (ff_ivi_dec_huff_desc(&VAR_0->gb, VAR_0->frame_flags & 0x40, IVI_MB_HUFF, &VAR_0->mb_vlc, VAR_1))
            return -1;
        skip_bits(&VAR_0->gb, 3); 
    align_get_bits(&VAR_0->gb);
    return 0;
static int FUNC_0(IVI5DecContext *VAR_0, AVCodecContext *VAR_1)
{ if (get_bits(&VAR_0->gb, 5) != 0x1F) { av_log(VAR_1, AV_LOG_ERROR, "Invalid picture start code!\n"); return -1; VAR_0->prev_frame_type = VAR_0->frame_type; VAR_0->frame_type      = get_bits(&VAR_0->gb, 3); if (VAR_0->frame_type >= 5) { av_log(VAR_1, AV_LOG_ERROR, "Invalid frame type: %d \n", VAR_0->frame_type); return -1; VAR_0->frame_num = get_bits(&VAR_0->gb, 8); if (VAR_0->frame_type == FRAMETYPE_INTRA) { VAR_0->gop_invalid = 1; if (decode_gop_header(VAR_0, VAR_1))
return -1; VAR_0->gop_invalid = 0; if (VAR_0->frame_type != FRAMETYPE_NULL) { VAR_0->frame_flags = get_bits(&VAR_0->gb, 8); VAR_0->pic_hdr_size = (VAR_0->frame_flags & 1) ? get_bits_long(&VAR_0->gb, 24) : 0; VAR_0->checksum = (VAR_0->frame_flags & 0x10) ? get_bits(&VAR_0->gb, 16) : 0; if (VAR_0->frame_flags & 0x20)
skip_hdr_extension(&VAR_0->gb); if (ff_ivi_dec_huff_desc(&VAR_0->gb, VAR_0->frame_flags & 0x40, IVI_MB_HUFF, &VAR_0->mb_vlc, VAR_1))
return -1; skip_bits(&VAR_0->gb, 3); align_get_bits(&VAR_0->gb); return 0;