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

{

    HLSContext *c = s->priv_data;

    int ret, i, minvariant = -1;



    if (c->first_packet) {

        recheck_discard_flags(s, 1);

        c->first_packet = 0;

    }



start:

    c->end_of_segment = 0;

    for (i = 0; i < c->n_variants; i++) {

        struct variant *var = c->variants[i];

        /* Make sure we've got one buffered packet from each open variant

         * stream */

        if (var->needed && !var->pkt.data) {

            while (1) {

                int64_t ts_diff;

                AVStream *st;

                ret = av_read_frame(var->ctx, &var->pkt);

                if (ret < 0) {

                    if (!var->pb.eof_reached)

                        return ret;


                    break;

                } else {

                    if (c->first_timestamp == AV_NOPTS_VALUE &&

                        var->pkt.dts       != AV_NOPTS_VALUE)

                        c->first_timestamp = av_rescale_q(var->pkt.dts,

                            var->ctx->streams[var->pkt.stream_index]->time_base,

                            AV_TIME_BASE_Q);

                }



                if (c->seek_timestamp == AV_NOPTS_VALUE)

                    break;



                if (var->pkt.dts == AV_NOPTS_VALUE) {

                    c->seek_timestamp = AV_NOPTS_VALUE;

                    break;

                }



                st = var->ctx->streams[var->pkt.stream_index];

                ts_diff = av_rescale_rnd(var->pkt.dts, AV_TIME_BASE,

                                         st->time_base.den, AV_ROUND_DOWN) -

                          c->seek_timestamp;

                if (ts_diff >= 0 && (c->seek_flags  & AVSEEK_FLAG_ANY ||

                                     var->pkt.flags & AV_PKT_FLAG_KEY)) {

                    c->seek_timestamp = AV_NOPTS_VALUE;

                    break;

                }



            }

        }

        /* Check if this stream still is on an earlier segment number, or

         * has the packet with the lowest dts */

        if (var->pkt.data) {

            struct variant *minvar = c->variants[minvariant];

            if (minvariant < 0 || var->cur_seq_no < minvar->cur_seq_no) {

                minvariant = i;

            } else if (var->cur_seq_no == minvar->cur_seq_no) {

                int64_t dts     =    var->pkt.dts;

                int64_t mindts  = minvar->pkt.dts;

                AVStream *st    =    var->ctx->streams[var->pkt.stream_index];

                AVStream *minst = minvar->ctx->streams[minvar->pkt.stream_index];



                if (dts == AV_NOPTS_VALUE) {

                    minvariant = i;

                } else if (mindts != AV_NOPTS_VALUE) {

                    if (st->start_time    != AV_NOPTS_VALUE)

                        dts    -= st->start_time;

                    if (minst->start_time != AV_NOPTS_VALUE)

                        mindts -= minst->start_time;



                    if (av_compare_ts(dts, st->time_base,

                                      mindts, minst->time_base) < 0)

                        minvariant = i;

                }

            }

        }

    }

    if (c->end_of_segment) {

        if (recheck_discard_flags(s, 0))

            goto start;

    }

    /* If we got a packet, return it */

    if (minvariant >= 0) {

        *pkt = c->variants[minvariant]->pkt;

        pkt->stream_index += c->variants[minvariant]->stream_offset;

        reset_packet(&c->variants[minvariant]->pkt);

        return 0;

    }

    return AVERROR_EOF;

}
static int hls_read_packet(AVFormatContext *s, AVPacket *pkt)

{

    HLSContext *c = s->priv_data;

    int ret, i, minvariant = -1;



    if (c->first_packet) {

        recheck_discard_flags(s, 1);

        c->first_packet = 0;

    }



start:

    c->end_of_segment = 0;

    for (i = 0; i < c->n_variants; i++) {

        struct variant *var = c->variants[i];

        



        if (var->needed && !var->pkt.data) {

            while (1) {

                int64_t ts_diff;

                AVStream *st;

                ret = av_read_frame(var->ctx, &var->pkt);

                if (ret < 0) {

                    if (!var->pb.eof_reached)

                        return ret;


                    break;

                } else {

                    if (c->first_timestamp == AV_NOPTS_VALUE &&

                        var->pkt.dts       != AV_NOPTS_VALUE)

                        c->first_timestamp = av_rescale_q(var->pkt.dts,

                            var->ctx->streams[var->pkt.stream_index]->time_base,

                            AV_TIME_BASE_Q);

                }



                if (c->seek_timestamp == AV_NOPTS_VALUE)

                    break;



                if (var->pkt.dts == AV_NOPTS_VALUE) {

                    c->seek_timestamp = AV_NOPTS_VALUE;

                    break;

                }



                st = var->ctx->streams[var->pkt.stream_index];

                ts_diff = av_rescale_rnd(var->pkt.dts, AV_TIME_BASE,

                                         st->time_base.den, AV_ROUND_DOWN) -

                          c->seek_timestamp;

                if (ts_diff >= 0 && (c->seek_flags  & AVSEEK_FLAG_ANY ||

                                     var->pkt.flags & AV_PKT_FLAG_KEY)) {

                    c->seek_timestamp = AV_NOPTS_VALUE;

                    break;

                }



            }

        }

        



        if (var->pkt.data) {

            struct variant *minvar = c->variants[minvariant];

            if (minvariant < 0 || var->cur_seq_no < minvar->cur_seq_no) {

                minvariant = i;

            } else if (var->cur_seq_no == minvar->cur_seq_no) {

                int64_t dts     =    var->pkt.dts;

                int64_t mindts  = minvar->pkt.dts;

                AVStream *st    =    var->ctx->streams[var->pkt.stream_index];

                AVStream *minst = minvar->ctx->streams[minvar->pkt.stream_index];



                if (dts == AV_NOPTS_VALUE) {

                    minvariant = i;

                } else if (mindts != AV_NOPTS_VALUE) {

                    if (st->start_time    != AV_NOPTS_VALUE)

                        dts    -= st->start_time;

                    if (minst->start_time != AV_NOPTS_VALUE)

                        mindts -= minst->start_time;



                    if (av_compare_ts(dts, st->time_base,

                                      mindts, minst->time_base) < 0)

                        minvariant = i;

                }

            }

        }

    }

    if (c->end_of_segment) {

        if (recheck_discard_flags(s, 0))

            goto start;

    }

    

    if (minvariant >= 0) {

        *pkt = c->variants[minvariant]->pkt;

        pkt->stream_index += c->variants[minvariant]->stream_offset;

        reset_packet(&c->variants[minvariant]->pkt);

        return 0;

    }

    return AVERROR_EOF;

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

{

    HLSContext *c = VAR_0->priv_data;

    int VAR_2, VAR_3, VAR_4 = -1;



    if (c->first_packet) {

        recheck_discard_flags(VAR_0, 1);

        c->first_packet = 0;

    }



start:

    c->end_of_segment = 0;

    for (VAR_3 = 0; VAR_3 < c->n_variants; VAR_3++) {

        struct variant *var = c->variants[VAR_3];

        



        if (var->needed && !var->VAR_1.data) {

            while (1) {

                int64_t ts_diff;

                AVStream *st;

                VAR_2 = av_read_frame(var->ctx, &var->VAR_1);

                if (VAR_2 < 0) {

                    if (!var->pb.eof_reached)

                        return VAR_2;


                    break;

                } else {

                    if (c->first_timestamp == AV_NOPTS_VALUE &&

                        var->VAR_1.dts       != AV_NOPTS_VALUE)

                        c->first_timestamp = av_rescale_q(var->VAR_1.dts,

                            var->ctx->streams[var->VAR_1.stream_index]->time_base,

                            AV_TIME_BASE_Q);

                }



                if (c->seek_timestamp == AV_NOPTS_VALUE)

                    break;



                if (var->VAR_1.dts == AV_NOPTS_VALUE) {

                    c->seek_timestamp = AV_NOPTS_VALUE;

                    break;

                }



                st = var->ctx->streams[var->VAR_1.stream_index];

                ts_diff = av_rescale_rnd(var->VAR_1.dts, AV_TIME_BASE,

                                         st->time_base.den, AV_ROUND_DOWN) -

                          c->seek_timestamp;

                if (ts_diff >= 0 && (c->seek_flags  & AVSEEK_FLAG_ANY ||

                                     var->VAR_1.flags & AV_PKT_FLAG_KEY)) {

                    c->seek_timestamp = AV_NOPTS_VALUE;

                    break;

                }



            }

        }

        



        if (var->VAR_1.data) {

            struct variant *minvar = c->variants[VAR_4];

            if (VAR_4 < 0 || var->cur_seq_no < minvar->cur_seq_no) {

                VAR_4 = VAR_3;

            } else if (var->cur_seq_no == minvar->cur_seq_no) {

                int64_t dts     =    var->VAR_1.dts;

                int64_t mindts  = minvar->VAR_1.dts;

                AVStream *st    =    var->ctx->streams[var->VAR_1.stream_index];

                AVStream *minst = minvar->ctx->streams[minvar->VAR_1.stream_index];



                if (dts == AV_NOPTS_VALUE) {

                    VAR_4 = VAR_3;

                } else if (mindts != AV_NOPTS_VALUE) {

                    if (st->start_time    != AV_NOPTS_VALUE)

                        dts    -= st->start_time;

                    if (minst->start_time != AV_NOPTS_VALUE)

                        mindts -= minst->start_time;



                    if (av_compare_ts(dts, st->time_base,

                                      mindts, minst->time_base) < 0)

                        VAR_4 = VAR_3;

                }

            }

        }

    }

    if (c->end_of_segment) {

        if (recheck_discard_flags(VAR_0, 0))

            goto start;

    }

    

    if (VAR_4 >= 0) {

        *VAR_1 = c->variants[VAR_4]->VAR_1;

        VAR_1->stream_index += c->variants[VAR_4]->stream_offset;

        reset_packet(&c->variants[VAR_4]->VAR_1);

        return 0;

    }

    return AVERROR_EOF;

}
static int FUNC_0(AVFormatContext *VAR_0, AVPacket *VAR_1)
{ HLSContext *c = VAR_0->priv_data; int VAR_2, VAR_3, VAR_4 = -1; if (c->first_packet) { recheck_discard_flags(VAR_0, 1); c->first_packet = 0; } start:
c->end_of_segment = 0; for (VAR_3 = 0; VAR_3 < c->n_variants; VAR_3++) { struct variant *var = c->variants[VAR_3]; if (var->needed && !var->VAR_1.data) { while (1) { int64_t ts_diff; AVStream *st; VAR_2 = av_read_frame(var->ctx, &var->VAR_1); if (VAR_2 < 0) { if (!var->pb.eof_reached)
return VAR_2; break; } else { if (c->first_timestamp == AV_NOPTS_VALUE &&
var->VAR_1.dts       != AV_NOPTS_VALUE)
c->first_timestamp = av_rescale_q(var->VAR_1.dts,
var->ctx->streams[var->VAR_1.stream_index]->time_base,
AV_TIME_BASE_Q); } if (c->seek_timestamp == AV_NOPTS_VALUE)
break; if (var->VAR_1.dts == AV_NOPTS_VALUE) { c->seek_timestamp = AV_NOPTS_VALUE; break; } st = var->ctx->streams[var->VAR_1.stream_index]; ts_diff = av_rescale_rnd(var->VAR_1.dts, AV_TIME_BASE,
st->time_base.den, AV_ROUND_DOWN) -
c->seek_timestamp; if (ts_diff >= 0 && (c->seek_flags  & AVSEEK_FLAG_ANY ||
var->VAR_1.flags & AV_PKT_FLAG_KEY)) { c->seek_timestamp = AV_NOPTS_VALUE; break; } } } if (var->VAR_1.data) { struct variant *minvar = c->variants[VAR_4]; if (VAR_4 < 0 || var->cur_seq_no < minvar->cur_seq_no) { VAR_4 = VAR_3; } else if (var->cur_seq_no == minvar->cur_seq_no) { int64_t dts     =    var->VAR_1.dts; int64_t mindts  = minvar->VAR_1.dts; AVStream *st    =    var->ctx->streams[var->VAR_1.stream_index]; AVStream *minst = minvar->ctx->streams[minvar->VAR_1.stream_index]; if (dts == AV_NOPTS_VALUE) { VAR_4 = VAR_3; } else if (mindts != AV_NOPTS_VALUE) { if (st->start_time    != AV_NOPTS_VALUE)
dts    -= st->start_time; if (minst->start_time != AV_NOPTS_VALUE)
mindts -= minst->start_time; if (av_compare_ts(dts, st->time_base,
mindts, minst->time_base) < 0)
VAR_4 = VAR_3; } } } } if (c->end_of_segment) { if (recheck_discard_flags(VAR_0, 0))
goto start; } if (VAR_4 >= 0) { *VAR_1 = c->variants[VAR_4]->VAR_1; VAR_1->stream_index += c->variants[VAR_4]->stream_offset; reset_packet(&c->variants[VAR_4]->VAR_1); return 0; } return AVERROR_EOF; }