# Path: twimp/amf0.py
# class Object(OrderedObject):
#     """AMF Object class, with chronological attribute ordering, for
#     increased compatibility.
#     """
# 
# Path: twimp/chunks.py
# class Header(object):
# class ChunkStreamParseError(ValueError):
# class ChunkStreamValueError(ValueError):
# class Demuxer(object):
# class Chunker(object):
# class SimpleChunkProducer(object):
# class Muxer(object):
#     def __init__(self, cs_id, time, size, type, ms_id, **kw):
#     def __repr__(self):
#         def _repr_maybe(v, provided):
# def absolutize(h, base):
# def read_header_head(s):
#     def __init__(self, protocol):
#     def doSetChunkSize(self, header, new_size):
#     def doAbortMessage(self, header, cs_id):
#     def doACK(self, header, seq_num):
#     def doUserControlMessage(self, header, evt_type, body):
#     def doWindowSize(self, header, window_size):
#     def doSetBandwidth(self, header, window_size, limit_type):
#     def controlMessageUnknown(self, header, body):
#     def controlMessageReceived(self, header, body):
#     def gen_handler(self):
# def _encode_basic_header(h_type, cs_id, time=None):
# def encode_full_header(cs_id, time, size, msg_type, ms_id):
# def encode_comp_header(h_type, cs_id, time, size, msg_type, ms_id):
#     def set_chunk_size(self, new_chunk_size):
#     def __call__(self, cs_id, first_header, body, time=None):
#     def __init__(self, transport):
#     def queue_chunker(self, priority, chunker):
#     def sync(self, priority):
#     def pauseProducing(self):
#     def resumeProducing(self):
#     def stopProducing(self):
#     def __init__(self, transport):
#     def _precompute_dispatch(self, amf_ver):
#     def _make_adhoc_csid(self, mt):
#     def set_chunk_size(self, new_chunk_size):
#     def sendMessage(self, time, type_, ms_id, body, absolute=False):
# DEFAULT_CHUNK_SIZE = 128
# (PROTO_SET_CHUNK_SIZE, PROTO_ABORT_MESSAGE, PROTO_ACK, PROTO_USER_CONTROL,
#  PROTO_WINDOW_SIZE, PROTO_SET_BANDWIDTH, MSG_COMMAND, MSG_DATA, MSG_SO,
#  MSG_AUDIO, MSG_VIDEO, MSG_AGGREGATE) = range(12)
# 
# Path: twimp/primitives.py

# 
# Path: twimp/helpers.py
# def vb_clone(vb):
#     # TODO: add this functionality to the vecbuf/VecBuf itself
#     return VecBuf(vb.peek_seq(len(vb)))
# 
# def vb(s):
#     # TODO: add this functionality to the vecbuf/VecBuf itself
#     return VecBuf([s])


from collections import deque
from twisted.internet import defer
from twimp.amf0 import Object
from twimp import chunks
from twimp.primitives import _s_uchar, _s_double_uchar
from twimp.helpers import vb_clone, vb
import twimp.log
        self._nstream.set_listeners(mute_callback=self.on_mute_message)

        d = self._scan_tracks()

        d.addCallback(self._send_status_cb)

        d.addCallback(self._send_meta_cb)
        d.addCallback(self._add_headers_cb)

        d.addCallback(self._subscribe_cb)
        return d

    def stop(self):
        self._nstream.unset_listeners()

        d = defer.succeed(None)

        if self._subscription:
            def do_unsubscribe(_result, s, subscr):
                return s.unsubscribe(subscr)
            for s, subscr in self._subscription:
                d.addCallback(do_unsubscribe, s, subscr)
            self._subscription = None
            return d

        return d

    def on_header_data_added(self, type_, ts, flags, data):
        log.debug('=> %s, %s, %s, %s, %s',
                  ts, type_, flags, self._nstream.id, len(data))

# Path: twimp/amf0.py
# class Object(OrderedObject):
#     """AMF Object class, with chronological attribute ordering, for
#     increased compatibility.
#     """
# 
# Path: twimp/chunks.py
# class Header(object):
# class ChunkStreamParseError(ValueError):
# class ChunkStreamValueError(ValueError):
# class Demuxer(object):
# class Chunker(object):
# class SimpleChunkProducer(object):
# class Muxer(object):
#     def __init__(self, cs_id, time, size, type, ms_id, **kw):
#     def __repr__(self):
#         def _repr_maybe(v, provided):
# def absolutize(h, base):
# def read_header_head(s):
#     def __init__(self, protocol):
#     def doSetChunkSize(self, header, new_size):
#     def doAbortMessage(self, header, cs_id):
#     def doACK(self, header, seq_num):
#     def doUserControlMessage(self, header, evt_type, body):
#     def doWindowSize(self, header, window_size):
#     def doSetBandwidth(self, header, window_size, limit_type):
#     def controlMessageUnknown(self, header, body):
#     def controlMessageReceived(self, header, body):
#     def gen_handler(self):
# def _encode_basic_header(h_type, cs_id, time=None):
# def encode_full_header(cs_id, time, size, msg_type, ms_id):
# def encode_comp_header(h_type, cs_id, time, size, msg_type, ms_id):
#     def set_chunk_size(self, new_chunk_size):
#     def __call__(self, cs_id, first_header, body, time=None):
#     def __init__(self, transport):
#     def queue_chunker(self, priority, chunker):
#     def sync(self, priority):
#     def pauseProducing(self):
#     def resumeProducing(self):
#     def stopProducing(self):
#     def __init__(self, transport):
#     def _precompute_dispatch(self, amf_ver):
#     def _make_adhoc_csid(self, mt):
#     def set_chunk_size(self, new_chunk_size):
#     def sendMessage(self, time, type_, ms_id, body, absolute=False):
# DEFAULT_CHUNK_SIZE = 128
# (PROTO_SET_CHUNK_SIZE, PROTO_ABORT_MESSAGE, PROTO_ACK, PROTO_USER_CONTROL,
#  PROTO_WINDOW_SIZE, PROTO_SET_BANDWIDTH, MSG_COMMAND, MSG_DATA, MSG_SO,
#  MSG_AUDIO, MSG_VIDEO, MSG_AGGREGATE) = range(12)
# 
# Path: twimp/primitives.py

# 
# Path: twimp/helpers.py
# def vb_clone(vb):
#     # TODO: add this functionality to the vecbuf/VecBuf itself
#     return VecBuf(vb.peek_seq(len(vb)))
# 
# def vb(s):
#     # TODO: add this functionality to the vecbuf/VecBuf itself
#     return VecBuf([s])


# Path: twimp/server/controllers.py
from collections import deque
from twisted.internet import defer
from twimp.amf0 import Object
from twimp import chunks
from twimp.primitives import _s_uchar, _s_double_uchar
from twimp.helpers import vb_clone, vb
import twimp.log

        self._nstream.set_listeners(mute_callback=self.on_mute_message)

        d = self._scan_tracks()

        d.addCallback(self._send_status_cb)

        d.addCallback(self._send_meta_cb)
        d.addCallback(self._add_headers_cb)

        d.addCallback(self._subscribe_cb)
        return d

    def stop(self):
        self._nstream.unset_listeners()

        d = defer.succeed(None)

        if self._subscription:
            def do_unsubscribe(_result, s, subscr):
                return s.unsubscribe(subscr)
            for s, subscr in self._subscription:
                d.addCallback(do_unsubscribe, s, subscr)
            self._subscription = None
            return d

        return d

    def on_header_data_added(self, type_, ts, flags, data):
        log.debug('=> %s, %s, %s, %s, %s',
                  ts, type_, flags, self._nstream.id, len(data))

        self._nstream.send(0, type_, vb_clone(data))