Commit 4e995f01 authored by petter's avatar petter
Browse files

bugfix

git-svn-id: https://www2.in.tum.de/repos/ttt/trunk@65 0463f305-d864-43cb-8a47-61cf597d4139
parent 07c776ef
......@@ -221,7 +221,6 @@ public class LectureProfileDialog {
CameraSettingsButton.setEnabled(false);
CameraSettings = new ttt.videoRecorder.VideoSettingPanel();
CameraSettings.show(false);
CameraSettingsButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
CameraSettings.show(true);
......@@ -468,6 +467,7 @@ public class LectureProfileDialog {
cancelButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
CameraSettings.release();
CameraSettings.show(false);
// close dialog
if (monitorPanel != null)
monitorPanel.close();
......@@ -593,7 +593,8 @@ public class LectureProfileDialog {
// else
CameraSettings.release();
CameraSettings.release();
// store profile
LectureProfile lectureProfile = LectureProfile.getProfile((String) lectureComboBox
.getSelectedItem());
......
......@@ -283,18 +283,7 @@ public class PostProcessorPanel extends GradientPanel {
audioField.setForeground(Color.RED);
audioField.setText("not found");
}
// video available
try {
if (recording.getVideoFilename() != null) {
videoField.setForeground(Color.GREEN);
videoField.setText("found");
} else
throw new FileNotFoundException();
} catch (Exception e) {
videoField.setForeground(Color.RED);
videoField.setText("not found");
}
// init thumbs and script panel
if (recording.thumbnailsAvailable()) {
thumbnailsStatusField.setForeground(Color.GREEN);
......@@ -328,13 +317,17 @@ public class PostProcessorPanel extends GradientPanel {
ocrStatusField.setText("not found");
ocrStatusField.setToolTipText(null);
}
if (recording.getExistingFileBySuffix("zip").exists()) {
if (recording.getExistingFileBySuffix("bjpg").exists()) {
videoField.setForeground(Color.GREEN);
videoField.setText("found");
camStatusField.setForeground(Color.GREEN);
camStatusField.setText("folder found");
camStatusField.setToolTipText("folder exists - content not confirmed");
} else {
camStatusField.setForeground(Color.RED);
camStatusField.setText("not found");
videoField.setForeground(Color.RED);
videoField.setText("not found");
camStatusField.setToolTipText(null);
}
if (recording.getExistingFileBySuffix("mp3").exists()) {
......@@ -1240,8 +1233,7 @@ public class PostProcessorPanel extends GradientPanel {
String audio_filename = recording.getAudioFilename();
if (!session.publish(audio_filename + ".orig", basePath, batch) && audio_filename.length() > 4)
// try if original is wav file
if (!session.publish(audio_filename.substring(0, audio_filename.length() - 4) + ".wav",
basePath, batch))
// if (!session.publish(audio_filename.substring(0, audio_filename.length() - 4) + ".wav", basePath, batch))
// try if original is mp2 file
session.publish(audio_filename.substring(0, audio_filename.length() - 4) + ".mp2",
basePath, batch);
......
......@@ -333,11 +333,7 @@ public class Recorder implements MessageConsumer, Closeable {
//VideoRec start
//TODO recording options
if(lectureProfile.isRecordVideoEnabled()){
VideoRecorder = new VideoRecorderPanel();
VideoRecorder.setRecordingFormat(lectureProfile.getVideoFormat());
VideoRecorder.setRecordingCamera(lectureProfile.getRecordingCamera());
VideoRecorder.setVideoQuality(lectureProfile.getVideoQuality());
VideoRecorder.setRecordpath(file.getCanonicalPath().substring(0, file.getCanonicalPath().length()-4));
VideoRecorder = new VideoRecorderPanel(lectureProfile.getRecordingCamera(), lectureProfile.getVideoFormat(),lectureProfile.getVideoQuality(),file.getCanonicalPath().substring(0, file.getCanonicalPath().length()-4));
VideoRecorder.Start();
}
......
package ttt.videoRecorder;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Iterator;
import java.util.Locale;
import javax.imageio.IIOImage;
import javax.imageio.ImageIO;
import javax.imageio.ImageWriteParam;
import javax.imageio.ImageWriter;
import javax.imageio.plugins.jpeg.JPEGImageWriteParam;
import javax.imageio.stream.MemoryCacheImageOutputStream;
//handles the incoming pictures for linuxcam and windowscam
public abstract class CaptureHandler {
public abstract void onNewImage(byte[] image, String RecordPath, float Quality);
public byte[] compressJpegFile(byte[] inbytes,
float compressionQuality) {
//1.0f equals no compression
if (Float.compare(compressionQuality, 1.0f) != 0) {
try {
BufferedImage bimg = ImageIO.read(new ByteArrayInputStream(inbytes));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
JPEGImageWriteParam iwparam = new JPEGImageWriteParam(Locale.getDefault());
iwparam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
iwparam.setCompressionQuality(compressionQuality);
ImageWriter writer = null;
Iterator<ImageWriter> iter = ImageIO.getImageWritersByFormatName("jpg");
if (iter.hasNext()) {
writer = iter.next();
}
MemoryCacheImageOutputStream mciis= new MemoryCacheImageOutputStream(baos);
writer.setOutput(mciis);
writer.write(null,new IIOImage(bimg,null,null),iwparam);
byte[] bytesOut = baos.toByteArray();
baos.close();
return bytesOut;
} catch (IOException ioe) {
System.out.println("write error: " + ioe.getMessage());
return null;
}
}
return inbytes;
}
}
package ttt.videoRecorder;
//handles the incoming pictures for linuxcam and windowscam
public interface CaptureInterface {
public void onNewImage(byte[] image, String RecordPath, float Quality);
}
......@@ -15,25 +15,24 @@ import au.edu.jcu.v4l4j.exceptions.V4L4JException;
public class LinuxCam implements WebCamControl, Runnable {
private CaptureInterface CI;
private String v4lSysfsPath = "/sys/class/video4linux/";
private CaptureHandler CI;
private String RecordPath;
private List<VideoDevice> system = new LinkedList<VideoDevice>();
private FrameGrabber fg;
private Thread captureThread;
int w = 160, h = 120;
private int w = 160, h = 120;
private boolean CamFound = false;
private float CompressionQuality = 0.1f;
public boolean isRecording = false;
String dev = "/dev/video0";
int currentdev = 0;
private float CompressionQuality = 0.1f;
private boolean isRecording = false;
private int selectedCameraID = 0;
public LinuxCam() throws V4L4JException {
initializeDevices();
}
//all cameras are initialized in order to gather information about them
protected void initializeDevices() throws V4L4JException {
for (Object i : listV4LDeviceFiles()) {
for (Object i : listV4LDeviceFiles()) {
system.add(new VideoDevice(i.toString()));
}
}
......@@ -47,21 +46,20 @@ public class LinuxCam implements WebCamControl, Runnable {
byte[] image;
try {
while (isRecording) {
if (isRecording) {
bb = fg.getFrame();
image = new byte[bb.limit()];
bb.get(image);
CI.onNewImage(image, RecordPath, CompressionQuality);
}
CI.onNewImage(image, RecordPath, CompressionQuality);
}
} catch (V4L4JException e) {
e.printStackTrace();
System.out.println("Failed to capture image");
}
}
private Object[] listV4LDeviceFiles() {
Vector<String> sdev = new Vector<String>();
String v4lSysfsPath = "/sys/class/video4linux/";
File dir = new File(v4lSysfsPath);
String[] files = dir.list();
if (files!=null)
......@@ -81,13 +79,12 @@ public class LinuxCam implements WebCamControl, Runnable {
}
private void initFrameGrabber(int std, int channel)
throws V4L4JException {
fg = system.get(currentdev)
.getJPEGFrameGrabber(w, h, channel, std, V4L4JConstants.MAX_JPEG_QUALITY);
throws V4L4JException {
fg = system.get(selectedCameraID).getJPEGFrameGrabber(w, h, channel, std, V4L4JConstants.MAX_JPEG_QUALITY);
}
@Override
public void release() {
public void release() {//all initialized systems have to be released.
for (VideoDevice x : system) {
x.releaseFrameGrabber();
x.release();
......@@ -96,17 +93,28 @@ public class LinuxCam implements WebCamControl, Runnable {
@Override
public boolean Start() {
boolean check = false;
if (CamFound)
try {
//checking if camera (still) exists
for(Object i: listV4LDeviceFiles()){
if( i.toString().equals(system.get(selectedCameraID).getDevicefile())) {
check = true;
}
}
if(check){
initFrameGrabber(0, 0);
if (!isRecording) {
fg.startCapture();
captureThread = new Thread(this, "Capture Thread");
isRecording = true;
captureThread.start();
return true;
}
}
} catch (V4L4JException e) {
e.printStackTrace();
}
return false;
......@@ -119,41 +127,42 @@ public class LinuxCam implements WebCamControl, Runnable {
isRecording = false;
fg.stopCapture();
fg = null;
system.get(currentdev).releaseFrameGrabber();
system.get(selectedCameraID).releaseFrameGrabber();
return true;
}
return false;
}
@Override
public String getDeviceID(int Device) {
public String getDeviceName(int DeviceID) {
if (CamFound)
return "/dev/video" + Device;
try {
return system.get(DeviceID).getDeviceInfo().getName();
} catch (V4L4JException e) {
e.printStackTrace();
}
return null;
}
@Override
public List<String> getDeviceList() {
List<String> deviselist = new LinkedList<String>();
if (CamFound)
public List<String> getDeviceNames() {
List<String> devicelist = new LinkedList<String>();
if (CamFound){
for (VideoDevice i : system) {
try {
deviselist.add(i.getDeviceInfo().getName());
return deviselist;
devicelist.add(i.getDeviceInfo().getName());
} catch (V4L4JException e) {
e.printStackTrace();
}
}
if(!devicelist.isEmpty())
return devicelist;
}
return null;
}
@Override
public List<TTTVideoFormat> getSupportedFormats(int Device) {
currentdev = Device;
public List<TTTVideoFormat> getSupportedFormats(int Device) {
List<TTTVideoFormat> SupportedFormats = new LinkedList<TTTVideoFormat>();
if (CamFound)
try {
......@@ -173,7 +182,6 @@ public class LinuxCam implements WebCamControl, Runnable {
} catch (V4L4JException e) {
e.printStackTrace();
}
return null;
}
......@@ -181,13 +189,21 @@ public class LinuxCam implements WebCamControl, Runnable {
public void setFormat(int Width, int Height) {
w = Width;
h = Height;
}
@Override
public void setSelectedCam(String DeviceID) {
dev = DeviceID;
}
public void setSelectedCam(String DeviceID) throws SetCameraException {
for(int i = 0; i < system.size();i++){
try {
if(system.get(i).getDeviceInfo().getName().equals(DeviceID)){
selectedCameraID = i;
break;
}
} catch (V4L4JException e) {
throw new SetCameraException();
}
}//for closing
}
@Override
public void setRecordPath(String Path) {
......@@ -195,7 +211,7 @@ public class LinuxCam implements WebCamControl, Runnable {
}
@Override
public void setCaptureInterface(CaptureInterface OnPic) {
public void setCaptureInterface(CaptureHandler OnPic) {
CI = OnPic;
}
......
......@@ -14,26 +14,13 @@ import java.awt.event.MouseMotionAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.awt.image.BufferedImage;
import java.awt.image.RenderedImage;
import java.io.File;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Iterator;
import java.util.Locale;
import javax.imageio.IIOImage;
import javax.imageio.ImageIO;
import javax.imageio.ImageWriteParam;
import javax.imageio.ImageWriter;
import javax.imageio.plugins.jpeg.JPEGImageWriteParam;
import javax.imageio.stream.ImageOutputStream;
import javax.imageio.stream.MemoryCacheImageOutputStream;
import javax.swing.JButton;
import javax.swing.ImageIcon;
......@@ -64,12 +51,11 @@ public class VideoRecorderPanel implements WindowListener, ActionListener {
private TTTVideoFormat tttFormat = new TTTVideoFormat(160, 120);
public VideoRecorderPanel() {
public VideoRecorderPanel(String RecordingCamera, TTTVideoFormat Format, float Quality, String RecordPath) {
try {
WBC = OSUtils.obtainWebcam();
} catch (CameraException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
......@@ -77,6 +63,10 @@ public class VideoRecorderPanel implements WindowListener, ActionListener {
WBC.setCaptureInterface(new MyCapture());
if (WBC.CameraFound()) {
setRecordingCamera(RecordingCamera);
setRecordingFormat(Format);
setRecordpath(RecordPath);
setVideoQuality(Quality);
butHide.setSize(20, 15);
butHide.addActionListener(this);
......@@ -105,7 +95,11 @@ public class VideoRecorderPanel implements WindowListener, ActionListener {
if (!isRecording) {
WBC.setFormat(tttFormat.getWidth(), tttFormat.getHeight());
setSize();
WBC.Start();
try {
WBC.Start();
} catch (CameraStartException e) {
e.printStackTrace();
}
startTime = System.nanoTime();
isRecording = true;
}
......@@ -113,7 +107,11 @@ public class VideoRecorderPanel implements WindowListener, ActionListener {
public void Stop() {
if (isRecording) {
WBC.Stop();
try {
WBC.Stop();
} catch (CameraStopException e) {
e.printStackTrace();
}
WBC.release();
isRecording = false;
saveelapsedTime();
......@@ -141,10 +139,15 @@ public class VideoRecorderPanel implements WindowListener, ActionListener {
}
public void setRecordingCamera(String recordCameraID) {
try{
if (recordCameraID != null) {
WBC.setSelectedCam(recordCameraID);
} else {
WBC.setSelectedCam(WBC.getDeviceID(0));
WBC.setSelectedCam(WBC.getDeviceName(0));
}}
catch(SetCameraException e) {
System.out.println("Couldn't select Camera. Closing Record Window.");
this.close();
}
}
......@@ -208,7 +211,7 @@ public class VideoRecorderPanel implements WindowListener, ActionListener {
}
}
class MyCapture implements CaptureInterface {
class MyCapture extends CaptureHandler {
@Override
public void onNewImage(byte[] image, String RecordPath, float Quality) {
......@@ -229,38 +232,7 @@ public class VideoRecorderPanel implements WindowListener, ActionListener {
} catch (Exception e) {
e.printStackTrace();
}
}
public byte[] compressJpegFile(byte[] inbytes,
float compressionQuality) {
//1.0f means no compression
if (Float.compare(compressionQuality, 1.0f) != 0) {
try {
BufferedImage bimg = ImageIO.read(new ByteArrayInputStream(inbytes));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
JPEGImageWriteParam iwparam = new JPEGImageWriteParam(Locale.getDefault());
iwparam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
iwparam.setCompressionQuality(compressionQuality);
ImageWriter writer = null;
Iterator<ImageWriter> iter = ImageIO.getImageWritersByFormatName("jpg");
if (iter.hasNext()) {
writer = iter.next();
}
MemoryCacheImageOutputStream mciis= new MemoryCacheImageOutputStream(baos);
writer.setOutput(mciis);
writer.write(null,new IIOImage(bimg,null,null),iwparam);
byte[] bytesOut = baos.toByteArray();
baos.close();
return bytesOut;
} catch (IOException ioe) {
System.out.println("write error: " + ioe.getMessage());
return null;
}
}
return inbytes;
}
}
}
......
......@@ -5,26 +5,10 @@ import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.awt.image.RenderedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import javax.imageio.IIOImage;
import javax.imageio.ImageIO;
import javax.imageio.ImageWriteParam;
import javax.imageio.ImageWriter;
import javax.imageio.plugins.jpeg.JPEGImageWriteParam;
import javax.imageio.stream.ImageOutputStream;
import javax.imageio.stream.MemoryCacheImageInputStream;
import javax.imageio.stream.MemoryCacheImageOutputStream;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JEditorPane;
......@@ -93,19 +77,20 @@ public class VideoSettingPanel implements ActionListener {
//MySettings is a nested class within VideoSettingsPanel
WBC.setCaptureInterface(new MySettings());
if (WBC.CameraFound()) {
CamFound = true;
list = WBC.getDeviceList();
list = WBC.getDeviceNames();
WBC.setSelectedCam(WBC.getDeviceID(0));
WBC.setSelectedCam(WBC.getDeviceName(0));
CurrentCameraformat(0);
if(list != null)
for (int i = 0; i < list.size(); ++i) {
boxCameras.addItem(list.get(i));
}
for (int i = 1; i < 11; i++)
for (int i = 1; i < 11; i++){
boxQuality.addItem(i);
}
boxCameras.addActionListener(this);
......@@ -137,9 +122,10 @@ public class VideoSettingPanel implements ActionListener {
}
}catch(CameraException e){
lblnotice.setText("No Camera Found");
}catch(SetCameraException e){
}
butClose.addActionListener(this);
panelControll.add(butClose);
......@@ -150,22 +136,15 @@ public class VideoSettingPanel implements ActionListener {
addPanel(panelstartstop);
addPanel(panelquality);
addPanel(panelControll);
c.gridy = c.gridy + 1;
c.anchor = GridBagConstraints.PAGE_START;
c.gridy = c.gridy + 1;
frame.add(lblnotice, c);
c.gridy = c.gridy + 1;
c.gridy = c.gridy + 1;
frame.add(myLabel, c);
frame.pack();
// frame.setSize(320, 200);
frame.setVisible(true);
c.anchor = GridBagConstraints.CENTER;
frame.pack();
frame.setVisible(false);
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
this.setEnabled(true);
}// End Constructor
GridBagConstraints c = new GridBagConstraints();
......@@ -185,9 +164,14 @@ public class VideoSettingPanel implements ActionListener {
public void CurrentCameraformat(int DeviceID) {
// updates the CameraModeBox
boxFormat.removeAllItems();
formats = WBC.getSupportedFormats(DeviceID);
try {
formats = WBC.getSupportedFormats(DeviceID);
} catch (CameragetFormatsException e) {
e.printStackTrace();
}
if (formats.isEmpty()) {
if (formats == null) {
formats = new LinkedList<TTTVideoFormat>();
lblnotice
.setText("No supported Formats found. Setting Resolution to 160x120.");
formats.add(new TTTVideoFormat(160, 120));
......@@ -207,11 +191,11 @@ public class VideoSettingPanel implements ActionListener {
public TTTVideoFormat getRecordingFormat() {
return AppliedFormat;
}