/*     */ import java.applet.Applet;
/*     */ import java.awt.Color;
/*     */ import java.awt.Component;
/*     */ import java.awt.Container;
/*     */ import java.awt.Font;
/*     */ import java.awt.Graphics;
/*     */ import java.awt.Image;
/*     */ import java.awt.MediaTracker;
/*     */ import java.awt.Toolkit;
/*     */ import java.io.BufferedInputStream;
/*     */ import java.io.DataInputStream;
/*     */ import java.io.FilterInputStream;
/*     */ import java.io.PrintStream;
/*     */ import java.io.PrintWriter;
/*     */ import java.net.Socket;
/*     */ import java.net.URL;
/*     */ 
/*     */ public class mJPEG extends Applet
/*     */   implements Runnable
/*     */ {
/*     */   Font wetfont;
/*     */   private String filename;
/*     */   private String host;
/*     */   private String portasstr;
/*     */   private int port;
/*     */   private String Title;
/*     */   private String Status;
/*     */   private MediaTracker wetTracker;
/*     */   private Toolkit toolkit;
/*     */   private Image wetImage;
/*     */   private Image[] Buffer;
/*     */   private int[] BufferTick;
/*     */   private byte[] abyte0;
/*     */   private PrintWriter printwriter;
/*     */   private DataInputStream is;
/*     */   private BufferedInputStream myBufferedStream;
/*     */   private Socket socket;
/*     */   private int mybuffnum;
/*     */   private int BufferIndex;
/*     */   private long LastShownIndex;
/*     */   private Thread wetThread;
/*     */   private Thread DisplayThread;
/*     */   private boolean running;
/*     */   private long imagenum;
/*     */   private int refresh;
/*     */   private long bytesread;
/*     */   private boolean Reading;
/*     */   private boolean StopBuffering;
/*     */   private long NowSystemTime;
/*     */   private long LastSystemTime;
/*     */ 
/*     */   public mJPEG()
/*     */   {
/*  18 */     this.wetfont = new Font("Arial", 1, 12);
/*  19 */     this.Buffer = new Image[30];
/*  20 */     this.BufferTick = new int[30];
/*  21 */     this.mybuffnum = 0;
/*  22 */     this.BufferIndex = 0;
/*  23 */     this.LastShownIndex = 0L;
/*  24 */     this.StopBuffering = false;
/*  25 */     this.Title = "attempting mJPEG connection ...";
/*     */   }
/*     */ 
/*     */   public void destroy()
/*     */   {
/*  30 */     for (int i = 0; i < 30; i++) {
/*  31 */       if (this.Buffer[i] == null)
/*     */         continue;
/*  33 */       this.Buffer[i].flush();
/*  34 */       this.Buffer[i] = null;
/*     */     }
/*     */ 
/*  37 */     this.wetThread = null;
/*  38 */     this.DisplayThread = null;
/*  39 */     this.wetTracker = null;
/*     */   }
/*     */ 
/*     */   public void stop()
/*     */   {
/*  44 */     this.port = 0;
/*  45 */     this.refresh = 0;
/*  46 */     this.running = false;
/*     */   }
/*     */ 
/*     */   public void init()
/*     */   {
/*  51 */     this.filename = getParameter("filename");
/*  52 */     String str = null;
/*  53 */     str = getParameter("refresh");
/*  54 */     if (str != null)
/*  55 */       this.refresh = Integer.parseInt(str);
/*     */     else
/*  57 */       this.refresh = 0;
/*  58 */     this.wetTracker = new MediaTracker(this);
/*  59 */     setLayout(null);
/*  60 */     setBackground(Color.gray);
/*  61 */     setVisible(true);
/*  62 */     this.Reading = false;
/*  63 */     this.Status = "MT mJPEG java client v3.21 (c) 2oo5 by w3t";
/*  64 */     showStatus(this.Status);
/*     */   }
/*     */ 
/*     */   public static void main(String[] paramArrayOfString)
/*     */   {
/*     */   }
/*     */ 
/*     */   public void paint(Graphics paramGraphics)
/*     */   {
/*     */     try
/*     */     {
/*  75 */       synchronized (this.Buffer)
/*     */       {
/*  77 */         if (this.Buffer[this.mybuffnum] != null)
/*     */         {
/*  79 */           this.wetTracker.waitForID(this.mybuffnum);
/*  80 */           paramGraphics.drawImage(this.Buffer[this.mybuffnum], 0, 0, this);
/*     */         }
/*  82 */         else if (this.Title != null)
/*     */         {
/*  84 */           paramGraphics.setFont(this.wetfont);
/*  85 */           paramGraphics.drawString(this.Title, 4, 12);
/*     */         }
/*     */       }
/*     */     }
/*     */     catch (Exception localException)
/*     */     {
/*  91 */       this.Status = ("paint :: " + localException);
/*  92 */       showStatus(this.Status);
/*     */     }
/*  94 */     if (this.wetImage != null)
/*  95 */       return;
/*     */   }
/*     */ 
/*     */   public void run()
/*     */   {
/* 102 */     this.running = true;
/* 103 */     this.LastSystemTime = System.currentTimeMillis();
/*     */     do
/*     */     {
/* 106 */       while (Thread.currentThread() == this.wetThread)
/*     */         try
/*     */         {
/* 109 */           if (!this.Reading)
/* 110 */             readImage(this.filename);
/* 111 */           mJPEG localmJPEG1 = this;
/* 112 */           Thread.sleep(100L);
/*     */         }
/*     */         catch (Exception localException1)
/*     */         {
/* 116 */           this.Status = ("read exception :: " + localException1);
/* 117 */           showStatus(this.Status);
/*     */         }
/* 119 */       while (Thread.currentThread() == this.DisplayThread)
/*     */         try
/*     */         {
/* 122 */           int i = 0;
/* 123 */           i = 40;
/* 124 */           synchronized (this.Buffer)
/*     */           {
/* 126 */             long l = this.BufferIndex - 1;
/* 127 */             if (l < 0L)
/* 128 */               l = 29L;
/*     */             Object localObject1;
/* 129 */             if (this.mybuffnum != l)
/*     */             {
/* 131 */               this.mybuffnum += 1;
/* 132 */               if (this.mybuffnum == 30)
/* 133 */                 this.mybuffnum = 0;
/* 134 */               localObject1 = getGraphics();
/* 135 */               if (this.Buffer[this.mybuffnum] != null)
/*     */               {
/* 137 */                 this.wetTracker.waitForID(this.mybuffnum);
/* 138 */                 ((Graphics)localObject1).drawImage(this.Buffer[this.mybuffnum], 0, 0, this);
/* 139 */                 if ((this.BufferTick[this.mybuffnum] > 0) && (this.BufferTick[this.mybuffnum] < 1000))
/* 140 */                   i = this.BufferTick[this.mybuffnum];
/* 141 */                 if (this.mybuffnum > 1)
/* 142 */                   this.Buffer[(this.mybuffnum - 1)].flush();
/* 143 */                 if ((this.mybuffnum - this.BufferIndex < 10) || (this.mybuffnum - this.BufferIndex > 20))
/* 144 */                   this.StopBuffering = false;
/*     */                 else
/* 146 */                   this.StopBuffering = true;
/*     */               }
/* 148 */               ((Graphics)localObject1).dispose();
/* 149 */               validate();
/* 150 */               this.LastShownIndex = this.mybuffnum;
/*     */             }
/*     */             else {
/* 153 */               localObject1 = this;
/* 154 */               Thread.sleep(50L);
/*     */             }
/*     */           }
/* 157 */           mJPEG localmJPEG2 = this;
/* 158 */           Thread.sleep(i);
/*     */         }
/*     */         catch (Exception localException2)
/*     */         {
/* 162 */           this.Status = ("display :: " + localException2);
/* 163 */           showStatus(this.Status);
/*     */         }
/*     */     }
/* 104 */     while (this.running);
/*     */   }
/*     */ 
/*     */   public void start()
/*     */   {
/* 170 */     if (this.wetThread == null)
/*     */     {
/* 172 */       this.wetThread = new Thread(this);
/* 173 */       this.wetThread.start();
/*     */     }
/* 175 */     if (this.DisplayThread == null)
/*     */     {
/* 177 */       this.DisplayThread = new Thread(this);
/* 178 */       this.DisplayThread.start();
/*     */     }
/*     */   }
/*     */ 
/*     */   public void readImage2(String paramString)
/*     */     throws Exception
/*     */   {
/* 185 */     if (this.wetImage != null)
/* 186 */       this.wetImage.flush();
/* 187 */     this.wetImage = getImage(getCodeBase(), paramString);
/* 188 */     this.wetTracker.addImage(this.wetImage, 0);
/* 189 */     this.wetTracker.waitForID(0);
/* 190 */     this.wetTracker.removeImage(this.wetImage, 0);
/* 191 */     repaint();
/*     */   }
/*     */ 
/*     */   public void readImage(String paramString)
/*     */     throws Exception
/*     */   {
/* 197 */     if (this.abyte0 == null)
/* 198 */       this.abyte0 = new byte[256000];
/* 199 */     long l1 = 0L;
/* 200 */     long l2 = 0L;
/* 201 */     int i = 0;
/* 202 */     int j = 0;
/* 203 */     long l3 = 0L;
/* 204 */     int k = 0;
/* 205 */     this.Reading = true;
/* 206 */     String str1 = "";
/* 207 */     String str2 = "GET " + getCodeBase() + "/" + paramString + " HTTP/1.0\n\n";
/*     */     try
/*     */     {
/* 210 */       this.socket = new Socket(getCodeBase().getHost(), getCodeBase().getPort());
/* 211 */       this.printwriter = new PrintWriter(this.socket.getOutputStream());
/* 212 */       this.myBufferedStream = new BufferedInputStream(this.socket.getInputStream());
/* 213 */       this.is = new DataInputStream(this.myBufferedStream);
/*     */     }
/*     */     catch (Exception localException1)
/*     */     {
/* 217 */       this.Status = ("connection error :: " + localException1);
/* 218 */       showStatus(this.Status);
/* 219 */       this.socket = null;
/* 220 */       this.printwriter = null;
/* 221 */       this.myBufferedStream = null;
/* 222 */       this.is = null;
/*     */     }
/*     */     try
/*     */     {
/* 226 */       this.printwriter.println(str2);
/* 227 */       this.printwriter.flush();
/*     */     }
/*     */     catch (Exception localException2)
/*     */     {
/* 231 */       this.Status = ("print writer error :: " + localException2);
/* 232 */       showStatus(this.Status);
/*     */     }
/* 234 */     String str3 = "";
/* 235 */     int m = 0;
/* 236 */     int n = 0;
/* 237 */     int i1 = 0;
/* 238 */     int i2 = 0;
/* 239 */     int i3 = 0;
/* 240 */     this.imagenum = 0L;
/* 241 */     int i4 = 0;
/* 242 */     synchronized (this.Buffer)
/*     */     {
/* 244 */       this.BufferIndex = 1;
/* 245 */       this.mybuffnum = 0;
/*     */     }
/*     */     do
/*     */     {
/* 249 */       int i5 = -1;
/* 250 */       boolean bool = false;
/* 251 */       synchronized (this.Buffer)
/*     */       {
/* 253 */         bool = this.StopBuffering;
/*     */       }
/* 255 */       if (!bool)
/*     */         try
/*     */         {
/* 258 */           i5 = this.is.read();
/*     */         }
/*     */         catch (Exception localException3)
/*     */         {
/* 262 */           i5 = -1;
/*     */         }
/* 264 */       if (i5 < 0)
/* 265 */         bool = true;
/* 266 */       if (!bool)
/*     */       {
/*     */         int i6;
/*     */         int i8;
/* 268 */         if (m == 0)
/*     */         {
/* 270 */           str3 = str3 + (char)i5;
/* 271 */           if (i5 != 10)
/*     */             continue;
/* 273 */           i6 = str3.indexOf("Content-Length:");
/* 274 */           int i7 = str3.indexOf("Content-Type:");
/* 275 */           i8 = str3.indexOf("webcamXP");
/* 276 */           if ((i6 != -1) && (i3 == 0))
/* 277 */             i3 = str3.length() - 2;
/* 278 */           System.out.print(str3);
/* 279 */           System.out.println();
/* 280 */           if (i8 == -1)
/*     */             continue;
/*     */           try
/*     */           {
/* 284 */             l1 = Integer.parseInt(str3.substring(16 + i6, i3));
/*     */           }
/*     */           catch (Exception localException8)
/*     */           {
/* 288 */             l1 = 0L;
/*     */           }
/* 290 */           l2 = l1;
/* 291 */           m = 1;
/* 292 */           j = 0;
/* 293 */           l3 = 0L;
/* 294 */           i1 = 1;
/* 295 */           str3 = "";
/* 296 */           str1 = "";
/* 297 */           i2 = 0;
/*     */         }
/* 301 */         else if (i1 != 0)
/*     */         {
/* 303 */           str3 = str3 + (char)i5;
/* 304 */           if (i5 == 10)
/* 305 */             if (str3.indexOf("WWW-") >= 0)
/*     */             {
/* 307 */               i1 = 1;
/* 308 */               str3 = "";
/*     */             }
/*     */             else {
/* 311 */               i1 = 0;
/*     */             }
/*     */         }
/* 314 */         else if (l3 < l1)
/*     */         {
/* 316 */           if (j >= l2)
/*     */           {
/* 318 */             i6 = 0;
/* 319 */             this.bytesread += j;
/* 320 */             if (j > 400)
/*     */             {
/* 322 */               if (this.wetImage != null)
/* 323 */                 this.wetImage.flush();
/* 324 */               synchronized (this.Buffer)
/*     */               {
/*     */                 try
/*     */                 {
/* 328 */                   if (this.Buffer[this.BufferIndex] != null)
/* 329 */                     this.Buffer[this.BufferIndex].flush();
/* 330 */                   this.wetTracker.removeImage(this.Buffer[this.BufferIndex], this.BufferIndex);
/* 331 */                   if (j > 0)
/*     */                   {
/* 333 */                     this.Buffer[this.BufferIndex] = Toolkit.getDefaultToolkit().createImage(this.abyte0);
/* 334 */                     this.BufferTick[this.BufferIndex] = i;
/*     */                   }
/* 336 */                   this.wetTracker.addImage(this.Buffer[this.BufferIndex], this.BufferIndex);
/* 337 */                   this.BufferIndex += 1;
/* 338 */                   if (this.BufferIndex > 29)
/* 339 */                     this.BufferIndex = 0;
/* 340 */                   i8 = this.BufferIndex;
/*     */                 }
/*     */                 catch (Exception localException7)
/*     */                 {
/* 344 */                   this.Status = ("buffering error :: " + localException7);
/* 345 */                   showStatus(this.Status);
/*     */                 }
/*     */               }
/* 348 */               mJPEG localmJPEG2 = this;
/* 349 */               Thread.sleep(20L);
/*     */             }
/* 351 */             str1 = "";
/* 352 */             i2 = 0;
/* 353 */             j = 0;
/* 354 */             this.abyte0 = null;
/* 355 */             this.abyte0 = new byte[256000];
/* 356 */             this.imagenum += 1L;
/*     */           }
/* 358 */           if (j < l2)
/* 359 */             if (i2 != 0)
/*     */             {
/*     */               try
/*     */               {
/* 363 */                 this.abyte0[j] = (byte)i5;
/*     */               }
/*     */               catch (Exception localException4)
/*     */               {
/* 367 */                 this.Status = ("stream buffer error :: " + localException4);
/* 368 */                 showStatus(this.Status);
/*     */               }
/*     */             }
/*     */             else {
/* 372 */               str1 = str1 + (char)i5;
/* 373 */               if (j == 5)
/*     */               {
/* 375 */                 if (str1.indexOf("mjpeg") < 0)
/* 376 */                   n = 1;
/* 377 */                 str1 = "";
/*     */               }
/* 379 */               if (j == 11)
/*     */               {
/*     */                 try
/*     */                 {
/* 383 */                   l2 = Integer.parseInt(str1);
/*     */                 }
/*     */                 catch (Exception localException5)
/*     */                 {
/* 387 */                   n = 1;
/*     */                 }
/* 389 */                 str1 = "";
/*     */               }
/* 391 */               if (j == 17)
/*     */               {
/*     */                 try
/*     */                 {
/* 395 */                   i = Integer.parseInt(str1);
/*     */                 }
/*     */                 catch (Exception localException6)
/*     */                 {
/* 399 */                   i = 40;
/*     */                 }
/* 401 */                 str1 = "";
/*     */               }
/* 403 */               if (j == 49)
/*     */               {
/* 405 */                 i2 = 1;
/* 406 */                 j = -1;
/*     */               }
/*     */             }
/* 409 */           if (i5 < 0)
/*     */             continue;
/* 411 */           j++;
/* 412 */           l3 += 1L;
/*     */         }
/*     */         else
/*     */         {
/* 416 */           this.abyte0 = null;
/* 417 */           m = 0;
/* 418 */           n = 1;
/* 419 */           str3 = "";
/*     */         }
/*     */       }
/*     */       else {
/* 423 */         mJPEG localmJPEG1 = this;
/* 424 */         Thread.sleep(50L);
/*     */       }
/*     */     }
/* 247 */     while ((n == 0) && (this.running));
/*     */ 
/* 427 */     this.Reading = false;
/* 428 */     if (this.is != null)
/* 429 */       this.is.close();
/* 430 */     if (this.myBufferedStream != null)
/* 431 */       this.myBufferedStream.close();
/* 432 */     if (this.socket != null)
/* 433 */       this.socket.close();
/* 434 */     if (this.printwriter != null)
/* 435 */       this.printwriter.close();
/* 436 */     this.is = null;
/* 437 */     this.myBufferedStream = null;
/* 438 */     this.socket = null;
/* 439 */     this.printwriter = null;
/*     */   }
/*     */ 
/*     */   public void update(Graphics paramGraphics)
/*     */   {
/* 444 */     paint(paramGraphics);
/*     */   }
/*     */ }

/* Location:           /home/mm/Dokumentumok/balubati/website_files/mars2020/streaming.jar
 * Qualified Name:     mJPEG
 * JD-Core Version:    0.6.0
 */