예제 #1
0
def makeHandshakeResponse(handshake):
    flash_plugin_version = unpack(">I", handshake[4:8])[0]
    #scheme = SCHEMES.get(flash_plugin_version, 0)
    scheme = validateClient(handshake)
    print "scheme", scheme

    handshake = prepareHandshake(handshake, scheme)

    output = BytesOutput(True)
    output.writeByte(0x03)
    output.write(makeHandshakePart1(handshake, scheme))
    output.write(makeHandshakePart2(handshake, scheme))
    return output.getBytes()
예제 #2
0
def makeHandshakeResponse(handshake):
	flash_plugin_version = unpack(">I", handshake[4:8])[0]
	#scheme = SCHEMES.get(flash_plugin_version, 0)
	scheme = validateClient(handshake)
	print "scheme", scheme
	
	handshake = prepareHandshake(handshake, scheme);
	
	output = BytesOutput(True)
	output.writeByte(0x03)
	output.write(makeHandshakePart1(handshake, scheme))
	output.write(makeHandshakePart2(handshake, scheme))
	return output.getBytes()
예제 #3
0
파일: Stream.py 프로젝트: slyseal/slyseal
	def getFrameHeader(self, type, keyframe, description = False, ref_time = 0):
		output = BytesOutput(True)
		
		if type == FRAME_TYPE_VIDEO:
			output.writeByte((0x27, 0x17)[keyframe])
			output.writeByte((0x01, 0x00)[description])
			output.writeInt24(ref_time)
		elif type == FRAME_TYPE_AUDIO:
			output.writeByte(0xAF)
			output.writeByte((0x01, 0x00)[description])

		return output.getBytes()
예제 #4
0
파일: Stream.py 프로젝트: slyseal/slyseal
    def getFrameHeader(self, type, keyframe, description=False, ref_time=0):
        output = BytesOutput(True)

        if type == FRAME_TYPE_VIDEO:
            output.writeByte((0x27, 0x17)[keyframe])
            output.writeByte((0x01, 0x00)[description])
            output.writeInt24(ref_time)
        elif type == FRAME_TYPE_AUDIO:
            output.writeByte(0xAF)
            output.writeByte((0x01, 0x00)[description])

        return output.getBytes()
예제 #5
0
파일: Rtmp.py 프로젝트: slyseal/slyseal
    def makeHeader(self, header):
        output = BytesOutput(True)

        header_size = 1
        if header[4] is not None:
            header_size = 12
        elif header[3] is not None:
            header_size = 8
        elif header[1] is not None:
            header_size = 4

        output.writeByte(header[0] | (headerSizeToByte(header_size) << 6))

        if header_size >= 4:
            output.writeUInt24(header[1])
        if header_size >= 8:
            output.writeUInt24(header[2])
            output.writeByte(header[3])
        if (header_size >= 12):
            output.setEndianess(False)
            output.writeUInt(header[4])
            output.setEndianess(True)

        return output.getBytes()
예제 #6
0
파일: Rtmp.py 프로젝트: slyseal/slyseal
	def makeHeader(self, header):
		output = BytesOutput(True)
		
		header_size = 1
		if header[4] is not None:
			header_size = 12
		elif header[3] is not None:
			header_size = 8
		elif header[1] is not None:
			header_size = 4
			
		output.writeByte(header[0] | (headerSizeToByte(header_size) << 6))
		
		if header_size >= 4:
			output.writeUInt24(header[1])
		if header_size >= 8:
			output.writeUInt24(header[2])
			output.writeByte(header[3])
		if (header_size >= 12):
			output.setEndianess(False)
			output.writeUInt(header[4])
			output.setEndianess(True)
		
		return output.getBytes()
예제 #7
0
파일: Rtmp.py 프로젝트: slyseal/slyseal
    def make(self, channel_id, packet, timestamp=0, stream_id=0):
        type = packet[0]
        header = [channel_id, timestamp, None, type, stream_id]

        data = BytesOutput(True)

        # 0x01 - Chunk Size
        if type == RTMP_TYPE_CHUNK_SIZE:
            data.writeUInt(packet[1])

        # 0x03 - Bytes Read
        elif type == RTMP_TYPE_BYTES_READ:
            data.writeUInt(packet[1])

        # 0x04 - Control
        elif type == RTMP_TYPE_CONTROL:
            control_stream_id, control = packet[1]
            control_type = control[0]
            value1 = None
            value2 = None

            # 0x00 - Clear
            if control_type == RTMP_CONTROL_CLEAR:
                pass

            # 0x01 - Clear Play
            elif control_type == RTMP_CONTROL_CLEAR_PLAY:
                pass

            # 0x03 - Client Buffer
            elif control_type == RTMP_CONTROL_CLIENT_BUFFER:
                value1 = control[1]

            # 0x04 - Reset
            elif control_type == RTMP_CONTROL_RESET:
                pass

            # 0x06 - Ping
            elif control_type == RTMP_CONTROL_PING:
                value1 = control[1]

            # 0x07 - Pong
            elif control_type == RTMP_CONTROL_PONG:
                value1 = control[1]

            # Unknown
            elif control_type == RTMP_CONTROL_UNKNOWN:
                control_type = control[1]
                value1 = control[2]
                value2 = control[3]

            data.writeUInt16(control_type)
            data.writeUInt(control_stream_id)

            if value1 is not None:
                data.writeUInt(value1)
            if value2 is not None:
                data.writeUInt(value2)

        # 0x05 - Server BW
        elif type == RTMP_TYPE_SERVER_BW:
            data.writeUInt(0x002625A0)

        # 0x06 - Client BW
        elif type == RTMP_TYPE_CLIENT_BW:
            data.writeUInt(0x002625A0)
            data.writeByte(0x02)

        # 0x08 - Audio
        elif type == RTMP_TYPE_AUDIO:
            data.write(packet[1])

        # 0x09 - Video
        elif type == RTMP_TYPE_VIDEO:
            data.write(packet[1])

        # 0x12 - Notify
        elif type == RTMP_TYPE_NOTIFY:
            data.writeString(packet[1])

        # 0x13 - Shared
        elif type == RTMP_TYPE_SHARED:
            raise Exception, "Not implemented"  #TODO -> Shared Object functions

        # 0x14 - Command
        elif type == RTMP_TYPE_COMMAND:
            name, id, args = packet[1]
            Amf.write(data, (3, name))  #Command name
            Amf.write(data, (1, id))  #Command id
            for arg in args:  # Args (Amf Values)
                Amf.write(data, arg)

        # Unknown
        elif type == RTMP_TYPE_UNKNOWN:
            type, body = packet[1]
            header[4] = type
            data.write(body)

        # Other
        else:
            header[4] = None

        data = data.getBytes()
        length = len(data)
        header[2] = length

        output = BytesOutput(True)

        output.write(self.makeHeader(header))
        if length > 0:
            pos = self.write_chunk_size
            if length <= pos:
                output.write(data)
            else:
                output.write(buffer(data, 0, pos))
                length -= pos
                while length > 0:
                    output.writeByte(header[0] | (headerSizeToByte(1) << 6))
                    n = (length,
                         self.write_chunk_size)[length > self.write_chunk_size]
                    output.write(buffer(data, pos, n))
                    pos += n
                    length -= n

        return output.getBytes()
예제 #8
0
파일: Rtmp.py 프로젝트: slyseal/slyseal
	def make(self, channel_id, packet, timestamp = 0, stream_id = 0):
		type = packet[0]
		header = [channel_id, timestamp, None, type, stream_id]
		
		data = BytesOutput(True)
		
		# 0x01 - Chunk Size
		if type == RTMP_TYPE_CHUNK_SIZE:
			data.writeUInt(packet[1])
			
		# 0x03 - Bytes Read
		elif type == RTMP_TYPE_BYTES_READ:
			data.writeUInt(packet[1])
			
		# 0x04 - Control
		elif type == RTMP_TYPE_CONTROL:
			control_stream_id, control = packet[1]
			control_type = control[0]
			value1 = None
			value2 = None
			
			# 0x00 - Clear
			if control_type == RTMP_CONTROL_CLEAR:
				pass
				
			# 0x01 - Clear Play
			elif control_type == RTMP_CONTROL_CLEAR_PLAY:
				pass
				
			# 0x03 - Client Buffer
			elif control_type == RTMP_CONTROL_CLIENT_BUFFER:
				value1 = control[1]
				
			# 0x04 - Reset
			elif control_type == RTMP_CONTROL_RESET:
				pass
				
			# 0x06 - Ping
			elif control_type == RTMP_CONTROL_PING:
				value1 = control[1]
				
			# 0x07 - Pong
			elif control_type == RTMP_CONTROL_PONG:
				value1 = control[1]
				
			# Unknown
			elif control_type == RTMP_CONTROL_UNKNOWN:
				control_type = control[1]
				value1 = control[2]
				value2 = control[3]

			data.writeUInt16(control_type)
			data.writeUInt(control_stream_id)
			
			if value1 is not None:
				data.writeUInt(value1)
			if value2 is not None:
				data.writeUInt(value2)
				
		# 0x05 - Server BW
		elif type == RTMP_TYPE_SERVER_BW:
			data.writeUInt(0x002625A0)
			
		# 0x06 - Client BW
		elif type == RTMP_TYPE_CLIENT_BW:
			data.writeUInt(0x002625A0)
			data.writeByte(0x02)
			
		# 0x08 - Audio
		elif type == RTMP_TYPE_AUDIO:
			data.write(packet[1])
			
		# 0x09 - Video
		elif type == RTMP_TYPE_VIDEO:
			data.write(packet[1])
			
		# 0x12 - Notify
		elif type == RTMP_TYPE_NOTIFY:
			data.writeString(packet[1])
			
		# 0x13 - Shared
		elif type == RTMP_TYPE_SHARED:
			raise Exception, "Not implemented" #TODO -> Shared Object functions
			
		# 0x14 - Command
		elif type == RTMP_TYPE_COMMAND:
			name, id, args = packet[1]
			Amf.write(data, (3, name)) #Command name
			Amf.write(data, (1, id)) #Command id
			for arg in args: # Args (Amf Values)
				Amf.write(data, arg)
				
		# Unknown
		elif type == RTMP_TYPE_UNKNOWN: 
			type, body = packet[1]
			header[4] = type
			data.write(body)
			
		# Other
		else:
			header[4] = None
			
		data = data.getBytes()
		length = len(data)
		header[2] = length

		
		output = BytesOutput(True)
		
		output.write(self.makeHeader(header))
		if length > 0:
			pos = self.write_chunk_size
			if length <= pos:
				output.write(data)
			else:
				output.write(buffer(data, 0, pos))
				length -= pos
				while length > 0:
					output.writeByte(header[0] | (headerSizeToByte(1) << 6))
					n = (length, self.write_chunk_size)[length > self.write_chunk_size]
					output.write(buffer(data, pos, n))
					pos += n
					length -= n

		return output.getBytes()