class FLVReader(Resource): # Read a local FLV file, one message at a time, and implement inter-message wait. def __init__(self): Resource.__init__(self) self.type, self.mode, self._gen, self.id, self.client = 'file', 'r', None, 1, True def open(self, url): if _debug: print 'FLVReader.open', url yield # needed at least one yield in a generator self.url, u = url, urlparse.urlparse(url, 'file') self.fp = FLV().open(u.path) if self.fp: self._gen = self.fp.reader(self); multitask.add(self._gen) raise StopIteration, self else: raise StopIteration, None def close(self): if self.fp: self.fp.close(); self.fp = None if self._gen is not None: self._gen.close() yield # yield is needed since there is no other blocking operation def send(self, msg): def sendInternal(self, msg): yield self.queue.put(msg) if msg.type in (Message.RPC, Message.RPC3): cmd = Command.fromMessage(msg) if cmd.name == 'onStatus' and len(cmd.args) > 0 and hasattr(cmd.args[0], 'code') and cmd.args[ 0].code == 'NetStream.Play.Stop': msg = False # indicates end of file multitask.add(sendInternal(self, msg))
def open(self, url): if _debug: print 'FLVReader.open', url self.url, u = url, urlparse.urlparse(url, 'file') self.fp = FLV().open(u.path) if self.fp: self._gen = self.fp.reader(self); multitask.add(self._gen) raise StopIteration, self else: raise StopIteration, None
class FLVWriter(Resource): # Write a local FLV file. def __init__(self): Resource.__init__(self) self.type, self.mode = 'file', 'w' def open(self, url): if _debug: print 'FLVWrite.open', url self.url, u = url, urlparse.urlparse(url, 'file') self.fp = FLV().open(u.path, 'record'); yield # yield is needed since there is no other blocking operation. raise StopIteration, self if self.fp else None def close(self): if self.fp is not None: self.fp.close(); self.fp = None yield # yield is needed since there is no other blocking operation def put(self, item): if self.fp is not None: self.fp.write(item) yield # yield is needed since there is no other blocking operation
class FLVReader( Resource ): # Read a local FLV file, one message at a time, and implement inter-message wait. def __init__(self): Resource.__init__(self) self.type, self.mode, self._gen, self.id, self.client = 'file', 'r', None, 1, True def open(self, url): if _debug: print 'FLVReader.open', url yield # needed at least one yield in a generator self.url, u = url, urlparse.urlparse(url, 'file') self.fp = FLV().open(u.path) if self.fp: self._gen = self.fp.reader(self) multitask.add(self._gen) raise StopIteration, self else: raise StopIteration, None def close(self): if self.fp: self.fp.close() self.fp = None if self._gen is not None: self._gen.close() yield # yield is needed since there is no other blocking operation def send(self, msg): def sendInternal(self, msg): yield self.queue.put(msg) if msg.type in (Message.RPC, Message.RPC3): cmd = Command.fromMessage(msg) if cmd.name == 'onStatus' and len(cmd.args) > 0 and hasattr( cmd.args[0], 'code') and cmd.args[0].code == 'NetStream.Play.Stop': msg = False # indicates end of file multitask.add(sendInternal(self, msg))
def open(self, url): if _debug: print 'FLVWrite.open', url self.url, u = url, urlparse.urlparse(url, 'file') self.fp = FLV().open(u.path, 'record') yield # yield is needed since there is no other blocking operation. raise StopIteration, self if self.fp else None
def open(self, url): if _debug: print 'FLVWrite.open', url self.url, u = url, urlparse.urlparse(url, 'file') self.fp = FLV().open(u.path, 'record'); yield # yield is needed since there is no other blocking operation. raise StopIteration, self if self.fp else None