From d40e146dd6db8e53b0b0c10925ab3a9031a0f9f1 Mon Sep 17 00:00:00 2001 From: Richard Alam Date: Thu, 20 Aug 2009 16:24:13 +0000 Subject: [PATCH] - fred fixed it git-svn-id: http://bigbluebutton.googlecode.com/svn/trunk@2308 af16638f-c34d-0410-8cfa-b39d5352b314 --- .../deskshare/client/DeskShareApplet.java | 28 +++++++------ .../deskshare/client/ScreenCaptureTaker.java | 6 ++- .../client/net/HttpScreenCaptureSender.java | 3 +- .../client/net/ScreenCaptureSender.java | 3 +- .../client/net/SocketScreenCaptureSender.java | 30 +++++++------ .../client/tiles/ChangedTilesListener.java | 2 +- .../deskshare/client/tiles/Tile.java | 40 +++++++++++------- .../deskshare/client/tiles/TileManager.java | 42 +++++++++---------- 8 files changed, 85 insertions(+), 69 deletions(-) diff --git a/deskshare-applet/src/main/java/org/bigbluebutton/deskshare/client/DeskShareApplet.java b/deskshare-applet/src/main/java/org/bigbluebutton/deskshare/client/DeskShareApplet.java index c378a5ecdd..5d53640062 100644 --- a/deskshare-applet/src/main/java/org/bigbluebutton/deskshare/client/DeskShareApplet.java +++ b/deskshare-applet/src/main/java/org/bigbluebutton/deskshare/client/DeskShareApplet.java @@ -19,10 +19,10 @@ */ package org.bigbluebutton.deskshare.client; -import java.awt.image.BufferedImage; -import java.util.ArrayList; +import java.applet.Applet; + +import java.awt.image.BufferedImage; -import javax.swing.JApplet; import org.bigbluebutton.deskshare.client.net.HttpScreenCaptureSender; import org.bigbluebutton.deskshare.client.net.ScreenCaptureSender; @@ -30,9 +30,10 @@ import org.bigbluebutton.deskshare.client.net.SocketScreenCaptureSender; import org.bigbluebutton.deskshare.client.tiles.ChangedTile; import org.bigbluebutton.deskshare.client.tiles.ChangedTilesListener; import org.bigbluebutton.deskshare.client.tiles.Dimension; +import org.bigbluebutton.deskshare.client.tiles.Tile; import org.bigbluebutton.deskshare.client.tiles.TileManager; -public class DeskShareApplet extends JApplet implements IScreenCaptureListener, ChangedTilesListener { +public class DeskShareApplet extends Applet implements IScreenCaptureListener, ChangedTilesListener { private static final long serialVersionUID = 1L; private ScreenCaptureTaker captureTaker; @@ -40,8 +41,8 @@ public class DeskShareApplet extends JApplet implements IScreenCaptureListener, private Thread captureTakerThread; private ScreenCaptureSender captureSender; - private int screenWidth = 800; - private int screenHeight = 600; + private int screenWidth = 1400; + private int screenHeight = 1000; private int x = 0; private int y = 0; private boolean httpTunnel = false; @@ -51,7 +52,8 @@ public class DeskShareApplet extends JApplet implements IScreenCaptureListener, private String host = "192.168.0.136"; public void init(){ - System.out.println("Applet built july 20, 2009 at 3:03PM"); + + System.out.println("Applet built aug 20, 2009 at 11:50AM"); screenWidth = Integer.parseInt(getParameter("CAPTURE_WIDTH")); screenHeight = Integer.parseInt(getParameter("CAPTURE_HEIGHT")); x = Integer.parseInt(getParameter("X")); @@ -84,7 +86,7 @@ public class DeskShareApplet extends JApplet implements IScreenCaptureListener, } Dimension screenDim = new Dimension(screenWidth, screenHeight); - Dimension tileDim = new Dimension(64, 64); + Dimension tileDim = new Dimension(256, 256); tileManager = new TileManager(); tileManager.addListener(this); tileManager.initialize(screenDim, tileDim); @@ -95,7 +97,7 @@ public class DeskShareApplet extends JApplet implements IScreenCaptureListener, captureTaker.addListener(this); captureTaker.setCapture(true); - captureTakerThread = new Thread(captureTaker); + captureTakerThread = new Thread(captureTaker, "ScreenCapture"); captureTakerThread.start(); } @@ -118,12 +120,12 @@ public class DeskShareApplet extends JApplet implements IScreenCaptureListener, } static public void main (String argv[]) { - final JApplet applet = new DeskShareApplet(); + final Applet applet = new DeskShareApplet(); applet.start(); } - public void onChangedTiles(ArrayList changedTiles) { - System.out.println("On ChangedTiles " + changedTiles.size()); - captureSender.send(changedTiles); + public void onChangedTiles(Tile changedTile) { +// System.out.println("On ChangedTiles " + changedTiles.size()); + captureSender.send(changedTile); } } diff --git a/deskshare-applet/src/main/java/org/bigbluebutton/deskshare/client/ScreenCaptureTaker.java b/deskshare-applet/src/main/java/org/bigbluebutton/deskshare/client/ScreenCaptureTaker.java index c8143b36a3..e5c9e85f6c 100644 --- a/deskshare-applet/src/main/java/org/bigbluebutton/deskshare/client/ScreenCaptureTaker.java +++ b/deskshare-applet/src/main/java/org/bigbluebutton/deskshare/client/ScreenCaptureTaker.java @@ -42,9 +42,11 @@ public class ScreenCaptureTaker implements Runnable { while (startCapture){ BufferedImage image = capture.takeSingleSnapshot(); notifyListeners(image); - + image = null; + System.gc(); try{ - Thread.sleep(timeBase); + //Thread.sleep(timeBase); + Thread.sleep(1000); } catch (Exception e){ System.out.println("Exception sleeping."); System.exit(0); diff --git a/deskshare-applet/src/main/java/org/bigbluebutton/deskshare/client/net/HttpScreenCaptureSender.java b/deskshare-applet/src/main/java/org/bigbluebutton/deskshare/client/net/HttpScreenCaptureSender.java index 46ba8d3959..bfeba32490 100644 --- a/deskshare-applet/src/main/java/org/bigbluebutton/deskshare/client/net/HttpScreenCaptureSender.java +++ b/deskshare-applet/src/main/java/org/bigbluebutton/deskshare/client/net/HttpScreenCaptureSender.java @@ -32,6 +32,7 @@ import java.util.ArrayList; import javax.imageio.ImageIO; import org.bigbluebutton.deskshare.client.tiles.ChangedTile; +import org.bigbluebutton.deskshare.client.tiles.Tile; import com.myjavatools.web.ClientHttpRequest; @@ -102,7 +103,7 @@ public class HttpScreenCaptureSender implements ScreenCaptureSender { } } - public void send(ArrayList changedTiles) { + public void send(Tile changedTile) { // TODO Auto-generated method stub } diff --git a/deskshare-applet/src/main/java/org/bigbluebutton/deskshare/client/net/ScreenCaptureSender.java b/deskshare-applet/src/main/java/org/bigbluebutton/deskshare/client/net/ScreenCaptureSender.java index 584522130e..90f5b20f04 100644 --- a/deskshare-applet/src/main/java/org/bigbluebutton/deskshare/client/net/ScreenCaptureSender.java +++ b/deskshare-applet/src/main/java/org/bigbluebutton/deskshare/client/net/ScreenCaptureSender.java @@ -22,11 +22,12 @@ package org.bigbluebutton.deskshare.client.net; import java.util.ArrayList; import org.bigbluebutton.deskshare.client.tiles.ChangedTile; +import org.bigbluebutton.deskshare.client.tiles.Tile; public interface ScreenCaptureSender { public void connect(String host, String room, int videoWidth, int videoHeight, int frameRate); - public void send(ArrayList changedTiles); + public void send(Tile changedTile); public void disconnect(); } diff --git a/deskshare-applet/src/main/java/org/bigbluebutton/deskshare/client/net/SocketScreenCaptureSender.java b/deskshare-applet/src/main/java/org/bigbluebutton/deskshare/client/net/SocketScreenCaptureSender.java index 79b4603e2d..60d3301e57 100644 --- a/deskshare-applet/src/main/java/org/bigbluebutton/deskshare/client/net/SocketScreenCaptureSender.java +++ b/deskshare-applet/src/main/java/org/bigbluebutton/deskshare/client/net/SocketScreenCaptureSender.java @@ -31,6 +31,7 @@ import java.util.ArrayList; import javax.imageio.ImageIO; import org.bigbluebutton.deskshare.client.tiles.ChangedTile; +import org.bigbluebutton.deskshare.client.tiles.Tile; public class SocketScreenCaptureSender implements ScreenCaptureSender { @@ -42,7 +43,6 @@ public class SocketScreenCaptureSender implements ScreenCaptureSender { private Socket socket = null; private DataOutputStream outStream = null; - private PrintWriter out; private String room; private int videoWidth; private int videoHeight; @@ -61,8 +61,8 @@ public class SocketScreenCaptureSender implements ScreenCaptureSender { socket = new Socket(host, PORT); outStream = new DataOutputStream(socket.getOutputStream()); sendCaptureStartMessage(); - sendRoom(room); - sendScreenCaptureInfo(videoWidth, videoHeight, frameRate); + sendRoom(this.room); + sendScreenCaptureInfo(this.videoWidth, this.videoHeight, this.frameRate); } catch(UnknownHostException e){ System.out.println("Unknow host: " + host); @@ -86,23 +86,25 @@ public class SocketScreenCaptureSender implements ScreenCaptureSender { outStream.writeBytes(videoInfo); } - public void send(ArrayList changedTiles) { - for (ChangedTile ct : changedTiles) { - sendChangedTileInfo(ct); - sendTile(ct); - } + public void send(Tile changedTile) { +// for (ChangedTile ct : changedTiles) { + sendChangedTileInfo(changedTile); + sendTile(changedTile); +// } + System.out.println("NULLing changedTiles"); + changedTile = null; } private void sendCaptureUpdateMessage() throws IOException { outStream.writeInt(CAPTURE_UPDATE); } - private void sendChangedTileInfo(ChangedTile tile) { + private void sendChangedTileInfo(Tile tile) { String tileInfo = Integer.toString(tile.getWidth()) + "x" + Integer.toString(tile.getHeight()) + "x" + Integer.toString(tile.getX()) + "x" + Integer.toString(tile.getY()) - + "x" + Integer.toString(tile.getPosition()); + + "x" + Integer.toString(tile.getTilePosition()); try { sendCaptureUpdateMessage(); outStream.writeInt(tileInfo.length()); @@ -114,10 +116,10 @@ public class SocketScreenCaptureSender implements ScreenCaptureSender { } - private void sendTile(ChangedTile tile) { + private void sendTile(Tile tile) { try{ ByteArrayOutputStream byteConvert = new ByteArrayOutputStream(); - ImageIO.write(tile.getImage(), "jpeg", byteConvert); + ImageIO.write(tile.getImage(), "png", byteConvert); byte[] imageData = byteConvert.toByteArray(); outStream.writeInt(imageData.length); outStream.write(imageData); @@ -125,7 +127,9 @@ public class SocketScreenCaptureSender implements ScreenCaptureSender { outStream.flush(); } catch(IOException e){ System.out.println("IOException while sending screen capture."); - } + } finally { + tile.imageSent(); + } } public void disconnect(){ diff --git a/deskshare-applet/src/main/java/org/bigbluebutton/deskshare/client/tiles/ChangedTilesListener.java b/deskshare-applet/src/main/java/org/bigbluebutton/deskshare/client/tiles/ChangedTilesListener.java index f99121c3d1..f6f926dd4d 100644 --- a/deskshare-applet/src/main/java/org/bigbluebutton/deskshare/client/tiles/ChangedTilesListener.java +++ b/deskshare-applet/src/main/java/org/bigbluebutton/deskshare/client/tiles/ChangedTilesListener.java @@ -4,5 +4,5 @@ import java.util.ArrayList; public interface ChangedTilesListener { - public void onChangedTiles(ArrayList changedTiles); + public void onChangedTiles(Tile changedTile); } diff --git a/deskshare-applet/src/main/java/org/bigbluebutton/deskshare/client/tiles/Tile.java b/deskshare-applet/src/main/java/org/bigbluebutton/deskshare/client/tiles/Tile.java index 700dd5e05f..fc6033bbe8 100644 --- a/deskshare-applet/src/main/java/org/bigbluebutton/deskshare/client/tiles/Tile.java +++ b/deskshare-applet/src/main/java/org/bigbluebutton/deskshare/client/tiles/Tile.java @@ -7,7 +7,7 @@ import java.awt.image.ImageObserver; import java.awt.image.PixelGrabber; import java.util.zip.Adler32; -final class Tile { +public final class Tile { private final Adler32 checksum; private final Dimension dim; private final int position; @@ -26,17 +26,21 @@ final class Tile { this.location = location; } - void updateTile(BufferedImage tile) + void updateTile(BufferedImage capturedSreen) { + BufferedImage tile = capturedSreen.getSubimage(getX(), getY(), getWidth(), getHeight()); + long oldsum; oldsum = checksum.getValue(); calcChecksum(tile); if (oldsum != checksum.getValue()) { + image = null; this.image = tile; version++; dirty = true; } else { + tile = null; dirty = false; } } @@ -89,37 +93,41 @@ final class Tile { } } - BufferedImage getImage() { - return image; + public BufferedImage getImage() { + return image.getSubimage(0, 0, getWidth(), getHeight()); } - int getWidth() + public int getWidth() { - return dim.getWidth(); + return new Integer(dim.getWidth()).intValue(); } - int getHeight() + public int getHeight() { - return dim.getHeight(); + return new Integer(dim.getHeight()).intValue(); } - int getTilePosition() { - return position; + public int getTilePosition() { + return new Integer(position).intValue(); } - int getX() { - return location.x; + public int getX() { + return new Integer(location.x).intValue(); } - int getY() { - return location.y; + public int getY() { + return new Integer(location.y).intValue(); } Dimension getDimension() { - return dim; + return new Dimension(dim.getWidth(), dim.getHeight()); } Point getLocation() { - return location; + return new Point(location.x, location.y); + } + + public void imageSent() { + image = null; } } diff --git a/deskshare-applet/src/main/java/org/bigbluebutton/deskshare/client/tiles/TileManager.java b/deskshare-applet/src/main/java/org/bigbluebutton/deskshare/client/tiles/TileManager.java index 3aa73750e9..428e3a3b39 100644 --- a/deskshare-applet/src/main/java/org/bigbluebutton/deskshare/client/tiles/TileManager.java +++ b/deskshare-applet/src/main/java/org/bigbluebutton/deskshare/client/tiles/TileManager.java @@ -13,7 +13,8 @@ public class TileManager { private int numRows; private TileFactory factory; - private Set listeners = new HashSet(); + private ChangedTilesListener listeners; + //private Set listeners = new HashSet(); public TileManager() {} @@ -35,47 +36,44 @@ public class TileManager { } } - public void processCapturedScreen(BufferedImage capturedSreen) + public void processCapturedScreen(BufferedImage capturedScreen) { - System.out.println("Processing captured screen."); - BufferedImage capturedTile; - ArrayList changedTiles = new ArrayList(); - + System.out.println("Processing captured screen."); for (int row = 0; row < numRows; row++) { for (int col = 0; col < numColumns; col++) { int position = factory.indexToPosition(row, col); Tile tile = getTile(position); -// System.out.println("Processing tile [" + row + "," + col + "] " + position); -// System.out.println("tile [" + tile.getWidth() + "," + tile.getHeight() + "][" + tile.getX() + "," + tile.getY() + "]"); - capturedTile = capturedSreen.getSubimage(tile.getX(), tile.getY(), tile.getWidth(), tile.getHeight()); - tile.updateTile(capturedTile); + tile.updateTile(capturedScreen); if (tile.isDirty()) { - ChangedTileImp ct = new ChangedTileImp(tile.getDimension(), tile.getTilePosition(), tile.getLocation(), tile.getImage()); - changedTiles.add(ct); - // System.out.println("Changed Tile " + tile.getTilePosition()); + //ChangedTileImp ct = new ChangedTileImp(tile.getDimension(), tile.getTilePosition(), tile.getLocation(), tile.getImage()); + notifyChangedTilesListener(tile); } } } - if (changedTiles.size() > 0) { - notifyChangedTilesListener(changedTiles); - } +// if (changedTiles.size() > 0) { +// notifyChangedTilesListener(changedTiles); +// } + +// capturedScreen = null; } - private void notifyChangedTilesListener(ArrayList changedTiles) { - for (ChangedTilesListener ctl : listeners) { - ctl.onChangedTiles(changedTiles); - } + private void notifyChangedTilesListener(Tile changedTile) { +// for (ChangedTilesListener ctl : listeners) { +// ctl.onChangedTiles(changedTile); +// } + listeners.onChangedTiles(changedTile); } public void addListener(ChangedTilesListener listener) { - listeners.add(listener); + listeners = listener; } public void removeListener(ChangedTilesListener listener) { - listeners.remove(listener); + //listeners.remove(listener); + listeners = null; } void createTile(int position) {