- copy deskshare applet to trunk

git-svn-id: http://bigbluebutton.googlecode.com/svn/trunk@1764 af16638f-c34d-0410-8cfa-b39d5352b314
This commit is contained in:
Richard Alam 2009-06-23 16:45:21 +00:00
parent c7acddd129
commit 457ad87938
10 changed files with 371 additions and 0 deletions

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="bin"/>
</classpath>

17
deskshare-applet/.project Normal file
View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>deskShareClient</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@ -0,0 +1,12 @@
#Thu Jun 11 14:39:57 EDT 2009
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.4
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.4

Binary file not shown.

View File

@ -0,0 +1,23 @@
package converter;
/**
* The EightBit converter converts a 32 bit Image to an 8 bit Image
* The Conversion takes the following form:
* - The 32bit representation is decomosed into alpha, red, green, and blue values (8 bit each)
* - Alpha values are discarded
* - 3 most significant bits of the red value are kept
* - 3 most significant bits of the green value are kept
* - 2 most significant bits of the blue value are kept
* - Floyd-Steinberg Dithering is applied to create a more proper image
* @author Snap
* @unimplemented
*
*/
public class EightBitConverter {
public EightBitConverter(){
}
}

View File

@ -0,0 +1,150 @@
package screenshot;
import java.awt.AWTException;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
/**
* The Capture class uses the java Robot class to capture the screen
* The image captured is scaled down. This is done because of bandwidth issues and because it
* is unnecessary for the Flex Client to be able to see the full screen, in fact it is undesirable
* to do so.
* The image can then be sent for further processing
* @author Snap
*
*/
public class Capture {
private Robot robot;
private Toolkit toolkit;
private Rectangle screenBounds;
private int width, height, x,y;
/**
* The default constructor. Performs initialisation work
*/
public Capture(int x, int y, int screenWidth, int screenHeight){
this.width = screenWidth;
this.height = screenHeight;
try{
robot = new Robot();
}catch (AWTException e){
System.out.println(e.getMessage());
}
this.toolkit = Toolkit.getDefaultToolkit();
this.screenBounds = new Rectangle(x, y, this.width, this.height);
}
public BufferedImage takeSingleSnapshot(){
return robot.createScreenCapture(this.screenBounds);
}
public int getScreenshotWidth(){
return toolkit.getScreenSize().width;
}
public int getScreenshotHeight(){
return toolkit.getScreenSize().height;
}
public void setWidth(int width){
int screenWidth = toolkit.getScreenSize().width;
if (width > screenWidth) this.width = screenWidth;
else this.width = width;
updateBounds();
}
public void setHeight(int height){
int screenHeight = toolkit.getScreenSize().height;
if (height > screenHeight) this.height = screenHeight;
else this.height = height;
updateBounds();
}
public void setX(int x){
/*int screenWidth = toolkit.getScreenSize().width;
if ((screenWidth < this.width + x) ){
this.x = screenWidth - this.width;
} else if (x - this.width < 0){
this.x = 0;
} else this.x = x;*/
this.x = x;
updateBounds();
}
public void setY(int y){
/*int screenHeight = toolkit.getScreenSize().height;
if (screenHeight < (this.height + y) ){
this.y = screenHeight - this.height;
} else if (y - this.height < 0) {
this.y = 0;
} else this.y = y;*/
this.y = y;
updateBounds();
}
public void updateBounds(){
this.screenBounds = new Rectangle(x,y,width,height);
}
/**
* Convert a {@link BufferedImage} of any type, to {@link
* BufferedImage} of a specified type. If the source image is the
* same type as the target type, then original image is returned,
* otherwise new image of the correct type is created and the content
* of the source image is copied into the new image.
*
* @param sourceImage the image to be converted
* @param targetType the desired BufferedImage type
*
* @return a BufferedImage of the specifed target type.
*
* @see BufferedImage
*
* @author Robert Harris
*/
public BufferedImage convertToType(BufferedImage sourceImage,
int targetType)
{
BufferedImage image;
// if the source image is already the target type, return the source image
if (sourceImage.getType() == targetType)
image = sourceImage;
// otherwise create a new image of the target type and draw the new
// image
else
{
image = new BufferedImage(sourceImage.getWidth(), sourceImage.getHeight(),
targetType);
image.getGraphics().drawImage(sourceImage, 0, 0, null);
}
return image;
}
public int getWidth(){
return this.width;
}
public int getHeight(){
return this.height;
}
public int getProperFrameRate(){
long area = width*height;
if (area > 1000000) return 1;
else if (area > 600000) return 2;
else if (area > 300000) return 4;
else if (area > 150000) return 8;
else return 10;
}
}

View File

@ -0,0 +1,75 @@
package screenshot;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.Socket;
import javax.imageio.ImageIO;
public class CaptureThread implements Runnable {
private static final int PORT = 1026;
//private static final String IP = "192.168.0.120";
private Socket socket = null;
public Capture capture;
private String roomNumber;
private String IP;
private int timeBase;
public CaptureThread(Capture capture, String IP, String room){
this.capture = capture;
this.roomNumber = room;
this.IP = IP;
this.timeBase = 1000 / capture.getProperFrameRate();
}
public void run(){
DataOutputStream outStream = null;
try{
socket = new Socket(IP, PORT);
PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
out.println(roomNumber);
out.println(Integer.toString(capture.getWidth())
+ "x" + Integer.toString(capture.getHeight())
+ "x" + Integer.toString(capture.getProperFrameRate()));
outStream = new DataOutputStream(socket.getOutputStream());
} catch(Exception e){
e.printStackTrace(System.out);
System.exit(0);
}
while (true){
BufferedImage image = capture.takeSingleSnapshot();
try{
ByteArrayOutputStream byteConvert = new ByteArrayOutputStream();
ImageIO.write(image, "jpeg", byteConvert);
byte[] imageData = byteConvert.toByteArray();
outStream.writeLong(imageData.length);
outStream.write(imageData);
System.out.println("Sent: "+ imageData.length);
} catch(Exception e){
e.printStackTrace(System.out);
System.exit(0);
}
try{
Thread.sleep(timeBase);
} catch (Exception e){
System.exit(0);
}
}
}
public void closeConnection(){
try{
socket.close();
} catch(IOException e){
e.printStackTrace(System.out);
}
}
}

View File

@ -0,0 +1,42 @@
package test;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
import screenshot.Capture;
public class Runner {
private static int index = 0;
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Starting");
Capture capture = new Capture(0, 0, 800, 600);
while (index < 20){
BufferedImage image = capture.takeSingleSnapshot();
try{
//ByteArrayOutputStream byteConvert = new ByteArrayOutputStream();
ImageIO.write(image, "jpeg", new File(Integer.toString(index) + ".jpeg"));
index++;
//byte[] imageData = byteConvert.toByteArray();
System.out.println(index);
} catch(Exception e){
e.printStackTrace(System.out);
System.exit(0);
}
try{
Thread.sleep(200);
} catch (Exception e){
System.exit(0);
}
}
}
}

View File

@ -0,0 +1,46 @@
package test;
import javax.swing.JApplet;
import screenshot.Capture;
import screenshot.CaptureThread;
public class RunnerApplet extends JApplet {
/**
*
*/
private static final long serialVersionUID = 1L;
CaptureThread capThread;
public void init(){
int screenWidth = Integer.parseInt(getParameter("CAPTURE_WIDTH"));
int screenHeight = Integer.parseInt(getParameter("CAPTURE_HEIGHT"));
int x = Integer.parseInt(getParameter("X"));
int y = Integer.parseInt(getParameter("Y"));
Capture capture = new Capture(x, y, screenWidth, screenHeight);
String roomNumber = getParameter("ROOM");
String IP = getParameter("IP");
capThread = new CaptureThread(capture, IP, roomNumber);
}
public void stop(){
}
public void start(){
Thread thread = new Thread(capThread);
thread.start();
}
/**
* This method is called when the user closes the browser window containing the applet
*/
public void destroy(){
capThread.closeConnection();
}
public void setScreenCoordinates(int x, int y){
capThread.capture.setX(x);
capThread.capture.setY(y);
}
}

Binary file not shown.