Open lgstud-io opened 4 years ago
Did you increase "cameraNumber" after capture picture?
I call takePicture for camera No1. It retuns me picPath "...._1.jpg" Then I call takePicture for camera No2. It retuns me picPath" ..._1.jpg" also. => did you check the picture content, are you sure picture #1 is different with picture #2? (if different, for sure it is because the second camera saved the picture #2 into the path _1)
there are separate wrapper objects existing for each camera, so camera number is all right. I have downloaded the repository, and did a huge refactoring. (I also removed the video parts as I am not going to use it, and it made only complications with the refactoring.
The main problem is that your solution is not thread safe therefore the threads of the cameras access the same variable and therefore there is a problem I have mentioned.
The solution I have created is a nutshell is:
I have removed your isShooting (or something like that) boolean, again because it was not thread safe, and made capturing a still is based on the picturePath string object like this:
private IFrameCallback mIFrameCallback = new IFrameCallback() {
@Override
public void onFrame(ByteBuffer frame) {
int len = frame.capacity();
byte[] yuv = new byte[len];
frame.get(yuv);
// picture
if (!TextUtils.isEmpty(picPath)) {
String newPath = picPath;
picPath = null;
new Thread(new Runnable() {
@Override
public void run() {
saveYuv2Jpeg(newPath, yuv);
}
}).start();
}
}
};
so basically that's it. not I can take pictures with as many cameras as I possibly can connect to the device, and more importantly, all at the same time.
@lgstud-io can you send me code for multiple camera taking picture as well as recording video??
I have an issue to take pictures simultaneously with multiple cameras. Most of the cases (99% of time) only a single picture is taken
I have a class that wraps every connected camera to the device. The cameraNumber is a unique number of the camera (1 to n) I call this method for every single camera wrapper object
It does not matter if I call them all at once (in a loop), or all one by one waiting for the previous camera to finish and call onPhotoSaved in listener. Only a single photo is taken by camera 1. And the result of the .stillCapture callback returns the path to the image "..._1.jpg" for every other still capture call also.
So: I call takePicture for camera No1. It retuns me picPath "...._1.jpg" Then I call takePicture for camera No2. It retuns me picPath" ..._1.jpg" also. and the picture named "...._2.jpg" is never taken.
What might be the problem?
my photo taking code is the following:
void takePicture(String folderPath, String photoTime) {
if (cameraHandler != null && cameraHandler.isOpened()) {
String newImagePath = folderPath + "/" + photoTime+ "_" + cameraNumber + ".jpg";
cameraHandler.captureStill(newImagePath, picPath -> {
listener.onPhotoSaved(new CapturedPhoto(cameraNumber, picPath));
}
});
}
else {
listener.onPhotoSaved(new CapturedPhoto(cameraNumber, null));
}
}
}