I am currently developing an Android app using Java. The application is designed to record videos using the back camera and process each frame in real-time.
I've successfully obtained and processed the frames initially, but after a few seconds of runtime, the video frames are no longer being processed. Here are more details:
Below is the relevant portion of my code. Feel free to request additional details:
private ImageReader imageReader;
private CaptureRequest.Builder previewRequestBuilder;
private int imageCount = 0;
// Method is called at the beginning, setting things up
private void createCameraPreviewSession(){
...
Surface imageReaderSurface = imageReader.getSurface();
previewRequestBuilder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
previewRequestBuilder.addTarget(imageReaderSurface);
imageReader = ImageReader.newInstance(
previewSize.getWidth(), previewSize.getHeight(),
ImageFormat.JPEG, 2);
...
}
// Method that is called when clicking on a button to start the video recording
private void startRecording(Context context){
...
imageReader.setOnImageAvailableListener(reader -> {
//ExtractImageFromStream
Image image = reader.acquireLatestImage();
if (image != null) {
processImageTest(context, image);
image.close();
}
}, backgroundHandler);
...
}
// This method process images, it only process 1 image out of 10 so it can run faster and actually works in real time.
// I have tried doing it with 1 image out of 5 and 20, it still has the exact same behaviour
void processImageTest(Context context, Image image){
imageCount ++;
Log.d("Video Service", "Image " + imageCount);
if (imageCount % 10 != 0){
return;
}
Log.d("Video Service", "Image " + imageCount + " is being considered");
}
The issue arises after exactly 118 images, where the app stops recording new frames and ceases to log the image count. This occurs consistently after precisely 118 images.
What I've attempted:
Checked the app's memory usage: The problem doesn't seem to stem from memory usage, as the app crashes at a relatively low memory usage, even though it previously worked at much higher levels on the same phone.
Looked for error messages or logs: Despite searching for error messages or crash reports, I couldn't find any information explaining why the application stops working. It simply stops logging image information.
Any insights into the potential cause of this issue or suggestions on how to investigate this peculiar behavior would be greatly appreciated.
EDIT :
I tried the app on another phone and it works great. The phone I am having problem with is a CrossCall Core-X5 and the OS is NEO.