static int seg_write_trailer(struct AVFormatContext *s)

{

    SegmentContext *seg = s->priv_data;

    AVFormatContext *oc = seg->avf;

    int ret = 0;



    if (!oc)

        goto fail;



    if (!seg->write_header_trailer) {

        if ((ret = segment_end(oc, 0)) < 0)

            goto fail;

        open_null_ctx(&oc->pb);

        ret = av_write_trailer(oc);

        close_null_ctx(oc->pb);

    } else {

        ret = segment_end(oc, 1);

    }



    if (ret < 0)

        goto fail;



    if (seg->list && seg->list_type == LIST_HLS) {

        if ((ret = segment_hls_window(s, 1) < 0))

            goto fail;

    }



fail:

    avio_close(seg->pb);

    avformat_free_context(oc);

    return ret;

}

static int seg_write_trailer(struct AVFormatContext *s)

{

    SegmentContext *seg = s->priv_data;

    AVFormatContext *oc = seg->avf;

    int ret = 0;



    if (!oc)

        goto fail;



    if (!seg->write_header_trailer) {

        if ((ret = segment_end(oc, 0)) < 0)

            goto fail;

        open_null_ctx(&oc->pb);

        ret = av_write_trailer(oc);

        close_null_ctx(oc->pb);

    } else {

        ret = segment_end(oc, 1);

    }



    if (ret < 0)

        goto fail;



    if (seg->list && seg->list_type == LIST_HLS) {

        if ((ret = segment_hls_window(s, 1) < 0))

            goto fail;

    }



fail:

    avio_close(seg->pb);

    avformat_free_context(oc);

    return ret;

}

static int FUNC_0(struct AVFormatContext *VAR_0)

{

    SegmentContext *seg = VAR_0->priv_data;

    AVFormatContext *VAR_1 = seg->avf;

    int VAR_2 = 0;



    if (!VAR_1)

        goto fail;



    if (!seg->write_header_trailer) {

        if ((VAR_2 = segment_end(VAR_1, 0)) < 0)

            goto fail;

        open_null_ctx(&VAR_1->pb);

        VAR_2 = av_write_trailer(VAR_1);

        close_null_ctx(VAR_1->pb);

    } else {

        VAR_2 = segment_end(VAR_1, 1);

    }



    if (VAR_2 < 0)

        goto fail;



    if (seg->list && seg->list_type == LIST_HLS) {

        if ((VAR_2 = segment_hls_window(VAR_0, 1) < 0))

            goto fail;

    }



fail:

    avio_close(seg->pb);

    avformat_free_context(VAR_1);

    return VAR_2;

}

static int FUNC_0(struct AVFormatContext *VAR_0)
{ SegmentContext *seg = VAR_0->priv_data; AVFormatContext *VAR_1 = seg->avf; int VAR_2 = 0; if (!VAR_1)
goto fail; if (!seg->write_header_trailer) { if ((VAR_2 = segment_end(VAR_1, 0)) < 0)
goto fail; open_null_ctx(&VAR_1->pb); VAR_2 = av_write_trailer(VAR_1); close_null_ctx(VAR_1->pb); } else { VAR_2 = segment_end(VAR_1, 1); } if (VAR_2 < 0)
goto fail; if (seg->list && seg->list_type == LIST_HLS) { if ((VAR_2 = segment_hls_window(VAR_0, 1) < 0))
goto fail; } fail:
avio_close(seg->pb); avformat_free_context(VAR_1); return VAR_2; }