Permalink
Browse files

Merge branch 'master' of github.com:eastein/zmstream

Conflicts:
	zmstream.py
  • Loading branch information...
2 parents d22d22e + 583562f commit 5cae17c7150e250cd926c6287a4533469c194f2b @eastein committed Aug 26, 2011
Showing with 46 additions and 13 deletions.
  1. +1 −0 .gitignore
  2. +0 −12 README
  3. +15 −0 README.md
  4. +13 −0 README.txt
  5. +17 −1 zmstream.py
View
@@ -0,0 +1 @@
+*.pyc
View
@@ -1,12 +0,0 @@
-ZMStream is a library for creating creating an iterable object for image
-frames from a ZoneMinder stream.
-
-Platforms
--------------------
-
-ZMStream has been tested to work on Ubuntu 10.04.
-
-Examples
--------------------
-
-Please see test.py for an example.
View
@@ -0,0 +1,15 @@
+ZMStream is a library for creating creating an iterable object for image
+frames from a ZoneMinder stream.
+
+<A name="toc2-4" title="Platforms" />
+Platforms
+-------------------
+
+ZMStream has been tested to work on Ubuntu 10.04 and Debian Squeeze, using CPython 2.6.
+
+<A name="toc2-10" title="Examples" />
+Examples
+-------------------
+
+* Please see test.py for an example.
+* Another use case for zmstream is lidless (https://github.com/eastein/lidless).
View
@@ -0,0 +1,13 @@
+ZMStream is a library for creating creating an iterable object for image
+frames from a ZoneMinder stream.
+
+Platforms
+-------------------
+
+ZMStream has been tested to work on Ubuntu 10.04 and Debian Squeeze, using CPython 2.6.
+
+Examples
+-------------------
+
+* Please see test.py for an example.
+* Another use case for zmstream is lidless (https://github.com/eastein/lidless).
View
@@ -4,14 +4,18 @@
import time
import base64
+class Timeout(Exception) :
+ pass
+
class ZMStreamer(object) :
ST_FILE = 1
ST_SOCKET = 2
ZF_FRAME_HEADER = '--%s\r\n'
- def __init__(self, timeout, input_capture, auth=None, boundary=None) :
+ def __init__(self, timeout, input_capture, failure_timeout=10, auth=None, boundary=None) :
self.timeout = timeout
+ self.failure_timeout = failure_timeout
self.ok = True
self.auth = auth
if boundary :
@@ -50,6 +54,13 @@ def __init__(self, timeout, input_capture, auth=None, boundary=None) :
self.chunk = 1024
+ def __del__(self) :
+ if hasattr(self, 'fh') :
+ try :
+ self.fh.close()
+ except :
+ pass
+
def rf(self, size) :
if self.stream_type == self.ST_FILE :
r = self.fh.read(size)
@@ -94,11 +105,16 @@ def read_until(self, buf, including) :
def abortcheck(self) :
if not self.ok :
raise StopIteration
+ if hasattr(self, 'abort_ts') :
+ if time.time() > self.abort_ts :
+ raise Timeout
def generate(self) :
buf = ''
# first, read until there's a ZF_FRAME_HEADER
while True :
+ self.abort_ts = time.time() + self.failure_timeout
+
# we haven't already aligned to a zoneminder frame. align now.
buf = self.discard_until(buf, ZMStreamer.ZF_FRAME_HEADER % self.boundary)
header = True

0 comments on commit 5cae17c

Please sign in to comment.