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

{

    HDSContext *c = s->priv_data;

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

    OutputStream *os = &c->streams[s->streams[pkt->stream_index]->id];

    int64_t end_dts = (os->fragment_index) * c->min_frag_duration;

    int ret;



    if (st->first_dts == AV_NOPTS_VALUE)

        st->first_dts = pkt->dts;



    if ((!os->has_video || st->codec->codec_type == AVMEDIA_TYPE_VIDEO) &&

        av_compare_ts(pkt->dts - st->first_dts, st->time_base,

                      end_dts, AV_TIME_BASE_Q) >= 0 &&

        pkt->flags & AV_PKT_FLAG_KEY && os->packets_written) {



        if ((ret = hds_flush(s, os, 0, pkt->dts)) < 0)

            return ret;

    }



    // Note, these fragment start timestamps, that represent a whole

    // OutputStream, assume all streams in it have the same time base.

    if (!os->packets_written)

        os->frag_start_ts = pkt->dts;

    os->last_ts = pkt->dts;



    os->packets_written++;

    return ff_write_chained(os->ctx, pkt->stream_index - os->first_stream, pkt, s);

}

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

{

    HDSContext *c = s->priv_data;

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

    OutputStream *os = &c->streams[s->streams[pkt->stream_index]->id];

    int64_t end_dts = (os->fragment_index) * c->min_frag_duration;

    int ret;



    if (st->first_dts == AV_NOPTS_VALUE)

        st->first_dts = pkt->dts;



    if ((!os->has_video || st->codec->codec_type == AVMEDIA_TYPE_VIDEO) &&

        av_compare_ts(pkt->dts - st->first_dts, st->time_base,

                      end_dts, AV_TIME_BASE_Q) >= 0 &&

        pkt->flags & AV_PKT_FLAG_KEY && os->packets_written) {



        if ((ret = hds_flush(s, os, 0, pkt->dts)) < 0)

            return ret;

    }



    

    

    if (!os->packets_written)

        os->frag_start_ts = pkt->dts;

    os->last_ts = pkt->dts;



    os->packets_written++;

    return ff_write_chained(os->ctx, pkt->stream_index - os->first_stream, pkt, s);

}

    int64_t end_dts = (os->fragment_index) * c->min_frag_duration;
static int FUNC_0(AVFormatContext *VAR_0, AVPacket *VAR_1)

{

    HDSContext *c = VAR_0->priv_data;

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

    OutputStream *os = &c->streams[VAR_0->streams[VAR_1->stream_index]->id];

    int64_t end_dts = (os->fragment_index) * c->min_frag_duration;

    int VAR_2;



    if (st->first_dts == AV_NOPTS_VALUE)

        st->first_dts = VAR_1->dts;



    if ((!os->has_video || st->codec->codec_type == AVMEDIA_TYPE_VIDEO) &&

        av_compare_ts(VAR_1->dts - st->first_dts, st->time_base,

                      end_dts, AV_TIME_BASE_Q) >= 0 &&

        VAR_1->flags & AV_PKT_FLAG_KEY && os->packets_written) {



        if ((VAR_2 = hds_flush(VAR_0, os, 0, VAR_1->dts)) < 0)

            return VAR_2;

    }



    

    

    if (!os->packets_written)

        os->frag_start_ts = VAR_1->dts;

    os->last_ts = VAR_1->dts;



    os->packets_written++;

    return ff_write_chained(os->ctx, VAR_1->stream_index - os->first_stream, VAR_1, VAR_0);

}

static int FUNC_0(AVFormatContext *VAR_0, AVPacket *VAR_1)
{ HDSContext *c = VAR_0->priv_data; AVStream *st = VAR_0->streams[VAR_1->stream_index]; OutputStream *os = &c->streams[VAR_0->streams[VAR_1->stream_index]->id]; int64_t end_dts = (os->fragment_index) * c->min_frag_duration; int VAR_2; if (st->first_dts == AV_NOPTS_VALUE)
st->first_dts = VAR_1->dts; if ((!os->has_video || st->codec->codec_type == AVMEDIA_TYPE_VIDEO) &&
av_compare_ts(VAR_1->dts - st->first_dts, st->time_base,
end_dts, AV_TIME_BASE_Q) >= 0 &&
VAR_1->flags & AV_PKT_FLAG_KEY && os->packets_written) { if ((VAR_2 = hds_flush(VAR_0, os, 0, VAR_1->dts)) < 0)
return VAR_2; } if (!os->packets_written)
os->frag_start_ts = VAR_1->dts; os->last_ts = VAR_1->dts; os->packets_written++; return ff_write_chained(os->ctx, VAR_1->stream_index - os->first_stream, VAR_1, VAR_0); }