当前位置: 首页>>代码示例>>Python>>正文


Python BufferedByteStream.truncate方法代码示例

本文整理汇总了Python中pyamf.util.BufferedByteStream.truncate方法的典型用法代码示例。如果您正苦于以下问题:Python BufferedByteStream.truncate方法的具体用法?Python BufferedByteStream.truncate怎么用?Python BufferedByteStream.truncate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyamf.util.BufferedByteStream的用法示例。


在下文中一共展示了BufferedByteStream.truncate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ProducingChannel

# 需要导入模块: from pyamf.util import BufferedByteStream [as 别名]
# 或者: from pyamf.util.BufferedByteStream import truncate [as 别名]
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))
开发者ID:Flumotion,项目名称:rtmpy,代码行数:52,代码来源:codec.py

示例2: BaseStreamer

# 需要导入模块: from pyamf.util import BufferedByteStream [as 别名]
# 或者: from pyamf.util.BufferedByteStream import truncate [as 别名]
class BaseStreamer(object):
    """
    Provides all the base functionality for handling an RTMP input/output.

    @ivar decoder: RTMP Decoder that is fed data via L{dataReceived}
    """

    implements(message.IMessageListener)

    dispatcher = MessageDispatcher


    @property
    def decoding(self):
        """
        Whether this streamer is currently decoding RTMP message/s.

        If all the input buffer has been consumed, this will be C{False}.
        """
        return getattr(self, 'decoding_task', None) is not None


    @property
    def encoding(self):
        """
        Whether this streamer is currently encoding RTMP message/s.
        """
        return getattr(self, 'encoding_task', None) is not None


    def getWriter(self):
        """
        Returns a file like object that provides a I{write} method. This must be
        provided by subclasses.

        For example, for L{protocol.Protocol} instances this should return
        C{self.transport}.
        """
        raise NotImplementedError


    def buildStreamManager(self):
        """
        Returns an instance that provides L{interfaces.IStreamManager}. This
        must be provided by subclasses.
        """
        raise NotImplementedError


    def getDispatcher(self):
        """
        Returns an instance that will provide L{interfaces.IMessageDispatcher}
        """
        return self.dispatcher(self)


    def bytesInterval(self, bytes):
        """
        """
        self.sendMessage(message.BytesRead(bytes), self.controlStream)


    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


    def stopStreaming(self, reason=None):
        """
        """
        self.streamManager.closeAllStreams()

        self._decodingBuffer.truncate()
        self._encodingBuffer.truncate()

        del self._decodingBuffer
        del self._encodingBuffer

        del self.decoder_task, self.decoder
        del self.encoder_task, self.encoder


    def dataReceived(self, data):
        """
        Data has been received by the endpoint.
        """
#.........这里部分代码省略.........
开发者ID:Flumotion,项目名称:rtmpy,代码行数:103,代码来源:__init__.py

示例3: Codec

# 需要导入模块: from pyamf.util import BufferedByteStream [as 别名]
# 或者: from pyamf.util.BufferedByteStream import truncate [as 别名]
class Codec(object):
    """
    Generic channels and frame operations.

    @ivar stream: The underlying buffer containing the raw bytes.
    @type stream: L{BufferedByteStream}
    @ivar channels: A L{dict} of L{BaseChannel} objects that are handling data.
    @ivar frameSize: The maximum size for an individual frame. Read-only, use
        L{setFrameSize} instead.
    """


    def __init__(self):
        self.buffer = BufferedByteStream()

        self.channels = {}
        self.frameSize = FRAME_SIZE
        self.bytes = 0


    def setFrameSize(self, size):
        """
        Set the size of the next frame to be handled.
        """
        self.frameSize = size

        for channel in self.channels.values():
            channel.setFrameSize(size)


    def buildChannel(self, channelId):
        """
        Called to build a channel suitable for use with this codec.

        Must be implemented by subclasses.
        """
        raise NotImplementedError


    def getChannel(self, channelId):
        """
        Returns a channel based on channelId. If the channel doesn't exist,
        then one is created.

        @param channelId: Index for the channel to retrieve.
        @type channelId: C{int}
        @rtype: L{Channel}
        """
        channel = self.channels.get(channelId, None)

        if channel is not None:
            return channel

        if channelId > MAX_CHANNELS:
            raise IndexError('Attempted to get channelId %d which is > %d' % (
                channelId, MAX_CHANNELS))

        channel = self.buildChannel(channelId)
        self.channels[channelId] = channel

        channel.reset()

        return channel


    def clear(self):
        """
        Clears the underlying buffer.
        """
        self.buffer.consume()
        self.buffer.truncate()
开发者ID:njoyce,项目名称:rtmpy,代码行数:73,代码来源:codec.py


注:本文中的pyamf.util.BufferedByteStream.truncate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。