From 120203a4f5bf39651d56a0be981667cea720f733 Mon Sep 17 00:00:00 2001 From: KillerInk Date: Wed, 14 Nov 2018 15:04:55 +0100 Subject: [PATCH 1/2] check if prepare is sucessfull bevor starting a recording --- .../apis/basecamera/record/VideoRecorder.java | 13 ++-- .../camera1/modules/AbstractVideoModule.java | 63 ++++++------------- .../apis/camera2/modules/VideoModuleApi2.java | 25 +++++--- 3 files changed, 42 insertions(+), 59 deletions(-) diff --git a/app/src/main/java/freed/cam/apis/basecamera/record/VideoRecorder.java b/app/src/main/java/freed/cam/apis/basecamera/record/VideoRecorder.java index a22072bda..2dbb81181 100644 --- a/app/src/main/java/freed/cam/apis/basecamera/record/VideoRecorder.java +++ b/app/src/main/java/freed/cam/apis/basecamera/record/VideoRecorder.java @@ -105,7 +105,7 @@ public void stop() mediaRecorder.stop(); } - public void prepare() + public boolean prepare() { mediaRecorder.reset(); if (camera != null) @@ -119,7 +119,7 @@ public void prepare() catch (NullPointerException ex) { Log.WriteEx(ex); - + //return false; } try { if (this.currentVideoProfile.duration != 0) @@ -129,6 +129,7 @@ public void prepare() { Log.WriteEx(ex); Log.e(TAG,"Failed to set Duration"); + //return false; } if (errorListener != null) @@ -157,13 +158,13 @@ public void prepare() { mediaRecorder.reset(); UserMessageHandler.sendMSG("AudioSource not Supported",true); - return; + return false; } catch (IllegalStateException ex) { mediaRecorder.reset(); UserMessageHandler.sendMSG("AudioSource not Supported",true); - return; + return false; } } break; @@ -213,6 +214,7 @@ void setCaptureRate (double fps) { mediaRecorder.reset(); UserMessageHandler.sendMSG("AudioCodec not Supported",false); + return false; } mediaRecorder.setAudioChannels(this.currentVideoProfile.audioChannels); mediaRecorder.setAudioEncodingBitRate(this.currentVideoProfile.audioBitRate); @@ -233,8 +235,9 @@ void setCaptureRate (double fps) } catch (IOException ex) { Log.WriteEx(ex); UserMessageHandler.sendMSG("Prepare failed :" + ex.getMessage(),false); - return; + return false; } + return true; } private void setRecorderFilePath() { diff --git a/app/src/main/java/freed/cam/apis/camera1/modules/AbstractVideoModule.java b/app/src/main/java/freed/cam/apis/camera1/modules/AbstractVideoModule.java index dd6cb74ec..15cc4ccce 100644 --- a/app/src/main/java/freed/cam/apis/camera1/modules/AbstractVideoModule.java +++ b/app/src/main/java/freed/cam/apis/camera1/modules/AbstractVideoModule.java @@ -62,6 +62,7 @@ public void InitModule() { initRecorder(); } + @Override public String ShortName() { return "Mov"; @@ -148,25 +149,24 @@ private void prepareRecorder() recorder.setPreviewSurface(((CameraHolder) cameraUiWrapper.getCameraHolder()).getSurfaceHolder()); - try { + Log.d(TAG,"Preparing Recorder"); - recorder.prepare(); - Log.d(TAG, "Recorder Prepared, Starting Recording"); - recorder.start(); - Log.d(TAG, "Recording started"); - sendStartToUi(); - - } catch (Exception ex) - { - Log.e(TAG,"Recording failed"); - UserMessageHandler.sendMSG("Start Recording failed " + ex.getLocalizedMessage(),false); - Log.WriteEx(ex); - isWorking = false; - ((CameraHolder) cameraUiWrapper.getCameraHolder()).GetCamera().lock(); - recorder.release(); - isWorking = false; - sendStopToUi(); - } + if(recorder.prepare()) { + Log.d(TAG, "Recorder Prepared, Starting Recording"); + recorder.start(); + Log.d(TAG, "Recording started"); + sendStartToUi(); + } + else + { + Log.e(TAG,"Recording failed"); + UserMessageHandler.sendMSG("Start Recording failed ",false); + isWorking = false; + ((CameraHolder) cameraUiWrapper.getCameraHolder()).GetCamera().lock(); + recorder.reset(); + isWorking = false; + sendStopToUi(); + } } catch (NullPointerException ex) { @@ -174,7 +174,7 @@ private void prepareRecorder() UserMessageHandler.sendMSG("Start Recording failed",false); isWorking = false; ((CameraHolder) cameraUiWrapper.getCameraHolder()).GetCamera().lock(); - recorder.release(); + recorder.reset(); isWorking = false; sendStopToUi(); @@ -226,31 +226,6 @@ void stopRecording() } } - /*private void setRecorderOutPutFile(String s) - { - if (VERSION.SDK_INT < VERSION_CODES.KITKAT - || !SettingsManager.getInstance().GetWriteExternal() && VERSION.SDK_INT >= VERSION_CODES.KITKAT) - recorder.setOutputFile(s); - else - { - File f = new File(s); - DocumentFile df = cameraUiWrapper.getActivityInterface().getFreeDcamDocumentFolder();*/ - //DocumentFile wr = df.createFile("*/*", f.getName()); - /*try { - fileDescriptor = cameraUiWrapper.getContext().getContentResolver().openFileDescriptor(wr.getUri(), "rw"); - recorder.setOutputFile(fileDescriptor.getFileDescriptor()); - } catch (FileNotFoundException ex) { - Log.WriteEx(ex); - try { - fileDescriptor.close(); - } catch (IOException ex1) { - Log.WriteEx(ex1); - } - } - } - - }*/ - @Override public void onInfo(MediaRecorder mr, int what, int extra) { if (what == MediaRecorder.MEDIA_RECORDER_INFO_MAX_DURATION_REACHED) diff --git a/app/src/main/java/freed/cam/apis/camera2/modules/VideoModuleApi2.java b/app/src/main/java/freed/cam/apis/camera2/modules/VideoModuleApi2.java index d3035a5f9..e8c7bd63d 100644 --- a/app/src/main/java/freed/cam/apis/camera2/modules/VideoModuleApi2.java +++ b/app/src/main/java/freed/cam/apis/camera2/modules/VideoModuleApi2.java @@ -288,16 +288,21 @@ else if (what == MediaRecorder.MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED) videoRecorder.setVideoSource(VideoSource.SURFACE); videoRecorder.setOrientation(0); - videoRecorder.prepare(); - recorderSurface = videoRecorder.getSurface(); - cameraUiWrapper.captureSessionHandler.AddSurface(recorderSurface,true); - Range fps = new Range<>(currentVideoProfile.videoFrameRate,currentVideoProfile.videoFrameRate); - cameraUiWrapper.captureSessionHandler.SetPreviewParameter(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE,fps); - - if (currentVideoProfile.Mode != VideoMediaProfile.VideoMode.Highspeed) - cameraUiWrapper.captureSessionHandler.CreateCaptureSession(previewrdy); - else - cameraUiWrapper.captureSessionHandler.CreateHighSpeedCaptureSession(previewrdy); + if(videoRecorder.prepare()) { + recorderSurface = videoRecorder.getSurface(); + cameraUiWrapper.captureSessionHandler.AddSurface(recorderSurface, true); + Range fps = new Range<>(currentVideoProfile.videoFrameRate, currentVideoProfile.videoFrameRate); + cameraUiWrapper.captureSessionHandler.SetPreviewParameter(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE, fps); + + if (currentVideoProfile.Mode != VideoMediaProfile.VideoMode.Highspeed) + cameraUiWrapper.captureSessionHandler.CreateCaptureSession(previewrdy); + else + cameraUiWrapper.captureSessionHandler.CreateHighSpeedCaptureSession(previewrdy); + } + else{ + isRecording = false; + changeCaptureState(ModuleHandlerAbstract.CaptureStates.video_recording_stop); + } } private void recordnextFile(MediaRecorder mr) { From 2776cc6b0f14e05e657354d91f8ffbb480eca422 Mon Sep 17 00:00:00 2001 From: KillerInk Date: Wed, 14 Nov 2018 15:08:08 +0100 Subject: [PATCH 2/2] add ability to overwrite minfocusdistance on camera2 --- .../featuredetector/Camera2FeatureDetectorTask.java | 2 ++ .../main/java/freed/settings/SettingsManager.java | 13 +++++++++++++ .../main/java/freed/settings/XmlParserWriter.java | 2 ++ app/src/main/res/raw/supported_devices.xml | 2 ++ 4 files changed, 19 insertions(+) diff --git a/app/src/main/java/freed/cam/apis/featuredetector/Camera2FeatureDetectorTask.java b/app/src/main/java/freed/cam/apis/featuredetector/Camera2FeatureDetectorTask.java index 5b298a7bd..4de2e20ec 100644 --- a/app/src/main/java/freed/cam/apis/featuredetector/Camera2FeatureDetectorTask.java +++ b/app/src/main/java/freed/cam/apis/featuredetector/Camera2FeatureDetectorTask.java @@ -954,6 +954,8 @@ private void detectManualFocus(CameraCharacteristics cameraCharacteristics) { SettingMode mf = SettingsManager.get(SettingKeys.M_Focus); float maxfocusrange = cameraCharacteristics.get(CameraCharacteristics.LENS_INFO_MINIMUM_FOCUS_DISTANCE); + if (SettingsManager.getInstance().getCamera2MinFocusPosition() > 0) + maxfocusrange = SettingsManager.getInstance().getCamera2MinFocusPosition(); if (maxfocusrange == 0) { mf.setIsSupported(false); diff --git a/app/src/main/java/freed/settings/SettingsManager.java b/app/src/main/java/freed/settings/SettingsManager.java index 6ee656177..f70078f93 100644 --- a/app/src/main/java/freed/settings/SettingsManager.java +++ b/app/src/main/java/freed/settings/SettingsManager.java @@ -383,6 +383,19 @@ public void setCamera2MaxIso(int max) Log.d(TAG,"Override max iso:" +settings.getInt("camera2maxiso",0)); } + public void setCamera2MinFocusPosition(float pos) + { + SharedPreferences.Editor editor = settings.edit(); + editor.putFloat("camera2minfocuspos",pos); + editor.commit(); + Log.d(TAG,"Override min focus position:" +settings.getInt("camera2minfocuspos",0)); + } + + public float getCamera2MinFocusPosition() + { + return settings.getInt("camera2minfocuspos",0); + } + public void setDevice(String device) { this.mDevice = device; putString("DEVICE", mDevice); diff --git a/app/src/main/java/freed/settings/XmlParserWriter.java b/app/src/main/java/freed/settings/XmlParserWriter.java index c7294d8cf..e148222ff 100644 --- a/app/src/main/java/freed/settings/XmlParserWriter.java +++ b/app/src/main/java/freed/settings/XmlParserWriter.java @@ -267,6 +267,8 @@ public void parseAndFindSupportedDevice(Resources resources, HashMap dngProfileHashMap = new LongSparseArray<>(); diff --git a/app/src/main/res/raw/supported_devices.xml b/app/src/main/res/raw/supported_devices.xml index 3c7ac98d1..d18507aea 100644 --- a/app/src/main/res/raw/supported_devices.xml +++ b/app/src/main/res/raw/supported_devices.xml @@ -77,6 +77,8 @@ in ms 34000 overwrite max iso + + 2.0 //used to remove vignett on dngs