static int64_t mpegts_get_pcr(AVFormatContext *s, int stream_index,
                              int64_t *ppos, int64_t pos_limit)
{
    MpegTSContext *ts = s->priv_data;
    int64_t pos, timestamp;
    uint8_t buf[TS_PACKET_SIZE];
    int pcr_l, pcr_pid = ((PESContext*)s->streams[stream_index]->priv_data)->pcr_pid;
    const int find_next= 1;
    pos = ((*ppos  + ts->raw_packet_size - 1) / ts->raw_packet_size) * ts->raw_packet_size;
    if (find_next) {
        for(;;) {
            url_fseek(s->pb, pos, SEEK_SET);
            if (get_buffer(s->pb, buf, TS_PACKET_SIZE) != TS_PACKET_SIZE)
                return AV_NOPTS_VALUE;
            if ((pcr_pid < 0 || (AV_RB16(buf + 1) & 0x1fff) == pcr_pid) &&
                parse_pcr(&timestamp, &pcr_l, buf) == 0) {
                break;
            }
            pos += ts->raw_packet_size;
        }
    } else {
        for(;;) {
            pos -= ts->raw_packet_size;
            if (pos < 0)
                return AV_NOPTS_VALUE;
            url_fseek(s->pb, pos, SEEK_SET);
            if (get_buffer(s->pb, buf, TS_PACKET_SIZE) != TS_PACKET_SIZE)
                return AV_NOPTS_VALUE;
            if ((pcr_pid < 0 || (AV_RB16(buf + 1) & 0x1fff) == pcr_pid) &&
                parse_pcr(&timestamp, &pcr_l, buf) == 0) {
                break;
            }
        }
    }
    *ppos = pos;
    return timestamp;
}
['static int64_t mpegts_get_pcr(AVFormatContext *s, int stream_index,\n                              int64_t *ppos, int64_t pos_limit)\n{\n    MpegTSContext *ts = s->priv_data;\n    int64_t pos, timestamp;\n    uint8_t buf[TS_PACKET_SIZE];\n    int pcr_l, pcr_pid = ((PESContext*)s->streams[stream_index]->priv_data)->pcr_pid;\n    const int find_next= 1;\n    pos = ((*ppos  + ts->raw_packet_size - 1) / ts->raw_packet_size) * ts->raw_packet_size;\n    if (find_next) {\n        for(;;) {\n            url_fseek(s->pb, pos, SEEK_SET);\n            if (get_buffer(s->pb, buf, TS_PACKET_SIZE) != TS_PACKET_SIZE)\n                return AV_NOPTS_VALUE;\n            if ((pcr_pid < 0 || (AV_RB16(buf + 1) & 0x1fff) == pcr_pid) &&\n                parse_pcr(&timestamp, &pcr_l, buf) == 0) {\n                break;\n            }\n            pos += ts->raw_packet_size;\n        }\n    } else {\n        for(;;) {\n            pos -= ts->raw_packet_size;\n            if (pos < 0)\n                return AV_NOPTS_VALUE;\n            url_fseek(s->pb, pos, SEEK_SET);\n            if (get_buffer(s->pb, buf, TS_PACKET_SIZE) != TS_PACKET_SIZE)\n                return AV_NOPTS_VALUE;\n            if ((pcr_pid < 0 || (AV_RB16(buf + 1) & 0x1fff) == pcr_pid) &&\n                parse_pcr(&timestamp, &pcr_l, buf) == 0) {\n                break;\n            }\n        }\n    }\n    *ppos = pos;\n    return timestamp;\n}']