From 2485b899c303f60a837baaaf704a3c8eb631ed9b Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 10 Nov 2017 12:11:33 +0100 Subject: demux: avoid wasting time by stopping packet search as early as possible The packet queue is sorted, so we can stop the search if we have found a packet, and the next packet in the queue has a higher PTS than the seek PTS (for the sake of SEEK_FORWARD, we still consider the first packet with a higher PTS). Also, as a mostly cosmetic change, but which might be "faster", check target for NULL, instead of target_diff for a magic float value. --- demux/demux.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'demux') diff --git a/demux/demux.c b/demux/demux.c index 42d083fea3..6070fd74a8 100644 --- a/demux/demux.c +++ b/demux/demux.c @@ -2131,7 +2131,7 @@ static struct demux_packet *find_seek_target(struct demux_queue *queue, if (diff > 0) continue; } - if (target_diff != MP_NOPTS_VALUE) { + if (target) { if (diff <= 0) { if (target_diff <= 0 && diff <= target_diff) continue; @@ -2140,6 +2140,8 @@ static struct demux_packet *find_seek_target(struct demux_queue *queue, } target_diff = diff; target = dp; + if (range_pts > pts) + break; } return target; -- cgit v1.2.3