add src files decompiled via jad
[rsa2client.git] / src / mcsClient / LiveVideoPanel.java
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 
4
5 package mcsClient;
6
7 import java.awt.*;
8 import java.awt.image.*;
9 import java.io.*;
10 import java.net.DatagramPacket;
11 import java.util.LinkedList;
12 import java.util.logging.Level;
13 import java.util.logging.Logger;
14 import javax.swing.JPanel;
15
16 // Referenced classes of package mcsClient:
17 //            ColorPalette, Decompress, McsTargetSize, McsTcpConnection, 
18 //            McsToolBar, LockingKeyStateManager
19
20 public final class LiveVideoPanel extends JPanel
21     implements Runnable {
22
23     private int targetWidth;
24     private int targetHeight;
25     private boolean initialized;
26     private McsTargetSize targetSize;
27     private ColorPalette colorPalette;
28     private IndexColorModel indexColorModel;
29     private LinkedList datagramList;
30     public static boolean PRINT_HEADER = false;
31     public static boolean MEASURE_PERFORMANCE = false;
32     public boolean SHOW_CURSOR;
33     public static final boolean DEBUG_MOUSE = false;
34     public static final int SUCCESS = 1;
35     public static final int FAILURE = 2;
36     boolean doPartialScreenUpdates;
37     boolean interpolation;
38     Graphics2D graphics2D;
39     RenderingHints renderingHints;
40     private final Toolkit defaultToolkit = Toolkit.getDefaultToolkit();
41     private final Cursor invisibleCursor;
42     private Cursor visibleCursor;
43     private Cursor currentCursor;
44     private byte imageData[];
45     private MemoryImageSource memoryImageSource;
46     private MemoryImageSource memoryImageSource_1024_768;
47     private MemoryImageSource memoryImageSource_800_600;
48     private MemoryImageSource memoryImageSource_640_480;
49     private MemoryImageSource memoryImageSource_640_400;
50     private MemoryImageSource memoryImageSource_656_496;
51     private Image image_1024_768;
52     private Image image_800_600;
53     private Image image_640_480;
54     private Image image_640_400;
55     private Image image_656_496;
56     private Image image;
57     private int blankImage[];
58     private MemoryImageSource blankMemoryImageSource;
59     private Image blank;
60     private Dimension dimension_1024_768;
61     private Dimension dimension_800_600;
62     private Dimension dimension_640_480;
63     private Dimension dimension_640_400;
64     private Dimension dimension_656_496;
65     private McsTcpConnection mcsTcpConnection;
66     private int frameWidth;
67     private int frameHeight;
68     private int livePanelWait;
69     private boolean livePanelSchedule;
70     private McsToolBar sliderListener;
71     private static int resumeMessage[] = new int[2];
72     private static int pauseMessage[] = new int[2];
73     boolean imagesAutomaticallyPaused;
74     private LockingKeyStateManager lockingKeyStateManager;
75     private static Logger logger = Logger.getAnonymousLogger();
76
77     public LiveVideoPanel(McsTcpConnection mcstcpconnection, LinkedList linkedlist, McsTargetSize mcstargetsize, LockingKeyStateManager lockingkeystatemanager) {
78         targetWidth = 1024;
79         targetHeight = 768;
80         initialized = false;
81         colorPalette = new ColorPalette();
82         indexColorModel = new IndexColorModel(8, colorPalette.hardwareColors.length, colorPalette.hardwareColors, 0, 0, null);
83         SHOW_CURSOR = true;
84         doPartialScreenUpdates = true;
85         interpolation = false;
86         graphics2D = null;
87         renderingHints = null;
88         invisibleCursor = defaultToolkit.createCustomCursor(new BufferedImage(1, 1, 2), new Point(0, 0), "");
89         dimension_1024_768 = new Dimension(1024, 768);
90         dimension_800_600 = new Dimension(800, 600);
91         dimension_640_480 = new Dimension(640, 480);
92         dimension_640_400 = new Dimension(640, 400);
93         dimension_656_496 = new Dimension(656, 496);
94         sliderListener = null;
95         imagesAutomaticallyPaused = false;
96         mcsTcpConnection = mcstcpconnection;
97         datagramList = linkedlist;
98         targetSize = mcstargetsize;
99         lockingKeyStateManager = lockingkeystatemanager;
100         imageData = new byte[targetWidth * targetHeight * 2];
101         memoryImageSource_1024_768 = new MemoryImageSource(1024, 768, indexColorModel, imageData, 0, 1024);
102         memoryImageSource_800_600 = new MemoryImageSource(800, 600, indexColorModel, imageData, 0, 800);
103         memoryImageSource_640_480 = new MemoryImageSource(640, 480, indexColorModel, imageData, 0, 640);
104         memoryImageSource_640_400 = new MemoryImageSource(640, 400, indexColorModel, imageData, 0, 640);
105         memoryImageSource_656_496 = new MemoryImageSource(656, 496, indexColorModel, imageData, 0, 656);
106         memoryImageSource_1024_768.setAnimated(true);
107         memoryImageSource_800_600.setAnimated(true);
108         memoryImageSource_640_480.setAnimated(true);
109         memoryImageSource_640_400.setAnimated(true);
110         memoryImageSource_656_496.setAnimated(true);
111         memoryImageSource = memoryImageSource_1024_768;
112         image_1024_768 = createImage(memoryImageSource_1024_768);
113         image_800_600 = createImage(memoryImageSource_800_600);
114         image_640_480 = createImage(memoryImageSource_640_480);
115         image_640_400 = createImage(memoryImageSource_640_400);
116         image_656_496 = createImage(memoryImageSource_656_496);
117         image = image_1024_768;
118         blankImage = new int[0xc0000];
119         blankMemoryImageSource = new MemoryImageSource(1024, 768, indexColorModel, blankImage, 0, 1024);
120         blank = createImage(blankMemoryImageSource);
121         Cursor cursor = getCursor();
122         Cursor cursor1 = cursor;
123         if (!SHOW_CURSOR) {
124             setCursor(invisibleCursor);
125             Cursor cursor2 = invisibleCursor;
126         }
127         resumeMessage[0] = resumeMessage.length * 4;
128         resumeMessage[1] = 8;
129         pauseMessage[0] = pauseMessage.length * 4;
130         pauseMessage[1] = 7;
131         livePanelWait = 0;
132         livePanelSchedule = true;
133         logger.setLevel(Level.WARNING);
134         String s = System.getProperty("mcs.debug");
135         if (s != null && s.equalsIgnoreCase("true"))
136             logger.setLevel(Level.ALL);
137         initialized = true;
138     }
139
140     public void toggleVisibleCursor() {
141         if (currentCursor.equals(visibleCursor)) {
142             setCursor(invisibleCursor);
143             currentCursor = invisibleCursor;
144         } else {
145             setCursor(visibleCursor);
146             currentCursor = visibleCursor;
147         }
148     }
149
150     public boolean initialized() {
151         return initialized;
152     }
153
154     public boolean isFocusable() {
155         return true;
156     }
157
158     public void addNotify() {
159         super.addNotify();
160     }
161
162     public boolean isOpaque() {
163         return false;
164     }
165
166     public void paintComponent(Graphics g) {
167         super.paintComponent(g);
168         Rectangle rectangle = g.getClipBounds();
169         if (rectangle.x >= 0 && rectangle.x < targetWidth && rectangle.y >= 0 && rectangle.y < targetHeight)
170             g.drawImage(image, 0, 0, null);
171         livePanelWait = 0;
172     }
173
174     public void update(Graphics g) {
175         super.update(g);
176     }
177
178     public void setInterpolation(boolean flag) {
179         interpolation = flag;
180     }
181
182     private void cleanupThread() {
183         mcsTcpConnection = null;
184         datagramList = null;
185         lockingKeyStateManager = null;
186         initialized = false;
187     }
188
189     private void process() {
190         float f;
191         float f1;
192         float f2;
193         float f3;
194         long l;
195         int k;
196         boolean flag3;
197         int ai[];
198         Decompress decompress;
199         Thread thread;
200         f = 0.0F;
201         f1 = 0.0F;
202         f2 = 0.0F;
203         f3 = 0.0F;
204         boolean flag = false;
205         k = 2;
206         boolean flag1 = false;
207         boolean flag2 = false;
208         Object obj = null;
209         flag3 = false;
210         Object obj1 = null;
211         ai = new int[2];
212         ai[0] = ai.length * 4;
213         ai[1] = 16;
214         setBackground(Color.white);
215         setEnabled(true);
216         setVisible(true);
217         decompress = new Decompress(imageData);
218         long l1;
219         l = l1 = System.currentTimeMillis();
220         graphics2D = (Graphics2D)getGraphics();
221         renderingHints = graphics2D.getRenderingHints();
222         logger.info("RenderingHints size = " + renderingHints.size());
223         thread = Thread.currentThread();
224         break MISSING_BLOCK_LABEL_1474;
225 _L2:
226         LinkedList linkedlist = datagramList;
227         JVM INSTR monitorenter ;
228         int i;
229         DatagramPacket datagrampacket;
230 label0:
231         {
232             thread;
233             if (Thread.interrupted()) {
234                 logger.info("Terminating LiveVideoPanel");
235                 return;
236             }
237             try {
238                 while ((i = datagramList.size()) == 0) 
239                     datagramList.wait();
240                 datagrampacket = (DatagramPacket)datagramList.removeLast();
241                 break label0;
242             }
243             catch (InterruptedException interruptedexception1) { }
244             return;
245         }
246         Exception exception;
247         exception;
248         throw exception;
249         if (i > 2 || !imagesAutomaticallyPaused)
250             break MISSING_BLOCK_LABEL_277;
251         if (resumeVideo() != 1) {
252             logger.severe("Socket exception - LiveVideoPanel exiting");
253             return;
254         }
255         imagesAutomaticallyPaused = false;
256         break MISSING_BLOCK_LABEL_313;
257         if (i < 6 || imagesAutomaticallyPaused)
258             break MISSING_BLOCK_LABEL_313;
259         if (pauseVideo() != 1) {
260             logger.severe("Socket exception - LiveVideoPanel exiting");
261             return;
262         }
263         imagesAutomaticallyPaused = true;
264         DataInputStream datainputstream;
265         try {
266             datainputstream = new DataInputStream(new ByteArrayInputStream(datagrampacket.getData(), datagrampacket.getOffset(), datagrampacket.getLength()));
267         }
268         catch (NullPointerException nullpointerexception) {
269             logger.severe("Data stream has been closed.  LiveVideoPanel exiting.");
270             return;
271         }
272         int i1;
273         int i2;
274         int j2;
275         try {
276             int j = datagrampacket.getLength();
277             i1 = datainputstream.readInt();
278             int j1 = datainputstream.readInt();
279             int k1 = datainputstream.readInt();
280             i2 = datainputstream.readInt();
281             j2 = datainputstream.readInt();
282             int k2 = datainputstream.readInt();
283             if (MEASURE_PERFORMANCE) {
284                 f3++;
285                 f1 += i1;
286                 f += j2;
287             }
288             if (PRINT_HEADER) {
289                 System.out.println();
290                 System.out.println("dg length: " + i1 + ", vro: " + i2 + ", vrc: " + j2);
291             }
292             flag3 = false;
293             if (i1 > 1458) {
294                 flag3 = true;
295                 logger.warning("Bad datagramLength = " + i1);
296             }
297             if (j1 != k) {
298                 if (j1 == 2) {
299                     memoryImageSource = memoryImageSource_1024_768;
300                     image = image_1024_768;
301                     logger.info("Setting to 1024 x 768");
302                     setPreferredSize(dimension_1024_768);
303                     targetWidth = 1024;
304                     targetHeight = 768;
305                     targetSize.setWidth(1024);
306                     targetSize.setHeight(768);
307                 } else
308                 if (j1 == 3) {
309                     memoryImageSource = memoryImageSource_800_600;
310                     image = image_800_600;
311                     logger.info("Setting to 800 x 600");
312                     setPreferredSize(dimension_800_600);
313                     targetWidth = 800;
314                     targetHeight = 600;
315                     targetSize.setWidth(800);
316                     targetSize.setHeight(600);
317                 } else
318                 if (j1 == 4) {
319                     memoryImageSource = memoryImageSource_640_480;
320                     image = image_640_480;
321                     logger.info("Setting to 640 x 480");
322                     setPreferredSize(dimension_640_480);
323                     targetWidth = 640;
324                     targetHeight = 480;
325                     targetSize.setWidth(640);
326                     targetSize.setHeight(480);
327                 } else
328                 if (j1 == 23) {
329                     memoryImageSource = memoryImageSource_640_400;
330                     image = image_640_400;
331                     logger.info("Setting to 640 x 400");
332                     setPreferredSize(dimension_640_400);
333                     targetWidth = 640;
334                     targetHeight = 400;
335                     targetSize.setWidth(640);
336                     targetSize.setHeight(400);
337                 } else
338                 if (j1 == 25) {
339                     memoryImageSource = memoryImageSource_656_496;
340                     image = image_656_496;
341                     logger.info("Setting to 656 x 496");
342                     setPreferredSize(dimension_656_496);
343                     targetWidth = 656;
344                     targetHeight = 496;
345                     targetSize.setWidth(656);
346                     targetSize.setHeight(496);
347                 } else {
348                     flag3 = true;
349                     logger.warning("Bad messageType = " + j1);
350                 }
351                 java.awt.Container container = getParent();
352                 java.awt.Container container1 = container;
353                 k = j1;
354             }
355             if (i2 < 0 || i2 > targetWidth * targetHeight) {
356                 flag3 = true;
357                 logger.warning("Bad videoRamOffset = " + i2);
358             }
359             if (j2 < 0 || j2 > targetWidth * targetHeight) {
360                 flag3 = true;
361                 logger.warning("Bad videoRamCount = " + j2);
362             }
363         }
364         catch (IOException ioexception) {
365             logger.warning("LiveVideoPanel: got I/O exception" + ioexception);
366             break; /* Loop/switch isn't completed */
367         }
368         if (!flag3)
369             try {
370                 decompress.doDecompress(datainputstream, i1 - 24, i2, j2, memoryImageSource, targetWidth, targetHeight);
371             }
372             catch (ArrayIndexOutOfBoundsException arrayindexoutofboundsexception) {
373                 logger.warning("Decompress failed - " + arrayindexoutofboundsexception.toString());
374                 flag3 = true;
375             }
376         if (i2 + j2 >= targetWidth * targetHeight)
377             break; /* Loop/switch isn't completed */
378         if (doPartialScreenUpdates) {
379             if (!decompress.pixelsInParts)
380                 memoryImageSource.newPixels(0, 0, targetWidth, targetHeight, false);
381             if (!flag3)
382                 repaint();
383         }
384 _L3:
385         thread;
386         if (!Thread.interrupted()) goto _L2; else goto _L1
387 _L1:
388         thread;
389         if (Thread.interrupted())
390             return;
391         if (!decompress.pixelsInParts)
392             memoryImageSource.newPixels(0, 0, targetWidth, targetHeight, false);
393         if (!flag3) {
394             repaint();
395             try {
396                 livePanelWait += 2;
397                 Thread.currentThread();
398                 Thread.sleep(livePanelWait);
399             }
400             catch (InterruptedException interruptedexception) { }
401         }
402         if (MEASURE_PERFORMANCE) {
403             f2++;
404             long l2 = System.currentTimeMillis();
405             if (l2 - l > 10000L) {
406                 System.out.println("Datagrams/sec = " + (f3 * 1000F) / (float)(l2 - l));
407                 System.out.println("Frames/sec = " + (f2 * 1000F) / (float)(l2 - l));
408                 System.out.println("Bit rate = " + (8F * f1) / 10F);
409                 f2 = 0.0F;
410                 f = 0.0F;
411                 f1 = 0.0F;
412                 f3 = 0.0F;
413                 l = l2 = System.currentTimeMillis();
414                 try {
415                     mcsTcpConnection.sendMessage(ai);
416                 }
417                 catch (IOException ioexception1) {
418                     logger.warning("Socket exception - LiveVideoPanel exiting");
419                     return;
420                 }
421             }
422         }
423         thread;
424         if (Thread.interrupted())
425             return;
426           goto _L3
427     }
428
429     public void run() {
430         process();
431         cleanupThread();
432     }
433
434     void setFrameSize(int i, int j) {
435         frameWidth = i;
436         frameHeight = j;
437     }
438
439     public int resumeVideo() {
440         try {
441             mcsTcpConnection.sendMessage(resumeMessage);
442         }
443         catch (IOException ioexception) {
444             return 2;
445         }
446         return 1;
447     }
448
449     public int pauseVideo() {
450         imagesAutomaticallyPaused = false;
451         try {
452             mcsTcpConnection.sendMessage(pauseMessage);
453         }
454         catch (IOException ioexception) {
455             return 2;
456         }
457         return 1;
458     }
459
460     public void addSliderListener(McsToolBar mcstoolbar) {
461         sliderListener = mcstoolbar;
462     }
463
464 }