Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dispatch FrameAvailable event to UI thread #14

Merged
merged 1 commit into from
Feb 10, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 26 additions & 8 deletions CameraPanel/CameraAndroid.uno
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,42 @@ public extern(Android) class Camera
cameraAndroid.setOnFrameAvailableListener(new android.graphics.SurfaceTexture.OnFrameAvailableListener() {
public void onFrameAvailable(android.graphics.SurfaceTexture surfaceTexture) {
if(cameraAndroid.HasSurfaceTexture())
{
@{Camera:Of(_this).MakeContextCurrent():Call()};
surfaceTexture.updateTexImage();
@{Camera:Of(_this).OnFrameAvailable():Call()};
}
@{Camera:Of(_this).DispatchFrameAvailable(Java.Object):Call(surfaceTexture)};
}
});

android.app.Activity activity = @(Activity.Package).@(Activity.Name).GetRootActivity();
cameraAndroid.start(activity.getWindowManager().getDefaultDisplay().getRotation(), textureHandle, @{Camera:Of(_this).IntFacing:Get()});
@}

void MakeContextCurrent()
class FrameAvailableClosure
{
if defined(Android)
extern "GLHelper::MakeWorkerThreadContextCurrent()";
Camera _camera;
Java.Object _tex;

public FrameAvailableClosure(Camera camera, Java.Object tex)
{
_camera = camera;
_tex = tex;
}

public void FrameAvailable()
{
UpdateTexImage(_tex);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely sure this is quite enough. I think we still can risk not having a GL-context active, for instance if the app was kicked to the background before the dispatch took effect. But I'm not 100% sure.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, needs to be tested

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi All and thanks a lot for your replies and help,

I tested the following (on my Oppo R9 where the preview works):

  1. Launch the app: preview ok
  2. App to background > open other apps > reopen ours : preview resumes ok
  3. App to background > open the mobile's camera app > close it > reopen ours: preview does not resume, there is no crash, the latest preview frame keeps being displayed, but not updated.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will complete my answer once we've been able to re-test on the Samsung Trend Plus, where the preview did not work since the app launch. Should be done with the next 24 hours

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The app still crashes at opening on Samsung Trend Plus.

_camera.OnFrameAvailable();
}

[Foreign(Language.Java)]
void UpdateTexImage(Java.Object tex)
@{
((android.graphics.SurfaceTexture)tex).updateTexImage();
@}
}

void DispatchFrameAvailable(Java.Object surfaceTexture)
{
Fuse.UpdateManager.Dispatcher.Invoke(new FrameAvailableClosure(this, surfaceTexture).FrameAvailable);
}

public void OnFrameAvailable()
{
Expand Down