本文整理汇总了Python中pyamf.util.BufferedByteStream类的典型用法代码示例。如果您正苦于以下问题:Python BufferedByteStream类的具体用法?Python BufferedByteStream怎么用?Python BufferedByteStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BufferedByteStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sendMessage
def sendMessage(self, msg, stream, whenDone=None):
"""
Queues L{msg} for encoding into RTMP and being spit out to L{output}.
This is a low level api and is not for public consumption. Use
L{interfaces.IStream.sendMessage} instead.
@param msg: The message being sent to the peer.
@type msg: L{message.IMessage}
@param stream: The stream instance that is sending the message.
@type stream: L{interfaces.IStream}
@param whenDone: A callback fired when the message has been written to
the RTMP stream. See L{BaseStream.sendMessage}
"""
buf = BufferedByteStream()
e = self.encoder
# this will probably need to be rethought as this could block for an
# unacceptable amount of time. For most messages however it seems to be
# fast enough and the penalty for setting up a new thread is too high.
msg.encode(buf)
e.send(buf.getvalue(), msg.__data_type__,
stream.streamId, stream.timestamp, whenDone)
if e.active and not self._encoding_task:
self.startEncoding()
示例2: sendMessage
def sendMessage(self, msg, stream, whenDone=None):
"""
Sends an RTMP message to the peer. Not part of a public api, use
C{stream.sendMessage} instead.
@param msg: The message being sent to the peer.
@type msg: L{message.IMessage}
@param stream: The stream instance that is sending the message.
@type stream: L{NetStream}
@param whenDone: A callback fired when the message has been written to
the RTMP stream. See L{BaseStream.sendMessage}
"""
buf = BufferedByteStream()
e = self.encoder
# this will probably need to be rethought as this could block for an
# unacceptable amount of time. For most messages however it seems to be
# fast enough and the penalty for setting up a new thread is too high.
msg.encode(buf)
e.send(buf.getvalue(), msg.__data_type__,
stream.streamId, stream.timestamp, whenDone)
if e.active and not self.encoder_task:
self.startEncoding()
示例3: test_assemble
def test_assemble(self):
for fixture in self.data:
buf = BufferedByteStream()
a = RTMPAssembler(128, buf)
for packet in fixture['packets']:
a.push_packet(packet)
buf.seek(0, 0)
self.failUnlessEqual(struct.pack("B" * len(fixture['data']), *fixture['data']), buf.read())
示例4: test_assemble_chunks
def test_assemble_chunks(self):
chunkSizes = (32, 64, 128, 256)
header = RTMPHeader(object_id=2, timestamp=9504486, length=10, type=0x04, stream_id=0)
for chunkSize in chunkSizes:
for l in xrange(1, 258):
data = ''.join([chr(random.randint(0, 255)) for x in xrange(l)])
buf = BufferedByteStream()
a = RTMPAssembler(chunkSize, buf)
a.push_packet(DataPacket(header=header, data=data))
buf.seek(0, 0)
self.failUnlessEqual(''.join(self.gen_packet("\x02\x91\x06\xe6\x00\x00\x01\x04\x00\x00\x00\x00", ["\xc2"], data, l, chunkSize)), buf.read())
示例5: startStreaming
def startStreaming(self):
"""
This must be called before any RTMP data is received.
"""
self.streamManager = self.buildStreamManager()
self.controlStream = self.streamManager.getControlStream()
self._decodingBuffer = BufferedByteStream()
self._encodingBuffer = BufferedByteStream()
self.decoder = codec.Decoder(self.getDispatcher(), self.streamManager, stream=self._decodingBuffer)
self.encoder = codec.Encoder(self.getWriter(), stream=self._encodingBuffer)
self.decoder_task = None
self.encoder_task = None
示例6: _BackRelay
class _BackRelay(protocol.ProcessProtocol):
def __init__(self, deferred):
self.deferred = deferred
self.s = BufferedByteStream()
def errReceived(self, text):
self.deferred.errback(failure.Failure(IOError()))
self.deferred = None
self.transport.loseConnection()
def outReceived(self, text):
self.s.write(text)
def processEnded(self, reason):
if self.deferred is not None:
result = self.s.getvalue()
self.deferred.callback(result)
示例7: connectionMade
def connectionMade(self):
"""
Successfully connected to peer.
"""
self.input = RTMPDisassembler(constants.DEFAULT_CHUNK_SIZE)
self.output = RTMPAssembler(constants.DEFAULT_CHUNK_SIZE, self.transport)
self.state = self.State.HANDSHAKE_SEND
self.handshakeTimeout = reactor.callLater(config.getint('RTMP', 'handshakeTimeout'), self._handshakeTimedout)
self.handshakeBuf = BufferedByteStream()
self._beginHandshake()
示例8: __init__
def __init__(self, chunkSize):
"""
Constructor.
@param chunkSize: initial size of chunk
@type chunkSize: C{int}
"""
self.lastHeaders = {}
self.pool = {}
self.chunkSize = chunkSize
self.buffer = BufferedByteStream()
示例9: start
def start(self, uptime=0, version=0):
"""
Called to start the handshaking negotiations.
"""
if self.started:
raise AlreadyStarted('Handshake negotiator cannot be restarted')
self.started = True
self.uptime = uptime
self.version = version
self._buffer = BufferedByteStream()
示例10: write
def write(self):
"""
Encode packet into bytes.
@return: representation of packet
@rtype: C{str}
"""
buf = BufferedByteStream()
buf.write_ushort(self.event)
for val in self.data:
buf.write_ulong(val)
self.header.length = len(buf)
buf.seek(0, 0)
return buf.read()
示例11: ProducingChannel
class ProducingChannel(BaseChannel):
"""
Writes RTMP frames.
@ivar buffer: Any data waiting to be written to the underlying stream.
@type buffer: L{BufferedByteStream}
@ivar acquired: Whether this channel is acquired. See L{ChannelMuxer.
acquireChannel}
"""
def __init__(self, channelId, stream, frameSize):
BaseChannel.__init__(self, channelId, stream, frameSize)
self.buffer = BufferedByteStream()
self.acquired = False
self.callback = None
def setCallback(self, cb):
"""
Sets the callback that will be fired once this channel has been completely
encoded.
"""
self.callback = cb
def reset(self):
"""
Called when the channel has completed writing the buffer.
"""
BaseChannel.reset(self)
self.buffer.seek(0)
self.buffer.truncate()
self.header = None
def append(self, data):
"""
Appends data to the buffer in preparation of encoding in RTMP.
"""
self.buffer.append(data)
def marshallFrame(self, size):
"""
Writes a section of the buffer as part of the RTMP frame.
"""
self.stream.write(self.buffer.read(size))
示例12: __init__
def __init__(self, channel, streamId, output):
self.type = None
self.channel = channel
self.streamId = streamId
self.output = output
self.stream = BufferedByteStream()
self._lastHeader = None
self._oldStream = channel.stream
channel.stream = self.stream
h = header.Header(channel.channelId)
# encode a continuation header for speed
header.encode(self.stream, h, h)
self._continuationHeader = self.stream.getvalue()
self.stream.consume()
示例13: start
def start(self, uptime=None, version=None):
"""
Called to start the handshaking negotiations.
"""
if self.started:
raise HandshakeError('Handshake negotiator cannot be restarted')
self.started = True
self.buffer = BufferedByteStream()
self.peer_version = None
self.my_syn = Packet(uptime, version)
self.my_ack = None
self.peer_syn = None
self.peer_ack = None
self.buildSynPayload(self.my_syn)
self._writePacket(self.my_syn)
示例14: __init__
def __init__(self):
self.buffer = BufferedByteStream()
示例15: __init__
def __init__(self):
self.buffer = BufferedByteStream()
self.channels = {}
self.frameSize = FRAME_SIZE
self.bytes = 0