static int decode_info_header(NUTContext *nut)

{

    AVFormatContext *s = nut->avf;

    AVIOContext *bc    = s->pb;

    uint64_t tmp, chapter_start, chapter_len;

    unsigned int stream_id_plus1, count;

    int chapter_id, i;

    int64_t value, end;

    char name[256], str_value[1024], type_str[256];

    const char *type;

    int *event_flags;

    AVChapter *chapter      = NULL;

    AVStream *st            = NULL;

    AVDictionary **metadata = NULL;

    int metadata_flag       = 0;



    end  = get_packetheader(nut, bc, 1, INFO_STARTCODE);

    end += avio_tell(bc);



    GET_V(stream_id_plus1, tmp <= s->nb_streams);

    chapter_id    = get_s(bc);

    chapter_start = ffio_read_varlen(bc);

    chapter_len   = ffio_read_varlen(bc);

    count         = ffio_read_varlen(bc);



    if (chapter_id && !stream_id_plus1) {

        int64_t start = chapter_start / nut->time_base_count;

        chapter = avpriv_new_chapter(s, chapter_id,

                                     nut->time_base[chapter_start %

                                                    nut->time_base_count],

                                     start, start + chapter_len, NULL);

        metadata = &chapter->metadata;

    } else if (stream_id_plus1) {

        st       = s->streams[stream_id_plus1 - 1];

        metadata = &st->metadata;

        event_flags = &st->event_flags;

        metadata_flag = AVSTREAM_EVENT_FLAG_METADATA_UPDATED;

    } else {

        metadata = &s->metadata;

        event_flags = &s->event_flags;

        metadata_flag = AVFMT_EVENT_FLAG_METADATA_UPDATED;

    }



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

        get_str(bc, name, sizeof(name));

        value = get_s(bc);

        if (value == -1) {

            type = "UTF-8";

            get_str(bc, str_value, sizeof(str_value));

        } else if (value == -2) {

            get_str(bc, type_str, sizeof(type_str));

            type = type_str;

            get_str(bc, str_value, sizeof(str_value));

        } else if (value == -3) {

            type  = "s";

            value = get_s(bc);

        } else if (value == -4) {

            type  = "t";

            value = ffio_read_varlen(bc);

        } else if (value < -4) {

            type = "r";

            get_s(bc);

        } else {

            type = "v";

        }



        if (stream_id_plus1 > s->nb_streams) {

            av_log(s, AV_LOG_ERROR, "invalid stream id for info packet\n");

            continue;

        }



        if (!strcmp(type, "UTF-8")) {

            if (chapter_id == 0 && !strcmp(name, "Disposition")) {

                set_disposition_bits(s, str_value, stream_id_plus1 - 1);

                continue;

            }

            if (metadata && av_strcasecmp(name, "Uses") &&

                av_strcasecmp(name, "Depends") && av_strcasecmp(name, "Replaces")) {

                *event_flags |= metadata_flag;

                av_dict_set(metadata, name, str_value, 0);

            }

        }

    }



    if (skip_reserved(bc, end) || ffio_get_checksum(bc)) {

        av_log(s, AV_LOG_ERROR, "info header checksum mismatch\n");

        return AVERROR_INVALIDDATA;

    }

    return 0;

}

static int decode_info_header(NUTContext *nut)

{

    AVFormatContext *s = nut->avf;

    AVIOContext *bc    = s->pb;

    uint64_t tmp, chapter_start, chapter_len;

    unsigned int stream_id_plus1, count;

    int chapter_id, i;

    int64_t value, end;

    char name[256], str_value[1024], type_str[256];

    const char *type;

    int *event_flags;

    AVChapter *chapter      = NULL;

    AVStream *st            = NULL;

    AVDictionary **metadata = NULL;

    int metadata_flag       = 0;



    end  = get_packetheader(nut, bc, 1, INFO_STARTCODE);

    end += avio_tell(bc);



    GET_V(stream_id_plus1, tmp <= s->nb_streams);

    chapter_id    = get_s(bc);

    chapter_start = ffio_read_varlen(bc);

    chapter_len   = ffio_read_varlen(bc);

    count         = ffio_read_varlen(bc);



    if (chapter_id && !stream_id_plus1) {

        int64_t start = chapter_start / nut->time_base_count;

        chapter = avpriv_new_chapter(s, chapter_id,

                                     nut->time_base[chapter_start %

                                                    nut->time_base_count],

                                     start, start + chapter_len, NULL);

        metadata = &chapter->metadata;

    } else if (stream_id_plus1) {

        st       = s->streams[stream_id_plus1 - 1];

        metadata = &st->metadata;

        event_flags = &st->event_flags;

        metadata_flag = AVSTREAM_EVENT_FLAG_METADATA_UPDATED;

    } else {

        metadata = &s->metadata;

        event_flags = &s->event_flags;

        metadata_flag = AVFMT_EVENT_FLAG_METADATA_UPDATED;

    }



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

        get_str(bc, name, sizeof(name));

        value = get_s(bc);

        if (value == -1) {

            type = "UTF-8";

            get_str(bc, str_value, sizeof(str_value));

        } else if (value == -2) {

            get_str(bc, type_str, sizeof(type_str));

            type = type_str;

            get_str(bc, str_value, sizeof(str_value));

        } else if (value == -3) {

            type  = "s";

            value = get_s(bc);

        } else if (value == -4) {

            type  = "t";

            value = ffio_read_varlen(bc);

        } else if (value < -4) {

            type = "r";

            get_s(bc);

        } else {

            type = "v";

        }



        if (stream_id_plus1 > s->nb_streams) {

            av_log(s, AV_LOG_ERROR, "invalid stream id for info packet\n");

            continue;

        }



        if (!strcmp(type, "UTF-8")) {

            if (chapter_id == 0 && !strcmp(name, "Disposition")) {

                set_disposition_bits(s, str_value, stream_id_plus1 - 1);

                continue;

            }

            if (metadata && av_strcasecmp(name, "Uses") &&

                av_strcasecmp(name, "Depends") && av_strcasecmp(name, "Replaces")) {

                *event_flags |= metadata_flag;

                av_dict_set(metadata, name, str_value, 0);

            }

        }

    }



    if (skip_reserved(bc, end) || ffio_get_checksum(bc)) {

        av_log(s, AV_LOG_ERROR, "info header checksum mismatch\n");

        return AVERROR_INVALIDDATA;

    }

    return 0;

}

    int *event_flags;                 *event_flags |= metadata_flag;
static int FUNC_0(NUTContext *VAR_0)

{

    AVFormatContext *s = VAR_0->avf;

    AVIOContext *bc    = s->pb;

    uint64_t tmp, chapter_start, chapter_len;

    unsigned int VAR_1, VAR_2;

    int VAR_3, VAR_4;

    int64_t value, end;

    char VAR_5[256], VAR_6[1024], VAR_7[256];

    const char *VAR_8;

    int *VAR_9;

    AVChapter *chapter      = NULL;

    AVStream *st            = NULL;

    AVDictionary **metadata = NULL;

    int VAR_10       = 0;



    end  = get_packetheader(VAR_0, bc, 1, INFO_STARTCODE);

    end += avio_tell(bc);



    GET_V(VAR_1, tmp <= s->nb_streams);

    VAR_3    = get_s(bc);

    chapter_start = ffio_read_varlen(bc);

    chapter_len   = ffio_read_varlen(bc);

    VAR_2         = ffio_read_varlen(bc);



    if (VAR_3 && !VAR_1) {

        int64_t start = chapter_start / VAR_0->time_base_count;

        chapter = avpriv_new_chapter(s, VAR_3,

                                     VAR_0->time_base[chapter_start %

                                                    VAR_0->time_base_count],

                                     start, start + chapter_len, NULL);

        metadata = &chapter->metadata;

    } else if (VAR_1) {

        st       = s->streams[VAR_1 - 1];

        metadata = &st->metadata;

        VAR_9 = &st->VAR_9;

        VAR_10 = AVSTREAM_EVENT_FLAG_METADATA_UPDATED;

    } else {

        metadata = &s->metadata;

        VAR_9 = &s->VAR_9;

        VAR_10 = AVFMT_EVENT_FLAG_METADATA_UPDATED;

    }



    for (VAR_4 = 0; VAR_4 < VAR_2; VAR_4++) {

        get_str(bc, VAR_5, sizeof(VAR_5));

        value = get_s(bc);

        if (value == -1) {

            VAR_8 = "UTF-8";

            get_str(bc, VAR_6, sizeof(VAR_6));

        } else if (value == -2) {

            get_str(bc, VAR_7, sizeof(VAR_7));

            VAR_8 = VAR_7;

            get_str(bc, VAR_6, sizeof(VAR_6));

        } else if (value == -3) {

            VAR_8  = "s";

            value = get_s(bc);

        } else if (value == -4) {

            VAR_8  = "t";

            value = ffio_read_varlen(bc);

        } else if (value < -4) {

            VAR_8 = "r";

            get_s(bc);

        } else {

            VAR_8 = "v";

        }



        if (VAR_1 > s->nb_streams) {

            av_log(s, AV_LOG_ERROR, "invalid stream id for info packet\n");

            continue;

        }



        if (!strcmp(VAR_8, "UTF-8")) {

            if (VAR_3 == 0 && !strcmp(VAR_5, "Disposition")) {

                set_disposition_bits(s, VAR_6, VAR_1 - 1);

                continue;

            }

            if (metadata && av_strcasecmp(VAR_5, "Uses") &&

                av_strcasecmp(VAR_5, "Depends") && av_strcasecmp(VAR_5, "Replaces")) {

                *VAR_9 |= VAR_10;

                av_dict_set(metadata, VAR_5, VAR_6, 0);

            }

        }

    }



    if (skip_reserved(bc, end) || ffio_get_checksum(bc)) {

        av_log(s, AV_LOG_ERROR, "info header checksum mismatch\n");

        return AVERROR_INVALIDDATA;

    }

    return 0;

}

static int FUNC_0(NUTContext *VAR_0)
{ AVFormatContext *s = VAR_0->avf; AVIOContext *bc    = s->pb; uint64_t tmp, chapter_start, chapter_len; unsigned int VAR_1, VAR_2; int VAR_3, VAR_4; int64_t value, end; char VAR_5[256], VAR_6[1024], VAR_7[256]; const char *VAR_8; int *VAR_9; AVChapter *chapter      = NULL; AVStream *st            = NULL; AVDictionary **metadata = NULL; int VAR_10       = 0; end  = get_packetheader(VAR_0, bc, 1, INFO_STARTCODE); end += avio_tell(bc); GET_V(VAR_1, tmp <= s->nb_streams); VAR_3    = get_s(bc); chapter_start = ffio_read_varlen(bc); chapter_len   = ffio_read_varlen(bc); VAR_2         = ffio_read_varlen(bc); if (VAR_3 && !VAR_1) { int64_t start = chapter_start / VAR_0->time_base_count; chapter = avpriv_new_chapter(s, VAR_3,
VAR_0->time_base[chapter_start %
VAR_0->time_base_count],
start, start + chapter_len, NULL); metadata = &chapter->metadata; } else if (VAR_1) { st       = s->streams[VAR_1 - 1]; metadata = &st->metadata; VAR_9 = &st->VAR_9; VAR_10 = AVSTREAM_EVENT_FLAG_METADATA_UPDATED; } else { metadata = &s->metadata; VAR_9 = &s->VAR_9; VAR_10 = AVFMT_EVENT_FLAG_METADATA_UPDATED; } for (VAR_4 = 0; VAR_4 < VAR_2; VAR_4++) { get_str(bc, VAR_5, sizeof(VAR_5)); value = get_s(bc); if (value == -1) { VAR_8 = "UTF-8"; get_str(bc, VAR_6, sizeof(VAR_6)); } else if (value == -2) { get_str(bc, VAR_7, sizeof(VAR_7)); VAR_8 = VAR_7; get_str(bc, VAR_6, sizeof(VAR_6)); } else if (value == -3) { VAR_8  = "s"; value = get_s(bc); } else if (value == -4) { VAR_8  = "t"; value = ffio_read_varlen(bc); } else if (value < -4) { VAR_8 = "r"; get_s(bc); } else { VAR_8 = "v"; } if (VAR_1 > s->nb_streams) { av_log(s, AV_LOG_ERROR, "invalid stream id for info packet\n"); continue; } if (!strcmp(VAR_8, "UTF-8")) { if (VAR_3 == 0 && !strcmp(VAR_5, "Disposition")) { set_disposition_bits(s, VAR_6, VAR_1 - 1); continue; } if (metadata && av_strcasecmp(VAR_5, "Uses") &&
av_strcasecmp(VAR_5, "Depends") && av_strcasecmp(VAR_5, "Replaces")) { *VAR_9 |= VAR_10; av_dict_set(metadata, VAR_5, VAR_6, 0); } } } if (skip_reserved(bc, end) || ffio_get_checksum(bc)) { av_log(s, AV_LOG_ERROR, "info header checksum mismatch\n"); return AVERROR_INVALIDDATA; } return 0; }