﻿Type=StaticCode
Version=5
ModulesStructureVersion=1
B4J=true
@EndOfDesignText@
'Static code module
Sub Process_Globals
 
	Private fx As JFX
	Private bn As BigInteger
	Private cb As StringBuilder
	Private menus As Map
	Private timeSignal As Map
	Private SpliceInfoSection As Map
	Private SpliceInsert	As Map
	Private segmentation_upid As Map
	Private SpliceDescriptor As Map
	Private segmentationDescriptor As Map
	Private PrivateDescriptor As Map
	Private hexx As List
	Private segmentationUPID As Map
	Private sf As JStringFunctions
	Private Splice_Command As List 
	Private segmentationDescriptorLIST As Map
	'Private hexx As List
	Private splicecommand() As String = Array As String("splice_null","Reserved","Reserved","Reserved","splice_schedule","splice_insert","time_signal","bandwidth_reservation","Reserved","private_command","ERROR")
	Private coloumName() As String = Array As String("Nb","Name","Value")
	Private out_of_network_indicator_text() As String = Array As String(" ▲ (In Point)", " ▼ (Out Point)")
	Private bufptr As Int
	Private desptr As Int
	Private segptr As Int = 0
	Private ptr As Int
	Private SPLICE_NULL As Int = 0x00
	Private SPLICE_SCHEDULE As Int = 0x04
	Private SPLICE_INSERT As Int = 0x05
	Private TIME_SIGNAL As Int = 0x06
	Private BANDWIDTH_RESERVATION As Int = 0x07
	Private PRIVATE_COMMAND As Int = 0x00ff
	Dim xd As Int
	Private CrcTable() As Int = Array As Int( _
	0x00000000, 0x04C11DB7, 0x09823B6E, 0x0D4326D9, 0x130476DC, 0x17C56B6B, 0x1A864DB2, 0x1E475005, 0x2608EDB8, 0x22C9F00F, _
	0x2F8AD6D6, 0x2B4BCB61, 0x350C9B64, 0x31CD86D3, 0x3C8EA00A, 0x384FBDBD, 0x4C11DB70, 0x48D0C6C7, 0x4593E01E, 0x4152FDA9, _
	0x5F15ADAC, 0x5BD4B01B, 0x569796C2, 0x52568B75, 0x6A1936C8, 0x6ED82B7F, 0x639B0DA6, 0x675A1011, 0x791D4014, 0x7DDC5DA3, _
	0x709F7B7A, 0x745E66CD, 0x9823B6E0, 0x9CE2AB57, 0x91A18D8E, 0x95609039, 0x8B27C03C, 0x8FE6DD8B, 0x82A5FB52, 0x8664E6E5, _
	0xBE2B5B58, 0xBAEA46EF, 0xB7A96036, 0xB3687D81, 0xAD2F2D84, 0xA9EE3033, 0xA4AD16EA, 0xA06C0B5D, 0xD4326D90, 0xD0F37027, _
	0xDDB056FE, 0xD9714B49, 0xC7361B4C, 0xC3F706FB, 0xCEB42022, 0xCA753D95, 0xF23A8028, 0xF6FB9D9F, 0xFBB8BB46, 0xFF79A6F1, _
	0xE13EF6F4, 0xE5FFEB43, 0xE8BCCD9A, 0xEC7DD02D, 0x34867077, 0x30476DC0, 0x3D044B19, 0x39C556AE, 0x278206AB, 0x23431B1C, _
	0x2E003DC5, 0x2AC12072, 0x128E9DCF, 0x164F8078, 0x1B0CA6A1, 0x1FCDBB16, 0x018AEB13, 0x054BF6A4, 0x0808D07D, 0x0CC9CDCA, _
	0x7897AB07, 0x7C56B6B0, 0x71159069, 0x75D48DDE, 0x6B93DDDB, 0x6F52C06C, 0x6211E6B5, 0x66D0FB02, 0x5E9F46BF, 0x5A5E5B08, _
	0x571D7DD1, 0x53DC6066, 0x4D9B3063, 0x495A2DD4, 0x44190B0D, 0x40D816BA, 0xACA5C697, 0xA864DB20, 0xA527FDF9, 0xA1E6E04E, _
	0xBFA1B04B, 0xBB60ADFC, 0xB6238B25, 0xB2E29692, 0x8AAD2B2F, 0x8E6C3698, 0x832F1041, 0x87EE0DF6, 0x99A95DF3, 0x9D684044, _
	0x902B669D, 0x94EA7B2A, 0xE0B41DE7, 0xE4750050, 0xE9362689, 0xEDF73B3E, 0xF3B06B3B, 0xF771768C, 0xFA325055, 0xFEF34DE2, _
	0xC6BCF05F, 0xC27DEDE8, 0xCF3ECB31, 0xCBFFD686, 0xD5B88683, 0xD1799B34, 0xDC3ABDED, 0xD8FBA05A, 0x690CE0EE, 0x6DCDFD59, _
	0x608EDB80, 0x644FC637, 0x7A089632, 0x7EC98B85, 0x738AAD5C, 0x774BB0EB, 0x4F040D56, 0x4BC510E1, 0x46863638, 0x42472B8F, _
	0x5C007B8A, 0x58C1663D, 0x558240E4, 0x51435D53, 0x251D3B9E, 0x21DC2629, 0x2C9F00F0, 0x285E1D47, 0x36194D42, 0x32D850F5, _
	0x3F9B762C, 0x3B5A6B9B, 0x0315D626, 0x07D4CB91, 0x0A97ED48, 0x0E56F0FF, 0x1011A0FA, 0x14D0BD4D, 0x19939B94, 0x1D528623, _
	0xF12F560E, 0xF5EE4BB9, 0xF8AD6D60, 0xFC6C70D7, 0xE22B20D2, 0xE6EA3D65, 0xEBA91BBC, 0xEF68060B, 0xD727BBB6, 0xD3E6A601, _
	0xDEA580D8, 0xDA649D6F, 0xC423CD6A, 0xC0E2D0DD, 0xCDA1F604, 0xC960EBB3, 0xBD3E8D7E, 0xB9FF90C9, 0xB4BCB610, 0xB07DABA7, _
	0xAE3AFBA2, 0xAAFBE615, 0xA7B8C0CC, 0xA379DD7B, 0x9B3660C6, 0x9FF77D71, 0x92B45BA8, 0x9675461F, 0x8832161A, 0x8CF30BAD, _
	0x81B02D74, 0x857130C3, 0x5D8A9099, 0x594B8D2E, 0x5408ABF7, 0x50C9B640, 0x4E8EE645, 0x4A4FFBF2, 0x470CDD2B, 0x43CDC09C, _
	0x7B827D21, 0x7F436096, 0x7200464F, 0x76C15BF8, 0x68860BFD, 0x6C47164A, 0x61043093, 0x65C52D24, 0x119B4BE9, 0x155A565E, _
	0x18197087, 0x1CD86D30, 0x029F3D35, 0x065E2082, 0x0B1D065B, 0x0FDC1BEC, 0x3793A651, 0x3352BBE6, 0x3E119D3F, 0x3AD08088, _
	0x2497D08D, 0x2056CD3A, 0x2D15EBE3, 0x29D4F654, 0xC5A92679, 0xC1683BCE, 0xCC2B1D17, 0xC8EA00A0, 0xD6AD50A5, 0xD26C4D12, _
	0xDF2F6BCB, 0xDBEE767C, 0xE3A1CBC1, 0xE760D676, 0xEA23F0AF, 0xEEE2ED18, 0xF0A5BD1D, 0xF464A0AA, 0xF9278673, 0xFDE69BC4, _
	0x89B8FD09, 0x8D79E0BE, 0x803AC667, 0x84FBDBD0, 0x9ABC8BD5, 0x9E7D9662, 0x933EB0BB, 0x97FFAD0C, 0xAFB010B1, 0xAB710D06, _
	0xA6322BDF, 0xA2F33668, 0xBCB4666D, 0xB8757BDA, 0xB5365D03, 0xB1F740B4)
 
End Sub
 
Sub init
 
	Splice_Command.Initialize
	Splice_Command.AddAll(splicecommand)
	init_lists
	clear_lists
	sf.Initialize
	hexx.Initialize
 
End Sub
 
Sub get_type (inp As String)As String
 
	hexx.Initialize
	BuildHEXtable(inp)
	Private b1 As Int
	b1 = Bit.And(hexx.Get(13) , 0x00ff)
	Return Splice_Command.get(b1)
 
End Sub
 
Sub parse_data(inp As String)
 
	Log(inp)
	Main.AppLog("parse_data Start")
	clear_lists
	xd = 1
	ptr = 0
	segptr = 0
	BuildHEXtable(inp)
	'		If Bit.And(hexx.Get(0) , 0xff) <> 252 Then
	'			hexx.Clear
	'			Return
	'		End If
	SpliceInfoSection.Put("tableID", "0x" & Bit.ToHexString(Bit.And(hexx.Get(0) , 0xff)).ToUpperCase)
	SpliceInfoSection.Put("sectionSyntaxIndicator", Bit.And((Bit.ShiftRight(hexx.Get(1) , 7)), 0x01))
	SpliceInfoSection.Put("privateIndicator", Bit.And((Bit.ShiftRight(hexx.Get(1) , 6)), 0x01))
	SpliceInfoSection.Put("reserved1", Bit.And((Bit.ShiftRight(hexx.Get(1) , 4)), 0x03))
	Private i1 As Int = Bit.And(hexx.Get(1), 0x0f)
	Private i2 As Int = Bit.And(hexx.Get(2), 0x00ff)
	SpliceInfoSection.Put("sectionLength", Bit.ShiftLeft(i1 , 8) + i2)
	SpliceInfoSection.Put("protocolVersion", hexx.Get(3))
	SpliceInfoSection.Put("encryptedPacket", Bit.And((Bit.ShiftRight(hexx.Get(4) , 7)), 0x01))
	SpliceInfoSection.Put("encryptionAlgorithm", Bit.And((Bit.ShiftRight(hexx.Get(4) , 1)), 0x3f))
	Private l1 As Int = Bit.And(hexx.Get(4), 0x01)
	Private l2 As Int = Bit.And(hexx.Get(5), 0x00ff)
	Private l3 As Int = Bit.And(hexx.Get(6), 0x00ff)
	Private l4 As Int = Bit.And(hexx.Get(7), 0x00ff)
	Private l5 As Int = Bit.And(hexx.Get(8), 0x00ff)
	SpliceInfoSection.Put("ptsAdjustment", (Bit.ShiftLeft(l1, 32)) + (Bit.ShiftLeft(l2, 24)) + (Bit.ShiftLeft(l3, 16)) + (Bit.ShiftLeft(l4, 8)) + l5)
	SpliceInfoSection.Put("cwIndex", Bit.And(hexx.Get(9) , 0x00ff))
	Private i1 As Int = Bit.And(hexx.Get(10), 0x00ff)
	Private i2 As Int = Bit.ShiftRight(Bit.And(hexx.Get(11), 0x00f0), 4)
	SpliceInfoSection.Put("tier", Bit.ShiftLeft(i1, 4) + i2)
	Private i1 As Int = Bit.And(hexx.Get(11), 0x000f)
	Private i2 As Int = Bit.And(hexx.Get(12), 0x00ff)
	SpliceInfoSection.Put("spliceCommandLength", Bit.ShiftLeft(i1, 8) + i2)
	Private b1 As Int
	b1 = Bit.And(hexx.Get(13) , 0x00ff)
	SpliceInfoSection.Put("spliceCommandType",b1&" = (" &Splice_Command.get(b1)&")")
	bufptr = 14
	Select sf.Left(SpliceInfoSection.Get("spliceCommandType"), 2).Trim
		Case SPLICE_NULL
			Main.AppLog("SPLICE_NULL")
		Case SPLICE_SCHEDULE
			Main.AppLog("SPLICE_SCHEDULE")
		Case SPLICE_INSERT		
			Private l1 As Int = Bit.And(hexx.Get(bufptr), 0x00ff)
			bufptr = bufptr + 1
			Private l2 As Int = Bit.And(hexx.Get(bufptr), 0x00ff)
			bufptr = bufptr + 1
			Private l3 As Int = Bit.And(hexx.Get(bufptr), 0x00ff)
			bufptr = bufptr + 1
			Private l4 As Int = Bit.And(hexx.Get(bufptr), 0x00ff)
			bufptr = bufptr + 1
			SpliceInsert.Put("spliceEventID", Bit.And( Bit.ShiftLeft(l1, 24) + Bit.ShiftLeft(l2, 16) + Bit.ShiftLeft(l3, 8) + l4, 0x00ffffffff))
			Private i1 As Int = Bit.And(hexx.Get(bufptr), 0x0080)
			bufptr = bufptr + 1
			SpliceInsert.Put("spliceEventCancelIndicator", i1)
			l4 = Bit.ShiftRight(Bit.And(hexx.Get(bufptr), 0x0080), 7)
			SpliceInsert.Put("outOfNetworkIndicator", l4 &" " & out_of_network_indicator_text(l4))
			SpliceInsert.Put("programSpliceFlag", Bit.ShiftRight(Bit.And(hexx.Get(bufptr), 0x0040), 6))
			SpliceInsert.Put("durationFlag", Bit.ShiftRight(Bit.And(hexx.Get(bufptr), 0x0020), 5))
			SpliceInsert.Put("spliceImmediateFlag", Bit.ShiftRight(Bit.And(hexx.Get(bufptr), 0x0010), 4))
			bufptr = bufptr + 1
			If SpliceInsert.get("programSpliceFlag") = 1 And SpliceInsert.get("spliceImmediateFlag") = 0 Then
				If Bit.And(hexx.Get(bufptr), 0x080) <> 0 Then
					'	SpliceInsert.Put("TimeSpecifiedFlag ", 1)
					Private l1 As Int = Bit.And(hexx.Get(bufptr), 0x01)
					bufptr = bufptr + 1
					Private l2 As Int = Bit.And(hexx.Get(bufptr), 0x00ff)
					bufptr = bufptr + 1
					Private l3 As Int = Bit.And(hexx.Get(bufptr), 0x00ff)
					bufptr = bufptr + 1
					Private l4 As Int = Bit.And(hexx.Get(bufptr), 0x00ff)
					bufptr = bufptr + 1
					Private l5 As Int = Bit.And(hexx.Get(bufptr), 0x00ff)
					Private l1_, l2_, l3_, l4_, value As Long
					bn.Initialize(l1)
					l1_ = bn.ShiftLeft(32)
					bn.Initialize(l2)
					l2_ = bn.ShiftLeft(24)
					bn.Initialize(l3)
					l3_ = bn.ShiftLeft(16)
					bn.Initialize(l4)
					l4_ = bn.ShiftLeft(8)
					value = l1_ + l2_ + l3_ + l4_ + l5
					SpliceInsert.Put("ptsTime", value &" = " & MPEG_Time(value))
				End If
 
				bufptr = bufptr + 1
			End If
 
			If SpliceInsert.get("durationFlag") <> 0 Then
				SpliceInsert.Put("autoReturn", Bit.ShiftRight(Bit.And(hexx.Get(25), 0x0080), 7))
				Private l1 As Int = Bit.And(hexx.Get(bufptr), 0x01)
				bufptr = bufptr + 1
				Private l2 As Int = Bit.And(hexx.Get(bufptr), 0x00ff)
				bufptr = bufptr + 1
				Private l3 As Int = Bit.And(hexx.Get(bufptr), 0x00ff)
				bufptr = bufptr + 1
				Private l4 As Int = Bit.And(hexx.Get(bufptr), 0x00ff)
				bufptr = bufptr + 1
				Private l5 As Int = Bit.And(hexx.Get(bufptr), 0x00ff)
				bufptr = bufptr + 1
				Private l1_, l2_, l3_, l4_, value As Long
				bn.Initialize(l1)
				l1_ = bn.ShiftLeft(32)
				bn.Initialize(l2)
				l2_ = bn.ShiftLeft(24)
				bn.Initialize(l3)
				l3_ = bn.ShiftLeft(16)
				bn.Initialize(l4)
				l4_ = bn.ShiftLeft(8)
				value = l1_ + l2_ + l3_ + l4_ + l5
				SpliceInsert.Put("Break duration",value & " = " & (MPEG_Time(value)))
			End If
 
			'value & " = " & 
			Private i1 As Int = Bit.And(hexx.Get(bufptr), 0x00ff)
			bufptr = bufptr + 1
			Private i2 As Int = Bit.And(hexx.Get(bufptr), 0x00ff)
			bufptr = bufptr + 1
			SpliceInsert.Put("uniqueProgramID", Bit.ShiftLeft(i1, 8) + i2)
			SpliceInsert.Put("availNum", Bit.And(hexx.Get(bufptr), 0x00ff))
			bufptr = bufptr + 1
			SpliceInsert.Put("availsExpected", Bit.And(hexx.Get(bufptr), 0x00ff))
			bufptr = bufptr + 1
		Case TIME_SIGNAL
			timeSignal.Put("timeSpecifiedFlag", Bit.ShiftRight(Bit.And(hexx.Get(14), 0x0080), 7))
			If timeSignal.Get("timeSpecifiedFlag") <> 0 Then
				Private l1 As Int = Bit.And(hexx.Get(bufptr), 0x01)
				bufptr = bufptr + 1
				Private l2 As Int = Bit.And(hexx.Get(bufptr), 0x00ff)
				bufptr = bufptr + 1
				Private l3 As Int = Bit.And(hexx.Get(bufptr), 0x00ff)
				bufptr = bufptr + 1
				Private l4 As Int = Bit.And(hexx.Get(bufptr), 0x00ff)
				bufptr = bufptr + 1
				Private l5 As Int = Bit.And(hexx.Get(bufptr), 0x00ff)
				Private l1_, l2_, l3_, l4_, value As Long
				bn.Initialize(l1)
				l1_ = bn.ShiftLeft(32)
				bn.Initialize(l2)
				l2_ = bn.ShiftLeft(24)
				bn.Initialize(l3)
				l3_ = bn.ShiftLeft(16)
				bn.Initialize(l4)
				l4_ = bn.ShiftLeft(8)
				value = l1_ + l2_ + l3_ + l4_ + l5
				timeSignal.Put("ptsTime",value&" = " & MPEG_Time(value))
			End If
 
			bufptr = bufptr + 1
		Case BANDWIDTH_RESERVATION
			Main.AppLog("BANDWIDTH_RESERVATION")
		Case PRIVATE_COMMAND
			Main.AppLog("PRIVATE_COMMAND")
		Case Else
			'	Dlg.InformationDialog("ERROR Unknown command", "SpliceCommandType",SpliceInfoSection.Get("spliceCommandType"))
			Log("ERROR Unknown command, SpliceCommandType " &SpliceInfoSection.Get("spliceCommandType"))
	End Select
 
	If (SpliceInfoSection.get("spliceCommandLength") <> 0x0fff) Then
		If bufptr <> (SpliceInfoSection.get("spliceCommandLength") + 14) Then
			'	Log("ERROR decoded command length " & bufptr & " not equal to specified command length " & SpliceInfoSection.get("spliceCommandLength"))
			'	Dlg.ErrorDialog("ERROR decoded command length " , bufptr & " not equal to specified command length " , SpliceInfoSection.get("spliceCommandLength"))
			Log("ERROR decoded command length " & bufptr & " not equal to specified command length " & SpliceInfoSection.get("spliceCommandLength"))
		End If	
 
	End If
 
	Private i1 As Int = Bit.And(hexx.Get(bufptr), 0x00ff)
	bufptr = bufptr + 1
	Private i2 As Int = Bit.And(hexx.Get(bufptr), 0x00ff)
	bufptr = bufptr + 1
	SpliceInfoSection.Put("DescriptorLoopLength", Bit.ShiftLeft(i1, 8) + i2)
	desptr = bufptr
	If SpliceInfoSection.Get("DescriptorLoopLength") > 0 Then
		Do While (bufptr - desptr) < SpliceInfoSection.get("DescriptorLoopLength")
			Private tag As Int = Bit.And(hexx.Get(bufptr), 0x00ff)
			bufptr = bufptr + 1
			Private len As Int = Bit.And(hexx.Get(bufptr), 0x00ff)
			bufptr = bufptr + 1
			Private l1 As Int = Bit.And(hexx.Get(bufptr), 0x00ff)
			bufptr = bufptr + 1
			Private l2 As Int = Bit.And(hexx.Get(bufptr), 0x00ff)
			bufptr = bufptr + 1
			Private l3 As Int = Bit.And(hexx.Get(bufptr), 0x00ff)
			bufptr = bufptr + 1
			Private l4 As Int = Bit.And(hexx.Get(bufptr), 0x00ff)
			bufptr = bufptr + 1
			Private identifier As String = Bit.ToHexString(l1) & Bit.ToHexString(l2) & Bit.ToHexString(l3) & Bit.ToHexString(l4)
			'Private identifier As Long = ((Bit.ShiftLeft(l1, 24)) & (Bit.ShiftLeft(l2, 16)) & (Bit.ShiftLeft(l3, 8)) & l4)
			SpliceDescriptor.Put("SpliceDescriptorTag",tag&" " & get_SpliceDescriptorriptor_tag(tag))
			SpliceDescriptor.Put("DescriptorLength", len)
			Private ff As String = Chr(l1) & Chr(l2) & Chr(l3) & Chr(l4)
			SpliceDescriptor.Put("Identifier",identifier& " = ("& ff&")")
			If (identifier = "43554549") Then
				Select tag
					Case 0
						SpliceInfoSection.Put("AvailDescriptorLength", len)
						Private l1 As Int = Bit.And(hexx.Get(bufptr), 0x00ff)
						bufptr = bufptr + 1
						Private l2 As Int = Bit.And(hexx.Get(bufptr), 0x00ff)
						bufptr = bufptr + 1
						Private l3 As Int = Bit.And(hexx.Get(bufptr), 0x00ff)
						bufptr = bufptr + 1
						Private l4 As Int = Bit.And(hexx.Get(bufptr), 0x00ff)
						bufptr = bufptr + 1
						Private availDesc As Long = Bit.And(((Bit.ShiftLeft(l1, 24)) + (Bit.ShiftLeft(l2, 16)) + (Bit.ShiftLeft(l3, 8)) + l4), 0x00ffffffff)
						SpliceInfoSection.Put("AvailDescriptor", availDesc)
					Case 1
						SpliceInfoSection.Put("DTMFDescriptorLength", len)
						Private preroll As Double = Bit.And(hexx.Get(bufptr), 0x00ff)
						preroll = preroll / 10
						SpliceInfoSection.Put("Preroll", preroll)
						bufptr = bufptr + 1
						Private dtmfCount As Int = Bit.ShiftRight(Bit.And(hexx.Get(bufptr), 0x00E0), 5)
						bufptr = bufptr + 1
						SpliceInfoSection.Put("DTMFCount", dtmfCount)
						For i = 0 To dtmfCount
							SpliceInfoSection.Put("DTMFChar", Bit.And(hexx.Get(bufptr), 0x00ff))
							bufptr = bufptr + 1
						Next
 
					Case 2
						'SegmentDescriptor.Put("SegmentationDescriptorLength", len)
						'	seg(segptr).Initialize
						'	seg(segptr).descriptorLength = len
						'						segmentationDescriptor.Put("descriptorLength", len)
						Private l1 As Int = Bit.And(hexx.Get(bufptr), 0x00ff)
						bufptr = bufptr + 1
						Private l2 As Int = Bit.And(hexx.Get(bufptr), 0x00ff)
						bufptr = bufptr + 1
						Private l3 As Int = Bit.And(hexx.Get(bufptr), 0x00ff)
						bufptr = bufptr + 1
						Private l4 As Int = Bit.And(hexx.Get(bufptr), 0x00ff)
						bufptr = bufptr + 1
						'seg(segptr).segmentationEventID = Bit.And(((Bit.ShiftLeft(l1, 24)) + (Bit.ShiftLeft(l2, 16)) + (Bit.ShiftLeft(l3, 8)) + l4), 0x00ffffffff)
						segmentationDescriptor.Put("segmentationEventID", Bit.And(((Bit.ShiftLeft(l1, 24)) + (Bit.ShiftLeft(l2, 16)) + (Bit.ShiftLeft(l3, 8)) + l4), 0x00ffffffff))
						'seg(segptr).segmentationEventCancelIndicator = Bit.ShiftRight(Bit.And(hexx.Get(bufptr), 0x0080), 7)
						segmentationDescriptor.Put("segmentationEventCancelIndicator", Bit.ShiftRight(Bit.And(hexx.Get(bufptr), 0x0080), 7))
						'seg(segptr).reserved1 = Bit.And(hexx.Get(bufptr), 0x00ff)
						segmentationDescriptor.Put("reserved1", Bit.And(hexx.Get(bufptr), 0x00ff))
						bufptr = bufptr + 1
						'If seg(segptr).segmentationEventCancelIndicator = 0 Then
						If segmentationDescriptor.Get("segmentationEventCancelIndicator") = 0 Then
							'seg(segptr).programSegmentationFlag = Bit.ShiftRight(Bit.And(hexx.Get(bufptr), 0x0080), 7)
							segmentationDescriptor.Put("programSegmentationFlag", Bit.ShiftRight(Bit.And(hexx.Get(bufptr), 0x0080), 7))
							'seg(segptr).segmentationDurationFlag = Bit.ShiftRight(Bit.And(hexx.Get(bufptr), 0x0040), 6)
							segmentationDescriptor.Put("segmentationDurationFlag", Bit.ShiftRight(Bit.And(hexx.Get(bufptr), 0x0040), 6))
							'seg(segptr).deliveryNotRestricted = Bit.ShiftRight(Bit.And(hexx.Get(bufptr), 0x0020), 5)
							segmentationDescriptor.Put("deliveryNotRestricted", Bit.ShiftRight(Bit.And(hexx.Get(bufptr), 0x0020), 5))
							'If seg(segptr).deliveryNotRestricted = 0 Then
							If segmentationDescriptor.Get("deliveryNotRestricted") = 0 Then
								'seg(segptr).webDeliveryAllowedFlag = Bit.ShiftRight(Bit.And(hexx.Get(bufptr), 0x0010), 4)
								segmentationDescriptor.Put("webDeliveryAllowedFlag", Bit.ShiftRight(Bit.And(hexx.Get(bufptr), 0x0010), 4))
								'seg(segptr).noRegionalBlackoutFlag = Bit.ShiftRight(Bit.And(hexx.Get(bufptr), 0x0008), 3)
								segmentationDescriptor.Put("noRegionalBlackoutFlag", Bit.ShiftRight(Bit.And(hexx.Get(bufptr), 0x0008), 3))
								'seg(segptr).archiveAllowed = Bit.ShiftRight(Bit.And(hexx.Get(bufptr), 0x0004), 2
								segmentationDescriptor.Put("archiveAllowed", Bit.ShiftRight(Bit.And(hexx.Get(bufptr), 0x0004), 2))
								'seg(segptr).deviceRestriction = Bit.And(hexx.Get(bufptr), 0x0003)
								segmentationDescriptor.Put("deviceRestriction", Bit.And(hexx.Get(bufptr), 0x0003))
							Else
								'seg(segptr).reserved2 = 	Bit.And((Bit.ShiftRight(hexx.Get(bufptr) , 1)), 0x1f)
								segmentationDescriptor.Put("reserved2", 	Bit.And((Bit.ShiftRight(hexx.Get(bufptr) , 1)), 0x1f))
							End If	
 
							bufptr = bufptr + 1
							If segmentationDescriptor.Get("programSegmentationFlag") = 0 Then
								'If seg(segptr).programSegmentationFlag = 0 Then
							Else
							End If	
 
							If segmentationDescriptor.Get("segmentationDurationFlag") = 1 Then
								'If seg(segptr).segmentationDurationFlag = 1 Then
								Private l1 As Int = Bit.And(hexx.Get(bufptr), 0x0ff)
								bufptr = bufptr + 1
								Private l2 As Int = Bit.And(hexx.Get(bufptr), 0x00ff)
								bufptr = bufptr + 1
								Private l3 As Int = Bit.And(hexx.Get(bufptr), 0x00ff)
								bufptr = bufptr + 1
								Private l4 As Int = Bit.And(hexx.Get(bufptr), 0x00ff)
								bufptr = bufptr + 1
								Private l5 As Int = Bit.And(hexx.Get(bufptr), 0x00ff)
								bufptr = bufptr + 1
								Private value As Long
								value = Bit.ShiftLeft(l1, 32) + Bit.ShiftLeft(l2, 24) + Bit.ShiftLeft(l3, 16) + Bit.ShiftLeft(l4, 8) + l5
								'seg(segptr).segmentationDuration = value & " = " & MPEG_Time(value)
								segmentationDescriptor.Put("segmentationDuration", value & " = " & MPEG_Time(value))
							End If
 
							Dim segmentationUPIDtype As Int 
							Dim segmentationUPIDlength As Int
							'seg(segptr).segmentationUPIDtype = Bit.And(hexx.Get(bufptr), 0x00ff)
							'segmentationDescriptor.Put("segmentationUPIDtype", Bit.And(hexx.Get(bufptr), 0x00ff))
							segmentationUPIDtype = Bit.And(hexx.Get(bufptr), 0x00ff)
							bufptr = bufptr + 1
							'seg(segptr).segmentationUPIDlength = Bit.And(hexx.Get(bufptr), 0x00ff)
							'segmentationDescriptor.Put("segmentationUPIDlength", Bit.And(hexx.Get(bufptr), 0x00ff))
							segmentationUPIDlength = Bit.And(hexx.Get(bufptr), 0x00ff)
							bufptr = bufptr + 1
							'Select Case seg(segptr).segmentationUPIDtype
							Select Case	segmentationUPIDtype'segmentationDescriptor.Get("segmentationUPIDtype")
								Case 0x00
								Case 0x01
									'seg(segptr).segmentationUPIDtypeText = segmentation_upid_type(1)
									segmentationDescriptor.Put("segmentationUPIDtypeText","1 = " & segmentation_upid_type(1))
									segmentationDescriptor.Put("segmentationUPIDlength", segmentationUPIDlength)
									Private e As String
									'For j = bufptr To bufptr + seg(segptr).segmentationUPIDlength
									For j = bufptr To bufptr + segmentationDescriptor.Get("segmentationUPIDlength")
										If hexx.get(j) > 31 Then
											e = e & Chr(hexx.get(j))
										Else
											e = e & "0"	
										End If
 
									Next
 
									'seg(segptr).segmentationupidErrorText = e		
									segmentationDescriptor.Put("segmentationupidErrorText", e)							
									'bufptr = bufptr + seg(segptr).segmentationUPIDlength
									bufptr = bufptr + segmentationDescriptor.Get("segmentationUPIDlength")
								Case 0x02
									'seg(segptr).segmentationUPIDtypeText = segmentation_upid_type(2)
									segmentationDescriptor.Put("segmentationUPIDtypeText","2 = " & segmentation_upid_type(2))
									segmentationDescriptor.Put("segmentationUPIDlength", segmentationUPIDlength)
									Private e As String
									'For j = bufptr To bufptr + seg(segptr).segmentationUPIDlength
									For j = bufptr To bufptr + segmentationDescriptor.Get("segmentationUPIDlength")
										If hexx.get(j) > 31 Then
											e = e & Chr(hexx.get(j))
										Else
											e = e & "0"	
										End If
 
									Next
 
									'seg(segptr).segmentationupidErrorText = e
									segmentationDescriptor.Put("segmentationupidErrorText", e)										
									'bufptr = bufptr + seg(segptr).segmentationUPIDlength
									bufptr = bufptr + segmentationDescriptor.Get("segmentationUPIDlength")
								Case 0x03
									'seg(segptr).segmentationUPIDtypeText = segmentation_upid_type(3)
									segmentationDescriptor.Put("segmentationUPIDtypeText","3 = " & segmentation_upid_type(3))
									segmentationDescriptor.Put("segmentationUPIDlength", segmentationUPIDlength)
									Private e As String
									'For j = bufptr To bufptr + seg(segptr).segmentationUPIDlength
									For j = bufptr To bufptr + segmentationDescriptor.Get("segmentationUPIDlength")
										If hexx.get(j) > 31 Then
											e = e & Chr(hexx.get(j))
										Else
											e = e & "0"	
										End If
 
									Next
 
									'seg(segptr).segmentationupidErrorText = e	
									segmentationDescriptor.Put("segmentationupidErrorText", e)									
									'bufptr = bufptr + seg(segptr).segmentationUPIDlength
									bufptr = bufptr + segmentationDescriptor.Get("segmentationUPIDlength")
								Case 0x04
									'seg(segptr).segmentationUPIDtypeText = segmentation_upid_type(4)
									segmentationDescriptor.Put("segmentationUPIDtypeText","4 = " & segmentation_upid_type(4))
									segmentationDescriptor.Put("segmentationUPIDlength", segmentationUPIDlength)
									'bufptr = bufptr + seg(segptr).segmentationUPIDlength
									bufptr = bufptr + segmentationDescriptor.Get("segmentationUPIDlength")
								Case 0x05	
									'seg(segptr).segmentationUPIDtypeText = segmentation_upid_type(5)
									segmentationDescriptor.Put("segmentationUPIDtypeText","5 = " & segmentation_upid_type(5))
									segmentationDescriptor.Put("segmentationUPIDlength", segmentationUPIDlength)
									'bufptr = bufptr + seg(segptr).segmentationUPIDlength
									bufptr = bufptr + segmentationDescriptor.Get("segmentationUPIDlength")
								Case 0x06
									'seg(segptr).segmentationUPIDtypeText = segmentation_upid_type(6)
									segmentationDescriptor.Put("segmentationUPIDtypeText","6 = " & segmentation_upid_type(6))
									segmentationDescriptor.Put("segmentationUPIDlength", segmentationUPIDlength)
									'bufptr = bufptr + seg(segptr).segmentationUPIDlength
									bufptr = bufptr + segmentationDescriptor.Get("segmentationUPIDlength")
								Case 0x07
									'seg(segptr).segmentationUPIDtypeText = segmentation_upid_type(7)
									segmentationDescriptor.Put("segmentationUPIDtypeText","7 = " & segmentation_upid_type(7))
									segmentationDescriptor.Put("segmentationUPIDlength", segmentationUPIDlength)
									'bufptr = bufptr + seg(segptr).segmentationUPIDlength
									bufptr = bufptr + segmentationDescriptor.Get("segmentationUPIDlength")
								Case 0x08
									segmentationDescriptor.Put("segmentationUPIDlength", segmentationUPIDlength)
									Private l1 As Int = Bit.And(hexx.Get(bufptr), 0x00ff)
									bufptr = bufptr + 1
									Private l2 As Int = Bit.And(hexx.Get(bufptr), 0x00ff)
									bufptr = bufptr + 1
									Private l3 As Int = Bit.And(hexx.Get(bufptr), 0x00ff)
									bufptr = bufptr + 1
									Private l4 As Int = Bit.And(hexx.Get(bufptr), 0x00ff)
									bufptr = bufptr + 1
									Private l5 As Int = Bit.And(hexx.Get(bufptr), 0x00ff)
									bufptr = bufptr + 1
									Private l6 As Int = Bit.And(hexx.Get(bufptr), 0x00ff)
									bufptr = bufptr + 1
									Private l7 As Int = Bit.And(hexx.Get(bufptr), 0x00ff)
									bufptr = bufptr + 1
									Private l8 As Int = Bit.And(hexx.Get(bufptr), 0x00ff)
									bufptr = bufptr + 1
									'seg(segptr).turnerIdentifier = (Bit.ShiftLeft(l1, 56)) + (Bit.ShiftLeft(l2, 48)) + (Bit.ShiftLeft(l3, 40)) + (Bit.ShiftLeft(l4, 32)) + (Bit.ShiftLeft(l5, 24)) + (Bit.ShiftLeft(l6, 16)) + (Bit.ShiftLeft(l7, 8)) + l8
									segmentationDescriptor.Put("turnerIdentifier", (Bit.ShiftLeft(l1, 56)) + (Bit.ShiftLeft(l2, 48)) + (Bit.ShiftLeft(l3, 40)) + (Bit.ShiftLeft(l4, 32)) + (Bit.ShiftLeft(l5, 24)) + (Bit.ShiftLeft(l6, 16)) + (Bit.ShiftLeft(l7, 8)) + l8)
								Case 0x09	
									'seg(segptr).segmentationUPIDtypeText = segmentation_upid_type(9)
									segmentationDescriptor.Put("segmentationUPIDtypeText", "9 = " & segmentation_upid_type(9))
									segmentationDescriptor.Put("segmentationUPIDlength", segmentationUPIDlength)
									Private e As String
									Private l As Int
									'For j = bufptr To bufptr + seg(segptr).segmentationUPIDlength
									For j = bufptr To bufptr + segmentationDescriptor.Get("segmentationUPIDlength") - 1
										l = l + 1
										If hexx.get(j) > 31 Then
											'	e = e & Chr(hexx.get(j))
											segmentationDescriptor.Put(l, hexx.get(j) & " = " & Chr(hexx.get(j)))
										Else
											'	e = e & "0"
											segmentationDescriptor.Put(l, hexx.get(j) & " = not Printable")
										End If
 
									Next
 
									'seg(segptr).segmentationupidErrorText = e
									'segmentationDescriptor.Put("segmentationupidErrorText" , e)
									'bufptr = bufptr + seg(segptr).segmentationUPIDlength		
									bufptr = bufptr + segmentationDescriptor.Get("segmentationUPIDlength")
								Case 0x0A
									'seg(segptr).segmentationUPIDtypeText = segmentation_upid_type(10)
									segmentationDescriptor.Put("segmentationUPIDtypeText", "10 = " & segmentation_upid_type(10))
									segmentationDescriptor.Put("segmentationUPIDlength", segmentationUPIDlength)
									'bufptr = bufptr + seg(segptr).segmentationUPIDlength
									bufptr = bufptr + segmentationDescriptor.Get("segmentationUPIDlength")
								Case 0x0B
									'seg(segptr).segmentationUPIDtypeText = segmentation_upid_type(11)
									segmentationDescriptor.Put("segmentationUPIDtypeText", "11 = " & segmentation_upid_type(11))
									segmentationDescriptor.Put("segmentationUPIDlength", segmentationUPIDlength)
									'bufptr = bufptr + seg(segptr).segmentationUPIDlength
									bufptr = bufptr + segmentationDescriptor.Get("segmentationUPIDlength")
								Case 0x0C
									'seg(segptr).segmentationUPIDtypeText = segmentation_upid_type(12)
									segmentationDescriptor.Put("segmentationUPIDtypeText","12 = " & segmentation_upid_type(12))
									segmentationDescriptor.Put("segmentationUPIDlength", segmentationUPIDlength)
									'bufptr = bufptr + seg(segptr).segmentationUPIDlength
									bufptr = bufptr + segmentationDescriptor.Get("segmentationUPIDlength")
								Case 0x0D
									Private j1 As Int
									Private s As String
									'seg(segptr).segmentationUPIDtypeText = segmentation_upid_type(13)
									segmentationDescriptor.Put("segmentationUPIDtypeText","13 = " & segmentation_upid_type(13))
									segmentationDescriptor.Put("segmentationUPIDlength", segmentationUPIDlength)
									'For j1 = bufptr To bufptr + seg(segptr).segmentationUPIDlength
									For j1 = bufptr To bufptr + segmentationDescriptor.Get("segmentationUPIDlength")
										s = s & hexx.Get(j1)
									Next
 
									'seg(segptr).segmentationupidErrorText = s
									segmentationDescriptor.Put("segmentationupidErrorText" , s)
									'bufptr = bufptr + seg(segptr).segmentationUPIDlength 
									bufptr = bufptr + segmentationDescriptor.Get("segmentationUPIDlength")
								Case Else	
									Private j2 As Int
									Private s1 As String
									'For j2 = bufptr To bufptr + seg(segptr).segmentationUPIDlength
									segmentationDescriptor.Put("segmentationUPIDlength", segmentationUPIDlength)
									For j2 = bufptr To bufptr + segmentationDescriptor.Get("segmentationUPIDlength")
										s1 = s1 & hexx.Get(j2)
									Next
 
									'seg(segptr).segmentationupidErrorText = s1
									segmentationDescriptor.Put("segmentationUPIDtypeText", s1)
									'bufptr = bufptr + seg(segptr).segmentationUPIDlength		
									bufptr = bufptr + segmentationDescriptor.Get("segmentationUPIDlength")											
							End Select
 
							'seg(segptr).segmentationTypeID = Bit.And(hexx.Get(bufptr), 0x00ff)
							Dim segmentationTypeID As Int
							'	segmentationDescriptor.Put("segmentationTypeID", Bit.And(hexx.Get(bufptr), 0x00ff))
							segmentationTypeID = Bit.And(hexx.Get(bufptr), 0x00ff)
							bufptr = bufptr + 1
							'seg(segptr).segmentationTypeIDText = GetSegmentation_TypeID(seg(segptr).segmentationTypeID)
							segmentationDescriptor.Put("segmentationTypeIDText",segmentationTypeID &" = " & GetSegmentation_TypeID(segmentationTypeID))
							'seg(segptr).segmentNum = Bit.And(hexx.Get(bufptr), 0x00ff)
							segmentationDescriptor.Put("segmentNum", Bit.And(hexx.Get(bufptr), 0x00ff))
							bufptr = bufptr + 1
							'seg(segptr).segmentsExpected = Bit.And(hexx.Get(bufptr), 0x00ff)
							segmentationDescriptor.Put("segmentsExpected", Bit.And(hexx.Get(bufptr), 0x00ff))
							bufptr = bufptr + 1
							'ot += "Segment num = " + seg[segptr].segmentNum + " Segments Expected = " + seg[segptr].segmentsExpected + "\n";
							segptr = segptr + 1
						Else
							Main.AppLog("Segmentation Event Cancel Indicator SET")
							'seg(segptr).segmentationEventCancelIndicator = 1
							segmentationDescriptor.Put("segmentationEventCancelIndicator", 1)
						End If
 
						segmentationDescriptorLIST.Put(ptr, segmentationDescriptor)
				End Select
 
			Else
				'	Dlg.InformationDialog("INFO","Indent: "& identifier &" ("&ff&")","Not known, please check SCTE data")
				Log("Indent: "& identifier &" ("&ff&") Not known, please check SCTE data")
				Private j1 As Int
				Private t1 As String
				'hasError = True
				PrivateDescriptor.Put("Private Tag", tag)
				PrivateDescriptor.Put("Private Length", len)
				'PrivateDescriptor.Put("Private Identifier", identifier)
				If bufptr + (len - 4) < hexx.Size Then
					For j1 = bufptr To bufptr + (len - 4)
						Try
							t1 = t1 & hexx.Get(j1)
						Catch
							Log("Indent " & LastException)'still something wrong with the length?
						End Try
 
					Next
 
				Else
					For j1 = bufptr To hexx.Size - 1
						t1 = t1 & hexx.Get(j1)
					Next
 
					t1 = "NOTE: Couldn't parse descriptor correctly, wrong length provided" & CRLF & "Descriptor: " & t1
				End If
 
				PrivateDescriptor.Put("Descriptor", t1)
				bufptr = bufptr + len - 4
			End If
 
		Loop
 
	End If
 
	If bufptr <> SpliceInfoSection.Get("DescriptorLoopLength") + desptr Then
		Private dlen As Int
		dlen = bufptr - desptr
		Log("ERROR decoded descriptor length " & dlen & " not equal to specified descriptor length " & SpliceInfoSection.get("DescriptorLoopLength"))
		'Dlg.ErrorDialog("ERROR decoded descriptor length " , dlen & " not equal to specified descriptor length " , SpliceInfoSection.get("DescriptorLoopLength"))
		bufptr = desptr + SpliceInfoSection.Get("DescriptorLoopLength")
		'	Dlg.InformationDialog("INFO","SKIPPING REST OF THE COMMAND!!!!!!","")
		Log("SKIPPING REST OF THE COMMAND!!!!!!")
	Else
		If SpliceInfoSection.Get("encryptedPacket") <> 0 Then
			SpliceInfoSection.Put("alignmentStuffing", 0)
			SpliceInfoSection.Put("CRC", 0)
		End If
 
		If bufptr <= hexx.Size Then
			Try
				Private l1 As Int = Bit.And(hexx.Get(bufptr), 0x00ff)
				bufptr = bufptr + 1
				Private l2 As Int = Bit.And(hexx.Get(bufptr), 0x00ff)
				bufptr = bufptr + 1
				Private l3 As Int = Bit.And(hexx.Get(bufptr), 0x00ff)
				bufptr = bufptr + 1
				Private l4 As Int = Bit.And(hexx.Get(bufptr), 0x00ff)
				bufptr = bufptr + 1
				SpliceInfoSection.Put("CRC32", "0x" & Bit.ToHexString(Bit.And( Bit.ShiftLeft(l1, 24) + Bit.ShiftLeft(l2, 16) + Bit.ShiftLeft(l3, 8) + l4, 0x00ffffffff)).ToUpperCase)
			Catch
				Log("bufptr <= hexx.Size " & LastException)
				'		Dlg.InformationDialog("INFO","Provided SCTE data is to short by "& (bufptr - hexx.Size+1) & " byte", "can't parse CRC32")
				Log("Provided SCTE data is to short by "& (bufptr - hexx.Size+1) & " byte can't parse CRC32")
			End Try
 
		End If
 
	End If
 
	SpliceInfoSection.Put("Calc CRC32", crc(0, bufptr))
	'	debug_map(SpliceInfoSection)
	print_all
	Main.AppLog("parse_data End")
 
End Sub
 
Sub print_all
 
	Main.AppLog("print_all Start")
	fill_tableview(SpliceInfoSection, "SpliceInfoSection")
	fill_tableview(timeSignal, "timeSignal")
	fill_tableview(SpliceDescriptor, "SpliceDescriptor")
	fill_tableview(PrivateDescriptor, "PrivateDescriptor")
	fill_tableview(SpliceInsert, "SpliceInsert")
	Dim i As Int
	For i = 0 To segmentationDescriptorLIST.Size - 1
		fill_tableview(segmentationDescriptorLIST.Get(i), "segmentationDescriptor")
	Next	
 
	Main.AppLog("print_all End")
 
End Sub
 
Sub fill_tableview(inn As Map, name As String)
 
	Main.AppLog("Fill_TableView Start")
	'	Private ti As TreeItem
	'	ti.Initialize("ti", name)
	If inn.Size > 0 Then
		Private s As Int
		For s = 0 To inn.Size - 1
			'			Private Row(3) As Object
			'			Row(0) = xd
			'			Row(1) = inn.GetKeyAt(s)
			'			Row(2) = inn.GetValueAt(s)
			'			TableView1.Items.Add(Row)	
			Private a As String
			Dim number As Label
			number.Initialize("")
			number.Text = xd
			'	number.Style = get_style(name)	' Just play a bit with styles
			Dim tname As Label
			tname.Initialize("")
			tname.Text = inn.GetKeyAt(s)
			'	tname.Style = get_style(name)	' Just play a bit with styles
			Dim tvalue As Label
			tvalue.Initialize("")
			tvalue.Text = inn.GetValueAt(s)
			'	tvalue.Style = get_style(name)	' Just play a bit with styles
			Main.TableView2.Items.add(Array As Object(number, tname, tvalue))
			'	TableView1.Style ="-fx-text-fill: Red;"
			'		Private cti As TreeItem
			'		If inn.GetKeyAt(s) <> "" And inn.GetValueAt(s)<>"" Then
			'			cti.Initialize("ti",inn.GetKeyAt(s)&" = " & inn.GetValueAt(s) )
			'			ti.Children.Add(cti) 'add the child
			'		End If
			xd = xd + 1
		Next
 
		'	TreeView1.Root.Children.Add(ti) 'add the father to the root
		'	AutoSizeTableCols(TableView1, 5, 120)
	End If
 
	Main.AppLog("Fill_TableView End")	
 
End Sub
 
Sub clear_lists
 
	Main.AppLog("clear_lists Start")
	hexx.clear
	timeSignal.clear
	SpliceInsert.clear
	SpliceDescriptor.clear
	segmentation_upid.clear
	SpliceInfoSection.clear
	PrivateDescriptor.clear
	segmentationDescriptor.clear
	segmentationDescriptorLIST.clear 
	Main.AppLog("clear_lists end")
 
End Sub
 
Sub init_lists
 
	Main.AppLog("init_lists Start")
	hexx.Initialize
	timeSignal.Initialize
	SpliceInsert.Initialize
	SpliceDescriptor.Initialize
	segmentation_upid.Initialize
	SpliceInfoSection.Initialize
	PrivateDescriptor.Initialize
	segmentationDescriptor.Initialize
	segmentationDescriptorLIST.Initialize
	segmentationUPID.Initialize
	Main.AppLog("init_lists End")
 
End Sub
 
Sub BuildHEXtable(inp As String)As Int
 
	Main.AppLog("BuildHEXtable Start")
	Private q, w As Int
	Private cc As String
	q = inp.Length
	For w = 0 To q - 2 Step 2
		cc = inp.SubString2(w, w + 2)
		Main.AppLog(cc)
		hexx.Add(binTodec( HEXtoBin(cc)))
	Next
 
	Main.AppLog("BuildHEXtable End")
 
End Sub
 
Sub binTodec(binVal As String)As Long
 
	Main.AppLog("Bin2Dec Start")
	Try
		Private i As Int, v As Int, dec As Int
		i = binVal.Length
		v = 1
		For pos = i To 1 Step - 1
			If binVal.SubString2(pos - 1, pos) = "1" Then dec = dec + v
			v = v * 2
		Next 
 
		Main.AppLog("Bin2Dec End")
		Return dec
	Catch
		Log("binTodec " & LastException)
	End Try
 
End Sub
 
Sub HEXtoBin(hexString As String)As String
 
	Main.AppLog("hexString Start")
	Try
		Main.AppLog(hexString)
		Private binaryString As String = ""
		Private byteString As String
		Private zeros As String = "00000000"
		' Private bc As ByteConverter
		If hexString.Length Mod 2 = 1 Then hexString = "0" & hexString
		For i = 0 To hexString.Length - 1 Step 2
			byteString = Bit.ToBinaryString(Bit.ParseInt(hexString.SubString2(i, i + 2), 16))
			byteString = zeros.SubString(byteString.Length) & byteString
			binaryString = binaryString & byteString
		Next
 
		Return binaryString
	Catch
		Log("tobin " & LastException)
	End Try
 
	Main.AppLog("ToBin End")
 
End Sub
 
Sub segmentation_upid_type(inp As Int)As String
 
	Main.AppLog("segmentation_upid_type Start")
	'inp = binTodec(inp)
	Select inp
		Case 0
			Return("(Not Used)")
		Case 1
			Return("(User Defined (Deprecated))")
		Case 2
			Return("ISCII (deprecated)")
		Case 3
			Return("(Ad-ID)")
		Case 4
			Return("(UMID)")
		Case 5
			Return("(ISAN)")		
		Case 6
			Return("(ISAN)")
		Case 7
			Return("(TID)")			
		Case 8
			Return("(TI)")			
		Case 9
			Return("(ADI)")	
		Case 10
			Return("(EIDR)")
		Case 11
			Return("(ATSC Content Identifier)")
		Case 12
			Return("(MPU())")
		Case 13
			Return("(MID())")		
		Case Else
			Return("(Reserved)")	
	End Select
 
End Sub
 
Sub GetSegmentation_TypeID(inp As Int)As String
 
	Main.AppLog("GetSegmentation_TypeID Start")
	Select inp
		Case 0
			Return "(Not Indicated)"
		Case 1
			Return "(Content Identification)"
		Case 16
			Return "(Program Start)"
		Case 17
			Return "(Program End)"
		Case 18
			Return "(Program Early Termination)"
		Case 19
			Return "(Program Breakaway)"
		Case 20
			Return "(Program Resumption)"
		Case 21
			Return "(Program Runover Planned)"
		Case 22
			Return "(Program Runover Unplanned)"
		Case 23
			Return "(Program Overlap Start)"
		Case 32
			Return "(Chapter Start)"
		Case 33
			Return "(Chapter End)"
		Case 48
			Return "(Provider Advertisement Start)"
		Case 49
			Return "(Provider Advertisement End)"
		Case 50
			Return "(Distributor Advertisement Start)"
		Case 51
			Return "(Distributor Advertisement End)"
		Case 52
			Return "(Placement Opportunity Start)"
		Case 53
			Return "(Placement Opportunity End)"
		Case 64
			Return "(Unscheduled Event Start)"
		Case 65
			Return "(Unscheduled Event End)"
		Case 80
			Return "(Network Start)"
		Case 81
			Return "(Network End)"
		Case Else
			Return "Unknown = " & inp
	End Select
 
End Sub
 
Sub MPEG_Time(inp As Double) As String
 
	Main.AppLog("MPEG-Time Start")
	Private ty As Float
	ty = (inp / 90000)
	Private nm As String
	nm = SecondsToDateTimeSerial(ty)
	Return nm
 
End Sub
 
Sub get_SpliceDescriptorriptor_tag(inp As Int)As String
 
	Main.AppLog("get_SpliceDescriptorriptor_tag Start")
	Select inp
		Case 0 
			Return(" = (avail_descriptor)")
		Case 1 
			Return(" = (DTMF_descriptor)")
		Case 2 
			Return(" = (segmentation_descriptor)")
		Case Else
			Return(" = (reserved for future SCTE SpliceDescriptorriptors)")
	End Select		
 
	'	Main.AppLog("get_SpliceDescriptorriptor_tag End")
 
End Sub
 
Sub SecondsToDateTimeSerial(sec As Float) As String
 
	Main.AppLog("SecondsToDateTimeSerial Start")
	Private a As String = "a"
	Private lngSecParam As Long
	Private lngDays As Long
	Private lngHours As Long
	Private lngMinutes As Long
	Private tempSecParam As Double
	'	Private lngms As Double
	'	Private az As Float
	Private ax As Float
	Private a, b, c, d, e, f As String
	Try
		lngSecParam = sec
		lngDays = lngSecParam / 86400
		lngSecParam = lngSecParam - (lngDays * 86400)
		lngHours = lngSecParam / 3600
		lngSecParam = lngSecParam - (lngHours * 3600)
		lngMinutes = lngSecParam / 60
		lngSecParam = lngSecParam - (lngMinutes * 60)
		tempSecParam = lngSecParam
		ax = Floor((sec - Floor(sec)) * 1000)
		a = (sec)
		b = (lngDays)
		c = NumberFormat(lngHours, 2, 2)
		d = NumberFormat(lngMinutes, 2, 2)
		e = NumberFormat(tempSecParam, 2, 2)
		f = NumberFormat(ax, 2, 2)
		Return a & " (time " & b &" day, hh:mm:ss:ms "& c &":"& d &":" & e&"." & f&")"
	Catch
		Log("SecondsToDateTimeSerial " & LastException)
	End Try
 
End Sub
 
Sub debug_map(inn As Map)
 
	Main.AppLog("Debug_Map Start")
	Private s As Int
	Private v As Int
	s = inn.Size
	For v = 0 To s - 1
		Log(inn.GetKeyAt(v) & " --> " & inn.GetValueAt(v))
	Next
 
	Main.AppLog("Debug_Map End")
 
End Sub
 
Sub crc(startIdx As Int, endIdx As Int) As String
 
	Main.AppLog("crc Start")
	Private value As Long = 0xFFFFFFFF
	Private ptrr As Long
	If endIdx <= hexx.Size Then
		For i = startIdx To endIdx - 1
			ptrr = Bit.And(Bit.Xor(Bit.And(Bit.ShiftRight(value, 24), 0x00ff), hexx.get(i)), 0x00ff)
			Main.AppLog(ptrr)
			value = Bit.Xor(Bit.ShiftLeft(value, 8), CrcTable (ptrr))
		Next
 
		If Bit.And(value, 0xFFFFFFFFL) = 0 Then
			Return "0 = (same as provided CRC32)" 
		Else
			Return "0x" & Bit.ToHexString( Bit.And(value, 0xFFFFFFFFL)).ToUpperCase
		End If
 
	Else
		Return "NOTE: calculation not possible!, wrong length provided" 
	End If
 
End Sub
 