def send_msg(self, datatype, body): """ Helper method that send the specified message into the stream. Takes care to prepend the necessary headers and split the message into appropriately sized chunks. """ # Values that just work. :-) if datatype >= 1 and datatype <= 7: channel_id = 2 stream_id = 0 else: channel_id = 3 stream_id = 0 timestamp = 0 header = rtmp_protocol_base.Header(channelId=channel_id, streamId=stream_id, datatype=datatype, bodyLength=len(body), timestamp=timestamp) rtmp_protocol_base.header_encode(self.stream, header) for i in xrange(0, len(body), self.chunk_size): chunk = body[i:i + self.chunk_size] self.stream.write(chunk) if i + self.chunk_size < len(body): rtmp_protocol_base.header_encode(self.stream, header, header)
def send_msg(self, datatype, body, message=None): """ Helper method that send the specified message into the stream. Takes care to prepend the necessary headers and split the message into appropriately sized chunks. """ # superDebugNotice("rtmp writer, send_msg") # superDebug("datatype", datatype) # superDebug("body", body) # Values that just work. :-) if datatype >= 1 and datatype <= 7: channel_id = 2 stream_id = 0 else: channel_id = 3 stream_id = 0 timestamp = 0 # Specials have a streamid. try: stream_id = message['streamid'] if "closeStream" in body: channel_id = 4 elif "deleteStream" in body: channel_id = 3 elif "publish" in body: channel_id = 8 elif datatype == DataTypes.SET_CHUNK_SIZE: channel_id = 2 timestamp = message["timestamp"] elif "play" in body: channel_id = 8 elif datatype == DataTypes.VIDEO_MESSAGE: channel_id = 6 timestamp = message["timestamp"] elif datatype == DataTypes.AUDIO_MESSAGE: channel_id = 4 timestamp = message["timestamp"] except: pass header = rtmp_protocol_base.Header( channelId=channel_id, streamId=stream_id, datatype=datatype, bodyLength=len(body), timestamp=timestamp) rtmp_protocol_base.header_encode(self.stream, header) # superDebug("header", header) for i in xrange(0,len(body),self.chunk_size): chunk = body[i:i+self.chunk_size] self.stream.write(chunk) if i+self.chunk_size < len(body): rtmp_protocol_base.header_encode(self.stream, header, header)
def send_msg(self, datatype, body, message=None): """ Helper method that sends the specified message into the stream. Takes care to prepend the necessary headers and split the message into appropriately sized chunks. """ # Values that just work. :-) if 1 <= datatype <= 7: channel_id = 2 stream_id = 0 else: channel_id = 3 stream_id = 0 timestamp = 0 try: stream_id = message['stream_id'] if 'closeStream' in body: channel_id = 8 elif 'deleteStream' in body: channel_id = 3 elif 'publish' in body: channel_id = 8 elif 'play' in body: channel_id = 8 elif datatype == DataTypes.SET_CHUNK_SIZE: channel_id = 2 elif datatype == DataTypes.AUDIO or datatype == DataTypes.VIDEO: channel_id = random.randint(10, 50) timestamp = message['timestamp'] except Exception: pass header = rtmp_protocol_base.Header(channelId=channel_id, timestamp=timestamp, streamId=stream_id, bodyLength=len(body), datatype=datatype) rtmp_protocol_base.header_encode(self.stream, header) for i in xrange(0, len(body), self.chunk_size): chunk = body[i:i + self.chunk_size] self.stream.write(chunk) if i + self.chunk_size < len(body): rtmp_protocol_base.header_encode(self.stream, header, header)
def send_msg_publish(self, datatype, body): """ Helper method that send the specified message into the stream. Takes care to prepend the necessary headers and split the message into appropriately sized chunks. """ # superDebugNotice("rtmp writer, send_msg") # superDebug("datatype", datatype) # superDebug("body", body) # Values that just work. :-) # if datatype >= 1 and datatype <= 7: # channel_id = 2 # stream_id = 1 # else: # channel_id = 3 # stream_id = 1 # timestamp = 0 header = rtmp_protocol_base.Header( channelId=11, streamId=1, datatype=datatype, bodyLength=len(body), timestamp=0) rtmp_protocol_base.header_encode(self.stream, header) # superDebug("header", header) for i in xrange(0, len(body), self.chunk_size): chunk = body[i:i+self.chunk_size] self.stream.write(chunk) if i+self.chunk_size < len(body): rtmp_protocol_base.header_encode(self.stream, header, header)