2

I have an application that is using the Android port of GPUImage as the OpenGL Renderer and manager of several filters.

It currently does not have a video implementation, so I am trying to adapt the RecordFBOActivity from the Google grafika repository to work with the GPUImage architecture.

The base GPUImage class manages the GLContext and GLSurfaceView, and the GPUImageRenderer class implements the Renderer class.

This is the class where I am trying to adapt the RenderThread from the RecordFBOActivity of grafika. There are a few problems.

First, in the preparegl() method, I am passing a SurfaceTexture instead of a Surface, as GPUImage doesn't use the SurfaceHolder at all (I think I can implement it, but am trying not to change the base code too much, as i would like to push back my implementation to the aforementioned repo). I know that WindowSurface.java has an overloaded method to construct a WindowSurface from a SurfaceTexture as well as a Surface, but if I do this the mSurface iVar is always null, as I never have a surface to pass to it, which causes a NPE in the makeCurrent() method of recording.

Second, GPUImage attaches itself to a GLSurfaceView, not a SurfaceView like the grafika example uses, so I'm a little uncertain if there are any low level inconsistencies that may be causing conflicts for me...

Third, and I think this is the main issue, at least at the moment, is that I can't seem to reconcile the camera preview of GPUImage with the WindowSurface of grafika. If I comment out the prepareGl() method, the setUpSurfaceTexture() of GPUImage sets the preview texture of the camera from the SurfaceTexture that is created by glGenTextures() and the preview works fine.. as well as being attached to the filter render chain. However, if I try to call the prepareGL() method, and pass the exact same SurfaceTexture to the constructor of mWindowSurface, the camera service dies and i get a EGL_BAD_SURFACE error.

Long question, with a few moving parts, I know... Will attempt to edit/update as I can clarify issues and approaches to myself. But would love if anyone has any thoughts/interrogations... particularly @fadden :D

jesses.co.tt
  • 2,689
  • 1
  • 30
  • 49
  • @fadden would love if you could chime in here at all... – jesses.co.tt Nov 17 '14 at 23:43
  • Can you clarify if you are using the Camera. Have you looked at the camera2 api? Or is your intention to get it working on legacy camera api? – Morrison Chang Nov 18 '14 at 00:32
  • @MorrisonChang Yes, I am passing the camera from my MainActivity into the GPUImage class, and that camera has its preview texture set in the GPUImageRenderer class... Everything works fine with the camera and the preview until I attempt to set the WindowSurface with the same SurfaceTexture that I am feeding the Camera... – jesses.co.tt Nov 18 '14 at 00:40
  • And yes, I am looking at the new Camera API on Lollipop, but that will have to come later... I'm not sure from my initial review of the class that it will change anything, I think it is an underlying logic issue with a shared OpenGLES context that is my problem... – jesses.co.tt Nov 18 '14 at 00:41
  • 1
    I'm not familiar with the other software you mention, so I'm a bit fuzzy on what the issues are. Initial thought: use of GLSurfaceView means the management of the EGL context is handled "behind the scenes", so instead of rendering to two surfaces with a single context, you have to create a second context for your recording surface, and configure it to share state with the GLSurfaceView context. "Show + capture camera" activity does this. If you're using an independent EGL context, the texture ID from the GLSurfaceView context won't map to what you want. – fadden Nov 18 '14 at 00:46
  • @fadden ok, that may point me in the right direction - thank you. – jesses.co.tt Nov 18 '14 at 21:10

1 Answers1

0

I was also trying to achieve the same thing and have tried what fadden has suggested. Tried to integrate CameraSurfaceRenderer functionality to GPUImageRenderer. The preview is fine but the recording is just a video with black frames. EGL14.eglGetCurrentContext() returns null for following call and my guess is if a new context is created it will not be same as what GPUImage might have

mVideoEncoder.startRecording(new TextureMovieEncoder.EncoderConfig(
                                    mOutputFile, 640, 480, 1000000, EGL14.eglGetCurrentContext()));

@Jesses.co.tt were you able to achieve it?

(as I can't add comment it is added as an answer).

Murtaza Khursheed Hussain
  • 15,176
  • 7
  • 58
  • 83
Amit
  • 69
  • 1
  • 1
  • 7
  • not yet... I also got it to show the preview, and can record a glitchy texture, but no success as of yet. Had to step away from this last week, will be picking up... – jesses.co.tt Dec 08 '14 at 17:27