Basic video streaming finished.
This commit is contained in:
@@ -60,6 +60,7 @@ public class CameraImageMonitor{
|
||||
imageConsumed = false;
|
||||
this.imageMonitor.notifyAll();
|
||||
}
|
||||
System.gc();
|
||||
Logger.log_d(TAG, CLASS_NAME + ".setImageData() :: Data copy finished.");
|
||||
}else{
|
||||
Logger.log_d(TAG, CLASS_NAME + ".setImageData() :: Old image still valid, ignoring new image.");
|
||||
|
@@ -105,12 +105,22 @@ public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback
|
||||
requestLayout();
|
||||
|
||||
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 + ")");
|
||||
camParams.setPreviewSize(optimal.width, optimal.height);
|
||||
camParams.setPreviewSize(optimal.width, optimal.height);*/
|
||||
camParams.setPreviewSize(720, 480);
|
||||
camera.setParameters(camParams);
|
||||
previewWidth = optimal.width;
|
||||
previewHeight = optimal.height;
|
||||
/*previewWidth = optimal.width;
|
||||
previewHeight = optimal.height;*/
|
||||
previewWidth = 720;
|
||||
previewHeight = 480;
|
||||
|
||||
android.hardware.Camera.CameraInfo info = new android.hardware.Camera.CameraInfo();
|
||||
android.hardware.Camera.getCameraInfo(0, info);
|
||||
|
@@ -49,6 +49,7 @@ public class VideoStreamingThread extends Thread{
|
||||
private final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
|
||||
public VideoStreamingThread(String serverIp){
|
||||
super("Video Streaming Thread");
|
||||
this.serverIp = serverIp;
|
||||
pause = false;
|
||||
done = false;
|
||||
@@ -189,6 +190,9 @@ public class VideoStreamingThread extends Thread{
|
||||
}else{
|
||||
while(!done){
|
||||
sendImage();
|
||||
try{
|
||||
sleep(50L);
|
||||
}catch(InterruptedException ie){}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,6 +206,10 @@ public class VideoStreamingThread extends Thread{
|
||||
Rect imageSize;
|
||||
|
||||
image = camMonitor.getImageData();
|
||||
if(image == null){
|
||||
Logger.log_e(TAG, CLASS_NAME + ".sendImage() :: image is null, skipping frame.");
|
||||
return;
|
||||
}
|
||||
imageSize = camMonitor.getImageParameters();
|
||||
|
||||
// Compress the image as Jpeg.
|
||||
@@ -219,7 +227,7 @@ public class VideoStreamingThread extends Thread{
|
||||
Logger.log_d(TAG, CLASS_NAME + ".sendImage() :: Sending message.");
|
||||
writer.writeObject(message);
|
||||
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){
|
||||
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{
|
||||
Logger.log_d(TAG, CLASS_NAME + ".sendImage() :: Cleaning.");
|
||||
outputStream.reset();
|
||||
image = null;
|
||||
yuvImage = null;
|
||||
message = null;
|
||||
imageSize = null;
|
||||
System.gc();
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -32,5 +32,5 @@ public abstract class ProjectConstants {
|
||||
// Activity results.
|
||||
public static final int RESULT_CAMERA_FAILURE = Activity.RESULT_FIRST_USER + 1;
|
||||
|
||||
public static final boolean DEBUG = true;
|
||||
public static final boolean DEBUG = false;
|
||||
}
|
||||
|
Reference in New Issue
Block a user