fyhertz / libstreaming

A solution for streaming H.264, H.263, AMR, AAC using RTP on Android
Apache License 2.0
3.49k stars 1.08k forks source link

How to add autofocus feature to camera #164

Open ghost opened 8 years ago

ghost commented 8 years ago

Hi All,

I am trying to implement the autofocus feature in my livestreaming project. I initially made a sample native Android project as mentioned in this link [http://android-er.blogspot.in/2011/01/start-camera-auto-focusing-autofocus.html ]

However, when I am trying to do the same using libstreaming, I am not getting the desired result.

Here is the code in my live streaming project that uses libstreaming

            {
                   /*auto focus feature*/
    RelativeLayout layoutBackground = (RelativeLayout)findViewById(R.id.surface_layout);
    layoutBackground.setOnClickListener(new RelativeLayout.OnClickListener(){
        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            setCameraFocus(myAutoFocusCallback);
        }
    });
      } //onCreate ends

          public static void setCameraFocus(AutoFocusCallback autoFocus){
    if (VideoStream.mCamera.getParameters().getFocusMode().equals(VideoStream.mCamera.getParameters().FOCUS_MODE_AUTO) ||
            VideoStream.mCamera.getParameters().getFocusMode().equals(VideoStream.mCamera.getParameters().FOCUS_MODE_MACRO)){
        VideoStream.mCamera.getParameters().setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
        VideoStream.mCamera.autoFocus(autoFocus);

    }
}

private AutoFocusCallback myAutoFocusCallback = new AutoFocusCallback(){
    public void onAutoFocus(boolean autoFocusSuccess, Camera arg1) {
            //I get the log message every time but the auto focus isn't happening on screen
                Log.i("App", "Auto focus called success...........");

    }
};
dvidz commented 8 years ago

Hi,

perhaps it will help

add this on VideoStream.java around line 600 & 660

if (parameters.getSupportedFocusModes().contains(
            Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO)) {
        parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO);
    }
ghost commented 8 years ago

Hi @dvidz ,

I tried this but it didn't work :( Can you suggest some other solution

ghost commented 8 years ago

Hi Dvidz, Even I tried your code, but It din't help. Is there any other way?

dvidz commented 8 years ago

Try to change :

Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO

by

Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE
ghost commented 8 years ago

Thanks a lot @dvidz : Our problem is solved :-)

ghost commented 8 years ago

Thanks a ton dvidz. Even my problem is solved.

HjoshM commented 7 years ago

@karanbalkar @dvidz @ram10609601 Hi all, Can you please see my post here and help me? It is directly related to FOCUS MODE that seems to be resolved by you. Thank you