static int mkv_write_tracks(AVFormatContext *s)

{

    MatroskaMuxContext *mkv = s->priv_data;

    AVIOContext *dyn_cp, *pb = s->pb;

    ebml_master tracks;

    int i, ret, default_stream_exists = 0;



    ret = mkv_add_seekhead_entry(mkv->main_seekhead, MATROSKA_ID_TRACKS, avio_tell(pb));

    if (ret < 0)

        return ret;



    ret = start_ebml_master_crc32(pb, &dyn_cp, &tracks, MATROSKA_ID_TRACKS, 0);

    if (ret < 0)

        return ret;



    for (i = 0; i < s->nb_streams; i++) {

        AVStream *st = s->streams[i];

        default_stream_exists |= st->disposition & AV_DISPOSITION_DEFAULT;

    }

    for (i = 0; i < s->nb_streams; i++) {

        ret = mkv_write_track(s, mkv, i, dyn_cp, default_stream_exists);

        if (ret < 0)

            return ret;

    }

    end_ebml_master_crc32(pb, &dyn_cp, mkv, tracks);

    return 0;

}

static int mkv_write_tracks(AVFormatContext *s)

{

    MatroskaMuxContext *mkv = s->priv_data;

    AVIOContext *dyn_cp, *pb = s->pb;

    ebml_master tracks;

    int i, ret, default_stream_exists = 0;



    ret = mkv_add_seekhead_entry(mkv->main_seekhead, MATROSKA_ID_TRACKS, avio_tell(pb));

    if (ret < 0)

        return ret;



    ret = start_ebml_master_crc32(pb, &dyn_cp, &tracks, MATROSKA_ID_TRACKS, 0);

    if (ret < 0)

        return ret;



    for (i = 0; i < s->nb_streams; i++) {

        AVStream *st = s->streams[i];

        default_stream_exists |= st->disposition & AV_DISPOSITION_DEFAULT;

    }

    for (i = 0; i < s->nb_streams; i++) {

        ret = mkv_write_track(s, mkv, i, dyn_cp, default_stream_exists);

        if (ret < 0)

            return ret;

    }

    end_ebml_master_crc32(pb, &dyn_cp, mkv, tracks);

    return 0;

}

static int FUNC_0(AVFormatContext *VAR_0)

{

    MatroskaMuxContext *mkv = VAR_0->priv_data;

    AVIOContext *dyn_cp, *pb = VAR_0->pb;

    ebml_master tracks;

    int VAR_1, VAR_2, VAR_3 = 0;



    VAR_2 = mkv_add_seekhead_entry(mkv->main_seekhead, MATROSKA_ID_TRACKS, avio_tell(pb));

    if (VAR_2 < 0)

        return VAR_2;



    VAR_2 = start_ebml_master_crc32(pb, &dyn_cp, &tracks, MATROSKA_ID_TRACKS, 0);

    if (VAR_2 < 0)

        return VAR_2;



    for (VAR_1 = 0; VAR_1 < VAR_0->nb_streams; VAR_1++) {

        AVStream *st = VAR_0->streams[VAR_1];

        VAR_3 |= st->disposition & AV_DISPOSITION_DEFAULT;

    }

    for (VAR_1 = 0; VAR_1 < VAR_0->nb_streams; VAR_1++) {

        VAR_2 = mkv_write_track(VAR_0, mkv, VAR_1, dyn_cp, VAR_3);

        if (VAR_2 < 0)

            return VAR_2;

    }

    end_ebml_master_crc32(pb, &dyn_cp, mkv, tracks);

    return 0;

}

static int FUNC_0(AVFormatContext *VAR_0)
{ MatroskaMuxContext *mkv = VAR_0->priv_data; AVIOContext *dyn_cp, *pb = VAR_0->pb; ebml_master tracks; int VAR_1, VAR_2, VAR_3 = 0; VAR_2 = mkv_add_seekhead_entry(mkv->main_seekhead, MATROSKA_ID_TRACKS, avio_tell(pb)); if (VAR_2 < 0)
return VAR_2; VAR_2 = start_ebml_master_crc32(pb, &dyn_cp, &tracks, MATROSKA_ID_TRACKS, 0); if (VAR_2 < 0)
return VAR_2; for (VAR_1 = 0; VAR_1 < VAR_0->nb_streams; VAR_1++) { AVStream *st = VAR_0->streams[VAR_1]; VAR_3 |= st->disposition & AV_DISPOSITION_DEFAULT; } for (VAR_1 = 0; VAR_1 < VAR_0->nb_streams; VAR_1++) { VAR_2 = mkv_write_track(VAR_0, mkv, VAR_1, dyn_cp, VAR_3); if (VAR_2 < 0)
return VAR_2; } end_ebml_master_crc32(pb, &dyn_cp, mkv, tracks); return 0; }