nicolas2k / google-glass-api

Automatically exported from code.google.com/p/google-glass-api
1 stars 0 forks source link

Cannot re-acquire the camera #369

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Create an activity that simply acquires camera in onStart and releases it in 
onStop.
2. Launch the activity with the screen on (swipe a bit back and forth to keep 
the screen on)
3. Let the screen go out (depending on how much time passed, Glass will either 
stop or destroy the activity).
4. Restart the activity.
5. Observe Camera.open in onStart

What is the expected output? What do you see instead?
Expected: camera is re-acquired.
Actual: exception is thrown

What version of the product are you using? On what operating system?
XE12

Please provide any additional information below.

Here's the code for my activity:
import android.app.Activity;
import android.hardware.Camera;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;

public class MyCameraActivity extends Activity { 

    private Camera camera;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.camera_view);
    }

    @Override
    protected void onStart() {
        super.onStart();
        try {
            camera = Camera.open();
        } catch (Exception e) {
            e.printStackTrace();
            finish();
        }
    }

    @Override
    protected void onStop() {
        super.onStop();
        if (camera != null) {
            camera.release();
            camera = null;
        }
    }
}

This issue blocks implementing camera preview start/stop on screen going on/off.

Original issue reported on code.google.com by eug...@wearableintelligence.com on 17 Jan 2014 at 8:56

GoogleCodeExporter commented 8 years ago
Hello,

Unfortunately, I haven't been able to reproduce your issue. My initial guess is 
that you started/stopped the camera in onStart/onStop instead of 
onResume/onPause (which is the recommended way) but even using your logic did 
not cause any issue.

Do you have a specific stack trace that you could share? Also, could you try 
moving your starting/stopping logic to onResume/onPause and see if it fixes 
your issue?

Lastly, if you could share a small project that does reproduce the issue, that 
would help us investigate.

Best,
Alain

Original comment by ala...@google.com on 21 Jan 2014 at 11:38

GoogleCodeExporter commented 8 years ago
Alain, the issue of onResume/onPause is irrelevant. I chose to attach my 
recording control to onStart/onStop. If there's an absolute reason why I 
shouldn't be doing that, that's not a recommendation but a constraint and 
should be stated as such.

As for the code sample, what I posted above is the full sample. I didn't 
provide the layout, but, since I'm not using anything there, I deemed it 
irrelevant. My layout consists of a simple SurfaceView put inside a 
RelativeLayout.

My guess is that the problem is not in the code itself but, rather, in camera's 
native code occasionally going out of sync with the Java code. I noticed that 
piece to be extremely fragile. It gets affected by everything - from an 
overheated camera, to an instance released at a wrong time, to even occasional 
screen issues (when screen just dies and only a reboot helps).

Unfortunately, I cannot help you more with this issue. Please take it as 
reported.

Original comment by eug...@wearableintelligence.com on 22 Jan 2014 at 12:43

GoogleCodeExporter commented 8 years ago
Hello,

onResume/onPause is recommended by the Android documentation on camera 
management: http://developer.android.com/reference/android/hardware/Camera.html

As mentioned in our docs, knowing Android development is a requirement before 
using the GDK: https://developers.google.com/glass/develop/gdk/index

The above code does not start any preview nor does it attach a Surface for the 
camera to draw on, that is why I asked for a more detailed code to understand 
how you do start the preview as you mentioned trying to implement camera 
preview start/stop.

I was also wondering if you could provide a stack trace that would help us 
investigate.

Again, the GDK is in sneak peek, it is not yet fully ready and this is clearly 
mentioned everywhere in our docs. I understand your frustration in the API not 
being stable, it is not a reason to be rude.

I am willing to help you, but since I can't reproduce your issue, I have to ask 
for more information; the bug won't go anywhere until me or someone else 
managed to reproduce.

Best,
Alain

Original comment by ala...@google.com on 22 Jan 2014 at 1:42

GoogleCodeExporter commented 8 years ago
Alain, the preview was not required to reproduce the issue. The code I
provided was sufficient. Like I said, it is possible that the issue was due
to a state of my specific hardware.

Regarding your allusion to my misuse of the API, I am quite fluent in the
use of camera (or, rather, have become so after many trial and error tests)
and can tell you that the docs are incomplete and leave a lot to guesswork
and blind experimentation. I stand by all the bugs I submitted on this and
related issues and would like to see them fixed, even if only by updating
docs.

Original comment by eug...@wearableintelligence.com on 22 Jan 2014 at 1:54

GoogleCodeExporter commented 8 years ago
Facing the same issue.
Sample application Logic : Will try to open the camera in onResume() and 
release the camera in onPause().
Issue: After 3-5 times launch, Camera.open() will fail to acquire the camera.

Steps to be followed: 
a)Launch the app with the voice command:Ok Glass,test the camera.
b)Exit the application by swiping down.
c)If camera not acquired, application will exit directly.

Logs with Stack trace and Sample application eclipse project attached.

Original comment by tinojant...@gmail.com on 23 Jan 2014 at 11:31

Attachments:

GoogleCodeExporter commented 8 years ago

Original comment by ala...@google.com on 27 Jan 2014 at 5:21

GoogleCodeExporter commented 8 years ago
This is definitely an issue with the camera.  It also seems to happen when you 
stop and start a camera preview, such as re-sizing the preview screen by 
changing it's parameters.  This issue is present in the normal camera 
application as well from what I have noticed.

Original comment by gerald.m...@gmail.com on 25 Jul 2014 at 7:58

GoogleCodeExporter commented 8 years ago
Did anyone resolve this issue?  I am having almost the same issue on XE 22!

Original comment by saifrah...@gmail.com on 18 May 2015 at 5:20