static int handle_packets(MpegTSContext *ts, int nb_packets)

{

    AVFormatContext *s = ts->stream;

    uint8_t packet[TS_PACKET_SIZE];

    int packet_num, ret = 0;



    if (avio_tell(s->pb) != ts->last_pos) {

        int i;

        av_dlog(ts->stream, "Skipping after seek\n");

        /* seek detected, flush pes buffer */

        for (i = 0; i < NB_PID_MAX; i++) {

            if (ts->pids[i]) {

                if (ts->pids[i]->type == MPEGTS_PES) {

                   PESContext *pes = ts->pids[i]->u.pes_filter.opaque;

                   av_freep(&pes->buffer);

                   pes->data_index = 0;

                   pes->state = MPEGTS_SKIP; /* skip until pes header */

                }

                ts->pids[i]->last_cc = -1;

            }

        }

    }



    ts->stop_parse = 0;

    packet_num = 0;

    for(;;) {

        if (ts->stop_parse>0)

            break;

        packet_num++;

        if (nb_packets != 0 && packet_num >= nb_packets)

            break;

        ret = read_packet(s, packet, ts->raw_packet_size);

        if (ret != 0)

            break;

        ret = handle_packet(ts, packet);

        if (ret != 0)

            break;

    }

    ts->last_pos = avio_tell(s->pb);

    return ret;

}

static int handle_packets(MpegTSContext *ts, int nb_packets)

{

    AVFormatContext *s = ts->stream;

    uint8_t packet[TS_PACKET_SIZE];

    int packet_num, ret = 0;



    if (avio_tell(s->pb) != ts->last_pos) {

        int i;

        av_dlog(ts->stream, "Skipping after seek\n");

        

        for (i = 0; i < NB_PID_MAX; i++) {

            if (ts->pids[i]) {

                if (ts->pids[i]->type == MPEGTS_PES) {

                   PESContext *pes = ts->pids[i]->u.pes_filter.opaque;

                   av_freep(&pes->buffer);

                   pes->data_index = 0;

                   pes->state = MPEGTS_SKIP; 

                }

                ts->pids[i]->last_cc = -1;

            }

        }

    }



    ts->stop_parse = 0;

    packet_num = 0;

    for(;;) {

        if (ts->stop_parse>0)

            break;

        packet_num++;

        if (nb_packets != 0 && packet_num >= nb_packets)

            break;

        ret = read_packet(s, packet, ts->raw_packet_size);

        if (ret != 0)

            break;

        ret = handle_packet(ts, packet);

        if (ret != 0)

            break;

    }

    ts->last_pos = avio_tell(s->pb);

    return ret;

}

    uint8_t packet[TS_PACKET_SIZE];
static int FUNC_0(MpegTSContext *VAR_0, int VAR_1)

{

    AVFormatContext *s = VAR_0->stream;

    uint8_t packet[TS_PACKET_SIZE];

    int VAR_2, VAR_3 = 0;



    if (avio_tell(s->pb) != VAR_0->last_pos) {

        int VAR_4;

        av_dlog(VAR_0->stream, "Skipping after seek\n");

        

        for (VAR_4 = 0; VAR_4 < NB_PID_MAX; VAR_4++) {

            if (VAR_0->pids[VAR_4]) {

                if (VAR_0->pids[VAR_4]->type == MPEGTS_PES) {

                   PESContext *pes = VAR_0->pids[VAR_4]->u.pes_filter.opaque;

                   av_freep(&pes->buffer);

                   pes->data_index = 0;

                   pes->state = MPEGTS_SKIP; 

                }

                VAR_0->pids[VAR_4]->last_cc = -1;

            }

        }

    }



    VAR_0->stop_parse = 0;

    VAR_2 = 0;

    for(;;) {

        if (VAR_0->stop_parse>0)

            break;

        VAR_2++;

        if (VAR_1 != 0 && VAR_2 >= VAR_1)

            break;

        VAR_3 = read_packet(s, packet, VAR_0->raw_packet_size);

        if (VAR_3 != 0)

            break;

        VAR_3 = handle_packet(VAR_0, packet);

        if (VAR_3 != 0)

            break;

    }

    VAR_0->last_pos = avio_tell(s->pb);

    return VAR_3;

}

static int FUNC_0(MpegTSContext *VAR_0, int VAR_1)
{ AVFormatContext *s = VAR_0->stream; uint8_t packet[TS_PACKET_SIZE]; int VAR_2, VAR_3 = 0; if (avio_tell(s->pb) != VAR_0->last_pos) { int VAR_4; av_dlog(VAR_0->stream, "Skipping after seek\n"); for (VAR_4 = 0; VAR_4 < NB_PID_MAX; VAR_4++) { if (VAR_0->pids[VAR_4]) { if (VAR_0->pids[VAR_4]->type == MPEGTS_PES) { PESContext *pes = VAR_0->pids[VAR_4]->u.pes_filter.opaque; av_freep(&pes->buffer); pes->data_index = 0; pes->state = MPEGTS_SKIP; } VAR_0->pids[VAR_4]->last_cc = -1; } } } VAR_0->stop_parse = 0; VAR_2 = 0; for(;;) { if (VAR_0->stop_parse>0)
break; VAR_2++; if (VAR_1 != 0 && VAR_2 >= VAR_1)
break; VAR_3 = read_packet(s, packet, VAR_0->raw_packet_size); if (VAR_3 != 0)
break; VAR_3 = handle_packet(VAR_0, packet); if (VAR_3 != 0)
break; } VAR_0->last_pos = avio_tell(s->pb); return VAR_3; }