Skip to content
Snippets Groups Projects
Commit f9273975 authored by Adrien Béraud's avatar Adrien Béraud
Browse files

camera: catch codec exception, fix leaks

Change-Id: I6e0690d4f590474c2c0ebf9c7c414c04c2ec5471
parent f94a44db
No related branches found
No related tags found
No related merge requests found
...@@ -512,7 +512,10 @@ public class CameraService { ...@@ -512,7 +512,10 @@ public class CameraService {
} }
} catch (Exception e) { } catch (Exception e) {
Log.e(TAG, "Can't open codec", e); Log.e(TAG, "Can't open codec", e);
if (codec != null) {
codec.release();
codec = null; codec = null;
}
if (encoderInput != null) { if (encoderInput != null) {
encoderInput.release(); encoderInput.release();
encoderInput = null; encoderInput = null;
...@@ -771,8 +774,12 @@ public class CameraService { ...@@ -771,8 +774,12 @@ public class CameraService {
@Override @Override
public void onCaptureStarted(@NonNull CameraCaptureSession session, @NonNull CaptureRequest request, long timestamp, long frameNumber) { public void onCaptureStarted(@NonNull CameraCaptureSession session, @NonNull CaptureRequest request, long timestamp, long frameNumber) {
if (frameNumber == 1) { if (frameNumber == 1) {
try {
codec.first.start(); codec.first.start();
codecStarted[0] = true; codecStarted[0] = true;
} catch (Exception e) {
listener.onError();
}
} }
} }
} : null, handler); } : null, handler);
...@@ -820,13 +827,20 @@ public class CameraService { ...@@ -820,13 +827,20 @@ public class CameraService {
Log.w(TAG, "onClosed"); Log.w(TAG, "onClosed");
if (previewCamera == camera) if (previewCamera == camera)
previewCamera = null; previewCamera = null;
if (codec != null && codec.first != null) { if (codec != null) {
if (codec.first != null) {
if (codecStarted[0]) if (codecStarted[0])
codec.first.signalEndOfInputStream(); codec.first.signalEndOfInputStream();
codec.first.release(); codec.first.release();
if (codec.first == currentCodec) if (codec.first == currentCodec)
currentCodec = null; currentCodec = null;
} }
if (codec.second != null)
codec.second.release();
}
if (reader != null) {
reader.close();
}
s.release(); s.release();
} }
}, handler); }, handler);
......
...@@ -478,6 +478,10 @@ public class HardwareServiceImpl extends HardwareService implements AudioManager ...@@ -478,6 +478,10 @@ public class HardwareServiceImpl extends HardwareService implements AudioManager
@Override @Override
public void startCapture(@Nullable String camId) { public void startCapture(@Nullable String camId) {
if (mIsScreenSharing) {
cameraService.stopScreenSharing();
mIsScreenSharing = false;
}
mShouldCapture = true; mShouldCapture = true;
if (mIsCapturing && mCapturingId != null && mCapturingId.equals(camId)) { if (mIsCapturing && mCapturingId != null && mCapturingId.equals(camId)) {
return; return;
...@@ -544,6 +548,10 @@ public class HardwareServiceImpl extends HardwareService implements AudioManager ...@@ -544,6 +548,10 @@ public class HardwareServiceImpl extends HardwareService implements AudioManager
Log.d(TAG, "stopCapture: " + cameraService.isOpen()); Log.d(TAG, "stopCapture: " + cameraService.isOpen());
mShouldCapture = false; mShouldCapture = false;
endCapture(); endCapture();
if (mIsScreenSharing) {
cameraService.stopScreenSharing();
mIsScreenSharing = false;
}
} }
public void requestKeyFrame() { public void requestKeyFrame() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment