Skip to content

Commit

Permalink
* Fix swallowed InterruptedException (issue #315)
Browse files Browse the repository at this point in the history
  • Loading branch information
saudet committed Jan 30, 2016
1 parent fc30fc8 commit 6875b0e
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 27 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

* Fix swallowed `InterruptedException` ([issue #315](https://github.com/bytedeco/javacv/issues/315))
* Fix `IPCameraFrameGrabber.stop()` not checking for null ([pull #300](https://github.com/bytedeco/javacv/pull/300)
* Upgrade dependencies for OpenCV 3.1.0, FFmpeg 2.8.4
* Let users call `FFmpegFrameFilter.push(null)` to indicate EOF, as required by some filters like "palettegen" ([issue #287](https://github.com/bytedeco/javacv/issues/287))
* Call `cvHaarDetectObjects()` with `CV_HAAR_FIND_BIGGEST_OBJECT | CV_HAAR_DO_ROUGH_SEARCH` instead of `CV_HAAR_DO_CANNY_PRUNING` in the face detection samples to get acceptable performance with OpenCV 3.0 ([issue #272](https://github.com/bytedeco/javacv/issues/272))
Expand Down
7 changes: 6 additions & 1 deletion samples/RecordActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ShortBuffer;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import org.bytedeco.javacv.Frame;
import org.bytedeco.javacv.FFmpegFrameRecorder;
Expand Down Expand Up @@ -265,7 +268,9 @@ public void stopRecording() {
try {
audioThread.join();
} catch (InterruptedException e) {
e.printStackTrace();
// reset interrupt to be nice
Thread.currentThread().interrupt();
return;
}
audioRecordRunnable = null;
audioThread = null;
Expand Down
10 changes: 3 additions & 7 deletions samples/Square.java
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,11 @@ void drawSquares(IplImage img, CvSeq squares) {
String names[] = new String[]{ "pic1.png", "pic2.png", "pic3.png",
"pic4.png", "pic5.png", "pic6.png" };

public static void main(String args[]) {
public static void main(String args[]) throws Exception {
new Square().main();
}

public void main() {
public void main() throws InterruptedException {
// Java translation: c not used
int i; // , c;
// create memory storage that will contain all the dynamic data
Expand Down Expand Up @@ -283,11 +283,7 @@ public void main() {
// wait for key.
// Also the function cvWaitKey takes care of event processing
// Java translation
KeyEvent key = null;
try {
key = canvas.waitKey(0);
} catch(InterruptedException ie) {
}
KeyEvent key = canvas.waitKey(0);
// c = cvWaitKey(0);

// release both images
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/org/bytedeco/javacv/DC1394FrameGrabber.java
Original file line number Diff line number Diff line change
Expand Up @@ -331,12 +331,16 @@ public void start(boolean tryReset, boolean try1394b) throws Exception {
} catch (Exception e) {
// if we couldn't start, try again with a bus reset
if (tryReset && !resetDone) {
dc1394_reset_bus(camera);
try {
dc1394_reset_bus(camera);
Thread.sleep(100);
} catch (InterruptedException ex) { }
resetDone = true;
start(false, try1394b);
resetDone = true;
start(false, try1394b);
} catch (InterruptedException ex) {
// reset interrupt to be nice
Thread.currentThread().interrupt();
return;
}
} else {
throw e;
}
Expand Down
20 changes: 12 additions & 8 deletions src/main/java/org/bytedeco/javacv/OpenCVFrameGrabber.java
Original file line number Diff line number Diff line change
Expand Up @@ -197,15 +197,19 @@ public void start() throws Exception {
}
cvSetCaptureProperty(capture, CV_CAP_PROP_CONVERT_RGB, imageMode == ImageMode.COLOR ? 1 : 0);

// Before cvRetrieveFrame() starts returning something else then null
// QTKit sometimes requires some "warm-up" time for some reason...
// The first frame on Linux is sometimes null as well,
// so it's probably a good idea to run this for all platforms... ?
int count = 0;
while (count++ < 100 && cvGrabFrame(capture) != 0 && cvRetrieveFrame(capture) == null) {
try {
try {
// Before cvRetrieveFrame() starts returning something else then null
// QTKit sometimes requires some "warm-up" time for some reason...
// The first frame on Linux is sometimes null as well,
// so it's probably a good idea to run this for all platforms... ?
int count = 0;
while (count++ < 100 && cvGrabFrame(capture) != 0 && cvRetrieveFrame(capture) == null) {
Thread.sleep(100);
} catch (InterruptedException ex) { }
}
} catch (InterruptedException ex) {
// reset interrupt to be nice
Thread.currentThread().interrupt();
return;
}

if (!triggerMode) {
Expand Down
12 changes: 5 additions & 7 deletions src/main/java/org/bytedeco/javacv/ProCamGeometricCalibrator.java
Original file line number Diff line number Diff line change
Expand Up @@ -299,19 +299,19 @@ public boolean processMarkers(Marker[] imagedBoardMarkers,
}
}

public void addMarkers() {
public void addMarkers() throws InterruptedException {
addMarkers(0);
}
public void addMarkers(int cameraNumber) {
public void addMarkers(int cameraNumber) throws InterruptedException {
addMarkers(lastDetectedMarkers1[cameraNumber], lastDetectedMarkers2[cameraNumber], cameraNumber);
}
public void addMarkers(Marker[] imagedBoardMarkers, Marker[] imagedProjectorMarkers) {
public void addMarkers(Marker[] imagedBoardMarkers, Marker[] imagedProjectorMarkers) throws InterruptedException {
addMarkers(imagedBoardMarkers, imagedProjectorMarkers, 0);
}
private static ThreadLocal<CvMat>
tempWarp3x3 = CvMat.createThreadLocal(3, 3);
public void addMarkers(Marker[] imagedBoardMarkers,
Marker[] imagedProjectorMarkers, int cameraNumber) {
Marker[] imagedProjectorMarkers, int cameraNumber) throws InterruptedException {
CvMat tempWarp = tempWarp3x3.get();

if (!settings.useOnlyIntersection) {
Expand Down Expand Up @@ -362,9 +362,7 @@ public void addMarkers(Marker[] imagedBoardMarkers,
synchronized (projectorCalibrator) {
// wait our turn to add markers orderly in the projector calibrator...
while (projectorCalibrator.getImageCount()%cameraCalibrators.length < cameraNumber) {
try {
projectorCalibrator.wait();
} catch (InterruptedException ex) { }
projectorCalibrator.wait();
}
projectorCalibrator.addMarkers(imagedProjectorMarkers, prewrappedProjMarkers);
projectorCalibrator.notify();
Expand Down

0 comments on commit 6875b0e

Please sign in to comment.