The common case of the pointer having increased by one packet (which results
in no change to the modulus) can be detected with a 64-bit subtraction,
which is far cheaper than a division on many platforms.
Before After
Mean StdDev Mean StdDev Change
Divisions 248.3 8.8 51.5 7.4 +381.7%
Overall 2773.2 25.6 2372.5 43.1 +16.9%
---
libavformat/mpegts.c | 6 +++++-
1 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index 1540a8d..8e548d9 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -98,6 +98,8 @@ struct MpegTSContext {
int raw_packet_size;
int pos47;
+ /** position corresponding to pos47, or 0 if pos47 invalid */
+ int64_t pos;
/** if true, all pids are analyzed to find streams */
int auto_guess;
@@ -1683,7 +1685,9 @@ static int handle_packet(MpegTSContext *ts, const uint8_t
*packet)
return 0;
pos = avio_tell(ts->stream->pb);
- ts->pos47= pos % ts->raw_packet_size;
+ if (ts->pos == 0 || pos - ts->pos != ts->raw_packet_size)
+ ts->pos47 = pos % ts->raw_packet_size;
+ ts->pos = pos;
if (tss->type == MPEGTS_SECTION) {
if (is_start) {
--
1.7.5.4
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel