static int hds_flush(AVFormatContext *s, OutputStream *os, int final,

                     int64_t end_ts)

{

    HDSContext *c = s->priv_data;

    int i, ret = 0;

    char target_filename[1024];

    int index = s->streams[os->first_stream]->id;



    if (!os->packets_written)

        return 0;



    avio_flush(os->ctx->pb);

    os->packets_written = 0;

    close_file(os);



    snprintf(target_filename, sizeof(target_filename),

             "%s/stream%dSeg1-Frag%d", s->filename, index, os->fragment_index);

    ret = ff_rename(os->temp_filename, target_filename);

    if (ret < 0)

        return ret;

    add_fragment(os, target_filename, os->frag_start_ts, end_ts - os->frag_start_ts);



    if (!final) {

        ret = init_file(s, os, end_ts);

        if (ret < 0)

            return ret;

    }



    if (c->window_size || (final && c->remove_at_exit)) {

        int remove = os->nb_fragments - c->window_size - c->extra_window_size;

        if (final && c->remove_at_exit)

            remove = os->nb_fragments;

        if (remove > 0) {

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

                unlink(os->fragments[i]->file);

                av_free(os->fragments[i]);

            }

            os->nb_fragments -= remove;

            memmove(os->fragments, os->fragments + remove,

                    os->nb_fragments * sizeof(*os->fragments));

        }

    }



    if (ret >= 0)

        ret = write_abst(s, os, final);

    return ret;

}

static int hds_flush(AVFormatContext *s, OutputStream *os, int final,

                     int64_t end_ts)

{

    HDSContext *c = s->priv_data;

    int i, ret = 0;

    char target_filename[1024];

    int index = s->streams[os->first_stream]->id;



    if (!os->packets_written)

        return 0;



    avio_flush(os->ctx->pb);

    os->packets_written = 0;

    close_file(os);



    snprintf(target_filename, sizeof(target_filename),

             "%s/stream%dSeg1-Frag%d", s->filename, index, os->fragment_index);

    ret = ff_rename(os->temp_filename, target_filename);

    if (ret < 0)

        return ret;

    add_fragment(os, target_filename, os->frag_start_ts, end_ts - os->frag_start_ts);



    if (!final) {

        ret = init_file(s, os, end_ts);

        if (ret < 0)

            return ret;

    }



    if (c->window_size || (final && c->remove_at_exit)) {

        int remove = os->nb_fragments - c->window_size - c->extra_window_size;

        if (final && c->remove_at_exit)

            remove = os->nb_fragments;

        if (remove > 0) {

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

                unlink(os->fragments[i]->file);

                av_free(os->fragments[i]);

            }

            os->nb_fragments -= remove;

            memmove(os->fragments, os->fragments + remove,

                    os->nb_fragments * sizeof(*os->fragments));

        }

    }



    if (ret >= 0)

        ret = write_abst(s, os, final);

    return ret;

}

static int FUNC_0(AVFormatContext *VAR_0, OutputStream *VAR_1, int VAR_2,

                     int64_t VAR_3)

{

    HDSContext *c = VAR_0->priv_data;

    int VAR_4, VAR_5 = 0;

    char VAR_6[1024];

    int VAR_7 = VAR_0->streams[VAR_1->first_stream]->id;



    if (!VAR_1->packets_written)

        return 0;



    avio_flush(VAR_1->ctx->pb);

    VAR_1->packets_written = 0;

    close_file(VAR_1);



    snprintf(VAR_6, sizeof(VAR_6),

             "%VAR_0/stream%dSeg1-Frag%d", VAR_0->filename, VAR_7, VAR_1->fragment_index);

    VAR_5 = ff_rename(VAR_1->temp_filename, VAR_6);

    if (VAR_5 < 0)

        return VAR_5;

    add_fragment(VAR_1, VAR_6, VAR_1->frag_start_ts, VAR_3 - VAR_1->frag_start_ts);



    if (!VAR_2) {

        VAR_5 = init_file(VAR_0, VAR_1, VAR_3);

        if (VAR_5 < 0)

            return VAR_5;

    }



    if (c->window_size || (VAR_2 && c->remove_at_exit)) {

        int VAR_8 = VAR_1->nb_fragments - c->window_size - c->extra_window_size;

        if (VAR_2 && c->remove_at_exit)

            VAR_8 = VAR_1->nb_fragments;

        if (VAR_8 > 0) {

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

                unlink(VAR_1->fragments[VAR_4]->file);

                av_free(VAR_1->fragments[VAR_4]);

            }

            VAR_1->nb_fragments -= VAR_8;

            memmove(VAR_1->fragments, VAR_1->fragments + VAR_8,

                    VAR_1->nb_fragments * sizeof(*VAR_1->fragments));

        }

    }



    if (VAR_5 >= 0)

        VAR_5 = write_abst(VAR_0, VAR_1, VAR_2);

    return VAR_5;

}

static int FUNC_0(AVFormatContext *VAR_0, OutputStream *VAR_1, int VAR_2,
int64_t VAR_3)
{ HDSContext *c = VAR_0->priv_data; int VAR_4, VAR_5 = 0; char VAR_6[1024]; int VAR_7 = VAR_0->streams[VAR_1->first_stream]->id; if (!VAR_1->packets_written)
return 0; avio_flush(VAR_1->ctx->pb); VAR_1->packets_written = 0; close_file(VAR_1); snprintf(VAR_6, sizeof(VAR_6),
"%VAR_0/stream%dSeg1-Frag%d", VAR_0->filename, VAR_7, VAR_1->fragment_index); VAR_5 = ff_rename(VAR_1->temp_filename, VAR_6); if (VAR_5 < 0)
return VAR_5; add_fragment(VAR_1, VAR_6, VAR_1->frag_start_ts, VAR_3 - VAR_1->frag_start_ts); if (!VAR_2) { VAR_5 = init_file(VAR_0, VAR_1, VAR_3); if (VAR_5 < 0)
return VAR_5; } if (c->window_size || (VAR_2 && c->remove_at_exit)) { int VAR_8 = VAR_1->nb_fragments - c->window_size - c->extra_window_size; if (VAR_2 && c->remove_at_exit)
VAR_8 = VAR_1->nb_fragments; if (VAR_8 > 0) { for (VAR_4 = 0; VAR_4 < VAR_8; VAR_4++) { unlink(VAR_1->fragments[VAR_4]->file); av_free(VAR_1->fragments[VAR_4]); } VAR_1->nb_fragments -= VAR_8; memmove(VAR_1->fragments, VAR_1->fragments + VAR_8,
VAR_1->nb_fragments * sizeof(*VAR_1->fragments)); } } if (VAR_5 >= 0)
VAR_5 = write_abst(VAR_0, VAR_1, VAR_2); return VAR_5; }