static int seg_write_packet(AVFormatContext *s, AVPacket *pkt)

{

    SegmentContext *seg = s->priv_data;

    AVFormatContext *oc = seg->avf;

    AVStream *st = s->streams[pkt->stream_index];

    int64_t end_pts = seg->recording_time * seg->number;

    int ret, can_split = 1;



    if (!oc)

        return AVERROR(EINVAL);



    if (seg->has_video) {

        can_split = st->codec->codec_type == AVMEDIA_TYPE_VIDEO &&

                    pkt->flags & AV_PKT_FLAG_KEY;

    }



    if (can_split && av_compare_ts(pkt->pts, st->time_base, end_pts,

                                   AV_TIME_BASE_Q) >= 0) {

        av_log(s, AV_LOG_DEBUG, "Next segment starts at %d %"PRId64"\n",

               pkt->stream_index, pkt->pts);



        ret = segment_end(oc, seg->individual_header_trailer);



        if (!ret)

            ret = segment_start(s, seg->individual_header_trailer);



        if (ret)

            goto fail;



        oc = seg->avf;



        if (seg->list) {

            if (seg->list_type == LIST_HLS) {

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

                    goto fail;

            } else {

                avio_printf(seg->pb, "%s\n", oc->filename);

                avio_flush(seg->pb);

                if (seg->size && !(seg->number % seg->size)) {

                    avio_closep(&seg->pb);

                    if ((ret = avio_open2(&seg->pb, seg->list, AVIO_FLAG_WRITE,

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

                        goto fail;

                }

            }

        }

    }



    ret = ff_write_chained(oc, pkt->stream_index, pkt, s);



fail:

    if (ret < 0)

        seg_free_context(seg);



    return ret;

}

static int seg_write_packet(AVFormatContext *s, AVPacket *pkt)

{

    SegmentContext *seg = s->priv_data;

    AVFormatContext *oc = seg->avf;

    AVStream *st = s->streams[pkt->stream_index];

    int64_t end_pts = seg->recording_time * seg->number;

    int ret, can_split = 1;



    if (!oc)

        return AVERROR(EINVAL);



    if (seg->has_video) {

        can_split = st->codec->codec_type == AVMEDIA_TYPE_VIDEO &&

                    pkt->flags & AV_PKT_FLAG_KEY;

    }



    if (can_split && av_compare_ts(pkt->pts, st->time_base, end_pts,

                                   AV_TIME_BASE_Q) >= 0) {

        av_log(s, AV_LOG_DEBUG, "Next segment starts at %d %"PRId64"\n",

               pkt->stream_index, pkt->pts);



        ret = segment_end(oc, seg->individual_header_trailer);



        if (!ret)

            ret = segment_start(s, seg->individual_header_trailer);



        if (ret)

            goto fail;



        oc = seg->avf;



        if (seg->list) {

            if (seg->list_type == LIST_HLS) {

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

                    goto fail;

            } else {

                avio_printf(seg->pb, "%s\n", oc->filename);

                avio_flush(seg->pb);

                if (seg->size && !(seg->number % seg->size)) {

                    avio_closep(&seg->pb);

                    if ((ret = avio_open2(&seg->pb, seg->list, AVIO_FLAG_WRITE,

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

                        goto fail;

                }

            }

        }

    }



    ret = ff_write_chained(oc, pkt->stream_index, pkt, s);



fail:

    if (ret < 0)

        seg_free_context(seg);



    return ret;

}

static int FUNC_0(AVFormatContext *VAR_0, AVPacket *VAR_1)

{

    SegmentContext *seg = VAR_0->priv_data;

    AVFormatContext *oc = seg->avf;

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

    int64_t end_pts = seg->recording_time * seg->number;

    int VAR_2, VAR_3 = 1;



    if (!oc)

        return AVERROR(EINVAL);



    if (seg->has_video) {

        VAR_3 = st->codec->codec_type == AVMEDIA_TYPE_VIDEO &&

                    VAR_1->flags & AV_PKT_FLAG_KEY;

    }



    if (VAR_3 && av_compare_ts(VAR_1->pts, st->time_base, end_pts,

                                   AV_TIME_BASE_Q) >= 0) {

        av_log(VAR_0, AV_LOG_DEBUG, "Next segment starts at %d %"PRId64"\n",

               VAR_1->stream_index, VAR_1->pts);



        VAR_2 = segment_end(oc, seg->individual_header_trailer);



        if (!VAR_2)

            VAR_2 = segment_start(VAR_0, seg->individual_header_trailer);



        if (VAR_2)

            goto fail;



        oc = seg->avf;



        if (seg->list) {

            if (seg->list_type == LIST_HLS) {

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

                    goto fail;

            } else {

                avio_printf(seg->pb, "%VAR_0\n", oc->filename);

                avio_flush(seg->pb);

                if (seg->size && !(seg->number % seg->size)) {

                    avio_closep(&seg->pb);

                    if ((VAR_2 = avio_open2(&seg->pb, seg->list, AVIO_FLAG_WRITE,

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

                        goto fail;

                }

            }

        }

    }



    VAR_2 = ff_write_chained(oc, VAR_1->stream_index, VAR_1, VAR_0);



fail:

    if (VAR_2 < 0)

        seg_free_context(seg);



    return VAR_2;

}

static int FUNC_0(AVFormatContext *VAR_0, AVPacket *VAR_1)
{ SegmentContext *seg = VAR_0->priv_data; AVFormatContext *oc = seg->avf; AVStream *st = VAR_0->streams[VAR_1->stream_index]; int64_t end_pts = seg->recording_time * seg->number; int VAR_2, VAR_3 = 1; if (!oc)
return AVERROR(EINVAL); if (seg->has_video) { VAR_3 = st->codec->codec_type == AVMEDIA_TYPE_VIDEO &&
VAR_1->flags & AV_PKT_FLAG_KEY; } if (VAR_3 && av_compare_ts(VAR_1->pts, st->time_base, end_pts,
AV_TIME_BASE_Q) >= 0) { av_log(VAR_0, AV_LOG_DEBUG, "Next segment starts at %d %"PRId64"\n",
VAR_1->stream_index, VAR_1->pts); VAR_2 = segment_end(oc, seg->individual_header_trailer); if (!VAR_2)
VAR_2 = segment_start(VAR_0, seg->individual_header_trailer); if (VAR_2)
goto fail; oc = seg->avf; if (seg->list) { if (seg->list_type == LIST_HLS) { if ((VAR_2 = segment_hls_window(VAR_0, 0)) < 0)
goto fail; } else { avio_printf(seg->pb, "%VAR_0\n", oc->filename); avio_flush(seg->pb); if (seg->size && !(seg->number % seg->size)) { avio_closep(&seg->pb); if ((VAR_2 = avio_open2(&seg->pb, seg->list, AVIO_FLAG_WRITE,
&VAR_0->interrupt_callback, NULL)) < 0)
goto fail; } } } } VAR_2 = ff_write_chained(oc, VAR_1->stream_index, VAR_1, VAR_0); fail:
if (VAR_2 < 0)
seg_free_context(seg); return VAR_2; }