# HG changeset patch # User michael # Date 1086022620 0 # Node ID 2846bb67dd8f69ce8d8996e2a2910ca44a56e62d # Parent e0a66a870b7f0228a9249260bbbc90965b027c20 fix playback of http://www.zonque.org/test-long.ps better seeking, (not to keyframes but at least to the start of packets ...) diff -r e0a66a870b7f -r 2846bb67dd8f mpegts.c --- a/mpegts.c Sun May 30 20:37:15 2004 +0000 +++ b/mpegts.c Mon May 31 16:57:00 2004 +0000 @@ -1080,10 +1080,10 @@ MpegTSContext *ts = s->priv_data; ByteIOContext *pb = &s->pb; uint8_t buf[1024]; - int len, sid; + int len, sid, i; int64_t pos; MpegTSService *service; - + if (ap) { ts->mpeg2ts_raw = ap->mpeg2ts_raw; ts->mpeg2ts_compute_pcr = ap->mpeg2ts_compute_pcr; @@ -1135,21 +1135,23 @@ } /* tune to first service found */ - service = ts->services[0]; - sid = service->sid; + for(i=0; inb_services && ts->set_service_ret; i++){ + service = ts->services[i]; + sid = service->sid; #ifdef DEBUG_SI - printf("tuning to '%s'\n", service->name); + printf("tuning to '%s'\n", service->name); #endif - /* now find the info for the first service if we found any, - otherwise try to filter all PATs */ + /* now find the info for the first service if we found any, + otherwise try to filter all PATs */ + + url_fseek(pb, pos, SEEK_SET); + mpegts_set_service(ts, sid, set_service_cb, ts); + + handle_packets(ts, MAX_SCAN_PACKETS); + } + /* if could not find service, exit */ - url_fseek(pb, pos, SEEK_SET); - mpegts_set_service(ts, sid, set_service_cb, ts); - - handle_packets(ts, MAX_SCAN_PACKETS); - - /* if could not find service, exit */ if (ts->set_service_ret != 0) return -1; @@ -1324,6 +1326,29 @@ return timestamp; } +static int read_seek(AVFormatContext *s, int stream_index, int64_t target_ts){ + MpegTSContext *ts = s->priv_data; + uint8_t buf[TS_PACKET_SIZE]; + int64_t pos; + + if(av_seek_frame_binary(s, stream_index, target_ts) < 0) + return -1; + + pos= url_ftell(&s->pb); + + for(;;) { + url_fseek(&s->pb, pos, SEEK_SET); + if (get_buffer(&s->pb, buf, TS_PACKET_SIZE) != TS_PACKET_SIZE) + return -1; +// pid = ((buf[1] & 0x1f) << 8) | buf[2]; + if(buf[1] & 0x40) break; + pos += ts->raw_packet_size; + } + url_fseek(&s->pb, pos, SEEK_SET); + + return 0; +} + /**************************************************************/ /* parsing functions - called from other demuxers such as RTP */ @@ -1385,7 +1410,7 @@ mpegts_read_header, mpegts_read_packet, mpegts_read_close, - NULL, //mpegts_read_seek, + read_seek, mpegts_get_pcr, .flags = AVFMT_SHOW_IDS, };