Basic video streaming finished.

This commit is contained in:
2014-01-08 15:21:37 -04:30
parent f843700235
commit 5cc769ad2e
4 changed files with 30 additions and 6 deletions

View File

@@ -60,6 +60,7 @@ public class CameraImageMonitor{
imageConsumed = false; imageConsumed = false;
this.imageMonitor.notifyAll(); this.imageMonitor.notifyAll();
} }
System.gc();
Logger.log_d(TAG, CLASS_NAME + ".setImageData() :: Data copy finished."); Logger.log_d(TAG, CLASS_NAME + ".setImageData() :: Data copy finished.");
}else{ }else{
Logger.log_d(TAG, CLASS_NAME + ".setImageData() :: Old image still valid, ignoring new image."); Logger.log_d(TAG, CLASS_NAME + ".setImageData() :: Old image still valid, ignoring new image.");

View File

@@ -105,12 +105,22 @@ public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback
requestLayout(); requestLayout();
camParams = camera.getParameters(); camParams = camera.getParameters();
Size optimal = getOptimalPreviewSize(camParams.getSupportedPreviewSizes(), w, h); camParams.getSupportedPreviewSizes();
List<Size> sizes = camParams.getSupportedPreviewSizes();
/*for(Size size: sizes){
Logger.log_d(TAG, CLASS_NAME + ".surfaceChanged() :: Supported preview size (" + size.width + ", " + size.height + ")");
}
Size optimal = getOptimalPreviewSize(sizes, w, h);
Logger.log_d(TAG, CLASS_NAME + ".surfaceChanged() :: Preview size set at (" + optimal.width + ", " + optimal.height + ")"); Logger.log_d(TAG, CLASS_NAME + ".surfaceChanged() :: Preview size set at (" + optimal.width + ", " + optimal.height + ")");
camParams.setPreviewSize(optimal.width, optimal.height); camParams.setPreviewSize(optimal.width, optimal.height);*/
camParams.setPreviewSize(720, 480);
camera.setParameters(camParams); camera.setParameters(camParams);
previewWidth = optimal.width; /*previewWidth = optimal.width;
previewHeight = optimal.height; previewHeight = optimal.height;*/
previewWidth = 720;
previewHeight = 480;
android.hardware.Camera.CameraInfo info = new android.hardware.Camera.CameraInfo(); android.hardware.Camera.CameraInfo info = new android.hardware.Camera.CameraInfo();
android.hardware.Camera.getCameraInfo(0, info); android.hardware.Camera.getCameraInfo(0, info);

View File

@@ -49,6 +49,7 @@ public class VideoStreamingThread extends Thread{
private final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); private final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
public VideoStreamingThread(String serverIp){ public VideoStreamingThread(String serverIp){
super("Video Streaming Thread");
this.serverIp = serverIp; this.serverIp = serverIp;
pause = false; pause = false;
done = false; done = false;
@@ -189,6 +190,9 @@ public class VideoStreamingThread extends Thread{
}else{ }else{
while(!done){ while(!done){
sendImage(); sendImage();
try{
sleep(50L);
}catch(InterruptedException ie){}
} }
} }
@@ -202,6 +206,10 @@ public class VideoStreamingThread extends Thread{
Rect imageSize; Rect imageSize;
image = camMonitor.getImageData(); image = camMonitor.getImageData();
if(image == null){
Logger.log_e(TAG, CLASS_NAME + ".sendImage() :: image is null, skipping frame.");
return;
}
imageSize = camMonitor.getImageParameters(); imageSize = camMonitor.getImageParameters();
// Compress the image as Jpeg. // Compress the image as Jpeg.
@@ -219,7 +227,7 @@ public class VideoStreamingThread extends Thread{
Logger.log_d(TAG, CLASS_NAME + ".sendImage() :: Sending message."); Logger.log_d(TAG, CLASS_NAME + ".sendImage() :: Sending message.");
writer.writeObject(message); writer.writeObject(message);
writer.flush(); writer.flush();
Logger.log_e(TAG, CLASS_NAME + ".sendImage() :: Message sent successfully: "); Logger.log_d(TAG, CLASS_NAME + ".sendImage() :: Message sent successfully: ");
}catch(IOException io){ }catch(IOException io){
Logger.log_e(TAG, CLASS_NAME + ".sendImage() :: Error sending image to the server: " + io.getMessage()); Logger.log_e(TAG, CLASS_NAME + ".sendImage() :: Error sending image to the server: " + io.getMessage());
@@ -227,6 +235,11 @@ public class VideoStreamingThread extends Thread{
}finally{ }finally{
Logger.log_d(TAG, CLASS_NAME + ".sendImage() :: Cleaning."); Logger.log_d(TAG, CLASS_NAME + ".sendImage() :: Cleaning.");
outputStream.reset(); outputStream.reset();
image = null;
yuvImage = null;
message = null;
imageSize = null;
System.gc();
} }
} }

View File

@@ -32,5 +32,5 @@ public abstract class ProjectConstants {
// Activity results. // Activity results.
public static final int RESULT_CAMERA_FAILURE = Activity.RESULT_FIRST_USER + 1; public static final int RESULT_CAMERA_FAILURE = Activity.RESULT_FIRST_USER + 1;
public static final boolean DEBUG = true; public static final boolean DEBUG = false;
} }