- minimize logging

git-svn-id: http://bigbluebutton.googlecode.com/svn/trunk@2304 af16638f-c34d-0410-8cfa-b39d5352b314
This commit is contained in:
Richard Alam 2009-08-19 18:16:12 +00:00
parent 7b6a6a8955
commit bb885ebd51
9 changed files with 118 additions and 99 deletions

View File

@ -30,7 +30,7 @@ build.optimize=false
# Change this var to build to a different Java version # Change this var to build to a different Java version
# Defaults to current version. Valid options are 1.6, or 1.5. Note 1.4 is not supported. # Defaults to current version. Valid options are 1.6, or 1.5. Note 1.4 is not supported.
#java.target_version=${java.specification.version} #java.target_version=${java.specification.version}
java.target_version=1.4 java.target_version=1.5
# jikes options # jikes options
build.compiler.emacs=false build.compiler.emacs=false

View File

@ -20,25 +20,32 @@
package org.bigbluebutton.deskshare.client; package org.bigbluebutton.deskshare.client;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.util.ArrayList;
import javax.swing.JApplet; import javax.swing.JApplet;
import org.bigbluebutton.deskshare.client.net.HttpScreenCaptureSender; import org.bigbluebutton.deskshare.client.net.HttpScreenCaptureSender;
import org.bigbluebutton.deskshare.client.net.ScreenCaptureSender;
import org.bigbluebutton.deskshare.client.net.SocketScreenCaptureSender; 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.TileManager;
public class DeskShareApplet extends JApplet implements IScreenCaptureListener { public class DeskShareApplet extends JApplet implements IScreenCaptureListener, ChangedTilesListener {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private ScreenCaptureTaker captureTaker; private ScreenCaptureTaker captureTaker;
private ScreenCapture capture; private ScreenCapture capture;
private Thread captureTakerThread; private Thread captureTakerThread;
private IScreenCaptureSender captureSender; private ScreenCaptureSender captureSender;
private int screenWidth = 800; private int screenWidth = 800;
private int screenHeight = 600; private int screenHeight = 600;
private int x = 0; private int x = 0;
private int y = 0; private int y = 0;
private boolean httpTunnel = true; private boolean httpTunnel = false;
private TileManager tileManager;
private String room = "f7e8821f-8528-4c28-994e-2db7659f9538"; private String room = "f7e8821f-8528-4c28-994e-2db7659f9538";
private String host = "192.168.0.136"; private String host = "192.168.0.136";
@ -74,11 +81,16 @@ public class DeskShareApplet extends JApplet implements IScreenCaptureListener {
captureSender = new HttpScreenCaptureSender(); captureSender = new HttpScreenCaptureSender();
} else { } else {
captureSender = new SocketScreenCaptureSender(); captureSender = new SocketScreenCaptureSender();
} }
captureSender.connect(host, room, capture.getVideoWidth(), Dimension screenDim = new Dimension(screenWidth, screenHeight);
capture.getVideoHeight(), capture.getProperFrameRate()); Dimension tileDim = new Dimension(64, 64);
tileManager = new TileManager();
tileManager.addListener(this);
tileManager.initialize(screenDim, tileDim);
captureSender.connect(host, room, capture.getWidth(),
capture.getHeight(), capture.getProperFrameRate());
captureTaker.addListener(this); captureTaker.addListener(this);
captureTaker.setCapture(true); captureTaker.setCapture(true);
@ -101,14 +113,17 @@ public class DeskShareApplet extends JApplet implements IScreenCaptureListener {
capture.setY(y); capture.setY(y);
} }
public void onScreenCaptured(BufferedImage screen) { public void onScreenCaptured(BufferedImage screen) {
captureSender.send(screen); tileManager.processCapturedScreen(screen);
} }
static public void main (String argv[]) { static public void main (String argv[]) {
final JApplet applet = new DeskShareApplet(); final JApplet applet = new DeskShareApplet();
applet.start(); applet.start();
} }
public void onChangedTiles(ArrayList<ChangedTile> changedTiles) {
System.out.println("On ChangedTiles " + changedTiles.size());
captureSender.send(changedTiles);
}
} }

View File

@ -20,9 +20,7 @@
package org.bigbluebutton.deskshare.client; package org.bigbluebutton.deskshare.client;
import java.awt.AWTException; import java.awt.AWTException;
import java.awt.Graphics2D;
import java.awt.Rectangle; import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.Robot; import java.awt.Robot;
import java.awt.Toolkit; import java.awt.Toolkit;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
@ -36,15 +34,12 @@ import java.awt.image.BufferedImage;
* @author Snap * @author Snap
* *
*/ */
public class ScreenCapture { public class ScreenCapture {
private Robot robot; private Robot robot;
private Toolkit toolkit; private Toolkit toolkit;
private Rectangle screenBounds; private Rectangle screenBounds;
private int width, height, x,y, videoWidth, videoHeight; private int width, height, x,y, videoWidth, videoHeight;
private boolean needScale = true;
public ScreenCapture(int x, int y, int screenWidth, int screenHeight){ public ScreenCapture(int x, int y, int screenWidth, int screenHeight){
this.width = screenWidth; this.width = screenWidth;
this.height = screenHeight; this.height = screenHeight;
@ -55,16 +50,10 @@ public class ScreenCapture {
} }
this.toolkit = Toolkit.getDefaultToolkit(); this.toolkit = Toolkit.getDefaultToolkit();
this.screenBounds = new Rectangle(x, y, this.width, this.height); this.screenBounds = new Rectangle(x, y, this.width, this.height);
this.needScale = areDimensionsScaled(this.width, this.height);
} }
public BufferedImage takeSingleSnapshot(){ public BufferedImage takeSingleSnapshot(){
if (needScale) { return robot.createScreenCapture(this.screenBounds);
return getScaledImage(robot.createScreenCapture(this.screenBounds));
}
else {
return robot.createScreenCapture(this.screenBounds);
}
} }
public int getScreenshotWidth(){ public int getScreenshotWidth(){
@ -123,43 +112,7 @@ public class ScreenCapture {
else if (area > 150000) return 8; else if (area > 150000) return 8;
else return 10; else return 10;
} }
private boolean areDimensionsScaled(int width, int height){
int bigger = Math.max(width, height);
if (bigger < 800){
videoWidth = width;
videoHeight = height;
return false;
}
else{
if (width >= height){
videoWidth = 800;
videoHeight = Math.round(height/(width/800));
} else if (height > width){
videoHeight = 800;
videoWidth = Math.round(width/(height/800));
}
return true;
}
}
private BufferedImage getScaledImage(BufferedImage image){
BufferedImage scaledImage = new BufferedImage(
videoWidth, videoHeight, BufferedImage.TYPE_3BYTE_BGR);
// Paint scaled version of image to new image
Graphics2D graphics2D = scaledImage.createGraphics();
graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
graphics2D.drawImage(image, 0, 0, videoWidth, videoHeight, null);
// clean up
graphics2D.dispose();
return scaledImage;
}
public int getVideoWidth(){ public int getVideoWidth(){
return videoWidth; return videoWidth;
} }

View File

@ -27,13 +27,16 @@ import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.net.URLConnection; import java.net.URLConnection;
import java.util.ArrayList;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import org.bigbluebutton.deskshare.client.tiles.ChangedTile;
import com.myjavatools.web.ClientHttpRequest; import com.myjavatools.web.ClientHttpRequest;
public class HttpScreenCaptureSender implements IScreenCaptureSender { public class HttpScreenCaptureSender implements ScreenCaptureSender {
private String host = "localhost"; private String host = "localhost";
private String room; private String room;
private int videoWidth; private int videoWidth;
@ -99,5 +102,8 @@ public class HttpScreenCaptureSender implements IScreenCaptureSender {
} }
} }
public void send(ArrayList<ChangedTile> changedTiles) {
// TODO Auto-generated method stub
}
} }

View File

@ -19,12 +19,14 @@
*/ */
package org.bigbluebutton.deskshare.client.net; package org.bigbluebutton.deskshare.client.net;
import java.awt.image.BufferedImage; import java.util.ArrayList;
public interface IScreenCaptureSender { import org.bigbluebutton.deskshare.client.tiles.ChangedTile;
public interface ScreenCaptureSender {
public void connect(String host, String room, int videoWidth, int videoHeight, int frameRate); public void connect(String host, String room, int videoWidth, int videoHeight, int frameRate);
public void send(BufferedImage screenCapture); public void send(ArrayList<ChangedTile> changedTiles);
public void disconnect(); public void disconnect();
} }

View File

@ -26,11 +26,14 @@ import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.net.Socket; import java.net.Socket;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.util.ArrayList;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import org.bigbluebutton.deskshare.client.tiles.ChangedTile;
public class SocketScreenCaptureSender implements IScreenCaptureSender {
public class SocketScreenCaptureSender implements ScreenCaptureSender {
private static final int PORT = 9123; private static final int PORT = 9123;
@ -45,6 +48,10 @@ public class SocketScreenCaptureSender implements IScreenCaptureSender {
private int videoHeight; private int videoHeight;
private int frameRate; private int frameRate;
private static final int CAPTURE_START = 0;
private static final int CAPTURE_UPDATE = 1;
private static final int CAPTURE_END = 2;
public void connect(String host, String room, int videoWidth, int videoHeight, int frameRate) { public void connect(String host, String room, int videoWidth, int videoHeight, int frameRate) {
this.room = room; this.room = room;
this.videoWidth = videoWidth; this.videoWidth = videoWidth;
@ -52,8 +59,8 @@ public class SocketScreenCaptureSender implements IScreenCaptureSender {
this.frameRate = frameRate; this.frameRate = frameRate;
try{ try{
socket = new Socket(host, PORT); socket = new Socket(host, PORT);
out = new PrintWriter(socket.getOutputStream(), true);
outStream = new DataOutputStream(socket.getOutputStream()); outStream = new DataOutputStream(socket.getOutputStream());
sendCaptureStartMessage();
sendRoom(room); sendRoom(room);
sendScreenCaptureInfo(videoWidth, videoHeight, frameRate); sendScreenCaptureInfo(videoWidth, videoHeight, frameRate);
@ -64,34 +71,63 @@ public class SocketScreenCaptureSender implements IScreenCaptureSender {
} }
} }
private void sendRoom(String room) { private void sendCaptureStartMessage() throws IOException {
out.println(room); outStream.writeInt(CAPTURE_START);
} }
private void sendScreenCaptureInfo(int videoWidth, int videoHeight, int frameRate) { private void sendRoom(String room) throws IOException {
out.println(Integer.toString(videoWidth) outStream.writeInt(room.length());
+ "x" + Integer.toString(videoHeight) outStream.writeBytes(room);
+ "x" + Integer.toString(frameRate)); }
private void sendScreenCaptureInfo(int videoWidth, int videoHeight, int frameRate) throws IOException {
String videoInfo = Integer.toString(videoWidth) + "x" + Integer.toString(videoHeight) + "x" + Integer.toString(frameRate);
System.out.println("Sending video info " + videoInfo);
outStream.writeInt(videoInfo.length());
outStream.writeBytes(videoInfo);
} }
public void send(BufferedImage screenCapture) { public void send(ArrayList<ChangedTile> changedTiles) {
sendRoom(room); for (ChangedTile ct : changedTiles) {
sendScreenCaptureInfo(videoWidth, videoHeight, frameRate); sendChangedTileInfo(ct);
try{ sendTile(ct);
ByteArrayOutputStream byteConvert = new ByteArrayOutputStream();
ImageIO.write(screenCapture, "jpeg", byteConvert);
byte[] imageData = byteConvert.toByteArray();
outStream.writeInt(imageData.length);
//out.println("xxx");
outStream.write(imageData);
//out.println("vvv");
System.out.println("Sent: "+ imageData.length);
outStream.flush();
} catch(IOException e){
System.out.println("IOException while sending screen capture.");
} }
} }
private void sendCaptureUpdateMessage() throws IOException {
outStream.writeInt(CAPTURE_UPDATE);
}
private void sendChangedTileInfo(ChangedTile 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());
try {
sendCaptureUpdateMessage();
outStream.writeInt(tileInfo.length());
outStream.writeBytes(tileInfo);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private void sendTile(ChangedTile tile) {
try{
ByteArrayOutputStream byteConvert = new ByteArrayOutputStream();
ImageIO.write(tile.getImage(), "jpeg", byteConvert);
byte[] imageData = byteConvert.toByteArray();
outStream.writeInt(imageData.length);
outStream.write(imageData);
// System.out.println("Sent: tile "+ tile.getPosition() + " with size " + imageData.length);
outStream.flush();
} catch(IOException e){
System.out.println("IOException while sending screen capture.");
}
}
public void disconnect(){ public void disconnect(){
System.out.println("Closing connection."); System.out.println("Closing connection.");
try{ try{

View File

@ -1,20 +1,20 @@
package org.bigbluebutton.deskshare.client.tiles; package org.bigbluebutton.deskshare.client.tiles;
final class Dimension { public final class Dimension {
private final int width; private final int width;
private final int height; private final int height;
Dimension(int width, int height) { public Dimension(int width, int height) {
this.width = width; this.width = width;
this.height = height; this.height = height;
} }
int getWidth() { public int getWidth() {
return width; return width;
} }
int getHeight() { public int getHeight() {
return height; return height;
} }

View File

@ -49,7 +49,7 @@ class TileFactory {
int y = computeTileYLocation(row); int y = computeTileYLocation(row);
int pos = computeTilePosition(row, col); int pos = computeTilePosition(row, col);
System.out.println("Tile dim=" + w + "x" + h + " index=" + row + "," + col + " loc=" + x + "," + y); // System.out.println("Tile dim=" + w + "x" + h + " index=" + row + "," + col + " loc=" + x + "," + y);
Tile t = new Tile(new Dimension(w, h), pos, new Point(x,y)); Tile t = new Tile(new Dimension(w, h), pos, new Point(x,y));
return t; return t;

View File

@ -24,8 +24,9 @@ public class TileManager {
numRows = factory.getRowCount(); numRows = factory.getRowCount();
tiles = new Tile[numRows][numColumns]; tiles = new Tile[numRows][numColumns];
System.out.println("Setting tiles " + numRows + " " + numColumns);
for (int row = 0; row < numRows; row++) { for (int row = 0; row < numRows; row++) {
for (int col = 0; col > numColumns; col++) { for (int col = 0; col < numColumns; col++) {
if (tiles[row][col] == null) { if (tiles[row][col] == null) {
int position = factory.indexToPosition(row, col); int position = factory.indexToPosition(row, col);
tiles[row][col] = factory.createTile(position); tiles[row][col] = factory.createTile(position);
@ -36,18 +37,22 @@ public class TileManager {
public void processCapturedScreen(BufferedImage capturedSreen) public void processCapturedScreen(BufferedImage capturedSreen)
{ {
System.out.println("Processing captured screen.");
BufferedImage capturedTile; BufferedImage capturedTile;
ArrayList<ChangedTile> changedTiles = new ArrayList<ChangedTile>(); ArrayList<ChangedTile> changedTiles = new ArrayList<ChangedTile>();
for (int row = 0; row < numRows; row++) { for (int row = 0; row < numRows; row++) {
for (int col = 0; col > numColumns; col++) { for (int col = 0; col < numColumns; col++) {
int position = factory.indexToPosition(row, col); int position = factory.indexToPosition(row, col);
Tile tile = getTile(position); Tile tile = getTile(position);
capturedTile = capturedSreen.getSubimage(tile.getWidth(), tile.getHeight(), tile.getX(), tile.getY()); // 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(capturedTile);
if (tile.isDirty()) { if (tile.isDirty()) {
ChangedTileImp ct = new ChangedTileImp(tile.getDimension(), tile.getTilePosition(), tile.getLocation(), tile.getImage()); ChangedTileImp ct = new ChangedTileImp(tile.getDimension(), tile.getTilePosition(), tile.getLocation(), tile.getImage());
changedTiles.add(ct); changedTiles.add(ct);
// System.out.println("Changed Tile " + tile.getTilePosition());
} }
} }
} }
@ -58,7 +63,9 @@ public class TileManager {
} }
private void notifyChangedTilesListener(ArrayList<ChangedTile> changedTiles) { private void notifyChangedTilesListener(ArrayList<ChangedTile> changedTiles) {
for (ChangedTilesListener ctl : listeners) {
ctl.onChangedTiles(changedTiles);
}
} }