From d8f81e41871b0638ecf15de4cc14b426ab98381a Mon Sep 17 00:00:00 2001 From: John-Mark Gurney Date: Mon, 25 Feb 2008 01:41:36 -0800 Subject: [PATCH] make it cheaper to have the mpegtsmod loaded... We now do a quick check to make sure there are TS packets, before scanning the first 2megs in an expensive iter loop to find out that there are none... this makes things a lot faster... [git-p4: depot-paths = "//depot/": change = 1126] --- mpegtsmod.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/mpegtsmod.py b/mpegtsmod.py index 3ef734b..042ba35 100644 --- a/mpegtsmod.py +++ b/mpegtsmod.py @@ -344,7 +344,27 @@ class MultiMPEGTS(FSObject, StorageFolder): if doupdate: StorageFolder.doUpdate(self) +def findtsstream(fp, pktsz=188): + d = fp.read(200*pktsz) + i = 5 + pos = 0 + while i and pos < len(d) and pos != -1: + if d[pos] == 'G': + i -= 1 + pos += pktsz + else: + i = 5 + pos = d.find('G', pos + 1) + + if i or pos == -1: + return False + + return True + def detectmpegts(path, fobj): + if not findtsstream(fobj): + return None, None + f = mpegts.TSPStream(_LimitedFile(path, size= 2*1024*1024)) tvct = mpegts.GetTVCT(f)