Camera2 API

picitup

Senior Member
Jan 9, 2011
205
65
0
Deal
Brill thanks again! I'm learning loads lol.

I just added the extra line you suggested and it works like a charm! Open Camera 1.47.3 (the latest from Play) reports 14 cameras in Settings/About and you can switch between them using the camera switch icon.

The 1st 5 work OK and 6 reports a serious camera error. If you keep tapping, you get a blank screen each time, and eventually it works again, but it starts at camera 1 (selfie) so it looks like Open Camera gets upset at camera 6. To get camera 0 again, you have to close Open Camera and kill the task, restart it again and it's on Camera 0.

I have often thought I should build my own version of Open Camera, but never got round to it. Maybe it's time once I get other projects out the way.

Have a good evening.

Steve
 

TF1920

Senior Member
Nov 23, 2019
68
14
0
It occurred to me that it would be nice if Open Camera had an option to display the current camera on screen so I've asked the nice Mark to consider it here:

https://sourceforge.net/p/opencamera/tickets/669/

:)
Yes it is very easy to build your own version of opencam, and you can simply modify this for your device to show the text you want at each camera pos

at the function clickedSwitchCamera in MainActivity.java

Code:
     public void clickedSwitchCamera(View view) {
        if( MyDebug.LOG )
            Log.d(TAG, "clickedSwitchCamera");
        if( preview.isOpeningCamera() ) {
            if( MyDebug.LOG )
                Log.d(TAG, "already opening camera in background thread");
            return;
        }
        this.closePopup();
        if( this.preview.canSwitchCamera() ) {

            int cameraId = getNextCameraId();
            Log.d(TAG, "HII THERE: "+cameraId);

            if(cameraId==6)
                cameraId=7;
            if(cameraId==8)
                cameraId=9;
            if(cameraId==10)
                cameraId=11;
            if(cameraId==11)
                cameraId=12;
            if(cameraId==12)
                cameraId=13;
            if( preview.getCameraControllerManager().getNumberOfCameras() > 2 ) {
                // telling the user which camera is pointless for only two cameras, but on devices that now
                // expose many cameras it can be confusing, so show a toast to at least display the id
                String CamText="";
                switch (cameraId){
                    case 0:
                        CamText=" Wide 27Mpx";
                        break;
                    case 1:
                        CamText=" Selfi Cam";
                        break;
                    case 2:
                        CamText=" 12Mpx 2X zoom portrait";
                        break;
                    case 3:
                        CamText=" UltraWide 20Mpx";
                        break;
                    case 4:
                        CamText=" Macro 2Mpx";
                        break;
                    case 5:
                        CamText=" Zoom 5X 5Mpx";
                        break;
                }

                String toast_string = getResources().getString(
                        preview.getCameraControllerManager().isFrontFacing(cameraId) ? R.string.front_camera : R.string.back_camera ) +
                        " : " + getResources().getString(R.string.camera_id) + " " + cameraId+ " "+ CamText;
                preview.showToast(null, toast_string);
            }

            View switchCameraButton = findViewById(R.id.switch_camera);
            switchCameraButton.setEnabled(false); // prevent slowdown if user repeatedly clicks
            applicationInterface.reset();
            this.preview.setCamera(cameraId);
            switchCameraButton.setEnabled(true);
            // no need to call mainUI.setSwitchCameraContentDescription - this will be called from PreviewcameraSetup when the
            // new camera is opened
        }
    }
            }
 
  • Like
Reactions: picitup

picitup

Senior Member
Jan 9, 2011
205
65
0
Deal
Well you're just the gift that keeps on giving :)

Thanks for the code. Yes, that does look easy. I can't touch it right now as I'm motorising my microscope with a pic chip to do focus stacking and have promised myself I'll finish it before taking on another project lol. I see Open Camera is compiled in Android Studio so I'll download it and have a play, probably next week.

For interest, I've edited build.prop and added footej camera (com.footej.camera) and camera2test (com.airbeat.device.inspector). Footej does not seem to support any extra cameras, only front and back so +1 for Open Camera. Camera2test did show more cameras, but the 27MP repeated cameras are shown as 4032x2034, or 12MP so I think it's wrong. More importantly, still no 108MP :(

I've attached the (very long) screenshot of Camera2Test.
 

Attachments

TF1920

Senior Member
Nov 23, 2019
68
14
0
The 108Mpx seems elusive for now, in the stock cam they add a new stream configuration so this mode is enabled

Code:
CameraCapabilities: addStreamConfigurationToList: xiaomi.scaler.availableSuperResolutionStreamConfigurations: size = 15
Setting that is what updates the max resolution to

updateSize: picture size is: 12032x9024
But still didnt find how to call it from code to enable it for the camera2 api
 

TF1920

Senior Member
Nov 23, 2019
68
14
0
Yes the 108Mpx mode is there if you use the adb sell and type:
Code:
adb shell dumpsys media.camera > camera.txt
you get all the info from the cam

Code:
 xiaomi.scaler.availableSuperResolutionStreamConfigurations (80420000): int32[60]
        [35 12032 9024 0 ]
        [35 12032 9024 1 ]
        [33 12032 9024 0 ]
        [35 6016 4512 0 ]
        [35 6016 4512 1 ]
        [34 6016 4512 0 ]
        [34 6016 4512 1 ]
and it even opens the possibility of raw ?
android.scaler.availableRawSizes (d0008): int32[14]
[12032 9024 6016 4512 ]
[752 4464 3008 2256 ]
[752 1116 3008 2256 ]
[752 1116 ]
 
Last edited:

picitup

Senior Member
Jan 9, 2011
205
65
0
Deal
Wow if we could get 108MP raw that would be the best!

I'm back home now and had some time this morning so I installed Android Studio, Open Camera source and after some fiddling got it working. What threw me a bit, was when I tried to build it, nothing happened, no error messages, nothing. However once I''d created a virtual device with Tools/AVD and installed the Pie binary, it all worked fine.

So now I have a custom version of Open Camera as I've added your mods. I'll have a proper play later and report back.

Thanks once again for all your efforts.

Steve
 

picitup

Senior Member
Jan 9, 2011
205
65
0
Deal
After playing with Open Camera, it seems that camera id 9 is causing problems with my EU rom. After camera 9 is used, Open Camera no longer updates the screen with the camera image.

Just for now, I've modded the code to limit the last camera id to 5 which seems to work fine:

Code:
            int cameraId = getNextCameraId();

          [B]  if(cameraId>5)  cameraId=0;[/B]

         
            if(cameraId==6)  cameraId=7;
            if(cameraId==8)  cameraId=9;
            if(cameraId==10) cameraId=11;
            if(cameraId==11) cameraId=12;
            if(cameraId==12) cameraId=13;
 

TF1920

Senior Member
Nov 23, 2019
68
14
0
Morning :)

I was poking around the Mi9 forum and found this thread:

[APP][MOD][MAGISK] 48MP and improvements for GCam

https://forum.xda-developers.com/Mi-9/themes/app-48mp-improvements-gcam-t3992597/page2

I appreciate it's for another camera module, but wonder if there's any clues for our sensor there?

Cheers

Steve
Thanks Steve, looks interesting, since there is no code I have downlaoded and trying to decompile it to see what it does, looks dangerous by the comments in the thread :cool:

Camera 9 works for me but it is weird bottom half of the picture is green stripes and upper the image is duplicated like a stereo pic...
 

TF1920

Senior Member
Nov 23, 2019
68
14
0
btw tryed adding this to build.prop but so far see no difference
Code:
persist.camera.HAL3.enabled=1
persist.camera.eis.enabled=1
and from the Mi9 forum there are a few more props to test like
Code:
persist.camera.CDS=1
persist.camera.HAL3.enabled=1
persist.camera.ae.capture.bound=7
persist.camera.ae.instant.bound=7
persist.camera.auto.hdr.enable=1
persist.camera.auxcamera.swap
persist.camera.batchcount=0
persist.camera.continuous.iso
persist.camera.dc.frame.sync
persist.camera.dcrf.enable=1
persist.camera.disable_zsl_mode=0
persist.camera.dual.camera
persist.camera.dual.camera.dump
persist.camera.dual.camera.mpo
persist.camera.dual_led_calib=1
persist.camera.dumpimg
persist.camera.dumpmetadata
persist.camera.eis.enable=1
persist.camera.exif.rotation
persist.camera.eztune.enable
persist.camera.facedetect=1
persist.camera.fdvideo
persist.camera.feature.cac
persist.camera.feature.restart
persist.camera.feature.shutter
persist.camera.global.debug
persist.camera.gyro.android=4
persist.camera.hal.debug
persist.camera.hal3.prv.feature=1
persist.camera.hal3hfr.enable=1
persist.camera.hdr.outcrop
persist.camera.hdr.video=2
persist.camera.imglib.stillmore
persist.camera.initial.exp.val
persist.camera.instant.aec
persist.camera.instant.capture
persist.camera.is_mode=4
persist.camera.is_type=4
persist.camera.jpeg_burst
persist.camera.kpi.debug
persist.camera.led.on.period
persist.camera.liveshot.size
persist.camera.longshot.save
persist.camera.longshot.stages
persist.camera.ltmforseemore
persist.camera.mem.usecache
persist.camera.mem.usepool
persist.camera.mobicat
persist.camera.multi_pass=1
persist.camera.no-display
persist.camera.nonzsl.yuv
persist.camera.offlineraw
persist.camera.ois.disable=0
persist.camera.ois.video=1
persist.camera.opt.livepic=1
persist.camera.preview.seemore
persist.camera.preview.ubwc
persist.camera.preview_raw
persist.camera.preview_yuv
persist.camera.raw.debug.dump
persist.camera.raw.dump
persist.camera.raw.format
persist.camera.raw_yuv
persist.camera.rdi.mode=1
persist.camera.rdimode=1
persist.camera.remosaic.trigeriso=250
persist.camera.retro.number
persist.camera.saf.stablecnt=3
persist.camera.secure.mode
persist.camera.set.afd
persist.camera.snap.format
persist.camera.snapshot.fd
persist.camera.snapshot.number
persist.camera.snapshot_raw
persist.camera.stats.af.paaf
persist.camera.stats.debug.mask
persist.camera.thermal.mode
persist.camera.thermal.mode=frameskip
persist.camera.time.monotonic
persist.camera.tintless
persist.camera.tn.disable
persist.camera.tnr.preview=1
persist.camera.tnr.video=1
persist.camera.tof.direct=1
persist.camera.video.CDS
persist.camera.video.ubwc
persist.camera.video_raw
persist.camera.zsl.backlookcnt
persist.camera.zsl.interval
persist.camera.zsl.mode
persist.camera.zsl.queuedepth
persist.camera.zsl_matching
persist.camera.zsl_raw
persist.camera.zsl_yuv
persist.capture.burst.exposures
 
Last edited:

TF1920

Senior Member
Nov 23, 2019
68
14
0
Also found in the file at /data/property some persist properties related to the camera:

Code:
persist.camera.rearMain.vendorID 03
persist.camera.frontMain.vendorID 01
persist.camera.rearTele4x.vendorID 03
persist.camera.rearTele.vendorID 03
persist.camera.rearMacro.vendorID 01
persist.camera.rearUltra.vendorID 01
persist.camera.module.info Iback_camera=F4_semco_Samsung_s5khmx;front_camera=F4_sunny_Samsung_s5kgd1
persist.camera.module.infoext Lback_camera_aux=F4_semco_OV_ov08a10;back_camera_aux=F4_semco_Samsung_s5k2l7
persist.camera.module.infoext2 Iback_camera_aux=F4_sunny_OV_ov02a10;back_camera_aux=F4_sunny_Sony_imx350
persist.camera.algoup.disableldc 0
And there are plenty more camera props if at adb you check all of them

Code:
find . -name '*so' | xargs strings | grep '^persist\.'
 
Last edited:

picitup

Senior Member
Jan 9, 2011
205
65
0
Deal
Sound like you cracked it wide open! Well done :)

I'll try it out today and report back on the other thread.

You should add a donate button to your account..... :)
 

TF1920

Senior Member
Nov 23, 2019
68
14
0
Code:
also @picitup I found other files that may change the stock or other cam apps behavior to tinker and test at system\vendor\etc\camera\
like camxoverridesettings.txt

these are the contents of mine: some are commented #

Code:
multiCameraEnable=TRUE
#logInfoMask=0x10098
#overrideLogLevels=0x1F
enableNCSService=TRUE
disableOIS=FALSE
disablePDAF=FALSE
pdafHWEnableMask=0x2
disableFocusIndication=1
#enable3ADebugData=TRUE
#enableTuningMetadata=TRUE
advanceFeatureMask=0x7E7
isBeautyMakeupSupported=TRUE
isVideoBeautifierSupported=TRUE
exposeFullSizeForQCFA=FALSE
useFeatureForQCFA=1
enableSensorHWSync=TRUE
multiCameraFrameSync=1
enableSensorFpsMatch=TRUE
enableICAInGrid=1
forceDisableUBWCOnIfeIpeLink=0
enableInternalHALPixelStreamConfig=TRUE
iseispreviewSupported=TRUE
enableBubbleRecovery=FALSE
minReprocessInputWidth=6016
minReprocessInputHeight=4512
logConfigMask=0
ismfnrbokehsupported=TRUE
fovcEnable=1
tintlessEnable=TRUE
enableTOFInterface=TRUE
dynamicEnableTOFInterface=TRUE
isTeleOisSupported=TRUE
gyroSensitivityLLS=0.04
gyroSensitivityLLSEnable=FALSE
FDPreProcessing=GTM
enableOfflineNoiseReprocess=1
enableOISOptimization=TRUE
#Moon Mode Parms Start
enableMoonOffset=1
cubicParamMoonOffset=0
quadraticParamMoonOffset=0
linerParamMoonOffset=10.921
constantParamMoonOffset=0
#Moon Mode Parms End
 
  • Like
Reactions: dedors and picitup