static int segment_start(AVFormatContext *s, int write_header)

{

    SegmentContext *c = s->priv_data;

    AVFormatContext *oc = c->avf;

    int err = 0;



    if (write_header) {

        avformat_free_context(oc);

        c->avf = NULL;

        if ((err = segment_mux_init(s)) < 0)

            return err;

        oc = c->avf;

    }



    if (c->wrap)

        c->number %= c->wrap;



    if (av_get_frame_filename(oc->filename, sizeof(oc->filename),

                              s->filename, c->number++) < 0)

        return AVERROR(EINVAL);



    if ((err = avio_open2(&oc->pb, oc->filename, AVIO_FLAG_WRITE,

                          &s->interrupt_callback, NULL)) < 0)

        return err;



    if (oc->oformat->priv_class && oc->priv_data)

        av_opt_set(oc->priv_data, "resend_headers", "1", 0); /* mpegts specific */



    if (write_header) {

        if ((err = avformat_write_header(oc, NULL)) < 0)

            return err;

    }



    return 0;

}

static int segment_start(AVFormatContext *s, int write_header)

{

    SegmentContext *c = s->priv_data;

    AVFormatContext *oc = c->avf;

    int err = 0;



    if (write_header) {

        avformat_free_context(oc);

        c->avf = NULL;

        if ((err = segment_mux_init(s)) < 0)

            return err;

        oc = c->avf;

    }



    if (c->wrap)

        c->number %= c->wrap;



    if (av_get_frame_filename(oc->filename, sizeof(oc->filename),

                              s->filename, c->number++) < 0)

        return AVERROR(EINVAL);



    if ((err = avio_open2(&oc->pb, oc->filename, AVIO_FLAG_WRITE,

                          &s->interrupt_callback, NULL)) < 0)

        return err;



    if (oc->oformat->priv_class && oc->priv_data)

        av_opt_set(oc->priv_data, "resend_headers", "1", 0); 



    if (write_header) {

        if ((err = avformat_write_header(oc, NULL)) < 0)

            return err;

    }



    return 0;

}

static int FUNC_0(AVFormatContext *VAR_0, int VAR_1)

{

    SegmentContext *c = VAR_0->priv_data;

    AVFormatContext *oc = c->avf;

    int VAR_2 = 0;



    if (VAR_1) {

        avformat_free_context(oc);

        c->avf = NULL;

        if ((VAR_2 = segment_mux_init(VAR_0)) < 0)

            return VAR_2;

        oc = c->avf;

    }



    if (c->wrap)

        c->number %= c->wrap;



    if (av_get_frame_filename(oc->filename, sizeof(oc->filename),

                              VAR_0->filename, c->number++) < 0)

        return AVERROR(EINVAL);



    if ((VAR_2 = avio_open2(&oc->pb, oc->filename, AVIO_FLAG_WRITE,

                          &VAR_0->interrupt_callback, NULL)) < 0)

        return VAR_2;



    if (oc->oformat->priv_class && oc->priv_data)

        av_opt_set(oc->priv_data, "resend_headers", "1", 0); 



    if (VAR_1) {

        if ((VAR_2 = avformat_write_header(oc, NULL)) < 0)

            return VAR_2;

    }



    return 0;

}

static int FUNC_0(AVFormatContext *VAR_0, int VAR_1)
{ SegmentContext *c = VAR_0->priv_data; AVFormatContext *oc = c->avf; int VAR_2 = 0; if (VAR_1) { avformat_free_context(oc); c->avf = NULL; if ((VAR_2 = segment_mux_init(VAR_0)) < 0)
return VAR_2; oc = c->avf; } if (c->wrap)
c->number %= c->wrap; if (av_get_frame_filename(oc->filename, sizeof(oc->filename),
VAR_0->filename, c->number++) < 0)
return AVERROR(EINVAL); if ((VAR_2 = avio_open2(&oc->pb, oc->filename, AVIO_FLAG_WRITE,
&VAR_0->interrupt_callback, NULL)) < 0)
return VAR_2; if (oc->oformat->priv_class && oc->priv_data)
av_opt_set(oc->priv_data, "resend_headers", "1", 0); if (VAR_1) { if ((VAR_2 = avformat_write_header(oc, NULL)) < 0)
return VAR_2; } return 0; }