static int decode_main_header(NUTContext *nut){

    AVFormatContext *s= nut->avf;

    ByteIOContext *bc = &s->pb;

    uint64_t tmp;

    int i, j;

    

    get_packetheader(nut, bc, 8, 1);



    tmp = get_v(bc);

    if (tmp != 1){

	av_log(s, AV_LOG_ERROR, "bad version (%Ld)\n", tmp);

        return -1;

    }

    

    nut->stream_count = get_v(bc);

    get_v(bc); //checksum threshold



    for(i=0; i<256;){

        int tmp_flags = get_v(bc);

        int tmp_stream= get_v(bc);

        int tmp_mul   = get_v(bc);

        int tmp_size  = get_v(bc);

        int count     = get_v(bc);



        if(count == 0 || i+count > 256){

            av_log(s, AV_LOG_ERROR, "illegal count %d at %d\n", count, i);

            return -1;

        }



        if((tmp_flags & FLAG_FRAME_TYPE) && tmp_flags != 1){

            if(tmp_flags & FLAG_PRED_KEY_FRAME){

                av_log(s, AV_LOG_ERROR, "keyframe prediction in non 0 frame type\n");

                return -1;

            }

            if(!(tmp_flags & FLAG_PTS) || !(tmp_flags & FLAG_FULL_PTS) ){

                av_log(s, AV_LOG_ERROR, "no full pts in non 0 frame type\n");

                return -1;

            }

        }



        for(j=0; j<count; j++,i++){

            if(tmp_stream > nut->stream_count + 1){

                av_log(s, AV_LOG_ERROR, "illegal stream number\n");

                return -1;

            }



            nut->frame_code[i].flags           = tmp_flags ;

            nut->frame_code[i].stream_id_plus1 = tmp_stream;

            nut->frame_code[i].size_mul        = tmp_mul   ;

            nut->frame_code[i].size_lsb        = tmp_size  ;

            if(++tmp_size >= tmp_mul){

                tmp_size=0;

                tmp_stream++;

            }

        }

    }

    if(nut->frame_code['N'].flags != 1){

        av_log(s, AV_LOG_ERROR, "illegal frame_code table\n");

        return -1;

    }



    if(check_checksum(bc)){

        av_log(s, AV_LOG_ERROR, "Main header checksum missmatch\n");

        return -1;

    }



    return 0;

}

static int decode_main_header(NUTContext *nut){

    AVFormatContext *s= nut->avf;

    ByteIOContext *bc = &s->pb;

    uint64_t tmp;

    int i, j;

    

    get_packetheader(nut, bc, 8, 1);



    tmp = get_v(bc);

    if (tmp != 1){

	av_log(s, AV_LOG_ERROR, "bad version (%Ld)\n", tmp);

        return -1;

    }

    

    nut->stream_count = get_v(bc);

    get_v(bc); 



    for(i=0; i<256;){

        int tmp_flags = get_v(bc);

        int tmp_stream= get_v(bc);

        int tmp_mul   = get_v(bc);

        int tmp_size  = get_v(bc);

        int count     = get_v(bc);



        if(count == 0 || i+count > 256){

            av_log(s, AV_LOG_ERROR, "illegal count %d at %d\n", count, i);

            return -1;

        }



        if((tmp_flags & FLAG_FRAME_TYPE) && tmp_flags != 1){

            if(tmp_flags & FLAG_PRED_KEY_FRAME){

                av_log(s, AV_LOG_ERROR, "keyframe prediction in non 0 frame type\n");

                return -1;

            }

            if(!(tmp_flags & FLAG_PTS) || !(tmp_flags & FLAG_FULL_PTS) ){

                av_log(s, AV_LOG_ERROR, "no full pts in non 0 frame type\n");

                return -1;

            }

        }



        for(j=0; j<count; j++,i++){

            if(tmp_stream > nut->stream_count + 1){

                av_log(s, AV_LOG_ERROR, "illegal stream number\n");

                return -1;

            }



            nut->frame_code[i].flags           = tmp_flags ;

            nut->frame_code[i].stream_id_plus1 = tmp_stream;

            nut->frame_code[i].size_mul        = tmp_mul   ;

            nut->frame_code[i].size_lsb        = tmp_size  ;

            if(++tmp_size >= tmp_mul){

                tmp_size=0;

                tmp_stream++;

            }

        }

    }

    if(nut->frame_code['N'].flags != 1){

        av_log(s, AV_LOG_ERROR, "illegal frame_code table\n");

        return -1;

    }



    if(check_checksum(bc)){

        av_log(s, AV_LOG_ERROR, "Main header checksum missmatch\n");

        return -1;

    }



    return 0;

}

static int FUNC_0(NUTContext *VAR_0){

    AVFormatContext *s= VAR_0->avf;

    ByteIOContext *bc = &s->pb;

    uint64_t tmp;

    int VAR_1, VAR_2;

    

    get_packetheader(VAR_0, bc, 8, 1);



    tmp = get_v(bc);

    if (tmp != 1){

	av_log(s, AV_LOG_ERROR, "bad version (%Ld)\n", tmp);

        return -1;

    }

    

    VAR_0->stream_count = get_v(bc);

    get_v(bc); 



    for(VAR_1=0; VAR_1<256;){

        int VAR_3 = get_v(bc);

        int VAR_4= get_v(bc);

        int VAR_5   = get_v(bc);

        int VAR_6  = get_v(bc);

        int VAR_7     = get_v(bc);



        if(VAR_7 == 0 || VAR_1+VAR_7 > 256){

            av_log(s, AV_LOG_ERROR, "illegal VAR_7 %d at %d\n", VAR_7, VAR_1);

            return -1;

        }



        if((VAR_3 & FLAG_FRAME_TYPE) && VAR_3 != 1){

            if(VAR_3 & FLAG_PRED_KEY_FRAME){

                av_log(s, AV_LOG_ERROR, "keyframe prediction in non 0 frame type\n");

                return -1;

            }

            if(!(VAR_3 & FLAG_PTS) || !(VAR_3 & FLAG_FULL_PTS) ){

                av_log(s, AV_LOG_ERROR, "no full pts in non 0 frame type\n");

                return -1;

            }

        }



        for(VAR_2=0; VAR_2<VAR_7; VAR_2++,VAR_1++){

            if(VAR_4 > VAR_0->stream_count + 1){

                av_log(s, AV_LOG_ERROR, "illegal stream number\n");

                return -1;

            }



            VAR_0->frame_code[VAR_1].flags           = VAR_3 ;

            VAR_0->frame_code[VAR_1].stream_id_plus1 = VAR_4;

            VAR_0->frame_code[VAR_1].size_mul        = VAR_5   ;

            VAR_0->frame_code[VAR_1].size_lsb        = VAR_6  ;

            if(++VAR_6 >= VAR_5){

                VAR_6=0;

                VAR_4++;

            }

        }

    }

    if(VAR_0->frame_code['N'].flags != 1){

        av_log(s, AV_LOG_ERROR, "illegal frame_code table\n");

        return -1;

    }



    if(check_checksum(bc)){

        av_log(s, AV_LOG_ERROR, "Main header checksum missmatch\n");

        return -1;

    }



    return 0;

}

static int FUNC_0(NUTContext *VAR_0){ AVFormatContext *s= VAR_0->avf; ByteIOContext *bc = &s->pb; uint64_t tmp; int VAR_1, VAR_2; get_packetheader(VAR_0, bc, 8, 1); tmp = get_v(bc); if (tmp != 1){ av_log(s, AV_LOG_ERROR, "bad version (%Ld)\n", tmp); return -1; } VAR_0->stream_count = get_v(bc); get_v(bc); for(VAR_1=0; VAR_1<256;){ int VAR_3 = get_v(bc); int VAR_4= get_v(bc); int VAR_5   = get_v(bc); int VAR_6  = get_v(bc); int VAR_7     = get_v(bc); if(VAR_7 == 0 || VAR_1+VAR_7 > 256){ av_log(s, AV_LOG_ERROR, "illegal VAR_7 %d at %d\n", VAR_7, VAR_1); return -1; } if((VAR_3 & FLAG_FRAME_TYPE) && VAR_3 != 1){ if(VAR_3 & FLAG_PRED_KEY_FRAME){ av_log(s, AV_LOG_ERROR, "keyframe prediction in non 0 frame type\n"); return -1; } if(!(VAR_3 & FLAG_PTS) || !(VAR_3 & FLAG_FULL_PTS) ){ av_log(s, AV_LOG_ERROR, "no full pts in non 0 frame type\n"); return -1; } } for(VAR_2=0; VAR_2<VAR_7; VAR_2++,VAR_1++){ if(VAR_4 > VAR_0->stream_count + 1){ av_log(s, AV_LOG_ERROR, "illegal stream number\n"); return -1; } VAR_0->frame_code[VAR_1].flags           = VAR_3 ; VAR_0->frame_code[VAR_1].stream_id_plus1 = VAR_4; VAR_0->frame_code[VAR_1].size_mul        = VAR_5   ; VAR_0->frame_code[VAR_1].size_lsb        = VAR_6  ; if(++VAR_6 >= VAR_5){ VAR_6=0; VAR_4++; } } } if(VAR_0->frame_code['N'].flags != 1){ av_log(s, AV_LOG_ERROR, "illegal frame_code table\n"); return -1; } if(check_checksum(bc)){ av_log(s, AV_LOG_ERROR, "Main header checksum missmatch\n"); return -1; } return 0; }