Skip to content

Commit

Permalink
Sync packages.flashmedia with upstream.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrippa committed Feb 27, 2013
1 parent 2e27f21 commit 7c6d70f
Show file tree
Hide file tree
Showing 9 changed files with 1,601 additions and 862 deletions.
23 changes: 23 additions & 0 deletions LICENSE.flashmedia
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Copyright (c) 2011-2013, Christopher Rosell
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

60 changes: 30 additions & 30 deletions src/livestreamer/packages/flashmedia/amf0.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from .compat import *
from .error import *
from .packet import *
from .types import *
from .util import *

class AMF0Header(Packet):
Expand All @@ -12,23 +13,23 @@ def __init__(self, name, value, must_understand=False):
@property
def size(self):
size = 4+1
size += PacketIO.script_string_size(self.name)
size += PacketIO.script_value_size(self.value)
size += ScriptDataString.size(self.name)
size += ScriptDataValue.size(self.value)

return size

def _serialize(self, packet):
packet.write_script_string(self.name)
packet.write_u8(int(self.must_understand))
packet.write_u32(self.size)
packet.write_script_value(self.value)
packet += ScriptDataString(self.name)
packet += U8(int(self.must_understand))
packet += U32BE(self.size)
packet += ScriptDataValue(self.value)

@classmethod
def _deserialize(cls, io):
name = io.read_script_string()
must_understand = bool(io.read_u8())
length = io.read_u32()
value = io.read_script_value()
name = ScriptDataString.read(io)
must_understand = bool(U8.read(io))
length = U32BE.read(io)
value = ScriptDataValue.read(io)

return cls(name, value, must_understand)

Expand All @@ -42,25 +43,24 @@ def __init__(self, target_uri, response_uri, value):
@property
def size(self):
size = 4
size += PacketIO.script_string_size(self.target_uri)
size += PacketIO.script_string_size(self.response_uri)
size += PacketIO.script_value_size(self.value)
size += ScriptDataString.size(self.target_uri)
size += ScriptDataString.size(self.response_uri)
size += ScriptDataValue.size(self.value)

return size

def _serialize(self, packet):
packet.write_script_string(self.target_uri)
packet.write_script_string(self.response_uri)
packet.write_u32(self.size)
packet.write_script_value(self.value)
packet += ScriptDataString(self.target_uri)
packet += ScriptDataString(self.response_uri)
packet += U32BE(self.size)
packet += ScriptDataValue(self.value)

@classmethod
def _deserialize(cls, io):
target_uri = io.read_script_string()
response_uri = io.read_script_string()
length = io.read_u32()
value = io.read_script_value()

target_uri = ScriptDataString.read(io)
response_uri = ScriptDataString.read(io)
length = U32BE.read(io)
value = ScriptDataValue.read(io)

return cls(target_uri, response_uri, value)

Expand All @@ -84,34 +84,34 @@ def size(self):
return size

def _serialize(self, packet):
packet.write_u16(self.version)
packet.write_u16(len(self.headers))
packet += U16BE(self.version)
packet += U16BE(len(self.headers))

for header in self.headers:
header.serialize(packet)

packet.write_u16(len(self.messages))
packet += U16BE(len(self.messages))
for message in self.messages:
message.serialize(packet)

@classmethod
def _deserialize(cls, io):
version = io.read_u16()
version = U16BE.read(io)

if version != 0:
raise AMFError("AMF version must be 0")

headers = []
header_count = io.read_u16()
header_count = U16BE.read(io)

for i in range(header_count):
header = AMF0Header.deserialize(io=io)
header = AMF0Header.deserialize(io)
headers.append(header)

messages = []
message_count = io.read_u16()
message_count = U16BE.read(io)
for i in range(message_count):
message = AMF0Message.deserialize(io=io)
message = AMF0Message.deserialize(io)
messages.append(message)

return cls(version, headers, messages)
Expand Down
Loading

0 comments on commit 7c6d70f

Please sign in to comment.