<s> from ctypes import BigEndianStructure , Union , c_uint8 , c_uint16 , c_uint32 <EOL> from io import BytesIO <EOL> from . compat import * <EOL> from . error import * <EOL> from . packet import * <EOL> from . types import * <EOL> from . util import * <EOL> class Box ( Packet ) : <EOL> exception = F4VError <EOL> def __init__ ( self , type , payload , extended_size = False ) : <EOL> self . type = type <EOL> self . payload = payload <EOL> self . extended_size = extended_size <EOL> @ property <EOL> def size ( self ) : <EOL> size = <NUM_LIT:8> <EOL> size += self . payload . size <EOL> if size > <NUM_LIT> or self . extended_size : <EOL> size += <NUM_LIT:8> <EOL> return size <EOL> @ classmethod <EOL> def _deserialize ( cls , io , strict = False , raw_payload = False ) : <EOL> size = U32BE . read ( io ) <EOL> type_ = FourCC . read ( io ) <EOL> header_size = <NUM_LIT:8> <EOL> extended_size = False <EOL> if size == <NUM_LIT:1> : <EOL> size = U64BE . read ( io ) <EOL> header_size += <NUM_LIT:8> <EOL> extended_size = True <EOL> if size == <NUM_LIT:0> : <EOL> data = io . read ( ) <EOL> else : <EOL> data = chunked_read ( io , size - header_size , exception = F4VError ) <EOL> if type_ in PayloadTypes and not raw_payload : <EOL> payloadcls = PayloadTypes [ type_ ] <EOL> payloadio = BytesIO ( data ) <EOL> payload = payloadcls . deserialize ( payloadio ) <EOL> else : <EOL> payload = RawPayload ( data ) <EOL> box = cls ( type_ , payload , extended_size ) <EOL> if strict and box . size != size : <EOL> raise F4VError ( "<STR_LIT>" ) <EOL> return box <EOL> def _serialize ( self , packet ) : <EOL> size = self . payload . size <EOL> if size > <NUM_LIT> or self . extended_size : <EOL> packet += U32BE ( <NUM_LIT:1> ) <EOL> else : <EOL> packet += U32BE ( size + <NUM_LIT:8> ) <EOL> packet += FourCC ( self . type ) <EOL> if size > <NUM_LIT> or self . extended_size : <EOL> packet += U64BE ( size + <NUM_LIT:16> ) <EOL> if isinstance ( self . payload , BoxPayload ) : <EOL> self . payload . serialize ( packet ) <EOL> else : <EOL> packetwrite ( self . payload ) <EOL> class BoxPayload ( Packet ) : <EOL> exception = F4VError <EOL> @ property <EOL> def size ( self ) : <EOL> return <NUM_LIT:0> <EOL> @ classmethod <EOL> def box ( cls , * args , ** kw ) : <EOL> type_ = None <EOL> for name , kls in PayloadTypes . items ( ) : <EOL> if kls == cls : <EOL> type_ = name <EOL> break <EOL> payload = cls ( * args , ** kw ) <EOL> return Box ( type_ , <NUM_LIT:0> , payload ) <EOL> class BoxContainer ( BoxPayload ) : <EOL> def __init__ ( self , boxes ) : <EOL> self . boxes = boxes <EOL> @ property <EOL> def size ( self ) : <EOL> size = <NUM_LIT:0> <EOL> for box in self . boxes : <EOL> size += box . size <EOL> return size <EOL> def _serialize ( self , packet ) : <EOL> for box in self . boxes : <EOL> box . serialize ( packet ) <EOL> @ classmethod <EOL> def _deserialize ( cls , io ) : <EOL> boxes = [ ] <EOL> while True : <EOL> try : <EOL> box = Box . deserialize ( io ) <EOL> except IOError : <EOL> break <EOL> boxes . append ( box ) <EOL> return cls ( boxes ) <EOL> class BoxContainerSingle ( BoxPayload ) : <EOL> def __init__ ( self , box ) : <EOL> self . box = box <EOL> @ property <EOL> def size ( self ) : <EOL> return self . box . size <EOL> def _serialize ( self , packet ) : <EOL> self . box . serialize ( packet ) <EOL> @ classmethod <EOL> def _deserialize ( cls , io ) : <EOL> box = Box . deserialize ( io ) <EOL> return cls ( box ) <EOL> class RawPayload ( BoxPayload ) : <EOL> def __init__ ( self , data ) : <EOL> self . data = data <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" . format ( self . size ) <EOL> @ property <EOL> def size ( self ) : <EOL> return len ( self . data ) <EOL> @ classmethod <EOL> def _deserialize ( cls , io ) : <EOL> data = io . read ( ) <EOL> return cls ( data ) <EOL> def _serialize ( self , packet ) : <EOL> packet += self . data <EOL> class BoxPayloadFTYP ( BoxPayload ) : <EOL> def __init__ ( self , major_brand = "<STR_LIT>" , minor_version = <NUM_LIT:0> , <EOL> compatible_brands = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) : <EOL> self . major_brand = major_brand <EOL> self . minor_version = minor_version <EOL> self . compatible_brands = compatible_brands <EOL> @ property <EOL> def size ( self ) : <EOL> return <NUM_LIT:4> + <NUM_LIT:4> + ( len ( self . compatible_brands ) * <NUM_LIT:4> ) <EOL> def _serialize ( self , packet ) : <EOL> packet += FourCC ( self . major_brand ) <EOL> packet += U32BE ( self . minor_version ) <EOL> for brand in self . compatible_brands : <EOL> packet += FourCC ( brand ) <EOL> @ classmethod <EOL> def _deserialize ( cls , io ) : <EOL> major_brand = FourCC . read ( io ) <EOL> minor_version = U32BE . read ( io ) <EOL> compatible_brands = [ ] <EOL> while True : <EOL> try : <EOL> brand = FourCC . read ( io ) <EOL> except IOError : <EOL> break <EOL> compatible_brands . append ( brand ) <EOL> return cls ( major_brand , minor_version , <EOL> compatible_brands ) <EOL> class BoxPayloadMVHD ( BoxPayload ) : <EOL> def __init__ ( self , version = <NUM_LIT:0> , creation_time = <NUM_LIT:0> , modification_time = <NUM_LIT:0> , <EOL> time_scale = <NUM_LIT:1000> , duration = <NUM_LIT:0> , rate = <NUM_LIT:1.0> , volume = <NUM_LIT:1.0> , <EOL> matrix = [ <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT> ] , <EOL> next_track_id = <NUM_LIT:0> ) : <EOL> self . version = version <EOL> self . creation_time = creation_time <EOL> self . modification_time = modification_time <EOL> self . time_scale = time_scale <EOL> self . duration = duration <EOL> self . rate = rate <EOL> self . volume = volume <EOL> self . matrix = matrix <EOL> self . next_track_id = next_track_id <EOL> @ property <EOL> def size ( self ) : <EOL> size = <NUM_LIT:1> + <NUM_LIT:3> + <NUM_LIT:4> + <NUM_LIT:4> + <NUM_LIT:2> + <NUM_LIT:2> + <NUM_LIT:4> + <NUM_LIT:4> + ( <NUM_LIT:9> * <NUM_LIT:4> ) + ( <NUM_LIT:6> * <NUM_LIT:4> ) + <NUM_LIT:4> <EOL> if self . version == <NUM_LIT:1> : <EOL> size += <NUM_LIT:3> * <NUM_LIT:8> <EOL> else : <EOL> size += <NUM_LIT:3> * <NUM_LIT:4> <EOL> return size <EOL> def _serialize ( self , packet ) : <EOL> packet += U8 ( self . version ) <EOL> packet += U24BE ( <NUM_LIT:0> ) <EOL> packet += U3264 ( self . creation_time , self . version ) <EOL> packet += U3264 ( self . modification_time , self . version ) <EOL> packet += U32BE ( self . time_scale ) <EOL> packet += U3264 ( self . duration , self . version ) <EOL> packet += S16BE_16 ( self . rate ) <EOL> packet += S8_8BE ( self . volume ) <EOL> packet += U16BE ( <NUM_LIT:0> ) <EOL> packet += U32BE ( <NUM_LIT:0> ) <EOL> packet += U32BE ( <NUM_LIT:0> ) <EOL> for m in self . matrix : <EOL> packet += U32BE ( m ) <EOL> for i in range ( <NUM_LIT:6> ) : <EOL> packet += U32BE ( <NUM_LIT:0> ) <EOL> packet += U32BE ( self . next_track_id ) <EOL> @ classmethod <EOL> def _deserialize ( cls , io ) : <EOL> version = U8 . read ( io ) <EOL> U24BE . read ( io ) <EOL> creation_time = U3264 . read ( io , version ) <EOL> modification_time = U3264 . read ( io , version ) <EOL> time_scale = U32BE . read ( io ) <EOL> duration = U3264 . read ( io , version ) <EOL> rate = S16_16 . read ( io ) <EOL> volume = S8_8BE . read ( io ) <EOL> U16BE . read ( io ) <EOL> U32BE . read ( io ) <EOL> U32BE . read ( io ) <EOL> matrix = [ ] <EOL> for i in range ( <NUM_LIT:9> ) : <EOL> matrix . append ( U32BE . read ( io ) ) <EOL> for i in range ( <NUM_LIT:6> ) : <EOL> U32BE . read ( io ) <EOL> next_track_id = U32BE . read ( io ) <EOL> return cls ( version , creation_time , <EOL> modification_time , time_scale , duration , <EOL> rate , volume , matrix , next_track_id ) <EOL> class SampleFlags ( BoxPayload ) : <EOL> class Flags ( Union ) : <EOL> class Bits ( BigEndianStructure ) : <EOL> _fields_ = [ ( "<STR_LIT>" , c_uint8 , <NUM_LIT:6> ) , <EOL> ( "<STR_LIT>" , c_uint8 , <NUM_LIT:2> ) , <EOL> ( "<STR_LIT>" , c_uint8 , <NUM_LIT:2> ) , <EOL> ( "<STR_LIT>" , c_uint8 , <NUM_LIT:2> ) , <EOL> ( "<STR_LIT>" , c_uint8 , <NUM_LIT:3> ) , <EOL> ( "<STR_LIT>" , c_uint8 , <NUM_LIT:1> ) , <EOL> ( "<STR_LIT>" , c_uint16 , <NUM_LIT:16> ) ] <EOL> _fields_ = [ ( "<STR_LIT>" , Bits ) , ( "<STR_LIT>" , c_uint32 ) ] <EOL> def __init__ ( self , sample_depends_on , sample_is_depended_on , <EOL> sample_has_redundancy , sample_padding_value , <EOL> sample_is_difference_sample , sample_degradation_priority ) : <EOL> self . flags = self . Flags ( ) <EOL> self . flags . bit . reserved = <NUM_LIT:0> <EOL> self . flags . bit . sample_depends_on = sample_depends_on <EOL> self . flags . bit . sample_is_depended_on = sample_is_depended_on <EOL> self . flags . bit . sample_has_redundancy = sample_has_redundancy <EOL> self . flags . bit . sample_padding_value = sample_padding_value <EOL> self . flags . bit . sample_is_difference_sample = sample_is_difference_sample <EOL> self . flags . bit . sample_degradation_priority = sample_degradation_priority <EOL> @ property <EOL> def size ( self ) : <EOL> return <NUM_LIT:4> <EOL> def _serialize ( self , packet ) : <EOL> packet += U32BE ( self . flags . byte ) <EOL> @ classmethod <EOL> def _deserialize ( cls , io ) : <EOL> flags = cls . Flags ( ) <EOL> flags . byte = U32BE . read ( io ) <EOL> return cls ( flags . bit . sample_depends_on , flags . bit . sample_is_depended_on , <EOL> flags . bit . sample_has_redundancy , flags . bit . sample_padding_value , <EOL> flags . bit . sample_is_difference_sample , flags . bit . sample_degradation_priority ) <EOL> class BoxPayloadTREX ( BoxPayload ) : <EOL> def __init__ ( self , version , track_id , <EOL> default_sample_description_index , <EOL> default_sample_duration , default_sample_size , <EOL> default_sample_flags ) : <EOL> self . version = version <EOL> self . track_id = track_id <EOL> self . default_sample_description_index = default_sample_description_index <EOL> self . default_sample_duration = default_sample_duration <EOL> self . default_sample_size = default_sample_size <EOL> self . default_sample_flags = default_sample_flags <EOL> @ property <EOL> def size ( self ) : <EOL> return <NUM_LIT:1> + <NUM_LIT:3> + <NUM_LIT:4> + <NUM_LIT:4> + <NUM_LIT:4> + <NUM_LIT:4> + self . default_sample_flags . size <EOL> def _serialize ( self , packet ) : <EOL> packet += U8 ( self . version ) <EOL> packet += U24BE ( <NUM_LIT:0> ) <EOL> packet += U32BE ( self . track_id ) <EOL> packet += U32BE ( self . default_sample_description_index ) <EOL> packet += U32BE ( self . default_sample_duration ) <EOL> packet += U32BE ( self . default_sample_size ) <EOL> self . default_sample_flags . serialize ( packet ) <EOL> @ classmethod <EOL> def _deserialize ( cls , io ) : <EOL> version = U8 . read ( io ) <EOL> flags = U24BE . read ( io ) <EOL> track_id = U32BE . read ( io ) <EOL> default_sample_description_index = U32BE . read ( io ) <EOL> default_sample_duration = U32BE . read ( io ) <EOL> default_sample_size = U32BE . read ( io ) <EOL> default_sample_flags = SampleFlags . deserialize ( io ) <EOL> return cls ( version , track_id , <EOL> default_sample_description_index , <EOL> default_sample_duration , default_sample_size , <EOL> default_sample_flags ) <EOL> class BoxPayloadTKHD ( BoxPayload ) : <EOL> def __init__ ( self , version = <NUM_LIT:0> , flags = <NUM_LIT:1> , creation_time = <NUM_LIT:0> , modification_time = <NUM_LIT:0> , <EOL> track_id = <NUM_LIT:1> , duration = <NUM_LIT:0> , layer = <NUM_LIT:0> , alternate_group = <NUM_LIT:0> , volume = <NUM_LIT:0.0> , <EOL> transform_matrix = [ <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT> ] , <EOL> width = <NUM_LIT:0.0> , height = <NUM_LIT:0.0> ) : <EOL> self . version = version <EOL> self . flags = flags <EOL> self . creation_time = creation_time <EOL> self . modification_time = modification_time <EOL> self . track_id = track_id <EOL> self . duration = duration <EOL> self . layer = layer <EOL> self . alternate_group = alternate_group <EOL> self . volume = volume <EOL> self . transform_matrix = transform_matrix <EOL> self . width = width <EOL> self . height = height <EOL> @ property <EOL> def size ( self ) : <EOL> size = <NUM_LIT:1> + <NUM_LIT:3> + <NUM_LIT:4> + <NUM_LIT:4> + <NUM_LIT:4> + <NUM_LIT:4> + <NUM_LIT:4> + ( <NUM_LIT:4> * <NUM_LIT:2> ) + <NUM_LIT:2> + <NUM_LIT:2> + <NUM_LIT:2> + <NUM_LIT:2> + ( <NUM_LIT:9> * <NUM_LIT:4> ) + <NUM_LIT:4> + <NUM_LIT:4> <EOL> if self . version == <NUM_LIT:1> : <EOL> size += <NUM_LIT:4> * <NUM_LIT:3> <EOL> return size <EOL> def _serialize ( self , packet ) : <EOL> packet += U8 ( self . version ) <EOL> packet += U24BE ( self . flags ) <EOL> packet += U3264 ( self . creation_time , self . version ) <EOL> packet += U3264 ( self . modification_time , self . version ) <EOL> packet += U32BE ( self . track_id ) <EOL> packet += U32BE ( <NUM_LIT:0> ) <EOL> packet += U3264 ( self . duration , self . version ) <EOL> for i in range ( <NUM_LIT:2> ) : <EOL> packet += U32BE ( <NUM_LIT:0> ) <EOL> packet += S16BE ( self . layer ) <EOL> packet += S16BE ( self . alternate_group ) <EOL> packet += S8_8BE ( self . volume ) <EOL> packet += U16BE ( <NUM_LIT:0> ) <EOL> for i in range ( <NUM_LIT:9> ) : <EOL> packet += U32BE ( self . transform_matrix [ i ] ) <EOL> packet += S16BE_16 ( self . width ) <EOL> packet += S16BE_16 ( self . height ) <EOL> @ classmethod <EOL> def _deserialize ( cls , io ) : <EOL> version = U8 . read ( io ) <EOL> flags = U24BE . read ( io ) <EOL> creation_time = U3264 . read ( io , version ) <EOL> modification_time = U3264 . read ( io , version ) <EOL> track_id = U32BE . read ( io ) <EOL> U32BE . read ( io ) <EOL> duration = U3264 . read ( io , version ) <EOL> for i in range ( <NUM_LIT:2> ) : <EOL> U32BE . read ( io ) <EOL> layer = S16BE . read ( io ) <EOL> alternate_group = S16BE . read ( io ) <EOL> volume = S8_8BE . read ( io ) <EOL> U16BE . read ( io ) <EOL> transform_matrix = [ ] <EOL> for i in range ( <NUM_LIT:9> ) : <EOL> transform_matrix . append ( S32BE . read ( io ) ) <EOL> width = S16_16 . read ( io ) <EOL> height = S16_16 . read ( io ) <EOL> return cls ( version , flags , creation_time , modification_time , <EOL> track_id , duration , layer , alternate_group , volume , <EOL> transform_matrix , width , height ) <EOL> class BoxPayloadMDHD ( BoxPayload ) : <EOL> def __init__ ( self , version = <NUM_LIT:0> , creation_time = <NUM_LIT:0> , modification_time = <NUM_LIT:0> , <EOL> time_scale = <NUM_LIT:1000> , duration = <NUM_LIT:0> , language = "<STR_LIT>" ) : <EOL> self . version = version <EOL> self . creation_time = creation_time <EOL> self . modification_time = modification_time <EOL> self . time_scale = time_scale <EOL> self . duration = duration <EOL> self . language = language <EOL> @ property <EOL> def size ( self ) : <EOL> size = <NUM_LIT:1> + <NUM_LIT:3> + <NUM_LIT:4> + <NUM_LIT:4> + <NUM_LIT:4> + <NUM_LIT:4> + <NUM_LIT:2> + <NUM_LIT:2> <EOL> if self . version == <NUM_LIT:1> : <EOL> size += <NUM_LIT:4> * <NUM_LIT:3> <EOL> return size <EOL> def _serialize ( self , packet ) : <EOL> packet += U8 ( self . version ) <EOL> packet += U24BE ( <NUM_LIT:0> ) <EOL> packet += U3264 ( self . creation_time , self . version ) <EOL> packet += U3264 ( self . modification_time , self . version ) <EOL> packet += U32BE ( self . time_scale ) <EOL> packet += U3264 ( self . duration , self . version ) <EOL> packet += S16BE ( iso639_to_lang ( self . language ) ) <EOL> packet += U16BE ( <NUM_LIT:0> ) <EOL> @ classmethod <EOL> def _deserialize ( cls , io ) : <EOL> version = U8 . read ( io ) <EOL> U24BE . read ( io ) <EOL> creation_time = U3264 . read ( io , version ) <EOL> modification_time = U3264 . read ( io , version ) <EOL> time_scale = U32BE . read ( io ) <EOL> duration = U3264 . read ( io , version ) <EOL> language = lang_to_iso639 ( U16BE . read ( io ) ) <EOL> U16BE . read ( io ) <EOL> return cls ( version , creation_time , modification_time , <EOL> time_scale , duration , language ) <EOL> class BoxPayloadHDLR ( BoxPayload ) : <EOL> def __init__ ( self , version = <NUM_LIT:0> , predefined = <NUM_LIT:0> , handler_type = "<STR_LIT>" , <EOL> name = "<STR_LIT>" ) : <EOL> self . version = version <EOL> self . predefined = predefined <EOL> self . handler_type = handler_type <EOL> self . name = name <EOL> @ property <EOL> def size ( self ) : <EOL> size = <NUM_LIT:1> + <NUM_LIT:3> + <NUM_LIT:4> + <NUM_LIT:4> + ( <NUM_LIT:3> * <NUM_LIT:4> ) <EOL> size += len ( self . name ) <EOL> return size <EOL> def _serialize ( self , packet ) : <EOL> packet += U8 ( self . version ) <EOL> packet += U24BE ( <NUM_LIT:0> ) <EOL> packet += U32BE ( self . predefined ) <EOL> packet += FourCC ( self . handler_type ) <EOL> for i in range ( <NUM_LIT:3> ) : <EOL> packet += U32BE ( <NUM_LIT:0> ) <EOL> packet += CString ( self . name ) <EOL> @ classmethod <EOL> def _deserialize ( cls , io ) : <EOL> version = U8 . read ( io ) <EOL> flags = U24BE . read ( io ) <EOL> predefined = U32BE . read ( io ) <EOL> handler_type = FourCC . read ( io ) <EOL> for i in range ( <NUM_LIT:3> ) : <EOL> U32BE . read ( io ) <EOL> name = CString . read ( io ) <EOL> return cls ( version , predefined , handler_type , <EOL> name ) <EOL> class BoxPayloadVMHD ( BoxPayload ) : <EOL> def __init__ ( self , version = <NUM_LIT:0> , flags = <NUM_LIT:1> , graphics_mode = <NUM_LIT:0> , op_color = [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ] ) : <EOL> self . version = version <EOL> self . flags = flags <EOL> self . graphics_mode = graphics_mode <EOL> self . op_color = op_color <EOL> @ property <EOL> def size ( self ) : <EOL> return <NUM_LIT:1> + <NUM_LIT:3> + <NUM_LIT:2> + ( <NUM_LIT:3> * <NUM_LIT:2> ) <EOL> def _serialize ( self , packet ) : <EOL> packet += U8 ( self . version ) <EOL> packet += U24BE ( self . flags ) <EOL> packet += U16BE ( self . graphics_mode ) <EOL> for i in range ( <NUM_LIT:3> ) : <EOL> packet += U16BE ( self . op_color [ i ] ) <EOL> @ classmethod <EOL> def _deserialize ( cls , io ) : <EOL> version = U8 . read ( io ) <EOL> flags = U24BE . read ( io ) <EOL> graphics_mode = U16BE . read ( io ) <EOL> op_color = [ ] <EOL> for i in range ( <NUM_LIT:3> ) : <EOL> op_color . append ( U16BE . read ( io ) ) <EOL> return cls ( version , flags , graphics_mode , op_color ) <EOL> class BoxPayloadDREF ( BoxContainer ) : <EOL> def __init__ ( self , version = <NUM_LIT:0> , boxes = [ ] ) : <EOL> self . version = version <EOL> self . boxes = boxes <EOL> @ property <EOL> def size ( self ) : <EOL> size = <NUM_LIT:1> + <NUM_LIT:3> + <NUM_LIT:4> <EOL> for box in self . boxes : <EOL> size += box . size <EOL> return size <EOL> def _serialize ( self , packet ) : <EOL> packet += U8 ( self . version ) <EOL> packet += U24BE ( <NUM_LIT:0> ) <EOL> packet += U32BE ( len ( self . boxes ) ) <EOL> for box in self . boxes : <EOL> box . serialize ( packet ) <EOL> @ classmethod <EOL> def _deserialize ( cls , io ) : <EOL> version = U8 . read ( io ) <EOL> flags = U24BE . read ( io ) <EOL> entry_count = U32BE . read ( io ) <EOL> boxes = [ ] <EOL> for i in range ( entry_count ) : <EOL> box = Box . deserialize ( io ) <EOL> boxes . append ( box ) <EOL> return cls ( version , boxes ) <EOL> class BoxPayloadURL ( BoxPayload ) : <EOL> def __init__ ( self , version = <NUM_LIT:0> , flags = <NUM_LIT:1> ) : <EOL> self . version = version <EOL> self . flags = flags <EOL> @ property <EOL> def size ( self ) : <EOL> return <NUM_LIT:4> <EOL> def _serialize ( self , packet ) : <EOL> packet += U8 ( self . version ) <EOL> packet += U24BE ( self . flags ) <EOL> @ classmethod <EOL> def _deserialize ( cls , io ) : <EOL> version = U8 . read ( io ) <EOL> flags = U24BE . read ( io ) <EOL> return cls ( version , flags ) <EOL> class BoxPayloadSTSD ( BoxContainer ) : <EOL> def __init__ ( self , version = <NUM_LIT:0> , descriptions = [ ] ) : <EOL> self . version = version <EOL> self . descriptions = descriptions <EOL> @ property <EOL> def size ( self ) : <EOL> size = <NUM_LIT:4> + <NUM_LIT:4> <EOL> for description in self . descriptions : <EOL> size += description . size <EOL> return size <EOL> @ property <EOL> def boxes ( self ) : <EOL> return self . descriptions <EOL> def _serialize ( self , packet ) : <EOL> packet += U8 ( self . version ) <EOL> packet += U24BE ( <NUM_LIT:0> ) <EOL> packet += U32BE ( len ( self . descriptions ) ) <EOL> for description in self . descriptions : <EOL> description . serialize ( packet ) <EOL> @ classmethod <EOL> def _deserialize ( cls , io ) : <EOL> version = U8 . read ( io ) <EOL> flags = U24BE . read ( io ) <EOL> count = U32BE . read ( io ) <EOL> descriptions = [ ] <EOL> for i in range ( count ) : <EOL> box = Box . deserialize ( io ) <EOL> descriptions . append ( box ) <EOL> return cls ( version , descriptions ) <EOL> class BoxPayloadVisualSample ( BoxContainer ) : <EOL> def __init__ ( self , data_reference_index = <NUM_LIT:0> , width = <NUM_LIT:0> , height = <NUM_LIT:0> , <EOL> horiz_resolution = <NUM_LIT:0.0> , vert_resolution = <NUM_LIT:0.0> , frame_count = <NUM_LIT:0> , <EOL> compressor_name = "<STR_LIT>" , depth = <NUM_LIT:0> , boxes = [ ] ) : <EOL> self . data_reference_index = data_reference_index <EOL> self . width = width <EOL> self . height = height <EOL> self . horiz_resolution = horiz_resolution <EOL> self . vert_resolution = vert_resolution <EOL> self . frame_count = frame_count <EOL> self . compressor_name = compressor_name <EOL> slef . depth = depth <EOL> self . boxes = boxes <EOL> @ property <EOL> def size ( self ) : <EOL> return <NUM_LIT:4> <EOL> def _serialize ( self , packet ) : <EOL> packet += U8 ( self . version ) <EOL> packet += U24BE ( self . flags ) <EOL> @ classmethod <EOL> def _deserialize ( cls , io ) : <EOL> for i in range ( <NUM_LIT:4> ) : <EOL> U8 . read ( io ) <EOL> return cls ( version , flags ) <EOL> class BoxPayloadMDAT ( RawPayload ) : <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" . format ( self . size ) <EOL> class BoxPayloadSKIP ( RawPayload ) : <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" . format ( self . size ) <EOL> class BoxPayloadFREE ( RawPayload ) : <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" . format ( self . size ) <EOL> class BoxPayloadABST ( BoxPayload ) : <EOL> class Flags ( Union ) : <EOL> class Bits ( BigEndianStructure ) : <EOL> _fields_ = [ ( "<STR_LIT>" , c_uint8 , <NUM_LIT:2> ) , <EOL> ( "<STR_LIT>" , c_uint8 , <NUM_LIT:1> ) , <EOL> ( "<STR_LIT>" , c_uint8 , <NUM_LIT:1> ) , <EOL> ( "<STR_LIT>" , c_uint8 , <NUM_LIT:4> ) ] <EOL> _fields_ = [ ( "<STR_LIT>" , Bits ) , ( "<STR_LIT>" , c_uint8 ) ] <EOL> def __init__ ( self , version , bootstrap_info_version , profile , live , update , <EOL> time_scale , current_media_time , smpte_time_code_offset , <EOL> movie_identifier , server_entry_table , quality_entry_table , <EOL> drm_data , metadata , segment_run_table_entries , <EOL> fragment_run_table_entries ) : <EOL> self . version = version <EOL> self . bootstrap_info_version = bootstrap_info_version <EOL> self . flags = self . Flags ( ) <EOL> self . flags . bit . profile = profile <EOL> self . flags . bit . live = live <EOL> self . flags . bit . update = update <EOL> self . flags . bit . reserved = <NUM_LIT:0> <EOL> self . time_scale = time_scale <EOL> self . current_media_time = current_media_time <EOL> self . smpte_time_code_offset = smpte_time_code_offset <EOL> self . movie_identifier = movie_identifier <EOL> self . server_entry_table = server_entry_table <EOL> self . quality_entry_table = quality_entry_table <EOL> self . drm_data = drm_data <EOL> self . metadata = metadata <EOL> self . segment_run_table_entries = segment_run_table_entries <EOL> self . fragment_run_table_entries = fragment_run_table_entries <EOL> profile = flagproperty ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> update = flagproperty ( "<STR_LIT>" , "<STR_LIT>" , True ) <EOL> live = flagproperty ( "<STR_LIT>" , "<STR_LIT>" , True ) <EOL> @ property <EOL> def size ( self ) : <EOL> size = <NUM_LIT:1> + <NUM_LIT:3> + <NUM_LIT:4> + <NUM_LIT:1> + <NUM_LIT:4> + <NUM_LIT:8> + <NUM_LIT:8> <EOL> size += len ( self . movie_identifier ) + <NUM_LIT:1> <EOL> size += <NUM_LIT:1> <EOL> for server in self . server_entry_table : <EOL> size += len ( server ) + <NUM_LIT:1> <EOL> size += <NUM_LIT:1> <EOL> for quality_entry in self . quality_entry_table : <EOL> size += len ( quality_entry ) + <NUM_LIT:1> <EOL> size += len ( self . drm_data ) + <NUM_LIT:1> <EOL> size += len ( self . metadata ) + <NUM_LIT:1> <EOL> size += <NUM_LIT:1> <EOL> for segment_run_table in self . segment_run_table_entries : <EOL> size += segment_run_table . size <EOL> size += <NUM_LIT:1> <EOL> for fragment_run_table in self . fragment_run_table_entries : <EOL> size += fragment_run_table . size <EOL> return size <EOL> def _serialize ( self , packet ) : <EOL> packet += U8 ( self . version ) <EOL> packet += U24BE ( <NUM_LIT:0> ) <EOL> packet += U32BE ( self . bootstrap_info_version ) <EOL> packet += U8 ( self . flags . byte ) <EOL> packet += U32BE ( self . time_scale ) <EOL> packet += U64BE ( self . current_media_time ) <EOL> packet += U64BE ( self . smpte_time_code_offset ) <EOL> packet += CString ( self . movie_identifier ) <EOL> packet += U8 ( len ( self . server_entry_table ) ) <EOL> for server_entry in self . server_entry_table : <EOL> packet += CString ( server_entry ) <EOL> packet += U8 ( len ( self . quality_entry_table ) ) <EOL> for quality_entry in self . quality_entry_table : <EOL> packet += CString ( quality_entry ) <EOL> packet += CString ( self . drm_data ) <EOL> packet += CString ( self . metadata ) <EOL> packet += U8 ( len ( self . segment_run_table_entries ) ) <EOL> for segment_run_table in self . segment_run_table_entries : <EOL> segment_run_table . serialize ( packet ) <EOL> packet += U8 ( len ( self . fragment_run_table_entries ) ) <EOL> for fragment_run_table in self . fragment_run_table_entries : <EOL> fragment_run_table . serialize ( packet ) <EOL> @ classmethod <EOL> def _deserialize ( cls , io ) : <EOL> version = U8 . read ( io ) <EOL> U24BE . read ( io ) <EOL> bootstrap_info_version = U32BE . read ( io ) <EOL> flags = cls . Flags ( ) <EOL> flags . byte = U8 . read ( io ) <EOL> time_scale = U32BE . read ( io ) <EOL> current_media_time = U64BE . read ( io ) <EOL> smpte_time_code_offset = U64BE . read ( io ) <EOL> movie_identifier = CString . read ( io ) <EOL> server_entry_table = [ ] <EOL> server_entry_count = U8 . read ( io ) <EOL> for i in range ( server_entry_count ) : <EOL> server_entry = CString . read ( io ) <EOL> server_entry_table . append ( server_entry ) <EOL> quality_entry_table = [ ] <EOL> quality_entry_count = U8 . read ( io ) <EOL> for i in range ( quality_entry_count ) : <EOL> quality_entry = CString . read ( io ) <EOL> quality_entry_table . append ( quality_entry ) <EOL> drm_data = CString . read ( io ) <EOL> metadata = CString . read ( io ) <EOL> segment_run_table_entries = [ ] <EOL> segment_run_table_count = U8 . read ( io ) <EOL> for i in range ( segment_run_table_count ) : <EOL> segment_run_table = Box . deserialize ( io ) <EOL> segment_run_table_entries . append ( segment_run_table ) <EOL> fragment_run_table_entries = [ ] <EOL> fragment_run_table_count = U8 . read ( io ) <EOL> for i in range ( fragment_run_table_count ) : <EOL> fragment_run_table = Box . deserialize ( io ) <EOL> fragment_run_table_entries . append ( fragment_run_table ) <EOL> return cls ( version , bootstrap_info_version , flags . bit . profile , <EOL> flags . bit . live , flags . bit . update , time_scale , <EOL> current_media_time , smpte_time_code_offset , movie_identifier , <EOL> server_entry_table , quality_entry_table , drm_data , <EOL> metadata , segment_run_table_entries , fragment_run_table_entries ) <EOL> class SegmentRunEntry ( BoxPayload ) : <EOL> def __init__ ( self , first_segment , fragments_per_segment ) : <EOL> self . first_segment = first_segment <EOL> self . fragments_per_segment = fragments_per_segment <EOL> @ property <EOL> def size ( self ) : <EOL> return <NUM_LIT:8> <EOL> def _serialize ( self , packet ) : <EOL> packet += U32BE ( self . first_segment ) <EOL> packet += U32BE ( self . fragments_per_segment ) <EOL> @ classmethod <EOL> def _deserialize ( cls , io ) : <EOL> first_segment = U32BE . read ( io ) <EOL> fragments_per_segment = U32BE . read ( io ) <EOL> return cls ( first_segment , fragments_per_segment ) <EOL> class BoxPayloadASRT ( BoxPayload ) : <EOL> def __init__ ( self , version , flags , quality_segment_url_modifiers , <EOL> segment_run_entry_table ) : <EOL> self . version = version <EOL> self . flags = flags <EOL> self . quality_segment_url_modifiers = quality_segment_url_modifiers <EOL> self . segment_run_entry_table = segment_run_entry_table <EOL> @ property <EOL> def size ( self ) : <EOL> size = <NUM_LIT:1> + <NUM_LIT:3> + <NUM_LIT:1> + <NUM_LIT:4> <EOL> for quality in self . quality_segment_url_modifiers : <EOL> size += len ( quality ) + <NUM_LIT:1> <EOL> for segment_run_entry in self . segment_run_entry_table : <EOL> size += segment_run_entry . size <EOL> return size <EOL> def _serialize ( self , packet ) : <EOL> packet += U8 ( self . version ) <EOL> packet += U24BE ( self . flags ) <EOL> packet += U8 ( len ( self . quality_segment_url_modifiers ) ) <EOL> for quality in self . quality_segment_url_modifiers : <EOL> packet += CString ( quality ) <EOL> packet += U32BE ( len ( self . segment_run_entry_table ) ) <EOL> for segment_run_entry in self . segment_run_entry_table : <EOL> segment_run_entry . serialize ( packet ) <EOL> @ classmethod <EOL> def _deserialize ( cls , io ) : <EOL> version = U8 . read ( io ) <EOL> flags = U24BE . read ( io ) <EOL> quality_segment_url_modifiers = [ ] <EOL> quality_entry_count = U8 . read ( io ) <EOL> for i in range ( quality_entry_count ) : <EOL> quality = CString . read ( io ) <EOL> quality_segment_url_modifiers . append ( quality ) <EOL> segment_run_entry_count = U32BE . read ( io ) <EOL> segment_run_entry_table = [ ] <EOL> for i in range ( segment_run_entry_count ) : <EOL> segment_run_entry = SegmentRunEntry . deserialize ( io ) <EOL> segment_run_entry_table . append ( segment_run_entry ) <EOL> return cls ( version , flags , quality_segment_url_modifiers , <EOL> segment_run_entry_table ) <EOL> class FragmentRunEntry ( BoxPayload ) : <EOL> def __init__ ( self , first_fragment , first_fragment_timestamp , <EOL> fragment_duration , discontinuity_indicator ) : <EOL> self . first_fragment = first_fragment <EOL> self . first_fragment_timestamp = first_fragment_timestamp <EOL> self . fragment_duration = fragment_duration <EOL> self . discontinuity_indicator = discontinuity_indicator <EOL> @ property <EOL> def size ( self ) : <EOL> size = <NUM_LIT:4> + <NUM_LIT:8> + <NUM_LIT:4> <EOL> if self . fragment_duration == <NUM_LIT:0> : <EOL> size += <NUM_LIT:1> <EOL> return size <EOL> def _serialize ( self , packet ) : <EOL> packet += U32BE ( self . first_fragment ) <EOL> packet += U64BE ( self . first_fragment_timestamp ) <EOL> packet += U32BE ( self . fragment_duration ) <EOL> if self . fragment_duration == <NUM_LIT:0> : <EOL> packet += U8 ( self . discontinuity_indicator ) <EOL> @ classmethod <EOL> def _deserialize ( cls , io ) : <EOL> first_fragment = U32BE . read ( io ) <EOL> first_fragment_timestamp = U64BE . read ( io ) <EOL> fragment_duration = U32BE . read ( io ) <EOL> if fragment_duration == <NUM_LIT:0> : <EOL> discontinuity_indicator = U8 . read ( io ) <EOL> else : <EOL> discontinuity_indicator = None <EOL> return cls ( first_fragment , first_fragment_timestamp , <EOL> fragment_duration , discontinuity_indicator ) <EOL> class BoxPayloadAFRT ( BoxPayload ) : <EOL> def __init__ ( self , version , flags , time_scale , <EOL> quality_segment_url_modifiers , <EOL> fragment_run_entry_table ) : <EOL> self . version = version <EOL> self . flags = flags <EOL> self . time_scale = time_scale <EOL> self . quality_segment_url_modifiers = quality_segment_url_modifiers <EOL> self . fragment_run_entry_table = fragment_run_entry_table <EOL> @ property <EOL> def size ( self ) : <EOL> size = <NUM_LIT:1> + <NUM_LIT:3> + <NUM_LIT:4> + <NUM_LIT:1> + <NUM_LIT:4> <EOL> for quality in self . quality_segment_url_modifiers : <EOL> size += len ( quality ) + <NUM_LIT:1> <EOL> for fragment_run_entry in self . fragment_run_entry_table : <EOL> size += fragment_run_entry . size <EOL> return size <EOL> def _serialize ( self , packet ) : <EOL> packet += U8 ( self . version ) <EOL> packet += U24BE ( self . flags ) <EOL> packet += U32BE ( self . time_scale ) <EOL> packet += U8 ( len ( self . quality_segment_url_modifiers ) ) <EOL> for quality in self . quality_segment_url_modifiers : <EOL> packet += CString ( quality ) <EOL> packet += U32BE ( len ( self . fragment_run_entry_table ) ) <EOL> for fragment_run_entry in self . fragment_run_entry_table : <EOL> fragment_run_entry . serialize ( packet ) <EOL> @ classmethod <EOL> def _deserialize ( cls , io ) : <EOL> version = U8 . read ( io ) <EOL> flags = U24BE . read ( io ) <EOL> time_scale = U32BE . read ( io ) <EOL> quality_segment_url_modifiers = [ ] <EOL> quality_entry_count = U8 . read ( io ) <EOL> for i in range ( quality_entry_count ) : <EOL> quality = CString . read ( io ) <EOL> quality_segment_url_modifiers . append ( quality ) <EOL> fragment_run_entry_count = U32BE . read ( io ) <EOL> fragment_run_entry_table = [ ] <EOL> for i in range ( fragment_run_entry_count ) : <EOL> fragment_run_entry = FragmentRunEntry . deserialize ( io ) <EOL> fragment_run_entry_table . append ( fragment_run_entry ) <EOL> return cls ( version , flags , time_scale , <EOL> quality_segment_url_modifiers , <EOL> fragment_run_entry_table ) <EOL> class BoxPayloadMVEX ( BoxContainer ) : <EOL> pass <EOL> class BoxPayloadMFRA ( BoxContainer ) : <EOL> pass <EOL> class BoxPayloadTRAK ( BoxContainer ) : <EOL> pass <EOL> class BoxPayloadMDIA ( BoxContainer ) : <EOL> pass <EOL> class BoxPayloadMINF ( BoxContainer ) : <EOL> pass <EOL> class BoxPayloadSTBL ( BoxContainer ) : <EOL> pass <EOL> class BoxPayloadMOOV ( BoxContainer ) : <EOL> pass <EOL> class BoxPayloadMOOF ( BoxContainer ) : <EOL> pass <EOL> class BoxPayloadMETA ( BoxContainer ) : <EOL> pass <EOL> class BoxPayloadDINF ( BoxContainerSingle ) : <EOL> pass <EOL> PayloadTypes = { <EOL> "<STR_LIT>" : BoxPayloadFTYP , <EOL> "<STR_LIT>" : BoxPayloadMVHD , <EOL> "<STR_LIT>" : BoxPayloadTREX , <EOL> "<STR_LIT>" : BoxPayloadTKHD , <EOL> "<STR_LIT>" : BoxPayloadMDHD , <EOL> "<STR_LIT>" : BoxPayloadHDLR , <EOL> "<STR_LIT>" : BoxPayloadVMHD , <EOL> "<STR_LIT>" : BoxPayloadDREF , <EOL> "<STR_LIT:url>" : BoxPayloadURL , <EOL> "<STR_LIT>" : BoxPayloadSTSD , <EOL> "<STR_LIT>" : BoxPayloadMDAT , <EOL> "<STR_LIT>" : BoxPayloadABST , <EOL> "<STR_LIT>" : BoxPayloadASRT , <EOL> "<STR_LIT>" : BoxPayloadAFRT , <EOL> "<STR_LIT>" : BoxPayloadSKIP , <EOL> "<STR_LIT>" : BoxPayloadFREE , <EOL> "<STR_LIT>" : BoxPayloadMOOV , <EOL> "<STR_LIT>" : BoxPayloadMOOF , <EOL> "<STR_LIT>" : BoxPayloadMVEX , <EOL> "<STR_LIT>" : BoxPayloadMDIA , <EOL> "<STR_LIT>" : BoxPayloadMINF , <EOL> "<STR_LIT>" : BoxPayloadMETA , <EOL> "<STR_LIT>" : BoxPayloadMFRA , <EOL> "<STR_LIT>" : BoxPayloadSTBL , <EOL> "<STR_LIT>" : BoxPayloadTRAK , <EOL> "<STR_LIT>" : BoxPayloadDINF , <EOL> } </s>
