python - Scapy layer for MPEG2-TS, with conditionalField for adaptation -
i try create mpeg2-ts layer scapy.
i need "add" , parse additional fields based on adaptation field.
here code:
_adapt_type = { 0x0 : 'reserved', 0x1 : 'payload only', 0x2 : 'adaptation only', 0x3 : 'adaptation , payload', } class mpeg2_ts(packet): name = "mpeg2-ts" fields_desc=[ byteenumfield('sync_byte', 0x47, _sync_type), bitfield('trans_err',0x0, 1), # transport error indicator (tei) if set 1 decoder ignore packet bitfield('start_ind',0x0, 1), bitfield('trans_pri',0x0, 1), xbitfield('pid', 0xa, 13), bitenumfield('trans_scramb', 0x0, 2, _scramble_type), bitenumfield('adapt_ctrl', 0x0, 2, _adapt_type), bitfield('cont_count', 0x0, 4), ]
i need parse additional data if adapt_ctrl set to:
0x1 : 'payload only', 0x2 : 'adaptation only', 0x3 : 'adaptation , payload'
how can create condition able parse base on result of field ? if "payload only" bit set, there no adaptation fields after header, didn't need parse it. if "adaptation , payload" set, need parse adaptation fields using following structure:
_adapt_fields = [ # number of bytes in adaptation field following byte bytefield('ada_len', 0x0), # set 1 if current ts packet in discontinuity state respect either continuity counter or program clock reference bitfield('dis', 0x0, 1), # set 1 if pes packet in ts packet starts video/audio sequence bitfield('ran_acc', 0x0, 1), # 1 = higher priority bitfield('es_str_pri', 0x0, 1), # set 1 if adaptation field contains pcr field bitfield('pcr_fla', 0x0, 1), # set 1 if adaptation field contains opcr field bitfield('opcr_fla', 0x0, 1), # set 1 if adaptation field contains splice countdown field bitfield('spl_fla', 0x0, 1), # set 1 if adaptation field contains private data bytes bitfield('trs_pri_dat_fla', 0x0, 1), # set 1 if adaptation field contains extension bitfield('ada_ext_fla', 0x0, 1), # variable depends on flags # bitfield('ada_ext_fla', 0x0, 1), # pcr 33+6+9 program clock reference, stored in 6 octets in big-endian 33 bits base, 6 bits padding, 9 bits extension. # opcr 33+6+9 original program clock reference. helps when 1 ts copied # splice countdown 8 indicates how many ts packets 1 splicing point occurs (may negative) # stuffing bytes variable ]
i tried conditionalfield without luck till now. help.
Comments
Post a Comment