1 // Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
2 // Jad home page: http://www.kpdus.com/jad.html
3 // Decompiler options: packimports(3) fieldsfirst nonlb space
7 import java.io.IOException;
9 import java.util.LinkedList;
10 import java.util.logging.Level;
11 import java.util.logging.Logger;
12 import javax.swing.JFrame;
13 import javax.swing.JOptionPane;
15 // Referenced classes of package mcsClient:
16 // BitMap, SecureDatagramSocket, McsTcpConnection, LiveVideoPanel,
19 public final class DatagramReader
22 public boolean videoLostSync;
23 private DatagramSocket dgSocket;
24 private McsTcpConnection mcsTcpConnection;
25 private LiveVideoPanel liveVideoPanel;
26 private LinkedList datagramList;
27 private static final boolean USE_MULTICAST = false;
28 public static final int DEFAULT_DIALIN_BITRATE;
29 public static final int DEFAULT_NET_BITRATE;
30 private long serverTime;
31 private long serverBaseTime;
32 private long clientTime;
33 private long clientBaseTime;
34 private boolean gotBaseTime;
36 private long upperSkew;
37 private long lowerSkew;
38 private long initialBitRate;
39 private long skewTime;
40 private boolean gotBeginningOfFrame;
41 private boolean gotInitialBitRate;
42 private boolean detectedPPP;
43 private int frameNumber;
44 private int maxSequenceNumber;
45 private int lastFrameNumber;
46 private long totalFrameSize;
47 private BitMap bitmap;
48 private boolean initialized;
49 private static int nakMessage[] = new int[4];
50 private McsToolBar sliderListener;
52 private static Logger logger = Logger.getAnonymousLogger();
54 public DatagramReader(McsTcpConnection mcstcpconnection, LiveVideoPanel livevideopanel, LinkedList linkedlist, String s, int i, boolean flag) {
55 videoLostSync = false;
65 gotBeginningOfFrame = false;
66 gotInitialBitRate = false;
68 maxSequenceNumber = 0;
71 bitmap = new BitMap();
73 sliderListener = null;
75 mcsTcpConnection = mcstcpconnection;
76 liveVideoPanel = livevideopanel;
77 datagramList = linkedlist;
78 logger.setLevel(Level.WARNING);
79 String s1 = System.getProperty("mcs.debug");
80 if (s1 != null && s1.equalsIgnoreCase("true"))
81 logger.setLevel(Level.ALL);
82 nakMessage[0] = nakMessage.length * 4;
84 if (mcstcpconnection.getDetectedPPP() || flag) {
90 if (mcstcpconnection.videoEncrypted())
91 dgSocket = new SecureDatagramSocket(mcstcpconnection.cipher1, mcstcpconnection.cipher2, mcstcpconnection.getLocalPort());
93 dgSocket = new DatagramSocket(mcstcpconnection.getLocalPort());
94 dgSocket.setReceiveBufferSize(0x1f400);
95 dgSocket.setSoTimeout(500);
99 byte abyte0[] = new byte[10];
100 DatagramPacket datagrampacket = new DatagramPacket(abyte0, abyte0.length, InetAddress.getByName(s), i);
101 for (int j = 0; j < 6; j++) {
102 dgSocket.send(datagrampacket);
104 Thread.currentThread();
107 catch (InterruptedException interruptedexception) { }
111 Thread.currentThread();
114 catch (InterruptedException interruptedexception1) { }
116 catch (Exception exception) {
117 logger.severe(exception.toString());
119 JOptionPane.showMessageDialog(new JFrame(), "Failed to connect. Try again.", "Remote Console Datagram Reader Initialization Error", 0);
124 private void cleanupThread() {
125 if (dgSocket != null) {
126 dgSocket.disconnect();
130 mcsTcpConnection = null;
131 liveVideoPanel = null;
136 private void process() {
140 boolean flag = false;
141 boolean flag1 = false;
142 boolean flag2 = false;
145 thread = Thread.currentThread();
148 if (nakCount >= 25) {
149 logger.info("25 NAK messages sent");
152 DatagramPacket datagrampacket;
153 byte abyte1[] = new byte[1500];
154 datagrampacket = new DatagramPacket(abyte1, abyte1.length);
155 dgSocket.receive(datagrampacket);
157 SocketTimeoutException sockettimeoutexception;
158 sockettimeoutexception;
160 IOException ioexception3;
162 logger.warning("Datagram Reader - error reading datagram " + ioexception3);
167 abyte0 = datagrampacket.getData();
168 j = datagrampacket.getOffset();
169 if (datagrampacket.getLength() >= 24) goto _L3; else goto _L1
171 if (abyte0[j + 7] != 6) goto _L5; else goto _L4
173 videoLostSync = true;
175 logger.info("DatagramReader: video lost sync");
178 videoLostSync = false;
179 frameNumber = (abyte0[j + 8] & 0xff) << 8 | abyte0[j + 9] & 0xff;
180 if (gotBeginningOfFrame) goto _L7; else goto _L6
182 if ((abyte0[j + 7] & 0xbf) != 0) goto _L8; else goto _L1
184 gotBeginningOfFrame = true;
185 lastFrameNumber = frameNumber - 1;
191 i = (abyte0[j + 10] & 0xff) << 8 | abyte0[j + 11] & 0xff;
192 int i1 = (abyte0[j + 2] & 0xff) << 8 | abyte0[j + 3] & 0xff;
193 totalFrameSize += i1;
194 serverTime = ((long)abyte0[j + 20] & 255L) << 24 | ((long)abyte0[j + 21] & 255L) << 16 | ((long)abyte0[j + 22] & 255L) << 8 | (long)abyte0[j + 23] & 255L;
195 clientTime = System.currentTimeMillis();
196 if (gotBaseTime) goto _L10; else goto _L9
199 serverBaseTime = serverTime;
200 clientBaseTime = clientTime;
205 skew = clientTime - clientBaseTime - (serverTime - serverBaseTime);
206 l1 = (totalFrameSize * 8L * 1000L) / ((clientTime - clientBaseTime) + 50L);
208 liveVideoPanel.doPartialScreenUpdates = false;
210 liveVideoPanel.doPartialScreenUpdates = true;
211 if (skew >= lowerSkew) goto _L13; else goto _L12
216 if (skew <= upperSkew || clientTime - clientBaseTime <= skewTime) goto _L11; else goto _L14
219 if (!gotInitialBitRate) {
221 gotInitialBitRate = true;
223 if (initialBitRate < (long)DEFAULT_DIALIN_BITRATE)
224 initialBitRate = DEFAULT_DIALIN_BITRATE;
226 if (initialBitRate < (long)DEFAULT_NET_BITRATE)
227 initialBitRate = DEFAULT_NET_BITRATE;
228 if (sliderListener != null)
229 sliderListener.setSliderInitialBitRate(initialBitRate);
231 if (l1 < (initialBitRate * 60L) / 100L)
232 l1 = (initialBitRate * 60L) / 100L;
233 if (detectedPPP && l1 > initialBitRate)
240 ai[0] = ai.length * 4;
244 if (Thread.interrupted())
247 mcsTcpConnection.sendMessage(ai, false);
249 catch (IOException ioexception4) {
250 logger.severe("Socket exception - DatagramReader exiting");
254 if (frameNumber == lastFrameNumber)
255 break MISSING_BLOCK_LABEL_1033;
256 if (frameNumber == lastFrameNumber + 1) goto _L16; else goto _L15
259 nakMessage[3] = frameNumber;
261 mcsTcpConnection.sendMessage(nakMessage, false);
263 catch (IOException ioexception) {
264 logger.severe("Socket exception - DatagramReader exiting");
270 if ((l & 0x80) != 0) goto _L19; else goto _L18
275 if (Thread.interrupted())
278 mcsTcpConnection.sendMessage(nakMessage, false);
280 catch (IOException ioexception1) {
281 logger.severe("Socket exception - DatagramReader exiting");
289 nakMessage[3] = frameNumber;
291 if (Thread.interrupted())
294 mcsTcpConnection.sendMessage(nakMessage, false);
296 catch (IOException ioexception2) {
297 logger.severe("Socket exception - DatagramReader exiting");
301 break; /* Loop/switch isn't completed */
303 if ((k = bitmap.findZeroBit()) <= maxSequenceNumber) goto _L20; else goto _L17
305 lastFrameNumber = frameNumber;
308 maxSequenceNumber = 0;
310 maxSequenceNumber = i <= maxSequenceNumber ? maxSequenceNumber : i;
312 abyte0[j + 7] &= 0x3f;
314 if ((j1 = datagramList.size()) < 10 || liveVideoPanel.imagesAutomaticallyPaused)
315 break MISSING_BLOCK_LABEL_1147;
317 if (Thread.interrupted())
319 if (liveVideoPanel.pauseVideo() != 1) {
320 logger.severe("Socket exception - DatagramReader exiting");
323 liveVideoPanel.imagesAutomaticallyPaused = true;
324 long l2 = ((long)abyte0[j] & 255L) << 24 | ((long)abyte0[j + 1] & 255L) << 16 | ((long)abyte0[j + 2] & 255L) << 8 | (long)abyte0[j + 3] & 255L;
325 long l3 = ((long)abyte0[j + 12] & 255L) << 24 | ((long)abyte0[j + 13] & 255L) << 16 | ((long)abyte0[j + 14] & 255L) << 8 | (long)abyte0[j + 15] & 255L;
326 long l4 = ((long)abyte0[j + 16] & 255L) << 24 | ((long)abyte0[j + 17] & 255L) << 16 | ((long)abyte0[j + 18] & 255L) << 8 | (long)abyte0[j + 19] & 255L;
327 if (i >= 0 && i <= 896 && l3 >= 0L && l3 <= 0xc0000L && l4 >= 0L && l3 <= 0xc0000L) {
329 synchronized (datagramList) {
330 datagramList.addFirst(datagrampacket);
331 datagramList.notify();
334 logger.warning("Bad packet discarded. seq num: " + i + " vid ram offset: " + l3 + " vid ram count: " + l4);
337 ArrayIndexOutOfBoundsException arrayindexoutofboundsexception;
338 arrayindexoutofboundsexception;
339 logger.warning(arrayindexoutofboundsexception.toString());
342 if (Thread.interrupted())
344 if (true) goto _L22; else goto _L21
353 protected void finalize() throws Throwable {
357 public boolean initialized() {
361 public void addSliderListener(McsToolBar mcstoolbar) {
362 sliderListener = mcstoolbar;
365 public void setInitialBitRate(long l) {
367 gotInitialBitRate = true;
368 int ai[] = new int[3];
369 ai[0] = ai.length * 4;
373 mcsTcpConnection.sendMessage(ai, true);
375 catch (IOException ioexception) {
376 logger.severe("Socket exception - setInitialBitRate");
382 DEFAULT_DIALIN_BITRATE = McsToolBar.BITRATES[2];
383 DEFAULT_NET_BITRATE = McsToolBar.BITRATES[7];